Removed partially functional renderers
authorSam Lantinga <slouken@libsdl.org>
Mon, 31 Jan 2011 22:21:29 -0800
changeset 5137e594f07297a9
parent 5136 1a47d41912ff
child 5138 da10636e5eca
Removed partially functional renderers
VisualC/SDL/SDL_VS2005.vcproj
VisualC/SDL/SDL_VS2008.vcproj
VisualC/SDL/SDL_VS2010.vcxproj
configure.in
include/SDL_config.h.in
include/SDL_config_macosx.h
include/SDL_config_windows.h
src/video/windows/SDL_gdirender.c
src/video/windows/SDL_gdirender.h
src/video/windows/SDL_windowsvideo.c
src/video/x11/SDL_x11render.c
src/video/x11/SDL_x11render.h
src/video/x11/SDL_x11video.c
     1.1 --- a/VisualC/SDL/SDL_VS2005.vcproj	Tue Feb 01 12:01:37 2011 -0800
     1.2 +++ b/VisualC/SDL/SDL_VS2005.vcproj	Mon Jan 31 22:21:29 2011 -0800
     1.3 @@ -856,14 +856,6 @@
     1.4  			>
     1.5  		</File>
     1.6  		<File
     1.7 -			RelativePath="..\..\src\video\windows\SDL_gdirender.c"
     1.8 -			>
     1.9 -		</File>
    1.10 -		<File
    1.11 -			RelativePath="..\..\src\video\windows\SDL_gdirender.h"
    1.12 -			>
    1.13 -		</File>
    1.14 -		<File
    1.15  			RelativePath="..\..\src\events\SDL_gesture.c"
    1.16  			>
    1.17  		</File>
     2.1 --- a/VisualC/SDL/SDL_VS2008.vcproj	Tue Feb 01 12:01:37 2011 -0800
     2.2 +++ b/VisualC/SDL/SDL_VS2008.vcproj	Mon Jan 31 22:21:29 2011 -0800
     2.3 @@ -843,14 +843,6 @@
     2.4  			>
     2.5  		</File>
     2.6  		<File
     2.7 -			RelativePath="..\..\src\video\windows\SDL_gdirender.c"
     2.8 -			>
     2.9 -		</File>
    2.10 -		<File
    2.11 -			RelativePath="..\..\src\video\windows\SDL_gdirender.h"
    2.12 -			>
    2.13 -		</File>
    2.14 -		<File
    2.15  			RelativePath="..\..\src\events\SDL_gesture.c"
    2.16  			>
    2.17  		</File>
     3.1 --- a/VisualC/SDL/SDL_VS2010.vcxproj	Tue Feb 01 12:01:37 2011 -0800
     3.2 +++ b/VisualC/SDL/SDL_VS2010.vcxproj	Mon Jan 31 22:21:29 2011 -0800
     3.3 @@ -296,7 +296,6 @@
     3.4      <ClInclude Include="..\..\src\SDL_error_c.h" />
     3.5      <ClInclude Include="..\..\src\events\SDL_events_c.h" />
     3.6      <ClInclude Include="..\..\src\SDL_fatal.h" />
     3.7 -    <ClInclude Include="..\..\src\video\windows\SDL_gdirender.h" />
     3.8      <ClInclude Include="..\..\src\video\SDL_glesfuncs.h" />
     3.9      <ClInclude Include="..\..\src\video\SDL_glfuncs.h" />
    3.10      <ClInclude Include="..\..\src\joystick\SDL_joystick_c.h" />
    3.11 @@ -401,7 +400,6 @@
    3.12      <ClCompile Include="..\..\src\SDL_fatal.c" />
    3.13      <ClCompile Include="..\..\src\video\SDL_fillrect.c" />
    3.14      <ClCompile Include="..\..\src\video\SDL_gamma.c" />
    3.15 -    <ClCompile Include="..\..\src\video\windows\SDL_gdirender.c" />
    3.16      <ClCompile Include="..\..\src\stdlib\SDL_getenv.c" />
    3.17      <ClCompile Include="..\..\src\haptic\SDL_haptic.c" />
    3.18      <ClCompile Include="..\..\src\stdlib\SDL_iconv.c" />
     4.1 --- a/configure.in	Tue Feb 01 12:01:37 2011 -0800
     4.2 +++ b/configure.in	Mon Jan 31 22:21:29 2011 -0800
     4.3 @@ -1322,12 +1322,6 @@
     4.4                  AC_DEFINE(SDL_VIDEO_DRIVER_X11_XDAMAGE)
     4.5                  AC_DEFINE(SDL_VIDEO_DRIVER_X11_XFIXES)
     4.6              fi
     4.7 -            AC_ARG_ENABLE(render-x11,
     4.8 -AC_HELP_STRING([--enable-render-x11], [enable the X11 render driver [[default=yes]]]),
     4.9 -                                , enable_render_x11=yes)
    4.10 -            if test x$enable_render_x11 = xyes; then
    4.11 -                AC_DEFINE(SDL_VIDEO_RENDER_X11)
    4.12 -            fi
    4.13          fi
    4.14      fi
    4.15  }
    4.16 @@ -2351,12 +2345,6 @@
    4.17              AC_DEFINE(SDL_VIDEO_DRIVER_WINDOWS)
    4.18              SOURCES="$SOURCES $srcdir/src/video/windows/*.c"
    4.19              have_video=yes
    4.20 -            AC_ARG_ENABLE(render-gdi,
    4.21 -AC_HELP_STRING([--enable-render-gdi], [enable the GDI render driver [[default=yes]]]),
    4.22 -                                , enable_render_gdi=yes)
    4.23 -            if test x$enable_render_gdi = xyes; then
    4.24 -                AC_DEFINE(SDL_VIDEO_RENDER_GDI)
    4.25 -            fi
    4.26              AC_ARG_ENABLE(render-gapi,
    4.27  AC_HELP_STRING([--enable-render-gapi], [enable the GAPI/RAWFRAMEBUFFER render driver [[default=yes]]]),
    4.28                                  , enable_render_gapi=yes)
    4.29 @@ -2457,12 +2445,6 @@
    4.30              AC_DEFINE(SDL_VIDEO_DRIVER_WINDOWS)
    4.31              SOURCES="$SOURCES $srcdir/src/video/windows/*.c"
    4.32              have_video=yes
    4.33 -            AC_ARG_ENABLE(render-gdi,
    4.34 -AC_HELP_STRING([--enable-render-gdi], [enable the GDI render driver [[default=yes]]]),
    4.35 -                                , enable_render_gdi=yes)
    4.36 -            if test x$enable_render_gdi = xyes; then
    4.37 -                AC_DEFINE(SDL_VIDEO_RENDER_GDI)
    4.38 -            fi
    4.39              AC_ARG_ENABLE(render-d3d,
    4.40  AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[default=yes]]]),
    4.41                                  , enable_render_d3d=yes)
     5.1 --- a/include/SDL_config.h.in	Tue Feb 01 12:01:37 2011 -0800
     5.2 +++ b/include/SDL_config.h.in	Mon Jan 31 22:21:29 2011 -0800
     5.3 @@ -285,10 +285,8 @@
     5.4  #undef SDL_VIDEO_DRIVER_X11_XSHAPE
     5.5  
     5.6  #undef SDL_VIDEO_RENDER_D3D
     5.7 -#undef SDL_VIDEO_RENDER_GDI
     5.8  #undef SDL_VIDEO_RENDER_OGL
     5.9  #undef SDL_VIDEO_RENDER_OGL_ES
    5.10 -#undef SDL_VIDEO_RENDER_X11
    5.11  #undef SDL_VIDEO_RENDER_GAPI
    5.12  #undef SDL_VIDEO_RENDER_DDRAW
    5.13  
     6.1 --- a/include/SDL_config_macosx.h	Tue Feb 01 12:01:37 2011 -0800
     6.2 +++ b/include/SDL_config_macosx.h	Mon Jan 31 22:21:29 2011 -0800
     6.3 @@ -151,9 +151,6 @@
     6.4  #ifndef SDL_VIDEO_RENDER_OGL
     6.5  #define SDL_VIDEO_RENDER_OGL	1
     6.6  #endif
     6.7 -#ifndef SDL_VIDEO_RENDER_X11
     6.8 -#define SDL_VIDEO_RENDER_X11	1
     6.9 -#endif
    6.10  
    6.11  /* Enable OpenGL support */
    6.12  #ifndef SDL_VIDEO_OPENGL
     7.1 --- a/include/SDL_config_windows.h	Tue Feb 01 12:01:37 2011 -0800
     7.2 +++ b/include/SDL_config_windows.h	Mon Jan 31 22:21:29 2011 -0800
     7.3 @@ -187,9 +187,6 @@
     7.4  #define SDL_VIDEO_RENDER_D3D	1
     7.5  #endif
     7.6  #endif
     7.7 -#ifndef SDL_VIDEO_RENDER_GDI
     7.8 -#define SDL_VIDEO_RENDER_GDI	1
     7.9 -#endif
    7.10  
    7.11  /* Enable OpenGL support */
    7.12  #ifndef _WIN32_WCE
     8.1 --- a/src/video/windows/SDL_gdirender.c	Tue Feb 01 12:01:37 2011 -0800
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,1129 +0,0 @@
     8.4 -/*
     8.5 -    SDL - Simple DirectMedia Layer
     8.6 -    Copyright (C) 1997-2010 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_GDI
    8.28 -
    8.29 -#include "SDL_windowsvideo.h"
    8.30 -#include "../SDL_rect_c.h"
    8.31 -#include "../SDL_yuv_sw_c.h"
    8.32 -#include "../SDL_alphamult.h"
    8.33 -
    8.34 -#ifdef _WIN32_WCE
    8.35 -#define NO_GETDIBBITS 1
    8.36 -#endif
    8.37 -
    8.38 -/* GDI renderer implementation */
    8.39 -
    8.40 -static SDL_Renderer *GDI_CreateRenderer(SDL_Window * window, Uint32 flags);
    8.41 -static int GDI_DisplayModeChanged(SDL_Renderer * renderer);
    8.42 -static int GDI_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    8.43 -static int GDI_QueryTexturePixels(SDL_Renderer * renderer,
    8.44 -                                  SDL_Texture * texture, void **pixels,
    8.45 -                                  int *pitch);
    8.46 -static int GDI_SetTexturePalette(SDL_Renderer * renderer,
    8.47 -                                 SDL_Texture * texture,
    8.48 -                                 const SDL_Color * colors, int firstcolor,
    8.49 -                                 int ncolors);
    8.50 -static int GDI_GetTexturePalette(SDL_Renderer * renderer,
    8.51 -                                 SDL_Texture * texture, SDL_Color * colors,
    8.52 -                                 int firstcolor, int ncolors);
    8.53 -static int GDI_SetTextureAlphaMod(SDL_Renderer * renderer,
    8.54 -                                  SDL_Texture * texture);
    8.55 -static int GDI_SetTextureBlendMode(SDL_Renderer * renderer,
    8.56 -                                   SDL_Texture * texture);
    8.57 -static int GDI_SetTextureScaleMode(SDL_Renderer * renderer,
    8.58 -                                   SDL_Texture * texture);
    8.59 -static int GDI_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    8.60 -                             const SDL_Rect * rect, const void *pixels,
    8.61 -                             int pitch);
    8.62 -static int GDI_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    8.63 -                           const SDL_Rect * rect, int markDirty,
    8.64 -                           void **pixels, int *pitch);
    8.65 -static void GDI_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    8.66 -static int GDI_SetDrawBlendMode(SDL_Renderer * renderer);
    8.67 -static int GDI_RenderDrawPoints(SDL_Renderer * renderer,
    8.68 -                                const SDL_Point * points, int count);
    8.69 -static int GDI_RenderDrawLines(SDL_Renderer * renderer,
    8.70 -                               const SDL_Point * points, int count);
    8.71 -static int GDI_RenderDrawRects(SDL_Renderer * renderer,
    8.72 -                               const SDL_Rect ** rects, int count);
    8.73 -static int GDI_RenderFillRects(SDL_Renderer * renderer,
    8.74 -                               const SDL_Rect ** rects, int count);
    8.75 -static int GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    8.76 -                          const SDL_Rect * srcrect, const SDL_Rect * dstrect);
    8.77 -static int GDI_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
    8.78 -                                Uint32 format, void * pixels, int pitch);
    8.79 -static int GDI_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
    8.80 -                                 Uint32 format, const void * pixels, int pitch);
    8.81 -static void GDI_RenderPresent(SDL_Renderer * renderer);
    8.82 -static void GDI_DestroyTexture(SDL_Renderer * renderer,
    8.83 -                               SDL_Texture * texture);
    8.84 -static void GDI_DestroyRenderer(SDL_Renderer * renderer);
    8.85 -
    8.86 -
    8.87 -SDL_RenderDriver GDI_RenderDriver = {
    8.88 -    GDI_CreateRenderer,
    8.89 -    {
    8.90 -     "gdi",
    8.91 -     (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
    8.92 -      SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
    8.93 -      SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED),
    8.94 -     (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_ALPHA),
    8.95 -     (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK),
    8.96 -     (SDL_SCALEMODE_NONE | SDL_SCALEMODE_FAST),
    8.97 -     14,
    8.98 -     {
    8.99 -      SDL_PIXELFORMAT_INDEX8,
   8.100 -      SDL_PIXELFORMAT_RGB555,
   8.101 -      SDL_PIXELFORMAT_RGB565,
   8.102 -      SDL_PIXELFORMAT_RGB888,
   8.103 -      SDL_PIXELFORMAT_BGR888,
   8.104 -      SDL_PIXELFORMAT_ARGB8888,
   8.105 -      SDL_PIXELFORMAT_RGBA8888,
   8.106 -      SDL_PIXELFORMAT_ABGR8888,
   8.107 -      SDL_PIXELFORMAT_BGRA8888,
   8.108 -      SDL_PIXELFORMAT_YV12,
   8.109 -      SDL_PIXELFORMAT_IYUV,
   8.110 -      SDL_PIXELFORMAT_YUY2,
   8.111 -      SDL_PIXELFORMAT_UYVY,
   8.112 -      SDL_PIXELFORMAT_YVYU},
   8.113 -     0,
   8.114 -     0}
   8.115 -};
   8.116 -
   8.117 -typedef struct
   8.118 -{
   8.119 -    HWND hwnd;
   8.120 -    HDC window_hdc;
   8.121 -    HDC render_hdc;
   8.122 -    HDC memory_hdc;
   8.123 -    HDC current_hdc;
   8.124 -#ifndef NO_GETDIBBITS
   8.125 -    LPBITMAPINFO bmi;
   8.126 -#endif
   8.127 -    HBITMAP hbm[3];
   8.128 -    int current_hbm;
   8.129 -    SDL_DirtyRectList dirty;
   8.130 -    SDL_bool makedirty;
   8.131 -} GDI_RenderData;
   8.132 -
   8.133 -typedef struct
   8.134 -{
   8.135 -    SDL_SW_YUVTexture *yuv;
   8.136 -    Uint32 format;
   8.137 -    HPALETTE hpal;
   8.138 -    HBITMAP hbm;
   8.139 -    void *pixels;
   8.140 -    int pitch;
   8.141 -    SDL_bool premultiplied;
   8.142 -} GDI_TextureData;
   8.143 -
   8.144 -static void
   8.145 -UpdateYUVTextureData(SDL_Texture * texture)
   8.146 -{
   8.147 -    GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
   8.148 -    SDL_Rect rect;
   8.149 -
   8.150 -    rect.x = 0;
   8.151 -    rect.y = 0;
   8.152 -    rect.w = texture->w;
   8.153 -    rect.h = texture->h;
   8.154 -    SDL_SW_CopyYUVToRGB(data->yuv, &rect, data->format, texture->w,
   8.155 -                        texture->h, data->pixels, data->pitch);
   8.156 -}
   8.157 -
   8.158 -void
   8.159 -GDI_AddRenderDriver(_THIS)
   8.160 -{
   8.161 -    int i;
   8.162 -    for (i = 0; i < _this->num_displays; ++i) {
   8.163 -        SDL_AddRenderDriver(&_this->displays[i], &GDI_RenderDriver);
   8.164 -    }
   8.165 -}
   8.166 -
   8.167 -SDL_Renderer *
   8.168 -GDI_CreateRenderer(SDL_Window * window, Uint32 flags)
   8.169 -{
   8.170 -    SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
   8.171 -    SDL_Renderer *renderer;
   8.172 -    GDI_RenderData *data;
   8.173 -#ifndef NO_GETDIBBITS
   8.174 -    int bmi_size;
   8.175 -    HBITMAP hbm;
   8.176 -#endif
   8.177 -    int i, n;
   8.178 -
   8.179 -    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
   8.180 -    if (!renderer) {
   8.181 -        SDL_OutOfMemory();
   8.182 -        return NULL;
   8.183 -    }
   8.184 -
   8.185 -    data = (GDI_RenderData *) SDL_calloc(1, sizeof(*data));
   8.186 -    if (!data) {
   8.187 -        GDI_DestroyRenderer(renderer);
   8.188 -        SDL_OutOfMemory();
   8.189 -        return NULL;
   8.190 -    }
   8.191 -
   8.192 -    windowdata->videodata->render = RENDER_GDI;
   8.193 -
   8.194 -    renderer->DisplayModeChanged = GDI_DisplayModeChanged;
   8.195 -    renderer->CreateTexture = GDI_CreateTexture;
   8.196 -    renderer->QueryTexturePixels = GDI_QueryTexturePixels;
   8.197 -    renderer->SetTexturePalette = GDI_SetTexturePalette;
   8.198 -    renderer->GetTexturePalette = GDI_GetTexturePalette;
   8.199 -    renderer->SetTextureAlphaMod = GDI_SetTextureAlphaMod;
   8.200 -    renderer->SetTextureBlendMode = GDI_SetTextureBlendMode;
   8.201 -    renderer->SetTextureScaleMode = GDI_SetTextureScaleMode;
   8.202 -    renderer->UpdateTexture = GDI_UpdateTexture;
   8.203 -    renderer->LockTexture = GDI_LockTexture;
   8.204 -    renderer->UnlockTexture = GDI_UnlockTexture;
   8.205 -    renderer->SetDrawBlendMode = GDI_SetDrawBlendMode;
   8.206 -    renderer->RenderDrawPoints = GDI_RenderDrawPoints;
   8.207 -    renderer->RenderDrawLines = GDI_RenderDrawLines;
   8.208 -    renderer->RenderDrawRects = GDI_RenderDrawRects;
   8.209 -    renderer->RenderFillRects = GDI_RenderFillRects;
   8.210 -    renderer->RenderCopy = GDI_RenderCopy;
   8.211 -    renderer->RenderReadPixels = GDI_RenderReadPixels;
   8.212 -    renderer->RenderWritePixels = GDI_RenderWritePixels;
   8.213 -    renderer->RenderPresent = GDI_RenderPresent;
   8.214 -    renderer->DestroyTexture = GDI_DestroyTexture;
   8.215 -    renderer->DestroyRenderer = GDI_DestroyRenderer;
   8.216 -    renderer->info = GDI_RenderDriver.info;
   8.217 -    renderer->window = window;
   8.218 -    renderer->driverdata = data;
   8.219 -
   8.220 -    renderer->info.flags = SDL_RENDERER_ACCELERATED;
   8.221 -
   8.222 -    data->hwnd = windowdata->hwnd;
   8.223 -    data->window_hdc = windowdata->hdc;
   8.224 -    data->render_hdc = CreateCompatibleDC(data->window_hdc);
   8.225 -    data->memory_hdc = CreateCompatibleDC(data->window_hdc);
   8.226 -
   8.227 -#ifndef NO_GETDIBBITS
   8.228 -    /* Fill in the compatible bitmap info */
   8.229 -    bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
   8.230 -    data->bmi = (LPBITMAPINFO) SDL_calloc(1, bmi_size);
   8.231 -    if (!data->bmi) {
   8.232 -        GDI_DestroyRenderer(renderer);
   8.233 -        SDL_OutOfMemory();
   8.234 -        return NULL;
   8.235 -    }
   8.236 -    data->bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
   8.237 -
   8.238 -    hbm = CreateCompatibleBitmap(data->window_hdc, 1, 1);
   8.239 -    GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS);
   8.240 -    GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS);
   8.241 -    DeleteObject(hbm);
   8.242 -#endif
   8.243 -
   8.244 -    if (flags & SDL_RENDERER_SINGLEBUFFER) {
   8.245 -        renderer->info.flags |=
   8.246 -            (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY);
   8.247 -        n = 0;
   8.248 -    } else if (flags & SDL_RENDERER_PRESENTFLIP2) {
   8.249 -        renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
   8.250 -        n = 2;
   8.251 -    } else if (flags & SDL_RENDERER_PRESENTFLIP3) {
   8.252 -        renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
   8.253 -        n = 3;
   8.254 -    } else {
   8.255 -        renderer->info.flags |= SDL_RENDERER_PRESENTCOPY;
   8.256 -        n = 1;
   8.257 -    }
   8.258 -    for (i = 0; i < n; ++i) {
   8.259 -        data->hbm[i] =
   8.260 -            CreateCompatibleBitmap(data->window_hdc, window->w, window->h);
   8.261 -        if (!data->hbm[i]) {
   8.262 -            GDI_DestroyRenderer(renderer);
   8.263 -            WIN_SetError("CreateCompatibleBitmap()");
   8.264 -            return NULL;
   8.265 -        }
   8.266 -    }
   8.267 -    if (n > 0) {
   8.268 -        SelectObject(data->render_hdc, data->hbm[0]);
   8.269 -        data->current_hdc = data->render_hdc;
   8.270 -        data->makedirty = SDL_TRUE;
   8.271 -    } else {
   8.272 -        data->current_hdc = data->window_hdc;
   8.273 -        data->makedirty = SDL_FALSE;
   8.274 -    }
   8.275 -    data->current_hbm = 0;
   8.276 -
   8.277 -#ifdef _WIN32_WCE
   8.278 -    // check size for GDI fullscreen and rotate
   8.279 -    if((window->flags & SDL_WINDOW_FULLSCREEN) &&
   8.280 -        GetSystemMetrics(SM_CXSCREEN) != GetSystemMetrics(SM_CYSCREEN) &&
   8.281 -        ((GetSystemMetrics(SM_CXSCREEN) < GetSystemMetrics(SM_CYSCREEN) && window->w > window->h) ||
   8.282 -         (GetSystemMetrics(SM_CXSCREEN) > GetSystemMetrics(SM_CYSCREEN) && window->w < window->h)))
   8.283 -    {
   8.284 -	int orientation = WINCE_GetDMOrientation();
   8.285 -	switch(orientation)
   8.286 -	{
   8.287 -	    case DMDO_0:   orientation = DMDO_90; break;
   8.288 -	    case DMDO_270: orientation = DMDO_180; break;
   8.289 -	    case DMDO_90:  orientation = DMDO_0; break;
   8.290 -	    case DMDO_180: orientation = DMDO_270; break;
   8.291 -
   8.292 -	    default:
   8.293 -		GDI_DestroyRenderer(renderer);
   8.294 -		return NULL;
   8.295 -	}
   8.296 -
   8.297 -	if(0 > WINCE_SetDMOrientation(orientation))
   8.298 -	{
   8.299 -	    GDI_DestroyRenderer(renderer);
   8.300 -	    return NULL;
   8.301 -	}
   8.302 -    }
   8.303 -#endif
   8.304 -
   8.305 -    return renderer;
   8.306 -}
   8.307 -
   8.308 -static int
   8.309 -GDI_DisplayModeChanged(SDL_Renderer * renderer)
   8.310 -{
   8.311 -    GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
   8.312 -    SDL_Window *window = renderer->window;
   8.313 -    int i, n;
   8.314 -
   8.315 -    if (renderer->info.flags & SDL_RENDERER_SINGLEBUFFER) {
   8.316 -        n = 0;
   8.317 -    } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
   8.318 -        n = 2;
   8.319 -    } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
   8.320 -        n = 3;
   8.321 -    } else {
   8.322 -        n = 1;
   8.323 -    }
   8.324 -    for (i = 0; i < n; ++i) {
   8.325 -        if (data->hbm[i]) {
   8.326 -            DeleteObject(data->hbm[i]);
   8.327 -            data->hbm[i] = NULL;
   8.328 -        }
   8.329 -    }
   8.330 -    for (i = 0; i < n; ++i) {
   8.331 -        data->hbm[i] =
   8.332 -            CreateCompatibleBitmap(data->window_hdc, window->w, window->h);
   8.333 -        if (!data->hbm[i]) {
   8.334 -            WIN_SetError("CreateCompatibleBitmap()");
   8.335 -            return -1;
   8.336 -        }
   8.337 -    }
   8.338 -    if (n > 0) {
   8.339 -        SelectObject(data->render_hdc, data->hbm[0]);
   8.340 -    }
   8.341 -    data->current_hbm = 0;
   8.342 -
   8.343 -    return 0;
   8.344 -}
   8.345 -
   8.346 -static HBITMAP
   8.347 -GDI_CreateDIBSection(HDC hdc, int w, int h, int pitch, Uint32 format,
   8.348 -                     HPALETTE * hpal, void ** pixels)
   8.349 -{
   8.350 -    int bmi_size;
   8.351 -    LPBITMAPINFO bmi;
   8.352 -
   8.353 -    bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
   8.354 -    bmi = (LPBITMAPINFO) SDL_calloc(1, bmi_size);
   8.355 -    if (!bmi) {
   8.356 -        SDL_OutOfMemory();
   8.357 -        return NULL;
   8.358 -    }
   8.359 -    bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
   8.360 -    bmi->bmiHeader.biWidth = w;
   8.361 -    bmi->bmiHeader.biHeight = -h;  /* topdown bitmap */
   8.362 -    bmi->bmiHeader.biPlanes = 1;
   8.363 -    bmi->bmiHeader.biSizeImage = h * pitch;
   8.364 -    bmi->bmiHeader.biXPelsPerMeter = 0;
   8.365 -    bmi->bmiHeader.biYPelsPerMeter = 0;
   8.366 -    bmi->bmiHeader.biClrUsed = 0;
   8.367 -    bmi->bmiHeader.biClrImportant = 0;
   8.368 -    bmi->bmiHeader.biBitCount = SDL_BYTESPERPIXEL(format) * 8;
   8.369 -    if (SDL_ISPIXELFORMAT_INDEXED(format)) {
   8.370 -        bmi->bmiHeader.biCompression = BI_RGB;
   8.371 -        if (hpal) {
   8.372 -            int i, ncolors;
   8.373 -            LOGPALETTE *palette;
   8.374 -
   8.375 -            ncolors = (1 << SDL_BITSPERPIXEL(format));
   8.376 -            palette =
   8.377 -                (LOGPALETTE *) SDL_malloc(sizeof(*palette) +
   8.378 -                                          ncolors * sizeof(PALETTEENTRY));
   8.379 -            if (!palette) {
   8.380 -                SDL_free(bmi);
   8.381 -                SDL_OutOfMemory();
   8.382 -                return NULL;
   8.383 -            }
   8.384 -            palette->palVersion = 0x300;
   8.385 -            palette->palNumEntries = ncolors;
   8.386 -            for (i = 0; i < ncolors; ++i) {
   8.387 -                palette->palPalEntry[i].peRed = 0xFF;
   8.388 -                palette->palPalEntry[i].peGreen = 0xFF;
   8.389 -                palette->palPalEntry[i].peBlue = 0xFF;
   8.390 -                palette->palPalEntry[i].peFlags = 0;
   8.391 -            }
   8.392 -            *hpal = CreatePalette(palette);
   8.393 -            SDL_free(palette);
   8.394 -        }
   8.395 -    } else {
   8.396 -        int bpp;
   8.397 -        Uint32 Rmask, Gmask, Bmask, Amask;
   8.398 -
   8.399 -        bmi->bmiHeader.biCompression = BI_BITFIELDS;
   8.400 -        SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask,
   8.401 -                                   &Amask);
   8.402 -        ((Uint32 *) bmi->bmiColors)[0] = Rmask;
   8.403 -        ((Uint32 *) bmi->bmiColors)[1] = Gmask;
   8.404 -        ((Uint32 *) bmi->bmiColors)[2] = Bmask;
   8.405 -        if (hpal) {
   8.406 -            *hpal = NULL;
   8.407 -        }
   8.408 -    }
   8.409 -    return CreateDIBSection(hdc, bmi, DIB_RGB_COLORS, pixels, NULL, 0);
   8.410 -}
   8.411 -
   8.412 -static int
   8.413 -GDI_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   8.414 -{
   8.415 -    GDI_RenderData *renderdata = (GDI_RenderData *) renderer->driverdata;
   8.416 -    SDL_Window *window = renderer->window;
   8.417 -    SDL_VideoDisplay *display = window->display;
   8.418 -    GDI_TextureData *data;
   8.419 -
   8.420 -    data = (GDI_TextureData *) SDL_calloc(1, sizeof(*data));
   8.421 -    if (!data) {
   8.422 -        SDL_OutOfMemory();
   8.423 -        return -1;
   8.424 -    }
   8.425 -
   8.426 -    texture->driverdata = data;
   8.427 -
   8.428 -    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   8.429 -        data->yuv =
   8.430 -            SDL_SW_CreateYUVTexture(texture->format, texture->w, texture->h);
   8.431 -        if (!data->yuv) {
   8.432 -            return -1;
   8.433 -        }
   8.434 -        data->format = display->current_mode.format;
   8.435 -    } else {
   8.436 -        data->format = texture->format;
   8.437 -    }
   8.438 -    data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format));
   8.439 -
   8.440 -    if (data->yuv || texture->access == SDL_TEXTUREACCESS_STREAMING
   8.441 -        || texture->format != display->current_mode.format) {
   8.442 -        data->hbm = GDI_CreateDIBSection(renderdata->memory_hdc,
   8.443 -                                         texture->w, texture->h,
   8.444 -                                         data->pitch, data->format,
   8.445 -                                         &data->hpal, &data->pixels);
   8.446 -    } else {
   8.447 -        data->hbm = CreateCompatibleBitmap(renderdata->window_hdc,
   8.448 -                                           texture->w, texture->h);
   8.449 -    }
   8.450 -    if (!data->hbm) {
   8.451 -        WIN_SetError("Couldn't create bitmap");
   8.452 -        return -1;
   8.453 -    }
   8.454 -
   8.455 -    return 0;
   8.456 -}
   8.457 -
   8.458 -static int
   8.459 -GDI_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
   8.460 -                       void **pixels, int *pitch)
   8.461 -{
   8.462 -    GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
   8.463 -
   8.464 -    if (data->yuv) {
   8.465 -        return SDL_SW_QueryYUVTexturePixels(data->yuv, pixels, pitch);
   8.466 -    } else {
   8.467 -        *pixels = data->pixels;
   8.468 -        *pitch = data->pitch;
   8.469 -        return 0;
   8.470 -    }
   8.471 -}
   8.472 -
   8.473 -static int
   8.474 -GDI_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
   8.475 -                      const SDL_Color * colors, int firstcolor, int ncolors)
   8.476 -{
   8.477 -    GDI_RenderData *renderdata = (GDI_RenderData *) renderer->driverdata;
   8.478 -    GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
   8.479 -
   8.480 -    if (data->yuv) {
   8.481 -        SDL_SetError("YUV textures don't have a palette");
   8.482 -        return -1;
   8.483 -    } else {
   8.484 -        PALETTEENTRY entries[256];
   8.485 -        int i;
   8.486 -
   8.487 -        for (i = 0; i < ncolors; ++i) {
   8.488 -            entries[i].peRed = colors[i].r;
   8.489 -            entries[i].peGreen = colors[i].g;
   8.490 -            entries[i].peBlue = colors[i].b;
   8.491 -            entries[i].peFlags = 0;
   8.492 -        }
   8.493 -        if (!SetPaletteEntries(data->hpal, firstcolor, ncolors, entries)) {
   8.494 -            WIN_SetError("SetPaletteEntries()");
   8.495 -            return -1;
   8.496 -        }
   8.497 -        return 0;
   8.498 -    }
   8.499 -}
   8.500 -
   8.501 -static int
   8.502 -GDI_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
   8.503 -                      SDL_Color * colors, int firstcolor, int ncolors)
   8.504 -{
   8.505 -    GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
   8.506 -
   8.507 -    if (data->yuv) {
   8.508 -        SDL_SetError("YUV textures don't have a palette");
   8.509 -        return -1;
   8.510 -    } else {
   8.511 -        PALETTEENTRY entries[256];
   8.512 -        int i;
   8.513 -
   8.514 -        if (!GetPaletteEntries(data->hpal, firstcolor, ncolors, entries)) {
   8.515 -            WIN_SetError("GetPaletteEntries()");
   8.516 -            return -1;
   8.517 -        }
   8.518 -        for (i = 0; i < ncolors; ++i) {
   8.519 -            colors[i].r = entries[i].peRed;
   8.520 -            colors[i].g = entries[i].peGreen;
   8.521 -            colors[i].b = entries[i].peBlue;
   8.522 -        }
   8.523 -        return 0;
   8.524 -    }
   8.525 -}
   8.526 -
   8.527 -static int
   8.528 -GDI_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
   8.529 -{
   8.530 -    return 0;
   8.531 -}
   8.532 -
   8.533 -static int
   8.534 -GDI_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
   8.535 -{
   8.536 -    GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
   8.537 -
   8.538 -    switch (texture->blendMode) {
   8.539 -    case SDL_BLENDMODE_NONE:
   8.540 -        if (data->premultiplied) {
   8.541 -            /* Crap, we've lost the original pixel data... *sigh* */
   8.542 -        }
   8.543 -        return 0;
   8.544 -#ifndef _WIN32_WCE              /* WinCE has no alphablend */
   8.545 -    case SDL_BLENDMODE_MASK:
   8.546 -    case SDL_BLENDMODE_BLEND:
   8.547 -        if (!data->premultiplied && data->pixels) {
   8.548 -            switch (texture->format) {
   8.549 -            case SDL_PIXELFORMAT_ARGB8888:
   8.550 -                SDL_PreMultiplyAlphaARGB8888(texture->w, texture->h,
   8.551 -                                             (Uint32 *) data->pixels,
   8.552 -                                             data->pitch);
   8.553 -                data->premultiplied = SDL_TRUE;
   8.554 -                break;
   8.555 -            case SDL_PIXELFORMAT_RGBA8888:
   8.556 -                SDL_PreMultiplyAlphaRGBA8888(texture->w, texture->h,
   8.557 -                                             (Uint32 *) data->pixels,
   8.558 -                                             data->pitch);
   8.559 -                data->premultiplied = SDL_TRUE;
   8.560 -                break;
   8.561 -            case SDL_PIXELFORMAT_ABGR8888:
   8.562 -                SDL_PreMultiplyAlphaABGR8888(texture->w, texture->h,
   8.563 -                                             (Uint32 *) data->pixels,
   8.564 -                                             data->pitch);
   8.565 -                data->premultiplied = SDL_TRUE;
   8.566 -                break;
   8.567 -            case SDL_PIXELFORMAT_BGRA8888:
   8.568 -                SDL_PreMultiplyAlphaBGRA8888(texture->w, texture->h,
   8.569 -                                             (Uint32 *) data->pixels,
   8.570 -                                             data->pitch);
   8.571 -                data->premultiplied = SDL_TRUE;
   8.572 -                break;
   8.573 -            }
   8.574 -        }
   8.575 -        return 0;
   8.576 -#endif
   8.577 -    default:
   8.578 -        SDL_Unsupported();
   8.579 -        texture->blendMode = SDL_BLENDMODE_NONE;
   8.580 -        return -1;
   8.581 -    }
   8.582 -}
   8.583 -
   8.584 -static int
   8.585 -GDI_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
   8.586 -{
   8.587 -    switch (texture->scaleMode) {
   8.588 -    case SDL_SCALEMODE_NONE:
   8.589 -    case SDL_SCALEMODE_FAST:
   8.590 -        return 0;
   8.591 -    case SDL_SCALEMODE_SLOW:
   8.592 -    case SDL_SCALEMODE_BEST:
   8.593 -        SDL_Unsupported();
   8.594 -        texture->scaleMode = SDL_SCALEMODE_FAST;
   8.595 -        return -1;
   8.596 -    default:
   8.597 -        SDL_Unsupported();
   8.598 -        texture->scaleMode = SDL_SCALEMODE_NONE;
   8.599 -        return -1;
   8.600 -    }
   8.601 -    return 0;
   8.602 -}
   8.603 -
   8.604 -static int
   8.605 -GDI_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   8.606 -                  const SDL_Rect * rect, const void *pixels, int pitch)
   8.607 -{
   8.608 -    GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
   8.609 -
   8.610 -    if (data->yuv) {
   8.611 -        if (SDL_SW_UpdateYUVTexture(data->yuv, rect, pixels, pitch) < 0) {
   8.612 -            return -1;
   8.613 -        }
   8.614 -        UpdateYUVTextureData(texture);
   8.615 -        return 0;
   8.616 -    } else {
   8.617 -        GDI_RenderData *renderdata = (GDI_RenderData *) renderer->driverdata;
   8.618 -
   8.619 -        if (data->pixels) {
   8.620 -            Uint8 *src, *dst;
   8.621 -            int row;
   8.622 -            size_t length;
   8.623 -
   8.624 -            src = (Uint8 *) pixels;
   8.625 -            dst =
   8.626 -                (Uint8 *) data->pixels + rect->y * data->pitch +
   8.627 -                rect->x * SDL_BYTESPERPIXEL(texture->format);
   8.628 -            length = rect->w * SDL_BYTESPERPIXEL(texture->format);
   8.629 -            for (row = 0; row < rect->h; ++row) {
   8.630 -                SDL_memcpy(dst, src, length);
   8.631 -                src += pitch;
   8.632 -                dst += data->pitch;
   8.633 -            }
   8.634 -            if (data->premultiplied) {
   8.635 -                Uint32 *pixels =
   8.636 -                    (Uint32 *) data->pixels + rect->y * (data->pitch / 4) +
   8.637 -                    rect->x;
   8.638 -                switch (texture->format) {
   8.639 -                case SDL_PIXELFORMAT_ARGB8888:
   8.640 -                    SDL_PreMultiplyAlphaARGB8888(rect->w, rect->h, pixels,
   8.641 -                                                 data->pitch);
   8.642 -                    break;
   8.643 -                case SDL_PIXELFORMAT_RGBA8888:
   8.644 -                    SDL_PreMultiplyAlphaRGBA8888(rect->w, rect->h, pixels,
   8.645 -                                                 data->pitch);
   8.646 -                    break;
   8.647 -                case SDL_PIXELFORMAT_ABGR8888:
   8.648 -                    SDL_PreMultiplyAlphaABGR8888(rect->w, rect->h, pixels,
   8.649 -                                                 data->pitch);
   8.650 -                    break;
   8.651 -                case SDL_PIXELFORMAT_BGRA8888:
   8.652 -                    SDL_PreMultiplyAlphaBGRA8888(rect->w, rect->h, pixels,
   8.653 -                                                 data->pitch);
   8.654 -                    break;
   8.655 -                }
   8.656 -            }
   8.657 -        } else if (rect->w == texture->w && pitch == data->pitch) {
   8.658 -#ifndef NO_GETDIBBITS
   8.659 -            if (!SetDIBits
   8.660 -                (renderdata->window_hdc, data->hbm, rect->y, rect->h, pixels,
   8.661 -                 renderdata->bmi, DIB_RGB_COLORS)) {
   8.662 -                WIN_SetError("SetDIBits()");
   8.663 -                return -1;
   8.664 -            }
   8.665 -#else
   8.666 -            SDL_SetError("FIXME: Update Texture");
   8.667 -            return -1;
   8.668 -#endif
   8.669 -        } else {
   8.670 -            SDL_SetError
   8.671 -                ("FIXME: Need to allocate temporary memory and do GetDIBits() followed by SetDIBits(), since we can only set blocks of scanlines at a time");
   8.672 -            return -1;
   8.673 -        }
   8.674 -        return 0;
   8.675 -    }
   8.676 -}
   8.677 -
   8.678 -static int
   8.679 -GDI_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   8.680 -                const SDL_Rect * rect, int markDirty, void **pixels,
   8.681 -                int *pitch)
   8.682 -{
   8.683 -    GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
   8.684 -
   8.685 -    if (data->yuv) {
   8.686 -        return SDL_SW_LockYUVTexture(data->yuv, rect, markDirty, pixels,
   8.687 -                                     pitch);
   8.688 -    } else if (data->pixels) {
   8.689 -#ifndef _WIN32_WCE
   8.690 -        /* WinCE has no GdiFlush */
   8.691 -        GdiFlush();
   8.692 -#endif
   8.693 -        *pixels =
   8.694 -            (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
   8.695 -                      rect->x * SDL_BYTESPERPIXEL(texture->format));
   8.696 -        *pitch = data->pitch;
   8.697 -        return 0;
   8.698 -    } else {
   8.699 -        SDL_SetError("No pixels available");
   8.700 -        return -1;
   8.701 -    }
   8.702 -}
   8.703 -
   8.704 -static void
   8.705 -GDI_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   8.706 -{
   8.707 -    GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
   8.708 -
   8.709 -    if (data->yuv) {
   8.710 -        SDL_SW_UnlockYUVTexture(data->yuv);
   8.711 -        UpdateYUVTextureData(texture);
   8.712 -    }
   8.713 -}
   8.714 -
   8.715 -static int
   8.716 -GDI_SetDrawBlendMode(SDL_Renderer * renderer)
   8.717 -{
   8.718 -    switch (renderer->blendMode) {
   8.719 -    case SDL_BLENDMODE_NONE:
   8.720 -        return 0;
   8.721 -    default:
   8.722 -        SDL_Unsupported();
   8.723 -        renderer->blendMode = SDL_BLENDMODE_NONE;
   8.724 -        return -1;
   8.725 -    }
   8.726 -}
   8.727 -
   8.728 -static int
   8.729 -GDI_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
   8.730 -                     int count)
   8.731 -{
   8.732 -    GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
   8.733 -    int i;
   8.734 -    COLORREF color;
   8.735 -
   8.736 -    if (data->makedirty) {
   8.737 -        /* Get the smallest rectangle that contains everything */
   8.738 -        SDL_Window *window = renderer->window;
   8.739 -        SDL_Rect rect;
   8.740 -
   8.741 -        rect.x = 0;
   8.742 -        rect.y = 0;
   8.743 -        rect.w = window->w;
   8.744 -        rect.h = window->h;
   8.745 -        if (!SDL_EnclosePoints(points, count, &rect, &rect)) {
   8.746 -            /* Nothing to draw */
   8.747 -            return 0;
   8.748 -        }
   8.749 -
   8.750 -        SDL_AddDirtyRect(&data->dirty, &rect);
   8.751 -    }
   8.752 -
   8.753 -    color = RGB(renderer->r, renderer->g, renderer->b);
   8.754 -    for (i = 0; i < count; ++i) {
   8.755 -        SetPixel(data->current_hdc, points[i].x, points[i].y, color);
   8.756 -    }
   8.757 -
   8.758 -    return 0;
   8.759 -}
   8.760 -
   8.761 -static int
   8.762 -GDI_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
   8.763 -                    int count)
   8.764 -{
   8.765 -    GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
   8.766 -    HPEN pen;
   8.767 -    BOOL status;
   8.768 -
   8.769 -    if (data->makedirty) {
   8.770 -        /* Get the smallest rectangle that contains everything */
   8.771 -        SDL_Window *window = renderer->window;
   8.772 -        SDL_Rect clip, rect;
   8.773 -
   8.774 -        clip.x = 0;
   8.775 -        clip.y = 0;
   8.776 -        clip.w = window->w;
   8.777 -        clip.h = window->h;
   8.778 -        SDL_EnclosePoints(points, count, NULL, &rect);
   8.779 -        if (!SDL_IntersectRect(&rect, &clip, &rect)) {
   8.780 -            /* Nothing to draw */
   8.781 -            return 0;
   8.782 -        }
   8.783 -
   8.784 -        SDL_AddDirtyRect(&data->dirty, &rect);
   8.785 -    }
   8.786 -
   8.787 -    /* Should we cache the pen? .. it looks like GDI does for us. :) */
   8.788 -    pen = CreatePen(PS_SOLID, 1, RGB(renderer->r, renderer->g, renderer->b));
   8.789 -    SelectObject(data->current_hdc, pen);
   8.790 -    {
   8.791 -        LPPOINT p = SDL_stack_alloc(POINT, count);
   8.792 -        int i;
   8.793 -
   8.794 -        for (i = 0; i < count; ++i) {
   8.795 -            p[i].x = points[i].x;
   8.796 -            p[i].y = points[i].y;
   8.797 -        }
   8.798 -        status = Polyline(data->current_hdc, p, count);
   8.799 -        SDL_stack_free(p);
   8.800 -    }
   8.801 -    DeleteObject(pen);
   8.802 -
   8.803 -    /* Need to close the endpoint of the line */
   8.804 -    if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
   8.805 -        SetPixel(data->current_hdc, points[count-1].x, points[count-1].y,
   8.806 -                 RGB(renderer->r, renderer->g, renderer->b));
   8.807 -    }
   8.808 -
   8.809 -    if (!status) {
   8.810 -        WIN_SetError("Polyline()");
   8.811 -        return -1;
   8.812 -    }
   8.813 -    return 0;
   8.814 -}
   8.815 -
   8.816 -static int
   8.817 -GDI_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
   8.818 -                    int count)
   8.819 -{
   8.820 -    GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
   8.821 -    HPEN pen;
   8.822 -    POINT vertices[5];
   8.823 -    int i, status = 1;
   8.824 -
   8.825 -    if (data->makedirty) {
   8.826 -        SDL_Window *window = renderer->window;
   8.827 -        SDL_Rect clip, rect;
   8.828 -
   8.829 -        clip.x = 0;
   8.830 -        clip.y = 0;
   8.831 -        clip.w = window->w;
   8.832 -        clip.h = window->h;
   8.833 -
   8.834 -        for (i = 0; i < count; ++i) {
   8.835 -            if (SDL_IntersectRect(rects[i], &clip, &rect)) {
   8.836 -                SDL_AddDirtyRect(&data->dirty, &rect);
   8.837 -            }
   8.838 -        }
   8.839 -    }
   8.840 -
   8.841 -    /* Should we cache the pen? .. it looks like GDI does for us. :) */
   8.842 -    pen = CreatePen(PS_SOLID, 1, RGB(renderer->r, renderer->g, renderer->b));
   8.843 -    SelectObject(data->current_hdc, pen);
   8.844 -    for (i = 0; i < count; ++i) {
   8.845 -        const SDL_Rect *rect = rects[i];
   8.846 -
   8.847 -        vertices[0].x = rect->x;
   8.848 -        vertices[0].y = rect->y;
   8.849 -
   8.850 -        vertices[1].x = rect->x+rect->w-1;
   8.851 -        vertices[1].y = rect->y;
   8.852 -
   8.853 -        vertices[2].x = rect->x+rect->w-1;
   8.854 -        vertices[2].y = rect->y+rect->h-1;
   8.855 -
   8.856 -        vertices[3].x = rect->x;
   8.857 -        vertices[3].y = rect->y+rect->h-1;
   8.858 -
   8.859 -        vertices[4].x = rect->x;
   8.860 -        vertices[4].y = rect->y;
   8.861 -
   8.862 -        status &= Polyline(data->current_hdc, vertices, 5);
   8.863 -    }
   8.864 -    DeleteObject(pen);
   8.865 -
   8.866 -    if (!status) {
   8.867 -        WIN_SetError("Polyline()");
   8.868 -        return -1;
   8.869 -    }
   8.870 -    return 0;
   8.871 -}
   8.872 -
   8.873 -static int
   8.874 -GDI_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
   8.875 -                    int count)
   8.876 -{
   8.877 -    GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
   8.878 -    RECT rc;
   8.879 -    HBRUSH brush;
   8.880 -    int i, status = 1;
   8.881 -
   8.882 -    if (data->makedirty) {
   8.883 -        SDL_Window *window = renderer->window;
   8.884 -        SDL_Rect clip, rect;
   8.885 -
   8.886 -        clip.x = 0;
   8.887 -        clip.y = 0;
   8.888 -        clip.w = window->w;
   8.889 -        clip.h = window->h;
   8.890 -
   8.891 -        for (i = 0; i < count; ++i) {
   8.892 -            if (SDL_IntersectRect(rects[i], &clip, &rect)) {
   8.893 -                SDL_AddDirtyRect(&data->dirty, &rect);
   8.894 -            }
   8.895 -        }
   8.896 -    }
   8.897 -
   8.898 -    /* Should we cache the brushes? .. it looks like GDI does for us. :) */
   8.899 -    brush = CreateSolidBrush(RGB(renderer->r, renderer->g, renderer->b));
   8.900 -    SelectObject(data->current_hdc, brush);
   8.901 -    for (i = 0; i < count; ++i) {
   8.902 -        const SDL_Rect *rect = rects[i];
   8.903 -
   8.904 -        rc.left = rect->x;
   8.905 -        rc.top = rect->y;
   8.906 -        rc.right = rect->x + rect->w;
   8.907 -        rc.bottom = rect->y + rect->h;
   8.908 -
   8.909 -        status &= FillRect(data->current_hdc, &rc, brush);
   8.910 -    }
   8.911 -    DeleteObject(brush);
   8.912 -
   8.913 -    if (!status) {
   8.914 -        WIN_SetError("FillRect()");
   8.915 -        return -1;
   8.916 -    }
   8.917 -    return 0;
   8.918 -}
   8.919 -
   8.920 -static int
   8.921 -GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   8.922 -               const SDL_Rect * srcrect, const SDL_Rect * dstrect)
   8.923 -{
   8.924 -    GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
   8.925 -    GDI_TextureData *texturedata = (GDI_TextureData *) texture->driverdata;
   8.926 -
   8.927 -    if (data->makedirty) {
   8.928 -        SDL_AddDirtyRect(&data->dirty, dstrect);
   8.929 -    }
   8.930 -
   8.931 -    SelectObject(data->memory_hdc, texturedata->hbm);
   8.932 -    if (texturedata->hpal) {
   8.933 -        SelectPalette(data->memory_hdc, texturedata->hpal, TRUE);
   8.934 -        RealizePalette(data->memory_hdc);
   8.935 -    }
   8.936 -    if (texture->blendMode & (SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND)) {
   8.937 -#ifdef _WIN32_WCE
   8.938 -        SDL_SetError("Texture has blendmode not supported under WinCE");
   8.939 -        return -1;
   8.940 -#else
   8.941 -        BLENDFUNCTION blendFunc = {
   8.942 -            AC_SRC_OVER,
   8.943 -            0,
   8.944 -            texture->a,
   8.945 -            AC_SRC_ALPHA
   8.946 -        };
   8.947 -        if (!AlphaBlend
   8.948 -            (data->current_hdc, dstrect->x, dstrect->y, dstrect->w,
   8.949 -             dstrect->h, data->memory_hdc, srcrect->x, srcrect->y, srcrect->w,
   8.950 -             srcrect->h, blendFunc)) {
   8.951 -            WIN_SetError("AlphaBlend()");
   8.952 -            return -1;
   8.953 -        }
   8.954 -#endif
   8.955 -    } else {
   8.956 -        if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
   8.957 -            if (!BitBlt
   8.958 -                (data->current_hdc, dstrect->x, dstrect->y, dstrect->w,
   8.959 -                 srcrect->h, data->memory_hdc, srcrect->x, srcrect->y,
   8.960 -                 SRCCOPY)) {
   8.961 -                WIN_SetError("BitBlt()");
   8.962 -                return -1;
   8.963 -            }
   8.964 -        } else {
   8.965 -            if (!StretchBlt
   8.966 -                (data->current_hdc, dstrect->x, dstrect->y, dstrect->w,
   8.967 -                 dstrect->h, data->memory_hdc, srcrect->x, srcrect->y,
   8.968 -                 srcrect->w, srcrect->h, SRCCOPY)) {
   8.969 -                WIN_SetError("StretchBlt()");
   8.970 -                return -1;
   8.971 -            }
   8.972 -        }
   8.973 -    }
   8.974 -    return 0;
   8.975 -}
   8.976 -
   8.977 -static int
   8.978 -GDI_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   8.979 -                     Uint32 format, void * pixels, int pitch)
   8.980 -{
   8.981 -    GDI_RenderData *renderdata = (GDI_RenderData *) renderer->driverdata;
   8.982 -    SDL_Window *window = renderer->window;
   8.983 -    SDL_VideoDisplay *display = window->display;
   8.984 -    struct {
   8.985 -        HBITMAP hbm;
   8.986 -        void *pixels;
   8.987 -        int pitch;
   8.988 -        Uint32 format;
   8.989 -    } data;
   8.990 -
   8.991 -    data.format = display->current_mode.format;
   8.992 -    data.pitch = (rect->w * SDL_BYTESPERPIXEL(data.format));
   8.993 -
   8.994 -    data.hbm = GDI_CreateDIBSection(renderdata->memory_hdc, rect->w, rect->h,
   8.995 -                                    data.pitch, data.format, NULL,
   8.996 -                                    &data.pixels);
   8.997 -    if (!data.hbm) {
   8.998 -        WIN_SetError("Couldn't create bitmap");
   8.999 -        return -1;
  8.1000 -    }
  8.1001 -
  8.1002 -    SelectObject(renderdata->memory_hdc, data.hbm);
  8.1003 -    if (!BitBlt(renderdata->memory_hdc, 0, 0, rect->w, rect->h,
  8.1004 -                renderdata->current_hdc, rect->x, rect->y, SRCCOPY)) {
  8.1005 -        WIN_SetError("BitBlt()");
  8.1006 -        DeleteObject(data.hbm);
  8.1007 -        return -1;
  8.1008 -    }
  8.1009 -
  8.1010 -    SDL_ConvertPixels(rect->w, rect->h,
  8.1011 -                      data.format, data.pixels, data.pitch,
  8.1012 -                      format, pixels, pitch);
  8.1013 -
  8.1014 -    DeleteObject(data.hbm);
  8.1015 -    return 0;
  8.1016 -}
  8.1017 -
  8.1018 -static int
  8.1019 -GDI_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
  8.1020 -                      Uint32 format, const void * pixels, int pitch)
  8.1021 -{
  8.1022 -    GDI_RenderData *renderdata = (GDI_RenderData *) renderer->driverdata;
  8.1023 -    SDL_Window *window = renderer->window;
  8.1024 -    SDL_VideoDisplay *display = window->display;
  8.1025 -    struct {
  8.1026 -        HBITMAP hbm;
  8.1027 -        void *pixels;
  8.1028 -        int pitch;
  8.1029 -        Uint32 format;
  8.1030 -    } data;
  8.1031 -
  8.1032 -    data.format = display->current_mode.format;
  8.1033 -    data.pitch = (rect->w * SDL_BYTESPERPIXEL(data.format));
  8.1034 -
  8.1035 -    data.hbm = GDI_CreateDIBSection(renderdata->memory_hdc, rect->w, rect->h,
  8.1036 -                                    data.pitch, data.format,
  8.1037 -                                    NULL, &data.pixels);
  8.1038 -    if (!data.hbm) {
  8.1039 -        WIN_SetError("Couldn't create bitmap");
  8.1040 -        return -1;
  8.1041 -    }
  8.1042 -
  8.1043 -    SDL_ConvertPixels(rect->w, rect->h, format, pixels, pitch,
  8.1044 -                      data.format, data.pixels, data.pitch);
  8.1045 -
  8.1046 -    SelectObject(renderdata->memory_hdc, data.hbm);
  8.1047 -    if (!BitBlt(renderdata->current_hdc, rect->x, rect->y, rect->w, rect->h,
  8.1048 -                renderdata->memory_hdc, 0, 0, SRCCOPY)) {
  8.1049 -        WIN_SetError("BitBlt()");
  8.1050 -        DeleteObject(data.hbm);
  8.1051 -        return -1;
  8.1052 -    }
  8.1053 -
  8.1054 -    DeleteObject(data.hbm);
  8.1055 -    return 0;
  8.1056 -}
  8.1057 -
  8.1058 -static void
  8.1059 -GDI_RenderPresent(SDL_Renderer * renderer)
  8.1060 -{
  8.1061 -    GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
  8.1062 -    SDL_DirtyRect *dirty;
  8.1063 -
  8.1064 -    /* Send the data to the display */
  8.1065 -    if (!(renderer->info.flags & SDL_RENDERER_SINGLEBUFFER)) {
  8.1066 -        for (dirty = data->dirty.list; dirty; dirty = dirty->next) {
  8.1067 -            const SDL_Rect *rect = &dirty->rect;
  8.1068 -            BitBlt(data->window_hdc, rect->x, rect->y, rect->w, rect->h,
  8.1069 -                   data->render_hdc, rect->x, rect->y, SRCCOPY);
  8.1070 -        }
  8.1071 -        SDL_ClearDirtyRects(&data->dirty);
  8.1072 -    }
  8.1073 -
  8.1074 -    /* Update the flipping chain, if any */
  8.1075 -    if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
  8.1076 -        data->current_hbm = (data->current_hbm + 1) % 2;
  8.1077 -        SelectObject(data->render_hdc, data->hbm[data->current_hbm]);
  8.1078 -    } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
  8.1079 -        data->current_hbm = (data->current_hbm + 1) % 3;
  8.1080 -        SelectObject(data->render_hdc, data->hbm[data->current_hbm]);
  8.1081 -    }
  8.1082 -}
  8.1083 -
  8.1084 -static void
  8.1085 -GDI_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
  8.1086 -{
  8.1087 -    GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
  8.1088 -
  8.1089 -    if (!data) {
  8.1090 -        return;
  8.1091 -    }
  8.1092 -    if (data->yuv) {
  8.1093 -        SDL_SW_DestroyYUVTexture(data->yuv);
  8.1094 -    }
  8.1095 -    if (data->hpal) {
  8.1096 -        DeleteObject(data->hpal);
  8.1097 -    }
  8.1098 -    if (data->hbm) {
  8.1099 -        DeleteObject(data->hbm);
  8.1100 -    }
  8.1101 -    SDL_free(data);
  8.1102 -    texture->driverdata = NULL;
  8.1103 -}
  8.1104 -
  8.1105 -static void
  8.1106 -GDI_DestroyRenderer(SDL_Renderer * renderer)
  8.1107 -{
  8.1108 -    GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
  8.1109 -    int i;
  8.1110 -
  8.1111 -    if (data) {
  8.1112 -        DeleteDC(data->render_hdc);
  8.1113 -        DeleteDC(data->memory_hdc);
  8.1114 -#ifndef NO_GETDIBBITS
  8.1115 -        if (data->bmi) {
  8.1116 -            SDL_free(data->bmi);
  8.1117 -        }
  8.1118 -#endif
  8.1119 -        for (i = 0; i < SDL_arraysize(data->hbm); ++i) {
  8.1120 -            if (data->hbm[i]) {
  8.1121 -                DeleteObject(data->hbm[i]);
  8.1122 -            }
  8.1123 -        }
  8.1124 -        SDL_FreeDirtyRects(&data->dirty);
  8.1125 -        SDL_free(data);
  8.1126 -    }
  8.1127 -    SDL_free(renderer);
  8.1128 -}
  8.1129 -
  8.1130 -#endif /* SDL_VIDEO_RENDER_GDI */
  8.1131 -
  8.1132 -/* vi: set ts=4 sw=4 expandtab: */
     9.1 --- a/src/video/windows/SDL_gdirender.h	Tue Feb 01 12:01:37 2011 -0800
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,30 +0,0 @@
     9.4 -/*
     9.5 -    SDL - Simple DirectMedia Layer
     9.6 -    Copyright (C) 1997-2010 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_GDI
    9.30 -extern void GDI_AddRenderDriver(_THIS);
    9.31 -#endif
    9.32 -
    9.33 -/* vi: set ts=4 sw=4 expandtab: */
    10.1 --- a/src/video/windows/SDL_windowsvideo.c	Tue Feb 01 12:01:37 2011 -0800
    10.2 +++ b/src/video/windows/SDL_windowsvideo.c	Mon Jan 31 22:21:29 2011 -0800
    10.3 @@ -225,9 +225,6 @@
    10.4  #if SDL_VIDEO_RENDER_DDRAW
    10.5      DDRAW_AddRenderDriver(_this);
    10.6  #endif
    10.7 -#if SDL_VIDEO_RENDER_GDI
    10.8 -    GDI_AddRenderDriver(_this);
    10.9 -#endif
   10.10  #if SDL_VIDEO_RENDER_GAPI
   10.11      WINCE_AddRenderDriver(_this);
   10.12  #endif
    11.1 --- a/src/video/x11/SDL_x11render.c	Tue Feb 01 12:01:37 2011 -0800
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,2360 +0,0 @@
    11.4 -/*
    11.5 -
    11.6 -    SDL - Simple DirectMedia Layer
    11.7 -    Copyright (C) 1997-2010 Sam Lantinga
    11.8 -
    11.9 -    This library is free software; you can redistribute it and/or
   11.10 -    modify it under the terms of the GNU Lesser General Public
   11.11 -    License as published by the Free Software Foundation; either
   11.12 -    version 2.1 of the License, or (at your option) any later version.
   11.13 -
   11.14 -    This library is distributed in the hope that it will be useful,
   11.15 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.16 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   11.17 -    Lesser General Public License for more details.
   11.18 -
   11.19 -    You should have received a copy of the GNU Lesser General Public
   11.20 -    License along with this library; if not, write to the Free Software
   11.21 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   11.22 -
   11.23 -    Sam Lantinga
   11.24 -    slouken@libsdl.org
   11.25 -*/
   11.26 -#include "SDL_config.h"
   11.27 -
   11.28 -#if SDL_VIDEO_RENDER_X11
   11.29 -
   11.30 -#include <limits.h> /* For INT_MIN and INT_MAX */
   11.31 -
   11.32 -#include "SDL_x11video.h"
   11.33 -#include "SDL_x11render.h"
   11.34 -#include "../SDL_rect_c.h"
   11.35 -#include "../SDL_pixels_c.h"
   11.36 -#include "../SDL_yuv_sw_c.h"
   11.37 -
   11.38 -/* X11 renderer implementation */
   11.39 -
   11.40 -static SDL_Renderer *X11_CreateRenderer(SDL_Window * window, Uint32 flags);
   11.41 -static int X11_DisplayModeChanged(SDL_Renderer * renderer);
   11.42 -static int X11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
   11.43 -static int X11_QueryTexturePixels(SDL_Renderer * renderer,
   11.44 -                                  SDL_Texture * texture, void **pixels,
   11.45 -                                  int *pitch);
   11.46 -static int X11_SetTextureRGBAMod(SDL_Renderer * renderer,
   11.47 -                                 SDL_Texture * texture);
   11.48 -static int X11_SetTextureBlendMode(SDL_Renderer * renderer,
   11.49 -                                   SDL_Texture * texture);
   11.50 -static int X11_SetTextureScaleMode(SDL_Renderer * renderer,
   11.51 -                                   SDL_Texture * texture);
   11.52 -static int X11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   11.53 -                             const SDL_Rect * rect, const void *pixels,
   11.54 -                             int pitch);
   11.55 -static int X11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   11.56 -                           const SDL_Rect * rect, int markDirty,
   11.57 -                           void **pixels, int *pitch);
   11.58 -static void X11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
   11.59 -static int X11_SetDrawBlendMode(SDL_Renderer * renderer);
   11.60 -static int X11_RenderDrawPoints(SDL_Renderer * renderer,
   11.61 -                                const SDL_Point * points, int count);
   11.62 -static int X11_RenderDrawLines(SDL_Renderer * renderer,
   11.63 -                               const SDL_Point * points, int count);
   11.64 -static int X11_RenderDrawRects(SDL_Renderer * renderer,
   11.65 -                               const SDL_Rect ** rects, int count);
   11.66 -static int X11_RenderFillRects(SDL_Renderer * renderer,
   11.67 -                               const SDL_Rect ** rects, int count);
   11.68 -static int X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   11.69 -                          const SDL_Rect * srcrect, const SDL_Rect * dstrect);
   11.70 -static int X11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   11.71 -                                Uint32 format, void * pixels, int pitch);
   11.72 -static int X11_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   11.73 -                                 Uint32 format, const void * pixels, int pitch);
   11.74 -static void X11_RenderPresent(SDL_Renderer * renderer);
   11.75 -static void X11_DestroyTexture(SDL_Renderer * renderer,
   11.76 -                               SDL_Texture * texture);
   11.77 -static void X11_DestroyRenderer(SDL_Renderer * renderer);
   11.78 -
   11.79 -
   11.80 -SDL_RenderDriver X11_RenderDriver = {
   11.81 -    X11_CreateRenderer,
   11.82 -    {
   11.83 -     "x11",
   11.84 -     (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
   11.85 -      SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
   11.86 -      SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED),
   11.87 -     SDL_TEXTUREMODULATE_NONE,
   11.88 -     SDL_BLENDMODE_NONE,
   11.89 -     SDL_SCALEMODE_NONE,
   11.90 -     0,
   11.91 -     {0},
   11.92 -     0,
   11.93 -     0}
   11.94 -};
   11.95 -
   11.96 -typedef struct
   11.97 -{
   11.98 -    Display *display;
   11.99 -    int screen;
  11.100 -    Visual *visual;
  11.101 -    int depth;
  11.102 -    int scanline_pad;
  11.103 -    Window xwindow;
  11.104 -    Pixmap pixmaps[3];
  11.105 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  11.106 -    Pixmap stencil;
  11.107 -    Pixmap brush;
  11.108 -    Picture brush_pict;
  11.109 -    Picture xwindow_pict;
  11.110 -    Picture pixmap_picts[3];
  11.111 -    Picture drawable_pict;
  11.112 -    Picture stencil_pict;
  11.113 -    int blend_op;
  11.114 -    XRenderPictFormat *xwindow_pict_fmt;
  11.115 -    XRenderPictFormat *drawable_pict_fmt;
  11.116 -    GC stencil_gc;
  11.117 -    SDL_bool use_xrender;
  11.118 -#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  11.119 -    SDL_bool use_xdamage;
  11.120 -    Damage stencil_damage;
  11.121 -    XserverRegion stencil_parts;
  11.122 -#endif
  11.123 -#endif
  11.124 -    int current_pixmap;
  11.125 -    Drawable drawable;
  11.126 -    SDL_PixelFormat format;
  11.127 -    GC gc;
  11.128 -    SDL_DirtyRectList dirty;
  11.129 -    SDL_bool makedirty;
  11.130 -} X11_RenderData;
  11.131 -
  11.132 -typedef struct
  11.133 -{
  11.134 -    SDL_SW_YUVTexture *yuv;
  11.135 -    Uint32 format;
  11.136 -    Pixmap pixmap;
  11.137 -    int depth;
  11.138 -    Visual *visual;
  11.139 -    GC gc;
  11.140 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  11.141 -    Picture picture;
  11.142 -    Pixmap modulated_pixmap;
  11.143 -    Picture modulated_picture;
  11.144 -    XRenderPictFormat* picture_fmt;
  11.145 -    int blend_op;
  11.146 -    const char* filter;
  11.147 -#endif
  11.148 -    XImage *image;
  11.149 -#ifndef NO_SHARED_MEMORY
  11.150 -    /* MIT shared memory extension information */
  11.151 -    XShmSegmentInfo shminfo;
  11.152 -#endif
  11.153 -    XImage *scaling_image;
  11.154 -    void *pixels;
  11.155 -    int pitch;
  11.156 -} X11_TextureData;
  11.157 -
  11.158 -#ifndef NO_SHARED_MEMORY
  11.159 -/* Shared memory error handler routine */
  11.160 -static int shm_error;
  11.161 -static int (*X_handler) (Display *, XErrorEvent *) = NULL;
  11.162 -static int
  11.163 -shm_errhandler(Display * d, XErrorEvent * e)
  11.164 -{
  11.165 -    if (e->error_code == BadAccess) {
  11.166 -        shm_error = True;
  11.167 -        return (0);
  11.168 -    } else {
  11.169 -        return (X_handler(d, e));
  11.170 -    }
  11.171 -}
  11.172 -#endif /* ! NO_SHARED_MEMORY */
  11.173 -
  11.174 -static void
  11.175 -UpdateYUVTextureData(SDL_Texture * texture)
  11.176 -{
  11.177 -    X11_TextureData *data = (X11_TextureData *) texture->driverdata;
  11.178 -    SDL_Rect rect;
  11.179 -
  11.180 -    rect.x = 0;
  11.181 -    rect.y = 0;
  11.182 -    rect.w = texture->w;
  11.183 -    rect.h = texture->h;
  11.184 -    SDL_SW_CopyYUVToRGB(data->yuv, &rect, data->format, texture->w,
  11.185 -                        texture->h, data->pixels, data->pitch);
  11.186 -}
  11.187 -
  11.188 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  11.189 -static SDL_bool
  11.190 -CheckXRender(Display *display, int *major, int *minor)
  11.191 -{
  11.192 -    const char *env;
  11.193 -
  11.194 -    *major = *minor = 0;
  11.195 -
  11.196 -    env = SDL_getenv("SDL_VIDEO_X11_XRENDER");
  11.197 -
  11.198 -    if (env && !SDL_atoi(env)) {
  11.199 -        return SDL_FALSE;
  11.200 -    }
  11.201 -
  11.202 -    if (!SDL_X11_HAVE_XRENDER) {
  11.203 -        return SDL_FALSE;
  11.204 -    }
  11.205 -
  11.206 -    if (!XRenderQueryVersion(display, major, minor)) {
  11.207 -        return SDL_FALSE;
  11.208 -    }
  11.209 -
  11.210 -    if (*major != 0 || *minor < 10) {
  11.211 -        return SDL_FALSE;
  11.212 -    }
  11.213 -
  11.214 -    return SDL_TRUE;
  11.215 -}
  11.216 -#endif
  11.217 -
  11.218 -#ifdef SDL_VIDEO_DRIVER_X11_XFIXES
  11.219 -static SDL_bool
  11.220 -CheckXFixes(Display *display, int *major, int *minor)
  11.221 -{
  11.222 -    const char *env;
  11.223 -
  11.224 -    *major = *minor = 0;
  11.225 -
  11.226 -    env = SDL_getenv("SDL_VIDEO_X11_XFIXES");
  11.227 -
  11.228 -    if (env && !SDL_atoi(env)) {
  11.229 -        return SDL_FALSE;
  11.230 -    }
  11.231 -
  11.232 -    if (!SDL_X11_HAVE_XFIXES) {
  11.233 -        return SDL_FALSE;
  11.234 -    }
  11.235 -
  11.236 -    if (!XFixesQueryVersion(display, major, minor)) {
  11.237 -        return SDL_FALSE;
  11.238 -    }
  11.239 -
  11.240 -    if (*major < 2) {
  11.241 -        return SDL_FALSE;
  11.242 -    }
  11.243 -
  11.244 -    return SDL_TRUE;
  11.245 -}
  11.246 -#endif
  11.247 -
  11.248 -#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  11.249 -static SDL_bool
  11.250 -CheckXDamage(Display *display, int *major, int *minor)
  11.251 -{
  11.252 -    const char *env;
  11.253 -
  11.254 -    *major = *minor = 0;
  11.255 -
  11.256 -    env = SDL_getenv("SDL_VIDEO_X11_XDAMAGE");
  11.257 -
  11.258 -    if (env && !SDL_atoi(env)) {
  11.259 -        return SDL_FALSE;
  11.260 -    }
  11.261 -
  11.262 -    if (!SDL_X11_HAVE_XDAMAGE) {
  11.263 -        return SDL_FALSE;
  11.264 -    }
  11.265 -
  11.266 -    if (!XDamageQueryVersion(display, major, minor)) {
  11.267 -        return SDL_FALSE;
  11.268 -    }
  11.269 -
  11.270 -    return SDL_TRUE;
  11.271 -}
  11.272 -#endif
  11.273 -
  11.274 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  11.275 -static Uint32
  11.276 -XRenderPictFormatToSDLPixelFormatEnum(XRenderPictFormat *pict_format)
  11.277 -{
  11.278 -    if (pict_format->type != PictTypeDirect) {
  11.279 -        SDL_SetError("Indexed pict formats not supported ATM");
  11.280 -        return 0;
  11.281 -    }
  11.282 -    Uint32 Amask, Rmask, Gmask, Bmask;
  11.283 -    int bpp;
  11.284 -
  11.285 -    Rmask = pict_format->direct.redMask << pict_format->direct.red;
  11.286 -    Gmask = pict_format->direct.greenMask << pict_format->direct.green;
  11.287 -    Bmask = pict_format->direct.blueMask << pict_format->direct.blue;
  11.288 -    Amask = pict_format->direct.alphaMask << pict_format->direct.alpha;
  11.289 -    bpp = pict_format->depth;
  11.290 -
  11.291 -    Uint32 format;
  11.292 -    format = SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
  11.293 -    return format;
  11.294 -}
  11.295 -#endif
  11.296 -
  11.297 -void
  11.298 -X11_AddRenderDriver(_THIS)
  11.299 -{
  11.300 -    SDL_RendererInfo *info = &X11_RenderDriver.info;
  11.301 -    SDL_DisplayMode *mode = &SDL_CurrentDisplay->desktop_mode;
  11.302 -    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
  11.303 -    int i;
  11.304 -
  11.305 -    info->texture_formats[info->num_texture_formats++] = mode->format;
  11.306 -    info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YV12;
  11.307 -    info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_IYUV;
  11.308 -    info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YUY2;
  11.309 -    info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_UYVY;
  11.310 -    info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YVYU;
  11.311 -
  11.312 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  11.313 -    int major, minor;
  11.314 -    if (CheckXRender(data->display, &major, &minor)) {
  11.315 -        XRenderPictFormat templ;
  11.316 -        templ.type = PictTypeDirect;
  11.317 -        XRenderPictFormat *pict_format;
  11.318 -        Uint32 format;
  11.319 -        int i = 0;
  11.320 -        /* Convert each XRenderPictFormat into appropriate
  11.321 -         * SDLPixelFormatEnum. */
  11.322 -        while (info->num_texture_formats < 50) {
  11.323 -            pict_format =
  11.324 -                XRenderFindFormat(data->display, PictFormatType, &templ, i++);
  11.325 -            if (pict_format) {
  11.326 -                format = XRenderPictFormatToSDLPixelFormatEnum(pict_format);
  11.327 -                if (format != SDL_PIXELTYPE_UNKNOWN) {
  11.328 -                    info->texture_formats[info->num_texture_formats++] = format;
  11.329 -                }
  11.330 -            }
  11.331 -            else
  11.332 -                break;
  11.333 -        }
  11.334 -        /* Update the capabilities of the renderer. */
  11.335 -        info->blend_modes |= (SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD |
  11.336 -                             SDL_BLENDMODE_MOD | SDL_BLENDMODE_MASK);
  11.337 -        info->scale_modes |= (SDL_SCALEMODE_FAST | SDL_SCALEMODE_SLOW |
  11.338 -                             SDL_SCALEMODE_BEST);
  11.339 -        info->mod_modes |= (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA);
  11.340 -    }
  11.341 -#endif
  11.342 -
  11.343 -    for (i = 0; i < _this->num_displays; ++i) {
  11.344 -        SDL_AddRenderDriver(&_this->displays[i], &X11_RenderDriver);
  11.345 -    }
  11.346 -}
  11.347 -
  11.348 -SDL_Renderer *
  11.349 -X11_CreateRenderer(SDL_Window * window, Uint32 flags)
  11.350 -{
  11.351 -    SDL_VideoDisplay *display = window->display;
  11.352 -    SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
  11.353 -    SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
  11.354 -    SDL_Renderer *renderer;
  11.355 -    X11_RenderData *data;
  11.356 -    XGCValues gcv;
  11.357 -    gcv.graphics_exposures = False;
  11.358 -    int i, n;
  11.359 -    int bpp;
  11.360 -    Uint32 Rmask, Gmask, Bmask, Amask;
  11.361 -
  11.362 -    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
  11.363 -    if (!renderer) {
  11.364 -        SDL_OutOfMemory();
  11.365 -        return NULL;
  11.366 -    }
  11.367 -
  11.368 -    data = (X11_RenderData *) SDL_calloc(1, sizeof(*data));
  11.369 -    if (!data) {
  11.370 -        X11_DestroyRenderer(renderer);
  11.371 -        SDL_OutOfMemory();
  11.372 -        return NULL;
  11.373 -    }
  11.374 -    data->display = windowdata->videodata->display;
  11.375 -    data->screen = displaydata->screen;
  11.376 -    data->visual = displaydata->visual;
  11.377 -    data->depth = displaydata->depth;
  11.378 -    data->scanline_pad = displaydata->scanline_pad;
  11.379 -    data->xwindow = windowdata->xwindow;
  11.380 -    
  11.381 -    renderer->DisplayModeChanged = X11_DisplayModeChanged;
  11.382 -    renderer->CreateTexture = X11_CreateTexture;
  11.383 -    renderer->QueryTexturePixels = X11_QueryTexturePixels;
  11.384 -    renderer->SetTextureAlphaMod = X11_SetTextureRGBAMod;
  11.385 -    renderer->SetTextureColorMod = X11_SetTextureRGBAMod;
  11.386 -    renderer->SetTextureBlendMode = X11_SetTextureBlendMode;
  11.387 -    renderer->SetTextureScaleMode = X11_SetTextureScaleMode;
  11.388 -    renderer->UpdateTexture = X11_UpdateTexture;
  11.389 -    renderer->LockTexture = X11_LockTexture;
  11.390 -    renderer->UnlockTexture = X11_UnlockTexture;
  11.391 -    renderer->SetDrawBlendMode = X11_SetDrawBlendMode;
  11.392 -    renderer->RenderDrawPoints = X11_RenderDrawPoints;
  11.393 -    renderer->RenderDrawLines = X11_RenderDrawLines;
  11.394 -    renderer->RenderDrawRects = X11_RenderDrawRects;
  11.395 -    renderer->RenderFillRects = X11_RenderFillRects;
  11.396 -    renderer->RenderCopy = X11_RenderCopy;
  11.397 -    renderer->RenderReadPixels = X11_RenderReadPixels;
  11.398 -    renderer->RenderWritePixels = X11_RenderWritePixels;
  11.399 -    renderer->RenderPresent = X11_RenderPresent;
  11.400 -    renderer->DestroyTexture = X11_DestroyTexture;
  11.401 -    renderer->DestroyRenderer = X11_DestroyRenderer;
  11.402 -    renderer->info = X11_RenderDriver.info;
  11.403 -    renderer->window = window;
  11.404 -    renderer->driverdata = data;
  11.405 -
  11.406 -    renderer->info.flags = SDL_RENDERER_ACCELERATED;
  11.407 -
  11.408 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  11.409 -    int major, minor;
  11.410 -    data->use_xrender = CheckXRender(data->display, &major, &minor);
  11.411 -#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  11.412 -    if (CheckXDamage(data->display, &major, &minor)) {
  11.413 -        if (CheckXFixes(data->display, &major, &minor)) {
  11.414 -            data->use_xdamage = SDL_TRUE;
  11.415 -        }
  11.416 -    }
  11.417 -#endif
  11.418 -    if (data->use_xrender) {
  11.419 -        /* Find the PictFormat from the visual.
  11.420 -         * Should be an RGB PictFormat most of the time. */
  11.421 -        data->xwindow_pict_fmt = XRenderFindVisualFormat(data->display,
  11.422 -                                                         data->visual);
  11.423 -        if (!data->xwindow_pict_fmt) {
  11.424 -            SDL_SetError("XRenderFindVisualFormat() failed");
  11.425 -            return NULL;
  11.426 -        }
  11.427 -        data->xwindow_pict = XRenderCreatePicture(data->display,
  11.428 -                                                  data->xwindow,
  11.429 -                                                  data->xwindow_pict_fmt,
  11.430 -                                                  0, NULL);
  11.431 -        if (!data->xwindow_pict) {
  11.432 -            SDL_SetError("XRenderCreatePicture() failed");
  11.433 -            return NULL;
  11.434 -        }
  11.435 -        // FIXME: Clear the window. Is this required?
  11.436 -        XRenderComposite(data->display,
  11.437 -                         PictOpClear,
  11.438 -                         data->xwindow_pict,
  11.439 -                         None,
  11.440 -                         data->xwindow_pict,
  11.441 -                         0, 0,
  11.442 -                         0, 0,
  11.443 -                         0, 0,
  11.444 -                         window->w, window->h);
  11.445 -        /* Create a clip mask that is used for rendering primitives. */
  11.446 -        data->stencil = XCreatePixmap(data->display, data->xwindow,
  11.447 -                                   window->w, window->h, 32);
  11.448 -        if (!data->stencil) {
  11.449 -            SDL_SetError("XCreatePixmap() failed.");
  11.450 -            return NULL;
  11.451 -        }
  11.452 -        
  11.453 -        /* Create the GC for the clip mask. */
  11.454 -        data->stencil_gc = XCreateGC(data->display, data->stencil,
  11.455 -                                  GCGraphicsExposures, &gcv);
  11.456 -        /* Set the GC parameters. */
  11.457 -        XSetBackground(data->display, data->stencil_gc, 0);
  11.458 -        XSetForeground(data->display, data->stencil_gc, 0);
  11.459 -        XFillRectangle(data->display, data->stencil, data->stencil_gc,
  11.460 -                       0, 0, window->w, window->h);
  11.461 -        XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF);
  11.462 -
  11.463 -        /* Create an XRender Picture for the clip mask. */
  11.464 -        data->stencil_pict =
  11.465 -            XRenderCreatePicture(data->display, data->stencil,
  11.466 -                                 XRenderFindStandardFormat(data->display,
  11.467 -                                                           PictStandardARGB32),
  11.468 -                                 0, NULL);
  11.469 -        if (!data->stencil_pict) {
  11.470 -            SDL_SetError("XRenderCreatePicture() failed.");
  11.471 -            return NULL;
  11.472 -        }
  11.473 -#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  11.474 -        if (data->use_xdamage) {
  11.475 -            data->stencil_damage =
  11.476 -                XDamageCreate(data->display, data->stencil, XDamageReportNonEmpty);
  11.477 -            if (!data->stencil_damage) {
  11.478 -                SDL_SetError("XDamageCreate() failed.");
  11.479 -                return NULL;
  11.480 -            }
  11.481 -            XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts);
  11.482 -        }
  11.483 -#endif
  11.484 -        /* Create a brush pixmap for the color being
  11.485 -         * drawn at any given time. */
  11.486 -        data->brush =
  11.487 -            XCreatePixmap(data->display, data->xwindow, 1, 1, 32);
  11.488 -        if (!data->brush) {
  11.489 -            SDL_SetError("XCreatePixmap() failed.");
  11.490 -            return NULL;
  11.491 -        }
  11.492 -
  11.493 -        /* Set some parameters for the brush. */
  11.494 -        XRenderPictureAttributes brush_attr;
  11.495 -        brush_attr.repeat = RepeatNormal;
  11.496 -        /* Create an XRender Picture for the brush
  11.497 -         * with the above parameters. */
  11.498 -        data->brush_pict =
  11.499 -            XRenderCreatePicture(data->display, data->brush,
  11.500 -                                 XRenderFindStandardFormat(data->display,
  11.501 -                                                           PictStandardARGB32),
  11.502 -                                 CPRepeat, &brush_attr);
  11.503 -        if (!data->brush_pict) {
  11.504 -            SDL_SetError("XRenderCreatePicture() failed.");
  11.505 -            return NULL;
  11.506 -        }
  11.507 -        // FIXME: Is the following necessary?
  11.508 -        /* Set the default blending mode. */
  11.509 -        renderer->blendMode = SDL_BLENDMODE_BLEND;
  11.510 -        data->blend_op = PictOpOver;
  11.511 -    }
  11.512 -#endif
  11.513 -    if (flags & SDL_RENDERER_SINGLEBUFFER) {
  11.514 -        renderer->info.flags |=
  11.515 -            (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY);
  11.516 -        n = 0;
  11.517 -    } else if (flags & SDL_RENDERER_PRESENTFLIP2) {
  11.518 -        renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
  11.519 -        n = 2;
  11.520 -    } else if (flags & SDL_RENDERER_PRESENTFLIP3) {
  11.521 -        renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
  11.522 -        n = 3;
  11.523 -    } else {
  11.524 -        renderer->info.flags |= SDL_RENDERER_PRESENTCOPY;
  11.525 -        n = 1;
  11.526 -    }
  11.527 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  11.528 -    if (data->use_xrender) {
  11.529 -        if (n > 0)
  11.530 -            data->drawable_pict_fmt =
  11.531 -                XRenderFindStandardFormat(data->display, PictStandardARGB32);
  11.532 -        else
  11.533 -            data->drawable_pict_fmt = data->xwindow_pict_fmt;
  11.534 -    }
  11.535 -#endif
  11.536 -    for (i = 0; i < n; ++i) {
  11.537 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  11.538 -        if (data->use_xrender) {
  11.539 -            data->pixmaps[i] = XCreatePixmap(data->display,
  11.540 -                                             data->xwindow,
  11.541 -                                             window->w,
  11.542 -                                             window->h,
  11.543 -                                             32);
  11.544 -        }
  11.545 -        else
  11.546 -#endif
  11.547 -        {
  11.548 -            data->pixmaps[i] =
  11.549 -                XCreatePixmap(data->display, data->xwindow, window->w, window->h,
  11.550 -                              displaydata->depth);
  11.551 -        }
  11.552 -        if (!data->pixmaps[i]) {
  11.553 -            X11_DestroyRenderer(renderer);
  11.554 -            SDL_SetError("XCreatePixmap() failed");
  11.555 -            return NULL;
  11.556 -        }
  11.557 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  11.558 -        if (data->use_xrender) {
  11.559 -            /* Create XRender pictures for each of the pixmaps
  11.560 -             * and clear the pixmaps. */
  11.561 -            data->pixmap_picts[i] = 
  11.562 -                XRenderCreatePicture(data->display,
  11.563 -                                     data->pixmaps[i],
  11.564 -                                     XRenderFindStandardFormat(data->display,
  11.565 -                                                               PictStandardARGB32),
  11.566 -                                     0, None);
  11.567 -            if (!data->pixmap_picts[i]) {
  11.568 -                SDL_SetError("XRenderCreatePicture() failed");
  11.569 -                return NULL;
  11.570 -            }
  11.571 -
  11.572 -            XRenderComposite(data->display,
  11.573 -                             PictOpClear,
  11.574 -                             data->pixmap_picts[i],
  11.575 -                             None,
  11.576 -                             data->pixmap_picts[i],
  11.577 -                             0, 0,
  11.578 -                             0, 0,
  11.579 -                             0, 0,
  11.580 -                             window->w, window->h);
  11.581 -        }
  11.582 -#endif
  11.583 -    }
  11.584 -    if (n > 0) {
  11.585 -        data->drawable = data->pixmaps[0];
  11.586 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  11.587 -        if(data->use_xrender == SDL_TRUE)
  11.588 -            data->drawable_pict = data->pixmap_picts[0];
  11.589 -#endif
  11.590 -        data->makedirty = SDL_TRUE;
  11.591 -    } else {
  11.592 -        data->drawable = data->xwindow;
  11.593 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  11.594 -        if(data->use_xrender == SDL_TRUE)
  11.595 -            data->drawable_pict = data->xwindow_pict;
  11.596 -#endif
  11.597 -        data->makedirty = SDL_FALSE;
  11.598 -    }
  11.599 -    data->current_pixmap = 0;
  11.600 -
  11.601 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  11.602 -    /* When using XRender the drawable format
  11.603 -     * is not the same as the screen format. */
  11.604 -    if (data->use_xrender) {
  11.605 -        bpp = data->drawable_pict_fmt->depth;
  11.606 -        Rmask = ((data->drawable_pict_fmt->direct.redMask)
  11.607 -                    << (data->drawable_pict_fmt->direct.red));
  11.608 -        Gmask = ((data->drawable_pict_fmt->direct.greenMask)
  11.609 -                    << (data->drawable_pict_fmt->direct.green));
  11.610 -        Bmask = ((data->drawable_pict_fmt->direct.blueMask)
  11.611 -                    << (data->drawable_pict_fmt->direct.blue));
  11.612 -        Amask = ((data->drawable_pict_fmt->direct.alphaMask)
  11.613 -                    << (data->drawable_pict_fmt->direct.alpha));
  11.614 -    }
  11.615 -    else
  11.616 -#endif
  11.617 -    {
  11.618 -        /* Get the format of the window */
  11.619 -        if (!SDL_PixelFormatEnumToMasks
  11.620 -            (display->current_mode.format, &bpp, &Rmask, &Gmask, &Bmask,
  11.621 -             &Amask)) {
  11.622 -            SDL_SetError("Unknown display format");
  11.623 -            X11_DestroyRenderer(renderer);
  11.624 -            return NULL;
  11.625 -        }
  11.626 -    }
  11.627 -    SDL_InitFormat(&data->format, bpp, Rmask, Gmask, Bmask, Amask);
  11.628 -
  11.629 -    /* Create the drawing context */
  11.630 -    gcv.graphics_exposures = False;
  11.631 -    data->gc =
  11.632 -        XCreateGC(data->display, data->drawable, GCGraphicsExposures, &gcv);
  11.633 -    if (!data->gc) {
  11.634 -        X11_DestroyRenderer(renderer);
  11.635 -        SDL_SetError("XCreateGC() failed");
  11.636 -        return NULL;
  11.637 -    }
  11.638 -
  11.639 -    return renderer;
  11.640 -}
  11.641 -
  11.642 -static int
  11.643 -X11_DisplayModeChanged(SDL_Renderer * renderer)
  11.644 -{
  11.645 -    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
  11.646 -    SDL_Window *window = renderer->window;
  11.647 -    int i, n;
  11.648 -
  11.649 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  11.650 -    if (data->use_xrender) {
  11.651 -        XRenderFreePicture(data->display, data->xwindow_pict);
  11.652 -        
  11.653 -        data->xwindow_pict_fmt =
  11.654 -            XRenderFindVisualFormat(data->display, data->visual);
  11.655 -        if (!data->xwindow_pict_fmt) {
  11.656 -            SDL_SetError("XRenderFindVisualFormat() failed.");
  11.657 -            return -1;
  11.658 -        }
  11.659 -
  11.660 -        data->xwindow_pict =
  11.661 -            XRenderCreatePicture(data->display, data->xwindow,
  11.662 -                                 data->xwindow_pict_fmt, 0, NULL);
  11.663 -        if (!data->xwindow_pict) {
  11.664 -            SDL_SetError("XRenderCreatePicture() failed.");
  11.665 -            return -1;
  11.666 -        }
  11.667 -
  11.668 -        XRenderComposite(data->display,
  11.669 -                         PictOpClear,
  11.670 -                         data->xwindow_pict,
  11.671 -                         None,
  11.672 -                         data->xwindow_pict,
  11.673 -                         0, 0,
  11.674 -                         0, 0,
  11.675 -                         0, 0,
  11.676 -                         window->w, window->h);
  11.677 -        
  11.678 -        XFreePixmap(data->display, data->stencil);
  11.679 -        data->stencil = XCreatePixmap(data->display, data->xwindow,
  11.680 -                                   window->w, window->h, 32);
  11.681 -        if (!data->stencil) {
  11.682 -            SDL_SetError("XCreatePixmap() failed.");
  11.683 -            return -1;
  11.684 -        }
  11.685 -
  11.686 -        XRenderFreePicture(data->display, data->stencil_pict);
  11.687 -        data->stencil_pict =
  11.688 -            XRenderCreatePicture(data->display, data->stencil,
  11.689 -                                 XRenderFindStandardFormat(data->display,
  11.690 -                                                           PictStandardARGB32),
  11.691 -                                 0, NULL);
  11.692 -        if (!data->stencil_pict) {
  11.693 -            SDL_SetError("XRenderCreatePicture() failed.");
  11.694 -            return -1;
  11.695 -        }
  11.696 -#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
  11.697 -        if (data->use_xdamage) {
  11.698 -            XDamageDestroy(data->display, data->stencil_damage);
  11.699 -            data->stencil_damage =
  11.700 -                XDamageCreate(data->display, data->stencil, XDamageReportNonEmpty);
  11.701 -            if (!data->stencil_damage) {
  11.702 -                SDL_SetError("XDamageCreate() failed.");
  11.703 -                return -1;
  11.704 -            }
  11.705 -            XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts);
  11.706 -        }
  11.707 -#endif
  11.708 -    }
  11.709 -#endif
  11.710 -    if (renderer->info.flags & SDL_RENDERER_SINGLEBUFFER) {
  11.711 -        n = 0;
  11.712 -    } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
  11.713 -        n = 2;
  11.714 -    } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
  11.715 -        n = 3;
  11.716 -    } else {
  11.717 -        n = 1;
  11.718 -    }
  11.719 -    for (i = 0; i < n; ++i) {
  11.720 -        if (data->pixmaps[i] != None) {
  11.721 -            XFreePixmap(data->display, data->pixmaps[i]);
  11.722 -            data->pixmaps[i] = None;
  11.723 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  11.724 -            XRenderFreePicture(data->display, data->pixmap_picts[i]);
  11.725 -            data->pixmap_picts[i] = None;
  11.726 -#endif
  11.727 -        }
  11.728 -    }
  11.729 -    for (i = 0; i < n; ++i) {
  11.730 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  11.731 -        if (data->use_xrender) {
  11.732 -            data->pixmaps[i] =
  11.733 -                XCreatePixmap(data->display,
  11.734 -                              data->xwindow,
  11.735 -                              window->w,
  11.736 -                              window->h,
  11.737 -                              32);
  11.738 -        }
  11.739 -        else
  11.740 -#endif
  11.741 -        {
  11.742 -            data->pixmaps[i] =
  11.743 -                XCreatePixmap(data->display, data->xwindow, window->w, window->h,
  11.744 -                              data->depth);
  11.745 -        }
  11.746 -        if (data->pixmaps[i] == None) {
  11.747 -            SDL_SetError("XCreatePixmap() failed");
  11.748 -            return -1;
  11.749 -        }
  11.750 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  11.751 -        if (data->use_xrender) {
  11.752 -            data->pixmap_picts[i] = 
  11.753 -                XRenderCreatePicture(data->display,
  11.754 -                                     data->pixmaps[i],
  11.755 -                                     XRenderFindStandardFormat(data->display,
  11.756 -                                                               PictStandardARGB32),
  11.757 -                                     0, None);
  11.758 -            if (!data->pixmap_picts[i]) {
  11.759 -                SDL_SetError("XRenderCreatePicture() failed");
  11.760 -                return -1;
  11.761 -            }
  11.762 -            XRenderComposite(data->display,
  11.763 -                             PictOpClear,
  11.764 -                             data->pixmap_picts[i],
  11.765 -                             None,
  11.766 -                             data->pixmap_picts[i],
  11.767 -                             0, 0,
  11.768 -                             0, 0,
  11.769 -                             0, 0,
  11.770 -                             window->w, window->h);
  11.771 -
  11.772 -       }
  11.773 -#endif
  11.774 -    }
  11.775 -    if (n > 0) {
  11.776 -        data->drawable = data->pixmaps[0];
  11.777 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  11.778 -        data->drawable_pict = data->pixmap_picts[0];
  11.779 -#endif
  11.780 -    }
  11.781 -    data->current_pixmap = 0;
  11.782 -
  11.783 -    return 0;
  11.784 -}
  11.785 -
  11.786 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  11.787 -static void
  11.788 -SDLMaskToXRenderMask(Uint32 sdl_mask, short *comp, short *compMask)
  11.789 -{
  11.790 -    if (sdl_mask == 0) {
  11.791 -        *comp = 0;
  11.792 -        *compMask = 0;
  11.793 -    } else {
  11.794 -        (*comp) = 0;
  11.795 -        (*compMask) = 0;
  11.796 -        while(!(sdl_mask & 1)) {
  11.797 -            (*comp)++;
  11.798 -            sdl_mask >>= 1;
  11.799 -        }
  11.800 -        while(sdl_mask & 1) {
  11.801 -            (*compMask) = ((*compMask) << 1) | 1;
  11.802 -            sdl_mask >>= 1;
  11.803 -        }
  11.804 -    }
  11.805 -}
  11.806 -
  11.807 -static XRenderPictFormat*
  11.808 -PixelFormatEnumToXRenderPictFormat(SDL_Renderer * renderer, Uint32 format)
  11.809 -{
  11.810 -    XRenderPictFormat* pict_fmt = NULL;
  11.811 -    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
  11.812 -    
  11.813 -    if (data->use_xrender) {
  11.814 -
  11.815 -        int bpp;
  11.816 -        Uint32 Amask, Rmask, Gmask, Bmask;
  11.817 -        if(!SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
  11.818 -            SDL_SetError("Unknown pixel format");
  11.819 -            return NULL;
  11.820 -        }
  11.821 -        XRenderPictFormat templ;
  11.822 -        unsigned long mask = (PictFormatType | PictFormatDepth | PictFormatRed |
  11.823 -                              PictFormatRedMask | PictFormatGreen | PictFormatGreenMask |
  11.824 -                              PictFormatBlue | PictFormatBlueMask | PictFormatAlpha |
  11.825 -                              PictFormatAlphaMask);
  11.826 -
  11.827 -        templ.type = PictTypeDirect;
  11.828 -        templ.depth = bpp;
  11.829 -        SDLMaskToXRenderMask(Amask, &(templ.direct.alpha), &(templ.direct.alphaMask));
  11.830 -        SDLMaskToXRenderMask(Rmask, &(templ.direct.red), &(templ.direct.redMask));
  11.831 -        SDLMaskToXRenderMask(Gmask, &(templ.direct.green), &(templ.direct.greenMask));
  11.832 -        SDLMaskToXRenderMask(Bmask, &(templ.direct.blue), &(templ.direct.blueMask));
  11.833 -        pict_fmt = XRenderFindFormat(data->display, mask, &templ, 0);
  11.834 -    }
  11.835 -    
  11.836 -    return pict_fmt;
  11.837 -}
  11.838 -
  11.839 -static Visual*
  11.840 -PixelFormatEnumToVisual(SDL_Renderer * renderer, Uint32 format)
  11.841 -{
  11.842 -    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
  11.843 -
  11.844 -    if (data->use_xrender) {
  11.845 -        int bpp;
  11.846 -        Uint32 Amask, Rmask, Gmask, Bmask;
  11.847 -        SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
  11.848 -
  11.849 -        XVisualInfo vinfo_templ;
  11.850 -        long vinfo_mask;
  11.851 -        int nitems_return;
  11.852 -
  11.853 -        vinfo_mask = (VisualDepthMask | VisualRedMaskMask |
  11.854 -                      VisualGreenMaskMask | VisualBlueMaskMask);
  11.855 -        vinfo_templ.depth = bpp;
  11.856 -        vinfo_templ.red_mask = Rmask;
  11.857 -        vinfo_templ.green_mask = Gmask;
  11.858 -        vinfo_templ.blue_mask = Bmask;
  11.859 -
  11.860 -        XVisualInfo * ret = XGetVisualInfo(data->display, vinfo_mask,
  11.861 -                                           &vinfo_templ, &nitems_return);
  11.862 -        
  11.863 -        if (nitems_return) {
  11.864 -            return ret[0].visual;
  11.865 -        }
  11.866 -    }
  11.867 -
  11.868 -    return NULL;
  11.869 -}
  11.870 -
  11.871 -static XRenderColor
  11.872 -SDLColorToXRenderColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
  11.873 -{
  11.874 -    double rd, gd, bd, ad;
  11.875 -    XRenderColor ret;
  11.876 -    rd = r / 255.0;
  11.877 -    gd = g / 255.0;
  11.878 -    bd = b / 255.0;
  11.879 -    ad = a / 255.0;
  11.880 -    
  11.881 -    ret.red = (unsigned short) (rd * ad * 0xFFFF);
  11.882 -    ret.green = (unsigned short) (gd * ad * 0xFFFF);
  11.883 -    ret.blue = (unsigned short) (bd * ad * 0xFFFF);
  11.884 -    ret.alpha = (unsigned short) (ad * 0xFFFF);
  11.885 -
  11.886 -    return ret;
  11.887 -}
  11.888 -#endif
  11.889 -
  11.890 -static int
  11.891 -X11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
  11.892 -{
  11.893 -    X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
  11.894 -    SDL_Window *window = renderer->window;
  11.895 -    SDL_VideoDisplay *display = window->display;
  11.896 -    X11_TextureData *data;
  11.897 -    int pitch_alignmask = ((renderdata->scanline_pad / 8) - 1);
  11.898 -    XGCValues gcv;
  11.899 -    
  11.900 -    data = (X11_TextureData *) SDL_calloc(1, sizeof(*data));
  11.901 -    if (!data) {
  11.902 -        SDL_OutOfMemory();
  11.903 -        return -1;
  11.904 -    }
  11.905 -    data->depth = renderdata->depth;
  11.906 -    data->visual = renderdata->visual;
  11.907 -    data->gc = renderdata->gc;
  11.908 -
  11.909 -    texture->driverdata = data;
  11.910 -    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
  11.911 -        data->yuv =
  11.912 -            SDL_SW_CreateYUVTexture(texture->format, texture->w, texture->h);
  11.913 -        if (!data->yuv) {
  11.914 -            return -1;
  11.915 -        }
  11.916 -        data->format = display->current_mode.format;
  11.917 -    } else {
  11.918 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
  11.919 -        if (renderdata->use_xrender)
  11.920 -        {
  11.921 -            Uint32 Amask, Rmask, Gmask, Bmask;
  11.922 -            SDL_PixelFormatEnumToMasks(texture->format, &(data->depth),
  11.923 -                                       &Rmask, &Gmask, &Bmask, &Amask);
  11.924 -            data->visual = PixelFormatEnumToVisual(renderer, texture->format);
  11.925 -        }
  11.926 -        else
  11.927 -#endif
  11.928 -        {
  11.929 -            if (texture->format != display->current_mode.format)
  11.930 -            {
  11.931 -                SDL_SetError("Texture format doesn't match window format");
  11.932 -                return -1;
  11.933 -            }
  11.934 -        }
  11.935 -        data->format = texture->format;
  11.936 -    }
  11.937 -    
  11.938 -    if (data->yuv || texture->access == SDL_TEXTUREACCESS_STREAMING) {
  11.939 -#ifndef NO_SHARED_MEMORY
  11.940 -        XShmSegmentInfo *shminfo = &data->shminfo;
  11.941 -
  11.942 -        shm_error = True;
  11.943 -
  11.944 -        if (SDL_X11_HAVE_SHM) {
  11.945 -            data->image =
  11.946 -                XShmCreateImage(renderdata->display, data->visual,
  11.947 -                                data->depth, ZPixmap, NULL,
  11.948 -                                shminfo, texture->w, texture->h);
  11.949 -            if (data->image) {
  11.950 -                shminfo->shmid =
  11.951 -                    shmget(IPC_PRIVATE, texture->h * data->image->bytes_per_line,
  11.952 -                           IPC_CREAT | 0777);
  11.953 -                if (shminfo->shmid >= 0) {
  11.954 -                    shminfo->shmaddr = (char *) shmat(shminfo->shmid, 0, 0);
  11.955 -                    shminfo->readOnly = False;
  11.956 -                    if (shminfo->shmaddr != (char *) -1) {
  11.957 -                        shm_error = False;
  11.958 -                        X_handler = XSetErrorHandler(shm_errhandler);
  11.959 -                        XShmAttach(renderdata->display, shminfo);
  11.960 -                        XSync(renderdata->display, False);
  11.961 -                        XSetErrorHandler(X_handler);
  11.962 -                        if (shm_error) {
  11.963 -                            XShmDetach(renderdata->display, shminfo);
  11.964 -                            shmdt(shminfo->shmaddr);
  11.965 -                            XDestroyImage(data->image);
  11.966 -                            XSync(renderdata->display, False);
  11.967 -                        }
  11.968 -                        else {
  11.969 -                            data->pixels = data->image->data = shminfo->shmaddr;
  11.970 -                            shmctl(shminfo->shmid, IPC_RMID, NULL);
  11.971 -                            data->pixmap =
  11.972 -                                XCreatePixmap(renderdata->display, renderdata->xwindow,
  11.973 -                                              texture->w, texture->h, data->depth);
  11.974 -                            if (!data->pixmap) {
  11.975 -                                SDL_SetError("XCreatePixmap() failed");
  11.976 -                                return -1;
  11.977 -                            }
  11.978 -                        }
  11.979 -                    }
  11.980 -                }
  11.981 -            }
  11.982 -        }
  11.983 -        if (shm_error) {
  11.984 -            shminfo->shmaddr = NULL;
  11.985 -        }
  11.986 -        if (!data->image)
  11.987 -#endif /* not NO_SHARED_MEMORY */
  11.988 -        {
  11.989 -            data->image =
  11.990 -                XCreateImage(renderdata->display, data->visual,
  11.991 -                             data->depth, ZPixmap, 0, NULL,
  11.992 -                             texture->w, texture->h,
  11.993 -                             SDL_BYTESPERPIXEL(data->format) * 8,
  11.994 -                             0);
  11.995 -            if (!data->image) {
  11.996 -                X11_DestroyTexture(renderer, texture);
  11.997 -                SDL_SetError("XCreateImage() failed");
  11.998 -                return -1;
  11.999 -            }
 11.1000 -            data->pixels = SDL_malloc(texture->h * data->image->bytes_per_line);
 11.1001 -            if (!data->pixels) {
 11.1002 -                X11_DestroyTexture(renderer, texture);
 11.1003 -                SDL_OutOfMemory();
 11.1004 -                return -1;
 11.1005 -            }
 11.1006 -            data->image->data = data->pixels;
 11.1007 -            data->pixmap =
 11.1008 -                XCreatePixmap(renderdata->display, renderdata->xwindow, texture->w,
 11.1009 -                              texture->h, data->depth);
 11.1010 -            if (data->pixmap == None) {
 11.1011 -                X11_DestroyTexture(renderer, texture);
 11.1012 -                SDL_SetError("XCreatePixmap() failed");
 11.1013 -                return -1;
 11.1014 -            }
 11.1015 -        }
 11.1016 -    } else {
 11.1017 -        data->image =
 11.1018 -            XCreateImage(renderdata->display, data->visual,
 11.1019 -                         data->depth, ZPixmap, 0, NULL,
 11.1020 -                         texture->w, texture->h,
 11.1021 -                         SDL_BYTESPERPIXEL(data->format) * 8,
 11.1022 -                         0);
 11.1023 -        if (!data->image) {
 11.1024 -            X11_DestroyTexture(renderer, texture);
 11.1025 -            SDL_SetError("XCreateImage() failed");
 11.1026 -            return -1;
 11.1027 -        }
 11.1028 -        data->pixmap =
 11.1029 -            XCreatePixmap(renderdata->display, renderdata->xwindow, texture->w,
 11.1030 -                          texture->h, data->depth);
 11.1031 -        if (data->pixmap == None) {
 11.1032 -            X11_DestroyTexture(renderer, texture);
 11.1033 -            SDL_SetError("XCreatePixmap() failed");
 11.1034 -            return -1;
 11.1035 -        }
 11.1036 -    }
 11.1037 -
 11.1038 -    data->pitch = data->image->bytes_per_line;
 11.1039 -
 11.1040 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.1041 -    if(renderdata->use_xrender && !data->yuv) {
 11.1042 -        gcv.graphics_exposures = False;
 11.1043 -        data->gc =
 11.1044 -            XCreateGC(renderdata->display, data->pixmap, GCGraphicsExposures, &gcv);
 11.1045 -        if (!data->gc) {
 11.1046 -            SDL_SetError("XCreateGC() failed");
 11.1047 -            return -1;
 11.1048 -        }
 11.1049 -        data->picture_fmt =
 11.1050 -            PixelFormatEnumToXRenderPictFormat(renderer, texture->format);
 11.1051 -        if (data->picture_fmt == NULL) {
 11.1052 -            X11_DestroyTexture(renderer, texture);
 11.1053 -            SDL_SetError("Texture format not supported by driver");
 11.1054 -            return -1;
 11.1055 -        }
 11.1056 -        data->picture =
 11.1057 -            XRenderCreatePicture(renderdata->display, data->pixmap,
 11.1058 -                                 data->picture_fmt, 0, NULL);
 11.1059 -        if (!data->picture) {
 11.1060 -            X11_DestroyTexture(renderer, texture);
 11.1061 -            SDL_SetError("XRenderCreatePicture() failed");
 11.1062 -            return -1;
 11.1063 -        }
 11.1064 -        data->modulated_pixmap =
 11.1065 -            XCreatePixmap(renderdata->display, renderdata->xwindow,
 11.1066 -                          texture->w, texture->h, data->depth);
 11.1067 -        if (!data->modulated_pixmap) {
 11.1068 -            X11_DestroyTexture(renderer, texture);
 11.1069 -            SDL_SetError("XCreatePixmap() failed");
 11.1070 -            return -1;
 11.1071 -        }
 11.1072 -        data->modulated_picture =
 11.1073 -            XRenderCreatePicture(renderdata->display, data->modulated_pixmap,
 11.1074 -                                 data->picture_fmt, 0, NULL);
 11.1075 -        if (!data->modulated_picture) {
 11.1076 -            X11_DestroyTexture(renderer, texture);
 11.1077 -            SDL_SetError("XRenderCreatePicture() failed");
 11.1078 -            return -1;
 11.1079 -        }
 11.1080 -        // FIXME: Is the following required?
 11.1081 -        /* Set the default blending and scaling modes. */
 11.1082 -        texture->blendMode = SDL_BLENDMODE_NONE;
 11.1083 -        texture->scaleMode = SDL_SCALEMODE_NONE;
 11.1084 -        data->blend_op = PictOpSrc;
 11.1085 -        data->filter = NULL;
 11.1086 -    }
 11.1087 -#endif
 11.1088 -    return 0;
 11.1089 -}
 11.1090 -
 11.1091 -static int
 11.1092 -X11_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
 11.1093 -                       void **pixels, int *pitch)
 11.1094 -{
 11.1095 -    X11_TextureData *data = (X11_TextureData *) texture->driverdata;
 11.1096 -
 11.1097 -    if (data->yuv) {
 11.1098 -        return SDL_SW_QueryYUVTexturePixels(data->yuv, pixels, pitch);
 11.1099 -    } else {
 11.1100 -        *pixels = data->pixels;
 11.1101 -        *pitch = data->pitch;
 11.1102 -        return 0;
 11.1103 -    }
 11.1104 -}
 11.1105 -
 11.1106 -static int
 11.1107 -X11_SetTextureRGBAMod(SDL_Renderer * renderer, SDL_Texture * texture)
 11.1108 -{
 11.1109 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.1110 -    X11_TextureData *data = (X11_TextureData *) texture->driverdata;
 11.1111 -    X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
 11.1112 -
 11.1113 -    if (renderdata->use_xrender) {
 11.1114 -
 11.1115 -        Uint8 r = 0xFF, g = 0xFF, b = 0xFF, a = 0xFF;
 11.1116 -
 11.1117 -        /* Check if alpha modulation is required. */
 11.1118 -        if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) {
 11.1119 -            a = texture->a;
 11.1120 -        }
 11.1121 -
 11.1122 -        /* Check if color modulation is required. */
 11.1123 -        if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
 11.1124 -            r = texture->r;
 11.1125 -            g = texture->g;
 11.1126 -            b = texture->b;
 11.1127 -        }
 11.1128 -
 11.1129 -        /* We can save some labour if no modulation is required. */
 11.1130 -        if (texture->modMode != SDL_TEXTUREMODULATE_NONE) {
 11.1131 -            XRenderColor mod_color =
 11.1132 -                SDLColorToXRenderColor(r, g, b, a);
 11.1133 -            XRenderFillRectangle(renderdata->display, PictOpSrc,
 11.1134 -                                 renderdata->brush_pict, &mod_color,
 11.1135 -                                 0, 0, 1, 1);
 11.1136 -        }
 11.1137 -
 11.1138 -        /* We can save some labour dealing with component alpha
 11.1139 -         * if color modulation is not required. */
 11.1140 -        XRenderPictureAttributes attr;
 11.1141 -        if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
 11.1142 -            attr.component_alpha = True;
 11.1143 -            XRenderChangePicture(renderdata->display, renderdata->brush_pict,
 11.1144 -                                 CPComponentAlpha, &attr);
 11.1145 -        }
 11.1146 -
 11.1147 -        /* Again none of this is necessary is no modulation
 11.1148 -         * is required. */
 11.1149 -        if (texture->modMode != SDL_TEXTUREMODULATE_NONE) {
 11.1150 -            XRenderComposite(renderdata->display, PictOpSrc,
 11.1151 -                             data->picture, renderdata->brush_pict,
 11.1152 -                             data->modulated_picture,
 11.1153 -                             0, 0, 0, 0, 0, 0, texture->w, texture->h);
 11.1154 -        }
 11.1155 -
 11.1156 -        /* We only need to reset the component alpha
 11.1157 -         * attribute if color modulation is required. */
 11.1158 -        if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) { 
 11.1159 -            attr.component_alpha = False;
 11.1160 -            XRenderChangePicture(renderdata->display, renderdata->brush_pict,
 11.1161 -                                 CPComponentAlpha, &attr);
 11.1162 -        }
 11.1163 -
 11.1164 -        return 0;
 11.1165 -    } else {
 11.1166 -        SDL_Unsupported();
 11.1167 -        return -1;
 11.1168 -    }
 11.1169 -#else
 11.1170 -    SDL_Unsupported();
 11.1171 -    return -1;
 11.1172 -#endif
 11.1173 -}
 11.1174 -
 11.1175 -static int
 11.1176 -X11_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
 11.1177 -{
 11.1178 -    X11_TextureData *data = (X11_TextureData *) texture->driverdata;
 11.1179 -    X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
 11.1180 -    switch (texture->blendMode) {
 11.1181 -    case SDL_BLENDMODE_NONE:
 11.1182 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.1183 -        if (renderdata->use_xrender) {
 11.1184 -            data->blend_op = PictOpSrc;
 11.1185 -            return 0;
 11.1186 -        }
 11.1187 -    case SDL_BLENDMODE_MOD:
 11.1188 -    case SDL_BLENDMODE_MASK:
 11.1189 -    case SDL_BLENDMODE_BLEND:
 11.1190 -        if (renderdata->use_xrender) {
 11.1191 -            data->blend_op = PictOpOver;
 11.1192 -            return 0;
 11.1193 -        }
 11.1194 -    case SDL_BLENDMODE_ADD:
 11.1195 -        if (renderdata->use_xrender) {
 11.1196 -            data->blend_op = PictOpAdd;
 11.1197 -            return 0;
 11.1198 -        }
 11.1199 -#endif
 11.1200 -        return 0;
 11.1201 -    default:
 11.1202 -        SDL_Unsupported();
 11.1203 -        texture->blendMode = SDL_BLENDMODE_NONE;
 11.1204 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.1205 -        if (renderdata->use_xrender) {
 11.1206 -            texture->blendMode = SDL_BLENDMODE_BLEND;
 11.1207 -            data->blend_op = PictOpOver;
 11.1208 -        }
 11.1209 -#endif
 11.1210 -        return -1;
 11.1211 -    }
 11.1212 -}
 11.1213 -
 11.1214 -static int
 11.1215 -X11_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
 11.1216 -{
 11.1217 -    X11_TextureData *data = (X11_TextureData *) texture->driverdata;
 11.1218 -    X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
 11.1219 -
 11.1220 -    switch (texture->scaleMode) {
 11.1221 -    case SDL_SCALEMODE_NONE:
 11.1222 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.1223 -        if (renderdata->use_xrender) {
 11.1224 -            data->filter = NULL;
 11.1225 -        }
 11.1226 -#endif
 11.1227 -        return 0;
 11.1228 -    case SDL_SCALEMODE_FAST:
 11.1229 -        /* We can sort of fake it for streaming textures */
 11.1230 -        if (data->yuv || texture->access == SDL_TEXTUREACCESS_STREAMING) {
 11.1231 -            return 0;
 11.1232 -        }
 11.1233 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.1234 -        if (renderdata->use_xrender) {
 11.1235 -            data->filter = FilterFast;
 11.1236 -            return 0;
 11.1237 -        }
 11.1238 -    case SDL_SCALEMODE_SLOW:
 11.1239 -        if (renderdata->use_xrender) {
 11.1240 -            data->filter = FilterGood;
 11.1241 -            return 0;
 11.1242 -        }
 11.1243 -    case SDL_SCALEMODE_BEST:
 11.1244 -        if (renderdata->use_xrender) {
 11.1245 -            data->filter = FilterBest;
 11.1246 -            return 0;
 11.1247 -        }
 11.1248 -#endif
 11.1249 -    /* Fall through to unsupported case */
 11.1250 -    default:
 11.1251 -        SDL_Unsupported();
 11.1252 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.1253 -        if (renderdata->use_xrender) {
 11.1254 -            texture->scaleMode = SDL_SCALEMODE_NONE;
 11.1255 -            data->filter = NULL;
 11.1256 -        }
 11.1257 -        else
 11.1258 -#endif
 11.1259 -            texture->scaleMode = SDL_SCALEMODE_NONE;
 11.1260 -        return -1;
 11.1261 -    }
 11.1262 -    return 0;
 11.1263 -}
 11.1264 -
 11.1265 -static int
 11.1266 -X11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
 11.1267 -                  const SDL_Rect * rect, const void *pixels, int pitch)
 11.1268 -{
 11.1269 -    X11_TextureData *data = (X11_TextureData *) texture->driverdata;
 11.1270 -
 11.1271 -    if (data->yuv) {
 11.1272 -        if (SDL_SW_UpdateYUVTexture(data->yuv, rect, pixels, pitch) < 0) {
 11.1273 -            return -1;
 11.1274 -        }
 11.1275 -        UpdateYUVTextureData(texture);
 11.1276 -        return 0;
 11.1277 -    } else {
 11.1278 -        X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
 11.1279 -
 11.1280 -        if (data->pixels) {
 11.1281 -            Uint8 *src, *dst;
 11.1282 -            int row;
 11.1283 -            size_t length;
 11.1284 -
 11.1285 -            src = (Uint8 *) pixels;
 11.1286 -            dst =
 11.1287 -                (Uint8 *) data->pixels + rect->y * data->pitch +
 11.1288 -                rect->x * SDL_BYTESPERPIXEL(texture->format);
 11.1289 -            length = rect->w * SDL_BYTESPERPIXEL(texture->format);
 11.1290 -            for (row = 0; row < rect->h; ++row) {
 11.1291 -                SDL_memcpy(dst, src, length);
 11.1292 -                src += pitch;
 11.1293 -                dst += data->pitch;
 11.1294 -            }
 11.1295 -        } else {
 11.1296 -            data->image->width = rect->w;
 11.1297 -            data->image->height = rect->h;
 11.1298 -            data->image->data = (char *) pixels;
 11.1299 -            data->image->bytes_per_line = pitch;
 11.1300 -            XPutImage(renderdata->display, data->pixmap, data->gc,
 11.1301 -                      data->image, 0, 0, rect->x, rect->y, rect->w, rect->h);
 11.1302 -        }
 11.1303 -        return 0;
 11.1304 -    }
 11.1305 -}
 11.1306 -
 11.1307 -static int
 11.1308 -X11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
 11.1309 -                const SDL_Rect * rect, int markDirty, void **pixels,
 11.1310 -                int *pitch)
 11.1311 -{
 11.1312 -    X11_TextureData *data = (X11_TextureData *) texture->driverdata;
 11.1313 -
 11.1314 -    if (data->yuv) {
 11.1315 -        return SDL_SW_LockYUVTexture(data->yuv, rect, markDirty, pixels,
 11.1316 -                                     pitch);
 11.1317 -    } else if (data->pixels) {
 11.1318 -        *pixels =
 11.1319 -            (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
 11.1320 -                      rect->x * SDL_BYTESPERPIXEL(texture->format));
 11.1321 -        *pitch = data->pitch;
 11.1322 -        return 0;
 11.1323 -    } else {
 11.1324 -        SDL_SetError("No pixels available");
 11.1325 -        return -1;
 11.1326 -    }
 11.1327 -}
 11.1328 -
 11.1329 -static void
 11.1330 -X11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
 11.1331 -{
 11.1332 -    X11_TextureData *data = (X11_TextureData *) texture->driverdata;
 11.1333 -
 11.1334 -    if (data->yuv) {
 11.1335 -        SDL_SW_UnlockYUVTexture(data->yuv);
 11.1336 -        UpdateYUVTextureData(texture);
 11.1337 -    }
 11.1338 -}
 11.1339 -
 11.1340 -static int
 11.1341 -X11_SetDrawBlendMode(SDL_Renderer * renderer)
 11.1342 -{
 11.1343 -    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
 11.1344 -    switch (renderer->blendMode) {
 11.1345 -    case SDL_BLENDMODE_NONE:
 11.1346 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.1347 -        //PictOpSrc
 11.1348 -        data->blend_op = PictOpSrc;
 11.1349 -        return 0;
 11.1350 -    case SDL_BLENDMODE_MOD:
 11.1351 -    case SDL_BLENDMODE_MASK:
 11.1352 -    case SDL_BLENDMODE_BLEND: // PictOpOver
 11.1353 -        data->blend_op = PictOpOver;
 11.1354 -        return 0;
 11.1355 -    case SDL_BLENDMODE_ADD: // PictOpAdd
 11.1356 -        data->blend_op = PictOpAdd;
 11.1357 -        return 0;
 11.1358 -    /* FIXME case SDL_BLENDMODE_MOD: */
 11.1359 -#endif
 11.1360 -        return 0;
 11.1361 -    default:
 11.1362 -        SDL_Unsupported();
 11.1363 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.1364 -        if(data->use_xrender) {
 11.1365 -            renderer->blendMode = SDL_BLENDMODE_BLEND;
 11.1366 -            data->blend_op = PictOpOver;
 11.1367 -        }
 11.1368 -        else
 11.1369 -#endif
 11.1370 -        {
 11.1371 -            renderer->blendMode = SDL_BLENDMODE_NONE;
 11.1372 -        }
 11.1373 -        return -1;
 11.1374 -    }
 11.1375 -}
 11.1376 -
 11.1377 -static Uint32
 11.1378 -renderdrawcolor(SDL_Renderer * renderer, int premult)
 11.1379 -{
 11.1380 -    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
 11.1381 -    Uint8 r = renderer->r;
 11.1382 -    Uint8 g = renderer->g;
 11.1383 -    Uint8 b = renderer->b;
 11.1384 -    Uint8 a = renderer->a;
 11.1385 -    if (premult)
 11.1386 -        return SDL_MapRGBA(&data->format, ((int) r * (int) a) / 255,
 11.1387 -                           ((int) g * (int) a) / 255,
 11.1388 -                           ((int) b * (int) a) / 255, 255);
 11.1389 -    else
 11.1390 -        return SDL_MapRGBA(&data->format, r, g, b, a);
 11.1391 -}
 11.1392 -
 11.1393 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.1394 -static XRenderColor
 11.1395 -xrenderdrawcolor(SDL_Renderer *renderer)
 11.1396 -{
 11.1397 -    XRenderColor xrender_color;
 11.1398 -    if(renderer->blendMode == SDL_BLENDMODE_NONE) {
 11.1399 -        xrender_color =
 11.1400 -            SDLColorToXRenderColor(renderer->r, renderer->g, renderer->b, 0xFF);
 11.1401 -    }
 11.1402 -    else {
 11.1403 -        xrender_color =
 11.1404 -            SDLColorToXRenderColor(renderer->r, renderer->g, renderer->b, renderer->a);
 11.1405 -    }
 11.1406 -    return xrender_color;
 11.1407 -}
 11.1408 -#endif
 11.1409 -
 11.1410 -static int
 11.1411 -X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
 11.1412 -                     int count)
 11.1413 -{
 11.1414 -    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
 11.1415 -    SDL_Window *window = renderer->window;
 11.1416 -    XPoint *xpoints, *xpoint;
 11.1417 -    int i, xcount;
 11.1418 -    SDL_Rect clip;
 11.1419 -
 11.1420 -    clip.x = 0;
 11.1421 -    clip.y = 0;
 11.1422 -    clip.w = window->w;
 11.1423 -    clip.h = window->h;
 11.1424 -    if (data->makedirty) {
 11.1425 -        SDL_Rect rect;
 11.1426 -
 11.1427 -        /* Get the smallest rectangle that contains everything */
 11.1428 -        rect.x = 0;
 11.1429 -        rect.y = 0;
 11.1430 -        rect.w = window->w;
 11.1431 -        rect.h = window->h;
 11.1432 -        if (!SDL_EnclosePoints(points, count, &rect, &rect)) {
 11.1433 -            /* Nothing to draw */
 11.1434 -            return 0;
 11.1435 -        }
 11.1436 -        SDL_AddDirtyRect(&data->dirty, &rect);
 11.1437 -    }
 11.1438 -    {
 11.1439 -        xpoint = xpoints = SDL_stack_alloc(XPoint, count);
 11.1440 -        xcount = 0;
 11.1441 -        for (i = 0; i < count; ++i) {
 11.1442 -            int x = points[i].x;
 11.1443 -            int y = points[i].y;
 11.1444 -            if (x < 0 || x >= window->w || y < 0 || y >= window->h) {
 11.1445 -                continue;
 11.1446 -            }
 11.1447 -            xpoint->x = (short)x;
 11.1448 -            xpoint->y = (short)y;
 11.1449 -            ++xpoint;
 11.1450 -            ++xcount;
 11.1451 -        }
 11.1452 -
 11.1453 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.1454 -        if (data->use_xrender &&
 11.1455 -            (renderer->blendMode != SDL_BLENDMODE_NONE) &&
 11.1456 -            !(renderer->a == 0xFF &&
 11.1457 -              renderer->blendMode != SDL_BLENDMODE_ADD &&
 11.1458 -              renderer->blendMode != SDL_BLENDMODE_MOD))
 11.1459 -        {
 11.1460 -            XSetForeground(data->display, data->stencil_gc, 0);
 11.1461 -#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
 11.1462 -            if (data->use_xdamage)
 11.1463 -            {
 11.1464 -                /* Update only those parts which were changed
 11.1465 -                * in the previous drawing operation */
 11.1466 -                XFixesSetGCClipRegion(data->display, data->stencil_gc,
 11.1467 -                                      0, 0, data->stencil_parts);
 11.1468 -            }
 11.1469 -#endif
 11.1470 -            XFillRectangle(data->display, data->stencil, data->stencil_gc,
 11.1471 -                           0, 0, window->w, window->h);
 11.1472 -#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
 11.1473 -            if (data->use_xdamage)
 11.1474 -            {
 11.1475 -                XFixesSetGCClipRegion(data->display, data->stencil_gc, 0, 0, None);
 11.1476 -            }
 11.1477 -#endif
 11.1478 -            XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF);
 11.1479 -
 11.1480 -            XDrawPoints(data->display, data->stencil, data->stencil_gc, xpoints, xcount,
 11.1481 -                        CoordModeOrigin);
 11.1482 -#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
 11.1483 -            if (data->use_xdamage)
 11.1484 -            {
 11.1485 -                /* Store the damaged region in stencil_parts */
 11.1486 -                XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts);
 11.1487 -            }
 11.1488 -#endif
 11.1489 -        }
 11.1490 -#endif
 11.1491 -    }
 11.1492 -
 11.1493 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.1494 -    if (data->use_xrender &&
 11.1495 -            (renderer->blendMode != SDL_BLENDMODE_NONE) &&
 11.1496 -            !(renderer->a == 0xFF &&
 11.1497 -              renderer->blendMode != SDL_BLENDMODE_ADD &&
 11.1498 -              renderer->blendMode != SDL_BLENDMODE_MOD))
 11.1499 -    {
 11.1500 -        XRenderColor foreground;
 11.1501 -        foreground = xrenderdrawcolor(renderer);
 11.1502 -
 11.1503 -        XRenderFillRectangle(data->display, PictOpSrc, data->brush_pict,
 11.1504 -                             &foreground, 0, 0, 1, 1);
 11.1505 -#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
 11.1506 -        if (data->use_xdamage)
 11.1507 -        {
 11.1508 -            /* Update only those parts which drawn
 11.1509 -             * to in the current drawing operation */
 11.1510 -            XFixesSetPictureClipRegion(data->display, data->drawable_pict,
 11.1511 -                                       0, 0, data->stencil_parts);
 11.1512 -        }
 11.1513 -#endif
 11.1514 -        XRenderComposite(data->display, data->blend_op, data->brush_pict,
 11.1515 -                         data->stencil_pict, data->drawable_pict,
 11.1516 -                         0, 0, 0, 0, 0, 0, window->w, window->h);
 11.1517 -#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
 11.1518 -        if (data->use_xdamage)
 11.1519 -        {
 11.1520 -            XFixesSetPictureClipRegion(data->display, data->drawable_pict, 0, 0, None);
 11.1521 -        }
 11.1522 -#endif
 11.1523 -    }
 11.1524 -    else
 11.1525 -#endif
 11.1526 -    {
 11.1527 -        unsigned long foreground = renderdrawcolor(renderer, 1);
 11.1528 -        XSetForeground(data->display, data->gc, foreground);
 11.1529 -
 11.1530 -
 11.1531 -        if (xcount > 0) {
 11.1532 -            XDrawPoints(data->display, data->drawable, data->gc, xpoints, xcount,
 11.1533 -                        CoordModeOrigin);
 11.1534 -        }
 11.1535 -    }
 11.1536 -
 11.1537 -    SDL_stack_free(xpoints);
 11.1538 -
 11.1539 -    return 0;
 11.1540 -}
 11.1541 -
 11.1542 -static int
 11.1543 -X11_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
 11.1544 -                    int count)
 11.1545 -{
 11.1546 -    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
 11.1547 -    SDL_Window *window = renderer->window;
 11.1548 -    SDL_Rect clip;
 11.1549 -    unsigned long foreground;
 11.1550 -    XPoint *xpoints, *xpoint;
 11.1551 -    int i, xcount;
 11.1552 -    int minx, miny;
 11.1553 -    int maxx, maxy;
 11.1554 -
 11.1555 -    clip.x = 0;
 11.1556 -    clip.y = 0;
 11.1557 -    clip.w = window->w;
 11.1558 -    clip.h = window->h;
 11.1559 -    {
 11.1560 -        Pixmap drawable;
 11.1561 -        GC gc;
 11.1562 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.1563 -       if (data->use_xrender &&
 11.1564 -            (renderer->blendMode != SDL_BLENDMODE_NONE) &&
 11.1565 -            !(renderer->a == 0xFF &&
 11.1566 -              renderer->blendMode != SDL_BLENDMODE_ADD &&
 11.1567 -              renderer->blendMode != SDL_BLENDMODE_MOD))
 11.1568 -       { 
 11.1569 -            drawable = data->stencil;
 11.1570 -            gc = data->stencil_gc;
 11.1571 -
 11.1572 -            XSetForeground(data->display, data->stencil_gc, 0);
 11.1573 -#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
 11.1574 -            if (data->use_xdamage)
 11.1575 -                XFixesSetGCClipRegion(data->display, data->stencil_gc,
 11.1576 -                                      0, 0, data->stencil_parts);
 11.1577 -#endif
 11.1578 -            XFillRectangle(data->display, data->stencil, data->stencil_gc,
 11.1579 -                           0, 0, window->w, window->h);
 11.1580 -#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
 11.1581 -            if (data->use_xdamage)
 11.1582 -                XFixesSetGCClipRegion(data->display, data->stencil_gc,
 11.1583 -                                      0, 0, None);
 11.1584 -#endif
 11.1585 -            XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF);
 11.1586 -        }
 11.1587 -        else
 11.1588 -#endif
 11.1589 -        {
 11.1590 -            drawable = data->drawable;
 11.1591 -            gc = data->gc;
 11.1592 -        }
 11.1593 -
 11.1594 -        foreground = renderdrawcolor(renderer, 1);
 11.1595 -        XSetForeground(data->display, data->gc, foreground);
 11.1596 -
 11.1597 -        xpoint = xpoints = SDL_stack_alloc(XPoint, count);
 11.1598 -        xcount = 0;
 11.1599 -        minx = INT_MAX;
 11.1600 -        miny = INT_MAX;
 11.1601 -        maxx = INT_MIN;
 11.1602 -        maxy = INT_MIN;
 11.1603 -        for (i = 0; i < count; ++i) {
 11.1604 -            int x = points[i].x;
 11.1605 -            int y = points[i].y;
 11.1606 -
 11.1607 -            /* If the point is inside the window, add it to the list */
 11.1608 -            if (x >= 0 && x < window->w && y >= 0 && y < window->h) {
 11.1609 -                if (x < minx) {
 11.1610 -                    minx = x;
 11.1611 -                } else if (x > maxx) {
 11.1612 -                    maxx = x;
 11.1613 -                }
 11.1614 -                if (y < miny) {
 11.1615 -                    miny = y;
 11.1616 -                } else if (y > maxy) {
 11.1617 -                    maxy = y;
 11.1618 -                }
 11.1619 -                xpoint->x = (short)x;
 11.1620 -                xpoint->y = (short)y;
 11.1621 -                ++xpoint;
 11.1622 -                ++xcount;
 11.1623 -                continue;
 11.1624 -            }
 11.1625 -
 11.1626 -            /* We need to clip the line segments joined by this point */
 11.1627 -            if (xcount > 0) {
 11.1628 -                int x1 = xpoint[-1].x;
 11.1629 -                int y1 = xpoint[-1].y;
 11.1630 -                int x2 = x;
 11.1631 -                int y2 = y;
 11.1632 -                if (SDL_IntersectRectAndLine(&clip, &x1, &y1, &x2, &y2)) {
 11.1633 -                    if (x2 < minx) {
 11.1634 -                        minx = x2;
 11.1635 -                    } else if (x2 > maxx) {
 11.1636 -                        maxx = x2;
 11.1637 -                    }
 11.1638 -                    if (y2 < miny) {
 11.1639 -                        miny = y2;
 11.1640 -                    } else if (y2 > maxy) {
 11.1641 -                        maxy = y2;
 11.1642 -                    }
 11.1643 -                    xpoint->x = (short)x2;
 11.1644 -                    xpoint->y = (short)y2;
 11.1645 -                    ++xpoint;
 11.1646 -                    ++xcount;
 11.1647 -                }
 11.1648 -                XDrawLines(data->display, drawable, gc,
 11.1649 -                           xpoints, xcount, CoordModeOrigin);
 11.1650 -                if (xpoints[0].x != x2 || xpoints[0].y != y2) {
 11.1651 -                    XDrawPoint(data->display, drawable, gc, x2, y2);
 11.1652 -                }
 11.1653 -                if (data->makedirty) {
 11.1654 -                    SDL_Rect rect;
 11.1655 -
 11.1656 -                    rect.x = minx;
 11.1657 -                    rect.y = miny;
 11.1658 -                    rect.w = (maxx - minx) + 1;
 11.1659 -                    rect.h = (maxy - miny) + 1;
 11.1660 -                    SDL_AddDirtyRect(&data->dirty, &rect);
 11.1661 -                }
 11.1662 -                xpoint = xpoints;
 11.1663 -                xcount = 0;
 11.1664 -                minx = INT_MAX;
 11.1665 -                miny = INT_MAX;
 11.1666 -                maxx = INT_MIN;
 11.1667 -                maxy = INT_MIN;
 11.1668 -            }
 11.1669 -            if (i < (count-1)) {
 11.1670 -                int x1 = x;
 11.1671 -                int y1 = y;
 11.1672 -                int x2 = points[i+1].x;
 11.1673 -                int y2 = points[i+1].y;
 11.1674 -                if (SDL_IntersectRectAndLine(&clip, &x1, &y1, &x2, &y2)) {
 11.1675 -                    if (x1 < minx) {
 11.1676 -                        minx = x1;
 11.1677 -                    } else if (x1 > maxx) {
 11.1678 -                        maxx = x1;
 11.1679 -                    }
 11.1680 -                    if (y1 < miny) {
 11.1681 -                        miny = y1;
 11.1682 -                    } else if (y1 > maxy) {
 11.1683 -                        maxy = y1;
 11.1684 -                    }
 11.1685 -                    xpoint->x = (short)x1;
 11.1686 -                    xpoint->y = (short)y1;
 11.1687 -                    ++xpoint;
 11.1688 -                    ++xcount;
 11.1689 -                }
 11.1690 -            }
 11.1691 -        }
 11.1692 -        if (xcount > 1) {
 11.1693 -            int x2 = xpoint[-1].x;
 11.1694 -            int y2 = xpoint[-1].y;
 11.1695 -            XDrawLines(data->display, drawable, gc, xpoints, xcount,
 11.1696 -                       CoordModeOrigin);
 11.1697 -            if (xpoints[0].x != x2 || xpoints[0].y != y2) {
 11.1698 -                XDrawPoint(data->display, drawable, gc, x2, y2);
 11.1699 -            }
 11.1700 -            if (data->makedirty) {
 11.1701 -                SDL_Rect rect;
 11.1702 -
 11.1703 -                rect.x = minx;
 11.1704 -                rect.y = miny;
 11.1705 -                rect.w = (maxx - minx) + 1;
 11.1706 -                rect.h = (maxy - miny) + 1;
 11.1707 -                SDL_AddDirtyRect(&data->dirty, &rect);
 11.1708 -            }
 11.1709 -        }
 11.1710 -    }
 11.1711 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.1712 -    if (data->use_xrender &&
 11.1713 -            (renderer->blendMode != SDL_BLENDMODE_NONE) &&
 11.1714 -            !(renderer->a == 0xFF &&
 11.1715 -              renderer->blendMode != SDL_BLENDMODE_ADD &&
 11.1716 -              renderer->blendMode != SDL_BLENDMODE_MOD))
 11.1717 -    {
 11.1718 -        XRenderColor xrforeground = xrenderdrawcolor(renderer);
 11.1719 -        XRenderFillRectangle(data->display, PictOpSrc, data->brush_pict,
 11.1720 -                             &xrforeground, 0, 0, 1, 1);
 11.1721 -#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
 11.1722 -        if (data->use_xdamage)
 11.1723 -        {
 11.1724 -            XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts);
 11.1725 -
 11.1726 -            XFixesSetPictureClipRegion(data->display, data->drawable_pict,
 11.1727 -                                       0, 0, data->stencil_parts);
 11.1728 -        }
 11.1729 -#endif
 11.1730 -        XRenderComposite(data->display, data->blend_op, data->brush_pict,
 11.1731 -                         data->stencil_pict, data->drawable_pict,
 11.1732 -                         0, 0, 0, 0, 0, 0, window->w, window->h);
 11.1733 -#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
 11.1734 -        if (data->use_xdamage)
 11.1735 -            XFixesSetPictureClipRegion(data->display, data->drawable_pict,
 11.1736 -                                       0, 0, None);
 11.1737 -#endif
 11.1738 -    }
 11.1739 -#endif
 11.1740 -    SDL_stack_free(xpoints);
 11.1741 -
 11.1742 -    return 0;
 11.1743 -}
 11.1744 -
 11.1745 -static int
 11.1746 -X11_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
 11.1747 -{
 11.1748 -    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
 11.1749 -    SDL_Window *window = renderer->window;
 11.1750 -    SDL_Rect clip, rect;
 11.1751 -    int i, xcount;
 11.1752 -    XRectangle *xrects, *xrect;
 11.1753 -    xrect = xrects = SDL_stack_alloc(XRectangle, count);
 11.1754 -    xcount = 0;
 11.1755 -    
 11.1756 -    clip.x = 0;
 11.1757 -    clip.y = 0;
 11.1758 -    clip.w = window->w;
 11.1759 -    clip.h = window->h;
 11.1760 -    {
 11.1761 -
 11.1762 -        for (i = 0; i < count; ++i) {
 11.1763 -            if (!SDL_IntersectRect(rects[i], &clip, &rect)) {
 11.1764 -                continue;
 11.1765 -            }
 11.1766 -
 11.1767 -            xrect->x = (short)rect.x;
 11.1768 -            xrect->y = (short)rect.y;
 11.1769 -            xrect->width = (unsigned short)rect.w - 1;
 11.1770 -            xrect->height = (unsigned short)rect.h - 1;
 11.1771 -            ++xrect;
 11.1772 -            ++xcount;
 11.1773 -
 11.1774 -            if (data->makedirty) {
 11.1775 -                SDL_AddDirtyRect(&data->dirty, &rect);
 11.1776 -            }
 11.1777 -        }
 11.1778 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.1779 -        if (data->use_xrender &&
 11.1780 -            (renderer->blendMode != SDL_BLENDMODE_NONE) &&
 11.1781 -            !(renderer->a == 0xFF &&
 11.1782 -              renderer->blendMode != SDL_BLENDMODE_ADD &&
 11.1783 -              renderer->blendMode != SDL_BLENDMODE_MOD))
 11.1784 -        {
 11.1785 -            XSetForeground(data->display, data->stencil_gc, 0);
 11.1786 -#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
 11.1787 -            if (data->use_xdamage)
 11.1788 -                XFixesSetGCClipRegion(data->display, data->stencil_gc,
 11.1789 -                                      0, 0, data->stencil_parts);
 11.1790 -#endif
 11.1791 -            XFillRectangle(data->display, data->stencil, data->stencil_gc,
 11.1792 -                           0, 0, window->w, window->h);
 11.1793 -#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
 11.1794 -            if (data->use_xdamage)
 11.1795 -                XFixesSetGCClipRegion(data->display, data->stencil_gc,
 11.1796 -                                      0, 0, None);
 11.1797 -#endif
 11.1798 -            XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF);
 11.1799 -
 11.1800 -            XDrawRectangles(data->display, data->stencil, data->stencil_gc, xrects, xcount);
 11.1801 -
 11.1802 -#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
 11.1803 -            if (data->use_xdamage)
 11.1804 -                XDamageSubtract(data->display, data->stencil_damage,
 11.1805 -                                None, data->stencil_parts);
 11.1806 -#endif
 11.1807 -        }
 11.1808 -#endif
 11.1809 -    }
 11.1810 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.1811 -    if (data->use_xrender &&
 11.1812 -            (renderer->blendMode != SDL_BLENDMODE_NONE) &&
 11.1813 -            !(renderer->a == 0xFF &&
 11.1814 -              renderer->blendMode != SDL_BLENDMODE_ADD &&
 11.1815 -              renderer->blendMode != SDL_BLENDMODE_MOD))
 11.1816 -    {
 11.1817 -        XRenderColor foreground;
 11.1818 -        foreground = xrenderdrawcolor(renderer);
 11.1819 -        XRenderFillRectangle(data->display, PictOpSrc, data->brush_pict,
 11.1820 -                             &foreground, 0, 0, 1, 1);
 11.1821 -#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
 11.1822 -        if (data->use_xdamage)
 11.1823 -            XFixesSetPictureClipRegion(data->display, data->drawable_pict,
 11.1824 -                                       0, 0, data->stencil_parts);
 11.1825 -#endif
 11.1826 -        XRenderComposite(data->display, data->blend_op, data->brush_pict,
 11.1827 -                         data->stencil_pict, data->drawable_pict,
 11.1828 -                         0, 0, 0, 0, 0, 0, window->w, window->h);
 11.1829 -#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
 11.1830 -        if (data->use_xdamage)
 11.1831 -            XFixesSetPictureClipRegion(data->display, data->drawable_pict,
 11.1832 -                                       0, 0, None);
 11.1833 -#endif
 11.1834 -    }
 11.1835 -    else
 11.1836 -#endif
 11.1837 -    {
 11.1838 -        unsigned long foreground;
 11.1839 -        
 11.1840 -        foreground = renderdrawcolor(renderer, 1);
 11.1841 -        XSetForeground(data->display, data->gc, foreground);
 11.1842 -    
 11.1843 -        if (xcount > 0) {
 11.1844 -            XDrawRectangles(data->display, data->drawable, data->gc,
 11.1845 -                            xrects, xcount);
 11.1846 -        }
 11.1847 -    }
 11.1848 -    SDL_stack_free(xrects);
 11.1849 -
 11.1850 -    return 0;
 11.1851 -}
 11.1852 -
 11.1853 -static int
 11.1854 -X11_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
 11.1855 -{
 11.1856 -    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
 11.1857 -    SDL_Window *window = renderer->window;
 11.1858 -    SDL_Rect clip, rect;
 11.1859 -    
 11.1860 -    clip.x = 0;
 11.1861 -    clip.y = 0;
 11.1862 -    clip.w = window->w;
 11.1863 -    clip.h = window->h;
 11.1864 -    
 11.1865 -    int i, xcount;
 11.1866 -    XRectangle *xrects, *xrect;
 11.1867 -    xrect = xrects = SDL_stack_alloc(XRectangle, count);
 11.1868 -    xcount = 0;
 11.1869 -    for (i = 0; i < count; ++i) {
 11.1870 -        if (!SDL_IntersectRect(rects[i], &clip, &rect)) {
 11.1871 -            continue;
 11.1872 -        }
 11.1873 -
 11.1874 -        xrect->x = (short)rect.x;
 11.1875 -        xrect->y = (short)rect.y;
 11.1876 -        xrect->width = (unsigned short)rect.w;
 11.1877 -        xrect->height = (unsigned short)rect.h;
 11.1878 -        ++xrect;
 11.1879 -        ++xcount;
 11.1880 -
 11.1881 -        if (data->makedirty) {
 11.1882 -            SDL_AddDirtyRect(&data->dirty, &rect);
 11.1883 -        }
 11.1884 -    }
 11.1885 -
 11.1886 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.1887 -    if (data->use_xrender) {
 11.1888 -        XRenderColor foreground;
 11.1889 -        foreground = xrenderdrawcolor(renderer);
 11.1890 -        if (xcount == 1) {
 11.1891 -            XRenderFillRectangle(data->display, data->blend_op, data->drawable_pict,
 11.1892 -                                 &foreground, xrects[0].x, xrects[0].y,
 11.1893 -                                 xrects[0].width, xrects[0].height);
 11.1894 -        }
 11.1895 -        else if (xcount > 1) {
 11.1896 -            XRenderFillRectangles(data->display, data->blend_op, data->drawable_pict,
 11.1897 -                                  &foreground, xrects, xcount);
 11.1898 -        }
 11.1899 -    }
 11.1900 -    else
 11.1901 -#endif
 11.1902 -    {
 11.1903 -        unsigned long foreground;
 11.1904 -        
 11.1905 -        foreground = renderdrawcolor(renderer, 1);
 11.1906 -        XSetForeground(data->display, data->gc, foreground);
 11.1907 - 
 11.1908 -        XFillRectangles(data->display, data->drawable, data->gc,
 11.1909 -                        xrects, xcount);
 11.1910 -    }
 11.1911 -
 11.1912 -    SDL_stack_free(xrects);
 11.1913 -    return 0;
 11.1914 -}
 11.1915 -
 11.1916 -static int
 11.1917 -X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
 11.1918 -               const SDL_Rect * srcrect, const SDL_Rect * dstrect)
 11.1919 -{
 11.1920 -    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
 11.1921 -    X11_TextureData *texturedata = (X11_TextureData *) texture->driverdata;
 11.1922 -
 11.1923 -    if (data->makedirty) {
 11.1924 -        SDL_AddDirtyRect(&data->dirty, dstrect);
 11.1925 -    }
 11.1926 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.1927 -    if (data->use_xrender && !texturedata->yuv) {
 11.1928 -        if(texture->access == SDL_TEXTUREACCESS_STREAMING) {
 11.1929 -#ifndef NO_SHARED_MEMORY
 11.1930 -            if(texturedata->shminfo.shmaddr) {
 11.1931 -                XShmPutImage(data->display, texturedata->pixmap, texturedata->gc,
 11.1932 -                             texturedata->image, srcrect->x, srcrect->y,
 11.1933 -                             srcrect->x, srcrect->y, srcrect->w, srcrect->h,
 11.1934 -                             False);
 11.1935 -            }
 11.1936 -            else
 11.1937 -#endif
 11.1938 -            if (texturedata->pixels) {
 11.1939 -                XPutImage(data->display, texturedata->pixmap, texturedata->gc,
 11.1940 -                          texturedata->image, srcrect->x, srcrect->y, srcrect->x,
 11.1941 -                          srcrect->y, srcrect->w, srcrect->h);
 11.1942 -            }
 11.1943 -            XSync(data->display, False);
 11.1944 -        }
 11.1945 -        Picture src, mask;
 11.1946 -        XRenderPictureAttributes attr;
 11.1947 -        const SDL_Rect *mrect;
 11.1948 -        /* mrect is the rectangular area of the mask
 11.1949 -         * picture that is aligned with the source. */
 11.1950 -
 11.1951 -        if (texture->modMode == SDL_TEXTUREMODULATE_NONE) {
 11.1952 -            src = texturedata->picture;
 11.1953 -        }
 11.1954 -        else {
 11.1955 -            src = texturedata->modulated_picture;
 11.1956 -        }
 11.1957 -
 11.1958 -        if(texture->blendMode == SDL_BLENDMODE_NONE) 
 11.1959 -        {
 11.1960 -            mask = None;
 11.1961 -            mrect = srcrect;
 11.1962 -        }
 11.1963 -        else if (texture->blendMode == SDL_BLENDMODE_MOD)
 11.1964 -        {
 11.1965 -            /* SDL_BLENDMODE_MOD requires a temporary buffer
 11.1966 -             * i.e. stencil_pict */
 11.1967 -            mask = data->stencil_pict;
 11.1968 -            mrect = dstrect;
 11.1969 -        }
 11.1970 -        else
 11.1971 -        {
 11.1972 -            /* This trick allows on-the-fly multiplication
 11.1973 -             * of the src color channels with it's alpha
 11.1974 -             * channel. */
 11.1975 -            mask = src;
 11.1976 -            mrect = srcrect;
 11.1977 -        }
 11.1978 -
 11.1979 -        if(srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
 11.1980 -            if (texture->blendMode == SDL_BLENDMODE_MOD) {
 11.1981 -                XRenderComposite(data->display, PictOpSrc, data->drawable_pict,
 11.1982 -                             src, data->stencil_pict,
 11.1983 -                             dstrect->x, dstrect->y, srcrect->x, srcrect->y,
 11.1984 -                             dstrect->x, dstrect->y, dstrect->w, dstrect->h);
 11.1985 -                attr.component_alpha = True;
 11.1986 -                XRenderChangePicture(data->display, data->stencil_pict,
 11.1987 -                                     CPComponentAlpha, &attr);
 11.1988 -            }
 11.1989 -            XRenderComposite(data->display, texturedata->blend_op,
 11.1990 -                            src, mask, data->drawable_pict, srcrect->x, srcrect->y,
 11.1991 -                            mrect->x, mrect->y, dstrect->x, dstrect->y,
 11.1992 -                            dstrect->w, dstrect->h);
 11.1993 -        } else {
 11.1994 -            /* The transformation is from the dst to src picture. */
 11.1995 -            double xscale = ((double) srcrect->w) / dstrect->w;
 11.1996 -            double yscale = ((double) srcrect->h) / dstrect->h;
 11.1997 -            XTransform xform = {{
 11.1998 -                    {XDoubleToFixed(xscale), XDoubleToFixed(0), XDoubleToFixed(0)},
 11.1999 -                    {XDoubleToFixed(0), XDoubleToFixed(yscale), XDoubleToFixed(0)},
 11.2000 -                    {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(1)}}};
 11.2001 -            XRenderSetPictureTransform(data->display, src, &xform);
 11.2002 -            
 11.2003 -            /* Black magic follows. */
 11.2004 -            if (texture->blendMode == SDL_BLENDMODE_MOD) {
 11.2005 -                /* Copy the dst to a temp buffer. */
 11.2006 -                XRenderComposite(data->display, PictOpSrc, data->drawable_pict,
 11.2007 -                             src, data->stencil_pict,
 11.2008 -                             dstrect->x, dstrect->y, srcrect->x, srcrect->y,
 11.2009 -                             dstrect->x, dstrect->y, dstrect->w, dstrect->h);
 11.2010 -                /* Set the compnent alpha flag on the temp buffer. */
 11.2011 -                attr.component_alpha = True;
 11.2012 -                XRenderChangePicture(data->display, data->stencil_pict,
 11.2013 -                                     CPComponentAlpha, &attr);
 11.2014 -            }
 11.2015 -
 11.2016 -            /* Set the picture filter only if a scaling mode is set. */
 11.2017 -            if (texture->scaleMode != SDL_SCALEMODE_NONE) {
 11.2018 -                XRenderSetPictureFilter(data->display, src,
 11.2019 -                                        texturedata->filter, 0, 0);
 11.2020 -            }
 11.2021 -
 11.2022 -            XRenderComposite(data->display, texturedata->blend_op,
 11.2023 -                             src, mask, data->drawable_pict,
 11.2024 -                             srcrect->x, srcrect->y, mrect->x, mrect->y,
 11.2025 -                             dstrect->x, dstrect->y, dstrect->w, dstrect->h);
 11.2026 -           /* Set the texture transformation back to the identity matrix. */ 
 11.2027 -            XTransform identity = {{
 11.2028 -                    {XDoubleToFixed(1), XDoubleToFixed(0), XDoubleToFixed(0)},
 11.2029 -                    {XDoubleToFixed(0), XDoubleToFixed(1), XDoubleToFixed(0)},
 11.2030 -                    {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(1)}}};
 11.2031 -            XRenderSetPictureTransform(data->display, src, &identity);
 11.2032 -        }
 11.2033 -        
 11.2034 -        /* Reset the component alpha flag only when
 11.2035 -         * the blending mode is SDL_BLENDMODE_MOD. */
 11.2036 -        if (renderer->blendMode == SDL_BLENDMODE_MOD) {
 11.2037 -            attr.component_alpha = False;
 11.2038 -            XRenderChangePicture(data->display, data->stencil_pict,
 11.2039 -                                 CPComponentAlpha, &attr);
 11.2040 -        }
 11.2041 -    }
 11.2042 -    else
 11.2043 -#endif
 11.2044 -    {
 11.2045 -        if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
 11.2046 -#ifndef NO_SHARED_MEMORY
 11.2047 -            if (texturedata->shminfo.shmaddr) {
 11.2048 -                XShmPutImage(data->display, data->drawable, data->gc,
 11.2049 -                             texturedata->image, srcrect->x, srcrect->y,
 11.2050 -                             dstrect->x, dstrect->y, srcrect->w, srcrect->h,
 11.2051 -                             False);
 11.2052 -            } else
 11.2053 -#endif
 11.2054 -            if (texturedata->pixels) {
 11.2055 -                XPutImage(data->display, data->drawable, data->gc,
 11.2056 -                          texturedata->image, srcrect->x, srcrect->y, dstrect->x,
 11.2057 -                          dstrect->y, srcrect->w, srcrect->h);
 11.2058 -            } else {
 11.2059 -                XCopyArea(data->display, texturedata->pixmap, data->drawable,
 11.2060 -                          data->gc, srcrect->x, srcrect->y, dstrect->w,
 11.2061 -                          dstrect->h, dstrect->x, dstrect->y);
 11.2062 -            }
 11.2063 -        } else if (texturedata->yuv
 11.2064 -                   || texture->access == SDL_TEXTUREACCESS_STREAMING) {
 11.2065 -            SDL_Surface src, dst;
 11.2066 -            SDL_PixelFormat fmt;
 11.2067 -            SDL_Rect rect;
 11.2068 -            XImage *image = texturedata->scaling_image;
 11.2069 -
 11.2070 -            if (!image) {
 11.2071 -                void *pixels;
 11.2072 -                int pitch;
 11.2073 -
 11.2074 -                pitch = dstrect->w * SDL_BYTESPERPIXEL(texturedata->format);
 11.2075 -                pixels = SDL_malloc(dstrect->h * pitch);
 11.2076 -                if (!pixels) {
 11.2077 -                    SDL_OutOfMemory();
 11.2078 -                    return -1;
 11.2079 -                }
 11.2080 -
 11.2081 -                image =
 11.2082 -                    XCreateImage(data->display, data->visual, data->depth,
 11.2083 -                                 ZPixmap, 0, pixels, dstrect->w, dstrect->h,
 11.2084 -                                 SDL_BYTESPERPIXEL(texturedata->format) * 8,
 11.2085 -                                 pitch);
 11.2086 -                if (!image) {
 11.2087 -                    SDL_SetError("XCreateImage() failed");
 11.2088 -                    return -1;
 11.2089 -                }
 11.2090 -                texturedata->scaling_image = image;
 11.2091 -
 11.2092 -            } else if (image->width != dstrect->w || image->height != dstrect->h
 11.2093 -                       || !image->data) {
 11.2094 -                image->width = dstrect->w;
 11.2095 -                image->height = dstrect->h;
 11.2096 -                image->bytes_per_line =
 11.2097 -                    image->width * SDL_BYTESPERPIXEL(texturedata->format);
 11.2098 -                image->data =
 11.2099 -                    (char *) SDL_realloc(image->data,
 11.2100 -                                         image->height * image->bytes_per_line);
 11.2101 -                if (!image->data) {
 11.2102 -                    SDL_OutOfMemory();
 11.2103 -                    return -1;
 11.2104 -                }
 11.2105 -            }
 11.2106 -
 11.2107 -            /* Set up fake surfaces for SDL_SoftStretch() */
 11.2108 -            SDL_zero(src);
 11.2109 -            src.format = &fmt;
 11.2110 -            src.w = texture->w;
 11.2111 -            src.h = texture->h;
 11.2112 -#ifndef NO_SHARED_MEMORY
 11.2113 -            if (texturedata->shminfo.shmaddr) {
 11.2114 -                src.pixels = texturedata->shminfo.shmaddr;
 11.2115 -            } else
 11.2116 -#endif
 11.2117 -                src.pixels = texturedata->pixels;
 11.2118 -            src.pitch = texturedata->pitch;
 11.2119 -
 11.2120 -            SDL_zero(dst);
 11.2121 -            dst.format = &fmt;
 11.2122 -            dst.w = image->width;
 11.2123 -            dst.h = image->height;
 11.2124 -            dst.pixels = image->data;
 11.2125 -            dst.pitch = image->bytes_per_line;
 11.2126 -
 11.2127 -            fmt.BytesPerPixel = SDL_BYTESPERPIXEL(texturedata->format);
 11.2128 -
 11.2129 -            rect.x = 0;
 11.2130 -            rect.y = 0;
 11.2131 -            rect.w = dstrect->w;
 11.2132 -            rect.h = dstrect->h;
 11.2133 -            if (SDL_SoftStretch(&src, srcrect, &dst, &rect) < 0) {
 11.2134 -                return -1;
 11.2135 -            }
 11.2136 -            XPutImage(data->display, data->drawable, data->gc, image, 0, 0,
 11.2137 -                      dstrect->x, dstrect->y, dstrect->w, dstrect->h);
 11.2138 -        } else {
 11.2139 -            XCopyArea(data->display, texturedata->pixmap, data->drawable,
 11.2140 -                      data->gc, srcrect->x, srcrect->y, dstrect->w, dstrect->h,
 11.2141 -                      srcrect->x, srcrect->y);
 11.2142 -        }
 11.2143 -    }
 11.2144 -    return 0;
 11.2145 -}
 11.2146 -
 11.2147 -static int
 11.2148 -X11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
 11.2149 -                     Uint32 format, void * pixels, int pitch)
 11.2150 -{
 11.2151 -    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
 11.2152 -    SDL_Window *window = renderer->window;
 11.2153 -    SDL_VideoDisplay *display = window->display;
 11.2154 -    Uint32 screen_format = display->current_mode.format;
 11.2155 -    XImage *image;
 11.2156 -
 11.2157 -    image = XGetImage(data->display, data->drawable, rect->x, rect->y,
 11.2158 -                      rect->w, rect->h, AllPlanes, ZPixmap);
 11.2159 -
 11.2160 -    SDL_ConvertPixels(rect->w, rect->h,
 11.2161 -                      screen_format, image->data, image->bytes_per_line,
 11.2162 -                      format, pixels, pitch);
 11.2163 -
 11.2164 -    XDestroyImage(image);
 11.2165 -    return 0;
 11.2166 -}
 11.2167 -
 11.2168 -static int
 11.2169 -X11_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
 11.2170 -                      Uint32 format, const void * pixels, int pitch)
 11.2171 -{
 11.2172 -    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
 11.2173 -    SDL_Window *window = renderer->window;
 11.2174 -    SDL_VideoDisplay *display = window->display;
 11.2175 -    Uint32 screen_format = display->current_mode.format;
 11.2176 -    XImage *image;
 11.2177 -    void *image_pixels;
 11.2178 -    int image_pitch;
 11.2179 -
 11.2180 -    image_pitch = rect->w * SDL_BYTESPERPIXEL(screen_format);
 11.2181 -    image_pixels = SDL_malloc(rect->h * image_pitch);
 11.2182 -    if (!image_pixels) {
 11.2183 -        SDL_OutOfMemory();
 11.2184 -        return -1;
 11.2185 -    }
 11.2186 -
 11.2187 -    image = XCreateImage(data->display, data->visual,
 11.2188 -                         data->depth, ZPixmap, 0, image_pixels,
 11.2189 -                         rect->w, rect->h,
 11.2190 -                         SDL_BYTESPERPIXEL(screen_format) * 8,
 11.2191 -                         image_pitch);
 11.2192 -    if (!image) {
 11.2193 -        SDL_SetError("XCreateImage() failed");
 11.2194 -        return -1;
 11.2195 -    }
 11.2196 -
 11.2197 -    SDL_ConvertPixels(rect->w, rect->h,
 11.2198 -                      format, pixels, pitch,
 11.2199 -                      screen_format, image->data, image->bytes_per_line);
 11.2200 -
 11.2201 -    XPutImage(data->display, data->drawable, data->gc,
 11.2202 -              image, 0, 0, rect->x, rect->y, rect->w, rect->h);
 11.2203 -
 11.2204 -    image->data = NULL;
 11.2205 -    XDestroyImage(image);
 11.2206 -
 11.2207 -    SDL_free(image_pixels);
 11.2208 -    return 0;
 11.2209 -}
 11.2210 -
 11.2211 -static void
 11.2212 -X11_RenderPresent(SDL_Renderer * renderer)
 11.2213 -{
 11.2214 -    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
 11.2215 -    SDL_DirtyRect *dirty;
 11.2216 -
 11.2217 -    /* Send the data to the display */
 11.2218 -    if (!(renderer->info.flags & SDL_RENDERER_SINGLEBUFFER)) {
 11.2219 -        for (dirty = data->dirty.list; dirty; dirty = dirty->next) {
 11.2220 -            const SDL_Rect *rect = &dirty->rect;
 11.2221 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.2222 -            if (data->use_xrender)
 11.2223 -            {
 11.2224 -                XRenderComposite(data->display,
 11.2225 -                                 data->blend_op,
 11.2226 -                                 data->drawable_pict,
 11.2227 -                                 None,
 11.2228 -                                 data->xwindow_pict,
 11.2229 -                                 rect->x, rect->y,
 11.2230 -                                 0, 0,
 11.2231 -                                 rect->x, rect->y,
 11.2232 -                                 rect->w, rect->h);
 11.2233 -            }
 11.2234 -            else
 11.2235 -#endif
 11.2236 -            {
 11.2237 -            XCopyArea(data->display, data->drawable, data->xwindow,
 11.2238 -                      data->gc, rect->x, rect->y, rect->w, rect->h,
 11.2239 -                      rect->x, rect->y);
 11.2240 -            }
 11.2241 -        }
 11.2242 -        SDL_ClearDirtyRects(&data->dirty);
 11.2243 -    }
 11.2244 -    XSync(data->display, False);
 11.2245 -
 11.2246 -    /* Update the flipping chain, if any */
 11.2247 -    if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
 11.2248 -        data->current_pixmap = (data->current_pixmap + 1) % 2;
 11.2249 -        data->drawable = data->pixmaps[data->current_pixmap];
 11.2250 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.2251 -        data->drawable_pict = data->pixmap_picts[data->current_pixmap];
 11.2252 -#endif
 11.2253 -    } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
 11.2254 -        data->current_pixmap = (data->current_pixmap + 1) % 3;
 11.2255 -        data->drawable = data->pixmaps[data->current_pixmap];
 11.2256 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.2257 -        data->drawable_pict = data->pixmap_picts[data->current_pixmap];
 11.2258 -#endif
 11.2259 -    }
 11.2260 -}
 11.2261 -
 11.2262 -static void
 11.2263 -X11_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
 11.2264 -{
 11.2265 -    X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
 11.2266 -    X11_TextureData *data = (X11_TextureData *) texture->driverdata;
 11.2267 -
 11.2268 -    if (!data) {
 11.2269 -        return;
 11.2270 -    }
 11.2271 -    if (data->yuv) {
 11.2272 -        SDL_SW_DestroyYUVTexture(data->yuv);
 11.2273 -    }
 11.2274 -    if (data->pixmap != None) {
 11.2275 -        XFreePixmap(renderdata->display, data->pixmap);
 11.2276 -    }
 11.2277 -    if (data->image) {
 11.2278 -        data->image->data = NULL;
 11.2279 -        XDestroyImage(data->image);
 11.2280 -    }
 11.2281 -#ifndef NO_SHARED_MEMORY
 11.2282 -    if (data->shminfo.shmaddr) {
 11.2283 -        XShmDetach(renderdata->display, &data->shminfo);
 11.2284 -        XSync(renderdata->display, False);
 11.2285 -        shmdt(data->shminfo.shmaddr);
 11.2286 -        data->pixels = NULL;
 11.2287 -    }
 11.2288 -#endif
 11.2289 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.2290 -    if (renderdata->use_xrender) {
 11.2291 -        if (data->picture) {
 11.2292 -            XRenderFreePicture(renderdata->display, data->picture);
 11.2293 -        }
 11.2294 -        if (data->modulated_pixmap) {
 11.2295 -            XFreePixmap(renderdata->display, data->modulated_pixmap);
 11.2296 -        }
 11.2297 -        if (data->modulated_picture) {
 11.2298 -            XRenderFreePicture(renderdata->display, data->modulated_picture);
 11.2299 -        }
 11.2300 -    }
 11.2301 -#endif
 11.2302 -    if (data->scaling_image) {
 11.2303 -        SDL_free(data->scaling_image->data);
 11.2304 -        data->scaling_image->data = NULL;
 11.2305 -        XDestroyImage(data->scaling_image);
 11.2306 -    }
 11.2307 -    if (data->pixels) {
 11.2308 -        SDL_free(data->pixels);
 11.2309 -    }
 11.2310 -    SDL_free(data);
 11.2311 -    texture->driverdata = NULL;
 11.2312 -}
 11.2313 -
 11.2314 -static void
 11.2315 -X11_DestroyRenderer(SDL_Renderer * renderer)
 11.2316 -{
 11.2317 -    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
 11.2318 -    int i;
 11.2319 -
 11.2320 -    if (data) {
 11.2321 -        for (i = 0; i < SDL_arraysize(data->pixmaps); ++i) {
 11.2322 -            if (data->pixmaps[i] != None) {
 11.2323 -                XFreePixmap(data->display, data->pixmaps[i]);
 11.2324 -            }
 11.2325 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.2326 -            if (data->use_xrender && data->pixmap_picts[i]) {
 11.2327 -                XRenderFreePicture(data->display, data->pixmap_picts[i]);
 11.2328 -            }
 11.2329 -#endif
 11.2330 -        }
 11.2331 -        if (data->gc) {
 11.2332 -            XFreeGC(data->display, data->gc);
 11.2333 -        }
 11.2334 -#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
 11.2335 -        if (data->use_xrender) {
 11.2336 -            if (data->stencil_gc) {
 11.2337 -                XFreeGC(data->display, data->stencil_gc);
 11.2338 -            }
 11.2339 -            if (data->stencil) {
 11.2340 -                XFreePixmap(data->display, data->stencil);
 11.2341 -            }
 11.2342 -            if (data->stencil_pict) {
 11.2343 -                XRenderFreePicture(data->display, data->stencil_pict);
 11.2344 -            }
 11.2345 -            if (data->xwindow_pict) {
 11.2346 -                XRenderFreePicture(data->display, data->xwindow_pict);
 11.2347 -            }
 11.2348 -#ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
 11.2349 -            if (data->use_xdamage && data->stencil_damage) {
 11.2350 -                XDamageDestroy(data->display, data->stencil_damage);
 11.2351 -            }
 11.2352 -#endif
 11.2353 -        }
 11.2354 -#endif
 11.2355 -        SDL_FreeDirtyRects(&data->dirty);
 11.2356 -        SDL_free(data);
 11.2357 -    }
 11.2358 -    SDL_free(renderer);
 11.2359 -}
 11.2360 -
 11.2361 -#endif /* SDL_VIDEO_RENDER_X11 */
 11.2362 -
 11.2363 -/* vi: set ts=4 sw=4 expandtab: */
    12.1 --- a/src/video/x11/SDL_x11render.h	Tue Feb 01 12:01:37 2011 -0800
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,30 +0,0 @@
    12.4 -/*
    12.5 -    SDL - Simple DirectMedia Layer
    12.6 -    Copyright (C) 1997-2010 Sam Lantinga
    12.7 -
    12.8 -    This library is free software; you can redistribute it and/or
    12.9 -    modify it under the terms of the GNU Lesser General Public
   12.10 -    License as published by the Free Software Foundation; either
   12.11 -    version 2.1 of the License, or (at your option) any later version.
   12.12 -
   12.13 -    This library is distributed in the hope that it will be useful,
   12.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   12.16 -    Lesser General Public License for more details.
   12.17 -
   12.18 -    You should have received a copy of the GNU Lesser General Public
   12.19 -    License along with this library; if not, write to the Free Software
   12.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   12.21 -
   12.22 -    Sam Lantinga
   12.23 -    slouken@libsdl.org
   12.24 -*/
   12.25 -#include "SDL_config.h"
   12.26 -
   12.27 -/* SDL surface based renderer implementation */
   12.28 -
   12.29 -#if SDL_VIDEO_RENDER_X11
   12.30 -extern void X11_AddRenderDriver(_THIS);
   12.31 -#endif
   12.32 -
   12.33 -/* vi: set ts=4 sw=4 expandtab: */
    13.1 --- a/src/video/x11/SDL_x11video.c	Tue Feb 01 12:01:37 2011 -0800
    13.2 +++ b/src/video/x11/SDL_x11video.c	Mon Jan 31 22:21:29 2011 -0800
    13.3 @@ -350,10 +350,6 @@
    13.4          return -1;
    13.5      }
    13.6  
    13.7 -#if SDL_VIDEO_RENDER_X11
    13.8 -    X11_AddRenderDriver(_this);
    13.9 -#endif
   13.10 -
   13.11      if (X11_InitKeyboard(_this) != 0) {
   13.12          return -1;
   13.13      }