changeset 4605:0b3a509c53a0

Respect environment variables.
author Sunny Sachanandani <sunnysachanandani@gmail.com>
date Mon, 19 Jul 2010 21:02:49 +0530
parents d7535d7a40ea
children 4e145485971b
files src/SDL_error.c src/video/x11/SDL_x11render.c src/video/x11/SDL_x11sym.h src/video/x11/SDL_x11video.h
diffstat 4 files changed, 101 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/SDL_error.c	Mon Jul 19 20:05:53 2010 +0530
+++ b/src/SDL_error.c	Mon Jul 19 21:02:49 2010 +0530
@@ -38,7 +38,7 @@
 
 #define SDL_ERRBUFIZE	1024
 
-#define DEBUG_ERROR
+//#define DEBUG_ERROR
 
 /* Private functions */
 
--- a/src/video/x11/SDL_x11render.c	Mon Jul 19 20:05:53 2010 +0530
+++ b/src/video/x11/SDL_x11render.c	Mon Jul 19 21:02:49 2010 +0530
@@ -176,11 +176,87 @@
                         texture->h, data->pixels, data->pitch);
 }
 
+#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
+static SDL_bool
+CheckXRender(Display *display, int *major, int *minor) {
+    const char *env;
+
+    *major = *minor = 0;
+
+    env = SDL_getenv("SDL_VIDEO_X11_XRENDER");
+
+    if (env && !SDL_atoi(env)) {
+        return SDL_FALSE;
+    }
+
+    if (!SDL_X11_HAVE_XRENDER) {
+        return SDL_FALSE;
+    }
+
+    if (!XRenderQueryVersion(display, major, minor)) {
+        return SDL_FALSE;
+    }
+
+    return SDL_TRUE;
+}
+#endif
+
+#ifdef SDL_VIDEO_DRIVER_X11_XFIXES
+static SDL_bool
+CheckXFixes(Display *display, int *major, int *minor) {
+    const char *env;
+
+    *major = *minor = 0;
+
+    env = SDL_getenv("SDL_VIDEO_X11_XFIXES");
+
+    if (env && !SDL_atoi(env)) {
+        return SDL_FALSE;
+    }
+
+    if (!SDL_X11_HAVE_XFIXES) {
+        return SDL_FALSE;
+    }
+
+    if (!XFixesQueryVersion(display, major, minor)) {
+        return SDL_FALSE;
+    }
+
+    return SDL_TRUE;
+}
+#endif
+
+#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
+static SDL_bool
+CheckXDamage(Display *display, int *major, int *minor) {
+    const char *env;
+
+    *major = *minor = 0;
+
+    env = SDL_getenv("SDL_VIDEO_X11_XDAMAGE");
+
+    if (env && !SDL_atoi(env)) {
+        return SDL_FALSE;
+    }
+
+    if (!SDL_X11_HAVE_XDAMAGE) {
+        return SDL_FALSE;
+    }
+
+    if (!XDamageQueryVersion(display, major, minor)) {
+        return SDL_FALSE;
+    }
+
+    return SDL_TRUE;
+}
+#endif
+
 void
 X11_AddRenderDriver(_THIS)
 {
     SDL_RendererInfo *info = &X11_RenderDriver.info;
     SDL_DisplayMode *mode = &SDL_CurrentDisplay->desktop_mode;
+    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     int i;
 
     info->texture_formats[info->num_texture_formats++] = mode->format;
@@ -189,7 +265,13 @@
     info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YUY2;
     info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_UYVY;
     info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YVYU;
-    info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_ARGB8888;
+
+#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
+    int major, minor;
+    if (CheckXRender(data->display, &major, &minor)) {
+        info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_ARGB8888;
+    }
+#endif
 
     for (i = 0; i < _this->num_displays; ++i) {
         SDL_AddRenderDriver(&_this->displays[i], &X11_RenderDriver);
@@ -255,36 +337,17 @@
     renderer->info.flags = SDL_RENDERER_ACCELERATED;
 
 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
-    data->use_xrender = SDL_FALSE;
-    data->use_xdamage = SDL_FALSE;
-    int event_basep, error_basep;
-    if (SDL_X11_HAVE_XRENDER) {
-        /* Query the extension. This is the server runtime check. */
-        if(XRenderQueryExtension(data->display,
-                                 &event_basep, &error_basep) == True)
-            data->use_xrender = SDL_TRUE;
+    int major, minor;
+    data->use_xrender = CheckXRender(data->display, &major, &minor);
+#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
+    if (CheckXDamage(data->display, &major, &minor)) {
+        if (CheckXFixes(data->display, &major, &minor)) {
+            if (major >= 2)
+                data->use_xdamage = SDL_TRUE;
+        }
     }
-#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
+#endif
     if (data->use_xrender) {
-        if(SDL_X11_HAVE_XDAMAGE && SDL_X11_HAVE_XFIXES) {
-        /* Query XDamage and XFixes */
-            if(XDamageQueryExtension(data->display,
-                                     &event_basep,
-                                     &error_basep) == True && 
-               (XFixesQueryExtension(data->display,
-                                        &event_basep,
-                                        &error_basep) == True)) {
-                    int major_version, minor_version;
-                    XFixesQueryVersion(data->display,
-                                       &major_version,
-                                       &minor_version);
-                    /* Only XFixes v 2 or greater
-                     * Required for XFixesSetPictureClipRegion() */
-                    if(major_version >= 2)
-                        data->use_xdamage = SDL_TRUE;
-            }
-        }
-#endif
         /* Find the PictFormat from the visual.
          * Should be an RGB PictFormat most of the time. */
         data->xwindow_pict_fmt = XRenderFindVisualFormat(data->display,
--- a/src/video/x11/SDL_x11sym.h	Mon Jul 19 20:05:53 2010 +0530
+++ b/src/video/x11/SDL_x11sym.h	Mon Jul 19 21:02:49 2010 +0530
@@ -240,6 +240,7 @@
 #if SDL_VIDEO_DRIVER_X11_XRENDER
 SDL_X11_MODULE(XRENDER)
 SDL_X11_SYM(Bool,XRenderQueryExtension,(Display *dpy,int *event_base,int *error_base),(dpy,event_base,error_base),return)
+SDL_X11_SYM(Bool,XRenderQueryVersion,(Display *dpy,int *major,int *minor),(dpy,major,minor),return)
 SDL_X11_SYM(XRenderPictFormat*,XRenderFindVisualFormat,(Display *dpy,_Xconst Visual *visual),(dpy,visual),return)
 SDL_X11_SYM(XRenderPictFormat*,XRenderFindStandardFormat,(Display *dpy,int format),(dpy,format),return)
 SDL_X11_SYM(XRenderPictFormat*,XRenderFindFormat,(Display *dpy,unsigned long mask,_Xconst XRenderPictFormat* templ,int count),(dpy,mask,templ,count),return)
@@ -256,6 +257,7 @@
 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
 SDL_X11_MODULE(XDAMAGE)
 SDL_X11_SYM(Bool,XDamageQueryExtension,(Display *dpy,int *event_base_return,int *error_base_return),(dpy,event_base_return,error_base_return),return)
+SDL_X11_SYM(Status,XDamageQueryVersion,(Display *dpy,int *major,int *minor),(dpy,major,minor),return)
 SDL_X11_SYM(Damage,XDamageCreate,(Display *dpy,Drawable d,int level),(dpy,d,level),return)
 SDL_X11_SYM(void,XDamageSubtract,(Display *dpy,Damage damage,XserverRegion repair,XserverRegion parts),(dpy,damage,repair,parts),return)
 SDL_X11_SYM(void,XDamageDestroy,(Display *dpy,Damage damage),(dpy,damage),return)
--- a/src/video/x11/SDL_x11video.h	Mon Jul 19 20:05:53 2010 +0530
+++ b/src/video/x11/SDL_x11video.h	Mon Jul 19 21:02:49 2010 +0530
@@ -48,6 +48,12 @@
 #if SDL_VIDEO_DRIVER_X11_XRENDER
 #include <X11/extensions/Xrender.h>
 #endif
+#if SDL_VIDEO_DRIVER_X11_XDAMAGE
+#include <X11/extensions/Xdamage.h>
+#endif
+#if SDL_VIDEO_DRIVER_X11_XFIXES
+#include <X11/extensions/Xfixes.h>
+#endif
 #include "SDL_x11dyn.h"
 
 #include "SDL_x11events.h"