diff 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
line wrap: on
line diff
--- a/src/SDL_compat.c	Mon Nov 24 21:43:02 2008 +0000
+++ b/src/SDL_compat.c	Mon Nov 24 23:25:36 2008 +0000
@@ -28,6 +28,7 @@
 
 #include "video/SDL_sysvideo.h"
 #include "video/SDL_pixels_c.h"
+#include "video/SDL_yuv_sw_c.h"
 
 static SDL_WindowID SDL_VideoWindow = 0;
 static SDL_RendererInfo SDL_VideoRendererInfo;
@@ -1349,6 +1350,8 @@
     Uint16 pitches[3];
     Uint8 *planes[3];
 
+	SDL_SW_YUVTexture *sw;
+
     SDL_TextureID textureID;
 };
 
@@ -1431,7 +1434,20 @@
 
     overlay->hwdata->textureID =
         SDL_CreateTexture(texture_format, SDL_TEXTUREACCESS_STREAMING, w, h);
-    if (!overlay->hwdata->textureID) {
+    if (overlay->hwdata->textureID) {
+		overlay->hwdata->sw = NULL;
+	} else {
+		overlay->hwdata->sw = SDL_SW_CreateYUVTexture(texture_format, w, h);
+		if (!overlay->hwdata->sw) {
+			SDL_FreeYUVOverlay(overlay);
+			return NULL;
+		}
+
+		/* Create a supported RGB format texture for display */
+		overlay->hwdata->textureID =
+			SDL_CreateTexture(SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, w, h);
+	}
+	if (!overlay->hwdata->textureID) {
         SDL_FreeYUVOverlay(overlay);
         return NULL;
     }
@@ -1449,10 +1465,16 @@
         SDL_SetError("Passed a NULL overlay");
         return -1;
     }
-    if (SDL_LockTexture(overlay->hwdata->textureID, NULL, 1, &pixels, &pitch)
-        < 0) {
-        return -1;
-    }
+	if (overlay->hwdata->sw) {
+		if (SDL_SW_QueryYUVTexturePixels(overlay->hwdata->sw, &pixels, &pitch) < 0) {
+			return -1;
+		}
+	} else {
+		if (SDL_LockTexture(overlay->hwdata->textureID, NULL, 1, &pixels, &pitch)
+			< 0) {
+			return -1;
+		}
+	}
     overlay->pixels[0] = (Uint8 *) pixels;
     overlay->pitches[0] = pitch;
     switch (overlay->format) {
@@ -1479,7 +1501,22 @@
     if (!overlay) {
         return;
     }
-    SDL_UnlockTexture(overlay->hwdata->textureID);
+	if (overlay->hwdata->sw) {
+		void *pixels;
+		int pitch;
+		if (SDL_LockTexture(overlay->hwdata->textureID, NULL, 1, &pixels, &pitch) == 0) {
+			SDL_Rect srcrect;
+
+			srcrect.x = 0;
+			srcrect.y = 0;
+			srcrect.w = overlay->w;
+			srcrect.h = overlay->h;
+			SDL_SW_CopyYUVToRGB(overlay->hwdata->sw, &srcrect, SDL_PIXELFORMAT_RGB888, overlay->w, overlay->h, pixels, pitch);
+			SDL_UnlockTexture(overlay->hwdata->textureID);
+		}
+	} else {
+		SDL_UnlockTexture(overlay->hwdata->textureID);
+	}
 }
 
 int