Starting support for Direct3D render driver. SDL-1.3
authorSam Lantinga <slouken@libsdl.org>
Sat, 08 Jul 2006 18:06:02 +0000
branchSDL-1.3
changeset 1730e70477157db9
parent 1729 0ef52d56e8bb
child 1731 875c3cf1a12c
Starting support for Direct3D render driver.
configure.in
include/SDL_config.h.in
include/SDL_config_win32.h
src/video/win32/SDL_d3drender.c
src/video/win32/SDL_d3drender.h
src/video/win32/SDL_dibrender.c
src/video/win32/SDL_dibrender.h
src/video/win32/SDL_gdirender.c
src/video/win32/SDL_gdirender.h
src/video/win32/SDL_win32video.c
src/video/win32/SDL_win32video.h
     1.1 --- a/configure.in	Fri Jul 07 10:39:33 2006 +0000
     1.2 +++ b/configure.in	Sat Jul 08 18:06:02 2006 +0000
     1.3 @@ -1861,12 +1861,6 @@
     1.4      if test x$enable_stdio_redirect != xyes; then
     1.5          EXTRA_CFLAGS="$EXTRA_CFLAGS -DNO_STDIO_REDIRECT"
     1.6      fi
     1.7 -
     1.8 -    if test x$enable_video = xyes; then
     1.9 -        AC_DEFINE(SDL_VIDEO_DRIVER_WIN32)
    1.10 -        SOURCES="$SOURCES $srcdir/src/video/win32/*.c"
    1.11 -        have_video=yes
    1.12 -    fi
    1.13  }
    1.14  
    1.15  dnl Find the DirectX includes and libraries
    1.16 @@ -1876,6 +1870,7 @@
    1.17  AC_HELP_STRING([--enable-directx], [use DirectX for Win32 audio/video [[default=yes]]]),
    1.18                    , enable_directx=yes)
    1.19      if test x$enable_directx = xyes; then
    1.20 +        AC_CHECK_HEADER(d3d9.h, have_d3d=yes)
    1.21          AC_CHECK_HEADER(dsound.h, have_dsound=yes)
    1.22          AC_CHECK_HEADER(dinput.h, use_dinput=yes)
    1.23      fi
    1.24 @@ -2298,6 +2293,24 @@
    1.25          CheckglSDL
    1.26          CheckDIRECTX
    1.27          CheckNASM
    1.28 +        # Set up files for the video library
    1.29 +        if test x$enable_video = xyes; then
    1.30 +            AC_DEFINE(SDL_VIDEO_DRIVER_WIN32)
    1.31 +            SOURCES="$SOURCES $srcdir/src/video/win32/*.c"
    1.32 +            have_video=yes
    1.33 +            AC_ARG_ENABLE(render-gdi,
    1.34 +AC_HELP_STRING([--enable-render-gdi], [enable the GDI render driver [[default=yes]]]),
    1.35 +                                , enable_render_gdi=yes)
    1.36 +            if test x$enable_render_gdi = xyes; then
    1.37 +                AC_DEFINE(SDL_VIDEO_RENDER_GDI)
    1.38 +            fi
    1.39 +            AC_ARG_ENABLE(render-d3d,
    1.40 +AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[default=yes]]]),
    1.41 +                                , enable_render_d3d=yes)
    1.42 +            if test x$enable_render_d3d = xyes -a x$have_d3d = xyes; then
    1.43 +                AC_DEFINE(SDL_VIDEO_RENDER_D3D)
    1.44 +            fi
    1.45 +        fi
    1.46          # Set up files for the audio library
    1.47          if test x$enable_audio = xyes; then
    1.48              AC_DEFINE(SDL_AUDIO_DRIVER_WAVEOUT)
     2.1 --- a/include/SDL_config.h.in	Fri Jul 07 10:39:33 2006 +0000
     2.2 +++ b/include/SDL_config.h.in	Sat Jul 08 18:06:02 2006 +0000
     2.3 @@ -291,6 +291,10 @@
     2.4  #undef SDL_VIDEO_DRIVER_X11_XV
     2.5  #undef SDL_VIDEO_DRIVER_XBIOS
     2.6  
     2.7 +#undef SDL_VIDEO_RENDER_D3D
     2.8 +#undef SDL_VIDEO_RENDER_GDI
     2.9 +#undef SDL_VIDEO_RENDER_OGL
    2.10 +
    2.11  /* Enable OpenGL support */
    2.12  #undef SDL_VIDEO_OPENGL
    2.13  #undef SDL_VIDEO_OPENGL_GLX
     3.1 --- a/include/SDL_config_win32.h	Fri Jul 07 10:39:33 2006 +0000
     3.2 +++ b/include/SDL_config_win32.h	Sat Jul 08 18:06:02 2006 +0000
     3.3 @@ -153,10 +153,14 @@
     3.4  #define SDL_VIDEO_DRIVER_DUMMY	1
     3.5  #define SDL_VIDEO_DRIVER_WIN32	1
     3.6  
     3.7 +#define SDL_VIDEO_RENDER_D3D	1
     3.8 +#define SDL_VIDEO_RENDER_GDI	1
     3.9 +
    3.10  /* Enable OpenGL support */
    3.11  #ifndef _WIN32_WCE
    3.12  #define SDL_VIDEO_OPENGL	1
    3.13  #define SDL_VIDEO_OPENGL_WGL	1
    3.14 +#define SDL_VIDEO_RENDER_OGL	1
    3.15  #endif
    3.16  
    3.17  /* Enable assembly routines (Win64 doesn't have inline asm) */
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/video/win32/SDL_d3drender.c	Sat Jul 08 18:06:02 2006 +0000
     4.3 @@ -0,0 +1,385 @@
     4.4 +/*
     4.5 +    SDL - Simple DirectMedia Layer
     4.6 +    Copyright (C) 1997-2006 Sam Lantinga
     4.7 +
     4.8 +    This library is free software; you can redistribute it and/or
     4.9 +    modify it under the terms of the GNU Lesser General Public
    4.10 +    License as published by the Free Software Foundation; either
    4.11 +    version 2.1 of the License, or (at your option) any later version.
    4.12 +
    4.13 +    This library is distributed in the hope that it will be useful,
    4.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.16 +    Lesser General Public License for more details.
    4.17 +
    4.18 +    You should have received a copy of the GNU Lesser General Public
    4.19 +    License along with this library; if not, write to the Free Software
    4.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    4.21 +
    4.22 +    Sam Lantinga
    4.23 +    slouken@libsdl.org
    4.24 +*/
    4.25 +#include "SDL_config.h"
    4.26 +
    4.27 +#if SDL_VIDEO_RENDER_D3D
    4.28 +
    4.29 +#include "SDL_win32video.h"
    4.30 +#include "../SDL_yuv_sw_c.h"
    4.31 +
    4.32 +/* Direct3D renderer implementation */
    4.33 +
    4.34 +static SDL_Renderer *SDL_D3D_CreateRenderer(SDL_Window * window,
    4.35 +                                            Uint32 flags);
    4.36 +static int SDL_D3D_CreateTexture(SDL_Renderer * renderer,
    4.37 +                                 SDL_Texture * texture);
    4.38 +static int SDL_D3D_QueryTexturePixels(SDL_Renderer * renderer,
    4.39 +                                      SDL_Texture * texture, void **pixels,
    4.40 +                                      int *pitch);
    4.41 +static int SDL_D3D_SetTexturePalette(SDL_Renderer * renderer,
    4.42 +                                     SDL_Texture * texture,
    4.43 +                                     const SDL_Color * colors, int firstcolor,
    4.44 +                                     int ncolors);
    4.45 +static int SDL_D3D_GetTexturePalette(SDL_Renderer * renderer,
    4.46 +                                     SDL_Texture * texture,
    4.47 +                                     SDL_Color * colors, int firstcolor,
    4.48 +                                     int ncolors);
    4.49 +static int SDL_D3D_UpdateTexture(SDL_Renderer * renderer,
    4.50 +                                 SDL_Texture * texture, const SDL_Rect * rect,
    4.51 +                                 const void *pixels, int pitch);
    4.52 +static int SDL_D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    4.53 +                               const SDL_Rect * rect, int markDirty,
    4.54 +                               void **pixels, int *pitch);
    4.55 +static void SDL_D3D_UnlockTexture(SDL_Renderer * renderer,
    4.56 +                                  SDL_Texture * texture);
    4.57 +static void SDL_D3D_DirtyTexture(SDL_Renderer * renderer,
    4.58 +                                 SDL_Texture * texture, int numrects,
    4.59 +                                 const SDL_Rect * rects);
    4.60 +static void SDL_D3D_SelectRenderTexture(SDL_Renderer * renderer,
    4.61 +                                        SDL_Texture * texture);
    4.62 +static int SDL_D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
    4.63 +                              Uint32 color);
    4.64 +static int SDL_D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    4.65 +                              const SDL_Rect * srcrect,
    4.66 +                              const SDL_Rect * dstrect, int blendMode,
    4.67 +                              int scaleMode);
    4.68 +static int SDL_D3D_RenderReadPixels(SDL_Renderer * renderer,
    4.69 +                                    const SDL_Rect * rect, void *pixels,
    4.70 +                                    int pitch);
    4.71 +static int SDL_D3D_RenderWritePixels(SDL_Renderer * renderer,
    4.72 +                                     const SDL_Rect * rect,
    4.73 +                                     const void *pixels, int pitch);
    4.74 +static void SDL_D3D_RenderPresent(SDL_Renderer * renderer);
    4.75 +static void SDL_D3D_DestroyTexture(SDL_Renderer * renderer,
    4.76 +                                   SDL_Texture * texture);
    4.77 +static void SDL_D3D_DestroyRenderer(SDL_Renderer * renderer);
    4.78 +
    4.79 +
    4.80 +SDL_RenderDriver SDL_D3D_RenderDriver = {
    4.81 +    SDL_D3D_CreateRenderer,
    4.82 +    {
    4.83 +     "d3d",
    4.84 +     (SDL_Renderer_PresentDiscard |
    4.85 +      SDL_Renderer_PresentCopy | SDL_Renderer_RenderTarget),
    4.86 +     (SDL_TextureBlendMode_None |
    4.87 +      SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend),
    4.88 +     (SDL_TextureScaleMode_None | SDL_TextureScaleMode_Fast),
    4.89 +     11,
    4.90 +     {
    4.91 +      SDL_PixelFormat_Index8,
    4.92 +      SDL_PixelFormat_RGB555,
    4.93 +      SDL_PixelFormat_RGB565,
    4.94 +      SDL_PixelFormat_RGB888,
    4.95 +      SDL_PixelFormat_BGR888,
    4.96 +      SDL_PixelFormat_ARGB8888,
    4.97 +      SDL_PixelFormat_RGBA8888,
    4.98 +      SDL_PixelFormat_ABGR8888,
    4.99 +      SDL_PixelFormat_BGRA8888,
   4.100 +      SDL_PixelFormat_YUY2,
   4.101 +      SDL_PixelFormat_UYVY},
   4.102 +     0,
   4.103 +     0}
   4.104 +};
   4.105 +
   4.106 +typedef struct
   4.107 +{
   4.108 +    IDirect3DDevice9 *device;
   4.109 +} SDL_D3D_RenderData;
   4.110 +
   4.111 +typedef struct
   4.112 +{
   4.113 +    SDL_SW_YUVTexture *yuv;
   4.114 +} SDL_D3D_TextureData;
   4.115 +
   4.116 +static void
   4.117 +UpdateYUVTextureData(SDL_Texture * texture)
   4.118 +{
   4.119 +    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
   4.120 +    SDL_Rect rect;
   4.121 +
   4.122 +    rect.x = 0;
   4.123 +    rect.y = 0;
   4.124 +    rect.w = texture->w;
   4.125 +    rect.h = texture->h;
   4.126 +    //SDL_SW_CopyYUVToRGB(data->yuv, &rect, data->format, texture->w,
   4.127 +    //                    texture->h, data->pixels, data->pitch);
   4.128 +}
   4.129 +
   4.130 +void
   4.131 +D3D_AddRenderDriver(_THIS)
   4.132 +{
   4.133 +    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
   4.134 +
   4.135 +    if (data->d3d) {
   4.136 +        SDL_AddRenderDriver(0, &SDL_D3D_RenderDriver);
   4.137 +    }
   4.138 +}
   4.139 +
   4.140 +SDL_Renderer *
   4.141 +SDL_D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
   4.142 +{
   4.143 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   4.144 +    SDL_VideoData *videodata = (SDL_VideoData *) display->device->driverdata;
   4.145 +    SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
   4.146 +    SDL_Renderer *renderer;
   4.147 +    SDL_D3D_RenderData *data;
   4.148 +
   4.149 +    renderer = (SDL_Renderer *) SDL_malloc(sizeof(*renderer));
   4.150 +    if (!renderer) {
   4.151 +        SDL_OutOfMemory();
   4.152 +        return NULL;
   4.153 +    }
   4.154 +    SDL_zerop(renderer);
   4.155 +
   4.156 +    data = (SDL_D3D_RenderData *) SDL_malloc(sizeof(*data));
   4.157 +    if (!data) {
   4.158 +        SDL_D3D_DestroyRenderer(renderer);
   4.159 +        SDL_OutOfMemory();
   4.160 +        return NULL;
   4.161 +    }
   4.162 +    SDL_zerop(data);
   4.163 +
   4.164 +    //data->device = IDirect3D9_CreateDevice(videodata->d3d,
   4.165 +
   4.166 +    renderer->CreateTexture = SDL_D3D_CreateTexture;
   4.167 +    renderer->QueryTexturePixels = SDL_D3D_QueryTexturePixels;
   4.168 +    renderer->SetTexturePalette = SDL_D3D_SetTexturePalette;
   4.169 +    renderer->GetTexturePalette = SDL_D3D_GetTexturePalette;
   4.170 +    renderer->UpdateTexture = SDL_D3D_UpdateTexture;
   4.171 +    renderer->LockTexture = SDL_D3D_LockTexture;
   4.172 +    renderer->UnlockTexture = SDL_D3D_UnlockTexture;
   4.173 +    renderer->DirtyTexture = SDL_D3D_DirtyTexture;
   4.174 +    renderer->SelectRenderTexture = SDL_D3D_SelectRenderTexture;
   4.175 +    renderer->RenderFill = SDL_D3D_RenderFill;
   4.176 +    renderer->RenderCopy = SDL_D3D_RenderCopy;
   4.177 +    renderer->RenderReadPixels = SDL_D3D_RenderReadPixels;
   4.178 +    renderer->RenderWritePixels = SDL_D3D_RenderWritePixels;
   4.179 +    renderer->RenderPresent = SDL_D3D_RenderPresent;
   4.180 +    renderer->DestroyTexture = SDL_D3D_DestroyTexture;
   4.181 +    renderer->DestroyRenderer = SDL_D3D_DestroyRenderer;
   4.182 +    renderer->info = SDL_D3D_RenderDriver.info;
   4.183 +    renderer->window = window->id;
   4.184 +    renderer->driverdata = data;
   4.185 +
   4.186 +    renderer->info.flags = SDL_Renderer_RenderTarget;
   4.187 +
   4.188 +    return renderer;
   4.189 +}
   4.190 +
   4.191 +static int
   4.192 +SDL_D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   4.193 +{
   4.194 +    SDL_D3D_RenderData *renderdata =
   4.195 +        (SDL_D3D_RenderData *) renderer->driverdata;
   4.196 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   4.197 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   4.198 +    SDL_D3D_TextureData *data;
   4.199 +
   4.200 +    data = (SDL_D3D_TextureData *) SDL_malloc(sizeof(*data));
   4.201 +    if (!data) {
   4.202 +        SDL_OutOfMemory();
   4.203 +        return -1;
   4.204 +    }
   4.205 +    SDL_zerop(data);
   4.206 +
   4.207 +    texture->driverdata = data;
   4.208 +
   4.209 +    return 0;
   4.210 +}
   4.211 +
   4.212 +static int
   4.213 +SDL_D3D_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
   4.214 +                           void **pixels, int *pitch)
   4.215 +{
   4.216 +    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
   4.217 +
   4.218 +    if (data->yuv) {
   4.219 +        return SDL_SW_QueryYUVTexturePixels(data->yuv, pixels, pitch);
   4.220 +    } else {
   4.221 +        return 0;
   4.222 +    }
   4.223 +}
   4.224 +
   4.225 +static int
   4.226 +SDL_D3D_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
   4.227 +                          const SDL_Color * colors, int firstcolor,
   4.228 +                          int ncolors)
   4.229 +{
   4.230 +    SDL_D3D_RenderData *renderdata =
   4.231 +        (SDL_D3D_RenderData *) renderer->driverdata;
   4.232 +    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
   4.233 +
   4.234 +    if (data->yuv) {
   4.235 +        SDL_SetError("YUV textures don't have a palette");
   4.236 +        return -1;
   4.237 +    } else {
   4.238 +        return 0;
   4.239 +    }
   4.240 +}
   4.241 +
   4.242 +static int
   4.243 +SDL_D3D_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
   4.244 +                          SDL_Color * colors, int firstcolor, int ncolors)
   4.245 +{
   4.246 +    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
   4.247 +
   4.248 +    if (data->yuv) {
   4.249 +        SDL_SetError("YUV textures don't have a palette");
   4.250 +        return -1;
   4.251 +    } else {
   4.252 +        return 0;
   4.253 +    }
   4.254 +}
   4.255 +
   4.256 +static int
   4.257 +SDL_D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   4.258 +                      const SDL_Rect * rect, const void *pixels, int pitch)
   4.259 +{
   4.260 +    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
   4.261 +
   4.262 +    if (data->yuv) {
   4.263 +        if (SDL_SW_UpdateYUVTexture(data->yuv, rect, pixels, pitch) < 0) {
   4.264 +            return -1;
   4.265 +        }
   4.266 +        UpdateYUVTextureData(texture);
   4.267 +        return 0;
   4.268 +    } else {
   4.269 +        SDL_D3D_RenderData *renderdata =
   4.270 +            (SDL_D3D_RenderData *) renderer->driverdata;
   4.271 +
   4.272 +        return 0;
   4.273 +    }
   4.274 +}
   4.275 +
   4.276 +static int
   4.277 +SDL_D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   4.278 +                    const SDL_Rect * rect, int markDirty, void **pixels,
   4.279 +                    int *pitch)
   4.280 +{
   4.281 +    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
   4.282 +
   4.283 +    if (data->yuv) {
   4.284 +        return SDL_SW_LockYUVTexture(data->yuv, rect, markDirty, pixels,
   4.285 +                                     pitch);
   4.286 +    } else {
   4.287 +        return 0;
   4.288 +    }
   4.289 +}
   4.290 +
   4.291 +static void
   4.292 +SDL_D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   4.293 +{
   4.294 +    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
   4.295 +
   4.296 +    if (data->yuv) {
   4.297 +        SDL_SW_UnlockYUVTexture(data->yuv);
   4.298 +        UpdateYUVTextureData(texture);
   4.299 +    }
   4.300 +}
   4.301 +
   4.302 +static void
   4.303 +SDL_D3D_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   4.304 +                     int numrects, const SDL_Rect * rects)
   4.305 +{
   4.306 +}
   4.307 +
   4.308 +static void
   4.309 +SDL_D3D_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   4.310 +{
   4.311 +    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
   4.312 +}
   4.313 +
   4.314 +static int
   4.315 +SDL_D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
   4.316 +                   Uint32 color)
   4.317 +{
   4.318 +    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
   4.319 +    Uint8 r, g, b;
   4.320 +
   4.321 +    r = (Uint8) ((color >> 16) & 0xFF);
   4.322 +    g = (Uint8) ((color >> 8) & 0xFF);
   4.323 +    b = (Uint8) (color & 0xFF);
   4.324 +
   4.325 +    return 0;
   4.326 +}
   4.327 +
   4.328 +static int
   4.329 +SDL_D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   4.330 +                   const SDL_Rect * srcrect, const SDL_Rect * dstrect,
   4.331 +                   int blendMode, int scaleMode)
   4.332 +{
   4.333 +    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
   4.334 +    SDL_D3D_TextureData *texturedata =
   4.335 +        (SDL_D3D_TextureData *) texture->driverdata;
   4.336 +
   4.337 +    return 0;
   4.338 +}
   4.339 +
   4.340 +static int
   4.341 +SDL_D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   4.342 +                         void *pixels, int pitch)
   4.343 +{
   4.344 +    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
   4.345 +
   4.346 +    return 0;
   4.347 +}
   4.348 +
   4.349 +static int
   4.350 +SDL_D3D_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   4.351 +                          const void *pixels, int pitch)
   4.352 +{
   4.353 +    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
   4.354 +
   4.355 +    return 0;
   4.356 +}
   4.357 +
   4.358 +static void
   4.359 +SDL_D3D_RenderPresent(SDL_Renderer * renderer)
   4.360 +{
   4.361 +}
   4.362 +
   4.363 +static void
   4.364 +SDL_D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   4.365 +{
   4.366 +    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
   4.367 +
   4.368 +    if (!data) {
   4.369 +        return;
   4.370 +    }
   4.371 +    SDL_free(data);
   4.372 +    texture->driverdata = NULL;
   4.373 +}
   4.374 +
   4.375 +void
   4.376 +SDL_D3D_DestroyRenderer(SDL_Renderer * renderer)
   4.377 +{
   4.378 +    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
   4.379 +
   4.380 +    if (data) {
   4.381 +        SDL_free(data);
   4.382 +    }
   4.383 +    SDL_free(renderer);
   4.384 +}
   4.385 +
   4.386 +#endif /* SDL_VIDEO_RENDER_D3D */
   4.387 +
   4.388 +/* vi: set ts=4 sw=4 expandtab: */
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/video/win32/SDL_d3drender.h	Sat Jul 08 18:06:02 2006 +0000
     5.3 @@ -0,0 +1,28 @@
     5.4 +/*
     5.5 +    SDL - Simple DirectMedia Layer
     5.6 +    Copyright (C) 1997-2006 Sam Lantinga
     5.7 +
     5.8 +    This library is free software; you can redistribute it and/or
     5.9 +    modify it under the terms of the GNU Lesser General Public
    5.10 +    License as published by the Free Software Foundation; either
    5.11 +    version 2.1 of the License, or (at your option) any later version.
    5.12 +
    5.13 +    This library is distributed in the hope that it will be useful,
    5.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    5.16 +    Lesser General Public License for more details.
    5.17 +
    5.18 +    You should have received a copy of the GNU Lesser General Public
    5.19 +    License along with this library; if not, write to the Free Software
    5.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    5.21 +
    5.22 +    Sam Lantinga
    5.23 +    slouken@libsdl.org
    5.24 +*/
    5.25 +#include "SDL_config.h"
    5.26 +
    5.27 +#if SDL_VIDEO_RENDER_D3D
    5.28 +extern void D3D_AddRenderDriver(_THIS);
    5.29 +#endif
    5.30 +
    5.31 +/* vi: set ts=4 sw=4 expandtab: */
     6.1 --- a/src/video/win32/SDL_dibrender.c	Fri Jul 07 10:39:33 2006 +0000
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,711 +0,0 @@
     6.4 -/*
     6.5 -    SDL - Simple DirectMedia Layer
     6.6 -    Copyright (C) 1997-2006 Sam Lantinga
     6.7 -
     6.8 -    This library is free software; you can redistribute it and/or
     6.9 -    modify it under the terms of the GNU Lesser General Public
    6.10 -    License as published by the Free Software Foundation; either
    6.11 -    version 2.1 of the License, or (at your option) any later version.
    6.12 -
    6.13 -    This library is distributed in the hope that it will be useful,
    6.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.16 -    Lesser General Public License for more details.
    6.17 -
    6.18 -    You should have received a copy of the GNU Lesser General Public
    6.19 -    License along with this library; if not, write to the Free Software
    6.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    6.21 -
    6.22 -    Sam Lantinga
    6.23 -    slouken@libsdl.org
    6.24 -*/
    6.25 -#include "SDL_config.h"
    6.26 -
    6.27 -#include "SDL_win32video.h"
    6.28 -#include "../SDL_yuv_sw_c.h"
    6.29 -
    6.30 -/* GDI renderer implementation */
    6.31 -
    6.32 -static SDL_Renderer *SDL_DIB_CreateRenderer(SDL_Window * window,
    6.33 -                                            Uint32 flags);
    6.34 -static int SDL_DIB_CreateTexture(SDL_Renderer * renderer,
    6.35 -                                 SDL_Texture * texture);
    6.36 -static int SDL_DIB_QueryTexturePixels(SDL_Renderer * renderer,
    6.37 -                                      SDL_Texture * texture, void **pixels,
    6.38 -                                      int *pitch);
    6.39 -static int SDL_DIB_SetTexturePalette(SDL_Renderer * renderer,
    6.40 -                                     SDL_Texture * texture,
    6.41 -                                     const SDL_Color * colors, int firstcolor,
    6.42 -                                     int ncolors);
    6.43 -static int SDL_DIB_GetTexturePalette(SDL_Renderer * renderer,
    6.44 -                                     SDL_Texture * texture,
    6.45 -                                     SDL_Color * colors, int firstcolor,
    6.46 -                                     int ncolors);
    6.47 -static int SDL_DIB_UpdateTexture(SDL_Renderer * renderer,
    6.48 -                                 SDL_Texture * texture, const SDL_Rect * rect,
    6.49 -                                 const void *pixels, int pitch);
    6.50 -static int SDL_DIB_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    6.51 -                               const SDL_Rect * rect, int markDirty,
    6.52 -                               void **pixels, int *pitch);
    6.53 -static void SDL_DIB_UnlockTexture(SDL_Renderer * renderer,
    6.54 -                                  SDL_Texture * texture);
    6.55 -static void SDL_DIB_DirtyTexture(SDL_Renderer * renderer,
    6.56 -                                 SDL_Texture * texture, int numrects,
    6.57 -                                 const SDL_Rect * rects);
    6.58 -static void SDL_DIB_SelectRenderTexture(SDL_Renderer * renderer,
    6.59 -                                        SDL_Texture * texture);
    6.60 -static int SDL_DIB_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
    6.61 -                              Uint32 color);
    6.62 -static int SDL_DIB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    6.63 -                              const SDL_Rect * srcrect,
    6.64 -                              const SDL_Rect * dstrect, int blendMode,
    6.65 -                              int scaleMode);
    6.66 -static int SDL_DIB_RenderReadPixels(SDL_Renderer * renderer,
    6.67 -                                    const SDL_Rect * rect, void *pixels,
    6.68 -                                    int pitch);
    6.69 -static int SDL_DIB_RenderWritePixels(SDL_Renderer * renderer,
    6.70 -                                     const SDL_Rect * rect,
    6.71 -                                     const void *pixels, int pitch);
    6.72 -static void SDL_DIB_RenderPresent(SDL_Renderer * renderer);
    6.73 -static void SDL_DIB_DestroyTexture(SDL_Renderer * renderer,
    6.74 -                                   SDL_Texture * texture);
    6.75 -static void SDL_DIB_DestroyRenderer(SDL_Renderer * renderer);
    6.76 -
    6.77 -
    6.78 -SDL_RenderDriver SDL_DIB_RenderDriver = {
    6.79 -    SDL_DIB_CreateRenderer,
    6.80 -    {
    6.81 -     "gdi",
    6.82 -     (SDL_Renderer_PresentDiscard |
    6.83 -      SDL_Renderer_PresentCopy | SDL_Renderer_RenderTarget),
    6.84 -     (SDL_TextureBlendMode_None |
    6.85 -      SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend),
    6.86 -     (SDL_TextureScaleMode_None | SDL_TextureScaleMode_Fast),
    6.87 -     11,
    6.88 -     {
    6.89 -      SDL_PixelFormat_Index8,
    6.90 -      SDL_PixelFormat_RGB555,
    6.91 -      SDL_PixelFormat_RGB565,
    6.92 -      SDL_PixelFormat_RGB888,
    6.93 -      SDL_PixelFormat_BGR888,
    6.94 -      SDL_PixelFormat_ARGB8888,
    6.95 -      SDL_PixelFormat_RGBA8888,
    6.96 -      SDL_PixelFormat_ABGR8888,
    6.97 -      SDL_PixelFormat_BGRA8888,
    6.98 -      SDL_PixelFormat_YUY2,
    6.99 -      SDL_PixelFormat_UYVY},
   6.100 -     0,
   6.101 -     0}
   6.102 -};
   6.103 -
   6.104 -typedef struct
   6.105 -{
   6.106 -    HWND hwnd;
   6.107 -    HDC window_hdc;
   6.108 -    HDC render_hdc;
   6.109 -    HDC memory_hdc;
   6.110 -    HDC current_hdc;
   6.111 -    LPBITMAPINFO bmi;
   6.112 -    HBITMAP window_bmp;
   6.113 -    void *window_pixels;
   6.114 -    int window_pitch;
   6.115 -} SDL_DIB_RenderData;
   6.116 -
   6.117 -typedef struct
   6.118 -{
   6.119 -    SDL_SW_YUVTexture *yuv;
   6.120 -    Uint32 format;
   6.121 -    HPALETTE hpal;
   6.122 -    HBITMAP hbm;
   6.123 -    void *pixels;
   6.124 -    int pitch;
   6.125 -} SDL_DIB_TextureData;
   6.126 -
   6.127 -static void
   6.128 -UpdateYUVTextureData(SDL_Texture * texture)
   6.129 -{
   6.130 -    SDL_DIB_TextureData *data = (SDL_DIB_TextureData *) texture->driverdata;
   6.131 -    SDL_Rect rect;
   6.132 -
   6.133 -    rect.x = 0;
   6.134 -    rect.y = 0;
   6.135 -    rect.w = texture->w;
   6.136 -    rect.h = texture->h;
   6.137 -    SDL_SW_CopyYUVToRGB(data->yuv, &rect, data->format, texture->w,
   6.138 -                        texture->h, data->pixels, data->pitch);
   6.139 -}
   6.140 -
   6.141 -SDL_Renderer *
   6.142 -SDL_DIB_CreateRenderer(SDL_Window * window, Uint32 flags)
   6.143 -{
   6.144 -    SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
   6.145 -    SDL_Renderer *renderer;
   6.146 -    SDL_DIB_RenderData *data;
   6.147 -    int bmi_size;
   6.148 -    HBITMAP hbm;
   6.149 -
   6.150 -    renderer = (SDL_Renderer *) SDL_malloc(sizeof(*renderer));
   6.151 -    if (!renderer) {
   6.152 -        SDL_OutOfMemory();
   6.153 -        return NULL;
   6.154 -    }
   6.155 -    SDL_zerop(renderer);
   6.156 -
   6.157 -    data = (SDL_DIB_RenderData *) SDL_malloc(sizeof(*data));
   6.158 -    if (!data) {
   6.159 -        SDL_DIB_DestroyRenderer(renderer);
   6.160 -        SDL_OutOfMemory();
   6.161 -        return NULL;
   6.162 -    }
   6.163 -    SDL_zerop(data);
   6.164 -
   6.165 -    data->hwnd = windowdata->hwnd;
   6.166 -    data->window_hdc = GetDC(data->hwnd);
   6.167 -    data->render_hdc = CreateCompatibleDC(data->window_hdc);
   6.168 -    data->memory_hdc = CreateCompatibleDC(data->window_hdc);
   6.169 -    data->current_hdc = data->window_hdc;
   6.170 -
   6.171 -    /* Fill in the compatible bitmap info */
   6.172 -    bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
   6.173 -    data->bmi = (LPBITMAPINFO) SDL_malloc(bmi_size);
   6.174 -    if (!data->bmi) {
   6.175 -        SDL_DIB_DestroyRenderer(renderer);
   6.176 -        SDL_OutOfMemory();
   6.177 -        return NULL;
   6.178 -    }
   6.179 -    SDL_memset(data->bmi, 0, bmi_size);
   6.180 -    data->bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
   6.181 -
   6.182 -    hbm = CreateCompatibleBitmap(data->window_hdc, 1, 1);
   6.183 -    GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS);
   6.184 -    GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS);
   6.185 -    DeleteObject(hbm);
   6.186 -
   6.187 -    renderer->CreateTexture = SDL_DIB_CreateTexture;
   6.188 -    renderer->QueryTexturePixels = SDL_DIB_QueryTexturePixels;
   6.189 -    renderer->SetTexturePalette = SDL_DIB_SetTexturePalette;
   6.190 -    renderer->GetTexturePalette = SDL_DIB_GetTexturePalette;
   6.191 -    renderer->UpdateTexture = SDL_DIB_UpdateTexture;
   6.192 -    renderer->LockTexture = SDL_DIB_LockTexture;
   6.193 -    renderer->UnlockTexture = SDL_DIB_UnlockTexture;
   6.194 -    renderer->DirtyTexture = SDL_DIB_DirtyTexture;
   6.195 -    renderer->SelectRenderTexture = SDL_DIB_SelectRenderTexture;
   6.196 -    renderer->RenderFill = SDL_DIB_RenderFill;
   6.197 -    renderer->RenderCopy = SDL_DIB_RenderCopy;
   6.198 -    renderer->RenderReadPixels = SDL_DIB_RenderReadPixels;
   6.199 -    renderer->RenderWritePixels = SDL_DIB_RenderWritePixels;
   6.200 -    renderer->RenderPresent = SDL_DIB_RenderPresent;
   6.201 -    renderer->DestroyTexture = SDL_DIB_DestroyTexture;
   6.202 -    renderer->DestroyRenderer = SDL_DIB_DestroyRenderer;
   6.203 -    renderer->info = SDL_DIB_RenderDriver.info;
   6.204 -    renderer->window = window->id;
   6.205 -    renderer->driverdata = data;
   6.206 -
   6.207 -    renderer->info.flags = SDL_Renderer_RenderTarget;
   6.208 -
   6.209 -    return renderer;
   6.210 -}
   6.211 -
   6.212 -static int
   6.213 -SDL_DIB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   6.214 -{
   6.215 -    SDL_DIB_RenderData *renderdata =
   6.216 -        (SDL_DIB_RenderData *) renderer->driverdata;
   6.217 -    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   6.218 -    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   6.219 -    SDL_DIB_TextureData *data;
   6.220 -
   6.221 -    data = (SDL_DIB_TextureData *) SDL_malloc(sizeof(*data));
   6.222 -    if (!data) {
   6.223 -        SDL_OutOfMemory();
   6.224 -        return -1;
   6.225 -    }
   6.226 -    SDL_zerop(data);
   6.227 -
   6.228 -    texture->driverdata = data;
   6.229 -
   6.230 -    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   6.231 -        if (texture->access == SDL_TextureAccess_Render) {
   6.232 -            SDL_SetError("Rendering to YUV format textures is not supported");
   6.233 -            return -1;
   6.234 -        }
   6.235 -        data->yuv = SDL_SW_CreateYUVTexture(texture);
   6.236 -        if (!data->yuv) {
   6.237 -            SDL_DIB_DestroyTexture(renderer, texture);
   6.238 -            return -1;
   6.239 -        }
   6.240 -        data->format = display->current_mode.format;
   6.241 -    } else {
   6.242 -        data->format = texture->format;
   6.243 -    }
   6.244 -    data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format));
   6.245 -
   6.246 -    if (data->yuv || texture->access == SDL_TextureAccess_Local
   6.247 -        || texture->format != SDL_GetCurrentDisplayMode()->format) {
   6.248 -        int bmi_size;
   6.249 -        LPBITMAPINFO bmi;
   6.250 -
   6.251 -        bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
   6.252 -        bmi = (LPBITMAPINFO) SDL_malloc(bmi_size);
   6.253 -        if (!bmi) {
   6.254 -            SDL_DIB_DestroyTexture(renderer, texture);
   6.255 -            SDL_OutOfMemory();
   6.256 -            return -1;
   6.257 -        }
   6.258 -        SDL_memset(bmi, 0, bmi_size);
   6.259 -        bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
   6.260 -        bmi->bmiHeader.biWidth = texture->w;
   6.261 -        bmi->bmiHeader.biHeight = -texture->h;  /* topdown bitmap */
   6.262 -        bmi->bmiHeader.biPlanes = 1;
   6.263 -        bmi->bmiHeader.biSizeImage = texture->h * data->pitch;
   6.264 -        bmi->bmiHeader.biXPelsPerMeter = 0;
   6.265 -        bmi->bmiHeader.biYPelsPerMeter = 0;
   6.266 -        bmi->bmiHeader.biClrUsed = 0;
   6.267 -        bmi->bmiHeader.biClrImportant = 0;
   6.268 -        bmi->bmiHeader.biBitCount = SDL_BYTESPERPIXEL(data->format) * 8;
   6.269 -        if (SDL_ISPIXELFORMAT_INDEXED(data->format)) {
   6.270 -            int i, ncolors;
   6.271 -            LOGPALETTE *palette;
   6.272 -
   6.273 -            bmi->bmiHeader.biCompression = BI_RGB;
   6.274 -            ncolors = (1 << SDL_BITSPERPIXEL(data->format));
   6.275 -            palette =
   6.276 -                (LOGPALETTE *) SDL_malloc(sizeof(*palette) +
   6.277 -                                          ncolors * sizeof(PALETTEENTRY));
   6.278 -            if (!palette) {
   6.279 -                SDL_free(bmi);
   6.280 -                SDL_DIB_DestroyTexture(renderer, texture);
   6.281 -                SDL_OutOfMemory();
   6.282 -                return -1;
   6.283 -            }
   6.284 -            palette->palVersion = 0x300;
   6.285 -            palette->palNumEntries = ncolors;
   6.286 -            for (i = 0; i < ncolors; ++i) {
   6.287 -                palette->palPalEntry[i].peRed = 0xFF;
   6.288 -                palette->palPalEntry[i].peGreen = 0xFF;
   6.289 -                palette->palPalEntry[i].peBlue = 0xFF;
   6.290 -                palette->palPalEntry[i].peFlags = 0;
   6.291 -            }
   6.292 -            data->hpal = CreatePalette(palette);
   6.293 -            SDL_free(palette);
   6.294 -        } else {
   6.295 -            int bpp;
   6.296 -            Uint32 Rmask, Gmask, Bmask, Amask;
   6.297 -
   6.298 -            bmi->bmiHeader.biCompression = BI_BITFIELDS;
   6.299 -            SDL_PixelFormatEnumToMasks(data->format, &bpp, &Rmask, &Gmask,
   6.300 -                                       &Bmask, &Amask);
   6.301 -            ((Uint32 *) bmi->bmiColors)[0] = Rmask;
   6.302 -            ((Uint32 *) bmi->bmiColors)[1] = Gmask;
   6.303 -            ((Uint32 *) bmi->bmiColors)[2] = Bmask;
   6.304 -            data->hpal = NULL;
   6.305 -        }
   6.306 -        data->hbm =
   6.307 -            CreateDIBSection(renderdata->memory_hdc, bmi, DIB_RGB_COLORS,
   6.308 -                             &data->pixels, NULL, 0);
   6.309 -    } else {
   6.310 -        data->hbm =
   6.311 -            CreateCompatibleBitmap(renderdata->window_hdc, texture->w,
   6.312 -                                   texture->h);
   6.313 -        data->pixels = NULL;
   6.314 -    }
   6.315 -    if (!data->hbm) {
   6.316 -        SDL_DIB_DestroyTexture(renderer, texture);
   6.317 -        WIN_SetError("Couldn't create bitmap");
   6.318 -        return -1;
   6.319 -    }
   6.320 -    return 0;
   6.321 -}
   6.322 -
   6.323 -static int
   6.324 -SDL_DIB_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
   6.325 -                           void **pixels, int *pitch)
   6.326 -{
   6.327 -    SDL_DIB_TextureData *data = (SDL_DIB_TextureData *) texture->driverdata;
   6.328 -
   6.329 -    if (data->yuv) {
   6.330 -        return SDL_SW_QueryYUVTexturePixels(data->yuv, pixels, pitch);
   6.331 -    } else {
   6.332 -        *pixels = data->pixels;
   6.333 -        *pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
   6.334 -        return 0;
   6.335 -    }
   6.336 -}
   6.337 -
   6.338 -static int
   6.339 -SDL_DIB_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
   6.340 -                          const SDL_Color * colors, int firstcolor,
   6.341 -                          int ncolors)
   6.342 -{
   6.343 -    SDL_DIB_RenderData *renderdata =
   6.344 -        (SDL_DIB_RenderData *) renderer->driverdata;
   6.345 -    SDL_DIB_TextureData *data = (SDL_DIB_TextureData *) texture->driverdata;
   6.346 -
   6.347 -    if (data->yuv) {
   6.348 -        SDL_SetError("YUV textures don't have a palette");
   6.349 -        return -1;
   6.350 -    } else {
   6.351 -        PALETTEENTRY entries[256];
   6.352 -        int i;
   6.353 -
   6.354 -        for (i = 0; i < ncolors; ++i) {
   6.355 -            entries[i].peRed = colors[i].r;
   6.356 -            entries[i].peGreen = colors[i].g;
   6.357 -            entries[i].peBlue = colors[i].b;
   6.358 -            entries[i].peFlags = 0;
   6.359 -        }
   6.360 -        if (!SetPaletteEntries(data->hpal, firstcolor, ncolors, entries)) {
   6.361 -            WIN_SetError("SetPaletteEntries()");
   6.362 -            return -1;
   6.363 -        }
   6.364 -        return 0;
   6.365 -    }
   6.366 -}
   6.367 -
   6.368 -static int
   6.369 -SDL_DIB_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
   6.370 -                          SDL_Color * colors, int firstcolor, int ncolors)
   6.371 -{
   6.372 -    SDL_DIB_TextureData *data = (SDL_DIB_TextureData *) texture->driverdata;
   6.373 -
   6.374 -    if (data->yuv) {
   6.375 -        SDL_SetError("YUV textures don't have a palette");
   6.376 -        return -1;
   6.377 -    } else {
   6.378 -        PALETTEENTRY entries[256];
   6.379 -        int i;
   6.380 -
   6.381 -        if (!GetPaletteEntries(data->hpal, firstcolor, ncolors, entries)) {
   6.382 -            WIN_SetError("GetPaletteEntries()");
   6.383 -            return -1;
   6.384 -        }
   6.385 -        for (i = 0; i < ncolors; ++i) {
   6.386 -            colors[i].r = entries[i].peRed;
   6.387 -            colors[i].g = entries[i].peGreen;
   6.388 -            colors[i].b = entries[i].peBlue;
   6.389 -        }
   6.390 -        return 0;
   6.391 -    }
   6.392 -}
   6.393 -
   6.394 -static int
   6.395 -SDL_DIB_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   6.396 -                      const SDL_Rect * rect, const void *pixels, int pitch)
   6.397 -{
   6.398 -    SDL_DIB_TextureData *data = (SDL_DIB_TextureData *) texture->driverdata;
   6.399 -
   6.400 -    if (data->yuv) {
   6.401 -        if (SDL_SW_UpdateYUVTexture(data->yuv, rect, pixels, pitch) < 0) {
   6.402 -            return -1;
   6.403 -        }
   6.404 -        UpdateYUVTextureData(texture);
   6.405 -        return 0;
   6.406 -    } else {
   6.407 -        SDL_DIB_RenderData *renderdata =
   6.408 -            (SDL_DIB_RenderData *) renderer->driverdata;
   6.409 -
   6.410 -        if (data->pixels) {
   6.411 -            Uint8 *src, *dst;
   6.412 -            int row;
   6.413 -            size_t length;
   6.414 -
   6.415 -            src = (Uint8 *) pixels;
   6.416 -            dst =
   6.417 -                (Uint8 *) data->pixels + rect->y * data->pitch +
   6.418 -                rect->x * SDL_BYTESPERPIXEL(texture->format);
   6.419 -            length = rect->w * SDL_BYTESPERPIXEL(texture->format);
   6.420 -            for (row = 0; row < rect->h; ++row) {
   6.421 -                SDL_memcpy(dst, src, length);
   6.422 -                src += pitch;
   6.423 -                dst += data->pitch;
   6.424 -            }
   6.425 -        } else if (rect->w == texture->w && pitch == data->pitch) {
   6.426 -            if (!SetDIBits
   6.427 -                (renderdata->window_hdc, data->hbm, rect->y, rect->h, pixels,
   6.428 -                 renderdata->bmi, DIB_RGB_COLORS)) {
   6.429 -                WIN_SetError("SetDIBits()");
   6.430 -                return -1;
   6.431 -            }
   6.432 -        } else {
   6.433 -            SDL_SetError
   6.434 -                ("FIXME: Need to allocate temporary memory and do GetDIBits() followed by SetDIBits(), since we can only set blocks of scanlines at a time");
   6.435 -            return -1;
   6.436 -        }
   6.437 -        return 0;
   6.438 -    }
   6.439 -}
   6.440 -
   6.441 -static int
   6.442 -SDL_DIB_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   6.443 -                    const SDL_Rect * rect, int markDirty, void **pixels,
   6.444 -                    int *pitch)
   6.445 -{
   6.446 -    SDL_DIB_TextureData *data = (SDL_DIB_TextureData *) texture->driverdata;
   6.447 -
   6.448 -    if (data->yuv) {
   6.449 -        return SDL_SW_LockYUVTexture(data->yuv, rect, markDirty, pixels,
   6.450 -                                     pitch);
   6.451 -    } else {
   6.452 -        GdiFlush();
   6.453 -        *pixels =
   6.454 -            (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
   6.455 -                      rect->x * SDL_BYTESPERPIXEL(texture->format));
   6.456 -        *pitch = data->pitch;
   6.457 -        return 0;
   6.458 -    }
   6.459 -}
   6.460 -
   6.461 -static void
   6.462 -SDL_DIB_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   6.463 -{
   6.464 -    SDL_DIB_TextureData *data = (SDL_DIB_TextureData *) texture->driverdata;
   6.465 -
   6.466 -    if (data->yuv) {
   6.467 -        SDL_SW_UnlockYUVTexture(data->yuv);
   6.468 -        UpdateYUVTextureData(texture);
   6.469 -    }
   6.470 -}
   6.471 -
   6.472 -static void
   6.473 -SDL_DIB_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   6.474 -                     int numrects, const SDL_Rect * rects)
   6.475 -{
   6.476 -}
   6.477 -
   6.478 -static void
   6.479 -SDL_DIB_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   6.480 -{
   6.481 -    SDL_DIB_RenderData *data = (SDL_DIB_RenderData *) renderer->driverdata;
   6.482 -
   6.483 -    if (texture) {
   6.484 -        SDL_DIB_TextureData *texturedata =
   6.485 -            (SDL_DIB_TextureData *) texture->driverdata;
   6.486 -        SelectObject(data->render_hdc, texturedata->hbm);
   6.487 -        if (texturedata->hpal) {
   6.488 -            SelectPalette(data->render_hdc, texturedata->hpal, TRUE);
   6.489 -            RealizePalette(data->render_hdc);
   6.490 -        }
   6.491 -        data->current_hdc = data->render_hdc;
   6.492 -    } else {
   6.493 -        data->current_hdc = data->current_hdc;
   6.494 -    }
   6.495 -}
   6.496 -
   6.497 -static int
   6.498 -SDL_DIB_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
   6.499 -                   Uint32 color)
   6.500 -{
   6.501 -    SDL_DIB_RenderData *data = (SDL_DIB_RenderData *) renderer->driverdata;
   6.502 -    Uint8 r, g, b;
   6.503 -    RECT rc;
   6.504 -    static HBRUSH brush;
   6.505 -    int status;
   6.506 -
   6.507 -    r = (Uint8) ((color >> 16) & 0xFF);
   6.508 -    g = (Uint8) ((color >> 8) & 0xFF);
   6.509 -    b = (Uint8) (color & 0xFF);
   6.510 -
   6.511 -    rc.left = rect->x;
   6.512 -    rc.top = rect->y;
   6.513 -    rc.right = rect->x + rect->w + 1;
   6.514 -    rc.bottom = rect->y + rect->h + 1;
   6.515 -
   6.516 -    /* Should we cache the brushes? .. it looks like GDI does for us. :) */
   6.517 -    brush = CreateSolidBrush(RGB(r, g, b));
   6.518 -    SelectObject(data->current_hdc, brush);
   6.519 -    status = FillRect(data->current_hdc, &rc, brush);
   6.520 -    DeleteObject(brush);
   6.521 -
   6.522 -    if (!status) {
   6.523 -        WIN_SetError("FillRect()");
   6.524 -        return -1;
   6.525 -    }
   6.526 -    return 0;
   6.527 -}
   6.528 -
   6.529 -static int
   6.530 -SDL_DIB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   6.531 -                   const SDL_Rect * srcrect, const SDL_Rect * dstrect,
   6.532 -                   int blendMode, int scaleMode)
   6.533 -{
   6.534 -    SDL_DIB_RenderData *data = (SDL_DIB_RenderData *) renderer->driverdata;
   6.535 -    SDL_DIB_TextureData *texturedata =
   6.536 -        (SDL_DIB_TextureData *) texture->driverdata;
   6.537 -
   6.538 -    SelectObject(data->memory_hdc, texturedata->hbm);
   6.539 -    if (texturedata->hpal) {
   6.540 -        SelectPalette(data->memory_hdc, texturedata->hpal, TRUE);
   6.541 -        RealizePalette(data->memory_hdc);
   6.542 -    }
   6.543 -    if (blendMode & (SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend)) {
   6.544 -        static BLENDFUNCTION blendFunc = {
   6.545 -            AC_SRC_OVER,
   6.546 -            0,
   6.547 -            255,
   6.548 -            AC_SRC_ALPHA
   6.549 -        };
   6.550 -        /* FIXME: GDI uses premultiplied alpha! */
   6.551 -        if (!AlphaBlend
   6.552 -            (data->current_hdc, dstrect->x, dstrect->y, dstrect->w,
   6.553 -             dstrect->h, data->memory_hdc, srcrect->x, srcrect->y, srcrect->w,
   6.554 -             srcrect->h, blendFunc)) {
   6.555 -            WIN_SetError("AlphaBlend()");
   6.556 -            return -1;
   6.557 -        }
   6.558 -    } else {
   6.559 -        if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
   6.560 -            if (!BitBlt
   6.561 -                (data->current_hdc, dstrect->x, dstrect->y, dstrect->w,
   6.562 -                 srcrect->h, data->memory_hdc, srcrect->x, srcrect->y,
   6.563 -                 SRCCOPY)) {
   6.564 -                WIN_SetError("BitBlt()");
   6.565 -                return -1;
   6.566 -            }
   6.567 -        } else {
   6.568 -            if (!StretchBlt
   6.569 -                (data->current_hdc, dstrect->x, dstrect->y, dstrect->w,
   6.570 -                 dstrect->h, data->memory_hdc, srcrect->x, srcrect->y,
   6.571 -                 srcrect->w, srcrect->h, SRCCOPY)) {
   6.572 -                WIN_SetError("StretchBlt()");
   6.573 -                return -1;
   6.574 -            }
   6.575 -        }
   6.576 -    }
   6.577 -    return 0;
   6.578 -}
   6.579 -
   6.580 -static int
   6.581 -CreateWindowDIB(SDL_DIB_RenderData * data, SDL_Window * window)
   6.582 -{
   6.583 -    data->window_pitch = window->w * (data->bmi->bmiHeader.biBitCount / 8);
   6.584 -    data->bmi->bmiHeader.biWidth = window->w;
   6.585 -    data->bmi->bmiHeader.biHeight = -window->h;
   6.586 -    data->bmi->bmiHeader.biSizeImage =
   6.587 -        window->h * (data->bmi->bmiHeader.biBitCount / 8);
   6.588 -    data->window_bmp =
   6.589 -        CreateDIBSection(data->window_hdc, data->bmi, DIB_RGB_COLORS,
   6.590 -                         &data->window_pixels, NULL, 0);
   6.591 -    if (!data->window_bmp) {
   6.592 -        WIN_SetError("CreateDIBSection()");
   6.593 -        return -1;
   6.594 -    }
   6.595 -    return 0;
   6.596 -}
   6.597 -
   6.598 -static int
   6.599 -SDL_DIB_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   6.600 -                         void *pixels, int pitch)
   6.601 -{
   6.602 -    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   6.603 -    SDL_DIB_RenderData *data = (SDL_DIB_RenderData *) renderer->driverdata;
   6.604 -
   6.605 -    if (!data->window_bmp) {
   6.606 -        if (CreateWindowDIB(data, window) < 0) {
   6.607 -            return -1;
   6.608 -        }
   6.609 -    }
   6.610 -
   6.611 -    SelectObject(data->memory_hdc, data->window_bmp);
   6.612 -    BitBlt(data->memory_hdc, rect->x, rect->y, rect->w, rect->h,
   6.613 -           data->window_hdc, rect->x, rect->y, SRCCOPY);
   6.614 -
   6.615 -    {
   6.616 -        int bpp = data->bmi->bmiHeader.biBitCount / 8;
   6.617 -        Uint8 *src =
   6.618 -            (Uint8 *) data->window_pixels + rect->y * data->window_pitch +
   6.619 -            rect->x * bpp;
   6.620 -        Uint8 *dst = (Uint8 *) pixels;
   6.621 -        int row;
   6.622 -
   6.623 -        for (row = 0; row < rect->h; ++row) {
   6.624 -            SDL_memcpy(dst, src, rect->w * bpp);
   6.625 -            src += data->window_pitch;
   6.626 -            dst += pitch;
   6.627 -        }
   6.628 -    }
   6.629 -
   6.630 -    return 0;
   6.631 -}
   6.632 -
   6.633 -static int
   6.634 -SDL_DIB_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   6.635 -                          const void *pixels, int pitch)
   6.636 -{
   6.637 -    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   6.638 -    SDL_DIB_RenderData *data = (SDL_DIB_RenderData *) renderer->driverdata;
   6.639 -
   6.640 -    if (!data->window_bmp) {
   6.641 -        if (CreateWindowDIB(data, window) < 0) {
   6.642 -            return -1;
   6.643 -        }
   6.644 -    }
   6.645 -
   6.646 -    {
   6.647 -        int bpp = data->bmi->bmiHeader.biBitCount / 8;
   6.648 -        Uint8 *src = (Uint8 *) pixels;
   6.649 -        Uint8 *dst =
   6.650 -            (Uint8 *) data->window_pixels + rect->y * data->window_pitch +
   6.651 -            rect->x * bpp;
   6.652 -        int row;
   6.653 -
   6.654 -        for (row = 0; row < rect->h; ++row) {
   6.655 -            SDL_memcpy(dst, src, rect->w * bpp);
   6.656 -            src += pitch;
   6.657 -            dst += data->window_pitch;
   6.658 -        }
   6.659 -    }
   6.660 -
   6.661 -    SelectObject(data->memory_hdc, data->window_bmp);
   6.662 -    BitBlt(data->window_hdc, rect->x, rect->y, rect->w, rect->h,
   6.663 -           data->memory_hdc, rect->x, rect->y, SRCCOPY);
   6.664 -
   6.665 -    return 0;
   6.666 -}
   6.667 -
   6.668 -static void
   6.669 -SDL_DIB_RenderPresent(SDL_Renderer * renderer)
   6.670 -{
   6.671 -}
   6.672 -
   6.673 -static void
   6.674 -SDL_DIB_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   6.675 -{
   6.676 -    SDL_DIB_TextureData *data = (SDL_DIB_TextureData *) texture->driverdata;
   6.677 -
   6.678 -    if (!data) {
   6.679 -        return;
   6.680 -    }
   6.681 -    if (data->yuv) {
   6.682 -        SDL_SW_DestroyYUVTexture(data->yuv);
   6.683 -    }
   6.684 -    if (data->hpal) {
   6.685 -        DeleteObject(data->hpal);
   6.686 -    }
   6.687 -    if (data->hbm) {
   6.688 -        DeleteObject(data->hbm);
   6.689 -    }
   6.690 -    SDL_free(data);
   6.691 -    texture->driverdata = NULL;
   6.692 -}
   6.693 -
   6.694 -void
   6.695 -SDL_DIB_DestroyRenderer(SDL_Renderer * renderer)
   6.696 -{
   6.697 -    SDL_DIB_RenderData *data = (SDL_DIB_RenderData *) renderer->driverdata;
   6.698 -
   6.699 -    if (data) {
   6.700 -        ReleaseDC(data->hwnd, data->window_hdc);
   6.701 -        DeleteDC(data->render_hdc);
   6.702 -        DeleteDC(data->memory_hdc);
   6.703 -        if (data->bmi) {
   6.704 -            SDL_free(data->bmi);
   6.705 -        }
   6.706 -        if (data->window_bmp) {
   6.707 -            DeleteObject(data->window_bmp);
   6.708 -        }
   6.709 -        SDL_free(data);
   6.710 -    }
   6.711 -    SDL_free(renderer);
   6.712 -}
   6.713 -
   6.714 -/* vi: set ts=4 sw=4 expandtab: */
     7.1 --- a/src/video/win32/SDL_dibrender.h	Fri Jul 07 10:39:33 2006 +0000
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,28 +0,0 @@
     7.4 -/*
     7.5 -    SDL - Simple DirectMedia Layer
     7.6 -    Copyright (C) 1997-2006 Sam Lantinga
     7.7 -
     7.8 -    This library is free software; you can redistribute it and/or
     7.9 -    modify it under the terms of the GNU Lesser General Public
    7.10 -    License as published by the Free Software Foundation; either
    7.11 -    version 2.1 of the License, or (at your option) any later version.
    7.12 -
    7.13 -    This library is distributed in the hope that it will be useful,
    7.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    7.16 -    Lesser General Public License for more details.
    7.17 -
    7.18 -    You should have received a copy of the GNU Lesser General Public
    7.19 -    License along with this library; if not, write to the Free Software
    7.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    7.21 -
    7.22 -    Sam Lantinga
    7.23 -    slouken@libsdl.org
    7.24 -*/
    7.25 -#include "SDL_config.h"
    7.26 -
    7.27 -/* SDL surface based renderer implementation */
    7.28 -
    7.29 -extern SDL_RenderDriver SDL_DIB_RenderDriver;
    7.30 -
    7.31 -/* vi: set ts=4 sw=4 expandtab: */
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/video/win32/SDL_gdirender.c	Sat Jul 08 18:06:02 2006 +0000
     8.3 @@ -0,0 +1,721 @@
     8.4 +/*
     8.5 +    SDL - Simple DirectMedia Layer
     8.6 +    Copyright (C) 1997-2006 Sam Lantinga
     8.7 +
     8.8 +    This library is free software; you can redistribute it and/or
     8.9 +    modify it under the terms of the GNU Lesser General Public
    8.10 +    License as published by the Free Software Foundation; either
    8.11 +    version 2.1 of the License, or (at your option) any later version.
    8.12 +
    8.13 +    This library is distributed in the hope that it will be useful,
    8.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    8.16 +    Lesser General Public License for more details.
    8.17 +
    8.18 +    You should have received a copy of the GNU Lesser General Public
    8.19 +    License along with this library; if not, write to the Free Software
    8.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    8.21 +
    8.22 +    Sam Lantinga
    8.23 +    slouken@libsdl.org
    8.24 +*/
    8.25 +#include "SDL_config.h"
    8.26 +
    8.27 +#if SDL_VIDEO_RENDER_GDI
    8.28 +
    8.29 +#include "SDL_win32video.h"
    8.30 +#include "../SDL_yuv_sw_c.h"
    8.31 +
    8.32 +/* GDI renderer implementation */
    8.33 +
    8.34 +static SDL_Renderer *SDL_GDI_CreateRenderer(SDL_Window * window,
    8.35 +                                            Uint32 flags);
    8.36 +static int SDL_GDI_CreateTexture(SDL_Renderer * renderer,
    8.37 +                                 SDL_Texture * texture);
    8.38 +static int SDL_GDI_QueryTexturePixels(SDL_Renderer * renderer,
    8.39 +                                      SDL_Texture * texture, void **pixels,
    8.40 +                                      int *pitch);
    8.41 +static int SDL_GDI_SetTexturePalette(SDL_Renderer * renderer,
    8.42 +                                     SDL_Texture * texture,
    8.43 +                                     const SDL_Color * colors, int firstcolor,
    8.44 +                                     int ncolors);
    8.45 +static int SDL_GDI_GetTexturePalette(SDL_Renderer * renderer,
    8.46 +                                     SDL_Texture * texture,
    8.47 +                                     SDL_Color * colors, int firstcolor,
    8.48 +                                     int ncolors);
    8.49 +static int SDL_GDI_UpdateTexture(SDL_Renderer * renderer,
    8.50 +                                 SDL_Texture * texture, const SDL_Rect * rect,
    8.51 +                                 const void *pixels, int pitch);
    8.52 +static int SDL_GDI_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    8.53 +                               const SDL_Rect * rect, int markDirty,
    8.54 +                               void **pixels, int *pitch);
    8.55 +static void SDL_GDI_UnlockTexture(SDL_Renderer * renderer,
    8.56 +                                  SDL_Texture * texture);
    8.57 +static void SDL_GDI_DirtyTexture(SDL_Renderer * renderer,
    8.58 +                                 SDL_Texture * texture, int numrects,
    8.59 +                                 const SDL_Rect * rects);
    8.60 +static void SDL_GDI_SelectRenderTexture(SDL_Renderer * renderer,
    8.61 +                                        SDL_Texture * texture);
    8.62 +static int SDL_GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
    8.63 +                              Uint32 color);
    8.64 +static int SDL_GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    8.65 +                              const SDL_Rect * srcrect,
    8.66 +                              const SDL_Rect * dstrect, int blendMode,
    8.67 +                              int scaleMode);
    8.68 +static int SDL_GDI_RenderReadPixels(SDL_Renderer * renderer,
    8.69 +                                    const SDL_Rect * rect, void *pixels,
    8.70 +                                    int pitch);
    8.71 +static int SDL_GDI_RenderWritePixels(SDL_Renderer * renderer,
    8.72 +                                     const SDL_Rect * rect,
    8.73 +                                     const void *pixels, int pitch);
    8.74 +static void SDL_GDI_RenderPresent(SDL_Renderer * renderer);
    8.75 +static void SDL_GDI_DestroyTexture(SDL_Renderer * renderer,
    8.76 +                                   SDL_Texture * texture);
    8.77 +static void SDL_GDI_DestroyRenderer(SDL_Renderer * renderer);
    8.78 +
    8.79 +
    8.80 +SDL_RenderDriver SDL_GDI_RenderDriver = {
    8.81 +    SDL_GDI_CreateRenderer,
    8.82 +    {
    8.83 +     "gdi",
    8.84 +     (SDL_Renderer_PresentDiscard |
    8.85 +      SDL_Renderer_PresentCopy | SDL_Renderer_RenderTarget),
    8.86 +     (SDL_TextureBlendMode_None |
    8.87 +      SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend),
    8.88 +     (SDL_TextureScaleMode_None | SDL_TextureScaleMode_Fast),
    8.89 +     11,
    8.90 +     {
    8.91 +      SDL_PixelFormat_Index8,
    8.92 +      SDL_PixelFormat_RGB555,
    8.93 +      SDL_PixelFormat_RGB565,
    8.94 +      SDL_PixelFormat_RGB888,
    8.95 +      SDL_PixelFormat_BGR888,
    8.96 +      SDL_PixelFormat_ARGB8888,
    8.97 +      SDL_PixelFormat_RGBA8888,
    8.98 +      SDL_PixelFormat_ABGR8888,
    8.99 +      SDL_PixelFormat_BGRA8888,
   8.100 +      SDL_PixelFormat_YUY2,
   8.101 +      SDL_PixelFormat_UYVY},
   8.102 +     0,
   8.103 +     0}
   8.104 +};
   8.105 +
   8.106 +typedef struct
   8.107 +{
   8.108 +    HWND hwnd;
   8.109 +    HDC window_hdc;
   8.110 +    HDC render_hdc;
   8.111 +    HDC memory_hdc;
   8.112 +    HDC current_hdc;
   8.113 +    LPBITMAPINFO bmi;
   8.114 +    HBITMAP window_bmp;
   8.115 +    void *window_pixels;
   8.116 +    int window_pitch;
   8.117 +} SDL_GDI_RenderData;
   8.118 +
   8.119 +typedef struct
   8.120 +{
   8.121 +    SDL_SW_YUVTexture *yuv;
   8.122 +    Uint32 format;
   8.123 +    HPALETTE hpal;
   8.124 +    HBITMAP hbm;
   8.125 +    void *pixels;
   8.126 +    int pitch;
   8.127 +} SDL_GDI_TextureData;
   8.128 +
   8.129 +static void
   8.130 +UpdateYUVTextureData(SDL_Texture * texture)
   8.131 +{
   8.132 +    SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata;
   8.133 +    SDL_Rect rect;
   8.134 +
   8.135 +    rect.x = 0;
   8.136 +    rect.y = 0;
   8.137 +    rect.w = texture->w;
   8.138 +    rect.h = texture->h;
   8.139 +    SDL_SW_CopyYUVToRGB(data->yuv, &rect, data->format, texture->w,
   8.140 +                        texture->h, data->pixels, data->pitch);
   8.141 +}
   8.142 +
   8.143 +void
   8.144 +GDI_AddRenderDriver(_THIS)
   8.145 +{
   8.146 +    SDL_AddRenderDriver(0, &SDL_GDI_RenderDriver);
   8.147 +}
   8.148 +
   8.149 +SDL_Renderer *
   8.150 +SDL_GDI_CreateRenderer(SDL_Window * window, Uint32 flags)
   8.151 +{
   8.152 +    SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
   8.153 +    SDL_Renderer *renderer;
   8.154 +    SDL_GDI_RenderData *data;
   8.155 +    int bmi_size;
   8.156 +    HBITMAP hbm;
   8.157 +
   8.158 +    renderer = (SDL_Renderer *) SDL_malloc(sizeof(*renderer));
   8.159 +    if (!renderer) {
   8.160 +        SDL_OutOfMemory();
   8.161 +        return NULL;
   8.162 +    }
   8.163 +    SDL_zerop(renderer);
   8.164 +
   8.165 +    data = (SDL_GDI_RenderData *) SDL_malloc(sizeof(*data));
   8.166 +    if (!data) {
   8.167 +        SDL_GDI_DestroyRenderer(renderer);
   8.168 +        SDL_OutOfMemory();
   8.169 +        return NULL;
   8.170 +    }
   8.171 +    SDL_zerop(data);
   8.172 +
   8.173 +    data->hwnd = windowdata->hwnd;
   8.174 +    data->window_hdc = GetDC(data->hwnd);
   8.175 +    data->render_hdc = CreateCompatibleDC(data->window_hdc);
   8.176 +    data->memory_hdc = CreateCompatibleDC(data->window_hdc);
   8.177 +    data->current_hdc = data->window_hdc;
   8.178 +
   8.179 +    /* Fill in the compatible bitmap info */
   8.180 +    bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
   8.181 +    data->bmi = (LPBITMAPINFO) SDL_malloc(bmi_size);
   8.182 +    if (!data->bmi) {
   8.183 +        SDL_GDI_DestroyRenderer(renderer);
   8.184 +        SDL_OutOfMemory();
   8.185 +        return NULL;
   8.186 +    }
   8.187 +    SDL_memset(data->bmi, 0, bmi_size);
   8.188 +    data->bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
   8.189 +
   8.190 +    hbm = CreateCompatibleBitmap(data->window_hdc, 1, 1);
   8.191 +    GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS);
   8.192 +    GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS);
   8.193 +    DeleteObject(hbm);
   8.194 +
   8.195 +    renderer->CreateTexture = SDL_GDI_CreateTexture;
   8.196 +    renderer->QueryTexturePixels = SDL_GDI_QueryTexturePixels;
   8.197 +    renderer->SetTexturePalette = SDL_GDI_SetTexturePalette;
   8.198 +    renderer->GetTexturePalette = SDL_GDI_GetTexturePalette;
   8.199 +    renderer->UpdateTexture = SDL_GDI_UpdateTexture;
   8.200 +    renderer->LockTexture = SDL_GDI_LockTexture;
   8.201 +    renderer->UnlockTexture = SDL_GDI_UnlockTexture;
   8.202 +    renderer->DirtyTexture = SDL_GDI_DirtyTexture;
   8.203 +    renderer->SelectRenderTexture = SDL_GDI_SelectRenderTexture;
   8.204 +    renderer->RenderFill = SDL_GDI_RenderFill;
   8.205 +    renderer->RenderCopy = SDL_GDI_RenderCopy;
   8.206 +    renderer->RenderReadPixels = SDL_GDI_RenderReadPixels;
   8.207 +    renderer->RenderWritePixels = SDL_GDI_RenderWritePixels;
   8.208 +    renderer->RenderPresent = SDL_GDI_RenderPresent;
   8.209 +    renderer->DestroyTexture = SDL_GDI_DestroyTexture;
   8.210 +    renderer->DestroyRenderer = SDL_GDI_DestroyRenderer;
   8.211 +    renderer->info = SDL_GDI_RenderDriver.info;
   8.212 +    renderer->window = window->id;
   8.213 +    renderer->driverdata = data;
   8.214 +
   8.215 +    renderer->info.flags = SDL_Renderer_RenderTarget;
   8.216 +
   8.217 +    return renderer;
   8.218 +}
   8.219 +
   8.220 +static int
   8.221 +SDL_GDI_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   8.222 +{
   8.223 +    SDL_GDI_RenderData *renderdata =
   8.224 +        (SDL_GDI_RenderData *) renderer->driverdata;
   8.225 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   8.226 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   8.227 +    SDL_GDI_TextureData *data;
   8.228 +
   8.229 +    data = (SDL_GDI_TextureData *) SDL_malloc(sizeof(*data));
   8.230 +    if (!data) {
   8.231 +        SDL_OutOfMemory();
   8.232 +        return -1;
   8.233 +    }
   8.234 +    SDL_zerop(data);
   8.235 +
   8.236 +    texture->driverdata = data;
   8.237 +
   8.238 +    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   8.239 +        if (texture->access == SDL_TextureAccess_Render) {
   8.240 +            SDL_SetError("Rendering to YUV format textures is not supported");
   8.241 +            return -1;
   8.242 +        }
   8.243 +        data->yuv = SDL_SW_CreateYUVTexture(texture);
   8.244 +        if (!data->yuv) {
   8.245 +            SDL_GDI_DestroyTexture(renderer, texture);
   8.246 +            return -1;
   8.247 +        }
   8.248 +        data->format = display->current_mode.format;
   8.249 +    } else {
   8.250 +        data->format = texture->format;
   8.251 +    }
   8.252 +    data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format));
   8.253 +
   8.254 +    if (data->yuv || texture->access == SDL_TextureAccess_Local
   8.255 +        || texture->format != SDL_GetCurrentDisplayMode()->format) {
   8.256 +        int bmi_size;
   8.257 +        LPBITMAPINFO bmi;
   8.258 +
   8.259 +        bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
   8.260 +        bmi = (LPBITMAPINFO) SDL_malloc(bmi_size);
   8.261 +        if (!bmi) {
   8.262 +            SDL_GDI_DestroyTexture(renderer, texture);
   8.263 +            SDL_OutOfMemory();
   8.264 +            return -1;
   8.265 +        }
   8.266 +        SDL_memset(bmi, 0, bmi_size);
   8.267 +        bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
   8.268 +        bmi->bmiHeader.biWidth = texture->w;
   8.269 +        bmi->bmiHeader.biHeight = -texture->h;  /* topdown bitmap */
   8.270 +        bmi->bmiHeader.biPlanes = 1;
   8.271 +        bmi->bmiHeader.biSizeImage = texture->h * data->pitch;
   8.272 +        bmi->bmiHeader.biXPelsPerMeter = 0;
   8.273 +        bmi->bmiHeader.biYPelsPerMeter = 0;
   8.274 +        bmi->bmiHeader.biClrUsed = 0;
   8.275 +        bmi->bmiHeader.biClrImportant = 0;
   8.276 +        bmi->bmiHeader.biBitCount = SDL_BYTESPERPIXEL(data->format) * 8;
   8.277 +        if (SDL_ISPIXELFORMAT_INDEXED(data->format)) {
   8.278 +            int i, ncolors;
   8.279 +            LOGPALETTE *palette;
   8.280 +
   8.281 +            bmi->bmiHeader.biCompression = BI_RGB;
   8.282 +            ncolors = (1 << SDL_BITSPERPIXEL(data->format));
   8.283 +            palette =
   8.284 +                (LOGPALETTE *) SDL_malloc(sizeof(*palette) +
   8.285 +                                          ncolors * sizeof(PALETTEENTRY));
   8.286 +            if (!palette) {
   8.287 +                SDL_free(bmi);
   8.288 +                SDL_GDI_DestroyTexture(renderer, texture);
   8.289 +                SDL_OutOfMemory();
   8.290 +                return -1;
   8.291 +            }
   8.292 +            palette->palVersion = 0x300;
   8.293 +            palette->palNumEntries = ncolors;
   8.294 +            for (i = 0; i < ncolors; ++i) {
   8.295 +                palette->palPalEntry[i].peRed = 0xFF;
   8.296 +                palette->palPalEntry[i].peGreen = 0xFF;
   8.297 +                palette->palPalEntry[i].peBlue = 0xFF;
   8.298 +                palette->palPalEntry[i].peFlags = 0;
   8.299 +            }
   8.300 +            data->hpal = CreatePalette(palette);
   8.301 +            SDL_free(palette);
   8.302 +        } else {
   8.303 +            int bpp;
   8.304 +            Uint32 Rmask, Gmask, Bmask, Amask;
   8.305 +
   8.306 +            bmi->bmiHeader.biCompression = BI_BITFIELDS;
   8.307 +            SDL_PixelFormatEnumToMasks(data->format, &bpp, &Rmask, &Gmask,
   8.308 +                                       &Bmask, &Amask);
   8.309 +            ((Uint32 *) bmi->bmiColors)[0] = Rmask;
   8.310 +            ((Uint32 *) bmi->bmiColors)[1] = Gmask;
   8.311 +            ((Uint32 *) bmi->bmiColors)[2] = Bmask;
   8.312 +            data->hpal = NULL;
   8.313 +        }
   8.314 +        data->hbm =
   8.315 +            CreateDIBSection(renderdata->memory_hdc, bmi, DIB_RGB_COLORS,
   8.316 +                             &data->pixels, NULL, 0);
   8.317 +    } else {
   8.318 +        data->hbm =
   8.319 +            CreateCompatibleBitmap(renderdata->window_hdc, texture->w,
   8.320 +                                   texture->h);
   8.321 +        data->pixels = NULL;
   8.322 +    }
   8.323 +    if (!data->hbm) {
   8.324 +        SDL_GDI_DestroyTexture(renderer, texture);
   8.325 +        WIN_SetError("Couldn't create bitmap");
   8.326 +        return -1;
   8.327 +    }
   8.328 +    return 0;
   8.329 +}
   8.330 +
   8.331 +static int
   8.332 +SDL_GDI_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
   8.333 +                           void **pixels, int *pitch)
   8.334 +{
   8.335 +    SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata;
   8.336 +
   8.337 +    if (data->yuv) {
   8.338 +        return SDL_SW_QueryYUVTexturePixels(data->yuv, pixels, pitch);
   8.339 +    } else {
   8.340 +        *pixels = data->pixels;
   8.341 +        *pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
   8.342 +        return 0;
   8.343 +    }
   8.344 +}
   8.345 +
   8.346 +static int
   8.347 +SDL_GDI_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
   8.348 +                          const SDL_Color * colors, int firstcolor,
   8.349 +                          int ncolors)
   8.350 +{
   8.351 +    SDL_GDI_RenderData *renderdata =
   8.352 +        (SDL_GDI_RenderData *) renderer->driverdata;
   8.353 +    SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata;
   8.354 +
   8.355 +    if (data->yuv) {
   8.356 +        SDL_SetError("YUV textures don't have a palette");
   8.357 +        return -1;
   8.358 +    } else {
   8.359 +        PALETTEENTRY entries[256];
   8.360 +        int i;
   8.361 +
   8.362 +        for (i = 0; i < ncolors; ++i) {
   8.363 +            entries[i].peRed = colors[i].r;
   8.364 +            entries[i].peGreen = colors[i].g;
   8.365 +            entries[i].peBlue = colors[i].b;
   8.366 +            entries[i].peFlags = 0;
   8.367 +        }
   8.368 +        if (!SetPaletteEntries(data->hpal, firstcolor, ncolors, entries)) {
   8.369 +            WIN_SetError("SetPaletteEntries()");
   8.370 +            return -1;
   8.371 +        }
   8.372 +        return 0;
   8.373 +    }
   8.374 +}
   8.375 +
   8.376 +static int
   8.377 +SDL_GDI_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
   8.378 +                          SDL_Color * colors, int firstcolor, int ncolors)
   8.379 +{
   8.380 +    SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata;
   8.381 +
   8.382 +    if (data->yuv) {
   8.383 +        SDL_SetError("YUV textures don't have a palette");
   8.384 +        return -1;
   8.385 +    } else {
   8.386 +        PALETTEENTRY entries[256];
   8.387 +        int i;
   8.388 +
   8.389 +        if (!GetPaletteEntries(data->hpal, firstcolor, ncolors, entries)) {
   8.390 +            WIN_SetError("GetPaletteEntries()");
   8.391 +            return -1;
   8.392 +        }
   8.393 +        for (i = 0; i < ncolors; ++i) {
   8.394 +            colors[i].r = entries[i].peRed;
   8.395 +            colors[i].g = entries[i].peGreen;
   8.396 +            colors[i].b = entries[i].peBlue;
   8.397 +        }
   8.398 +        return 0;
   8.399 +    }
   8.400 +}
   8.401 +
   8.402 +static int
   8.403 +SDL_GDI_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   8.404 +                      const SDL_Rect * rect, const void *pixels, int pitch)
   8.405 +{
   8.406 +    SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata;
   8.407 +
   8.408 +    if (data->yuv) {
   8.409 +        if (SDL_SW_UpdateYUVTexture(data->yuv, rect, pixels, pitch) < 0) {
   8.410 +            return -1;
   8.411 +        }
   8.412 +        UpdateYUVTextureData(texture);
   8.413 +        return 0;
   8.414 +    } else {
   8.415 +        SDL_GDI_RenderData *renderdata =
   8.416 +            (SDL_GDI_RenderData *) renderer->driverdata;
   8.417 +
   8.418 +        if (data->pixels) {
   8.419 +            Uint8 *src, *dst;
   8.420 +            int row;
   8.421 +            size_t length;
   8.422 +
   8.423 +            src = (Uint8 *) pixels;
   8.424 +            dst =
   8.425 +                (Uint8 *) data->pixels + rect->y * data->pitch +
   8.426 +                rect->x * SDL_BYTESPERPIXEL(texture->format);
   8.427 +            length = rect->w * SDL_BYTESPERPIXEL(texture->format);
   8.428 +            for (row = 0; row < rect->h; ++row) {
   8.429 +                SDL_memcpy(dst, src, length);
   8.430 +                src += pitch;
   8.431 +                dst += data->pitch;
   8.432 +            }
   8.433 +        } else if (rect->w == texture->w && pitch == data->pitch) {
   8.434 +            if (!SetDIBits
   8.435 +                (renderdata->window_hdc, data->hbm, rect->y, rect->h, pixels,
   8.436 +                 renderdata->bmi, DIB_RGB_COLORS)) {
   8.437 +                WIN_SetError("SetDIBits()");
   8.438 +                return -1;
   8.439 +            }
   8.440 +        } else {
   8.441 +            SDL_SetError
   8.442 +                ("FIXME: Need to allocate temporary memory and do GetDIBits() followed by SetDIBits(), since we can only set blocks of scanlines at a time");
   8.443 +            return -1;
   8.444 +        }
   8.445 +        return 0;
   8.446 +    }
   8.447 +}
   8.448 +
   8.449 +static int
   8.450 +SDL_GDI_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   8.451 +                    const SDL_Rect * rect, int markDirty, void **pixels,
   8.452 +                    int *pitch)
   8.453 +{
   8.454 +    SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata;
   8.455 +
   8.456 +    if (data->yuv) {
   8.457 +        return SDL_SW_LockYUVTexture(data->yuv, rect, markDirty, pixels,
   8.458 +                                     pitch);
   8.459 +    } else {
   8.460 +        GdiFlush();
   8.461 +        *pixels =
   8.462 +            (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
   8.463 +                      rect->x * SDL_BYTESPERPIXEL(texture->format));
   8.464 +        *pitch = data->pitch;
   8.465 +        return 0;
   8.466 +    }
   8.467 +}
   8.468 +
   8.469 +static void
   8.470 +SDL_GDI_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   8.471 +{
   8.472 +    SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata;
   8.473 +
   8.474 +    if (data->yuv) {
   8.475 +        SDL_SW_UnlockYUVTexture(data->yuv);
   8.476 +        UpdateYUVTextureData(texture);
   8.477 +    }
   8.478 +}
   8.479 +
   8.480 +static void
   8.481 +SDL_GDI_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   8.482 +                     int numrects, const SDL_Rect * rects)
   8.483 +{
   8.484 +}
   8.485 +
   8.486 +static void
   8.487 +SDL_GDI_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   8.488 +{
   8.489 +    SDL_GDI_RenderData *data = (SDL_GDI_RenderData *) renderer->driverdata;
   8.490 +
   8.491 +    if (texture) {
   8.492 +        SDL_GDI_TextureData *texturedata =
   8.493 +            (SDL_GDI_TextureData *) texture->driverdata;
   8.494 +        SelectObject(data->render_hdc, texturedata->hbm);
   8.495 +        if (texturedata->hpal) {
   8.496 +            SelectPalette(data->render_hdc, texturedata->hpal, TRUE);
   8.497 +            RealizePalette(data->render_hdc);
   8.498 +        }
   8.499 +        data->current_hdc = data->render_hdc;
   8.500 +    } else {
   8.501 +        data->current_hdc = data->current_hdc;
   8.502 +    }
   8.503 +}
   8.504 +
   8.505 +static int
   8.506 +SDL_GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
   8.507 +                   Uint32 color)
   8.508 +{
   8.509 +    SDL_GDI_RenderData *data = (SDL_GDI_RenderData *) renderer->driverdata;
   8.510 +    Uint8 r, g, b;
   8.511 +    RECT rc;
   8.512 +    static HBRUSH brush;
   8.513 +    int status;
   8.514 +
   8.515 +    r = (Uint8) ((color >> 16) & 0xFF);
   8.516 +    g = (Uint8) ((color >> 8) & 0xFF);
   8.517 +    b = (Uint8) (color & 0xFF);
   8.518 +
   8.519 +    rc.left = rect->x;
   8.520 +    rc.top = rect->y;
   8.521 +    rc.right = rect->x + rect->w + 1;
   8.522 +    rc.bottom = rect->y + rect->h + 1;
   8.523 +
   8.524 +    /* Should we cache the brushes? .. it looks like GDI does for us. :) */
   8.525 +    brush = CreateSolidBrush(RGB(r, g, b));
   8.526 +    SelectObject(data->current_hdc, brush);
   8.527 +    status = FillRect(data->current_hdc, &rc, brush);
   8.528 +    DeleteObject(brush);
   8.529 +
   8.530 +    if (!status) {
   8.531 +        WIN_SetError("FillRect()");
   8.532 +        return -1;
   8.533 +    }
   8.534 +    return 0;
   8.535 +}
   8.536 +
   8.537 +static int
   8.538 +SDL_GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   8.539 +                   const SDL_Rect * srcrect, const SDL_Rect * dstrect,
   8.540 +                   int blendMode, int scaleMode)
   8.541 +{
   8.542 +    SDL_GDI_RenderData *data = (SDL_GDI_RenderData *) renderer->driverdata;
   8.543 +    SDL_GDI_TextureData *texturedata =
   8.544 +        (SDL_GDI_TextureData *) texture->driverdata;
   8.545 +
   8.546 +    SelectObject(data->memory_hdc, texturedata->hbm);
   8.547 +    if (texturedata->hpal) {
   8.548 +        SelectPalette(data->memory_hdc, texturedata->hpal, TRUE);
   8.549 +        RealizePalette(data->memory_hdc);
   8.550 +    }
   8.551 +    if (blendMode & (SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend)) {
   8.552 +        static BLENDFUNCTION blendFunc = {
   8.553 +            AC_SRC_OVER,
   8.554 +            0,
   8.555 +            255,
   8.556 +            AC_SRC_ALPHA
   8.557 +        };
   8.558 +        /* FIXME: GDI uses premultiplied alpha! */
   8.559 +        if (!AlphaBlend
   8.560 +            (data->current_hdc, dstrect->x, dstrect->y, dstrect->w,
   8.561 +             dstrect->h, data->memory_hdc, srcrect->x, srcrect->y, srcrect->w,
   8.562 +             srcrect->h, blendFunc)) {
   8.563 +            WIN_SetError("AlphaBlend()");
   8.564 +            return -1;
   8.565 +        }
   8.566 +    } else {
   8.567 +        if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
   8.568 +            if (!BitBlt
   8.569 +                (data->current_hdc, dstrect->x, dstrect->y, dstrect->w,
   8.570 +                 srcrect->h, data->memory_hdc, srcrect->x, srcrect->y,
   8.571 +                 SRCCOPY)) {
   8.572 +                WIN_SetError("BitBlt()");
   8.573 +                return -1;
   8.574 +            }
   8.575 +        } else {
   8.576 +            if (!StretchBlt
   8.577 +                (data->current_hdc, dstrect->x, dstrect->y, dstrect->w,
   8.578 +                 dstrect->h, data->memory_hdc, srcrect->x, srcrect->y,
   8.579 +                 srcrect->w, srcrect->h, SRCCOPY)) {
   8.580 +                WIN_SetError("StretchBlt()");
   8.581 +                return -1;
   8.582 +            }
   8.583 +        }
   8.584 +    }
   8.585 +    return 0;
   8.586 +}
   8.587 +
   8.588 +static int
   8.589 +CreateWindowDIB(SDL_GDI_RenderData * data, SDL_Window * window)
   8.590 +{
   8.591 +    data->window_pitch = window->w * (data->bmi->bmiHeader.biBitCount / 8);
   8.592 +    data->bmi->bmiHeader.biWidth = window->w;
   8.593 +    data->bmi->bmiHeader.biHeight = -window->h;
   8.594 +    data->bmi->bmiHeader.biSizeImage =
   8.595 +        window->h * (data->bmi->bmiHeader.biBitCount / 8);
   8.596 +    data->window_bmp =
   8.597 +        CreateDIBSection(data->window_hdc, data->bmi, DIB_RGB_COLORS,
   8.598 +                         &data->window_pixels, NULL, 0);
   8.599 +    if (!data->window_bmp) {
   8.600 +        WIN_SetError("CreateDIBSection()");
   8.601 +        return -1;
   8.602 +    }
   8.603 +    return 0;
   8.604 +}
   8.605 +
   8.606 +static int
   8.607 +SDL_GDI_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   8.608 +                         void *pixels, int pitch)
   8.609 +{
   8.610 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   8.611 +    SDL_GDI_RenderData *data = (SDL_GDI_RenderData *) renderer->driverdata;
   8.612 +
   8.613 +    if (!data->window_bmp) {
   8.614 +        if (CreateWindowDIB(data, window) < 0) {
   8.615 +            return -1;
   8.616 +        }
   8.617 +    }
   8.618 +
   8.619 +    SelectObject(data->memory_hdc, data->window_bmp);
   8.620 +    BitBlt(data->memory_hdc, rect->x, rect->y, rect->w, rect->h,
   8.621 +           data->window_hdc, rect->x, rect->y, SRCCOPY);
   8.622 +
   8.623 +    {
   8.624 +        int bpp = data->bmi->bmiHeader.biBitCount / 8;
   8.625 +        Uint8 *src =
   8.626 +            (Uint8 *) data->window_pixels + rect->y * data->window_pitch +
   8.627 +            rect->x * bpp;
   8.628 +        Uint8 *dst = (Uint8 *) pixels;
   8.629 +        int row;
   8.630 +
   8.631 +        for (row = 0; row < rect->h; ++row) {
   8.632 +            SDL_memcpy(dst, src, rect->w * bpp);
   8.633 +            src += data->window_pitch;
   8.634 +            dst += pitch;
   8.635 +        }
   8.636 +    }
   8.637 +
   8.638 +    return 0;
   8.639 +}
   8.640 +
   8.641 +static int
   8.642 +SDL_GDI_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   8.643 +                          const void *pixels, int pitch)
   8.644 +{
   8.645 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   8.646 +    SDL_GDI_RenderData *data = (SDL_GDI_RenderData *) renderer->driverdata;
   8.647 +
   8.648 +    if (!data->window_bmp) {
   8.649 +        if (CreateWindowDIB(data, window) < 0) {
   8.650 +            return -1;
   8.651 +        }
   8.652 +    }
   8.653 +
   8.654 +    {
   8.655 +        int bpp = data->bmi->bmiHeader.biBitCount / 8;
   8.656 +        Uint8 *src = (Uint8 *) pixels;
   8.657 +        Uint8 *dst =
   8.658 +            (Uint8 *) data->window_pixels + rect->y * data->window_pitch +
   8.659 +            rect->x * bpp;
   8.660 +        int row;
   8.661 +
   8.662 +        for (row = 0; row < rect->h; ++row) {
   8.663 +            SDL_memcpy(dst, src, rect->w * bpp);
   8.664 +            src += pitch;
   8.665 +            dst += data->window_pitch;
   8.666 +        }
   8.667 +    }
   8.668 +
   8.669 +    SelectObject(data->memory_hdc, data->window_bmp);
   8.670 +    BitBlt(data->window_hdc, rect->x, rect->y, rect->w, rect->h,
   8.671 +           data->memory_hdc, rect->x, rect->y, SRCCOPY);
   8.672 +
   8.673 +    return 0;
   8.674 +}
   8.675 +
   8.676 +static void
   8.677 +SDL_GDI_RenderPresent(SDL_Renderer * renderer)
   8.678 +{
   8.679 +}
   8.680 +
   8.681 +static void
   8.682 +SDL_GDI_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   8.683 +{
   8.684 +    SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata;
   8.685 +
   8.686 +    if (!data) {
   8.687 +        return;
   8.688 +    }
   8.689 +    if (data->yuv) {
   8.690 +        SDL_SW_DestroyYUVTexture(data->yuv);
   8.691 +    }
   8.692 +    if (data->hpal) {
   8.693 +        DeleteObject(data->hpal);
   8.694 +    }
   8.695 +    if (data->hbm) {
   8.696 +        DeleteObject(data->hbm);
   8.697 +    }
   8.698 +    SDL_free(data);
   8.699 +    texture->driverdata = NULL;
   8.700 +}
   8.701 +
   8.702 +void
   8.703 +SDL_GDI_DestroyRenderer(SDL_Renderer * renderer)
   8.704 +{
   8.705 +    SDL_GDI_RenderData *data = (SDL_GDI_RenderData *) renderer->driverdata;
   8.706 +
   8.707 +    if (data) {
   8.708 +        ReleaseDC(data->hwnd, data->window_hdc);
   8.709 +        DeleteDC(data->render_hdc);
   8.710 +        DeleteDC(data->memory_hdc);
   8.711 +        if (data->bmi) {
   8.712 +            SDL_free(data->bmi);
   8.713 +        }
   8.714 +        if (data->window_bmp) {
   8.715 +            DeleteObject(data->window_bmp);
   8.716 +        }
   8.717 +        SDL_free(data);
   8.718 +    }
   8.719 +    SDL_free(renderer);
   8.720 +}
   8.721 +
   8.722 +#endif /* SDL_VIDEO_RENDER_GDI */
   8.723 +
   8.724 +/* vi: set ts=4 sw=4 expandtab: */
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/video/win32/SDL_gdirender.h	Sat Jul 08 18:06:02 2006 +0000
     9.3 @@ -0,0 +1,30 @@
     9.4 +/*
     9.5 +    SDL - Simple DirectMedia Layer
     9.6 +    Copyright (C) 1997-2006 Sam Lantinga
     9.7 +
     9.8 +    This library is free software; you can redistribute it and/or
     9.9 +    modify it under the terms of the GNU Lesser General Public
    9.10 +    License as published by the Free Software Foundation; either
    9.11 +    version 2.1 of the License, or (at your option) any later version.
    9.12 +
    9.13 +    This library is distributed in the hope that it will be useful,
    9.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    9.16 +    Lesser General Public License for more details.
    9.17 +
    9.18 +    You should have received a copy of the GNU Lesser General Public
    9.19 +    License along with this library; if not, write to the Free Software
    9.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    9.21 +
    9.22 +    Sam Lantinga
    9.23 +    slouken@libsdl.org
    9.24 +*/
    9.25 +#include "SDL_config.h"
    9.26 +
    9.27 +/* SDL surface based renderer implementation */
    9.28 +
    9.29 +#if SDL_VIDEO_RENDER_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/win32/SDL_win32video.c	Fri Jul 07 10:39:33 2006 +0000
    10.2 +++ b/src/video/win32/SDL_win32video.c	Sat Jul 08 18:06:02 2006 +0000
    10.3 @@ -28,7 +28,8 @@
    10.4  #include "../SDL_pixels_c.h"
    10.5  
    10.6  #include "SDL_win32video.h"
    10.7 -#include "SDL_dibrender.h"
    10.8 +#include "SDL_d3drender.h"
    10.9 +#include "SDL_gdirender.h"
   10.10  
   10.11  /* Initialization/Query functions */
   10.12  static int WIN_VideoInit(_THIS);
   10.13 @@ -45,7 +46,15 @@
   10.14  static void
   10.15  WIN_DeleteDevice(SDL_VideoDevice * device)
   10.16  {
   10.17 +    SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
   10.18 +
   10.19      SDL_UnregisterApp();
   10.20 +#if SDL_VIDEO_RENDER_D3D
   10.21 +    if (data->d3d) {
   10.22 +        IDirect3D9_Release(data->d3d);
   10.23 +        FreeLibrary(data->d3dDLL);
   10.24 +    }
   10.25 +#endif
   10.26      SDL_free(device->driverdata);
   10.27      SDL_free(device);
   10.28  }
   10.29 @@ -54,22 +63,41 @@
   10.30  WIN_CreateDevice(int devindex)
   10.31  {
   10.32      SDL_VideoDevice *device;
   10.33 +    SDL_VideoData *data;
   10.34  
   10.35      SDL_RegisterApp(NULL, 0, NULL);
   10.36  
   10.37      /* Initialize all variables that we clean on shutdown */
   10.38      device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
   10.39      if (device) {
   10.40 -        device->driverdata =
   10.41 -            (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
   10.42 +        data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
   10.43      }
   10.44 -    if (!device || !device->driverdata) {
   10.45 +    if (!device || !data) {
   10.46          SDL_OutOfMemory();
   10.47          if (device) {
   10.48              SDL_free(device);
   10.49          }
   10.50          return NULL;
   10.51      }
   10.52 +    device->driverdata = data;
   10.53 +
   10.54 +#if SDL_VIDEO_RENDER_D3D
   10.55 +    data->d3dDLL = LoadLibrary(TEXT("D3D9.DLL"));
   10.56 +    if (data->d3dDLL) {
   10.57 +        IDirect3D9 *WINAPI(*D3DCreate) (UINT SDKVersion);
   10.58 +
   10.59 +        D3DCreate =
   10.60 +            (IDirect3D9 * WINAPI(*)(UINT)) GetProcAddress(data->d3dDLL,
   10.61 +                                                          "Direct3DCreate9");
   10.62 +        if (D3DCreate) {
   10.63 +            data->d3d = D3DCreate(D3D_SDK_VERSION);
   10.64 +        }
   10.65 +        if (!data->d3d) {
   10.66 +            FreeLibrary(data->d3dDLL);
   10.67 +            data->d3dDLL = NULL;
   10.68 +        }
   10.69 +    }
   10.70 +#endif /* SDL_VIDEO_RENDER_D3D */
   10.71  
   10.72      /* Set the function pointers */
   10.73      device->VideoInit = WIN_VideoInit;
   10.74 @@ -108,7 +136,13 @@
   10.75  WIN_VideoInit(_THIS)
   10.76  {
   10.77      WIN_InitModes(_this);
   10.78 -    SDL_AddRenderDriver(0, &SDL_DIB_RenderDriver);
   10.79 +
   10.80 +#if SDL_VIDEO_RENDER_GDI
   10.81 +    GDI_AddRenderDriver(_this);
   10.82 +#endif
   10.83 +#if SDL_VIDEO_RENDER_D3D
   10.84 +    D3D_AddRenderDriver(_this);
   10.85 +#endif
   10.86  
   10.87      WIN_InitKeyboard(_this);
   10.88      WIN_InitMouse(_this);
    11.1 --- a/src/video/win32/SDL_win32video.h	Fri Jul 07 10:39:33 2006 +0000
    11.2 +++ b/src/video/win32/SDL_win32video.h	Sat Jul 08 18:06:02 2006 +0000
    11.3 @@ -28,9 +28,13 @@
    11.4  
    11.5  #define WIN32_LEAN_AND_MEAN
    11.6  #define UNICODE
    11.7 -#define WINVER  0x500           // Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices()
    11.8 +#define WINVER  0x500           /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices() */
    11.9  #include <windows.h>
   11.10  
   11.11 +#if SDL_VIDEO_RENDER_D3D
   11.12 +#include <d3d9.h>
   11.13 +#endif
   11.14 +
   11.15  #include "SDL_win32events.h"
   11.16  #include "SDL_win32keyboard.h"
   11.17  #include "SDL_win32modes.h"
   11.18 @@ -49,6 +53,10 @@
   11.19  
   11.20  typedef struct SDL_VideoData
   11.21  {
   11.22 +#if SDL_VIDEO_RENDER_D3D
   11.23 +    HANDLE d3dDLL;
   11.24 +    IDirect3D9 *d3d;
   11.25 +#endif
   11.26      int mouse;
   11.27      int keyboard;
   11.28  } SDL_VideoData;