Hi,
authorSam Lantinga <slouken@libsdl.org>
Sun, 07 Jun 2009 02:44:46 +0000
changeset 31686338b7f2d024
parent 3167 0c85abc61e47
child 3169 f294338ca6eb
Hi,

I have prepared a set of patches to readd WindowsCE support to SDL 1.3.
I've created a new GAPI/Rawframebuffer and a DirectDraw renderer.
Both renderers are work in progress and there are several unimplemented
cases. (Notably
RenderLine/RenderPoint/RenderFill/QueryTexturePixels/UpdateTexture and
texture blending )
Nevertheless I am successfully using these renderers together with the
SDL software renderer. (On most devices the SDL software renderer will
be much faster as there are only badly optimized vendor drivers available)

I send these patches now in this unpolished state because there seems to
be some interest in win ce and someone has to start supporting SDL 1.3

Now on to the patches:
wince_events_window_fixes.patch
fixes some wince incompatibilities and adds fullscreen support via
SHFullScreen. NOTE: This patch shouldn't have any side effects on
Windows, but I have NOT tested it on Windows, so please double-check.
This patch doesn't dependent on the following ones.

wince_renderers_system.patch
This patch does all necessary modifications to the SDL system.
- it adds the renderers to the configure system
- it adds the renderers to win32video

SDL_ceddrawrender.c
SDL_ceddrawrender.h
SDL_gapirender_c.h
SDL_gapirender.c
SDL_gapirender.h
these files add the new render drivers and should be placed in
src/video/win32

Some notes to people who want to test this:
- I have only compiled sdl with ming32ce, so the VisualC files are not
up to date
- As mingw32ce has no ddraw.h this file must be taken from the MS SDK
and modified to work with gcc
- I had to modify line 2611 in configure.in to
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lcoredll -lcommctrl -lmmtimer
-Wl,--image-base -Wl,0x10000"
otherwise GetCPinfo wouldn't link. If someone knows whats causing this
I'd be happy to hear about it.

It would be great if these patches could make their way into SVN as this
would make collaboration much much easier.

I'm out of office for the next week and therefore will be unavailable
via email.

