Skip to content

Latest commit

 

History

History
1290 lines (1113 loc) · 35.5 KB

SDL_gapivideo.c

File metadata and controls

1290 lines (1113 loc) · 35.5 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Dec 31, 2011
Dec 31, 2011
3
Copyright (C) 1997-2012 Sam Lantinga
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19
20
21
Sam Lantinga
slouken@libsdl.org
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
23
24
25
26
27
28
29
30
31
32
33
34
35
/* Pocket PC GAPI SDL video driver implementation;
Implemented by Dmitry Yakimov - support@activekitten.com
Inspired by http://arisme.free.fr/ports/SDL.php
*/
// TODO: copy surface on window when lost focus
// TODO: test buttons rotation
// TODO: test on be300 and HPC ( check WinDib fullscreen keys catching )
// TODO: test on smartphones
// TODO: windib on SH3 PPC2000 landscape test
// TODO: optimize 8bpp landscape mode
Mar 4, 2006
Mar 4, 2006
36
37
38
39
40
41
42
43
44
45
// there is some problems in runnings apps from a device landscape mode
// due to WinCE bugs. Some works and some - does not.
// TODO: finish Axim Dell X30 and user landscape mode, device landscape mode
// TODO: finish Axim Dell X30 user portrait, device landscape stylus conversion
// TODO: fix running GAPI apps from landscape mode -
// wince goes to portrait mode, but does not update video memory
#include "SDL.h"
#include "SDL_error.h"
46
47
#include "SDL_video.h"
#include "SDL_mouse.h"
Feb 16, 2006
Feb 16, 2006
48
49
50
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
Mar 4, 2006
Mar 4, 2006
51
52
53
#include "../wincommon/SDL_syswm_c.h"
#include "../wincommon/SDL_sysmouse_c.h"
#include "../windib/SDL_dibevents_c.h"
Feb 16, 2009
Feb 16, 2009
55
#include "../windib/SDL_gapidibvideo.h"
56
57
#include "SDL_gapivideo.h"
Feb 16, 2009
Feb 16, 2009
58
59
#define gapi this->hidden->gapiInfo
60
61
62
63
64
65
66
67
68
69
#define GAPIVID_DRIVER_NAME "gapi"
#if defined(DEBUG) || defined (_DEBUG) || defined(NDEBUG)
#define REPORT_VIDEO_INFO 1
#else
#define REPORT_VIDEO_INFO 0
#endif
// for testing with GapiEmu
#define USE_GAPI_EMU 0
Mar 4, 2006
Mar 4, 2006
70
71
#define EMULATE_AXIM_X30 0
#define WITHOUT_GAPI 0
72
73
74
75
76
#if USE_GAPI_EMU && !REPORT_VIDEO_INFO
#pragma message("Warning: Using GapiEmu in release build. I assume you'd like to set USE_GAPI_EMU to zero.")
#endif
Jan 3, 2008
Jan 3, 2008
77
78
79
80
81
82
83
84
#ifndef _T
#define _T(x) L##x
#endif
#ifndef ASSERT
#define ASSERT(x)
#endif
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// defined and used in SDL_sysevents.c
extern HINSTANCE aygshell;
extern void SDL_UnregisterApp();
extern int DIB_AddMode(_THIS, int bpp, int w, int h);
/* Initialization/Query functions */
static int GAPI_VideoInit(_THIS, SDL_PixelFormat *vformat);
static SDL_Rect **GAPI_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
static SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
static int GAPI_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
static void GAPI_VideoQuit(_THIS);
/* Hardware surface functions */
static int GAPI_AllocHWSurface(_THIS, SDL_Surface *surface);
static int GAPI_LockHWSurface(_THIS, SDL_Surface *surface);
static void GAPI_UnlockHWSurface(_THIS, SDL_Surface *surface);
static void GAPI_FreeHWSurface(_THIS, SDL_Surface *surface);
/* Windows message handling functions, will not be processed */
Feb 16, 2009
Feb 16, 2009
104
static void GAPI_Activate(_THIS, BOOL active, BOOL minimized);
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
static void GAPI_RealizePalette(_THIS);
static void GAPI_PaletteChanged(_THIS, HWND window);
static void GAPI_WinPAINT(_THIS, HDC hdc);
/* etc. */
static void GAPI_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
static HMODULE g_hGapiLib = 0;
#define LINK(type,name,import) \
if( g_hGapiLib ) \
name = (PFN##type)GetProcAddress( g_hGapiLib, _T(import) );
static char g_bRawBufferAvailable = 0;
/* GAPI driver bootstrap functions */
/* hi res definitions */
typedef struct _RawFrameBufferInfo
{
WORD wFormat;
WORD wBPP;
VOID *pFramePointer;
int cxStride;
int cyStride;
int cxPixels;
int cyPixels;
} RawFrameBufferInfo;
static struct _RawFrameBufferInfo g_RawFrameBufferInfo = {0};
#define GETRAWFRAMEBUFFER 0x00020001
#define FORMAT_565 1
#define FORMAT_555 2
Mar 4, 2006
Mar 4, 2006
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#define FORMAT_OTHER 3
/* Dell Axim x30 hangs when we use GAPI from landscape,
so lets avoid using GxOpenDisplay there via GETGXINFO trick
It seems that GAPI subsystem use the same ExtEscape code.
*/
#define GETGXINFO 0x00020000
typedef struct GXDeviceInfo
{
long Version; //00 (should filled with 100 before calling ExtEscape)
void * pvFrameBuffer; //04
unsigned long cbStride; //08
unsigned long cxWidth; //0c
unsigned long cyHeight; //10
unsigned long cBPP; //14
unsigned long ffFormat; //18
char Unused[0x84-7*4];
} GXDeviceInfo;
158
159
160
161
162
163
164
165
166
static int GAPI_Available(void)
{
// try to use VGA display, even on emulator
HDC hdc = GetDC(NULL);
int result = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *)&g_RawFrameBufferInfo);
ReleaseDC(NULL, hdc);
g_bRawBufferAvailable = result > 0;
Feb 16, 2009
Feb 16, 2009
167
168
169
170
171
//My Asus MyPAL 696 reports the RAWFRAMEBUFFER as available, but with a size of 0 x 0
if(g_RawFrameBufferInfo.cxPixels <= 0 || g_RawFrameBufferInfo.cyPixels <= 0){
g_bRawBufferAvailable = 0;
}
Mar 4, 2006
Mar 4, 2006
172
173
174
175
#if WITHOUT_GAPI
return g_bRawBufferAvailable;
#endif
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#if USE_GAPI_EMU
g_hGapiLib = LoadLibrary(_T("GAPI_Emu.dll"));
if( !g_hGapiLib )
{
SDL_SetError("Gapi Emu not found!");
}
return g_hGapiLib != 0;
#endif
// try to find gx.dll
g_hGapiLib = LoadLibrary(_T("\\Windows\\gx.dll"));
if( !g_hGapiLib )
{
g_hGapiLib = LoadLibrary(_T("gx.dll"));
if( !g_hGapiLib ) return g_bRawBufferAvailable;
}
return(1);
}
static int cmpmodes(const void *va, const void *vb)
{
SDL_Rect *a = *(SDL_Rect **)va;
SDL_Rect *b = *(SDL_Rect **)vb;
if ( a->w == b->w )
return b->h - a->h;
else
return b->w - a->w;
}
static int GAPI_AddMode(_THIS, int bpp, int w, int h)
{
SDL_Rect *mode;
int i, index;
int next_mode;
/* Check to see if we already have this mode */
if ( bpp < 8 ) { /* Not supported */
return(0);
}
index = ((bpp+7)/8)-1;
for ( i=0; i<gapi->SDL_nummodes[index]; ++i ) {
mode = gapi->SDL_modelist[index][i];
if ( (mode->w == w) && (mode->h == h) ) {
return(0);
}
}
/* Set up the new video mode rectangle */
Feb 7, 2006
Feb 7, 2006
225
mode = (SDL_Rect *)SDL_malloc(sizeof *mode);
226
227
228
229
230
231
232
233
234
235
236
237
if ( mode == NULL ) {
SDL_OutOfMemory();
return(-1);
}
mode->x = 0;
mode->y = 0;
mode->w = w;
mode->h = h;
/* Allocate the new list of modes, and fill in the new mode */
next_mode = gapi->SDL_nummodes[index];
gapi->SDL_modelist[index] = (SDL_Rect **)
Feb 7, 2006
Feb 7, 2006
238
SDL_realloc(gapi->SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *));
239
240
241
if ( gapi->SDL_modelist[index] == NULL ) {
SDL_OutOfMemory();
gapi->SDL_nummodes[index] = 0;
Feb 7, 2006
Feb 7, 2006
242
SDL_free(mode);
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
return(-1);
}
gapi->SDL_modelist[index][next_mode] = mode;
gapi->SDL_modelist[index][next_mode+1] = NULL;
gapi->SDL_nummodes[index]++;
return(0);
}
static void GAPI_DeleteDevice(SDL_VideoDevice *device)
{
if( g_hGapiLib )
{
FreeLibrary(g_hGapiLib);
g_hGapiLib = 0;
}
Feb 16, 2009
Feb 16, 2009
259
SDL_free(device->hidden->gapiInfo);
Feb 7, 2006
Feb 7, 2006
260
261
SDL_free(device->hidden);
SDL_free(device);
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
}
static SDL_VideoDevice *GAPI_CreateDevice(int devindex)
{
SDL_VideoDevice *device;
if( !g_hGapiLib && !g_bRawBufferAvailable)
{
if( !GAPI_Available() )
{
SDL_SetError("GAPI dll is not found and VGA mode is not available!");
return 0;
}
}
/* Initialize all variables that we clean on shutdown */
Feb 7, 2006
Feb 7, 2006
278
device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
Feb 7, 2006
Feb 7, 2006
280
SDL_memset(device, 0, (sizeof *device));
281
device->hidden = (struct SDL_PrivateVideoData *)
Feb 7, 2006
Feb 7, 2006
282
SDL_malloc((sizeof *device->hidden));
Feb 16, 2009
Feb 16, 2009
283
284
285
286
287
288
289
290
291
if(device->hidden){
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
device->hidden->gapiInfo = (GapiInfo *)SDL_malloc((sizeof(GapiInfo)));
if(device->hidden->gapiInfo == NULL)
{
SDL_free(device->hidden);
device->hidden = NULL;
}
}
292
293
294
295
}
if ( (device == NULL) || (device->hidden == NULL) ) {
SDL_OutOfMemory();
if ( device ) {
Feb 7, 2006
Feb 7, 2006
296
SDL_free(device);
297
298
299
}
return(0);
}
Feb 16, 2009
Feb 16, 2009
300
SDL_memset(device->hidden->gapiInfo, 0, (sizeof *device->hidden->gapiInfo));
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/* Set the function pointers */
device->VideoInit = GAPI_VideoInit;
device->ListModes = GAPI_ListModes;
device->SetVideoMode = GAPI_SetVideoMode;
device->UpdateMouse = WIN_UpdateMouse;
device->CreateYUVOverlay = NULL;
device->SetColors = GAPI_SetColors;
device->UpdateRects = GAPI_UpdateRects;
device->VideoQuit = GAPI_VideoQuit;
device->AllocHWSurface = GAPI_AllocHWSurface;
device->CheckHWBlit = NULL;
device->FillHWRect = NULL;
device->SetHWColorKey = NULL;
device->SetHWAlpha = NULL;
device->LockHWSurface = GAPI_LockHWSurface;
device->UnlockHWSurface = GAPI_UnlockHWSurface;
device->FlipHWSurface = NULL;
device->FreeHWSurface = GAPI_FreeHWSurface;
device->SetCaption = WIN_SetWMCaption;
device->SetIcon = WIN_SetWMIcon;
device->IconifyWindow = WIN_IconifyWindow;
device->GrabInput = WIN_GrabInput;
device->GetWMInfo = WIN_GetWMInfo;
device->FreeWMCursor = WIN_FreeWMCursor;
device->CreateWMCursor = WIN_CreateWMCursor;
device->ShowWMCursor = WIN_ShowWMCursor;
device->WarpWMCursor = WIN_WarpWMCursor;
device->CheckMouseMode = WIN_CheckMouseMode;
device->InitOSKeymap = DIB_InitOSKeymap;
device->PumpEvents = DIB_PumpEvents;
/* Set up the windows message handling functions */
Feb 16, 2009
Feb 16, 2009
334
WIN_Activate = GAPI_Activate;
335
336
337
338
339
340
341
342
WIN_RealizePalette = GAPI_RealizePalette;
WIN_PaletteChanged = GAPI_PaletteChanged;
WIN_WinPAINT = GAPI_WinPAINT;
HandleMessage = DIB_HandleMessage;
device->free = GAPI_DeleteDevice;
/* Load gapi library */
Feb 16, 2009
Feb 16, 2009
343
#define gx device->hidden->gapiInfo->gxFunc
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
LINK( GXOpenDisplay, gx.GXOpenDisplay, "?GXOpenDisplay@@YAHPAUHWND__@@K@Z" )
LINK( GXCloseDisplay, gx.GXCloseDisplay, "?GXCloseDisplay@@YAHXZ" )
LINK( GXBeginDraw, gx.GXBeginDraw, "?GXBeginDraw@@YAPAXXZ" )
LINK( GXEndDraw, gx.GXEndDraw, "?GXEndDraw@@YAHXZ" )
LINK( GXOpenInput, gx.GXOpenInput, "?GXOpenInput@@YAHXZ" )
LINK( GXCloseInput, gx.GXCloseInput, "?GXCloseInput@@YAHXZ" )
LINK( GXGetDisplayProperties, gx.GXGetDisplayProperties,"?GXGetDisplayProperties@@YA?AUGXDisplayProperties@@XZ" )
LINK( GXGetDefaultKeys, gx.GXGetDefaultKeys, "?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z" )
LINK( GXSuspend, gx.GXSuspend, "?GXSuspend@@YAHXZ" )
LINK( GXResume, gx.GXResume, "?GXResume@@YAHXZ" )
LINK( GXSetViewport, gx.GXSetViewport, "?GXSetViewport@@YAHKKKK@Z" )
LINK( GXIsDisplayDRAMBuffer, gx.GXIsDisplayDRAMBuffer, "?GXIsDisplayDRAMBuffer@@YAHXZ" )
/* wrong gapi.dll */
if( !gx.GXOpenDisplay )
{
if( g_hGapiLib )
{
FreeLibrary(g_hGapiLib);
g_hGapiLib = 0;
}
}
if( !gx.GXOpenDisplay && !g_bRawBufferAvailable)
{
SDL_SetError("Error: damaged or unknown gapi.dll!\n");
GAPI_DeleteDevice(device);
return 0;
}
return device;
}
VideoBootStrap GAPI_bootstrap = {
GAPIVID_DRIVER_NAME, "WinCE GAPI video driver",
GAPI_Available, GAPI_CreateDevice
};
static void FillStructs(_THIS, BOOL useVga)
{
#ifdef _ARM_
WCHAR oemstr[100];
#endif
/* fill a device properties */
if( !useVga )
{
Feb 16, 2009
Feb 16, 2009
392
393
394
395
396
gapi->gxProperties = gapi->gxFunc.GXGetDisplayProperties();
gapi->needUpdate = 1;
gapi->hiresFix = 0;
gapi->useVga = 0;
gapi->useGXOpenDisplay = 1;
Mar 4, 2006
Mar 4, 2006
397
398
399
400
401
402
#ifdef _ARM_
/* check some devices and extract addition info */
SystemParametersInfo( SPI_GETOEMINFO, sizeof( oemstr ), oemstr, 0 );
// buggy iPaq38xx
Feb 16, 2009
Feb 16, 2009
403
if ((oemstr[12] == 'H') && (oemstr[13] == '3') && (oemstr[14] == '8') && (gapi->gxProperties.cbxPitch > 0))
Feb 16, 2009
Feb 16, 2009
405
406
407
408
gapi->videoMem = (PIXEL*)0xac0755a0;
gapi->gxProperties.cbxPitch = -640;
gapi->gxProperties.cbyPitch = 2;
gapi->needUpdate = 0;
Mar 4, 2006
Mar 4, 2006
410
411
412
413
414
415
416
417
418
419
420
421
422
#if (EMULATE_AXIM_X30 == 0)
// buggy Dell Axim X30
if( _tcsncmp(oemstr, L"Dell Axim X30", 13) == 0 )
#endif
{
GXDeviceInfo gxInfo = {0};
HDC hdc = GetDC(NULL);
int result;
gxInfo.Version = 100;
result = ExtEscape(hdc, GETGXINFO, 0, NULL, sizeof(gxInfo), (char *)&gxInfo);
if( result > 0 )
{
Feb 16, 2009
Feb 16, 2009
423
424
425
426
427
428
429
430
gapi->useGXOpenDisplay = 0;
gapi->videoMem = gxInfo.pvFrameBuffer;
gapi->needUpdate = 0;
gapi->gxProperties.cbxPitch = 2;
gapi->gxProperties.cbyPitch = 480;
gapi->gxProperties.cxWidth = gxInfo.cxWidth;
gapi->gxProperties.cyHeight = gxInfo.cyHeight;
gapi->gxProperties.ffFormat = gxInfo.ffFormat;
Mar 4, 2006
Mar 4, 2006
431
432
}
}
433
434
435
#endif
} else
{
Feb 16, 2009
Feb 16, 2009
436
437
438
439
440
441
442
443
444
gapi->needUpdate = 0;
gapi->hiresFix = 0;
gapi->gxProperties.cBPP = g_RawFrameBufferInfo.wBPP;
gapi->gxProperties.cbxPitch = g_RawFrameBufferInfo.cxStride;
gapi->gxProperties.cbyPitch = g_RawFrameBufferInfo.cyStride;
gapi->gxProperties.cxWidth = g_RawFrameBufferInfo.cxPixels;
gapi->gxProperties.cyHeight = g_RawFrameBufferInfo.cyPixels;
gapi->videoMem = g_RawFrameBufferInfo.pFramePointer;
gapi->useVga = 1;
445
446
447
448
switch( g_RawFrameBufferInfo.wFormat )
{
case FORMAT_565:
Feb 16, 2009
Feb 16, 2009
449
gapi->gxProperties.ffFormat = kfDirect565;
450
451
break;
case FORMAT_555:
Feb 16, 2009
Feb 16, 2009
452
gapi->gxProperties.ffFormat = kfDirect555;
453
454
455
456
457
458
459
break;
default:
/* unknown pixel format, try define by BPP! */
switch( g_RawFrameBufferInfo.wBPP )
{
case 4:
case 8:
Feb 16, 2009
Feb 16, 2009
460
gapi->gxProperties.ffFormat = kfDirect;
Feb 16, 2009
Feb 16, 2009
462
gapi->gxProperties.ffFormat = kfDirect565;
Feb 16, 2009
Feb 16, 2009
464
gapi->gxProperties.ffFormat = kfDirect;
465
466
467
468
469
break;
}
}
}
Feb 16, 2009
Feb 16, 2009
470
if( gapi->gxProperties.cBPP != 16 )
Feb 16, 2009
Feb 16, 2009
472
gapi->gapiOrientation = SDL_ORIENTATION_UP;
Feb 16, 2009
Feb 16, 2009
474
if( (gapi->gxProperties.cbxPitch > 0) && (gapi->gxProperties.cbyPitch > 0 ))
Feb 16, 2009
Feb 16, 2009
476
gapi->gapiOrientation = SDL_ORIENTATION_UP;
Feb 16, 2009
Feb 16, 2009
478
if( (gapi->gxProperties.cbxPitch > 0) && (gapi->gxProperties.cbyPitch < 0 ))
Feb 16, 2009
Feb 16, 2009
480
gapi->gapiOrientation = SDL_ORIENTATION_RIGHT; // ipaq 3660
Feb 16, 2009
Feb 16, 2009
482
if( (gapi->gxProperties.cbxPitch < 0) && (gapi->gxProperties.cbyPitch > 0 ))
Feb 16, 2009
Feb 16, 2009
484
gapi->gapiOrientation = SDL_ORIENTATION_LEFT; // ipaq 3800
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
}
}
static void GAPI_CreatePalette(int ncolors, SDL_Color *colors)
{
// Setup a custom color palette
BYTE buffer[ sizeof(LOGPALETTE) + 255 * sizeof(PALETTEENTRY) ];
int i;
LOGPALETTE* pLogical = (LOGPALETTE*)buffer;
PALETTEENTRY* entries = pLogical->palPalEntry;
HPALETTE hPalette;
HDC hdc;
for (i = 0; i < ncolors; ++i)
{
// Find intensity by replicating the bit patterns over a byte
entries[i].peRed = colors[i].r;
entries[i].peGreen = colors[i].g;
entries[i].peBlue = colors[i].b;
entries[i].peFlags = 0;
}
// Create the GDI palette object
pLogical->palVersion = 0x0300;
pLogical->palNumEntries = ncolors;
hPalette = CreatePalette( pLogical );
ASSERT(hPalette);
// Realize the palette
hdc = GetDC(0);
SelectPalette( hdc, hPalette, FALSE );
RealizePalette( hdc );
ReleaseDC( 0, hdc );
DeleteObject( hPalette );
}
int GAPI_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
int i,bpp;
/* Create the window */
if ( DIB_CreateWindow(this) < 0 ) {
return(-1);
}
if( g_hGapiLib )
{
FillStructs(this, 0);
// SDL does not supports 2/4bpp mode, so use 16 bpp
bpp = gapi->gxProperties.cBPP < 8 ? 16 : gapi->gxProperties.cBPP;
/* set up normal and landscape mode */
GAPI_AddMode(this, bpp, gapi->gxProperties.cyHeight, gapi->gxProperties.cxWidth);
GAPI_AddMode(this, bpp, gapi->gxProperties.cxWidth, gapi->gxProperties.cyHeight);
}
/* add hi-res mode */
if( g_bRawBufferAvailable &&
!((gapi->gxProperties.cxWidth == (unsigned)g_RawFrameBufferInfo.cxPixels) && (gapi->gxProperties.cyHeight == (unsigned)g_RawFrameBufferInfo.cyPixels)))
{
FillStructs(this, 1);
// SDL does not supports 2/4bpp mode, so use 16 bpp
bpp = gapi->gxProperties.cBPP < 8 ? 16 : gapi->gxProperties.cBPP;
/* set up normal and landscape mode */
GAPI_AddMode(this, bpp, gapi->gxProperties.cyHeight, gapi->gxProperties.cxWidth);
GAPI_AddMode(this, bpp, gapi->gxProperties.cxWidth, gapi->gxProperties.cyHeight);
}
Feb 16, 2009
Feb 16, 2009
560
561
562
563
564
/* Determine the current screen size.
* This is NOT necessarily the size of the Framebuffer or GAPI, as they return
* the displaysize in ORIENTATION_UP */
this->info.current_w = GetSystemMetrics(SM_CXSCREEN);
this->info.current_h = GetSystemMetrics(SM_CYSCREEN);
Mar 15, 2006
Mar 15, 2006
565
566
567
568
/* Sort the mode lists */
for ( i=0; i<NUM_MODELISTS; ++i ) {
if ( gapi->SDL_nummodes[i] > 0 ) {
Feb 7, 2006
Feb 7, 2006
569
SDL_qsort(gapi->SDL_modelist[i], gapi->SDL_nummodes[i], sizeof *gapi->SDL_modelist[i], cmpmodes);
Feb 16, 2009
Feb 16, 2009
573
vformat->BitsPerPixel = gapi->gxProperties.cBPP < 8 ? 16 : (unsigned char)gapi->gxProperties.cBPP;
574
575
// Get color mask
Feb 16, 2009
Feb 16, 2009
576
if (gapi->gxProperties.ffFormat & kfDirect565) {
577
578
579
580
vformat->BitsPerPixel = 16;
vformat->Rmask = 0x0000f800;
vformat->Gmask = 0x000007e0;
vformat->Bmask = 0x0000001f;
Feb 16, 2009
Feb 16, 2009
581
gapi->videoMode = GAPI_DIRECT_565;
Feb 16, 2009
Feb 16, 2009
584
if (gapi->gxProperties.ffFormat & kfDirect555) {
585
586
587
588
vformat->BitsPerPixel = 16;
vformat->Rmask = 0x00007c00;
vformat->Gmask = 0x000003e0;
vformat->Bmask = 0x0000001f;
Feb 16, 2009
Feb 16, 2009
589
gapi->videoMode = GAPI_DIRECT_555;
Feb 16, 2009
Feb 16, 2009
592
if ((gapi->gxProperties.ffFormat & kfDirect) && (gapi->gxProperties.cBPP < 8)) {
593
594
595
596
597
// We'll perform the conversion
vformat->BitsPerPixel = 16;
vformat->Rmask = 0x0000f800; // 16 bit 565
vformat->Gmask = 0x000007e0;
vformat->Bmask = 0x0000001f;
Feb 16, 2009
Feb 16, 2009
598
599
600
601
if (gapi->gxProperties.ffFormat & kfDirectInverted)
gapi->invert = (1 << gapi->gxProperties.cBPP) - 1;
gapi->colorscale = gapi->gxProperties.cBPP < 8 ? 8 - gapi->gxProperties.cBPP : 0;
gapi->videoMode = GAPI_MONO;
Feb 16, 2009
Feb 16, 2009
604
605
if (gapi->gxProperties.ffFormat & kfPalette) {
gapi->videoMode = GAPI_PALETTE;
606
607
608
609
610
611
612
613
}
/* We're done! */
return(0);
}
SDL_Rect **GAPI_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
{
Feb 16, 2009
Feb 16, 2009
614
return(gapi->SDL_modelist[((format->BitsPerPixel+7)/8)-1]);
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
// return (SDL_Rect **) -1;
}
SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current,
int width, int height, int bpp, Uint32 flags)
{
SDL_Surface *video;
Uint32 Rmask, Gmask, Bmask;
DWORD style;
SDL_Rect allScreen;
if( bpp < 4 )
{
SDL_SetError("1 bpp and 2 bpp modes is not implemented yet!");
return 0;
}
/* Recalculate bitmasks if necessary */
if (bpp == current->format->BitsPerPixel) {
video = current;
}
else {
switch(bpp) {
case 8:
Rmask = 0;
Gmask = 0;
Bmask = 0;
break;
case 15:
case 16:
/* Default is 565 unless the display is specifically 555 */
Feb 16, 2009
Feb 16, 2009
646
if (gapi->gxProperties.ffFormat & kfDirect555) {
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
Rmask = 0x00007c00;
Gmask = 0x000003e0;
Bmask = 0x0000001f;
}
else {
Rmask = 0x0000f800;
Gmask = 0x000007e0;
Bmask = 0x0000001f;
}
break;
case 24:
case 32:
Rmask = 0x00ff0000;
Gmask = 0x0000ff00;
Bmask = 0x000000ff;
break;
default:
SDL_SetError("Unsupported Bits Per Pixel format requested");
return NULL;
}
video = SDL_CreateRGBSurface(SDL_SWSURFACE,
0, 0, bpp, Rmask, Gmask, Bmask, 0);
if ( video == NULL ) {
SDL_OutOfMemory();
return(NULL);
}
}
gapi->userOrientation = SDL_ORIENTATION_UP;
Oct 10, 2009
Oct 10, 2009
676
gapi->systemOrientation = SDL_ORIENTATION_UP;
677
678
679
680
681
682
683
684
685
686
687
688
video->flags = SDL_FULLSCREEN; /* Clear flags, GAPI supports fullscreen only */
/* GAPI or VGA? */
if( g_hGapiLib )
{
FillStructs(this, 0);
if( (((unsigned)width != gapi->gxProperties.cxWidth) || ((unsigned)height != gapi->gxProperties.cyHeight))
&& (((unsigned)width != gapi->gxProperties.cyHeight) || ((unsigned)height != gapi->gxProperties.cxWidth)))
FillStructs(this, 1); // gapi is found but we use VGA resolution
} else
FillStructs(this, 1);
Feb 16, 2009
Feb 16, 2009
689
if ( !gapi->needUpdate && !gapi->videoMem) {
690
691
692
693
SDL_SetError("Couldn't get address of video memory, may be unsupported device or bug");
return(NULL);
}
Mar 4, 2006
Mar 4, 2006
694
/* detect user landscape mode */
Nov 7, 2008
Nov 7, 2008
695
if( (width > height) && (gapi->gxProperties.cxWidth < gapi->gxProperties.cyHeight))
696
697
gapi->userOrientation = SDL_ORIENTATION_RIGHT;
Nov 7, 2008
Nov 7, 2008
698
if(GetSystemMetrics(SM_CYSCREEN) < GetSystemMetrics(SM_CXSCREEN))
Oct 10, 2009
Oct 10, 2009
699
gapi->systemOrientation = SDL_ORIENTATION_RIGHT;
Nov 7, 2008
Nov 7, 2008
700
Oct 10, 2009
Oct 10, 2009
702
703
704
/* check hires */
if(GetSystemMetrics(SM_CXSCREEN) < width && GetSystemMetrics(SM_CYSCREEN) < height)
Oct 10, 2009
Oct 10, 2009
706
707
gapi->hiresFix = 1;
}
708
709
710
711
712
713
714
715
716
717
718
719
720
721
switch( gapi->userOrientation )
{
case SDL_ORIENTATION_UP:
gapi->startOffset = 0;
gapi->dstLineStep = gapi->gxProperties.cbyPitch;
gapi->dstPixelStep = gapi->gxProperties.cbxPitch;
break;
case SDL_ORIENTATION_RIGHT:
switch( gapi->gapiOrientation )
{
case SDL_ORIENTATION_UP:
case SDL_ORIENTATION_RIGHT:
case SDL_ORIENTATION_LEFT:
Feb 16, 2009
Feb 16, 2009
722
if( (gapi->videoMode == GAPI_MONO) )
723
724
725
726
727
728
729
730
731
732
gapi->startOffset = -gapi->gxProperties.cbxPitch + 1; // monochrome mode
else
gapi->startOffset = gapi->gxProperties.cbyPitch * (gapi->gxProperties.cyHeight - 1);
gapi->dstLineStep = gapi->gxProperties.cbxPitch;
gapi->dstPixelStep = -gapi->gxProperties.cbyPitch;
break;
}
}
Feb 16, 2009
Feb 16, 2009
733
734
video->w = gapi->w = width;
video->h = gapi->h = height;
735
video->pitch = SDL_CalculatePitch(video);
Aug 1, 2019
Aug 1, 2019
736
if (!video->pitch) {
Mar 17, 2019
Mar 17, 2019
737
738
return(NULL);
}
739
740
741
742
743
744
745
746
747
748
749
750
/* Small fix for WinCE/Win32 - when activating window
SDL_VideoSurface is equal to zero, so activating code
is not called properly for fullscreen windows because
macros WINDIB_FULLSCREEN uses SDL_VideoSurface
*/
SDL_VideoSurface = video;
/* GAPI is always fullscreen, title bar is useless */
style = 0;
if (!SDL_windowid)
Mar 7, 2006
Mar 7, 2006
751
SetWindowLong(SDL_Window, GWL_STYLE, style);
Mar 4, 2006
Mar 4, 2006
752
753
/* Allocate bitmap */
Feb 16, 2009
Feb 16, 2009
754
if( gapi->buffer )
Feb 16, 2009
Feb 16, 2009
756
757
SDL_free( gapi->buffer );
gapi->buffer = NULL;
Feb 16, 2009
Feb 16, 2009
759
760
gapi->buffer = SDL_malloc(video->h * video->pitch);
video->pixels = gapi->buffer;
Feb 16, 2009
Feb 16, 2009
762
if ( ! gapi->buffer ) {
763
764
765
766
SDL_SetError("Couldn't allocate buffer for requested mode");
return(NULL);
}
Feb 16, 2009
Feb 16, 2009
767
SDL_memset(gapi->buffer, 255, video->h * video->pitch);
768
769
770
771
MoveWindow(SDL_Window, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), FALSE);
ShowWindow(SDL_Window, SW_SHOW);
SetForegroundWindow(SDL_Window);
Mar 14, 2006
Mar 14, 2006
772
773
774
775
776
777
/* JC 14 Mar 2006
Flush the message loop or this can cause big problems later
Especially if the user decides to use dialog boxes or assert()!
*/
WIN_FlushMessageQueue();
Sep 23, 2009
Sep 23, 2009
778
/* Open GAPI display */
Feb 16, 2009
Feb 16, 2009
779
if( !gapi->useVga && gapi->useGXOpenDisplay && !gapi->alreadyGXOpened )
Nov 7, 2008
Nov 7, 2008
780
{
Sep 23, 2009
Sep 23, 2009
781
782
783
784
#if REPORT_VIDEO_INFO
printf("system display width (orig): %d\n", GetSystemMetrics(SM_CXSCREEN));
printf("system display height (orig): %d\n", GetSystemMetrics(SM_CYSCREEN));
#endif
Feb 16, 2009
Feb 16, 2009
785
gapi->alreadyGXOpened = 1;
Mar 4, 2006
Mar 4, 2006
786
787
788
789
790
if( !gapi->gxFunc.GXOpenDisplay(SDL_Window, GX_FULLSCREEN) )
{
SDL_SetError("Couldn't initialize GAPI");
return(NULL);
}
Nov 7, 2008
Nov 7, 2008
791
}
Mar 4, 2006
Mar 4, 2006
792
Feb 16, 2009
Feb 16, 2009
793
if(gapi->useVga)
Oct 10, 2009
Oct 10, 2009
794
gapi->coordinateTransform = (4 - gapi->systemOrientation + gapi->userOrientation) % 4;
Feb 16, 2009
Feb 16, 2009
795
796
797
else
gapi->coordinateTransform = gapi->userOrientation;
798
799
800
801
802
#if REPORT_VIDEO_INFO
printf("Video properties:\n");
printf("display bpp: %d\n", gapi->gxProperties.cBPP);
printf("display width: %d\n", gapi->gxProperties.cxWidth);
printf("display height: %d\n", gapi->gxProperties.cyHeight);
Nov 7, 2008
Nov 7, 2008
803
804
printf("system display width: %d\n", GetSystemMetrics(SM_CXSCREEN));
printf("system display height: %d\n", GetSystemMetrics(SM_CYSCREEN));
805
806
807
printf("x pitch: %d\n", gapi->gxProperties.cbxPitch);
printf("y pitch: %d\n", gapi->gxProperties.cbyPitch);
printf("gapi flags: 0x%x\n", gapi->gxProperties.ffFormat);
Nov 7, 2008
Nov 7, 2008
808
printf("user orientation: %d\n", gapi->userOrientation);
Oct 10, 2009
Oct 10, 2009
809
printf("system orientation: %d\n", gapi->systemOrientation);
Nov 7, 2008
Nov 7, 2008
810
811
printf("gapi orientation: %d\n", gapi->gapiOrientation);
Mar 4, 2006
Mar 4, 2006
812
Feb 16, 2009
Feb 16, 2009
813
if( !gapi->useVga && gapi->useGXOpenDisplay && gapi->needUpdate)
Mar 4, 2006
Mar 4, 2006
814
815
816
817
818
{
gapi->videoMem = gapi->gxFunc.GXBeginDraw();
gapi->gxFunc.GXEndDraw();
}
819
820
821
822
printf("video memory: 0x%x\n", gapi->videoMem);
printf("need update: %d\n", gapi->needUpdate);
printf("hi-res fix: %d\n", gapi->hiresFix);
printf("VGA is available on the device: %d\n", g_bRawBufferAvailable);
Mar 4, 2006
Mar 4, 2006
823
printf("use raw framebuffer: %d\n", gapi->useVga);
824
825
826
printf("video surface bpp: %d\n", video->format->BitsPerPixel);
printf("video surface width: %d\n", video->w);
printf("video surface height: %d\n", video->h);
Feb 16, 2009
Feb 16, 2009
827
printf("mouse/arrows transformation angle: %d\n", gapi->coordinateTransform);
Mar 4, 2006
Mar 4, 2006
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
/* Blank screen */
allScreen.x = allScreen.y = 0;
allScreen.w = video->w - 1;
allScreen.h = video->h - 1;
GAPI_UpdateRects(this, 1, &allScreen);
/* We're done */
return(video);
}
/* We don't actually allow hardware surfaces other than the main one */
static int GAPI_AllocHWSurface(_THIS, SDL_Surface *surface)
{
return(-1);
}
static void GAPI_FreeHWSurface(_THIS, SDL_Surface *surface)
{
return;
}
/* We need to wait for vertical retrace on page flipped displays */
static int GAPI_LockHWSurface(_THIS, SDL_Surface *surface)
{
return(0);
}
static void GAPI_UnlockHWSurface(_THIS, SDL_Surface *surface)
{
return;
}
static int updateLine8to8(_THIS, unsigned char *srcPointer, unsigned char *destPointer, int width, int height, int lines)
{
if( gapi->dstPixelStep == 1) /* optimized blitting on most devices */
{
Feb 7, 2006
Feb 7, 2006
866
SDL_memcpy(destPointer, srcPointer, width);
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
return 1;
} else
{
// TODO: read 4 pixels, write DWORD
int step = gapi->dstPixelStep;
while(width--)
{
*destPointer = *srcPointer++;
destPointer += step;
}
}
return 1;
}
/* Video memory is very slow so lets optimize as much as possible */
static int updateLine16to16(_THIS, PIXEL *srcPointer, PIXEL *destPointer, int width, int height, int lines)
{
PIXEL *line1, *line2;
int step = gapi->dstPixelStep / 2;
if( step == 1 ) /* optimized blitting on most devices */
{
Feb 7, 2006
Feb 7, 2006
889
SDL_memcpy(destPointer, srcPointer, width * sizeof(PIXEL));
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
return 1;
}
else
{
if( (gapi->gapiOrientation != SDL_ORIENTATION_UP) &&
(gapi->userOrientation == SDL_ORIENTATION_UP )) // iPaq 3660/3800 and user orientation up
{
// to prevent data misalignment copy only one line
if( ((((unsigned)destPointer & 3) != 0) && (gapi->gapiOrientation == SDL_ORIENTATION_LEFT))
|| ((((unsigned)destPointer & 3) == 0) && (gapi->gapiOrientation != SDL_ORIENTATION_LEFT))
|| (lines == 1) )
{
while(width--)
{
*destPointer = *srcPointer++;
destPointer += step;
}
return 1;
}
/* read two lines at the same time, write DWORD */
line1 = srcPointer;
line2 = srcPointer + SDL_VideoSurface->pitch / 2;
if( gapi->gapiOrientation == SDL_ORIENTATION_LEFT )
while(width--) // iPaq 3800
{
*(DWORD*)destPointer =(*line2++ << 16) | *line1++;
destPointer += step;
}
else
{
destPointer += gapi->gxProperties.cbyPitch / 2;
Mar 4, 2006
Mar 4, 2006
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
while(width--) // iPaq 3660
{
*(DWORD*)destPointer =(*line1++ << 16) | *line2++;
destPointer += step;
}
}
return 2;
} else
{
// iPaq 3800 and user orientation landscape
if( gapi->gapiOrientation == SDL_ORIENTATION_LEFT )
{
int w1;
// to prevent data misalignment copy only one pixel
if( (((unsigned)destPointer & 3) == 0) && (width > 0))
{
*destPointer-- = *srcPointer++;
width--;
}
destPointer--;
w1 = width / 2;
while(w1--)
{
DWORD p = *(DWORD*)srcPointer;
*((DWORD*)destPointer) = (p << 16) | (p >> 16);
destPointer -= 2;
srcPointer += 2;
}
if( width & 1 ) // copy the last pixel
{
destPointer++;
*destPointer = *srcPointer;
}
return 1;
}
// modern iPaqs and user orientation landscape
// read two pixels, write DWORD
line1 = srcPointer;
line2 = srcPointer + SDL_VideoSurface->pitch / 2;
if( (((unsigned)destPointer & 3) != 0) || (lines == 1) )
{
while(width--)
{
*destPointer = *srcPointer++;
destPointer += step;
}
return 1;
}
while(width--)
{
*(DWORD*)destPointer =(*line2++ << 16) | *line1++;
destPointer -= gapi->gxProperties.cbyPitch / 2;
}
return 2;
}
}
}
// Color component masks for 565
#define REDMASK (31<<11)
#define GREENMASK (63<<5)
#define BLUEMASK (31)
static int updateLine16to4(_THIS, PIXEL *srcPointer, unsigned char *destPointer, int width, int height, int lines, int yNibble, int xNibble)
{
PIXEL *line1, *line2;