Date: Tue, 24 Aug 2004 06:16:32 +0200
authorSam Lantinga <slouken@libsdl.org>
Wed, 25 Aug 2004 05:39:03 +0000
changeset 950b7a5c1b64829
parent 949 e0d96eb0af19
child 951 121f56c1277d
Date: Tue, 24 Aug 2004 06:16:32 +0200
From: Christian Biere
Subject: [SDL] YUV Overlay vs. XV_AUTOPAINT_COLORKEY

I have a problem with SDL's YUV Overlay support using X11 Xv. Some people
reported that they get nothing but a black screen. I've compared the
output of xvattr they've sent me with the values I get here. It turned
out that XV_AUTOPAINT_COLORKEY was disabled. By enabling this feature
everything works fine.
src/video/x11/SDL_x11yuv.c
     1.1 --- a/src/video/x11/SDL_x11yuv.c	Tue Aug 24 07:40:14 2004 +0000
     1.2 +++ b/src/video/x11/SDL_x11yuv.c	Wed Aug 25 05:39:03 2004 +0000
     1.3 @@ -73,10 +73,11 @@
     1.4  };
     1.5  
     1.6  
     1.7 +static int (*X_handler)(Display *, XErrorEvent *) = NULL;
     1.8 +
     1.9  #ifndef NO_SHARED_MEMORY
    1.10  /* Shared memory error handler routine */
    1.11  static int shm_error;
    1.12 -static int (*X_handler)(Display *, XErrorEvent *) = NULL;
    1.13  static int shm_errhandler(Display *d, XErrorEvent *e)
    1.14  {
    1.15          if ( e->error_code == BadAccess ) {
    1.16 @@ -87,6 +88,15 @@
    1.17  }
    1.18  #endif /* !NO_SHARED_MEMORY */
    1.19  
    1.20 +static int xv_error;
    1.21 +static int xv_errhandler(Display *d, XErrorEvent *e)
    1.22 +{
    1.23 +        if ( e->error_code == BadMatch ) {
    1.24 +        	xv_error = True;
    1.25 +        	return(0);
    1.26 +        } else
    1.27 +		return(X_handler(d,e));
    1.28 +}
    1.29  
    1.30  SDL_Overlay *X11_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display)
    1.31  {
    1.32 @@ -192,6 +202,30 @@
    1.33  		return(NULL);
    1.34  	}
    1.35  
    1.36 +	/* Enable auto-painting of the overlay colorkey */
    1.37 +	{
    1.38 +		static const char *attr[] = { "XV_AUTOPAINT_COLORKEY", "XV_AUTOPAINT_COLOURKEY" };
    1.39 +		unsigned int i;
    1.40 +
    1.41 +		SDL_NAME(XvSelectPortNotify)(GFX_Display, xv_port, True);
    1.42 +		X_handler = XSetErrorHandler(xv_errhandler);
    1.43 +		for ( i=0; i < sizeof(attr)/(sizeof attr[0]); ++i ) {
    1.44 +			Atom a;
    1.45 +
    1.46 +			xv_error = False;
    1.47 +			a = XInternAtom(GFX_Display, attr[i], True);
    1.48 +			if ( a != None ) {
    1.49 +     				SDL_NAME(XvSetPortAttribute)(GFX_Display, xv_port, a, 1);
    1.50 +				XSync(GFX_Display, True);
    1.51 +				if ( ! xv_error ) {
    1.52 +					break;
    1.53 +				}
    1.54 +			}
    1.55 +		}
    1.56 +		XSetErrorHandler(X_handler);
    1.57 +		SDL_NAME(XvSelectPortNotify)(GFX_Display, xv_port, False);
    1.58 +	}
    1.59 +
    1.60  	/* Create the overlay structure */
    1.61  	overlay = (SDL_Overlay *)malloc(sizeof *overlay);
    1.62  	if ( overlay == NULL ) {