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.
     7.1 --- a/src/video/x11/SDL_x11render.c	Tue Jul 27 21:31:28 2010 -0700
     7.2 +++ b/src/video/x11/SDL_x11render.c	Wed Jul 28 00:54:23 2010 -0700
     7.3 @@ -1,4 +1,5 @@
     7.4  /*
     7.5 +
     7.6      SDL - Simple DirectMedia Layer
     7.7      Copyright (C) 1997-2010 Sam Lantinga
     7.8  
     7.9 @@ -39,6 +40,8 @@
    7.10  static int X11_QueryTexturePixels(SDL_Renderer * renderer,
    7.11                                    SDL_Texture * texture, void **pixels,
    7.12                                    int *pitch);
    7.13 +static int X11_SetTextureRGBAMod(SDL_Renderer * renderer,
    7.14 +                                 SDL_Texture * texture);
    7.15  static int X11_SetTextureBlendMode(SDL_Renderer * renderer,
    7.16                                     SDL_Texture * texture);
    7.17  static int X11_SetTextureScaleMode(SDL_Renderer * renderer,
    7.18 @@ -96,6 +99,25 @@
    7.19      int scanline_pad;
    7.20      Window xwindow;
    7.21      Pixmap pixmaps[3];
    7.22 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
    7.23 +    Pixmap stencil;
    7.24 +    Pixmap brush;
    7.25 +    Picture brush_pict;
    7.26 +    Picture xwindow_pict;
    7.27 +    Picture pixmap_picts[3];
    7.28 +    Picture drawable_pict;
    7.29 +    Picture stencil_pict;
    7.30 +    int blend_op;
    7.31 +    XRenderPictFormat *xwindow_pict_fmt;
    7.32 +    XRenderPictFormat *drawable_pict_fmt;
    7.33 +    GC stencil_gc;
    7.34 +    SDL_bool use_xrender;
    7.35 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
    7.36 +    SDL_bool use_xdamage;
    7.37 +    Damage stencil_damage;
    7.38 +    XserverRegion stencil_parts;
    7.39 +#endif
    7.40 +#endif
    7.41      int current_pixmap;
    7.42      Drawable drawable;
    7.43      SDL_PixelFormat format;
    7.44 @@ -109,6 +131,17 @@
    7.45      SDL_SW_YUVTexture *yuv;
    7.46      Uint32 format;
    7.47      Pixmap pixmap;
    7.48 +    int depth;
    7.49 +    Visual *visual;
    7.50 +    GC gc;
    7.51 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
    7.52 +    Picture picture;
    7.53 +    Pixmap modulated_pixmap;
    7.54 +    Picture modulated_picture;
    7.55 +    XRenderPictFormat* picture_fmt;
    7.56 +    int blend_op;
    7.57 +    const char* filter;
    7.58 +#endif
    7.59      XImage *image;
    7.60  #ifndef NO_SHARED_MEMORY
    7.61      /* MIT shared memory extension information */
    7.62 @@ -149,11 +182,109 @@
    7.63                          texture->h, data->pixels, data->pitch);
    7.64  }
    7.65  
    7.66 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
    7.67 +static SDL_bool
    7.68 +CheckXRender(Display *display, int *major, int *minor) {
    7.69 +    const char *env;
    7.70 +
    7.71 +    *major = *minor = 0;
    7.72 +
    7.73 +    env = SDL_getenv("SDL_VIDEO_X11_XRENDER");
    7.74 +
    7.75 +    if (env && !SDL_atoi(env)) {
    7.76 +        return SDL_FALSE;
    7.77 +    }
    7.78 +
    7.79 +    if (!SDL_X11_HAVE_XRENDER) {
    7.80 +        return SDL_FALSE;
    7.81 +    }
    7.82 +
    7.83 +    if (!XRenderQueryVersion(display, major, minor)) {
    7.84 +        return SDL_FALSE;
    7.85 +    }
    7.86 +
    7.87 +    return SDL_TRUE;
    7.88 +}
    7.89 +#endif
    7.90 +
    7.91 +#ifdef SDL_VIDEO_DRIVER_X11_XFIXES
    7.92 +static SDL_bool
    7.93 +CheckXFixes(Display *display, int *major, int *minor) {
    7.94 +    const char *env;
    7.95 +
    7.96 +    *major = *minor = 0;
    7.97 +
    7.98 +    env = SDL_getenv("SDL_VIDEO_X11_XFIXES");
    7.99 +
   7.100 +    if (env && !SDL_atoi(env)) {
   7.101 +        return SDL_FALSE;
   7.102 +    }
   7.103 +
   7.104 +    if (!SDL_X11_HAVE_XFIXES) {
   7.105 +        return SDL_FALSE;
   7.106 +    }
   7.107 +
   7.108 +    if (!XFixesQueryVersion(display, major, minor)) {
   7.109 +        return SDL_FALSE;
   7.110 +    }
   7.111 +
   7.112 +    return SDL_TRUE;
   7.113 +}
   7.114 +#endif
   7.115 +
   7.116 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
   7.117 +static SDL_bool
   7.118 +CheckXDamage(Display *display, int *major, int *minor) {
   7.119 +    const char *env;
   7.120 +
   7.121 +    *major = *minor = 0;
   7.122 +
   7.123 +    env = SDL_getenv("SDL_VIDEO_X11_XDAMAGE");
   7.124 +
   7.125 +    if (env && !SDL_atoi(env)) {
   7.126 +        return SDL_FALSE;
   7.127 +    }
   7.128 +
   7.129 +    if (!SDL_X11_HAVE_XDAMAGE) {
   7.130 +        return SDL_FALSE;
   7.131 +    }
   7.132 +
   7.133 +    if (!XDamageQueryVersion(display, major, minor)) {
   7.134 +        return SDL_FALSE;
   7.135 +    }
   7.136 +
   7.137 +    return SDL_TRUE;
   7.138 +}
   7.139 +#endif
   7.140 +
   7.141 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   7.142 +static Uint32
   7.143 +XRenderPictFormatToSDLPixelFormatEnum(XRenderPictFormat *pict_format) {
   7.144 +    if (pict_format->type != PictTypeDirect) {
   7.145 +        SDL_SetError("Indexed pict formats not supported ATM");
   7.146 +        return 0;
   7.147 +    }
   7.148 +    Uint32 Amask, Rmask, Gmask, Bmask;
   7.149 +    int bpp;
   7.150 +
   7.151 +    Rmask = pict_format->direct.redMask << pict_format->direct.red;
   7.152 +    Gmask = pict_format->direct.greenMask << pict_format->direct.green;
   7.153 +    Bmask = pict_format->direct.blueMask << pict_format->direct.blue;
   7.154 +    Amask = pict_format->direct.alphaMask << pict_format->direct.alpha;
   7.155 +    bpp = pict_format->depth;
   7.156 +
   7.157 +    Uint32 format;
   7.158 +    format = SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
   7.159 +    return format;
   7.160 +}
   7.161 +#endif
   7.162 +
   7.163  void
   7.164  X11_AddRenderDriver(_THIS)
   7.165  {
   7.166      SDL_RendererInfo *info = &X11_RenderDriver.info;
   7.167      SDL_DisplayMode *mode = &SDL_CurrentDisplay->desktop_mode;
   7.168 +    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
   7.169      int i;
   7.170  
   7.171      info->texture_formats[info->num_texture_formats++] = mode->format;
   7.172 @@ -163,6 +294,34 @@
   7.173      info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_UYVY;
   7.174      info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YVYU;
   7.175  
   7.176 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   7.177 +    int major, minor;
   7.178 +    if (CheckXRender(data->display, &major, &minor)) {
   7.179 +        XRenderPictFormat templ;
   7.180 +        templ.type = PictTypeDirect;
   7.181 +        XRenderPictFormat *pict_format;
   7.182 +        Uint32 format;
   7.183 +        int i = 0;
   7.184 +        while (info->num_texture_formats < 50) {
   7.185 +            pict_format =
   7.186 +                XRenderFindFormat(data->display, PictFormatType, &templ, i++);
   7.187 +            if (pict_format) {
   7.188 +                format = XRenderPictFormatToSDLPixelFormatEnum(pict_format);
   7.189 +                if (format != SDL_PIXELTYPE_UNKNOWN) {
   7.190 +                    info->texture_formats[info->num_texture_formats++] = format;
   7.191 +                }
   7.192 +            }
   7.193 +            else
   7.194 +                break;
   7.195 +        }
   7.196 +        info->blend_modes |= (SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD |
   7.197 +                             SDL_BLENDMODE_MOD | SDL_BLENDMODE_MASK);
   7.198 +        info->scale_modes |= (SDL_TEXTURESCALEMODE_FAST | SDL_TEXTURESCALEMODE_SLOW |
   7.199 +                             SDL_TEXTURESCALEMODE_BEST);
   7.200 +        info->mod_modes |= (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA);
   7.201 +    }
   7.202 +#endif
   7.203 +
   7.204      for (i = 0; i < _this->num_displays; ++i) {
   7.205          SDL_AddRenderDriver(&_this->displays[i], &X11_RenderDriver);
   7.206      }
   7.207 @@ -177,6 +336,7 @@
   7.208      SDL_Renderer *renderer;
   7.209      X11_RenderData *data;
   7.210      XGCValues gcv;
   7.211 +    gcv.graphics_exposures = False;
   7.212      int i, n;
   7.213      int bpp;
   7.214      Uint32 Rmask, Gmask, Bmask, Amask;
   7.215 @@ -199,10 +359,12 @@
   7.216      data->depth = displaydata->depth;
   7.217      data->scanline_pad = displaydata->scanline_pad;
   7.218      data->xwindow = windowdata->xwindow;
   7.219 -
   7.220 +    
   7.221      renderer->DisplayModeChanged = X11_DisplayModeChanged;
   7.222      renderer->CreateTexture = X11_CreateTexture;
   7.223      renderer->QueryTexturePixels = X11_QueryTexturePixels;
   7.224 +    renderer->SetTextureAlphaMod = X11_SetTextureRGBAMod;
   7.225 +    renderer->SetTextureColorMod = X11_SetTextureRGBAMod;
   7.226      renderer->SetTextureBlendMode = X11_SetTextureBlendMode;
   7.227      renderer->SetTextureScaleMode = X11_SetTextureScaleMode;
   7.228      renderer->UpdateTexture = X11_UpdateTexture;
   7.229 @@ -225,6 +387,82 @@
   7.230  
   7.231      renderer->info.flags = SDL_RENDERER_ACCELERATED;
   7.232  
   7.233 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   7.234 +    int major, minor;
   7.235 +    data->use_xrender = CheckXRender(data->display, &major, &minor);
   7.236 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
   7.237 +    if (CheckXDamage(data->display, &major, &minor)) {
   7.238 +        if (CheckXFixes(data->display, &major, &minor)) {
   7.239 +            if (major >= 2)
   7.240 +                data->use_xdamage = SDL_TRUE;
   7.241 +        }
   7.242 +    }
   7.243 +#endif
   7.244 +    if (data->use_xrender) {
   7.245 +        /* Find the PictFormat from the visual.
   7.246 +         * Should be an RGB PictFormat most of the time. */
   7.247 +        data->xwindow_pict_fmt = XRenderFindVisualFormat(data->display,
   7.248 +                                                         data->visual);
   7.249 +        if (!data->xwindow_pict_fmt) {
   7.250 +            SDL_SetError("XRenderFindVisualFormat() failed");
   7.251 +            return NULL;
   7.252 +        }
   7.253 +        data->xwindow_pict = XRenderCreatePicture(data->display,
   7.254 +                                                  data->xwindow,
   7.255 +                                                  data->xwindow_pict_fmt,
   7.256 +                                                  0, NULL);
   7.257 +        if (!data->xwindow_pict) {
   7.258 +            SDL_SetError("XRenderCreatePicture() failed");
   7.259 +            return NULL;
   7.260 +        }
   7.261 +        // FIXME: Clear the window. Is this required?
   7.262 +        XRenderComposite(data->display,
   7.263 +                         PictOpClear,
   7.264 +                         data->xwindow_pict,
   7.265 +                         None,
   7.266 +                         data->xwindow_pict,
   7.267 +                         0, 0,
   7.268 +                         0, 0,
   7.269 +                         0, 0,
   7.270 +                         window->w, window->h);
   7.271 +        /* Create a clip mask that is used for rendering primitives. */
   7.272 +        data->stencil = XCreatePixmap(data->display, data->xwindow,
   7.273 +                                   window->w, window->h, 32);
   7.274 +        
   7.275 +        /* Create the GC for the clip mask. */
   7.276 +        data->stencil_gc = XCreateGC(data->display, data->stencil,
   7.277 +                                  GCGraphicsExposures, &gcv);
   7.278 +        XSetBackground(data->display, data->stencil_gc, 0);
   7.279 +        XSetForeground(data->display, data->stencil_gc, 0);
   7.280 +        XFillRectangle(data->display, data->stencil, data->stencil_gc,
   7.281 +                       0, 0, window->w, window->h);
   7.282 +        XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF);
   7.283 +        data->stencil_pict =
   7.284 +            XRenderCreatePicture(data->display, data->stencil,
   7.285 +                                 XRenderFindStandardFormat(data->display,
   7.286 +                                                           PictStandardARGB32),
   7.287 +                                 0, NULL);
   7.288 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
   7.289 +        if (data->use_xdamage) {
   7.290 +            data->stencil_damage =
   7.291 +                XDamageCreate(data->display, data->stencil, XDamageReportNonEmpty);
   7.292 +            XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts);
   7.293 +        }
   7.294 +#endif
   7.295 +        data->brush =
   7.296 +            XCreatePixmap(data->display, data->xwindow, 1, 1, 32);
   7.297 +        XRenderPictureAttributes brush_attr;
   7.298 +        brush_attr.repeat = RepeatNormal;
   7.299 +        data->brush_pict =
   7.300 +            XRenderCreatePicture(data->display, data->brush,
   7.301 +                                 XRenderFindStandardFormat(data->display,
   7.302 +                                                           PictStandardARGB32),
   7.303 +                                 CPRepeat, &brush_attr);
   7.304 +        // Set the default blending mode.
   7.305 +        renderer->blendMode = SDL_BLENDMODE_BLEND;
   7.306 +        data->blend_op = PictOpOver;
   7.307 +    }
   7.308 +#endif
   7.309      if (flags & SDL_RENDERER_SINGLEBUFFER) {
   7.310          renderer->info.flags |=
   7.311              (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY);
   7.312 @@ -239,39 +477,110 @@
   7.313          renderer->info.flags |= SDL_RENDERER_PRESENTCOPY;
   7.314          n = 1;
   7.315      }
   7.316 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   7.317 +    if (data->use_xrender) {
   7.318 +        if (n > 0)
   7.319 +            data->drawable_pict_fmt =
   7.320 +                XRenderFindStandardFormat(data->display, PictStandardARGB32);
   7.321 +        else
   7.322 +            data->drawable_pict_fmt = data->xwindow_pict_fmt;
   7.323 +    }
   7.324 +#endif
   7.325      for (i = 0; i < n; ++i) {
   7.326 -        data->pixmaps[i] =
   7.327 -            XCreatePixmap(data->display, data->xwindow, window->w, window->h,
   7.328 -                          displaydata->depth);
   7.329 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   7.330 +        if (data->use_xrender) {
   7.331 +            data->pixmaps[i] = XCreatePixmap(data->display,
   7.332 +                                             data->xwindow,
   7.333 +                                             window->w,
   7.334 +                                             window->h,
   7.335 +                                             32);
   7.336 +        }
   7.337 +        else
   7.338 +#endif
   7.339 +        {
   7.340 +            data->pixmaps[i] =
   7.341 +                XCreatePixmap(data->display, data->xwindow, window->w, window->h,
   7.342 +                              displaydata->depth);
   7.343 +        }
   7.344          if (data->pixmaps[i] == None) {
   7.345              X11_DestroyRenderer(renderer);
   7.346              SDL_SetError("XCreatePixmap() failed");
   7.347              return NULL;
   7.348          }
   7.349 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   7.350 +        if (data->use_xrender) {
   7.351 +            /* Create xrender pictures for each of the pixmaps
   7.352 +             * and clear the pixmaps. */
   7.353 +            data->pixmap_picts[i] = 
   7.354 +                XRenderCreatePicture(data->display,
   7.355 +                                     data->pixmaps[i],
   7.356 +                                     XRenderFindStandardFormat(data->display,
   7.357 +                                                               PictStandardARGB32),
   7.358 +                                     0, None);
   7.359 +            if (!data->pixmap_picts[i]) {
   7.360 +                SDL_SetError("XRenderCreatePicture() failed");
   7.361 +                return NULL;
   7.362 +            }
   7.363 +
   7.364 +            XRenderComposite(data->display,
   7.365 +                             PictOpClear,
   7.366 +                             data->pixmap_picts[i],
   7.367 +                             None,
   7.368 +                             data->pixmap_picts[i],
   7.369 +                             0, 0,
   7.370 +                             0, 0,
   7.371 +                             0, 0,
   7.372 +                             window->w, window->h);
   7.373 +        }
   7.374 +#endif
   7.375      }
   7.376      if (n > 0) {
   7.377          data->drawable = data->pixmaps[0];
   7.378 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   7.379 +        if(data->use_xrender == SDL_TRUE)
   7.380 +            data->drawable_pict = data->pixmap_picts[0];
   7.381 +#endif
   7.382          data->makedirty = SDL_TRUE;
   7.383      } else {
   7.384          data->drawable = data->xwindow;
   7.385 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   7.386 +        if(data->use_xrender == SDL_TRUE)
   7.387 +            data->drawable_pict = data->xwindow_pict;
   7.388 +#endif
   7.389          data->makedirty = SDL_FALSE;
   7.390      }
   7.391      data->current_pixmap = 0;
   7.392  
   7.393 -    /* Get the format of the window */
   7.394 -    if (!SDL_PixelFormatEnumToMasks
   7.395 -        (display->current_mode.format, &bpp, &Rmask, &Gmask, &Bmask,
   7.396 -         &Amask)) {
   7.397 -        SDL_SetError("Unknown display format");
   7.398 -        X11_DestroyRenderer(renderer);
   7.399 -        return NULL;
   7.400 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   7.401 +    if (data->use_xrender) {
   7.402 +        bpp = data->drawable_pict_fmt->depth;
   7.403 +        Rmask = ((data->drawable_pict_fmt->direct.redMask)
   7.404 +                    << (data->drawable_pict_fmt->direct.red));
   7.405 +        Gmask = ((data->drawable_pict_fmt->direct.greenMask)
   7.406 +                    << (data->drawable_pict_fmt->direct.green));
   7.407 +        Bmask = ((data->drawable_pict_fmt->direct.blueMask)
   7.408 +                    << (data->drawable_pict_fmt->direct.blue));
   7.409 +        Amask = ((data->drawable_pict_fmt->direct.alphaMask)
   7.410 +                    << (data->drawable_pict_fmt->direct.alpha));
   7.411 +    }
   7.412 +    else
   7.413 +#endif
   7.414 +    {
   7.415 +        /* Get the format of the window */
   7.416 +        if (!SDL_PixelFormatEnumToMasks
   7.417 +            (display->current_mode.format, &bpp, &Rmask, &Gmask, &Bmask,
   7.418 +             &Amask)) {
   7.419 +            SDL_SetError("Unknown display format");
   7.420 +            X11_DestroyRenderer(renderer);
   7.421 +            return NULL;
   7.422 +        }
   7.423      }
   7.424      SDL_InitFormat(&data->format, bpp, Rmask, Gmask, Bmask, Amask);
   7.425  
   7.426      /* Create the drawing context */
   7.427      gcv.graphics_exposures = False;
   7.428      data->gc =
   7.429 -        XCreateGC(data->display, data->xwindow, GCGraphicsExposures, &gcv);
   7.430 +        XCreateGC(data->display, data->drawable, GCGraphicsExposures, &gcv);
   7.431      if (!data->gc) {
   7.432          X11_DestroyRenderer(renderer);
   7.433          SDL_SetError("XCreateGC() failed");
   7.434 @@ -288,6 +597,47 @@
   7.435      SDL_Window *window = renderer->window;
   7.436      int i, n;
   7.437  
   7.438 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   7.439 +    if (data->use_xrender) {
   7.440 +        XRenderFreePicture(data->display, data->xwindow_pict);
   7.441 +        
   7.442 +        data->xwindow_pict_fmt =
   7.443 +            XRenderFindVisualFormat(data->display, data->visual);
   7.444 +        data->xwindow_pict =
   7.445 +            XRenderCreatePicture(data->display, data->xwindow,
   7.446 +                                 data->xwindow_pict_fmt, 0, NULL);
   7.447 +        
   7.448 +        XRenderComposite(data->display,
   7.449 +                         PictOpClear,
   7.450 +                         data->xwindow_pict,
   7.451 +                         None,
   7.452 +                         data->xwindow_pict,
   7.453 +                         0, 0,
   7.454 +                         0, 0,
   7.455 +                         0, 0,
   7.456 +                         window->w, window->h);
   7.457 +        
   7.458 +        XFreePixmap(data->display, data->stencil);
   7.459 +        /* Create a clip mask that is used for rendering primitives. */
   7.460 +        data->stencil = XCreatePixmap(data->display, data->xwindow,
   7.461 +                                   window->w, window->h, 32);
   7.462 +        
   7.463 +        XRenderFreePicture(data->display, data->stencil_pict);
   7.464 +        data->stencil_pict =
   7.465 +            XRenderCreatePicture(data->display, data->stencil,
   7.466 +                                 XRenderFindStandardFormat(data->display,
   7.467 +                                                           PictStandardARGB32),
   7.468 +                                 0, NULL);
   7.469 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
   7.470 +        XDamageDestroy(data->display, data->stencil_damage);
   7.471 +        if (data->use_xdamage) {
   7.472 +            data->stencil_damage =
   7.473 +                XDamageCreate(data->display, data->stencil, XDamageReportNonEmpty);
   7.474 +            XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts);
   7.475 +        }
   7.476 +#endif
   7.477 +    }
   7.478 +#endif
   7.479      if (renderer->info.flags & SDL_RENDERER_SINGLEBUFFER) {
   7.480          n = 0;
   7.481      } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
   7.482 @@ -301,25 +651,170 @@
   7.483          if (data->pixmaps[i] != None) {
   7.484              XFreePixmap(data->display, data->pixmaps[i]);
   7.485              data->pixmaps[i] = None;
   7.486 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   7.487 +            XRenderFreePicture(data->display, data->pixmap_picts[i]);
   7.488 +            data->pixmap_picts[i] = None;
   7.489 +#endif
   7.490          }
   7.491      }
   7.492      for (i = 0; i < n; ++i) {
   7.493 -        data->pixmaps[i] =
   7.494 -            XCreatePixmap(data->display, data->xwindow, window->w, window->h,
   7.495 -                          data->depth);
   7.496 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   7.497 +        if (data->use_xrender) {
   7.498 +            data->pixmaps[i] =
   7.499 +                XCreatePixmap(data->display,
   7.500 +                              data->xwindow,
   7.501 +                              window->w,
   7.502 +                              window->h,
   7.503 +                              32);
   7.504 +        }
   7.505 +        else
   7.506 +#endif
   7.507 +        {
   7.508 +            data->pixmaps[i] =
   7.509 +                XCreatePixmap(data->display, data->xwindow, window->w, window->h,
   7.510 +                              data->depth);
   7.511 +        }
   7.512          if (data->pixmaps[i] == None) {
   7.513              SDL_SetError("XCreatePixmap() failed");
   7.514              return -1;
   7.515          }
   7.516 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   7.517 +        if (data->use_xrender) {
   7.518 +            data->pixmap_picts[i] = 
   7.519 +                XRenderCreatePicture(data->display,
   7.520 +                                     data->pixmaps[i],
   7.521 +                                     XRenderFindStandardFormat(data->display,
   7.522 +                                                               PictStandardARGB32),
   7.523 +                                     0, None);
   7.524 +            if (!data->pixmap_picts[i]) {
   7.525 +                SDL_SetError("XRenderCreatePicture() failed");
   7.526 +                return -1;
   7.527 +            }
   7.528 +            XRenderComposite(data->display,
   7.529 +                             PictOpClear,
   7.530 +                             data->pixmap_picts[i],
   7.531 +                             None,
   7.532 +                             data->pixmap_picts[i],
   7.533 +                             0, 0,
   7.534 +                             0, 0,
   7.535 +                             0, 0,
   7.536 +                             window->w, window->h);
   7.537 +
   7.538 +       }
   7.539 +#endif
   7.540      }
   7.541      if (n > 0) {
   7.542          data->drawable = data->pixmaps[0];
   7.543 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   7.544 +        data->drawable_pict = data->pixmap_picts[0];
   7.545 +#endif
   7.546      }
   7.547      data->current_pixmap = 0;
   7.548  
   7.549      return 0;
   7.550  }
   7.551  
   7.552 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   7.553 +static void
   7.554 +SDLMaskToXRenderMask(Uint32 sdl_mask, short *comp, short *compMask) {
   7.555 +    if (sdl_mask == 0) {
   7.556 +        *comp = 0;
   7.557 +        *compMask = 0;
   7.558 +    } else {
   7.559 +        (*comp) = 0;
   7.560 +        (*compMask) = 0;
   7.561 +        while(!(sdl_mask & 1)) {
   7.562 +            (*comp)++;
   7.563 +            sdl_mask >>= 1;
   7.564 +        }
   7.565 +        while(sdl_mask & 1) {
   7.566 +            (*compMask) = ((*compMask) << 1) | 1;
   7.567 +            sdl_mask >>= 1;
   7.568 +        }
   7.569 +    }
   7.570 +}
   7.571 +
   7.572 +static XRenderPictFormat*
   7.573 +PixelFormatEnumToXRenderPictFormat(SDL_Renderer * renderer, Uint32 format) {
   7.574 +    XRenderPictFormat* pict_fmt = NULL;
   7.575 +    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
   7.576 +    
   7.577 +    if (data->use_xrender) {
   7.578 +
   7.579 +        int bpp;
   7.580 +        Uint32 Amask, Rmask, Gmask, Bmask;
   7.581 +        if(!SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
   7.582 +            SDL_SetError("Unknown pixel format");
   7.583 +            return NULL;
   7.584 +        }
   7.585 +        XRenderPictFormat templ;
   7.586 +        unsigned long mask = (PictFormatType | PictFormatDepth | PictFormatRed |
   7.587 +                              PictFormatRedMask | PictFormatGreen | PictFormatGreenMask |
   7.588 +                              PictFormatBlue | PictFormatBlueMask | PictFormatAlpha |
   7.589 +                              PictFormatAlphaMask);
   7.590 +
   7.591 +        templ.type = PictTypeDirect;
   7.592 +        templ.depth = bpp;
   7.593 +        SDLMaskToXRenderMask(Amask, &(templ.direct.alpha), &(templ.direct.alphaMask));
   7.594 +        SDLMaskToXRenderMask(Rmask, &(templ.direct.red), &(templ.direct.redMask));
   7.595 +        SDLMaskToXRenderMask(Gmask, &(templ.direct.green), &(templ.direct.greenMask));
   7.596 +        SDLMaskToXRenderMask(Bmask, &(templ.direct.blue), &(templ.direct.blueMask));
   7.597 +        pict_fmt = XRenderFindFormat(data->display, mask, &templ, 0);
   7.598 +    }
   7.599 +    
   7.600 +    return pict_fmt;
   7.601 +}
   7.602 +
   7.603 +
   7.604 +static Visual*
   7.605 +PixelFormatEnumToVisual(SDL_Renderer * renderer, Uint32 format) {
   7.606 +    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
   7.607 +
   7.608 +    if (data->use_xrender) {
   7.609 +        int bpp;
   7.610 +        Uint32 Amask, Rmask, Gmask, Bmask;
   7.611 +        SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
   7.612 +
   7.613 +        XVisualInfo vinfo_templ;
   7.614 +        long vinfo_mask;
   7.615 +        int nitems_return;
   7.616 +
   7.617 +        vinfo_mask = (VisualDepthMask | VisualRedMaskMask |
   7.618 +                      VisualGreenMaskMask | VisualBlueMaskMask);
   7.619 +        vinfo_templ.depth = bpp;
   7.620 +        vinfo_templ.red_mask = Rmask;
   7.621 +        vinfo_templ.green_mask = Gmask;
   7.622 +        vinfo_templ.blue_mask = Bmask;
   7.623 +
   7.624 +        XVisualInfo * ret = XGetVisualInfo(data->display, vinfo_mask,
   7.625 +                                           &vinfo_templ, &nitems_return);
   7.626 +        
   7.627 +        if (nitems_return) {
   7.628 +            return ret[0].visual;
   7.629 +        }
   7.630 +    }
   7.631 +
   7.632 +    return NULL;
   7.633 +}
   7.634 +
   7.635 +static XRenderColor
   7.636 +SDLColorToXRenderColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
   7.637 +    double rd, gd, bd, ad;
   7.638 +    XRenderColor ret;
   7.639 +    rd = r / 255.0;
   7.640 +    gd = g / 255.0;
   7.641 +    bd = b / 255.0;
   7.642 +    ad = a / 255.0;
   7.643 +    
   7.644 +    ret.red = (unsigned short) (rd * ad * 0xFFFF);
   7.645 +    ret.green = (unsigned short) (gd * ad * 0xFFFF);
   7.646 +    ret.blue = (unsigned short) (bd * ad * 0xFFFF);
   7.647 +    ret.alpha = (unsigned short) (ad * 0xFFFF);
   7.648 +
   7.649 +    return ret;
   7.650 +}
   7.651 +#endif
   7.652 +
   7.653  static int
   7.654  X11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   7.655  {
   7.656 @@ -328,15 +823,18 @@
   7.657      SDL_VideoDisplay *display = window->display;
   7.658      X11_TextureData *data;
   7.659      int pitch_alignmask = ((renderdata->scanline_pad / 8) - 1);
   7.660 -
   7.661 +    XGCValues gcv;
   7.662 +    
   7.663      data = (X11_TextureData *) SDL_calloc(1, sizeof(*data));
   7.664      if (!data) {
   7.665          SDL_OutOfMemory();
   7.666          return -1;
   7.667      }
   7.668 +    data->depth = renderdata->depth;
   7.669 +    data->visual = renderdata->visual;
   7.670 +    data->gc = renderdata->gc;
   7.671  
   7.672      texture->driverdata = data;
   7.673 -
   7.674      if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   7.675          data->yuv =
   7.676              SDL_SW_CreateYUVTexture(texture->format, texture->w, texture->h);
   7.677 @@ -345,18 +843,26 @@
   7.678          }
   7.679          data->format = display->current_mode.format;
   7.680      } else {
   7.681 -        /* The image/pixmap depth must be the same as the window or you
   7.682 -           get a BadMatch error when trying to putimage or copyarea.
   7.683 -         */
   7.684 -        if (texture->format != display->current_mode.format) {
   7.685 -            SDL_SetError("Texture format doesn't match window format");
   7.686 -            return -1;
   7.687 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   7.688 +        if (renderdata->use_xrender)
   7.689 +        {
   7.690 +            Uint32 Amask, Rmask, Gmask, Bmask;
   7.691 +            SDL_PixelFormatEnumToMasks(texture->format, &(data->depth),
   7.692 +                                       &Rmask, &Gmask, &Bmask, &Amask);
   7.693 +            data->visual = PixelFormatEnumToVisual(renderer, texture->format);
   7.694 +        }
   7.695 +        else
   7.696 +#endif
   7.697 +        {
   7.698 +            if (texture->format != display->current_mode.format)
   7.699 +            {
   7.700 +                SDL_SetError("Texture format doesn't match window format");
   7.701 +                return -1;
   7.702 +            }
   7.703          }
   7.704          data->format = texture->format;
   7.705      }
   7.706 -    data->pitch = texture->w * SDL_BYTESPERPIXEL(data->format);
   7.707 -    data->pitch = (data->pitch + pitch_alignmask) & ~pitch_alignmask;
   7.708 -
   7.709 +    
   7.710      if (data->yuv || texture->access == SDL_TEXTUREACCESS_STREAMING) {
   7.711  #ifndef NO_SHARED_MEMORY
   7.712          XShmSegmentInfo *shminfo = &data->shminfo;
   7.713 @@ -364,37 +870,42 @@
   7.714          shm_error = True;
   7.715  
   7.716          if (SDL_X11_HAVE_SHM) {
   7.717 -            shminfo->shmid =
   7.718 -                shmget(IPC_PRIVATE, texture->h * data->pitch,
   7.719 -                       IPC_CREAT | 0777);
   7.720 -            if (shminfo->shmid >= 0) {
   7.721 -                shminfo->shmaddr = (char *) shmat(shminfo->shmid, 0, 0);
   7.722 -                shminfo->readOnly = False;
   7.723 -                if (shminfo->shmaddr != (char *) -1) {
   7.724 -                    shm_error = False;
   7.725 -                    X_handler = XSetErrorHandler(shm_errhandler);
   7.726 -                    XShmAttach(renderdata->display, shminfo);
   7.727 -                    XSync(renderdata->display, False);
   7.728 -                    XSetErrorHandler(X_handler);
   7.729 -                    if (shm_error) {
   7.730 -                        shmdt(shminfo->shmaddr);
   7.731 +            data->image =
   7.732 +                XShmCreateImage(renderdata->display, data->visual,
   7.733 +                                data->depth, ZPixmap, NULL,
   7.734 +                                shminfo, texture->w, texture->h);
   7.735 +            if (data->image) {
   7.736 +                shminfo->shmid =
   7.737 +                    shmget(IPC_PRIVATE, texture->h * data->image->bytes_per_line,
   7.738 +                           IPC_CREAT | 0777);
   7.739 +                if (shminfo->shmid >= 0) {
   7.740 +                    shminfo->shmaddr = (char *) shmat(shminfo->shmid, 0, 0);
   7.741 +                    shminfo->readOnly = False;
   7.742 +                    if (shminfo->shmaddr != (char *) -1) {
   7.743 +                        shm_error = False;
   7.744 +                        X_handler = XSetErrorHandler(shm_errhandler);
   7.745 +                        XShmAttach(renderdata->display, shminfo);
   7.746 +                        XSync(renderdata->display, False);
   7.747 +                        XSetErrorHandler(X_handler);
   7.748 +                        if (shm_error) {
   7.749 +                            XShmDetach(renderdata->display, shminfo);
   7.750 +                            shmdt(shminfo->shmaddr);
   7.751 +                            XDestroyImage(data->image);
   7.752 +                            XSync(renderdata->display, False);
   7.753 +                        }
   7.754 +                        else {
   7.755 +                            data->pixels = data->image->data = shminfo->shmaddr;
   7.756 +                            shmctl(shminfo->shmid, IPC_RMID, NULL);
   7.757 +                            data->pixmap =
   7.758 +                                XCreatePixmap(renderdata->display, renderdata->xwindow,
   7.759 +                                              texture->w, texture->h, data->depth);
   7.760 +                            if (!data->pixmap) {
   7.761 +                                SDL_SetError("XCreatePixmap() failed");
   7.762 +                                return -1;
   7.763 +                            }
   7.764 +                        }
   7.765                      }
   7.766                  }
   7.767 -                shmctl(shminfo->shmid, IPC_RMID, NULL);
   7.768 -            }
   7.769 -        }
   7.770 -        if (!shm_error) {
   7.771 -            data->pixels = shminfo->shmaddr;
   7.772 -
   7.773 -            data->image =
   7.774 -                XShmCreateImage(renderdata->display, renderdata->visual,
   7.775 -                                renderdata->depth, ZPixmap, shminfo->shmaddr,
   7.776 -                                shminfo, texture->w, texture->h);
   7.777 -            if (!data->image) {
   7.778 -                XShmDetach(renderdata->display, shminfo);
   7.779 -                XSync(renderdata->display, False);
   7.780 -                shmdt(shminfo->shmaddr);
   7.781 -                shm_error = True;
   7.782              }
   7.783          }
   7.784          if (shm_error) {
   7.785 @@ -403,47 +914,102 @@
   7.786          if (!data->image)
   7.787  #endif /* not NO_SHARED_MEMORY */
   7.788          {
   7.789 -            data->pixels = SDL_malloc(texture->h * data->pitch);
   7.790 -            if (!data->pixels) {
   7.791 -                X11_DestroyTexture(renderer, texture);
   7.792 -                SDL_OutOfMemory();
   7.793 -                return -1;
   7.794 -            }
   7.795 -
   7.796              data->image =
   7.797 -                XCreateImage(renderdata->display, renderdata->visual,
   7.798 -                             renderdata->depth, ZPixmap, 0, data->pixels,
   7.799 +                XCreateImage(renderdata->display, data->visual,
   7.800 +                             data->depth, ZPixmap, 0, NULL,
   7.801                               texture->w, texture->h,
   7.802                               SDL_BYTESPERPIXEL(data->format) * 8,
   7.803 -                             data->pitch);
   7.804 +                             0);
   7.805              if (!data->image) {
   7.806                  X11_DestroyTexture(renderer, texture);
   7.807                  SDL_SetError("XCreateImage() failed");
   7.808                  return -1;
   7.809              }
   7.810 +            data->pixels = SDL_malloc(texture->h * data->image->bytes_per_line);
   7.811 +            if (!data->pixels) {
   7.812 +                X11_DestroyTexture(renderer, texture);
   7.813 +                SDL_OutOfMemory();
   7.814 +                return -1;
   7.815 +            }
   7.816 +            data->image->data = data->pixels;
   7.817 +            data->pixmap =
   7.818 +                XCreatePixmap(renderdata->display, renderdata->xwindow, texture->w,
   7.819 +                              texture->h, data->depth);
   7.820 +            if (data->pixmap == None) {
   7.821 +                X11_DestroyTexture(renderer, texture);
   7.822 +                SDL_SetError("XCreatePixmap() failed");
   7.823 +                return -1;
   7.824 +            }
   7.825          }
   7.826 -    } else {
   7.827 +    } 
   7.828 +    else {
   7.829 +        data->image =
   7.830 +            XCreateImage(renderdata->display, data->visual,
   7.831 +                         data->depth, ZPixmap, 0, NULL,
   7.832 +                         texture->w, texture->h,
   7.833 +                         SDL_BYTESPERPIXEL(data->format) * 8,
   7.834 +                         0);
   7.835 +        if (!data->image) {
   7.836 +            X11_DestroyTexture(renderer, texture);
   7.837 +            SDL_SetError("XCreateImage() failed");
   7.838 +            return -1;
   7.839 +        }
   7.840          data->pixmap =
   7.841              XCreatePixmap(renderdata->display, renderdata->xwindow, texture->w,
   7.842 -                          texture->h, renderdata->depth);
   7.843 +                          texture->h, data->depth);
   7.844          if (data->pixmap == None) {
   7.845              X11_DestroyTexture(renderer, texture);
   7.846              SDL_SetError("XCreatePixmap() failed");
   7.847              return -1;
   7.848          }
   7.849 +    }
   7.850  
   7.851 -        data->image =
   7.852 -            XCreateImage(renderdata->display, renderdata->visual,
   7.853 -                         renderdata->depth, ZPixmap, 0, NULL, texture->w,
   7.854 -                         texture->h, SDL_BYTESPERPIXEL(data->format) * 8,
   7.855 -                         data->pitch);
   7.856 -        if (!data->image) {
   7.857 +    data->pitch = data->image->bytes_per_line;
   7.858 +
   7.859 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   7.860 +    if(renderdata->use_xrender) {
   7.861 +        gcv.graphics_exposures = False;
   7.862 +        data->gc =
   7.863 +            XCreateGC(renderdata->display, data->pixmap, GCGraphicsExposures, &gcv);
   7.864 +        if (!data->gc) {
   7.865 +            SDL_SetError("XCreateGC() failed");
   7.866 +            return -1;
   7.867 +        }
   7.868 +        data->picture_fmt =
   7.869 +            PixelFormatEnumToXRenderPictFormat(renderer, texture->format);
   7.870 +        if (data->picture_fmt == NULL) {
   7.871              X11_DestroyTexture(renderer, texture);
   7.872 -            SDL_SetError("XCreateImage() failed");
   7.873 +            SDL_SetError("Texture format not supported by driver");
   7.874              return -1;
   7.875          }
   7.876 +        data->picture =
   7.877 +            XRenderCreatePicture(renderdata->display, data->pixmap,
   7.878 +                                 data->picture_fmt, 0, NULL);
   7.879 +        if (!data->picture) {
   7.880 +            X11_DestroyTexture(renderer, texture);
   7.881 +            SDL_SetError("XRenderCreatePicture() failed");
   7.882 +            return -1;
   7.883 +        }
   7.884 +        data->modulated_pixmap =
   7.885 +            XCreatePixmap(renderdata->display, renderdata->xwindow,
   7.886 +                          texture->w, texture->h, data->depth);
   7.887 +        if (!data->modulated_pixmap) {
   7.888 +            X11_DestroyTexture(renderer, texture);
   7.889 +            SDL_SetError("XCreatePixmap() failed");
   7.890 +            return -1;
   7.891 +        }
   7.892 +        data->modulated_picture =
   7.893 +            XRenderCreatePicture(renderdata->display, data->modulated_pixmap,
   7.894 +                                 data->picture_fmt, 0, NULL);
   7.895 +        if (!data->modulated_picture) {
   7.896 +            X11_DestroyTexture(renderer, texture);
   7.897 +            SDL_SetError("XRenderCreatePicture() failed");
   7.898 +            return -1;
   7.899 +        }
   7.900 +        texture->blendMode = SDL_BLENDMODE_NONE;
   7.901 +        data->blend_op = PictOpSrc;
   7.902      }
   7.903 -
   7.904 +#endif
   7.905      return 0;
   7.906  }
   7.907  
   7.908 @@ -463,14 +1029,106 @@
   7.909  }
   7.910  
   7.911  static int
   7.912 +X11_SetTextureRGBAMod(SDL_Renderer * renderer, SDL_Texture * texture)
   7.913 +{
   7.914 +
   7.915 +    X11_TextureData *data = (X11_TextureData *) texture->driverdata;
   7.916 +    X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
   7.917 +
   7.918 +    if (renderdata->use_xrender) {
   7.919 +
   7.920 +        Uint8 r = 0xFF, g = 0xFF, b = 0xFF, a = 0xFF;
   7.921 +
   7.922 +        /* Check if alpha modulation is required. */
   7.923 +        if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) {
   7.924 +            a = texture->a;
   7.925 +        }
   7.926 +
   7.927 +        /* Check if color modulation is required. */
   7.928 +        if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
   7.929 +            r = texture->r;
   7.930 +            g = texture->g;
   7.931 +            b = texture->b;
   7.932 +        }
   7.933 +
   7.934 +        /* We can save some labour if no modulation is required. */
   7.935 +        if (texture->modMode != SDL_TEXTUREMODULATE_NONE) {
   7.936 +            XRenderColor mod_color =
   7.937 +                SDLColorToXRenderColor(r, g, b, a);
   7.938 +            XRenderFillRectangle(renderdata->display, PictOpSrc,
   7.939 +                                 renderdata->brush_pict, &mod_color,
   7.940 +                                 0, 0, 1, 1);
   7.941 +        }
   7.942 +
   7.943 +        /* We can save some labour dealing with component alpha
   7.944 +         * if color modulation is not required. */
   7.945 +        XRenderPictureAttributes attr;
   7.946 +        if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
   7.947 +            attr.component_alpha = True;
   7.948 +            XRenderChangePicture(renderdata->display, renderdata->brush_pict,
   7.949 +                                 CPComponentAlpha, &attr);
   7.950 +        }
   7.951 +
   7.952 +        /* Again none of this is necessary is no modulation
   7.953 +         * is required. */
   7.954 +        if (texture->modMode != SDL_TEXTUREMODULATE_NONE) {
   7.955 +            XRenderComposite(renderdata->display, PictOpSrc,
   7.956 +                             data->picture, renderdata->brush_pict,
   7.957 +                             data->modulated_picture,
   7.958 +                             0, 0, 0, 0, 0, 0, texture->w, texture->h);
   7.959 +        }
   7.960 +
   7.961 +        /* We only need to reset the component alpha
   7.962 +         * attribute if color modulation is required. */
   7.963 +        if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) { 
   7.964 +            attr.component_alpha = False;
   7.965 +            XRenderChangePicture(renderdata->display, renderdata->brush_pict,
   7.966 +                                 CPComponentAlpha, &attr);
   7.967 +        }
   7.968 +
   7.969 +        return 0;
   7.970 +    }
   7.971 +    else {
   7.972 +        SDL_Unsupported();
   7.973 +        return -1;
   7.974 +    }
   7.975 +}
   7.976 +
   7.977 +static int
   7.978  X11_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
   7.979  {
   7.980 +    X11_TextureData *data = (X11_TextureData *) texture->driverdata;
   7.981 +    X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
   7.982      switch (texture->blendMode) {
   7.983      case SDL_BLENDMODE_NONE:
   7.984 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   7.985 +        if (renderdata->use_xrender) {
   7.986 +            data->blend_op = PictOpSrc;
   7.987 +            return 0;
   7.988 +        }
   7.989 +    case SDL_BLENDMODE_MOD:
   7.990 +    case SDL_BLENDMODE_MASK:
   7.991 +    case SDL_BLENDMODE_BLEND:
   7.992 +        if (renderdata->use_xrender) {
   7.993 +            data->blend_op = PictOpOver;
   7.994 +            return 0;
   7.995 +        }
   7.996 +    case SDL_BLENDMODE_ADD:
   7.997 +        if (renderdata->use_xrender) {
   7.998 +            data->blend_op = PictOpAdd;
   7.999 +            return 0;
  7.1000 +        }
  7.1001 +#endif
  7.1002          return 0;
  7.1003      default:
  7.1004          SDL_Unsupported();
  7.1005          texture->blendMode = SDL_BLENDMODE_NONE;
  7.1006 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  7.1007 +        if (renderdata->use_xrender) {
  7.1008 +            texture->blendMode = SDL_BLENDMODE_BLEND;
  7.1009 +            data->blend_op = PictOpOver;
  7.1010 +        }
  7.1011 +#endif
  7.1012          return -1;
  7.1013      }
  7.1014  }
  7.1015 @@ -479,6 +1137,7 @@
  7.1016  X11_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
  7.1017  {
  7.1018      X11_TextureData *data = (X11_TextureData *) texture->driverdata;
  7.1019 +    X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
  7.1020  
  7.1021      switch (texture->scaleMode) {
  7.1022      case SDL_TEXTURESCALEMODE_NONE:
  7.1023 @@ -488,10 +1147,33 @@
  7.1024          if (data->yuv || texture->access == SDL_TEXTUREACCESS_STREAMING) {
  7.1025              return 0;
  7.1026          }
  7.1027 -        /* Fall through to unsupported case */
  7.1028 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  7.1029 +        if (renderdata->use_xrender) {
  7.1030 +            data->filter = FilterFast;
  7.1031 +            return 0;
  7.1032 +        }
  7.1033 +    case SDL_TEXTURESCALEMODE_SLOW:
  7.1034 +        if (renderdata->use_xrender) {
  7.1035 +            data->filter = FilterGood;
  7.1036 +            return 0;
  7.1037 +        }
  7.1038 +    case SDL_TEXTURESCALEMODE_BEST:
  7.1039 +        if (renderdata->use_xrender) {
  7.1040 +            data->filter = FilterBest;
  7.1041 +            return 0;
  7.1042 +        }
  7.1043 +#endif
  7.1044 +    /* Fall through to unsupported case */
  7.1045      default:
  7.1046          SDL_Unsupported();
  7.1047 -        texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
  7.1048 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  7.1049 +        if (renderdata->use_xrender) {
  7.1050 +            texture->scaleMode = SDL_TEXTURESCALEMODE_FAST;
  7.1051 +            data->filter = FilterFast;
  7.1052 +        }
  7.1053 +        else
  7.1054 +#endif
  7.1055 +            texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
  7.1056          return -1;
  7.1057      }
  7.1058      return 0;
  7.1059 @@ -532,7 +1214,7 @@
  7.1060              data->image->height = rect->h;
  7.1061              data->image->data = (char *) pixels;
  7.1062              data->image->bytes_per_line = pitch;
  7.1063 -            XPutImage(renderdata->display, data->pixmap, renderdata->gc,
  7.1064 +            XPutImage(renderdata->display, data->pixmap, data->gc,
  7.1065                        data->image, 0, 0, rect->x, rect->y, rect->w, rect->h);
  7.1066          }
  7.1067          return 0;
  7.1068 @@ -575,12 +1257,36 @@
  7.1069  static int
  7.1070  X11_SetDrawBlendMode(SDL_Renderer * renderer)
  7.1071  {
  7.1072 +    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
  7.1073      switch (renderer->blendMode) {
  7.1074      case SDL_BLENDMODE_NONE:
  7.1075 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  7.1076 +        //PictOpSrc
  7.1077 +        data->blend_op = PictOpSrc;
  7.1078 +        return 0;
  7.1079 +    case SDL_BLENDMODE_MOD:
  7.1080 +    case SDL_BLENDMODE_MASK:
  7.1081 +    case SDL_BLENDMODE_BLEND: // PictOpOver
  7.1082 +        data->blend_op = PictOpOver;
  7.1083 +        return 0;
  7.1084 +    case SDL_BLENDMODE_ADD: // PictOpAdd
  7.1085 +        data->blend_op = PictOpAdd;
  7.1086 +        return 0;
  7.1087 +    /* FIXME case SDL_BLENDMODE_MOD: */
  7.1088 +#endif
  7.1089          return 0;
  7.1090      default:
  7.1091          SDL_Unsupported();
  7.1092 -        renderer->blendMode = SDL_BLENDMODE_NONE;
  7.1093 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  7.1094 +        if(data->use_xrender) {
  7.1095 +            renderer->blendMode = SDL_BLENDMODE_BLEND;
  7.1096 +            data->blend_op = PictOpOver;
  7.1097 +        }
  7.1098 +        else
  7.1099 +#endif
  7.1100 +        {
  7.1101 +            renderer->blendMode = SDL_BLENDMODE_NONE;
  7.1102 +        }
  7.1103          return -1;
  7.1104      }
  7.1105  }
  7.1106 @@ -601,16 +1307,35 @@
  7.1107          return SDL_MapRGBA(&data->format, r, g, b, a);
  7.1108  }
  7.1109  
  7.1110 +static XRenderColor
  7.1111 +xrenderdrawcolor(SDL_Renderer *renderer)
  7.1112 +{
  7.1113 +    XRenderColor xrender_color;
  7.1114 +    if(renderer->blendMode == SDL_BLENDMODE_NONE) {
  7.1115 +        xrender_color =
  7.1116 +            SDLColorToXRenderColor(renderer->r, renderer->g, renderer->b, 0xFF);
  7.1117 +    }
  7.1118 +    else {
  7.1119 +        xrender_color =
  7.1120 +            SDLColorToXRenderColor(renderer->r, renderer->g, renderer->b, renderer->a);
  7.1121 +    }
  7.1122 +    return xrender_color;
  7.1123 +}
  7.1124 +
  7.1125  static int
  7.1126  X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
  7.1127                       int count)
  7.1128  {
  7.1129      X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
  7.1130      SDL_Window *window = renderer->window;
  7.1131 -    unsigned long foreground;
  7.1132      XPoint *xpoints, *xpoint;
  7.1133      int i, xcount;
  7.1134 +    SDL_Rect clip;
  7.1135  
  7.1136 +    clip.x = 0;
  7.1137 +    clip.y = 0;
  7.1138 +    clip.w = window->w;
  7.1139 +    clip.h = window->h;
  7.1140      if (data->makedirty) {
  7.1141          SDL_Rect rect;
  7.1142  
  7.1143 @@ -625,27 +1350,105 @@
  7.1144          }
  7.1145          SDL_AddDirtyRect(&data->dirty, &rect);
  7.1146      }
  7.1147 +    {
  7.1148 +        xpoint = xpoints = SDL_stack_alloc(XPoint, count);
  7.1149 +        xcount = 0;
  7.1150 +        for (i = 0; i < count; ++i) {
  7.1151 +            int x = points[i].x;
  7.1152 +            int y = points[i].y;
  7.1153 +            if (x < 0 || x >= window->w || y < 0 || y >= window->h) {
  7.1154 +                continue;
  7.1155 +            }
  7.1156 +            xpoint->x = (short)x;
  7.1157 +            xpoint->y = (short)y;
  7.1158 +            ++xpoint;
  7.1159 +            ++xcount;
  7.1160 +        }
  7.1161  
  7.1162 -    foreground = renderdrawcolor(renderer, 1);
  7.1163 -    XSetForeground(data->display, data->gc, foreground);
  7.1164 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  7.1165 +        if (data->use_xrender &&
  7.1166 +            (renderer->blendMode != SDL_BLENDMODE_NONE) &&
  7.1167 +            !(renderer->a == 0xFF &&
  7.1168 +              renderer->blendMode != SDL_BLENDMODE_ADD &&
  7.1169 +              renderer->blendMode != SDL_BLENDMODE_MOD))
  7.1170 +        {
  7.1171 +            XSetForeground(data->display, data->stencil_gc, 0);
  7.1172 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  7.1173 +            if (data->use_xdamage)
  7.1174 +            {
  7.1175 +                /* Update only those parts which were changed
  7.1176 +                * in the previous drawing operation */
  7.1177 +                XFixesSetGCClipRegion(data->display, data->stencil_gc,
  7.1178 +                                      0, 0, data->stencil_parts);
  7.1179 +            }
  7.1180 +#endif
  7.1181 +            XFillRectangle(data->display, data->stencil, data->stencil_gc,
  7.1182 +                           0, 0, window->w, window->h);
  7.1183 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  7.1184 +            if (data->use_xdamage)
  7.1185 +            {
  7.1186 +                XFixesSetGCClipRegion(data->display, data->stencil_gc, 0, 0, None);
  7.1187 +            }
  7.1188 +#endif
  7.1189 +            XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF);
  7.1190  
  7.1191 -    xpoint = xpoints = SDL_stack_alloc(XPoint, count);
  7.1192 -    xcount = 0;
  7.1193 -    for (i = 0; i < count; ++i) {
  7.1194 -        int x = points[i].x;
  7.1195 -        int y = points[i].y;
  7.1196 -        if (x < 0 || x >= window->w || y < 0 || y >= window->h) {
  7.1197 -            continue;
  7.1198 +            XDrawPoints(data->display, data->stencil, data->stencil_gc, xpoints, xcount,
  7.1199 +                        CoordModeOrigin);
  7.1200 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  7.1201 +            if (data->use_xdamage)
  7.1202 +            {
  7.1203 +                /* Store the damaged region in stencil_parts */
  7.1204 +                XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts);
  7.1205 +            }
  7.1206 +#endif
  7.1207          }
  7.1208 -        xpoint->x = (short)x;
  7.1209 -        xpoint->y = (short)y;
  7.1210 -        ++xpoint;
  7.1211 -        ++xcount;
  7.1212 +#endif
  7.1213      }
  7.1214 -    if (xcount > 0) {
  7.1215 -        XDrawPoints(data->display, data->drawable, data->gc, xpoints, xcount,
  7.1216 -                    CoordModeOrigin);
  7.1217 +
  7.1218 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  7.1219 +    if (data->use_xrender &&
  7.1220 +            (renderer->blendMode != SDL_BLENDMODE_NONE) &&
  7.1221 +            !(renderer->a == 0xFF &&
  7.1222 +              renderer->blendMode != SDL_BLENDMODE_ADD &&
  7.1223 +              renderer->blendMode != SDL_BLENDMODE_MOD))
  7.1224 +    {
  7.1225 +        XRenderColor foreground;
  7.1226 +        foreground = xrenderdrawcolor(renderer);
  7.1227 +
  7.1228 +        XRenderFillRectangle(data->display, PictOpSrc, data->brush_pict,
  7.1229 +                             &foreground, 0, 0, 1, 1);
  7.1230 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  7.1231 +        if (data->use_xdamage)
  7.1232 +        {
  7.1233 +            /* Update only those parts which drawn
  7.1234 +             * to in the current drawing operation */
  7.1235 +            XFixesSetPictureClipRegion(data->display, data->drawable_pict,
  7.1236 +                                       0, 0, data->stencil_parts);
  7.1237 +        }
  7.1238 +#endif
  7.1239 +        XRenderComposite(data->display, data->blend_op, data->brush_pict,
  7.1240 +                         data->stencil_pict, data->drawable_pict,
  7.1241 +                         0, 0, 0, 0, 0, 0, window->w, window->h);
  7.1242 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  7.1243 +        if (data->use_xdamage)
  7.1244 +        {
  7.1245 +            XFixesSetPictureClipRegion(data->display, data->drawable_pict, 0, 0, None);
  7.1246 +        }
  7.1247 +#endif
  7.1248      }
  7.1249 +    else
  7.1250 +#endif
  7.1251 +    {
  7.1252 +        unsigned long foreground = renderdrawcolor(renderer, 1);
  7.1253 +        XSetForeground(data->display, data->gc, foreground);
  7.1254 +
  7.1255 +
  7.1256 +        if (xcount > 0) {
  7.1257 +            XDrawPoints(data->display, data->drawable, data->gc, xpoints, xcount,
  7.1258 +                        CoordModeOrigin);
  7.1259 +        }
  7.1260 +    }
  7.1261 +
  7.1262      SDL_stack_free(xpoints);
  7.1263  
  7.1264      return 0;
  7.1265 @@ -668,65 +1471,146 @@
  7.1266      clip.y = 0;
  7.1267      clip.w = window->w;
  7.1268      clip.h = window->h;
  7.1269 -
  7.1270 -    foreground = renderdrawcolor(renderer, 1);
  7.1271 -    XSetForeground(data->display, data->gc, foreground);
  7.1272 -
  7.1273 -    xpoint = xpoints = SDL_stack_alloc(XPoint, count);
  7.1274 -    xcount = 0;
  7.1275 -    minx = INT_MAX;
  7.1276 -    miny = INT_MAX;
  7.1277 -    maxx = INT_MIN;
  7.1278 -    maxy = INT_MIN;
  7.1279 -    for (i = 0; i < count; ++i) {
  7.1280 -        int x = points[i].x;
  7.1281 -        int y = points[i].y;
  7.1282 +    {
  7.1283 +        Pixmap drawable;
  7.1284 +        GC gc;
  7.1285 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  7.1286 +       if (data->use_xrender &&
  7.1287 +            (renderer->blendMode != SDL_BLENDMODE_NONE) &&
  7.1288 +            !(renderer->a == 0xFF &&
  7.1289 +              renderer->blendMode != SDL_BLENDMODE_ADD &&
  7.1290 +              renderer->blendMode != SDL_BLENDMODE_MOD))
  7.1291 +       { 
  7.1292 +            drawable = data->stencil;
  7.1293 +            gc = data->stencil_gc;
  7.1294  
  7.1295 -        /* If the point is inside the window, add it to the list */
  7.1296 -        if (x >= 0 && x < window->w && y >= 0 && y < window->h) {
  7.1297 -            if (x < minx) {
  7.1298 -                minx = x;
  7.1299 -            } else if (x > maxx) {
  7.1300 -                maxx = x;
  7.1301 -            }
  7.1302 -            if (y < miny) {
  7.1303 -                miny = y;
  7.1304 -            } else if (y > maxy) {
  7.1305 -                maxy = y;
  7.1306 -            }
  7.1307 -            xpoint->x = (short)x;
  7.1308 -            xpoint->y = (short)y;
  7.1309 -            ++xpoint;
  7.1310 -            ++xcount;
  7.1311 -            continue;
  7.1312 +            XSetForeground(data->display, data->stencil_gc, 0);
  7.1313 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  7.1314 +            if (data->use_xdamage)
  7.1315 +                XFixesSetGCClipRegion(data->display, data->stencil_gc,
  7.1316 +                                      0, 0, data->stencil_parts);
  7.1317 +#endif
  7.1318 +            XFillRectangle(data->display, data->stencil, data->stencil_gc,
  7.1319 +                           0, 0, window->w, window->h);
  7.1320 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  7.1321 +            if (data->use_xdamage)
  7.1322 +                XFixesSetGCClipRegion(data->display, data->stencil_gc,
  7.1323 +                                      0, 0, None);
  7.1324 +#endif
  7.1325 +            XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF);
  7.1326 +        }
  7.1327 +        else
  7.1328 +#endif
  7.1329 +        {
  7.1330 +            drawable = data->drawable;
  7.1331 +            gc = data->gc;
  7.1332          }
  7.1333  
  7.1334 -        /* We need to clip the line segments joined by this point */
  7.1335 -        if (xcount > 0) {
  7.1336 -            int x1 = xpoint[-1].x;
  7.1337 -            int y1 = xpoint[-1].y;
  7.1338 -            int x2 = x;
  7.1339 -            int y2 = y;
  7.1340 -            if (SDL_IntersectRectAndLine(&clip, &x1, &y1, &x2, &y2)) {
  7.1341 -                if (x2 < minx) {
  7.1342 -                    minx = x2;
  7.1343 -                } else if (x2 > maxx) {
  7.1344 -                    maxx = x2;
  7.1345 +        foreground = renderdrawcolor(renderer, 1);
  7.1346 +        XSetForeground(data->display, data->gc, foreground);
  7.1347 +
  7.1348 +        xpoint = xpoints = SDL_stack_alloc(XPoint, count);
  7.1349 +        xcount = 0;
  7.1350 +        minx = INT_MAX;
  7.1351 +        miny = INT_MAX;
  7.1352 +        maxx = INT_MIN;
  7.1353 +        maxy = INT_MIN;
  7.1354 +        for (i = 0; i < count; ++i) {
  7.1355 +            int x = points[i].x;
  7.1356 +            int y = points[i].y;
  7.1357 +
  7.1358 +            /* If the point is inside the window, add it to the list */
  7.1359 +            if (x >= 0 && x < window->w && y >= 0 && y < window->h) {
  7.1360 +                if (x < minx) {
  7.1361 +                    minx = x;
  7.1362 +                } else if (x > maxx) {
  7.1363 +                    maxx = x;
  7.1364                  }
  7.1365 -                if (y2 < miny) {
  7.1366 -                    miny = y2;
  7.1367 -                } else if (y2 > maxy) {
  7.1368 -                    maxy = y2;
  7.1369 +                if (y < miny) {
  7.1370 +                    miny = y;
  7.1371 +                } else if (y > maxy) {
  7.1372 +                    maxy = y;
  7.1373                  }
  7.1374 -                xpoint->x = (short)x2;
  7.1375 -                xpoint->y = (short)y2;
  7.1376 +                xpoint->x = (short)x;
  7.1377 +                xpoint->y = (short)y;
  7.1378                  ++xpoint;
  7.1379                  ++xcount;
  7.1380 +                continue;
  7.1381              }
  7.1382 -            XDrawLines(data->display, data->drawable, data->gc,
  7.1383 -                       xpoints, xcount, CoordModeOrigin);
  7.1384 +
  7.1385 +            /* We need to clip the line segments joined by this point */
  7.1386 +            if (xcount > 0) {
  7.1387 +                int x1 = xpoint[-1].x;
  7.1388 +                int y1 = xpoint[-1].y;
  7.1389 +                int x2 = x;
  7.1390 +                int y2 = y;
  7.1391 +                if (SDL_IntersectRectAndLine(&clip, &x1, &y1, &x2, &y2)) {
  7.1392 +                    if (x2 < minx) {
  7.1393 +                        minx = x2;
  7.1394 +                    } else if (x2 > maxx) {
  7.1395 +                        maxx = x2;
  7.1396 +                    }
  7.1397 +                    if (y2 < miny) {
  7.1398 +                        miny = y2;
  7.1399 +                    } else if (y2 > maxy) {
  7.1400 +                        maxy = y2;
  7.1401 +                    }
  7.1402 +                    xpoint->x = (short)x2;
  7.1403 +                    xpoint->y = (short)y2;
  7.1404 +                    ++xpoint;
  7.1405 +                    ++xcount;
  7.1406 +                }
  7.1407 +                XDrawLines(data->display, drawable, gc,
  7.1408 +                           xpoints, xcount, CoordModeOrigin);
  7.1409 +                if (xpoints[0].x != x2 || xpoints[0].y != y2) {
  7.1410 +                    XDrawPoint(data->display, drawable, gc, x2, y2);
  7.1411 +                }
  7.1412 +                if (data->makedirty) {
  7.1413 +                    SDL_Rect rect;
  7.1414 +
  7.1415 +                    rect.x = minx;
  7.1416 +                    rect.y = miny;
  7.1417 +                    rect.w = (maxx - minx) + 1;
  7.1418 +                    rect.h = (maxy - miny) + 1;
  7.1419 +                    SDL_AddDirtyRect(&data->dirty, &rect);
  7.1420 +                }
  7.1421 +                xpoint = xpoints;
  7.1422 +                xcount = 0;
  7.1423 +                minx = INT_MAX;
  7.1424 +                miny = INT_MAX;
  7.1425 +                maxx = INT_MIN;
  7.1426 +                maxy = INT_MIN;
  7.1427 +            }
  7.1428 +            if (i < (count-1)) {
  7.1429 +                int x1 = x;
  7.1430 +                int y1 = y;
  7.1431 +                int x2 = points[i+1].x;
  7.1432 +                int y2 = points[i+1].y;
  7.1433 +                if (SDL_IntersectRectAndLine(&clip, &x1, &y1, &x2, &y2)) {
  7.1434 +                    if (x1 < minx) {
  7.1435 +                        minx = x1;
  7.1436 +                    } else if (x1 > maxx) {
  7.1437 +                        maxx = x1;
  7.1438 +                    }
  7.1439 +                    if (y1 < miny) {
  7.1440 +                        miny = y1;
  7.1441 +                    } else if (y1 > maxy) {
  7.1442 +                        maxy = y1;
  7.1443 +                    }
  7.1444 +                    xpoint->x = (short)x1;
  7.1445 +                    xpoint->y = (short)y1;
  7.1446 +                    ++xpoint;
  7.1447 +                    ++xcount;
  7.1448 +                }
  7.1449 +            }
  7.1450 +        }
  7.1451 +        if (xcount > 1) {
  7.1452 +            int x2 = xpoint[-1].x;
  7.1453 +            int y2 = xpoint[-1].y;
  7.1454 +            XDrawLines(data->display, drawable, gc, xpoints, xcount,
  7.1455 +                       CoordModeOrigin);
  7.1456              if (xpoints[0].x != x2 || xpoints[0].y != y2) {
  7.1457 -                XDrawPoint(data->display, data->drawable, data->gc, x2, y2);
  7.1458 +                XDrawPoint(data->display, drawable, gc, x2, y2);
  7.1459              }
  7.1460              if (data->makedirty) {
  7.1461                  SDL_Rect rect;
  7.1462 @@ -737,54 +1621,37 @@
  7.1463                  rect.h = (maxy - miny) + 1;
  7.1464                  SDL_AddDirtyRect(&data->dirty, &rect);
  7.1465              }
  7.1466 -            xpoint = xpoints;
  7.1467 -            xcount = 0;
  7.1468 -            minx = INT_MAX;
  7.1469 -            miny = INT_MAX;
  7.1470 -            maxx = INT_MIN;
  7.1471 -            maxy = INT_MIN;
  7.1472 -        }
  7.1473 -        if (i < (count-1)) {
  7.1474 -            int x1 = x;
  7.1475 -            int y1 = y;
  7.1476 -            int x2 = points[i+1].x;
  7.1477 -            int y2 = points[i+1].y;
  7.1478 -            if (SDL_IntersectRectAndLine(&clip, &x1, &y1, &x2, &y2)) {
  7.1479 -                if (x1 < minx) {
  7.1480 -                    minx = x1;
  7.1481 -                } else if (x1 > maxx) {
  7.1482 -                    maxx = x1;
  7.1483 -                }
  7.1484 -                if (y1 < miny) {
  7.1485 -                    miny = y1;
  7.1486 -                } else if (y1 > maxy) {
  7.1487 -                    maxy = y1;
  7.1488 -                }
  7.1489 -                xpoint->x = (short)x1;
  7.1490 -                xpoint->y = (short)y1;
  7.1491 -                ++xpoint;
  7.1492 -                ++xcount;
  7.1493 -            }
  7.1494          }
  7.1495      }
  7.1496 -    if (xcount > 1) {
  7.1497 -        int x2 = xpoint[-1].x;
  7.1498 -        int y2 = xpoint[-1].y;
  7.1499 -        XDrawLines(data->display, data->drawable, data->gc, xpoints, xcount,
  7.1500 -                   CoordModeOrigin);
  7.1501 -        if (xpoints[0].x != x2 || xpoints[0].y != y2) {
  7.1502 -            XDrawPoint(data->display, data->drawable, data->gc, x2, y2);
  7.1503 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  7.1504 +    if (data->use_xrender &&
  7.1505 +            (renderer->blendMode != SDL_BLENDMODE_NONE) &&
  7.1506 +            !(renderer->a == 0xFF &&
  7.1507 +              renderer->blendMode != SDL_BLENDMODE_ADD &&
  7.1508 +              renderer->blendMode != SDL_BLENDMODE_MOD))
  7.1509 +    {
  7.1510 +        XRenderColor xrforeground = xrenderdrawcolor(renderer);
  7.1511 +        XRenderFillRectangle(data->display, PictOpSrc, data->brush_pict,
  7.1512 +                             &xrforeground, 0, 0, 1, 1);
  7.1513 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  7.1514 +        if (data->use_xdamage)
  7.1515 +        {
  7.1516 +            XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts);
  7.1517 +
  7.1518 +            XFixesSetPictureClipRegion(data->display, data->drawable_pict,
  7.1519 +                                       0, 0, data->stencil_parts);
  7.1520          }
  7.1521 -        if (data->makedirty) {
  7.1522 -            SDL_Rect rect;
  7.1523 -
  7.1524 -            rect.x = minx;
  7.1525 -            rect.y = miny;
  7.1526 -            rect.w = (maxx - minx) + 1;
  7.1527 -            rect.h = (maxy - miny) + 1;
  7.1528 -            SDL_AddDirtyRect(&data->dirty, &rect);
  7.1529 -        }
  7.1530 +#endif
  7.1531 +        XRenderComposite(data->display, data->blend_op, data->brush_pict,
  7.1532 +                         data->stencil_pict, data->drawable_pict,
  7.1533 +                         0, 0, 0, 0, 0, 0, window->w, window->h);
  7.1534 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  7.1535 +        if (data->use_xdamage)
  7.1536 +            XFixesSetPictureClipRegion(data->display, data->drawable_pict,
  7.1537 +                                       0, 0, None);
  7.1538 +#endif
  7.1539      }
  7.1540 +#endif
  7.1541      SDL_stack_free(xpoints);
  7.1542  
  7.1543      return 0;
  7.1544 @@ -796,18 +1663,122 @@
  7.1545      X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
  7.1546      SDL_Window *window = renderer->window;
  7.1547      SDL_Rect clip, rect;
  7.1548 -    unsigned long foreground;
  7.1549 +    int i, xcount;
  7.1550      XRectangle *xrects, *xrect;
  7.1551 -    int i, xcount;
  7.1552 -
  7.1553 +    xrect = xrects = SDL_stack_alloc(XRectangle, count);
  7.1554 +    xcount = 0;
  7.1555 +    
  7.1556      clip.x = 0;
  7.1557      clip.y = 0;
  7.1558      clip.w = window->w;
  7.1559      clip.h = window->h;
  7.1560 +    {
  7.1561  
  7.1562 -    foreground = renderdrawcolor(renderer, 1);
  7.1563 -    XSetForeground(data->display, data->gc, foreground);
  7.1564 +        for (i = 0; i < count; ++i) {
  7.1565 +            if (!SDL_IntersectRect(rects[i], &clip, &rect)) {
  7.1566 +                continue;
  7.1567 +            }
  7.1568 +
  7.1569 +            xrect->x = (short)rect.x;
  7.1570 +            xrect->y = (short)rect.y;
  7.1571 +            xrect->width = (unsigned short)rect.w - 1;
  7.1572 +            xrect->height = (unsigned short)rect.h - 1;
  7.1573 +            ++xrect;
  7.1574 +            ++xcount;
  7.1575 +
  7.1576 +            if (data->makedirty) {
  7.1577 +                SDL_AddDirtyRect(&data->dirty, &rect);
  7.1578 +            }
  7.1579 +        }
  7.1580 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  7.1581 +        if (data->use_xrender &&
  7.1582 +            (renderer->blendMode != SDL_BLENDMODE_NONE) &&
  7.1583 +            !(renderer->a == 0xFF &&
  7.1584 +              renderer->blendMode != SDL_BLENDMODE_ADD &&
  7.1585 +              renderer->blendMode != SDL_BLENDMODE_MOD))
  7.1586 +        {
  7.1587 +            XSetForeground(data->display, data->stencil_gc, 0);
  7.1588 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  7.1589 +            if (data->use_xdamage)
  7.1590 +                XFixesSetGCClipRegion(data->display, data->stencil_gc,
  7.1591 +                                      0, 0, data->stencil_parts);
  7.1592 +#endif
  7.1593 +            XFillRectangle(data->display, data->stencil, data->stencil_gc,
  7.1594 +                           0, 0, window->w, window->h);
  7.1595 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  7.1596 +            if (data->use_xdamage)
  7.1597 +                XFixesSetGCClipRegion(data->display, data->stencil_gc,
  7.1598 +                                      0, 0, None);
  7.1599 +#endif
  7.1600 +            XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF);
  7.1601 +
  7.1602 +            XDrawRectangles(data->display, data->stencil, data->stencil_gc, xrects, xcount);
  7.1603  
  7.1604 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  7.1605 +            if (data->use_xdamage)
  7.1606 +                XDamageSubtract(data->display, data->stencil_damage,
  7.1607 +                                None, data->stencil_parts);
  7.1608 +#endif
  7.1609 +        }
  7.1610 +#endif
  7.1611 +    }
  7.1612 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  7.1613 +    if (data->use_xrender &&
  7.1614 +            (renderer->blendMode != SDL_BLENDMODE_NONE) &&
  7.1615 +            !(renderer->a == 0xFF &&
  7.1616 +              renderer->blendMode != SDL_BLENDMODE_ADD &&
  7.1617 +              renderer->blendMode != SDL_BLENDMODE_MOD))
  7.1618 +    {
  7.1619 +        XRenderColor foreground;
  7.1620 +        foreground = xrenderdrawcolor(renderer);
  7.1621 +        XRenderFillRectangle(data->display, PictOpSrc, data->brush_pict,
  7.1622 +                             &foreground, 0, 0, 1, 1);
  7.1623 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  7.1624 +        if (data->use_xdamage)
  7.1625 +            XFixesSetPictureClipRegion(data->display, data->drawable_pict,
  7.1626 +                                       0, 0, data->stencil_parts);
  7.1627 +#endif
  7.1628 +        XRenderComposite(data->display, data->blend_op, data->brush_pict,
  7.1629 +                         data->stencil_pict, data->drawable_pict,
  7.1630 +                         0, 0, 0, 0, 0, 0, window->w, window->h);
  7.1631 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  7.1632 +        if (data->use_xdamage)
  7.1633 +            XFixesSetPictureClipRegion(data->display, data->drawable_pict,
  7.1634 +                                       0, 0, None);
  7.1635 +#endif
  7.1636 +    }
  7.1637 +    else
  7.1638 +#endif
  7.1639 +    {
  7.1640 +        unsigned long foreground;
  7.1641 +        
  7.1642 +        foreground = renderdrawcolor(renderer, 1);
  7.1643 +        XSetForeground(data->display, data->gc, foreground);
  7.1644 +    
  7.1645 +        if (xcount > 0) {
  7.1646 +            XDrawRectangles(data->display, data->drawable, data->gc,
  7.1647 +                            xrects, xcount);
  7.1648 +        }
  7.1649 +    }
  7.1650 +    SDL_stack_free(xrects);
  7.1651 +
  7.1652 +    return 0;
  7.1653 +}
  7.1654 +
  7.1655 +static int
  7.1656 +X11_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
  7.1657 +{
  7.1658 +    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
  7.1659 +    SDL_Window *window = renderer->window;
  7.1660 +    SDL_Rect clip, rect;
  7.1661 +    
  7.1662 +    clip.x = 0;
  7.1663 +    clip.y = 0;
  7.1664 +    clip.w = window->w;
  7.1665 +    clip.h = window->h;
  7.1666 +    
  7.1667 +    int i, xcount;
  7.1668 +    XRectangle *xrects, *xrect;
  7.1669      xrect = xrects = SDL_stack_alloc(XRectangle, count);
  7.1670      xcount = 0;
  7.1671      for (i = 0; i < count; ++i) {
  7.1672 @@ -826,57 +1797,34 @@
  7.1673              SDL_AddDirtyRect(&data->dirty, &rect);
  7.1674          }
  7.1675      }
  7.1676 -    if (xcount > 0) {
  7.1677 -        XDrawRectangles(data->display, data->drawable, data->gc,
  7.1678 -                        xrects, xcount);
  7.1679 -    }
  7.1680 -    SDL_stack_free(xpoints);
  7.1681  
  7.1682 -    return 0;
  7.1683 -}
  7.1684 -
  7.1685 -static int
  7.1686 -X11_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
  7.1687 -{
  7.1688 -    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
  7.1689 -    SDL_Window *window = renderer->window;
  7.1690 -    SDL_Rect clip, rect;
  7.1691 -    unsigned long foreground;
  7.1692 -    XRectangle *xrects, *xrect;
  7.1693 -    int i, xcount;
  7.1694 -
  7.1695 -    clip.x = 0;
  7.1696 -    clip.y = 0;
  7.1697 -    clip.w = window->w;
  7.1698 -    clip.h = window->h;
  7.1699 -
  7.1700 -    foreground = renderdrawcolor(renderer, 1);
  7.1701 -    XSetForeground(data->display, data->gc, foreground);
  7.1702 -
  7.1703 -    xrect = xrects = SDL_stack_alloc(XRectangle, count);
  7.1704 -    xcount = 0;
  7.1705 -    for (i = 0; i < count; ++i) {
  7.1706 -        if (!SDL_IntersectRect(rects[i], &clip, &rect)) {
  7.1707 -            continue;
  7.1708 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  7.1709 +    if (data->use_xrender) {
  7.1710 +        XRenderColor foreground;
  7.1711 +        foreground = xrenderdrawcolor(renderer);
  7.1712 +        if (xcount == 1) {
  7.1713 +            XRenderFillRectangle(data->display, data->blend_op, data->drawable_pict,
  7.1714 +                                 &foreground, xrects[0].x, xrects[0].y,
  7.1715 +                                 xrects[0].width, xrects[0].height);
  7.1716          }
  7.1717 -
  7.1718 -        xrect->x = (short)rect.x;
  7.1719 -        xrect->y = (short)rect.y;
  7.1720 -        xrect->width = (unsigned short)rect.w;
  7.1721 -        xrect->height = (unsigned short)rect.h;
  7.1722 -        ++xrect;
  7.1723 -        ++xcount;
  7.1724 -
  7.1725 -        if (data->makedirty) {
  7.1726 -            SDL_AddDirtyRect(&data->dirty, &rect);
  7.1727 +        else if (xcount > 1) {
  7.1728 +            XRenderFillRectangles(data->display, data->blend_op, data->drawable_pict,
  7.1729 +                                  &foreground, xrects, xcount);
  7.1730          }
  7.1731      }
  7.1732 -    if (xcount > 0) {
  7.1733 +    else
  7.1734 +#endif
  7.1735 +    {
  7.1736 +        unsigned long foreground;
  7.1737 +        
  7.1738 +        foreground = renderdrawcolor(renderer, 1);
  7.1739 +        XSetForeground(data->display, data->gc, foreground);
  7.1740 + 
  7.1741          XFillRectangles(data->display, data->drawable, data->gc,
  7.1742                          xrects, xcount);
  7.1743      }
  7.1744 -    SDL_stack_free(xpoints);
  7.1745  
  7.1746 +    SDL_stack_free(xrects);
  7.1747      return 0;
  7.1748  }
  7.1749  
  7.1750 @@ -890,103 +1838,206 @@
  7.1751      if (data->makedirty) {
  7.1752          SDL_AddDirtyRect(&data->dirty, dstrect);
  7.1753      }
  7.1754 -    if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
  7.1755 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  7.1756 +    if (data->use_xrender) {
  7.1757 +        if(texture->access == SDL_TEXTUREACCESS_STREAMING) {
  7.1758  #ifndef NO_SHARED_MEMORY
  7.1759 -        if (texturedata->shminfo.shmaddr) {
  7.1760 -            XShmPutImage(data->display, data->drawable, data->gc,
  7.1761 -                         texturedata->image, srcrect->x, srcrect->y,
  7.1762 -                         dstrect->x, dstrect->y, srcrect->w, srcrect->h,
  7.1763 -                         False);
  7.1764 -        } else
  7.1765 +            if(texturedata->shminfo.shmaddr) {
  7.1766 +                XShmPutImage(data->display, texturedata->pixmap, texturedata->gc,
  7.1767 +                             texturedata->image, srcrect->x, srcrect->y,
  7.1768 +                             srcrect->x, srcrect->y, srcrect->w, srcrect->h,
  7.1769 +                             False);
  7.1770 +            }
  7.1771 +            else
  7.1772  #endif
  7.1773 -        if (texturedata->pixels) {
  7.1774 -            XPutImage(data->display, data->drawable, data->gc,
  7.1775 -                      texturedata->image, srcrect->x, srcrect->y, dstrect->x,
  7.1776 -                      dstrect->y, srcrect->w, srcrect->h);
  7.1777 +            if (texturedata->pixels) {
  7.1778 +                XPutImage(data->display, texturedata->pixmap, texturedata->gc,
  7.1779 +                          texturedata->image, srcrect->x, srcrect->y, srcrect->x,
  7.1780 +                          srcrect->y, srcrect->w, srcrect->h);
  7.1781 +            }
  7.1782 +            XSync(data->display, False);
  7.1783 +        }
  7.1784 +        Picture src, mask;
  7.1785 +        XRenderPictureAttributes attr;
  7.1786 +        const SDL_Rect *mrect;
  7.1787 +
  7.1788 +        if (texture->modMode == SDL_TEXTUREMODULATE_NONE) {
  7.1789 +            src = texturedata->picture;
  7.1790 +        }
  7.1791 +        else {
  7.1792 +            src = texturedata->modulated_picture;
  7.1793 +        }
  7.1794 +
  7.1795 +        if(texture->blendMode == SDL_BLENDMODE_NONE) 
  7.1796 +        {
  7.1797 +            mask = None;
  7.1798 +            mrect = srcrect;
  7.1799 +        }
  7.1800 +        else if (texture->blendMode == SDL_BLENDMODE_MOD)
  7.1801 +        {
  7.1802 +            mask = data->stencil_pict;
  7.1803 +            mrect = dstrect;
  7.1804 +        }
  7.1805 +        else
  7.1806 +        {
  7.1807 +            mask = texturedata->picture;
  7.1808 +            mrect = srcrect;
  7.1809 +        }
  7.1810 +
  7.1811 +        if(srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
  7.1812 +            if (texture->blendMode == SDL_BLENDMODE_MOD) {
  7.1813 +                XRenderComposite(data->display, PictOpSrc, data->drawable_pict,
  7.1814 +                             src, data->stencil_pict,
  7.1815 +                             dstrect->x, dstrect->y, srcrect->x, srcrect->y,
  7.1816 +                             dstrect->x, dstrect->y, dstrect->w, dstrect->h);
  7.1817 +                attr.component_alpha = True;
  7.1818 +                XRenderChangePicture(data->display, data->stencil_pict,
  7.1819 +                                     CPComponentAlpha, &attr);
  7.1820 +            }
  7.1821 +            XRenderComposite(data->display, texturedata->blend_op,
  7.1822 +                            src, mask, data->drawable_pict, srcrect->x, srcrect->y,
  7.1823 +                            mrect->x, mrect->y, dstrect->x, dstrect->y,
  7.1824 +                            dstrect->w, dstrect->h);
  7.1825          } else {
  7.1826 -            XCopyArea(data->display, texturedata->pixmap, data->drawable,
  7.1827 -                      data->gc, srcrect->x, srcrect->y, dstrect->w,
  7.1828 -                      dstrect->h, dstrect->x, dstrect->y);
  7.1829 -        }
  7.1830 -    } else if (texturedata->yuv
  7.1831 -               || texture->access == SDL_TEXTUREACCESS_STREAMING) {
  7.1832 -        SDL_Surface src, dst;
  7.1833 -        SDL_PixelFormat fmt;
  7.1834 -        SDL_Rect rect;
  7.1835 -        XImage *image = texturedata->scaling_image;
  7.1836 -
  7.1837 -        if (!image) {
  7.1838 -            void *pixels;
  7.1839 -            int pitch;
  7.1840 -
  7.1841 -            pitch = dstrect->w * SDL_BYTESPERPIXEL(texturedata->format);
  7.1842 -            pixels = SDL_malloc(dstrect->h * pitch);
  7.1843 -            if (!pixels) {
  7.1844 -                SDL_OutOfMemory();
  7.1845 -                return -1;
  7.1846 +            double xscale = ((double) dstrect->w) / srcrect->w;
  7.1847 +            double yscale = ((double) dstrect->h) / srcrect->h;
  7.1848 +            XTransform xform = {{
  7.1849 +                    {XDoubleToFixed(xscale), XDoubleToFixed(0), XDoubleToFixed(0)},
  7.1850 +                    {XDoubleToFixed(0), XDoubleToFixed(yscale), XDoubleToFixed(0)},
  7.1851 +                    {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(xscale * yscale)}}};
  7.1852 +            XRenderSetPictureTransform(data->display, src, &xform);
  7.1853 +            
  7.1854 +            if (texture->blendMode == SDL_BLENDMODE_MOD) {
  7.1855 +                XRenderComposite(data->display, PictOpSrc, data->drawable_pict,
  7.1856 +                             src, data->stencil_pict,
  7.1857 +                             dstrect->x, dstrect->y, srcrect->x, srcrect->y,
  7.1858 +                             dstrect->x, dstrect->y, dstrect->w, dstrect->h);
  7.1859 +                attr.component_alpha = True;
  7.1860 +                XRenderChangePicture(data->display, data->stencil_pict,
  7.1861 +                                     CPComponentAlpha, &attr);
  7.1862              }
  7.1863  
  7.1864 -            image =
  7.1865 -                XCreateImage(data->display, data->visual, data->depth,
  7.1866 -                             ZPixmap, 0, pixels, dstrect->w, dstrect->h,
  7.1867 -                             SDL_BYTESPERPIXEL(texturedata->format) * 8,
  7.1868 -                             pitch);
  7.1869 +            XRenderSetPictureFilter(data->display, src,
  7.1870 +                                    texturedata->filter, 0, 0);
  7.1871 +
  7.1872 +            XRenderComposite(data->display, texturedata->blend_op,
  7.1873 +                             src, mask, data->drawable_pict,
  7.1874 +                             srcrect->x, srcrect->y, mrect->x, mrect->y,
  7.1875 +                             dstrect->x, dstrect->y, dstrect->w, dstrect->h);
  7.1876 +            
  7.1877 +            XTransform identity = {{
  7.1878 +                    {XDoubleToFixed(1), XDoubleToFixed(0), XDoubleToFixed(0)},
  7.1879 +                    {XDoubleToFixed(0), XDoubleToFixed(1), XDoubleToFixed(0)},
  7.1880 +                    {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(1)}}};
  7.1881 +            XRenderSetPictureTransform(data->display, src, &identity);
  7.1882 +        }
  7.1883 +        if (renderer->blendMode == SDL_BLENDMODE_MOD) {
  7.1884 +            attr.component_alpha = False;
  7.1885 +            XRenderChangePicture(data->display, data->stencil_pict,
  7.1886 +                                 CPComponentAlpha, &attr);
  7.1887 +        }
  7.1888 +    }
  7.1889 +    else
  7.1890 +#endif
  7.1891 +    {
  7.1892 +        if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
  7.1893 +#ifndef NO_SHARED_MEMORY
  7.1894 +            if (texturedata->shminfo.shmaddr) {
  7.1895 +                XShmPutImage(data->display, data->drawable, data->gc,
  7.1896 +                             texturedata->image, srcrect->x, srcrect->y,
  7.1897 +                             dstrect->x, dstrect->y, srcrect->w, srcrect->h,
  7.1898 +                             False);
  7.1899 +            } else
  7.1900 +#endif
  7.1901 +            if (texturedata->pixels) {
  7.1902 +                XPutImage(data->display, data->drawable, data->gc,
  7.1903 +                          texturedata->image, srcrect->x, srcrect->y, dstrect->x,
  7.1904 +                          dstrect->y, srcrect->w, srcrect->h);
  7.1905 +            } else {
  7.1906 +                XCopyArea(data->display, texturedata->pixmap, data->drawable,
  7.1907 +                          data->gc, srcrect->x, srcrect->y, dstrect->w,
  7.1908 +                          dstrect->h, dstrect->x, dstrect->y);
  7.1909 +            }
  7.1910 +        } else if (texturedata->yuv
  7.1911 +                   || texture->access == SDL_TEXTUREACCESS_STREAMING) {
  7.1912 +            SDL_Surface src, dst;
  7.1913 +            SDL_PixelFormat fmt;
  7.1914 +            SDL_Rect rect;
  7.1915 +            XImage *image = texturedata->scaling_image;
  7.1916 +
  7.1917              if (!image) {
  7.1918 -                SDL_SetError("XCreateImage() failed");
  7.1919 +                void *pixels;
  7.1920 +                int pitch;
  7.1921 +
  7.1922 +                pitch = dstrect->w * SDL_BYTESPERPIXEL(texturedata->format);
  7.1923 +                pixels = SDL_malloc(dstrect->h * pitch);
  7.1924 +                if (!pixels) {
  7.1925 +                    SDL_OutOfMemory();
  7.1926 +                    return -1;
  7.1927 +                }
  7.1928 +
  7.1929 +                image =
  7.1930 +                    XCreateImage(data->display, data->visual, data->depth,
  7.1931 +                                 ZPixmap, 0, pixels, dstrect->w, dstrect->h,
  7.1932 +                                 SDL_BYTESPERPIXEL(texturedata->format) * 8,
  7.1933 +                                 pitch);
  7.1934 +                if (!image) {
  7.1935 +                    SDL_SetError("XCreateImage() failed");
  7.1936 +                    return -1;
  7.1937 +                }
  7.1938 +                texturedata->scaling_image = image;
  7.1939 +
  7.1940 +            } else if (image->width != dstrect->w || image->height != dstrect->h
  7.1941 +                       || !image->data) {
  7.1942 +                image->width = dstrect->w;
  7.1943 +                image->height = dstrect->h;
  7.1944 +                image->bytes_per_line =
  7.1945 +                    image->width * SDL_BYTESPERPIXEL(texturedata->format);
  7.1946 +                image->data =
  7.1947 +                    (char *) SDL_realloc(image->data,
  7.1948 +                                         image->height * image->bytes_per_line);
  7.1949 +                if (!image->data) {
  7.1950 +                    SDL_OutOfMemory();
  7.1951 +                    return -1;
  7.1952 +                }
  7.1953 +            }
  7.1954 +
  7.1955 +            /* Set up fake surfaces for SDL_SoftStretch() */
  7.1956 +            SDL_zero(src);
  7.1957 +            src.format = &fmt;
  7.1958 +            src.w = texture->w;
  7.1959 +            src.h = texture->h;
  7.1960 +#ifndef NO_SHARED_MEMORY
  7.1961 +            if (texturedata->shminfo.shmaddr) {
  7.1962 +                src.pixels = texturedata->shminfo.shmaddr;
  7.1963 +            } else
  7.1964 +#endif
  7.1965 +                src.pixels = texturedata->pixels;
  7.1966 +            src.pitch = texturedata->pitch;
  7.1967 +
  7.1968 +            SDL_zero(dst);
  7.1969 +            dst.format = &fmt;
  7.1970 +            dst.w = image->width;
  7.1971 +            dst.h = image->height;
  7.1972 +            dst.pixels = image->data;
  7.1973 +            dst.pitch = image->bytes_per_line;
  7.1974 +
  7.1975 +            fmt.BytesPerPixel = SDL_BYTESPERPIXEL(texturedata->format);
  7.1976 +
  7.1977 +            rect.x = 0;
  7.1978 +            rect.y = 0;
  7.1979 +            rect.w = dstrect->w;
  7.1980 +            rect.h = dstrect->h;
  7.1981 +            if (SDL_SoftStretch(&src, srcrect, &dst, &rect) < 0) {
  7.1982                  return -1;
  7.1983              }
  7.1984 -            texturedata->scaling_image = image;
  7.1985 -
  7.1986 -        } else if (image->width != dstrect->w || image->height != dstrect->h
  7.1987 -                   || !image->data) {
  7.1988 -            image->width = dstrect->w;
  7.1989 -            image->height = dstrect->h;
  7.1990 -            image->bytes_per_line =
  7.1991 -                image->width * SDL_BYTESPERPIXEL(texturedata->format);
  7.1992 -            image->data =
  7.1993 -                (char *) SDL_realloc(image->data,
  7.1994 -                                     image->height * image->bytes_per_line);
  7.1995 -            if (!image->data) {
  7.1996 -                SDL_OutOfMemory();
  7.1997 -                return -1;
  7.1998 -            }
  7.1999 +            XPutImage(data->display, data->drawable, data->gc, image, 0, 0,
  7.2000 +                      dstrect->x, dstrect->y, dstrect->w, dstrect->h);
  7.2001 +        } else {
  7.2002 +            XCopyArea(data->display, texturedata->pixmap, data->drawable,
  7.2003 +                      data->gc, srcrect->x, srcrect->y, dstrect->w, dstrect->h,
  7.2004 +                      srcrect->x, srcrect->y);
  7.2005          }
  7.2006 -
  7.2007 -        /* Set up fake surfaces for SDL_SoftStretch() */
  7.2008 -        SDL_zero(src);
  7.2009 -        src.format = &fmt;
  7.2010 -        src.w = texture->w;
  7.2011 -        src.h = texture->h;
  7.2012 -#ifndef NO_SHARED_MEMORY
  7.2013 -        if (texturedata->shminfo.shmaddr) {
  7.2014 -            src.pixels = texturedata->shminfo.shmaddr;
  7.2015 -        } else
  7.2016 -#endif
  7.2017 -            src.pixels = texturedata->pixels;
  7.2018 -        src.pitch = texturedata->pitch;
  7.2019 -
  7.2020 -        SDL_zero(dst);
  7.2021 -        dst.format = &fmt;
  7.2022 -        dst.w = image->width;
  7.2023 -        dst.h = image->height;
  7.2024 -        dst.pixels = image->data;
  7.2025 -        dst.pitch = image->bytes_per_line;
  7.2026 -
  7.2027 -        fmt.BytesPerPixel = SDL_BYTESPERPIXEL(texturedata->format);
  7.2028 -
  7.2029 -        rect.x = 0;
  7.2030 -        rect.y = 0;
  7.2031 -        rect.w = dstrect->w;
  7.2032 -        rect.h = dstrect->h;
  7.2033 -        if (SDL_SoftStretch(&src, srcrect, &dst, &rect) < 0) {
  7.2034 -            return -1;
  7.2035 -        }
  7.2036 -        XPutImage(data->display, data->drawable, data->gc, image, 0, 0,
  7.2037 -                  dstrect->x, dstrect->y, dstrect->w, dstrect->h);
  7.2038 -    } else {
  7.2039 -        XCopyArea(data->display, texturedata->pixmap, data->drawable,
  7.2040 -                  data->gc, srcrect->x, srcrect->y, dstrect->w, dstrect->h,
  7.2041 -                  srcrect->x, srcrect->y);
  7.2042      }
  7.2043      return 0;
  7.2044  }
  7.2045 @@ -1065,9 +2116,26 @@
  7.2046      if (!(renderer->info.flags & SDL_RENDERER_SINGLEBUFFER)) {
  7.2047          for (dirty = data->dirty.list; dirty; dirty = dirty->next) {
  7.2048              const SDL_Rect *rect = &dirty->rect;
  7.2049 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  7.2050 +            if (data->use_xrender)
  7.2051 +            {
  7.2052 +                XRenderComposite(data->display,
  7.2053 +                                 data->blend_op,
  7.2054 +                                 data->drawable_pict,
  7.2055 +                                 None,
  7.2056 +                                 data->xwindow_pict,
  7.2057 +                                 rect->x, rect->y,
  7.2058 +                                 0, 0,
  7.2059 +                                 rect->x, rect->y,
  7.2060 +                                 rect->w, rect->h);
  7.2061 +            }
  7.2062 +            else
  7.2063 +#endif
  7.2064 +            {
  7.2065              XCopyArea(data->display, data->drawable, data->xwindow,
  7.2066                        data->gc, rect->x, rect->y, rect->w, rect->h,
  7.2067                        rect->x, rect->y);
  7.2068 +            }
  7.2069          }
  7.2070          SDL_ClearDirtyRects(&data->dirty);
  7.2071      }
  7.2072 @@ -1077,9 +2145,15 @@
  7.2073      if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
  7.2074          data->current_pixmap = (data->current_pixmap + 1) % 2;
  7.2075          data->drawable = data->pixmaps[data->current_pixmap];
  7.2076 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  7.2077 +        data->drawable_pict = data->pixmap_picts[data->current_pixmap];
  7.2078 +#endif
  7.2079      } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
  7.2080          data->current_pixmap = (data->current_pixmap + 1) % 3;
  7.2081          data->drawable = data->pixmaps[data->current_pixmap];
  7.2082 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  7.2083 +        data->drawable_pict = data->pixmap_picts[data->current_pixmap];
  7.2084 +#endif
  7.2085      }
  7.2086  }
  7.2087  
  7.2088 @@ -1110,6 +2184,19 @@
  7.2089          data->pixels = NULL;
  7.2090      }
  7.2091  #endif
  7.2092 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  7.2093 +    if (renderdata->use_xrender) {
  7.2094 +        if (data->picture) {
  7.2095 +            XRenderFreePicture(renderdata->display, data->picture);
  7.2096 +        }
  7.2097 +        if (data->modulated_pixmap) {
  7.2098 +            XFreePixmap(renderdata->display, data->modulated_pixmap);
  7.2099 +        }
  7.2100 +        if (data->modulated_picture) {
  7.2101 +            XRenderFreePicture(renderdata->display, data->modulated_picture);
  7.2102 +        }
  7.2103 +    }
  7.2104 +#endif
  7.2105      if (data->scaling_image) {
  7.2106          SDL_free(data->scaling_image->data);
  7.2107          data->scaling_image->data = NULL;
  7.2108 @@ -1133,10 +2220,36 @@
  7.2109              if (data->pixmaps[i] != None) {
  7.2110                  XFreePixmap(data->display, data->pixmaps[i]);
  7.2111              }
  7.2112 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  7.2113 +            if (data->use_xrender && data->pixmap_picts[i]) {
  7.2114 +                XRenderFreePicture(data->display, data->pixmap_picts[i]);
  7.2115 +            }
  7.2116 +#endif
  7.2117          }
  7.2118          if (data->gc) {
  7.2119              XFreeGC(data->display, data->gc);
  7.2120          }
  7.2121 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  7.2122 +        if (data->use_xrender) {
  7.2123 +            if (data->stencil_gc) {
  7.2124 +                XFreeGC(data->display, data->stencil_gc);
  7.2125 +            }
  7.2126 +            if (data->stencil) {
  7.2127 +                XFreePixmap(data->display, data->stencil);
  7.2128 +            }
  7.2129 +            if (data->stencil_pict) {
  7.2130 +                XRenderFreePicture(data->display, data->stencil_pict);
  7.2131 +            }
  7.2132 +            if (data->xwindow_pict) {
  7.2133 +                XRenderFreePicture(data->display, data->xwindow_pict);
  7.2134 +            }
  7.2135 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  7.2136 +            if (data->use_xdamage && data->stencil_damage) {
  7.2137 +                XDamageDestroy(data->display, data->stencil_damage);
  7.2138 +            }
  7.2139 +#endif
  7.2140 +        }
  7.2141 +#endif
  7.2142          SDL_FreeDirtyRects(&data->dirty);
  7.2143          SDL_free(data);
  7.2144      }
     8.1 --- a/src/video/x11/SDL_x11sym.h	Tue Jul 27 21:31:28 2010 -0700
     8.2 +++ b/src/video/x11/SDL_x11sym.h	Wed Jul 28 00:54:23 2010 -0700
     8.3 @@ -156,6 +156,10 @@
     8.4  SDL_X11_SYM(SDL_X11_XESetWireToEventRetType,XESetWireToEvent,(Display* a,int b,SDL_X11_XESetWireToEventRetType c),(a,b,c),return)
     8.5  SDL_X11_SYM(SDL_X11_XESetEventToWireRetType,XESetEventToWire,(Display* a,int b,SDL_X11_XESetEventToWireRetType c),(a,b,c),return)
     8.6  SDL_X11_SYM(XExtensionErrorHandler,XSetExtensionErrorHandler,(XExtensionErrorHandler a),(a),return)
     8.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)
     8.8 +SDL_X11_SYM(int,XSetBackground,(Display *dpy,GC gc,unsigned long background),(dpy,gc,background),return)
     8.9 +SDL_X11_SYM(Status,XInitImage,(XImage *image),(image),return)
    8.10 +SDL_X11_SYM(int,XSetClipMask,(Display *dpy,GC gc,Pixmap pixmap),(dpy,gc,pixmap),return)
    8.11  
    8.12  #if NeedWidePrototypes
    8.13  SDL_X11_SYM(KeySym,XKeycodeToKeysym,(Display* a,unsigned int b,int c),(a,b,c),return)
    8.14 @@ -182,6 +186,7 @@
    8.15  SDL_X11_SYM(Status,XShmDetach,(Display* a,XShmSegmentInfo* b),(a,b),return)
    8.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)
    8.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)
    8.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)
    8.19  SDL_X11_SYM(Bool,XShmQueryExtension,(Display* a),(a),return)
    8.20  #endif
    8.21  
    8.22 @@ -237,6 +242,41 @@
    8.23  SDL_X11_SYM(void,XScreenSaverSuspend,(Display *dpy,Bool suspend),(dpy,suspend),return)
    8.24  #endif
    8.25  
    8.26 +/* XRender support */
    8.27 +#if SDL_VIDEO_DRIVER_X11_XRENDER
    8.28 +SDL_X11_MODULE(XRENDER)
    8.29 +SDL_X11_SYM(Bool,XRenderQueryExtension,(Display *dpy,int *event_base,int *error_base),(dpy,event_base,error_base),return)
    8.30 +SDL_X11_SYM(Bool,XRenderQueryVersion,(Display *dpy,int *major,int *minor),(dpy,major,minor),return)
    8.31 +SDL_X11_SYM(XRenderPictFormat*,XRenderFindVisualFormat,(Display *dpy,_Xconst Visual *visual),(dpy,visual),return)
    8.32 +SDL_X11_SYM(XRenderPictFormat*,XRenderFindStandardFormat,(Display *dpy,int format),(dpy,format),return)
    8.33 +SDL_X11_SYM(XRenderPictFormat*,XRenderFindFormat,(Display *dpy,unsigned long mask,_Xconst XRenderPictFormat* templ,int count),(dpy,mask,templ,count),return)
    8.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)
    8.35 +SDL_X11_SYM(void,XRenderFreePicture,(Display *dpy,Picture picture),(dpy,picture),return)
    8.36 +SDL_X11_SYM(void,XRenderChangePicture,(Display *dpy,Picture picture,unsigned long valuemask,_Xconst XRenderPictureAttributes* attributes),(dpy,picture,valuemask,attributes),return)
    8.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)
    8.38 +SDL_X11_SYM(Picture,XRenderCreateSolidFill,(Display *dpy,const XRenderColor *color),(dpy,color),return)
    8.39 +SDL_X11_SYM(void,XRenderSetPictureTransform,(Display *dpy,Picture picture,XTransform *transform),(dpy,picture,transform),return)
    8.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)
    8.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)
    8.42 +SDL_X11_SYM(void,XRenderSetPictureFilter,(Display *dpy,Picture picture,const char *filter,XFixed *params,int nparams),(dpy,picture,filter,params,nparams),return)
    8.43 +#endif
    8.44 +
    8.45 +#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
    8.46 +SDL_X11_MODULE(XDAMAGE)
    8.47 +SDL_X11_SYM(Bool,XDamageQueryExtension,(Display *dpy,int *event_base_return,int *error_base_return),(dpy,event_base_return,error_base_return),return)
    8.48 +SDL_X11_SYM(Status,XDamageQueryVersion,(Display *dpy,int *major,int *minor),(dpy,major,minor),return)
    8.49 +SDL_X11_SYM(Damage,XDamageCreate,(Display *dpy,Drawable d,int level),(dpy,d,level),return)
    8.50 +SDL_X11_SYM(void,XDamageSubtract,(Display *dpy,Damage damage,XserverRegion repair,XserverRegion parts),(dpy,damage,repair,parts),return)
    8.51 +SDL_X11_SYM(void,XDamageDestroy,(Display *dpy,Damage damage),(dpy,damage),return)
    8.52 +#endif
    8.53 +
    8.54 +#ifdef SDL_VIDEO_DRIVER_X11_XFIXES
    8.55 +SDL_X11_MODULE(XFIXES)
    8.56 +SDL_X11_SYM(Bool,XFixesQueryExtension,(Display *dpy,int *event_base,int *error_base),(dpy,event_base,error_base),return)
    8.57 +SDL_X11_SYM(Status,XFixesQueryVersion,(Display *dpy,int *major,int *minor),(dpy,major,minor),return)
    8.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)
    8.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)
    8.60 +#endif
    8.61  /* *INDENT-ON* */
    8.62  
    8.63  /* vi: set ts=4 sw=4 expandtab: */
     9.1 --- a/src/video/x11/SDL_x11video.h	Tue Jul 27 21:31:28 2010 -0700
     9.2 +++ b/src/video/x11/SDL_x11video.h	Wed Jul 28 00:54:23 2010 -0700
     9.3 @@ -45,7 +45,15 @@
     9.4  #if SDL_VIDEO_DRIVER_X11_SCRNSAVER
     9.5  #include <X11/extensions/scrnsaver.h>
     9.6  #endif
     9.7 -
     9.8 +#if SDL_VIDEO_DRIVER_X11_XRENDER
     9.9 +#include <X11/extensions/Xrender.h>
    9.10 +#endif
    9.11 +#if SDL_VIDEO_DRIVER_X11_XDAMAGE
    9.12 +#include <X11/extensions/Xdamage.h>
    9.13 +#endif
    9.14 +#if SDL_VIDEO_DRIVER_X11_XFIXES
    9.15 +#include <X11/extensions/Xfixes.h>
    9.16 +#endif
    9.17  #include "SDL_x11dyn.h"
    9.18  
    9.19  #include "SDL_x11clipboard.h"