Regards
Stefan
configure.in
include/SDL_config.h.in
src/video/win32/SDL_ceddrawrender.c
src/video/win32/SDL_ceddrawrender.h
src/video/win32/SDL_gapirender.c
src/video/win32/SDL_gapirender.h
src/video/win32/SDL_gapirender_c.h
src/video/win32/SDL_win32events.c
src/video/win32/SDL_win32video.c
src/video/win32/SDL_win32video.h
src/video/win32/SDL_win32window.c
     1.1 --- a/configure.in	Fri Jun 05 23:36:00 2009 +0000
     1.2 +++ b/configure.in	Sun Jun 07 02:44:46 2009 +0000
     1.3 @@ -2077,6 +2077,18 @@
     1.4         ])
     1.5      fi
     1.6  
     1.7 +    AC_MSG_CHECKING(Windows CE)
     1.8 +    have_wince=no
     1.9 +    AC_TRY_COMPILE([
    1.10 +#ifndef _WIN32_WCE
    1.11 +#error This is not Windows CE
    1.12 +#endif
    1.13 +    ],[
    1.14 +    ],[
    1.15 +    have_wince=yes
    1.16 +    ])
    1.17 +    AC_MSG_RESULT($have_wince)
    1.18 +
    1.19      dnl See if the user wants to redirect standard output to files
    1.20      AC_ARG_ENABLE(stdio-redirect,
    1.21  AC_HELP_STRING([--enable-stdio-redirect], [Redirect STDIO to files on Win32 [[default=yes]]]),
    1.22 @@ -2094,6 +2106,7 @@
    1.23                    , enable_directx=yes)
    1.24      if test x$enable_directx = xyes; then
    1.25          AC_CHECK_HEADER(d3d9.h, have_d3d=yes)
    1.26 +        AC_CHECK_HEADER(ddraw.h, have_ddraw=yes)
    1.27          AC_CHECK_HEADER(dsound.h, have_dsound=yes)
    1.28          AC_CHECK_HEADER(dinput.h, have_dinput=yes)
    1.29      fi
    1.30 @@ -2556,6 +2569,18 @@
    1.31              if test x$enable_render_gdi = xyes; then
    1.32                  AC_DEFINE(SDL_VIDEO_RENDER_GDI)
    1.33              fi
    1.34 +            AC_ARG_ENABLE(render-gapi,
    1.35 +AC_HELP_STRING([--enable-render-gapi], [enable the GAPI/RAWFRAMEBUFFER render driver [[default=yes]]]),
    1.36 +                                , enable_render_gapi=yes)
    1.37 +            if test x$enable_render_gapi = xyes -a x$have_wince = xyes; then
    1.38 +                AC_DEFINE(SDL_VIDEO_RENDER_GAPI)
    1.39 +            fi
    1.40 +            AC_ARG_ENABLE(render-ddraw,
    1.41 +AC_HELP_STRING([--enable-render-ddraw], [enable the Mobile DirectDraw render driver [[default=yes]]]),
    1.42 +                                , enable_render_ddraw=yes)
    1.43 +            if test x$enable_render_ddraw = xyes -a x$have_wince = xyes -a x$have_ddraw = xyes; then
    1.44 +                AC_DEFINE(SDL_VIDEO_RENDER_DDRAW)
    1.45 +            fi
    1.46              AC_ARG_ENABLE(render-d3d,
    1.47  AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[default=yes]]]),
    1.48                                  , enable_render_d3d=yes)
     2.1 --- a/include/SDL_config.h.in	Fri Jun 05 23:36:00 2009 +0000
     2.2 +++ b/include/SDL_config.h.in	Sun Jun 07 02:44:46 2009 +0000
     2.3 @@ -278,7 +278,6 @@
     2.4  #undef SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC
     2.5  #undef SDL_VIDEO_DRIVER_DUMMY
     2.6  #undef SDL_VIDEO_DRIVER_FBCON
     2.7 -#undef SDL_VIDEO_DRIVER_GAPI
     2.8  #undef SDL_VIDEO_DRIVER_GEM
     2.9  #undef SDL_VIDEO_DRIVER_IPOD
    2.10  #undef SDL_VIDEO_DRIVER_NANOX
    2.11 @@ -312,6 +311,8 @@
    2.12  #undef SDL_VIDEO_RENDER_OGL
    2.13  #undef SDL_VIDEO_RENDER_OGL_ES
    2.14  #undef SDL_VIDEO_RENDER_X11
    2.15 +#undef SDL_VIDEO_RENDER_GAPI
    2.16 +#undef SDL_VIDEO_RENDER_DDRAW
    2.17  
    2.18  /* Enable OpenGL support */
    2.19  #undef SDL_VIDEO_OPENGL
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/video/win32/SDL_ceddrawrender.c	Sun Jun 07 02:44:46 2009 +0000
     3.3 @@ -0,0 +1,831 @@
     3.4 +/*
     3.5 +    SDL - Simple DirectMedia Layer
     3.6 +    Copyright (C) 1997-2009 Sam Lantinga
     3.7 +
     3.8 +    This library is free software; you can redistribute it and/or
     3.9 +    modify it under the terms of the GNU Lesser General Public
    3.10 +    License as published by the Free Software Foundation; either
    3.11 +    version 2.1 of the License, or (at your option) any later version.
    3.12 +
    3.13 +    This library is distributed in the hope that it will be useful,
    3.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.16 +    Lesser General Public License for more details.
    3.17 +
    3.18 +    You should have received a copy of the GNU Lesser General Public
    3.19 +    License along with this library; if not, write to the Free Software
    3.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    3.21 +
    3.22 +    Sam Lantinga
    3.23 +    slouken@libsdl.org
    3.24 +    
    3.25 +    Stefan Klug
    3.26 +    klug.stefan@gmx.de
    3.27 +*/
    3.28 +#include "SDL_config.h"
    3.29 +
    3.30 +#if SDL_VIDEO_RENDER_DDRAW
    3.31 +
    3.32 +#include "SDL_win32video.h"
    3.33 +#include "../SDL_yuv_sw_c.h"
    3.34 +
    3.35 +#if 0
    3.36 +#define DDRAW_LOG(...) printf(__VA_ARGS__)
    3.37 +#else
    3.38 +#define DDRAW_LOG(...)
    3.39 +#endif
    3.40 +
    3.41 +
    3.42 +/* DirectDraw renderer implementation */
    3.43 +
    3.44 +static SDL_Renderer *DDRAW_CreateRenderer(SDL_Window * window, Uint32 flags);
    3.45 +static int DDRAW_DisplayModeChanged(SDL_Renderer * renderer);
    3.46 +static int DDRAW_CreateTexture(SDL_Renderer * renderer,
    3.47 +                               SDL_Texture * texture);
    3.48 +static int DDRAW_QueryTexturePixels(SDL_Renderer * renderer,
    3.49 +                                    SDL_Texture * texture, void **pixels,
    3.50 +                                    int *pitch);
    3.51 +static int DDRAW_SetTextureColorMod(SDL_Renderer * renderer,
    3.52 +                                    SDL_Texture * texture);
    3.53 +static int DDRAW_SetTextureAlphaMod(SDL_Renderer * renderer,
    3.54 +                                    SDL_Texture * texture);
    3.55 +static int DDRAW_SetTextureBlendMode(SDL_Renderer * renderer,
    3.56 +                                     SDL_Texture * texture);
    3.57 +static int DDRAW_SetTextureScaleMode(SDL_Renderer * renderer,
    3.58 +                                     SDL_Texture * texture);
    3.59 +static int DDRAW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    3.60 +                               const SDL_Rect * rect, const void *pixels,
    3.61 +                               int pitch);
    3.62 +static int DDRAW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    3.63 +                             const SDL_Rect * rect, int markDirty,
    3.64 +                             void **pixels, int *pitch);
    3.65 +static void DDRAW_UnlockTexture(SDL_Renderer * renderer,
    3.66 +                                SDL_Texture * texture);
    3.67 +static void DDRAW_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    3.68 +                               int numrects, const SDL_Rect * rects);
    3.69 +static int DDRAW_RenderPoint(SDL_Renderer * renderer, int x, int y);
    3.70 +static int DDRAW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2,
    3.71 +                            int y2);
    3.72 +static int DDRAW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect);
    3.73 +static int DDRAW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    3.74 +                            const SDL_Rect * srcrect,
    3.75 +                            const SDL_Rect * dstrect);
    3.76 +static void DDRAW_RenderPresent(SDL_Renderer * renderer);
    3.77 +static void DDRAW_DestroyTexture(SDL_Renderer * renderer,
    3.78 +                                 SDL_Texture * texture);
    3.79 +static void DDRAW_DestroyRenderer(SDL_Renderer * renderer);
    3.80 +
    3.81 +
    3.82 +SDL_RenderDriver DDRAW_RenderDriver = {
    3.83 +    DDRAW_CreateRenderer,
    3.84 +    {
    3.85 +     "ddraw",
    3.86 +     (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
    3.87 +      SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
    3.88 +      SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED),
    3.89 +     (SDL_TEXTUREMODULATE_NONE),
    3.90 +     (SDL_BLENDMODE_NONE),
    3.91 +     (SDL_TEXTURESCALEMODE_NONE),
    3.92 +     0,
    3.93 +     {0},
    3.94 +     0,
    3.95 +     0}
    3.96 +};
    3.97 +
    3.98 +typedef struct
    3.99 +{
   3.100 +    IDirectDraw *ddraw;
   3.101 +    IDirectDrawSurface *primary;
   3.102 +} DDRAW_RenderData;
   3.103 +
   3.104 +typedef struct
   3.105 +{
   3.106 +    RECT lock;
   3.107 +    IDirectDrawSurface *surface;
   3.108 +} DDRAW_TextureData;
   3.109 +
   3.110 +
   3.111 +static void
   3.112 +DDRAW_SetError(const char *prefix, HRESULT result)
   3.113 +{
   3.114 +    const char *error;
   3.115 +
   3.116 +    switch (result) {
   3.117 +    case DDERR_CANTCREATEDC:
   3.118 +        error = "CANTCREATEDC";
   3.119 +        break;
   3.120 +    case DDERR_CANTLOCKSURFACE:
   3.121 +        error = "CANTLOCKSURFACE";
   3.122 +        break;
   3.123 +    case DDERR_CLIPPERISUSINGHWND:
   3.124 +        error = "CLIPPERISUSINGHWND";
   3.125 +        break;
   3.126 +    case DDERR_COLORKEYNOTSET:
   3.127 +        error = "COLORKEYNOTSET";
   3.128 +        break;
   3.129 +    case DDERR_CURRENTLYNOTAVAIL:
   3.130 +        error = "CURRENTLYNOTAVAIL";
   3.131 +        break;
   3.132 +    case DDERR_DCALREADYCREATED:
   3.133 +        error = "DCALREADYCREATED";
   3.134 +        break;
   3.135 +    case DDERR_DEVICEDOESNTOWNSURFACE:
   3.136 +        error = "DEVICEDOESNTOWNSURFACE";
   3.137 +        break;
   3.138 +    case DDERR_DIRECTDRAWALREADYCREATED:
   3.139 +        error = "DIRECTDRAWALREADYCREATED";
   3.140 +        break;
   3.141 +    case DDERR_EXCLUSIVEMODEALREADYSET:
   3.142 +        error = "EXCLUSIVEMODEALREADYSET";
   3.143 +        break;
   3.144 +    case DDERR_GENERIC:
   3.145 +        error = "GENERIC";
   3.146 +        break;
   3.147 +    case DDERR_HEIGHTALIGN:
   3.148 +        error = "HEIGHTALIGN";
   3.149 +        break;
   3.150 +    case DDERR_IMPLICITLYCREATED:
   3.151 +        error = "IMPLICITLYCREATED";
   3.152 +        break;
   3.153 +    case DDERR_INCOMPATIBLEPRIMARY:
   3.154 +        error = "INCOMPATIBLEPRIMARY";
   3.155 +        break;
   3.156 +    case DDERR_INVALIDCAPS:
   3.157 +        error = "INVALIDCAPS";
   3.158 +        break;
   3.159 +    case DDERR_INVALIDCLIPLIST:
   3.160 +        error = "INVALIDCLIPLIST";
   3.161 +        break;
   3.162 +    case DDERR_INVALIDMODE:
   3.163 +        error = "INVALIDMODE";
   3.164 +        break;
   3.165 +    case DDERR_INVALIDOBJECT:
   3.166 +        error = "INVALIDOBJECT";
   3.167 +        break;
   3.168 +    case DDERR_INVALIDPARAMS:
   3.169 +        error = "INVALIDPARAMS";
   3.170 +        break;
   3.171 +    case DDERR_INVALIDPIXELFORMAT:
   3.172 +        error = "INVALIDPIXELFORMAT";
   3.173 +        break;
   3.174 +    case DDERR_INVALIDPOSITION:
   3.175 +        error = "INVALIDPOSITION";
   3.176 +        break;
   3.177 +    case DDERR_INVALIDRECT:
   3.178 +        error = "INVALIDRECT";
   3.179 +        break;
   3.180 +    case DDERR_LOCKEDSURFACES:
   3.181 +        error = "LOCKEDSURFACES";
   3.182 +        break;
   3.183 +    case DDERR_MOREDATA:
   3.184 +        error = "MOREDATA";
   3.185 +        break;
   3.186 +    case DDERR_NOALPHAHW:
   3.187 +        error = "NOALPHAHW";
   3.188 +        break;
   3.189 +    case DDERR_NOBLTHW:
   3.190 +        error = "NOBLTHW";
   3.191 +        break;
   3.192 +    case DDERR_NOCLIPLIST:
   3.193 +        error = "NOCLIPLIST";
   3.194 +        break;
   3.195 +    case DDERR_NOCLIPPERATTACHED:
   3.196 +        error = "NOCLIPPERATTACHED";
   3.197 +        break;
   3.198 +    case DDERR_NOCOLORCONVHW:
   3.199 +        error = "NOCOLORCONVHW";
   3.200 +        break;
   3.201 +    case DDERR_NOCOLORKEYHW:
   3.202 +        error = "NOCOLORKEYHW";
   3.203 +        break;
   3.204 +    case DDERR_NOCOOPERATIVELEVELSET:
   3.205 +        error = "NOCOOPERATIVELEVELSET";
   3.206 +        break;
   3.207 +    case DDERR_NODC:
   3.208 +        error = "NODC";
   3.209 +        break;
   3.210 +    case DDERR_NOFLIPHW:
   3.211 +        error = "NOFLIPHW";
   3.212 +        break;
   3.213 +    case DDERR_NOOVERLAYDEST:
   3.214 +        error = "NOOVERLAYDEST";
   3.215 +        break;
   3.216 +    case DDERR_NOOVERLAYHW:
   3.217 +        error = "NOOVERLAYHW";
   3.218 +        break;
   3.219 +    case DDERR_NOPALETTEATTACHED:
   3.220 +        error = "NOPALETTEATTACHED";
   3.221 +        break;
   3.222 +    case DDERR_NOPALETTEHW:
   3.223 +        error = "NOPALETTEHW";
   3.224 +        break;
   3.225 +    case DDERR_NORASTEROPHW:
   3.226 +        error = "NORASTEROPHW";
   3.227 +        break;
   3.228 +    case DDERR_NOSTRETCHHW:
   3.229 +        error = "NOSTRETCHHW";
   3.230 +        break;
   3.231 +    case DDERR_NOTAOVERLAYSURFACE:
   3.232 +        error = "NOTAOVERLAYSURFACE";
   3.233 +        break;
   3.234 +    case DDERR_NOTFLIPPABLE:
   3.235 +        error = "NOTFLIPPABLE";
   3.236 +        break;
   3.237 +    case DDERR_NOTFOUND:
   3.238 +        error = "NOTFOUND";
   3.239 +        break;
   3.240 +    case DDERR_NOTLOCKED:
   3.241 +        error = "NOTLOCKED";
   3.242 +        break;
   3.243 +    case DDERR_NOTPALETTIZED:
   3.244 +        error = "NOTPALETTIZED";
   3.245 +        break;
   3.246 +    case DDERR_NOVSYNCHW:
   3.247 +        error = "NOVSYNCHW";
   3.248 +        break;
   3.249 +    case DDERR_NOZOVERLAYHW:
   3.250 +        error = "NOZOVERLAYHW";
   3.251 +        break;
   3.252 +    case DDERR_OUTOFCAPS:
   3.253 +        error = "OUTOFCAPS";
   3.254 +        break;
   3.255 +    case DDERR_OUTOFMEMORY:
   3.256 +        error = "OUTOFMEMORY";
   3.257 +        break;
   3.258 +    case DDERR_OUTOFVIDEOMEMORY:
   3.259 +        error = "OUTOFVIDEOMEMORY";
   3.260 +        break;
   3.261 +    case DDERR_OVERLAPPINGRECTS:
   3.262 +        error = "OVERLAPPINGRECTS";
   3.263 +        break;
   3.264 +    case DDERR_OVERLAYNOTVISIBLE:
   3.265 +        error = "OVERLAYNOTVISIBLE";
   3.266 +        break;
   3.267 +    case DDERR_PALETTEBUSY:
   3.268 +        error = "PALETTEBUSY";
   3.269 +        break;
   3.270 +    case DDERR_PRIMARYSURFACEALREADYEXISTS:
   3.271 +        error = "PRIMARYSURFACEALREADYEXISTS";
   3.272 +        break;
   3.273 +    case DDERR_REGIONTOOSMALL:
   3.274 +        error = "REGIONTOOSMALL";
   3.275 +        break;
   3.276 +    case DDERR_SURFACEBUSY:
   3.277 +        error = "SURFACEBUSY";
   3.278 +        break;
   3.279 +    case DDERR_SURFACELOST:
   3.280 +        error = "SURFACELOST";
   3.281 +        break;
   3.282 +    case DDERR_TOOBIGHEIGHT:
   3.283 +        error = "TOOBIGHEIGHT";
   3.284 +        break;
   3.285 +    case DDERR_TOOBIGSIZE:
   3.286 +        error = "TOOBIGSIZE";
   3.287 +        break;
   3.288 +    case DDERR_TOOBIGWIDTH:
   3.289 +        error = "TOOBIGWIDTH";
   3.290 +        break;
   3.291 +    case DDERR_UNSUPPORTED:
   3.292 +        error = "UNSUPPORTED";
   3.293 +        break;
   3.294 +    case DDERR_UNSUPPORTEDFORMAT:
   3.295 +        error = "UNSUPPORTEDFORMAT";
   3.296 +        break;
   3.297 +    case DDERR_VERTICALBLANKINPROGRESS:
   3.298 +        error = "VERTICALBLANKINPROGRESS";
   3.299 +        break;
   3.300 +    case DDERR_VIDEONOTACTIVE:
   3.301 +        error = "VIDEONOTACTIVE";
   3.302 +        break;
   3.303 +    case DDERR_WASSTILLDRAWING:
   3.304 +        error = "WASSTILLDRAWING";
   3.305 +        break;
   3.306 +    case DDERR_WRONGMODE:
   3.307 +        error = "WRONGMODE";
   3.308 +        break;
   3.309 +    default:
   3.310 +        error = "UNKNOWN";
   3.311 +        break;
   3.312 +    }
   3.313 +    SDL_SetError("%s: %s", prefix, error);
   3.314 +}
   3.315 +
   3.316 +static SDL_bool
   3.317 +PixelFormatToDDPIXELFORMAT(Uint32 format, LPDDPIXELFORMAT dst)
   3.318 +{
   3.319 +    SDL_zerop(dst);
   3.320 +    dst->dwSize = sizeof(*dst);
   3.321 +
   3.322 +    if (SDL_ISPIXELFORMAT_FOURCC(format)) {
   3.323 +        dst->dwFlags = DDPF_FOURCC;
   3.324 +        dst->dwFourCC = format;
   3.325 +    } else if (SDL_ISPIXELFORMAT_INDEXED(format)) {
   3.326 +        SDL_SetError("Indexed pixelformats are not supported.");
   3.327 +        return SDL_FALSE;
   3.328 +    } else {
   3.329 +        int bpp;
   3.330 +        Uint32 Rmask, Gmask, Bmask, Amask;
   3.331 +        if (!SDL_PixelFormatEnumToMasks
   3.332 +            (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
   3.333 +            SDL_SetError("pixelformat not supported");
   3.334 +            return SDL_FALSE;
   3.335 +        }
   3.336 +
   3.337 +        if (!Rmask && !Gmask && !Bmask) {
   3.338 +            dst->dwFlags = DDPF_ALPHA;
   3.339 +            dst->dwAlphaBitDepth = bpp;
   3.340 +        } else {
   3.341 +            dst->dwFlags = DDPF_RGB;
   3.342 +            dst->dwRGBBitCount = bpp;
   3.343 +            dst->dwRBitMask = Rmask;
   3.344 +            dst->dwGBitMask = Gmask;
   3.345 +            dst->dwBBitMask = Bmask;
   3.346 +
   3.347 +            if (Amask) {
   3.348 +                dst->dwFlags |= DDPF_ALPHAPIXELS;
   3.349 +                dst->dwRGBAlphaBitMask = Amask;
   3.350 +            }
   3.351 +        }
   3.352 +    }
   3.353 +
   3.354 +    return SDL_TRUE;
   3.355 +}
   3.356 +
   3.357 +static SDL_bool
   3.358 +DDRAW_IsTextureFormatAvailable(IDirectDraw * ddraw, Uint32 display_format,
   3.359 +                               Uint32 texture_format)
   3.360 +{
   3.361 +    int bpp;
   3.362 +    Uint32 Rmask, Gmask, Bmask, Amask;
   3.363 +
   3.364 +    if (SDL_ISPIXELFORMAT_FOURCC(texture_format)) {
   3.365 +        //TODO I don't expect DDRAW to support all 4CC formats, but I don't know which ones
   3.366 +        return SDL_TRUE;
   3.367 +    }
   3.368 +    //These are only basic checks
   3.369 +    if (SDL_ISPIXELFORMAT_INDEXED(texture_format)) {
   3.370 +        return SDL_FALSE;
   3.371 +    }
   3.372 +
   3.373 +    if (!SDL_PixelFormatEnumToMasks
   3.374 +        (texture_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
   3.375 +        return SDL_FALSE;
   3.376 +    }
   3.377 +
   3.378 +    switch (bpp) {
   3.379 +    case 4:
   3.380 +    case 8:
   3.381 +    case 16:
   3.382 +    case 24:
   3.383 +    case 32:
   3.384 +        break;
   3.385 +    default:
   3.386 +        return SDL_FALSE;
   3.387 +    }
   3.388 +
   3.389 +    return SDL_TRUE;
   3.390 +}
   3.391 +
   3.392 +void
   3.393 +DDRAW_AddRenderDriver(_THIS)
   3.394 +{
   3.395 +    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
   3.396 +    SDL_RendererInfo *info = &DDRAW_RenderDriver.info;
   3.397 +    SDL_DisplayMode *mode = &SDL_CurrentDisplay.desktop_mode;
   3.398 +
   3.399 +    if (data->ddraw) {
   3.400 +        int i;
   3.401 +        int formats[] = {
   3.402 +            SDL_PIXELFORMAT_INDEX8,
   3.403 +            SDL_PIXELFORMAT_RGB332,
   3.404 +            SDL_PIXELFORMAT_RGB444,
   3.405 +            SDL_PIXELFORMAT_RGB555,
   3.406 +            SDL_PIXELFORMAT_ARGB4444,
   3.407 +            SDL_PIXELFORMAT_ARGB1555,
   3.408 +            SDL_PIXELFORMAT_RGB565,
   3.409 +            SDL_PIXELFORMAT_RGB888,
   3.410 +            SDL_PIXELFORMAT_ARGB8888,
   3.411 +            SDL_PIXELFORMAT_ARGB2101010,
   3.412 +        };
   3.413 +
   3.414 +        for (i = 0; i < SDL_arraysize(formats); ++i) {
   3.415 +            if (DDRAW_IsTextureFormatAvailable
   3.416 +                (data->ddraw, mode->format, formats[i])) {
   3.417 +                info->texture_formats[info->num_texture_formats++] =
   3.418 +                    formats[i];
   3.419 +            }
   3.420 +        }
   3.421 +
   3.422 +        //TODO the fourcc formats should get fetched from IDirectDraw::GetFourCCCodes
   3.423 +        info->texture_formats[info->num_texture_formats++] =
   3.424 +            SDL_PIXELFORMAT_YV12;
   3.425 +        info->texture_formats[info->num_texture_formats++] =
   3.426 +            SDL_PIXELFORMAT_IYUV;
   3.427 +        info->texture_formats[info->num_texture_formats++] =
   3.428 +            SDL_PIXELFORMAT_YUY2;
   3.429 +        info->texture_formats[info->num_texture_formats++] =
   3.430 +            SDL_PIXELFORMAT_UYVY;
   3.431 +        info->texture_formats[info->num_texture_formats++] =
   3.432 +            SDL_PIXELFORMAT_YVYU;
   3.433 +
   3.434 +        SDL_AddRenderDriver(0, &DDRAW_RenderDriver);
   3.435 +    }
   3.436 +}
   3.437 +
   3.438 +SDL_Renderer *
   3.439 +DDRAW_CreateRenderer(SDL_Window * window, Uint32 flags)
   3.440 +{
   3.441 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   3.442 +    SDL_VideoData *videodata = (SDL_VideoData *) display->device->driverdata;
   3.443 +    SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
   3.444 +    SDL_Renderer *renderer;
   3.445 +    DDRAW_RenderData *data;
   3.446 +    HRESULT result;
   3.447 +    DDSURFACEDESC ddsd;
   3.448 +
   3.449 +    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
   3.450 +    if (!renderer) {
   3.451 +        SDL_OutOfMemory();
   3.452 +        return NULL;
   3.453 +    }
   3.454 +
   3.455 +    data = (DDRAW_RenderData *) SDL_calloc(1, sizeof(*data));
   3.456 +    if (!data) {
   3.457 +        DDRAW_DestroyRenderer(renderer);
   3.458 +        SDL_OutOfMemory();
   3.459 +        return NULL;
   3.460 +    }
   3.461 +    data->ddraw = videodata->ddraw;
   3.462 +
   3.463 +    renderer->DisplayModeChanged = DDRAW_DisplayModeChanged;
   3.464 +    renderer->CreateTexture = DDRAW_CreateTexture;
   3.465 +    renderer->QueryTexturePixels = DDRAW_QueryTexturePixels;
   3.466 +
   3.467 +    renderer->SetTextureColorMod = DDRAW_SetTextureColorMod;
   3.468 +    renderer->SetTextureAlphaMod = DDRAW_SetTextureAlphaMod;
   3.469 +    renderer->SetTextureBlendMode = DDRAW_SetTextureBlendMode;
   3.470 +    renderer->SetTextureScaleMode = DDRAW_SetTextureScaleMode;
   3.471 +    renderer->UpdateTexture = DDRAW_UpdateTexture;
   3.472 +    renderer->LockTexture = DDRAW_LockTexture;
   3.473 +    renderer->UnlockTexture = DDRAW_UnlockTexture;
   3.474 +    renderer->DirtyTexture = DDRAW_DirtyTexture;
   3.475 +    renderer->RenderPoint = DDRAW_RenderPoint;
   3.476 +    renderer->RenderLine = DDRAW_RenderLine;
   3.477 +    renderer->RenderFill = DDRAW_RenderFill;
   3.478 +    renderer->RenderCopy = DDRAW_RenderCopy;
   3.479 +    renderer->RenderPresent = DDRAW_RenderPresent;
   3.480 +    renderer->DestroyTexture = DDRAW_DestroyTexture;
   3.481 +    renderer->DestroyRenderer = DDRAW_DestroyRenderer;
   3.482 +    renderer->info = DDRAW_RenderDriver.info;
   3.483 +    renderer->window = window->id;
   3.484 +    renderer->driverdata = data;
   3.485 +
   3.486 +    renderer->info.flags = SDL_RENDERER_ACCELERATED;
   3.487 +
   3.488 +    SDL_zero(ddsd);
   3.489 +    ddsd.dwSize = sizeof(ddsd);
   3.490 +    ddsd.dwFlags = DDSD_CAPS;
   3.491 +
   3.492 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   3.493 +        ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
   3.494 +    } else {
   3.495 +        //TODO handle non fullscreen
   3.496 +        SDL_SetError("DirectDraw renderer has only fullscreen implemented");
   3.497 +        DDRAW_DestroyRenderer(renderer);
   3.498 +        return NULL;
   3.499 +    }
   3.500 +
   3.501 +    if (flags & SDL_RENDERER_PRESENTFLIP2) {
   3.502 +        ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT;
   3.503 +        ddsd.dwBackBufferCount = 2;
   3.504 +    } else if (flags & SDL_RENDERER_PRESENTFLIP3) {
   3.505 +        ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT;
   3.506 +        ddsd.dwBackBufferCount = 3;
   3.507 +    } else if (flags & SDL_RENDERER_PRESENTCOPY) {
   3.508 +        //TODO what is the best approximation to this mode
   3.509 +    } else {
   3.510 +
   3.511 +    }
   3.512 +
   3.513 +    if (flags & SDL_RENDERER_PRESENTVSYNC) {
   3.514 +        SDL_SetError("DirectDraw renderer with v-sync is not implemented");
   3.515 +        DDRAW_DestroyRenderer(renderer);
   3.516 +        return NULL;
   3.517 +    }
   3.518 +
   3.519 +    result =
   3.520 +        data->ddraw->lpVtbl->SetCooperativeLevel(data->ddraw,
   3.521 +                                                 windowdata->hwnd,
   3.522 +                                                 DDSCL_NORMAL);
   3.523 +    if (result != DD_OK) {
   3.524 +        DDRAW_SetError("CreateDevice()", result);
   3.525 +        DDRAW_DestroyRenderer(renderer);
   3.526 +        return NULL;
   3.527 +    }
   3.528 +
   3.529 +    result =
   3.530 +        data->ddraw->lpVtbl->CreateSurface(data->ddraw, &ddsd, &data->primary,
   3.531 +                                           NULL);
   3.532 +    if (result != DD_OK) {
   3.533 +        DDRAW_SetError("CreateDevice()", result);
   3.534 +        DDRAW_DestroyRenderer(renderer);
   3.535 +        return NULL;
   3.536 +    }
   3.537 +
   3.538 +    return renderer;
   3.539 +}
   3.540 +
   3.541 +static int
   3.542 +DDRAW_Reset(SDL_Renderer * renderer)
   3.543 +{
   3.544 +    //TODO implement
   3.545 +    /*D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
   3.546 +       HRESULT result;
   3.547 +
   3.548 +       result = IDirect3DDevice9_Reset(data->device, &data->pparams);
   3.549 +       if (FAILED(result)) {
   3.550 +       if (result == D3DERR_DEVICELOST) {
   3.551 +       /* Don't worry about it, we'll reset later... *
   3.552 +       return 0;
   3.553 +       } else {
   3.554 +       D3D_SetError("Reset()", result);
   3.555 +       return -1;
   3.556 +       }
   3.557 +       }
   3.558 +       IDirect3DDevice9_SetVertexShader(data->device, NULL);
   3.559 +       IDirect3DDevice9_SetFVF(data->device,
   3.560 +       D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
   3.561 +       IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
   3.562 +       D3DCULL_NONE);
   3.563 +       IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE); */
   3.564 +    return 0;
   3.565 +}
   3.566 +
   3.567 +static int
   3.568 +DDRAW_DisplayModeChanged(SDL_Renderer * renderer)
   3.569 +{
   3.570 +    //TODO implement
   3.571 +    /*D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
   3.572 +       SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   3.573 +       SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   3.574 +
   3.575 +       data->pparams.BackBufferWidth = window->w;
   3.576 +       data->pparams.BackBufferHeight = window->h;
   3.577 +       if (window->flags & SDL_WINDOW_FULLSCREEN) {
   3.578 +       data->pparams.BackBufferFormat =
   3.579 +       PixelFormatToD3DFMT(display->fullscreen_mode.format);
   3.580 +       } else {
   3.581 +       data->pparams.BackBufferFormat = D3DFMT_UNKNOWN;
   3.582 +       }
   3.583 +       return D3D_Reset(renderer); */
   3.584 +    return 0;
   3.585 +}
   3.586 +
   3.587 +static int
   3.588 +DDRAW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   3.589 +{
   3.590 +    DDRAW_RenderData *renderdata = (DDRAW_RenderData *) renderer->driverdata;
   3.591 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   3.592 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   3.593 +    Uint32 display_format = display->current_mode.format;
   3.594 +    DDRAW_TextureData *data;
   3.595 +    DDSURFACEDESC ddsd;
   3.596 +    HRESULT result;
   3.597 +
   3.598 +    data = (DDRAW_TextureData *) SDL_calloc(1, sizeof(*data));
   3.599 +    if (!data) {
   3.600 +        SDL_OutOfMemory();
   3.601 +        return -1;
   3.602 +    }
   3.603 +
   3.604 +    SDL_zero(ddsd);
   3.605 +    ddsd.dwSize = sizeof(ddsd);
   3.606 +    ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_HEIGHT | DDSD_WIDTH;
   3.607 +    ddsd.dwWidth = texture->w;
   3.608 +    ddsd.dwHeight = texture->h;
   3.609 +
   3.610 +
   3.611 +    if (!PixelFormatToDDPIXELFORMAT(texture->format, &ddsd.ddpfPixelFormat)) {
   3.612 +        SDL_free(data);
   3.613 +        return -1;
   3.614 +    }
   3.615 +
   3.616 +    texture->driverdata = data;
   3.617 +
   3.618 +    result =
   3.619 +        renderdata->ddraw->lpVtbl->CreateSurface(renderdata->ddraw, &ddsd,
   3.620 +                                                 &data->surface, NULL);
   3.621 +    if (result != DD_OK) {
   3.622 +        SDL_free(data);
   3.623 +        DDRAW_SetError("CreateTexture", result);
   3.624 +        return -1;
   3.625 +    }
   3.626 +
   3.627 +    return 0;
   3.628 +}
   3.629 +
   3.630 +static int
   3.631 +DDRAW_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
   3.632 +                         void **pixels, int *pitch)
   3.633 +{
   3.634 +    //TODO implement
   3.635 +    SDL_SetError("QueryTexturePixels is not implemented");
   3.636 +    return -1;
   3.637 +}
   3.638 +
   3.639 +static int
   3.640 +DDRAW_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
   3.641 +{
   3.642 +    return 0;
   3.643 +}
   3.644 +
   3.645 +static int
   3.646 +DDRAW_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
   3.647 +{
   3.648 +    return 0;
   3.649 +}
   3.650 +
   3.651 +static int
   3.652 +DDRAW_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
   3.653 +{
   3.654 +    switch (texture->blendMode) {
   3.655 +    case SDL_BLENDMODE_NONE:
   3.656 +        return 0;
   3.657 +    default:
   3.658 +        SDL_Unsupported();
   3.659 +        texture->blendMode = SDL_BLENDMODE_NONE;
   3.660 +        return -1;
   3.661 +    }
   3.662 +}
   3.663 +
   3.664 +static int
   3.665 +DDRAW_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
   3.666 +{
   3.667 +    switch (texture->scaleMode) {
   3.668 +    case SDL_TEXTURESCALEMODE_NONE:
   3.669 +    default:
   3.670 +        SDL_Unsupported();
   3.671 +        texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
   3.672 +        return -1;
   3.673 +    }
   3.674 +    return 0;
   3.675 +}
   3.676 +
   3.677 +static int
   3.678 +DDRAW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   3.679 +                    const SDL_Rect * rect, const void *pixels, int pitch)
   3.680 +{
   3.681 +    DDRAW_TextureData *data = (DDRAW_TextureData *) texture->driverdata;
   3.682 +
   3.683 +    //TODO implement
   3.684 +    SDL_SetError("UpdateTexture is not implemented");
   3.685 +    return 0;
   3.686 +}
   3.687 +
   3.688 +static int
   3.689 +DDRAW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   3.690 +                  const SDL_Rect * rect, int markDirty, void **pixels,
   3.691 +                  int *pitch)
   3.692 +{
   3.693 +    DDRAW_TextureData *data = (DDRAW_TextureData *) texture->driverdata;
   3.694 +    HRESULT result;
   3.695 +    DDSURFACEDESC ddsd;
   3.696 +
   3.697 +    SDL_zero(ddsd);
   3.698 +    ddsd.dwSize = sizeof(ddsd);
   3.699 +
   3.700 +    /**
   3.701 +     * On a Axim x51v locking a subrect returns the startaddress of the whole surface,
   3.702 +     * wheras on my ASUS MyPal 696 the startaddress of the locked area is returned,
   3.703 +     * thats why I always lock the whole surface and calculate the pixels pointer by hand.
   3.704 +     * This shouldn't be a speed problem, as multiple locks aren't available on DDraw Mobile
   3.705 +     * see http://msdn.microsoft.com/en-us/library/ms858221.aspx
   3.706 +     */
   3.707 +
   3.708 +    result = data->surface->lpVtbl->Lock(data->surface, NULL, &ddsd, 0, NULL);
   3.709 +    if (result != DD_OK) {
   3.710 +        DDRAW_SetError("LockRect()", result);
   3.711 +        return -1;
   3.712 +    }
   3.713 +
   3.714 +    *pixels = ddsd.lpSurface + rect->y * ddsd.lPitch + rect->x * ddsd.lXPitch;
   3.715 +    *pitch = ddsd.lPitch;
   3.716 +    return 0;
   3.717 +}
   3.718 +
   3.719 +static void
   3.720 +DDRAW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   3.721 +{
   3.722 +    DDRAW_TextureData *data = (DDRAW_TextureData *) texture->driverdata;
   3.723 +
   3.724 +    data->surface->lpVtbl->Unlock(data->surface, NULL);
   3.725 +}
   3.726 +
   3.727 +static void
   3.728 +DDRAW_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   3.729 +                   int numrects, const SDL_Rect * rects)
   3.730 +{
   3.731 +}
   3.732 +
   3.733 +static void
   3.734 +DDRAW_SetBlendMode(DDRAW_RenderData * data, int blendMode)
   3.735 +{
   3.736 +    switch (blendMode) {
   3.737 +
   3.738 +    }
   3.739 +}
   3.740 +
   3.741 +static int
   3.742 +DDRAW_RenderPoint(SDL_Renderer * renderer, int x, int y)
   3.743 +{
   3.744 +    return -1;
   3.745 +}
   3.746 +
   3.747 +static int
   3.748 +DDRAW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
   3.749 +{
   3.750 +    return -1;
   3.751 +}
   3.752 +
   3.753 +static int
   3.754 +DDRAW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect)
   3.755 +{
   3.756 +    return -1;
   3.757 +}
   3.758 +
   3.759 +static int
   3.760 +DDRAW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   3.761 +                 const SDL_Rect * srcrect, const SDL_Rect * dstrect)
   3.762 +{
   3.763 +    DDRAW_RenderData *data = (DDRAW_RenderData *) renderer->driverdata;
   3.764 +    DDRAW_TextureData *texturedata =
   3.765 +        (DDRAW_TextureData *) texture->driverdata;
   3.766 +    HRESULT result;
   3.767 +    RECT srcr;
   3.768 +    RECT dstr;
   3.769 +    DDBLTFX bltfx;
   3.770 +
   3.771 +    srcr.left = srcrect->x;
   3.772 +    srcr.top = srcrect->y;
   3.773 +    srcr.right = srcrect->x + srcrect->w;
   3.774 +    srcr.bottom = srcrect->y + srcrect->h;
   3.775 +
   3.776 +    dstr.left = dstrect->x;
   3.777 +    dstr.top = dstrect->y;
   3.778 +    dstr.right = dstrect->x + dstrect->w;
   3.779 +    dstr.bottom = dstrect->y + dstrect->h;
   3.780 +
   3.781 +    SDL_zero(bltfx);
   3.782 +    bltfx.dwSize = sizeof(bltfx);
   3.783 +    bltfx.dwROP = SRCCOPY;
   3.784 +
   3.785 +    data->primary->lpVtbl->Blt(data->primary, &dstr, texturedata->surface,
   3.786 +                               &srcr, DDBLT_ROP, &bltfx);
   3.787 +
   3.788 +    return 0;
   3.789 +}
   3.790 +
   3.791 +static void
   3.792 +DDRAW_RenderPresent(SDL_Renderer * renderer)
   3.793 +{
   3.794 +    DDRAW_RenderData *data = (DDRAW_RenderData *) renderer->driverdata;
   3.795 +    HRESULT result;
   3.796 +
   3.797 +    return;
   3.798 +
   3.799 +    result =
   3.800 +        data->primary->lpVtbl->Flip(data->primary, NULL, DDFLIP_INTERVAL1);
   3.801 +    if (result != DD_OK) {
   3.802 +        DDRAW_SetError("Present()", result);
   3.803 +    }
   3.804 +}
   3.805 +
   3.806 +static void
   3.807 +DDRAW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   3.808 +{
   3.809 +    DDRAW_TextureData *data = (DDRAW_TextureData *) texture->driverdata;
   3.810 +
   3.811 +    if (!data) {
   3.812 +        return;
   3.813 +    }
   3.814 +
   3.815 +    data->surface->lpVtbl->Release(data->surface);
   3.816 +    SDL_free(data);
   3.817 +    texture->driverdata = NULL;
   3.818 +}
   3.819 +
   3.820 +static void
   3.821 +DDRAW_DestroyRenderer(SDL_Renderer * renderer)
   3.822 +{
   3.823 +    DDRAW_RenderData *data = (DDRAW_RenderData *) renderer->driverdata;
   3.824 +
   3.825 +    if (data) {
   3.826 +        data->primary->lpVtbl->Release(data->primary);
   3.827 +        SDL_free(data);
   3.828 +    }
   3.829 +    SDL_free(renderer);
   3.830 +}
   3.831 +
   3.832 +#endif /* SDL_VIDEO_RENDER_DDRAW */
   3.833 +
   3.834 +/* vi: set ts=4 sw=4 expandtab: */
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/video/win32/SDL_ceddrawrender.h	Sun Jun 07 02:44:46 2009 +0000
     4.3 @@ -0,0 +1,31 @@
     4.4 +/*
     4.5 +    SDL - Simple DirectMedia Layer
     4.6 +    Copyright (C) 1997-2009 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 +    Stefan Klug
    4.26 +    klug.stefan@gmx.de
    4.27 +*/
    4.28 +#include "SDL_config.h"
    4.29 +
    4.30 +#if SDL_VIDEO_RENDER_DDRAW
    4.31 +extern void DDRAW_AddRenderDriver(_THIS);
    4.32 +#endif
    4.33 +
    4.34 +/* 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_gapirender.c	Sun Jun 07 02:44:46 2009 +0000
     5.3 @@ -0,0 +1,646 @@
     5.4 +/*
     5.5 +    SDL - Simple DirectMedia Layer
     5.6 +    Copyright (C) 1997-2009 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 +    Stefan Klug
    5.26 +    klug.stefan@gmx.de
    5.27 +*/
    5.28 +#include "SDL_config.h"
    5.29 +
    5.30 +#if SDL_VIDEO_RENDER_GAPI
    5.31 +
    5.32 +#include "SDL_win32video.h"
    5.33 +//#include "../SDL_sysvideo.h"
    5.34 +#include "../SDL_yuv_sw_c.h"
    5.35 +#include "../SDL_renderer_sw.h"
    5.36 +
    5.37 +#include "SDL_gapirender_c.h"
    5.38 +
    5.39 +#define GAPI_RENDERER_DEBUG 1
    5.40 +
    5.41 +/* GAPI renderer implementation */
    5.42 +
    5.43 +static SDL_Renderer *GAPI_CreateRenderer(SDL_Window * window, Uint32 flags);
    5.44 +static int GAPI_RenderPoint(SDL_Renderer * renderer, int x, int y);
    5.45 +static int GAPI_RenderLine(SDL_Renderer * renderer, int x1, int y1,
    5.46 +                           int x2, int y2);
    5.47 +static int GAPI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect);
    5.48 +static int GAPI_RenderCopy(SDL_Renderer * renderer,
    5.49 +                           SDL_Texture * texture,
    5.50 +                           const SDL_Rect * srcrect,
    5.51 +                           const SDL_Rect * dstrect);
    5.52 +static void GAPI_RenderPresent(SDL_Renderer * renderer);
    5.53 +static void GAPI_DestroyRenderer(SDL_Renderer * renderer);
    5.54 +
    5.55 +
    5.56 +SDL_RenderDriver GAPI_RenderDriver = {
    5.57 +    GAPI_CreateRenderer,
    5.58 +    {
    5.59 +     "gapi",
    5.60 +     (SDL_RENDERER_SINGLEBUFFER),
    5.61 +     }
    5.62 +};
    5.63 +
    5.64 +static HMODULE g_hGapiLib = 0;
    5.65 +
    5.66 +// for testing with GapiEmu
    5.67 +#define USE_GAPI_EMU 0
    5.68 +#define EMULATE_AXIM_X30 0
    5.69 +
    5.70 +#if 0
    5.71 +#define GAPI_LOG(...) printf(__VA_ARGS__)
    5.72 +#else
    5.73 +#define GAPI_LOG(...)
    5.74 +#endif
    5.75 +
    5.76 +
    5.77 +#if USE_GAPI_EMU && !REPORT_VIDEO_INFO
    5.78 +#pragma message("Warning: Using GapiEmu in release build. I assume you'd like to set USE_GAPI_EMU to zero.")
    5.79 +#endif
    5.80 +
    5.81 +
    5.82 +static void
    5.83 +GAPI_SetError(const char *prefix, HRESULT result)
    5.84 +{
    5.85 +    const char *error;
    5.86 +
    5.87 +    switch (result) {
    5.88 +    default:
    5.89 +        error = "UNKNOWN";
    5.90 +        break;
    5.91 +    }
    5.92 +    SDL_SetError("%s: %s", prefix, error);
    5.93 +}
    5.94 +
    5.95 +void
    5.96 +GAPI_AddRenderDriver(_THIS)
    5.97 +{
    5.98 +    /* TODO: should we check for support of GetRawFramebuffer here?
    5.99 +     */
   5.100 +#if USE_GAPI_EMU
   5.101 +    g_hGapiLib = LoadLibrary(L"GAPI_Emu.dll");
   5.102 +#else
   5.103 +    g_hGapiLib = LoadLibrary(L"\\Windows\\gx.dll");
   5.104 +#endif
   5.105 +
   5.106 +    if (g_hGapiLib) {
   5.107 +#define LINK(name,import) gx.name = (PFN##name)GetProcAddress( g_hGapiLib, L##import );
   5.108 +
   5.109 +        LINK(GXOpenDisplay, "?GXOpenDisplay@@YAHPAUHWND__@@K@Z")
   5.110 +            LINK(GXCloseDisplay, "?GXCloseDisplay@@YAHXZ")
   5.111 +            LINK(GXBeginDraw, "?GXBeginDraw@@YAPAXXZ")
   5.112 +            LINK(GXEndDraw, "?GXEndDraw@@YAHXZ")
   5.113 +            LINK(GXOpenInput, "?GXOpenInput@@YAHXZ")
   5.114 +            LINK(GXCloseInput, "?GXCloseInput@@YAHXZ")
   5.115 +            LINK(GXGetDisplayProperties,
   5.116 +                 "?GXGetDisplayProperties@@YA?AUGXDisplayProperties@@XZ")
   5.117 +            LINK(GXGetDefaultKeys, "?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z")
   5.118 +            LINK(GXSuspend, "?GXSuspend@@YAHXZ")
   5.119 +            LINK(GXResume, "?GXResume@@YAHXZ")
   5.120 +            LINK(GXSetViewport, "?GXSetViewport@@YAHKKKK@Z")
   5.121 +            LINK(GXIsDisplayDRAMBuffer, "?GXIsDisplayDRAMBuffer@@YAHXZ")
   5.122 +
   5.123 +            /* wrong gapi.dll */
   5.124 +            if (!gx.GXOpenDisplay) {
   5.125 +            FreeLibrary(g_hGapiLib);
   5.126 +            g_hGapiLib = 0;
   5.127 +        }
   5.128 +#undef LINK
   5.129 +    }
   5.130 +
   5.131 +    SDL_AddRenderDriver(0, &GAPI_RenderDriver);
   5.132 +}
   5.133 +
   5.134 +typedef enum
   5.135 +{
   5.136 +    USAGE_GX_FUNCS = 0x0001,    /* enable to use GXOpen/GXClose/GXBeginDraw... */
   5.137 +    USAGE_DATA_PTR_CONSTANT = 0x0002    /* the framebuffer is at a constant location, don't use values from GXBeginDraw() */
   5.138 +} GAPI_UsageFlags;
   5.139 +
   5.140 +
   5.141 +
   5.142 +typedef struct
   5.143 +{
   5.144 +    int w;
   5.145 +    int h;
   5.146 +    int xPitch;                 /* bytes to move to go to the next pixel */
   5.147 +    int yPitch;                 /* bytes to move to go to the next line */
   5.148 +    int offset;                 /* data offset, to add to the data returned from GetFramebuffer, before processing */
   5.149 +
   5.150 +    void *data;
   5.151 +    Uint32 usageFlags;          /* these flags contain options to define screen handling and to reliably workarounds */
   5.152 +
   5.153 +    Uint32 format;              /* pixel format as defined in SDL_pixels.h */
   5.154 +
   5.155 +} GAPI_RenderData;
   5.156 +
   5.157 +
   5.158 +static Uint32
   5.159 +GuessPixelFormatFromBpp(int bpp)
   5.160 +{
   5.161 +    switch (bpp) {
   5.162 +    case 15:
   5.163 +        return SDL_PIXELFORMAT_RGB555;
   5.164 +    case 16:
   5.165 +        return SDL_PIXELFORMAT_RGB565;
   5.166 +    default:
   5.167 +        return SDL_PIXELFORMAT_UNKNOWN;
   5.168 +        break;
   5.169 +    }
   5.170 +}
   5.171 +
   5.172 +static GAPI_RenderData *
   5.173 +FillRenderDataRawFramebuffer(SDL_Window * window)
   5.174 +{
   5.175 +    RawFrameBufferInfo rbi;
   5.176 +    GAPI_RenderData *renderdata;
   5.177 +    HDC hdc;
   5.178 +
   5.179 +    //TODO should we use the hdc of the window?
   5.180 +    hdc = GetDC(NULL);
   5.181 +    int result = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL,
   5.182 +                           sizeof(RawFrameBufferInfo),
   5.183 +                           (char *) &rbi);
   5.184 +    ReleaseDC(NULL, hdc);
   5.185 +
   5.186 +    if (!(result > 0)) {
   5.187 +        return NULL;
   5.188 +    }
   5.189 +
   5.190 +    /* Asus A696 returns wrong results so we do a sanity check
   5.191 +       See:
   5.192 +       http://groups.google.com/group/microsoft.public.smartphone.developer/browse_thread/thread/4fde5bddd477de81
   5.193 +     */
   5.194 +    if (rbi.cxPixels <= 0 ||
   5.195 +        rbi.cyPixels <= 0 ||
   5.196 +        rbi.cxStride == 0 || rbi.cyStride == 0 || rbi.pFramePointer == 0) {
   5.197 +        return NULL;
   5.198 +    }
   5.199 +
   5.200 +
   5.201 +    renderdata = (GAPI_RenderData *) SDL_calloc(1, sizeof(*renderdata));
   5.202 +    if (!renderdata) {
   5.203 +        SDL_OutOfMemory();
   5.204 +        return NULL;
   5.205 +    }
   5.206 +    //Try to match the window size
   5.207 +    //TODO add rotation support
   5.208 +    if (rbi.cxPixels != window->w || rbi.cyPixels != window->h) {
   5.209 +        SDL_free(renderdata);
   5.210 +        return NULL;
   5.211 +    }
   5.212 +    //Check that the display uses a known display format
   5.213 +    switch (rbi.wFormat) {
   5.214 +    case FORMAT_565:
   5.215 +        renderdata->format = SDL_PIXELFORMAT_RGB565;
   5.216 +        break;
   5.217 +    case FORMAT_555:
   5.218 +        renderdata->format = SDL_PIXELFORMAT_RGB555;
   5.219 +        break;
   5.220 +    default:
   5.221 +        //TODO we should add support for other formats
   5.222 +        SDL_free(renderdata);
   5.223 +        return NULL;
   5.224 +    }
   5.225 +
   5.226 +    renderdata->usageFlags = USAGE_DATA_PTR_CONSTANT;
   5.227 +    renderdata->data = rbi.pFramePointer;
   5.228 +    renderdata->w = rbi.cxPixels;
   5.229 +    renderdata->h = rbi.cyPixels;
   5.230 +    renderdata->xPitch = rbi.cxStride;
   5.231 +    renderdata->yPitch = rbi.cyStride;
   5.232 +
   5.233 +    return renderdata;
   5.234 +
   5.235 +}
   5.236 +
   5.237 +
   5.238 +static GAPI_RenderData *
   5.239 +FillRenderDataGAPI(SDL_Window * window)
   5.240 +{
   5.241 +    GAPI_RenderData *renderdata;
   5.242 +    struct GXDisplayProperties gxdp;
   5.243 +    int tmp;
   5.244 +
   5.245 +#ifdef _ARM_
   5.246 +    WCHAR oemstr[100];
   5.247 +#endif
   5.248 +
   5.249 +    if (!g_hGapiLib) {
   5.250 +        return NULL;
   5.251 +    }
   5.252 +
   5.253 +    renderdata = (GAPI_RenderData *) SDL_calloc(1, sizeof(GAPI_RenderData));
   5.254 +    if (!renderdata) {
   5.255 +        SDL_OutOfMemory();
   5.256 +        return NULL;
   5.257 +    }
   5.258 +
   5.259 +    gxdp = gx.GXGetDisplayProperties();
   5.260 +    renderdata->usageFlags = USAGE_GX_FUNCS;
   5.261 +    renderdata->w = gxdp.cxWidth;
   5.262 +    renderdata->h = gxdp.cyHeight;
   5.263 +    renderdata->xPitch = gxdp.cbxPitch;
   5.264 +    renderdata->yPitch = gxdp.cbyPitch;
   5.265 +
   5.266 +    //Check that the display uses a known display format
   5.267 +    if (gxdp.ffFormat & kfDirect565) {
   5.268 +        renderdata->format = SDL_PIXELFORMAT_RGB565;
   5.269 +    } else if (gxdp.ffFormat & kfDirect555) {
   5.270 +        renderdata->format = SDL_PIXELFORMAT_RGB555;
   5.271 +    } else {
   5.272 +        renderdata->format = SDL_PIXELFORMAT_UNKNOWN;
   5.273 +    }
   5.274 +
   5.275 +    /* apply some device specific corrections */
   5.276 +#ifdef _ARM_
   5.277 +    SystemParametersInfo(SPI_GETOEMINFO, sizeof(oemstr), oemstr, 0);
   5.278 +
   5.279 +    // buggy iPaq38xx
   5.280 +    if ((oemstr[12] == 'H') && (oemstr[13] == '3')
   5.281 +        && (oemstr[14] == '8')
   5.282 +        && (gxdp.cbxPitch > 0)) {
   5.283 +        renderdata->data = (void *) 0xac0755a0;
   5.284 +        renderdata->xPitch = -640;
   5.285 +        renderdata->yPitch = 2;
   5.286 +    }
   5.287 +#if (EMULATE_AXIM_X30 == 0)
   5.288 +    // buggy Dell Axim X30
   5.289 +    if (_tcsncmp(oemstr, L"Dell Axim X30", 13) == 0)
   5.290 +#endif
   5.291 +    {
   5.292 +        GXDeviceInfo gxInfo = { 0 };
   5.293 +        HDC hdc = GetDC(NULL);
   5.294 +        int result;
   5.295 +
   5.296 +        gxInfo.Version = 100;
   5.297 +        result =
   5.298 +            ExtEscape(hdc, GETGXINFO, 0, NULL, sizeof(gxInfo),
   5.299 +                      (char *) &gxInfo);
   5.300 +        if (result > 0) {
   5.301 +            renderdata->usageFlags = USAGE_DATA_PTR_CONSTANT;   /* no more GAPI usage from now */
   5.302 +            renderdata->data = gxInfo.pvFrameBuffer;
   5.303 +            this->hidden->needUpdate = 0;
   5.304 +            renderdata->xPitch = 2;
   5.305 +            renderdata->yPitch = 480;
   5.306 +            renderdata->w = gxInfo.cxWidth;
   5.307 +            renderdata->h = gxInfo.cyHeight;
   5.308 +
   5.309 +            //Check that the display uses a known display format
   5.310 +            switch (rbi->wFormat) {
   5.311 +            case FORMAT_565:
   5.312 +                renderdata->format = SDL_PIXELFORMAT_RGB565;
   5.313 +                break;
   5.314 +            case FORMAT_555:
   5.315 +                renderdata->format = SDL_PIXELFORMAT_RGB555;
   5.316 +                break;
   5.317 +            default:
   5.318 +                //TODO we should add support for other formats
   5.319 +                SDL_free(renderdata);
   5.320 +                return NULL;
   5.321 +            }
   5.322 +        }
   5.323 +    }
   5.324 +#endif
   5.325 +
   5.326 +
   5.327 +    if (renderdata->format == SDL_PIXELFORMAT_UNKNOWN) {
   5.328 +        SDL_SetError("Gapi Pixelformat is unknown");
   5.329 +        SDL_free(renderdata);
   5.330 +        return NULL;
   5.331 +    }
   5.332 +
   5.333 +    /* Gapi always returns values in standard orientation, so we manually apply
   5.334 +       the current orientation 
   5.335 +     */
   5.336 +
   5.337 +    DEVMODE settings;
   5.338 +    SDL_memset(&settings, 0, sizeof(DEVMODE));
   5.339 +    settings.dmSize = sizeof(DEVMODE);
   5.340 +
   5.341 +    settings.dmFields = DM_DISPLAYORIENTATION;
   5.342 +    ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_TEST, NULL);
   5.343 +
   5.344 +    if (settings.dmDisplayOrientation == DMDO_90) {
   5.345 +
   5.346 +        tmp = renderdata->w;
   5.347 +        renderdata->w = renderdata->h;
   5.348 +        renderdata->h = tmp;
   5.349 +
   5.350 +        tmp = renderdata->xPitch;
   5.351 +        renderdata->xPitch = -renderdata->yPitch;
   5.352 +        renderdata->yPitch = tmp;
   5.353 +
   5.354 +        renderdata->offset = -renderdata->w * renderdata->xPitch;
   5.355 +
   5.356 +    } else if (settings.dmDisplayOrientation == DMDO_180) {
   5.357 +
   5.358 +        renderdata->xPitch = -renderdata->xPitch;
   5.359 +        renderdata->yPitch = -renderdata->yPitch;
   5.360 +
   5.361 +        renderdata->offset = -renderdata->h * renderdata->yPitch
   5.362 +            - renderdata->w * renderdata->xPitch;
   5.363 +
   5.364 +    } else if (settings.dmDisplayOrientation == DMDO_270) {
   5.365 +
   5.366 +        tmp = renderdata->w;
   5.367 +        renderdata->w = renderdata->h;
   5.368 +        renderdata->h = tmp;
   5.369 +
   5.370 +        tmp = renderdata->xPitch;
   5.371 +        renderdata->xPitch = renderdata->yPitch;
   5.372 +        renderdata->yPitch = -tmp;
   5.373 +
   5.374 +        renderdata->offset = -renderdata->h * renderdata->yPitch;
   5.375 +
   5.376 +    }
   5.377 +
   5.378 +    if (renderdata->w != window->w || renderdata->h != window->h) {
   5.379 +        GAPI_LOG("GAPI open failed, wrong size %i %i %i %i\n", renderdata->w,
   5.380 +                 renderdata->h, renderdata->xPitch, renderdata->yPitch);
   5.381 +        SDL_free(renderdata);
   5.382 +        return NULL;
   5.383 +    }
   5.384 +
   5.385 +    return renderdata;
   5.386 +
   5.387 +}
   5.388 +
   5.389 +
   5.390 +/* This function does the whole encapsulation of Gapi/RAWFRAMEBUFFER
   5.391 +   it should handle all the device dependent details and fill the device INDEPENDENT
   5.392 +   RenderData structure.
   5.393 + */
   5.394 +GAPI_RenderData *
   5.395 +FillRenderData(SDL_Window * window)
   5.396 +{
   5.397 +    /* We try to match the requested window to the modes available by GAPI and RAWFRAMEBUFFER.
   5.398 +       First RAWFRAMEBUFFER is tried, as it is the most reliable one 
   5.399 +       Look here for detailed discussions:
   5.400 +       http://pdaphonehome.com/forums/samsung-i700/28087-just-saw.html
   5.401 +       http://blogs.msdn.com/windowsmobile/archive/2007/08/13/have-you-migrated-to-directdraw-yet.aspx
   5.402 +     */
   5.403 +
   5.404 +    GAPI_RenderData *res;
   5.405 +
   5.406 +    res = FillRenderDataRawFramebuffer(window);
   5.407 +    GAPI_LOG("FillRenderDataRawFramebuffer: %p\n", res);
   5.408 +    if (res) {
   5.409 +        return res;
   5.410 +    }
   5.411 +    //Now we try gapi
   5.412 +    res = FillRenderDataGAPI(window);
   5.413 +    GAPI_LOG("FillRenderDataGAPI: %p\n", res);
   5.414 +
   5.415 +    return res;
   5.416 +}
   5.417 +
   5.418 +void *
   5.419 +GetFramebuffer()
   5.420 +{
   5.421 +
   5.422 +}
   5.423 +
   5.424 +
   5.425 +SDL_Renderer *
   5.426 +GAPI_CreateRenderer(SDL_Window * window, Uint32 flags)
   5.427 +{
   5.428 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   5.429 +    SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
   5.430 +    SDL_DisplayMode *displayMode = &display->current_mode;
   5.431 +    SDL_Renderer *renderer;
   5.432 +    GAPI_RenderData *data;
   5.433 +    int i, n;
   5.434 +    int bpp;
   5.435 +    Uint32 Rmask, Gmask, Bmask, Amask;
   5.436 +
   5.437 +    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
   5.438 +        SDL_SetError("Gapi supports only fullscreen windows");
   5.439 +        return NULL;
   5.440 +    }
   5.441 +
   5.442 +    if (!SDL_PixelFormatEnumToMasks
   5.443 +        (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
   5.444 +        SDL_SetError("Unknown display format");
   5.445 +        return NULL;
   5.446 +    }
   5.447 +
   5.448 +    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
   5.449 +    if (!renderer) {
   5.450 +        SDL_OutOfMemory();
   5.451 +        return NULL;
   5.452 +    }
   5.453 +
   5.454 +    data = FillRenderData(window);
   5.455 +    if (!data) {
   5.456 +        GAPI_DestroyRenderer(renderer);
   5.457 +        SDL_OutOfMemory();
   5.458 +        return NULL;
   5.459 +    }
   5.460 +
   5.461 +    renderer->RenderPoint = GAPI_RenderPoint;
   5.462 +    renderer->RenderLine = GAPI_RenderLine;
   5.463 +    renderer->RenderFill = GAPI_RenderFill;
   5.464 +    renderer->RenderCopy = GAPI_RenderCopy;
   5.465 +    renderer->RenderPresent = GAPI_RenderPresent;
   5.466 +    renderer->DestroyRenderer = GAPI_DestroyRenderer;
   5.467 +    renderer->info.name = GAPI_RenderDriver.info.name;
   5.468 +    renderer->info.flags = 0;
   5.469 +    renderer->window = window->id;
   5.470 +    renderer->driverdata = data;
   5.471 +
   5.472 +    /* Gapi provides only a framebuffer so lets use software implementation */
   5.473 +    Setup_SoftwareRenderer(renderer);
   5.474 +
   5.475 +#ifdef GAPI_RENDERER_DEBUG
   5.476 +    printf("Created gapi renderer\n");
   5.477 +    printf("use GX functions: %i\n", data->usageFlags & USAGE_GX_FUNCS);
   5.478 +    printf("framebuffer is constant: %i\n",
   5.479 +           data->usageFlags & USAGE_DATA_PTR_CONSTANT);
   5.480 +    printf("w: %i h: %i\n", data->w, data->h);
   5.481 +    printf("data ptr: %p\n", data->data);       /* this can be 0 in case of GAPI usage */
   5.482 +    printf("xPitch: %i\n", data->xPitch);
   5.483 +    printf("yPitch: %i\n", data->yPitch);
   5.484 +    printf("offset: %i\n", data->offset);
   5.485 +    printf("format: %x\n", data->format);
   5.486 +#endif
   5.487 +
   5.488 +    if (data->usageFlags & USAGE_GX_FUNCS) {
   5.489 +        if (gx.GXOpenDisplay(windowdata->hwnd, GX_FULLSCREEN) == 0) {
   5.490 +            GAPI_DestroyRenderer(renderer);
   5.491 +            return NULL;
   5.492 +        }
   5.493 +    }
   5.494 +
   5.495 +    return renderer;
   5.496 +}
   5.497 +
   5.498 +static int
   5.499 +GAPI_RenderPoint(SDL_Renderer * renderer, int x, int y)
   5.500 +{
   5.501 +    //TODO implement
   5.502 +    return -1;
   5.503 +}
   5.504 +
   5.505 +static int
   5.506 +GAPI_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
   5.507 +{
   5.508 +    //TODO implement
   5.509 +    return -11;
   5.510 +}
   5.511 +
   5.512 +static int
   5.513 +GAPI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect)
   5.514 +{
   5.515 +    //TODO implement
   5.516 +    return -1;
   5.517 +}
   5.518 +
   5.519 +/* Video memory is very slow so lets optimize as much as possible */
   5.520 +static void
   5.521 +updateLine16to16(char *src, int srcXPitch, int srcYPitch,
   5.522 +                 char *dst, int dstXPitch, int dstYPitch, int width,
   5.523 +                 int height)
   5.524 +{
   5.525 +    char *srcLine, *dstLine;
   5.526 +    char *srcPix, *dstPix;
   5.527 +
   5.528 +    int x, y;
   5.529 +
   5.530 +    //First dumb solution
   5.531 +    if (srcXPitch == 2 && dstXPitch == 2) {
   5.532 +        srcLine = src;
   5.533 +        dstLine = dst;
   5.534 +        y = height;
   5.535 +        while (y--) {
   5.536 +            SDL_memcpy(dstLine, srcLine, width * sizeof(Uint16));
   5.537 +            srcLine += srcYPitch;
   5.538 +            dstLine += dstYPitch;
   5.539 +        }
   5.540 +    } else {
   5.541 +        //printf("GAPI uses slow blit path %i, %i\n", dstXPitch, dstYPitch);
   5.542 +        srcLine = src;
   5.543 +        dstLine = dst;
   5.544 +        y = height;
   5.545 +        while (y--) {
   5.546 +            srcPix = srcLine;
   5.547 +            dstPix = dstLine;
   5.548 +            x = width;
   5.549 +            while (x--) {
   5.550 +                *((Uint16 *) dstPix) = *((Uint16 *) srcPix);
   5.551 +                dstPix += dstXPitch;
   5.552 +                srcPix += srcXPitch;
   5.553 +            }
   5.554 +            srcLine += srcYPitch;
   5.555 +            dstLine += dstYPitch;
   5.556 +        }
   5.557 +    }
   5.558 +}
   5.559 +
   5.560 +static int
   5.561 +GAPI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   5.562 +                const SDL_Rect * srcrect, const SDL_Rect * dstrect)
   5.563 +{
   5.564 +    GAPI_RenderData *data = (GAPI_RenderData *) renderer->driverdata;
   5.565 +    int bpp;
   5.566 +    int bytespp;
   5.567 +    int status;
   5.568 +    Uint32 Rmask, Gmask, Bmask, Amask;
   5.569 +
   5.570 +    if (texture->format != data->format) {
   5.571 +        SDL_SetError("Gapi got wrong texture");
   5.572 +        return -1;
   5.573 +    }
   5.574 +
   5.575 +    GAPI_LOG("GAPI_RenderCopy\n");
   5.576 +
   5.577 +    if (data->usageFlags & USAGE_GX_FUNCS) {
   5.578 +        char *buffer;
   5.579 +        buffer = gx.GXBeginDraw();
   5.580 +        if (!(data->usageFlags & USAGE_DATA_PTR_CONSTANT)) {
   5.581 +            data->data = buffer;
   5.582 +        }
   5.583 +    }
   5.584 +
   5.585 +    GAPI_LOG("GAPI_RenderCopy blit\n");
   5.586 +    /* If our framebuffer has an xPitch which matches the pixelsize, we
   5.587 +       can convert the framebuffer to a SDL_surface and blit there,
   5.588 +       otherwise, we have to use our own blitting routine
   5.589 +     */
   5.590 +    SDL_PixelFormatEnumToMasks(data->format, &bpp, &Rmask, &Gmask, &Bmask,
   5.591 +                               &Amask);
   5.592 +    bytespp = bpp >> 3;
   5.593 +    if (data->xPitch == bytespp && 0) {
   5.594 +        SDL_Surface *screen =
   5.595 +            SDL_CreateRGBSurfaceFrom(data->data, data->w, data->h,
   5.596 +                                     bpp, data->yPitch, Rmask, Gmask, Bmask,
   5.597 +                                     Amask);
   5.598 +        status =
   5.599 +            SDL_UpperBlit((SDL_Surface *) texture->driverdata, srcrect,
   5.600 +                          screen, dstrect);
   5.601 +        SDL_FreeSurface(screen);
   5.602 +    } else {                    /* screen is rotated, we have to blit on our own */
   5.603 +        SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
   5.604 +
   5.605 +        char *src, *dst;
   5.606 +        src = surface->pixels;
   5.607 +        src += srcrect->y * surface->pitch + srcrect->x * 2;
   5.608 +
   5.609 +        dst = data->data + data->offset;
   5.610 +        dst += dstrect->y * data->yPitch + dstrect->x * data->xPitch;
   5.611 +
   5.612 +        updateLine16to16(src, 2, surface->pitch,
   5.613 +                         dst, data->xPitch, data->yPitch,
   5.614 +                         srcrect->w, srcrect->h);
   5.615 +
   5.616 +    }
   5.617 +
   5.618 +    Uint32 ticks = SDL_GetTicks();
   5.619 +    if (data->usageFlags & USAGE_GX_FUNCS) {
   5.620 +        gx.GXEndDraw();
   5.621 +    }
   5.622 +    GAPI_LOG("GAPI_RenderCopy %i\n", SDL_GetTicks() - ticks);
   5.623 +    return status;
   5.624 +}
   5.625 +
   5.626 +static void
   5.627 +GAPI_RenderPresent(SDL_Renderer * renderer)
   5.628 +{
   5.629 +    /* Nothing todo as we rendered directly to the screen on RenderCopy */
   5.630 +}
   5.631 +
   5.632 +static void
   5.633 +GAPI_DestroyRenderer(SDL_Renderer * renderer)
   5.634 +{
   5.635 +    GAPI_RenderData *data = (GAPI_RenderData *) renderer->driverdata;
   5.636 +
   5.637 +    if (data->usageFlags & USAGE_GX_FUNCS) {
   5.638 +        gx.GXCloseDisplay();
   5.639 +    }
   5.640 +
   5.641 +    if (data) {
   5.642 +        SDL_free(data);
   5.643 +    }
   5.644 +    SDL_free(renderer);
   5.645 +}
   5.646 +
   5.647 +#endif /* SDL_VIDEO_RENDER_GAPI */
   5.648 +
   5.649 +/* vi: set ts=4 sw=4 expandtab: */
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/video/win32/SDL_gapirender.h	Sun Jun 07 02:44:46 2009 +0000
     6.3 @@ -0,0 +1,33 @@
     6.4 +/*
     6.5 +    SDL - Simple DirectMedia Layer
     6.6 +    Copyright (C) 1997-2009 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 +    Stefan Klug
    6.26 +    klug.stefan@gmx.de
    6.27 +*/
    6.28 +#include "SDL_config.h"
    6.29 +
    6.30 +/* SDL surface based renderer implementation */
    6.31 +
    6.32 +#if SDL_VIDEO_RENDER_GAPI
    6.33 +extern void GAPI_AddRenderDriver(_THIS);
    6.34 +#endif
    6.35 +
    6.36 +/* vi: set ts=4 sw=4 expandtab: */
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/video/win32/SDL_gapirender_c.h	Sun Jun 07 02:44:46 2009 +0000
     7.3 @@ -0,0 +1,121 @@
     7.4 +/*
     7.5 +    SDL - Simple DirectMedia Layer
     7.6 +    Copyright (C) 1997-2009 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 +    Stefan Klug
    7.26 +    klug.stefan@gmx.de
    7.27 +*/
    7.28 +
    7.29 +#define WIN32_LEAN_AND_MEAN
    7.30 +#include <windows.h>
    7.31 +
    7.32 +/* hi res definitions */
    7.33 +typedef struct _RawFrameBufferInfo
    7.34 +{
    7.35 +    WORD wFormat;
    7.36 +    WORD wBPP;
    7.37 +    VOID *pFramePointer;
    7.38 +    int cxStride;
    7.39 +    int cyStride;
    7.40 +    int cxPixels;
    7.41 +    int cyPixels;
    7.42 +} RawFrameBufferInfo;
    7.43 +
    7.44 +#define GETRAWFRAMEBUFFER   0x00020001
    7.45 +
    7.46 +#define FORMAT_565 1
    7.47 +#define FORMAT_555 2
    7.48 +#define FORMAT_OTHER 3
    7.49 +
    7.50 +
    7.51 +/* From gx.h, since it's not really C compliant */
    7.52 +
    7.53 +struct GXDisplayProperties
    7.54 +{
    7.55 +    DWORD cxWidth;
    7.56 +    DWORD cyHeight;             // notice lack of 'th' in the word height.
    7.57 +    long cbxPitch;              // number of bytes to move right one x pixel - can be negative.
    7.58 +    long cbyPitch;              // number of bytes to move down one y pixel - can be negative.
    7.59 +    long cBPP;                  // # of bits in each pixel
    7.60 +    DWORD ffFormat;             // format flags.
    7.61 +};
    7.62 +
    7.63 +struct GXKeyList
    7.64 +{
    7.65 +    short vkUp;                 // key for up
    7.66 +    POINT ptUp;                 // x,y position of key/button.  Not on screen but in screen coordinates.
    7.67 +    short vkDown;
    7.68 +    POINT ptDown;
    7.69 +    short vkLeft;
    7.70 +    POINT ptLeft;
    7.71 +    short vkRight;
    7.72 +    POINT ptRight;
    7.73 +    short vkA;
    7.74 +    POINT ptA;
    7.75 +    short vkB;
    7.76 +    POINT ptB;
    7.77 +    short vkC;
    7.78 +    POINT ptC;
    7.79 +    short vkStart;
    7.80 +    POINT ptStart;
    7.81 +};
    7.82 +
    7.83 +typedef int (*PFNGXOpenDisplay) (HWND hWnd, DWORD dwFlags);
    7.84 +typedef int (*PFNGXCloseDisplay) ();
    7.85 +typedef void *(*PFNGXBeginDraw) ();
    7.86 +typedef int (*PFNGXEndDraw) ();
    7.87 +typedef int (*PFNGXOpenInput) ();
    7.88 +typedef int (*PFNGXCloseInput) ();
    7.89 +typedef struct GXDisplayProperties (*PFNGXGetDisplayProperties) ();
    7.90 +typedef struct GXKeyList (*PFNGXGetDefaultKeys) (int iOptions);
    7.91 +typedef int (*PFNGXSuspend) ();
    7.92 +typedef int (*PFNGXResume) ();
    7.93 +typedef int (*PFNGXSetViewport) (DWORD dwTop, DWORD dwHeight,
    7.94 +                                 DWORD dwReserved1, DWORD dwReserved2);
    7.95 +typedef BOOL(*PFNGXIsDisplayDRAMBuffer) ();
    7.96 +
    7.97 +struct GapiFunc
    7.98 +{
    7.99 +    PFNGXOpenDisplay GXOpenDisplay;
   7.100 +    PFNGXCloseDisplay GXCloseDisplay;
   7.101 +    PFNGXBeginDraw GXBeginDraw;
   7.102 +    PFNGXEndDraw GXEndDraw;
   7.103 +    PFNGXOpenInput GXOpenInput;
   7.104 +    PFNGXCloseInput GXCloseInput;
   7.105 +    PFNGXGetDisplayProperties GXGetDisplayProperties;
   7.106 +    PFNGXGetDefaultKeys GXGetDefaultKeys;
   7.107 +    PFNGXSuspend GXSuspend;
   7.108 +    PFNGXResume GXResume;
   7.109 +    PFNGXSetViewport GXSetViewport;
   7.110 +    PFNGXIsDisplayDRAMBuffer GXIsDisplayDRAMBuffer;
   7.111 +} gx;
   7.112 +
   7.113 +#define kfLandscape      0x8    // Screen is rotated 270 degrees
   7.114 +#define kfPalette        0x10   // Pixel values are indexes into a palette
   7.115 +#define kfDirect         0x20   // Pixel values contain actual level information
   7.116 +#define kfDirect555      0x40   // 5 bits each for red, green and blue values in a pixel.
   7.117 +#define kfDirect565      0x80   // 5 red bits, 6 green bits and 5 blue bits per pixel
   7.118 +#define kfDirect888      0x100  // 8 bits each for red, green and blue values in a pixel.
   7.119 +#define kfDirect444      0x200  // 4 red, 4 green, 4 blue
   7.120 +#define kfDirectInverted 0x400
   7.121 +
   7.122 +#define GX_FULLSCREEN    0x01   // for OpenDisplay()
   7.123 +#define GX_NORMALKEYS    0x02
   7.124 +#define GX_LANDSCAPEKEYS        0x03
     8.1 --- a/src/video/win32/SDL_win32events.c	Fri Jun 05 23:36:00 2009 +0000
     8.2 +++ b/src/video/win32/SDL_win32events.c	Sun Jun 07 02:44:46 2009 +0000
     8.3 @@ -473,6 +473,7 @@
     8.4              int x, y;
     8.5              int w, h;
     8.6              int style;
     8.7 +            BOOL menu;
     8.8  
     8.9              /* If we allow resizing, let the resize happen naturally */
    8.10              if (SDL_GetWindowFlags(data->windowID) & SDL_WINDOW_RESIZABLE) {
    8.11 @@ -491,15 +492,19 @@
    8.12              size.bottom = h;
    8.13              size.right = w;
    8.14  
    8.15 +
    8.16 +            style = GetWindowLong(hwnd, GWL_STYLE);
    8.17 +#ifdef _WIN32_WCE
    8.18 +            menu = FALSE;
    8.19 +#else
    8.20              /* DJM - according to the docs for GetMenu(), the
    8.21                 return value is undefined if hwnd is a child window.
    8.22                 Aparently it's too difficult for MS to check
    8.23                 inside their function, so I have to do it here.
    8.24               */
    8.25 -            style = GetWindowLong(hwnd, GWL_STYLE);
    8.26 -            AdjustWindowRect(&size, style,
    8.27 -                             style & WS_CHILDWINDOW ? FALSE : GetMenu(hwnd)
    8.28 -                             != NULL);
    8.29 +            menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
    8.30 +#endif
    8.31 +            AdjustWindowRectEx(&size, style, menu, 0);
    8.32              w = size.right - size.left;
    8.33              h = size.bottom - size.top;
    8.34  
     9.1 --- a/src/video/win32/SDL_win32video.c	Fri Jun 05 23:36:00 2009 +0000
     9.2 +++ b/src/video/win32/SDL_win32video.c	Sun Jun 07 02:44:46 2009 +0000
     9.3 @@ -60,6 +60,12 @@
     9.4          FreeLibrary(data->d3dDLL);
     9.5      }
     9.6  #endif
     9.7 +#if SDL_VIDEO_RENDER_DDRAW
     9.8 +    if (data->ddraw) {
     9.9 +        data->ddraw->lpVtbl->Release(data->ddraw);
    9.10 +        FreeLibrary(data->ddrawDLL);
    9.11 +    }
    9.12 +#endif
    9.13      if (data->wintabDLL) {
    9.14          FreeLibrary(data->wintabDLL);
    9.15      }
    9.16 @@ -106,6 +112,24 @@
    9.17          }
    9.18      }
    9.19  #endif /* SDL_VIDEO_RENDER_D3D */
    9.20 +#if SDL_VIDEO_RENDER_DDRAW
    9.21 +    data->ddrawDLL = LoadLibrary(TEXT("ddraw.dll"));
    9.22 +    if (data->ddrawDLL) {
    9.23 +        IDirectDraw *(WINAPI * DDCreate) (GUID FAR * lpGUID,
    9.24 +                                          LPDIRECTDRAW FAR * lplpDD,
    9.25 +                                          IUnknown FAR * pUnkOuter);
    9.26 +
    9.27 +        DDCreate =
    9.28 +            (IDirectDraw *
    9.29 +             (WINAPI *) (GUID FAR *, LPDIRECTDRAW FAR *, IUnknown FAR *))
    9.30 +            GetProcAddress(data->ddrawDLL, TEXT("DirectDrawCreate"));
    9.31 +        if (!DDCreate || DDCreate(NULL, &data->ddraw, NULL) != DD_OK) {
    9.32 +            FreeLibrary(data->ddrawDLL);
    9.33 +            data->ddrawDLL = NULL;
    9.34 +            data->ddraw = NULL;
    9.35 +        }
    9.36 +    }
    9.37 +#endif /* SDL_VIDEO_RENDER_DDRAW */
    9.38  
    9.39      data->wintabDLL = LoadLibrary(TEXT("WINTAB32.DLL"));
    9.40      if (data->wintabDLL) {
    9.41 @@ -188,9 +212,15 @@
    9.42  #if SDL_VIDEO_RENDER_D3D
    9.43      D3D_AddRenderDriver(_this);
    9.44  #endif
    9.45 +#if SDL_VIDEO_RENDER_DDRAW
    9.46 +    DDRAW_AddRenderDriver(_this);
    9.47 +#endif
    9.48  #if SDL_VIDEO_RENDER_GDI
    9.49      GDI_AddRenderDriver(_this);
    9.50  #endif
    9.51 +#if SDL_VIDEO_RENDER_GAPI
    9.52 +    GAPI_AddRenderDriver(_this);
    9.53 +#endif
    9.54  
    9.55      g_hCtx = SDL_malloc(sizeof(HCTX));
    9.56      WIN_InitKeyboard(_this);
    10.1 --- a/src/video/win32/SDL_win32video.h	Fri Jun 05 23:36:00 2009 +0000
    10.2 +++ b/src/video/win32/SDL_win32video.h	Sun Jun 07 02:44:46 2009 +0000
    10.3 @@ -37,6 +37,12 @@
    10.4  #include "d3d9.h"
    10.5  #endif
    10.6  
    10.7 +#if SDL_VIDEO_RENDER_DDRAW
    10.8 +/* WIN32_LEAN_AND_MEAN was defined, so we have to include this by hand */
    10.9 +#include <objbase.h>
   10.10 +#include "ddraw.h"
   10.11 +#endif
   10.12 +
   10.13  #include "wactab/wintab.h"
   10.14  #define PACKETDATA ( PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_CURSOR)
   10.15  #define PACKETMODE 0
   10.16 @@ -66,6 +72,11 @@
   10.17      HANDLE d3dDLL;
   10.18      IDirect3D9 *d3d;
   10.19  #endif
   10.20 +#if SDL_VIDEO_RENDER_DDRAW
   10.21 +    HANDLE ddrawDLL;
   10.22 +    IDirectDraw *ddraw;
   10.23 +#endif
   10.24 +
   10.25  /* *INDENT-OFF* */
   10.26      /* Function pointers for the Wacom API */
   10.27      HANDLE wintabDLL;
    11.1 --- a/src/video/win32/SDL_win32window.c	Fri Jun 05 23:36:00 2009 +0000
    11.2 +++ b/src/video/win32/SDL_win32window.c	Sun Jun 07 02:44:46 2009 +0000
    11.3 @@ -38,6 +38,41 @@
    11.4  /* This is included after SDL_win32video.h, which includes windows.h */
    11.5  #include "SDL_syswm.h"
    11.6  
    11.7 +
    11.8 +#define SHFS_SHOWTASKBAR            0x0001
    11.9 +#define SHFS_HIDETASKBAR            0x0002
   11.10 +#define SHFS_SHOWSIPBUTTON          0x0004
   11.11 +#define SHFS_HIDESIPBUTTON          0x0008
   11.12 +#define SHFS_SHOWSTARTICON          0x0010
   11.13 +#define SHFS_HIDESTARTICON          0x0020
   11.14 +
   11.15 +#ifdef _WIN32_WCE
   11.16 +// dynamically load aygshell dll because we want SDL to work on HPC and be300
   11.17 +int aygshell_loaded = 0;
   11.18 +BOOL(WINAPI * SHFullScreen) (HWND hwndRequester, DWORD dwState) = 0;
   11.19 +
   11.20 +
   11.21 +static BOOL
   11.22 +CE_SHFullScreen(HWND hwndRequester, DWORD dwState)
   11.23 +{
   11.24 +    if (SHFullScreen == 0 && aygshell_loaded == 0) {
   11.25 +        aygshell_loaded = 0;
   11.26 +        void *lib = SDL_LoadObject("aygshell.dll");
   11.27 +        if (lib) {
   11.28 +            SHFullScreen =
   11.29 +                (BOOL(WINAPI *) (HWND, DWORD)) SDL_LoadFunction(lib,
   11.30 +                                                                "SHFullScreen");
   11.31 +        }
   11.32 +    }
   11.33 +
   11.34 +    if (SHFullScreen) {
   11.35 +        SHFullScreen(hwndRequester, dwState);
   11.36 +        //printf("SHFullscreen(%i)\n",dwState);
   11.37 +    }
   11.38 +}
   11.39 +
   11.40 +#endif
   11.41 +
   11.42  extern HCTX *g_hCtx;            /* the table of tablet event contexts, each windows has to have it's own tablet context */
   11.43  static Uint32 highestId = 0;    /* the highest id of the tablet context */
   11.44  
   11.45 @@ -385,6 +420,7 @@
   11.46      RECT rect;
   11.47      DWORD style;
   11.48      HWND top;
   11.49 +    BOOL menu;
   11.50      int x, y;
   11.51  
   11.52      /* Figure out what the window area will be */
   11.53 @@ -398,9 +434,12 @@
   11.54      rect.top = 0;
   11.55      rect.right = window->w;
   11.56      rect.bottom = window->h;
   11.57 -    AdjustWindowRectEx(&rect, style,
   11.58 -                       (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) !=
   11.59 -                                                           NULL), 0);
   11.60 +#ifdef _WIN32_WCE
   11.61 +    menu = FALSE;
   11.62 +#else
   11.63 +    menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
   11.64 +#endif
   11.65 +    AdjustWindowRectEx(&rect, style, menu, 0);
   11.66  
   11.67      if ((window->flags & SDL_WINDOW_FULLSCREEN)
   11.68          || window->x == SDL_WINDOWPOS_CENTERED) {
   11.69 @@ -425,6 +464,7 @@
   11.70      RECT rect;
   11.71      DWORD style;
   11.72      HWND top;
   11.73 +    BOOL menu;
   11.74      int w, h;
   11.75  
   11.76      /* Figure out what the window area will be */
   11.77 @@ -438,9 +478,12 @@
   11.78      rect.top = 0;
   11.79      rect.right = window->w;
   11.80      rect.bottom = window->h;
   11.81 -    AdjustWindowRectEx(&rect, style,
   11.82 -                       (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) !=
   11.83 -                                                           NULL), 0);
   11.84 +#ifdef _WIN32_WCE
   11.85 +    menu = FALSE;
   11.86 +#else
   11.87 +    menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
   11.88 +#endif
   11.89 +    AdjustWindowRectEx(&rect, style, menu, 0);
   11.90      w = (rect.right - rect.left);
   11.91      h = (rect.bottom - rect.top);
   11.92  
   11.93 @@ -453,6 +496,14 @@
   11.94      HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   11.95  
   11.96      ShowWindow(hwnd, SW_SHOW);
   11.97 +
   11.98 +#ifdef _WIN32_WCE
   11.99 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
  11.100 +        CE_SHFullScreen(hwnd,
  11.101 +                        SHFS_HIDESTARTICON | SHFS_HIDETASKBAR |
  11.102 +                        SHFS_HIDESIPBUTTON);
  11.103 +    }
  11.104 +#endif
  11.105  }
  11.106  
  11.107  void
  11.108 @@ -461,6 +512,14 @@
  11.109      HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  11.110  
  11.111      ShowWindow(hwnd, SW_HIDE);
  11.112 +
  11.113 +#ifdef _WIN32_WCE
  11.114 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
  11.115 +        CE_SHFullScreen(hwnd,
  11.116 +                        SHFS_SHOWSTARTICON | SHFS_SHOWTASKBAR |
  11.117 +                        SHFS_SHOWSIPBUTTON);
  11.118 +    }
  11.119 +#endif
  11.120  }
  11.121  
  11.122  void
  11.123 @@ -475,6 +534,14 @@
  11.124          top = HWND_NOTOPMOST;
  11.125      }
  11.126      SetWindowPos(hwnd, top, 0, 0, 0, 0, (SWP_NOMOVE | SWP_NOSIZE));
  11.127 +
  11.128 +#ifdef _WIN32_WCE
  11.129 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
  11.130 +        CE_SHFullScreen(hwnd,
  11.131 +                        SHFS_HIDESTARTICON | SHFS_HIDETASKBAR |
  11.132 +                        SHFS_HIDESIPBUTTON);
  11.133 +    }
  11.134 +#endif
  11.135  }
  11.136  
  11.137  void
  11.138 @@ -483,6 +550,14 @@
  11.139      HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  11.140  
  11.141      ShowWindow(hwnd, SW_MAXIMIZE);
  11.142 +
  11.143 +#ifdef _WIN32_WCE
  11.144 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
  11.145 +        CE_SHFullScreen(hwnd,
  11.146 +                        SHFS_HIDESTARTICON | SHFS_HIDETASKBAR |
  11.147 +                        SHFS_HIDESIPBUTTON);
  11.148 +    }
  11.149 +#endif
  11.150  }
  11.151  
  11.152  void
  11.153 @@ -491,6 +566,14 @@
  11.154      HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  11.155  
  11.156      ShowWindow(hwnd, SW_MINIMIZE);
  11.157 +
  11.158 +#ifdef _WIN32_WCE
  11.159 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
  11.160 +        CE_SHFullScreen(hwnd,
  11.161 +                        SHFS_SHOWSTARTICON | SHFS_SHOWTASKBAR |
  11.162 +                        SHFS_SHOWSIPBUTTON);
  11.163 +    }
  11.164 +#endif
  11.165  }
  11.166  
  11.167  void
  11.168 @@ -579,12 +662,18 @@
  11.169          return -1;
  11.170      }
  11.171  
  11.172 +    HWND hWndParent = NULL;
  11.173 +#ifndef _WIN32_WCE
  11.174 +    /* WinCE doesn't have HWND_MESSAGE */
  11.175 +    hWndParent = HWND_MESSAGE;
  11.176 +#endif
  11.177 +
  11.178      /* Create the window. */
  11.179      SDL_HelperWindow = CreateWindowEx(0, SDL_HelperWindowClassName,
  11.180                                        SDL_HelperWindowName,
  11.181 -                                      WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
  11.182 +                                      WS_OVERLAPPED, CW_USEDEFAULT,
  11.183                                        CW_USEDEFAULT, CW_USEDEFAULT,
  11.184 -                                      CW_USEDEFAULT, HWND_MESSAGE, NULL,
  11.185 +                                      CW_USEDEFAULT, hWndParent, NULL,
  11.186                                        hInstance, NULL);
  11.187      if (SDL_HelperWindow == NULL) {
  11.188          UnregisterClass(SDL_HelperWindowClassName, hInstance);