Respect environment variables.
authorSunny Sachanandani <sunnysachanandani@gmail.com>
Mon, 19 Jul 2010 21:02:49 +0530
changeset 46050b3a509c53a0
parent 4604 d7535d7a40ea
child 4606 4e145485971b
Respect environment variables.
src/SDL_error.c
src/video/x11/SDL_x11render.c
src/video/x11/SDL_x11sym.h
src/video/x11/SDL_x11video.h
     1.1 --- a/src/SDL_error.c	Mon Jul 19 20:05:53 2010 +0530
     1.2 +++ b/src/SDL_error.c	Mon Jul 19 21:02:49 2010 +0530
     1.3 @@ -38,7 +38,7 @@
     1.4  
     1.5  #define SDL_ERRBUFIZE	1024
     1.6  
     1.7 -#define DEBUG_ERROR
     1.8 +//#define DEBUG_ERROR
     1.9  
    1.10  /* Private functions */
    1.11  
     2.1 --- a/src/video/x11/SDL_x11render.c	Mon Jul 19 20:05:53 2010 +0530
     2.2 +++ b/src/video/x11/SDL_x11render.c	Mon Jul 19 21:02:49 2010 +0530
     2.3 @@ -176,11 +176,87 @@
     2.4                          texture->h, data->pixels, data->pitch);
     2.5  }
     2.6  
     2.7 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
     2.8 +static SDL_bool
     2.9 +CheckXRender(Display *display, int *major, int *minor) {
    2.10 +    const char *env;
    2.11 +
    2.12 +    *major = *minor = 0;
    2.13 +
    2.14 +    env = SDL_getenv("SDL_VIDEO_X11_XRENDER");
    2.15 +
    2.16 +    if (env && !SDL_atoi(env)) {
    2.17 +        return SDL_FALSE;
    2.18 +    }
    2.19 +
    2.20 +    if (!SDL_X11_HAVE_XRENDER) {
    2.21 +        return SDL_FALSE;
    2.22 +    }
    2.23 +
    2.24 +    if (!XRenderQueryVersion(display, major, minor)) {
    2.25 +        return SDL_FALSE;
    2.26 +    }
    2.27 +
    2.28 +    return SDL_TRUE;
    2.29 +}
    2.30 +#endif
    2.31 +
    2.32 +#ifdef SDL_VIDEO_DRIVER_X11_XFIXES
    2.33 +static SDL_bool
    2.34 +CheckXFixes(Display *display, int *major, int *minor) {
    2.35 +    const char *env;
    2.36 +
    2.37 +    *major = *minor = 0;
    2.38 +
    2.39 +    env = SDL_getenv("SDL_VIDEO_X11_XFIXES");
    2.40 +
    2.41 +    if (env && !SDL_atoi(env)) {
    2.42 +        return SDL_FALSE;
    2.43 +    }
    2.44 +
    2.45 +    if (!SDL_X11_HAVE_XFIXES) {
    2.46 +        return SDL_FALSE;
    2.47 +    }
    2.48 +
    2.49 +    if (!XFixesQueryVersion(display, major, minor)) {
    2.50 +        return SDL_FALSE;
    2.51 +    }
    2.52 +
    2.53 +    return SDL_TRUE;
    2.54 +}
    2.55 +#endif
    2.56 +
    2.57 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
    2.58 +static SDL_bool
    2.59 +CheckXDamage(Display *display, int *major, int *minor) {
    2.60 +    const char *env;
    2.61 +
    2.62 +    *major = *minor = 0;
    2.63 +
    2.64 +    env = SDL_getenv("SDL_VIDEO_X11_XDAMAGE");
    2.65 +
    2.66 +    if (env && !SDL_atoi(env)) {
    2.67 +        return SDL_FALSE;
    2.68 +    }
    2.69 +
    2.70 +    if (!SDL_X11_HAVE_XDAMAGE) {
    2.71 +        return SDL_FALSE;
    2.72 +    }
    2.73 +
    2.74 +    if (!XDamageQueryVersion(display, major, minor)) {
    2.75 +        return SDL_FALSE;
    2.76 +    }
    2.77 +
    2.78 +    return SDL_TRUE;
    2.79 +}
    2.80 +#endif
    2.81 +
    2.82  void
    2.83  X11_AddRenderDriver(_THIS)
    2.84  {
    2.85      SDL_RendererInfo *info = &X11_RenderDriver.info;
    2.86      SDL_DisplayMode *mode = &SDL_CurrentDisplay->desktop_mode;
    2.87 +    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    2.88      int i;
    2.89  
    2.90      info->texture_formats[info->num_texture_formats++] = mode->format;
    2.91 @@ -189,7 +265,13 @@
    2.92      info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YUY2;
    2.93      info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_UYVY;
    2.94      info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YVYU;
    2.95 -    info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_ARGB8888;
    2.96 +
    2.97 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
    2.98 +    int major, minor;
    2.99 +    if (CheckXRender(data->display, &major, &minor)) {
   2.100 +        info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_ARGB8888;
   2.101 +    }
   2.102 +#endif
   2.103  
   2.104      for (i = 0; i < _this->num_displays; ++i) {
   2.105          SDL_AddRenderDriver(&_this->displays[i], &X11_RenderDriver);
   2.106 @@ -255,36 +337,17 @@
   2.107      renderer->info.flags = SDL_RENDERER_ACCELERATED;
   2.108  
   2.109  #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   2.110 -    data->use_xrender = SDL_FALSE;
   2.111 -    data->use_xdamage = SDL_FALSE;
   2.112 -    int event_basep, error_basep;
   2.113 -    if (SDL_X11_HAVE_XRENDER) {
   2.114 -        /* Query the extension. This is the server runtime check. */
   2.115 -        if(XRenderQueryExtension(data->display,
   2.116 -                                 &event_basep, &error_basep) == True)
   2.117 -            data->use_xrender = SDL_TRUE;
   2.118 +    int major, minor;
   2.119 +    data->use_xrender = CheckXRender(data->display, &major, &minor);
   2.120 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
   2.121 +    if (CheckXDamage(data->display, &major, &minor)) {
   2.122 +        if (CheckXFixes(data->display, &major, &minor)) {
   2.123 +            if (major >= 2)
   2.124 +                data->use_xdamage = SDL_TRUE;
   2.125 +        }
   2.126      }
   2.127 -#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
   2.128 +#endif
   2.129      if (data->use_xrender) {
   2.130 -        if(SDL_X11_HAVE_XDAMAGE && SDL_X11_HAVE_XFIXES) {
   2.131 -        /* Query XDamage and XFixes */
   2.132 -            if(XDamageQueryExtension(data->display,
   2.133 -                                     &event_basep,
   2.134 -                                     &error_basep) == True && 
   2.135 -               (XFixesQueryExtension(data->display,
   2.136 -                                        &event_basep,
   2.137 -                                        &error_basep) == True)) {
   2.138 -                    int major_version, minor_version;
   2.139 -                    XFixesQueryVersion(data->display,
   2.140 -                                       &major_version,
   2.141 -                                       &minor_version);
   2.142 -                    /* Only XFixes v 2 or greater
   2.143 -                     * Required for XFixesSetPictureClipRegion() */
   2.144 -                    if(major_version >= 2)
   2.145 -                        data->use_xdamage = SDL_TRUE;
   2.146 -            }
   2.147 -        }
   2.148 -#endif
   2.149          /* Find the PictFormat from the visual.
   2.150           * Should be an RGB PictFormat most of the time. */
   2.151          data->xwindow_pict_fmt = XRenderFindVisualFormat(data->display,
     3.1 --- a/src/video/x11/SDL_x11sym.h	Mon Jul 19 20:05:53 2010 +0530
     3.2 +++ b/src/video/x11/SDL_x11sym.h	Mon Jul 19 21:02:49 2010 +0530
     3.3 @@ -240,6 +240,7 @@
     3.4  #if SDL_VIDEO_DRIVER_X11_XRENDER
     3.5  SDL_X11_MODULE(XRENDER)
     3.6  SDL_X11_SYM(Bool,XRenderQueryExtension,(Display *dpy,int *event_base,int *error_base),(dpy,event_base,error_base),return)
     3.7 +SDL_X11_SYM(Bool,XRenderQueryVersion,(Display *dpy,int *major,int *minor),(dpy,major,minor),return)
     3.8  SDL_X11_SYM(XRenderPictFormat*,XRenderFindVisualFormat,(Display *dpy,_Xconst Visual *visual),(dpy,visual),return)
     3.9  SDL_X11_SYM(XRenderPictFormat*,XRenderFindStandardFormat,(Display *dpy,int format),(dpy,format),return)
    3.10  SDL_X11_SYM(XRenderPictFormat*,XRenderFindFormat,(Display *dpy,unsigned long mask,_Xconst XRenderPictFormat* templ,int count),(dpy,mask,templ,count),return)
    3.11 @@ -256,6 +257,7 @@
    3.12  #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
    3.13  SDL_X11_MODULE(XDAMAGE)
    3.14  SDL_X11_SYM(Bool,XDamageQueryExtension,(Display *dpy,int *event_base_return,int *error_base_return),(dpy,event_base_return,error_base_return),return)
    3.15 +SDL_X11_SYM(Status,XDamageQueryVersion,(Display *dpy,int *major,int *minor),(dpy,major,minor),return)
    3.16  SDL_X11_SYM(Damage,XDamageCreate,(Display *dpy,Drawable d,int level),(dpy,d,level),return)
    3.17  SDL_X11_SYM(void,XDamageSubtract,(Display *dpy,Damage damage,XserverRegion repair,XserverRegion parts),(dpy,damage,repair,parts),return)
    3.18  SDL_X11_SYM(void,XDamageDestroy,(Display *dpy,Damage damage),(dpy,damage),return)
     4.1 --- a/src/video/x11/SDL_x11video.h	Mon Jul 19 20:05:53 2010 +0530
     4.2 +++ b/src/video/x11/SDL_x11video.h	Mon Jul 19 21:02:49 2010 +0530
     4.3 @@ -48,6 +48,12 @@
     4.4  #if SDL_VIDEO_DRIVER_X11_XRENDER
     4.5  #include <X11/extensions/Xrender.h>
     4.6  #endif
     4.7 +#if SDL_VIDEO_DRIVER_X11_XDAMAGE
     4.8 +#include <X11/extensions/Xdamage.h>
     4.9 +#endif
    4.10 +#if SDL_VIDEO_DRIVER_X11_XFIXES
    4.11 +#include <X11/extensions/Xfixes.h>
    4.12 +#endif
    4.13  #include "SDL_x11dyn.h"
    4.14  
    4.15  #include "SDL_x11events.h"