Mercurial > sdl-ios-xcode
changeset 1730:e70477157db9 SDL-1.3
Starting support for Direct3D render driver.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 08 Jul 2006 18:06:02 +0000 |
parents | 0ef52d56e8bb |
children | 875c3cf1a12c |
files | 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 |
diffstat | 11 files changed, 1239 insertions(+), 751 deletions(-) [+] |
line wrap: on
line diff
--- a/configure.in Fri Jul 07 10:39:33 2006 +0000 +++ b/configure.in Sat Jul 08 18:06:02 2006 +0000 @@ -1861,12 +1861,6 @@ if test x$enable_stdio_redirect != xyes; then EXTRA_CFLAGS="$EXTRA_CFLAGS -DNO_STDIO_REDIRECT" fi - - if test x$enable_video = xyes; then - AC_DEFINE(SDL_VIDEO_DRIVER_WIN32) - SOURCES="$SOURCES $srcdir/src/video/win32/*.c" - have_video=yes - fi } dnl Find the DirectX includes and libraries @@ -1876,6 +1870,7 @@ AC_HELP_STRING([--enable-directx], [use DirectX for Win32 audio/video [[default=yes]]]), , enable_directx=yes) if test x$enable_directx = xyes; then + AC_CHECK_HEADER(d3d9.h, have_d3d=yes) AC_CHECK_HEADER(dsound.h, have_dsound=yes) AC_CHECK_HEADER(dinput.h, use_dinput=yes) fi @@ -2298,6 +2293,24 @@ CheckglSDL CheckDIRECTX CheckNASM + # Set up files for the video library + if test x$enable_video = xyes; then + AC_DEFINE(SDL_VIDEO_DRIVER_WIN32) + SOURCES="$SOURCES $srcdir/src/video/win32/*.c" + have_video=yes + AC_ARG_ENABLE(render-gdi, +AC_HELP_STRING([--enable-render-gdi], [enable the GDI render driver [[default=yes]]]), + , enable_render_gdi=yes) + if test x$enable_render_gdi = xyes; then + AC_DEFINE(SDL_VIDEO_RENDER_GDI) + fi + AC_ARG_ENABLE(render-d3d, +AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[default=yes]]]), + , enable_render_d3d=yes) + if test x$enable_render_d3d = xyes -a x$have_d3d = xyes; then + AC_DEFINE(SDL_VIDEO_RENDER_D3D) + fi + fi # Set up files for the audio library if test x$enable_audio = xyes; then AC_DEFINE(SDL_AUDIO_DRIVER_WAVEOUT)
--- a/include/SDL_config.h.in Fri Jul 07 10:39:33 2006 +0000 +++ b/include/SDL_config.h.in Sat Jul 08 18:06:02 2006 +0000 @@ -291,6 +291,10 @@ #undef SDL_VIDEO_DRIVER_X11_XV #undef SDL_VIDEO_DRIVER_XBIOS +#undef SDL_VIDEO_RENDER_D3D +#undef SDL_VIDEO_RENDER_GDI +#undef SDL_VIDEO_RENDER_OGL + /* Enable OpenGL support */ #undef SDL_VIDEO_OPENGL #undef SDL_VIDEO_OPENGL_GLX
--- a/include/SDL_config_win32.h Fri Jul 07 10:39:33 2006 +0000 +++ b/include/SDL_config_win32.h Sat Jul 08 18:06:02 2006 +0000 @@ -153,10 +153,14 @@ #define SDL_VIDEO_DRIVER_DUMMY 1 #define SDL_VIDEO_DRIVER_WIN32 1 +#define SDL_VIDEO_RENDER_D3D 1 +#define SDL_VIDEO_RENDER_GDI 1 + /* Enable OpenGL support */ #ifndef _WIN32_WCE #define SDL_VIDEO_OPENGL 1 #define SDL_VIDEO_OPENGL_WGL 1 +#define SDL_VIDEO_RENDER_OGL 1 #endif /* Enable assembly routines (Win64 doesn't have inline asm) */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/win32/SDL_d3drender.c Sat Jul 08 18:06:02 2006 +0000 @@ -0,0 +1,385 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#if SDL_VIDEO_RENDER_D3D + +#include "SDL_win32video.h" +#include "../SDL_yuv_sw_c.h" + +/* Direct3D renderer implementation */ + +static SDL_Renderer *SDL_D3D_CreateRenderer(SDL_Window * window, + Uint32 flags); +static int SDL_D3D_CreateTexture(SDL_Renderer * renderer, + SDL_Texture * texture); +static int SDL_D3D_QueryTexturePixels(SDL_Renderer * renderer, + SDL_Texture * texture, void **pixels, + int *pitch); +static int SDL_D3D_SetTexturePalette(SDL_Renderer * renderer, + SDL_Texture * texture, + const SDL_Color * colors, int firstcolor, + int ncolors); +static int SDL_D3D_GetTexturePalette(SDL_Renderer * renderer, + SDL_Texture * texture, + SDL_Color * colors, int firstcolor, + int ncolors); +static int SDL_D3D_UpdateTexture(SDL_Renderer * renderer, + SDL_Texture * texture, const SDL_Rect * rect, + const void *pixels, int pitch); +static int SDL_D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, int markDirty, + void **pixels, int *pitch); +static void SDL_D3D_UnlockTexture(SDL_Renderer * renderer, + SDL_Texture * texture); +static void SDL_D3D_DirtyTexture(SDL_Renderer * renderer, + SDL_Texture * texture, int numrects, + const SDL_Rect * rects); +static void SDL_D3D_SelectRenderTexture(SDL_Renderer * renderer, + SDL_Texture * texture); +static int SDL_D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, + Uint32 color); +static int SDL_D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * srcrect, + const SDL_Rect * dstrect, int blendMode, + int scaleMode); +static int SDL_D3D_RenderReadPixels(SDL_Renderer * renderer, + const SDL_Rect * rect, void *pixels, + int pitch); +static int SDL_D3D_RenderWritePixels(SDL_Renderer * renderer, + const SDL_Rect * rect, + const void *pixels, int pitch); +static void SDL_D3D_RenderPresent(SDL_Renderer * renderer); +static void SDL_D3D_DestroyTexture(SDL_Renderer * renderer, + SDL_Texture * texture); +static void SDL_D3D_DestroyRenderer(SDL_Renderer * renderer); + + +SDL_RenderDriver SDL_D3D_RenderDriver = { + SDL_D3D_CreateRenderer, + { + "d3d", + (SDL_Renderer_PresentDiscard | + SDL_Renderer_PresentCopy | SDL_Renderer_RenderTarget), + (SDL_TextureBlendMode_None | + SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend), + (SDL_TextureScaleMode_None | SDL_TextureScaleMode_Fast), + 11, + { + SDL_PixelFormat_Index8, + SDL_PixelFormat_RGB555, + SDL_PixelFormat_RGB565, + SDL_PixelFormat_RGB888, + SDL_PixelFormat_BGR888, + SDL_PixelFormat_ARGB8888, + SDL_PixelFormat_RGBA8888, + SDL_PixelFormat_ABGR8888, + SDL_PixelFormat_BGRA8888, + SDL_PixelFormat_YUY2, + SDL_PixelFormat_UYVY}, + 0, + 0} +}; + +typedef struct +{ + IDirect3DDevice9 *device; +} SDL_D3D_RenderData; + +typedef struct +{ + SDL_SW_YUVTexture *yuv; +} SDL_D3D_TextureData; + +static void +UpdateYUVTextureData(SDL_Texture * texture) +{ + SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata; + SDL_Rect rect; + + rect.x = 0; + rect.y = 0; + rect.w = texture->w; + rect.h = texture->h; + //SDL_SW_CopyYUVToRGB(data->yuv, &rect, data->format, texture->w, + // texture->h, data->pixels, data->pitch); +} + +void +D3D_AddRenderDriver(_THIS) +{ + SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; + + if (data->d3d) { + SDL_AddRenderDriver(0, &SDL_D3D_RenderDriver); + } +} + +SDL_Renderer * +SDL_D3D_CreateRenderer(SDL_Window * window, Uint32 flags) +{ + SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); + SDL_VideoData *videodata = (SDL_VideoData *) display->device->driverdata; + SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata; + SDL_Renderer *renderer; + SDL_D3D_RenderData *data; + + renderer = (SDL_Renderer *) SDL_malloc(sizeof(*renderer)); + if (!renderer) { + SDL_OutOfMemory(); + return NULL; + } + SDL_zerop(renderer); + + data = (SDL_D3D_RenderData *) SDL_malloc(sizeof(*data)); + if (!data) { + SDL_D3D_DestroyRenderer(renderer); + SDL_OutOfMemory(); + return NULL; + } + SDL_zerop(data); + + //data->device = IDirect3D9_CreateDevice(videodata->d3d, + + renderer->CreateTexture = SDL_D3D_CreateTexture; + renderer->QueryTexturePixels = SDL_D3D_QueryTexturePixels; + renderer->SetTexturePalette = SDL_D3D_SetTexturePalette; + renderer->GetTexturePalette = SDL_D3D_GetTexturePalette; + renderer->UpdateTexture = SDL_D3D_UpdateTexture; + renderer->LockTexture = SDL_D3D_LockTexture; + renderer->UnlockTexture = SDL_D3D_UnlockTexture; + renderer->DirtyTexture = SDL_D3D_DirtyTexture; + renderer->SelectRenderTexture = SDL_D3D_SelectRenderTexture; + renderer->RenderFill = SDL_D3D_RenderFill; + renderer->RenderCopy = SDL_D3D_RenderCopy; + renderer->RenderReadPixels = SDL_D3D_RenderReadPixels; + renderer->RenderWritePixels = SDL_D3D_RenderWritePixels; + renderer->RenderPresent = SDL_D3D_RenderPresent; + renderer->DestroyTexture = SDL_D3D_DestroyTexture; + renderer->DestroyRenderer = SDL_D3D_DestroyRenderer; + renderer->info = SDL_D3D_RenderDriver.info; + renderer->window = window->id; + renderer->driverdata = data; + + renderer->info.flags = SDL_Renderer_RenderTarget; + + return renderer; +} + +static int +SDL_D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) +{ + SDL_D3D_RenderData *renderdata = + (SDL_D3D_RenderData *) renderer->driverdata; + SDL_Window *window = SDL_GetWindowFromID(renderer->window); + SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); + SDL_D3D_TextureData *data; + + data = (SDL_D3D_TextureData *) SDL_malloc(sizeof(*data)); + if (!data) { + SDL_OutOfMemory(); + return -1; + } + SDL_zerop(data); + + texture->driverdata = data; + + return 0; +} + +static int +SDL_D3D_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, + void **pixels, int *pitch) +{ + SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata; + + if (data->yuv) { + return SDL_SW_QueryYUVTexturePixels(data->yuv, pixels, pitch); + } else { + return 0; + } +} + +static int +SDL_D3D_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Color * colors, int firstcolor, + int ncolors) +{ + SDL_D3D_RenderData *renderdata = + (SDL_D3D_RenderData *) renderer->driverdata; + SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata; + + if (data->yuv) { + SDL_SetError("YUV textures don't have a palette"); + return -1; + } else { + return 0; + } +} + +static int +SDL_D3D_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, + SDL_Color * colors, int firstcolor, int ncolors) +{ + SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata; + + if (data->yuv) { + SDL_SetError("YUV textures don't have a palette"); + return -1; + } else { + return 0; + } +} + +static int +SDL_D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, const void *pixels, int pitch) +{ + SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata; + + if (data->yuv) { + if (SDL_SW_UpdateYUVTexture(data->yuv, rect, pixels, pitch) < 0) { + return -1; + } + UpdateYUVTextureData(texture); + return 0; + } else { + SDL_D3D_RenderData *renderdata = + (SDL_D3D_RenderData *) renderer->driverdata; + + return 0; + } +} + +static int +SDL_D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, int markDirty, void **pixels, + int *pitch) +{ + SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata; + + if (data->yuv) { + return SDL_SW_LockYUVTexture(data->yuv, rect, markDirty, pixels, + pitch); + } else { + return 0; + } +} + +static void +SDL_D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) +{ + SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata; + + if (data->yuv) { + SDL_SW_UnlockYUVTexture(data->yuv); + UpdateYUVTextureData(texture); + } +} + +static void +SDL_D3D_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, + int numrects, const SDL_Rect * rects) +{ +} + +static void +SDL_D3D_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture) +{ + SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata; +} + +static int +SDL_D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, + Uint32 color) +{ + SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata; + Uint8 r, g, b; + + r = (Uint8) ((color >> 16) & 0xFF); + g = (Uint8) ((color >> 8) & 0xFF); + b = (Uint8) (color & 0xFF); + + return 0; +} + +static int +SDL_D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * srcrect, const SDL_Rect * dstrect, + int blendMode, int scaleMode) +{ + SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata; + SDL_D3D_TextureData *texturedata = + (SDL_D3D_TextureData *) texture->driverdata; + + return 0; +} + +static int +SDL_D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, + void *pixels, int pitch) +{ + SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata; + + return 0; +} + +static int +SDL_D3D_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, + const void *pixels, int pitch) +{ + SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata; + + return 0; +} + +static void +SDL_D3D_RenderPresent(SDL_Renderer * renderer) +{ +} + +static void +SDL_D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) +{ + SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata; + + if (!data) { + return; + } + SDL_free(data); + texture->driverdata = NULL; +} + +void +SDL_D3D_DestroyRenderer(SDL_Renderer * renderer) +{ + SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata; + + if (data) { + SDL_free(data); + } + SDL_free(renderer); +} + +#endif /* SDL_VIDEO_RENDER_D3D */ + +/* vi: set ts=4 sw=4 expandtab: */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/win32/SDL_d3drender.h Sat Jul 08 18:06:02 2006 +0000 @@ -0,0 +1,28 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#if SDL_VIDEO_RENDER_D3D +extern void D3D_AddRenderDriver(_THIS); +#endif + +/* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/win32/SDL_dibrender.c Fri Jul 07 10:39:33 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,711 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2006 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#include "SDL_win32video.h" -#include "../SDL_yuv_sw_c.h" - -/* GDI renderer implementation */ - -static SDL_Renderer *SDL_DIB_CreateRenderer(SDL_Window * window, - Uint32 flags); -static int SDL_DIB_CreateTexture(SDL_Renderer * renderer, - SDL_Texture * texture); -static int SDL_DIB_QueryTexturePixels(SDL_Renderer * renderer, - SDL_Texture * texture, void **pixels, - int *pitch); -static int SDL_DIB_SetTexturePalette(SDL_Renderer * renderer, - SDL_Texture * texture, - const SDL_Color * colors, int firstcolor, - int ncolors); -static int SDL_DIB_GetTexturePalette(SDL_Renderer * renderer, - SDL_Texture * texture, - SDL_Color * colors, int firstcolor, - int ncolors); -static int SDL_DIB_UpdateTexture(SDL_Renderer * renderer, - SDL_Texture * texture, const SDL_Rect * rect, - const void *pixels, int pitch); -static int SDL_DIB_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, int markDirty, - void **pixels, int *pitch); -static void SDL_DIB_UnlockTexture(SDL_Renderer * renderer, - SDL_Texture * texture); -static void SDL_DIB_DirtyTexture(SDL_Renderer * renderer, - SDL_Texture * texture, int numrects, - const SDL_Rect * rects); -static void SDL_DIB_SelectRenderTexture(SDL_Renderer * renderer, - SDL_Texture * texture); -static int SDL_DIB_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 color); -static int SDL_DIB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, - const SDL_Rect * dstrect, int blendMode, - int scaleMode); -static int SDL_DIB_RenderReadPixels(SDL_Renderer * renderer, - const SDL_Rect * rect, void *pixels, - int pitch); -static int SDL_DIB_RenderWritePixels(SDL_Renderer * renderer, - const SDL_Rect * rect, - const void *pixels, int pitch); -static void SDL_DIB_RenderPresent(SDL_Renderer * renderer); -static void SDL_DIB_DestroyTexture(SDL_Renderer * renderer, - SDL_Texture * texture); -static void SDL_DIB_DestroyRenderer(SDL_Renderer * renderer); - - -SDL_RenderDriver SDL_DIB_RenderDriver = { - SDL_DIB_CreateRenderer, - { - "gdi", - (SDL_Renderer_PresentDiscard | - SDL_Renderer_PresentCopy | SDL_Renderer_RenderTarget), - (SDL_TextureBlendMode_None | - SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend), - (SDL_TextureScaleMode_None | SDL_TextureScaleMode_Fast), - 11, - { - SDL_PixelFormat_Index8, - SDL_PixelFormat_RGB555, - SDL_PixelFormat_RGB565, - SDL_PixelFormat_RGB888, - SDL_PixelFormat_BGR888, - SDL_PixelFormat_ARGB8888, - SDL_PixelFormat_RGBA8888, - SDL_PixelFormat_ABGR8888, - SDL_PixelFormat_BGRA8888, - SDL_PixelFormat_YUY2, - SDL_PixelFormat_UYVY}, - 0, - 0} -}; - -typedef struct -{ - HWND hwnd; - HDC window_hdc; - HDC render_hdc; - HDC memory_hdc; - HDC current_hdc; - LPBITMAPINFO bmi; - HBITMAP window_bmp; - void *window_pixels; - int window_pitch; -} SDL_DIB_RenderData; - -typedef struct -{ - SDL_SW_YUVTexture *yuv; - Uint32 format; - HPALETTE hpal; - HBITMAP hbm; - void *pixels; - int pitch; -} SDL_DIB_TextureData; - -static void -UpdateYUVTextureData(SDL_Texture * texture) -{ - SDL_DIB_TextureData *data = (SDL_DIB_TextureData *) texture->driverdata; - SDL_Rect rect; - - rect.x = 0; - rect.y = 0; - rect.w = texture->w; - rect.h = texture->h; - SDL_SW_CopyYUVToRGB(data->yuv, &rect, data->format, texture->w, - texture->h, data->pixels, data->pitch); -} - -SDL_Renderer * -SDL_DIB_CreateRenderer(SDL_Window * window, Uint32 flags) -{ - SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata; - SDL_Renderer *renderer; - SDL_DIB_RenderData *data; - int bmi_size; - HBITMAP hbm; - - renderer = (SDL_Renderer *) SDL_malloc(sizeof(*renderer)); - if (!renderer) { - SDL_OutOfMemory(); - return NULL; - } - SDL_zerop(renderer); - - data = (SDL_DIB_RenderData *) SDL_malloc(sizeof(*data)); - if (!data) { - SDL_DIB_DestroyRenderer(renderer); - SDL_OutOfMemory(); - return NULL; - } - SDL_zerop(data); - - data->hwnd = windowdata->hwnd; - data->window_hdc = GetDC(data->hwnd); - data->render_hdc = CreateCompatibleDC(data->window_hdc); - data->memory_hdc = CreateCompatibleDC(data->window_hdc); - data->current_hdc = data->window_hdc; - - /* Fill in the compatible bitmap info */ - bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD); - data->bmi = (LPBITMAPINFO) SDL_malloc(bmi_size); - if (!data->bmi) { - SDL_DIB_DestroyRenderer(renderer); - SDL_OutOfMemory(); - return NULL; - } - SDL_memset(data->bmi, 0, bmi_size); - data->bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - - hbm = CreateCompatibleBitmap(data->window_hdc, 1, 1); - GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS); - GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS); - DeleteObject(hbm); - - renderer->CreateTexture = SDL_DIB_CreateTexture; - renderer->QueryTexturePixels = SDL_DIB_QueryTexturePixels; - renderer->SetTexturePalette = SDL_DIB_SetTexturePalette; - renderer->GetTexturePalette = SDL_DIB_GetTexturePalette; - renderer->UpdateTexture = SDL_DIB_UpdateTexture; - renderer->LockTexture = SDL_DIB_LockTexture; - renderer->UnlockTexture = SDL_DIB_UnlockTexture; - renderer->DirtyTexture = SDL_DIB_DirtyTexture; - renderer->SelectRenderTexture = SDL_DIB_SelectRenderTexture; - renderer->RenderFill = SDL_DIB_RenderFill; - renderer->RenderCopy = SDL_DIB_RenderCopy; - renderer->RenderReadPixels = SDL_DIB_RenderReadPixels; - renderer->RenderWritePixels = SDL_DIB_RenderWritePixels; - renderer->RenderPresent = SDL_DIB_RenderPresent; - renderer->DestroyTexture = SDL_DIB_DestroyTexture; - renderer->DestroyRenderer = SDL_DIB_DestroyRenderer; - renderer->info = SDL_DIB_RenderDriver.info; - renderer->window = window->id; - renderer->driverdata = data; - - renderer->info.flags = SDL_Renderer_RenderTarget; - - return renderer; -} - -static int -SDL_DIB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - SDL_DIB_RenderData *renderdata = - (SDL_DIB_RenderData *) renderer->driverdata; - SDL_Window *window = SDL_GetWindowFromID(renderer->window); - SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); - SDL_DIB_TextureData *data; - - data = (SDL_DIB_TextureData *) SDL_malloc(sizeof(*data)); - if (!data) { - SDL_OutOfMemory(); - return -1; - } - SDL_zerop(data); - - texture->driverdata = data; - - if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { - if (texture->access == SDL_TextureAccess_Render) { - SDL_SetError("Rendering to YUV format textures is not supported"); - return -1; - } - data->yuv = SDL_SW_CreateYUVTexture(texture); - if (!data->yuv) { - SDL_DIB_DestroyTexture(renderer, texture); - return -1; - } - data->format = display->current_mode.format; - } else { - data->format = texture->format; - } - data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format)); - - if (data->yuv || texture->access == SDL_TextureAccess_Local - || texture->format != SDL_GetCurrentDisplayMode()->format) { - int bmi_size; - LPBITMAPINFO bmi; - - bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD); - bmi = (LPBITMAPINFO) SDL_malloc(bmi_size); - if (!bmi) { - SDL_DIB_DestroyTexture(renderer, texture); - SDL_OutOfMemory(); - return -1; - } - SDL_memset(bmi, 0, bmi_size); - bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bmi->bmiHeader.biWidth = texture->w; - bmi->bmiHeader.biHeight = -texture->h; /* topdown bitmap */ - bmi->bmiHeader.biPlanes = 1; - bmi->bmiHeader.biSizeImage = texture->h * data->pitch; - bmi->bmiHeader.biXPelsPerMeter = 0; - bmi->bmiHeader.biYPelsPerMeter = 0; - bmi->bmiHeader.biClrUsed = 0; - bmi->bmiHeader.biClrImportant = 0; - bmi->bmiHeader.biBitCount = SDL_BYTESPERPIXEL(data->format) * 8; - if (SDL_ISPIXELFORMAT_INDEXED(data->format)) { - int i, ncolors; - LOGPALETTE *palette; - - bmi->bmiHeader.biCompression = BI_RGB; - ncolors = (1 << SDL_BITSPERPIXEL(data->format)); - palette = - (LOGPALETTE *) SDL_malloc(sizeof(*palette) + - ncolors * sizeof(PALETTEENTRY)); - if (!palette) { - SDL_free(bmi); - SDL_DIB_DestroyTexture(renderer, texture); - SDL_OutOfMemory(); - return -1; - } - palette->palVersion = 0x300; - palette->palNumEntries = ncolors; - for (i = 0; i < ncolors; ++i) { - palette->palPalEntry[i].peRed = 0xFF; - palette->palPalEntry[i].peGreen = 0xFF; - palette->palPalEntry[i].peBlue = 0xFF; - palette->palPalEntry[i].peFlags = 0; - } - data->hpal = CreatePalette(palette); - SDL_free(palette); - } else { - int bpp; - Uint32 Rmask, Gmask, Bmask, Amask; - - bmi->bmiHeader.biCompression = BI_BITFIELDS; - SDL_PixelFormatEnumToMasks(data->format, &bpp, &Rmask, &Gmask, - &Bmask, &Amask); - ((Uint32 *) bmi->bmiColors)[0] = Rmask; - ((Uint32 *) bmi->bmiColors)[1] = Gmask; - ((Uint32 *) bmi->bmiColors)[2] = Bmask; - data->hpal = NULL; - } - data->hbm = - CreateDIBSection(renderdata->memory_hdc, bmi, DIB_RGB_COLORS, - &data->pixels, NULL, 0); - } else { - data->hbm = - CreateCompatibleBitmap(renderdata->window_hdc, texture->w, - texture->h); - data->pixels = NULL; - } - if (!data->hbm) { - SDL_DIB_DestroyTexture(renderer, texture); - WIN_SetError("Couldn't create bitmap"); - return -1; - } - return 0; -} - -static int -SDL_DIB_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, - void **pixels, int *pitch) -{ - SDL_DIB_TextureData *data = (SDL_DIB_TextureData *) texture->driverdata; - - if (data->yuv) { - return SDL_SW_QueryYUVTexturePixels(data->yuv, pixels, pitch); - } else { - *pixels = data->pixels; - *pitch = texture->w * SDL_BYTESPERPIXEL(texture->format); - return 0; - } -} - -static int -SDL_DIB_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Color * colors, int firstcolor, - int ncolors) -{ - SDL_DIB_RenderData *renderdata = - (SDL_DIB_RenderData *) renderer->driverdata; - SDL_DIB_TextureData *data = (SDL_DIB_TextureData *) texture->driverdata; - - if (data->yuv) { - SDL_SetError("YUV textures don't have a palette"); - return -1; - } else { - PALETTEENTRY entries[256]; - int i; - - for (i = 0; i < ncolors; ++i) { - entries[i].peRed = colors[i].r; - entries[i].peGreen = colors[i].g; - entries[i].peBlue = colors[i].b; - entries[i].peFlags = 0; - } - if (!SetPaletteEntries(data->hpal, firstcolor, ncolors, entries)) { - WIN_SetError("SetPaletteEntries()"); - return -1; - } - return 0; - } -} - -static int -SDL_DIB_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, - SDL_Color * colors, int firstcolor, int ncolors) -{ - SDL_DIB_TextureData *data = (SDL_DIB_TextureData *) texture->driverdata; - - if (data->yuv) { - SDL_SetError("YUV textures don't have a palette"); - return -1; - } else { - PALETTEENTRY entries[256]; - int i; - - if (!GetPaletteEntries(data->hpal, firstcolor, ncolors, entries)) { - WIN_SetError("GetPaletteEntries()"); - return -1; - } - for (i = 0; i < ncolors; ++i) { - colors[i].r = entries[i].peRed; - colors[i].g = entries[i].peGreen; - colors[i].b = entries[i].peBlue; - } - return 0; - } -} - -static int -SDL_DIB_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *pixels, int pitch) -{ - SDL_DIB_TextureData *data = (SDL_DIB_TextureData *) texture->driverdata; - - if (data->yuv) { - if (SDL_SW_UpdateYUVTexture(data->yuv, rect, pixels, pitch) < 0) { - return -1; - } - UpdateYUVTextureData(texture); - return 0; - } else { - SDL_DIB_RenderData *renderdata = - (SDL_DIB_RenderData *) renderer->driverdata; - - if (data->pixels) { - Uint8 *src, *dst; - int row; - size_t length; - - src = (Uint8 *) pixels; - dst = - (Uint8 *) data->pixels + rect->y * data->pitch + - rect->x * SDL_BYTESPERPIXEL(texture->format); - length = rect->w * SDL_BYTESPERPIXEL(texture->format); - for (row = 0; row < rect->h; ++row) { - SDL_memcpy(dst, src, length); - src += pitch; - dst += data->pitch; - } - } else if (rect->w == texture->w && pitch == data->pitch) { - if (!SetDIBits - (renderdata->window_hdc, data->hbm, rect->y, rect->h, pixels, - renderdata->bmi, DIB_RGB_COLORS)) { - WIN_SetError("SetDIBits()"); - return -1; - } - } else { - SDL_SetError - ("FIXME: Need to allocate temporary memory and do GetDIBits() followed by SetDIBits(), since we can only set blocks of scanlines at a time"); - return -1; - } - return 0; - } -} - -static int -SDL_DIB_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, int markDirty, void **pixels, - int *pitch) -{ - SDL_DIB_TextureData *data = (SDL_DIB_TextureData *) texture->driverdata; - - if (data->yuv) { - return SDL_SW_LockYUVTexture(data->yuv, rect, markDirty, pixels, - pitch); - } else { - GdiFlush(); - *pixels = - (void *) ((Uint8 *) data->pixels + rect->y * data->pitch + - rect->x * SDL_BYTESPERPIXEL(texture->format)); - *pitch = data->pitch; - return 0; - } -} - -static void -SDL_DIB_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - SDL_DIB_TextureData *data = (SDL_DIB_TextureData *) texture->driverdata; - - if (data->yuv) { - SDL_SW_UnlockYUVTexture(data->yuv); - UpdateYUVTextureData(texture); - } -} - -static void -SDL_DIB_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, - int numrects, const SDL_Rect * rects) -{ -} - -static void -SDL_DIB_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - SDL_DIB_RenderData *data = (SDL_DIB_RenderData *) renderer->driverdata; - - if (texture) { - SDL_DIB_TextureData *texturedata = - (SDL_DIB_TextureData *) texture->driverdata; - SelectObject(data->render_hdc, texturedata->hbm); - if (texturedata->hpal) { - SelectPalette(data->render_hdc, texturedata->hpal, TRUE); - RealizePalette(data->render_hdc); - } - data->current_hdc = data->render_hdc; - } else { - data->current_hdc = data->current_hdc; - } -} - -static int -SDL_DIB_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 color) -{ - SDL_DIB_RenderData *data = (SDL_DIB_RenderData *) renderer->driverdata; - Uint8 r, g, b; - RECT rc; - static HBRUSH brush; - int status; - - r = (Uint8) ((color >> 16) & 0xFF); - g = (Uint8) ((color >> 8) & 0xFF); - b = (Uint8) (color & 0xFF); - - rc.left = rect->x; - rc.top = rect->y; - rc.right = rect->x + rect->w + 1; - rc.bottom = rect->y + rect->h + 1; - - /* Should we cache the brushes? .. it looks like GDI does for us. :) */ - brush = CreateSolidBrush(RGB(r, g, b)); - SelectObject(data->current_hdc, brush); - status = FillRect(data->current_hdc, &rc, brush); - DeleteObject(brush); - - if (!status) { - WIN_SetError("FillRect()"); - return -1; - } - return 0; -} - -static int -SDL_DIB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_Rect * dstrect, - int blendMode, int scaleMode) -{ - SDL_DIB_RenderData *data = (SDL_DIB_RenderData *) renderer->driverdata; - SDL_DIB_TextureData *texturedata = - (SDL_DIB_TextureData *) texture->driverdata; - - SelectObject(data->memory_hdc, texturedata->hbm); - if (texturedata->hpal) { - SelectPalette(data->memory_hdc, texturedata->hpal, TRUE); - RealizePalette(data->memory_hdc); - } - if (blendMode & (SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend)) { - static BLENDFUNCTION blendFunc = { - AC_SRC_OVER, - 0, - 255, - AC_SRC_ALPHA - }; - /* FIXME: GDI uses premultiplied alpha! */ - if (!AlphaBlend - (data->current_hdc, dstrect->x, dstrect->y, dstrect->w, - dstrect->h, data->memory_hdc, srcrect->x, srcrect->y, srcrect->w, - srcrect->h, blendFunc)) { - WIN_SetError("AlphaBlend()"); - return -1; - } - } else { - if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) { - if (!BitBlt - (data->current_hdc, dstrect->x, dstrect->y, dstrect->w, - srcrect->h, data->memory_hdc, srcrect->x, srcrect->y, - SRCCOPY)) { - WIN_SetError("BitBlt()"); - return -1; - } - } else { - if (!StretchBlt - (data->current_hdc, dstrect->x, dstrect->y, dstrect->w, - dstrect->h, data->memory_hdc, srcrect->x, srcrect->y, - srcrect->w, srcrect->h, SRCCOPY)) { - WIN_SetError("StretchBlt()"); - return -1; - } - } - } - return 0; -} - -static int -CreateWindowDIB(SDL_DIB_RenderData * data, SDL_Window * window) -{ - data->window_pitch = window->w * (data->bmi->bmiHeader.biBitCount / 8); - data->bmi->bmiHeader.biWidth = window->w; - data->bmi->bmiHeader.biHeight = -window->h; - data->bmi->bmiHeader.biSizeImage = - window->h * (data->bmi->bmiHeader.biBitCount / 8); - data->window_bmp = - CreateDIBSection(data->window_hdc, data->bmi, DIB_RGB_COLORS, - &data->window_pixels, NULL, 0); - if (!data->window_bmp) { - WIN_SetError("CreateDIBSection()"); - return -1; - } - return 0; -} - -static int -SDL_DIB_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - void *pixels, int pitch) -{ - SDL_Window *window = SDL_GetWindowFromID(renderer->window); - SDL_DIB_RenderData *data = (SDL_DIB_RenderData *) renderer->driverdata; - - if (!data->window_bmp) { - if (CreateWindowDIB(data, window) < 0) { - return -1; - } - } - - SelectObject(data->memory_hdc, data->window_bmp); - BitBlt(data->memory_hdc, rect->x, rect->y, rect->w, rect->h, - data->window_hdc, rect->x, rect->y, SRCCOPY); - - { - int bpp = data->bmi->bmiHeader.biBitCount / 8; - Uint8 *src = - (Uint8 *) data->window_pixels + rect->y * data->window_pitch + - rect->x * bpp; - Uint8 *dst = (Uint8 *) pixels; - int row; - - for (row = 0; row < rect->h; ++row) { - SDL_memcpy(dst, src, rect->w * bpp); - src += data->window_pitch; - dst += pitch; - } - } - - return 0; -} - -static int -SDL_DIB_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, - const void *pixels, int pitch) -{ - SDL_Window *window = SDL_GetWindowFromID(renderer->window); - SDL_DIB_RenderData *data = (SDL_DIB_RenderData *) renderer->driverdata; - - if (!data->window_bmp) { - if (CreateWindowDIB(data, window) < 0) { - return -1; - } - } - - { - int bpp = data->bmi->bmiHeader.biBitCount / 8; - Uint8 *src = (Uint8 *) pixels; - Uint8 *dst = - (Uint8 *) data->window_pixels + rect->y * data->window_pitch + - rect->x * bpp; - int row; - - for (row = 0; row < rect->h; ++row) { - SDL_memcpy(dst, src, rect->w * bpp); - src += pitch; - dst += data->window_pitch; - } - } - - SelectObject(data->memory_hdc, data->window_bmp); - BitBlt(data->window_hdc, rect->x, rect->y, rect->w, rect->h, - data->memory_hdc, rect->x, rect->y, SRCCOPY); - - return 0; -} - -static void -SDL_DIB_RenderPresent(SDL_Renderer * renderer) -{ -} - -static void -SDL_DIB_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - SDL_DIB_TextureData *data = (SDL_DIB_TextureData *) texture->driverdata; - - if (!data) { - return; - } - if (data->yuv) { - SDL_SW_DestroyYUVTexture(data->yuv); - } - if (data->hpal) { - DeleteObject(data->hpal); - } - if (data->hbm) { - DeleteObject(data->hbm); - } - SDL_free(data); - texture->driverdata = NULL; -} - -void -SDL_DIB_DestroyRenderer(SDL_Renderer * renderer) -{ - SDL_DIB_RenderData *data = (SDL_DIB_RenderData *) renderer->driverdata; - - if (data) { - ReleaseDC(data->hwnd, data->window_hdc); - DeleteDC(data->render_hdc); - DeleteDC(data->memory_hdc); - if (data->bmi) { - SDL_free(data->bmi); - } - if (data->window_bmp) { - DeleteObject(data->window_bmp); - } - SDL_free(data); - } - SDL_free(renderer); -} - -/* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/win32/SDL_dibrender.h Fri Jul 07 10:39:33 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2006 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -/* SDL surface based renderer implementation */ - -extern SDL_RenderDriver SDL_DIB_RenderDriver; - -/* vi: set ts=4 sw=4 expandtab: */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/win32/SDL_gdirender.c Sat Jul 08 18:06:02 2006 +0000 @@ -0,0 +1,721 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#if SDL_VIDEO_RENDER_GDI + +#include "SDL_win32video.h" +#include "../SDL_yuv_sw_c.h" + +/* GDI renderer implementation */ + +static SDL_Renderer *SDL_GDI_CreateRenderer(SDL_Window * window, + Uint32 flags); +static int SDL_GDI_CreateTexture(SDL_Renderer * renderer, + SDL_Texture * texture); +static int SDL_GDI_QueryTexturePixels(SDL_Renderer * renderer, + SDL_Texture * texture, void **pixels, + int *pitch); +static int SDL_GDI_SetTexturePalette(SDL_Renderer * renderer, + SDL_Texture * texture, + const SDL_Color * colors, int firstcolor, + int ncolors); +static int SDL_GDI_GetTexturePalette(SDL_Renderer * renderer, + SDL_Texture * texture, + SDL_Color * colors, int firstcolor, + int ncolors); +static int SDL_GDI_UpdateTexture(SDL_Renderer * renderer, + SDL_Texture * texture, const SDL_Rect * rect, + const void *pixels, int pitch); +static int SDL_GDI_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, int markDirty, + void **pixels, int *pitch); +static void SDL_GDI_UnlockTexture(SDL_Renderer * renderer, + SDL_Texture * texture); +static void SDL_GDI_DirtyTexture(SDL_Renderer * renderer, + SDL_Texture * texture, int numrects, + const SDL_Rect * rects); +static void SDL_GDI_SelectRenderTexture(SDL_Renderer * renderer, + SDL_Texture * texture); +static int SDL_GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, + Uint32 color); +static int SDL_GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * srcrect, + const SDL_Rect * dstrect, int blendMode, + int scaleMode); +static int SDL_GDI_RenderReadPixels(SDL_Renderer * renderer, + const SDL_Rect * rect, void *pixels, + int pitch); +static int SDL_GDI_RenderWritePixels(SDL_Renderer * renderer, + const SDL_Rect * rect, + const void *pixels, int pitch); +static void SDL_GDI_RenderPresent(SDL_Renderer * renderer); +static void SDL_GDI_DestroyTexture(SDL_Renderer * renderer, + SDL_Texture * texture); +static void SDL_GDI_DestroyRenderer(SDL_Renderer * renderer); + + +SDL_RenderDriver SDL_GDI_RenderDriver = { + SDL_GDI_CreateRenderer, + { + "gdi", + (SDL_Renderer_PresentDiscard | + SDL_Renderer_PresentCopy | SDL_Renderer_RenderTarget), + (SDL_TextureBlendMode_None | + SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend), + (SDL_TextureScaleMode_None | SDL_TextureScaleMode_Fast), + 11, + { + SDL_PixelFormat_Index8, + SDL_PixelFormat_RGB555, + SDL_PixelFormat_RGB565, + SDL_PixelFormat_RGB888, + SDL_PixelFormat_BGR888, + SDL_PixelFormat_ARGB8888, + SDL_PixelFormat_RGBA8888, + SDL_PixelFormat_ABGR8888, + SDL_PixelFormat_BGRA8888, + SDL_PixelFormat_YUY2, + SDL_PixelFormat_UYVY}, + 0, + 0} +}; + +typedef struct +{ + HWND hwnd; + HDC window_hdc; + HDC render_hdc; + HDC memory_hdc; + HDC current_hdc; + LPBITMAPINFO bmi; + HBITMAP window_bmp; + void *window_pixels; + int window_pitch; +} SDL_GDI_RenderData; + +typedef struct +{ + SDL_SW_YUVTexture *yuv; + Uint32 format; + HPALETTE hpal; + HBITMAP hbm; + void *pixels; + int pitch; +} SDL_GDI_TextureData; + +static void +UpdateYUVTextureData(SDL_Texture * texture) +{ + SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata; + SDL_Rect rect; + + rect.x = 0; + rect.y = 0; + rect.w = texture->w; + rect.h = texture->h; + SDL_SW_CopyYUVToRGB(data->yuv, &rect, data->format, texture->w, + texture->h, data->pixels, data->pitch); +} + +void +GDI_AddRenderDriver(_THIS) +{ + SDL_AddRenderDriver(0, &SDL_GDI_RenderDriver); +} + +SDL_Renderer * +SDL_GDI_CreateRenderer(SDL_Window * window, Uint32 flags) +{ + SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata; + SDL_Renderer *renderer; + SDL_GDI_RenderData *data; + int bmi_size; + HBITMAP hbm; + + renderer = (SDL_Renderer *) SDL_malloc(sizeof(*renderer)); + if (!renderer) { + SDL_OutOfMemory(); + return NULL; + } + SDL_zerop(renderer); + + data = (SDL_GDI_RenderData *) SDL_malloc(sizeof(*data)); + if (!data) { + SDL_GDI_DestroyRenderer(renderer); + SDL_OutOfMemory(); + return NULL; + } + SDL_zerop(data); + + data->hwnd = windowdata->hwnd; + data->window_hdc = GetDC(data->hwnd); + data->render_hdc = CreateCompatibleDC(data->window_hdc); + data->memory_hdc = CreateCompatibleDC(data->window_hdc); + data->current_hdc = data->window_hdc; + + /* Fill in the compatible bitmap info */ + bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD); + data->bmi = (LPBITMAPINFO) SDL_malloc(bmi_size); + if (!data->bmi) { + SDL_GDI_DestroyRenderer(renderer); + SDL_OutOfMemory(); + return NULL; + } + SDL_memset(data->bmi, 0, bmi_size); + data->bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + + hbm = CreateCompatibleBitmap(data->window_hdc, 1, 1); + GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS); + GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS); + DeleteObject(hbm); + + renderer->CreateTexture = SDL_GDI_CreateTexture; + renderer->QueryTexturePixels = SDL_GDI_QueryTexturePixels; + renderer->SetTexturePalette = SDL_GDI_SetTexturePalette; + renderer->GetTexturePalette = SDL_GDI_GetTexturePalette; + renderer->UpdateTexture = SDL_GDI_UpdateTexture; + renderer->LockTexture = SDL_GDI_LockTexture; + renderer->UnlockTexture = SDL_GDI_UnlockTexture; + renderer->DirtyTexture = SDL_GDI_DirtyTexture; + renderer->SelectRenderTexture = SDL_GDI_SelectRenderTexture; + renderer->RenderFill = SDL_GDI_RenderFill; + renderer->RenderCopy = SDL_GDI_RenderCopy; + renderer->RenderReadPixels = SDL_GDI_RenderReadPixels; + renderer->RenderWritePixels = SDL_GDI_RenderWritePixels; + renderer->RenderPresent = SDL_GDI_RenderPresent; + renderer->DestroyTexture = SDL_GDI_DestroyTexture; + renderer->DestroyRenderer = SDL_GDI_DestroyRenderer; + renderer->info = SDL_GDI_RenderDriver.info; + renderer->window = window->id; + renderer->driverdata = data; + + renderer->info.flags = SDL_Renderer_RenderTarget; + + return renderer; +} + +static int +SDL_GDI_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) +{ + SDL_GDI_RenderData *renderdata = + (SDL_GDI_RenderData *) renderer->driverdata; + SDL_Window *window = SDL_GetWindowFromID(renderer->window); + SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); + SDL_GDI_TextureData *data; + + data = (SDL_GDI_TextureData *) SDL_malloc(sizeof(*data)); + if (!data) { + SDL_OutOfMemory(); + return -1; + } + SDL_zerop(data); + + texture->driverdata = data; + + if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { + if (texture->access == SDL_TextureAccess_Render) { + SDL_SetError("Rendering to YUV format textures is not supported"); + return -1; + } + data->yuv = SDL_SW_CreateYUVTexture(texture); + if (!data->yuv) { + SDL_GDI_DestroyTexture(renderer, texture); + return -1; + } + data->format = display->current_mode.format; + } else { + data->format = texture->format; + } + data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format)); + + if (data->yuv || texture->access == SDL_TextureAccess_Local + || texture->format != SDL_GetCurrentDisplayMode()->format) { + int bmi_size; + LPBITMAPINFO bmi; + + bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD); + bmi = (LPBITMAPINFO) SDL_malloc(bmi_size); + if (!bmi) { + SDL_GDI_DestroyTexture(renderer, texture); + SDL_OutOfMemory(); + return -1; + } + SDL_memset(bmi, 0, bmi_size); + bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + bmi->bmiHeader.biWidth = texture->w; + bmi->bmiHeader.biHeight = -texture->h; /* topdown bitmap */ + bmi->bmiHeader.biPlanes = 1; + bmi->bmiHeader.biSizeImage = texture->h * data->pitch; + bmi->bmiHeader.biXPelsPerMeter = 0; + bmi->bmiHeader.biYPelsPerMeter = 0; + bmi->bmiHeader.biClrUsed = 0; + bmi->bmiHeader.biClrImportant = 0; + bmi->bmiHeader.biBitCount = SDL_BYTESPERPIXEL(data->format) * 8; + if (SDL_ISPIXELFORMAT_INDEXED(data->format)) { + int i, ncolors; + LOGPALETTE *palette; + + bmi->bmiHeader.biCompression = BI_RGB; + ncolors = (1 << SDL_BITSPERPIXEL(data->format)); + palette = + (LOGPALETTE *) SDL_malloc(sizeof(*palette) + + ncolors * sizeof(PALETTEENTRY)); + if (!palette) { + SDL_free(bmi); + SDL_GDI_DestroyTexture(renderer, texture); + SDL_OutOfMemory(); + return -1; + } + palette->palVersion = 0x300; + palette->palNumEntries = ncolors; + for (i = 0; i < ncolors; ++i) { + palette->palPalEntry[i].peRed = 0xFF; + palette->palPalEntry[i].peGreen = 0xFF; + palette->palPalEntry[i].peBlue = 0xFF; + palette->palPalEntry[i].peFlags = 0; + } + data->hpal = CreatePalette(palette); + SDL_free(palette); + } else { + int bpp; + Uint32 Rmask, Gmask, Bmask, Amask; + + bmi->bmiHeader.biCompression = BI_BITFIELDS; + SDL_PixelFormatEnumToMasks(data->format, &bpp, &Rmask, &Gmask, + &Bmask, &Amask); + ((Uint32 *) bmi->bmiColors)[0] = Rmask; + ((Uint32 *) bmi->bmiColors)[1] = Gmask; + ((Uint32 *) bmi->bmiColors)[2] = Bmask; + data->hpal = NULL; + } + data->hbm = + CreateDIBSection(renderdata->memory_hdc, bmi, DIB_RGB_COLORS, + &data->pixels, NULL, 0); + } else { + data->hbm = + CreateCompatibleBitmap(renderdata->window_hdc, texture->w, + texture->h); + data->pixels = NULL; + } + if (!data->hbm) { + SDL_GDI_DestroyTexture(renderer, texture); + WIN_SetError("Couldn't create bitmap"); + return -1; + } + return 0; +} + +static int +SDL_GDI_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, + void **pixels, int *pitch) +{ + SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata; + + if (data->yuv) { + return SDL_SW_QueryYUVTexturePixels(data->yuv, pixels, pitch); + } else { + *pixels = data->pixels; + *pitch = texture->w * SDL_BYTESPERPIXEL(texture->format); + return 0; + } +} + +static int +SDL_GDI_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Color * colors, int firstcolor, + int ncolors) +{ + SDL_GDI_RenderData *renderdata = + (SDL_GDI_RenderData *) renderer->driverdata; + SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata; + + if (data->yuv) { + SDL_SetError("YUV textures don't have a palette"); + return -1; + } else { + PALETTEENTRY entries[256]; + int i; + + for (i = 0; i < ncolors; ++i) { + entries[i].peRed = colors[i].r; + entries[i].peGreen = colors[i].g; + entries[i].peBlue = colors[i].b; + entries[i].peFlags = 0; + } + if (!SetPaletteEntries(data->hpal, firstcolor, ncolors, entries)) { + WIN_SetError("SetPaletteEntries()"); + return -1; + } + return 0; + } +} + +static int +SDL_GDI_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, + SDL_Color * colors, int firstcolor, int ncolors) +{ + SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata; + + if (data->yuv) { + SDL_SetError("YUV textures don't have a palette"); + return -1; + } else { + PALETTEENTRY entries[256]; + int i; + + if (!GetPaletteEntries(data->hpal, firstcolor, ncolors, entries)) { + WIN_SetError("GetPaletteEntries()"); + return -1; + } + for (i = 0; i < ncolors; ++i) { + colors[i].r = entries[i].peRed; + colors[i].g = entries[i].peGreen; + colors[i].b = entries[i].peBlue; + } + return 0; + } +} + +static int +SDL_GDI_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, const void *pixels, int pitch) +{ + SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata; + + if (data->yuv) { + if (SDL_SW_UpdateYUVTexture(data->yuv, rect, pixels, pitch) < 0) { + return -1; + } + UpdateYUVTextureData(texture); + return 0; + } else { + SDL_GDI_RenderData *renderdata = + (SDL_GDI_RenderData *) renderer->driverdata; + + if (data->pixels) { + Uint8 *src, *dst; + int row; + size_t length; + + src = (Uint8 *) pixels; + dst = + (Uint8 *) data->pixels + rect->y * data->pitch + + rect->x * SDL_BYTESPERPIXEL(texture->format); + length = rect->w * SDL_BYTESPERPIXEL(texture->format); + for (row = 0; row < rect->h; ++row) { + SDL_memcpy(dst, src, length); + src += pitch; + dst += data->pitch; + } + } else if (rect->w == texture->w && pitch == data->pitch) { + if (!SetDIBits + (renderdata->window_hdc, data->hbm, rect->y, rect->h, pixels, + renderdata->bmi, DIB_RGB_COLORS)) { + WIN_SetError("SetDIBits()"); + return -1; + } + } else { + SDL_SetError + ("FIXME: Need to allocate temporary memory and do GetDIBits() followed by SetDIBits(), since we can only set blocks of scanlines at a time"); + return -1; + } + return 0; + } +} + +static int +SDL_GDI_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, int markDirty, void **pixels, + int *pitch) +{ + SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata; + + if (data->yuv) { + return SDL_SW_LockYUVTexture(data->yuv, rect, markDirty, pixels, + pitch); + } else { + GdiFlush(); + *pixels = + (void *) ((Uint8 *) data->pixels + rect->y * data->pitch + + rect->x * SDL_BYTESPERPIXEL(texture->format)); + *pitch = data->pitch; + return 0; + } +} + +static void +SDL_GDI_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) +{ + SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata; + + if (data->yuv) { + SDL_SW_UnlockYUVTexture(data->yuv); + UpdateYUVTextureData(texture); + } +} + +static void +SDL_GDI_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, + int numrects, const SDL_Rect * rects) +{ +} + +static void +SDL_GDI_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture) +{ + SDL_GDI_RenderData *data = (SDL_GDI_RenderData *) renderer->driverdata; + + if (texture) { + SDL_GDI_TextureData *texturedata = + (SDL_GDI_TextureData *) texture->driverdata; + SelectObject(data->render_hdc, texturedata->hbm); + if (texturedata->hpal) { + SelectPalette(data->render_hdc, texturedata->hpal, TRUE); + RealizePalette(data->render_hdc); + } + data->current_hdc = data->render_hdc; + } else { + data->current_hdc = data->current_hdc; + } +} + +static int +SDL_GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, + Uint32 color) +{ + SDL_GDI_RenderData *data = (SDL_GDI_RenderData *) renderer->driverdata; + Uint8 r, g, b; + RECT rc; + static HBRUSH brush; + int status; + + r = (Uint8) ((color >> 16) & 0xFF); + g = (Uint8) ((color >> 8) & 0xFF); + b = (Uint8) (color & 0xFF); + + rc.left = rect->x; + rc.top = rect->y; + rc.right = rect->x + rect->w + 1; + rc.bottom = rect->y + rect->h + 1; + + /* Should we cache the brushes? .. it looks like GDI does for us. :) */ + brush = CreateSolidBrush(RGB(r, g, b)); + SelectObject(data->current_hdc, brush); + status = FillRect(data->current_hdc, &rc, brush); + DeleteObject(brush); + + if (!status) { + WIN_SetError("FillRect()"); + return -1; + } + return 0; +} + +static int +SDL_GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * srcrect, const SDL_Rect * dstrect, + int blendMode, int scaleMode) +{ + SDL_GDI_RenderData *data = (SDL_GDI_RenderData *) renderer->driverdata; + SDL_GDI_TextureData *texturedata = + (SDL_GDI_TextureData *) texture->driverdata; + + SelectObject(data->memory_hdc, texturedata->hbm); + if (texturedata->hpal) { + SelectPalette(data->memory_hdc, texturedata->hpal, TRUE); + RealizePalette(data->memory_hdc); + } + if (blendMode & (SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend)) { + static BLENDFUNCTION blendFunc = { + AC_SRC_OVER, + 0, + 255, + AC_SRC_ALPHA + }; + /* FIXME: GDI uses premultiplied alpha! */ + if (!AlphaBlend + (data->current_hdc, dstrect->x, dstrect->y, dstrect->w, + dstrect->h, data->memory_hdc, srcrect->x, srcrect->y, srcrect->w, + srcrect->h, blendFunc)) { + WIN_SetError("AlphaBlend()"); + return -1; + } + } else { + if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) { + if (!BitBlt + (data->current_hdc, dstrect->x, dstrect->y, dstrect->w, + srcrect->h, data->memory_hdc, srcrect->x, srcrect->y, + SRCCOPY)) { + WIN_SetError("BitBlt()"); + return -1; + } + } else { + if (!StretchBlt + (data->current_hdc, dstrect->x, dstrect->y, dstrect->w, + dstrect->h, data->memory_hdc, srcrect->x, srcrect->y, + srcrect->w, srcrect->h, SRCCOPY)) { + WIN_SetError("StretchBlt()"); + return -1; + } + } + } + return 0; +} + +static int +CreateWindowDIB(SDL_GDI_RenderData * data, SDL_Window * window) +{ + data->window_pitch = window->w * (data->bmi->bmiHeader.biBitCount / 8); + data->bmi->bmiHeader.biWidth = window->w; + data->bmi->bmiHeader.biHeight = -window->h; + data->bmi->bmiHeader.biSizeImage = + window->h * (data->bmi->bmiHeader.biBitCount / 8); + data->window_bmp = + CreateDIBSection(data->window_hdc, data->bmi, DIB_RGB_COLORS, + &data->window_pixels, NULL, 0); + if (!data->window_bmp) { + WIN_SetError("CreateDIBSection()"); + return -1; + } + return 0; +} + +static int +SDL_GDI_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, + void *pixels, int pitch) +{ + SDL_Window *window = SDL_GetWindowFromID(renderer->window); + SDL_GDI_RenderData *data = (SDL_GDI_RenderData *) renderer->driverdata; + + if (!data->window_bmp) { + if (CreateWindowDIB(data, window) < 0) { + return -1; + } + } + + SelectObject(data->memory_hdc, data->window_bmp); + BitBlt(data->memory_hdc, rect->x, rect->y, rect->w, rect->h, + data->window_hdc, rect->x, rect->y, SRCCOPY); + + { + int bpp = data->bmi->bmiHeader.biBitCount / 8; + Uint8 *src = + (Uint8 *) data->window_pixels + rect->y * data->window_pitch + + rect->x * bpp; + Uint8 *dst = (Uint8 *) pixels; + int row; + + for (row = 0; row < rect->h; ++row) { + SDL_memcpy(dst, src, rect->w * bpp); + src += data->window_pitch; + dst += pitch; + } + } + + return 0; +} + +static int +SDL_GDI_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, + const void *pixels, int pitch) +{ + SDL_Window *window = SDL_GetWindowFromID(renderer->window); + SDL_GDI_RenderData *data = (SDL_GDI_RenderData *) renderer->driverdata; + + if (!data->window_bmp) { + if (CreateWindowDIB(data, window) < 0) { + return -1; + } + } + + { + int bpp = data->bmi->bmiHeader.biBitCount / 8; + Uint8 *src = (Uint8 *) pixels; + Uint8 *dst = + (Uint8 *) data->window_pixels + rect->y * data->window_pitch + + rect->x * bpp; + int row; + + for (row = 0; row < rect->h; ++row) { + SDL_memcpy(dst, src, rect->w * bpp); + src += pitch; + dst += data->window_pitch; + } + } + + SelectObject(data->memory_hdc, data->window_bmp); + BitBlt(data->window_hdc, rect->x, rect->y, rect->w, rect->h, + data->memory_hdc, rect->x, rect->y, SRCCOPY); + + return 0; +} + +static void +SDL_GDI_RenderPresent(SDL_Renderer * renderer) +{ +} + +static void +SDL_GDI_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) +{ + SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata; + + if (!data) { + return; + } + if (data->yuv) { + SDL_SW_DestroyYUVTexture(data->yuv); + } + if (data->hpal) { + DeleteObject(data->hpal); + } + if (data->hbm) { + DeleteObject(data->hbm); + } + SDL_free(data); + texture->driverdata = NULL; +} + +void +SDL_GDI_DestroyRenderer(SDL_Renderer * renderer) +{ + SDL_GDI_RenderData *data = (SDL_GDI_RenderData *) renderer->driverdata; + + if (data) { + ReleaseDC(data->hwnd, data->window_hdc); + DeleteDC(data->render_hdc); + DeleteDC(data->memory_hdc); + if (data->bmi) { + SDL_free(data->bmi); + } + if (data->window_bmp) { + DeleteObject(data->window_bmp); + } + SDL_free(data); + } + SDL_free(renderer); +} + +#endif /* SDL_VIDEO_RENDER_GDI */ + +/* vi: set ts=4 sw=4 expandtab: */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/win32/SDL_gdirender.h Sat Jul 08 18:06:02 2006 +0000 @@ -0,0 +1,30 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +/* SDL surface based renderer implementation */ + +#if SDL_VIDEO_RENDER_GDI +extern void GDI_AddRenderDriver(_THIS); +#endif + +/* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/win32/SDL_win32video.c Fri Jul 07 10:39:33 2006 +0000 +++ b/src/video/win32/SDL_win32video.c Sat Jul 08 18:06:02 2006 +0000 @@ -28,7 +28,8 @@ #include "../SDL_pixels_c.h" #include "SDL_win32video.h" -#include "SDL_dibrender.h" +#include "SDL_d3drender.h" +#include "SDL_gdirender.h" /* Initialization/Query functions */ static int WIN_VideoInit(_THIS); @@ -45,7 +46,15 @@ static void WIN_DeleteDevice(SDL_VideoDevice * device) { + SDL_VideoData *data = (SDL_VideoData *) device->driverdata; + SDL_UnregisterApp(); +#if SDL_VIDEO_RENDER_D3D + if (data->d3d) { + IDirect3D9_Release(data->d3d); + FreeLibrary(data->d3dDLL); + } +#endif SDL_free(device->driverdata); SDL_free(device); } @@ -54,22 +63,41 @@ WIN_CreateDevice(int devindex) { SDL_VideoDevice *device; + SDL_VideoData *data; SDL_RegisterApp(NULL, 0, NULL); /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); if (device) { - device->driverdata = - (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); + data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); } - if (!device || !device->driverdata) { + if (!device || !data) { SDL_OutOfMemory(); if (device) { SDL_free(device); } return NULL; } + device->driverdata = data; + +#if SDL_VIDEO_RENDER_D3D + data->d3dDLL = LoadLibrary(TEXT("D3D9.DLL")); + if (data->d3dDLL) { + IDirect3D9 *WINAPI(*D3DCreate) (UINT SDKVersion); + + D3DCreate = + (IDirect3D9 * WINAPI(*)(UINT)) GetProcAddress(data->d3dDLL, + "Direct3DCreate9"); + if (D3DCreate) { + data->d3d = D3DCreate(D3D_SDK_VERSION); + } + if (!data->d3d) { + FreeLibrary(data->d3dDLL); + data->d3dDLL = NULL; + } + } +#endif /* SDL_VIDEO_RENDER_D3D */ /* Set the function pointers */ device->VideoInit = WIN_VideoInit; @@ -108,7 +136,13 @@ WIN_VideoInit(_THIS) { WIN_InitModes(_this); - SDL_AddRenderDriver(0, &SDL_DIB_RenderDriver); + +#if SDL_VIDEO_RENDER_GDI + GDI_AddRenderDriver(_this); +#endif +#if SDL_VIDEO_RENDER_D3D + D3D_AddRenderDriver(_this); +#endif WIN_InitKeyboard(_this); WIN_InitMouse(_this);
--- a/src/video/win32/SDL_win32video.h Fri Jul 07 10:39:33 2006 +0000 +++ b/src/video/win32/SDL_win32video.h Sat Jul 08 18:06:02 2006 +0000 @@ -28,9 +28,13 @@ #define WIN32_LEAN_AND_MEAN #define UNICODE -#define WINVER 0x500 // Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices() +#define WINVER 0x500 /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices() */ #include <windows.h> +#if SDL_VIDEO_RENDER_D3D +#include <d3d9.h> +#endif + #include "SDL_win32events.h" #include "SDL_win32keyboard.h" #include "SDL_win32modes.h" @@ -49,6 +53,10 @@ typedef struct SDL_VideoData { +#if SDL_VIDEO_RENDER_D3D + HANDLE d3dDLL; + IDirect3D9 *d3d; +#endif int mouse; int keyboard; } SDL_VideoData;