Andrey A.
authorSam Lantinga <slouken@libsdl.org>
Tue, 27 Jul 2010 21:31:28 -0700
changeset 4569e1664f94f026
parent 4568 25b9cd8bdc30
child 4618 844b5ef4b149
Andrey A.

I made a video driver GAPI/RAW for WinCE (SDL-1.3).
RAW mode has a priority, and also, GAPI mode works with environment
"SDL_VIDEO_RENDERER=gapi" and for RAW mode "SDL_VIDEO_RENDERER=raw".

I checked the work on the screens of VGA, WVGA, QVGA, WQVGA, HVGA,
+ tested all modes with WindowsMobile Emulator.

Also, correctly draws the pointer position and the scale of the pointer
for VGA/WVGA modes,
correctly draws top left position for DM orientation screen, and
portrait/landscape/square geometry the screen also correct.

Also, I added a small fix for GDI fullscreen mode.

Patch for latest revision SDL-1.3 in an attachment.
Also added small path for mingw32ce build.
configure.in
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/win32/SDL_ceddrawrender.c
src/video/win32/SDL_d3drender.c
src/video/win32/SDL_gapirender.c
src/video/win32/SDL_gapirender.h
src/video/win32/SDL_gapirender_c.h
src/video/win32/SDL_gdirender.c
src/video/win32/SDL_win32clipboard.c
src/video/win32/SDL_win32events.c
src/video/win32/SDL_win32modes.c
src/video/win32/SDL_win32video.c
src/video/win32/SDL_win32video.h
src/video/win32/SDL_win32window.c
src/video/win32/SDL_win32window.h
     1.1 --- a/configure.in	Fri Jul 23 21:33:00 2010 -0700
     1.2 +++ b/configure.in	Tue Jul 27 21:31:28 2010 -0700
     1.3 @@ -1917,7 +1917,7 @@
     1.4      AC_MSG_CHECKING(Windows CE)
     1.5      have_wince=no
     1.6      AC_TRY_COMPILE([
     1.7 -#ifndef _WIN32_WCE
     1.8 +#if !defined(_WIN32_WCE) && !defined(__MINGW32CE__)
     1.9  #error This is not Windows CE
    1.10  #endif
    1.11      ],[
    1.12 @@ -2388,6 +2388,12 @@
    1.13              SOURCES="$SOURCES $srcdir/src/atomic/win32/*.c"
    1.14              have_atomic=yes
    1.15          fi
    1.16 +        # Set up dummy files for the joystick for now
    1.17 +        if test x$enable_joystick = xyes; then
    1.18 +            AC_DEFINE(SDL_JOYSTICK_DUMMY)
    1.19 +            SOURCES="$SOURCES $srcdir/src/joystick/dummy/*.c"
    1.20 +            have_joystick=yes
    1.21 +        fi
    1.22          # Set up files for the thread library
    1.23          if test x$enable_threads = xyes; then
    1.24              AC_DEFINE(SDL_THREAD_WIN32)
    1.25 @@ -2411,10 +2417,20 @@
    1.26          fi
    1.27          # Set up the system libraries we need
    1.28          EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lcoredll -lcommctrl -lmmtimer"
    1.29 +
    1.30 +	# mingw32ce library
    1.31 +	case "$host" in
    1.32 +    	    *-mingw32ce)
    1.33 +    		EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lmingwex"
    1.34 +    		;;
    1.35 +    	    *)
    1.36 +        	;;
    1.37 +	esac
    1.38 +
    1.39          # The Win32 platform requires special setup
    1.40          SDLMAIN_SOURCES="$srcdir/src/main/win32/*.c"
    1.41 -        SDL_CFLAGS="$SDL_CFLAGS -Dmain=SDL_main -D_WIN32_WCE=0x420"
    1.42 -        SDL_LIBS="-lSDLmain $SDL_LIBS"
    1.43 +        EXTRA_CFLAGS="$EXTRA_CFLAGS -Dmain=SDL_main -D_WIN32_WCE=0x420"
    1.44 +        EXTRA_LDFLAGS="-lSDLmain $EXTRA_LDFLAGS"
    1.45          ;;
    1.46      *-*-cygwin* | *-*-mingw32*)
    1.47          ARCH=win32
     2.1 --- a/src/video/SDL_sysvideo.h	Fri Jul 23 21:33:00 2010 -0700
     2.2 +++ b/src/video/SDL_sysvideo.h	Tue Jul 27 21:31:28 2010 -0700
     2.3 @@ -387,9 +387,6 @@
     2.4  #if SDL_VIDEO_DRIVER_SVGALIB
     2.5  extern VideoBootStrap SVGALIB_bootstrap;
     2.6  #endif
     2.7 -#if SDL_VIDEO_DRIVER_GAPI
     2.8 -extern VideoBootStrap GAPI_bootstrap;
     2.9 -#endif
    2.10  #if SDL_VIDEO_DRIVER_WIN32
    2.11  extern VideoBootStrap WIN32_bootstrap;
    2.12  #endif
     3.1 --- a/src/video/SDL_video.c	Fri Jul 23 21:33:00 2010 -0700
     3.2 +++ b/src/video/SDL_video.c	Tue Jul 27 21:31:28 2010 -0700
     3.3 @@ -67,9 +67,6 @@
     3.4  #if SDL_VIDEO_DRIVER_SVGALIB
     3.5      &SVGALIB_bootstrap,
     3.6  #endif
     3.7 -#if SDL_VIDEO_DRIVER_GAPI
     3.8 -    &GAPI_bootstrap,
     3.9 -#endif
    3.10  #if SDL_VIDEO_DRIVER_WIN32
    3.11      &WIN32_bootstrap,
    3.12  #endif
     4.1 --- a/src/video/win32/SDL_ceddrawrender.c	Fri Jul 23 21:33:00 2010 -0700
     4.2 +++ b/src/video/win32/SDL_ceddrawrender.c	Tue Jul 27 21:31:28 2010 -0700
     4.3 @@ -459,6 +459,8 @@
     4.4      }
     4.5      data->ddraw = videodata->ddraw;
     4.6  
     4.7 +    videodata->render = RENDER_DDRAW;
     4.8 +
     4.9      renderer->DisplayModeChanged = DDRAW_DisplayModeChanged;
    4.10      renderer->CreateTexture = DDRAW_CreateTexture;
    4.11      renderer->QueryTexturePixels = DDRAW_QueryTexturePixels;
     5.1 --- a/src/video/win32/SDL_d3drender.c	Fri Jul 23 21:33:00 2010 -0700
     5.2 +++ b/src/video/win32/SDL_d3drender.c	Tue Jul 27 21:31:28 2010 -0700
     5.3 @@ -451,6 +451,8 @@
     5.4      }
     5.5      data->d3d = videodata->d3d;
     5.6  
     5.7 +    videodata->render = RENDER_D3D;
     5.8 +
     5.9      renderer->DisplayModeChanged = D3D_DisplayModeChanged;
    5.10      renderer->CreateTexture = D3D_CreateTexture;
    5.11      renderer->QueryTexturePixels = D3D_QueryTexturePixels;
     6.1 --- a/src/video/win32/SDL_gapirender.c	Fri Jul 23 21:33:00 2010 -0700
     6.2 +++ b/src/video/win32/SDL_gapirender.c	Tue Jul 27 21:31:28 2010 -0700
     6.3 @@ -1,670 +1,1281 @@
     6.4 -/*
     6.5 -    SDL - Simple DirectMedia Layer
     6.6 -    Copyright (C) 1997-2010 Sam Lantinga
     6.7 +/***************************************************************************
     6.8 + *   Copyright (C) 2010 by Andrey Afletdinov <afletdinov@gmail.com>        *
     6.9 + *                                                                         *
    6.10 + *   WinCE RAW/GAPI video driver                                           *
    6.11 + *                                                                         *
    6.12 + *   Part of the SDL - (Simple DirectMedia Layer)                          *
    6.13 + *   http://www.libsdl.org                                                 *
    6.14 + *                                                                         *
    6.15 + *   This program is free software; you can redistribute it and/or modify  *
    6.16 + *   it under the terms of the GNU General Public License as published by  *
    6.17 + *   the Free Software Foundation; either version 2 of the License, or     *
    6.18 + *   (at your option) any later version.                                   *
    6.19 + *                                                                         *
    6.20 + *   This program is distributed in the hope that it will be useful,       *
    6.21 + *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    6.22 + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    6.23 + *   GNU General Public License for more details.                          *
    6.24 + *                                                                         *
    6.25 + *   You should have received a copy of the GNU General Public License     *
    6.26 + *   along with this program; if not, write to the                         *
    6.27 + *   Free Software Foundation, Inc.,                                       *
    6.28 + *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    6.29 + ***************************************************************************/
    6.30  
    6.31 -    This library is free software; you can redistribute it and/or
    6.32 -    modify it under the terms of the GNU Lesser General Public
    6.33 -    License as published by the Free Software Foundation; either
    6.34 -    version 2.1 of the License, or (at your option) any later version.
    6.35 -
    6.36 -    This library is distributed in the hope that it will be useful,
    6.37 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.38 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.39 -    Lesser General Public License for more details.
    6.40 -
    6.41 -    You should have received a copy of the GNU Lesser General Public
    6.42 -    License along with this library; if not, write to the Free Software
    6.43 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    6.44 -
    6.45 -    Sam Lantinga
    6.46 -    slouken@libsdl.org
    6.47 -    
    6.48 -    Stefan Klug
    6.49 -    klug.stefan@gmx.de
    6.50 -*/
    6.51  #include "SDL_config.h"
    6.52  
    6.53  #if SDL_VIDEO_RENDER_GAPI
    6.54  
    6.55  #include "SDL_win32video.h"
    6.56 -//#include "../SDL_sysvideo.h"
    6.57 +#include "SDL_win32window.h"
    6.58  #include "../SDL_yuv_sw_c.h"
    6.59 -#include "../SDL_renderer_sw.h"
    6.60  
    6.61 -#include "SDL_gapirender_c.h"
    6.62 +// RawFrameBufferInfo
    6.63 +typedef struct
    6.64 +{
    6.65 +   WORD wFormat;
    6.66 +   WORD wBPP;
    6.67 +   VOID *pFramePointer;
    6.68 +   int  cxStride;
    6.69 +   int  cyStride;
    6.70 +   int  cxPixels;
    6.71 +   int  cyPixels;
    6.72 +} RawFrameBufferInfo;
    6.73  
    6.74 -#define GAPI_RENDERER_DEBUG 1
    6.75 +// GXDeviceInfo
    6.76 +typedef struct
    6.77 +{
    6.78 +    long Version;
    6.79 +    void* pvFrameBuffer;
    6.80 +    unsigned long cbStride;
    6.81 +    unsigned long cxWidth;
    6.82 +    unsigned long cyHeight;
    6.83 +    unsigned long cBPP;
    6.84 +    unsigned long ffFormat;
    6.85 +    char unknown[0x84 - 7 * 4];
    6.86 +} GXDeviceInfo;
    6.87  
    6.88 -/* GAPI renderer implementation */
    6.89 -
    6.90 -static SDL_Renderer *GAPI_CreateRenderer(SDL_Window * window, Uint32 flags);
    6.91 -static int GAPI_RenderDrawPoints(SDL_Renderer * renderer,
    6.92 -                                 const SDL_Point * points, int count);
    6.93 -static int GAPI_RenderDrawLines(SDL_Renderer * renderer,
    6.94 -                                const SDL_Point * points, int count);
    6.95 -static int GAPI_RenderDrawRects(SDL_Renderer * renderer,
    6.96 -                                const SDL_Rect ** rects, int count);
    6.97 -static int GAPI_RenderFillRects(SDL_Renderer * renderer,
    6.98 -                                const SDL_Rect ** rects, int count);
    6.99 -static int GAPI_RenderCopy(SDL_Renderer * renderer,
   6.100 -                           SDL_Texture * texture,
   6.101 -                           const SDL_Rect * srcrect,
   6.102 -                           const SDL_Rect * dstrect);
   6.103 -static void GAPI_RenderPresent(SDL_Renderer * renderer);
   6.104 -static void GAPI_DestroyRenderer(SDL_Renderer * renderer);
   6.105 -
   6.106 -
   6.107 -SDL_RenderDriver GAPI_RenderDriver = {
   6.108 -    GAPI_CreateRenderer,
   6.109 -    {
   6.110 -     "gapi",
   6.111 -     (SDL_RENDERER_SINGLEBUFFER),
   6.112 -     }
   6.113 +// wince: GXDisplayProperties
   6.114 +struct GXDisplayProperties
   6.115 +{
   6.116 +    DWORD cxWidth;
   6.117 +    DWORD cyHeight;
   6.118 +    long cbxPitch;
   6.119 +    long cbyPitch;
   6.120 +    long cBPP;
   6.121 +    DWORD ffFormat;
   6.122  };
   6.123  
   6.124 -static HMODULE g_hGapiLib = 0;
   6.125 +// gx.dll
   6.126 +typedef int   (*PFNGXOpenDisplay)(HWND hWnd, DWORD dwFlags);
   6.127 +typedef int   (*PFNGXCloseDisplay)();
   6.128 +typedef void* (*PFNGXBeginDraw)();
   6.129 +typedef int   (*PFNGXEndDraw)();
   6.130 +typedef struct GXDisplayProperties (*PFNGXGetDisplayProperties)();
   6.131 +typedef int   (*PFNGXSuspend)();
   6.132 +typedef int   (*PFNGXResume)();
   6.133  
   6.134 -// for testing with GapiEmu
   6.135 -#define USE_GAPI_EMU 0
   6.136 -#define EMULATE_AXIM_X30 0
   6.137 +typedef struct
   6.138 +{
   6.139 +    // gx.dll
   6.140 +    HMODULE                   hGapiLib;
   6.141 +    PFNGXOpenDisplay          GXOpenDisplay;
   6.142 +    PFNGXCloseDisplay         GXCloseDisplay;
   6.143 +    PFNGXBeginDraw            GXBeginDraw;
   6.144 +    PFNGXEndDraw              GXEndDraw;
   6.145 +    PFNGXGetDisplayProperties GXGetDisplayProperties;
   6.146 +    PFNGXSuspend              GXSuspend;
   6.147 +    PFNGXResume               GXResume;
   6.148 +} GapiInfo;
   6.149  
   6.150 -#if 0
   6.151 -#define GAPI_LOG(...) printf(__VA_ARGS__)
   6.152 -#else
   6.153 -#define GAPI_LOG(...)
   6.154 -#endif
   6.155 +//#ifndef DM_DISPLAYORIENTATION
   6.156 +//#define DM_DISPLAYORIENTATION 0x00800000L
   6.157 +//#endif
   6.158  
   6.159 +#define FORMAT_565		1
   6.160 +#define FORMAT_555		2
   6.161 +#define FORMAT_OTHER		3
   6.162  
   6.163 -#if USE_GAPI_EMU && !REPORT_VIDEO_INFO
   6.164 -#pragma message("Warning: Using GapiEmu in release build. I assume you'd like to set USE_GAPI_EMU to zero.")
   6.165 -#endif
   6.166 +#define GETRAWFRAMEBUFFER	0x00020001
   6.167 +#define GETGXINFO		0x00020000
   6.168  
   6.169 +#define kfPalette		0x10
   6.170 +#define kfDirect		0x20
   6.171 +#define kfDirect555		0x40
   6.172 +#define kfDirect565		0x80
   6.173  
   6.174 -static void
   6.175 -GAPI_SetError(const char *prefix, HRESULT result)
   6.176 +#define GX_FULLSCREEN		0x01
   6.177 +
   6.178 +enum ScreenOrientation { ORIENTATION_UNKNOWN = -1, ORIENTATION_UP = DMDO_0, ORIENTATION_DOWN = DMDO_180, ORIENTATION_LEFT = DMDO_270, ORIENTATION_RIGHT = DMDO_90 };
   6.179 +enum ScreenGeometry { GEOMETRY_UNKNOWN, GEOMETRY_PORTRAIT, GEOMETRY_LANDSCAPE, GEOMETRY_SQUARE };
   6.180 +enum FrameBufferFlags { FB_SKIP_OFFSET = 0x0001, FB_RAW_MODE = 0x0002, FB_SUSPENDED = 0x0004 };
   6.181 +
   6.182 +// private framebuffer info
   6.183 +typedef struct
   6.184  {
   6.185 -    const char *error;
   6.186 +    int width;
   6.187 +    int height;
   6.188 +    int xpitch;
   6.189 +    int ypitch;
   6.190 +    int offset;
   6.191 +} FrameBufferInfo;
   6.192  
   6.193 -    switch (result) {
   6.194 -    default:
   6.195 -        error = "UNKNOWN";
   6.196 -        break;
   6.197 +// private display data
   6.198 +typedef struct
   6.199 +{
   6.200 +    unsigned char* pixels;	// video memory
   6.201 +    int format;			// video format
   6.202 +    FrameBufferInfo fb;		// framebuffer geometry
   6.203 +    GapiInfo* gapi;		// GAPI module
   6.204 +    int userOrientation;
   6.205 +    int systemOrientation;
   6.206 +    int hardwareGeometry;
   6.207 +    int flags;			// fb flags
   6.208 +    float scale;		// scale pointer position
   6.209 +    int debug;
   6.210 +
   6.211 +} WINCE_RenderData;
   6.212 +
   6.213 +typedef struct
   6.214 +{
   6.215 +    SDL_SW_YUVTexture *yuv;
   6.216 +    Uint32 format;
   6.217 +    void *pixels;
   6.218 +    int pitch;
   6.219 +
   6.220 +} WINCE_TextureData;
   6.221 +
   6.222 +
   6.223 +// system func
   6.224 +SDL_Renderer*	WINCE_CreateRenderer(SDL_Window* window, Uint32 flags);
   6.225 +void		WINCE_DestroyRenderer(SDL_Renderer* renderer);
   6.226 +
   6.227 +int		WINCE_CreateTexture(SDL_Renderer* renderer, SDL_Texture* texture);
   6.228 +void		WINCE_DestroyTexture(SDL_Renderer* renderer, SDL_Texture* texture);
   6.229 +int		WINCE_QueryTexturePixels(SDL_Renderer* renderer, SDL_Texture* texture, void** pixels, int* pitch);
   6.230 +int		WINCE_UpdateTexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, const void* pixels, int pitch);
   6.231 +int		WINCE_LockTexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, int dirty, void** pixels, int* pitch);
   6.232 +void		WINCE_UnlockTexture(SDL_Renderer* renderer, SDL_Texture* texture);
   6.233 +
   6.234 +int		WINCE_Available(void);
   6.235 +void		WINCE_SetupOrientation(WINCE_RenderData* data, int width, int height);
   6.236 +
   6.237 +int		WINCE_RenderCopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srect, const SDL_Rect* drect);
   6.238 +void		WINCE_ShowWindow(_THIS, SDL_Window* window, int visible);
   6.239 +
   6.240 +void		WINCE_RenderPresent(SDL_Renderer* renderer);
   6.241 +int		WINCE_RenderDrawPoints(SDL_Renderer* renderer, const SDL_Point* points, int count);
   6.242 +int		WINCE_RenderDrawLines(SDL_Renderer* renderer, const SDL_Point* points, int count);
   6.243 +int		WINCE_RenderDrawRects(SDL_Renderer* renderer, const SDL_Rect ** rects, int count);
   6.244 +int		WINCE_RenderFillRects(SDL_Renderer* renderer, const SDL_Rect** rects, int count);
   6.245 +
   6.246 +void		WINCE_PointerCoordinateTransform(SDL_Window* window, POINT* pt);
   6.247 +void		WINCE_DumpVideoInfo(WINCE_RenderData* data);
   6.248 +void		WINCE_PortraitTransform(WINCE_RenderData* data, int width, int height);
   6.249 +void		WINCE_LandscapeTransform(WINCE_RenderData* data, int width, int height);
   6.250 +void		WINCE_SquareTransform(WINCE_RenderData* data, int width, int height);
   6.251 +int		WINCE_FixedGeometry(FrameBufferInfo* fb, int bpp, int debug);
   6.252 +int		WINCE_GetDMOrientation(void);
   6.253 +int		WINCE_SetDMOrientation(int orientation);
   6.254 +void		WINCE_UpdateYUVTextureData(SDL_Texture* texture);
   6.255 +
   6.256 +// gapi engine specific
   6.257 +int		GAPI_Init(WINCE_RenderData* data, HWND hwnd);
   6.258 +void		GAPI_Quit(WINCE_RenderData* data);
   6.259 +
   6.260 +// raw engine specific
   6.261 +int		RAW_Init(WINCE_RenderData* data);
   6.262 +void		RAW_Quit(WINCE_RenderData* data);
   6.263 +
   6.264 +// tools
   6.265 +void		FrameBufferRotate(FrameBufferInfo* src, int orientation);
   6.266 +int		GetFrameBufferOrientation(const FrameBufferInfo* src);
   6.267 +void		PointerRotate(POINT* pt, const FrameBufferInfo* fb, int orientation);
   6.268 +void		FrameBufferInitialize(FrameBufferInfo* fb);
   6.269 +void		FrameBufferDumpInfo(const FrameBufferInfo* fb, const char*);
   6.270 +const		char* GetOrientationName(int orientation);
   6.271 +void		UpdateLine16to16(const FrameBufferInfo* fb, const Uint16* src, Uint16* dst, Uint16 width);
   6.272 +
   6.273 +// stdlib
   6.274 +inline int	__abs(int x){ return x < 0 ? -x : x; };
   6.275 +inline void	__swap(int* a, int* b){ int t = *a; *a = *b; *b = t; };
   6.276 +
   6.277 +#define GAPI_RENDER_NAME	"gapi"
   6.278 +#define RAW_RENDER_NAME		"raw"
   6.279 +//
   6.280 +SDL_RenderDriver GAPI_RenderDriver = {
   6.281 +    WINCE_CreateRenderer,
   6.282 +    {
   6.283 +	GAPI_RENDER_NAME,
   6.284 +	(SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD),
   6.285 +	(SDL_TEXTUREMODULATE_NONE),
   6.286 +	(SDL_BLENDMODE_NONE),
   6.287 +	(SDL_TEXTURESCALEMODE_NONE),
   6.288 +	7,
   6.289 +	{
   6.290 +	    SDL_PIXELFORMAT_RGB555,
   6.291 +	    SDL_PIXELFORMAT_RGB565,
   6.292 +	    SDL_PIXELFORMAT_YV12,
   6.293 +	    SDL_PIXELFORMAT_IYUV,
   6.294 +	    SDL_PIXELFORMAT_YUY2,
   6.295 +	    SDL_PIXELFORMAT_UYVY,
   6.296 +	    SDL_PIXELFORMAT_YVYU
   6.297 +	},
   6.298 +	0,
   6.299 +	0
   6.300      }
   6.301 -    SDL_SetError("%s: %s", prefix, error);
   6.302 +};
   6.303 +
   6.304 +SDL_RenderDriver RAW_RenderDriver = {
   6.305 +    WINCE_CreateRenderer,
   6.306 +    {
   6.307 +	RAW_RENDER_NAME,
   6.308 +	(SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD),
   6.309 +	(SDL_TEXTUREMODULATE_NONE),
   6.310 +	(SDL_BLENDMODE_NONE),
   6.311 +	(SDL_TEXTURESCALEMODE_NONE),
   6.312 +	7,
   6.313 +	{
   6.314 +	    SDL_PIXELFORMAT_RGB555,
   6.315 +	    SDL_PIXELFORMAT_RGB565,
   6.316 +	    SDL_PIXELFORMAT_YV12,
   6.317 +	    SDL_PIXELFORMAT_IYUV,
   6.318 +	    SDL_PIXELFORMAT_YUY2,
   6.319 +	    SDL_PIXELFORMAT_UYVY,
   6.320 +	    SDL_PIXELFORMAT_YVYU
   6.321 +	},
   6.322 +	0,
   6.323 +	0
   6.324 +    }
   6.325 +};
   6.326 +
   6.327 +int WINCE_Available(void)
   6.328 +{
   6.329 +    const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER");
   6.330 +
   6.331 +    // raw check
   6.332 +    RawFrameBufferInfo rfbi = { 0 };
   6.333 +    HDC hdc = GetDC(NULL);
   6.334 +    int render_raw = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *) &rfbi);
   6.335 +    ReleaseDC(NULL, hdc);
   6.336 +
   6.337 +    if(render_raw != 0 && rfbi.cxPixels != 0 && rfbi.cyPixels != 0 &&
   6.338 +        rfbi.pFramePointer != 0 && rfbi.cxStride != 0 && rfbi.cyStride != 0)
   6.339 +	    render_raw = 1;
   6.340 +
   6.341 +    if(preferably && 0 == SDL_strcasecmp(preferably, RAW_RENDER_NAME)) return 0 != render_raw;
   6.342 +
   6.343 +    // gapi check
   6.344 +    HMODULE render_gapi = LoadLibrary(TEXT("\\Windows\\gx.dll"));
   6.345 +    if(0 == render_gapi)
   6.346 +        render_gapi = LoadLibrary(TEXT("gx.dll"));
   6.347 +    FreeLibrary(render_gapi);
   6.348 +
   6.349 +    if(preferably && 0 == SDL_strcasecmp(preferably, GAPI_RENDER_NAME)) return 0 != render_gapi;
   6.350 +
   6.351 +    return 0 != render_raw || 0 != render_gapi;
   6.352  }
   6.353  
   6.354 -void
   6.355 -GAPI_AddRenderDriver(_THIS)
   6.356 +void WINCE_AddRenderDriver(_THIS)
   6.357  {
   6.358 -    int i;
   6.359 +    HDC hdc;
   6.360 +    HMODULE render_gapi;
   6.361 +    int render_raw, ii;
   6.362 +    const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER");
   6.363  
   6.364 -    /* TODO: should we check for support of GetRawFramebuffer here?
   6.365 -     */
   6.366 -#if USE_GAPI_EMU
   6.367 -    g_hGapiLib = LoadLibrary(L"GAPI_Emu.dll");
   6.368 -#else
   6.369 -    g_hGapiLib = LoadLibrary(L"\\Windows\\gx.dll");
   6.370 -#endif
   6.371 +   // raw check
   6.372 +    RawFrameBufferInfo rfbi = { 0 };
   6.373 +    hdc = GetDC(NULL);
   6.374 +    render_raw = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *) &rfbi);
   6.375 +    ReleaseDC(NULL, hdc);
   6.376  
   6.377 -    if (g_hGapiLib) {
   6.378 -#define LINK(name,import) gx.name = (PFN##name)GetProcAddress( g_hGapiLib, L##import );
   6.379 +    if(render_raw != 0 && rfbi.cxPixels != 0 && rfbi.cyPixels != 0 &&
   6.380 +    	rfbi.pFramePointer != 0 && rfbi.cxStride != 0 && rfbi.cyStride != 0)
   6.381 +	    render_raw = 1;
   6.382  
   6.383 -        LINK(GXOpenDisplay, "?GXOpenDisplay@@YAHPAUHWND__@@K@Z")
   6.384 -            LINK(GXCloseDisplay, "?GXCloseDisplay@@YAHXZ")
   6.385 -            LINK(GXBeginDraw, "?GXBeginDraw@@YAPAXXZ")
   6.386 -            LINK(GXEndDraw, "?GXEndDraw@@YAHXZ")
   6.387 -            LINK(GXOpenInput, "?GXOpenInput@@YAHXZ")
   6.388 -            LINK(GXCloseInput, "?GXCloseInput@@YAHXZ")
   6.389 -            LINK(GXGetDisplayProperties,
   6.390 -                 "?GXGetDisplayProperties@@YA?AUGXDisplayProperties@@XZ")
   6.391 -            LINK(GXGetDefaultKeys, "?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z")
   6.392 -            LINK(GXSuspend, "?GXSuspend@@YAHXZ")
   6.393 -            LINK(GXResume, "?GXResume@@YAHXZ")
   6.394 -            LINK(GXSetViewport, "?GXSetViewport@@YAHKKKK@Z")
   6.395 -            LINK(GXIsDisplayDRAMBuffer, "?GXIsDisplayDRAMBuffer@@YAHXZ")
   6.396 +    // gapi check
   6.397 +    render_gapi = LoadLibrary(TEXT("\\Windows\\gx.dll"));
   6.398 +    if(0 == render_gapi)
   6.399 +        render_gapi = LoadLibrary(TEXT("gx.dll"));
   6.400  
   6.401 -            /* wrong gapi.dll */
   6.402 -            if (!gx.GXOpenDisplay) {
   6.403 -            FreeLibrary(g_hGapiLib);
   6.404 -            g_hGapiLib = 0;
   6.405 -        }
   6.406 -#undef LINK
   6.407 -    }
   6.408 +    if(render_gapi)
   6.409 +	FreeLibrary(render_gapi);
   6.410  
   6.411 -    for (i = 0; i < _this->num_displays; ++i) {
   6.412 -        SDL_AddRenderDriver(&_this->displays[i], &GAPI_RenderDriver);
   6.413 +    for(ii = 0; ii < _this->num_displays; ++ii)
   6.414 +    {
   6.415 +	if(preferably)
   6.416 +	{
   6.417 +	    if(0 == SDL_strcasecmp(preferably, RAW_RENDER_NAME) && render_raw)
   6.418 +    		SDL_AddRenderDriver(&_this->displays[ii], &RAW_RenderDriver);
   6.419 +	    else
   6.420 +	    if(0 == SDL_strcasecmp(preferably, GAPI_RENDER_NAME) && render_gapi)
   6.421 +    		SDL_AddRenderDriver(&_this->displays[ii], &GAPI_RenderDriver);
   6.422 +	}
   6.423 +	else
   6.424 +	{
   6.425 +	    if(render_raw)
   6.426 +    		SDL_AddRenderDriver(&_this->displays[ii], &RAW_RenderDriver);
   6.427 +	    if(render_gapi)
   6.428 +    		SDL_AddRenderDriver(&_this->displays[ii], &GAPI_RenderDriver);
   6.429 +	}
   6.430      }
   6.431  }
   6.432  
   6.433 -typedef enum
   6.434 +SDL_Renderer* WINCE_CreateRenderer(SDL_Window* window, Uint32 flags)
   6.435  {
   6.436 -    USAGE_GX_FUNCS = 0x0001,    /* enable to use GXOpen/GXClose/GXBeginDraw... */
   6.437 -    USAGE_DATA_PTR_CONSTANT = 0x0002    /* the framebuffer is at a constant location, don't use values from GXBeginDraw() */
   6.438 -} GAPI_UsageFlags;
   6.439 +    SDL_VideoDisplay* display = window->display;
   6.440 +    SDL_DisplayMode* displayMode = &display->current_mode;
   6.441 +    SDL_WindowData* windowdata = (SDL_WindowData *) window->driverdata;
   6.442 +    SDL_Renderer* renderer;
   6.443 +    WINCE_RenderData* data;
   6.444 +    int bpp;
   6.445 +    Uint32 Rmask, Gmask, Bmask, Amask;
   6.446  
   6.447 +    if(!(window->flags & SDL_WINDOW_FULLSCREEN))
   6.448 +	window->flags |= SDL_WINDOW_FULLSCREEN;
   6.449  
   6.450 -
   6.451 -typedef struct
   6.452 -{
   6.453 -    int w;
   6.454 -    int h;
   6.455 -    int xPitch;                 /* bytes to move to go to the next pixel */
   6.456 -    int yPitch;                 /* bytes to move to go to the next line */
   6.457 -    int offset;                 /* data offset, to add to the data returned from GetFramebuffer, before processing */
   6.458 -
   6.459 -    void *data;
   6.460 -    Uint32 usageFlags;          /* these flags contain options to define screen handling and to reliably workarounds */
   6.461 -
   6.462 -    Uint32 format;              /* pixel format as defined in SDL_pixels.h */
   6.463 -
   6.464 -} GAPI_RenderData;
   6.465 -
   6.466 -
   6.467 -static Uint32
   6.468 -GuessPixelFormatFromBpp(int bpp)
   6.469 -{
   6.470 -    switch (bpp) {
   6.471 -    case 15:
   6.472 -        return SDL_PIXELFORMAT_RGB555;
   6.473 -    case 16:
   6.474 -        return SDL_PIXELFORMAT_RGB565;
   6.475 -    default:
   6.476 -        return SDL_PIXELFORMAT_UNKNOWN;
   6.477 -        break;
   6.478 -    }
   6.479 -}
   6.480 -
   6.481 -static GAPI_RenderData *
   6.482 -FillRenderDataRawFramebuffer(SDL_Window * window)
   6.483 -{
   6.484 -    RawFrameBufferInfo rbi;
   6.485 -    GAPI_RenderData *renderdata;
   6.486 -    HDC hdc;
   6.487 -
   6.488 -    //TODO should we use the hdc of the window?
   6.489 -    hdc = GetDC(NULL);
   6.490 -    int result = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL,
   6.491 -                           sizeof(RawFrameBufferInfo),
   6.492 -                           (char *) &rbi);
   6.493 -    ReleaseDC(NULL, hdc);
   6.494 -
   6.495 -    if (!(result > 0)) {
   6.496 +    if(!SDL_PixelFormatEnumToMasks(displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask))
   6.497 +    {
   6.498 +        SDL_SetError("Unknown display format");
   6.499          return NULL;
   6.500      }
   6.501  
   6.502 -    /* Asus A696 returns wrong results so we do a sanity check
   6.503 -       See:
   6.504 -       http://groups.google.com/group/microsoft.public.smartphone.developer/browse_thread/thread/4fde5bddd477de81
   6.505 -     */
   6.506 -    if (rbi.cxPixels <= 0 ||
   6.507 -        rbi.cyPixels <= 0 ||
   6.508 -        rbi.cxStride == 0 || rbi.cyStride == 0 || rbi.pFramePointer == 0) {
   6.509 -        return NULL;
   6.510 +    switch(window->fullscreen_mode.format)
   6.511 +    {
   6.512 +	case SDL_PIXELFORMAT_RGB555:
   6.513 +	case SDL_PIXELFORMAT_RGB565:
   6.514 +	    break;
   6.515 +
   6.516 +	default:
   6.517 +    	    SDL_SetError("Support only 16 or 15 bpp");
   6.518 +	    return NULL;
   6.519      }
   6.520  
   6.521 -
   6.522 -    renderdata = (GAPI_RenderData *) SDL_calloc(1, sizeof(*renderdata));
   6.523 -    if (!renderdata) {
   6.524 -        SDL_OutOfMemory();
   6.525 -        return NULL;
   6.526 -    }
   6.527 -    //Try to match the window size
   6.528 -    //TODO add rotation support
   6.529 -    if (rbi.cxPixels != window->w || rbi.cyPixels != window->h) {
   6.530 -        SDL_free(renderdata);
   6.531 -        return NULL;
   6.532 -    }
   6.533 -    //Check that the display uses a known display format
   6.534 -    switch (rbi.wFormat) {
   6.535 -    case FORMAT_565:
   6.536 -        renderdata->format = SDL_PIXELFORMAT_RGB565;
   6.537 -        break;
   6.538 -    case FORMAT_555:
   6.539 -        renderdata->format = SDL_PIXELFORMAT_RGB555;
   6.540 -        break;
   6.541 -    default:
   6.542 -        //TODO we should add support for other formats
   6.543 -        SDL_free(renderdata);
   6.544 -        return NULL;
   6.545 -    }
   6.546 -
   6.547 -    renderdata->usageFlags = USAGE_DATA_PTR_CONSTANT;
   6.548 -    renderdata->data = rbi.pFramePointer;
   6.549 -    renderdata->w = rbi.cxPixels;
   6.550 -    renderdata->h = rbi.cyPixels;
   6.551 -    renderdata->xPitch = rbi.cxStride;
   6.552 -    renderdata->yPitch = rbi.cyStride;
   6.553 -
   6.554 -    return renderdata;
   6.555 -
   6.556 -}
   6.557 -
   6.558 -
   6.559 -static GAPI_RenderData *
   6.560 -FillRenderDataGAPI(SDL_Window * window)
   6.561 -{
   6.562 -    GAPI_RenderData *renderdata;
   6.563 -    struct GXDisplayProperties gxdp;
   6.564 -    int tmp;
   6.565 -
   6.566 -#ifdef _ARM_
   6.567 -    WCHAR oemstr[100];
   6.568 -#endif
   6.569 -
   6.570 -    if (!g_hGapiLib) {
   6.571 -        return NULL;
   6.572 -    }
   6.573 -
   6.574 -    renderdata = (GAPI_RenderData *) SDL_calloc(1, sizeof(GAPI_RenderData));
   6.575 -    if (!renderdata) {
   6.576 +    renderer = (SDL_Renderer*) SDL_calloc(1, sizeof(SDL_Renderer));
   6.577 +    if(!renderer)
   6.578 +    {
   6.579          SDL_OutOfMemory();
   6.580          return NULL;
   6.581      }
   6.582  
   6.583 -    gxdp = gx.GXGetDisplayProperties();
   6.584 -    renderdata->usageFlags = USAGE_GX_FUNCS;
   6.585 -    renderdata->w = gxdp.cxWidth;
   6.586 -    renderdata->h = gxdp.cyHeight;
   6.587 -    renderdata->xPitch = gxdp.cbxPitch;
   6.588 -    renderdata->yPitch = gxdp.cbyPitch;
   6.589 -
   6.590 -    //Check that the display uses a known display format
   6.591 -    if (gxdp.ffFormat & kfDirect565) {
   6.592 -        renderdata->format = SDL_PIXELFORMAT_RGB565;
   6.593 -    } else if (gxdp.ffFormat & kfDirect555) {
   6.594 -        renderdata->format = SDL_PIXELFORMAT_RGB555;
   6.595 -    } else {
   6.596 -        renderdata->format = SDL_PIXELFORMAT_UNKNOWN;
   6.597 -    }
   6.598 -
   6.599 -    /* apply some device specific corrections */
   6.600 -#ifdef _ARM_
   6.601 -    SystemParametersInfo(SPI_GETOEMINFO, sizeof(oemstr), oemstr, 0);
   6.602 -
   6.603 -    // buggy iPaq38xx
   6.604 -    if ((oemstr[12] == 'H') && (oemstr[13] == '3')
   6.605 -        && (oemstr[14] == '8')
   6.606 -        && (gxdp.cbxPitch > 0)) {
   6.607 -        renderdata->data = (void *) 0xac0755a0;
   6.608 -        renderdata->xPitch = -640;
   6.609 -        renderdata->yPitch = 2;
   6.610 -    }
   6.611 -#if (EMULATE_AXIM_X30 == 0)
   6.612 -    // buggy Dell Axim X30
   6.613 -    if (_tcsncmp(oemstr, L"Dell Axim X30", 13) == 0)
   6.614 -#endif
   6.615 +    data = (WINCE_RenderData*) SDL_calloc(1, sizeof(WINCE_RenderData));
   6.616 +    if(!data)
   6.617      {
   6.618 -        GXDeviceInfo gxInfo = { 0 };
   6.619 -        HDC hdc = GetDC(NULL);
   6.620 -        int result;
   6.621 -
   6.622 -        gxInfo.Version = 100;
   6.623 -        result =
   6.624 -            ExtEscape(hdc, GETGXINFO, 0, NULL, sizeof(gxInfo),
   6.625 -                      (char *) &gxInfo);
   6.626 -        if (result > 0) {
   6.627 -            renderdata->usageFlags = USAGE_DATA_PTR_CONSTANT;   /* no more GAPI usage from now */
   6.628 -            renderdata->data = gxInfo.pvFrameBuffer;
   6.629 -            this->hidden->needUpdate = 0;
   6.630 -            renderdata->xPitch = 2;
   6.631 -            renderdata->yPitch = 480;
   6.632 -            renderdata->w = gxInfo.cxWidth;
   6.633 -            renderdata->h = gxInfo.cyHeight;
   6.634 -
   6.635 -            //Check that the display uses a known display format
   6.636 -            switch (rbi->wFormat) {
   6.637 -            case FORMAT_565:
   6.638 -                renderdata->format = SDL_PIXELFORMAT_RGB565;
   6.639 -                break;
   6.640 -            case FORMAT_555:
   6.641 -                renderdata->format = SDL_PIXELFORMAT_RGB555;
   6.642 -                break;
   6.643 -            default:
   6.644 -                //TODO we should add support for other formats
   6.645 -                SDL_free(renderdata);
   6.646 -                return NULL;
   6.647 -            }
   6.648 -        }
   6.649 -    }
   6.650 -#endif
   6.651 -
   6.652 -
   6.653 -    if (renderdata->format == SDL_PIXELFORMAT_UNKNOWN) {
   6.654 -        SDL_SetError("Gapi Pixelformat is unknown");
   6.655 -        SDL_free(renderdata);
   6.656 -        return NULL;
   6.657 -    }
   6.658 -
   6.659 -    /* Gapi always returns values in standard orientation, so we manually apply
   6.660 -       the current orientation 
   6.661 -     */
   6.662 -
   6.663 -    DEVMODE settings;
   6.664 -    SDL_memset(&settings, 0, sizeof(DEVMODE));
   6.665 -    settings.dmSize = sizeof(DEVMODE);
   6.666 -
   6.667 -    settings.dmFields = DM_DISPLAYORIENTATION;
   6.668 -    ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_TEST, NULL);
   6.669 -
   6.670 -    if (settings.dmDisplayOrientation == DMDO_90) {
   6.671 -
   6.672 -        tmp = renderdata->w;
   6.673 -        renderdata->w = renderdata->h;
   6.674 -        renderdata->h = tmp;
   6.675 -
   6.676 -        tmp = renderdata->xPitch;
   6.677 -        renderdata->xPitch = -renderdata->yPitch;
   6.678 -        renderdata->yPitch = tmp;
   6.679 -
   6.680 -        renderdata->offset = -renderdata->w * renderdata->xPitch;
   6.681 -
   6.682 -    } else if (settings.dmDisplayOrientation == DMDO_180) {
   6.683 -
   6.684 -        renderdata->xPitch = -renderdata->xPitch;
   6.685 -        renderdata->yPitch = -renderdata->yPitch;
   6.686 -
   6.687 -        renderdata->offset = -renderdata->h * renderdata->yPitch
   6.688 -            - renderdata->w * renderdata->xPitch;
   6.689 -
   6.690 -    } else if (settings.dmDisplayOrientation == DMDO_270) {
   6.691 -
   6.692 -        tmp = renderdata->w;
   6.693 -        renderdata->w = renderdata->h;
   6.694 -        renderdata->h = tmp;
   6.695 -
   6.696 -        tmp = renderdata->xPitch;
   6.697 -        renderdata->xPitch = renderdata->yPitch;
   6.698 -        renderdata->yPitch = -tmp;
   6.699 -
   6.700 -        renderdata->offset = -renderdata->h * renderdata->yPitch;
   6.701 -
   6.702 -    }
   6.703 -
   6.704 -    if (renderdata->w != window->w || renderdata->h != window->h) {
   6.705 -        GAPI_LOG("GAPI open failed, wrong size %i %i %i %i\n", renderdata->w,
   6.706 -                 renderdata->h, renderdata->xPitch, renderdata->yPitch);
   6.707 -        SDL_free(renderdata);
   6.708 -        return NULL;
   6.709 -    }
   6.710 -
   6.711 -    return renderdata;
   6.712 -
   6.713 -}
   6.714 -
   6.715 -
   6.716 -/* This function does the whole encapsulation of Gapi/RAWFRAMEBUFFER
   6.717 -   it should handle all the device dependent details and fill the device INDEPENDENT
   6.718 -   RenderData structure.
   6.719 - */
   6.720 -GAPI_RenderData *
   6.721 -FillRenderData(SDL_Window * window)
   6.722 -{
   6.723 -    /* We try to match the requested window to the modes available by GAPI and RAWFRAMEBUFFER.
   6.724 -       First RAWFRAMEBUFFER is tried, as it is the most reliable one 
   6.725 -       Look here for detailed discussions:
   6.726 -       http://pdaphonehome.com/forums/samsung-i700/28087-just-saw.html
   6.727 -       http://blogs.msdn.com/windowsmobile/archive/2007/08/13/have-you-migrated-to-directdraw-yet.aspx
   6.728 -     */
   6.729 -
   6.730 -    GAPI_RenderData *res;
   6.731 -
   6.732 -    res = FillRenderDataRawFramebuffer(window);
   6.733 -    GAPI_LOG("FillRenderDataRawFramebuffer: %p\n", res);
   6.734 -    if (res) {
   6.735 -        return res;
   6.736 -    }
   6.737 -    //Now we try gapi
   6.738 -    res = FillRenderDataGAPI(window);
   6.739 -    GAPI_LOG("FillRenderDataGAPI: %p\n", res);
   6.740 -
   6.741 -    return res;
   6.742 -}
   6.743 -
   6.744 -void *
   6.745 -GetFramebuffer()
   6.746 -{
   6.747 -
   6.748 -}
   6.749 -
   6.750 -
   6.751 -SDL_Renderer *
   6.752 -GAPI_CreateRenderer(SDL_Window * window, Uint32 flags)
   6.753 -{
   6.754 -    SDL_VideoDisplay *display = window->display;
   6.755 -    SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
   6.756 -    SDL_DisplayMode *displayMode = &display->current_mode;
   6.757 -    SDL_Renderer *renderer;
   6.758 -    GAPI_RenderData *data;
   6.759 -    int i, n;
   6.760 -    int bpp;
   6.761 -    Uint32 Rmask, Gmask, Bmask, Amask;
   6.762 -
   6.763 -    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
   6.764 -        SDL_SetError("Gapi supports only fullscreen windows");
   6.765 -        return NULL;
   6.766 -    }
   6.767 -
   6.768 -    if (!SDL_PixelFormatEnumToMasks
   6.769 -        (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
   6.770 -        SDL_SetError("Unknown display format");
   6.771 -        return NULL;
   6.772 -    }
   6.773 -
   6.774 -    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
   6.775 -    if (!renderer) {
   6.776 +        WINCE_DestroyRenderer(renderer);
   6.777          SDL_OutOfMemory();
   6.778          return NULL;
   6.779      }
   6.780  
   6.781 -    data = FillRenderData(window);
   6.782 -    if (!data) {
   6.783 -        GAPI_DestroyRenderer(renderer);
   6.784 -        SDL_OutOfMemory();
   6.785 +    // initialize internal engine
   6.786 +    if(!RAW_Init(data) && !GAPI_Init(data, windowdata->hwnd))
   6.787 +    {
   6.788 +        WINCE_DestroyRenderer(renderer);
   6.789          return NULL;
   6.790      }
   6.791  
   6.792 -    renderer->RenderDrawPoints = GAPI_RenderDrawPoints;
   6.793 -    renderer->RenderDrawLines = GAPI_RenderDrawLines;
   6.794 -    renderer->RenderDrawRects = GAPI_RenderDrawRects;
   6.795 -    renderer->RenderFillRects = GAPI_RenderFillRects;
   6.796 -    renderer->RenderCopy = GAPI_RenderCopy;
   6.797 -    renderer->RenderPresent = GAPI_RenderPresent;
   6.798 -    renderer->DestroyRenderer = GAPI_DestroyRenderer;
   6.799 -    renderer->info.name = GAPI_RenderDriver.info.name;
   6.800 -    renderer->info.flags = 0;
   6.801 +
   6.802 +    // set debug
   6.803 +    data->debug	= SDL_getenv("DEBUG_VIDEO_GAPI") || SDL_getenv("GAPI_RENDERER_DEBUG") ? 1 : 0;
   6.804 +#if defined(DEBUG_VIDEO_GAPI) || defined(GAPI_RENDERER_DEBUG)
   6.805 +    data->debug	= 1;
   6.806 +#endif
   6.807 +
   6.808 +    windowdata->videodata->render = data->gapi ? RENDER_GAPI : RENDER_RAW;
   6.809 +    windowdata->videodata->CoordTransform = WINCE_PointerCoordinateTransform;
   6.810 +
   6.811 +    window->display->device->MaximizeWindow = NULL;
   6.812 +    window->display->device->MinimizeWindow = NULL;
   6.813 +
   6.814 +    WINCE_SetupOrientation(data, window->w, window->h);
   6.815 +
   6.816 +    renderer->CreateTexture = WINCE_CreateTexture;
   6.817 +    renderer->DestroyTexture = WINCE_DestroyTexture;
   6.818 +    renderer->QueryTexturePixels = WINCE_QueryTexturePixels;
   6.819 +    renderer->UpdateTexture = WINCE_UpdateTexture;
   6.820 +    renderer->LockTexture = WINCE_LockTexture;
   6.821 +    renderer->UnlockTexture = WINCE_UnlockTexture;
   6.822 +
   6.823 +    renderer->RenderCopy = WINCE_RenderCopy;
   6.824 +    renderer->DestroyRenderer = WINCE_DestroyRenderer;
   6.825 +
   6.826 +    renderer->RenderPresent = WINCE_RenderPresent;
   6.827 +    renderer->RenderDrawPoints = WINCE_RenderDrawPoints;
   6.828 +    renderer->RenderDrawLines = WINCE_RenderDrawLines;
   6.829 +    renderer->RenderDrawRects = WINCE_RenderDrawRects;
   6.830 +    renderer->RenderFillRects = WINCE_RenderFillRects;
   6.831 +
   6.832 +    renderer->info = data->gapi ? GAPI_RenderDriver.info : RAW_RenderDriver.info;
   6.833 +
   6.834      renderer->window = window;
   6.835      renderer->driverdata = data;
   6.836  
   6.837 -    /* Gapi provides only a framebuffer so lets use software implementation */
   6.838 -    Setup_SoftwareRenderer(renderer);
   6.839 -
   6.840 -#ifdef GAPI_RENDERER_DEBUG
   6.841 -    printf("Created gapi renderer\n");
   6.842 -    printf("use GX functions: %i\n", data->usageFlags & USAGE_GX_FUNCS);
   6.843 -    printf("framebuffer is constant: %i\n",
   6.844 -           data->usageFlags & USAGE_DATA_PTR_CONSTANT);
   6.845 -    printf("w: %i h: %i\n", data->w, data->h);
   6.846 -    printf("data ptr: %p\n", data->data);       /* this can be 0 in case of GAPI usage */
   6.847 -    printf("xPitch: %i\n", data->xPitch);
   6.848 -    printf("yPitch: %i\n", data->yPitch);
   6.849 -    printf("offset: %i\n", data->offset);
   6.850 -    printf("format: %x\n", data->format);
   6.851 -#endif
   6.852 -
   6.853 -    if (data->usageFlags & USAGE_GX_FUNCS) {
   6.854 -        if (gx.GXOpenDisplay(windowdata->hwnd, GX_FULLSCREEN) == 0) {
   6.855 -            GAPI_DestroyRenderer(renderer);
   6.856 -            return NULL;
   6.857 -        }
   6.858 -    }
   6.859 -
   6.860      return renderer;
   6.861  }
   6.862  
   6.863 -static int
   6.864 -GAPI_RenderDrawPoints(SDL_Renderer * renderer,
   6.865 -                      const SDL_Point * points, int count)
   6.866 +void WINCE_DestroyRenderer(SDL_Renderer* renderer)
   6.867  {
   6.868 -    // TODO implement
   6.869 +    WINCE_RenderData *renderdata = (WINCE_RenderData*) renderer->driverdata;
   6.870 +
   6.871 +    if(renderdata)
   6.872 +    {
   6.873 +	if(renderdata->gapi)
   6.874 +    	    GAPI_Quit(renderdata);
   6.875 +	else
   6.876 +	    RAW_Quit(renderdata);
   6.877 +
   6.878 +        SDL_free(renderdata);
   6.879 +    }
   6.880 +
   6.881 +    SDL_free(renderer);
   6.882 +}
   6.883 +
   6.884 +int WINCE_CreateTexture(SDL_Renderer* renderer, SDL_Texture* texture)
   6.885 +{
   6.886 +    WINCE_TextureData* texturedata = (WINCE_TextureData*) SDL_calloc(1, sizeof(WINCE_TextureData));
   6.887 +    if(NULL == texturedata)
   6.888 +    {
   6.889 +        SDL_OutOfMemory();
   6.890 +        return -1;
   6.891 +    }
   6.892 +
   6.893 +    texturedata->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
   6.894 +    texturedata->pixels = SDL_malloc(texture->h * texturedata->pitch);
   6.895 +    if(NULL == texturedata->pixels)
   6.896 +    {
   6.897 +        SDL_OutOfMemory();
   6.898 +        return -1;
   6.899 +    }
   6.900 +
   6.901 +    if(SDL_ISPIXELFORMAT_FOURCC(texture->format))
   6.902 +    {
   6.903 +	texturedata->yuv = SDL_SW_CreateYUVTexture(texture->format, texture->w, texture->h);
   6.904 +        if(NULL == texturedata->yuv)
   6.905 +	{
   6.906 +    	    SDL_OutOfMemory();
   6.907 +            return -1;
   6.908 +        }
   6.909 +	SDL_Window* window = renderer->window;
   6.910 +	SDL_VideoDisplay* display = window->display;
   6.911 +	texturedata->format = display->current_mode.format;
   6.912 +    }
   6.913 +    else
   6.914 +    {
   6.915 +	texturedata->yuv = NULL;
   6.916 +	texturedata->format = texture->format;
   6.917 +    }
   6.918 +
   6.919 +    texture->driverdata = texturedata;
   6.920 +
   6.921 +    return 0;
   6.922 +}
   6.923 +
   6.924 +void WINCE_DestroyTexture(SDL_Renderer* renderer, SDL_Texture* texture)
   6.925 +{
   6.926 +    WINCE_TextureData *texturedata = (WINCE_TextureData*) texture->driverdata;
   6.927 +
   6.928 +    if(texturedata)
   6.929 +    {
   6.930 +	if(texturedata->yuv) SDL_SW_DestroyYUVTexture(texturedata->yuv);
   6.931 +	if(texturedata->pixels) SDL_free(texturedata->pixels);
   6.932 +	SDL_free(texturedata);
   6.933 +	texture->driverdata = NULL;
   6.934 +    }
   6.935 +}
   6.936 +
   6.937 +int WINCE_QueryTexturePixels(SDL_Renderer* renderer, SDL_Texture* texture, void** pixels, int* pitch)
   6.938 +{
   6.939 +    WINCE_TextureData* texturedata = (WINCE_TextureData*) texture->driverdata;
   6.940 +
   6.941 +    if(texturedata->yuv)
   6.942 +        return SDL_SW_QueryYUVTexturePixels(texturedata->yuv, pixels, pitch);
   6.943 +
   6.944 +    *pixels = texturedata->pixels;
   6.945 +    *pitch = texturedata->pitch;
   6.946 +
   6.947 +    return 0;
   6.948 +}
   6.949 +
   6.950 +int WINCE_UpdateTexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, const void* pixels, int pitch)
   6.951 +{
   6.952 +    WINCE_TextureData* texturedata = (WINCE_TextureData*) texture->driverdata;
   6.953 +
   6.954 +    if(texturedata->yuv)
   6.955 +    {
   6.956 +        if(SDL_SW_UpdateYUVTexture(texturedata->yuv, rect, pixels, pitch) < 0)
   6.957 +            return -1;
   6.958 +        WINCE_UpdateYUVTextureData(texture);
   6.959 +        return 0;
   6.960 +    }
   6.961 +
   6.962 +    if(0 < rect->w && 0 < rect->h)
   6.963 +    {
   6.964 +	const unsigned char *src = ((const unsigned char*) pixels);
   6.965 +	unsigned char *dst = ((unsigned char*) texturedata->pixels) +
   6.966 +				rect->y * texturedata->pitch +
   6.967 +				rect->x * SDL_BYTESPERPIXEL(texture->format);
   6.968 +        int length = rect->w * SDL_BYTESPERPIXEL(texture->format);
   6.969 +	int height = rect->h;
   6.970 +
   6.971 +	while(height--)
   6.972 +	{
   6.973 +	    SDL_memcpy(dst, src, length);
   6.974 +	    dst += texturedata->pitch;
   6.975 +	    src += pitch;
   6.976 +	}
   6.977 +    }
   6.978 +
   6.979 +    return 0;
   6.980 +}
   6.981 +
   6.982 +int WINCE_LockTexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, int dirty, void** pixels, int* pitch)
   6.983 +{
   6.984 +    WINCE_TextureData *texturedata = (WINCE_TextureData*) texture->driverdata;
   6.985 +
   6.986 +    if(texturedata->yuv)
   6.987 +        return SDL_SW_LockYUVTexture(texturedata->yuv, rect, dirty, pixels, pitch);
   6.988 +
   6.989 +    *pixels = (void *) ((unsigned char*) texturedata->pixels +
   6.990 +		    rect->y * texturedata->pitch +
   6.991 +		    rect->x * SDL_BYTESPERPIXEL(texture->format));
   6.992 +    *pitch = texturedata->pitch;
   6.993 +}
   6.994 +
   6.995 +void WINCE_UnlockTexture(SDL_Renderer* renderer, SDL_Texture* texture)
   6.996 +{
   6.997 +    WINCE_TextureData *texturedata = (WINCE_TextureData*) texture->driverdata;
   6.998 +
   6.999 +    if(texturedata->yuv)
  6.1000 +    {
  6.1001 +        SDL_SW_UnlockYUVTexture(texturedata->yuv);
  6.1002 +	WINCE_UpdateYUVTextureData(texture);
  6.1003 +    }
  6.1004 +}
  6.1005 +
  6.1006 +int WINCE_RenderCopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srect, const SDL_Rect* drect)
  6.1007 +{
  6.1008 +    WINCE_RenderData* dstdata = (WINCE_RenderData*) renderer->driverdata;
  6.1009 +    WINCE_TextureData* srcdata = (WINCE_TextureData*) texture->driverdata;
  6.1010 +
  6.1011 +    if((dstdata->flags & FB_SUSPENDED) ||
  6.1012 +       0 >= srect->w || 0 >= srect->h) return;
  6.1013 +
  6.1014 +    // lock gapi
  6.1015 +    if(dstdata->gapi) dstdata->gapi->GXBeginDraw();
  6.1016 +
  6.1017 +    const unsigned char *src = ((const unsigned char*) srcdata->pixels);
  6.1018 +    unsigned char *dst = dstdata->pixels + (dstdata->flags & FB_SKIP_OFFSET ? 0 : dstdata->fb.offset) +
  6.1019 +				drect->y * dstdata->fb.ypitch +
  6.1020 +				drect->x * dstdata->fb.xpitch;
  6.1021 +    if(srcdata->yuv)
  6.1022 +    {
  6.1023 +	return SDL_SW_CopyYUVToRGB(srcdata->yuv,
  6.1024 +                                   srect, srcdata->format,
  6.1025 +                                   drect->w, drect->h, dst,
  6.1026 +                                   dstdata->fb.ypitch);
  6.1027 +    }
  6.1028 +    else
  6.1029 +    {
  6.1030 +	int height = drect->h;
  6.1031 +	int length = drect->w * SDL_BYTESPERPIXEL(texture->format); // in bytes
  6.1032 +
  6.1033 +	while(height--)
  6.1034 +	{
  6.1035 +	    switch(SDL_BYTESPERPIXEL(texture->format))
  6.1036 +	    {
  6.1037 +		case 2: UpdateLine16to16(&dstdata->fb, (Uint16*) src, (Uint16*) dst, length >> 1); break;
  6.1038 +
  6.1039 +		default: break;
  6.1040 +	    }
  6.1041 +
  6.1042 +	    dst += dstdata->fb.ypitch;
  6.1043 +	    src += srcdata->pitch;
  6.1044 +	}
  6.1045 +    }
  6.1046 +
  6.1047 +    // unlock gapi
  6.1048 +    if(dstdata->gapi) dstdata->gapi->GXEndDraw();
  6.1049 +
  6.1050 +    return 0;
  6.1051 +}
  6.1052 +
  6.1053 +void WINCE_RenderPresent(SDL_Renderer* renderer)
  6.1054 +{
  6.1055 +}
  6.1056 +
  6.1057 +int WINCE_RenderDrawPoints(SDL_Renderer* renderer, const SDL_Point* points, int count)
  6.1058 +{
  6.1059      SDL_Unsupported();
  6.1060      return -1;
  6.1061  }
  6.1062  
  6.1063 -static int
  6.1064 -GAPI_RenderDrawLines(SDL_Renderer * renderer,
  6.1065 -                     const SDL_Point * points, int count)
  6.1066 +int WINCE_RenderDrawLines(SDL_Renderer* renderer, const SDL_Point* points, int count)
  6.1067  {
  6.1068 -    // TODO implement
  6.1069      SDL_Unsupported();
  6.1070      return -1;
  6.1071  }
  6.1072  
  6.1073 -static int
  6.1074 -GAPI_RenderDrawRects(SDL_Renderer * renderer,
  6.1075 -                     const SDL_Rect ** rects, int count)
  6.1076 +int WINCE_RenderDrawRects(SDL_Renderer* renderer, const SDL_Rect ** rects, int count)
  6.1077  {
  6.1078 -    // TODO implement
  6.1079      SDL_Unsupported();
  6.1080      return -1;
  6.1081  }
  6.1082  
  6.1083 -static int
  6.1084 -GAPI_RenderFillRects(SDL_Renderer * renderer,
  6.1085 -                     const SDL_Rect ** rects, int count)
  6.1086 +int WINCE_RenderFillRects(SDL_Renderer* renderer, const SDL_Rect** rects, int count)
  6.1087  {
  6.1088 -    // TODO implement
  6.1089      SDL_Unsupported();
  6.1090      return -1;
  6.1091  }
  6.1092  
  6.1093 -/* Video memory is very slow so lets optimize as much as possible */
  6.1094 -static void
  6.1095 -updateLine16to16(char *src, int srcXPitch, int srcYPitch,
  6.1096 -                 char *dst, int dstXPitch, int dstYPitch, int width,
  6.1097 -                 int height)
  6.1098 +
  6.1099 +
  6.1100 +void WINCE_SetupOrientation(WINCE_RenderData* data, int width, int height)
  6.1101  {
  6.1102 -    char *srcLine, *dstLine;
  6.1103 -    char *srcPix, *dstPix;
  6.1104 +    const float maxW1 = GetSystemMetrics(SM_CXSCREEN) > GetSystemMetrics(SM_CYSCREEN) ? GetSystemMetrics(SM_CXSCREEN) : GetSystemMetrics(SM_CYSCREEN);
  6.1105 +    const float maxW2 = data->fb.width > data->fb.height ? data->fb.width : data->fb.height;
  6.1106  
  6.1107 -    int x, y;
  6.1108 +    // scale define
  6.1109 +    data->scale = maxW2 / maxW1;
  6.1110  
  6.1111 -    //First dumb solution
  6.1112 -    if (srcXPitch == 2 && dstXPitch == 2) {
  6.1113 -        srcLine = src;
  6.1114 -        dstLine = dst;
  6.1115 -        y = height;
  6.1116 -        while (y--) {
  6.1117 -            SDL_memcpy(dstLine, srcLine, width * sizeof(Uint16));
  6.1118 -            srcLine += srcYPitch;
  6.1119 -            dstLine += dstYPitch;
  6.1120 -        }
  6.1121 -    } else {
  6.1122 -        //printf("GAPI uses slow blit path %i, %i\n", dstXPitch, dstYPitch);
  6.1123 -        srcLine = src;
  6.1124 -        dstLine = dst;
  6.1125 -        y = height;
  6.1126 -        while (y--) {
  6.1127 -            srcPix = srcLine;
  6.1128 -            dstPix = dstLine;
  6.1129 -            x = width;
  6.1130 -            while (x--) {
  6.1131 -                *((Uint16 *) dstPix) = *((Uint16 *) srcPix);
  6.1132 -                dstPix += dstXPitch;
  6.1133 -                srcPix += srcXPitch;
  6.1134 -            }
  6.1135 -            srcLine += srcYPitch;
  6.1136 -            dstLine += dstYPitch;
  6.1137 -        }
  6.1138 +    // init fb values
  6.1139 +    FrameBufferInitialize(&data->fb);
  6.1140 +
  6.1141 +    // orientation values
  6.1142 +    data->userOrientation = ORIENTATION_UP;
  6.1143 +    data->systemOrientation = WINCE_GetDMOrientation();
  6.1144 +    data->hardwareGeometry = data->fb.width == data->fb.height ? GEOMETRY_SQUARE :
  6.1145 +				(data->fb.width < data->fb.height ? GEOMETRY_PORTRAIT : GEOMETRY_LANDSCAPE);
  6.1146 +
  6.1147 +    if(data->debug)
  6.1148 +	WINCE_DumpVideoInfo(data);
  6.1149 +
  6.1150 +    if(data->systemOrientation == ORIENTATION_UNKNOWN)
  6.1151 +	data->systemOrientation == ORIENTATION_UP;
  6.1152 +
  6.1153 +    data->userOrientation = ORIENTATION_UP;
  6.1154 +
  6.1155 +    switch(data->hardwareGeometry)
  6.1156 +    {
  6.1157 +	case GEOMETRY_PORTRAIT:  WINCE_PortraitTransform(data, width, height); break;
  6.1158 +	case GEOMETRY_LANDSCAPE: WINCE_LandscapeTransform(data, width, height); break;
  6.1159 +	case GEOMETRY_SQUARE:    WINCE_SquareTransform(data, width, height); break;
  6.1160 +	default: break;
  6.1161 +    }
  6.1162 +
  6.1163 +    // debug
  6.1164 +    if(data->debug)
  6.1165 +    {
  6.1166 +	printf("\n");
  6.1167 +	printf("user video width:          %d\n", width);
  6.1168 +	printf("user video height:         %d\n", height);
  6.1169 +	FrameBufferDumpInfo(&data->fb, "user");
  6.1170      }
  6.1171  }
  6.1172  
  6.1173 -static int
  6.1174 -GAPI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
  6.1175 -                const SDL_Rect * srcrect, const SDL_Rect * dstrect)
  6.1176 +void WINCE_DumpVideoInfo(WINCE_RenderData* data)
  6.1177  {
  6.1178 -    GAPI_RenderData *data = (GAPI_RenderData *) renderer->driverdata;
  6.1179 -    int bpp;
  6.1180 -    int bytespp;
  6.1181 -    int status;
  6.1182 -    Uint32 Rmask, Gmask, Bmask, Amask;
  6.1183 +    // get oem info
  6.1184 +    WCHAR oemInfo[48];
  6.1185 +    SDL_memset(oemInfo, 0, sizeof(oemInfo));
  6.1186 +    SystemParametersInfo(SPI_GETOEMINFO, sizeof(oemInfo) - sizeof(WCHAR), oemInfo, 0);
  6.1187  
  6.1188 -    if (texture->format != data->format) {
  6.1189 -        SDL_SetError("Gapi got wrong texture");
  6.1190 -        return -1;
  6.1191 +    printf("hardware oem: ");
  6.1192 +    wprintf(oemInfo);
  6.1193 +    printf("\n");
  6.1194 +
  6.1195 +    printf("video driver mode:             %s\n", (data->flags & FB_RAW_MODE ? RAW_RENDER_NAME : GAPI_RENDER_NAME));
  6.1196 +    printf("GetSystemMetrics(SM_CXSCREEN): %d\n", GetSystemMetrics(SM_CXSCREEN));
  6.1197 +    printf("GetSystemMetrics(SM_CYSCREEN): %d\n", GetSystemMetrics(SM_CYSCREEN));
  6.1198 +    printf("scale coord:                   %f\n", data->scale);
  6.1199 +
  6.1200 +    FrameBufferDumpInfo(&data->fb, "hardware");
  6.1201 +
  6.1202 +    printf("display format:                %p\n", data->format);
  6.1203 +    printf("display bits per pixel:        %d\n", SDL_BITSPERPIXEL(data->format));
  6.1204 +    printf("display bytes per pixel:       %d\n", SDL_BYTESPERPIXEL(data->format));
  6.1205 +    printf("display memory:                %p\n", data->pixels);
  6.1206 +    printf("system orientation:            %d, %s\n", data->systemOrientation, GetOrientationName(data->systemOrientation));
  6.1207 +    printf("hardware geometry:             %d\n", data->hardwareGeometry);
  6.1208 +}
  6.1209 +
  6.1210 +void WINCE_ShowWindow(_THIS, SDL_Window* window, int visible)
  6.1211 +{
  6.1212 +    SDL_WindowData* windowdata = (SDL_WindowData*) window->driverdata;
  6.1213 +    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
  6.1214 +    SDL_Renderer* renderer = (SDL_Renderer*) window->renderer;
  6.1215 +
  6.1216 +    if(visible)
  6.1217 +    {
  6.1218 +	if(window->flags & SDL_WINDOW_FULLSCREEN)
  6.1219 +	{
  6.1220 +	    if(videodata->SHFullScreen)
  6.1221 +		videodata->SHFullScreen(windowdata->hwnd, SHFS_HIDETASKBAR | SHFS_HIDESTARTICON | SHFS_HIDESIPBUTTON);
  6.1222 +	    ShowWindow(FindWindow(TEXT("HHTaskBar"), NULL), SW_HIDE);
  6.1223 +	}
  6.1224 +
  6.1225 +	ShowWindow(windowdata->hwnd, SW_SHOW);
  6.1226 +        SetForegroundWindow(windowdata->hwnd);
  6.1227 +
  6.1228 +	if(renderer &&
  6.1229 +	    (videodata->render == RENDER_GAPI || videodata->render == RENDER_RAW))
  6.1230 +	{
  6.1231 +	    WINCE_RenderData* renderdata = (WINCE_RenderData*) renderer->driverdata;
  6.1232 +	    renderdata->flags &= ~FB_SUSPENDED;
  6.1233 +	    if(renderdata->gapi) renderdata->gapi->GXResume();
  6.1234 +	}
  6.1235 +    }
  6.1236 +    else
  6.1237 +    {
  6.1238 +	if(renderer &&
  6.1239 +	    (videodata->render == RENDER_GAPI || videodata->render == RENDER_RAW))
  6.1240 +	{
  6.1241 +	    WINCE_RenderData* renderdata = (WINCE_RenderData*) renderer->driverdata;
  6.1242 +	    if(renderdata->gapi) renderdata->gapi->GXSuspend();
  6.1243 +	    renderdata->flags |= FB_SUSPENDED;
  6.1244 +	}
  6.1245 +
  6.1246 +	ShowWindow(windowdata->hwnd, SW_HIDE);
  6.1247 +
  6.1248 +	if(window->flags & SDL_WINDOW_FULLSCREEN)
  6.1249 +	{
  6.1250 +	    if(videodata->SHFullScreen)
  6.1251 +		videodata->SHFullScreen(windowdata->hwnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON | SHFS_SHOWSIPBUTTON);
  6.1252 +	    ShowWindow(FindWindow(TEXT("HHTaskBar"), NULL), SW_SHOW);
  6.1253 +	}
  6.1254 +    }
  6.1255 +}
  6.1256 +
  6.1257 +
  6.1258 +void WINCE_PointerCoordinateTransform(SDL_Window* window, POINT* pt)
  6.1259 +{
  6.1260 +    WINCE_RenderData* data = (WINCE_RenderData*) window->renderer->driverdata;
  6.1261 +
  6.1262 +    pt->x *= data->scale;
  6.1263 +    pt->y *= data->scale;
  6.1264 +
  6.1265 +    PointerRotate(pt, &data->fb, data->userOrientation);
  6.1266 +}
  6.1267 +
  6.1268 +void WINCE_PortraitTransform(WINCE_RenderData* data, int width, int height)
  6.1269 +{
  6.1270 +    if(data->systemOrientation != ORIENTATION_UP)
  6.1271 +	FrameBufferRotate(&data->fb, data->systemOrientation);
  6.1272 +
  6.1273 +    if(data->fb.width != width || data->fb.height != height)
  6.1274 +    switch(data->systemOrientation)
  6.1275 +    {
  6.1276 +	case ORIENTATION_UP:
  6.1277 +	case ORIENTATION_LEFT: data->userOrientation = ORIENTATION_RIGHT; break;
  6.1278 +	case ORIENTATION_RIGHT:
  6.1279 +	case ORIENTATION_DOWN: data->userOrientation = ORIENTATION_LEFT; break;
  6.1280 +	default: break;
  6.1281      }
  6.1282  
  6.1283 -    GAPI_LOG("GAPI_RenderCopy\n");
  6.1284 +    if(data->userOrientation != ORIENTATION_UP)
  6.1285 +	FrameBufferRotate(&data->fb, data->userOrientation);
  6.1286 +}
  6.1287  
  6.1288 -    if (data->usageFlags & USAGE_GX_FUNCS) {
  6.1289 -        char *buffer;
  6.1290 -        buffer = gx.GXBeginDraw();
  6.1291 -        if (!(data->usageFlags & USAGE_DATA_PTR_CONSTANT)) {
  6.1292 -            data->data = buffer;
  6.1293 -        }
  6.1294 +void WINCE_LandscapeTransform(WINCE_RenderData* data, int width, int height)
  6.1295 +{
  6.1296 +    switch(data->systemOrientation)
  6.1297 +    {
  6.1298 +	case ORIENTATION_UP:  FrameBufferRotate(&data->fb, ORIENTATION_LEFT); break;
  6.1299 +	case ORIENTATION_LEFT:FrameBufferRotate(&data->fb, ORIENTATION_DOWN); break;
  6.1300 +	case ORIENTATION_DOWN:FrameBufferRotate(&data->fb, ORIENTATION_RIGHT); break;
  6.1301 +	default: break;
  6.1302      }
  6.1303  
  6.1304 -    GAPI_LOG("GAPI_RenderCopy blit\n");
  6.1305 -    /* If our framebuffer has an xPitch which matches the pixelsize, we
  6.1306 -       can convert the framebuffer to a SDL_surface and blit there,
  6.1307 -       otherwise, we have to use our own blitting routine
  6.1308 -     */
  6.1309 -    SDL_PixelFormatEnumToMasks(data->format, &bpp, &Rmask, &Gmask, &Bmask,
  6.1310 -                               &Amask);
  6.1311 -    bytespp = bpp >> 3;
  6.1312 -    if (data->xPitch == bytespp && 0) {
  6.1313 -        SDL_Surface *screen =
  6.1314 -            SDL_CreateRGBSurfaceFrom(data->data, data->w, data->h,
  6.1315 -                                     bpp, data->yPitch, Rmask, Gmask, Bmask,
  6.1316 -                                     Amask);
  6.1317 -        status =
  6.1318 -            SDL_UpperBlit((SDL_Surface *) texture->driverdata, srcrect,
  6.1319 -                          screen, dstrect);
  6.1320 -        SDL_FreeSurface(screen);
  6.1321 -    } else {                    /* screen is rotated, we have to blit on our own */
  6.1322 -        SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
  6.1323 -
  6.1324 -        char *src, *dst;
  6.1325 -        src = surface->pixels;
  6.1326 -        src += srcrect->y * surface->pitch + srcrect->x * 2;
  6.1327 -
  6.1328 -        dst = data->data + data->offset;
  6.1329 -        dst += dstrect->y * data->yPitch + dstrect->x * data->xPitch;
  6.1330 -
  6.1331 -        updateLine16to16(src, 2, surface->pitch,
  6.1332 -                         dst, data->xPitch, data->yPitch,
  6.1333 -                         srcrect->w, srcrect->h);
  6.1334 -
  6.1335 +    if(data->fb.width != width || data->fb.height != height)
  6.1336 +    switch(data->systemOrientation)
  6.1337 +    {
  6.1338 +	case ORIENTATION_UP:
  6.1339 +	case ORIENTATION_LEFT: data->userOrientation = ORIENTATION_RIGHT; break;
  6.1340 +	case ORIENTATION_RIGHT:
  6.1341 +	case ORIENTATION_DOWN: data->userOrientation = ORIENTATION_LEFT; break;
  6.1342 +	default: break;
  6.1343      }
  6.1344  
  6.1345 -    Uint32 ticks = SDL_GetTicks();
  6.1346 -    if (data->usageFlags & USAGE_GX_FUNCS) {
  6.1347 -        gx.GXEndDraw();
  6.1348 -    }
  6.1349 -    GAPI_LOG("GAPI_RenderCopy %i\n", SDL_GetTicks() - ticks);
  6.1350 -    return status;
  6.1351 +    if(data->userOrientation != ORIENTATION_UP)
  6.1352 +	FrameBufferRotate(&data->fb, data->userOrientation);
  6.1353  }
  6.1354  
  6.1355 -static void
  6.1356 -GAPI_RenderPresent(SDL_Renderer * renderer)
  6.1357 +void WINCE_SquareTransform(WINCE_RenderData* data, int width, int height)
  6.1358  {
  6.1359 -    /* Nothing todo as we rendered directly to the screen on RenderCopy */
  6.1360 +    WINCE_PortraitTransform(data, width, height);
  6.1361  }
  6.1362  
  6.1363 -static void
  6.1364 -GAPI_DestroyRenderer(SDL_Renderer * renderer)
  6.1365 +int WINCE_FixedGeometry(FrameBufferInfo* fb, int bpp, int debug)
  6.1366  {
  6.1367 -    GAPI_RenderData *data = (GAPI_RenderData *) renderer->driverdata;
  6.1368 -
  6.1369 -    if (data->usageFlags & USAGE_GX_FUNCS) {
  6.1370 -        gx.GXCloseDisplay();
  6.1371 +    // check square
  6.1372 +    if(GetSystemMetrics(SM_CXSCREEN) == GetSystemMetrics(SM_CYSCREEN) &&
  6.1373 +	fb->width != fb->height)
  6.1374 +    {
  6.1375 +	if(fb->width < fb->height)
  6.1376 +	    fb->height = fb->width;
  6.1377 +	else
  6.1378 +	if(fb->height < fb->width)
  6.1379 +	    fb->width = fb->height;
  6.1380      }
  6.1381  
  6.1382 -    if (data) {
  6.1383 -        SDL_free(data);
  6.1384 +    // check width
  6.1385 +    if(__abs(fb->xpitch) == bpp &&
  6.1386 +	fb->width  != __abs(fb->ypitch) / bpp)
  6.1387 +    {
  6.1388 +	if(fb->height == __abs(fb->ypitch) / bpp)
  6.1389 +    	{
  6.1390 +	    __swap(&fb->width, &fb->height);
  6.1391 +
  6.1392 +	    if(debug)
  6.1393 +		printf("WINCE_FixedGeometry: width: %d, height: %d\n", fb->width, fb->height);
  6.1394 +	}
  6.1395 +	else
  6.1396 +	    return -1;
  6.1397      }
  6.1398 -    SDL_free(renderer);
  6.1399 +    else
  6.1400 +    // check height
  6.1401 +    if(__abs(fb->ypitch) == bpp &&
  6.1402 +	fb->height != __abs(fb->xpitch) / bpp)
  6.1403 +    {
  6.1404 +	if(fb->width  == __abs(fb->xpitch) / bpp)
  6.1405 +    	{
  6.1406 +	    __swap(&fb->width, &fb->height);
  6.1407 +
  6.1408 +	    if(debug)
  6.1409 +		printf("WINCE_FixedGeometry: width: %d, height: %d\n", fb->width, fb->height);
  6.1410 +	}
  6.1411 +	else
  6.1412 +	    return -1;
  6.1413 +    }
  6.1414 +
  6.1415 +    return 0;
  6.1416  }
  6.1417  
  6.1418 -#endif /* SDL_VIDEO_RENDER_GAPI */
  6.1419 +void WINCE_UpdateYUVTextureData(SDL_Texture* texture)
  6.1420 +{
  6.1421 +    WINCE_TextureData* texturedata = (WINCE_TextureData*) texture->driverdata;
  6.1422 +    SDL_Rect rect;
  6.1423  
  6.1424 -/* vi: set ts=4 sw=4 expandtab: */
  6.1425 +    rect.x = 0;
  6.1426 +    rect.y = 0;
  6.1427 +    rect.w = texture->w;
  6.1428 +    rect.h = texture->h;
  6.1429 +    SDL_SW_CopyYUVToRGB(texturedata->yuv, &rect, texturedata->format, texture->w, texture->h, texturedata->pixels, texturedata->pitch);
  6.1430 +}
  6.1431 +
  6.1432 +int GAPI_Init(WINCE_RenderData* data, HWND hwnd)
  6.1433 +{
  6.1434 +    if(NULL == data->gapi)
  6.1435 +    {
  6.1436 +	const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER");
  6.1437 +	if(preferably && 0 != SDL_strcasecmp(preferably, GAPI_RENDER_NAME)) return 0;
  6.1438 +
  6.1439 +        data->gapi = (GapiInfo *) SDL_calloc(1, sizeof(GapiInfo));
  6.1440 +        if(NULL == data->gapi)
  6.1441 +        {
  6.1442 +            SDL_OutOfMemory();
  6.1443 +            return 0;
  6.1444 +        }
  6.1445 +
  6.1446 +	data->gapi->hGapiLib = LoadLibrary(TEXT("\\Windows\\gx.dll"));
  6.1447 +	if(0 == data->gapi->hGapiLib)
  6.1448 +	{
  6.1449 +	    data->gapi->hGapiLib = LoadLibrary(TEXT("gx.dll"));
  6.1450 +	    if(0 == data->gapi->hGapiLib) return 0;
  6.1451 +	}
  6.1452 +
  6.1453 +	// load gapi library
  6.1454 +#define LINK(type,name,import) name=(PFN##type)GetProcAddress(data->gapi->hGapiLib,TEXT(import))
  6.1455 +	LINK(GXOpenDisplay,         data->gapi->GXOpenDisplay,         "?GXOpenDisplay@@YAHPAUHWND__@@K@Z");
  6.1456 +	LINK(GXCloseDisplay,        data->gapi->GXCloseDisplay,        "?GXCloseDisplay@@YAHXZ");
  6.1457 +	LINK(GXBeginDraw,           data->gapi->GXBeginDraw,           "?GXBeginDraw@@YAPAXXZ");
  6.1458 +	LINK(GXEndDraw,             data->gapi->GXEndDraw,             "?GXEndDraw@@YAHXZ");
  6.1459 +	LINK(GXGetDisplayProperties,data->gapi->GXGetDisplayProperties,"?GXGetDisplayProperties@@YA?AUGXDisplayProperties@@XZ");
  6.1460 +	LINK(GXSuspend,             data->gapi->GXSuspend,             "?GXSuspend@@YAHXZ");
  6.1461 +	LINK(GXResume,              data->gapi->GXResume,              "?GXResume@@YAHXZ");
  6.1462 +#undef LINK
  6.1463 +
  6.1464 +	int enable = data->gapi->GXGetDisplayProperties && data->gapi->GXCloseDisplay && data->gapi->GXOpenDisplay &&
  6.1465 +	    data->gapi->GXBeginDraw && data->gapi->GXEndDraw && data->gapi->GXSuspend && data->gapi->GXResume;
  6.1466 +
  6.1467 +	if(!enable)
  6.1468 +	{
  6.1469 +	    SDL_SetError("GAPI_Init: error gx.dll: internal error");
  6.1470 +	    GAPI_Quit(data);
  6.1471 +	    return 0;
  6.1472 +	}
  6.1473 +
  6.1474 +	if(0 == data->gapi->GXOpenDisplay(hwnd, GX_FULLSCREEN))
  6.1475 +	{
  6.1476 +	    SDL_SetError("GAPI_Init: couldn't initialize GAPI");
  6.1477 +	    GAPI_Quit(data);
  6.1478 +	    return 0;
  6.1479 +	}
  6.1480 +
  6.1481 +	struct GXDisplayProperties gxProperties = data->gapi->GXGetDisplayProperties();
  6.1482 +
  6.1483 +	// fill FrameBufferInfo
  6.1484 +	data->fb.xpitch = gxProperties.cbxPitch;
  6.1485 +	data->fb.ypitch = gxProperties.cbyPitch;
  6.1486 +	data->fb.width  = gxProperties.cxWidth;
  6.1487 +	data->fb.height = gxProperties.cyHeight;
  6.1488 +	data->fb.offset = 0;
  6.1489 +
  6.1490 +        if((gxProperties.ffFormat & kfDirect565) || 16 == gxProperties.cBPP)
  6.1491 +	    data->format = SDL_PIXELFORMAT_RGB565;
  6.1492 +	else
  6.1493 +	if((gxProperties.ffFormat & kfDirect555) || 15 == gxProperties.cBPP)
  6.1494 +	    data->format = SDL_PIXELFORMAT_RGB555;
  6.1495 +	else
  6.1496 +	    data->format = 0;
  6.1497 +
  6.1498 +	// get pixels
  6.1499 +	GXDeviceInfo gxInfo = { 0 };
  6.1500 +	HDC hdc = GetDC(NULL);
  6.1501 +
  6.1502 +	gxInfo.Version = 100;
  6.1503 +	int result = ExtEscape(hdc, GETGXINFO, 0, NULL, sizeof(gxInfo), (char *) &gxInfo);
  6.1504 +	ReleaseDC(NULL, hdc);
  6.1505 +
  6.1506 +	if(result > 0)
  6.1507 +	{
  6.1508 +	    // more debug
  6.1509 +	    if(data->debug)
  6.1510 +	    {
  6.1511 +		printf("GXDeviceInfo.pvFrameBuffer:    %p\n", gxInfo.pvFrameBuffer);
  6.1512 +    		printf("GXDeviceInfo.cxWidth:          %d\n", gxInfo.cxWidth);
  6.1513 +    		printf("GXDeviceInfo.cyHeight:         %d\n", gxInfo.cyHeight);
  6.1514 +    		printf("GXDeviceInfo.cbStride:         %d\n", gxInfo.cbStride);
  6.1515 +    		printf("GXDeviceInfo.cBPP:             %d\n", gxInfo.cBPP);
  6.1516 +    		printf("GXDeviceInfo.ffFormat:        0x%x\n", gxInfo.ffFormat);
  6.1517 +
  6.1518 +    		printf("GXDeviceInfo.unk:\n");
  6.1519 +		int ii; for(ii = 0; ii <  sizeof(gxInfo.unknown); ++ii)
  6.1520 +		printf("0x%02hhX,", gxInfo.unknown[ii]);
  6.1521 +		printf("\n");
  6.1522 +	    }
  6.1523 +
  6.1524 +    	    if(gxInfo.ffFormat && gxInfo.ffFormat != gxProperties.ffFormat)
  6.1525 +	    {
  6.1526 +		if((gxInfo.ffFormat & kfDirect565) || 16 == gxInfo.cBPP)
  6.1527 +		    data->format = SDL_PIXELFORMAT_RGB565;
  6.1528 +		else
  6.1529 +		if((gxInfo.ffFormat & kfDirect555) || 15 == gxInfo.cBPP)
  6.1530 +		    data->format = SDL_PIXELFORMAT_RGB555;
  6.1531 +	    }
  6.1532 +
  6.1533 +    	    data->pixels = gxInfo.pvFrameBuffer;
  6.1534 +        }
  6.1535 +	else
  6.1536 +	{
  6.1537 +	    data->flags |= FB_SKIP_OFFSET;
  6.1538 +	    data->pixels = data->gapi->GXBeginDraw();
  6.1539 +	    data->gapi->GXEndDraw();
  6.1540 +
  6.1541 +	    if(data->debug)
  6.1542 +	    {
  6.1543 +		printf("GAPI_Init\n");
  6.1544 +		printf("use GXBeginDraw:               %p\n", data->pixels);
  6.1545 +		printf("use skip offset\n");
  6.1546 +	    }
  6.1547 +	}
  6.1548 +
  6.1549 +	if(0 == data->format ||
  6.1550 +	    0 > WINCE_FixedGeometry(&data->fb, SDL_BYTESPERPIXEL(data->format), data->debug))
  6.1551 +	{
  6.1552 +	    SDL_SetError("GAPI_Init: unknown hardware");
  6.1553 +	    GAPI_Quit(data);
  6.1554 +	    return 0;
  6.1555 +	}
  6.1556 +    }
  6.1557 +
  6.1558 +    return data->gapi && data->pixels ? 1 : 0;
  6.1559 +}
  6.1560 +
  6.1561 +void GAPI_Quit(WINCE_RenderData* data)
  6.1562 +{
  6.1563 +    if(data->gapi)
  6.1564 +    {
  6.1565 +	if(data->gapi->GXCloseDisplay) data->gapi->GXCloseDisplay(); 
  6.1566 +	if(data->gapi->hGapiLib)  FreeLibrary(data->gapi->hGapiLib);
  6.1567 +
  6.1568 +	SDL_free(data->gapi);
  6.1569 +        data->gapi = NULL;
  6.1570 +    }
  6.1571 +}
  6.1572 +
  6.1573 +int RAW_Init(WINCE_RenderData* data)
  6.1574 +{
  6.1575 +    const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER");
  6.1576 +    if(preferably && 0 != SDL_strcasecmp(preferably, RAW_RENDER_NAME)) return 0;
  6.1577 +
  6.1578 +    RawFrameBufferInfo rfbi = { 0 };
  6.1579 +    HDC hdc = GetDC(NULL);
  6.1580 +    int result = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *) &rfbi);
  6.1581 +    ReleaseDC(NULL, hdc);
  6.1582 +
  6.1583 +    //disable
  6.1584 +    if(result == 0 || rfbi.pFramePointer == 0 ||
  6.1585 +    	rfbi.cxPixels == 0 || rfbi.cyPixels == 0 ||
  6.1586 +	rfbi.cxStride == 0 || rfbi.cyStride == 0) return 0;
  6.1587 +
  6.1588 +    data->flags     = FB_RAW_MODE;
  6.1589 +
  6.1590 +    // fill FrameBufferInfo
  6.1591 +    SDL_memset(&data->fb, 0, sizeof(FrameBufferInfo));
  6.1592 +
  6.1593 +    data->fb.xpitch = rfbi.cxStride;
  6.1594 +    data->fb.ypitch = rfbi.cyStride;
  6.1595 +    data->fb.width  = rfbi.cxPixels;
  6.1596 +    data->fb.height = rfbi.cyPixels;
  6.1597 +    data->fb.offset = 0;
  6.1598 +
  6.1599 +    if((FORMAT_565 & rfbi.wFormat) || 16 == rfbi.wBPP)
  6.1600 +	data->format = SDL_PIXELFORMAT_RGB565;
  6.1601 +    else
  6.1602 +    if((FORMAT_555 & rfbi.wFormat) || 15 == rfbi.wBPP)
  6.1603 +	data->format = SDL_PIXELFORMAT_RGB555;
  6.1604 +    else
  6.1605 +	data->format = 0;
  6.1606 +
  6.1607 +    if(0 == data->format ||
  6.1608 +	0 > WINCE_FixedGeometry(&data->fb, SDL_BYTESPERPIXEL(data->format), data->debug))
  6.1609 +    {
  6.1610 +	SDL_SetError("RAW_Init: unknown hardware");
  6.1611 +	RAW_Quit(data);
  6.1612 +	return 0;
  6.1613 +    }
  6.1614 +
  6.1615 +    data->pixels = rfbi.pFramePointer;
  6.1616 +
  6.1617 +    return data->pixels ? 1 : 0;
  6.1618 +}
  6.1619 +
  6.1620 +void RAW_Quit(WINCE_RenderData* data)
  6.1621 +{
  6.1622 +}
  6.1623 +
  6.1624 +void FrameBufferInitialize(FrameBufferInfo* fb)
  6.1625 +{
  6.1626 +    int orientation = GetFrameBufferOrientation(fb);
  6.1627 +
  6.1628 +    // set correct start offset
  6.1629 +    switch(orientation)
  6.1630 +    {
  6.1631 +	case ORIENTATION_UP:
  6.1632 +	    fb->offset = 0;
  6.1633 +	    break;
  6.1634 +
  6.1635 +	case ORIENTATION_LEFT:
  6.1636 +	    fb->offset = __abs(fb->ypitch * (fb->height - 1));
  6.1637 +	    break;
  6.1638 +
  6.1639 +	case ORIENTATION_RIGHT:
  6.1640 +	    fb->offset = __abs(fb->xpitch * (fb->width - 1));
  6.1641 +	    break;
  6.1642 +
  6.1643 +	case ORIENTATION_DOWN:
  6.1644 +	    fb->offset = __abs(fb->xpitch * (fb->width - 1) +
  6.1645 +				fb->ypitch * (fb->height - 1));
  6.1646 +	    break;
  6.1647 +
  6.1648 +	default: break;
  6.1649 +    }
  6.1650 +
  6.1651 +    //if(orientation != ORIENTATION_UP)
  6.1652 +    switch(orientation)
  6.1653 +    {
  6.1654 +	case ORIENTATION_LEFT: FrameBufferRotate(fb, ORIENTATION_RIGHT); break;
  6.1655 +	case ORIENTATION_RIGHT:FrameBufferRotate(fb, ORIENTATION_LEFT); break;
  6.1656 +	case ORIENTATION_DOWN: FrameBufferRotate(fb, ORIENTATION_DOWN); break;
  6.1657 +
  6.1658 +	default: break;
  6.1659 +    }
  6.1660 +}
  6.1661 +
  6.1662 +int GetFrameBufferOrientation(const FrameBufferInfo* src)
  6.1663 +{
  6.1664 +    if(src->xpitch > 0 && src->ypitch > 0)
  6.1665 +	return ORIENTATION_UP;
  6.1666 +    else
  6.1667 +    if(src->xpitch > 0 && src->ypitch < 0)
  6.1668 +	return ORIENTATION_LEFT;
  6.1669 +    else
  6.1670 +    if(src->xpitch < 0 && src->ypitch > 0)
  6.1671 +	return ORIENTATION_RIGHT;
  6.1672 +    else
  6.1673 +    if(src->xpitch < 0 && src->ypitch < 0)
  6.1674 +	return ORIENTATION_DOWN;
  6.1675 +
  6.1676 +    return ORIENTATION_UNKNOWN;
  6.1677 +}
  6.1678 +
  6.1679 +void FrameBufferRotate(FrameBufferInfo* dst, int orientation)
  6.1680 +{
  6.1681 +    FrameBufferInfo src;
  6.1682 +    // copy dst -> src
  6.1683 +    SDL_memcpy(&src, dst, sizeof(FrameBufferInfo));
  6.1684 +
  6.1685 +    switch(orientation)
  6.1686 +    {
  6.1687 +        case ORIENTATION_LEFT:
  6.1688 +	    dst->width  = src.height;
  6.1689 +	    dst->height = src.width;
  6.1690 +	    dst->xpitch = src.ypitch;
  6.1691 +	    dst->ypitch = -src.xpitch;
  6.1692 +	    dst->offset = src.offset + src.xpitch * (src.width - 1);
  6.1693 +	    break;
  6.1694 +
  6.1695 +        case ORIENTATION_RIGHT:
  6.1696 +	    dst->width  = src.height;
  6.1697 +	    dst->height = src.width;
  6.1698 +	    dst->xpitch = -src.ypitch;
  6.1699 +	    dst->ypitch = src.xpitch;
  6.1700 +	    dst->offset = src.offset + src.ypitch * (src.height - 1);
  6.1701 +	    break;
  6.1702 +
  6.1703 +        case ORIENTATION_DOWN:
  6.1704 +	    FrameBufferRotate(dst, ORIENTATION_LEFT);
  6.1705 +	    FrameBufferRotate(dst, ORIENTATION_LEFT);
  6.1706 +	    break;
  6.1707 +
  6.1708 +        default:
  6.1709 +	    break;
  6.1710 +    }
  6.1711 +}
  6.1712 +
  6.1713 +void PointerRotate(POINT* pt, const FrameBufferInfo* fb, int orientation)
  6.1714 +{
  6.1715 +    switch(orientation)
  6.1716 +    {
  6.1717 +	case ORIENTATION_UP:
  6.1718 +	    break;
  6.1719 +
  6.1720 +	case ORIENTATION_LEFT:
  6.1721 +	{
  6.1722 +	    int temp = pt->y;
  6.1723 +	    pt->y = fb->height - pt->x;
  6.1724 +	    pt->x = temp;
  6.1725 +	}
  6.1726 +	    break;
  6.1727 +
  6.1728 +	case ORIENTATION_RIGHT:
  6.1729 +	{
  6.1730 +	    int temp = pt->x;
  6.1731 +	    pt->x = fb->width - pt->y;
  6.1732 +	    pt->y = temp;
  6.1733 +	}
  6.1734 +	    break;
  6.1735 +
  6.1736 +	case ORIENTATION_DOWN:
  6.1737 +	    pt->x = fb->width  - pt->x;
  6.1738 +	    pt->y = fb->height - pt->y;
  6.1739 +	    break;
  6.1740 +
  6.1741 +	default: break;
  6.1742 +    }
  6.1743 +}
  6.1744 +
  6.1745 +const char* GetOrientationName(int orientation)
  6.1746 +{
  6.1747 +    switch(orientation)
  6.1748 +    {
  6.1749 +        case ORIENTATION_UP:        return "UP";
  6.1750 +        case ORIENTATION_DOWN:      return "DOWN";
  6.1751 +        case ORIENTATION_LEFT:      return "LEFT";
  6.1752 +        case ORIENTATION_RIGHT:     return "RIGHT";
  6.1753 +        default: break;
  6.1754 +    }
  6.1755 +
  6.1756 +    return "UNKNOWN";
  6.1757 +}
  6.1758 +
  6.1759 +int WINCE_GetDMOrientation(void)
  6.1760 +{
  6.1761 +    DEVMODE sDevMode = {0};
  6.1762 +    sDevMode.dmSize = sizeof(DEVMODE);
  6.1763 +    sDevMode.dmFields = DM_DISPLAYORIENTATION;
  6.1764 +
  6.1765 +    // DMDO_0, DMDO_90, DMDO_180, DMDO_270
  6.1766 +    if(DISP_CHANGE_BADMODE != ChangeDisplaySettingsEx(NULL, &sDevMode, 0, CDS_TEST, NULL))
  6.1767 +	switch(sDevMode.dmDisplayOrientation)
  6.1768 +	{
  6.1769 +	    case DMDO_0:	return DMDO_0;
  6.1770 +	    case DMDO_90:	return DMDO_90;
  6.1771 +	    case DMDO_180:	return DMDO_180;
  6.1772 +	    case DMDO_270:	return DMDO_270;
  6.1773 +	    default: break;
  6.1774 +	}
  6.1775 +
  6.1776 +    SDL_SetError("WINCE_GetDMOrientation: ChangeDisplaySettingsEx return BADMODE");
  6.1777 +    return -1;
  6.1778 +}
  6.1779 +
  6.1780 +int WINCE_SetDMOrientation(int orientation)
  6.1781 +{
  6.1782 +    DEVMODE sDevMode = {0};
  6.1783 +    sDevMode.dmSize = sizeof(DEVMODE);
  6.1784 +    sDevMode.dmFields = DM_DISPLAYORIENTATION;
  6.1785 +
  6.1786 +    switch(orientation)
  6.1787 +    {
  6.1788 +	case DMDO_0:	sDevMode.dmDisplayOrientation = DMDO_0;   break;
  6.1789 +	case DMDO_90:	sDevMode.dmDisplayOrientation = DMDO_90;  break;
  6.1790 +	case DMDO_180:	sDevMode.dmDisplayOrientation = DMDO_180; break;
  6.1791 +	case DMDO_270:	sDevMode.dmDisplayOrientation = DMDO_270; break;
  6.1792 +	default: return 0;
  6.1793 +    }
  6.1794 +
  6.1795 +    if(DISP_CHANGE_BADMODE != ChangeDisplaySettingsEx(NULL, &sDevMode, 0, CDS_RESET, NULL))
  6.1796 +	return 1;
  6.1797 +
  6.1798 +    SDL_SetError("WINCE_SetDMOrientation: ChangeDisplaySettingsEx return BADMODE");
  6.1799 +    return -1;
  6.1800 +}
  6.1801 +
  6.1802 +void FrameBufferDumpInfo(const FrameBufferInfo* fb, const char* name)
  6.1803 +{
  6.1804 +    printf("%s fb.width:       %d\n", name, fb->width);
  6.1805 +    printf("%s fb.height:      %d\n", name, fb->height);
  6.1806 +    printf("%s fb.xpitch:      %d\n", name, fb->xpitch);
  6.1807 +    printf("%s fb.ypitch:      %d\n", name, fb->ypitch);
  6.1808 +    printf("%s fb.offset:      %d\n", name, fb->offset);
  6.1809 +
  6.1810 +    int orientation = GetFrameBufferOrientation(fb);
  6.1811 +    printf("%s fb.orientation: %d, %s\n", name, orientation, GetOrientationName(orientation));
  6.1812 +}
  6.1813 +
  6.1814 +void UpdateLine16to16(const FrameBufferInfo* fb, const Uint16* src, Uint16* dst, Uint16 width)
  6.1815 +{
  6.1816 +    if(2 == fb->xpitch)
  6.1817 +    {
  6.1818 +	switch(width)
  6.1819 +	{
  6.1820 +	    case 1:
  6.1821 +		*dst = *src;
  6.1822 +		break;
  6.1823 +
  6.1824 +	    case 2:
  6.1825 +		*((Uint32*) dst) = *((Uint32*) src);
  6.1826 +		break;
  6.1827 +
  6.1828 +	    default:
  6.1829 +		SDL_memcpy(dst, src, width * 2);
  6.1830 +		break;
  6.1831 +	}
  6.1832 +    }
  6.1833 +    else
  6.1834 +    if(-2 == fb->xpitch)
  6.1835 +    {
  6.1836 +	while(width--)
  6.1837 +	    *dst-- = *src++;
  6.1838 +    }
  6.1839 +    else
  6.1840 +    {
  6.1841 +	while(width--)
  6.1842 +	{
  6.1843 +	    *dst = *src++;
  6.1844 +	    dst += fb->xpitch / 2;
  6.1845 +	}
  6.1846 +    }
  6.1847 +}
  6.1848 +
  6.1849 +#endif // SDL_VIDEO_RENDER_GAPI
     7.1 --- a/src/video/win32/SDL_gapirender.h	Fri Jul 23 21:33:00 2010 -0700
     7.2 +++ b/src/video/win32/SDL_gapirender.h	Tue Jul 27 21:31:28 2010 -0700
     7.3 @@ -27,7 +27,11 @@
     7.4  /* SDL surface based renderer implementation */
     7.5  
     7.6  #if SDL_VIDEO_RENDER_GAPI
     7.7 -extern void GAPI_AddRenderDriver(_THIS);
     7.8 +extern void WINCE_AddRenderDriver(_THIS);
     7.9 +extern int  WINCE_Available(void);
    7.10 +extern void WINCE_ShowWindow(_THIS, SDL_Window* window, int visible);
    7.11 +extern int  WINCE_GetDMOrientation(void);
    7.12 +extern int  WINCE_SetDMOrientation(int orientation);
    7.13  #endif
    7.14  
    7.15  /* vi: set ts=4 sw=4 expandtab: */
     8.1 --- a/src/video/win32/SDL_gapirender_c.h	Fri Jul 23 21:33:00 2010 -0700
     8.2 +++ b/src/video/win32/SDL_gapirender_c.h	Tue Jul 27 21:31:28 2010 -0700
     8.3 @@ -22,100 +22,3 @@
     8.4      Stefan Klug
     8.5      klug.stefan@gmx.de
     8.6  */
     8.7 -
     8.8 -#define WIN32_LEAN_AND_MEAN
     8.9 -#include <windows.h>
    8.10 -
    8.11 -/* hi res definitions */
    8.12 -typedef struct _RawFrameBufferInfo
    8.13 -{
    8.14 -    WORD wFormat;
    8.15 -    WORD wBPP;
    8.16 -    VOID *pFramePointer;
    8.17 -    int cxStride;
    8.18 -    int cyStride;
    8.19 -    int cxPixels;
    8.20 -    int cyPixels;
    8.21 -} RawFrameBufferInfo;
    8.22 -
    8.23 -#define GETRAWFRAMEBUFFER   0x00020001
    8.24 -
    8.25 -#define FORMAT_565 1
    8.26 -#define FORMAT_555 2
    8.27 -#define FORMAT_OTHER 3
    8.28 -
    8.29 -
    8.30 -/* From gx.h, since it's not really C compliant */
    8.31 -
    8.32 -struct GXDisplayProperties
    8.33 -{
    8.34 -    DWORD cxWidth;
    8.35 -    DWORD cyHeight;             // notice lack of 'th' in the word height.
    8.36 -    long cbxPitch;              // number of bytes to move right one x pixel - can be negative.
    8.37 -    long cbyPitch;              // number of bytes to move down one y pixel - can be negative.
    8.38 -    long cBPP;                  // # of bits in each pixel
    8.39 -    DWORD ffFormat;             // format flags.
    8.40 -};
    8.41 -
    8.42 -struct GXKeyList
    8.43 -{
    8.44 -    short vkUp;                 // key for up
    8.45 -    POINT ptUp;                 // x,y position of key/button.  Not on screen but in screen coordinates.
    8.46 -    short vkDown;
    8.47 -    POINT ptDown;
    8.48 -    short vkLeft;
    8.49 -    POINT ptLeft;
    8.50 -    short vkRight;
    8.51 -    POINT ptRight;
    8.52 -    short vkA;
    8.53 -    POINT ptA;
    8.54 -    short vkB;
    8.55 -    POINT ptB;
    8.56 -    short vkC;
    8.57 -    POINT ptC;
    8.58 -    short vkStart;
    8.59 -    POINT ptStart;
    8.60 -};
    8.61 -
    8.62 -typedef int (*PFNGXOpenDisplay) (HWND hWnd, DWORD dwFlags);
    8.63 -typedef int (*PFNGXCloseDisplay) ();
    8.64 -typedef void *(*PFNGXBeginDraw) ();
    8.65 -typedef int (*PFNGXEndDraw) ();
    8.66 -typedef int (*PFNGXOpenInput) ();
    8.67 -typedef int (*PFNGXCloseInput) ();
    8.68 -typedef struct GXDisplayProperties (*PFNGXGetDisplayProperties) ();
    8.69 -typedef struct GXKeyList (*PFNGXGetDefaultKeys) (int iOptions);
    8.70 -typedef int (*PFNGXSuspend) ();
    8.71 -typedef int (*PFNGXResume) ();
    8.72 -typedef int (*PFNGXSetViewport) (DWORD dwTop, DWORD dwHeight,
    8.73 -                                 DWORD dwReserved1, DWORD dwReserved2);
    8.74 -typedef BOOL(*PFNGXIsDisplayDRAMBuffer) ();
    8.75 -
    8.76 -struct GapiFunc
    8.77 -{
    8.78 -    PFNGXOpenDisplay GXOpenDisplay;
    8.79 -    PFNGXCloseDisplay GXCloseDisplay;
    8.80 -    PFNGXBeginDraw GXBeginDraw;
    8.81 -    PFNGXEndDraw GXEndDraw;
    8.82 -    PFNGXOpenInput GXOpenInput;
    8.83 -    PFNGXCloseInput GXCloseInput;
    8.84 -    PFNGXGetDisplayProperties GXGetDisplayProperties;
    8.85 -    PFNGXGetDefaultKeys GXGetDefaultKeys;
    8.86 -    PFNGXSuspend GXSuspend;
    8.87 -    PFNGXResume GXResume;
    8.88 -    PFNGXSetViewport GXSetViewport;
    8.89 -    PFNGXIsDisplayDRAMBuffer GXIsDisplayDRAMBuffer;
    8.90 -} gx;
    8.91 -
    8.92 -#define kfLandscape      0x8    // Screen is rotated 270 degrees
    8.93 -#define kfPalette        0x10   // Pixel values are indexes into a palette
    8.94 -#define kfDirect         0x20   // Pixel values contain actual level information
    8.95 -#define kfDirect555      0x40   // 5 bits each for red, green and blue values in a pixel.
    8.96 -#define kfDirect565      0x80   // 5 red bits, 6 green bits and 5 blue bits per pixel
    8.97 -#define kfDirect888      0x100  // 8 bits each for red, green and blue values in a pixel.
    8.98 -#define kfDirect444      0x200  // 4 red, 4 green, 4 blue
    8.99 -#define kfDirectInverted 0x400
   8.100 -
   8.101 -#define GX_FULLSCREEN    0x01   // for OpenDisplay()
   8.102 -#define GX_NORMALKEYS    0x02
   8.103 -#define GX_LANDSCAPEKEYS        0x03
     9.1 --- a/src/video/win32/SDL_gdirender.c	Fri Jul 23 21:33:00 2010 -0700
     9.2 +++ b/src/video/win32/SDL_gdirender.c	Tue Jul 27 21:31:28 2010 -0700
     9.3 @@ -184,6 +184,8 @@
     9.4          return NULL;
     9.5      }
     9.6  
     9.7 +    windowdata->videodata->render = RENDER_GDI;
     9.8 +
     9.9      renderer->DisplayModeChanged = GDI_DisplayModeChanged;
    9.10      renderer->CreateTexture = GDI_CreateTexture;
    9.11      renderer->QueryTexturePixels = GDI_QueryTexturePixels;
    9.12 @@ -267,6 +269,34 @@
    9.13      }
    9.14      data->current_hbm = 0;
    9.15  
    9.16 +#ifdef _WIN32_WCE
    9.17 +    // check size for GDI fullscreen and rotate
    9.18 +    if((window->flags & SDL_WINDOW_FULLSCREEN) &&
    9.19 +        GetSystemMetrics(SM_CXSCREEN) != GetSystemMetrics(SM_CYSCREEN) &&
    9.20 +        ((GetSystemMetrics(SM_CXSCREEN) < GetSystemMetrics(SM_CYSCREEN) && window->w > window->h) ||
    9.21 +         (GetSystemMetrics(SM_CXSCREEN) > GetSystemMetrics(SM_CYSCREEN) && window->w < window->h)))
    9.22 +    {
    9.23 +	int orientation = WINCE_GetDMOrientation();
    9.24 +	switch(orientation)
    9.25 +	{
    9.26 +	    case DMDO_0:   orientation = DMDO_90; break;
    9.27 +	    case DMDO_270: orientation = DMDO_180; break;
    9.28 +	    case DMDO_90:  orientation = DMDO_0; break;
    9.29 +	    case DMDO_180: orientation = DMDO_270; break;
    9.30 +
    9.31 +	    default:
    9.32 +		GDI_DestroyRenderer(renderer);
    9.33 +		return NULL;
    9.34 +	}
    9.35 +
    9.36 +	if(0 > WINCE_SetDMOrientation(orientation))
    9.37 +	{
    9.38 +	    GDI_DestroyRenderer(renderer);
    9.39 +	    return NULL;
    9.40 +	}
    9.41 +    }
    9.42 +#endif
    9.43 +
    9.44      return renderer;
    9.45  }
    9.46  
    9.47 @@ -416,6 +446,7 @@
    9.48          WIN_SetError("Couldn't create bitmap");
    9.49          return -1;
    9.50      }
    9.51 +
    9.52      return 0;
    9.53  }
    9.54  
    10.1 --- a/src/video/win32/SDL_win32clipboard.c	Fri Jul 23 21:33:00 2010 -0700
    10.2 +++ b/src/video/win32/SDL_win32clipboard.c	Tue Jul 27 21:31:28 2010 -0700
    10.3 @@ -95,7 +95,11 @@
    10.4                  WIN_SetError("Couldn't set clipboard data");
    10.5                  result = -1;
    10.6              }
    10.7 +#ifdef _WIN32_WCE
    10.8 +            data->clipboard_count = 0;
    10.9 +#else
   10.10              data->clipboard_count = GetClipboardSequenceNumber();
   10.11 +#endif
   10.12          }
   10.13          SDL_free(tstr);
   10.14  
   10.15 @@ -149,7 +153,11 @@
   10.16  {
   10.17      DWORD count;
   10.18  
   10.19 +#ifdef _WIN32_WCE
   10.20 +    count = 0;
   10.21 +#else
   10.22      count = GetClipboardSequenceNumber();
   10.23 +#endif
   10.24      if (count != data->clipboard_count) {
   10.25          if (data->clipboard_count) {
   10.26              SDL_SendClipboardUpdate();
    11.1 --- a/src/video/win32/SDL_win32events.c	Fri Jul 23 21:33:00 2010 -0700
    11.2 +++ b/src/video/win32/SDL_win32events.c	Tue Jul 27 21:31:28 2010 -0700
    11.3 @@ -184,6 +184,22 @@
    11.4          break;
    11.5  
    11.6  	case WM_MOUSEMOVE:
    11.7 +#ifdef _WIN32_WCE
    11.8 +	/* transform coords for VGA, WVGA... */
    11.9 +	{
   11.10 +	    SDL_VideoData *videodata = data->videodata;
   11.11 +	    if(videodata->CoordTransform &&
   11.12 +		(videodata->render == RENDER_GAPI || videodata->render == RENDER_RAW))
   11.13 +	    {
   11.14 +		POINT pt;
   11.15 +		pt.x = LOWORD(lParam);
   11.16 +		pt.y = HIWORD(lParam);
   11.17 +		videodata->CoordTransform(data->window, &pt);
   11.18 +    		SDL_SendMouseMotion(data->window, 0, pt.x, pt.y);
   11.19 +		break;
   11.20 +	    }
   11.21 +	}
   11.22 +#endif
   11.23          SDL_SendMouseMotion(data->window, 0, LOWORD(lParam), HIWORD(lParam));
   11.24          break;
   11.25  
    12.1 --- a/src/video/win32/SDL_win32modes.c	Fri Jul 23 21:33:00 2010 -0700
    12.2 +++ b/src/video/win32/SDL_win32modes.c	Tue Jul 27 21:31:28 2010 -0700
    12.3 @@ -203,10 +203,18 @@
    12.4  {
    12.5      SDL_DisplayModeData *data = (SDL_DisplayModeData *) display->desktop_mode.driverdata;
    12.6  
    12.7 +#ifdef _WIN32_WCE
    12.8 +    // WINCE: DEVMODE.dmPosition not found, or may be mingw32ce bug
    12.9 +    rect->x = 0;
   12.10 +    rect->y = 0;
   12.11 +    rect->w = display->windows->w;
   12.12 +    rect->h = display->windows->h;
   12.13 +#else
   12.14      rect->x = (int)data->DeviceMode.dmPosition.x;
   12.15      rect->y = (int)data->DeviceMode.dmPosition.y;
   12.16      rect->w = data->DeviceMode.dmPelsWidth;
   12.17      rect->h = data->DeviceMode.dmPelsHeight;
   12.18 +#endif
   12.19      return 0;
   12.20  }
   12.21  
    13.1 --- a/src/video/win32/SDL_win32video.c	Fri Jul 23 21:33:00 2010 -0700
    13.2 +++ b/src/video/win32/SDL_win32video.c	Tue Jul 27 21:31:28 2010 -0700
    13.3 @@ -30,6 +30,7 @@
    13.4  #include "SDL_win32video.h"
    13.5  #include "SDL_d3drender.h"
    13.6  #include "SDL_gdirender.h"
    13.7 +#include "SDL_gapirender.h"
    13.8  
    13.9  /* Initialization/Query functions */
   13.10  static int WIN_VideoInit(_THIS);
   13.11 @@ -48,6 +49,7 @@
   13.12      SDL_free(message);
   13.13  }
   13.14  
   13.15 +
   13.16  /* WIN32 driver bootstrap functions */
   13.17  
   13.18  static int
   13.19 @@ -74,6 +76,11 @@
   13.20          FreeLibrary(data->ddrawDLL);
   13.21      }
   13.22  #endif
   13.23 +#ifdef _WIN32_WCE
   13.24 +    if(data->hAygShell) {
   13.25 +       FreeLibrary(data->hAygShell);
   13.26 +    }
   13.27 +#endif
   13.28      SDL_free(device->driverdata);
   13.29      SDL_free(device);
   13.30  }
   13.31 @@ -138,6 +145,15 @@
   13.32      }
   13.33  #endif /* SDL_VIDEO_RENDER_DDRAW */
   13.34  
   13.35 +#ifdef _WIN32_WCE
   13.36 +    data->hAygShell = LoadLibrary(TEXT("\\windows\\aygshell.dll"));
   13.37 +    if(0 == data->hAygShell)
   13.38 +        data->hAygShell = LoadLibrary(TEXT("aygshell.dll"));
   13.39 +    data->SHFullScreen = (0 != data->hAygShell ?
   13.40 +        (PFNSHFullScreen) GetProcAddress(data->hAygShell, TEXT("SHFullScreen")) : 0);
   13.41 +    data->CoordTransform = NULL;
   13.42 +#endif
   13.43 +
   13.44      /* Set the function pointers */
   13.45      device->VideoInit = WIN_VideoInit;
   13.46      device->VideoQuit = WIN_VideoQuit;
   13.47 @@ -186,10 +202,13 @@
   13.48  }
   13.49  
   13.50  VideoBootStrap WIN32_bootstrap = {
   13.51 +#ifdef _WIN32_WCE
   13.52 +    "wince", "SDL WinCE video driver", WINCE_Available, WIN_CreateDevice
   13.53 +#else
   13.54      "win32", "SDL Win32/64 video driver", WIN_Available, WIN_CreateDevice
   13.55 +#endif
   13.56  };
   13.57  
   13.58 -
   13.59  int
   13.60  WIN_VideoInit(_THIS)
   13.61  {
   13.62 @@ -207,7 +226,7 @@
   13.63      GDI_AddRenderDriver(_this);
   13.64  #endif
   13.65  #if SDL_VIDEO_RENDER_GAPI
   13.66 -    GAPI_AddRenderDriver(_this);
   13.67 +    WINCE_AddRenderDriver(_this);
   13.68  #endif
   13.69  
   13.70      WIN_InitKeyboard(_this);
    14.1 --- a/src/video/win32/SDL_win32video.h	Fri Jul 23 21:33:00 2010 -0700
    14.2 +++ b/src/video/win32/SDL_win32video.h	Tue Jul 27 21:31:28 2010 -0700
    14.3 @@ -28,7 +28,9 @@
    14.4  
    14.5  #define WIN32_LEAN_AND_MEAN
    14.6  #define STRICT
    14.7 +#ifndef UNICODE
    14.8  #define UNICODE
    14.9 +#endif
   14.10  #undef WINVER
   14.11  #define WINVER  0x500           /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices() */
   14.12  #include <windows.h>
   14.13 @@ -63,10 +65,17 @@
   14.14  #endif
   14.15  extern void WIN_SetError(const char *prefix);
   14.16  
   14.17 +enum { RENDER_NONE, RENDER_D3D, RENDER_DDRAW, RENDER_GDI, RENDER_GAPI, RENDER_RAW };
   14.18 +
   14.19 +typedef BOOL  (*PFNSHFullScreen)(HWND, DWORD);
   14.20 +typedef void  (*PFCoordTransform)(SDL_Window*, POINT*);
   14.21 +
   14.22  /* Private display data */
   14.23  
   14.24  typedef struct SDL_VideoData
   14.25  {
   14.26 +    int render;
   14.27 +
   14.28  #if SDL_VIDEO_RENDER_D3D
   14.29      HANDLE d3dDLL;
   14.30      IDirect3D9 *d3d;
   14.31 @@ -75,6 +84,11 @@
   14.32      HANDLE ddrawDLL;
   14.33      IDirectDraw *ddraw;
   14.34  #endif
   14.35 +#ifdef _WIN32_WCE
   14.36 +    HMODULE hAygShell;
   14.37 +    PFNSHFullScreen SHFullScreen;
   14.38 +    PFCoordTransform CoordTransform;
   14.39 +#endif
   14.40  
   14.41      DWORD clipboard_count;
   14.42  
    15.1 --- a/src/video/win32/SDL_win32window.c	Fri Jul 23 21:33:00 2010 -0700
    15.2 +++ b/src/video/win32/SDL_win32window.c	Tue Jul 27 21:31:28 2010 -0700
    15.3 @@ -34,45 +34,13 @@
    15.4  #include "../../events/SDL_keyboard_c.h"
    15.5  
    15.6  #include "SDL_win32video.h"
    15.7 +#include "SDL_win32window.h"
    15.8  
    15.9  /* This is included after SDL_win32video.h, which includes windows.h */
   15.10  #include "SDL_syswm.h"
   15.11 +#include "SDL_gapirender.h"
   15.12  
   15.13  
   15.14 -#define SHFS_SHOWTASKBAR            0x0001
   15.15 -#define SHFS_HIDETASKBAR            0x0002
   15.16 -#define SHFS_SHOWSIPBUTTON          0x0004
   15.17 -#define SHFS_HIDESIPBUTTON          0x0008
   15.18 -#define SHFS_SHOWSTARTICON          0x0010
   15.19 -#define SHFS_HIDESTARTICON          0x0020
   15.20 -
   15.21 -#ifdef _WIN32_WCE
   15.22 -// dynamically load aygshell dll because we want SDL to work on HPC and be300
   15.23 -int aygshell_loaded = 0;
   15.24 -BOOL(WINAPI * SHFullScreen) (HWND hwndRequester, DWORD dwState) = 0;
   15.25 -
   15.26 -
   15.27 -static BOOL
   15.28 -CE_SHFullScreen(HWND hwndRequester, DWORD dwState)
   15.29 -{
   15.30 -    if (SHFullScreen == 0 && aygshell_loaded == 0) {
   15.31 -        aygshell_loaded = 0;
   15.32 -        void *lib = SDL_LoadObject("aygshell.dll");
   15.33 -        if (lib) {
   15.34 -            SHFullScreen =
   15.35 -                (BOOL(WINAPI *) (HWND, DWORD)) SDL_LoadFunction(lib,
   15.36 -                                                                "SHFullScreen");
   15.37 -        }
   15.38 -    }
   15.39 -
   15.40 -    if (SHFullScreen) {
   15.41 -        SHFullScreen(hwndRequester, dwState);
   15.42 -        //printf("SHFullscreen(%i)\n",dwState);
   15.43 -    }
   15.44 -}
   15.45 -
   15.46 -#endif
   15.47 -
   15.48  /* Fake window to help with DirectInput events. */
   15.49  HWND SDL_HelperWindow = NULL;
   15.50  static WCHAR *SDL_HelperWindowClassName = TEXT("SDLHelperWindowInputCatcher");
   15.51 @@ -472,32 +440,22 @@
   15.52  void
   15.53  WIN_ShowWindow(_THIS, SDL_Window * window)
   15.54  {
   15.55 +#ifdef _WIN32_WCE
   15.56 +    WINCE_ShowWindow(_this, window, 1);
   15.57 +#else
   15.58      HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   15.59 -
   15.60      ShowWindow(hwnd, SW_SHOW);
   15.61 -
   15.62 -#ifdef _WIN32_WCE
   15.63 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   15.64 -        CE_SHFullScreen(hwnd,
   15.65 -                        SHFS_HIDESTARTICON | SHFS_HIDETASKBAR |
   15.66 -                        SHFS_HIDESIPBUTTON);
   15.67 -    }
   15.68  #endif
   15.69  }
   15.70  
   15.71  void
   15.72  WIN_HideWindow(_THIS, SDL_Window * window)
   15.73  {
   15.74 +#ifdef _WIN32_WCE
   15.75 +    WINCE_ShowWindow(_this, window, 0);
   15.76 +#else
   15.77      HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   15.78 -
   15.79      ShowWindow(hwnd, SW_HIDE);
   15.80 -
   15.81 -#ifdef _WIN32_WCE
   15.82 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   15.83 -        CE_SHFullScreen(hwnd,
   15.84 -                        SHFS_SHOWSTARTICON | SHFS_SHOWTASKBAR |
   15.85 -                        SHFS_SHOWSIPBUTTON);
   15.86 -    }
   15.87  #endif
   15.88  }
   15.89  
   15.90 @@ -513,45 +471,33 @@
   15.91          top = HWND_NOTOPMOST;
   15.92      }
   15.93      SetWindowPos(hwnd, top, 0, 0, 0, 0, (SWP_NOMOVE | SWP_NOSIZE));
   15.94 -
   15.95 -#ifdef _WIN32_WCE
   15.96 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   15.97 -        CE_SHFullScreen(hwnd,
   15.98 -                        SHFS_HIDESTARTICON | SHFS_HIDETASKBAR |
   15.99 -                        SHFS_HIDESIPBUTTON);
  15.100 -    }
  15.101 -#endif
  15.102  }
  15.103  
  15.104  void
  15.105  WIN_MaximizeWindow(_THIS, SDL_Window * window)
  15.106  {
  15.107      HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  15.108 +    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
  15.109 +
  15.110 +#ifdef _WIN32_WCE
  15.111 +    if((window->flags & SDL_WINDOW_FULLSCREEN) && videodata->SHFullScreen)
  15.112 +        videodata->SHFullScreen(hwnd, SHFS_HIDETASKBAR | SHFS_HIDESTARTICON | SHFS_HIDESIPBUTTON);
  15.113 +#endif
  15.114  
  15.115      ShowWindow(hwnd, SW_MAXIMIZE);
  15.116 -
  15.117 -#ifdef _WIN32_WCE
  15.118 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
  15.119 -        CE_SHFullScreen(hwnd,
  15.120 -                        SHFS_HIDESTARTICON | SHFS_HIDETASKBAR |
  15.121 -                        SHFS_HIDESIPBUTTON);
  15.122 -    }
  15.123 -#endif
  15.124  }
  15.125  
  15.126  void
  15.127  WIN_MinimizeWindow(_THIS, SDL_Window * window)
  15.128  {
  15.129      HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  15.130 +    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
  15.131  
  15.132      ShowWindow(hwnd, SW_MINIMIZE);
  15.133  
  15.134  #ifdef _WIN32_WCE
  15.135 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
  15.136 -        CE_SHFullScreen(hwnd,
  15.137 -                        SHFS_SHOWSTARTICON | SHFS_SHOWTASKBAR |
  15.138 -                        SHFS_SHOWSIPBUTTON);
  15.139 -    }
  15.140 +    if((window->flags & SDL_WINDOW_FULLSCREEN) && videodata->SHFullScreen)
  15.141 +	videodata->SHFullScreen(hwnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON | SHFS_SHOWSIPBUTTON);
  15.142  #endif
  15.143  }
  15.144  
  15.145 @@ -586,6 +532,9 @@
  15.146      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  15.147  
  15.148      if (data) {
  15.149 +#ifdef _WIN32_WCE
  15.150 +	WINCE_ShowWindow(_this, window, 0);
  15.151 +#endif
  15.152          ReleaseDC(data->hwnd, data->hdc);
  15.153          if (data->created) {
  15.154              DestroyWindow(data->hwnd);
    16.1 --- a/src/video/win32/SDL_win32window.h	Fri Jul 23 21:33:00 2010 -0700
    16.2 +++ b/src/video/win32/SDL_win32window.h	Tue Jul 27 21:31:28 2010 -0700
    16.3 @@ -24,6 +24,15 @@
    16.4  #ifndef _SDL_win32window_h
    16.5  #define _SDL_win32window_h
    16.6  
    16.7 +#ifdef _WIN32_WCE
    16.8 +#define SHFS_SHOWTASKBAR        0x0001
    16.9 +#define SHFS_HIDETASKBAR        0x0002
   16.10 +#define SHFS_SHOWSIPBUTTON      0x0004
   16.11 +#define SHFS_HIDESIPBUTTON      0x0008
   16.12 +#define SHFS_SHOWSTARTICON      0x0010
   16.13 +#define SHFS_HIDESTARTICON      0x0020
   16.14 +#endif
   16.15 +
   16.16  typedef struct
   16.17  {
   16.18      SDL_Window *window;