Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
authorSam Lantinga <slouken@libsdl.org>
Sun, 30 Nov 2008 21:58:23 +0000
changeset 281027cb878a278e
parent 2809 7e257c3a3bf0
child 2811 7af2419ad5b0
Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
configure.in
include/SDL_config.h.in
src/video/SDL_renderer_sw.c
src/video/SDL_video.c
src/video/nds/SDL_ndsrender.c
src/video/win32/SDL_d3drender.c
src/video/win32/SDL_gdirender.c
src/video/x11/SDL_x11render.c
src/video/x11/SDL_x11render.h
src/video/x11/SDL_x11sym.h
src/video/x11/SDL_x11video.c
     1.1 --- a/configure.in	Sat Nov 29 21:48:14 2008 +0000
     1.2 +++ b/configure.in	Sun Nov 30 21:58:23 2008 +0000
     1.3 @@ -1172,6 +1172,13 @@
     1.4                      AC_DEFINE(SDL_VIDEO_DRIVER_X11_DPMS)
     1.5                  fi
     1.6              fi
     1.7 +
     1.8 +            AC_ARG_ENABLE(render-x11,
     1.9 +AC_HELP_STRING([--enable-render-x11], [enable the X11 render driver [[default=yes]]]),
    1.10 +                                , enable_render_x11=yes)
    1.11 +            if test x$enable_render_x11 = xyes; then
    1.12 +                AC_DEFINE(SDL_VIDEO_RENDER_X11)
    1.13 +            fi
    1.14          fi
    1.15      fi
    1.16  }
     2.1 --- a/include/SDL_config.h.in	Sat Nov 29 21:48:14 2008 +0000
     2.2 +++ b/include/SDL_config.h.in	Sun Nov 30 21:58:23 2008 +0000
     2.3 @@ -294,6 +294,7 @@
     2.4  #undef SDL_VIDEO_RENDER_D3D
     2.5  #undef SDL_VIDEO_RENDER_GDI
     2.6  #undef SDL_VIDEO_RENDER_OGL
     2.7 +#undef SDL_VIDEO_RENDER_X11
     2.8  
     2.9  /* Enable OpenGL support */
    2.10  #undef SDL_VIDEO_OPENGL
     3.1 --- a/src/video/SDL_renderer_sw.c	Sat Nov 29 21:48:14 2008 +0000
     3.2 +++ b/src/video/SDL_renderer_sw.c	Sun Nov 30 21:58:23 2008 +0000
     3.3 @@ -59,9 +59,6 @@
     3.4                            const SDL_Rect * rect, int markDirty, void **pixels,
     3.5                            int *pitch);
     3.6  static void SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
     3.7 -static void SW_DirtyTexture(SDL_Renderer * renderer,
     3.8 -                            SDL_Texture * texture, int numrects,
     3.9 -                            const SDL_Rect * rects);
    3.10  static int SW_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
    3.11                           Uint8 a, const SDL_Rect * rect);
    3.12  static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    3.13 @@ -84,7 +81,7 @@
    3.14        SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD |
    3.15        SDL_TEXTUREBLENDMODE_MOD),
    3.16       (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST),
    3.17 -     11,
    3.18 +     12,
    3.19       {
    3.20        SDL_PIXELFORMAT_INDEX8,
    3.21        SDL_PIXELFORMAT_RGB555,
    3.22 @@ -96,7 +93,8 @@
    3.23        SDL_PIXELFORMAT_ABGR8888,
    3.24        SDL_PIXELFORMAT_BGRA8888,
    3.25        SDL_PIXELFORMAT_YUY2,
    3.26 -      SDL_PIXELFORMAT_UYVY},
    3.27 +      SDL_PIXELFORMAT_UYVY,
    3.28 +      SDL_PIXELFORMAT_YVYU},
    3.29       0,
    3.30       0}
    3.31  };
    3.32 @@ -174,7 +172,6 @@
    3.33      renderer->UpdateTexture = SW_UpdateTexture;
    3.34      renderer->LockTexture = SW_LockTexture;
    3.35      renderer->UnlockTexture = SW_UnlockTexture;
    3.36 -    renderer->DirtyTexture = SW_DirtyTexture;
    3.37      renderer->DestroyTexture = SW_DestroyTexture;
    3.38  
    3.39      renderer->info.mod_modes = SW_RenderDriver.info.mod_modes;
    3.40 @@ -520,12 +517,6 @@
    3.41      }
    3.42  }
    3.43  
    3.44 -static void
    3.45 -SW_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    3.46 -                int numrects, const SDL_Rect * rects)
    3.47 -{
    3.48 -}
    3.49 -
    3.50  static int
    3.51  SW_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
    3.52                const SDL_Rect * rect)
     4.1 --- a/src/video/SDL_video.c	Sat Nov 29 21:48:14 2008 +0000
     4.2 +++ b/src/video/SDL_video.c	Sun Nov 30 21:58:23 2008 +0000
     4.3 @@ -1476,7 +1476,11 @@
     4.4          return 0;
     4.5      }
     4.6      renderer = SDL_CurrentDisplay.current_renderer;
     4.7 -    if (!renderer || !renderer->CreateTexture) {
     4.8 +    if (!renderer) {
     4.9 +        return 0;
    4.10 +    }
    4.11 +    if (!renderer->CreateTexture) {
    4.12 +        SDL_Unsupported();
    4.13          return 0;
    4.14      }
    4.15      texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture));
    4.16 @@ -1669,6 +1673,7 @@
    4.17      }
    4.18      renderer = texture->renderer;
    4.19      if (!renderer->QueryTexturePixels) {
    4.20 +        SDL_Unsupported();
    4.21          return -1;
    4.22      }
    4.23      return renderer->QueryTexturePixels(renderer, texture, pixels, pitch);
    4.24 @@ -1686,6 +1691,7 @@
    4.25      }
    4.26      renderer = texture->renderer;
    4.27      if (!renderer->SetTexturePalette) {
    4.28 +        SDL_Unsupported();
    4.29          return -1;
    4.30      }
    4.31      return renderer->SetTexturePalette(renderer, texture, colors, firstcolor,
    4.32 @@ -1704,6 +1710,7 @@
    4.33      }
    4.34      renderer = texture->renderer;
    4.35      if (!renderer->GetTexturePalette) {
    4.36 +        SDL_Unsupported();
    4.37          return -1;
    4.38      }
    4.39      return renderer->GetTexturePalette(renderer, texture, colors, firstcolor,
    4.40 @@ -1721,6 +1728,7 @@
    4.41      }
    4.42      renderer = texture->renderer;
    4.43      if (!renderer->SetTextureColorMod) {
    4.44 +        SDL_Unsupported();
    4.45          return -1;
    4.46      }
    4.47      if (r < 255 || g < 255 || b < 255) {
    4.48 @@ -1768,6 +1776,7 @@
    4.49      }
    4.50      renderer = texture->renderer;
    4.51      if (!renderer->SetTextureAlphaMod) {
    4.52 +        SDL_Unsupported();
    4.53          return -1;
    4.54      }
    4.55      if (alpha < 255) {
    4.56 @@ -1804,6 +1813,7 @@
    4.57      }
    4.58      renderer = texture->renderer;
    4.59      if (!renderer->SetTextureBlendMode) {
    4.60 +        SDL_Unsupported();
    4.61          return -1;
    4.62      }
    4.63      texture->blendMode = blendMode;
    4.64 @@ -1835,6 +1845,7 @@
    4.65      }
    4.66      renderer = texture->renderer;
    4.67      if (!renderer->SetTextureScaleMode) {
    4.68 +        SDL_Unsupported();
    4.69          return -1;
    4.70      }
    4.71      texture->scaleMode = scaleMode;
    4.72 @@ -1868,6 +1879,7 @@
    4.73      }
    4.74      renderer = texture->renderer;
    4.75      if (!renderer->UpdateTexture) {
    4.76 +        SDL_Unsupported();
    4.77          return -1;
    4.78      }
    4.79      if (!rect) {
    4.80 @@ -1897,6 +1909,7 @@
    4.81      }
    4.82      renderer = texture->renderer;
    4.83      if (!renderer->LockTexture) {
    4.84 +        SDL_Unsupported();
    4.85          return -1;
    4.86      }
    4.87      if (!rect) {
    4.88 @@ -1961,7 +1974,11 @@
    4.89          return -1;
    4.90      }
    4.91      renderer = SDL_CurrentDisplay.current_renderer;
    4.92 -    if (!renderer || !renderer->RenderFill) {
    4.93 +    if (!renderer) {
    4.94 +        return -1;
    4.95 +    }
    4.96 +    if(!renderer->RenderFill) {
    4.97 +        SDL_Unsupported();
    4.98          return -1;
    4.99      }
   4.100      window = SDL_GetWindowFromID(renderer->window);
   4.101 @@ -1991,7 +2008,11 @@
   4.102          return -1;
   4.103      }
   4.104      renderer = SDL_CurrentDisplay.current_renderer;
   4.105 -    if (!renderer || !renderer->RenderCopy) {
   4.106 +    if (!renderer) {
   4.107 +        return -1;
   4.108 +    }
   4.109 +    if (!renderer->RenderCopy) {
   4.110 +        SDL_Unsupported();
   4.111          return -1;
   4.112      }
   4.113      window = SDL_GetWindowFromID(renderer->window);
     5.1 --- a/src/video/nds/SDL_ndsrender.c	Sat Nov 29 21:48:14 2008 +0000
     5.2 +++ b/src/video/nds/SDL_ndsrender.c	Sun Nov 30 21:58:23 2008 +0000
     5.3 @@ -124,9 +124,6 @@
     5.4                             const SDL_Rect * rect, int markDirty,
     5.5                             void **pixels, int *pitch);
     5.6  static void NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
     5.7 -static void NDS_DirtyTexture(SDL_Renderer * renderer,
     5.8 -                             SDL_Texture * texture, int numrects,
     5.9 -                             const SDL_Rect * rects);
    5.10  static int NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g,
    5.11                            Uint8 b, Uint8 a, const SDL_Rect * rect);
    5.12  static int NDS_RenderCopy(SDL_Renderer * renderer,
    5.13 @@ -246,7 +243,6 @@
    5.14      renderer->UpdateTexture = NDS_UpdateTexture;
    5.15      renderer->LockTexture = NDS_LockTexture;
    5.16      renderer->UnlockTexture = NDS_UnlockTexture;
    5.17 -    renderer->DirtyTexture = NDS_DirtyTexture;
    5.18      renderer->DestroyTexture = NDS_DestroyTexture;
    5.19  
    5.20      renderer->info.mod_modes = NDS_RenderDriver.info.mod_modes;
    5.21 @@ -499,13 +495,6 @@
    5.22      /* stub! */
    5.23  }
    5.24  
    5.25 -static void
    5.26 -NDS_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    5.27 -                 int numrects, const SDL_Rect * rects)
    5.28 -{
    5.29 -    /* stub! */
    5.30 -}
    5.31 -
    5.32  static int
    5.33  NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
    5.34                 Uint8 a, const SDL_Rect * rect)
     6.1 --- a/src/video/win32/SDL_d3drender.c	Sat Nov 29 21:48:14 2008 +0000
     6.2 +++ b/src/video/win32/SDL_d3drender.c	Sun Nov 30 21:58:23 2008 +0000
     6.3 @@ -87,7 +87,7 @@
     6.4        SDL_TEXTUREBLENDMODE_MOD),
     6.5       (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST |
     6.6        SDL_TEXTURESCALEMODE_SLOW | SDL_TEXTURESCALEMODE_BEST),
     6.7 -     12,
     6.8 +     13,
     6.9       {
    6.10        SDL_PIXELFORMAT_INDEX8,
    6.11        SDL_PIXELFORMAT_RGB332,
    6.12 @@ -99,8 +99,9 @@
    6.13        SDL_PIXELFORMAT_RGB888,
    6.14        SDL_PIXELFORMAT_ARGB8888,
    6.15        SDL_PIXELFORMAT_ARGB2101010,
    6.16 +      SDL_PIXELFORMAT_YUY2,
    6.17        SDL_PIXELFORMAT_UYVY,
    6.18 -      SDL_PIXELFORMAT_YUY2},
    6.19 +      SDL_PIXELFORMAT_YVYU},
    6.20       0,
    6.21       0}
    6.22  };
     7.1 --- a/src/video/win32/SDL_gdirender.c	Sat Nov 29 21:48:14 2008 +0000
     7.2 +++ b/src/video/win32/SDL_gdirender.c	Sun Nov 30 21:58:23 2008 +0000
     7.3 @@ -55,8 +55,6 @@
     7.4                             const SDL_Rect * rect, int markDirty,
     7.5                             void **pixels, int *pitch);
     7.6  static void GDI_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
     7.7 -static void GDI_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
     7.8 -                             int numrects, const SDL_Rect * rects);
     7.9  static int GDI_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
    7.10                            Uint8 a, const SDL_Rect * rect);
    7.11  static int GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    7.12 @@ -78,7 +76,7 @@
    7.13       (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK |
    7.14        SDL_TEXTUREBLENDMODE_BLEND),
    7.15       (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST),
    7.16 -     11,
    7.17 +     12,
    7.18       {
    7.19        SDL_PIXELFORMAT_INDEX8,
    7.20        SDL_PIXELFORMAT_RGB555,
    7.21 @@ -90,7 +88,8 @@
    7.22        SDL_PIXELFORMAT_ABGR8888,
    7.23        SDL_PIXELFORMAT_BGRA8888,
    7.24        SDL_PIXELFORMAT_YUY2,
    7.25 -      SDL_PIXELFORMAT_UYVY},
    7.26 +      SDL_PIXELFORMAT_UYVY,
    7.27 +      SDL_PIXELFORMAT_YVYU},
    7.28       0,
    7.29       0}
    7.30  };
    7.31 @@ -173,7 +172,6 @@
    7.32      renderer->UpdateTexture = GDI_UpdateTexture;
    7.33      renderer->LockTexture = GDI_LockTexture;
    7.34      renderer->UnlockTexture = GDI_UnlockTexture;
    7.35 -    renderer->DirtyTexture = GDI_DirtyTexture;
    7.36      renderer->RenderFill = GDI_RenderFill;
    7.37      renderer->RenderCopy = GDI_RenderCopy;
    7.38      renderer->RenderPresent = GDI_RenderPresent;
    7.39 @@ -274,6 +272,8 @@
    7.40      if (n > 0) {
    7.41          SelectObject(data->render_hdc, data->hbm[0]);
    7.42      }
    7.43 +    data->current_hbm = 0;
    7.44 +
    7.45      return 0;
    7.46  }
    7.47  
    7.48 @@ -568,12 +568,6 @@
    7.49      }
    7.50  }
    7.51  
    7.52 -static void
    7.53 -GDI_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects,
    7.54 -                 const SDL_Rect * rects)
    7.55 -{
    7.56 -}
    7.57 -
    7.58  static int
    7.59  GDI_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
    7.60                 const SDL_Rect * rect)
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/video/x11/SDL_x11render.c	Sun Nov 30 21:58:23 2008 +0000
     8.3 @@ -0,0 +1,724 @@
     8.4 +/*
     8.5 +    SDL - Simple DirectMedia Layer
     8.6 +    Copyright (C) 1997-2006 Sam Lantinga
     8.7 +
     8.8 +    This library is free software; you can redistribute it and/or
     8.9 +    modify it under the terms of the GNU Lesser General Public
    8.10 +    License as published by the Free Software Foundation; either
    8.11 +    version 2.1 of the License, or (at your option) any later version.
    8.12 +
    8.13 +    This library is distributed in the hope that it will be useful,
    8.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    8.16 +    Lesser General Public License for more details.
    8.17 +
    8.18 +    You should have received a copy of the GNU Lesser General Public
    8.19 +    License along with this library; if not, write to the Free Software
    8.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    8.21 +
    8.22 +    Sam Lantinga
    8.23 +    slouken@libsdl.org
    8.24 +*/
    8.25 +#include "SDL_config.h"
    8.26 +
    8.27 +#if SDL_VIDEO_RENDER_X11
    8.28 +
    8.29 +#include "SDL_x11video.h"
    8.30 +#include "../SDL_rect_c.h"
    8.31 +#include "../SDL_pixels_c.h"
    8.32 +#include "../SDL_yuv_sw_c.h"
    8.33 +
    8.34 +/* X11 renderer implementation */
    8.35 +
    8.36 +static SDL_Renderer *X11_CreateRenderer(SDL_Window * window, Uint32 flags);
    8.37 +static int X11_DisplayModeChanged(SDL_Renderer * renderer);
    8.38 +static int X11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    8.39 +static int X11_QueryTexturePixels(SDL_Renderer * renderer,
    8.40 +                                  SDL_Texture * texture, void **pixels,
    8.41 +                                  int *pitch);
    8.42 +static int X11_SetTextureBlendMode(SDL_Renderer * renderer,
    8.43 +                                   SDL_Texture * texture);
    8.44 +static int X11_SetTextureScaleMode(SDL_Renderer * renderer,
    8.45 +                                   SDL_Texture * texture);
    8.46 +static int X11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    8.47 +                             const SDL_Rect * rect, const void *pixels,
    8.48 +                             int pitch);
    8.49 +static int X11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    8.50 +                           const SDL_Rect * rect, int markDirty,
    8.51 +                           void **pixels, int *pitch);
    8.52 +static void X11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    8.53 +static int X11_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
    8.54 +                          Uint8 a, const SDL_Rect * rect);
    8.55 +static int X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    8.56 +                          const SDL_Rect * srcrect, const SDL_Rect * dstrect);
    8.57 +static void X11_RenderPresent(SDL_Renderer * renderer);
    8.58 +static void X11_DestroyTexture(SDL_Renderer * renderer,
    8.59 +                               SDL_Texture * texture);
    8.60 +static void X11_DestroyRenderer(SDL_Renderer * renderer);
    8.61 +
    8.62 +
    8.63 +SDL_RenderDriver X11_RenderDriver = {
    8.64 +    X11_CreateRenderer,
    8.65 +    {
    8.66 +     "x11",
    8.67 +     (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
    8.68 +      SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
    8.69 +      SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED),
    8.70 +     SDL_TEXTUREMODULATE_NONE,
    8.71 +     SDL_TEXTUREBLENDMODE_NONE,
    8.72 +     SDL_TEXTURESCALEMODE_NONE,
    8.73 +     0,
    8.74 +     {0},
    8.75 +     0,
    8.76 +     0}
    8.77 +};
    8.78 +
    8.79 +typedef struct
    8.80 +{
    8.81 +    Display *display;
    8.82 +    int screen;
    8.83 +    Window window;
    8.84 +    Pixmap pixmaps[3];
    8.85 +    int current_pixmap;
    8.86 +    Drawable drawable;
    8.87 +    SDL_PixelFormat *format;
    8.88 +    GC gc;
    8.89 +    SDL_DirtyRectList dirty;
    8.90 +    SDL_bool makedirty;
    8.91 +} X11_RenderData;
    8.92 +
    8.93 +typedef struct
    8.94 +{
    8.95 +    SDL_SW_YUVTexture *yuv;
    8.96 +    Uint32 format;
    8.97 +    Pixmap pixmap;
    8.98 +    XImage *image;
    8.99 +#ifndef NO_SHARED_MEMORY
   8.100 +    /* MIT shared memory extension information */
   8.101 +    XShmSegmentInfo shminfo;
   8.102 +#endif
   8.103 +    void *pixels;
   8.104 +    int pitch;
   8.105 +} X11_TextureData;
   8.106 +
   8.107 +#ifndef NO_SHARED_MEMORY
   8.108 +/* Shared memory error handler routine */
   8.109 +static int shm_error;
   8.110 +static int (*X_handler)(Display *, XErrorEvent *) = NULL;
   8.111 +static int shm_errhandler(Display *d, XErrorEvent *e)
   8.112 +{
   8.113 +        if (e->error_code == BadAccess) {
   8.114 +            shm_error = True;
   8.115 +            return(0);
   8.116 +        } else {
   8.117 +            return(X_handler(d,e));
   8.118 +        }
   8.119 +}
   8.120 +#endif /* ! NO_SHARED_MEMORY */
   8.121 +
   8.122 +static void
   8.123 +UpdateYUVTextureData(SDL_Texture * texture)
   8.124 +{
   8.125 +    X11_TextureData *data = (X11_TextureData *) texture->driverdata;
   8.126 +    SDL_Rect rect;
   8.127 +
   8.128 +    rect.x = 0;
   8.129 +    rect.y = 0;
   8.130 +    rect.w = texture->w;
   8.131 +    rect.h = texture->h;
   8.132 +    SDL_SW_CopyYUVToRGB(data->yuv, &rect, data->format, texture->w,
   8.133 +                        texture->h, data->pixels, data->pitch);
   8.134 +}
   8.135 +
   8.136 +static Uint32
   8.137 +X11_GetPixelFormatFromDepth(Display *display, int screen, int depth, int bpp)
   8.138 +{
   8.139 +    XVisualInfo vinfo;
   8.140 +
   8.141 +    if (XMatchVisualInfo(display, screen, depth, DirectColor, &vinfo) ||
   8.142 +        XMatchVisualInfo(display, screen, depth, TrueColor, &vinfo)) {
   8.143 +        Uint32 Rmask, Gmask, Bmask, Amask;
   8.144 +
   8.145 +        Rmask = vinfo.visual->red_mask;
   8.146 +        Gmask = vinfo.visual->green_mask;
   8.147 +        Bmask = vinfo.visual->blue_mask;
   8.148 +        if (vinfo.depth == 32) {
   8.149 +            Amask = (0xFFFFFFFF & ~(Rmask | Gmask | Bmask));
   8.150 +        } else {
   8.151 +            Amask = 0;
   8.152 +        }
   8.153 +        return SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
   8.154 +    }
   8.155 +
   8.156 +    /* No matching visual, try to pick a safe default */
   8.157 +    switch (depth) {
   8.158 +        case 15:
   8.159 +            return SDL_PIXELFORMAT_RGB555;
   8.160 +        case 16:
   8.161 +            return SDL_PIXELFORMAT_RGB565;
   8.162 +        default:
   8.163 +            break;
   8.164 +    }
   8.165 +    return SDL_PIXELFORMAT_UNKNOWN;
   8.166 +}
   8.167 +
   8.168 +void
   8.169 +X11_AddRenderDriver(_THIS)
   8.170 +{
   8.171 +    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
   8.172 +    SDL_RendererInfo *info = &X11_RenderDriver.info;
   8.173 +    XPixmapFormatValues *pixmapFormats;
   8.174 +    int i, n, bpp;
   8.175 +
   8.176 +    /* Query the available texture formats */
   8.177 +    pixmapFormats = XListPixmapFormats(data->display, &n);
   8.178 +    if (pixmapFormats) {
   8.179 +        info->num_texture_formats = 0;
   8.180 +        for (i = 0; i < n; ++i) {
   8.181 +            Uint32 format;
   8.182 +
   8.183 +            if (pixmapFormats[i].depth == 24) {
   8.184 +                bpp = pixmapFormats[i].bits_per_pixel;
   8.185 +            } else {
   8.186 +                bpp = pixmapFormats[i].depth;
   8.187 +            }
   8.188 +            format = X11_GetPixelFormatFromDepth(data->display, DefaultScreen(data->display), pixmapFormats[i].depth, bpp);
   8.189 +            if (format != SDL_PIXELFORMAT_UNKNOWN) {
   8.190 +                info->texture_formats[info->num_texture_formats++] = format;
   8.191 +            }
   8.192 +        }
   8.193 +        XFree(pixmapFormats);
   8.194 +
   8.195 +        if (info->num_texture_formats == 0) {
   8.196 +            return;
   8.197 +        }
   8.198 +        info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YUY2;
   8.199 +        info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_UYVY;
   8.200 +        info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YVYU;
   8.201 +    }
   8.202 +
   8.203 +    SDL_AddRenderDriver(0, &X11_RenderDriver);
   8.204 +}
   8.205 +
   8.206 +SDL_Renderer *
   8.207 +X11_CreateRenderer(SDL_Window * window, Uint32 flags)
   8.208 +{
   8.209 +    SDL_DisplayData *displaydata =
   8.210 +        (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata;
   8.211 +    SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
   8.212 +    SDL_Renderer *renderer;
   8.213 +    SDL_RendererInfo *info;
   8.214 +    X11_RenderData *data;
   8.215 +    XWindowAttributes attributes;
   8.216 +    XGCValues gcv;
   8.217 +    int i, n;
   8.218 +    int bpp;
   8.219 +    Uint32 Rmask, Gmask, Bmask, Amask;
   8.220 +
   8.221 +    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
   8.222 +    if (!renderer) {
   8.223 +        SDL_OutOfMemory();
   8.224 +        return NULL;
   8.225 +    }
   8.226 +
   8.227 +    data = (X11_RenderData *) SDL_calloc(1, sizeof(*data));
   8.228 +    if (!data) {
   8.229 +        X11_DestroyRenderer(renderer);
   8.230 +        SDL_OutOfMemory();
   8.231 +        return NULL;
   8.232 +    }
   8.233 +    data->display = windowdata->videodata->display;
   8.234 +    data->screen = displaydata->screen;
   8.235 +    data->window = windowdata->window;
   8.236 +
   8.237 +    renderer->DisplayModeChanged = X11_DisplayModeChanged;
   8.238 +    renderer->CreateTexture = X11_CreateTexture;
   8.239 +    renderer->QueryTexturePixels = X11_QueryTexturePixels;
   8.240 +    renderer->SetTextureBlendMode = X11_SetTextureBlendMode;
   8.241 +    renderer->SetTextureScaleMode = X11_SetTextureScaleMode;
   8.242 +    renderer->UpdateTexture = X11_UpdateTexture;
   8.243 +    renderer->LockTexture = X11_LockTexture;
   8.244 +    renderer->UnlockTexture = X11_UnlockTexture;
   8.245 +    renderer->RenderFill = X11_RenderFill;
   8.246 +    renderer->RenderCopy = X11_RenderCopy;
   8.247 +    renderer->RenderPresent = X11_RenderPresent;
   8.248 +    renderer->DestroyTexture = X11_DestroyTexture;
   8.249 +    renderer->DestroyRenderer = X11_DestroyRenderer;
   8.250 +    renderer->info = X11_RenderDriver.info;
   8.251 +    renderer->window = window->id;
   8.252 +    renderer->driverdata = data;
   8.253 +
   8.254 +    renderer->info.flags = SDL_RENDERER_ACCELERATED;
   8.255 +
   8.256 +    if (flags & SDL_RENDERER_SINGLEBUFFER) {
   8.257 +        renderer->info.flags |=
   8.258 +            (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY);
   8.259 +        n = 0;
   8.260 +    } else if (flags & SDL_RENDERER_PRESENTFLIP2) {
   8.261 +        renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
   8.262 +        n = 2;
   8.263 +    } else if (flags & SDL_RENDERER_PRESENTFLIP3) {
   8.264 +        renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
   8.265 +        n = 3;
   8.266 +    } else {
   8.267 +        renderer->info.flags |= SDL_RENDERER_PRESENTCOPY;
   8.268 +        n = 1;
   8.269 +    }
   8.270 +    XGetWindowAttributes(data->display, data->window, &attributes);
   8.271 +    for (i = 0; i < n; ++i) {
   8.272 +        data->pixmaps[i] = XCreatePixmap(data->display, data->window, window->w, window->h, attributes.depth);
   8.273 +        if (data->pixmaps[i] == None) {
   8.274 +            X11_DestroyRenderer(renderer);
   8.275 +            SDL_SetError("XCreatePixmap() failed");
   8.276 +            return NULL;
   8.277 +        }
   8.278 +    }
   8.279 +    if (n > 0) {
   8.280 +        data->drawable = data->pixmaps[0];
   8.281 +        data->makedirty = SDL_TRUE;
   8.282 +    } else {
   8.283 +        data->drawable = data->window;
   8.284 +        data->makedirty = SDL_FALSE;
   8.285 +    }
   8.286 +    data->current_pixmap = 0;
   8.287 +
   8.288 +    /* Get the format of the window */
   8.289 +    bpp = attributes.depth;
   8.290 +    if (bpp == 24) {
   8.291 +        XPixmapFormatValues *p = XListPixmapFormats(data->display, &n);
   8.292 +        if (p) {
   8.293 +            for (i = 0; i < n; ++i) {
   8.294 +                if (p[i].depth == 24) {
   8.295 +                    bpp = p[i].bits_per_pixel;
   8.296 +                    break;
   8.297 +                }
   8.298 +            }
   8.299 +            XFree(p);
   8.300 +        }
   8.301 +    }
   8.302 +    Rmask = attributes.visual->red_mask;
   8.303 +    Gmask = attributes.visual->green_mask;
   8.304 +    Bmask = attributes.visual->blue_mask;
   8.305 +    if (attributes.depth == 32) {
   8.306 +        Amask = (0xFFFFFFFF & ~(Rmask | Gmask | Bmask));
   8.307 +    } else {
   8.308 +        Amask = 0;
   8.309 +    }
   8.310 +    data->format = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask);
   8.311 +    if (!data->format) {
   8.312 +        X11_DestroyRenderer(renderer);
   8.313 +        return NULL;
   8.314 +    }
   8.315 +
   8.316 +    /* Create the drawing context */
   8.317 +    gcv.graphics_exposures = False;
   8.318 +    data->gc = XCreateGC(data->display, data->window, GCGraphicsExposures, &gcv);
   8.319 +    if (!data->gc) {
   8.320 +        X11_DestroyRenderer(renderer);
   8.321 +        SDL_SetError("XCreateGC() failed");
   8.322 +        return NULL;
   8.323 +    }
   8.324 +
   8.325 +    return renderer;
   8.326 +}
   8.327 +
   8.328 +static int
   8.329 +X11_DisplayModeChanged(SDL_Renderer * renderer)
   8.330 +{
   8.331 +    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
   8.332 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   8.333 +    XWindowAttributes attributes;
   8.334 +    int i, n;
   8.335 +
   8.336 +    if (renderer->info.flags & SDL_RENDERER_SINGLEBUFFER) {
   8.337 +        n = 0;
   8.338 +    } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
   8.339 +        n = 2;
   8.340 +    } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
   8.341 +        n = 3;
   8.342 +    } else {
   8.343 +        n = 1;
   8.344 +    }
   8.345 +    for (i = 0; i < n; ++i) {
   8.346 +        if (data->pixmaps[i] != None) {
   8.347 +            XFreePixmap(data->display, data->pixmaps[i]);
   8.348 +            data->pixmaps[i] = None;
   8.349 +        }
   8.350 +    }
   8.351 +    XGetWindowAttributes(data->display, data->window, &attributes);
   8.352 +    for (i = 0; i < n; ++i) {
   8.353 +        data->pixmaps[i] = XCreatePixmap(data->display, data->window, window->w, window->h, attributes.depth);
   8.354 +        if (data->pixmaps[i] == None) {
   8.355 +            SDL_SetError("XCreatePixmap() failed");
   8.356 +            return -1;
   8.357 +        }
   8.358 +    }
   8.359 +    if (n > 0) {
   8.360 +        data->drawable = data->pixmaps[0];
   8.361 +    }
   8.362 +    data->current_pixmap = 0;
   8.363 +
   8.364 +    return 0;
   8.365 +}
   8.366 +
   8.367 +static int
   8.368 +X11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   8.369 +{
   8.370 +    X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
   8.371 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   8.372 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   8.373 +    X11_TextureData *data;
   8.374 +    XWindowAttributes attributes;
   8.375 +    int depth, order;
   8.376 +
   8.377 +    data = (X11_TextureData *) SDL_calloc(1, sizeof(*data));
   8.378 +    if (!data) {
   8.379 +        SDL_OutOfMemory();
   8.380 +        return -1;
   8.381 +    }
   8.382 +
   8.383 +    texture->driverdata = data;
   8.384 +
   8.385 +    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   8.386 +        data->yuv =
   8.387 +            SDL_SW_CreateYUVTexture(texture->format, texture->w, texture->h);
   8.388 +        if (!data->yuv) {
   8.389 +            return -1;
   8.390 +        }
   8.391 +        data->format = display->current_mode.format;
   8.392 +    } else {
   8.393 +        data->format = texture->format;
   8.394 +    }
   8.395 +    data->pitch = texture->w*SDL_BYTESPERPIXEL(data->format);
   8.396 +
   8.397 +    XGetWindowAttributes(renderdata->display, renderdata->window, &attributes);
   8.398 +    depth = SDL_BITSPERPIXEL(data->format);
   8.399 +    order = SDL_PIXELORDER(data->format);
   8.400 +    if (depth == 32 && (order == SDL_PACKEDORDER_XRGB || order == SDL_PACKEDORDER_RGBX || SDL_PACKEDORDER_XBGR || order == SDL_PACKEDORDER_BGRX)) {
   8.401 +        depth = 24;
   8.402 +    }
   8.403 +
   8.404 +    if (data->yuv || texture->access == SDL_TEXTUREACCESS_STREAMING) {
   8.405 +#ifndef NO_SHARED_MEMORY
   8.406 +        XShmSegmentInfo *shminfo = &data->shminfo;
   8.407 +
   8.408 +        shm_error = True;
   8.409 +
   8.410 +        if (SDL_X11_HAVE_SHM) {
   8.411 +            shminfo->shmid = shmget(IPC_PRIVATE, texture->h*data->pitch, IPC_CREAT | 0777);
   8.412 +            if (shminfo->shmid >= 0) {
   8.413 +                shminfo->shmaddr = (char *)shmat(shminfo->shmid, 0, 0);
   8.414 +                shminfo->readOnly = False;
   8.415 +                if (shminfo->shmaddr != (char *)-1) {
   8.416 +                    shm_error = False;
   8.417 +                    X_handler = XSetErrorHandler(shm_errhandler);
   8.418 +                    XShmAttach(renderdata->display, shminfo);
   8.419 +                    XSync(renderdata->display, True);
   8.420 +                    XSetErrorHandler(X_handler);
   8.421 +                    if (shm_error) {
   8.422 +                        shmdt(shminfo->shmaddr);
   8.423 +                    }
   8.424 +                }
   8.425 +                shmctl(shminfo->shmid, IPC_RMID, NULL);
   8.426 +            }
   8.427 +        }
   8.428 +        if (!shm_error) {
   8.429 +            data->pixels = shminfo->shmaddr;
   8.430 +
   8.431 +            data->image = XShmCreateImage(renderdata->display, attributes.visual, depth, ZPixmap, shminfo->shmaddr, shminfo, texture->w, texture->h);
   8.432 +            if(!data->image) {
   8.433 +                XShmDetach(renderdata->display, shminfo);
   8.434 +                XSync(renderdata->display, False);
   8.435 +                shmdt(shminfo->shmaddr);
   8.436 +                shm_error = True;
   8.437 +            }
   8.438 +        }
   8.439 +        if (shm_error) {
   8.440 +            shminfo->shmaddr = NULL;
   8.441 +        }
   8.442 +        if (!data->image)
   8.443 +#endif /* not NO_SHARED_MEMORY */
   8.444 +        {
   8.445 +            data->pixels = SDL_malloc(texture->h * data->pitch);
   8.446 +            if (!data->pixels) {
   8.447 +                SDL_OutOfMemory();
   8.448 +                return -1;
   8.449 +            }
   8.450 +
   8.451 +            data->image = XCreateImage(renderdata->display, attributes.visual, depth, ZPixmap, 0, data->pixels, texture->w, texture->h, SDL_BYTESPERPIXEL(data->format)*8, data->pitch);
   8.452 +            if (!data->image) {
   8.453 +                SDL_SetError("XCreateImage() failed");
   8.454 +                return -1;
   8.455 +            }
   8.456 +        }
   8.457 +    } else {
   8.458 +        data->pixmap = XCreatePixmap(renderdata->display, renderdata->window, texture->w, texture->h, depth);
   8.459 +        if (data->pixmap == None) {
   8.460 +            SDL_SetError("XCteatePixmap() failed");
   8.461 +            return -1;
   8.462 +        }
   8.463 +
   8.464 +        data->image = XCreateImage(renderdata->display, attributes.visual, depth, ZPixmap, 0, NULL, texture->w, texture->h, SDL_BYTESPERPIXEL(data->format)*8, data->pitch);
   8.465 +        if (!data->image) {
   8.466 +            SDL_SetError("XCreateImage() failed");
   8.467 +            return -1;
   8.468 +        }
   8.469 +    }
   8.470 +
   8.471 +    return 0;
   8.472 +}
   8.473 +
   8.474 +static int
   8.475 +X11_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
   8.476 +                       void **pixels, int *pitch)
   8.477 +{
   8.478 +    X11_TextureData *data = (X11_TextureData *) texture->driverdata;
   8.479 +
   8.480 +    if (data->yuv) {
   8.481 +        return SDL_SW_QueryYUVTexturePixels(data->yuv, pixels, pitch);
   8.482 +    } else {
   8.483 +        *pixels = data->pixels;
   8.484 +        *pitch = data->pitch;
   8.485 +        return 0;
   8.486 +    }
   8.487 +}
   8.488 +
   8.489 +static int
   8.490 +X11_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
   8.491 +{
   8.492 +    switch (texture->blendMode) {
   8.493 +    case SDL_TEXTUREBLENDMODE_NONE:
   8.494 +        return 0;
   8.495 +    default:
   8.496 +        SDL_Unsupported();
   8.497 +        texture->blendMode = SDL_TEXTUREBLENDMODE_NONE;
   8.498 +        return -1;
   8.499 +    }
   8.500 +}
   8.501 +
   8.502 +static int
   8.503 +X11_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
   8.504 +{
   8.505 +    switch (texture->scaleMode) {
   8.506 +    case SDL_TEXTURESCALEMODE_NONE:
   8.507 +        return 0;
   8.508 +    default:
   8.509 +        SDL_Unsupported();
   8.510 +        texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
   8.511 +        return -1;
   8.512 +    }
   8.513 +    return 0;
   8.514 +}
   8.515 +
   8.516 +static int
   8.517 +X11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   8.518 +                  const SDL_Rect * rect, const void *pixels, int pitch)
   8.519 +{
   8.520 +    X11_TextureData *data = (X11_TextureData *) texture->driverdata;
   8.521 +
   8.522 +    if (data->yuv) {
   8.523 +        if (SDL_SW_UpdateYUVTexture(data->yuv, rect, pixels, pitch) < 0) {
   8.524 +            return -1;
   8.525 +        }
   8.526 +        UpdateYUVTextureData(texture);
   8.527 +        return 0;
   8.528 +    } else {
   8.529 +        X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
   8.530 +
   8.531 +        if (data->pixels) {
   8.532 +            Uint8 *src, *dst;
   8.533 +            int row;
   8.534 +            size_t length;
   8.535 +
   8.536 +            src = (Uint8 *) pixels;
   8.537 +            dst =
   8.538 +                (Uint8 *) data->pixels + rect->y * data->pitch +
   8.539 +                rect->x * SDL_BYTESPERPIXEL(texture->format);
   8.540 +            length = rect->w * SDL_BYTESPERPIXEL(texture->format);
   8.541 +            for (row = 0; row < rect->h; ++row) {
   8.542 +                SDL_memcpy(dst, src, length);
   8.543 +                src += pitch;
   8.544 +                dst += data->pitch;
   8.545 +            }
   8.546 +        } else {
   8.547 +            data->image->width = rect->w;
   8.548 +            data->image->height = rect->h;
   8.549 +            data->image->data = (char *)pixels;
   8.550 +            data->image->bytes_per_line = pitch;
   8.551 +            XPutImage(renderdata->display, data->pixmap, renderdata->gc, data->image, 0, 0, rect->x, rect->y, rect->w, rect->h);
   8.552 +        }
   8.553 +        return 0;
   8.554 +    }
   8.555 +}
   8.556 +
   8.557 +static int
   8.558 +X11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   8.559 +                const SDL_Rect * rect, int markDirty, void **pixels,
   8.560 +                int *pitch)
   8.561 +{
   8.562 +    X11_TextureData *data = (X11_TextureData *) texture->driverdata;
   8.563 +
   8.564 +    if (data->yuv) {
   8.565 +        return SDL_SW_LockYUVTexture(data->yuv, rect, markDirty, pixels,
   8.566 +                                     pitch);
   8.567 +    } else if (data->pixels) {
   8.568 +        *pixels =
   8.569 +            (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
   8.570 +                      rect->x * SDL_BYTESPERPIXEL(texture->format));
   8.571 +        *pitch = data->pitch;
   8.572 +        return 0;
   8.573 +    } else {
   8.574 +        SDL_SetError("No pixels available");
   8.575 +        return -1;
   8.576 +    }
   8.577 +}
   8.578 +
   8.579 +static void
   8.580 +X11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   8.581 +{
   8.582 +    X11_TextureData *data = (X11_TextureData *) texture->driverdata;
   8.583 +
   8.584 +    if (data->yuv) {
   8.585 +        SDL_SW_UnlockYUVTexture(data->yuv);
   8.586 +        UpdateYUVTextureData(texture);
   8.587 +    }
   8.588 +}
   8.589 +
   8.590 +static int
   8.591 +X11_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
   8.592 +               const SDL_Rect * rect)
   8.593 +{
   8.594 +    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
   8.595 +    unsigned long foreground;
   8.596 +
   8.597 +    if (data->makedirty) {
   8.598 +        SDL_AddDirtyRect(&data->dirty, rect);
   8.599 +    }
   8.600 +
   8.601 +    foreground = SDL_MapRGBA(data->format, r, g, b, a);
   8.602 +    XSetForeground(data->display, data->gc, foreground);
   8.603 +    XDrawRectangle(data->display, data->drawable, data->gc, rect->x, rect->y, rect->w, rect->h);
   8.604 +    return 0;
   8.605 +}
   8.606 +
   8.607 +static int
   8.608 +X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   8.609 +               const SDL_Rect * srcrect, const SDL_Rect * dstrect)
   8.610 +{
   8.611 +    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
   8.612 +    X11_TextureData *texturedata = (X11_TextureData *) texture->driverdata;
   8.613 +
   8.614 +    if (data->makedirty) {
   8.615 +        SDL_AddDirtyRect(&data->dirty, dstrect);
   8.616 +    }
   8.617 +
   8.618 +    if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
   8.619 +#ifndef NO_SHARED_MEMORY
   8.620 +        if (texturedata->shminfo.shmaddr) {
   8.621 +            XShmPutImage(data->display, data->drawable, data->gc, texturedata->image, srcrect->x, srcrect->y, dstrect->x, dstrect->y, dstrect->w, dstrect->h, False);
   8.622 +        }
   8.623 +        else
   8.624 +#endif
   8.625 +        if (texturedata->pixels) {
   8.626 +            XPutImage(data->display, data->drawable, data->gc, texturedata->image, srcrect->x, srcrect->y, dstrect->x, dstrect->y, dstrect->w, dstrect->h);
   8.627 +        } else {
   8.628 +            XCopyArea(data->display, texturedata->pixmap, data->drawable,
   8.629 +                      data->gc, srcrect->x, srcrect->y, dstrect->w, dstrect->h,
   8.630 +                      dstrect->x, dstrect->y);
   8.631 +        }
   8.632 +    } else {
   8.633 +        SDL_SetError("Scaling not supported in the X11 renderer");
   8.634 +        return -1;
   8.635 +    }
   8.636 +    return 0;
   8.637 +}
   8.638 +
   8.639 +static void
   8.640 +X11_RenderPresent(SDL_Renderer * renderer)
   8.641 +{
   8.642 +    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
   8.643 +    SDL_DirtyRect *dirty;
   8.644 +
   8.645 +    /* Send the data to the display */
   8.646 +    if (!(renderer->info.flags & SDL_RENDERER_SINGLEBUFFER)) {
   8.647 +        for (dirty = data->dirty.list; dirty; dirty = dirty->next) {
   8.648 +            const SDL_Rect *rect = &dirty->rect;
   8.649 +            XCopyArea(data->display, data->drawable, data->window,
   8.650 +                      data->gc, rect->x, rect->y, rect->w, rect->h,
   8.651 +                      rect->x, rect->y);
   8.652 +        }
   8.653 +        SDL_ClearDirtyRects(&data->dirty);
   8.654 +    }
   8.655 +    XSync(data->display, False);
   8.656 +
   8.657 +    /* Update the flipping chain, if any */
   8.658 +    if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
   8.659 +        data->current_pixmap = (data->current_pixmap + 1) % 2;
   8.660 +        data->drawable = data->pixmaps[data->current_pixmap];
   8.661 +    } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
   8.662 +        data->current_pixmap = (data->current_pixmap + 1) % 3;
   8.663 +        data->drawable = data->pixmaps[data->current_pixmap];
   8.664 +    }
   8.665 +}
   8.666 +
   8.667 +static void
   8.668 +X11_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   8.669 +{
   8.670 +    X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
   8.671 +    X11_TextureData *data = (X11_TextureData *) texture->driverdata;
   8.672 +
   8.673 +    if (!data) {
   8.674 +        return;
   8.675 +    }
   8.676 +    if (data->yuv) {
   8.677 +        SDL_SW_DestroyYUVTexture(data->yuv);
   8.678 +    }
   8.679 +    if (data->pixmap != None) {
   8.680 +        XFreePixmap(renderdata->display, data->pixmap);
   8.681 +    }
   8.682 +    if (data->image) {
   8.683 +        data->image->data = NULL;
   8.684 +        XDestroyImage(data->image);
   8.685 +    }
   8.686 +#ifndef NO_SHARED_MEMORY
   8.687 +    if (data->shminfo.shmaddr) {
   8.688 +        XShmDetach(renderdata->display, &data->shminfo);
   8.689 +        XSync(renderdata->display, False);
   8.690 +        shmdt(data->shminfo.shmaddr);
   8.691 +        data->pixels = NULL;
   8.692 +    }
   8.693 +#endif
   8.694 +    if (data->pixels) {
   8.695 +        SDL_free(data->pixels);
   8.696 +    }
   8.697 +    SDL_free(data);
   8.698 +    texture->driverdata = NULL;
   8.699 +}
   8.700 +
   8.701 +static void
   8.702 +X11_DestroyRenderer(SDL_Renderer * renderer)
   8.703 +{
   8.704 +    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
   8.705 +    int i;
   8.706 +
   8.707 +    if (data) {
   8.708 +        for (i = 0; i < SDL_arraysize(data->pixmaps); ++i) {
   8.709 +            if (data->pixmaps[i] != None) {
   8.710 +                XFreePixmap(data->display, data->pixmaps[i]);
   8.711 +            }
   8.712 +        }
   8.713 +        if (data->format) {
   8.714 +            SDL_FreeFormat(data->format);
   8.715 +        }
   8.716 +        if (data->gc) {
   8.717 +            XFreeGC(data->display, data->gc);
   8.718 +        }
   8.719 +        SDL_FreeDirtyRects(&data->dirty);
   8.720 +        SDL_free(data);
   8.721 +    }
   8.722 +    SDL_free(renderer);
   8.723 +}
   8.724 +
   8.725 +#endif /* SDL_VIDEO_RENDER_X11 */
   8.726 +
   8.727 +/* vi: set ts=4 sw=4 expandtab: */
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/video/x11/SDL_x11render.h	Sun Nov 30 21:58:23 2008 +0000
     9.3 @@ -0,0 +1,30 @@
     9.4 +/*
     9.5 +    SDL - Simple DirectMedia Layer
     9.6 +    Copyright (C) 1997-2006 Sam Lantinga
     9.7 +
     9.8 +    This library is free software; you can redistribute it and/or
     9.9 +    modify it under the terms of the GNU Lesser General Public
    9.10 +    License as published by the Free Software Foundation; either
    9.11 +    version 2.1 of the License, or (at your option) any later version.
    9.12 +
    9.13 +    This library is distributed in the hope that it will be useful,
    9.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    9.16 +    Lesser General Public License for more details.
    9.17 +
    9.18 +    You should have received a copy of the GNU Lesser General Public
    9.19 +    License along with this library; if not, write to the Free Software
    9.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    9.21 +
    9.22 +    Sam Lantinga
    9.23 +    slouken@libsdl.org
    9.24 +*/
    9.25 +#include "SDL_config.h"
    9.26 +
    9.27 +/* SDL surface based renderer implementation */
    9.28 +
    9.29 +#if SDL_VIDEO_RENDER_X11
    9.30 +extern void X11_AddRenderDriver(_THIS);
    9.31 +#endif
    9.32 +
    9.33 +/* vi: set ts=4 sw=4 expandtab: */
    10.1 --- a/src/video/x11/SDL_x11sym.h	Sat Nov 29 21:48:14 2008 +0000
    10.2 +++ b/src/video/x11/SDL_x11sym.h	Sun Nov 30 21:58:23 2008 +0000
    10.3 @@ -37,6 +37,7 @@
    10.4  SDL_X11_SYM(Bool,XCheckWindowEvent,(Display* a,Window b,long c,XEvent* d),(a,b,c,d),return)
    10.5  SDL_X11_SYM(int,XClearWindow,(Display* a,Window b),(a,b),return)
    10.6  SDL_X11_SYM(int,XCloseDisplay,(Display* a),(a),return)
    10.7 +SDL_X11_SYM(int,XCopyArea,(Display* a,Drawable b,Drawable c,GC d,int e,int f,unsigned int g,unsigned int h,int i,int j),(a,b,c,d,e,f,g,h,i,j),return)
    10.8  SDL_X11_SYM(Colormap,XCreateColormap,(Display* a,Window b,Visual* c,int d),(a,b,c,d),return)
    10.9  SDL_X11_SYM(Cursor,XCreatePixmapCursor,(Display* a,Pixmap b,Pixmap c,XColor* d,XColor* e,unsigned int f,unsigned int g),(a,b,c,d,e,f,g),return)
   10.10  SDL_X11_SYM(GC,XCreateGC,(Display* a,Drawable b,unsigned long c,XGCValues* d),(a,b,c,d),return)
   10.11 @@ -49,6 +50,7 @@
   10.12  SDL_X11_SYM(int,XDeleteProperty,(Display* a,Window b,Atom c),(a,b,c),return)
   10.13  SDL_X11_SYM(int,XDestroyWindow,(Display* a,Window b),(a,b),return)
   10.14  SDL_X11_SYM(int,XDisplayKeycodes,(Display* a,int* b,int* c),(a,b,c),return)
   10.15 +SDL_X11_SYM(int,XDrawRectangle,(Display* a,Drawable b,GC c,int d, int e, unsigned int f, unsigned int g),(a,b,c,d,e,f,g),return)
   10.16  SDL_X11_SYM(char*,XDisplayName,(_Xconst char* a),(a),return)
   10.17  SDL_X11_SYM(int,XEventsQueued,(Display* a,int b),(a,b),return)
   10.18  SDL_X11_SYM(Bool,XFilterEvent,(XEvent *event,Window w),(event,w),return)
   10.19 @@ -102,6 +104,7 @@
   10.20  SDL_X11_SYM(Status,XSendEvent,(Display* a,Window b,Bool c,long d,XEvent* e),(a,b,c,d,e),return)
   10.21  SDL_X11_SYM(int,XSetClassHint,(Display* a,Window b,XClassHint* c),(a,b,c),return)
   10.22  SDL_X11_SYM(int,XSetCloseDownMode,(Display *a, int b),(a,b),return)
   10.23 +SDL_X11_SYM(int,XSetForeground,(Display* a,GC b,unsigned long c),(a,b,c),return)
   10.24  SDL_X11_SYM(XErrorHandler,XSetErrorHandler,(XErrorHandler a),(a),return)
   10.25  SDL_X11_SYM(XIOErrorHandler,XSetIOErrorHandler,(XIOErrorHandler a),(a),return)
   10.26  SDL_X11_SYM(void,XSetRGBColormaps,( Display *a,Window b,XStandardColormap *c,int d,Atom e),(a,b,c,d,e),return)
    11.1 --- a/src/video/x11/SDL_x11video.c	Sat Nov 29 21:48:14 2008 +0000
    11.2 +++ b/src/video/x11/SDL_x11video.c	Sun Nov 30 21:58:23 2008 +0000
    11.3 @@ -244,6 +244,10 @@
    11.4  
    11.5      X11_InitModes(_this);
    11.6  
    11.7 +#if SDL_VIDEO_RENDER_X11
    11.8 +    X11_AddRenderDriver(_this);
    11.9 +#endif
   11.10 +
   11.11      if (X11_InitKeyboard(_this) != 0) {
   11.12          return -1;
   11.13      }