This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
SDL_photon.c
2852 lines (2559 loc) · 106 KB
1
2
/*
SDL - Simple DirectMedia Layer
3
Copyright (C) 1997-2010 Sam Lantinga
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
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
Lesser General Public License for more details.
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
Sam Lantinga
slouken@libsdl.org
21
22
23
24
QNX Photon GUI SDL driver
Copyright (C) 2009 Mike Gorchak
(mike@malva.ua, lestat@i.com.ua)
25
26
*/
27
/* SDL internals */
28
#include "SDL_config.h"
29
30
31
#include "../SDL_sysvideo.h"
#include "SDL_version.h"
#include "SDL_syswm.h"
32
33
34
35
#include "SDL_loadso.h"
#include "SDL_events.h"
#include "../../events/SDL_mouse_c.h"
#include "../../events/SDL_keyboard_c.h"
36
37
/* Photon declarations */
38
39
#include "SDL_photon.h"
40
41
42
43
44
/* Pixel format conversion routines */
#include "SDL_photon_pixelfmt.h"
/* Use GF's pixel format functions for OpenGL ES context creation */
#if defined(SDL_VIDEO_OPENGL_ES)
45
#include "../qnxgf/SDL_gf_pixelfmt.h"
46
47
/* If GF driver is not compiled in, include some of usefull functions */
48
49
50
#if !defined(SDL_VIDEO_DRIVER_QNXGF)
#include "../qnxgf/SDL_gf_pixelfmt.c"
#endif /* SDL_VIDEO_DRIVER_QNXGF */
51
52
53
54
#endif /* SDL_VIDEO_OPENGL_ES */
/* Use GF's OpenGL ES 1.1 functions emulation */
#if defined(SDL_VIDEO_OPENGL_ES)
55
#include "../qnxgf/SDL_gf_opengles.h"
56
57
/* If GF driver is not compiled in, include some of usefull functions */
58
59
60
#if !defined(SDL_VIDEO_DRIVER_QNXGF)
#include "../qnxgf/SDL_gf_opengles.c"
#endif /* SDL_VIDEO_DRIVER_QNXGF */
61
62
63
#endif /* SDL_VIDEO_OPENGL_ES */
/* Low level device graphics driver names, which they are reporting */
64
static const Photon_DeviceCaps photon_devicename[] = {
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
139
/* ATI Rage 128 graphics driver (devg-ati_rage128) */
{"ati_rage128", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
/* Fujitsu Carmine graphics driver (devg-carmine.so) */
{"carmine", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
,
/* C&T graphics driver (devg-chips.so) */
{"chips", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
/* Fujitsu Coral graphics driver (devg-coral.so) */
{"coral", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
,
/* Intel integrated graphics driver (devg-extreme2.so) */
{"extreme2", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
,
/* Unaccelerated FB driver (devg-flat.so) */
{"flat", SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
/* NS Geode graphics driver (devg-geode.so) */
{"geode", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
/* Geode LX graphics driver (devg-geodelx.so) */
{"geodelx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
/* Intel integrated graphics driver (devg-gma9xx.so) */
{"gma", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
,
/* Intel integrated graphics driver (devg-i810.so) */
{"i810", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
/* Intel integrated graphics driver (devg-i830.so) */
{"i830", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
/* Geode LX graphics driver (devg-lx800.so) */
{"lx800", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
/* Matrox Gxx graphics driver (devg-matroxg.so) */
{"matroxg", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
/* Intel Poulsbo graphics driver (devg-poulsbo.so) */
{"poulsbo", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
,
/* ATI Radeon driver (devg-radeon.so) */
{"radeon", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
/* ATI Rage driver (devg-rage.so) */
{"rage", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
/* S3 Savage graphics driver (devg-s3_savage.so) */
{"s3_savage", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
/* SiS630 integrated graphics driver (devg-sis630.so) */
{"sis630", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
/* PowerVR SGX 535 graphics driver (devg-poulsbo.so) */
{"sgx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
,
/* SM Voyager GX graphics driver (devg-smi5xx.so) */
{"smi5xx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
/* Silicon Motion graphics driver (devg-smi7xx.so) */
{"smi7xx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
/* SVGA unaccelerated gfx driver (devg-svga.so) */
{"svga", SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
/* nVidia TNT graphics driver (devg-tnt.so) */
{"tnt", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
/* VIA integrated graphics driver (devg-tvia.so) */
{"tvia", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
/* VIA UniChrome graphics driver (devg-unichrome.so) */
{"unichrome", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
140
/* VESA unaccelerated gfx driver (devg-vesabios.so) */
141
142
143
144
145
146
147
148
149
150
{"vesa", SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
/* VmWare graphics driver (devg-volari.so) */
{"vmware", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
/* XGI XP10 graphics driver (devg-volari.so), OpenGL 1.5 */
{"volari", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
,
/* End of list */
{NULL, 0x00000000}
151
152
};
153
static SDL_bool photon_initialized = SDL_FALSE;
154
155
156
static int
photon_available(void)
157
{
158
int32_t status;
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* Check if Photon was initialized before */
if (photon_initialized == SDL_FALSE) {
/* Initialize Photon widget library and open channel to Photon */
status = PtInit(NULL);
if (status == 0) {
photon_initialized = SDL_TRUE;
return 1;
} else {
photon_initialized = SDL_FALSE;
return 0;
}
}
return 1;
174
175
}
176
177
static void
photon_destroy(SDL_VideoDevice * device)
178
{
179
180
181
182
183
184
185
186
187
188
189
SDL_VideoData *phdata = (SDL_VideoData *) device->driverdata;
#if defined(SDL_VIDEO_OPENGL_ES)
if (phdata->gfinitialized != SDL_FALSE) {
gf_dev_detach(phdata->gfdev);
}
#endif /* SDL_VIDEO_OPENGL_ES */
if (device->driverdata != NULL) {
device->driverdata = NULL;
}
190
191
}
192
193
static SDL_VideoDevice *
photon_create(int devindex)
194
{
195
196
SDL_VideoDevice *device;
SDL_VideoData *phdata;
197
int32_t status;
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/* Check if photon could be initialized */
status = photon_available();
if (status == 0) {
/* Photon could not be used */
return NULL;
}
/* Photon agregates all video devices to one with multiple heads */
if (devindex != 0) {
/* devindex could be zero only in Photon SDL driver */
return NULL;
}
/* Initialize SDL_VideoDevice structure */
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
if (device == NULL) {
SDL_OutOfMemory();
return NULL;
}
/* Initialize internal photon specific data */
phdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
if (phdata == NULL) {
SDL_OutOfMemory();
SDL_free(device);
return NULL;
}
device->driverdata = phdata;
/* Get all photon display devices */
phdata->avail_rids =
PdGetDevices(&phdata->rid[0], SDL_VIDEO_PHOTON_MAX_RIDS);
if (phdata->avail_rids > SDL_VIDEO_PHOTON_MAX_RIDS) {
phdata->avail_rids = SDL_VIDEO_PHOTON_MAX_RIDS;
}
#if defined(SDL_VIDEO_OPENGL_ES)
/* TODO: add real device detection versus multiple heads */
status =
gf_dev_attach(&phdata->gfdev, GF_DEVICE_INDEX(0),
&phdata->gfdev_info);
if (status != GF_ERR_OK) {
/* Do not fail right now, if GF can't be attached */
phdata->gfinitialized = SDL_FALSE;
} else {
phdata->gfinitialized = SDL_TRUE;
}
#endif /* SDL_VIDEO_OPENGL_ES */
/* Set default target device */
status = PdSetTargetDevice(NULL, phdata->rid[0]);
if (status == -1) {
SDL_SetError("Photon: Can't set default target device");
#if defined(SDL_VIDEO_OPENGL_ES)
gf_dev_detach(phdata->gfdev);
#endif /* SDL_VIDEO_OPENGL_ES */
SDL_free(phdata);
SDL_free(device);
return NULL;
}
phdata->current_device_id = 0;
/* Setup amount of available displays and current display */
device->num_displays = 0;
device->current_display = 0;
/* Set device free function */
device->free = photon_destroy;
/* Setup all functions which we can handle */
device->VideoInit = photon_videoinit;
device->VideoQuit = photon_videoquit;
device->GetDisplayModes = photon_getdisplaymodes;
device->SetDisplayMode = photon_setdisplaymode;
device->CreateWindow = photon_createwindow;
device->CreateWindowFrom = photon_createwindowfrom;
device->SetWindowTitle = photon_setwindowtitle;
device->SetWindowIcon = photon_setwindowicon;
device->SetWindowPosition = photon_setwindowposition;
device->SetWindowSize = photon_setwindowsize;
device->ShowWindow = photon_showwindow;
device->HideWindow = photon_hidewindow;
device->RaiseWindow = photon_raisewindow;
device->MaximizeWindow = photon_maximizewindow;
device->MinimizeWindow = photon_minimizewindow;
device->RestoreWindow = photon_restorewindow;
device->SetWindowGrab = photon_setwindowgrab;
device->DestroyWindow = photon_destroywindow;
device->GetWindowWMInfo = photon_getwindowwminfo;
device->GL_LoadLibrary = photon_gl_loadlibrary;
device->GL_GetProcAddress = photon_gl_getprocaddres;
device->GL_UnloadLibrary = photon_gl_unloadlibrary;
device->GL_CreateContext = photon_gl_createcontext;
device->GL_MakeCurrent = photon_gl_makecurrent;
device->GL_SetSwapInterval = photon_gl_setswapinterval;
device->GL_GetSwapInterval = photon_gl_getswapinterval;
device->GL_SwapWindow = photon_gl_swapwindow;
device->GL_DeleteContext = photon_gl_deletecontext;
device->PumpEvents = photon_pumpevents;
device->SuspendScreenSaver = photon_suspendscreensaver;
return device;
300
301
}
302
303
304
305
306
VideoBootStrap photon_bootstrap = {
"photon",
"SDL QNX Photon video driver",
photon_available,
photon_create
307
308
};
309
310
311
/*****************************************************************************/
/* SDL Video and Display initialization/handling functions */
/*****************************************************************************/
312
313
int
photon_videoinit(_THIS)
314
{
315
316
317
318
319
320
321
322
323
324
325
326
SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
PgHWCaps_t hwcaps;
PgVideoModeInfo_t modeinfo;
int32_t status;
SDL_VideoDisplay display;
SDL_DisplayMode current_mode;
SDL_DisplayData *didata;
uint32_t it;
uint32_t jt;
char *override;
/* By default Photon do not uses swap on VSYNC */
327
#if defined(SDL_VIDEO_OPENGL_ES)
328
phdata->swapinterval = 0;
329
#endif /* SDL_VIDEO_OPENGL_ES */
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
for (it = 0; it < phdata->avail_rids; it++) {
didata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
if (didata == NULL) {
/* memory allocation error */
SDL_OutOfMemory();
return -1;
}
/* Allocate two cursors with SDL_VIDEO_PHOTON_MAX_CURSOR_SIZE size */
/* and 128 bytes of spare place */
didata->cursor_size =
((SDL_VIDEO_PHOTON_MAX_CURSOR_SIZE * 4) >> 3) + 128;
didata->cursor = (PhCursorDef_t *) SDL_calloc(1, didata->cursor_size);
if (didata->cursor == NULL) {
/* memory allocation error */
SDL_OutOfMemory();
SDL_free(didata);
return -1;
}
/* Initialize GF in case of OpenGL ES support is compiled in */
#if defined(SDL_VIDEO_OPENGL_ES)
/* TODO: add real device detection versus multiple heads */
if (phdata->gfinitialized == SDL_TRUE) {
status =
gf_display_attach(&didata->display, phdata->gfdev, it,
&didata->display_info);
if (status != GF_ERR_OK) {
/* Just shutdown GF, do not fail */
gf_dev_detach(phdata->gfdev);
phdata->gfinitialized = SDL_FALSE;
362
}
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
}
#endif /* SDL_VIDEO_OPENGL_ES */
/* Check if current device is not the same as target */
if (phdata->current_device_id != it) {
/* Set target device as default for Pd and Pg functions */
status = PdSetTargetDevice(NULL, phdata->rid[it]);
if (status != 0) {
SDL_SetError("Photon: Can't set default target device\n");
SDL_free(didata->cursor);
SDL_free(didata);
return -1;
}
phdata->current_device_id = it;
}
/* Store device id */
didata->device_id = it;
/* Query photon about graphics hardware caps and current video mode */
383
SDL_memset(&hwcaps, 0x00, sizeof(PgHWCaps_t));
384
385
status = PgGetGraphicsHWCaps(&hwcaps);
if (status != 0) {
386
PhRect_t extent;
387
PdOffscreenContext_t* curctx;
388
389
390
/* If error happens, this also could mean, that photon is working */
/* under custom (not listed by photon) video mode */
391
status=PhWindowQueryVisible(Ph_QUERY_GRAPHICS, 0, 0, &extent);
392
393
394
395
396
397
if (status != 0) {
SDL_SetError("Photon: Can't get graphics driver region");
SDL_free(didata->cursor);
SDL_free(didata);
return -1;
}
398
399
modeinfo.width=extent.lr.x+1;
modeinfo.height=extent.lr.y+1;
400
/* Hardcode 60Hz, as the base refresh rate frequency */
401
hwcaps.current_rrate=60;
402
/* Clear current video driver name, no way to get it somehow */
403
hwcaps.chip_name[0]=0x00;
404
405
406
/* Create offscreen context from video memory, which is currently */
/* displayed on the screen */
407
408
409
curctx=PdCreateOffscreenContext(0, 0, 0, Pg_OSC_MAIN_DISPLAY);
if (curctx==NULL)
{
410
411
412
413
414
415
SDL_SetError("Photon: Can't get display area capabilities");
SDL_free(didata->cursor);
SDL_free(didata);
return -1;
}
/* Retrieve current bpp */
416
modeinfo.type=curctx->format;
417
418
419
420
421
PhDCRelease(curctx);
} else {
/* Get current video mode details */
status = PgGetVideoModeInfo(hwcaps.current_video_mode, &modeinfo);
if (status != 0) {
422
SDL_SetError("Photon: Can't get current video mode information");
423
424
425
426
SDL_free(didata->cursor);
SDL_free(didata);
return -1;
}
427
428
/* Get current video mode 2D capabilities for the renderer */
429
430
431
didata->mode_2dcaps=0;
if ((modeinfo.mode_capabilities2 & PgVM_MODE_CAP2_ALPHA_BLEND)==PgVM_MODE_CAP2_ALPHA_BLEND)
{
432
didata->mode_2dcaps|=SDL_VIDEO_PHOTON_CAP_ALPHA_BLEND;
433
434
435
}
if ((modeinfo.mode_capabilities2 & PgVM_MODE_CAP2_SCALED_BLIT)==PgVM_MODE_CAP2_SCALED_BLIT)
{
436
didata->mode_2dcaps|=SDL_VIDEO_PHOTON_CAP_SCALED_BLIT;
437
}
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
}
/* Setup current desktop mode for SDL */
SDL_zero(current_mode);
current_mode.w = modeinfo.width;
current_mode.h = modeinfo.height;
current_mode.refresh_rate = hwcaps.current_rrate;
current_mode.format = photon_image_to_sdl_pixelformat(modeinfo.type);
current_mode.driverdata = NULL;
/* Copy device name */
SDL_strlcpy(didata->description, hwcaps.chip_name,
SDL_VIDEO_PHOTON_DEVICENAME_MAX - 1);
/* Search device capabilities and possible workarounds */
jt = 0;
do {
if (photon_devicename[jt].name == NULL) {
break;
}
if (SDL_strncmp
(photon_devicename[jt].name, didata->description,
SDL_strlen(photon_devicename[jt].name)) == 0) {
didata->caps = photon_devicename[jt].caps;
}
jt++;
} while (1);
/* Initialize display structure */
SDL_zero(display);
display.desktop_mode = current_mode;
display.current_mode = current_mode;
470
display.fullscreen_mode = current_mode;
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
display.driverdata = didata;
didata->current_mode = current_mode;
SDL_AddVideoDisplay(&display);
/* Check for environment variables which could override some SDL settings */
didata->custom_refresh = 0;
override = SDL_getenv("SDL_VIDEO_PHOTON_REFRESH_RATE");
if (override != NULL) {
if (SDL_sscanf(override, "%u", &didata->custom_refresh) != 1) {
didata->custom_refresh = 0;
}
}
}
/* Add photon input devices */
status = photon_addinputdevices(_this);
if (status != 0) {
/* SDL error is set by photon_addinputdevices() function */
return -1;
}
/* Add photon renderer to SDL */
photon_addrenderdriver(_this);
/* video has been initialized successfully */
return 1;
497
498
}
499
500
void
photon_videoquit(_THIS)
501
{
502
503
504
505
506
507
508
509
510
511
512
513
514
SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
SDL_DisplayData *didata;
uint32_t it;
/* SDL will restore our desktop mode on exit */
for (it = 0; it < _this->num_displays; it++) {
didata = _this->displays[it].driverdata;
if (didata->cursor != NULL) {
SDL_free(didata->cursor);
}
#if defined(SDL_VIDEO_OPENGL_ES)
if (phdata->gfinitialized == SDL_TRUE) {
515
516
/* Detach GF display */
gf_display_detach(didata->display);
517
518
519
}
#endif /* SDL_VIDEO_OPENGL_ES */
}
520
521
}
522
void
523
photon_getdisplaymodes(_THIS, SDL_VideoDisplay * display)
524
{
525
SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
526
SDL_DisplayData *didata = (SDL_DisplayData *) display->driverdata;
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
560
561
562
563
564
565
566
SDL_DisplayMode mode;
PgVideoModes_t modes;
PgVideoModeInfo_t modeinfo;
int32_t status;
uint32_t it;
uint32_t jt;
/* Check if current device is not the same as target */
if (phdata->current_device_id != didata->device_id) {
/* Set target device as default for Pd and Pg functions */
status = PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
if (status != 0) {
SDL_SetError("Photon: Can't set default target device\n");
return;
}
phdata->current_device_id = didata->device_id;
}
/* Get array of available video modes */
status = PgGetVideoModeList(&modes);
if (status != 0) {
SDL_SetError("Photon: Can't get video mode list");
return;
}
for (it = 0; it < modes.num_modes; it++) {
status = PgGetVideoModeInfo(modes.modes[it], &modeinfo);
if (status != 0) {
/* Maybe something wrong with this particular mode, skip it */
continue;
}
jt = 0;
do {
if (modeinfo.refresh_rates[jt] != 0) {
mode.w = modeinfo.width;
mode.h = modeinfo.height;
mode.refresh_rate = modeinfo.refresh_rates[jt];
mode.format = photon_image_to_sdl_pixelformat(modeinfo.type);
mode.driverdata = NULL;
567
SDL_AddDisplayMode(display, &mode);
568
569
570
571
572
573
574
575
/* If mode is RGBA8888, add the same mode as RGBx888 */
if (modeinfo.type == Pg_IMAGE_DIRECT_8888) {
mode.w = modeinfo.width;
mode.h = modeinfo.height;
mode.refresh_rate = modeinfo.refresh_rates[jt];
mode.format = SDL_PIXELFORMAT_RGB888;
mode.driverdata = NULL;
576
SDL_AddDisplayMode(display, &mode);
577
578
579
580
581
582
583
584
585
}
/* If mode is RGBA1555, add the same mode as RGBx555 */
if (modeinfo.type == Pg_IMAGE_DIRECT_1555) {
mode.w = modeinfo.width;
mode.h = modeinfo.height;
mode.refresh_rate = modeinfo.refresh_rates[jt];
mode.format = SDL_PIXELFORMAT_RGB555;
mode.driverdata = NULL;
586
SDL_AddDisplayMode(display, &mode);
587
588
}
589
590
591
592
593
594
jt++;
} else {
break;
}
} while (1);
}
595
596
}
597
int
598
photon_setdisplaymode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
599
{
600
SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
601
SDL_DisplayData *didata = (SDL_DisplayData *) display->driverdata;
602
603
604
605
606
607
608
609
610
611
612
613
614
PgVideoModes_t modes;
PgVideoModeInfo_t modeinfo;
PgDisplaySettings_t modesettings;
uint32_t refresh_rate = 0;
int32_t status;
uint32_t it;
/* Check if current device is not the same as target */
if (phdata->current_device_id != didata->device_id) {
/* Set target device as default for Pd and Pg functions */
status = PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
if (status != 0) {
SDL_SetError("Photon: Can't set default target device\n");
615
return -1;
616
617
618
619
620
621
622
623
}
phdata->current_device_id = didata->device_id;
}
/* Get array of available video modes */
status = PgGetVideoModeList(&modes);
if (status != 0) {
SDL_SetError("Photon: Can't get video mode list");
624
return -1;
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
}
/* Current display dimension and bpp are no more valid */
didata->current_mode.format = SDL_PIXELFORMAT_UNKNOWN;
didata->current_mode.w = 0;
didata->current_mode.h = 0;
/* Check if custom refresh rate requested */
if (didata->custom_refresh != 0) {
refresh_rate = didata->custom_refresh;
} else {
refresh_rate = mode->refresh_rate;
}
/* Check if SDL GF driver needs to find appropriate refresh rate itself */
if (refresh_rate == 0) {
SDL_DisplayMode tempmode;
/* Clear display mode structure */
SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode));
tempmode.refresh_rate = 0x0000FFFF;
/* Check if window width and height matches one of our modes */
648
649
650
651
for (it = 0; it < display->num_display_modes; it++) {
if ((display->display_modes[it].w == mode->w) &&
(display->display_modes[it].h == mode->h) &&
(display->display_modes[it].format == mode->format))
652
{
653
654
/* Find the lowest refresh rate available */
if (tempmode.refresh_rate >
655
656
display->display_modes[it].refresh_rate) {
tempmode = display->display_modes[it];
657
}
658
}
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
}
if (tempmode.refresh_rate != 0x0000FFFF) {
refresh_rate = tempmode.refresh_rate;
} else {
/* Let video driver decide what to do with this */
refresh_rate = 0;
}
}
/* Check if SDL GF driver needs to check custom refresh rate */
if (didata->custom_refresh != 0) {
SDL_DisplayMode tempmode;
/* Clear display mode structure */
SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode));
tempmode.refresh_rate = 0x0000FFFF;
/* Check if window width and height matches one of our modes */
677
678
679
680
for (it = 0; it < display->num_display_modes; it++) {
if ((display->display_modes[it].w == mode->w) &&
(display->display_modes[it].h == mode->h) &&
(display->display_modes[it].format == mode->format))
681
{
682
683
/* Find the lowest refresh rate available */
if (tempmode.refresh_rate >
684
685
display->display_modes[it].refresh_rate) {
tempmode = display->display_modes[it];
686
687
688
689
}
/* Check if requested refresh rate found */
if (refresh_rate ==
690
691
display->display_modes[it].refresh_rate) {
tempmode = display->display_modes[it];
692
693
break;
}
694
}
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
}
if (tempmode.refresh_rate != 0x0000FFFF) {
refresh_rate = tempmode.refresh_rate;
} else {
/* Let video driver decide what to do with this */
refresh_rate = 0;
}
}
/* Find photon's video mode number */
for (it = 0; it < modes.num_modes; it++) {
uint32_t jt;
uint32_t foundrefresh;
/* Get current video mode details */
status = PgGetVideoModeInfo(modes.modes[it], &modeinfo);
if (status != 0) {
/* Maybe something wrong with this particular mode, skip it */
continue;
}
if ((modeinfo.width == mode->w) && (modeinfo.height == mode->h) &&
(modeinfo.type == photon_sdl_to_image_pixelformat(mode->format)))
{
/* Mode is found, find requested refresh rate, this case is for */
/* video drivers, which provide non-generic video modes. */
jt = 0;
foundrefresh = 0;
do {
if (modeinfo.refresh_rates[jt] != 0) {
if (modeinfo.refresh_rates[jt] == refresh_rate) {
foundrefresh = 1;
break;
}
jt++;
} else {
break;
}
} while (1);
if (foundrefresh != 0) {
break;
735
}
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
}
}
/* Check if video mode has not been found */
if (it == modes.num_modes) {
SDL_SetError("Photon: Can't find appropriate video mode");
return -1;
}
/* Fill mode settings */
modesettings.flags = 0x00000000;
modesettings.mode = modes.modes[it];
modesettings.refresh = refresh_rate;
/* Finally set new video mode */
status = PgSetVideoMode(&modesettings);
if (status != 0) {
SDL_SetError("Photon: Can't set new video mode");
return -1;
}
/* Store new video mode parameters */
didata->current_mode = *mode;
didata->current_mode.refresh_rate = refresh_rate;
761
/* Get current video mode 2D capabilities for the renderer */
762
763
764
didata->mode_2dcaps=0;
if ((modeinfo.mode_capabilities2 & PgVM_MODE_CAP2_ALPHA_BLEND)==PgVM_MODE_CAP2_ALPHA_BLEND)
{
765
didata->mode_2dcaps|=SDL_VIDEO_PHOTON_CAP_ALPHA_BLEND;
766
767
768
}
if ((modeinfo.mode_capabilities2 & PgVM_MODE_CAP2_SCALED_BLIT)==PgVM_MODE_CAP2_SCALED_BLIT)
{
769
didata->mode_2dcaps|=SDL_VIDEO_PHOTON_CAP_SCALED_BLIT;
770
771
}
772
return 0;
773
774
}
775
776
int
photon_createwindow(_THIS, SDL_Window * window)
777
{
778
779
SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
SDL_DisplayData *didata =
780
(SDL_DisplayData *) window->display->driverdata;
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
SDL_WindowData *wdata;
PhDim_t winsize;
PhPoint_t winpos;
PtArg_t winargs[32];
uint32_t winargc = 0;
int32_t status;
PhRegion_t wregion;
/* Allocate window internal data */
wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
if (wdata == NULL) {
SDL_OutOfMemory();
return -1;
}
/* Setup driver data for this window */
window->driverdata = wdata;
/* Set initial window title */
if (window->title != NULL) {
PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_TITLE, window->title, 0);
} else {
803
PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_TITLE, "SDL unnamed application", 0);
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
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
866
867
868
}
/* TODO: handle SDL_WINDOW_INPUT_GRABBED */
/* Disable default window filling on redraw */
PtSetArg(&winargs[winargc++], Pt_ARG_BASIC_FLAGS, Pt_TRUE,
Pt_BASIC_PREVENT_FILL);
/* Reset default managed flags to disabled state */
PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE,
Ph_WM_APP_DEF_MANAGED);
/* Set which events we will not handle, let WM to handle them */
PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE,
Ph_WM_BACKDROP | Ph_WM_TOFRONT | Ph_WM_COLLAPSE | Ph_WM_FFRONT |
Ph_WM_FOCUS | Ph_WM_HELP | Ph_WM_HIDE | Ph_WM_MAX |
Ph_WM_MENU | Ph_WM_MOVE | Ph_WM_RESTORE | Ph_WM_TASKBAR |
Ph_WM_TOBACK | Ph_WM_RESIZE);
/* Reset default notify events to disable */
PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE,
Ph_WM_RESIZE | Ph_WM_CLOSE | Ph_WM_HELP);
/* Set which events we will handle */
PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE,
Ph_WM_CLOSE | Ph_WM_COLLAPSE | Ph_WM_FOCUS | Ph_WM_MAX |
Ph_WM_MOVE | Ph_WM_RESIZE | Ph_WM_RESTORE | Ph_WM_HIDE);
/* Borderless window can't be resizeable */
if ((window->flags & SDL_WINDOW_BORDERLESS) == SDL_WINDOW_BORDERLESS) {
window->flags &= ~(SDL_WINDOW_RESIZABLE);
}
/* Reset all default decorations */
PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE,
Ph_WM_APP_DEF_RENDER);
/* Fullscreen window has its own decorations */
if ((window->flags & SDL_WINDOW_FULLSCREEN) == SDL_WINDOW_FULLSCREEN) {
window->flags |= SDL_WINDOW_BORDERLESS;
window->flags &= ~(SDL_WINDOW_RESIZABLE);
PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE,
Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_TITLE);
} else {
uint32_t decorations =
Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MIN |
Ph_WM_RENDER_TITLE | Ph_WM_RENDER_MOVE;
if ((window->flags & SDL_WINDOW_RESIZABLE) == SDL_WINDOW_RESIZABLE) {
decorations |=
Ph_WM_RENDER_BORDER | Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX;
PtSetArg(&winargs[winargc++], Pt_ARG_RESIZE_FLAGS, Pt_TRUE,
Pt_RESIZE_XY_AS_REQUIRED);
}
if ((window->flags & SDL_WINDOW_BORDERLESS) != SDL_WINDOW_BORDERLESS) {
decorations |= Ph_WM_RENDER_BORDER;
}
PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE,
decorations);
}
/* Set initial window state */
PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_FALSE,
Ph_WM_STATE_ISFOCUS);
PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE,
Ph_WM_STATE_ISALTKEY);
869
870
871
872
873
874
875
/* Special case, do not handle maximize events, if window can't be resized */
if ((window->flags & SDL_WINDOW_RESIZABLE) != SDL_WINDOW_RESIZABLE)
{
PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE,
Ph_WM_MAX | Ph_WM_RESTORE | Ph_WM_RESIZE);
}
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
/* Set window dimension */
winsize.w = window->w;
winsize.h = window->h;
PtSetArg(&winargs[winargc++], Pt_ARG_DIM, &winsize, 0);
/* Check if upper level requests WM to position window */
if ((window->x == SDL_WINDOWPOS_UNDEFINED)
&& (window->y == SDL_WINDOWPOS_UNDEFINED)) {
/* Do not set widget position, let WM to set it */
} else {
if (window->x == SDL_WINDOWPOS_UNDEFINED) {
window->x = 0;
}
if (window->y == SDL_WINDOWPOS_UNDEFINED) {
window->y = 0;
}
if (window->x == SDL_WINDOWPOS_CENTERED) {
window->x = (didata->current_mode.w - window->w) / 2;
}
if (window->y == SDL_WINDOWPOS_CENTERED) {
window->y = (didata->current_mode.h - window->h) / 2;
}
/* Now set window position */
winpos.x = window->x;
winpos.y = window->y;
PtSetArg(&winargs[winargc++], Pt_ARG_POS, &winpos, 0);
}
/* Check if window must support OpenGL ES rendering */
if ((window->flags & SDL_WINDOW_OPENGL) == SDL_WINDOW_OPENGL) {
#if defined(SDL_VIDEO_OPENGL_ES)
EGLBoolean initstatus;
/* Check if GF was initialized correctly */
if (phdata->gfinitialized == SDL_FALSE) {
SDL_SetError
("Photon: GF initialization failed, no OpenGL ES support");
914
return -1;
915
}
916
917
918
/* Mark this window as OpenGL ES compatible */
wdata->uses_gles = SDL_TRUE;
919
920
921
922
923
924
925
/* Create connection to OpenGL ES */
if (phdata->egldisplay == EGL_NO_DISPLAY) {
phdata->egldisplay = eglGetDisplay(phdata->gfdev);
if (phdata->egldisplay == EGL_NO_DISPLAY) {
SDL_SetError("Photon: Can't get connection to OpenGL ES");
return -1;
926
927
928
}
/* Initialize OpenGL ES library, ignore EGL version */
929
930
931
932
initstatus = eglInitialize(phdata->egldisplay, NULL, NULL);
if (initstatus != EGL_TRUE) {
SDL_SetError("Photon: Can't init OpenGL ES library");
return -1;
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
}
/* Increment GL ES reference count usage */
phdata->egl_refcount++;
#else
SDL_SetError("Photon: OpenGL ES support is not compiled in");
return -1;
#endif /* SDL_VIDEO_OPENGL_ES */
}
/* Finally create the window */
wdata->window = PtCreateWidget(PtWindow, Pt_NO_PARENT, winargc, winargs);
if (wdata->window == NULL) {
SDL_SetError("Photon: Can't create window widget");
SDL_free(wdata);
return -1;
}
/* Show widget */
status = PtRealizeWidget(wdata->window);
if (status != 0) {
SDL_SetError("Photon: Can't realize window widget");
PtDestroyWidget(wdata->window);
SDL_free(wdata);
return;
}
/* Just created SDL window always gets focus */
window->flags |= SDL_WINDOW_INPUT_FOCUS;
/* Create window-specific cursor after creation */
if (didata->cursor_visible == SDL_TRUE) {
/* Setup cursor type. shape and default color */
PtSetResource(wdata->window, Pt_ARG_CURSOR_COLOR,
Ph_CURSOR_DEFAULT_COLOR, 0);
PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0);
PtSetResource(wdata->window, Pt_ARG_BITMAP_CURSOR, didata->cursor,
didata->cursor->hdr.len + sizeof(PhRegionDataHdr_t));
} else {
PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0);
}
/* Set window region sensible to mouse motion events */
status =
PhRegionQuery(PtWidgetRid(wdata->window), &wregion, NULL, NULL, 0);
if (status != 0) {
SDL_SetError
("Photon: Can't set region sensivity to mouse motion events");
PtDestroyWidget(wdata->window);
SDL_free(wdata);
return -1;
}
wregion.events_sense |=
Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
status = PhRegionChange(Ph_REGION_EV_SENSE, 0, &wregion, NULL, NULL);
if (status < 0) {
SDL_SetError("Photon: Can't change region sensivity");
PtDestroyWidget(wdata->window);
SDL_free(wdata);
return -1;
}
/* Flush all widget operations again */
PtFlush();
/* By default last created window got a input focus */
1000
SDL_SetKeyboardFocus(0, window);