Merged Sunny's XRender changes from SDL-gsoc2010_xrender
authorSam Lantinga <slouken@libsdl.org>
Wed, 28 Jul 2010 00:54:23 -0700
changeset 4618844b5ef4b149
parent 4569 e1664f94f026
parent 4617 cfbb1ff4b8ec
child 4619 b9a205e6369f
Merged Sunny's XRender changes from SDL-gsoc2010_xrender
configure.in
include/SDL_video.h
src/SDL_error.c
src/video/x11/SDL_x11modes.c
src/video/x11/SDL_x11render.c
src/video/x11/SDL_x11sym.h
src/video/x11/SDL_x11video.h
src/video/x11/SDL_x11window.c
     1.1 --- a/configure.in	Tue Jul 27 21:31:28 2010 -0700
     1.2 +++ b/configure.in	Wed Jul 28 00:54:23 2010 -0700
     1.3 @@ -1055,6 +1055,8 @@
     1.4                      xrandr_lib=[`find_lib "libXrandr.so.*" "$X_LIBS -L/usr/X11/$base_libdir -L/usr/X11R6/$base_libdir" | sed 's/.*\/\(.*\)/\1/; q'`]
     1.5                      xinput_lib=[`find_lib "libXi.so.*" "$X_LIBS -L/usr/X11/$base_libdir -L/usr/X11R6/$base_libdir" | sed 's/.*\/\(.*\)/\1/; q'`]
     1.6                      xss_lib=[`find_lib "libXss.so.*" "$X_LIBS -L/usr/X11/$base_libdir -L/usr/X11R6/$base_libdir" | sed 's/.*\/\(.*\)/\1/; q'`]
     1.7 +                    xdamage_lib=[`find_lib "libXdamage.so.*" "$X_LIBS -L/usr/X11/$base_libdir -L/usr/X11R6/$base_libdir" | sed 's/.*\/\(.*\)/\1/; q'`]
     1.8 +                    xfixes_lib=[`find_lib "libXfixes.so.*" "$X_LIBS -L/usr/X11/$base_libdir -L/usr/X11R6/$base_libdir" | sed 's/.*\/\(.*\)/\1/; q'`]
     1.9                      ;;
    1.10              esac
    1.11  
    1.12 @@ -1128,16 +1130,13 @@
    1.13                                  ])
    1.14                  if test x$have_xrandr_h_hdr = xyes; then
    1.15                      if test x$enable_x11_shared = xyes && test x$xrandr_lib != x ; then
    1.16 -                        echo "-- dynamic libXrender -> $xrender_lib"
    1.17                          echo "-- dynamic libXrandr -> $xrandr_lib"
    1.18 -                        AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER, "$xrender_lib")
    1.19                          AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR, "$xrandr_lib")
    1.20                          definitely_enable_video_x11_xrandr=yes
    1.21                      else
    1.22 -                        AC_CHECK_LIB(Xrender, XRenderQueryExtension, have_xrender_lib=yes)
    1.23                          AC_CHECK_LIB(Xrandr, XRRQueryExtension, have_xrandr_lib=yes)
    1.24 -                        if test x$have_xrender_lib = xyes && test x$have_xrandr_lib = xyes ; then
    1.25 -                            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lXrandr -lXrender"
    1.26 +                        if test x$have_xrandr_lib = xyes ; then
    1.27 +                            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lXrandr"
    1.28                              definitely_enable_video_x11_xrandr=yes
    1.29                          fi
    1.30                      fi
    1.31 @@ -1199,7 +1198,69 @@
    1.32              if test x$definitely_enable_video_x11_scrnsaver = xyes; then
    1.33                  AC_DEFINE(SDL_VIDEO_DRIVER_X11_SCRNSAVER)
    1.34              fi
    1.35 -
    1.36 +            AC_ARG_ENABLE(video-x11-xrender,
    1.37 +AC_HELP_STRING([--enable-video-x11-xrender], [enable X11 Xrender extension [[default=yes]]]),
    1.38 +                            , enable_video_x11_xrender=yes)
    1.39 +            if test x$enable_video_x11_xrender = xyes; then
    1.40 +                AC_CHECK_HEADER(X11/extensions/Xrender.h,
    1.41 +                                have_xrender_h_hdr=yes,
    1.42 +                                have_xrender_h_hdr=no,
    1.43 +                                [#include <X11/Xlib.h>
    1.44 +                                ])
    1.45 +                if test x$have_xrender_h_hdr = xyes; then
    1.46 +                    if test x$enable_x11_shared = xyes && test x$xrender_lib != x ; then
    1.47 +                        echo "-- dynamic libXrender -> $xrender_lib"
    1.48 +                        AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER, "$xrender_lib")
    1.49 +                        definitely_enable_video_x11_xrender=yes
    1.50 +                    else
    1.51 +                        AC_CHECK_LIB(Xrender, XRenderQueryExtension, have_xrender_lib=yes)
    1.52 +                        if test x$have_xrender_lib = xyes ; then
    1.53 +                            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lXrender"
    1.54 +                            definitely_enable_video_x11_xrender=yes
    1.55 +                        fi
    1.56 +                    fi
    1.57 +                fi
    1.58 +            fi
    1.59 +            if test x$definitely_enable_video_x11_xrender = xyes; then
    1.60 +                AC_DEFINE(SDL_VIDEO_DRIVER_X11_XRENDER)
    1.61 +            fi
    1.62 +            AC_ARG_ENABLE(video-x11-xdamage-xfixes,
    1.63 +AC_HELP_STRING([--enable-video-x11-xdamage-xfixes], [enable X11 Xdamage and Xfixes extensions [[default=yes]]]),
    1.64 +                            , enable_video_x11_xdamage=yes)
    1.65 +            if test x$enable_video_x11_xdamage = xyes && test x$definitely_enable_video_x11_xrender = xyes ; then
    1.66 +                AC_CHECK_HEADER(X11/extensions/Xdamage.h,
    1.67 +                                have_xdamage_h_hdr=yes,
    1.68 +                                have_xdamage_h_hdr=no,
    1.69 +                                [#include <X11/Xlib.h>
    1.70 +                                ])
    1.71 +                AC_CHECK_HEADER(X11/extensions/Xfixes.h,
    1.72 +                                have_xfixes_h_hdr=yes,
    1.73 +                                have_xfixes_h_hdr=no,
    1.74 +                                [#include <X11/Xlib.h>
    1.75 +                                ])
    1.76 +                if test x$have_xdamage_h_hdr = xyes && test x$have_xfixes_h_hdr = xyes ; then
    1.77 +                    if test x$enable_x11_shared = xyes && test x$xdamage_lib != x && test x$xfixes_lib != x ; then
    1.78 +                        echo "-- dynamic libXdamage -> $xdamage_lib"
    1.79 +                        echo "-- dynamic libXfixes -> $xfixes_lib"
    1.80 +                        AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_X11_DYNAMIC_XDAMAGE, "$xdamage_lib")
    1.81 +                        AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_X11_DYNAMIC_XFIXES, "$xfixes_lib")
    1.82 +                        definitely_enable_video_x11_xdamage=yes
    1.83 +                        definitely_enable_video_x11_xfixes=yes
    1.84 +                    else
    1.85 +                        AC_CHECK_LIB(Xdamage, XDamageQueryExtension, have_xdamage_lib=yes)
    1.86 +                        AC_CHECK_LIB(Xfixes, XFixesQueryExtension, have_xfixes_lib=yes)
    1.87 +                        if test x$have_xdamage_lib = xyes && test x$have_xfixes_lib = xyes ; then
    1.88 +                            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lXdamage -lXfixes"
    1.89 +                            definitely_enable_video_x11_xdamage=yes
    1.90 +                            definitely_enable_video_x11_xfixes=yes
    1.91 +                        fi
    1.92 +                    fi
    1.93 +                fi
    1.94 +            fi
    1.95 +            if test x$definitely_enable_video_x11_xdamage = xyes && test x$definitely_enable_video_x11_xfixes = xyes ; then
    1.96 +                AC_DEFINE(SDL_VIDEO_DRIVER_X11_XDAMAGE)
    1.97 +                AC_DEFINE(SDL_VIDEO_DRIVER_X11_XFIXES)
    1.98 +            fi
    1.99              AC_ARG_ENABLE(render-x11,
   1.100  AC_HELP_STRING([--enable-render-x11], [enable the X11 render driver [[default=yes]]]),
   1.101                                  , enable_render_x11=yes)
     2.1 --- a/include/SDL_config.h.in	Tue Jul 27 21:31:28 2010 -0700
     2.2 +++ b/include/SDL_config.h.in	Wed Jul 28 00:54:23 2010 -0700
     2.3 @@ -272,12 +272,19 @@
     2.4  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER
     2.5  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT
     2.6  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS
     2.7 +#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XDAMAGE
     2.8 +#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XFIXES
     2.9  #undef SDL_VIDEO_DRIVER_X11_VIDMODE
    2.10  #undef SDL_VIDEO_DRIVER_X11_XINERAMA
    2.11  #undef SDL_VIDEO_DRIVER_X11_XRANDR
    2.12  #undef SDL_VIDEO_DRIVER_X11_XINPUT
    2.13  #undef SDL_VIDEO_DRIVER_X11_SCRNSAVER
    2.14  #undef SDL_VIDEO_DRIVER_X11_XV
    2.15 +#undef SDL_VIDEO_DRIVER_X11_XRENDER
    2.16 +#undef SDL_VIDEO_DRIVER_X11_XDAMAGE
    2.17 +#undef SDL_VIDEO_DRIVER_X11_XFIXES
    2.18 +
    2.19 +#undef SDL_VIDEO_RENDER_X11
    2.20  
    2.21  #undef SDL_VIDEO_RENDER_D3D
    2.22  #undef SDL_VIDEO_RENDER_GDI
     3.1 --- a/include/SDL_video.h	Tue Jul 27 21:31:28 2010 -0700
     3.2 +++ b/include/SDL_video.h	Wed Jul 28 00:54:23 2010 -0700
     3.3 @@ -189,7 +189,7 @@
     3.4      Uint32 blend_modes;         /**< A mask of supported blend modes */
     3.5      Uint32 scale_modes;         /**< A mask of supported scale modes */
     3.6      Uint32 num_texture_formats; /**< The number of available texture formats */
     3.7 -    Uint32 texture_formats[20]; /**< The available texture formats */
     3.8 +    Uint32 texture_formats[50]; /**< The available texture formats */
     3.9      int max_texture_width;      /**< The maximimum texture width */
    3.10      int max_texture_height;     /**< The maximimum texture height */
    3.11  } SDL_RendererInfo;
     4.1 --- a/src/SDL_error.c	Tue Jul 27 21:31:28 2010 -0700
     4.2 +++ b/src/SDL_error.c	Wed Jul 28 00:54:23 2010 -0700
     4.3 @@ -26,6 +26,8 @@
     4.4  #include "SDL_error.h"
     4.5  #include "SDL_error_c.h"
     4.6  
     4.7 +/*#define DEBUG_ERROR*/
     4.8 +
     4.9  /* Routine to get the thread-specific error variable */
    4.10  #if SDL_THREADS_DISABLED
    4.11  /* !!! FIXME: what does this comment mean? Victim of Search and Replace? */
     5.1 --- a/src/video/x11/SDL_x11dyn.h	Tue Jul 27 21:31:28 2010 -0700
     5.2 +++ b/src/video/x11/SDL_x11dyn.h	Wed Jul 28 00:54:23 2010 -0700
     5.3 @@ -52,6 +52,18 @@
     5.4  #include <X11/extensions/XInput.h>
     5.5  #endif
     5.6  
     5.7 +#if SDL_VIDEO_DRIVER_X11_XRENDER
     5.8 +#include <X11/extensions/Xrender.h>
     5.9 +#endif
    5.10 +
    5.11 +#if SDL_VIDEO_DRIVER_X11_XDAMAGE
    5.12 +#include <X11/extensions/Xdamage.h>
    5.13 +#endif
    5.14 +
    5.15 +#if SDL_VIDEO_DRIVER_X11_XFIXES
    5.16 +#include <X11/extensions/Xfixes.h>
    5.17 +#endif
    5.18 +
    5.19  /*
    5.20   * When using the "dynamic X11" functionality, we duplicate all the Xlib
    5.21   *  symbols that would be referenced by SDL inside of SDL itself.
     6.1 --- a/src/video/x11/SDL_x11render.c	Tue Jul 27 21:31:28 2010 -0700
     6.2 +++ b/src/video/x11/SDL_x11render.c	Wed Jul 28 00:54:23 2010 -0700
     6.3 @@ -1,4 +1,5 @@
     6.4  /*
     6.5 +
     6.6      SDL - Simple DirectMedia Layer
     6.7      Copyright (C) 1997-2010 Sam Lantinga
     6.8  
     6.9 @@ -39,6 +40,8 @@
    6.10  static int X11_QueryTexturePixels(SDL_Renderer * renderer,
    6.11                                    SDL_Texture * texture, void **pixels,
    6.12                                    int *pitch);
    6.13 +static int X11_SetTextureRGBAMod(SDL_Renderer * renderer,
    6.14 +                                 SDL_Texture * texture);
    6.15  static int X11_SetTextureBlendMode(SDL_Renderer * renderer,
    6.16                                     SDL_Texture * texture);
    6.17  static int X11_SetTextureScaleMode(SDL_Renderer * renderer,
    6.18 @@ -96,6 +99,25 @@
    6.19      int scanline_pad;
    6.20      Window xwindow;
    6.21      Pixmap pixmaps[3];
    6.22 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
    6.23 +    Pixmap stencil;
    6.24 +    Pixmap brush;
    6.25 +    Picture brush_pict;
    6.26 +    Picture xwindow_pict;
    6.27 +    Picture pixmap_picts[3];
    6.28 +    Picture drawable_pict;
    6.29 +    Picture stencil_pict;
    6.30 +    int blend_op;
    6.31 +    XRenderPictFormat *xwindow_pict_fmt;
    6.32 +    XRenderPictFormat *drawable_pict_fmt;
    6.33 +    GC stencil_gc;
    6.34 +    SDL_bool use_xrender;
    6.35 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
    6.36 +    SDL_bool use_xdamage;
    6.37 +    Damage stencil_damage;
    6.38 +    XserverRegion stencil_parts;
    6.39 +#endif
    6.40 +#endif
    6.41      int current_pixmap;
    6.42      Drawable drawable;
    6.43      SDL_PixelFormat format;
    6.44 @@ -109,6 +131,17 @@
    6.45      SDL_SW_YUVTexture *yuv;
    6.46      Uint32 format;
    6.47      Pixmap pixmap;
    6.48 +    int depth;
    6.49 +    Visual *visual;
    6.50 +    GC gc;
    6.51 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
    6.52 +    Picture picture;
    6.53 +    Pixmap modulated_pixmap;
    6.54 +    Picture modulated_picture;
    6.55 +    XRenderPictFormat* picture_fmt;
    6.56 +    int blend_op;
    6.57 +    const char* filter;
    6.58 +#endif
    6.59      XImage *image;
    6.60  #ifndef NO_SHARED_MEMORY
    6.61      /* MIT shared memory extension information */
    6.62 @@ -149,11 +182,109 @@
    6.63                          texture->h, data->pixels, data->pitch);
    6.64  }
    6.65  
    6.66 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
    6.67 +static SDL_bool
    6.68 +CheckXRender(Display *display, int *major, int *minor) {
    6.69 +    const char *env;
    6.70 +
    6.71 +    *major = *minor = 0;
    6.72 +
    6.73 +    env = SDL_getenv("SDL_VIDEO_X11_XRENDER");
    6.74 +
    6.75 +    if (env && !SDL_atoi(env)) {
    6.76 +        return SDL_FALSE;
    6.77 +    }
    6.78 +
    6.79 +    if (!SDL_X11_HAVE_XRENDER) {
    6.80 +        return SDL_FALSE;
    6.81 +    }
    6.82 +
    6.83 +    if (!XRenderQueryVersion(display, major, minor)) {
    6.84 +        return SDL_FALSE;
    6.85 +    }
    6.86 +
    6.87 +    return SDL_TRUE;
    6.88 +}
    6.89 +#endif
    6.90 +
    6.91 +#ifdef SDL_VIDEO_DRIVER_X11_XFIXES
    6.92 +static SDL_bool
    6.93 +CheckXFixes(Display *display, int *major, int *minor) {
    6.94 +    const char *env;
    6.95 +
    6.96 +    *major = *minor = 0;
    6.97 +
    6.98 +    env = SDL_getenv("SDL_VIDEO_X11_XFIXES");
    6.99 +
   6.100 +    if (env && !SDL_atoi(env)) {
   6.101 +        return SDL_FALSE;
   6.102 +    }
   6.103 +
   6.104 +    if (!SDL_X11_HAVE_XFIXES) {
   6.105 +        return SDL_FALSE;
   6.106 +    }
   6.107 +
   6.108 +    if (!XFixesQueryVersion(display, major, minor)) {
   6.109 +        return SDL_FALSE;
   6.110 +    }
   6.111 +
   6.112 +    return SDL_TRUE;
   6.113 +}
   6.114 +#endif
   6.115 +
   6.116 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
   6.117 +static SDL_bool
   6.118 +CheckXDamage(Display *display, int *major, int *minor) {
   6.119 +    const char *env;
   6.120 +
   6.121 +    *major = *minor = 0;
   6.122 +
   6.123 +    env = SDL_getenv("SDL_VIDEO_X11_XDAMAGE");
   6.124 +
   6.125 +    if (env && !SDL_atoi(env)) {
   6.126 +        return SDL_FALSE;
   6.127 +    }
   6.128 +
   6.129 +    if (!SDL_X11_HAVE_XDAMAGE) {
   6.130 +        return SDL_FALSE;
   6.131 +    }
   6.132 +
   6.133 +    if (!XDamageQueryVersion(display, major, minor)) {
   6.134 +        return SDL_FALSE;
   6.135 +    }
   6.136 +
   6.137 +    return SDL_TRUE;
   6.138 +}
   6.139 +#endif
   6.140 +
   6.141 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   6.142 +static Uint32
   6.143 +XRenderPictFormatToSDLPixelFormatEnum(XRenderPictFormat *pict_format) {
   6.144 +    if (pict_format->type != PictTypeDirect) {
   6.145 +        SDL_SetError("Indexed pict formats not supported ATM");
   6.146 +        return 0;
   6.147 +    }
   6.148 +    Uint32 Amask, Rmask, Gmask, Bmask;
   6.149 +    int bpp;
   6.150 +
   6.151 +    Rmask = pict_format->direct.redMask << pict_format->direct.red;
   6.152 +    Gmask = pict_format->direct.greenMask << pict_format->direct.green;
   6.153 +    Bmask = pict_format->direct.blueMask << pict_format->direct.blue;
   6.154 +    Amask = pict_format->direct.alphaMask << pict_format->direct.alpha;
   6.155 +    bpp = pict_format->depth;
   6.156 +
   6.157 +    Uint32 format;
   6.158 +    format = SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
   6.159 +    return format;
   6.160 +}
   6.161 +#endif
   6.162 +
   6.163  void
   6.164  X11_AddRenderDriver(_THIS)
   6.165  {
   6.166      SDL_RendererInfo *info = &X11_RenderDriver.info;
   6.167      SDL_DisplayMode *mode = &SDL_CurrentDisplay->desktop_mode;
   6.168 +    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
   6.169      int i;
   6.170  
   6.171      info->texture_formats[info->num_texture_formats++] = mode->format;
   6.172 @@ -163,6 +294,34 @@
   6.173      info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_UYVY;
   6.174      info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YVYU;
   6.175  
   6.176 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   6.177 +    int major, minor;
   6.178 +    if (CheckXRender(data->display, &major, &minor)) {
   6.179 +        XRenderPictFormat templ;
   6.180 +        templ.type = PictTypeDirect;
   6.181 +        XRenderPictFormat *pict_format;
   6.182 +        Uint32 format;
   6.183 +        int i = 0;
   6.184 +        while (info->num_texture_formats < 50) {
   6.185 +            pict_format =
   6.186 +                XRenderFindFormat(data->display, PictFormatType, &templ, i++);
   6.187 +            if (pict_format) {
   6.188 +                format = XRenderPictFormatToSDLPixelFormatEnum(pict_format);
   6.189 +                if (format != SDL_PIXELTYPE_UNKNOWN) {
   6.190 +                    info->texture_formats[info->num_texture_formats++] = format;
   6.191 +                }
   6.192 +            }
   6.193 +            else
   6.194 +                break;
   6.195 +        }
   6.196 +        info->blend_modes |= (SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD |
   6.197 +                             SDL_BLENDMODE_MOD | SDL_BLENDMODE_MASK);
   6.198 +        info->scale_modes |= (SDL_TEXTURESCALEMODE_FAST | SDL_TEXTURESCALEMODE_SLOW |
   6.199 +                             SDL_TEXTURESCALEMODE_BEST);
   6.200 +        info->mod_modes |= (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA);
   6.201 +    }
   6.202 +#endif
   6.203 +
   6.204      for (i = 0; i < _this->num_displays; ++i) {
   6.205          SDL_AddRenderDriver(&_this->displays[i], &X11_RenderDriver);
   6.206      }
   6.207 @@ -177,6 +336,7 @@
   6.208      SDL_Renderer *renderer;
   6.209      X11_RenderData *data;
   6.210      XGCValues gcv;
   6.211 +    gcv.graphics_exposures = False;
   6.212      int i, n;
   6.213      int bpp;
   6.214      Uint32 Rmask, Gmask, Bmask, Amask;
   6.215 @@ -199,10 +359,12 @@
   6.216      data->depth = displaydata->depth;
   6.217      data->scanline_pad = displaydata->scanline_pad;
   6.218      data->xwindow = windowdata->xwindow;
   6.219 -
   6.220 +    
   6.221      renderer->DisplayModeChanged = X11_DisplayModeChanged;
   6.222      renderer->CreateTexture = X11_CreateTexture;
   6.223      renderer->QueryTexturePixels = X11_QueryTexturePixels;
   6.224 +    renderer->SetTextureAlphaMod = X11_SetTextureRGBAMod;
   6.225 +    renderer->SetTextureColorMod = X11_SetTextureRGBAMod;
   6.226      renderer->SetTextureBlendMode = X11_SetTextureBlendMode;
   6.227      renderer->SetTextureScaleMode = X11_SetTextureScaleMode;
   6.228      renderer->UpdateTexture = X11_UpdateTexture;
   6.229 @@ -225,6 +387,82 @@
   6.230  
   6.231      renderer->info.flags = SDL_RENDERER_ACCELERATED;
   6.232  
   6.233 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   6.234 +    int major, minor;
   6.235 +    data->use_xrender = CheckXRender(data->display, &major, &minor);
   6.236 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
   6.237 +    if (CheckXDamage(data->display, &major, &minor)) {
   6.238 +        if (CheckXFixes(data->display, &major, &minor)) {
   6.239 +            if (major >= 2)
   6.240 +                data->use_xdamage = SDL_TRUE;
   6.241 +        }
   6.242 +    }
   6.243 +#endif
   6.244 +    if (data->use_xrender) {
   6.245 +        /* Find the PictFormat from the visual.
   6.246 +         * Should be an RGB PictFormat most of the time. */
   6.247 +        data->xwindow_pict_fmt = XRenderFindVisualFormat(data->display,
   6.248 +                                                         data->visual);
   6.249 +        if (!data->xwindow_pict_fmt) {
   6.250 +            SDL_SetError("XRenderFindVisualFormat() failed");
   6.251 +            return NULL;
   6.252 +        }
   6.253 +        data->xwindow_pict = XRenderCreatePicture(data->display,
   6.254 +                                                  data->xwindow,
   6.255 +                                                  data->xwindow_pict_fmt,
   6.256 +                                                  0, NULL);
   6.257 +        if (!data->xwindow_pict) {
   6.258 +            SDL_SetError("XRenderCreatePicture() failed");
   6.259 +            return NULL;
   6.260 +        }
   6.261 +        // FIXME: Clear the window. Is this required?
   6.262 +        XRenderComposite(data->display,
   6.263 +                         PictOpClear,
   6.264 +                         data->xwindow_pict,
   6.265 +                         None,
   6.266 +                         data->xwindow_pict,
   6.267 +                         0, 0,
   6.268 +                         0, 0,
   6.269 +                         0, 0,
   6.270 +                         window->w, window->h);
   6.271 +        /* Create a clip mask that is used for rendering primitives. */
   6.272 +        data->stencil = XCreatePixmap(data->display, data->xwindow,
   6.273 +                                   window->w, window->h, 32);
   6.274 +        
   6.275 +        /* Create the GC for the clip mask. */
   6.276 +        data->stencil_gc = XCreateGC(data->display, data->stencil,
   6.277 +                                  GCGraphicsExposures, &gcv);
   6.278 +        XSetBackground(data->display, data->stencil_gc, 0);
   6.279 +        XSetForeground(data->display, data->stencil_gc, 0);
   6.280 +        XFillRectangle(data->display, data->stencil, data->stencil_gc,
   6.281 +                       0, 0, window->w, window->h);
   6.282 +        XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF);
   6.283 +        data->stencil_pict =
   6.284 +            XRenderCreatePicture(data->display, data->stencil,
   6.285 +                                 XRenderFindStandardFormat(data->display,
   6.286 +                                                           PictStandardARGB32),
   6.287 +                                 0, NULL);
   6.288 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
   6.289 +        if (data->use_xdamage) {
   6.290 +            data->stencil_damage =
   6.291 +                XDamageCreate(data->display, data->stencil, XDamageReportNonEmpty);
   6.292 +            XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts);
   6.293 +        }
   6.294 +#endif
   6.295 +        data->brush =
   6.296 +            XCreatePixmap(data->display, data->xwindow, 1, 1, 32);
   6.297 +        XRenderPictureAttributes brush_attr;
   6.298 +        brush_attr.repeat = RepeatNormal;
   6.299 +        data->brush_pict =
   6.300 +            XRenderCreatePicture(data->display, data->brush,
   6.301 +                                 XRenderFindStandardFormat(data->display,
   6.302 +                                                           PictStandardARGB32),
   6.303 +                                 CPRepeat, &brush_attr);
   6.304 +        // Set the default blending mode.
   6.305 +        renderer->blendMode = SDL_BLENDMODE_BLEND;
   6.306 +        data->blend_op = PictOpOver;
   6.307 +    }
   6.308 +#endif
   6.309      if (flags & SDL_RENDERER_SINGLEBUFFER) {
   6.310          renderer->info.flags |=
   6.311              (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY);
   6.312 @@ -239,39 +477,110 @@
   6.313          renderer->info.flags |= SDL_RENDERER_PRESENTCOPY;
   6.314          n = 1;
   6.315      }
   6.316 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   6.317 +    if (data->use_xrender) {
   6.318 +        if (n > 0)
   6.319 +            data->drawable_pict_fmt =
   6.320 +                XRenderFindStandardFormat(data->display, PictStandardARGB32);
   6.321 +        else
   6.322 +            data->drawable_pict_fmt = data->xwindow_pict_fmt;
   6.323 +    }
   6.324 +#endif
   6.325      for (i = 0; i < n; ++i) {
   6.326 -        data->pixmaps[i] =
   6.327 -            XCreatePixmap(data->display, data->xwindow, window->w, window->h,
   6.328 -                          displaydata->depth);
   6.329 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   6.330 +        if (data->use_xrender) {
   6.331 +            data->pixmaps[i] = XCreatePixmap(data->display,
   6.332 +                                             data->xwindow,
   6.333 +                                             window->w,
   6.334 +                                             window->h,
   6.335 +                                             32);
   6.336 +        }
   6.337 +        else
   6.338 +#endif
   6.339 +        {
   6.340 +            data->pixmaps[i] =
   6.341 +                XCreatePixmap(data->display, data->xwindow, window->w, window->h,
   6.342 +                              displaydata->depth);
   6.343 +        }
   6.344          if (data->pixmaps[i] == None) {
   6.345              X11_DestroyRenderer(renderer);
   6.346              SDL_SetError("XCreatePixmap() failed");
   6.347              return NULL;
   6.348          }
   6.349 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   6.350 +        if (data->use_xrender) {
   6.351 +            /* Create xrender pictures for each of the pixmaps
   6.352 +             * and clear the pixmaps. */
   6.353 +            data->pixmap_picts[i] = 
   6.354 +                XRenderCreatePicture(data->display,
   6.355 +                                     data->pixmaps[i],
   6.356 +                                     XRenderFindStandardFormat(data->display,
   6.357 +                                                               PictStandardARGB32),
   6.358 +                                     0, None);
   6.359 +            if (!data->pixmap_picts[i]) {
   6.360 +                SDL_SetError("XRenderCreatePicture() failed");
   6.361 +                return NULL;
   6.362 +            }
   6.363 +
   6.364 +            XRenderComposite(data->display,
   6.365 +                             PictOpClear,
   6.366 +                             data->pixmap_picts[i],
   6.367 +                             None,
   6.368 +                             data->pixmap_picts[i],
   6.369 +                             0, 0,
   6.370 +                             0, 0,
   6.371 +                             0, 0,
   6.372 +                             window->w, window->h);
   6.373 +        }
   6.374 +#endif
   6.375      }
   6.376      if (n > 0) {
   6.377          data->drawable = data->pixmaps[0];
   6.378 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   6.379 +        if(data->use_xrender == SDL_TRUE)
   6.380 +            data->drawable_pict = data->pixmap_picts[0];
   6.381 +#endif
   6.382          data->makedirty = SDL_TRUE;
   6.383      } else {
   6.384          data->drawable = data->xwindow;
   6.385 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   6.386 +        if(data->use_xrender == SDL_TRUE)
   6.387 +            data->drawable_pict = data->xwindow_pict;
   6.388 +#endif
   6.389          data->makedirty = SDL_FALSE;
   6.390      }
   6.391      data->current_pixmap = 0;
   6.392  
   6.393 -    /* Get the format of the window */
   6.394 -    if (!SDL_PixelFormatEnumToMasks
   6.395 -        (display->current_mode.format, &bpp, &Rmask, &Gmask, &Bmask,
   6.396 -         &Amask)) {
   6.397 -        SDL_SetError("Unknown display format");
   6.398 -        X11_DestroyRenderer(renderer);
   6.399 -        return NULL;
   6.400 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   6.401 +    if (data->use_xrender) {
   6.402 +        bpp = data->drawable_pict_fmt->depth;
   6.403 +        Rmask = ((data->drawable_pict_fmt->direct.redMask)
   6.404 +                    << (data->drawable_pict_fmt->direct.red));
   6.405 +        Gmask = ((data->drawable_pict_fmt->direct.greenMask)
   6.406 +                    << (data->drawable_pict_fmt->direct.green));
   6.407 +        Bmask = ((data->drawable_pict_fmt->direct.blueMask)
   6.408 +                    << (data->drawable_pict_fmt->direct.blue));
   6.409 +        Amask = ((data->drawable_pict_fmt->direct.alphaMask)
   6.410 +                    << (data->drawable_pict_fmt->direct.alpha));
   6.411 +    }
   6.412 +    else
   6.413 +#endif
   6.414 +    {
   6.415 +        /* Get the format of the window */
   6.416 +        if (!SDL_PixelFormatEnumToMasks
   6.417 +            (display->current_mode.format, &bpp, &Rmask, &Gmask, &Bmask,
   6.418 +             &Amask)) {
   6.419 +            SDL_SetError("Unknown display format");
   6.420 +            X11_DestroyRenderer(renderer);
   6.421 +            return NULL;
   6.422 +        }
   6.423      }
   6.424      SDL_InitFormat(&data->format, bpp, Rmask, Gmask, Bmask, Amask);
   6.425  
   6.426      /* Create the drawing context */
   6.427      gcv.graphics_exposures = False;
   6.428      data->gc =
   6.429 -        XCreateGC(data->display, data->xwindow, GCGraphicsExposures, &gcv);
   6.430 +        XCreateGC(data->display, data->drawable, GCGraphicsExposures, &gcv);
   6.431      if (!data->gc) {
   6.432          X11_DestroyRenderer(renderer);
   6.433          SDL_SetError("XCreateGC() failed");
   6.434 @@ -288,6 +597,47 @@
   6.435      SDL_Window *window = renderer->window;
   6.436      int i, n;
   6.437  
   6.438 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   6.439 +    if (data->use_xrender) {
   6.440 +        XRenderFreePicture(data->display, data->xwindow_pict);
   6.441 +        
   6.442 +        data->xwindow_pict_fmt =
   6.443 +            XRenderFindVisualFormat(data->display, data->visual);
   6.444 +        data->xwindow_pict =
   6.445 +            XRenderCreatePicture(data->display, data->xwindow,
   6.446 +                                 data->xwindow_pict_fmt, 0, NULL);
   6.447 +        
   6.448 +        XRenderComposite(data->display,
   6.449 +                         PictOpClear,
   6.450 +                         data->xwindow_pict,
   6.451 +                         None,
   6.452 +                         data->xwindow_pict,
   6.453 +                         0, 0,
   6.454 +                         0, 0,
   6.455 +                         0, 0,
   6.456 +                         window->w, window->h);
   6.457 +        
   6.458 +        XFreePixmap(data->display, data->stencil);
   6.459 +        /* Create a clip mask that is used for rendering primitives. */
   6.460 +        data->stencil = XCreatePixmap(data->display, data->xwindow,
   6.461 +                                   window->w, window->h, 32);
   6.462 +        
   6.463 +        XRenderFreePicture(data->display, data->stencil_pict);
   6.464 +        data->stencil_pict =
   6.465 +            XRenderCreatePicture(data->display, data->stencil,
   6.466 +                                 XRenderFindStandardFormat(data->display,
   6.467 +                                                           PictStandardARGB32),
   6.468 +                                 0, NULL);
   6.469 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
   6.470 +        XDamageDestroy(data->display, data->stencil_damage);
   6.471 +        if (data->use_xdamage) {
   6.472 +            data->stencil_damage =
   6.473 +                XDamageCreate(data->display, data->stencil, XDamageReportNonEmpty);
   6.474 +            XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts);
   6.475 +        }
   6.476 +#endif
   6.477 +    }
   6.478 +#endif
   6.479      if (renderer->info.flags & SDL_RENDERER_SINGLEBUFFER) {
   6.480          n = 0;
   6.481      } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
   6.482 @@ -301,25 +651,170 @@
   6.483          if (data->pixmaps[i] != None) {
   6.484              XFreePixmap(data->display, data->pixmaps[i]);
   6.485              data->pixmaps[i] = None;
   6.486 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   6.487 +            XRenderFreePicture(data->display, data->pixmap_picts[i]);
   6.488 +            data->pixmap_picts[i] = None;
   6.489 +#endif
   6.490          }
   6.491      }
   6.492      for (i = 0; i < n; ++i) {
   6.493 -        data->pixmaps[i] =
   6.494 -            XCreatePixmap(data->display, data->xwindow, window->w, window->h,
   6.495 -                          data->depth);
   6.496 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   6.497 +        if (data->use_xrender) {
   6.498 +            data->pixmaps[i] =
   6.499 +                XCreatePixmap(data->display,
   6.500 +                              data->xwindow,
   6.501 +                              window->w,
   6.502 +                              window->h,
   6.503 +                              32);
   6.504 +        }
   6.505 +        else
   6.506 +#endif
   6.507 +        {
   6.508 +            data->pixmaps[i] =
   6.509 +                XCreatePixmap(data->display, data->xwindow, window->w, window->h,
   6.510 +                              data->depth);
   6.511 +        }
   6.512          if (data->pixmaps[i] == None) {
   6.513              SDL_SetError("XCreatePixmap() failed");
   6.514              return -1;
   6.515          }
   6.516 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   6.517 +        if (data->use_xrender) {
   6.518 +            data->pixmap_picts[i] = 
   6.519 +                XRenderCreatePicture(data->display,
   6.520 +                                     data->pixmaps[i],
   6.521 +                                     XRenderFindStandardFormat(data->display,
   6.522 +                                                               PictStandardARGB32),
   6.523 +                                     0, None);
   6.524 +            if (!data->pixmap_picts[i]) {
   6.525 +                SDL_SetError("XRenderCreatePicture() failed");
   6.526 +                return -1;
   6.527 +            }
   6.528 +            XRenderComposite(data->display,
   6.529 +                             PictOpClear,
   6.530 +                             data->pixmap_picts[i],
   6.531 +                             None,
   6.532 +                             data->pixmap_picts[i],
   6.533 +                             0, 0,
   6.534 +                             0, 0,
   6.535 +                             0, 0,
   6.536 +                             window->w, window->h);
   6.537 +
   6.538 +       }
   6.539 +#endif
   6.540      }
   6.541      if (n > 0) {
   6.542          data->drawable = data->pixmaps[0];
   6.543 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   6.544 +        data->drawable_pict = data->pixmap_picts[0];
   6.545 +#endif
   6.546      }
   6.547      data->current_pixmap = 0;
   6.548  
   6.549      return 0;
   6.550  }
   6.551  
   6.552 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   6.553 +static void
   6.554 +SDLMaskToXRenderMask(Uint32 sdl_mask, short *comp, short *compMask) {
   6.555 +    if (sdl_mask == 0) {
   6.556 +        *comp = 0;
   6.557 +        *compMask = 0;
   6.558 +    } else {
   6.559 +        (*comp) = 0;
   6.560 +        (*compMask) = 0;
   6.561 +        while(!(sdl_mask & 1)) {
   6.562 +            (*comp)++;
   6.563 +            sdl_mask >>= 1;
   6.564 +        }
   6.565 +        while(sdl_mask & 1) {
   6.566 +            (*compMask) = ((*compMask) << 1) | 1;
   6.567 +            sdl_mask >>= 1;
   6.568 +        }
   6.569 +    }
   6.570 +}
   6.571 +
   6.572 +static XRenderPictFormat*
   6.573 +PixelFormatEnumToXRenderPictFormat(SDL_Renderer * renderer, Uint32 format) {
   6.574 +    XRenderPictFormat* pict_fmt = NULL;
   6.575 +    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
   6.576 +    
   6.577 +    if (data->use_xrender) {
   6.578 +
   6.579 +        int bpp;
   6.580 +        Uint32 Amask, Rmask, Gmask, Bmask;
   6.581 +        if(!SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
   6.582 +            SDL_SetError("Unknown pixel format");
   6.583 +            return NULL;
   6.584 +        }
   6.585 +        XRenderPictFormat templ;
   6.586 +        unsigned long mask = (PictFormatType | PictFormatDepth | PictFormatRed |
   6.587 +                              PictFormatRedMask | PictFormatGreen | PictFormatGreenMask |
   6.588 +                              PictFormatBlue | PictFormatBlueMask | PictFormatAlpha |
   6.589 +                              PictFormatAlphaMask);
   6.590 +
   6.591 +        templ.type = PictTypeDirect;
   6.592 +        templ.depth = bpp;
   6.593 +        SDLMaskToXRenderMask(Amask, &(templ.direct.alpha), &(templ.direct.alphaMask));
   6.594 +        SDLMaskToXRenderMask(Rmask, &(templ.direct.red), &(templ.direct.redMask));
   6.595 +        SDLMaskToXRenderMask(Gmask, &(templ.direct.green), &(templ.direct.greenMask));
   6.596 +        SDLMaskToXRenderMask(Bmask, &(templ.direct.blue), &(templ.direct.blueMask));
   6.597 +        pict_fmt = XRenderFindFormat(data->display, mask, &templ, 0);
   6.598 +    }
   6.599 +    
   6.600 +    return pict_fmt;
   6.601 +}
   6.602 +
   6.603 +
   6.604 +static Visual*
   6.605 +PixelFormatEnumToVisual(SDL_Renderer * renderer, Uint32 format) {
   6.606 +    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
   6.607 +
   6.608 +    if (data->use_xrender) {
   6.609 +        int bpp;
   6.610 +        Uint32 Amask, Rmask, Gmask, Bmask;
   6.611 +        SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
   6.612 +
   6.613 +        XVisualInfo vinfo_templ;
   6.614 +        long vinfo_mask;
   6.615 +        int nitems_return;
   6.616 +
   6.617 +        vinfo_mask = (VisualDepthMask | VisualRedMaskMask |
   6.618 +                      VisualGreenMaskMask | VisualBlueMaskMask);
   6.619 +        vinfo_templ.depth = bpp;
   6.620 +        vinfo_templ.red_mask = Rmask;
   6.621 +        vinfo_templ.green_mask = Gmask;
   6.622 +        vinfo_templ.blue_mask = Bmask;
   6.623 +
   6.624 +        XVisualInfo * ret = XGetVisualInfo(data->display, vinfo_mask,
   6.625 +                                           &vinfo_templ, &nitems_return);
   6.626 +        
   6.627 +        if (nitems_return) {
   6.628 +            return ret[0].visual;
   6.629 +        }
   6.630 +    }
   6.631 +
   6.632 +    return NULL;
   6.633 +}
   6.634 +
   6.635 +static XRenderColor
   6.636 +SDLColorToXRenderColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
   6.637 +    double rd, gd, bd, ad;
   6.638 +    XRenderColor ret;
   6.639 +    rd = r / 255.0;
   6.640 +    gd = g / 255.0;
   6.641 +    bd = b / 255.0;
   6.642 +    ad = a / 255.0;
   6.643 +    
   6.644 +    ret.red = (unsigned short) (rd * ad * 0xFFFF);
   6.645 +    ret.green = (unsigned short) (gd * ad * 0xFFFF);
   6.646 +    ret.blue = (unsigned short) (bd * ad * 0xFFFF);
   6.647 +    ret.alpha = (unsigned short) (ad * 0xFFFF);
   6.648 +
   6.649 +    return ret;
   6.650 +}
   6.651 +#endif
   6.652 +
   6.653  static int
   6.654  X11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   6.655  {
   6.656 @@ -328,15 +823,18 @@
   6.657      SDL_VideoDisplay *display = window->display;
   6.658      X11_TextureData *data;
   6.659      int pitch_alignmask = ((renderdata->scanline_pad / 8) - 1);
   6.660 -
   6.661 +    XGCValues gcv;
   6.662 +    
   6.663      data = (X11_TextureData *) SDL_calloc(1, sizeof(*data));
   6.664      if (!data) {
   6.665          SDL_OutOfMemory();
   6.666          return -1;
   6.667      }
   6.668 +    data->depth = renderdata->depth;
   6.669 +    data->visual = renderdata->visual;
   6.670 +    data->gc = renderdata->gc;
   6.671  
   6.672      texture->driverdata = data;
   6.673 -
   6.674      if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   6.675          data->yuv =
   6.676              SDL_SW_CreateYUVTexture(texture->format, texture->w, texture->h);
   6.677 @@ -345,18 +843,26 @@
   6.678          }
   6.679          data->format = display->current_mode.format;
   6.680      } else {
   6.681 -        /* The image/pixmap depth must be the same as the window or you
   6.682 -           get a BadMatch error when trying to putimage or copyarea.
   6.683 -         */
   6.684 -        if (texture->format != display->current_mode.format) {
   6.685 -            SDL_SetError("Texture format doesn't match window format");
   6.686 -            return -1;
   6.687 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   6.688 +        if (renderdata->use_xrender)
   6.689 +        {
   6.690 +            Uint32 Amask, Rmask, Gmask, Bmask;
   6.691 +            SDL_PixelFormatEnumToMasks(texture->format, &(data->depth),
   6.692 +                                       &Rmask, &Gmask, &Bmask, &Amask);
   6.693 +            data->visual = PixelFormatEnumToVisual(renderer, texture->format);
   6.694 +        }
   6.695 +        else
   6.696 +#endif
   6.697 +        {
   6.698 +            if (texture->format != display->current_mode.format)
   6.699 +            {
   6.700 +                SDL_SetError("Texture format doesn't match window format");
   6.701 +                return -1;
   6.702 +            }
   6.703          }
   6.704          data->format = texture->format;
   6.705      }
   6.706 -    data->pitch = texture->w * SDL_BYTESPERPIXEL(data->format);
   6.707 -    data->pitch = (data->pitch + pitch_alignmask) & ~pitch_alignmask;
   6.708 -
   6.709 +    
   6.710      if (data->yuv || texture->access == SDL_TEXTUREACCESS_STREAMING) {
   6.711  #ifndef NO_SHARED_MEMORY
   6.712          XShmSegmentInfo *shminfo = &data->shminfo;
   6.713 @@ -364,37 +870,42 @@
   6.714          shm_error = True;
   6.715  
   6.716          if (SDL_X11_HAVE_SHM) {
   6.717 -            shminfo->shmid =
   6.718 -                shmget(IPC_PRIVATE, texture->h * data->pitch,
   6.719 -                       IPC_CREAT | 0777);
   6.720 -            if (shminfo->shmid >= 0) {
   6.721 -                shminfo->shmaddr = (char *) shmat(shminfo->shmid, 0, 0);
   6.722 -                shminfo->readOnly = False;
   6.723 -                if (shminfo->shmaddr != (char *) -1) {
   6.724 -                    shm_error = False;
   6.725 -                    X_handler = XSetErrorHandler(shm_errhandler);
   6.726 -                    XShmAttach(renderdata->display, shminfo);
   6.727 -                    XSync(renderdata->display, False);
   6.728 -                    XSetErrorHandler(X_handler);
   6.729 -                    if (shm_error) {
   6.730 -                        shmdt(shminfo->shmaddr);
   6.731 +            data->image =
   6.732 +                XShmCreateImage(renderdata->display, data->visual,
   6.733 +                                data->depth, ZPixmap, NULL,
   6.734 +                                shminfo, texture->w, texture->h);
   6.735 +            if (data->image) {
   6.736 +                shminfo->shmid =
   6.737 +                    shmget(IPC_PRIVATE, texture->h * data->image->bytes_per_line,
   6.738 +                           IPC_CREAT | 0777);
   6.739 +                if (shminfo->shmid >= 0) {
   6.740 +                    shminfo->shmaddr = (char *) shmat(shminfo->shmid, 0, 0);
   6.741 +                    shminfo->readOnly = False;
   6.742 +                    if (shminfo->shmaddr != (char *) -1) {
   6.743 +                        shm_error = False;
   6.744 +                        X_handler = XSetErrorHandler(shm_errhandler);
   6.745 +                        XShmAttach(renderdata->display, shminfo);
   6.746 +                        XSync(renderdata->display, False);
   6.747 +                        XSetErrorHandler(X_handler);
   6.748 +                        if (shm_error) {
   6.749 +                            XShmDetach(renderdata->display, shminfo);
   6.750 +                            shmdt(shminfo->shmaddr);
   6.751 +                            XDestroyImage(data->image);
   6.752 +                            XSync(renderdata->display, False);
   6.753 +                        }
   6.754 +                        else {
   6.755 +                            data->pixels = data->image->data = shminfo->shmaddr;
   6.756 +                            shmctl(shminfo->shmid, IPC_RMID, NULL);
   6.757 +                            data->pixmap =
   6.758 +                                XCreatePixmap(renderdata->display, renderdata->xwindow,
   6.759 +                                              texture->w, texture->h, data->depth);
   6.760 +                            if (!data->pixmap) {
   6.761 +                                SDL_SetError("XCreatePixmap() failed");
   6.762 +                                return -1;
   6.763 +                            }
   6.764 +                        }
   6.765                      }
   6.766                  }
   6.767 -                shmctl(shminfo->shmid, IPC_RMID, NULL);
   6.768 -            }
   6.769 -        }
   6.770 -        if (!shm_error) {
   6.771 -            data->pixels = shminfo->shmaddr;
   6.772 -
   6.773 -            data->image =
   6.774 -                XShmCreateImage(renderdata->display, renderdata->visual,
   6.775 -                                renderdata->depth, ZPixmap, shminfo->shmaddr,
   6.776 -                                shminfo, texture->w, texture->h);
   6.777 -            if (!data->image) {
   6.778 -                XShmDetach(renderdata->display, shminfo);
   6.779 -                XSync(renderdata->display, False);
   6.780 -                shmdt(shminfo->shmaddr);
   6.781 -                shm_error = True;
   6.782              }
   6.783          }
   6.784          if (shm_error) {
   6.785 @@ -403,47 +914,102 @@
   6.786          if (!data->image)
   6.787  #endif /* not NO_SHARED_MEMORY */
   6.788          {
   6.789 -            data->pixels = SDL_malloc(texture->h * data->pitch);
   6.790 +            data->image =
   6.791 +                XCreateImage(renderdata->display, data->visual,
   6.792 +                             data->depth, ZPixmap, 0, NULL,
   6.793 +                             texture->w, texture->h,
   6.794 +                             SDL_BYTESPERPIXEL(data->format) * 8,
   6.795 +                             0);
   6.796 +            if (!data->image) {
   6.797 +                X11_DestroyTexture(renderer, texture);
   6.798 +                SDL_SetError("XCreateImage() failed");
   6.799 +                return -1;
   6.800 +            }
   6.801 +            data->pixels = SDL_malloc(texture->h * data->image->bytes_per_line);
   6.802              if (!data->pixels) {
   6.803                  X11_DestroyTexture(renderer, texture);
   6.804                  SDL_OutOfMemory();
   6.805                  return -1;
   6.806              }
   6.807 -
   6.808 -            data->image =
   6.809 -                XCreateImage(renderdata->display, renderdata->visual,
   6.810 -                             renderdata->depth, ZPixmap, 0, data->pixels,
   6.811 -                             texture->w, texture->h,
   6.812 -                             SDL_BYTESPERPIXEL(data->format) * 8,
   6.813 -                             data->pitch);
   6.814 -            if (!data->image) {
   6.815 +            data->image->data = data->pixels;
   6.816 +            data->pixmap =
   6.817 +                XCreatePixmap(renderdata->display, renderdata->xwindow, texture->w,
   6.818 +                              texture->h, data->depth);
   6.819 +            if (data->pixmap == None) {
   6.820                  X11_DestroyTexture(renderer, texture);
   6.821 -                SDL_SetError("XCreateImage() failed");
   6.822 +                SDL_SetError("XCreatePixmap() failed");
   6.823                  return -1;
   6.824              }
   6.825          }
   6.826 -    } else {
   6.827 +    } 
   6.828 +    else {
   6.829 +        data->image =
   6.830 +            XCreateImage(renderdata->display, data->visual,
   6.831 +                         data->depth, ZPixmap, 0, NULL,
   6.832 +                         texture->w, texture->h,
   6.833 +                         SDL_BYTESPERPIXEL(data->format) * 8,
   6.834 +                         0);
   6.835 +        if (!data->image) {
   6.836 +            X11_DestroyTexture(renderer, texture);
   6.837 +            SDL_SetError("XCreateImage() failed");
   6.838 +            return -1;
   6.839 +        }
   6.840          data->pixmap =
   6.841              XCreatePixmap(renderdata->display, renderdata->xwindow, texture->w,
   6.842 -                          texture->h, renderdata->depth);
   6.843 +                          texture->h, data->depth);
   6.844          if (data->pixmap == None) {
   6.845              X11_DestroyTexture(renderer, texture);
   6.846              SDL_SetError("XCreatePixmap() failed");
   6.847              return -1;
   6.848          }
   6.849 +    }
   6.850  
   6.851 -        data->image =
   6.852 -            XCreateImage(renderdata->display, renderdata->visual,
   6.853 -                         renderdata->depth, ZPixmap, 0, NULL, texture->w,
   6.854 -                         texture->h, SDL_BYTESPERPIXEL(data->format) * 8,
   6.855 -                         data->pitch);
   6.856 -        if (!data->image) {
   6.857 -            X11_DestroyTexture(renderer, texture);
   6.858 -            SDL_SetError("XCreateImage() failed");
   6.859 +    data->pitch = data->image->bytes_per_line;
   6.860 +
   6.861 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   6.862 +    if(renderdata->use_xrender) {
   6.863 +        gcv.graphics_exposures = False;
   6.864 +        data->gc =
   6.865 +            XCreateGC(renderdata->display, data->pixmap, GCGraphicsExposures, &gcv);
   6.866 +        if (!data->gc) {
   6.867 +            SDL_SetError("XCreateGC() failed");
   6.868              return -1;
   6.869          }
   6.870 +        data->picture_fmt =
   6.871 +            PixelFormatEnumToXRenderPictFormat(renderer, texture->format);
   6.872 +        if (data->picture_fmt == NULL) {
   6.873 +            X11_DestroyTexture(renderer, texture);
   6.874 +            SDL_SetError("Texture format not supported by driver");
   6.875 +            return -1;
   6.876 +        }
   6.877 +        data->picture =
   6.878 +            XRenderCreatePicture(renderdata->display, data->pixmap,
   6.879 +                                 data->picture_fmt, 0, NULL);
   6.880 +        if (!data->picture) {
   6.881 +            X11_DestroyTexture(renderer, texture);
   6.882 +            SDL_SetError("XRenderCreatePicture() failed");
   6.883 +            return -1;
   6.884 +        }
   6.885 +        data->modulated_pixmap =
   6.886 +            XCreatePixmap(renderdata->display, renderdata->xwindow,
   6.887 +                          texture->w, texture->h, data->depth);
   6.888 +        if (!data->modulated_pixmap) {
   6.889 +            X11_DestroyTexture(renderer, texture);
   6.890 +            SDL_SetError("XCreatePixmap() failed");
   6.891 +            return -1;
   6.892 +        }
   6.893 +        data->modulated_picture =
   6.894 +            XRenderCreatePicture(renderdata->display, data->modulated_pixmap,
   6.895 +                                 data->picture_fmt, 0, NULL);
   6.896 +        if (!data->modulated_picture) {
   6.897 +            X11_DestroyTexture(renderer, texture);
   6.898 +            SDL_SetError("XRenderCreatePicture() failed");
   6.899 +            return -1;
   6.900 +        }
   6.901 +        texture->blendMode = SDL_BLENDMODE_NONE;
   6.902 +        data->blend_op = PictOpSrc;
   6.903      }
   6.904 -
   6.905 +#endif
   6.906      return 0;
   6.907  }
   6.908  
   6.909 @@ -463,14 +1029,106 @@
   6.910  }
   6.911  
   6.912  static int
   6.913 +X11_SetTextureRGBAMod(SDL_Renderer * renderer, SDL_Texture * texture)
   6.914 +{
   6.915 +
   6.916 +    X11_TextureData *data = (X11_TextureData *) texture->driverdata;
   6.917 +    X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
   6.918 +
   6.919 +    if (renderdata->use_xrender) {
   6.920 +
   6.921 +        Uint8 r = 0xFF, g = 0xFF, b = 0xFF, a = 0xFF;
   6.922 +
   6.923 +        /* Check if alpha modulation is required. */
   6.924 +        if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) {
   6.925 +            a = texture->a;
   6.926 +        }
   6.927 +
   6.928 +        /* Check if color modulation is required. */
   6.929 +        if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
   6.930 +            r = texture->r;
   6.931 +            g = texture->g;
   6.932 +            b = texture->b;
   6.933 +        }
   6.934 +
   6.935 +        /* We can save some labour if no modulation is required. */
   6.936 +        if (texture->modMode != SDL_TEXTUREMODULATE_NONE) {
   6.937 +            XRenderColor mod_color =
   6.938 +                SDLColorToXRenderColor(r, g, b, a);
   6.939 +            XRenderFillRectangle(renderdata->display, PictOpSrc,
   6.940 +                                 renderdata->brush_pict, &mod_color,
   6.941 +                                 0, 0, 1, 1);
   6.942 +        }
   6.943 +
   6.944 +        /* We can save some labour dealing with component alpha
   6.945 +         * if color modulation is not required. */
   6.946 +        XRenderPictureAttributes attr;
   6.947 +        if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
   6.948 +            attr.component_alpha = True;
   6.949 +            XRenderChangePicture(renderdata->display, renderdata->brush_pict,
   6.950 +                                 CPComponentAlpha, &attr);
   6.951 +        }
   6.952 +
   6.953 +        /* Again none of this is necessary is no modulation
   6.954 +         * is required. */
   6.955 +        if (texture->modMode != SDL_TEXTUREMODULATE_NONE) {
   6.956 +            XRenderComposite(renderdata->display, PictOpSrc,
   6.957 +                             data->picture, renderdata->brush_pict,
   6.958 +                             data->modulated_picture,
   6.959 +                             0, 0, 0, 0, 0, 0, texture->w, texture->h);
   6.960 +        }
   6.961 +
   6.962 +        /* We only need to reset the component alpha
   6.963 +         * attribute if color modulation is required. */
   6.964 +        if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) { 
   6.965 +            attr.component_alpha = False;
   6.966 +            XRenderChangePicture(renderdata->display, renderdata->brush_pict,
   6.967 +                                 CPComponentAlpha, &attr);
   6.968 +        }
   6.969 +
   6.970 +        return 0;
   6.971 +    }
   6.972 +    else {
   6.973 +        SDL_Unsupported();
   6.974 +        return -1;
   6.975 +    }
   6.976 +}
   6.977 +
   6.978 +static int
   6.979  X11_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
   6.980  {
   6.981 +    X11_TextureData *data = (X11_TextureData *) texture->driverdata;
   6.982 +    X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
   6.983      switch (texture->blendMode) {
   6.984      case SDL_BLENDMODE_NONE:
   6.985 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   6.986 +        if (renderdata->use_xrender) {
   6.987 +            data->blend_op = PictOpSrc;
   6.988 +            return 0;
   6.989 +        }
   6.990 +    case SDL_BLENDMODE_MOD:
   6.991 +    case SDL_BLENDMODE_MASK:
   6.992 +    case SDL_BLENDMODE_BLEND:
   6.993 +        if (renderdata->use_xrender) {
   6.994 +            data->blend_op = PictOpOver;
   6.995 +            return 0;
   6.996 +        }
   6.997 +    case SDL_BLENDMODE_ADD:
   6.998 +        if (renderdata->use_xrender) {
   6.999 +            data->blend_op = PictOpAdd;
  6.1000 +            return 0;
  6.1001 +        }
  6.1002 +#endif
  6.1003          return 0;
  6.1004      default:
  6.1005          SDL_Unsupported();
  6.1006          texture->blendMode = SDL_BLENDMODE_NONE;
  6.1007 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  6.1008 +        if (renderdata->use_xrender) {
  6.1009 +            texture->blendMode = SDL_BLENDMODE_BLEND;
  6.1010 +            data->blend_op = PictOpOver;
  6.1011 +        }
  6.1012 +#endif
  6.1013          return -1;
  6.1014      }
  6.1015  }
  6.1016 @@ -479,6 +1137,7 @@
  6.1017  X11_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
  6.1018  {
  6.1019      X11_TextureData *data = (X11_TextureData *) texture->driverdata;
  6.1020 +    X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
  6.1021  
  6.1022      switch (texture->scaleMode) {
  6.1023      case SDL_TEXTURESCALEMODE_NONE:
  6.1024 @@ -488,10 +1147,33 @@
  6.1025          if (data->yuv || texture->access == SDL_TEXTUREACCESS_STREAMING) {
  6.1026              return 0;
  6.1027          }
  6.1028 -        /* Fall through to unsupported case */
  6.1029 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  6.1030 +        if (renderdata->use_xrender) {
  6.1031 +            data->filter = FilterFast;
  6.1032 +            return 0;
  6.1033 +        }
  6.1034 +    case SDL_TEXTURESCALEMODE_SLOW:
  6.1035 +        if (renderdata->use_xrender) {
  6.1036 +            data->filter = FilterGood;
  6.1037 +            return 0;
  6.1038 +        }
  6.1039 +    case SDL_TEXTURESCALEMODE_BEST:
  6.1040 +        if (renderdata->use_xrender) {
  6.1041 +            data->filter = FilterBest;
  6.1042 +            return 0;
  6.1043 +        }
  6.1044 +#endif
  6.1045 +    /* Fall through to unsupported case */
  6.1046      default:
  6.1047          SDL_Unsupported();
  6.1048 -        texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
  6.1049 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  6.1050 +        if (renderdata->use_xrender) {
  6.1051 +            texture->scaleMode = SDL_TEXTURESCALEMODE_FAST;
  6.1052 +            data->filter = FilterFast;
  6.1053 +        }
  6.1054 +        else
  6.1055 +#endif
  6.1056 +            texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
  6.1057          return -1;
  6.1058      }
  6.1059      return 0;
  6.1060 @@ -532,7 +1214,7 @@
  6.1061              data->image->height = rect->h;
  6.1062              data->image->data = (char *) pixels;
  6.1063              data->image->bytes_per_line = pitch;
  6.1064 -            XPutImage(renderdata->display, data->pixmap, renderdata->gc,
  6.1065 +            XPutImage(renderdata->display, data->pixmap, data->gc,
  6.1066                        data->image, 0, 0, rect->x, rect->y, rect->w, rect->h);
  6.1067          }
  6.1068          return 0;
  6.1069 @@ -575,12 +1257,36 @@
  6.1070  static int
  6.1071  X11_SetDrawBlendMode(SDL_Renderer * renderer)
  6.1072  {
  6.1073 +    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
  6.1074      switch (renderer->blendMode) {
  6.1075      case SDL_BLENDMODE_NONE:
  6.1076 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  6.1077 +        //PictOpSrc
  6.1078 +        data->blend_op = PictOpSrc;
  6.1079 +        return 0;
  6.1080 +    case SDL_BLENDMODE_MOD:
  6.1081 +    case SDL_BLENDMODE_MASK:
  6.1082 +    case SDL_BLENDMODE_BLEND: // PictOpOver
  6.1083 +        data->blend_op = PictOpOver;
  6.1084 +        return 0;
  6.1085 +    case SDL_BLENDMODE_ADD: // PictOpAdd
  6.1086 +        data->blend_op = PictOpAdd;
  6.1087 +        return 0;
  6.1088 +    /* FIXME case SDL_BLENDMODE_MOD: */
  6.1089 +#endif
  6.1090          return 0;
  6.1091      default:
  6.1092          SDL_Unsupported();
  6.1093 -        renderer->blendMode = SDL_BLENDMODE_NONE;
  6.1094 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  6.1095 +        if(data->use_xrender) {
  6.1096 +            renderer->blendMode = SDL_BLENDMODE_BLEND;
  6.1097 +            data->blend_op = PictOpOver;
  6.1098 +        }
  6.1099 +        else
  6.1100 +#endif
  6.1101 +        {
  6.1102 +            renderer->blendMode = SDL_BLENDMODE_NONE;
  6.1103 +        }
  6.1104          return -1;
  6.1105      }
  6.1106  }
  6.1107 @@ -601,16 +1307,35 @@
  6.1108          return SDL_MapRGBA(&data->format, r, g, b, a);
  6.1109  }
  6.1110  
  6.1111 +static XRenderColor
  6.1112 +xrenderdrawcolor(SDL_Renderer *renderer)
  6.1113 +{
  6.1114 +    XRenderColor xrender_color;
  6.1115 +    if(renderer->blendMode == SDL_BLENDMODE_NONE) {
  6.1116 +        xrender_color =
  6.1117 +            SDLColorToXRenderColor(renderer->r, renderer->g, renderer->b, 0xFF);
  6.1118 +    }
  6.1119 +    else {
  6.1120 +        xrender_color =
  6.1121 +            SDLColorToXRenderColor(renderer->r, renderer->g, renderer->b, renderer->a);
  6.1122 +    }
  6.1123 +    return xrender_color;
  6.1124 +}
  6.1125 +
  6.1126  static int
  6.1127  X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
  6.1128                       int count)
  6.1129  {
  6.1130      X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
  6.1131      SDL_Window *window = renderer->window;
  6.1132 -    unsigned long foreground;
  6.1133      XPoint *xpoints, *xpoint;
  6.1134      int i, xcount;
  6.1135 +    SDL_Rect clip;
  6.1136  
  6.1137 +    clip.x = 0;
  6.1138 +    clip.y = 0;
  6.1139 +    clip.w = window->w;
  6.1140 +    clip.h = window->h;
  6.1141      if (data->makedirty) {
  6.1142          SDL_Rect rect;
  6.1143  
  6.1144 @@ -625,27 +1350,105 @@
  6.1145          }
  6.1146          SDL_AddDirtyRect(&data->dirty, &rect);
  6.1147      }
  6.1148 +    {
  6.1149 +        xpoint = xpoints = SDL_stack_alloc(XPoint, count);
  6.1150 +        xcount = 0;
  6.1151 +        for (i = 0; i < count; ++i) {
  6.1152 +            int x = points[i].x;
  6.1153 +            int y = points[i].y;
  6.1154 +            if (x < 0 || x >= window->w || y < 0 || y >= window->h) {
  6.1155 +                continue;
  6.1156 +            }
  6.1157 +            xpoint->x = (short)x;
  6.1158 +            xpoint->y = (short)y;
  6.1159 +            ++xpoint;
  6.1160 +            ++xcount;
  6.1161 +        }
  6.1162  
  6.1163 -    foreground = renderdrawcolor(renderer, 1);
  6.1164 -    XSetForeground(data->display, data->gc, foreground);
  6.1165 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  6.1166 +        if (data->use_xrender &&
  6.1167 +            (renderer->blendMode != SDL_BLENDMODE_NONE) &&
  6.1168 +            !(renderer->a == 0xFF &&
  6.1169 +              renderer->blendMode != SDL_BLENDMODE_ADD &&
  6.1170 +              renderer->blendMode != SDL_BLENDMODE_MOD))
  6.1171 +        {
  6.1172 +            XSetForeground(data->display, data->stencil_gc, 0);
  6.1173 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  6.1174 +            if (data->use_xdamage)
  6.1175 +            {
  6.1176 +                /* Update only those parts which were changed
  6.1177 +                * in the previous drawing operation */
  6.1178 +                XFixesSetGCClipRegion(data->display, data->stencil_gc,
  6.1179 +                                      0, 0, data->stencil_parts);
  6.1180 +            }
  6.1181 +#endif
  6.1182 +            XFillRectangle(data->display, data->stencil, data->stencil_gc,
  6.1183 +                           0, 0, window->w, window->h);
  6.1184 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  6.1185 +            if (data->use_xdamage)
  6.1186 +            {
  6.1187 +                XFixesSetGCClipRegion(data->display, data->stencil_gc, 0, 0, None);
  6.1188 +            }
  6.1189 +#endif
  6.1190 +            XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF);
  6.1191  
  6.1192 -    xpoint = xpoints = SDL_stack_alloc(XPoint, count);
  6.1193 -    xcount = 0;
  6.1194 -    for (i = 0; i < count; ++i) {
  6.1195 -        int x = points[i].x;
  6.1196 -        int y = points[i].y;
  6.1197 -        if (x < 0 || x >= window->w || y < 0 || y >= window->h) {
  6.1198 -            continue;
  6.1199 +            XDrawPoints(data->display, data->stencil, data->stencil_gc, xpoints, xcount,
  6.1200 +                        CoordModeOrigin);
  6.1201 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  6.1202 +            if (data->use_xdamage)
  6.1203 +            {
  6.1204 +                /* Store the damaged region in stencil_parts */
  6.1205 +                XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts);
  6.1206 +            }
  6.1207 +#endif
  6.1208          }
  6.1209 -        xpoint->x = (short)x;
  6.1210 -        xpoint->y = (short)y;
  6.1211 -        ++xpoint;
  6.1212 -        ++xcount;
  6.1213 +#endif
  6.1214      }
  6.1215 -    if (xcount > 0) {
  6.1216 -        XDrawPoints(data->display, data->drawable, data->gc, xpoints, xcount,
  6.1217 -                    CoordModeOrigin);
  6.1218 +
  6.1219 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  6.1220 +    if (data->use_xrender &&
  6.1221 +            (renderer->blendMode != SDL_BLENDMODE_NONE) &&
  6.1222 +            !(renderer->a == 0xFF &&
  6.1223 +              renderer->blendMode != SDL_BLENDMODE_ADD &&
  6.1224 +              renderer->blendMode != SDL_BLENDMODE_MOD))
  6.1225 +    {
  6.1226 +        XRenderColor foreground;
  6.1227 +        foreground = xrenderdrawcolor(renderer);
  6.1228 +
  6.1229 +        XRenderFillRectangle(data->display, PictOpSrc, data->brush_pict,
  6.1230 +                             &foreground, 0, 0, 1, 1);
  6.1231 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  6.1232 +        if (data->use_xdamage)
  6.1233 +        {
  6.1234 +            /* Update only those parts which drawn
  6.1235 +             * to in the current drawing operation */
  6.1236 +            XFixesSetPictureClipRegion(data->display, data->drawable_pict,
  6.1237 +                                       0, 0, data->stencil_parts);
  6.1238 +        }
  6.1239 +#endif
  6.1240 +        XRenderComposite(data->display, data->blend_op, data->brush_pict,
  6.1241 +                         data->stencil_pict, data->drawable_pict,
  6.1242 +                         0, 0, 0, 0, 0, 0, window->w, window->h);
  6.1243 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  6.1244 +        if (data->use_xdamage)
  6.1245 +        {
  6.1246 +            XFixesSetPictureClipRegion(data->display, data->drawable_pict, 0, 0, None);
  6.1247 +        }
  6.1248 +#endif
  6.1249      }
  6.1250 +    else
  6.1251 +#endif
  6.1252 +    {
  6.1253 +        unsigned long foreground = renderdrawcolor(renderer, 1);
  6.1254 +        XSetForeground(data->display, data->gc, foreground);
  6.1255 +
  6.1256 +
  6.1257 +        if (xcount > 0) {
  6.1258 +            XDrawPoints(data->display, data->drawable, data->gc, xpoints, xcount,
  6.1259 +                        CoordModeOrigin);
  6.1260 +        }
  6.1261 +    }
  6.1262 +
  6.1263      SDL_stack_free(xpoints);
  6.1264  
  6.1265      return 0;
  6.1266 @@ -668,65 +1471,146 @@
  6.1267      clip.y = 0;
  6.1268      clip.w = window->w;
  6.1269      clip.h = window->h;
  6.1270 +    {
  6.1271 +        Pixmap drawable;
  6.1272 +        GC gc;
  6.1273 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  6.1274 +       if (data->use_xrender &&
  6.1275 +            (renderer->blendMode != SDL_BLENDMODE_NONE) &&
  6.1276 +            !(renderer->a == 0xFF &&
  6.1277 +              renderer->blendMode != SDL_BLENDMODE_ADD &&
  6.1278 +              renderer->blendMode != SDL_BLENDMODE_MOD))
  6.1279 +       { 
  6.1280 +            drawable = data->stencil;
  6.1281 +            gc = data->stencil_gc;
  6.1282  
  6.1283 -    foreground = renderdrawcolor(renderer, 1);
  6.1284 -    XSetForeground(data->display, data->gc, foreground);
  6.1285 -
  6.1286 -    xpoint = xpoints = SDL_stack_alloc(XPoint, count);
  6.1287 -    xcount = 0;
  6.1288 -    minx = INT_MAX;
  6.1289 -    miny = INT_MAX;
  6.1290 -    maxx = INT_MIN;
  6.1291 -    maxy = INT_MIN;
  6.1292 -    for (i = 0; i < count; ++i) {
  6.1293 -        int x = points[i].x;
  6.1294 -        int y = points[i].y;
  6.1295 -
  6.1296 -        /* If the point is inside the window, add it to the list */
  6.1297 -        if (x >= 0 && x < window->w && y >= 0 && y < window->h) {
  6.1298 -            if (x < minx) {
  6.1299 -                minx = x;
  6.1300 -            } else if (x > maxx) {
  6.1301 -                maxx = x;
  6.1302 -            }
  6.1303 -            if (y < miny) {
  6.1304 -                miny = y;
  6.1305 -            } else if (y > maxy) {
  6.1306 -                maxy = y;
  6.1307 -            }
  6.1308 -            xpoint->x = (short)x;
  6.1309 -            xpoint->y = (short)y;
  6.1310 -            ++xpoint;
  6.1311 -            ++xcount;
  6.1312 -            continue;
  6.1313 +            XSetForeground(data->display, data->stencil_gc, 0);
  6.1314 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  6.1315 +            if (data->use_xdamage)
  6.1316 +                XFixesSetGCClipRegion(data->display, data->stencil_gc,
  6.1317 +                                      0, 0, data->stencil_parts);
  6.1318 +#endif
  6.1319 +            XFillRectangle(data->display, data->stencil, data->stencil_gc,
  6.1320 +                           0, 0, window->w, window->h);
  6.1321 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  6.1322 +            if (data->use_xdamage)
  6.1323 +                XFixesSetGCClipRegion(data->display, data->stencil_gc,
  6.1324 +                                      0, 0, None);
  6.1325 +#endif
  6.1326 +            XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF);
  6.1327 +        }
  6.1328 +        else
  6.1329 +#endif
  6.1330 +        {
  6.1331 +            drawable = data->drawable;
  6.1332 +            gc = data->gc;
  6.1333          }
  6.1334  
  6.1335 -        /* We need to clip the line segments joined by this point */
  6.1336 -        if (xcount > 0) {
  6.1337 -            int x1 = xpoint[-1].x;
  6.1338 -            int y1 = xpoint[-1].y;
  6.1339 -            int x2 = x;
  6.1340 -            int y2 = y;
  6.1341 -            if (SDL_IntersectRectAndLine(&clip, &x1, &y1, &x2, &y2)) {
  6.1342 -                if (x2 < minx) {
  6.1343 -                    minx = x2;
  6.1344 -                } else if (x2 > maxx) {
  6.1345 -                    maxx = x2;
  6.1346 +        foreground = renderdrawcolor(renderer, 1);
  6.1347 +        XSetForeground(data->display, data->gc, foreground);
  6.1348 +
  6.1349 +        xpoint = xpoints = SDL_stack_alloc(XPoint, count);
  6.1350 +        xcount = 0;
  6.1351 +        minx = INT_MAX;
  6.1352 +        miny = INT_MAX;
  6.1353 +        maxx = INT_MIN;
  6.1354 +        maxy = INT_MIN;
  6.1355 +        for (i = 0; i < count; ++i) {
  6.1356 +            int x = points[i].x;
  6.1357 +            int y = points[i].y;
  6.1358 +
  6.1359 +            /* If the point is inside the window, add it to the list */
  6.1360 +            if (x >= 0 && x < window->w && y >= 0 && y < window->h) {
  6.1361 +                if (x < minx) {
  6.1362 +                    minx = x;
  6.1363 +                } else if (x > maxx) {
  6.1364 +                    maxx = x;
  6.1365                  }
  6.1366 -                if (y2 < miny) {
  6.1367 -                    miny = y2;
  6.1368 -                } else if (y2 > maxy) {
  6.1369 -                    maxy = y2;
  6.1370 +                if (y < miny) {
  6.1371 +                    miny = y;
  6.1372 +                } else if (y > maxy) {
  6.1373 +                    maxy = y;
  6.1374                  }
  6.1375 -                xpoint->x = (short)x2;
  6.1376 -                xpoint->y = (short)y2;
  6.1377 +                xpoint->x = (short)x;
  6.1378 +                xpoint->y = (short)y;
  6.1379                  ++xpoint;
  6.1380                  ++xcount;
  6.1381 +                continue;
  6.1382              }
  6.1383 -            XDrawLines(data->display, data->drawable, data->gc,
  6.1384 -                       xpoints, xcount, CoordModeOrigin);
  6.1385 +
  6.1386 +            /* We need to clip the line segments joined by this point */
  6.1387 +            if (xcount > 0) {
  6.1388 +                int x1 = xpoint[-1].x;
  6.1389 +                int y1 = xpoint[-1].y;
  6.1390 +                int x2 = x;
  6.1391 +                int y2 = y;
  6.1392 +                if (SDL_IntersectRectAndLine(&clip, &x1, &y1, &x2, &y2)) {
  6.1393 +                    if (x2 < minx) {
  6.1394 +                        minx = x2;
  6.1395 +                    } else if (x2 > maxx) {
  6.1396 +                        maxx = x2;
  6.1397 +                    }
  6.1398 +                    if (y2 < miny) {
  6.1399 +                        miny = y2;
  6.1400 +                    } else if (y2 > maxy) {
  6.1401 +                        maxy = y2;
  6.1402 +                    }
  6.1403 +                    xpoint->x = (short)x2;
  6.1404 +                    xpoint->y = (short)y2;
  6.1405 +                    ++xpoint;
  6.1406 +                    ++xcount;
  6.1407 +                }
  6.1408 +                XDrawLines(data->display, drawable, gc,
  6.1409 +                           xpoints, xcount, CoordModeOrigin);
  6.1410 +                if (xpoints[0].x != x2 || xpoints[0].y != y2) {
  6.1411 +                    XDrawPoint(data->display, drawable, gc, x2, y2);
  6.1412 +                }
  6.1413 +                if (data->makedirty) {
  6.1414 +                    SDL_Rect rect;
  6.1415 +
  6.1416 +                    rect.x = minx;
  6.1417 +                    rect.y = miny;
  6.1418 +                    rect.w = (maxx - minx) + 1;
  6.1419 +                    rect.h = (maxy - miny) + 1;
  6.1420 +                    SDL_AddDirtyRect(&data->dirty, &rect);
  6.1421 +                }
  6.1422 +                xpoint = xpoints;
  6.1423 +                xcount = 0;
  6.1424 +                minx = INT_MAX;
  6.1425 +                miny = INT_MAX;
  6.1426 +                maxx = INT_MIN;
  6.1427 +                maxy = INT_MIN;
  6.1428 +            }
  6.1429 +            if (i < (count-1)) {
  6.1430 +                int x1 = x;
  6.1431 +                int y1 = y;
  6.1432 +                int x2 = points[i+1].x;
  6.1433 +                int y2 = points[i+1].y;
  6.1434 +                if (SDL_IntersectRectAndLine(&clip, &x1, &y1, &x2, &y2)) {
  6.1435 +                    if (x1 < minx) {
  6.1436 +                        minx = x1;
  6.1437 +                    } else if (x1 > maxx) {
  6.1438 +                        maxx = x1;
  6.1439 +                    }
  6.1440 +                    if (y1 < miny) {
  6.1441 +                        miny = y1;
  6.1442 +                    } else if (y1 > maxy) {
  6.1443 +                        maxy = y1;
  6.1444 +                    }
  6.1445 +                    xpoint->x = (short)x1;
  6.1446 +                    xpoint->y = (short)y1;
  6.1447 +                    ++xpoint;
  6.1448 +                    ++xcount;
  6.1449 +                }
  6.1450 +            }
  6.1451 +        }
  6.1452 +        if (xcount > 1) {
  6.1453 +            int x2 = xpoint[-1].x;
  6.1454 +            int y2 = xpoint[-1].y;
  6.1455 +            XDrawLines(data->display, drawable, gc, xpoints, xcount,
  6.1456 +                       CoordModeOrigin);
  6.1457              if (xpoints[0].x != x2 || xpoints[0].y != y2) {
  6.1458 -                XDrawPoint(data->display, data->drawable, data->gc, x2, y2);
  6.1459 +                XDrawPoint(data->display, drawable, gc, x2, y2);
  6.1460              }
  6.1461              if (data->makedirty) {
  6.1462                  SDL_Rect rect;
  6.1463 @@ -737,54 +1621,37 @@
  6.1464                  rect.h = (maxy - miny) + 1;
  6.1465                  SDL_AddDirtyRect(&data->dirty, &rect);
  6.1466              }
  6.1467 -            xpoint = xpoints;
  6.1468 -            xcount = 0;
  6.1469 -            minx = INT_MAX;
  6.1470 -            miny = INT_MAX;
  6.1471 -            maxx = INT_MIN;
  6.1472 -            maxy = INT_MIN;
  6.1473 -        }
  6.1474 -        if (i < (count-1)) {
  6.1475 -            int x1 = x;
  6.1476 -            int y1 = y;
  6.1477 -            int x2 = points[i+1].x;
  6.1478 -            int y2 = points[i+1].y;
  6.1479 -            if (SDL_IntersectRectAndLine(&clip, &x1, &y1, &x2, &y2)) {
  6.1480 -                if (x1 < minx) {
  6.1481 -                    minx = x1;
  6.1482 -                } else if (x1 > maxx) {
  6.1483 -                    maxx = x1;
  6.1484 -                }
  6.1485 -                if (y1 < miny) {
  6.1486 -                    miny = y1;
  6.1487 -                } else if (y1 > maxy) {
  6.1488 -                    maxy = y1;
  6.1489 -                }
  6.1490 -                xpoint->x = (short)x1;
  6.1491 -                xpoint->y = (short)y1;
  6.1492 -                ++xpoint;
  6.1493 -                ++xcount;
  6.1494 -            }
  6.1495          }
  6.1496      }
  6.1497 -    if (xcount > 1) {
  6.1498 -        int x2 = xpoint[-1].x;
  6.1499 -        int y2 = xpoint[-1].y;
  6.1500 -        XDrawLines(data->display, data->drawable, data->gc, xpoints, xcount,
  6.1501 -                   CoordModeOrigin);
  6.1502 -        if (xpoints[0].x != x2 || xpoints[0].y != y2) {
  6.1503 -            XDrawPoint(data->display, data->drawable, data->gc, x2, y2);
  6.1504 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  6.1505 +    if (data->use_xrender &&
  6.1506 +            (renderer->blendMode != SDL_BLENDMODE_NONE) &&
  6.1507 +            !(renderer->a == 0xFF &&
  6.1508 +              renderer->blendMode != SDL_BLENDMODE_ADD &&
  6.1509 +              renderer->blendMode != SDL_BLENDMODE_MOD))
  6.1510 +    {
  6.1511 +        XRenderColor xrforeground = xrenderdrawcolor(renderer);
  6.1512 +        XRenderFillRectangle(data->display, PictOpSrc, data->brush_pict,
  6.1513 +                             &xrforeground, 0, 0, 1, 1);
  6.1514 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  6.1515 +        if (data->use_xdamage)
  6.1516 +        {
  6.1517 +            XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts);
  6.1518 +
  6.1519 +            XFixesSetPictureClipRegion(data->display, data->drawable_pict,
  6.1520 +                                       0, 0, data->stencil_parts);
  6.1521          }
  6.1522 -        if (data->makedirty) {
  6.1523 -            SDL_Rect rect;
  6.1524 -
  6.1525 -            rect.x = minx;
  6.1526 -            rect.y = miny;
  6.1527 -            rect.w = (maxx - minx) + 1;
  6.1528 -            rect.h = (maxy - miny) + 1;
  6.1529 -            SDL_AddDirtyRect(&data->dirty, &rect);
  6.1530 -        }
  6.1531 +#endif
  6.1532 +        XRenderComposite(data->display, data->blend_op, data->brush_pict,
  6.1533 +                         data->stencil_pict, data->drawable_pict,
  6.1534 +                         0, 0, 0, 0, 0, 0, window->w, window->h);
  6.1535 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  6.1536 +        if (data->use_xdamage)
  6.1537 +            XFixesSetPictureClipRegion(data->display, data->drawable_pict,
  6.1538 +                                       0, 0, None);
  6.1539 +#endif
  6.1540      }
  6.1541 +#endif
  6.1542      SDL_stack_free(xpoints);
  6.1543  
  6.1544      return 0;
  6.1545 @@ -796,18 +1663,122 @@
  6.1546      X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
  6.1547      SDL_Window *window = renderer->window;
  6.1548      SDL_Rect clip, rect;
  6.1549 -    unsigned long foreground;
  6.1550 +    int i, xcount;
  6.1551      XRectangle *xrects, *xrect;
  6.1552 -    int i, xcount;
  6.1553 -
  6.1554 +    xrect = xrects = SDL_stack_alloc(XRectangle, count);
  6.1555 +    xcount = 0;
  6.1556 +    
  6.1557      clip.x = 0;
  6.1558      clip.y = 0;
  6.1559      clip.w = window->w;
  6.1560      clip.h = window->h;
  6.1561 +    {
  6.1562  
  6.1563 -    foreground = renderdrawcolor(renderer, 1);
  6.1564 -    XSetForeground(data->display, data->gc, foreground);
  6.1565 +        for (i = 0; i < count; ++i) {
  6.1566 +            if (!SDL_IntersectRect(rects[i], &clip, &rect)) {
  6.1567 +                continue;
  6.1568 +            }
  6.1569  
  6.1570 +            xrect->x = (short)rect.x;
  6.1571 +            xrect->y = (short)rect.y;
  6.1572 +            xrect->width = (unsigned short)rect.w - 1;
  6.1573 +            xrect->height = (unsigned short)rect.h - 1;
  6.1574 +            ++xrect;
  6.1575 +            ++xcount;
  6.1576 +
  6.1577 +            if (data->makedirty) {
  6.1578 +                SDL_AddDirtyRect(&data->dirty, &rect);
  6.1579 +            }
  6.1580 +        }
  6.1581 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  6.1582 +        if (data->use_xrender &&
  6.1583 +            (renderer->blendMode != SDL_BLENDMODE_NONE) &&
  6.1584 +            !(renderer->a == 0xFF &&
  6.1585 +              renderer->blendMode != SDL_BLENDMODE_ADD &&
  6.1586 +              renderer->blendMode != SDL_BLENDMODE_MOD))
  6.1587 +        {
  6.1588 +            XSetForeground(data->display, data->stencil_gc, 0);
  6.1589 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  6.1590 +            if (data->use_xdamage)
  6.1591 +                XFixesSetGCClipRegion(data->display, data->stencil_gc,
  6.1592 +                                      0, 0, data->stencil_parts);
  6.1593 +#endif
  6.1594 +            XFillRectangle(data->display, data->stencil, data->stencil_gc,
  6.1595 +                           0, 0, window->w, window->h);
  6.1596 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  6.1597 +            if (data->use_xdamage)
  6.1598 +                XFixesSetGCClipRegion(data->display, data->stencil_gc,
  6.1599 +                                      0, 0, None);
  6.1600 +#endif
  6.1601 +            XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF);
  6.1602 +
  6.1603 +            XDrawRectangles(data->display, data->stencil, data->stencil_gc, xrects, xcount);
  6.1604 +
  6.1605 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  6.1606 +            if (data->use_xdamage)
  6.1607 +                XDamageSubtract(data->display, data->stencil_damage,
  6.1608 +                                None, data->stencil_parts);
  6.1609 +#endif
  6.1610 +        }
  6.1611 +#endif
  6.1612 +    }
  6.1613 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  6.1614 +    if (data->use_xrender &&
  6.1615 +            (renderer->blendMode != SDL_BLENDMODE_NONE) &&
  6.1616 +            !(renderer->a == 0xFF &&
  6.1617 +              renderer->blendMode != SDL_BLENDMODE_ADD &&
  6.1618 +              renderer->blendMode != SDL_BLENDMODE_MOD))
  6.1619 +    {
  6.1620 +        XRenderColor foreground;
  6.1621 +        foreground = xrenderdrawcolor(renderer);
  6.1622 +        XRenderFillRectangle(data->display, PictOpSrc, data->brush_pict,
  6.1623 +                             &foreground, 0, 0, 1, 1);
  6.1624 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  6.1625 +        if (data->use_xdamage)
  6.1626 +            XFixesSetPictureClipRegion(data->display, data->drawable_pict,
  6.1627 +                                       0, 0, data->stencil_parts);
  6.1628 +#endif
  6.1629 +        XRenderComposite(data->display, data->blend_op, data->brush_pict,
  6.1630 +                         data->stencil_pict, data->drawable_pict,
  6.1631 +                         0, 0, 0, 0, 0, 0, window->w, window->h);
  6.1632 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  6.1633 +        if (data->use_xdamage)
  6.1634 +            XFixesSetPictureClipRegion(data->display, data->drawable_pict,
  6.1635 +                                       0, 0, None);
  6.1636 +#endif
  6.1637 +    }
  6.1638 +    else
  6.1639 +#endif
  6.1640 +    {
  6.1641 +        unsigned long foreground;
  6.1642 +        
  6.1643 +        foreground = renderdrawcolor(renderer, 1);
  6.1644 +        XSetForeground(data->display, data->gc, foreground);
  6.1645 +    
  6.1646 +        if (xcount > 0) {
  6.1647 +            XDrawRectangles(data->display, data->drawable, data->gc,
  6.1648 +                            xrects, xcount);
  6.1649 +        }
  6.1650 +    }
  6.1651 +    SDL_stack_free(xrects);
  6.1652 +
  6.1653 +    return 0;
  6.1654 +}
  6.1655 +
  6.1656 +static int
  6.1657 +X11_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
  6.1658 +{
  6.1659 +    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
  6.1660 +    SDL_Window *window = renderer->window;
  6.1661 +    SDL_Rect clip, rect;
  6.1662 +    
  6.1663 +    clip.x = 0;
  6.1664 +    clip.y = 0;
  6.1665 +    clip.w = window->w;
  6.1666 +    clip.h = window->h;
  6.1667 +    
  6.1668 +    int i, xcount;
  6.1669 +    XRectangle *xrects, *xrect;
  6.1670      xrect = xrects = SDL_stack_alloc(XRectangle, count);
  6.1671      xcount = 0;
  6.1672      for (i = 0; i < count; ++i) {
  6.1673 @@ -826,57 +1797,34 @@
  6.1674              SDL_AddDirtyRect(&data->dirty, &rect);
  6.1675          }
  6.1676      }
  6.1677 -    if (xcount > 0) {
  6.1678 -        XDrawRectangles(data->display, data->drawable, data->gc,
  6.1679 -                        xrects, xcount);
  6.1680 -    }
  6.1681 -    SDL_stack_free(xpoints);
  6.1682  
  6.1683 -    return 0;
  6.1684 -}
  6.1685 -
  6.1686 -static int
  6.1687 -X11_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
  6.1688 -{
  6.1689 -    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
  6.1690 -    SDL_Window *window = renderer->window;
  6.1691 -    SDL_Rect clip, rect;
  6.1692 -    unsigned long foreground;
  6.1693 -    XRectangle *xrects, *xrect;
  6.1694 -    int i, xcount;
  6.1695 -
  6.1696 -    clip.x = 0;
  6.1697 -    clip.y = 0;
  6.1698 -    clip.w = window->w;
  6.1699 -    clip.h = window->h;
  6.1700 -
  6.1701 -    foreground = renderdrawcolor(renderer, 1);
  6.1702 -    XSetForeground(data->display, data->gc, foreground);
  6.1703 -
  6.1704 -    xrect = xrects = SDL_stack_alloc(XRectangle, count);
  6.1705 -    xcount = 0;
  6.1706 -    for (i = 0; i < count; ++i) {
  6.1707 -        if (!SDL_IntersectRect(rects[i], &clip, &rect)) {
  6.1708 -            continue;
  6.1709 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  6.1710 +    if (data->use_xrender) {
  6.1711 +        XRenderColor foreground;
  6.1712 +        foreground = xrenderdrawcolor(renderer);
  6.1713 +        if (xcount == 1) {
  6.1714 +            XRenderFillRectangle(data->display, data->blend_op, data->drawable_pict,
  6.1715 +                                 &foreground, xrects[0].x, xrects[0].y,
  6.1716 +                                 xrects[0].width, xrects[0].height);
  6.1717          }
  6.1718 -
  6.1719 -        xrect->x = (short)rect.x;
  6.1720 -        xrect->y = (short)rect.y;
  6.1721 -        xrect->width = (unsigned short)rect.w;
  6.1722 -        xrect->height = (unsigned short)rect.h;
  6.1723 -        ++xrect;
  6.1724 -        ++xcount;
  6.1725 -
  6.1726 -        if (data->makedirty) {
  6.1727 -            SDL_AddDirtyRect(&data->dirty, &rect);
  6.1728 +        else if (xcount > 1) {
  6.1729 +            XRenderFillRectangles(data->display, data->blend_op, data->drawable_pict,
  6.1730 +                                  &foreground, xrects, xcount);
  6.1731          }
  6.1732      }
  6.1733 -    if (xcount > 0) {
  6.1734 +    else
  6.1735 +#endif
  6.1736 +    {
  6.1737 +        unsigned long foreground;
  6.1738 +        
  6.1739 +        foreground = renderdrawcolor(renderer, 1);
  6.1740 +        XSetForeground(data->display, data->gc, foreground);
  6.1741 + 
  6.1742          XFillRectangles(data->display, data->drawable, data->gc,
  6.1743                          xrects, xcount);
  6.1744      }
  6.1745 -    SDL_stack_free(xpoints);
  6.1746  
  6.1747 +    SDL_stack_free(xrects);
  6.1748      return 0;
  6.1749  }
  6.1750  
  6.1751 @@ -890,103 +1838,206 @@
  6.1752      if (data->makedirty) {
  6.1753          SDL_AddDirtyRect(&data->dirty, dstrect);
  6.1754      }
  6.1755 -    if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
  6.1756 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  6.1757 +    if (data->use_xrender) {
  6.1758 +        if(texture->access == SDL_TEXTUREACCESS_STREAMING) {
  6.1759  #ifndef NO_SHARED_MEMORY
  6.1760 -        if (texturedata->shminfo.shmaddr) {
  6.1761 -            XShmPutImage(data->display, data->drawable, data->gc,
  6.1762 -                         texturedata->image, srcrect->x, srcrect->y,
  6.1763 -                         dstrect->x, dstrect->y, srcrect->w, srcrect->h,
  6.1764 -                         False);
  6.1765 -        } else
  6.1766 +            if(texturedata->shminfo.shmaddr) {
  6.1767 +                XShmPutImage(data->display, texturedata->pixmap, texturedata->gc,
  6.1768 +                             texturedata->image, srcrect->x, srcrect->y,
  6.1769 +                             srcrect->x, srcrect->y, srcrect->w, srcrect->h,
  6.1770 +                             False);
  6.1771 +            }
  6.1772 +            else
  6.1773  #endif
  6.1774 -        if (texturedata->pixels) {
  6.1775 -            XPutImage(data->display, data->drawable, data->gc,
  6.1776 -                      texturedata->image, srcrect->x, srcrect->y, dstrect->x,
  6.1777 -                      dstrect->y, srcrect->w, srcrect->h);
  6.1778 +            if (texturedata->pixels) {
  6.1779 +                XPutImage(data->display, texturedata->pixmap, texturedata->gc,
  6.1780 +                          texturedata->image, srcrect->x, srcrect->y, srcrect->x,
  6.1781 +                          srcrect->y, srcrect->w, srcrect->h);
  6.1782 +            }
  6.1783 +            XSync(data->display, False);
  6.1784 +        }
  6.1785 +        Picture src, mask;
  6.1786 +        XRenderPictureAttributes attr;
  6.1787 +        const SDL_Rect *mrect;
  6.1788 +
  6.1789 +        if (texture->modMode == SDL_TEXTUREMODULATE_NONE) {
  6.1790 +            src = texturedata->picture;
  6.1791 +        }
  6.1792 +        else {
  6.1793 +            src = texturedata->modulated_picture;
  6.1794 +        }
  6.1795 +
  6.1796 +        if(texture->blendMode == SDL_BLENDMODE_NONE) 
  6.1797 +        {
  6.1798 +            mask = None;
  6.1799 +            mrect = srcrect;
  6.1800 +        }
  6.1801 +        else if (texture->blendMode == SDL_BLENDMODE_MOD)
  6.1802 +        {
  6.1803 +            mask = data->stencil_pict;
  6.1804 +            mrect = dstrect;
  6.1805 +        }
  6.1806 +        else
  6.1807 +        {
  6.1808 +            mask = texturedata->picture;
  6.1809 +            mrect = srcrect;
  6.1810 +        }
  6.1811 +
  6.1812 +        if(srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
  6.1813 +            if (texture->blendMode == SDL_BLENDMODE_MOD) {
  6.1814 +                XRenderComposite(data->display, PictOpSrc, data->drawable_pict,
  6.1815 +                             src, data->stencil_pict,
  6.1816 +                             dstrect->x, dstrect->y, srcrect->x, srcrect->y,
  6.1817 +                             dstrect->x, dstrect->y, dstrect->w, dstrect->h);
  6.1818 +                attr.component_alpha = True;
  6.1819 +                XRenderChangePicture(data->display, data->stencil_pict,
  6.1820 +                                     CPComponentAlpha, &attr);
  6.1821 +            }
  6.1822 +            XRenderComposite(data->display, texturedata->blend_op,
  6.1823 +                            src, mask, data->drawable_pict, srcrect->x, srcrect->y,
  6.1824 +                            mrect->x, mrect->y, dstrect->x, dstrect->y,
  6.1825 +                            dstrect->w, dstrect->h);
  6.1826 +        } else {
  6.1827 +            double xscale = ((double) dstrect->w) / srcrect->w;
  6.1828 +            double yscale = ((double) dstrect->h) / srcrect->h;
  6.1829 +            XTransform xform = {{
  6.1830 +                    {XDoubleToFixed(xscale), XDoubleToFixed(0), XDoubleToFixed(0)},
  6.1831 +                    {XDoubleToFixed(0), XDoubleToFixed(yscale), XDoubleToFixed(0)},
  6.1832 +                    {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(xscale * yscale)}}};
  6.1833 +            XRenderSetPictureTransform(data->display, src, &xform);
  6.1834 +            
  6.1835 +            if (texture->blendMode == SDL_BLENDMODE_MOD) {
  6.1836 +                XRenderComposite(data->display, PictOpSrc, data->drawable_pict,
  6.1837 +                             src, data->stencil_pict,
  6.1838 +                             dstrect->x, dstrect->y, srcrect->x, srcrect->y,
  6.1839 +                             dstrect->x, dstrect->y, dstrect->w, dstrect->h);
  6.1840 +                attr.component_alpha = True;
  6.1841 +                XRenderChangePicture(data->display, data->stencil_pict,
  6.1842 +                                     CPComponentAlpha, &attr);
  6.1843 +            }
  6.1844 +
  6.1845 +            XRenderSetPictureFilter(data->display, src,
  6.1846 +                                    texturedata->filter, 0, 0);
  6.1847 +
  6.1848 +            XRenderComposite(data->display, texturedata->blend_op,
  6.1849 +                             src, mask, data->drawable_pict,
  6.1850 +                             srcrect->x, srcrect->y, mrect->x, mrect->y,
  6.1851 +                             dstrect->x, dstrect->y, dstrect->w, dstrect->h);
  6.1852 +            
  6.1853 +            XTransform identity = {{
  6.1854 +                    {XDoubleToFixed(1), XDoubleToFixed(0), XDoubleToFixed(0)},
  6.1855 +                    {XDoubleToFixed(0), XDoubleToFixed(1), XDoubleToFixed(0)},
  6.1856 +                    {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(1)}}};
  6.1857 +            XRenderSetPictureTransform(data->display, src, &identity);
  6.1858 +        }
  6.1859 +        if (renderer->blendMode == SDL_BLENDMODE_MOD) {
  6.1860 +            attr.component_alpha = False;
  6.1861 +            XRenderChangePicture(data->display, data->stencil_pict,
  6.1862 +                                 CPComponentAlpha, &attr);
  6.1863 +        }
  6.1864 +    }
  6.1865 +    else
  6.1866 +#endif
  6.1867 +    {
  6.1868 +        if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
  6.1869 +#ifndef NO_SHARED_MEMORY
  6.1870 +            if (texturedata->shminfo.shmaddr) {
  6.1871 +                XShmPutImage(data->display, data->drawable, data->gc,
  6.1872 +                             texturedata->image, srcrect->x, srcrect->y,
  6.1873 +                             dstrect->x, dstrect->y, srcrect->w, srcrect->h,
  6.1874 +                             False);
  6.1875 +            } else
  6.1876 +#endif
  6.1877 +            if (texturedata->pixels) {
  6.1878 +                XPutImage(data->display, data->drawable, data->gc,
  6.1879 +                          texturedata->image, srcrect->x, srcrect->y, dstrect->x,
  6.1880 +                          dstrect->y, srcrect->w, srcrect->h);
  6.1881 +            } else {
  6.1882 +                XCopyArea(data->display, texturedata->pixmap, data->drawable,
  6.1883 +                          data->gc, srcrect->x, srcrect->y, dstrect->w,
  6.1884 +                          dstrect->h, dstrect->x, dstrect->y);
  6.1885 +            }
  6.1886 +        } else if (texturedata->yuv
  6.1887 +                   || texture->access == SDL_TEXTUREACCESS_STREAMING) {
  6.1888 +            SDL_Surface src, dst;
  6.1889 +            SDL_PixelFormat fmt;
  6.1890 +            SDL_Rect rect;
  6.1891 +            XImage *image = texturedata->scaling_image;
  6.1892 +
  6.1893 +            if (!image) {
  6.1894 +                void *pixels;
  6.1895 +                int pitch;
  6.1896 +
  6.1897 +                pitch = dstrect->w * SDL_BYTESPERPIXEL(texturedata->format);
  6.1898 +                pixels = SDL_malloc(dstrect->h * pitch);
  6.1899 +                if (!pixels) {
  6.1900 +                    SDL_OutOfMemory();
  6.1901 +                    return -1;
  6.1902 +                }
  6.1903 +
  6.1904 +                image =
  6.1905 +                    XCreateImage(data->display, data->visual, data->depth,
  6.1906 +                                 ZPixmap, 0, pixels, dstrect->w, dstrect->h,
  6.1907 +                                 SDL_BYTESPERPIXEL(texturedata->format) * 8,
  6.1908 +                                 pitch);
  6.1909 +                if (!image) {
  6.1910 +                    SDL_SetError("XCreateImage() failed");
  6.1911 +                    return -1;
  6.1912 +                }
  6.1913 +                texturedata->scaling_image = image;
  6.1914 +
  6.1915 +            } else if (image->width != dstrect->w || image->height != dstrect->h
  6.1916 +                       || !image->data) {
  6.1917 +                image->width = dstrect->w;
  6.1918 +                image->height = dstrect->h;
  6.1919 +                image->bytes_per_line =
  6.1920 +                    image->width * SDL_BYTESPERPIXEL(texturedata->format);
  6.1921 +                image->data =
  6.1922 +                    (char *) SDL_realloc(image->data,
  6.1923 +                                         image->height * image->bytes_per_line);
  6.1924 +                if (!image->data) {
  6.1925 +                    SDL_OutOfMemory();
  6.1926 +                    return -1;
  6.1927 +                }
  6.1928 +            }
  6.1929 +
  6.1930 +            /* Set up fake surfaces for SDL_SoftStretch() */
  6.1931 +            SDL_zero(src);
  6.1932 +            src.format = &fmt;
  6.1933 +            src.w = texture->w;
  6.1934 +            src.h = texture->h;
  6.1935 +#ifndef NO_SHARED_MEMORY
  6.1936 +            if (texturedata->shminfo.shmaddr) {
  6.1937 +                src.pixels = texturedata->shminfo.shmaddr;
  6.1938 +            } else
  6.1939 +#endif
  6.1940 +                src.pixels = texturedata->pixels;
  6.1941 +            src.pitch = texturedata->pitch;
  6.1942 +
  6.1943 +            SDL_zero(dst);
  6.1944 +            dst.format = &fmt;
  6.1945 +            dst.w = image->width;
  6.1946 +            dst.h = image->height;
  6.1947 +            dst.pixels = image->data;
  6.1948 +            dst.pitch = image->bytes_per_line;
  6.1949 +
  6.1950 +            fmt.BytesPerPixel = SDL_BYTESPERPIXEL(texturedata->format);
  6.1951 +
  6.1952 +            rect.x = 0;
  6.1953 +            rect.y = 0;
  6.1954 +            rect.w = dstrect->w;
  6.1955 +            rect.h = dstrect->h;
  6.1956 +            if (SDL_SoftStretch(&src, srcrect, &dst, &rect) < 0) {
  6.1957 +                return -1;
  6.1958 +            }
  6.1959 +            XPutImage(data->display, data->drawable, data->gc, image, 0, 0,
  6.1960 +                      dstrect->x, dstrect->y, dstrect->w, dstrect->h);
  6.1961          } else {
  6.1962              XCopyArea(data->display, texturedata->pixmap, data->drawable,
  6.1963 -                      data->gc, srcrect->x, srcrect->y, dstrect->w,
  6.1964 -                      dstrect->h, dstrect->x, dstrect->y);
  6.1965 +                      data->gc, srcrect->x, srcrect->y, dstrect->w, dstrect->h,
  6.1966 +                      srcrect->x, srcrect->y);
  6.1967          }
  6.1968 -    } else if (texturedata->yuv
  6.1969 -               || texture->access == SDL_TEXTUREACCESS_STREAMING) {
  6.1970 -        SDL_Surface src, dst;
  6.1971 -        SDL_PixelFormat fmt;
  6.1972 -        SDL_Rect rect;
  6.1973 -        XImage *image = texturedata->scaling_image;
  6.1974 -
  6.1975 -        if (!image) {
  6.1976 -            void *pixels;
  6.1977 -            int pitch;
  6.1978 -
  6.1979 -            pitch = dstrect->w * SDL_BYTESPERPIXEL(texturedata->format);
  6.1980 -            pixels = SDL_malloc(dstrect->h * pitch);
  6.1981 -            if (!pixels) {
  6.1982 -                SDL_OutOfMemory();
  6.1983 -                return -1;
  6.1984 -            }
  6.1985 -
  6.1986 -            image =
  6.1987 -                XCreateImage(data->display, data->visual, data->depth,
  6.1988 -                             ZPixmap, 0, pixels, dstrect->w, dstrect->h,
  6.1989 -                             SDL_BYTESPERPIXEL(texturedata->format) * 8,
  6.1990 -                             pitch);
  6.1991 -            if (!image) {
  6.1992 -                SDL_SetError("XCreateImage() failed");
  6.1993 -                return -1;
  6.1994 -            }
  6.1995 -            texturedata->scaling_image = image;
  6.1996 -
  6.1997 -        } else if (image->width != dstrect->w || image->height != dstrect->h
  6.1998 -                   || !image->data) {
  6.1999 -            image->width = dstrect->w;
  6.2000 -            image->height = dstrect->h;
  6.2001 -            image->bytes_per_line =
  6.2002 -                image->width * SDL_BYTESPERPIXEL(texturedata->format);
  6.2003 -            image->data =
  6.2004 -                (char *) SDL_realloc(image->data,
  6.2005 -                                     image->height * image->bytes_per_line);
  6.2006 -            if (!image->data) {
  6.2007 -                SDL_OutOfMemory();
  6.2008 -                return -1;
  6.2009 -            }
  6.2010 -        }
  6.2011 -
  6.2012 -        /* Set up fake surfaces for SDL_SoftStretch() */
  6.2013 -        SDL_zero(src);
  6.2014 -        src.format = &fmt;
  6.2015 -        src.w = texture->w;
  6.2016 -        src.h = texture->h;
  6.2017 -#ifndef NO_SHARED_MEMORY
  6.2018 -        if (texturedata->shminfo.shmaddr) {
  6.2019 -            src.pixels = texturedata->shminfo.shmaddr;
  6.2020 -        } else
  6.2021 -#endif
  6.2022 -            src.pixels = texturedata->pixels;
  6.2023 -        src.pitch = texturedata->pitch;
  6.2024 -
  6.2025 -        SDL_zero(dst);
  6.2026 -        dst.format = &fmt;
  6.2027 -        dst.w = image->width;
  6.2028 -        dst.h = image->height;
  6.2029 -        dst.pixels = image->data;
  6.2030 -        dst.pitch = image->bytes_per_line;
  6.2031 -
  6.2032 -        fmt.BytesPerPixel = SDL_BYTESPERPIXEL(texturedata->format);
  6.2033 -
  6.2034 -        rect.x = 0;
  6.2035 -        rect.y = 0;
  6.2036 -        rect.w = dstrect->w;
  6.2037 -        rect.h = dstrect->h;
  6.2038 -        if (SDL_SoftStretch(&src, srcrect, &dst, &rect) < 0) {
  6.2039 -            return -1;
  6.2040 -        }
  6.2041 -        XPutImage(data->display, data->drawable, data->gc, image, 0, 0,
  6.2042 -                  dstrect->x, dstrect->y, dstrect->w, dstrect->h);
  6.2043 -    } else {
  6.2044 -        XCopyArea(data->display, texturedata->pixmap, data->drawable,
  6.2045 -                  data->gc, srcrect->x, srcrect->y, dstrect->w, dstrect->h,
  6.2046 -                  srcrect->x, srcrect->y);
  6.2047      }
  6.2048      return 0;
  6.2049  }
  6.2050 @@ -1065,9 +2116,26 @@
  6.2051      if (!(renderer->info.flags & SDL_RENDERER_SINGLEBUFFER)) {
  6.2052          for (dirty = data->dirty.list; dirty; dirty = dirty->next) {
  6.2053              const SDL_Rect *rect = &dirty->rect;
  6.2054 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  6.2055 +            if (data->use_xrender)
  6.2056 +            {
  6.2057 +                XRenderComposite(data->display,
  6.2058 +                                 data->blend_op,
  6.2059 +                                 data->drawable_pict,
  6.2060 +                                 None,
  6.2061 +                                 data->xwindow_pict,
  6.2062 +                                 rect->x, rect->y,
  6.2063 +                                 0, 0,
  6.2064 +                                 rect->x, rect->y,
  6.2065 +                                 rect->w, rect->h);
  6.2066 +            }
  6.2067 +            else
  6.2068 +#endif
  6.2069 +            {
  6.2070              XCopyArea(data->display, data->drawable, data->xwindow,
  6.2071                        data->gc, rect->x, rect->y, rect->w, rect->h,
  6.2072                        rect->x, rect->y);
  6.2073 +            }
  6.2074          }
  6.2075          SDL_ClearDirtyRects(&data->dirty);
  6.2076      }
  6.2077 @@ -1077,9 +2145,15 @@
  6.2078      if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
  6.2079          data->current_pixmap = (data->current_pixmap + 1) % 2;
  6.2080          data->drawable = data->pixmaps[data->current_pixmap];
  6.2081 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  6.2082 +        data->drawable_pict = data->pixmap_picts[data->current_pixmap];
  6.2083 +#endif
  6.2084      } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
  6.2085          data->current_pixmap = (data->current_pixmap + 1) % 3;
  6.2086          data->drawable = data->pixmaps[data->current_pixmap];
  6.2087 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  6.2088 +        data->drawable_pict = data->pixmap_picts[data->current_pixmap];
  6.2089 +#endif
  6.2090      }
  6.2091  }
  6.2092  
  6.2093 @@ -1110,6 +2184,19 @@
  6.2094          data->pixels = NULL;
  6.2095      }
  6.2096  #endif
  6.2097 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  6.2098 +    if (renderdata->use_xrender) {
  6.2099 +        if (data->picture) {
  6.2100 +            XRenderFreePicture(renderdata->display, data->picture);
  6.2101 +        }
  6.2102 +        if (data->modulated_pixmap) {
  6.2103 +            XFreePixmap(renderdata->display, data->modulated_pixmap);
  6.2104 +        }
  6.2105 +        if (data->modulated_picture) {
  6.2106 +            XRenderFreePicture(renderdata->display, data->modulated_picture);
  6.2107 +        }
  6.2108 +    }
  6.2109 +#endif
  6.2110      if (data->scaling_image) {
  6.2111          SDL_free(data->scaling_image->data);
  6.2112          data->scaling_image->data = NULL;
  6.2113 @@ -1133,10 +2220,36 @@
  6.2114              if (data->pixmaps[i] != None) {
  6.2115                  XFreePixmap(data->display, data->pixmaps[i]);
  6.2116              }
  6.2117 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  6.2118 +            if (data->use_xrender && data->pixmap_picts[i]) {
  6.2119 +                XRenderFreePicture(data->display, data->pixmap_picts[i]);
  6.2120 +            }
  6.2121 +#endif
  6.2122          }
  6.2123          if (data->gc) {
  6.2124              XFreeGC(data->display, data->gc);
  6.2125          }
  6.2126 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  6.2127 +        if (data->use_xrender) {
  6.2128 +            if (data->stencil_gc) {
  6.2129 +                XFreeGC(data->display, data->stencil_gc);
  6.2130 +            }
  6.2131 +            if (data->stencil) {
  6.2132 +                XFreePixmap(data->display, data->stencil);
  6.2133 +            }
  6.2134 +            if (data->stencil_pict) {
  6.2135 +                XRenderFreePicture(data->display, data->stencil_pict);
  6.2136 +            }
  6.2137 +            if (data->xwindow_pict) {
  6.2138 +                XRenderFreePicture(data->display, data->xwindow_pict);
  6.2139 +            }
  6.2140 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  6.2141 +            if (data->use_xdamage && data->stencil_damage) {
  6.2142 +                XDamageDestroy(data->display, data->stencil_damage);
  6.2143 +            }
  6.2144 +#endif
  6.2145 +        }
  6.2146 +#endif
  6.2147          SDL_FreeDirtyRects(&data->dirty);
  6.2148          SDL_free(data);
  6.2149      }
     7.1 --- a/src/video/x11/SDL_x11sym.h	Tue Jul 27 21:31:28 2010 -0700
     7.2 +++ b/src/video/x11/SDL_x11sym.h	Wed Jul 28 00:54:23 2010 -0700
     7.3 @@ -156,6 +156,10 @@
     7.4  SDL_X11_SYM(SDL_X11_XESetWireToEventRetType,XESetWireToEvent,(Display* a,int b,SDL_X11_XESetWireToEventRetType c),(a,b,c),return)
     7.5  SDL_X11_SYM(SDL_X11_XESetEventToWireRetType,XESetEventToWire,(Display* a,int b,SDL_X11_XESetEventToWireRetType c),(a,b,c),return)
     7.6  SDL_X11_SYM(XExtensionErrorHandler,XSetExtensionErrorHandler,(XExtensionErrorHandler a),(a),return)
     7.7 +SDL_X11_SYM(int,XFillRectangle,(Display *dpy,Drawable d,GC gc,int x,int y,unsigned int width,unsigned int height),(dpy,d,gc,x,y,width,height),return)
     7.8 +SDL_X11_SYM(int,XSetBackground,(Display *dpy,GC gc,unsigned long background),(dpy,gc,background),return)
     7.9 +SDL_X11_SYM(Status,XInitImage,(XImage *image),(image),return)
    7.10 +SDL_X11_SYM(int,XSetClipMask,(Display *dpy,GC gc,Pixmap pixmap),(dpy,gc,pixmap),return)
    7.11  
    7.12  #if NeedWidePrototypes
    7.13  SDL_X11_SYM(KeySym,XKeycodeToKeysym,(Display* a,unsigned int b,int c),(a,b,c),return)
    7.14 @@ -182,6 +186,7 @@
    7.15  SDL_X11_SYM(Status,XShmDetach,(Display* a,XShmSegmentInfo* b),(a,b),return)
    7.16  SDL_X11_SYM(Status,XShmPutImage,(Display* a,Drawable b,GC c,XImage* d,int e,int f,int g,int h,unsigned int i,unsigned int j,Bool k),(a,b,c,d,e,f,g,h,i,j,k),return)
    7.17  SDL_X11_SYM(XImage*,XShmCreateImage,(Display* a,Visual* b,unsigned int c,int d,char* e,XShmSegmentInfo* f,unsigned int g,unsigned int h),(a,b,c,d,e,f,g,h),return)
    7.18 +SDL_X11_SYM(Pixmap,XShmCreatePixmap,(Display *a,Drawable b,char* c,XShmSegmentInfo* d, unsigned int e, unsigned int f, unsigned int g),(a,b,c,d,e,f,g),return)
    7.19  SDL_X11_SYM(Bool,XShmQueryExtension,(Display* a),(a),return)
    7.20  #endif
    7.21  
    7.22 @@ -237,6 +242,41 @@
    7.23  SDL_X11_SYM(void,XScreenSaverSuspend,(Display *dpy,Bool suspend),(dpy,suspend),return)
    7.24  #endif
    7.25  
    7.26 +/* XRender support */
    7.27 +#if SDL_VIDEO_DRIVER_X11_XRENDER
    7.28 +SDL_X11_MODULE(XRENDER)
    7.29 +SDL_X11_SYM(Bool,XRenderQueryExtension,(Display *dpy,int *event_base,int *error_base),(dpy,event_base,error_base),return)
    7.30 +SDL_X11_SYM(Bool,XRenderQueryVersion,(Display *dpy,int *major,int *minor),(dpy,major,minor),return)
    7.31 +SDL_X11_SYM(XRenderPictFormat*,XRenderFindVisualFormat,(Display *dpy,_Xconst Visual *visual),(dpy,visual),return)
    7.32 +SDL_X11_SYM(XRenderPictFormat*,XRenderFindStandardFormat,(Display *dpy,int format),(dpy,format),return)
    7.33 +SDL_X11_SYM(XRenderPictFormat*,XRenderFindFormat,(Display *dpy,unsigned long mask,_Xconst XRenderPictFormat* templ,int count),(dpy,mask,templ,count),return)
    7.34 +SDL_X11_SYM(Picture,XRenderCreatePicture,(Display *dpy,Drawable drawable,_Xconst XRenderPictFormat* format,unsigned long valuemask,_Xconst XRenderPictureAttributes* attributes),(dpy,drawable,format,valuemask,attributes),return)
    7.35 +SDL_X11_SYM(void,XRenderFreePicture,(Display *dpy,Picture picture),(dpy,picture),return)
    7.36 +SDL_X11_SYM(void,XRenderChangePicture,(Display *dpy,Picture picture,unsigned long valuemask,_Xconst XRenderPictureAttributes* attributes),(dpy,picture,valuemask,attributes),return)
    7.37 +SDL_X11_SYM(void,XRenderComposite,(Display *dpy,int op,Picture src,Picture mask,Picture dst,int src_x,int src_y,int mask_x,int mask_y,int dst_x,int dst_y,unsigned int width,unsigned int height),(dpy,op,src,mask,dst,src_x,src_y,mask_x,mask_y,dst_x,dst_y,width,height),return)
    7.38 +SDL_X11_SYM(Picture,XRenderCreateSolidFill,(Display *dpy,const XRenderColor *color),(dpy,color),return)
    7.39 +SDL_X11_SYM(void,XRenderSetPictureTransform,(Display *dpy,Picture picture,XTransform *transform),(dpy,picture,transform),return)
    7.40 +SDL_X11_SYM(void,XRenderFillRectangle,(Display *dpy,int op,Picture dst,_Xconst XRenderColor *color,int x,int y,unsigned int width,unsigned int height),(dpy,op,dst,color,x,y,width,height),return)
    7.41 +SDL_X11_SYM(void,XRenderFillRectangles,(Display *dpy,int op,Picture dst,_Xconst XRenderColor *color,_Xconst XRectangle *rectangles,int n_rects),(dpy,op,dst,color,rectangles,n_rects),return)
    7.42 +SDL_X11_SYM(void,XRenderSetPictureFilter,(Display *dpy,Picture picture,const char *filter,XFixed *params,int nparams),(dpy,picture,filter,params,nparams),return)
    7.43 +#endif
    7.44 +
    7.45 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
    7.46 +SDL_X11_MODULE(XDAMAGE)
    7.47 +SDL_X11_SYM(Bool,XDamageQueryExtension,(Display *dpy,int *event_base_return,int *error_base_return),(dpy,event_base_return,error_base_return),return)
    7.48 +SDL_X11_SYM(Status,XDamageQueryVersion,(Display *dpy,int *major,int *minor),(dpy,major,minor),return)
    7.49 +SDL_X11_SYM(Damage,XDamageCreate,(Display *dpy,Drawable d,int level),(dpy,d,level),return)
    7.50 +SDL_X11_SYM(void,XDamageSubtract,(Display *dpy,Damage damage,XserverRegion repair,XserverRegion parts),(dpy,damage,repair,parts),return)
    7.51 +SDL_X11_SYM(void,XDamageDestroy,(Display *dpy,Damage damage),(dpy,damage),return)
    7.52 +#endif
    7.53 +
    7.54 +#ifdef SDL_VIDEO_DRIVER_X11_XFIXES
    7.55 +SDL_X11_MODULE(XFIXES)
    7.56 +SDL_X11_SYM(Bool,XFixesQueryExtension,(Display *dpy,int *event_base,int *error_base),(dpy,event_base,error_base),return)
    7.57 +SDL_X11_SYM(Status,XFixesQueryVersion,(Display *dpy,int *major,int *minor),(dpy,major,minor),return)
    7.58 +SDL_X11_SYM(void,XFixesSetGCClipRegion,(Display *dpy,GC gc,int clip_x,int clip_y,XserverRegion region),(dpy,gc,clip_x,clip_y,region),return)
    7.59 +SDL_X11_SYM(void,XFixesSetPictureClipRegion,(Display *dpy,XID picture,int clip_x,int clip_y,XserverRegion region),(dpy,picture,clip_x,clip_y,region),return)
    7.60 +#endif
    7.61  /* *INDENT-ON* */
    7.62  
    7.63  /* vi: set ts=4 sw=4 expandtab: */
     8.1 --- a/src/video/x11/SDL_x11video.h	Tue Jul 27 21:31:28 2010 -0700
     8.2 +++ b/src/video/x11/SDL_x11video.h	Wed Jul 28 00:54:23 2010 -0700
     8.3 @@ -45,7 +45,15 @@
     8.4  #if SDL_VIDEO_DRIVER_X11_SCRNSAVER
     8.5  #include <X11/extensions/scrnsaver.h>
     8.6  #endif
     8.7 -
     8.8 +#if SDL_VIDEO_DRIVER_X11_XRENDER
     8.9 +#include <X11/extensions/Xrender.h>
    8.10 +#endif
    8.11 +#if SDL_VIDEO_DRIVER_X11_XDAMAGE
    8.12 +#include <X11/extensions/Xdamage.h>
    8.13 +#endif
    8.14 +#if SDL_VIDEO_DRIVER_X11_XFIXES
    8.15 +#include <X11/extensions/Xfixes.h>
    8.16 +#endif
    8.17  #include "SDL_x11dyn.h"
    8.18  
    8.19  #include "SDL_x11clipboard.h"