comparison src/video/gapi/SDL_gapivideo.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 8d9bb0cf2c2a
children e1da92da346c
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
48 #include "../SDL_sysvideo.h" 48 #include "../SDL_sysvideo.h"
49 #include "../SDL_pixels_c.h" 49 #include "../SDL_pixels_c.h"
50 #include "../../events/SDL_events_c.h" 50 #include "../../events/SDL_events_c.h"
51 #include "../wincommon/SDL_syswm_c.h" 51 #include "../wincommon/SDL_syswm_c.h"
52 #include "../wincommon/SDL_sysmouse_c.h" 52 #include "../wincommon/SDL_sysmouse_c.h"
53 #include "../windib/SDL_dibevents_c.h" 53 #include "../windib/SDL_dibevents_c.h"
54 54
55 #include "SDL_gapivideo.h" 55 #include "SDL_gapivideo.h"
56 56
57 #define GAPIVID_DRIVER_NAME "gapi" 57 #define GAPIVID_DRIVER_NAME "gapi"
58 58
75 extern HINSTANCE aygshell; 75 extern HINSTANCE aygshell;
76 extern void SDL_UnregisterApp(); 76 extern void SDL_UnregisterApp();
77 extern int DIB_AddMode(_THIS, int bpp, int w, int h); 77 extern int DIB_AddMode(_THIS, int bpp, int w, int h);
78 78
79 /* Initialization/Query functions */ 79 /* Initialization/Query functions */
80 static int GAPI_VideoInit(_THIS, SDL_PixelFormat *vformat); 80 static int GAPI_VideoInit(_THIS, SDL_PixelFormat * vformat);
81 static SDL_Rect **GAPI_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); 81 static SDL_Rect **GAPI_ListModes(_THIS, SDL_PixelFormat * format,
82 static SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); 82 Uint32 flags);
83 static int GAPI_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); 83 static SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface * current,
84 int width, int height, int bpp,
85 Uint32 flags);
86 static int GAPI_SetColors(_THIS, int firstcolor, int ncolors,
87 SDL_Color * colors);
84 static void GAPI_VideoQuit(_THIS); 88 static void GAPI_VideoQuit(_THIS);
85 89
86 /* Hardware surface functions */ 90 /* Hardware surface functions */
87 static int GAPI_AllocHWSurface(_THIS, SDL_Surface *surface); 91 static int GAPI_AllocHWSurface(_THIS, SDL_Surface * surface);
88 static int GAPI_LockHWSurface(_THIS, SDL_Surface *surface); 92 static int GAPI_LockHWSurface(_THIS, SDL_Surface * surface);
89 static void GAPI_UnlockHWSurface(_THIS, SDL_Surface *surface); 93 static void GAPI_UnlockHWSurface(_THIS, SDL_Surface * surface);
90 static void GAPI_FreeHWSurface(_THIS, SDL_Surface *surface); 94 static void GAPI_FreeHWSurface(_THIS, SDL_Surface * surface);
91 95
92 /* Windows message handling functions, will not be processed */ 96 /* Windows message handling functions, will not be processed */
93 static void GAPI_RealizePalette(_THIS); 97 static void GAPI_RealizePalette(_THIS);
94 static void GAPI_PaletteChanged(_THIS, HWND window); 98 static void GAPI_PaletteChanged(_THIS, HWND window);
95 static void GAPI_WinPAINT(_THIS, HDC hdc); 99 static void GAPI_WinPAINT(_THIS, HDC hdc);
96 100
97 /* etc. */ 101 /* etc. */
98 static void GAPI_UpdateRects(_THIS, int numrects, SDL_Rect *rects); 102 static void GAPI_UpdateRects(_THIS, int numrects, SDL_Rect * rects);
99 103
100 static HMODULE g_hGapiLib = 0; 104 static HMODULE g_hGapiLib = 0;
101 #define LINK(type,name,import) \ 105 #define LINK(type,name,import) \
102 if( g_hGapiLib ) \ 106 if( g_hGapiLib ) \
103 name = (PFN##type)GetProcAddress( g_hGapiLib, _T(import) ); 107 name = (PFN##type)GetProcAddress( g_hGapiLib, _T(import) );
104 108
105 static char g_bRawBufferAvailable = 0; 109 static char g_bRawBufferAvailable = 0;
106 110
107 /* GAPI driver bootstrap functions */ 111 /* GAPI driver bootstrap functions */
108 112
109 /* hi res definitions */ 113 /* hi res definitions */
110 typedef struct _RawFrameBufferInfo 114 typedef struct _RawFrameBufferInfo
111 { 115 {
112 WORD wFormat; 116 WORD wFormat;
113 WORD wBPP; 117 WORD wBPP;
114 VOID *pFramePointer; 118 VOID *pFramePointer;
115 int cxStride; 119 int cxStride;
116 int cyStride; 120 int cyStride;
117 int cxPixels; 121 int cxPixels;
118 int cyPixels; 122 int cyPixels;
119 } RawFrameBufferInfo; 123 } RawFrameBufferInfo;
120 124
121 static struct _RawFrameBufferInfo g_RawFrameBufferInfo = {0}; 125 static struct _RawFrameBufferInfo g_RawFrameBufferInfo = { 0 };
122 126
123 #define GETRAWFRAMEBUFFER 0x00020001 127 #define GETRAWFRAMEBUFFER 0x00020001
124 128
125 #define FORMAT_565 1 129 #define FORMAT_565 1
126 #define FORMAT_555 2 130 #define FORMAT_555 2
132 */ 136 */
133 #define GETGXINFO 0x00020000 137 #define GETGXINFO 0x00020000
134 138
135 typedef struct GXDeviceInfo 139 typedef struct GXDeviceInfo
136 { 140 {
137 long Version; //00 (should filled with 100 before calling ExtEscape) 141 long Version; //00 (should filled with 100 before calling ExtEscape)
138 void * pvFrameBuffer; //04 142 void *pvFrameBuffer; //04
139 unsigned long cbStride; //08 143 unsigned long cbStride; //08
140 unsigned long cxWidth; //0c 144 unsigned long cxWidth; //0c
141 unsigned long cyHeight; //10 145 unsigned long cyHeight; //10
142 unsigned long cBPP; //14 146 unsigned long cBPP; //14
143 unsigned long ffFormat; //18 147 unsigned long ffFormat; //18
144 char Unused[0x84-7*4]; 148 char Unused[0x84 - 7 * 4];
145 } GXDeviceInfo; 149 } GXDeviceInfo;
146 150
147 static int GAPI_Available(void) 151 static int
148 { 152 GAPI_Available(void)
149 // try to use VGA display, even on emulator 153 {
150 HDC hdc = GetDC(NULL); 154 // try to use VGA display, even on emulator
151 int result = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *)&g_RawFrameBufferInfo); 155 HDC hdc = GetDC(NULL);
152 ReleaseDC(NULL, hdc); 156 int result = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL,
153 g_bRawBufferAvailable = result > 0; 157 sizeof(RawFrameBufferInfo),
158 (char *) &g_RawFrameBufferInfo);
159 ReleaseDC(NULL, hdc);
160 g_bRawBufferAvailable = result > 0;
154 161
155 #if WITHOUT_GAPI 162 #if WITHOUT_GAPI
156 return g_bRawBufferAvailable; 163 return g_bRawBufferAvailable;
157 #endif 164 #endif
158 165
159 #if USE_GAPI_EMU 166 #if USE_GAPI_EMU
160 g_hGapiLib = LoadLibrary(_T("GAPI_Emu.dll")); 167 g_hGapiLib = LoadLibrary(_T("GAPI_Emu.dll"));
161 if( !g_hGapiLib ) 168 if (!g_hGapiLib) {
162 { 169 SDL_SetError("Gapi Emu not found!");
163 SDL_SetError("Gapi Emu not found!"); 170 }
164 } 171 return g_hGapiLib != 0;
165 return g_hGapiLib != 0;
166 #endif 172 #endif
167 173
168 // try to find gx.dll 174 // try to find gx.dll
169 g_hGapiLib = LoadLibrary(_T("\\Windows\\gx.dll")); 175 g_hGapiLib = LoadLibrary(_T("\\Windows\\gx.dll"));
170 if( !g_hGapiLib ) 176 if (!g_hGapiLib) {
171 { 177 g_hGapiLib = LoadLibrary(_T("gx.dll"));
172 g_hGapiLib = LoadLibrary(_T("gx.dll")); 178 if (!g_hGapiLib)
173 if( !g_hGapiLib ) return g_bRawBufferAvailable; 179 return g_bRawBufferAvailable;
174 } 180 }
175 181
176 return(1); 182 return (1);
177 } 183 }
178 184
179 static int cmpmodes(const void *va, const void *vb) 185 static int
180 { 186 cmpmodes(const void *va, const void *vb)
181 SDL_Rect *a = *(SDL_Rect **)va; 187 {
182 SDL_Rect *b = *(SDL_Rect **)vb; 188 SDL_Rect *a = *(SDL_Rect **) va;
183 if ( a->w == b->w ) 189 SDL_Rect *b = *(SDL_Rect **) vb;
190 if (a->w == b->w)
184 return b->h - a->h; 191 return b->h - a->h;
185 else 192 else
186 return b->w - a->w; 193 return b->w - a->w;
187 } 194 }
188 195
189 static int GAPI_AddMode(_THIS, int bpp, int w, int h) 196 static int
190 { 197 GAPI_AddMode(_THIS, int bpp, int w, int h)
191 SDL_Rect *mode; 198 {
192 int i, index; 199 SDL_Rect *mode;
193 int next_mode; 200 int i, index;
194 201 int next_mode;
195 /* Check to see if we already have this mode */ 202
196 if ( bpp < 8 ) { /* Not supported */ 203 /* Check to see if we already have this mode */
197 return(0); 204 if (bpp < 8) { /* Not supported */
198 } 205 return (0);
199 index = ((bpp+7)/8)-1; 206 }
200 for ( i=0; i<gapi->SDL_nummodes[index]; ++i ) { 207 index = ((bpp + 7) / 8) - 1;
201 mode = gapi->SDL_modelist[index][i]; 208 for (i = 0; i < gapi->SDL_nummodes[index]; ++i) {
202 if ( (mode->w == w) && (mode->h == h) ) { 209 mode = gapi->SDL_modelist[index][i];
203 return(0); 210 if ((mode->w == w) && (mode->h == h)) {
204 } 211 return (0);
205 } 212 }
206 213 }
207 /* Set up the new video mode rectangle */ 214
208 mode = (SDL_Rect *)SDL_malloc(sizeof *mode); 215 /* Set up the new video mode rectangle */
209 if ( mode == NULL ) { 216 mode = (SDL_Rect *) SDL_malloc(sizeof *mode);
210 SDL_OutOfMemory(); 217 if (mode == NULL) {
211 return(-1); 218 SDL_OutOfMemory();
212 } 219 return (-1);
213 mode->x = 0; 220 }
214 mode->y = 0; 221 mode->x = 0;
215 mode->w = w; 222 mode->y = 0;
216 mode->h = h; 223 mode->w = w;
217 224 mode->h = h;
218 /* Allocate the new list of modes, and fill in the new mode */ 225
219 next_mode = gapi->SDL_nummodes[index]; 226 /* Allocate the new list of modes, and fill in the new mode */
220 gapi->SDL_modelist[index] = (SDL_Rect **) 227 next_mode = gapi->SDL_nummodes[index];
221 SDL_realloc(gapi->SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *)); 228 gapi->SDL_modelist[index] = (SDL_Rect **)
222 if ( gapi->SDL_modelist[index] == NULL ) { 229 SDL_realloc(gapi->SDL_modelist[index],
223 SDL_OutOfMemory(); 230 (1 + next_mode + 1) * sizeof(SDL_Rect *));
224 gapi->SDL_nummodes[index] = 0; 231 if (gapi->SDL_modelist[index] == NULL) {
225 SDL_free(mode); 232 SDL_OutOfMemory();
226 return(-1); 233 gapi->SDL_nummodes[index] = 0;
227 } 234 SDL_free(mode);
228 gapi->SDL_modelist[index][next_mode] = mode; 235 return (-1);
229 gapi->SDL_modelist[index][next_mode+1] = NULL; 236 }
230 gapi->SDL_nummodes[index]++; 237 gapi->SDL_modelist[index][next_mode] = mode;
231 238 gapi->SDL_modelist[index][next_mode + 1] = NULL;
232 return(0); 239 gapi->SDL_nummodes[index]++;
233 } 240
234 241 return (0);
235 static void GAPI_DeleteDevice(SDL_VideoDevice *device) 242 }
236 { 243
237 if( g_hGapiLib ) 244 static void
238 { 245 GAPI_DeleteDevice(SDL_VideoDevice * device)
239 FreeLibrary(g_hGapiLib); 246 {
240 g_hGapiLib = 0; 247 if (g_hGapiLib) {
241 } 248 FreeLibrary(g_hGapiLib);
242 SDL_free(device->hidden); 249 g_hGapiLib = 0;
243 SDL_free(device); 250 }
244 } 251 SDL_free(device->hidden);
245 252 SDL_free(device);
246 static SDL_VideoDevice *GAPI_CreateDevice(int devindex) 253 }
247 { 254
248 SDL_VideoDevice *device; 255 static SDL_VideoDevice *
249 256 GAPI_CreateDevice(int devindex)
250 if( !g_hGapiLib && !g_bRawBufferAvailable) 257 {
251 { 258 SDL_VideoDevice *device;
252 if( !GAPI_Available() ) 259
253 { 260 if (!g_hGapiLib && !g_bRawBufferAvailable) {
254 SDL_SetError("GAPI dll is not found and VGA mode is not available!"); 261 if (!GAPI_Available()) {
255 return 0; 262 SDL_SetError
256 } 263 ("GAPI dll is not found and VGA mode is not available!");
257 } 264 return 0;
258 265 }
259 /* Initialize all variables that we clean on shutdown */ 266 }
260 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); 267
261 if ( device ) { 268 /* Initialize all variables that we clean on shutdown */
262 SDL_memset(device, 0, (sizeof *device)); 269 device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
263 device->hidden = (struct SDL_PrivateVideoData *) 270 if (device) {
264 SDL_malloc((sizeof *device->hidden)); 271 SDL_memset(device, 0, (sizeof *device));
265 } 272 device->hidden = (struct SDL_PrivateVideoData *)
266 if ( (device == NULL) || (device->hidden == NULL) ) { 273 SDL_malloc((sizeof *device->hidden));
267 SDL_OutOfMemory(); 274 }
268 if ( device ) { 275 if ((device == NULL) || (device->hidden == NULL)) {
269 SDL_free(device); 276 SDL_OutOfMemory();
270 } 277 if (device) {
271 return(0); 278 SDL_free(device);
272 } 279 }
273 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); 280 return (0);
274 281 }
275 /* Set the function pointers */ 282 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
276 device->VideoInit = GAPI_VideoInit; 283
277 device->ListModes = GAPI_ListModes; 284 /* Set the function pointers */
278 device->SetVideoMode = GAPI_SetVideoMode; 285 device->VideoInit = GAPI_VideoInit;
279 device->UpdateMouse = WIN_UpdateMouse; 286 device->ListModes = GAPI_ListModes;
280 device->CreateYUVOverlay = NULL; 287 device->SetVideoMode = GAPI_SetVideoMode;
281 device->SetColors = GAPI_SetColors; 288 device->UpdateMouse = WIN_UpdateMouse;
282 device->UpdateRects = GAPI_UpdateRects; 289 device->CreateYUVOverlay = NULL;
283 device->VideoQuit = GAPI_VideoQuit; 290 device->SetColors = GAPI_SetColors;
284 device->AllocHWSurface = GAPI_AllocHWSurface; 291 device->UpdateRects = GAPI_UpdateRects;
285 device->CheckHWBlit = NULL; 292 device->VideoQuit = GAPI_VideoQuit;
286 device->FillHWRect = NULL; 293 device->AllocHWSurface = GAPI_AllocHWSurface;
287 device->SetHWColorKey = NULL; 294 device->CheckHWBlit = NULL;
288 device->SetHWAlpha = NULL; 295 device->FillHWRect = NULL;
289 device->LockHWSurface = GAPI_LockHWSurface; 296 device->SetHWColorKey = NULL;
290 device->UnlockHWSurface = GAPI_UnlockHWSurface; 297 device->SetHWAlpha = NULL;
291 device->FlipHWSurface = NULL; 298 device->LockHWSurface = GAPI_LockHWSurface;
292 device->FreeHWSurface = GAPI_FreeHWSurface; 299 device->UnlockHWSurface = GAPI_UnlockHWSurface;
293 device->SetCaption = WIN_SetWMCaption; 300 device->FlipHWSurface = NULL;
294 device->SetIcon = WIN_SetWMIcon; 301 device->FreeHWSurface = GAPI_FreeHWSurface;
295 device->IconifyWindow = WIN_IconifyWindow; 302 device->SetCaption = WIN_SetWMCaption;
296 device->GrabInput = WIN_GrabInput; 303 device->SetIcon = WIN_SetWMIcon;
297 device->GetWMInfo = WIN_GetWMInfo; 304 device->IconifyWindow = WIN_IconifyWindow;
298 device->FreeWMCursor = WIN_FreeWMCursor; 305 device->GrabInput = WIN_GrabInput;
299 device->CreateWMCursor = WIN_CreateWMCursor; 306 device->GetWMInfo = WIN_GetWMInfo;
300 device->ShowWMCursor = WIN_ShowWMCursor; 307 device->FreeWMCursor = WIN_FreeWMCursor;
301 device->WarpWMCursor = WIN_WarpWMCursor; 308 device->CreateWMCursor = WIN_CreateWMCursor;
309 device->ShowWMCursor = WIN_ShowWMCursor;
310 device->WarpWMCursor = WIN_WarpWMCursor;
302 device->CheckMouseMode = WIN_CheckMouseMode; 311 device->CheckMouseMode = WIN_CheckMouseMode;
303 device->InitOSKeymap = DIB_InitOSKeymap; 312 device->InitOSKeymap = DIB_InitOSKeymap;
304 device->PumpEvents = DIB_PumpEvents; 313 device->PumpEvents = DIB_PumpEvents;
305 314
306 /* Set up the windows message handling functions */ 315 /* Set up the windows message handling functions */
307 WIN_RealizePalette = GAPI_RealizePalette; 316 WIN_RealizePalette = GAPI_RealizePalette;
308 WIN_PaletteChanged = GAPI_PaletteChanged; 317 WIN_PaletteChanged = GAPI_PaletteChanged;
309 WIN_WinPAINT = GAPI_WinPAINT; 318 WIN_WinPAINT = GAPI_WinPAINT;
310 HandleMessage = DIB_HandleMessage; 319 HandleMessage = DIB_HandleMessage;
311 320
312 device->free = GAPI_DeleteDevice; 321 device->free = GAPI_DeleteDevice;
313 322
314 /* Load gapi library */ 323 /* Load gapi library */
315 #define gx device->hidden->gxFunc 324 #define gx device->hidden->gxFunc
316 325
317 LINK( GXOpenDisplay, gx.GXOpenDisplay, "?GXOpenDisplay@@YAHPAUHWND__@@K@Z" ) 326 LINK(GXOpenDisplay, gx.GXOpenDisplay,
318 LINK( GXCloseDisplay, gx.GXCloseDisplay, "?GXCloseDisplay@@YAHXZ" ) 327 "?GXOpenDisplay@@YAHPAUHWND__@@K@Z") LINK(GXCloseDisplay,
319 LINK( GXBeginDraw, gx.GXBeginDraw, "?GXBeginDraw@@YAPAXXZ" ) 328 gx.GXCloseDisplay,
320 LINK( GXEndDraw, gx.GXEndDraw, "?GXEndDraw@@YAHXZ" ) 329 "?GXCloseDisplay@@YAHXZ")
321 LINK( GXOpenInput, gx.GXOpenInput, "?GXOpenInput@@YAHXZ" ) 330 LINK(GXBeginDraw, gx.GXBeginDraw,
322 LINK( GXCloseInput, gx.GXCloseInput, "?GXCloseInput@@YAHXZ" ) 331 "?GXBeginDraw@@YAPAXXZ") LINK(GXEndDraw, gx.GXEndDraw,
323 LINK( GXGetDisplayProperties, gx.GXGetDisplayProperties,"?GXGetDisplayProperties@@YA?AUGXDisplayProperties@@XZ" ) 332 "?GXEndDraw@@YAHXZ")
324 LINK( GXGetDefaultKeys, gx.GXGetDefaultKeys, "?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z" ) 333 LINK(GXOpenInput, gx.GXOpenInput,
325 LINK( GXSuspend, gx.GXSuspend, "?GXSuspend@@YAHXZ" ) 334 "?GXOpenInput@@YAHXZ") LINK(GXCloseInput, gx.GXCloseInput,
326 LINK( GXResume, gx.GXResume, "?GXResume@@YAHXZ" ) 335 "?GXCloseInput@@YAHXZ")
327 LINK( GXSetViewport, gx.GXSetViewport, "?GXSetViewport@@YAHKKKK@Z" ) 336 LINK(GXGetDisplayProperties, gx.GXGetDisplayProperties,
328 LINK( GXIsDisplayDRAMBuffer, gx.GXIsDisplayDRAMBuffer, "?GXIsDisplayDRAMBuffer@@YAHXZ" ) 337 "?GXGetDisplayProperties@@YA?AUGXDisplayProperties@@XZ")
329 338 LINK(GXGetDefaultKeys, gx.GXGetDefaultKeys,
330 /* wrong gapi.dll */ 339 "?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z") LINK(GXSuspend,
331 if( !gx.GXOpenDisplay ) 340 gx.GXSuspend,
332 { 341 "?GXSuspend@@YAHXZ")
333 if( g_hGapiLib ) 342 LINK(GXResume, gx.GXResume, "?GXResume@@YAHXZ") LINK(GXSetViewport,
334 { 343 gx.
335 FreeLibrary(g_hGapiLib); 344 GXSetViewport,
336 g_hGapiLib = 0; 345 "?GXSetViewport@@YAHKKKK@Z")
337 } 346 LINK(GXIsDisplayDRAMBuffer, gx.GXIsDisplayDRAMBuffer,
338 } 347 "?GXIsDisplayDRAMBuffer@@YAHXZ")
339 348 /* wrong gapi.dll */
340 if( !gx.GXOpenDisplay && !g_bRawBufferAvailable) 349 if (!gx.GXOpenDisplay) {
341 { 350 if (g_hGapiLib) {
342 SDL_SetError("Error: damaged or unknown gapi.dll!\n"); 351 FreeLibrary(g_hGapiLib);
343 GAPI_DeleteDevice(device); 352 g_hGapiLib = 0;
344 return 0; 353 }
345 } 354 }
346 355
347 return device; 356 if (!gx.GXOpenDisplay && !g_bRawBufferAvailable) {
357 SDL_SetError("Error: damaged or unknown gapi.dll!\n");
358 GAPI_DeleteDevice(device);
359 return 0;
360 }
361
362 return device;
348 } 363 }
349 364
350 VideoBootStrap GAPI_bootstrap = { 365 VideoBootStrap GAPI_bootstrap = {
351 GAPIVID_DRIVER_NAME, "WinCE GAPI video driver", 366 GAPIVID_DRIVER_NAME, "WinCE GAPI video driver",
352 GAPI_Available, GAPI_CreateDevice 367 GAPI_Available, GAPI_CreateDevice
353 }; 368 };
354 369
355 static void FillStructs(_THIS, BOOL useVga) 370 static void
371 FillStructs(_THIS, BOOL useVga)
356 { 372 {
357 #ifdef _ARM_ 373 #ifdef _ARM_
358 WCHAR oemstr[100]; 374 WCHAR oemstr[100];
359 #endif 375 #endif
360 /* fill a device properties */ 376 /* fill a device properties */
361 377
362 if( !useVga ) 378 if (!useVga) {
363 { 379 this->hidden->gxProperties =
364 this->hidden->gxProperties = this->hidden->gxFunc.GXGetDisplayProperties(); 380 this->hidden->gxFunc.GXGetDisplayProperties();
365 this->hidden->needUpdate = 1; 381 this->hidden->needUpdate = 1;
366 this->hidden->hiresFix = 0; 382 this->hidden->hiresFix = 0;
367 this->hidden->useVga = 0; 383 this->hidden->useVga = 0;
368 this->hidden->useGXOpenDisplay = 1; 384 this->hidden->useGXOpenDisplay = 1;
369 385
370 #ifdef _ARM_ 386 #ifdef _ARM_
371 /* check some devices and extract addition info */ 387 /* check some devices and extract addition info */
372 SystemParametersInfo( SPI_GETOEMINFO, sizeof( oemstr ), oemstr, 0 ); 388 SystemParametersInfo(SPI_GETOEMINFO, sizeof(oemstr), oemstr, 0);
373 389
374 // buggy iPaq38xx 390 // buggy iPaq38xx
375 if ((oemstr[12] == 'H') && (oemstr[13] == '3') && (oemstr[14] == '8') && (this->hidden->gxProperties.cbxPitch > 0)) 391 if ((oemstr[12] == 'H') && (oemstr[13] == '3')
376 { 392 && (oemstr[14] == '8')
377 this->hidden->videoMem = (PIXEL*)0xac0755a0; 393 && (this->hidden->gxProperties.cbxPitch > 0)) {
378 this->hidden->gxProperties.cbxPitch = -640; 394 this->hidden->videoMem = (PIXEL *) 0xac0755a0;
379 this->hidden->gxProperties.cbyPitch = 2; 395 this->hidden->gxProperties.cbxPitch = -640;
380 this->hidden->needUpdate = 0; 396 this->hidden->gxProperties.cbyPitch = 2;
381 } 397 this->hidden->needUpdate = 0;
398 }
382 #if (EMULATE_AXIM_X30 == 0) 399 #if (EMULATE_AXIM_X30 == 0)
383 // buggy Dell Axim X30 400 // buggy Dell Axim X30
384 if( _tcsncmp(oemstr, L"Dell Axim X30", 13) == 0 ) 401 if (_tcsncmp(oemstr, L"Dell Axim X30", 13) == 0)
385 #endif 402 #endif
386 { 403 {
387 GXDeviceInfo gxInfo = {0}; 404 GXDeviceInfo gxInfo = { 0 };
388 HDC hdc = GetDC(NULL); 405 HDC hdc = GetDC(NULL);
389 int result; 406 int result;
390 407
391 gxInfo.Version = 100; 408 gxInfo.Version = 100;
392 result = ExtEscape(hdc, GETGXINFO, 0, NULL, sizeof(gxInfo), (char *)&gxInfo); 409 result =
393 if( result > 0 ) 410 ExtEscape(hdc, GETGXINFO, 0, NULL, sizeof(gxInfo),
394 { 411 (char *) &gxInfo);
395 this->hidden->useGXOpenDisplay = 0; 412 if (result > 0) {
396 this->hidden->videoMem = gxInfo.pvFrameBuffer; 413 this->hidden->useGXOpenDisplay = 0;
397 this->hidden->needUpdate = 0; 414 this->hidden->videoMem = gxInfo.pvFrameBuffer;
398 this->hidden->gxProperties.cbxPitch = 2; 415 this->hidden->needUpdate = 0;
399 this->hidden->gxProperties.cbyPitch = 480; 416 this->hidden->gxProperties.cbxPitch = 2;
400 this->hidden->gxProperties.cxWidth = gxInfo.cxWidth; 417 this->hidden->gxProperties.cbyPitch = 480;
401 this->hidden->gxProperties.cyHeight = gxInfo.cyHeight; 418 this->hidden->gxProperties.cxWidth = gxInfo.cxWidth;
402 this->hidden->gxProperties.ffFormat = gxInfo.ffFormat; 419 this->hidden->gxProperties.cyHeight = gxInfo.cyHeight;
403 } 420 this->hidden->gxProperties.ffFormat = gxInfo.ffFormat;
404 } 421 }
422 }
405 #endif 423 #endif
406 } else 424 } else {
407 { 425 this->hidden->needUpdate = 0;
408 this->hidden->needUpdate = 0; 426 this->hidden->hiresFix = 0;
409 this->hidden->hiresFix = 0; 427 this->hidden->gxProperties.cBPP = g_RawFrameBufferInfo.wBPP;
410 this->hidden->gxProperties.cBPP = g_RawFrameBufferInfo.wBPP; 428 this->hidden->gxProperties.cbxPitch = g_RawFrameBufferInfo.cxStride;
411 this->hidden->gxProperties.cbxPitch = g_RawFrameBufferInfo.cxStride; 429 this->hidden->gxProperties.cbyPitch = g_RawFrameBufferInfo.cyStride;
412 this->hidden->gxProperties.cbyPitch = g_RawFrameBufferInfo.cyStride; 430 this->hidden->gxProperties.cxWidth = g_RawFrameBufferInfo.cxPixels;
413 this->hidden->gxProperties.cxWidth = g_RawFrameBufferInfo.cxPixels; 431 this->hidden->gxProperties.cyHeight = g_RawFrameBufferInfo.cyPixels;
414 this->hidden->gxProperties.cyHeight = g_RawFrameBufferInfo.cyPixels; 432 this->hidden->videoMem = g_RawFrameBufferInfo.pFramePointer;
415 this->hidden->videoMem = g_RawFrameBufferInfo.pFramePointer; 433 this->hidden->useVga = 1;
416 this->hidden->useVga = 1; 434
417 435 switch (g_RawFrameBufferInfo.wFormat) {
418 switch( g_RawFrameBufferInfo.wFormat ) 436 case FORMAT_565:
419 { 437 this->hidden->gxProperties.ffFormat = kfDirect565;
420 case FORMAT_565: 438 break;
421 this->hidden->gxProperties.ffFormat = kfDirect565; 439 case FORMAT_555:
422 break; 440 this->hidden->gxProperties.ffFormat = kfDirect555;
423 case FORMAT_555: 441 break;
424 this->hidden->gxProperties.ffFormat = kfDirect555; 442 default:
425 break; 443 /* unknown pixel format, try define by BPP! */
426 default: 444 switch (g_RawFrameBufferInfo.wBPP) {
427 /* unknown pixel format, try define by BPP! */ 445 case 4:
428 switch( g_RawFrameBufferInfo.wBPP ) 446 case 8:
429 { 447 this->hidden->gxProperties.ffFormat = kfDirect;
430 case 4: 448 case 16:
431 case 8: 449 this->hidden->gxProperties.ffFormat = kfDirect565;
432 this->hidden->gxProperties.ffFormat = kfDirect; 450 default:
433 case 16: 451 this->hidden->gxProperties.ffFormat = kfDirect;
434 this->hidden->gxProperties.ffFormat = kfDirect565; 452 break;
435 default: 453 }
436 this->hidden->gxProperties.ffFormat = kfDirect; 454 }
437 break; 455 }
438 } 456
439 } 457 if (this->hidden->gxProperties.cBPP != 16) {
440 } 458 this->hidden->gapiOrientation = SDL_ORIENTATION_UP;
441 459 } else if ((this->hidden->gxProperties.cbxPitch > 0)
442 if( this->hidden->gxProperties.cBPP != 16 ) 460 && (this->hidden->gxProperties.cbyPitch > 0)) {
443 { 461 this->hidden->gapiOrientation = SDL_ORIENTATION_UP;
444 this->hidden->gapiOrientation = SDL_ORIENTATION_UP; 462 } else if ((this->hidden->gxProperties.cbxPitch > 0)
445 } else 463 && (this->hidden->gxProperties.cbyPitch < 0)) {
446 if( (this->hidden->gxProperties.cbxPitch > 0) && (this->hidden->gxProperties.cbyPitch > 0 )) 464 this->hidden->gapiOrientation = SDL_ORIENTATION_RIGHT; // ipaq 3660
447 { 465 } else if ((this->hidden->gxProperties.cbxPitch < 0)
448 this->hidden->gapiOrientation = SDL_ORIENTATION_UP; 466 && (this->hidden->gxProperties.cbyPitch > 0)) {
449 } else 467 this->hidden->gapiOrientation = SDL_ORIENTATION_LEFT; // ipaq 3800
450 if( (this->hidden->gxProperties.cbxPitch > 0) && (this->hidden->gxProperties.cbyPitch < 0 )) 468 }
451 { 469 }
452 this->hidden->gapiOrientation = SDL_ORIENTATION_RIGHT; // ipaq 3660 470
453 } else 471 static void
454 if( (this->hidden->gxProperties.cbxPitch < 0) && (this->hidden->gxProperties.cbyPitch > 0 )) 472 GAPI_CreatePalette(int ncolors, SDL_Color * colors)
455 { 473 {
456 this->hidden->gapiOrientation = SDL_ORIENTATION_LEFT; // ipaq 3800 474 // Setup a custom color palette
457 } 475 BYTE buffer[sizeof(LOGPALETTE) + 255 * sizeof(PALETTEENTRY)];
458 } 476 int i;
459 477 LOGPALETTE *pLogical = (LOGPALETTE *) buffer;
460 static void GAPI_CreatePalette(int ncolors, SDL_Color *colors) 478 PALETTEENTRY *entries = pLogical->palPalEntry;
461 { 479 HPALETTE hPalette;
462 // Setup a custom color palette 480 HDC hdc;
463 BYTE buffer[ sizeof(LOGPALETTE) + 255 * sizeof(PALETTEENTRY) ]; 481
464 int i; 482 for (i = 0; i < ncolors; ++i) {
465 LOGPALETTE* pLogical = (LOGPALETTE*)buffer; 483 // Find intensity by replicating the bit patterns over a byte
466 PALETTEENTRY* entries = pLogical->palPalEntry; 484 entries[i].peRed = colors[i].r;
467 HPALETTE hPalette; 485 entries[i].peGreen = colors[i].g;
468 HDC hdc; 486 entries[i].peBlue = colors[i].b;
469 487 entries[i].peFlags = 0;
470 for (i = 0; i < ncolors; ++i) 488 }
471 { 489
472 // Find intensity by replicating the bit patterns over a byte 490 // Create the GDI palette object
473 entries[i].peRed = colors[i].r; 491 pLogical->palVersion = 0x0300;
474 entries[i].peGreen = colors[i].g; 492 pLogical->palNumEntries = ncolors;
475 entries[i].peBlue = colors[i].b; 493
476 entries[i].peFlags = 0; 494 hPalette = CreatePalette(pLogical);
477 } 495 ASSERT(hPalette);
478 496
479 // Create the GDI palette object 497
480 pLogical->palVersion = 0x0300; 498 // Realize the palette
481 pLogical->palNumEntries = ncolors; 499 hdc = GetDC(0);
482 500
483 hPalette = CreatePalette( pLogical ); 501 SelectPalette(hdc, hPalette, FALSE);
484 ASSERT(hPalette); 502 RealizePalette(hdc);
485 503
486 504 ReleaseDC(0, hdc);
487 // Realize the palette 505 DeleteObject(hPalette);
488 hdc = GetDC(0); 506 }
489 507
490 SelectPalette( hdc, hPalette, FALSE ); 508 int
491 RealizePalette( hdc ); 509 GAPI_VideoInit(_THIS, SDL_PixelFormat * vformat)
492 510 {
493 ReleaseDC( 0, hdc ); 511 int i, bpp;
494 DeleteObject( hPalette ); 512
495 } 513 /* Create the window */
496 514 if (DIB_CreateWindow(this) < 0) {
497 int GAPI_VideoInit(_THIS, SDL_PixelFormat *vformat) 515 return (-1);
498 { 516 }
499 int i,bpp; 517
500 518 if (g_hGapiLib) {
501 /* Create the window */ 519 FillStructs(this, 0);
502 if ( DIB_CreateWindow(this) < 0 ) { 520
503 return(-1); 521 // SDL does not supports 2/4bpp mode, so use 16 bpp
504 } 522 bpp = gapi->gxProperties.cBPP < 8 ? 16 : gapi->gxProperties.cBPP;
505 523
506 if( g_hGapiLib ) 524 /* set up normal and landscape mode */
507 { 525 GAPI_AddMode(this, bpp, gapi->gxProperties.cyHeight,
508 FillStructs(this, 0); 526 gapi->gxProperties.cxWidth);
509 527 GAPI_AddMode(this, bpp, gapi->gxProperties.cxWidth,
510 // SDL does not supports 2/4bpp mode, so use 16 bpp 528 gapi->gxProperties.cyHeight);
511 bpp = gapi->gxProperties.cBPP < 8 ? 16 : gapi->gxProperties.cBPP; 529 }
512 530
513 /* set up normal and landscape mode */ 531 /* add hi-res mode */
514 GAPI_AddMode(this, bpp, gapi->gxProperties.cyHeight, gapi->gxProperties.cxWidth); 532 if (g_bRawBufferAvailable &&
515 GAPI_AddMode(this, bpp, gapi->gxProperties.cxWidth, gapi->gxProperties.cyHeight); 533 !((gapi->gxProperties.cxWidth ==
516 } 534 (unsigned) g_RawFrameBufferInfo.cxPixels)
517 535 && (gapi->gxProperties.cyHeight ==
518 /* add hi-res mode */ 536 (unsigned) g_RawFrameBufferInfo.cyPixels))) {
519 if( g_bRawBufferAvailable && 537 FillStructs(this, 1);
520 !((gapi->gxProperties.cxWidth == (unsigned)g_RawFrameBufferInfo.cxPixels) && (gapi->gxProperties.cyHeight == (unsigned)g_RawFrameBufferInfo.cyPixels))) 538
521 { 539 // SDL does not supports 2/4bpp mode, so use 16 bpp
522 FillStructs(this, 1); 540 bpp = gapi->gxProperties.cBPP < 8 ? 16 : gapi->gxProperties.cBPP;
523 541
524 // SDL does not supports 2/4bpp mode, so use 16 bpp 542 /* set up normal and landscape mode */
525 bpp = gapi->gxProperties.cBPP < 8 ? 16 : gapi->gxProperties.cBPP; 543 GAPI_AddMode(this, bpp, gapi->gxProperties.cyHeight,
526 544 gapi->gxProperties.cxWidth);
527 /* set up normal and landscape mode */ 545 GAPI_AddMode(this, bpp, gapi->gxProperties.cxWidth,
528 GAPI_AddMode(this, bpp, gapi->gxProperties.cyHeight, gapi->gxProperties.cxWidth); 546 gapi->gxProperties.cyHeight);
529 GAPI_AddMode(this, bpp, gapi->gxProperties.cxWidth, gapi->gxProperties.cyHeight); 547 }
530 } 548
531 549 /* Determine the current screen size */
532 /* Determine the current screen size */ 550 this->info.current_w = gapi->gxProperties.cxWidth;
533 this->info.current_w = gapi->gxProperties.cxWidth; 551 this->info.current_h = gapi->gxProperties.cyHeight;
534 this->info.current_h = gapi->gxProperties.cyHeight; 552
535 553 /* Sort the mode lists */
536 /* Sort the mode lists */ 554 for (i = 0; i < NUM_MODELISTS; ++i) {
537 for ( i=0; i<NUM_MODELISTS; ++i ) { 555 if (gapi->SDL_nummodes[i] > 0) {
538 if ( gapi->SDL_nummodes[i] > 0 ) { 556 SDL_qsort(gapi->SDL_modelist[i], gapi->SDL_nummodes[i],
539 SDL_qsort(gapi->SDL_modelist[i], gapi->SDL_nummodes[i], sizeof *gapi->SDL_modelist[i], cmpmodes); 557 sizeof *gapi->SDL_modelist[i], cmpmodes);
540 } 558 }
541 } 559 }
542 560
543 vformat->BitsPerPixel = this->hidden->gxProperties.cBPP < 8 ? 16 : (unsigned char)this->hidden->gxProperties.cBPP; 561 vformat->BitsPerPixel =
544 562 this->hidden->gxProperties.cBPP <
545 // Get color mask 563 8 ? 16 : (unsigned char) this->hidden->gxProperties.cBPP;
546 if (this->hidden->gxProperties.ffFormat & kfDirect565) { 564
547 vformat->BitsPerPixel = 16; 565 // Get color mask
548 vformat->Rmask = 0x0000f800; 566 if (this->hidden->gxProperties.ffFormat & kfDirect565) {
549 vformat->Gmask = 0x000007e0; 567 vformat->BitsPerPixel = 16;
550 vformat->Bmask = 0x0000001f; 568 vformat->Rmask = 0x0000f800;
551 this->hidden->videoMode = GAPI_DIRECT_565; 569 vformat->Gmask = 0x000007e0;
552 } 570 vformat->Bmask = 0x0000001f;
553 else 571 this->hidden->videoMode = GAPI_DIRECT_565;
554 if (this->hidden->gxProperties.ffFormat & kfDirect555) { 572 } else if (this->hidden->gxProperties.ffFormat & kfDirect555) {
555 vformat->BitsPerPixel = 16; 573 vformat->BitsPerPixel = 16;
556 vformat->Rmask = 0x00007c00; 574 vformat->Rmask = 0x00007c00;
557 vformat->Gmask = 0x000003e0; 575 vformat->Gmask = 0x000003e0;
558 vformat->Bmask = 0x0000001f; 576 vformat->Bmask = 0x0000001f;
559 this->hidden->videoMode = GAPI_DIRECT_555; 577 this->hidden->videoMode = GAPI_DIRECT_555;
560 } 578 } else if ((this->hidden->gxProperties.ffFormat & kfDirect)
561 else 579 && (this->hidden->gxProperties.cBPP < 8)) {
562 if ((this->hidden->gxProperties.ffFormat & kfDirect) && (this->hidden->gxProperties.cBPP < 8)) { 580 // We'll perform the conversion
563 // We'll perform the conversion 581 vformat->BitsPerPixel = 16;
564 vformat->BitsPerPixel = 16; 582 vformat->Rmask = 0x0000f800; // 16 bit 565
565 vformat->Rmask = 0x0000f800; // 16 bit 565 583 vformat->Gmask = 0x000007e0;
566 vformat->Gmask = 0x000007e0; 584 vformat->Bmask = 0x0000001f;
567 vformat->Bmask = 0x0000001f; 585 if (this->hidden->gxProperties.ffFormat & kfDirectInverted)
568 if (this->hidden->gxProperties.ffFormat & kfDirectInverted) 586 this->hidden->invert = (1 << this->hidden->gxProperties.cBPP) - 1;
569 this->hidden->invert = (1 << this->hidden->gxProperties.cBPP) - 1; 587 this->hidden->colorscale =
570 this->hidden->colorscale = this->hidden->gxProperties.cBPP < 8 ? 8 - this->hidden->gxProperties.cBPP : 0; 588 this->hidden->gxProperties.cBPP <
571 this->hidden->videoMode = GAPI_MONO; 589 8 ? 8 - this->hidden->gxProperties.cBPP : 0;
572 } 590 this->hidden->videoMode = GAPI_MONO;
573 else 591 } else if (this->hidden->gxProperties.ffFormat & kfPalette) {
574 if (this->hidden->gxProperties.ffFormat & kfPalette) { 592 this->hidden->videoMode = GAPI_PALETTE;
575 this->hidden->videoMode = GAPI_PALETTE; 593 }
576 } 594
577 595 /* We're done! */
578 /* We're done! */ 596 return (0);
579 return(0); 597 }
580 } 598
581 599 SDL_Rect **
582 SDL_Rect **GAPI_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) 600 GAPI_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
583 { 601 {
584 return(this->hidden->SDL_modelist[((format->BitsPerPixel+7)/8)-1]); 602 return (this->hidden->SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1]);
585 // return (SDL_Rect **) -1; 603 // return (SDL_Rect **) -1;
586 } 604 }
587 605
588 SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current, 606 SDL_Surface *
589 int width, int height, int bpp, Uint32 flags) 607 GAPI_SetVideoMode(_THIS, SDL_Surface * current,
590 { 608 int width, int height, int bpp, Uint32 flags)
591 SDL_Surface *video; 609 {
592 Uint32 Rmask, Gmask, Bmask; 610 SDL_Surface *video;
593 DWORD style; 611 Uint32 Rmask, Gmask, Bmask;
594 SDL_Rect allScreen; 612 DWORD style;
595 613 SDL_Rect allScreen;
596 if( bpp < 4 ) 614
597 { 615 if (bpp < 4) {
598 SDL_SetError("1 bpp and 2 bpp modes is not implemented yet!"); 616 SDL_SetError("1 bpp and 2 bpp modes is not implemented yet!");
599 return 0; 617 return 0;
600 } 618 }
601 619
602 /* Recalculate bitmasks if necessary */ 620 /* Recalculate bitmasks if necessary */
603 if (bpp == current->format->BitsPerPixel) { 621 if (bpp == current->format->BitsPerPixel) {
604 video = current; 622 video = current;
605 } 623 } else {
606 else { 624 switch (bpp) {
607 switch(bpp) { 625 case 8:
608 case 8: 626 Rmask = 0;
609 Rmask = 0; 627 Gmask = 0;
610 Gmask = 0; 628 Bmask = 0;
611 Bmask = 0; 629 break;
612 break; 630 case 15:
613 case 15: 631 case 16:
614 case 16: 632 /* Default is 565 unless the display is specifically 555 */
615 /* Default is 565 unless the display is specifically 555 */ 633 if (this->hidden->gxProperties.ffFormat & kfDirect555) {
616 if (this->hidden->gxProperties.ffFormat & kfDirect555) { 634 Rmask = 0x00007c00;
617 Rmask = 0x00007c00; 635 Gmask = 0x000003e0;
618 Gmask = 0x000003e0; 636 Bmask = 0x0000001f;
619 Bmask = 0x0000001f; 637 } else {
620 } 638 Rmask = 0x0000f800;
621 else { 639 Gmask = 0x000007e0;
622 Rmask = 0x0000f800; 640 Bmask = 0x0000001f;
623 Gmask = 0x000007e0; 641 }
624 Bmask = 0x0000001f; 642 break;
625 } 643 case 24:
626 break; 644 case 32:
627 case 24: 645 Rmask = 0x00ff0000;
628 case 32: 646 Gmask = 0x0000ff00;
629 Rmask = 0x00ff0000; 647 Bmask = 0x000000ff;
630 Gmask = 0x0000ff00; 648 break;
631 Bmask = 0x000000ff; 649 default:
632 break; 650 SDL_SetError("Unsupported Bits Per Pixel format requested");
633 default: 651 return NULL;
634 SDL_SetError("Unsupported Bits Per Pixel format requested"); 652 }
635 return NULL; 653 video = SDL_CreateRGBSurface(SDL_SWSURFACE,
636 } 654 0, 0, bpp, Rmask, Gmask, Bmask, 0);
637 video = SDL_CreateRGBSurface(SDL_SWSURFACE, 655 if (video == NULL) {
638 0, 0, bpp, Rmask, Gmask, Bmask, 0); 656 SDL_OutOfMemory();
639 if ( video == NULL ) { 657 return (NULL);
640 SDL_OutOfMemory(); 658 }
641 return(NULL); 659 }
642 } 660
643 } 661 gapi->userOrientation = SDL_ORIENTATION_UP;
644 662 video->flags = SDL_FULLSCREEN; /* Clear flags, GAPI supports fullscreen only */
645 gapi->userOrientation = SDL_ORIENTATION_UP; 663
646 video->flags = SDL_FULLSCREEN; /* Clear flags, GAPI supports fullscreen only */ 664 /* GAPI or VGA? */
647 665 if (g_hGapiLib) {
648 /* GAPI or VGA? */ 666 FillStructs(this, 0);
649 if( g_hGapiLib ) 667 if ((((unsigned) width != gapi->gxProperties.cxWidth)
650 { 668 || ((unsigned) height != gapi->gxProperties.cyHeight))
651 FillStructs(this, 0); 669 && (((unsigned) width != gapi->gxProperties.cyHeight)
652 if( (((unsigned)width != gapi->gxProperties.cxWidth) || ((unsigned)height != gapi->gxProperties.cyHeight)) 670 || ((unsigned) height != gapi->gxProperties.cxWidth)))
653 && (((unsigned)width != gapi->gxProperties.cyHeight) || ((unsigned)height != gapi->gxProperties.cxWidth))) 671 FillStructs(this, 1); // gapi is found but we use VGA resolution
654 FillStructs(this, 1); // gapi is found but we use VGA resolution 672 } else
655 } else 673 FillStructs(this, 1);
656 FillStructs(this, 1); 674
657 675 if (!this->hidden->needUpdate && !this->hidden->videoMem) {
658 if ( !this->hidden->needUpdate && !this->hidden->videoMem) { 676 SDL_SetError
659 SDL_SetError("Couldn't get address of video memory, may be unsupported device or bug"); 677 ("Couldn't get address of video memory, may be unsupported device or bug");
660 return(NULL); 678 return (NULL);
661 } 679 }
662 680
663 /* detect user landscape mode */ 681 /* detect user landscape mode */
664 if( (width > height) && (GetSystemMetrics(SM_CXSCREEN) < GetSystemMetrics(SM_CYSCREEN))) 682 if ((width > height)
665 gapi->userOrientation = SDL_ORIENTATION_RIGHT; 683 && (GetSystemMetrics(SM_CXSCREEN) < GetSystemMetrics(SM_CYSCREEN)))
666 684 gapi->userOrientation = SDL_ORIENTATION_RIGHT;
667 /* shall we apply hires fix? for example when we do not use hires resource */ 685
668 gapi->hiresFix = 0; 686 /* shall we apply hires fix? for example when we do not use hires resource */
669 if( gapi->userOrientation == SDL_ORIENTATION_RIGHT ) 687 gapi->hiresFix = 0;
670 { 688 if (gapi->userOrientation == SDL_ORIENTATION_RIGHT) {
671 if( (width > GetSystemMetrics(SM_CYSCREEN)) || (height > GetSystemMetrics(SM_CXSCREEN))) 689 if ((width > GetSystemMetrics(SM_CYSCREEN))
672 gapi->hiresFix = 1; 690 || (height > GetSystemMetrics(SM_CXSCREEN)))
673 } else 691 gapi->hiresFix = 1;
674 if( (width > GetSystemMetrics(SM_CXSCREEN)) || (height > GetSystemMetrics(SM_CYSCREEN))) 692 } else if ((width > GetSystemMetrics(SM_CXSCREEN))
675 if( !((width == GetSystemMetrics(SM_CYSCREEN)) && (height == GetSystemMetrics(SM_CXSCREEN)))) // user portrait, device landscape 693 || (height > GetSystemMetrics(SM_CYSCREEN)))
676 gapi->hiresFix = 1; 694 if (!((width == GetSystemMetrics(SM_CYSCREEN)) && (height == GetSystemMetrics(SM_CXSCREEN)))) // user portrait, device landscape
677 695 gapi->hiresFix = 1;
678 switch( gapi->userOrientation ) 696
679 { 697 switch (gapi->userOrientation) {
680 case SDL_ORIENTATION_UP: 698 case SDL_ORIENTATION_UP:
681 gapi->startOffset = 0; 699 gapi->startOffset = 0;
682 gapi->dstLineStep = gapi->gxProperties.cbyPitch; 700 gapi->dstLineStep = gapi->gxProperties.cbyPitch;
683 gapi->dstPixelStep = gapi->gxProperties.cbxPitch; 701 gapi->dstPixelStep = gapi->gxProperties.cbxPitch;
684 break; 702 break;
685 case SDL_ORIENTATION_RIGHT: 703 case SDL_ORIENTATION_RIGHT:
686 switch( gapi->gapiOrientation ) 704 switch (gapi->gapiOrientation) {
687 { 705 case SDL_ORIENTATION_UP:
688 case SDL_ORIENTATION_UP: 706 case SDL_ORIENTATION_RIGHT:
689 case SDL_ORIENTATION_RIGHT: 707 case SDL_ORIENTATION_LEFT:
690 case SDL_ORIENTATION_LEFT: 708 if ((this->hidden->videoMode == GAPI_MONO))
691 if( (this->hidden->videoMode == GAPI_MONO) ) 709 gapi->startOffset = -gapi->gxProperties.cbxPitch + 1; // monochrome mode
692 gapi->startOffset = -gapi->gxProperties.cbxPitch + 1; // monochrome mode 710 else
693 else 711 gapi->startOffset =
694 gapi->startOffset = gapi->gxProperties.cbyPitch * (gapi->gxProperties.cyHeight - 1); 712 gapi->gxProperties.cbyPitch *
695 713 (gapi->gxProperties.cyHeight - 1);
696 gapi->dstLineStep = gapi->gxProperties.cbxPitch; 714
697 gapi->dstPixelStep = -gapi->gxProperties.cbyPitch; 715 gapi->dstLineStep = gapi->gxProperties.cbxPitch;
698 break; 716 gapi->dstPixelStep = -gapi->gxProperties.cbyPitch;
699 } 717 break;
700 } 718 }
701 719 }
702 video->w = this->hidden->w = width; 720
703 video->h = this->hidden->h = height; 721 video->w = this->hidden->w = width;
704 video->pitch = SDL_CalculatePitch(video); 722 video->h = this->hidden->h = height;
705 723 video->pitch = SDL_CalculatePitch(video);
706 /* Small fix for WinCE/Win32 - when activating window 724
707 SDL_VideoSurface is equal to zero, so activating code 725 /* Small fix for WinCE/Win32 - when activating window
708 is not called properly for fullscreen windows because 726 SDL_VideoSurface is equal to zero, so activating code
709 macros WINDIB_FULLSCREEN uses SDL_VideoSurface 727 is not called properly for fullscreen windows because
710 */ 728 macros WINDIB_FULLSCREEN uses SDL_VideoSurface
711 SDL_VideoSurface = video; 729 */
712 730 SDL_VideoSurface = video;
713 /* GAPI is always fullscreen, title bar is useless */ 731
714 style = 0; 732 /* GAPI is always fullscreen, title bar is useless */
715 733 style = 0;
716 if (!SDL_windowid) 734
717 SetWindowLong(SDL_Window, GWL_STYLE, style); 735 if (!SDL_windowid)
718 736 SetWindowLong(SDL_Window, GWL_STYLE, style);
719 /* Allocate bitmap */ 737
720 if(gapiBuffer) 738 /* Allocate bitmap */
721 { 739 if (gapiBuffer) {
722 SDL_free(gapiBuffer); 740 SDL_free(gapiBuffer);
723 gapiBuffer = NULL; 741 gapiBuffer = NULL;
724 } 742 }
725 gapiBuffer = SDL_malloc(video->h * video->pitch); 743 gapiBuffer = SDL_malloc(video->h * video->pitch);
726 video->pixels = gapiBuffer; 744 video->pixels = gapiBuffer;
727 745
728 if ( ! this->hidden->buffer ) { 746 if (!this->hidden->buffer) {
729 SDL_SetError("Couldn't allocate buffer for requested mode"); 747 SDL_SetError("Couldn't allocate buffer for requested mode");
730 return(NULL); 748 return (NULL);
731 } 749 }
732 750
733 SDL_memset(gapiBuffer, 255, video->h * video->pitch); 751 SDL_memset(gapiBuffer, 255, video->h * video->pitch);
734 MoveWindow(SDL_Window, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), FALSE); 752 MoveWindow(SDL_Window, 0, 0, GetSystemMetrics(SM_CXSCREEN),
735 ShowWindow(SDL_Window, SW_SHOW); 753 GetSystemMetrics(SM_CYSCREEN), FALSE);
736 SetForegroundWindow(SDL_Window); 754 ShowWindow(SDL_Window, SW_SHOW);
737 755 SetForegroundWindow(SDL_Window);
738 /* JC 14 Mar 2006 756
739 Flush the message loop or this can cause big problems later 757 /* JC 14 Mar 2006
740 Especially if the user decides to use dialog boxes or assert()! 758 Flush the message loop or this can cause big problems later
741 */ 759 Especially if the user decides to use dialog boxes or assert()!
742 WIN_FlushMessageQueue(); 760 */
743 761 WIN_FlushMessageQueue();
744 /* Open GAPI display */ 762
745 if( !gapi->useVga && this->hidden->useGXOpenDisplay ) 763 /* Open GAPI display */
746 if( !gapi->gxFunc.GXOpenDisplay(SDL_Window, GX_FULLSCREEN) ) 764 if (!gapi->useVga && this->hidden->useGXOpenDisplay)
747 { 765 if (!gapi->gxFunc.GXOpenDisplay(SDL_Window, GX_FULLSCREEN)) {
748 SDL_SetError("Couldn't initialize GAPI"); 766 SDL_SetError("Couldn't initialize GAPI");
749 return(NULL); 767 return (NULL);
750 } 768 }
751
752 #if REPORT_VIDEO_INFO 769 #if REPORT_VIDEO_INFO
753 printf("Video properties:\n"); 770 printf("Video properties:\n");
754 printf("display bpp: %d\n", gapi->gxProperties.cBPP); 771 printf("display bpp: %d\n", gapi->gxProperties.cBPP);
755 printf("display width: %d\n", gapi->gxProperties.cxWidth); 772 printf("display width: %d\n", gapi->gxProperties.cxWidth);
756 printf("display height: %d\n", gapi->gxProperties.cyHeight); 773 printf("display height: %d\n", gapi->gxProperties.cyHeight);
757 printf("x pitch: %d\n", gapi->gxProperties.cbxPitch); 774 printf("x pitch: %d\n", gapi->gxProperties.cbxPitch);
758 printf("y pitch: %d\n", gapi->gxProperties.cbyPitch); 775 printf("y pitch: %d\n", gapi->gxProperties.cbyPitch);
759 printf("gapi flags: 0x%x\n", gapi->gxProperties.ffFormat); 776 printf("gapi flags: 0x%x\n", gapi->gxProperties.ffFormat);
760 777
761 if( !gapi->useVga && this->hidden->useGXOpenDisplay && gapi->needUpdate) 778 if (!gapi->useVga && this->hidden->useGXOpenDisplay && gapi->needUpdate) {
762 { 779 gapi->videoMem = gapi->gxFunc.GXBeginDraw();
763 gapi->videoMem = gapi->gxFunc.GXBeginDraw(); 780 gapi->gxFunc.GXEndDraw();
764 gapi->gxFunc.GXEndDraw(); 781 }
765 } 782
766 783 printf("video memory: 0x%x\n", gapi->videoMem);
767 printf("video memory: 0x%x\n", gapi->videoMem); 784 printf("need update: %d\n", gapi->needUpdate);
768 printf("need update: %d\n", gapi->needUpdate); 785 printf("hi-res fix: %d\n", gapi->hiresFix);
769 printf("hi-res fix: %d\n", gapi->hiresFix); 786 printf("VGA is available on the device: %d\n", g_bRawBufferAvailable);
770 printf("VGA is available on the device: %d\n", g_bRawBufferAvailable); 787 printf("use raw framebuffer: %d\n", gapi->useVga);
771 printf("use raw framebuffer: %d\n", gapi->useVga); 788 printf("video surface bpp: %d\n", video->format->BitsPerPixel);
772 printf("video surface bpp: %d\n", video->format->BitsPerPixel); 789 printf("video surface width: %d\n", video->w);
773 printf("video surface width: %d\n", video->w); 790 printf("video surface height: %d\n", video->h);
774 printf("video surface height: %d\n", video->h);
775 #endif 791 #endif
776 792
777 793
778 /* Blank screen */ 794 /* Blank screen */
779 allScreen.x = allScreen.y = 0; 795 allScreen.x = allScreen.y = 0;
780 allScreen.w = video->w - 1; 796 allScreen.w = video->w - 1;
781 allScreen.h = video->h - 1; 797 allScreen.h = video->h - 1;
782 GAPI_UpdateRects(this, 1, &allScreen); 798 GAPI_UpdateRects(this, 1, &allScreen);
783 799
784 /* We're done */ 800 /* We're done */
785 return(video); 801 return (video);
786 } 802 }
787 803
788 /* We don't actually allow hardware surfaces other than the main one */ 804 /* We don't actually allow hardware surfaces other than the main one */
789 static int GAPI_AllocHWSurface(_THIS, SDL_Surface *surface) 805 static int
790 { 806 GAPI_AllocHWSurface(_THIS, SDL_Surface * surface)
791 return(-1); 807 {
792 } 808 return (-1);
793 static void GAPI_FreeHWSurface(_THIS, SDL_Surface *surface) 809 }
794 { 810 static void
795 return; 811 GAPI_FreeHWSurface(_THIS, SDL_Surface * surface)
812 {
813 return;
796 } 814 }
797 815
798 /* We need to wait for vertical retrace on page flipped displays */ 816 /* We need to wait for vertical retrace on page flipped displays */
799 static int GAPI_LockHWSurface(_THIS, SDL_Surface *surface) 817 static int
800 { 818 GAPI_LockHWSurface(_THIS, SDL_Surface * surface)
801 return(0); 819 {
802 } 820 return (0);
803 821 }
804 static void GAPI_UnlockHWSurface(_THIS, SDL_Surface *surface) 822
805 { 823 static void
806 return; 824 GAPI_UnlockHWSurface(_THIS, SDL_Surface * surface)
807 } 825 {
808 826 return;
809 static int updateLine8to8(_THIS, unsigned char *srcPointer, unsigned char *destPointer, int width, int height, int lines) 827 }
810 { 828
811 if( gapi->dstPixelStep == 1) /* optimized blitting on most devices */ 829 static int
812 { 830 updateLine8to8(_THIS, unsigned char *srcPointer, unsigned char *destPointer,
813 SDL_memcpy(destPointer, srcPointer, width); 831 int width, int height, int lines)
814 return 1; 832 {
815 } else 833 if (gapi->dstPixelStep == 1) { /* optimized blitting on most devices */
816 { 834 SDL_memcpy(destPointer, srcPointer, width);
817 // TODO: read 4 pixels, write DWORD 835 return 1;
818 int step = gapi->dstPixelStep; 836 } else {
819 while(width--) 837 // TODO: read 4 pixels, write DWORD
820 { 838 int step = gapi->dstPixelStep;
821 *destPointer = *srcPointer++; 839 while (width--) {
822 destPointer += step; 840 *destPointer = *srcPointer++;
823 } 841 destPointer += step;
824 } 842 }
825 return 1; 843 }
844 return 1;
826 } 845 }
827 846
828 /* Video memory is very slow so lets optimize as much as possible */ 847 /* Video memory is very slow so lets optimize as much as possible */
829 static int updateLine16to16(_THIS, PIXEL *srcPointer, PIXEL *destPointer, int width, int height, int lines) 848 static int
830 { 849 updateLine16to16(_THIS, PIXEL * srcPointer, PIXEL * destPointer, int width,
831 PIXEL *line1, *line2; 850 int height, int lines)
832 int step = gapi->dstPixelStep / 2; 851 {
833 852 PIXEL *line1, *line2;
834 if( step == 1 ) /* optimized blitting on most devices */ 853 int step = gapi->dstPixelStep / 2;
835 { 854
836 SDL_memcpy(destPointer, srcPointer, width * sizeof(PIXEL)); 855 if (step == 1) { /* optimized blitting on most devices */
837 return 1; 856 SDL_memcpy(destPointer, srcPointer, width * sizeof(PIXEL));
838 } 857 return 1;
839 else 858 } else {
840 { 859 if ((gapi->gapiOrientation != SDL_ORIENTATION_UP) && (gapi->userOrientation == SDL_ORIENTATION_UP)) // iPaq 3660/3800 and user orientation up
841 if( (gapi->gapiOrientation != SDL_ORIENTATION_UP) && 860 {
842 (gapi->userOrientation == SDL_ORIENTATION_UP )) // iPaq 3660/3800 and user orientation up 861 // to prevent data misalignment copy only one line
843 { 862 if (((((unsigned) destPointer & 3) != 0)
844 // to prevent data misalignment copy only one line 863 && (gapi->gapiOrientation == SDL_ORIENTATION_LEFT))
845 if( ((((unsigned)destPointer & 3) != 0) && (gapi->gapiOrientation == SDL_ORIENTATION_LEFT)) 864 || ((((unsigned) destPointer & 3) == 0)
846 || ((((unsigned)destPointer & 3) == 0) && (gapi->gapiOrientation != SDL_ORIENTATION_LEFT)) 865 && (gapi->gapiOrientation != SDL_ORIENTATION_LEFT))
847 || (lines == 1) ) 866 || (lines == 1)) {
848 { 867 while (width--) {
849 while(width--) 868 *destPointer = *srcPointer++;
850 { 869 destPointer += step;
851 *destPointer = *srcPointer++; 870 }
852 destPointer += step; 871 return 1;
853 } 872 }
854 return 1; 873
855 } 874 /* read two lines at the same time, write DWORD */
856 875 line1 = srcPointer;
857 /* read two lines at the same time, write DWORD */ 876 line2 = srcPointer + SDL_VideoSurface->pitch / 2;
858 line1 = srcPointer; 877
859 line2 = srcPointer + SDL_VideoSurface->pitch / 2; 878 if (gapi->gapiOrientation == SDL_ORIENTATION_LEFT)
860 879 while (width--) // iPaq 3800
861 if( gapi->gapiOrientation == SDL_ORIENTATION_LEFT ) 880 {
862 while(width--) // iPaq 3800 881 *(DWORD *) destPointer = (*line2++ << 16) | *line1++;
863 { 882 destPointer += step;
864 *(DWORD*)destPointer =(*line2++ << 16) | *line1++; 883 } else {
865 destPointer += step; 884 destPointer += gapi->gxProperties.cbyPitch / 2;
866 } 885
867 else 886 while (width--) // iPaq 3660
868 { 887 {
869 destPointer += gapi->gxProperties.cbyPitch / 2; 888 *(DWORD *) destPointer = (*line1++ << 16) | *line2++;
870 889 destPointer += step;
871 while(width--) // iPaq 3660 890 }
872 { 891 }
873 *(DWORD*)destPointer =(*line1++ << 16) | *line2++; 892 return 2;
874 destPointer += step; 893 } else {
875 } 894 // iPaq 3800 and user orientation landscape
876 } 895 if (gapi->gapiOrientation == SDL_ORIENTATION_LEFT) {
877 return 2; 896 int w1;
878 } else 897
879 { 898 // to prevent data misalignment copy only one pixel
880 // iPaq 3800 and user orientation landscape 899 if ((((unsigned) destPointer & 3) == 0) && (width > 0)) {
881 if( gapi->gapiOrientation == SDL_ORIENTATION_LEFT ) 900 *destPointer-- = *srcPointer++;
882 { 901 width--;
883 int w1; 902 }
884 903
885 // to prevent data misalignment copy only one pixel 904 destPointer--;
886 if( (((unsigned)destPointer & 3) == 0) && (width > 0)) 905
887 { 906 w1 = width / 2;
888 *destPointer-- = *srcPointer++; 907
889 width--; 908 while (w1--) {
890 } 909 DWORD p = *(DWORD *) srcPointer;
891 910 *((DWORD *) destPointer) = (p << 16) | (p >> 16);
892 destPointer--; 911 destPointer -= 2;
893 912 srcPointer += 2;
894 w1 = width / 2; 913 }
895 914
896 while(w1--) 915 if (width & 1) // copy the last pixel
897 { 916 {
898 DWORD p = *(DWORD*)srcPointer; 917 destPointer++;
899 *((DWORD*)destPointer) = (p << 16) | (p >> 16); 918 *destPointer = *srcPointer;
900 destPointer -= 2; 919 }
901 srcPointer += 2; 920
902 } 921 return 1;
903 922 }
904 if( width & 1 ) // copy the last pixel 923 // modern iPaqs and user orientation landscape
905 { 924 // read two pixels, write DWORD
906 destPointer++; 925
907 *destPointer = *srcPointer; 926 line1 = srcPointer;
908 } 927 line2 = srcPointer + SDL_VideoSurface->pitch / 2;
909 928
910 return 1; 929 if ((((unsigned) destPointer & 3) != 0) || (lines == 1)) {
911 } 930 while (width--) {
912 931 *destPointer = *srcPointer++;
913 // modern iPaqs and user orientation landscape 932 destPointer += step;
914 // read two pixels, write DWORD 933 }
915 934 return 1;
916 line1 = srcPointer; 935 }
917 line2 = srcPointer + SDL_VideoSurface->pitch / 2; 936
918 937 while (width--) {
919 if( (((unsigned)destPointer & 3) != 0) || (lines == 1) ) 938 *(DWORD *) destPointer = (*line2++ << 16) | *line1++;
920 { 939 destPointer -= gapi->gxProperties.cbyPitch / 2;
921 while(width--) 940 }
922 { 941 return 2;
923 *destPointer = *srcPointer++; 942 }
924 destPointer += step; 943 }
925 }
926 return 1;
927 }
928
929 while(width--)
930 {
931 *(DWORD*)destPointer =(*line2++ << 16) | *line1++;
932 destPointer -= gapi->gxProperties.cbyPitch / 2;
933 }
934 return 2;
935 }
936 }
937 } 944 }
938 945
939 // Color component masks for 565 946 // Color component masks for 565
940 #define REDMASK (31<<11) 947 #define REDMASK (31<<11)
941 #define GREENMASK (63<<5) 948 #define GREENMASK (63<<5)
942 #define BLUEMASK (31) 949 #define BLUEMASK (31)
943 950
944 951
945 static int updateLine16to4(_THIS, PIXEL *srcPointer, unsigned char *destPointer, int width, int height, int lines, int yNibble, int xNibble) 952 static int
946 { 953 updateLine16to4(_THIS, PIXEL * srcPointer, unsigned char *destPointer,
947 PIXEL *line1, *line2; 954 int width, int height, int lines, int yNibble, int xNibble)
948 int step = gapi->dstPixelStep; 955 {
949 956 PIXEL *line1, *line2;
950 if( gapi->userOrientation == SDL_ORIENTATION_UP ) 957 int step = gapi->dstPixelStep;
951 { 958
952 if( yNibble ) // copy bottom half of a line 959 if (gapi->userOrientation == SDL_ORIENTATION_UP) {
953 { 960 if (yNibble) // copy bottom half of a line
954 while(width--) 961 {
955 { 962 while (width--) {
956 PIXEL c1 = *srcPointer++; 963 PIXEL c1 = *srcPointer++;
957 c1 = ((c1 & REDMASK) >> 11) + ((c1 & GREENMASK) >> 5) + (c1 & BLUEMASK); 964 c1 = ((c1 & REDMASK) >> 11) + ((c1 & GREENMASK) >> 5) +
958 *destPointer = (*destPointer & 0x0F) | ((~(c1 >> 3) << 4)); 965 (c1 & BLUEMASK);
959 destPointer += step; 966 *destPointer = (*destPointer & 0x0F) | ((~(c1 >> 3) << 4));
960 } 967 destPointer += step;
961 return 1; 968 }
962 } 969 return 1;
963 970 }
964 // either 1 pixel picture or tail, anyway this is the last line 971 // either 1 pixel picture or tail, anyway this is the last line
965 if( lines == 1 ) 972 if (lines == 1) {
966 { 973 while (width--) {
967 while(width--) 974 PIXEL c1 = *srcPointer++;
968 { 975 c1 = ((c1 & REDMASK) >> 11) + ((c1 & GREENMASK) >> 5) +
969 PIXEL c1 = *srcPointer++; 976 (c1 & BLUEMASK);
970 c1 = ((c1 & REDMASK) >> 11) + ((c1 & GREENMASK) >> 5) + (c1 & BLUEMASK); 977 *destPointer = (*destPointer & 0xF0) | ((~(c1 >> 3) & 0xF));
971 *destPointer = (*destPointer & 0xF0) | ((~(c1 >> 3) & 0xF)); 978 destPointer += step;
972 destPointer += step; 979 }
973 } 980 return 1;
974 return 1; 981 }
975 } 982
976 983 line1 = srcPointer;
977 line1 = srcPointer; 984 line2 = srcPointer + SDL_VideoSurface->pitch / 2;
978 line2 = srcPointer + SDL_VideoSurface->pitch / 2; 985
979 986 while (width--) {
980 while(width--) 987 PIXEL c1 = *line1++;
981 { 988 PIXEL c2 = *line2++;
982 PIXEL c1 = *line1++; 989 c1 = ((c1 & REDMASK) >> 11) + ((c1 & GREENMASK) >> 5) +
983 PIXEL c2 = *line2++; 990 (c1 & BLUEMASK);
984 c1 = ((c1 & REDMASK) >> 11) + ((c1 & GREENMASK) >> 5) + (c1 & BLUEMASK); 991 c2 = ((c2 & REDMASK) >> 11) + ((c2 & GREENMASK) >> 5) +
985 c2 = ((c2 & REDMASK) >> 11) + ((c2 & GREENMASK) >> 5) + (c2 & BLUEMASK); 992 (c2 & BLUEMASK);
986 *destPointer = ~((c1 >> 3) + ((c2 >> 3) << 4)); 993 *destPointer = ~((c1 >> 3) + ((c2 >> 3) << 4));
987 destPointer += step; 994 destPointer += step;
988 } 995 }
989 return 2; 996 return 2;
990 } else 997 } else {
991 { 998 int w1;
992 int w1; 999 w1 = width / 2;
993 w1 = width / 2; 1000
994 1001 if (xNibble) {
995 if( xNibble ) 1002 // copy one pixel
996 { 1003 PIXEL c1 = *srcPointer++;
997 // copy one pixel 1004 c1 = ((c1 & REDMASK) >> 11) + ((c1 & GREENMASK) >> 5) +
998 PIXEL c1 = *srcPointer++; 1005 (c1 & BLUEMASK);
999 c1 = ((c1 & REDMASK) >> 11) + ((c1 & GREENMASK) >> 5) + (c1 & BLUEMASK); 1006 *destPointer = (*destPointer & 0xF0) | ((~(c1 >> 3) & 0xF));
1000 *destPointer = (*destPointer & 0xF0) | ((~(c1 >> 3) & 0xF)); 1007 destPointer++;
1001 destPointer++; 1008 }
1002 } 1009
1003 1010 while (w1--) {
1004 while(w1--) 1011 PIXEL c1 = *srcPointer;
1005 { 1012 PIXEL c2 = *(srcPointer + 1);
1006 PIXEL c1 = *srcPointer; 1013 c1 = ((c1 & REDMASK) >> 11) + ((c1 & GREENMASK) >> 5) +
1007 PIXEL c2 = *(srcPointer + 1); 1014 (c1 & BLUEMASK);
1008 c1 = ((c1 & REDMASK) >> 11) + ((c1 & GREENMASK) >> 5) + (c1 & BLUEMASK); 1015 c2 = ((c2 & REDMASK) >> 11) + ((c2 & GREENMASK) >> 5) +
1009 c2 = ((c2 & REDMASK) >> 11) + ((c2 & GREENMASK) >> 5) + (c2 & BLUEMASK); 1016 (c2 & BLUEMASK);
1010 *destPointer++ = ~((c2 >> 3) + ((c1 >> 3) << 4)); 1017 *destPointer++ = ~((c2 >> 3) + ((c1 >> 3) << 4));
1011 srcPointer += 2; 1018 srcPointer += 2;
1012 } 1019 }
1013 1020
1014 // copy tail 1021 // copy tail
1015 if( (width & 1) && !xNibble ) 1022 if ((width & 1) && !xNibble) {
1016 { 1023 PIXEL c1 = *srcPointer;
1017 PIXEL c1 = *srcPointer; 1024 c1 = ((c1 & REDMASK) >> 11) + ((c1 & GREENMASK) >> 5) +
1018 c1 = ((c1 & REDMASK) >> 11) + ((c1 & GREENMASK) >> 5) + (c1 & BLUEMASK); 1025 (c1 & BLUEMASK);
1019 *destPointer = (*destPointer & 0x0F) | ((~(c1 >> 3) << 4)); 1026 *destPointer = (*destPointer & 0x0F) | ((~(c1 >> 3) << 4));
1020 } 1027 }
1021 1028
1022 return 1; 1029 return 1;
1023 } 1030 }
1024 } 1031 }
1025 1032
1026 static void GAPI_UpdateRectsMono(_THIS, int numrects, SDL_Rect *rects) 1033 static void
1027 { 1034 GAPI_UpdateRectsMono(_THIS, int numrects, SDL_Rect * rects)
1028 int i, height; 1035 {
1029 int linesProcessed; 1036 int i, height;
1030 int xNibble, yNibble; 1037 int linesProcessed;
1031 1038 int xNibble, yNibble;
1032 for (i=0; i<numrects; i++) 1039
1033 { 1040 for (i = 0; i < numrects; i++) {
1034 unsigned char *destPointer; 1041 unsigned char *destPointer;
1035 unsigned char *srcPointer; 1042 unsigned char *srcPointer;
1036 1043
1037 if( gapi->userOrientation == SDL_ORIENTATION_UP ) 1044 if (gapi->userOrientation == SDL_ORIENTATION_UP)
1038 destPointer = (unsigned char*) gapi->videoMem + gapi->startOffset - rects[i].y * gapi->gxProperties.cBPP / 8 + rects[i].x * gapi->dstPixelStep; 1045 destPointer =
1039 else 1046 (unsigned char *) gapi->videoMem + gapi->startOffset -
1040 destPointer = (unsigned char*) gapi->videoMem + gapi->startOffset + rects[i].x * gapi->gxProperties.cBPP / 8 + rects[i].y * gapi->dstLineStep; 1047 rects[i].y * gapi->gxProperties.cBPP / 8 +
1041 1048 rects[i].x * gapi->dstPixelStep;
1042 srcPointer = ((unsigned char*) SDL_VideoSurface->pixels) + rects[i].y * SDL_VideoSurface->pitch + rects[i].x * 2; 1049 else
1043 yNibble = rects[i].y & 1; // TODO: only for 4 bpp 1050 destPointer =
1044 xNibble = rects[i].x & 1; 1051 (unsigned char *) gapi->videoMem + gapi->startOffset +
1045 height = rects[i].h; 1052 rects[i].x * gapi->gxProperties.cBPP / 8 +
1046 while (height > 0) 1053 rects[i].y * gapi->dstLineStep;
1047 { 1054
1048 switch(gapi->gxProperties.cBPP) 1055 srcPointer =
1049 { 1056 ((unsigned char *) SDL_VideoSurface->pixels) +
1050 case 2: // TODO 1057 rects[i].y * SDL_VideoSurface->pitch + rects[i].x * 2;
1051 case 4: 1058 yNibble = rects[i].y & 1; // TODO: only for 4 bpp
1052 linesProcessed = updateLine16to4(this, (PIXEL*) srcPointer, destPointer, rects[i].w, rects[i].h, height, yNibble, xNibble); 1059 xNibble = rects[i].x & 1;
1053 yNibble = 0; 1060 height = rects[i].h;
1054 } 1061 while (height > 0) {
1055 height -= linesProcessed; 1062 switch (gapi->gxProperties.cBPP) {
1056 if( gapi->userOrientation == SDL_ORIENTATION_UP ) 1063 case 2: // TODO
1057 destPointer--; // always fill 1 byte 1064 case 4:
1058 else destPointer += gapi->dstLineStep; 1065 linesProcessed =
1059 srcPointer += SDL_VideoSurface->pitch * linesProcessed; // pitch in bytes 1066 updateLine16to4(this, (PIXEL *) srcPointer,
1060 } 1067 destPointer, rects[i].w,
1061 } 1068 rects[i].h, height, yNibble, xNibble);
1062 } 1069 yNibble = 0;
1063 1070 }
1064 static void GAPI_UpdateRectsColor(_THIS, int numrects, SDL_Rect *rects) 1071 height -= linesProcessed;
1065 { 1072 if (gapi->userOrientation == SDL_ORIENTATION_UP)
1066 int i, height; 1073 destPointer--; // always fill 1 byte
1067 int bytesPerPixel = (gapi->gxProperties.cBPP + 1) / 8; 1074 else
1068 int linesProcessed; 1075 destPointer += gapi->dstLineStep;
1069 for (i=0; i<numrects; i++) { 1076 srcPointer += SDL_VideoSurface->pitch * linesProcessed; // pitch in bytes
1070 unsigned char *destPointer = (unsigned char*) gapi->videoMem + gapi->startOffset + rects[i].y * gapi->dstLineStep + rects[i].x * gapi->dstPixelStep; 1077 }
1071 unsigned char *srcPointer = ((unsigned char*) SDL_VideoSurface->pixels) + rects[i].y * SDL_VideoSurface->pitch + rects[i].x * bytesPerPixel; 1078 }
1072 height = rects[i].h; 1079 }
1073 1080
1074 // fprintf(stderr, "Starting rect %dx%d, dst=0x%x, w = %d, h = %d\n", rects[i].w, rects[i].h,destPointer,rects[i].w,rects[i].h); 1081 static void
1075 // fflush(stderr); 1082 GAPI_UpdateRectsColor(_THIS, int numrects, SDL_Rect * rects)
1076 linesProcessed = height; 1083 {
1077 1084 int i, height;
1078 while (height > 0) { 1085 int bytesPerPixel = (gapi->gxProperties.cBPP + 1) / 8;
1079 switch(bytesPerPixel) 1086 int linesProcessed;
1080 { 1087 for (i = 0; i < numrects; i++) {
1081 case 1: 1088 unsigned char *destPointer =
1082 linesProcessed = updateLine8to8(this, srcPointer, (unsigned char *) destPointer, rects[i].w, rects[i].h, height); 1089 (unsigned char *) gapi->videoMem + gapi->startOffset +
1083 break; 1090 rects[i].y * gapi->dstLineStep + rects[i].x * gapi->dstPixelStep;
1084 case 2: 1091 unsigned char *srcPointer =
1092 ((unsigned char *) SDL_VideoSurface->pixels) +
1093 rects[i].y * SDL_VideoSurface->pitch + rects[i].x * bytesPerPixel;
1094 height = rects[i].h;
1095
1096 // fprintf(stderr, "Starting rect %dx%d, dst=0x%x, w = %d, h = %d\n", rects[i].w, rects[i].h,destPointer,rects[i].w,rects[i].h);
1097 // fflush(stderr);
1098 linesProcessed = height;
1099
1100 while (height > 0) {
1101 switch (bytesPerPixel) {
1102 case 1:
1103 linesProcessed =
1104 updateLine8to8(this, srcPointer,
1105 (unsigned char *) destPointer,
1106 rects[i].w, rects[i].h, height);
1107 break;
1108 case 2:
1085 #pragma warning(disable: 4133) 1109 #pragma warning(disable: 4133)
1086 linesProcessed = updateLine16to16(this, (PIXEL*) srcPointer, destPointer, rects[i].w, rects[i].h, height); 1110 linesProcessed =
1087 break; 1111 updateLine16to16(this, (PIXEL *) srcPointer,
1088 } 1112 destPointer, rects[i].w,
1089 height -= linesProcessed; 1113 rects[i].h, height);
1090 destPointer += gapi->dstLineStep * linesProcessed; 1114 break;
1091 srcPointer += SDL_VideoSurface->pitch * linesProcessed; // pitch in bytes 1115 }
1092 } 1116 height -= linesProcessed;
1093 // fprintf(stderr, "End of rect\n"); 1117 destPointer += gapi->dstLineStep * linesProcessed;
1094 // fflush(stderr); 1118 srcPointer += SDL_VideoSurface->pitch * linesProcessed; // pitch in bytes
1095 } 1119 }
1096 } 1120 // fprintf(stderr, "End of rect\n");
1097 1121 // fflush(stderr);
1098 1122 }
1099 static void GAPI_UpdateRects(_THIS, int numrects, SDL_Rect *rects) 1123 }
1100 { 1124
1101 // we do not want to corrupt video memory 1125
1102 if( gapi->suspended ) return; 1126 static void
1103 1127 GAPI_UpdateRects(_THIS, int numrects, SDL_Rect * rects)
1104 if( gapi->needUpdate ) 1128 {
1105 gapi->videoMem = gapi->gxFunc.GXBeginDraw(); 1129 // we do not want to corrupt video memory
1106 1130 if (gapi->suspended)
1107 if( gapi->gxProperties.cBPP < 8 ) 1131 return;
1108 GAPI_UpdateRectsMono(this, numrects, rects); 1132
1109 else 1133 if (gapi->needUpdate)
1110 GAPI_UpdateRectsColor(this, numrects, rects); 1134 gapi->videoMem = gapi->gxFunc.GXBeginDraw();
1111 1135
1112 if( gapi->needUpdate ) 1136 if (gapi->gxProperties.cBPP < 8)
1113 gapi->gxFunc.GXEndDraw(); 1137 GAPI_UpdateRectsMono(this, numrects, rects);
1138 else
1139 GAPI_UpdateRectsColor(this, numrects, rects);
1140
1141 if (gapi->needUpdate)
1142 gapi->gxFunc.GXEndDraw();
1114 } 1143 }
1115 1144
1116 /* Note: If we are terminated, this could be called in the middle of 1145 /* Note: If we are terminated, this could be called in the middle of
1117 another SDL video routine -- notably UpdateRects. 1146 another SDL video routine -- notably UpdateRects.
1118 */ 1147 */
1119 void GAPI_VideoQuit(_THIS) 1148 void
1120 { 1149 GAPI_VideoQuit(_THIS)
1121 int i, j; 1150 {
1122 /* Destroy the window and everything associated with it */ 1151 int i, j;
1123 if ( SDL_Window ) 1152 /* Destroy the window and everything associated with it */
1124 { 1153 if (SDL_Window) {
1125 if ((g_hGapiLib != 0) && this && this->hidden && this->hidden->gxFunc.GXCloseDisplay && !this->hidden->useVga) 1154 if ((g_hGapiLib != 0) && this && this->hidden
1126 this->hidden->gxFunc.GXCloseDisplay(); 1155 && this->hidden->gxFunc.GXCloseDisplay && !this->hidden->useVga)
1127 1156 this->hidden->gxFunc.GXCloseDisplay();
1128 if (this->screen->pixels != NULL) 1157
1129 { 1158 if (this->screen->pixels != NULL) {
1130 SDL_free(this->screen->pixels); 1159 SDL_free(this->screen->pixels);
1131 this->screen->pixels = NULL; 1160 this->screen->pixels = NULL;
1132 } 1161 }
1133 if ( screen_icn ) { 1162 if (screen_icn) {
1134 DestroyIcon(screen_icn); 1163 DestroyIcon(screen_icn);
1135 screen_icn = NULL; 1164 screen_icn = NULL;
1136 } 1165 }
1137 1166
1138 DIB_DestroyWindow(this); 1167 DIB_DestroyWindow(this);
1139 SDL_UnregisterApp(); 1168 SDL_UnregisterApp();
1140 1169
1141 SDL_Window = NULL; 1170 SDL_Window = NULL;
1142 #if defined(_WIN32_WCE) 1171 #if defined(_WIN32_WCE)
1143 1172
1144 // Unload wince aygshell library to prevent leak 1173 // Unload wince aygshell library to prevent leak
1145 if( aygshell ) 1174 if (aygshell) {
1146 { 1175 FreeLibrary(aygshell);
1147 FreeLibrary(aygshell); 1176 aygshell = NULL;
1148 aygshell = NULL; 1177 }
1149 }
1150 #endif 1178 #endif
1151 1179
1152 /* Free video mode lists */ 1180 /* Free video mode lists */
1153 for ( i=0; i<NUM_MODELISTS; ++i ) { 1181 for (i = 0; i < NUM_MODELISTS; ++i) {
1154 if ( gapi->SDL_modelist[i] != NULL ) { 1182 if (gapi->SDL_modelist[i] != NULL) {
1155 for ( j=0; gapi->SDL_modelist[i][j]; ++j ) 1183 for (j = 0; gapi->SDL_modelist[i][j]; ++j)
1156 SDL_free(gapi->SDL_modelist[i][j]); 1184 SDL_free(gapi->SDL_modelist[i][j]);
1157 SDL_free(gapi->SDL_modelist[i]); 1185 SDL_free(gapi->SDL_modelist[i]);
1158 gapi->SDL_modelist[i] = NULL; 1186 gapi->SDL_modelist[i] = NULL;
1159 } 1187 }
1160 } 1188 }
1161 1189
1162 } 1190 }
1163 1191
1164 } 1192 }
1165 1193
1166 static void GAPI_RealizePalette(_THIS) 1194 static void
1167 { 1195 GAPI_RealizePalette(_THIS)
1168 OutputDebugString(TEXT("GAPI_RealizePalette NOT IMPLEMENTED !\r\n")); 1196 {
1169 } 1197 OutputDebugString(TEXT("GAPI_RealizePalette NOT IMPLEMENTED !\r\n"));
1170 1198 }
1171 static void GAPI_PaletteChanged(_THIS, HWND window) 1199
1172 { 1200 static void
1173 OutputDebugString(TEXT("GAPI_PaletteChanged NOT IMPLEMENTED !\r\n")); 1201 GAPI_PaletteChanged(_THIS, HWND window)
1174 } 1202 {
1175 1203 OutputDebugString(TEXT("GAPI_PaletteChanged NOT IMPLEMENTED !\r\n"));
1176 static void GAPI_WinPAINT(_THIS, HDC hdc) 1204 }
1177 { 1205
1178 // draw current offscreen buffer on hdc 1206 static void
1179 1207 GAPI_WinPAINT(_THIS, HDC hdc)
1180 int bpp = 16; // we always use either 8 or 16 bpp internally 1208 {
1181 1209 // draw current offscreen buffer on hdc
1182 unsigned short *bitmapData; 1210
1183 HBITMAP hb; 1211 int bpp = 16; // we always use either 8 or 16 bpp internally
1184 HDC srcDC; 1212
1213 unsigned short *bitmapData;
1214 HBITMAP hb;
1215 HDC srcDC;
1185 1216
1186 // Create a DIB 1217 // Create a DIB
1187 BYTE buffer[sizeof(BITMAPINFOHEADER) + 3 * sizeof(RGBQUAD)] = {0}; 1218 BYTE buffer[sizeof(BITMAPINFOHEADER) + 3 * sizeof(RGBQUAD)] = { 0 };
1188 BITMAPINFO* pBMI = (BITMAPINFO*)buffer; 1219 BITMAPINFO *pBMI = (BITMAPINFO *) buffer;
1189 BITMAPINFOHEADER* pHeader = &pBMI->bmiHeader; 1220 BITMAPINFOHEADER *pHeader = &pBMI->bmiHeader;
1190 DWORD* pColors = (DWORD*)&pBMI->bmiColors; 1221 DWORD *pColors = (DWORD *) & pBMI->bmiColors;
1191 1222
1192 // CreateDIBSection does not support 332 pixel format on wce 1223 // CreateDIBSection does not support 332 pixel format on wce
1193 if( gapi->gxProperties.cBPP == 8 ) return; 1224 if (gapi->gxProperties.cBPP == 8)
1225 return;
1194 1226
1195 // DIB Header 1227 // DIB Header
1196 pHeader->biSize = sizeof(BITMAPINFOHEADER); 1228 pHeader->biSize = sizeof(BITMAPINFOHEADER);
1197 pHeader->biWidth = this->hidden->w; 1229 pHeader->biWidth = this->hidden->w;
1198 pHeader->biHeight = -this->hidden->h; 1230 pHeader->biHeight = -this->hidden->h;
1199 pHeader->biPlanes = 1; 1231 pHeader->biPlanes = 1;
1200 pHeader->biBitCount = bpp; 1232 pHeader->biBitCount = bpp;
1201 pHeader->biCompression = BI_RGB; 1233 pHeader->biCompression = BI_RGB;
1202 pHeader->biSizeImage = (this->hidden->w * this->hidden->h * bpp) / 8; 1234 pHeader->biSizeImage = (this->hidden->w * this->hidden->h * bpp) / 8;
1203 1235
1204 // Color masks 1236 // Color masks
1205 if( bpp == 16 ) 1237 if (bpp == 16) {
1206 { 1238 pColors[0] = REDMASK;
1207 pColors[0] = REDMASK; 1239 pColors[1] = GREENMASK;
1208 pColors[1] = GREENMASK; 1240 pColors[2] = BLUEMASK;
1209 pColors[2] = BLUEMASK; 1241 pHeader->biCompression = BI_BITFIELDS;
1210 pHeader->biCompression = BI_BITFIELDS; 1242 }
1211 }
1212 // Create the DIB 1243 // Create the DIB
1213 hb = CreateDIBSection( 0, pBMI, DIB_RGB_COLORS, (void**)&bitmapData, 0, 0 ); 1244 hb = CreateDIBSection(0, pBMI, DIB_RGB_COLORS, (void **) &bitmapData, 0,
1214 1245 0);
1215 // copy data 1246
1216 // FIXME: prevent misalignment, but I've never seen non aligned width of screen 1247 // copy data
1217 memcpy(bitmapData, this->hidden->buffer, pHeader->biSizeImage); 1248 // FIXME: prevent misalignment, but I've never seen non aligned width of screen
1218 srcDC = CreateCompatibleDC(hdc); 1249 memcpy(bitmapData, this->hidden->buffer, pHeader->biSizeImage);
1219 SelectObject(srcDC, hb); 1250 srcDC = CreateCompatibleDC(hdc);
1220 1251 SelectObject(srcDC, hb);
1221 BitBlt(hdc, 0, 0, this->hidden->w, this->hidden->h, srcDC, 0, 0, SRCCOPY); 1252
1222 1253 BitBlt(hdc, 0, 0, this->hidden->w, this->hidden->h, srcDC, 0, 0, SRCCOPY);
1223 DeleteObject(hb); 1254
1224 DeleteDC(srcDC); 1255 DeleteObject(hb);
1225 } 1256 DeleteDC(srcDC);
1226 1257 }
1227 int GAPI_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) 1258
1228 { 1259 int
1229 GAPI_CreatePalette(ncolors, colors); 1260 GAPI_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
1230 return 1; 1261 {
1231 } 1262 GAPI_CreatePalette(ncolors, colors);
1263 return 1;
1264 }
1265
1266 /* vi: set ts=4 sw=4 expandtab: */