comparison src/video/gapi/SDL_gapivideo.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
71 #pragma message("Warning: Using GapiEmu in release build. I assume you'd like to set USE_GAPI_EMU to zero.") 71 #pragma message("Warning: Using GapiEmu in release build. I assume you'd like to set USE_GAPI_EMU to zero.")
72 #endif 72 #endif
73 73
74 // defined and used in SDL_sysevents.c 74 // defined and used in SDL_sysevents.c
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, 81 static SDL_Rect **GAPI_ListModes(_THIS, SDL_PixelFormat * format,
82 Uint32 flags); 82 Uint32 flags);
83 static SDL_Surface *GAPI_SetVideoMode (_THIS, SDL_Surface * current, 83 static SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface * current,
84 int width, int height, int bpp, 84 int width, int height, int bpp,
85 Uint32 flags); 85 Uint32 flags);
86 static int GAPI_SetColors (_THIS, int firstcolor, int ncolors, 86 static int GAPI_SetColors(_THIS, int firstcolor, int ncolors,
87 SDL_Color * colors); 87 SDL_Color * colors);
88 static void GAPI_VideoQuit (_THIS); 88 static void GAPI_VideoQuit(_THIS);
89 89
90 /* Hardware surface functions */ 90 /* Hardware surface functions */
91 static int GAPI_AllocHWSurface (_THIS, SDL_Surface * surface); 91 static int GAPI_AllocHWSurface(_THIS, SDL_Surface * surface);
92 static int GAPI_LockHWSurface (_THIS, SDL_Surface * surface); 92 static int GAPI_LockHWSurface(_THIS, SDL_Surface * surface);
93 static void GAPI_UnlockHWSurface (_THIS, SDL_Surface * surface); 93 static void GAPI_UnlockHWSurface(_THIS, SDL_Surface * surface);
94 static void GAPI_FreeHWSurface (_THIS, SDL_Surface * surface); 94 static void GAPI_FreeHWSurface(_THIS, SDL_Surface * surface);
95 95
96 /* Windows message handling functions, will not be processed */ 96 /* Windows message handling functions, will not be processed */
97 static void GAPI_RealizePalette (_THIS); 97 static void GAPI_RealizePalette(_THIS);
98 static void GAPI_PaletteChanged (_THIS, HWND window); 98 static void GAPI_PaletteChanged(_THIS, HWND window);
99 static void GAPI_WinPAINT (_THIS, HDC hdc); 99 static void GAPI_WinPAINT(_THIS, HDC hdc);
100 100
101 /* etc. */ 101 /* etc. */
102 static void GAPI_UpdateRects (_THIS, int numrects, SDL_Rect * rects); 102 static void GAPI_UpdateRects(_THIS, int numrects, SDL_Rect * rects);
103 103
104 static HMODULE g_hGapiLib = 0; 104 static HMODULE g_hGapiLib = 0;
105 #define LINK(type,name,import) \ 105 #define LINK(type,name,import) \
106 if( g_hGapiLib ) \ 106 if( g_hGapiLib ) \
107 name = (PFN##type)GetProcAddress( g_hGapiLib, _T(import) ); 107 name = (PFN##type)GetProcAddress( g_hGapiLib, _T(import) );
147 unsigned long ffFormat; //18 147 unsigned long ffFormat; //18
148 char Unused[0x84 - 7 * 4]; 148 char Unused[0x84 - 7 * 4];
149 } GXDeviceInfo; 149 } GXDeviceInfo;
150 150
151 static int 151 static int
152 GAPI_Available (void) 152 GAPI_Available(void)
153 { 153 {
154 // try to use VGA display, even on emulator 154 // try to use VGA display, even on emulator
155 HDC hdc = GetDC (NULL); 155 HDC hdc = GetDC(NULL);
156 int result = ExtEscape (hdc, GETRAWFRAMEBUFFER, 0, NULL, 156 int result = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL,
157 sizeof (RawFrameBufferInfo), 157 sizeof(RawFrameBufferInfo),
158 (char *) &g_RawFrameBufferInfo); 158 (char *) &g_RawFrameBufferInfo);
159 ReleaseDC (NULL, hdc); 159 ReleaseDC(NULL, hdc);
160 g_bRawBufferAvailable = result > 0; 160 g_bRawBufferAvailable = result > 0;
161 161
162 #if WITHOUT_GAPI 162 #if WITHOUT_GAPI
163 return g_bRawBufferAvailable; 163 return g_bRawBufferAvailable;
164 #endif 164 #endif
165 165
166 #if USE_GAPI_EMU 166 #if USE_GAPI_EMU
167 g_hGapiLib = LoadLibrary (_T ("GAPI_Emu.dll")); 167 g_hGapiLib = LoadLibrary(_T("GAPI_Emu.dll"));
168 if (!g_hGapiLib) { 168 if (!g_hGapiLib) {
169 SDL_SetError ("Gapi Emu not found!"); 169 SDL_SetError("Gapi Emu not found!");
170 } 170 }
171 return g_hGapiLib != 0; 171 return g_hGapiLib != 0;
172 #endif 172 #endif
173 173
174 // try to find gx.dll 174 // try to find gx.dll
175 g_hGapiLib = LoadLibrary (_T ("\\Windows\\gx.dll")); 175 g_hGapiLib = LoadLibrary(_T("\\Windows\\gx.dll"));
176 if (!g_hGapiLib) { 176 if (!g_hGapiLib) {
177 g_hGapiLib = LoadLibrary (_T ("gx.dll")); 177 g_hGapiLib = LoadLibrary(_T("gx.dll"));
178 if (!g_hGapiLib) 178 if (!g_hGapiLib)
179 return g_bRawBufferAvailable; 179 return g_bRawBufferAvailable;
180 } 180 }
181 181
182 return (1); 182 return (1);
183 } 183 }
184 184
185 static int 185 static int
186 cmpmodes (const void *va, const void *vb) 186 cmpmodes(const void *va, const void *vb)
187 { 187 {
188 SDL_Rect *a = *(SDL_Rect **) va; 188 SDL_Rect *a = *(SDL_Rect **) va;
189 SDL_Rect *b = *(SDL_Rect **) vb; 189 SDL_Rect *b = *(SDL_Rect **) vb;
190 if (a->w == b->w) 190 if (a->w == b->w)
191 return b->h - a->h; 191 return b->h - a->h;
192 else 192 else
193 return b->w - a->w; 193 return b->w - a->w;
194 } 194 }
195 195
196 static int 196 static int
197 GAPI_AddMode (_THIS, int bpp, int w, int h) 197 GAPI_AddMode(_THIS, int bpp, int w, int h)
198 { 198 {
199 SDL_Rect *mode; 199 SDL_Rect *mode;
200 int i, index; 200 int i, index;
201 int next_mode; 201 int next_mode;
202 202
211 return (0); 211 return (0);
212 } 212 }
213 } 213 }
214 214
215 /* Set up the new video mode rectangle */ 215 /* Set up the new video mode rectangle */
216 mode = (SDL_Rect *) SDL_malloc (sizeof *mode); 216 mode = (SDL_Rect *) SDL_malloc(sizeof *mode);
217 if (mode == NULL) { 217 if (mode == NULL) {
218 SDL_OutOfMemory (); 218 SDL_OutOfMemory();
219 return (-1); 219 return (-1);
220 } 220 }
221 mode->x = 0; 221 mode->x = 0;
222 mode->y = 0; 222 mode->y = 0;
223 mode->w = w; 223 mode->w = w;
224 mode->h = h; 224 mode->h = h;
225 225
226 /* Allocate the new list of modes, and fill in the new mode */ 226 /* Allocate the new list of modes, and fill in the new mode */
227 next_mode = gapi->SDL_nummodes[index]; 227 next_mode = gapi->SDL_nummodes[index];
228 gapi->SDL_modelist[index] = (SDL_Rect **) 228 gapi->SDL_modelist[index] = (SDL_Rect **)
229 SDL_realloc (gapi->SDL_modelist[index], 229 SDL_realloc(gapi->SDL_modelist[index],
230 (1 + next_mode + 1) * sizeof (SDL_Rect *)); 230 (1 + next_mode + 1) * sizeof(SDL_Rect *));
231 if (gapi->SDL_modelist[index] == NULL) { 231 if (gapi->SDL_modelist[index] == NULL) {
232 SDL_OutOfMemory (); 232 SDL_OutOfMemory();
233 gapi->SDL_nummodes[index] = 0; 233 gapi->SDL_nummodes[index] = 0;
234 SDL_free (mode); 234 SDL_free(mode);
235 return (-1); 235 return (-1);
236 } 236 }
237 gapi->SDL_modelist[index][next_mode] = mode; 237 gapi->SDL_modelist[index][next_mode] = mode;
238 gapi->SDL_modelist[index][next_mode + 1] = NULL; 238 gapi->SDL_modelist[index][next_mode + 1] = NULL;
239 gapi->SDL_nummodes[index]++; 239 gapi->SDL_nummodes[index]++;
240 240
241 return (0); 241 return (0);
242 } 242 }
243 243
244 static void 244 static void
245 GAPI_DeleteDevice (SDL_VideoDevice * device) 245 GAPI_DeleteDevice(SDL_VideoDevice * device)
246 { 246 {
247 if (g_hGapiLib) { 247 if (g_hGapiLib) {
248 FreeLibrary (g_hGapiLib); 248 FreeLibrary(g_hGapiLib);
249 g_hGapiLib = 0; 249 g_hGapiLib = 0;
250 } 250 }
251 SDL_free (device->hidden); 251 SDL_free(device->hidden);
252 SDL_free (device); 252 SDL_free(device);
253 } 253 }
254 254
255 static SDL_VideoDevice * 255 static SDL_VideoDevice *
256 GAPI_CreateDevice (int devindex) 256 GAPI_CreateDevice(int devindex)
257 { 257 {
258 SDL_VideoDevice *device; 258 SDL_VideoDevice *device;
259 259
260 if (!g_hGapiLib && !g_bRawBufferAvailable) { 260 if (!g_hGapiLib && !g_bRawBufferAvailable) {
261 if (!GAPI_Available ()) { 261 if (!GAPI_Available()) {
262 SDL_SetError 262 SDL_SetError
263 ("GAPI dll is not found and VGA mode is not available!"); 263 ("GAPI dll is not found and VGA mode is not available!");
264 return 0; 264 return 0;
265 } 265 }
266 } 266 }
267 267
268 /* Initialize all variables that we clean on shutdown */ 268 /* Initialize all variables that we clean on shutdown */
269 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)); 269 device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
270 if (device) { 270 if (device) {
271 SDL_memset (device, 0, (sizeof *device)); 271 SDL_memset(device, 0, (sizeof *device));
272 device->hidden = (struct SDL_PrivateVideoData *) 272 device->hidden = (struct SDL_PrivateVideoData *)
273 SDL_malloc ((sizeof *device->hidden)); 273 SDL_malloc((sizeof *device->hidden));
274 } 274 }
275 if ((device == NULL) || (device->hidden == NULL)) { 275 if ((device == NULL) || (device->hidden == NULL)) {
276 SDL_OutOfMemory (); 276 SDL_OutOfMemory();
277 if (device) { 277 if (device) {
278 SDL_free (device); 278 SDL_free(device);
279 } 279 }
280 return (0); 280 return (0);
281 } 281 }
282 SDL_memset (device->hidden, 0, (sizeof *device->hidden)); 282 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
283 283
284 /* Set the function pointers */ 284 /* Set the function pointers */
285 device->VideoInit = GAPI_VideoInit; 285 device->VideoInit = GAPI_VideoInit;
286 device->ListModes = GAPI_ListModes; 286 device->ListModes = GAPI_ListModes;
287 device->SetVideoMode = GAPI_SetVideoMode; 287 device->SetVideoMode = GAPI_SetVideoMode;
321 device->free = GAPI_DeleteDevice; 321 device->free = GAPI_DeleteDevice;
322 322
323 /* Load gapi library */ 323 /* Load gapi library */
324 #define gx device->hidden->gxFunc 324 #define gx device->hidden->gxFunc
325 325
326 LINK (GXOpenDisplay, gx.GXOpenDisplay, 326 LINK(GXOpenDisplay, gx.GXOpenDisplay,
327 "?GXOpenDisplay@@YAHPAUHWND__@@K@Z") LINK (GXCloseDisplay, 327 "?GXOpenDisplay@@YAHPAUHWND__@@K@Z") LINK(GXCloseDisplay,
328 gx.GXCloseDisplay, 328 gx.GXCloseDisplay,
329 "?GXCloseDisplay@@YAHXZ") 329 "?GXCloseDisplay@@YAHXZ")
330 LINK (GXBeginDraw, gx.GXBeginDraw, 330 LINK(GXBeginDraw, gx.GXBeginDraw,
331 "?GXBeginDraw@@YAPAXXZ") LINK (GXEndDraw, gx.GXEndDraw, 331 "?GXBeginDraw@@YAPAXXZ") LINK(GXEndDraw, gx.GXEndDraw,
332 "?GXEndDraw@@YAHXZ") 332 "?GXEndDraw@@YAHXZ")
333 LINK (GXOpenInput, gx.GXOpenInput, 333 LINK(GXOpenInput, gx.GXOpenInput,
334 "?GXOpenInput@@YAHXZ") LINK (GXCloseInput, gx.GXCloseInput, 334 "?GXOpenInput@@YAHXZ") LINK(GXCloseInput, gx.GXCloseInput,
335 "?GXCloseInput@@YAHXZ") 335 "?GXCloseInput@@YAHXZ")
336 LINK (GXGetDisplayProperties, gx.GXGetDisplayProperties, 336 LINK(GXGetDisplayProperties, gx.GXGetDisplayProperties,
337 "?GXGetDisplayProperties@@YA?AUGXDisplayProperties@@XZ") 337 "?GXGetDisplayProperties@@YA?AUGXDisplayProperties@@XZ")
338 LINK (GXGetDefaultKeys, gx.GXGetDefaultKeys, 338 LINK(GXGetDefaultKeys, gx.GXGetDefaultKeys,
339 "?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z") LINK (GXSuspend, 339 "?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z") LINK(GXSuspend,
340 gx.GXSuspend, 340 gx.GXSuspend,
341 "?GXSuspend@@YAHXZ") 341 "?GXSuspend@@YAHXZ")
342 LINK (GXResume, gx.GXResume, "?GXResume@@YAHXZ") LINK (GXSetViewport, 342 LINK(GXResume, gx.GXResume, "?GXResume@@YAHXZ") LINK(GXSetViewport,
343 gx. 343 gx.
344 GXSetViewport, 344 GXSetViewport,
345 "?GXSetViewport@@YAHKKKK@Z") 345 "?GXSetViewport@@YAHKKKK@Z")
346 LINK (GXIsDisplayDRAMBuffer, gx.GXIsDisplayDRAMBuffer, 346 LINK(GXIsDisplayDRAMBuffer, gx.GXIsDisplayDRAMBuffer,
347 "?GXIsDisplayDRAMBuffer@@YAHXZ") 347 "?GXIsDisplayDRAMBuffer@@YAHXZ")
348 /* wrong gapi.dll */ 348 /* wrong gapi.dll */
349 if (!gx.GXOpenDisplay) { 349 if (!gx.GXOpenDisplay) {
350 if (g_hGapiLib) { 350 if (g_hGapiLib) {
351 FreeLibrary (g_hGapiLib); 351 FreeLibrary(g_hGapiLib);
352 g_hGapiLib = 0; 352 g_hGapiLib = 0;
353 } 353 }
354 } 354 }
355 355
356 if (!gx.GXOpenDisplay && !g_bRawBufferAvailable) { 356 if (!gx.GXOpenDisplay && !g_bRawBufferAvailable) {
357 SDL_SetError ("Error: damaged or unknown gapi.dll!\n"); 357 SDL_SetError("Error: damaged or unknown gapi.dll!\n");
358 GAPI_DeleteDevice (device); 358 GAPI_DeleteDevice(device);
359 return 0; 359 return 0;
360 } 360 }
361 361
362 return device; 362 return device;
363 } 363 }
366 GAPIVID_DRIVER_NAME, "WinCE GAPI video driver", 366 GAPIVID_DRIVER_NAME, "WinCE GAPI video driver",
367 GAPI_Available, GAPI_CreateDevice 367 GAPI_Available, GAPI_CreateDevice
368 }; 368 };
369 369
370 static void 370 static void
371 FillStructs (_THIS, BOOL useVga) 371 FillStructs(_THIS, BOOL useVga)
372 { 372 {
373 #ifdef _ARM_ 373 #ifdef _ARM_
374 WCHAR oemstr[100]; 374 WCHAR oemstr[100];
375 #endif 375 #endif
376 /* fill a device properties */ 376 /* fill a device properties */
377 377
378 if (!useVga) { 378 if (!useVga) {
379 this->hidden->gxProperties = 379 this->hidden->gxProperties =
380 this->hidden->gxFunc.GXGetDisplayProperties (); 380 this->hidden->gxFunc.GXGetDisplayProperties();
381 this->hidden->needUpdate = 1; 381 this->hidden->needUpdate = 1;
382 this->hidden->hiresFix = 0; 382 this->hidden->hiresFix = 0;
383 this->hidden->useVga = 0; 383 this->hidden->useVga = 0;
384 this->hidden->useGXOpenDisplay = 1; 384 this->hidden->useGXOpenDisplay = 1;
385 385
386 #ifdef _ARM_ 386 #ifdef _ARM_
387 /* check some devices and extract addition info */ 387 /* check some devices and extract addition info */
388 SystemParametersInfo (SPI_GETOEMINFO, sizeof (oemstr), oemstr, 0); 388 SystemParametersInfo(SPI_GETOEMINFO, sizeof(oemstr), oemstr, 0);
389 389
390 // buggy iPaq38xx 390 // buggy iPaq38xx
391 if ((oemstr[12] == 'H') && (oemstr[13] == '3') 391 if ((oemstr[12] == 'H') && (oemstr[13] == '3')
392 && (oemstr[14] == '8') 392 && (oemstr[14] == '8')
393 && (this->hidden->gxProperties.cbxPitch > 0)) { 393 && (this->hidden->gxProperties.cbxPitch > 0)) {
396 this->hidden->gxProperties.cbyPitch = 2; 396 this->hidden->gxProperties.cbyPitch = 2;
397 this->hidden->needUpdate = 0; 397 this->hidden->needUpdate = 0;
398 } 398 }
399 #if (EMULATE_AXIM_X30 == 0) 399 #if (EMULATE_AXIM_X30 == 0)
400 // buggy Dell Axim X30 400 // buggy Dell Axim X30
401 if (_tcsncmp (oemstr, L"Dell Axim X30", 13) == 0) 401 if (_tcsncmp(oemstr, L"Dell Axim X30", 13) == 0)
402 #endif 402 #endif
403 { 403 {
404 GXDeviceInfo gxInfo = { 0 }; 404 GXDeviceInfo gxInfo = { 0 };
405 HDC hdc = GetDC (NULL); 405 HDC hdc = GetDC(NULL);
406 int result; 406 int result;
407 407
408 gxInfo.Version = 100; 408 gxInfo.Version = 100;
409 result = 409 result =
410 ExtEscape (hdc, GETGXINFO, 0, NULL, sizeof (gxInfo), 410 ExtEscape(hdc, GETGXINFO, 0, NULL, sizeof(gxInfo),
411 (char *) &gxInfo); 411 (char *) &gxInfo);
412 if (result > 0) { 412 if (result > 0) {
413 this->hidden->useGXOpenDisplay = 0; 413 this->hidden->useGXOpenDisplay = 0;
414 this->hidden->videoMem = gxInfo.pvFrameBuffer; 414 this->hidden->videoMem = gxInfo.pvFrameBuffer;
415 this->hidden->needUpdate = 0; 415 this->hidden->needUpdate = 0;
416 this->hidden->gxProperties.cbxPitch = 2; 416 this->hidden->gxProperties.cbxPitch = 2;
467 this->hidden->gapiOrientation = SDL_ORIENTATION_LEFT; // ipaq 3800 467 this->hidden->gapiOrientation = SDL_ORIENTATION_LEFT; // ipaq 3800
468 } 468 }
469 } 469 }
470 470
471 static void 471 static void
472 GAPI_CreatePalette (int ncolors, SDL_Color * colors) 472 GAPI_CreatePalette(int ncolors, SDL_Color * colors)
473 { 473 {
474 // Setup a custom color palette 474 // Setup a custom color palette
475 BYTE buffer[sizeof (LOGPALETTE) + 255 * sizeof (PALETTEENTRY)]; 475 BYTE buffer[sizeof(LOGPALETTE) + 255 * sizeof(PALETTEENTRY)];
476 int i; 476 int i;
477 LOGPALETTE *pLogical = (LOGPALETTE *) buffer; 477 LOGPALETTE *pLogical = (LOGPALETTE *) buffer;
478 PALETTEENTRY *entries = pLogical->palPalEntry; 478 PALETTEENTRY *entries = pLogical->palPalEntry;
479 HPALETTE hPalette; 479 HPALETTE hPalette;
480 HDC hdc; 480 HDC hdc;
489 489
490 // Create the GDI palette object 490 // Create the GDI palette object
491 pLogical->palVersion = 0x0300; 491 pLogical->palVersion = 0x0300;
492 pLogical->palNumEntries = ncolors; 492 pLogical->palNumEntries = ncolors;
493 493
494 hPalette = CreatePalette (pLogical); 494 hPalette = CreatePalette(pLogical);
495 ASSERT (hPalette); 495 ASSERT(hPalette);
496 496
497 497
498 // Realize the palette 498 // Realize the palette
499 hdc = GetDC (0); 499 hdc = GetDC(0);
500 500
501 SelectPalette (hdc, hPalette, FALSE); 501 SelectPalette(hdc, hPalette, FALSE);
502 RealizePalette (hdc); 502 RealizePalette(hdc);
503 503
504 ReleaseDC (0, hdc); 504 ReleaseDC(0, hdc);
505 DeleteObject (hPalette); 505 DeleteObject(hPalette);
506 } 506 }
507 507
508 int 508 int
509 GAPI_VideoInit (_THIS, SDL_PixelFormat * vformat) 509 GAPI_VideoInit(_THIS, SDL_PixelFormat * vformat)
510 { 510 {
511 int i, bpp; 511 int i, bpp;
512 512
513 /* Create the window */ 513 /* Create the window */
514 if (DIB_CreateWindow (this) < 0) { 514 if (DIB_CreateWindow(this) < 0) {
515 return (-1); 515 return (-1);
516 } 516 }
517 517
518 if (g_hGapiLib) { 518 if (g_hGapiLib) {
519 FillStructs (this, 0); 519 FillStructs(this, 0);
520 520
521 // SDL does not supports 2/4bpp mode, so use 16 bpp 521 // SDL does not supports 2/4bpp mode, so use 16 bpp
522 bpp = gapi->gxProperties.cBPP < 8 ? 16 : gapi->gxProperties.cBPP; 522 bpp = gapi->gxProperties.cBPP < 8 ? 16 : gapi->gxProperties.cBPP;
523 523
524 /* set up normal and landscape mode */ 524 /* set up normal and landscape mode */
525 GAPI_AddMode (this, bpp, gapi->gxProperties.cyHeight, 525 GAPI_AddMode(this, bpp, gapi->gxProperties.cyHeight,
526 gapi->gxProperties.cxWidth); 526 gapi->gxProperties.cxWidth);
527 GAPI_AddMode (this, bpp, gapi->gxProperties.cxWidth, 527 GAPI_AddMode(this, bpp, gapi->gxProperties.cxWidth,
528 gapi->gxProperties.cyHeight); 528 gapi->gxProperties.cyHeight);
529 } 529 }
530 530
531 /* add hi-res mode */ 531 /* add hi-res mode */
532 if (g_bRawBufferAvailable && 532 if (g_bRawBufferAvailable &&
533 !((gapi->gxProperties.cxWidth == 533 !((gapi->gxProperties.cxWidth ==
534 (unsigned) g_RawFrameBufferInfo.cxPixels) 534 (unsigned) g_RawFrameBufferInfo.cxPixels)
535 && (gapi->gxProperties.cyHeight == 535 && (gapi->gxProperties.cyHeight ==
536 (unsigned) g_RawFrameBufferInfo.cyPixels))) { 536 (unsigned) g_RawFrameBufferInfo.cyPixels))) {
537 FillStructs (this, 1); 537 FillStructs(this, 1);
538 538
539 // SDL does not supports 2/4bpp mode, so use 16 bpp 539 // SDL does not supports 2/4bpp mode, so use 16 bpp
540 bpp = gapi->gxProperties.cBPP < 8 ? 16 : gapi->gxProperties.cBPP; 540 bpp = gapi->gxProperties.cBPP < 8 ? 16 : gapi->gxProperties.cBPP;
541 541
542 /* set up normal and landscape mode */ 542 /* set up normal and landscape mode */
543 GAPI_AddMode (this, bpp, gapi->gxProperties.cyHeight, 543 GAPI_AddMode(this, bpp, gapi->gxProperties.cyHeight,
544 gapi->gxProperties.cxWidth); 544 gapi->gxProperties.cxWidth);
545 GAPI_AddMode (this, bpp, gapi->gxProperties.cxWidth, 545 GAPI_AddMode(this, bpp, gapi->gxProperties.cxWidth,
546 gapi->gxProperties.cyHeight); 546 gapi->gxProperties.cyHeight);
547 } 547 }
548 548
549 /* Determine the current screen size */ 549 /* Determine the current screen size */
550 this->info.current_w = gapi->gxProperties.cxWidth; 550 this->info.current_w = gapi->gxProperties.cxWidth;
551 this->info.current_h = gapi->gxProperties.cyHeight; 551 this->info.current_h = gapi->gxProperties.cyHeight;
552 552
553 /* Sort the mode lists */ 553 /* Sort the mode lists */
554 for (i = 0; i < NUM_MODELISTS; ++i) { 554 for (i = 0; i < NUM_MODELISTS; ++i) {
555 if (gapi->SDL_nummodes[i] > 0) { 555 if (gapi->SDL_nummodes[i] > 0) {
556 SDL_qsort (gapi->SDL_modelist[i], gapi->SDL_nummodes[i], 556 SDL_qsort(gapi->SDL_modelist[i], gapi->SDL_nummodes[i],
557 sizeof *gapi->SDL_modelist[i], cmpmodes); 557 sizeof *gapi->SDL_modelist[i], cmpmodes);
558 } 558 }
559 } 559 }
560 560
561 vformat->BitsPerPixel = 561 vformat->BitsPerPixel =
562 this->hidden->gxProperties.cBPP < 562 this->hidden->gxProperties.cBPP <
595 /* We're done! */ 595 /* We're done! */
596 return (0); 596 return (0);
597 } 597 }
598 598
599 SDL_Rect ** 599 SDL_Rect **
600 GAPI_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) 600 GAPI_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
601 { 601 {
602 return (this->hidden->SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1]); 602 return (this->hidden->SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1]);
603 // return (SDL_Rect **) -1; 603 // return (SDL_Rect **) -1;
604 } 604 }
605 605
606 SDL_Surface * 606 SDL_Surface *
607 GAPI_SetVideoMode (_THIS, SDL_Surface * current, 607 GAPI_SetVideoMode(_THIS, SDL_Surface * current,
608 int width, int height, int bpp, Uint32 flags) 608 int width, int height, int bpp, Uint32 flags)
609 { 609 {
610 SDL_Surface *video; 610 SDL_Surface *video;
611 Uint32 Rmask, Gmask, Bmask; 611 Uint32 Rmask, Gmask, Bmask;
612 DWORD style; 612 DWORD style;
613 SDL_Rect allScreen; 613 SDL_Rect allScreen;
614 614
615 if (bpp < 4) { 615 if (bpp < 4) {
616 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!");
617 return 0; 617 return 0;
618 } 618 }
619 619
620 /* Recalculate bitmasks if necessary */ 620 /* Recalculate bitmasks if necessary */
621 if (bpp == current->format->BitsPerPixel) { 621 if (bpp == current->format->BitsPerPixel) {
645 Rmask = 0x00ff0000; 645 Rmask = 0x00ff0000;
646 Gmask = 0x0000ff00; 646 Gmask = 0x0000ff00;
647 Bmask = 0x000000ff; 647 Bmask = 0x000000ff;
648 break; 648 break;
649 default: 649 default:
650 SDL_SetError ("Unsupported Bits Per Pixel format requested"); 650 SDL_SetError("Unsupported Bits Per Pixel format requested");
651 return NULL; 651 return NULL;
652 } 652 }
653 video = SDL_CreateRGBSurface (SDL_SWSURFACE, 653 video = SDL_CreateRGBSurface(SDL_SWSURFACE,
654 0, 0, bpp, Rmask, Gmask, Bmask, 0); 654 0, 0, bpp, Rmask, Gmask, Bmask, 0);
655 if (video == NULL) { 655 if (video == NULL) {
656 SDL_OutOfMemory (); 656 SDL_OutOfMemory();
657 return (NULL); 657 return (NULL);
658 } 658 }
659 } 659 }
660 660
661 gapi->userOrientation = SDL_ORIENTATION_UP; 661 gapi->userOrientation = SDL_ORIENTATION_UP;
662 video->flags = SDL_FULLSCREEN; /* Clear flags, GAPI supports fullscreen only */ 662 video->flags = SDL_FULLSCREEN; /* Clear flags, GAPI supports fullscreen only */
663 663
664 /* GAPI or VGA? */ 664 /* GAPI or VGA? */
665 if (g_hGapiLib) { 665 if (g_hGapiLib) {
666 FillStructs (this, 0); 666 FillStructs(this, 0);
667 if ((((unsigned) width != gapi->gxProperties.cxWidth) 667 if ((((unsigned) width != gapi->gxProperties.cxWidth)
668 || ((unsigned) height != gapi->gxProperties.cyHeight)) 668 || ((unsigned) height != gapi->gxProperties.cyHeight))
669 && (((unsigned) width != gapi->gxProperties.cyHeight) 669 && (((unsigned) width != gapi->gxProperties.cyHeight)
670 || ((unsigned) height != gapi->gxProperties.cxWidth))) 670 || ((unsigned) height != gapi->gxProperties.cxWidth)))
671 FillStructs (this, 1); // gapi is found but we use VGA resolution 671 FillStructs(this, 1); // gapi is found but we use VGA resolution
672 } else 672 } else
673 FillStructs (this, 1); 673 FillStructs(this, 1);
674 674
675 if (!this->hidden->needUpdate && !this->hidden->videoMem) { 675 if (!this->hidden->needUpdate && !this->hidden->videoMem) {
676 SDL_SetError 676 SDL_SetError
677 ("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");
678 return (NULL); 678 return (NULL);
679 } 679 }
680 680
681 /* detect user landscape mode */ 681 /* detect user landscape mode */
682 if ((width > height) 682 if ((width > height)
683 && (GetSystemMetrics (SM_CXSCREEN) < GetSystemMetrics (SM_CYSCREEN))) 683 && (GetSystemMetrics(SM_CXSCREEN) < GetSystemMetrics(SM_CYSCREEN)))
684 gapi->userOrientation = SDL_ORIENTATION_RIGHT; 684 gapi->userOrientation = SDL_ORIENTATION_RIGHT;
685 685
686 /* shall we apply hires fix? for example when we do not use hires resource */ 686 /* shall we apply hires fix? for example when we do not use hires resource */
687 gapi->hiresFix = 0; 687 gapi->hiresFix = 0;
688 if (gapi->userOrientation == SDL_ORIENTATION_RIGHT) { 688 if (gapi->userOrientation == SDL_ORIENTATION_RIGHT) {
689 if ((width > GetSystemMetrics (SM_CYSCREEN)) 689 if ((width > GetSystemMetrics(SM_CYSCREEN))
690 || (height > GetSystemMetrics (SM_CXSCREEN))) 690 || (height > GetSystemMetrics(SM_CXSCREEN)))
691 gapi->hiresFix = 1; 691 gapi->hiresFix = 1;
692 } else if ((width > GetSystemMetrics (SM_CXSCREEN)) 692 } else if ((width > GetSystemMetrics(SM_CXSCREEN))
693 || (height > GetSystemMetrics (SM_CYSCREEN))) 693 || (height > GetSystemMetrics(SM_CYSCREEN)))
694 if (!((width == GetSystemMetrics (SM_CYSCREEN)) && (height == GetSystemMetrics (SM_CXSCREEN)))) // user portrait, device landscape 694 if (!((width == GetSystemMetrics(SM_CYSCREEN)) && (height == GetSystemMetrics(SM_CXSCREEN)))) // user portrait, device landscape
695 gapi->hiresFix = 1; 695 gapi->hiresFix = 1;
696 696
697 switch (gapi->userOrientation) { 697 switch (gapi->userOrientation) {
698 case SDL_ORIENTATION_UP: 698 case SDL_ORIENTATION_UP:
699 gapi->startOffset = 0; 699 gapi->startOffset = 0;
718 } 718 }
719 } 719 }
720 720
721 video->w = this->hidden->w = width; 721 video->w = this->hidden->w = width;
722 video->h = this->hidden->h = height; 722 video->h = this->hidden->h = height;
723 video->pitch = SDL_CalculatePitch (video); 723 video->pitch = SDL_CalculatePitch(video);
724 724
725 /* Small fix for WinCE/Win32 - when activating window 725 /* Small fix for WinCE/Win32 - when activating window
726 SDL_VideoSurface is equal to zero, so activating code 726 SDL_VideoSurface is equal to zero, so activating code
727 is not called properly for fullscreen windows because 727 is not called properly for fullscreen windows because
728 macros WINDIB_FULLSCREEN uses SDL_VideoSurface 728 macros WINDIB_FULLSCREEN uses SDL_VideoSurface
731 731
732 /* GAPI is always fullscreen, title bar is useless */ 732 /* GAPI is always fullscreen, title bar is useless */
733 style = 0; 733 style = 0;
734 734
735 if (!SDL_windowid) 735 if (!SDL_windowid)
736 SetWindowLong (SDL_Window, GWL_STYLE, style); 736 SetWindowLong(SDL_Window, GWL_STYLE, style);
737 737
738 /* Allocate bitmap */ 738 /* Allocate bitmap */
739 if (gapiBuffer) { 739 if (gapiBuffer) {
740 SDL_free (gapiBuffer); 740 SDL_free(gapiBuffer);
741 gapiBuffer = NULL; 741 gapiBuffer = NULL;
742 } 742 }
743 gapiBuffer = SDL_malloc (video->h * video->pitch); 743 gapiBuffer = SDL_malloc(video->h * video->pitch);
744 video->pixels = gapiBuffer; 744 video->pixels = gapiBuffer;
745 745
746 if (!this->hidden->buffer) { 746 if (!this->hidden->buffer) {
747 SDL_SetError ("Couldn't allocate buffer for requested mode"); 747 SDL_SetError("Couldn't allocate buffer for requested mode");
748 return (NULL); 748 return (NULL);
749 } 749 }
750 750
751 SDL_memset (gapiBuffer, 255, video->h * video->pitch); 751 SDL_memset(gapiBuffer, 255, video->h * video->pitch);
752 MoveWindow (SDL_Window, 0, 0, GetSystemMetrics (SM_CXSCREEN), 752 MoveWindow(SDL_Window, 0, 0, GetSystemMetrics(SM_CXSCREEN),
753 GetSystemMetrics (SM_CYSCREEN), FALSE); 753 GetSystemMetrics(SM_CYSCREEN), FALSE);
754 ShowWindow (SDL_Window, SW_SHOW); 754 ShowWindow(SDL_Window, SW_SHOW);
755 SetForegroundWindow (SDL_Window); 755 SetForegroundWindow(SDL_Window);
756 756
757 /* JC 14 Mar 2006 757 /* JC 14 Mar 2006
758 Flush the message loop or this can cause big problems later 758 Flush the message loop or this can cause big problems later
759 Especially if the user decides to use dialog boxes or assert()! 759 Especially if the user decides to use dialog boxes or assert()!
760 */ 760 */
761 WIN_FlushMessageQueue (); 761 WIN_FlushMessageQueue();
762 762
763 /* Open GAPI display */ 763 /* Open GAPI display */
764 if (!gapi->useVga && this->hidden->useGXOpenDisplay) 764 if (!gapi->useVga && this->hidden->useGXOpenDisplay)
765 if (!gapi->gxFunc.GXOpenDisplay (SDL_Window, GX_FULLSCREEN)) { 765 if (!gapi->gxFunc.GXOpenDisplay(SDL_Window, GX_FULLSCREEN)) {
766 SDL_SetError ("Couldn't initialize GAPI"); 766 SDL_SetError("Couldn't initialize GAPI");
767 return (NULL); 767 return (NULL);
768 } 768 }
769 #if REPORT_VIDEO_INFO 769 #if REPORT_VIDEO_INFO
770 printf ("Video properties:\n"); 770 printf("Video properties:\n");
771 printf ("display bpp: %d\n", gapi->gxProperties.cBPP); 771 printf("display bpp: %d\n", gapi->gxProperties.cBPP);
772 printf ("display width: %d\n", gapi->gxProperties.cxWidth); 772 printf("display width: %d\n", gapi->gxProperties.cxWidth);
773 printf ("display height: %d\n", gapi->gxProperties.cyHeight); 773 printf("display height: %d\n", gapi->gxProperties.cyHeight);
774 printf ("x pitch: %d\n", gapi->gxProperties.cbxPitch); 774 printf("x pitch: %d\n", gapi->gxProperties.cbxPitch);
775 printf ("y pitch: %d\n", gapi->gxProperties.cbyPitch); 775 printf("y pitch: %d\n", gapi->gxProperties.cbyPitch);
776 printf ("gapi flags: 0x%x\n", gapi->gxProperties.ffFormat); 776 printf("gapi flags: 0x%x\n", gapi->gxProperties.ffFormat);
777 777
778 if (!gapi->useVga && this->hidden->useGXOpenDisplay && gapi->needUpdate) { 778 if (!gapi->useVga && this->hidden->useGXOpenDisplay && gapi->needUpdate) {
779 gapi->videoMem = gapi->gxFunc.GXBeginDraw (); 779 gapi->videoMem = gapi->gxFunc.GXBeginDraw();
780 gapi->gxFunc.GXEndDraw (); 780 gapi->gxFunc.GXEndDraw();
781 } 781 }
782 782
783 printf ("video memory: 0x%x\n", gapi->videoMem); 783 printf("video memory: 0x%x\n", gapi->videoMem);
784 printf ("need update: %d\n", gapi->needUpdate); 784 printf("need update: %d\n", gapi->needUpdate);
785 printf ("hi-res fix: %d\n", gapi->hiresFix); 785 printf("hi-res fix: %d\n", gapi->hiresFix);
786 printf ("VGA is available on the device: %d\n", g_bRawBufferAvailable); 786 printf("VGA is available on the device: %d\n", g_bRawBufferAvailable);
787 printf ("use raw framebuffer: %d\n", gapi->useVga); 787 printf("use raw framebuffer: %d\n", gapi->useVga);
788 printf ("video surface bpp: %d\n", video->format->BitsPerPixel); 788 printf("video surface bpp: %d\n", video->format->BitsPerPixel);
789 printf ("video surface width: %d\n", video->w); 789 printf("video surface width: %d\n", video->w);
790 printf ("video surface height: %d\n", video->h); 790 printf("video surface height: %d\n", video->h);
791 #endif 791 #endif
792 792
793 793
794 /* Blank screen */ 794 /* Blank screen */
795 allScreen.x = allScreen.y = 0; 795 allScreen.x = allScreen.y = 0;
796 allScreen.w = video->w - 1; 796 allScreen.w = video->w - 1;
797 allScreen.h = video->h - 1; 797 allScreen.h = video->h - 1;
798 GAPI_UpdateRects (this, 1, &allScreen); 798 GAPI_UpdateRects(this, 1, &allScreen);
799 799
800 /* We're done */ 800 /* We're done */
801 return (video); 801 return (video);
802 } 802 }
803 803
804 /* 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 */
805 static int 805 static int
806 GAPI_AllocHWSurface (_THIS, SDL_Surface * surface) 806 GAPI_AllocHWSurface(_THIS, SDL_Surface * surface)
807 { 807 {
808 return (-1); 808 return (-1);
809 } 809 }
810 static void 810 static void
811 GAPI_FreeHWSurface (_THIS, SDL_Surface * surface) 811 GAPI_FreeHWSurface(_THIS, SDL_Surface * surface)
812 { 812 {
813 return; 813 return;
814 } 814 }
815 815
816 /* We need to wait for vertical retrace on page flipped displays */ 816 /* We need to wait for vertical retrace on page flipped displays */
817 static int 817 static int
818 GAPI_LockHWSurface (_THIS, SDL_Surface * surface) 818 GAPI_LockHWSurface(_THIS, SDL_Surface * surface)
819 { 819 {
820 return (0); 820 return (0);
821 } 821 }
822 822
823 static void 823 static void
824 GAPI_UnlockHWSurface (_THIS, SDL_Surface * surface) 824 GAPI_UnlockHWSurface(_THIS, SDL_Surface * surface)
825 { 825 {
826 return; 826 return;
827 } 827 }
828 828
829 static int 829 static int
830 updateLine8to8 (_THIS, unsigned char *srcPointer, unsigned char *destPointer, 830 updateLine8to8(_THIS, unsigned char *srcPointer, unsigned char *destPointer,
831 int width, int height, int lines) 831 int width, int height, int lines)
832 { 832 {
833 if (gapi->dstPixelStep == 1) { /* optimized blitting on most devices */ 833 if (gapi->dstPixelStep == 1) { /* optimized blitting on most devices */
834 SDL_memcpy (destPointer, srcPointer, width); 834 SDL_memcpy(destPointer, srcPointer, width);
835 return 1; 835 return 1;
836 } else { 836 } else {
837 // TODO: read 4 pixels, write DWORD 837 // TODO: read 4 pixels, write DWORD
838 int step = gapi->dstPixelStep; 838 int step = gapi->dstPixelStep;
839 while (width--) { 839 while (width--) {
844 return 1; 844 return 1;
845 } 845 }
846 846
847 /* 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 */
848 static int 848 static int
849 updateLine16to16 (_THIS, PIXEL * srcPointer, PIXEL * destPointer, int width, 849 updateLine16to16(_THIS, PIXEL * srcPointer, PIXEL * destPointer, int width,
850 int height, int lines) 850 int height, int lines)
851 { 851 {
852 PIXEL *line1, *line2; 852 PIXEL *line1, *line2;
853 int step = gapi->dstPixelStep / 2; 853 int step = gapi->dstPixelStep / 2;
854 854
855 if (step == 1) { /* optimized blitting on most devices */ 855 if (step == 1) { /* optimized blitting on most devices */
856 SDL_memcpy (destPointer, srcPointer, width * sizeof (PIXEL)); 856 SDL_memcpy(destPointer, srcPointer, width * sizeof(PIXEL));
857 return 1; 857 return 1;
858 } else { 858 } else {
859 if ((gapi->gapiOrientation != SDL_ORIENTATION_UP) && (gapi->userOrientation == SDL_ORIENTATION_UP)) // iPaq 3660/3800 and user orientation up 859 if ((gapi->gapiOrientation != SDL_ORIENTATION_UP) && (gapi->userOrientation == SDL_ORIENTATION_UP)) // iPaq 3660/3800 and user orientation up
860 { 860 {
861 // to prevent data misalignment copy only one line 861 // to prevent data misalignment copy only one line
948 #define GREENMASK (63<<5) 948 #define GREENMASK (63<<5)
949 #define BLUEMASK (31) 949 #define BLUEMASK (31)
950 950
951 951
952 static int 952 static int
953 updateLine16to4 (_THIS, PIXEL * srcPointer, unsigned char *destPointer, 953 updateLine16to4(_THIS, PIXEL * srcPointer, unsigned char *destPointer,
954 int width, int height, int lines, int yNibble, int xNibble) 954 int width, int height, int lines, int yNibble, int xNibble)
955 { 955 {
956 PIXEL *line1, *line2; 956 PIXEL *line1, *line2;
957 int step = gapi->dstPixelStep; 957 int step = gapi->dstPixelStep;
958 958
959 if (gapi->userOrientation == SDL_ORIENTATION_UP) { 959 if (gapi->userOrientation == SDL_ORIENTATION_UP) {
1029 return 1; 1029 return 1;
1030 } 1030 }
1031 } 1031 }
1032 1032
1033 static void 1033 static void
1034 GAPI_UpdateRectsMono (_THIS, int numrects, SDL_Rect * rects) 1034 GAPI_UpdateRectsMono(_THIS, int numrects, SDL_Rect * rects)
1035 { 1035 {
1036 int i, height; 1036 int i, height;
1037 int linesProcessed; 1037 int linesProcessed;
1038 int xNibble, yNibble; 1038 int xNibble, yNibble;
1039 1039
1061 while (height > 0) { 1061 while (height > 0) {
1062 switch (gapi->gxProperties.cBPP) { 1062 switch (gapi->gxProperties.cBPP) {
1063 case 2: // TODO 1063 case 2: // TODO
1064 case 4: 1064 case 4:
1065 linesProcessed = 1065 linesProcessed =
1066 updateLine16to4 (this, (PIXEL *) srcPointer, 1066 updateLine16to4(this, (PIXEL *) srcPointer,
1067 destPointer, rects[i].w, 1067 destPointer, rects[i].w,
1068 rects[i].h, height, yNibble, xNibble); 1068 rects[i].h, height, yNibble, xNibble);
1069 yNibble = 0; 1069 yNibble = 0;
1070 } 1070 }
1071 height -= linesProcessed; 1071 height -= linesProcessed;
1072 if (gapi->userOrientation == SDL_ORIENTATION_UP) 1072 if (gapi->userOrientation == SDL_ORIENTATION_UP)
1073 destPointer--; // always fill 1 byte 1073 destPointer--; // always fill 1 byte
1077 } 1077 }
1078 } 1078 }
1079 } 1079 }
1080 1080
1081 static void 1081 static void
1082 GAPI_UpdateRectsColor (_THIS, int numrects, SDL_Rect * rects) 1082 GAPI_UpdateRectsColor(_THIS, int numrects, SDL_Rect * rects)
1083 { 1083 {
1084 int i, height; 1084 int i, height;
1085 int bytesPerPixel = (gapi->gxProperties.cBPP + 1) / 8; 1085 int bytesPerPixel = (gapi->gxProperties.cBPP + 1) / 8;
1086 int linesProcessed; 1086 int linesProcessed;
1087 for (i = 0; i < numrects; i++) { 1087 for (i = 0; i < numrects; i++) {
1099 1099
1100 while (height > 0) { 1100 while (height > 0) {
1101 switch (bytesPerPixel) { 1101 switch (bytesPerPixel) {
1102 case 1: 1102 case 1:
1103 linesProcessed = 1103 linesProcessed =
1104 updateLine8to8 (this, srcPointer, 1104 updateLine8to8(this, srcPointer,
1105 (unsigned char *) destPointer, 1105 (unsigned char *) destPointer,
1106 rects[i].w, rects[i].h, height); 1106 rects[i].w, rects[i].h, height);
1107 break; 1107 break;
1108 case 2: 1108 case 2:
1109 #pragma warning(disable: 4133) 1109 #pragma warning(disable: 4133)
1110 linesProcessed = 1110 linesProcessed =
1111 updateLine16to16 (this, (PIXEL *) srcPointer, 1111 updateLine16to16(this, (PIXEL *) srcPointer,
1112 destPointer, rects[i].w, 1112 destPointer, rects[i].w,
1113 rects[i].h, height); 1113 rects[i].h, height);
1114 break; 1114 break;
1115 } 1115 }
1116 height -= linesProcessed; 1116 height -= linesProcessed;
1117 destPointer += gapi->dstLineStep * linesProcessed; 1117 destPointer += gapi->dstLineStep * linesProcessed;
1118 srcPointer += SDL_VideoSurface->pitch * linesProcessed; // pitch in bytes 1118 srcPointer += SDL_VideoSurface->pitch * linesProcessed; // pitch in bytes
1122 } 1122 }
1123 } 1123 }
1124 1124
1125 1125
1126 static void 1126 static void
1127 GAPI_UpdateRects (_THIS, int numrects, SDL_Rect * rects) 1127 GAPI_UpdateRects(_THIS, int numrects, SDL_Rect * rects)
1128 { 1128 {
1129 // we do not want to corrupt video memory 1129 // we do not want to corrupt video memory
1130 if (gapi->suspended) 1130 if (gapi->suspended)
1131 return; 1131 return;
1132 1132
1133 if (gapi->needUpdate) 1133 if (gapi->needUpdate)
1134 gapi->videoMem = gapi->gxFunc.GXBeginDraw (); 1134 gapi->videoMem = gapi->gxFunc.GXBeginDraw();
1135 1135
1136 if (gapi->gxProperties.cBPP < 8) 1136 if (gapi->gxProperties.cBPP < 8)
1137 GAPI_UpdateRectsMono (this, numrects, rects); 1137 GAPI_UpdateRectsMono(this, numrects, rects);
1138 else 1138 else
1139 GAPI_UpdateRectsColor (this, numrects, rects); 1139 GAPI_UpdateRectsColor(this, numrects, rects);
1140 1140
1141 if (gapi->needUpdate) 1141 if (gapi->needUpdate)
1142 gapi->gxFunc.GXEndDraw (); 1142 gapi->gxFunc.GXEndDraw();
1143 } 1143 }
1144 1144
1145 /* 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
1146 another SDL video routine -- notably UpdateRects. 1146 another SDL video routine -- notably UpdateRects.
1147 */ 1147 */
1148 void 1148 void
1149 GAPI_VideoQuit (_THIS) 1149 GAPI_VideoQuit(_THIS)
1150 { 1150 {
1151 int i, j; 1151 int i, j;
1152 /* Destroy the window and everything associated with it */ 1152 /* Destroy the window and everything associated with it */
1153 if (SDL_Window) { 1153 if (SDL_Window) {
1154 if ((g_hGapiLib != 0) && this && this->hidden 1154 if ((g_hGapiLib != 0) && this && this->hidden
1155 && this->hidden->gxFunc.GXCloseDisplay && !this->hidden->useVga) 1155 && this->hidden->gxFunc.GXCloseDisplay && !this->hidden->useVga)
1156 this->hidden->gxFunc.GXCloseDisplay (); 1156 this->hidden->gxFunc.GXCloseDisplay();
1157 1157
1158 if (this->screen->pixels != NULL) { 1158 if (this->screen->pixels != NULL) {
1159 SDL_free (this->screen->pixels); 1159 SDL_free(this->screen->pixels);
1160 this->screen->pixels = NULL; 1160 this->screen->pixels = NULL;
1161 } 1161 }
1162 if (screen_icn) { 1162 if (screen_icn) {
1163 DestroyIcon (screen_icn); 1163 DestroyIcon(screen_icn);
1164 screen_icn = NULL; 1164 screen_icn = NULL;
1165 } 1165 }
1166 1166
1167 DIB_DestroyWindow (this); 1167 DIB_DestroyWindow(this);
1168 SDL_UnregisterApp (); 1168 SDL_UnregisterApp();
1169 1169
1170 SDL_Window = NULL; 1170 SDL_Window = NULL;
1171 #if defined(_WIN32_WCE) 1171 #if defined(_WIN32_WCE)
1172 1172
1173 // Unload wince aygshell library to prevent leak 1173 // Unload wince aygshell library to prevent leak
1174 if (aygshell) { 1174 if (aygshell) {
1175 FreeLibrary (aygshell); 1175 FreeLibrary(aygshell);
1176 aygshell = NULL; 1176 aygshell = NULL;
1177 } 1177 }
1178 #endif 1178 #endif
1179 1179
1180 /* Free video mode lists */ 1180 /* Free video mode lists */
1181 for (i = 0; i < NUM_MODELISTS; ++i) { 1181 for (i = 0; i < NUM_MODELISTS; ++i) {
1182 if (gapi->SDL_modelist[i] != NULL) { 1182 if (gapi->SDL_modelist[i] != NULL) {
1183 for (j = 0; gapi->SDL_modelist[i][j]; ++j) 1183 for (j = 0; gapi->SDL_modelist[i][j]; ++j)
1184 SDL_free (gapi->SDL_modelist[i][j]); 1184 SDL_free(gapi->SDL_modelist[i][j]);
1185 SDL_free (gapi->SDL_modelist[i]); 1185 SDL_free(gapi->SDL_modelist[i]);
1186 gapi->SDL_modelist[i] = NULL; 1186 gapi->SDL_modelist[i] = NULL;
1187 } 1187 }
1188 } 1188 }
1189 1189
1190 } 1190 }
1191 1191
1192 } 1192 }
1193 1193
1194 static void 1194 static void
1195 GAPI_RealizePalette (_THIS) 1195 GAPI_RealizePalette(_THIS)
1196 { 1196 {
1197 OutputDebugString (TEXT ("GAPI_RealizePalette NOT IMPLEMENTED !\r\n")); 1197 OutputDebugString(TEXT("GAPI_RealizePalette NOT IMPLEMENTED !\r\n"));
1198 } 1198 }
1199 1199
1200 static void 1200 static void
1201 GAPI_PaletteChanged (_THIS, HWND window) 1201 GAPI_PaletteChanged(_THIS, HWND window)
1202 { 1202 {
1203 OutputDebugString (TEXT ("GAPI_PaletteChanged NOT IMPLEMENTED !\r\n")); 1203 OutputDebugString(TEXT("GAPI_PaletteChanged NOT IMPLEMENTED !\r\n"));
1204 } 1204 }
1205 1205
1206 static void 1206 static void
1207 GAPI_WinPAINT (_THIS, HDC hdc) 1207 GAPI_WinPAINT(_THIS, HDC hdc)
1208 { 1208 {
1209 // draw current offscreen buffer on hdc 1209 // draw current offscreen buffer on hdc
1210 1210
1211 int bpp = 16; // we always use either 8 or 16 bpp internally 1211 int bpp = 16; // we always use either 8 or 16 bpp internally
1212 1212
1213 unsigned short *bitmapData; 1213 unsigned short *bitmapData;
1214 HBITMAP hb; 1214 HBITMAP hb;
1215 HDC srcDC; 1215 HDC srcDC;
1216 1216
1217 // Create a DIB 1217 // Create a DIB
1218 BYTE buffer[sizeof (BITMAPINFOHEADER) + 3 * sizeof (RGBQUAD)] = { 0 }; 1218 BYTE buffer[sizeof(BITMAPINFOHEADER) + 3 * sizeof(RGBQUAD)] = { 0 };
1219 BITMAPINFO *pBMI = (BITMAPINFO *) buffer; 1219 BITMAPINFO *pBMI = (BITMAPINFO *) buffer;
1220 BITMAPINFOHEADER *pHeader = &pBMI->bmiHeader; 1220 BITMAPINFOHEADER *pHeader = &pBMI->bmiHeader;
1221 DWORD *pColors = (DWORD *) & pBMI->bmiColors; 1221 DWORD *pColors = (DWORD *) & pBMI->bmiColors;
1222 1222
1223 // CreateDIBSection does not support 332 pixel format on wce 1223 // CreateDIBSection does not support 332 pixel format on wce
1224 if (gapi->gxProperties.cBPP == 8) 1224 if (gapi->gxProperties.cBPP == 8)
1225 return; 1225 return;
1226 1226
1227 // DIB Header 1227 // DIB Header
1228 pHeader->biSize = sizeof (BITMAPINFOHEADER); 1228 pHeader->biSize = sizeof(BITMAPINFOHEADER);
1229 pHeader->biWidth = this->hidden->w; 1229 pHeader->biWidth = this->hidden->w;
1230 pHeader->biHeight = -this->hidden->h; 1230 pHeader->biHeight = -this->hidden->h;
1231 pHeader->biPlanes = 1; 1231 pHeader->biPlanes = 1;
1232 pHeader->biBitCount = bpp; 1232 pHeader->biBitCount = bpp;
1233 pHeader->biCompression = BI_RGB; 1233 pHeader->biCompression = BI_RGB;
1239 pColors[1] = GREENMASK; 1239 pColors[1] = GREENMASK;
1240 pColors[2] = BLUEMASK; 1240 pColors[2] = BLUEMASK;
1241 pHeader->biCompression = BI_BITFIELDS; 1241 pHeader->biCompression = BI_BITFIELDS;
1242 } 1242 }
1243 // Create the DIB 1243 // Create the DIB
1244 hb = CreateDIBSection (0, pBMI, DIB_RGB_COLORS, (void **) &bitmapData, 0, 1244 hb = CreateDIBSection(0, pBMI, DIB_RGB_COLORS, (void **) &bitmapData, 0,
1245 0); 1245 0);
1246 1246
1247 // copy data 1247 // copy data
1248 // FIXME: prevent misalignment, but I've never seen non aligned width of screen 1248 // FIXME: prevent misalignment, but I've never seen non aligned width of screen
1249 memcpy (bitmapData, this->hidden->buffer, pHeader->biSizeImage); 1249 memcpy(bitmapData, this->hidden->buffer, pHeader->biSizeImage);
1250 srcDC = CreateCompatibleDC (hdc); 1250 srcDC = CreateCompatibleDC(hdc);
1251 SelectObject (srcDC, hb); 1251 SelectObject(srcDC, hb);
1252 1252
1253 BitBlt (hdc, 0, 0, this->hidden->w, this->hidden->h, srcDC, 0, 0, 1253 BitBlt(hdc, 0, 0, this->hidden->w, this->hidden->h, srcDC, 0, 0, SRCCOPY);
1254 SRCCOPY); 1254
1255 1255 DeleteObject(hb);
1256 DeleteObject (hb); 1256 DeleteDC(srcDC);
1257 DeleteDC (srcDC);
1258 } 1257 }
1259 1258
1260 int 1259 int
1261 GAPI_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) 1260 GAPI_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
1262 { 1261 {
1263 GAPI_CreatePalette (ncolors, colors); 1262 GAPI_CreatePalette(ncolors, colors);
1264 return 1; 1263 return 1;
1265 } 1264 }
1266 1265
1267 /* vi: set ts=4 sw=4 expandtab: */ 1266 /* vi: set ts=4 sw=4 expandtab: */