comparison src/SDL_compat.c @ 2781:5651642f4a78

Added software fallback for YUV overlay code when YUV textures aren't available.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 24 Nov 2008 23:25:36 +0000
parents f55c87ae336b
children 6bacfecbf27e
comparison
equal deleted inserted replaced
2780:cc15254e44b6 2781:5651642f4a78
26 #include "SDL.h" 26 #include "SDL.h"
27 #include "SDL_syswm.h" 27 #include "SDL_syswm.h"
28 28
29 #include "video/SDL_sysvideo.h" 29 #include "video/SDL_sysvideo.h"
30 #include "video/SDL_pixels_c.h" 30 #include "video/SDL_pixels_c.h"
31 #include "video/SDL_yuv_sw_c.h"
31 32
32 static SDL_WindowID SDL_VideoWindow = 0; 33 static SDL_WindowID SDL_VideoWindow = 0;
33 static SDL_RendererInfo SDL_VideoRendererInfo; 34 static SDL_RendererInfo SDL_VideoRendererInfo;
34 static SDL_TextureID SDL_VideoTexture = 0; 35 static SDL_TextureID SDL_VideoTexture = 0;
35 static SDL_Surface *SDL_VideoSurface = NULL; 36 static SDL_Surface *SDL_VideoSurface = NULL;
1346 1347
1347 struct private_yuvhwdata 1348 struct private_yuvhwdata
1348 { 1349 {
1349 Uint16 pitches[3]; 1350 Uint16 pitches[3];
1350 Uint8 *planes[3]; 1351 Uint8 *planes[3];
1352
1353 SDL_SW_YUVTexture *sw;
1351 1354
1352 SDL_TextureID textureID; 1355 SDL_TextureID textureID;
1353 }; 1356 };
1354 1357
1355 SDL_Overlay * 1358 SDL_Overlay *
1429 break; 1432 break;
1430 } 1433 }
1431 1434
1432 overlay->hwdata->textureID = 1435 overlay->hwdata->textureID =
1433 SDL_CreateTexture(texture_format, SDL_TEXTUREACCESS_STREAMING, w, h); 1436 SDL_CreateTexture(texture_format, SDL_TEXTUREACCESS_STREAMING, w, h);
1434 if (!overlay->hwdata->textureID) { 1437 if (overlay->hwdata->textureID) {
1438 overlay->hwdata->sw = NULL;
1439 } else {
1440 overlay->hwdata->sw = SDL_SW_CreateYUVTexture(texture_format, w, h);
1441 if (!overlay->hwdata->sw) {
1442 SDL_FreeYUVOverlay(overlay);
1443 return NULL;
1444 }
1445
1446 /* Create a supported RGB format texture for display */
1447 overlay->hwdata->textureID =
1448 SDL_CreateTexture(SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, w, h);
1449 }
1450 if (!overlay->hwdata->textureID) {
1435 SDL_FreeYUVOverlay(overlay); 1451 SDL_FreeYUVOverlay(overlay);
1436 return NULL; 1452 return NULL;
1437 } 1453 }
1438 1454
1439 return overlay; 1455 return overlay;
1447 1463
1448 if (!overlay) { 1464 if (!overlay) {
1449 SDL_SetError("Passed a NULL overlay"); 1465 SDL_SetError("Passed a NULL overlay");
1450 return -1; 1466 return -1;
1451 } 1467 }
1452 if (SDL_LockTexture(overlay->hwdata->textureID, NULL, 1, &pixels, &pitch) 1468 if (overlay->hwdata->sw) {
1453 < 0) { 1469 if (SDL_SW_QueryYUVTexturePixels(overlay->hwdata->sw, &pixels, &pitch) < 0) {
1454 return -1; 1470 return -1;
1455 } 1471 }
1472 } else {
1473 if (SDL_LockTexture(overlay->hwdata->textureID, NULL, 1, &pixels, &pitch)
1474 < 0) {
1475 return -1;
1476 }
1477 }
1456 overlay->pixels[0] = (Uint8 *) pixels; 1478 overlay->pixels[0] = (Uint8 *) pixels;
1457 overlay->pitches[0] = pitch; 1479 overlay->pitches[0] = pitch;
1458 switch (overlay->format) { 1480 switch (overlay->format) {
1459 case SDL_YV12_OVERLAY: 1481 case SDL_YV12_OVERLAY:
1460 case SDL_IYUV_OVERLAY: 1482 case SDL_IYUV_OVERLAY:
1477 SDL_UnlockYUVOverlay(SDL_Overlay * overlay) 1499 SDL_UnlockYUVOverlay(SDL_Overlay * overlay)
1478 { 1500 {
1479 if (!overlay) { 1501 if (!overlay) {
1480 return; 1502 return;
1481 } 1503 }
1482 SDL_UnlockTexture(overlay->hwdata->textureID); 1504 if (overlay->hwdata->sw) {
1505 void *pixels;
1506 int pitch;
1507 if (SDL_LockTexture(overlay->hwdata->textureID, NULL, 1, &pixels, &pitch) == 0) {
1508 SDL_Rect srcrect;
1509
1510 srcrect.x = 0;
1511 srcrect.y = 0;
1512 srcrect.w = overlay->w;
1513 srcrect.h = overlay->h;
1514 SDL_SW_CopyYUVToRGB(overlay->hwdata->sw, &srcrect, SDL_PIXELFORMAT_RGB888, overlay->w, overlay->h, pixels, pitch);
1515 SDL_UnlockTexture(overlay->hwdata->textureID);
1516 }
1517 } else {
1518 SDL_UnlockTexture(overlay->hwdata->textureID);
1519 }
1483 } 1520 }
1484 1521
1485 int 1522 int
1486 SDL_DisplayYUVOverlay(SDL_Overlay * overlay, SDL_Rect * dstrect) 1523 SDL_DisplayYUVOverlay(SDL_Overlay * overlay, SDL_Rect * dstrect)
1487 { 1524 {