src/video/SDL_yuv.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 26 Jul 2003 20:02:00 +0000
changeset 660 73440ac574a2
parent 297 f6ffac90895c
child 760 cf9dd3aa6756
permissions -rw-r--r--
You can't create a YUV overlay in OpenGL mode
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Library General Public
     7     License as published by the Free Software Foundation; either
     8     version 2 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Library General Public License for more details.
    14 
    15     You should have received a copy of the GNU Library General Public
    16     License along with this library; if not, write to the Free
    17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 
    23 #ifdef SAVE_RCSID
    24 static char rcsid =
    25  "@(#) $Id$";
    26 #endif
    27 
    28 /* This is the implementation of the YUV video surface support */
    29 
    30 #include <stdlib.h>
    31 #include <string.h>
    32 
    33 #include "SDL_getenv.h"
    34 #include "SDL_video.h"
    35 #include "SDL_error.h"
    36 #include "SDL_sysvideo.h"
    37 #include "SDL_yuvfuncs.h"
    38 #include "SDL_yuv_sw_c.h"
    39 
    40 
    41 SDL_Overlay *SDL_CreateYUVOverlay(int w, int h, Uint32 format,
    42                                   SDL_Surface *display)
    43 {
    44 	SDL_VideoDevice *video = current_video;
    45 	SDL_VideoDevice *this  = current_video;
    46 	const char *yuv_hwaccel;
    47 	SDL_Overlay *overlay;
    48 
    49 	if ( (SDL_VideoSurface->flags & SDL_OPENGL) == SDL_OPENGL ) {
    50 		SDL_SetError("YUV overlays are not supported in OpenGL mode");
    51 		return NULL;
    52 	}
    53 
    54 	/* Display directly on video surface, if possible */
    55 	if ( getenv("SDL_VIDEO_YUV_DIRECT") ) {
    56 		if ( (display == SDL_PublicSurface) &&
    57 		     ((SDL_VideoSurface->format->BytesPerPixel == 2) ||
    58 		      (SDL_VideoSurface->format->BytesPerPixel == 4)) ) {
    59 			display = SDL_VideoSurface;
    60 		}
    61 	}
    62 	overlay = NULL;
    63         yuv_hwaccel = getenv("SDL_VIDEO_YUV_HWACCEL");
    64 	if ( ((display == SDL_VideoSurface) && video->CreateYUVOverlay) &&
    65 	     (!yuv_hwaccel || (atoi(yuv_hwaccel) > 0)) ) {
    66 		overlay = video->CreateYUVOverlay(this, w, h, format, display);
    67 	}
    68 	/* If hardware YUV overlay failed ... */
    69 	if ( overlay == NULL ) {
    70 		overlay = SDL_CreateYUV_SW(this, w, h, format, display);
    71 	}
    72 	return overlay;
    73 }
    74 
    75 int SDL_LockYUVOverlay(SDL_Overlay *overlay)
    76 {
    77 	return overlay->hwfuncs->Lock(current_video, overlay);
    78 }
    79 
    80 void SDL_UnlockYUVOverlay(SDL_Overlay *overlay)
    81 {
    82 	overlay->hwfuncs->Unlock(current_video, overlay);
    83 }
    84 
    85 int SDL_DisplayYUVOverlay(SDL_Overlay *overlay, SDL_Rect *dstrect)
    86 {
    87 	return overlay->hwfuncs->Display(current_video, overlay, dstrect);
    88 }
    89 
    90 void SDL_FreeYUVOverlay(SDL_Overlay *overlay)
    91 {
    92 	if ( overlay ) {
    93 		if ( overlay->hwfuncs ) {
    94 			overlay->hwfuncs->FreeHW(current_video, overlay);
    95 		}
    96 		free(overlay);
    97 	}
    98 }