comparison src/SDL_compat.c @ 1675:d33dcfc3fde7 SDL-1.3

Overlay functions are being replaced by YUV textures. If the driver doesn't support YUV textures, they can be emulated by backing the texture with an RGB texture and using the software conversion routines. Note that it doesn't make sense to lock a portion of a YV12 texture, since you'd need to return three pixel pointers and pitch values instead of the one that's available through the API. I'm guessing that's one of the reasons DirectX 9 doesn't support this format at all.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 11 Jun 2006 07:30:16 +0000
parents eef792d31de8
children 90bf530ced8e
comparison
equal deleted inserted replaced
1674:7688a73b25b1 1675:d33dcfc3fde7
1233 SDL_cursor->area.y = 0; 1233 SDL_cursor->area.y = 0;
1234 SDL_memset(SDL_cursor->save[0], 0, savelen); 1234 SDL_memset(SDL_cursor->save[0], 0, savelen);
1235 } 1235 }
1236 } 1236 }
1237 1237
1238 SDL_Overlay *
1239 SDL_CreateYUVOverlay(int w, int h, Uint32 format, SDL_Surface * display)
1240 {
1241 SDL_VideoDevice *_this = SDL_GetVideoDevice();
1242 SDL_Window *window;
1243 const char *yuv_hwaccel;
1244 SDL_Overlay *overlay;
1245
1246 window = SDL_GetWindowFromSurface(display);
1247 if (window && (window->flags & SDL_WINDOW_OPENGL)) {
1248 SDL_SetError("YUV overlays are not supported in OpenGL mode");
1249 return NULL;
1250 }
1251
1252 /* Display directly on video surface, if possible */
1253 if (SDL_getenv("SDL_VIDEO_YUV_DIRECT")) {
1254 if (window &&
1255 ((window->surface->format->BytesPerPixel == 2) ||
1256 (window->surface->format->BytesPerPixel == 4))) {
1257 display = window->surface;
1258 }
1259 }
1260 overlay = NULL;
1261 yuv_hwaccel = SDL_getenv("SDL_VIDEO_YUV_HWACCEL");
1262 if (((display->flags & SDL_SCREEN_SURFACE) && _this->CreateYUVOverlay) &&
1263 (!yuv_hwaccel || (SDL_atoi(yuv_hwaccel) > 0))) {
1264 overlay = _this->CreateYUVOverlay(_this, w, h, format, display);
1265 }
1266 /* If hardware YUV overlay failed ... */
1267 if (overlay == NULL) {
1268 overlay = SDL_CreateYUV_SW(_this, w, h, format, display);
1269 }
1270 return overlay;
1271 }
1272
1273 int
1274 SDL_LockYUVOverlay(SDL_Overlay * overlay)
1275 {
1276 SDL_VideoDevice *_this = SDL_GetVideoDevice();
1277 return overlay->hwfuncs->Lock(_this, overlay);
1278 }
1279
1280 void
1281 SDL_UnlockYUVOverlay(SDL_Overlay * overlay)
1282 {
1283 SDL_VideoDevice *_this = SDL_GetVideoDevice();
1284 overlay->hwfuncs->Unlock(_this, overlay);
1285 }
1286
1287 int
1288 SDL_DisplayYUVOverlay(SDL_Overlay * overlay, SDL_Rect * dstrect)
1289 {
1290 SDL_VideoDevice *_this = SDL_GetVideoDevice();
1291 SDL_Rect src, dst;
1292 int srcx, srcy, srcw, srch;
1293 int dstx, dsty, dstw, dsth;
1294
1295 /* Clip the rectangle to the screen area */
1296 srcx = 0;
1297 srcy = 0;
1298 srcw = overlay->w;
1299 srch = overlay->h;
1300 dstx = dstrect->x;
1301 dsty = dstrect->y;
1302 dstw = dstrect->w;
1303 dsth = dstrect->h;
1304 if (dstx < 0) {
1305 srcw += (dstx * overlay->w) / dstrect->w;
1306 dstw += dstx;
1307 srcx -= (dstx * overlay->w) / dstrect->w;
1308 dstx = 0;
1309 }
1310 if ((dstx + dstw) > SDL_VideoSurface->w) {
1311 int extra = (dstx + dstw - SDL_VideoSurface->w);
1312 srcw -= (extra * overlay->w) / dstrect->w;
1313 dstw -= extra;
1314 }
1315 if (dsty < 0) {
1316 srch += (dsty * overlay->h) / dstrect->h;
1317 dsth += dsty;
1318 srcy -= (dsty * overlay->h) / dstrect->h;
1319 dsty = 0;
1320 }
1321 if ((dsty + dsth) > SDL_VideoSurface->h) {
1322 int extra = (dsty + dsth - SDL_VideoSurface->h);
1323 srch -= (extra * overlay->h) / dstrect->h;
1324 dsth -= extra;
1325 }
1326 if (srcw <= 0 || srch <= 0 || srch <= 0 || dsth <= 0) {
1327 return 0;
1328 }
1329 /* Ugh, I can't wait for SDL_Rect to be int values */
1330 src.x = srcx;
1331 src.y = srcy;
1332 src.w = srcw;
1333 src.h = srch;
1334 dst.x = dstx;
1335 dst.y = dsty;
1336 dst.w = dstw;
1337 dst.h = dsth;
1338 return overlay->hwfuncs->Display(_this, overlay, &src, &dst);
1339 }
1340
1341 void
1342 SDL_FreeYUVOverlay(SDL_Overlay * overlay)
1343 {
1344 SDL_VideoDevice *_this = SDL_GetVideoDevice();
1345 if (overlay) {
1346 if (overlay->hwfuncs) {
1347 overlay->hwfuncs->FreeHW(_this, overlay);
1348 }
1349 SDL_free(overlay);
1350 }
1351 }
1352
1238 /* vi: set ts=4 sw=4 expandtab: */ 1353 /* vi: set ts=4 sw=4 expandtab: */