comparison src/video/SDL_video.c @ 1676:e136f3ffdc1b SDL-1.3

Adding software renderer implementation
author Sam Lantinga <slouken@libsdl.org>
date Mon, 12 Jun 2006 09:10:06 +0000
parents 8e754b82cecc
children 5e4c5e095925
comparison
equal deleted inserted replaced
1675:d33dcfc3fde7 1676:e136f3ffdc1b
25 25
26 #include "SDL.h" 26 #include "SDL.h"
27 #include "SDL_sysvideo.h" 27 #include "SDL_sysvideo.h"
28 #include "SDL_blit.h" 28 #include "SDL_blit.h"
29 #include "SDL_pixels_c.h" 29 #include "SDL_pixels_c.h"
30 #include "SDL_renderer_sw.h"
30 #include "../events/SDL_sysevents.h" 31 #include "../events/SDL_sysevents.h"
31 #include "../events/SDL_events_c.h" 32 #include "../events/SDL_events_c.h"
32 33
33 /* Available video drivers */ 34 /* Available video drivers */
34 static VideoBootStrap *bootstrap[] = { 35 static VideoBootStrap *bootstrap[] = {
272 SDL_qsort(_this->displays[i].display_modes, 273 SDL_qsort(_this->displays[i].display_modes,
273 _this->displays[i].num_display_modes, 274 _this->displays[i].num_display_modes,
274 sizeof(SDL_DisplayMode), cmpmodes); 275 sizeof(SDL_DisplayMode), cmpmodes);
275 } 276 }
276 277
278 /* The software renderer is always available */
279 for (i = 0; i < _this->num_displays; ++i) {
280 if (_this->displays[i].num_render_drivers > 0) {
281 SDL_AddRenderDriver(i, &SDL_SW_RenderDriver);
282 }
283 }
284
277 /* Start the event loop */ 285 /* Start the event loop */
278 if (SDL_StartEventLoop(flags) < 0) { 286 if (SDL_StartEventLoop(flags) < 0) {
279 SDL_VideoQuit(); 287 SDL_VideoQuit();
280 return -1; 288 return -1;
281 } 289 }
576 window.x = x; 584 window.x = x;
577 window.y = y; 585 window.y = y;
578 window.w = w; 586 window.w = w;
579 window.h = h; 587 window.h = h;
580 window.flags = (flags & allowed_flags); 588 window.flags = (flags & allowed_flags);
589 window.display = &SDL_CurrentDisplay;
581 590
582 if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) { 591 if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) {
583 if (window.title) { 592 if (window.title) {
584 SDL_free(window.title); 593 SDL_free(window.title);
585 } 594 }
618 return (0); 627 return (0);
619 } 628 }
620 629
621 SDL_zero(window); 630 SDL_zero(window);
622 window.id = _this->next_object_id++; 631 window.id = _this->next_object_id++;
632 window.display = &SDL_CurrentDisplay;
623 633
624 if (!_this->CreateWindowFrom || 634 if (!_this->CreateWindowFrom ||
625 _this->CreateWindowFrom(_this, &window, data) < 0) { 635 _this->CreateWindowFrom(_this, &window, data) < 0) {
626 return 0; 636 return 0;
627 } 637 }
1086 texture->access = access; 1096 texture->access = access;
1087 texture->w = w; 1097 texture->w = w;
1088 texture->h = h; 1098 texture->h = h;
1089 texture->renderer = renderer; 1099 texture->renderer = renderer;
1090 1100
1091 if (renderer->CreateTexture(texture) < 0) { 1101 if (renderer->CreateTexture(renderer, texture) < 0) {
1092 SDL_free(texture); 1102 SDL_free(texture);
1093 return 0; 1103 return 0;
1094 } 1104 }
1095 } 1105 }
1096 1106
1284 1294
1285 renderer = texture->renderer; 1295 renderer = texture->renderer;
1286 if (!renderer->UpdateTexture) { 1296 if (!renderer->UpdateTexture) {
1287 return -1; 1297 return -1;
1288 } 1298 }
1289 return renderer->UpdateTexture(texture, rect, pixels, pitch); 1299 return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch);
1290 } 1300 }
1291 1301
1292 int 1302 int
1293 SDL_LockTexture(SDL_TextureID textureID, SDL_Rect * rect, int markDirty, 1303 SDL_LockTexture(SDL_TextureID textureID, SDL_Rect * rect, int markDirty,
1294 void **pixels, int *pitch) 1304 void **pixels, int *pitch)
1302 1312
1303 renderer = texture->renderer; 1313 renderer = texture->renderer;
1304 if (!renderer->LockTexture) { 1314 if (!renderer->LockTexture) {
1305 return -1; 1315 return -1;
1306 } 1316 }
1307 return renderer->LockTexture(texture, rect, markDirty, pixels, pitch); 1317 return renderer->LockTexture(renderer, texture, rect, markDirty, pixels,
1318 pitch);
1308 } 1319 }
1309 1320
1310 void 1321 void
1311 SDL_UnlockTexture(SDL_TextureID textureID) 1322 SDL_UnlockTexture(SDL_TextureID textureID)
1312 { 1323 {
1319 1330
1320 renderer = texture->renderer; 1331 renderer = texture->renderer;
1321 if (!renderer->UnlockTexture) { 1332 if (!renderer->UnlockTexture) {
1322 return; 1333 return;
1323 } 1334 }
1324 return renderer->UnlockTexture(texture); 1335 return renderer->UnlockTexture(renderer, texture);
1325 } 1336 }
1326 1337
1327 void 1338 void
1328 SDL_DirtyTexture(SDL_TextureID textureID, int numrects, SDL_Rect * rects) 1339 SDL_DirtyTexture(SDL_TextureID textureID, int numrects, SDL_Rect * rects)
1329 { 1340 {
1336 1347
1337 renderer = texture->renderer; 1348 renderer = texture->renderer;
1338 if (!renderer->DirtyTexture) { 1349 if (!renderer->DirtyTexture) {
1339 return; 1350 return;
1340 } 1351 }
1341 renderer->DirtyTexture(texture, numrects, rects); 1352 renderer->DirtyTexture(renderer, texture, numrects, rects);
1342 } 1353 }
1343 1354
1344 void 1355 void
1345 SDL_SelectRenderTexture(SDL_TextureID textureID) 1356 SDL_SelectRenderTexture(SDL_TextureID textureID)
1346 { 1357 {
1352 } 1363 }
1353 renderer = texture->renderer; 1364 renderer = texture->renderer;
1354 if (!renderer->SelectRenderTexture) { 1365 if (!renderer->SelectRenderTexture) {
1355 return; 1366 return;
1356 } 1367 }
1357 renderer->SelectRenderTexture(texture); 1368 renderer->SelectRenderTexture(renderer, texture);
1358 } 1369 }
1359 1370
1360 int 1371 int
1361 SDL_RenderFill(SDL_Rect * rect, Uint32 color) 1372 SDL_RenderFill(SDL_Rect * rect, Uint32 color)
1362 { 1373 {
1369 renderer = SDL_CurrentDisplay.current_renderer; 1380 renderer = SDL_CurrentDisplay.current_renderer;
1370 if (!renderer || !renderer->RenderFill) { 1381 if (!renderer || !renderer->RenderFill) {
1371 return -1; 1382 return -1;
1372 } 1383 }
1373 1384
1374 renderer->RenderFill(rect, color); 1385 renderer->RenderFill(renderer, rect, color);
1375 } 1386 }
1376 1387
1377 int 1388 int
1378 SDL_RenderCopy(SDL_TextureID textureID, SDL_Rect * srcrect, 1389 SDL_RenderCopy(SDL_TextureID textureID, SDL_Rect * srcrect,
1379 SDL_Rect * dstrect, int blendMode, int scaleMode) 1390 SDL_Rect * dstrect, int blendMode, int scaleMode)
1388 renderer = SDL_CurrentDisplay.current_renderer; 1399 renderer = SDL_CurrentDisplay.current_renderer;
1389 if (!renderer || !renderer->RenderCopy) { 1400 if (!renderer || !renderer->RenderCopy) {
1390 return -1; 1401 return -1;
1391 } 1402 }
1392 1403
1393 return renderer->RenderCopy(texture, srcrect, dstrect, blendMode, 1404 return renderer->RenderCopy(renderer, texture, srcrect, dstrect,
1394 scaleMode); 1405 blendMode, scaleMode);
1395 } 1406 }
1396 1407
1397 int 1408 int
1398 SDL_RenderReadPixels(SDL_Rect * rect, void *pixels, int pitch) 1409 SDL_RenderReadPixels(SDL_Rect * rect, void *pixels, int pitch)
1399 { 1410 {
1406 renderer = SDL_CurrentDisplay.current_renderer; 1417 renderer = SDL_CurrentDisplay.current_renderer;
1407 if (!renderer || !renderer->RenderReadPixels) { 1418 if (!renderer || !renderer->RenderReadPixels) {
1408 return -1; 1419 return -1;
1409 } 1420 }
1410 1421
1411 return renderer->RenderReadPixels(rect, pixels, pitch); 1422 return renderer->RenderReadPixels(renderer, rect, pixels, pitch);
1412 } 1423 }
1413 1424
1414 int 1425 int
1415 SDL_RenderWritePixels(SDL_Rect * rect, const void *pixels, int pitch) 1426 SDL_RenderWritePixels(SDL_Rect * rect, const void *pixels, int pitch)
1416 { 1427 {
1423 renderer = SDL_CurrentDisplay.current_renderer; 1434 renderer = SDL_CurrentDisplay.current_renderer;
1424 if (!renderer || !renderer->RenderWritePixels) { 1435 if (!renderer || !renderer->RenderWritePixels) {
1425 return -1; 1436 return -1;
1426 } 1437 }
1427 1438
1428 return renderer->RenderWritePixels(rect, pixels, pitch); 1439 return renderer->RenderWritePixels(renderer, rect, pixels, pitch);
1429 } 1440 }
1430 1441
1431 void 1442 void
1432 SDL_RenderPresent(void) 1443 SDL_RenderPresent(void)
1433 { 1444 {
1440 renderer = SDL_CurrentDisplay.current_renderer; 1451 renderer = SDL_CurrentDisplay.current_renderer;
1441 if (!renderer || !renderer->RenderPresent) { 1452 if (!renderer || !renderer->RenderPresent) {
1442 return; 1453 return;
1443 } 1454 }
1444 1455
1445 renderer->RenderPresent(); 1456 renderer->RenderPresent(renderer);
1446 } 1457 }
1447 1458
1448 void 1459 void
1449 SDL_DestroyTexture(SDL_TextureID textureID) 1460 SDL_DestroyTexture(SDL_TextureID textureID)
1450 { 1461 {
1476 SDL_CurrentDisplay.textures[hash] = texture->next; 1487 SDL_CurrentDisplay.textures[hash] = texture->next;
1477 } 1488 }
1478 1489
1479 /* Free the texture */ 1490 /* Free the texture */
1480 renderer = texture->renderer; 1491 renderer = texture->renderer;
1481 renderer->DestroyTexture(texture); 1492 renderer->DestroyTexture(renderer, texture);
1482 SDL_free(texture); 1493 SDL_free(texture);
1483 } 1494 }
1484 1495
1485 void 1496 void
1486 SDL_DestroyRenderer(SDL_WindowID windowID) 1497 SDL_DestroyRenderer(SDL_WindowID windowID)
1510 if (prev) { 1521 if (prev) {
1511 prev->next = next; 1522 prev->next = next;
1512 } else { 1523 } else {
1513 SDL_CurrentDisplay.textures[i] = next; 1524 SDL_CurrentDisplay.textures[i] = next;
1514 } 1525 }
1515 renderer->DestroyTexture(texture); 1526 renderer->DestroyTexture(renderer, texture);
1516 SDL_free(texture); 1527 SDL_free(texture);
1517 } else { 1528 } else {
1518 prev = texture; 1529 prev = texture;
1519 } 1530 }
1520 } 1531 }