comparison src/video/gapi/SDL_gapivideo.c @ 4162:3b7fc3416601 SDL-1.2

GAPI fixes from Stefan Klug
author Sam Lantinga <slouken@libsdl.org>
date Mon, 16 Feb 2009 22:32:34 +0000
parents a1b03ba2fcd0
children cbe5222d051a
comparison
equal deleted inserted replaced
4161:bd91db0b0b5d 4162:3b7fc3416601
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 "../windib/SDL_gapidibvideo.h"
55 #include "SDL_gapivideo.h" 56 #include "SDL_gapivideo.h"
57
58 #define gapi this->hidden->gapiInfo
56 59
57 #define GAPIVID_DRIVER_NAME "gapi" 60 #define GAPIVID_DRIVER_NAME "gapi"
58 61
59 #if defined(DEBUG) || defined (_DEBUG) || defined(NDEBUG) 62 #if defined(DEBUG) || defined (_DEBUG) || defined(NDEBUG)
60 #define REPORT_VIDEO_INFO 1 63 #define REPORT_VIDEO_INFO 1
96 static int GAPI_LockHWSurface(_THIS, SDL_Surface *surface); 99 static int GAPI_LockHWSurface(_THIS, SDL_Surface *surface);
97 static void GAPI_UnlockHWSurface(_THIS, SDL_Surface *surface); 100 static void GAPI_UnlockHWSurface(_THIS, SDL_Surface *surface);
98 static void GAPI_FreeHWSurface(_THIS, SDL_Surface *surface); 101 static void GAPI_FreeHWSurface(_THIS, SDL_Surface *surface);
99 102
100 /* Windows message handling functions, will not be processed */ 103 /* Windows message handling functions, will not be processed */
104 static void GAPI_Activate(_THIS, BOOL active, BOOL minimized);
101 static void GAPI_RealizePalette(_THIS); 105 static void GAPI_RealizePalette(_THIS);
102 static void GAPI_PaletteChanged(_THIS, HWND window); 106 static void GAPI_PaletteChanged(_THIS, HWND window);
103 static void GAPI_WinPAINT(_THIS, HDC hdc); 107 static void GAPI_WinPAINT(_THIS, HDC hdc);
104 108
105 /* etc. */ 109 /* etc. */
158 HDC hdc = GetDC(NULL); 162 HDC hdc = GetDC(NULL);
159 int result = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *)&g_RawFrameBufferInfo); 163 int result = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *)&g_RawFrameBufferInfo);
160 ReleaseDC(NULL, hdc); 164 ReleaseDC(NULL, hdc);
161 g_bRawBufferAvailable = result > 0; 165 g_bRawBufferAvailable = result > 0;
162 166
167 //My Asus MyPAL 696 reports the RAWFRAMEBUFFER as available, but with a size of 0 x 0
168 if(g_RawFrameBufferInfo.cxPixels <= 0 || g_RawFrameBufferInfo.cyPixels <= 0){
169 g_bRawBufferAvailable = 0;
170 }
171
163 #if WITHOUT_GAPI 172 #if WITHOUT_GAPI
164 return g_bRawBufferAvailable; 173 return g_bRawBufferAvailable;
165 #endif 174 #endif
166 175
167 #if USE_GAPI_EMU 176 #if USE_GAPI_EMU
245 if( g_hGapiLib ) 254 if( g_hGapiLib )
246 { 255 {
247 FreeLibrary(g_hGapiLib); 256 FreeLibrary(g_hGapiLib);
248 g_hGapiLib = 0; 257 g_hGapiLib = 0;
249 } 258 }
259 SDL_free(device->hidden->gapiInfo);
250 SDL_free(device->hidden); 260 SDL_free(device->hidden);
251 SDL_free(device); 261 SDL_free(device);
252 } 262 }
253 263
254 static SDL_VideoDevice *GAPI_CreateDevice(int devindex) 264 static SDL_VideoDevice *GAPI_CreateDevice(int devindex)
268 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); 278 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
269 if ( device ) { 279 if ( device ) {
270 SDL_memset(device, 0, (sizeof *device)); 280 SDL_memset(device, 0, (sizeof *device));
271 device->hidden = (struct SDL_PrivateVideoData *) 281 device->hidden = (struct SDL_PrivateVideoData *)
272 SDL_malloc((sizeof *device->hidden)); 282 SDL_malloc((sizeof *device->hidden));
283 if(device->hidden){
284 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
285 device->hidden->gapiInfo = (GapiInfo *)SDL_malloc((sizeof(GapiInfo)));
286 if(device->hidden->gapiInfo == NULL)
287 {
288 SDL_free(device->hidden);
289 device->hidden = NULL;
290 }
291 }
273 } 292 }
274 if ( (device == NULL) || (device->hidden == NULL) ) { 293 if ( (device == NULL) || (device->hidden == NULL) ) {
275 SDL_OutOfMemory(); 294 SDL_OutOfMemory();
276 if ( device ) { 295 if ( device ) {
277 SDL_free(device); 296 SDL_free(device);
278 } 297 }
279 return(0); 298 return(0);
280 } 299 }
281 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); 300 SDL_memset(device->hidden->gapiInfo, 0, (sizeof *device->hidden->gapiInfo));
282 301
283 /* Set the function pointers */ 302 /* Set the function pointers */
284 device->VideoInit = GAPI_VideoInit; 303 device->VideoInit = GAPI_VideoInit;
285 device->ListModes = GAPI_ListModes; 304 device->ListModes = GAPI_ListModes;
286 device->SetVideoMode = GAPI_SetVideoMode; 305 device->SetVideoMode = GAPI_SetVideoMode;
310 device->CheckMouseMode = WIN_CheckMouseMode; 329 device->CheckMouseMode = WIN_CheckMouseMode;
311 device->InitOSKeymap = DIB_InitOSKeymap; 330 device->InitOSKeymap = DIB_InitOSKeymap;
312 device->PumpEvents = DIB_PumpEvents; 331 device->PumpEvents = DIB_PumpEvents;
313 332
314 /* Set up the windows message handling functions */ 333 /* Set up the windows message handling functions */
334 WIN_Activate = GAPI_Activate;
315 WIN_RealizePalette = GAPI_RealizePalette; 335 WIN_RealizePalette = GAPI_RealizePalette;
316 WIN_PaletteChanged = GAPI_PaletteChanged; 336 WIN_PaletteChanged = GAPI_PaletteChanged;
317 WIN_WinPAINT = GAPI_WinPAINT; 337 WIN_WinPAINT = GAPI_WinPAINT;
318 HandleMessage = DIB_HandleMessage; 338 HandleMessage = DIB_HandleMessage;
319 339
320 device->free = GAPI_DeleteDevice; 340 device->free = GAPI_DeleteDevice;
321 341
322 /* Load gapi library */ 342 /* Load gapi library */
323 #define gx device->hidden->gxFunc 343 #define gx device->hidden->gapiInfo->gxFunc
324 344
325 LINK( GXOpenDisplay, gx.GXOpenDisplay, "?GXOpenDisplay@@YAHPAUHWND__@@K@Z" ) 345 LINK( GXOpenDisplay, gx.GXOpenDisplay, "?GXOpenDisplay@@YAHPAUHWND__@@K@Z" )
326 LINK( GXCloseDisplay, gx.GXCloseDisplay, "?GXCloseDisplay@@YAHXZ" ) 346 LINK( GXCloseDisplay, gx.GXCloseDisplay, "?GXCloseDisplay@@YAHXZ" )
327 LINK( GXBeginDraw, gx.GXBeginDraw, "?GXBeginDraw@@YAPAXXZ" ) 347 LINK( GXBeginDraw, gx.GXBeginDraw, "?GXBeginDraw@@YAPAXXZ" )
328 LINK( GXEndDraw, gx.GXEndDraw, "?GXEndDraw@@YAHXZ" ) 348 LINK( GXEndDraw, gx.GXEndDraw, "?GXEndDraw@@YAHXZ" )
367 #endif 387 #endif
368 /* fill a device properties */ 388 /* fill a device properties */
369 389
370 if( !useVga ) 390 if( !useVga )
371 { 391 {
372 this->hidden->gxProperties = this->hidden->gxFunc.GXGetDisplayProperties(); 392 gapi->gxProperties = gapi->gxFunc.GXGetDisplayProperties();
373 this->hidden->needUpdate = 1; 393 gapi->needUpdate = 1;
374 this->hidden->hiresFix = 0; 394 gapi->hiresFix = 0;
375 this->hidden->useVga = 0; 395 gapi->useVga = 0;
376 this->hidden->useGXOpenDisplay = 1; 396 gapi->useGXOpenDisplay = 1;
377 397
378 #ifdef _ARM_ 398 #ifdef _ARM_
379 /* check some devices and extract addition info */ 399 /* check some devices and extract addition info */
380 SystemParametersInfo( SPI_GETOEMINFO, sizeof( oemstr ), oemstr, 0 ); 400 SystemParametersInfo( SPI_GETOEMINFO, sizeof( oemstr ), oemstr, 0 );
381 401
382 // buggy iPaq38xx 402 // buggy iPaq38xx
383 if ((oemstr[12] == 'H') && (oemstr[13] == '3') && (oemstr[14] == '8') && (this->hidden->gxProperties.cbxPitch > 0)) 403 if ((oemstr[12] == 'H') && (oemstr[13] == '3') && (oemstr[14] == '8') && (gapi->gxProperties.cbxPitch > 0))
384 { 404 {
385 this->hidden->videoMem = (PIXEL*)0xac0755a0; 405 gapi->videoMem = (PIXEL*)0xac0755a0;
386 this->hidden->gxProperties.cbxPitch = -640; 406 gapi->gxProperties.cbxPitch = -640;
387 this->hidden->gxProperties.cbyPitch = 2; 407 gapi->gxProperties.cbyPitch = 2;
388 this->hidden->needUpdate = 0; 408 gapi->needUpdate = 0;
389 } 409 }
390 #if (EMULATE_AXIM_X30 == 0) 410 #if (EMULATE_AXIM_X30 == 0)
391 // buggy Dell Axim X30 411 // buggy Dell Axim X30
392 if( _tcsncmp(oemstr, L"Dell Axim X30", 13) == 0 ) 412 if( _tcsncmp(oemstr, L"Dell Axim X30", 13) == 0 )
393 #endif 413 #endif
398 418
399 gxInfo.Version = 100; 419 gxInfo.Version = 100;
400 result = ExtEscape(hdc, GETGXINFO, 0, NULL, sizeof(gxInfo), (char *)&gxInfo); 420 result = ExtEscape(hdc, GETGXINFO, 0, NULL, sizeof(gxInfo), (char *)&gxInfo);
401 if( result > 0 ) 421 if( result > 0 )
402 { 422 {
403 this->hidden->useGXOpenDisplay = 0; 423 gapi->useGXOpenDisplay = 0;
404 this->hidden->videoMem = gxInfo.pvFrameBuffer; 424 gapi->videoMem = gxInfo.pvFrameBuffer;
405 this->hidden->needUpdate = 0; 425 gapi->needUpdate = 0;
406 this->hidden->gxProperties.cbxPitch = 2; 426 gapi->gxProperties.cbxPitch = 2;
407 this->hidden->gxProperties.cbyPitch = 480; 427 gapi->gxProperties.cbyPitch = 480;
408 this->hidden->gxProperties.cxWidth = gxInfo.cxWidth; 428 gapi->gxProperties.cxWidth = gxInfo.cxWidth;
409 this->hidden->gxProperties.cyHeight = gxInfo.cyHeight; 429 gapi->gxProperties.cyHeight = gxInfo.cyHeight;
410 this->hidden->gxProperties.ffFormat = gxInfo.ffFormat; 430 gapi->gxProperties.ffFormat = gxInfo.ffFormat;
411 } 431 }
412 } 432 }
413 #endif 433 #endif
414 } else 434 } else
415 { 435 {
416 this->hidden->needUpdate = 0; 436 gapi->needUpdate = 0;
417 this->hidden->hiresFix = 0; 437 gapi->hiresFix = 0;
418 this->hidden->gxProperties.cBPP = g_RawFrameBufferInfo.wBPP; 438 gapi->gxProperties.cBPP = g_RawFrameBufferInfo.wBPP;
419 this->hidden->gxProperties.cbxPitch = g_RawFrameBufferInfo.cxStride; 439 gapi->gxProperties.cbxPitch = g_RawFrameBufferInfo.cxStride;
420 this->hidden->gxProperties.cbyPitch = g_RawFrameBufferInfo.cyStride; 440 gapi->gxProperties.cbyPitch = g_RawFrameBufferInfo.cyStride;
421 this->hidden->gxProperties.cxWidth = g_RawFrameBufferInfo.cxPixels; 441 gapi->gxProperties.cxWidth = g_RawFrameBufferInfo.cxPixels;
422 this->hidden->gxProperties.cyHeight = g_RawFrameBufferInfo.cyPixels; 442 gapi->gxProperties.cyHeight = g_RawFrameBufferInfo.cyPixels;
423 this->hidden->videoMem = g_RawFrameBufferInfo.pFramePointer; 443 gapi->videoMem = g_RawFrameBufferInfo.pFramePointer;
424 this->hidden->useVga = 1; 444 gapi->useVga = 1;
425 445
426 switch( g_RawFrameBufferInfo.wFormat ) 446 switch( g_RawFrameBufferInfo.wFormat )
427 { 447 {
428 case FORMAT_565: 448 case FORMAT_565:
429 this->hidden->gxProperties.ffFormat = kfDirect565; 449 gapi->gxProperties.ffFormat = kfDirect565;
430 break; 450 break;
431 case FORMAT_555: 451 case FORMAT_555:
432 this->hidden->gxProperties.ffFormat = kfDirect555; 452 gapi->gxProperties.ffFormat = kfDirect555;
433 break; 453 break;
434 default: 454 default:
435 /* unknown pixel format, try define by BPP! */ 455 /* unknown pixel format, try define by BPP! */
436 switch( g_RawFrameBufferInfo.wBPP ) 456 switch( g_RawFrameBufferInfo.wBPP )
437 { 457 {
438 case 4: 458 case 4:
439 case 8: 459 case 8:
440 this->hidden->gxProperties.ffFormat = kfDirect; 460 gapi->gxProperties.ffFormat = kfDirect;
441 case 16: 461 case 16:
442 this->hidden->gxProperties.ffFormat = kfDirect565; 462 gapi->gxProperties.ffFormat = kfDirect565;
443 default: 463 default:
444 this->hidden->gxProperties.ffFormat = kfDirect; 464 gapi->gxProperties.ffFormat = kfDirect;
445 break; 465 break;
446 } 466 }
447 } 467 }
448 } 468 }
449 469
450 if( this->hidden->gxProperties.cBPP != 16 ) 470 if( gapi->gxProperties.cBPP != 16 )
451 { 471 {
452 this->hidden->gapiOrientation = SDL_ORIENTATION_UP; 472 gapi->gapiOrientation = SDL_ORIENTATION_UP;
453 } else 473 } else
454 if( (this->hidden->gxProperties.cbxPitch > 0) && (this->hidden->gxProperties.cbyPitch > 0 )) 474 if( (gapi->gxProperties.cbxPitch > 0) && (gapi->gxProperties.cbyPitch > 0 ))
455 { 475 {
456 this->hidden->gapiOrientation = SDL_ORIENTATION_UP; 476 gapi->gapiOrientation = SDL_ORIENTATION_UP;
457 } else 477 } else
458 if( (this->hidden->gxProperties.cbxPitch > 0) && (this->hidden->gxProperties.cbyPitch < 0 )) 478 if( (gapi->gxProperties.cbxPitch > 0) && (gapi->gxProperties.cbyPitch < 0 ))
459 { 479 {
460 this->hidden->gapiOrientation = SDL_ORIENTATION_RIGHT; // ipaq 3660 480 gapi->gapiOrientation = SDL_ORIENTATION_RIGHT; // ipaq 3660
461 } else 481 } else
462 if( (this->hidden->gxProperties.cbxPitch < 0) && (this->hidden->gxProperties.cbyPitch > 0 )) 482 if( (gapi->gxProperties.cbxPitch < 0) && (gapi->gxProperties.cbyPitch > 0 ))
463 { 483 {
464 this->hidden->gapiOrientation = SDL_ORIENTATION_LEFT; // ipaq 3800 484 gapi->gapiOrientation = SDL_ORIENTATION_LEFT; // ipaq 3800
465 } 485 }
466 } 486 }
467 487
468 static void GAPI_CreatePalette(int ncolors, SDL_Color *colors) 488 static void GAPI_CreatePalette(int ncolors, SDL_Color *colors)
469 { 489 {
535 /* set up normal and landscape mode */ 555 /* set up normal and landscape mode */
536 GAPI_AddMode(this, bpp, gapi->gxProperties.cyHeight, gapi->gxProperties.cxWidth); 556 GAPI_AddMode(this, bpp, gapi->gxProperties.cyHeight, gapi->gxProperties.cxWidth);
537 GAPI_AddMode(this, bpp, gapi->gxProperties.cxWidth, gapi->gxProperties.cyHeight); 557 GAPI_AddMode(this, bpp, gapi->gxProperties.cxWidth, gapi->gxProperties.cyHeight);
538 } 558 }
539 559
540 /* Determine the current screen size */ 560 /* Determine the current screen size.
541 this->info.current_w = gapi->gxProperties.cxWidth; 561 * This is NOT necessarily the size of the Framebuffer or GAPI, as they return
542 this->info.current_h = gapi->gxProperties.cyHeight; 562 * the displaysize in ORIENTATION_UP */
563 this->info.current_w = GetSystemMetrics(SM_CXSCREEN);
564 this->info.current_h = GetSystemMetrics(SM_CYSCREEN);
543 565
544 /* Sort the mode lists */ 566 /* Sort the mode lists */
545 for ( i=0; i<NUM_MODELISTS; ++i ) { 567 for ( i=0; i<NUM_MODELISTS; ++i ) {
546 if ( gapi->SDL_nummodes[i] > 0 ) { 568 if ( gapi->SDL_nummodes[i] > 0 ) {
547 SDL_qsort(gapi->SDL_modelist[i], gapi->SDL_nummodes[i], sizeof *gapi->SDL_modelist[i], cmpmodes); 569 SDL_qsort(gapi->SDL_modelist[i], gapi->SDL_nummodes[i], sizeof *gapi->SDL_modelist[i], cmpmodes);
548 } 570 }
549 } 571 }
550 572
551 vformat->BitsPerPixel = this->hidden->gxProperties.cBPP < 8 ? 16 : (unsigned char)this->hidden->gxProperties.cBPP; 573 vformat->BitsPerPixel = gapi->gxProperties.cBPP < 8 ? 16 : (unsigned char)gapi->gxProperties.cBPP;
552 574
553 // Get color mask 575 // Get color mask
554 if (this->hidden->gxProperties.ffFormat & kfDirect565) { 576 if (gapi->gxProperties.ffFormat & kfDirect565) {
555 vformat->BitsPerPixel = 16; 577 vformat->BitsPerPixel = 16;
556 vformat->Rmask = 0x0000f800; 578 vformat->Rmask = 0x0000f800;
557 vformat->Gmask = 0x000007e0; 579 vformat->Gmask = 0x000007e0;
558 vformat->Bmask = 0x0000001f; 580 vformat->Bmask = 0x0000001f;
559 this->hidden->videoMode = GAPI_DIRECT_565; 581 gapi->videoMode = GAPI_DIRECT_565;
560 } 582 }
561 else 583 else
562 if (this->hidden->gxProperties.ffFormat & kfDirect555) { 584 if (gapi->gxProperties.ffFormat & kfDirect555) {
563 vformat->BitsPerPixel = 16; 585 vformat->BitsPerPixel = 16;
564 vformat->Rmask = 0x00007c00; 586 vformat->Rmask = 0x00007c00;
565 vformat->Gmask = 0x000003e0; 587 vformat->Gmask = 0x000003e0;
566 vformat->Bmask = 0x0000001f; 588 vformat->Bmask = 0x0000001f;
567 this->hidden->videoMode = GAPI_DIRECT_555; 589 gapi->videoMode = GAPI_DIRECT_555;
568 } 590 }
569 else 591 else
570 if ((this->hidden->gxProperties.ffFormat & kfDirect) && (this->hidden->gxProperties.cBPP < 8)) { 592 if ((gapi->gxProperties.ffFormat & kfDirect) && (gapi->gxProperties.cBPP < 8)) {
571 // We'll perform the conversion 593 // We'll perform the conversion
572 vformat->BitsPerPixel = 16; 594 vformat->BitsPerPixel = 16;
573 vformat->Rmask = 0x0000f800; // 16 bit 565 595 vformat->Rmask = 0x0000f800; // 16 bit 565
574 vformat->Gmask = 0x000007e0; 596 vformat->Gmask = 0x000007e0;
575 vformat->Bmask = 0x0000001f; 597 vformat->Bmask = 0x0000001f;
576 if (this->hidden->gxProperties.ffFormat & kfDirectInverted) 598 if (gapi->gxProperties.ffFormat & kfDirectInverted)
577 this->hidden->invert = (1 << this->hidden->gxProperties.cBPP) - 1; 599 gapi->invert = (1 << gapi->gxProperties.cBPP) - 1;
578 this->hidden->colorscale = this->hidden->gxProperties.cBPP < 8 ? 8 - this->hidden->gxProperties.cBPP : 0; 600 gapi->colorscale = gapi->gxProperties.cBPP < 8 ? 8 - gapi->gxProperties.cBPP : 0;
579 this->hidden->videoMode = GAPI_MONO; 601 gapi->videoMode = GAPI_MONO;
580 } 602 }
581 else 603 else
582 if (this->hidden->gxProperties.ffFormat & kfPalette) { 604 if (gapi->gxProperties.ffFormat & kfPalette) {
583 this->hidden->videoMode = GAPI_PALETTE; 605 gapi->videoMode = GAPI_PALETTE;
584 } 606 }
585 607
586 /* We're done! */ 608 /* We're done! */
587 return(0); 609 return(0);
588 } 610 }
589 611
590 SDL_Rect **GAPI_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) 612 SDL_Rect **GAPI_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
591 { 613 {
592 return(this->hidden->SDL_modelist[((format->BitsPerPixel+7)/8)-1]); 614 return(gapi->SDL_modelist[((format->BitsPerPixel+7)/8)-1]);
593 // return (SDL_Rect **) -1; 615 // return (SDL_Rect **) -1;
594 } 616 }
595 617
596 SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current, 618 SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current,
597 int width, int height, int bpp, Uint32 flags) 619 int width, int height, int bpp, Uint32 flags)
598 { 620 {
599 SDL_Surface *video; 621 SDL_Surface *video;
600 Uint32 Rmask, Gmask, Bmask; 622 Uint32 Rmask, Gmask, Bmask;
601 DWORD style; 623 DWORD style;
602 SDL_Rect allScreen; 624 SDL_Rect allScreen;
625 SDL_ScreenOrientation systemOrientation;
603 626
604 if( bpp < 4 ) 627 if( bpp < 4 )
605 { 628 {
606 SDL_SetError("1 bpp and 2 bpp modes is not implemented yet!"); 629 SDL_SetError("1 bpp and 2 bpp modes is not implemented yet!");
607 return 0; 630 return 0;
619 Bmask = 0; 642 Bmask = 0;
620 break; 643 break;
621 case 15: 644 case 15:
622 case 16: 645 case 16:
623 /* Default is 565 unless the display is specifically 555 */ 646 /* Default is 565 unless the display is specifically 555 */
624 if (this->hidden->gxProperties.ffFormat & kfDirect555) { 647 if (gapi->gxProperties.ffFormat & kfDirect555) {
625 Rmask = 0x00007c00; 648 Rmask = 0x00007c00;
626 Gmask = 0x000003e0; 649 Gmask = 0x000003e0;
627 Bmask = 0x0000001f; 650 Bmask = 0x0000001f;
628 } 651 }
629 else { 652 else {
649 return(NULL); 672 return(NULL);
650 } 673 }
651 } 674 }
652 675
653 gapi->userOrientation = SDL_ORIENTATION_UP; 676 gapi->userOrientation = SDL_ORIENTATION_UP;
654 gapi->systemOrientation = SDL_ORIENTATION_UP; 677 systemOrientation = SDL_ORIENTATION_UP;
655 video->flags = SDL_FULLSCREEN; /* Clear flags, GAPI supports fullscreen only */ 678 video->flags = SDL_FULLSCREEN; /* Clear flags, GAPI supports fullscreen only */
656 679
657 /* GAPI or VGA? */ 680 /* GAPI or VGA? */
658 if( g_hGapiLib ) 681 if( g_hGapiLib )
659 { 682 {
662 && (((unsigned)width != gapi->gxProperties.cyHeight) || ((unsigned)height != gapi->gxProperties.cxWidth))) 685 && (((unsigned)width != gapi->gxProperties.cyHeight) || ((unsigned)height != gapi->gxProperties.cxWidth)))
663 FillStructs(this, 1); // gapi is found but we use VGA resolution 686 FillStructs(this, 1); // gapi is found but we use VGA resolution
664 } else 687 } else
665 FillStructs(this, 1); 688 FillStructs(this, 1);
666 689
667 if ( !this->hidden->needUpdate && !this->hidden->videoMem) { 690 if ( !gapi->needUpdate && !gapi->videoMem) {
668 SDL_SetError("Couldn't get address of video memory, may be unsupported device or bug"); 691 SDL_SetError("Couldn't get address of video memory, may be unsupported device or bug");
669 return(NULL); 692 return(NULL);
670 } 693 }
671 694
672 /* detect user landscape mode */ 695 /* detect user landscape mode */
673 if( (width > height) && (gapi->gxProperties.cxWidth < gapi->gxProperties.cyHeight)) 696 if( (width > height) && (gapi->gxProperties.cxWidth < gapi->gxProperties.cyHeight))
674 gapi->userOrientation = SDL_ORIENTATION_RIGHT; 697 gapi->userOrientation = SDL_ORIENTATION_RIGHT;
675 698
676 if(GetSystemMetrics(SM_CYSCREEN) < GetSystemMetrics(SM_CXSCREEN)) 699 if(GetSystemMetrics(SM_CYSCREEN) < GetSystemMetrics(SM_CXSCREEN))
677 gapi->systemOrientation = SDL_ORIENTATION_RIGHT; 700 systemOrientation = SDL_ORIENTATION_RIGHT;
678 701
679 /* shall we apply hires fix? for example when we do not use hires resource */ 702 /* shall we apply hires fix? for example when we do not use hires resource */
680 gapi->hiresFix = 0; 703 gapi->hiresFix = 0;
681 if( gapi->systemOrientation == gapi->userOrientation ) 704 if( systemOrientation == gapi->userOrientation )
682 { 705 {
683 if( (width > GetSystemMetrics(SM_CXSCREEN)) || (height > GetSystemMetrics(SM_CYSCREEN))) 706 if( (width > GetSystemMetrics(SM_CXSCREEN)) || (height > GetSystemMetrics(SM_CYSCREEN)))
684 gapi->hiresFix = 1; 707 gapi->hiresFix = 1;
685 } else 708 } else
686 if( (width > GetSystemMetrics(SM_CYSCREEN)) || (height > GetSystemMetrics(SM_CXSCREEN))) 709 if( (width > GetSystemMetrics(SM_CYSCREEN)) || (height > GetSystemMetrics(SM_CXSCREEN)))
698 switch( gapi->gapiOrientation ) 721 switch( gapi->gapiOrientation )
699 { 722 {
700 case SDL_ORIENTATION_UP: 723 case SDL_ORIENTATION_UP:
701 case SDL_ORIENTATION_RIGHT: 724 case SDL_ORIENTATION_RIGHT:
702 case SDL_ORIENTATION_LEFT: 725 case SDL_ORIENTATION_LEFT:
703 if( (this->hidden->videoMode == GAPI_MONO) ) 726 if( (gapi->videoMode == GAPI_MONO) )
704 gapi->startOffset = -gapi->gxProperties.cbxPitch + 1; // monochrome mode 727 gapi->startOffset = -gapi->gxProperties.cbxPitch + 1; // monochrome mode
705 else 728 else
706 gapi->startOffset = gapi->gxProperties.cbyPitch * (gapi->gxProperties.cyHeight - 1); 729 gapi->startOffset = gapi->gxProperties.cbyPitch * (gapi->gxProperties.cyHeight - 1);
707 730
708 gapi->dstLineStep = gapi->gxProperties.cbxPitch; 731 gapi->dstLineStep = gapi->gxProperties.cbxPitch;
709 gapi->dstPixelStep = -gapi->gxProperties.cbyPitch; 732 gapi->dstPixelStep = -gapi->gxProperties.cbyPitch;
710 break; 733 break;
711 } 734 }
712 } 735 }
713 736
714 video->w = this->hidden->w = width; 737 video->w = gapi->w = width;
715 video->h = this->hidden->h = height; 738 video->h = gapi->h = height;
716 video->pitch = SDL_CalculatePitch(video); 739 video->pitch = SDL_CalculatePitch(video);
717 740
718 /* Small fix for WinCE/Win32 - when activating window 741 /* Small fix for WinCE/Win32 - when activating window
719 SDL_VideoSurface is equal to zero, so activating code 742 SDL_VideoSurface is equal to zero, so activating code
720 is not called properly for fullscreen windows because 743 is not called properly for fullscreen windows because
727 750
728 if (!SDL_windowid) 751 if (!SDL_windowid)
729 SetWindowLong(SDL_Window, GWL_STYLE, style); 752 SetWindowLong(SDL_Window, GWL_STYLE, style);
730 753
731 /* Allocate bitmap */ 754 /* Allocate bitmap */
732 if(gapiBuffer) 755 if( gapi->buffer )
733 { 756 {
734 SDL_free(gapiBuffer); 757 SDL_free( gapi->buffer );
735 gapiBuffer = NULL; 758 gapi->buffer = NULL;
736 } 759 }
737 gapiBuffer = SDL_malloc(video->h * video->pitch); 760 gapi->buffer = SDL_malloc(video->h * video->pitch);
738 video->pixels = gapiBuffer; 761 video->pixels = gapi->buffer;
739 762
740 if ( ! this->hidden->buffer ) { 763 if ( ! gapi->buffer ) {
741 SDL_SetError("Couldn't allocate buffer for requested mode"); 764 SDL_SetError("Couldn't allocate buffer for requested mode");
742 return(NULL); 765 return(NULL);
743 } 766 }
744 767
745 SDL_memset(gapiBuffer, 255, video->h * video->pitch); 768 SDL_memset(gapi->buffer, 255, video->h * video->pitch);
746 MoveWindow(SDL_Window, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), FALSE); 769 MoveWindow(SDL_Window, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), FALSE);
747 ShowWindow(SDL_Window, SW_SHOW); 770 ShowWindow(SDL_Window, SW_SHOW);
748 SetForegroundWindow(SDL_Window); 771 SetForegroundWindow(SDL_Window);
749 772
750 /* JC 14 Mar 2006 773 /* JC 14 Mar 2006
752 Especially if the user decides to use dialog boxes or assert()! 775 Especially if the user decides to use dialog boxes or assert()!
753 */ 776 */
754 WIN_FlushMessageQueue(); 777 WIN_FlushMessageQueue();
755 778
756 /* Open GAPI display */ 779 /* Open GAPI display */
757 if( !gapi->useVga && this->hidden->useGXOpenDisplay && !this->hidden->alreadyGXOpened ) 780 if( !gapi->useVga && gapi->useGXOpenDisplay && !gapi->alreadyGXOpened )
758 { 781 {
759 this->hidden->alreadyGXOpened = 1; 782 gapi->alreadyGXOpened = 1;
760 if( !gapi->gxFunc.GXOpenDisplay(SDL_Window, GX_FULLSCREEN) ) 783 if( !gapi->gxFunc.GXOpenDisplay(SDL_Window, GX_FULLSCREEN) )
761 { 784 {
762 SDL_SetError("Couldn't initialize GAPI"); 785 SDL_SetError("Couldn't initialize GAPI");
763 return(NULL); 786 return(NULL);
764 } 787 }
765 } 788 }
789
790 if(gapi->useVga)
791 gapi->coordinateTransform = (4 - systemOrientation + gapi->userOrientation) % 4;
792 else
793 gapi->coordinateTransform = gapi->userOrientation;
766 794
767 #if REPORT_VIDEO_INFO 795 #if REPORT_VIDEO_INFO
768 printf("Video properties:\n"); 796 printf("Video properties:\n");
769 printf("display bpp: %d\n", gapi->gxProperties.cBPP); 797 printf("display bpp: %d\n", gapi->gxProperties.cBPP);
770 printf("display width: %d\n", gapi->gxProperties.cxWidth); 798 printf("display width: %d\n", gapi->gxProperties.cxWidth);
773 printf("system display height: %d\n", GetSystemMetrics(SM_CYSCREEN)); 801 printf("system display height: %d\n", GetSystemMetrics(SM_CYSCREEN));
774 printf("x pitch: %d\n", gapi->gxProperties.cbxPitch); 802 printf("x pitch: %d\n", gapi->gxProperties.cbxPitch);
775 printf("y pitch: %d\n", gapi->gxProperties.cbyPitch); 803 printf("y pitch: %d\n", gapi->gxProperties.cbyPitch);
776 printf("gapi flags: 0x%x\n", gapi->gxProperties.ffFormat); 804 printf("gapi flags: 0x%x\n", gapi->gxProperties.ffFormat);
777 printf("user orientation: %d\n", gapi->userOrientation); 805 printf("user orientation: %d\n", gapi->userOrientation);
778 printf("system orientation: %d\n", gapi->userOrientation); 806 printf("system orientation: %d\n", systemOrientation);
779 printf("gapi orientation: %d\n", gapi->gapiOrientation); 807 printf("gapi orientation: %d\n", gapi->gapiOrientation);
780 808
781 809
782 if( !gapi->useVga && this->hidden->useGXOpenDisplay && gapi->needUpdate) 810 if( !gapi->useVga && gapi->useGXOpenDisplay && gapi->needUpdate)
783 { 811 {
784 gapi->videoMem = gapi->gxFunc.GXBeginDraw(); 812 gapi->videoMem = gapi->gxFunc.GXBeginDraw();
785 gapi->gxFunc.GXEndDraw(); 813 gapi->gxFunc.GXEndDraw();
786 } 814 }
787 815
791 printf("VGA is available on the device: %d\n", g_bRawBufferAvailable); 819 printf("VGA is available on the device: %d\n", g_bRawBufferAvailable);
792 printf("use raw framebuffer: %d\n", gapi->useVga); 820 printf("use raw framebuffer: %d\n", gapi->useVga);
793 printf("video surface bpp: %d\n", video->format->BitsPerPixel); 821 printf("video surface bpp: %d\n", video->format->BitsPerPixel);
794 printf("video surface width: %d\n", video->w); 822 printf("video surface width: %d\n", video->w);
795 printf("video surface height: %d\n", video->h); 823 printf("video surface height: %d\n", video->h);
824 printf("mouse/arrows transformation angle: %d\n", gapi->coordinateTransform);
796 #endif 825 #endif
797 826
798 827
799 /* Blank screen */ 828 /* Blank screen */
800 allScreen.x = allScreen.y = 0; 829 allScreen.x = allScreen.y = 0;
1141 { 1170 {
1142 int i, j; 1171 int i, j;
1143 /* Destroy the window and everything associated with it */ 1172 /* Destroy the window and everything associated with it */
1144 if ( SDL_Window ) 1173 if ( SDL_Window )
1145 { 1174 {
1146 if ((g_hGapiLib != 0) && this && this->hidden && this->hidden->gxFunc.GXCloseDisplay && !this->hidden->useVga) 1175 if ((g_hGapiLib != 0) && this && gapi && gapi->gxFunc.GXCloseDisplay && !gapi->useVga)
1147 this->hidden->gxFunc.GXCloseDisplay(); 1176 gapi->gxFunc.GXCloseDisplay();
1148 1177
1149 if (this->screen->pixels != NULL) 1178 if (this->screen->pixels != NULL)
1150 { 1179 {
1151 SDL_free(this->screen->pixels); 1180 SDL_free(this->screen->pixels);
1152 this->screen->pixels = NULL; 1181 this->screen->pixels = NULL;
1182 1211
1183 } 1212 }
1184 1213
1185 } 1214 }
1186 1215
1216 static void GAPI_Activate(_THIS, BOOL active, BOOL minimized)
1217 {
1218 //Nothing to do here (as far as I know)
1219 }
1220
1187 static void GAPI_RealizePalette(_THIS) 1221 static void GAPI_RealizePalette(_THIS)
1188 { 1222 {
1189 OutputDebugString(TEXT("GAPI_RealizePalette NOT IMPLEMENTED !\r\n")); 1223 OutputDebugString(TEXT("GAPI_RealizePalette NOT IMPLEMENTED !\r\n"));
1190 } 1224 }
1191 1225
1213 // CreateDIBSection does not support 332 pixel format on wce 1247 // CreateDIBSection does not support 332 pixel format on wce
1214 if( gapi->gxProperties.cBPP == 8 ) return; 1248 if( gapi->gxProperties.cBPP == 8 ) return;
1215 1249
1216 // DIB Header 1250 // DIB Header
1217 pHeader->biSize = sizeof(BITMAPINFOHEADER); 1251 pHeader->biSize = sizeof(BITMAPINFOHEADER);
1218 pHeader->biWidth = this->hidden->w; 1252 pHeader->biWidth = gapi->w;
1219 pHeader->biHeight = -this->hidden->h; 1253 pHeader->biHeight = -gapi->h;
1220 pHeader->biPlanes = 1; 1254 pHeader->biPlanes = 1;
1221 pHeader->biBitCount = bpp; 1255 pHeader->biBitCount = bpp;
1222 pHeader->biCompression = BI_RGB; 1256 pHeader->biCompression = BI_RGB;
1223 pHeader->biSizeImage = (this->hidden->w * this->hidden->h * bpp) / 8; 1257 pHeader->biSizeImage = (gapi->w * gapi->h * bpp) / 8;
1224 1258
1225 // Color masks 1259 // Color masks
1226 if( bpp == 16 ) 1260 if( bpp == 16 )
1227 { 1261 {
1228 pColors[0] = REDMASK; 1262 pColors[0] = REDMASK;
1233 // Create the DIB 1267 // Create the DIB
1234 hb = CreateDIBSection( 0, pBMI, DIB_RGB_COLORS, (void**)&bitmapData, 0, 0 ); 1268 hb = CreateDIBSection( 0, pBMI, DIB_RGB_COLORS, (void**)&bitmapData, 0, 0 );
1235 1269
1236 // copy data 1270 // copy data
1237 // FIXME: prevent misalignment, but I've never seen non aligned width of screen 1271 // FIXME: prevent misalignment, but I've never seen non aligned width of screen
1238 memcpy(bitmapData, this->hidden->buffer, pHeader->biSizeImage); 1272 memcpy(bitmapData, gapi->buffer, pHeader->biSizeImage);
1239 srcDC = CreateCompatibleDC(hdc); 1273 srcDC = CreateCompatibleDC(hdc);
1240 prevObject = SelectObject(srcDC, hb); 1274 prevObject = SelectObject(srcDC, hb);
1241 1275
1242 BitBlt(hdc, 0, 0, this->hidden->w, this->hidden->h, srcDC, 0, 0, SRCCOPY); 1276 BitBlt(hdc, 0, 0, gapi->w, gapi->h, srcDC, 0, 0, SRCCOPY);
1243 1277
1244 SelectObject(srcDC, prevObject); 1278 SelectObject(srcDC, prevObject);
1245 DeleteObject(hb); 1279 DeleteObject(hb);
1246 DeleteDC(srcDC); 1280 DeleteDC(srcDC);
1247 } 1281 }