Prefer the D3D renderer over GDI, at least for testing.
authorSam Lantinga <slouken@libsdl.org>
Fri, 14 Jul 2006 08:22:45 +0000
changeset 190536d52b1f0504
parent 1904 1a713f9d1f71
child 1906 0c49855a7a3e
Prefer the D3D renderer over GDI, at least for testing.
Added support for the SDL_VIDEO_RENDERER environment variable to pick the desired render driver.
Implemented WritePixels support for the D3D renderer.
src/video/SDL_video.c
src/video/win32/SDL_d3drender.c
src/video/win32/SDL_gdirender.c
src/video/win32/SDL_win32video.c
     1.1 --- a/src/video/SDL_video.c	Fri Jul 14 07:41:16 2006 +0000
     1.2 +++ b/src/video/SDL_video.c	Fri Jul 14 08:22:45 2006 +0000
     1.3 @@ -1296,18 +1296,25 @@
     1.4      }
     1.5  
     1.6      if (index < 0) {
     1.7 +        const char *override = SDL_getenv("SDL_VIDEO_RENDERER");
     1.8          int n = SDL_GetNumRenderers();
     1.9          for (index = 0; index < n; ++index) {
    1.10              SDL_RenderDriver *driver =
    1.11                  &SDL_CurrentDisplay.render_drivers[index];
    1.12  
    1.13 -            /* Skip minimal drivers in automatic scans */
    1.14 -            if (!(flags & SDL_Renderer_Minimal)
    1.15 -                && (driver->info.flags & SDL_Renderer_Minimal)) {
    1.16 -                continue;
    1.17 -            }
    1.18 -            if ((driver->info.flags & flags) == flags) {
    1.19 -                break;
    1.20 +            if (override) {
    1.21 +                if (SDL_strcasecmp(override, driver->info.name) == 0) {
    1.22 +                    break;
    1.23 +                }
    1.24 +            } else {
    1.25 +                /* Skip minimal drivers in automatic scans */
    1.26 +                if (!(flags & SDL_Renderer_Minimal)
    1.27 +                    && (driver->info.flags & SDL_Renderer_Minimal)) {
    1.28 +                    continue;
    1.29 +                }
    1.30 +                if ((driver->info.flags & flags) == flags) {
    1.31 +                    break;
    1.32 +                }
    1.33              }
    1.34          }
    1.35          if (index == n) {
     2.1 --- a/src/video/win32/SDL_d3drender.c	Fri Jul 14 07:41:16 2006 +0000
     2.2 +++ b/src/video/win32/SDL_d3drender.c	Fri Jul 14 08:22:45 2006 +0000
     2.3 @@ -74,10 +74,9 @@
     2.4      SDL_D3D_CreateRenderer,
     2.5      {
     2.6       "d3d",
     2.7 -     (                          //SDL_Renderer_Minimal |
     2.8 -         SDL_Renderer_SingleBuffer | SDL_Renderer_PresentCopy |
     2.9 -         SDL_Renderer_PresentFlip2 | SDL_Renderer_PresentFlip3 |
    2.10 -         SDL_Renderer_PresentDiscard | SDL_Renderer_RenderTarget),
    2.11 +     (SDL_Renderer_SingleBuffer | SDL_Renderer_PresentCopy |
    2.12 +      SDL_Renderer_PresentFlip2 | SDL_Renderer_PresentFlip3 |
    2.13 +      SDL_Renderer_PresentDiscard | SDL_Renderer_RenderTarget),
    2.14       (SDL_TextureBlendMode_None |
    2.15        SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend),
    2.16       (SDL_TextureScaleMode_None | SDL_TextureScaleMode_Fast),
    2.17 @@ -102,6 +101,8 @@
    2.18  typedef struct
    2.19  {
    2.20      IDirect3DDevice9 *device;
    2.21 +    IDirect3DSurface9 *surface;
    2.22 +    IDirect3DSurface9 *offscreen;
    2.23      SDL_bool beginScene;
    2.24  } SDL_D3D_RenderData;
    2.25  
    2.26 @@ -530,6 +531,8 @@
    2.27  SDL_D3D_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture)
    2.28  {
    2.29      SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
    2.30 +
    2.31 +    /* FIXME */
    2.32  }
    2.33  
    2.34  static int
    2.35 @@ -640,6 +643,7 @@
    2.36  {
    2.37      SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
    2.38  
    2.39 +    /* FIXME */
    2.40      return 0;
    2.41  }
    2.42  
    2.43 @@ -647,7 +651,75 @@
    2.44  SDL_D3D_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
    2.45                            const void *pixels, int pitch)
    2.46  {
    2.47 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
    2.48 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
    2.49      SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
    2.50 +    RECT d3drect;
    2.51 +    POINT point;
    2.52 +    D3DLOCKED_RECT locked;
    2.53 +    const Uint8 *src;
    2.54 +    Uint8 *dst;
    2.55 +    int row, length;
    2.56 +    HRESULT result;
    2.57 +
    2.58 +    if (!data->surface) {
    2.59 +        result =
    2.60 +            IDirect3DDevice9_GetBackBuffer(data->device, 0, 0,
    2.61 +                                           D3DBACKBUFFER_TYPE_MONO,
    2.62 +                                           &data->surface);
    2.63 +        if (FAILED(result)) {
    2.64 +            D3D_SetError("GetBackBuffer()", result);
    2.65 +            return -1;
    2.66 +        }
    2.67 +    }
    2.68 +    if (!data->offscreen) {
    2.69 +        result =
    2.70 +            IDirect3DDevice9_CreateOffscreenPlainSurface(data->device,
    2.71 +                                                         window->w, window->h,
    2.72 +                                                         PixelFormatToD3DFMT
    2.73 +                                                         (display->
    2.74 +                                                          current_mode.
    2.75 +                                                          format),
    2.76 +                                                         D3DPOOL_SYSTEMMEM,
    2.77 +                                                         &data->offscreen,
    2.78 +                                                         NULL);
    2.79 +        if (FAILED(result)) {
    2.80 +            D3D_SetError("CreateOffscreenPlainSurface()", result);
    2.81 +            return -1;
    2.82 +        }
    2.83 +    }
    2.84 +
    2.85 +    d3drect.left = rect->x;
    2.86 +    d3drect.right = rect->x + rect->w;
    2.87 +    d3drect.top = rect->y;
    2.88 +    d3drect.bottom = rect->y + rect->h;
    2.89 +
    2.90 +    result =
    2.91 +        IDirect3DSurface9_LockRect(data->offscreen, &locked, &d3drect, 0);
    2.92 +    if (FAILED(result)) {
    2.93 +        D3D_SetError("LockRect()", result);
    2.94 +        return -1;
    2.95 +    }
    2.96 +
    2.97 +    src = pixels;
    2.98 +    dst = locked.pBits;
    2.99 +    length = rect->w * SDL_BYTESPERPIXEL(display->current_mode.format);
   2.100 +    for (row = 0; row < rect->h; ++row) {
   2.101 +        SDL_memcpy(dst, src, length);
   2.102 +        src += pitch;
   2.103 +        dst += locked.Pitch;
   2.104 +    }
   2.105 +    IDirect3DSurface9_UnlockRect(data->offscreen);
   2.106 +
   2.107 +    point.x = rect->x;
   2.108 +    point.y = rect->y;
   2.109 +    result =
   2.110 +        IDirect3DDevice9_UpdateSurface(data->device, data->offscreen,
   2.111 +                                       &d3drect, data->surface, &point);
   2.112 +    if (FAILED(result)) {
   2.113 +        D3D_SetError("UpdateSurface()", result);
   2.114 +        return -1;
   2.115 +    }
   2.116  
   2.117      return 0;
   2.118  }
   2.119 @@ -693,6 +765,12 @@
   2.120          if (data->device) {
   2.121              IDirect3DDevice9_Release(data->device);
   2.122          }
   2.123 +        if (data->surface) {
   2.124 +            IDirect3DSurface9_Release(data->surface);
   2.125 +        }
   2.126 +        if (data->offscreen) {
   2.127 +            IDirect3DSurface9_Release(data->offscreen);
   2.128 +        }
   2.129          SDL_free(data);
   2.130      }
   2.131      SDL_free(renderer);
     3.1 --- a/src/video/win32/SDL_gdirender.c	Fri Jul 14 07:41:16 2006 +0000
     3.2 +++ b/src/video/win32/SDL_gdirender.c	Fri Jul 14 08:22:45 2006 +0000
     3.3 @@ -79,8 +79,7 @@
     3.4      SDL_GDI_CreateRenderer,
     3.5      {
     3.6       "gdi",
     3.7 -     (SDL_Renderer_Minimal |
     3.8 -      SDL_Renderer_SingleBuffer | SDL_Renderer_PresentCopy |
     3.9 +     (SDL_Renderer_SingleBuffer | SDL_Renderer_PresentCopy |
    3.10        SDL_Renderer_PresentFlip2 | SDL_Renderer_PresentFlip3 |
    3.11        SDL_Renderer_PresentDiscard | SDL_Renderer_RenderTarget),
    3.12       (SDL_TextureBlendMode_None | SDL_TextureBlendMode_Mask |
     4.1 --- a/src/video/win32/SDL_win32video.c	Fri Jul 14 07:41:16 2006 +0000
     4.2 +++ b/src/video/win32/SDL_win32video.c	Fri Jul 14 08:22:45 2006 +0000
     4.3 @@ -140,12 +140,12 @@
     4.4  {
     4.5      WIN_InitModes(_this);
     4.6  
     4.7 +#if SDL_VIDEO_RENDER_D3D
     4.8 +    D3D_AddRenderDriver(_this);
     4.9 +#endif
    4.10  #if SDL_VIDEO_RENDER_GDI
    4.11      GDI_AddRenderDriver(_this);
    4.12  #endif
    4.13 -#if SDL_VIDEO_RENDER_D3D
    4.14 -    D3D_AddRenderDriver(_this);
    4.15 -#endif
    4.16  
    4.17      WIN_InitKeyboard(_this);
    4.18      WIN_InitMouse(_this);