comparison src/video/photon/SDL_photon.c @ 3139:7f684f249ec9

indent
author Sam Lantinga <slouken@libsdl.org>
date Sat, 23 May 2009 22:41:08 +0000
parents 1102a3305928
children 44d5474c2c8a
comparison
equal deleted inserted replaced
3125:d71d8ceda8b3 3139:7f684f249ec9
40 /* Pixel format conversion routines */ 40 /* Pixel format conversion routines */
41 #include "SDL_photon_pixelfmt.h" 41 #include "SDL_photon_pixelfmt.h"
42 42
43 /* Use GF's pixel format functions for OpenGL ES context creation */ 43 /* Use GF's pixel format functions for OpenGL ES context creation */
44 #if defined(SDL_VIDEO_OPENGL_ES) 44 #if defined(SDL_VIDEO_OPENGL_ES)
45 #include "../qnxgf/SDL_gf_pixelfmt.h" 45 #include "../qnxgf/SDL_gf_pixelfmt.h"
46 46
47 /* If GF driver is not compiled in, include some of usefull functions */ 47 /* If GF driver is not compiled in, include some of usefull functions */
48 #if !defined(SDL_VIDEO_DRIVER_QNXGF) 48 #if !defined(SDL_VIDEO_DRIVER_QNXGF)
49 #include "../qnxgf/SDL_gf_pixelfmt.c" 49 #include "../qnxgf/SDL_gf_pixelfmt.c"
50 #endif /* SDL_VIDEO_DRIVER_QNXGF */ 50 #endif /* SDL_VIDEO_DRIVER_QNXGF */
51 #endif /* SDL_VIDEO_OPENGL_ES */ 51 #endif /* SDL_VIDEO_OPENGL_ES */
52 52
53 /* Use GF's OpenGL ES 1.1 functions emulation */ 53 /* Use GF's OpenGL ES 1.1 functions emulation */
54 #if defined(SDL_VIDEO_OPENGL_ES) 54 #if defined(SDL_VIDEO_OPENGL_ES)
55 #include "../qnxgf/SDL_gf_opengles.h" 55 #include "../qnxgf/SDL_gf_opengles.h"
56 56
57 /* If GF driver is not compiled in, include some of usefull functions */ 57 /* If GF driver is not compiled in, include some of usefull functions */
58 #if !defined(SDL_VIDEO_DRIVER_QNXGF) 58 #if !defined(SDL_VIDEO_DRIVER_QNXGF)
59 #include "../qnxgf/SDL_gf_opengles.c" 59 #include "../qnxgf/SDL_gf_opengles.c"
60 #endif /* SDL_VIDEO_DRIVER_QNXGF */ 60 #endif /* SDL_VIDEO_DRIVER_QNXGF */
61 #endif /* SDL_VIDEO_OPENGL_ES */ 61 #endif /* SDL_VIDEO_OPENGL_ES */
62 62
63 /* Low level device graphics driver names, which they are reporting */ 63 /* Low level device graphics driver names, which they are reporting */
64 Photon_DeviceCaps photon_devicename[]= 64 Photon_DeviceCaps photon_devicename[] = {
65 { 65 /* ATI Rage 128 graphics driver (devg-ati_rage128) */
66 /* ATI Rage 128 graphics driver (devg-ati_rage128) */ 66 {"ati_rage128", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
67 {"ati_rage128", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 67 ,
68 /* Fujitsu Carmine graphics driver (devg-carmine.so) */ 68 /* Fujitsu Carmine graphics driver (devg-carmine.so) */
69 {"carmine", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}, 69 {"carmine", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
70 /* C&T graphics driver (devg-chips.so) */ 70 ,
71 {"chips", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 71 /* C&T graphics driver (devg-chips.so) */
72 /* Fujitsu Coral graphics driver (devg-coral.so) */ 72 {"chips", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
73 {"coral", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}, 73 ,
74 /* Intel integrated graphics driver (devg-extreme2.so) */ 74 /* Fujitsu Coral graphics driver (devg-coral.so) */
75 {"extreme2", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}, 75 {"coral", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
76 /* Unaccelerated FB driver (devg-flat.so) */ 76 ,
77 {"flat", SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 77 /* Intel integrated graphics driver (devg-extreme2.so) */
78 /* NS Geode graphics driver (devg-geode.so) */ 78 {"extreme2", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
79 {"geode", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 79 ,
80 /* Geode LX graphics driver (devg-geodelx.so) */ 80 /* Unaccelerated FB driver (devg-flat.so) */
81 {"geodelx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 81 {"flat", SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
82 /* Intel integrated graphics driver (devg-gma9xx.so) */ 82 ,
83 {"gma", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}, 83 /* NS Geode graphics driver (devg-geode.so) */
84 /* Intel integrated graphics driver (devg-i810.so) */ 84 {"geode", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
85 {"i810", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 85 ,
86 /* Intel integrated graphics driver (devg-i830.so) */ 86 /* Geode LX graphics driver (devg-geodelx.so) */
87 {"i830", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 87 {"geodelx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
88 /* Geode LX graphics driver (devg-lx800.so) */ 88 ,
89 {"lx800", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 89 /* Intel integrated graphics driver (devg-gma9xx.so) */
90 /* Matrox Gxx graphics driver (devg-matroxg.so) */ 90 {"gma", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
91 {"matroxg", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 91 ,
92 /* Intel Poulsbo graphics driver (devg-poulsbo.so) */ 92 /* Intel integrated graphics driver (devg-i810.so) */
93 {"poulsbo", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}, 93 {"i810", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
94 /* ATI Radeon driver (devg-radeon.so) */ 94 ,
95 {"radeon", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 95 /* Intel integrated graphics driver (devg-i830.so) */
96 /* ATI Rage driver (devg-rage.so) */ 96 {"i830", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
97 {"rage", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 97 ,
98 /* S3 Savage graphics driver (devg-s3_savage.so) */ 98 /* Geode LX graphics driver (devg-lx800.so) */
99 {"s3_savage", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 99 {"lx800", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
100 /* SiS630 integrated graphics driver (devg-sis630.so) */ 100 ,
101 {"sis630", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 101 /* Matrox Gxx graphics driver (devg-matroxg.so) */
102 /* PowerVR SGX 535 graphics driver (devg-poulsbo.so) */ 102 {"matroxg", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
103 {"sgx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}, 103 ,
104 /* SM Voyager GX graphics driver (devg-smi5xx.so) */ 104 /* Intel Poulsbo graphics driver (devg-poulsbo.so) */
105 {"smi5xx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 105 {"poulsbo", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
106 /* Silicon Motion graphics driver (devg-smi7xx.so) */ 106 ,
107 {"smi7xx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 107 /* ATI Radeon driver (devg-radeon.so) */
108 /* SVGA unaccelerated gfx driver (devg-svga.so) */ 108 {"radeon", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
109 {"svga", SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 109 ,
110 /* nVidia TNT graphics driver (devg-tnt.so) */ 110 /* ATI Rage driver (devg-rage.so) */
111 {"tnt", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 111 {"rage", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
112 /* VIA integrated graphics driver (devg-tvia.so) */ 112 ,
113 {"tvia", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 113 /* S3 Savage graphics driver (devg-s3_savage.so) */
114 /* VIA UniChrome graphics driver (devg-unichrome.so) */ 114 {"s3_savage", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
115 {"unichrome", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 115 ,
116 /* VESA unaccelerated gfx driver (devg-vesa.so) */ 116 /* SiS630 integrated graphics driver (devg-sis630.so) */
117 {"vesa", SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 117 {"sis630", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
118 /* VmWare graphics driver (devg-volari.so) */ 118 ,
119 {"vmware", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 119 /* PowerVR SGX 535 graphics driver (devg-poulsbo.so) */
120 /* XGI XP10 graphics driver (devg-volari.so), OpenGL 1.5*/ 120 {"sgx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
121 {"volari", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}, 121 ,
122 /* End of list */ 122 /* SM Voyager GX graphics driver (devg-smi5xx.so) */
123 {NULL, 0x00000000} 123 {"smi5xx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
124 ,
125 /* Silicon Motion graphics driver (devg-smi7xx.so) */
126 {"smi7xx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
127 ,
128 /* SVGA unaccelerated gfx driver (devg-svga.so) */
129 {"svga", SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
130 ,
131 /* nVidia TNT graphics driver (devg-tnt.so) */
132 {"tnt", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
133 ,
134 /* VIA integrated graphics driver (devg-tvia.so) */
135 {"tvia", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
136 ,
137 /* VIA UniChrome graphics driver (devg-unichrome.so) */
138 {"unichrome", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
139 ,
140 /* VESA unaccelerated gfx driver (devg-vesa.so) */
141 {"vesa", SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
142 ,
143 /* VmWare graphics driver (devg-volari.so) */
144 {"vmware", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
145 ,
146 /* XGI XP10 graphics driver (devg-volari.so), OpenGL 1.5 */
147 {"volari", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
148 ,
149 /* End of list */
150 {NULL, 0x00000000}
124 }; 151 };
125 152
126 static SDL_bool photon_initialized=SDL_FALSE; 153 static SDL_bool photon_initialized = SDL_FALSE;
127 154
128 static int photon_available(void) 155 static int
129 { 156 photon_available(void)
130 int status; 157 {
131 158 int status;
132 /* Check if Photon was initialized before */ 159
133 if (photon_initialized==SDL_FALSE) 160 /* Check if Photon was initialized before */
134 { 161 if (photon_initialized == SDL_FALSE) {
135 /* Initialize Photon widget library and open channel to Photon */ 162 /* Initialize Photon widget library and open channel to Photon */
136 status=PtInit(NULL); 163 status = PtInit(NULL);
137 if (status==0) 164 if (status == 0) {
138 { 165 photon_initialized = SDL_TRUE;
139 photon_initialized=SDL_TRUE; 166 return 1;
140 return 1; 167 } else {
141 } 168 photon_initialized = SDL_FALSE;
142 else 169 return 0;
143 { 170 }
144 photon_initialized=SDL_FALSE; 171 }
145 return 0; 172
146 } 173 return 1;
147 } 174 }
148 175
149 return 1; 176 static void
150 } 177 photon_destroy(SDL_VideoDevice * device)
151 178 {
152 static void photon_destroy(SDL_VideoDevice* device) 179 SDL_VideoData *phdata = (SDL_VideoData *) device->driverdata;
153 { 180
154 SDL_VideoData* phdata=(SDL_VideoData*) device->driverdata; 181 #if defined(SDL_VIDEO_OPENGL_ES)
155 182 if (phdata->gfinitialized != SDL_FALSE) {
156 #if defined(SDL_VIDEO_OPENGL_ES) 183 gf_dev_detach(phdata->gfdev);
157 if (phdata->gfinitialized!=SDL_FALSE) 184 }
158 { 185 #endif /* SDL_VIDEO_OPENGL_ES */
159 gf_dev_detach(phdata->gfdev); 186
160 } 187 if (device->driverdata != NULL) {
161 #endif /* SDL_VIDEO_OPENGL_ES */ 188 device->driverdata = NULL;
162 189 }
163 if (device->driverdata!=NULL) 190 }
164 { 191
165 device->driverdata=NULL; 192 static SDL_VideoDevice *
166 } 193 photon_create(int devindex)
167 } 194 {
168 195 SDL_VideoDevice *device;
169 static SDL_VideoDevice* photon_create(int devindex) 196 SDL_VideoData *phdata;
170 { 197 int status;
171 SDL_VideoDevice* device; 198
172 SDL_VideoData* phdata; 199 /* Check if photon could be initialized */
173 int status; 200 status = photon_available();
174 201 if (status == 0) {
175 /* Check if photon could be initialized */ 202 /* Photon could not be used */
176 status=photon_available(); 203 return NULL;
177 if (status==0) 204 }
178 { 205
179 /* Photon could not be used */ 206 /* Photon agregates all video devices to one with multiple heads */
180 return NULL; 207 if (devindex != 0) {
181 } 208 /* devindex could be zero only in Photon SDL driver */
182 209 return NULL;
183 /* Photon agregates all video devices to one with multiple heads */ 210 }
184 if (devindex!=0) 211
185 { 212 /* Initialize SDL_VideoDevice structure */
186 /* devindex could be zero only in Photon SDL driver */ 213 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
187 return NULL; 214 if (device == NULL) {
188 } 215 SDL_OutOfMemory();
189 216 return NULL;
190 /* Initialize SDL_VideoDevice structure */ 217 }
191 device=(SDL_VideoDevice*)SDL_calloc(1, sizeof(SDL_VideoDevice)); 218
192 if (device==NULL) 219 /* Initialize internal photon specific data */
193 { 220 phdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
194 SDL_OutOfMemory(); 221 if (phdata == NULL) {
195 return NULL; 222 SDL_OutOfMemory();
196 } 223 SDL_free(device);
197 224 return NULL;
198 /* Initialize internal photon specific data */ 225 }
199 phdata=(SDL_VideoData*)SDL_calloc(1, sizeof(SDL_VideoData)); 226 device->driverdata = phdata;
200 if (phdata==NULL) 227
201 { 228 /* Get all photon display devices */
202 SDL_OutOfMemory(); 229 phdata->avail_rids =
203 SDL_free(device); 230 PdGetDevices(&phdata->rid[0], SDL_VIDEO_PHOTON_MAX_RIDS);
204 return NULL; 231 if (phdata->avail_rids > SDL_VIDEO_PHOTON_MAX_RIDS) {
205 } 232 phdata->avail_rids = SDL_VIDEO_PHOTON_MAX_RIDS;
206 device->driverdata=phdata; 233 }
207 234 #if defined(SDL_VIDEO_OPENGL_ES)
208 /* Get all photon display devices */ 235 /* TODO: add real device detection versus multiple heads */
209 phdata->avail_rids=PdGetDevices(&phdata->rid[0], SDL_VIDEO_PHOTON_MAX_RIDS); 236 status =
210 if (phdata->avail_rids>SDL_VIDEO_PHOTON_MAX_RIDS) 237 gf_dev_attach(&phdata->gfdev, GF_DEVICE_INDEX(0),
211 { 238 &phdata->gfdev_info);
212 phdata->avail_rids=SDL_VIDEO_PHOTON_MAX_RIDS; 239 if (status != GF_ERR_OK) {
213 } 240 /* Do not fail right now, if GF can't be attached */
214 241 phdata->gfinitialized = SDL_FALSE;
215 #if defined(SDL_VIDEO_OPENGL_ES) 242 } else {
216 /* TODO: add real device detection versus multiple heads */ 243 phdata->gfinitialized = SDL_TRUE;
217 status=gf_dev_attach(&phdata->gfdev, GF_DEVICE_INDEX(0), &phdata->gfdev_info); 244 }
218 if (status!=GF_ERR_OK) 245 #endif /* SDL_VIDEO_OPENGL_ES */
219 { 246
220 /* Do not fail right now, if GF can't be attached */ 247 /* Set default target device */
221 phdata->gfinitialized=SDL_FALSE; 248 status = PdSetTargetDevice(NULL, phdata->rid[0]);
222 } 249 if (status == -1) {
223 else 250 SDL_SetError("Photon: Can't set default target device");
224 { 251 #if defined(SDL_VIDEO_OPENGL_ES)
225 phdata->gfinitialized=SDL_TRUE; 252 gf_dev_detach(phdata->gfdev);
226 } 253 #endif /* SDL_VIDEO_OPENGL_ES */
227 #endif /* SDL_VIDEO_OPENGL_ES */ 254 SDL_free(phdata);
228 255 SDL_free(device);
229 /* Set default target device */ 256 return NULL;
230 status=PdSetTargetDevice(NULL, phdata->rid[0]); 257 }
231 if (status==-1) 258 phdata->current_device_id = 0;
232 { 259
233 SDL_SetError("Photon: Can't set default target device"); 260 /* Setup amount of available displays and current display */
234 #if defined(SDL_VIDEO_OPENGL_ES) 261 device->num_displays = 0;
235 gf_dev_detach(phdata->gfdev); 262 device->current_display = 0;
236 #endif /* SDL_VIDEO_OPENGL_ES */ 263
237 SDL_free(phdata); 264 /* Set device free function */
238 SDL_free(device); 265 device->free = photon_destroy;
239 return NULL; 266
240 } 267 /* Setup all functions which we can handle */
241 phdata->current_device_id=0; 268 device->VideoInit = photon_videoinit;
242 269 device->VideoQuit = photon_videoquit;
243 /* Setup amount of available displays and current display */ 270 device->GetDisplayModes = photon_getdisplaymodes;
244 device->num_displays=0; 271 device->SetDisplayMode = photon_setdisplaymode;
245 device->current_display=0; 272 device->SetDisplayPalette = photon_setdisplaypalette;
246 273 device->GetDisplayPalette = photon_getdisplaypalette;
247 /* Set device free function */ 274 device->SetDisplayGammaRamp = photon_setdisplaygammaramp;
248 device->free=photon_destroy; 275 device->GetDisplayGammaRamp = photon_getdisplaygammaramp;
249 276 device->CreateWindow = photon_createwindow;
250 /* Setup all functions which we can handle */ 277 device->CreateWindowFrom = photon_createwindowfrom;
251 device->VideoInit=photon_videoinit; 278 device->SetWindowTitle = photon_setwindowtitle;
252 device->VideoQuit=photon_videoquit; 279 device->SetWindowIcon = photon_setwindowicon;
253 device->GetDisplayModes=photon_getdisplaymodes; 280 device->SetWindowPosition = photon_setwindowposition;
254 device->SetDisplayMode=photon_setdisplaymode; 281 device->SetWindowSize = photon_setwindowsize;
255 device->SetDisplayPalette=photon_setdisplaypalette; 282 device->ShowWindow = photon_showwindow;
256 device->GetDisplayPalette=photon_getdisplaypalette; 283 device->HideWindow = photon_hidewindow;
257 device->SetDisplayGammaRamp=photon_setdisplaygammaramp; 284 device->RaiseWindow = photon_raisewindow;
258 device->GetDisplayGammaRamp=photon_getdisplaygammaramp; 285 device->MaximizeWindow = photon_maximizewindow;
259 device->CreateWindow=photon_createwindow; 286 device->MinimizeWindow = photon_minimizewindow;
260 device->CreateWindowFrom=photon_createwindowfrom; 287 device->RestoreWindow = photon_restorewindow;
261 device->SetWindowTitle=photon_setwindowtitle; 288 device->SetWindowGrab = photon_setwindowgrab;
262 device->SetWindowIcon=photon_setwindowicon; 289 device->DestroyWindow = photon_destroywindow;
263 device->SetWindowPosition=photon_setwindowposition; 290 device->GetWindowWMInfo = photon_getwindowwminfo;
264 device->SetWindowSize=photon_setwindowsize; 291 device->GL_LoadLibrary = photon_gl_loadlibrary;
265 device->ShowWindow=photon_showwindow; 292 device->GL_GetProcAddress = photon_gl_getprocaddres;
266 device->HideWindow=photon_hidewindow; 293 device->GL_UnloadLibrary = photon_gl_unloadlibrary;
267 device->RaiseWindow=photon_raisewindow; 294 device->GL_CreateContext = photon_gl_createcontext;
268 device->MaximizeWindow=photon_maximizewindow; 295 device->GL_MakeCurrent = photon_gl_makecurrent;
269 device->MinimizeWindow=photon_minimizewindow; 296 device->GL_SetSwapInterval = photon_gl_setswapinterval;
270 device->RestoreWindow=photon_restorewindow; 297 device->GL_GetSwapInterval = photon_gl_getswapinterval;
271 device->SetWindowGrab=photon_setwindowgrab; 298 device->GL_SwapWindow = photon_gl_swapwindow;
272 device->DestroyWindow=photon_destroywindow; 299 device->GL_DeleteContext = photon_gl_deletecontext;
273 device->GetWindowWMInfo=photon_getwindowwminfo; 300 device->PumpEvents = photon_pumpevents;
274 device->GL_LoadLibrary=photon_gl_loadlibrary; 301 device->SuspendScreenSaver = photon_suspendscreensaver;
275 device->GL_GetProcAddress=photon_gl_getprocaddres; 302
276 device->GL_UnloadLibrary=photon_gl_unloadlibrary; 303 return device;
277 device->GL_CreateContext=photon_gl_createcontext; 304 }
278 device->GL_MakeCurrent=photon_gl_makecurrent; 305
279 device->GL_SetSwapInterval=photon_gl_setswapinterval; 306 VideoBootStrap photon_bootstrap = {
280 device->GL_GetSwapInterval=photon_gl_getswapinterval; 307 "photon",
281 device->GL_SwapWindow=photon_gl_swapwindow; 308 "SDL QNX Photon video driver",
282 device->GL_DeleteContext=photon_gl_deletecontext; 309 photon_available,
283 device->PumpEvents=photon_pumpevents; 310 photon_create
284 device->SuspendScreenSaver=photon_suspendscreensaver;
285
286 return device;
287 }
288
289 VideoBootStrap photon_bootstrap=
290 {
291 "photon",
292 "SDL QNX Photon video driver",
293 photon_available,
294 photon_create
295 }; 311 };
296 312
297 /*****************************************************************************/ 313 /*****************************************************************************/
298 /* SDL Video and Display initialization/handling functions */ 314 /* SDL Video and Display initialization/handling functions */
299 /*****************************************************************************/ 315 /*****************************************************************************/
300 int photon_videoinit(_THIS) 316 int
301 { 317 photon_videoinit(_THIS)
302 SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata; 318 {
303 PgHWCaps_t hwcaps; 319 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
304 PgVideoModeInfo_t modeinfo; 320 PgHWCaps_t hwcaps;
305 int32_t status; 321 PgVideoModeInfo_t modeinfo;
306 SDL_VideoDisplay display; 322 int32_t status;
307 SDL_DisplayMode current_mode; 323 SDL_VideoDisplay display;
308 SDL_DisplayData* didata; 324 SDL_DisplayMode current_mode;
309 uint32_t it; 325 SDL_DisplayData *didata;
310 uint32_t jt; 326 uint32_t it;
311 char* override; 327 uint32_t jt;
312 328 char *override;
313 /* By default Photon do not uses swap on VSYNC */ 329
314 phdata->swapinterval=0; 330 /* By default Photon do not uses swap on VSYNC */
315 331 phdata->swapinterval = 0;
316 for (it=0; it<phdata->avail_rids; it++) 332
317 { 333 for (it = 0; it < phdata->avail_rids; it++) {
318 didata=(SDL_DisplayData*)SDL_calloc(1, sizeof(SDL_DisplayData)); 334 didata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
319 if (didata==NULL) 335 if (didata == NULL) {
320 { 336 /* memory allocation error */
321 /* memory allocation error */ 337 SDL_OutOfMemory();
322 SDL_OutOfMemory(); 338 return -1;
323 return -1; 339 }
324 } 340
325 341 /* Allocate two cursors with SDL_VIDEO_PHOTON_MAX_CURSOR_SIZE size */
326 /* Allocate two cursors with SDL_VIDEO_PHOTON_MAX_CURSOR_SIZE size */ 342 /* and 128 bytes of spare place */
327 /* and 128 bytes of spare place */ 343 didata->cursor_size =
328 didata->cursor_size=((SDL_VIDEO_PHOTON_MAX_CURSOR_SIZE*4)>>3)+128; 344 ((SDL_VIDEO_PHOTON_MAX_CURSOR_SIZE * 4) >> 3) + 128;
329 didata->cursor=(PhCursorDef_t*)SDL_calloc(1, didata->cursor_size); 345 didata->cursor = (PhCursorDef_t *) SDL_calloc(1, didata->cursor_size);
330 if (didata->cursor==NULL) 346 if (didata->cursor == NULL) {
331 { 347 /* memory allocation error */
332 /* memory allocation error */ 348 SDL_OutOfMemory();
333 SDL_OutOfMemory(); 349 SDL_free(didata);
334 SDL_free(didata); 350 return -1;
335 return -1; 351 }
336 } 352
337 353 /* Initialize GF in case of OpenGL ES support is compiled in */
338 /* Initialize GF in case of OpenGL ES support is compiled in */ 354 #if defined(SDL_VIDEO_OPENGL_ES)
339 #if defined(SDL_VIDEO_OPENGL_ES) 355 /* TODO: add real device detection versus multiple heads */
340 /* TODO: add real device detection versus multiple heads */ 356 if (phdata->gfinitialized == SDL_TRUE) {
341 if (phdata->gfinitialized==SDL_TRUE) 357 status =
342 { 358 gf_display_attach(&didata->display, phdata->gfdev, it,
343 status=gf_display_attach(&didata->display, phdata->gfdev, it, &didata->display_info); 359 &didata->display_info);
344 if (status!=GF_ERR_OK) 360 if (status != GF_ERR_OK) {
345 { 361 /* Just shutdown GF, do not fail */
346 /* Just shutdown GF, do not fail */ 362 gf_dev_detach(phdata->gfdev);
347 gf_dev_detach(phdata->gfdev); 363 phdata->gfinitialized = SDL_FALSE;
348 phdata->gfinitialized=SDL_FALSE;
349 } 364 }
350 } 365 }
351 #endif /* SDL_VIDEO_OPENGL_ES */ 366 #endif /* SDL_VIDEO_OPENGL_ES */
352 367
353 /* Check if current device is not the same as target */ 368 /* Check if current device is not the same as target */
354 if (phdata->current_device_id!=it) 369 if (phdata->current_device_id != it) {
355 { 370 /* Set target device as default for Pd and Pg functions */
356 /* Set target device as default for Pd and Pg functions */ 371 status = PdSetTargetDevice(NULL, phdata->rid[it]);
357 status=PdSetTargetDevice(NULL, phdata->rid[it]); 372 if (status != 0) {
358 if (status!=0) 373 SDL_SetError("Photon: Can't set default target device\n");
359 { 374 SDL_free(didata->cursor);
360 SDL_SetError("Photon: Can't set default target device\n"); 375 SDL_free(didata);
376 return -1;
377 }
378 phdata->current_device_id = it;
379 }
380
381 /* Store device id */
382 didata->device_id = it;
383
384 /* Query photon about graphics hardware caps and current video mode */
385 status = PgGetGraphicsHWCaps(&hwcaps);
386 if (status != 0) {
387 SDL_SetError("Photon: Can't get graphics capabilities");
361 SDL_free(didata->cursor); 388 SDL_free(didata->cursor);
362 SDL_free(didata); 389 SDL_free(didata);
363 return -1; 390 return -1;
364 } 391 }
365 phdata->current_device_id=it; 392
366 } 393 /* Get current video mode details */
367 394 status = PgGetVideoModeInfo(hwcaps.current_video_mode, &modeinfo);
368 /* Store device id */ 395 if (status != 0) {
369 didata->device_id=it; 396 SDL_SetError("Photon: Can't get current video mode information");
370 397 SDL_free(didata->cursor);
371 /* Query photon about graphics hardware caps and current video mode */ 398 SDL_free(didata);
372 status=PgGetGraphicsHWCaps(&hwcaps); 399 return -1;
373 if (status!=0) 400 }
374 { 401
375 SDL_SetError("Photon: Can't get graphics capabilities"); 402 /* Setup current desktop mode for SDL */
376 SDL_free(didata->cursor); 403 SDL_zero(current_mode);
377 SDL_free(didata); 404 current_mode.w = modeinfo.width;
378 return -1; 405 current_mode.h = modeinfo.height;
379 } 406 current_mode.refresh_rate = hwcaps.current_rrate;
380 407 current_mode.format = photon_image_to_sdl_pixelformat(modeinfo.type);
381 /* Get current video mode details */ 408 current_mode.driverdata = NULL;
382 status=PgGetVideoModeInfo(hwcaps.current_video_mode, &modeinfo); 409
383 if (status!=0) 410 /* Copy device name */
384 { 411 SDL_strlcpy(didata->description, hwcaps.chip_name,
385 SDL_SetError("Photon: Can't get current video mode information"); 412 SDL_VIDEO_PHOTON_DEVICENAME_MAX - 1);
386 SDL_free(didata->cursor); 413
387 SDL_free(didata); 414 /* Search device capabilities and possible workarounds */
388 return -1; 415 jt = 0;
389 } 416 do {
390 417 if (photon_devicename[jt].name == NULL) {
391 /* Setup current desktop mode for SDL */ 418 break;
392 SDL_zero(current_mode); 419 }
393 current_mode.w=modeinfo.width; 420 if (SDL_strncmp
394 current_mode.h=modeinfo.height; 421 (photon_devicename[jt].name, didata->description,
395 current_mode.refresh_rate=hwcaps.current_rrate; 422 SDL_strlen(photon_devicename[jt].name)) == 0) {
396 current_mode.format=photon_image_to_sdl_pixelformat(modeinfo.type); 423 didata->caps = photon_devicename[jt].caps;
397 current_mode.driverdata=NULL; 424 }
398 425 jt++;
399 /* Copy device name */ 426 } while (1);
400 SDL_strlcpy(didata->description, hwcaps.chip_name, SDL_VIDEO_PHOTON_DEVICENAME_MAX-1); 427
401 428 /* Initialize display structure */
402 /* Search device capabilities and possible workarounds */ 429 SDL_zero(display);
403 jt=0; 430 display.desktop_mode = current_mode;
404 do { 431 display.current_mode = current_mode;
405 if (photon_devicename[jt].name==NULL) 432 display.driverdata = didata;
406 { 433 didata->current_mode = current_mode;
407 break; 434 SDL_AddVideoDisplay(&display);
408 } 435
409 if (SDL_strncmp(photon_devicename[jt].name, didata->description, SDL_strlen(photon_devicename[jt].name))==0) 436 /* Check for environment variables which could override some SDL settings */
410 { 437 didata->custom_refresh = 0;
411 didata->caps=photon_devicename[jt].caps; 438 override = SDL_getenv("SDL_VIDEO_PHOTON_REFRESH_RATE");
412 } 439 if (override != NULL) {
413 jt++; 440 if (SDL_sscanf(override, "%u", &didata->custom_refresh) != 1) {
414 } while(1); 441 didata->custom_refresh = 0;
415 442 }
416 /* Initialize display structure */ 443 }
417 SDL_zero(display); 444 }
418 display.desktop_mode=current_mode; 445
419 display.current_mode=current_mode; 446 /* Add photon input devices */
420 display.driverdata=didata; 447 status = photon_addinputdevices(_this);
421 didata->current_mode=current_mode; 448 if (status != 0) {
422 SDL_AddVideoDisplay(&display); 449 /* SDL error is set by photon_addinputdevices() function */
423 450 return -1;
424 /* Check for environment variables which could override some SDL settings */ 451 }
425 didata->custom_refresh=0; 452
426 override=SDL_getenv("SDL_VIDEO_PHOTON_REFRESH_RATE"); 453 /* Add photon renderer to SDL */
427 if (override!=NULL) 454 photon_addrenderdriver(_this);
428 { 455
429 if (SDL_sscanf(override, "%u", &didata->custom_refresh)!=1) 456 /* video has been initialized successfully */
430 { 457 return 1;
431 didata->custom_refresh=0; 458 }
432 } 459
433 } 460 void
434 } 461 photon_videoquit(_THIS)
435 462 {
436 /* Add photon input devices */ 463 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
437 status=photon_addinputdevices(_this); 464 SDL_DisplayData *didata;
438 if (status!=0) 465 uint32_t it;
439 { 466
440 /* SDL error is set by photon_addinputdevices() function */ 467 /* SDL will restore our desktop mode on exit */
441 return -1; 468 for (it = 0; it < _this->num_displays; it++) {
442 } 469 didata = _this->displays[it].driverdata;
443 470
444 /* Add photon renderer to SDL */ 471 if (didata->cursor != NULL) {
445 photon_addrenderdriver(_this); 472 SDL_free(didata->cursor);
446 473 }
447 /* video has been initialized successfully */ 474 #if defined(SDL_VIDEO_OPENGL_ES)
448 return 1; 475 if (phdata->gfinitialized == SDL_TRUE) {
449 }
450
451 void photon_videoquit(_THIS)
452 {
453 SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
454 SDL_DisplayData* didata;
455 uint32_t it;
456
457 /* SDL will restore our desktop mode on exit */
458 for(it=0; it<_this->num_displays; it++)
459 {
460 didata=_this->displays[it].driverdata;
461
462 if (didata->cursor!=NULL)
463 {
464 SDL_free(didata->cursor);
465 }
466
467 #if defined(SDL_VIDEO_OPENGL_ES)
468 if (phdata->gfinitialized==SDL_TRUE)
469 {
470 /* Detach GF display */ 476 /* Detach GF display */
471 gf_display_detach(didata->display); 477 gf_display_detach(didata->display);
472 } 478 }
473 #endif /* SDL_VIDEO_OPENGL_ES */ 479 #endif /* SDL_VIDEO_OPENGL_ES */
474 } 480 }
475 } 481 }
476 482
477 void photon_getdisplaymodes(_THIS) 483 void
478 { 484 photon_getdisplaymodes(_THIS)
479 SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata; 485 {
480 SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata; 486 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
481 SDL_DisplayMode mode; 487 SDL_DisplayData *didata =
482 PgVideoModes_t modes; 488 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
483 PgVideoModeInfo_t modeinfo; 489 SDL_DisplayMode mode;
484 int32_t status; 490 PgVideoModes_t modes;
485 uint32_t it; 491 PgVideoModeInfo_t modeinfo;
486 uint32_t jt; 492 int32_t status;
487 493 uint32_t it;
488 /* Check if current device is not the same as target */ 494 uint32_t jt;
489 if (phdata->current_device_id!=didata->device_id) 495
490 { 496 /* Check if current device is not the same as target */
491 /* Set target device as default for Pd and Pg functions */ 497 if (phdata->current_device_id != didata->device_id) {
492 status=PdSetTargetDevice(NULL, phdata->rid[didata->device_id]); 498 /* Set target device as default for Pd and Pg functions */
493 if (status!=0) 499 status = PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
494 { 500 if (status != 0) {
495 SDL_SetError("Photon: Can't set default target device\n"); 501 SDL_SetError("Photon: Can't set default target device\n");
496 return; 502 return;
497 } 503 }
498 phdata->current_device_id=didata->device_id; 504 phdata->current_device_id = didata->device_id;
499 } 505 }
500 506
501 /* Get array of available video modes */ 507 /* Get array of available video modes */
502 status=PgGetVideoModeList(&modes); 508 status = PgGetVideoModeList(&modes);
503 if (status!=0) 509 if (status != 0) {
504 { 510 SDL_SetError("Photon: Can't get video mode list");
505 SDL_SetError("Photon: Can't get video mode list"); 511 return;
506 return; 512 }
507 } 513
508 514 for (it = 0; it < modes.num_modes; it++) {
509 for (it=0; it<modes.num_modes; it++) 515 status = PgGetVideoModeInfo(modes.modes[it], &modeinfo);
510 { 516 if (status != 0) {
511 status=PgGetVideoModeInfo(modes.modes[it], &modeinfo); 517 /* Maybe something wrong with this particular mode, skip it */
512 if (status!=0) 518 continue;
513 { 519 }
514 /* Maybe something wrong with this particular mode, skip it */ 520
515 continue; 521 jt = 0;
516 } 522 do {
517 523 if (modeinfo.refresh_rates[jt] != 0) {
518 jt=0; 524 mode.w = modeinfo.width;
519 do { 525 mode.h = modeinfo.height;
520 if (modeinfo.refresh_rates[jt]!=0) 526 mode.refresh_rate = modeinfo.refresh_rates[jt];
521 { 527 mode.format = photon_image_to_sdl_pixelformat(modeinfo.type);
522 mode.w=modeinfo.width; 528 mode.driverdata = NULL;
523 mode.h=modeinfo.height; 529 SDL_AddDisplayMode(_this->current_display, &mode);
524 mode.refresh_rate=modeinfo.refresh_rates[jt]; 530 jt++;
525 mode.format=photon_image_to_sdl_pixelformat(modeinfo.type); 531 } else {
526 mode.driverdata=NULL; 532 break;
527 SDL_AddDisplayMode(_this->current_display, &mode); 533 }
528 jt++; 534 } while (1);
529 } 535 }
530 else 536 }
531 { 537
532 break; 538 int
533 } 539 photon_setdisplaymode(_THIS, SDL_DisplayMode * mode)
534 } while(1); 540 {
535 } 541 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
536 } 542 SDL_DisplayData *didata =
537 543 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
538 int photon_setdisplaymode(_THIS, SDL_DisplayMode* mode) 544 PgVideoModes_t modes;
539 { 545 PgVideoModeInfo_t modeinfo;
540 SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata; 546 PgDisplaySettings_t modesettings;
541 SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata; 547 uint32_t refresh_rate = 0;
542 PgVideoModes_t modes; 548 int32_t status;
543 PgVideoModeInfo_t modeinfo; 549 uint32_t it;
544 PgDisplaySettings_t modesettings; 550
545 uint32_t refresh_rate=0; 551 /* Check if current device is not the same as target */
546 int32_t status; 552 if (phdata->current_device_id != didata->device_id) {
547 uint32_t it; 553 /* Set target device as default for Pd and Pg functions */
548 554 status = PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
549 /* Check if current device is not the same as target */ 555 if (status != 0) {
550 if (phdata->current_device_id!=didata->device_id) 556 SDL_SetError("Photon: Can't set default target device\n");
551 { 557 return;
552 /* Set target device as default for Pd and Pg functions */ 558 }
553 status=PdSetTargetDevice(NULL, phdata->rid[didata->device_id]); 559 phdata->current_device_id = didata->device_id;
554 if (status!=0) 560 }
555 { 561
556 SDL_SetError("Photon: Can't set default target device\n"); 562 /* Get array of available video modes */
557 return; 563 status = PgGetVideoModeList(&modes);
558 } 564 if (status != 0) {
559 phdata->current_device_id=didata->device_id; 565 SDL_SetError("Photon: Can't get video mode list");
560 } 566 return;
561 567 }
562 /* Get array of available video modes */ 568
563 status=PgGetVideoModeList(&modes); 569 /* Current display dimension and bpp are no more valid */
564 if (status!=0) 570 didata->current_mode.format = SDL_PIXELFORMAT_UNKNOWN;
565 { 571 didata->current_mode.w = 0;
566 SDL_SetError("Photon: Can't get video mode list"); 572 didata->current_mode.h = 0;
567 return; 573
568 } 574 /* Check if custom refresh rate requested */
569 575 if (didata->custom_refresh != 0) {
570 /* Current display dimension and bpp are no more valid */ 576 refresh_rate = didata->custom_refresh;
571 didata->current_mode.format=SDL_PIXELFORMAT_UNKNOWN; 577 } else {
572 didata->current_mode.w=0; 578 refresh_rate = mode->refresh_rate;
573 didata->current_mode.h=0; 579 }
574 580
575 /* Check if custom refresh rate requested */ 581 /* Check if SDL GF driver needs to find appropriate refresh rate itself */
576 if (didata->custom_refresh!=0) 582 if (refresh_rate == 0) {
577 { 583 SDL_DisplayMode tempmode;
578 refresh_rate=didata->custom_refresh; 584
579 } 585 /* Clear display mode structure */
580 else 586 SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode));
581 { 587 tempmode.refresh_rate = 0x0000FFFF;
582 refresh_rate=mode->refresh_rate; 588
583 } 589 /* Check if window width and height matches one of our modes */
584 590 for (it = 0; it < SDL_CurrentDisplay.num_display_modes; it++) {
585 /* Check if SDL GF driver needs to find appropriate refresh rate itself */ 591 if ((SDL_CurrentDisplay.display_modes[it].w == mode->w) &&
586 if (refresh_rate==0) 592 (SDL_CurrentDisplay.display_modes[it].h == mode->h) &&
587 { 593 (SDL_CurrentDisplay.display_modes[it].format == mode->format))
588 SDL_DisplayMode tempmode;
589
590 /* Clear display mode structure */
591 SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode));
592 tempmode.refresh_rate=0x0000FFFF;
593
594 /* Check if window width and height matches one of our modes */
595 for (it=0; it<SDL_CurrentDisplay.num_display_modes; it++)
596 {
597 if ((SDL_CurrentDisplay.display_modes[it].w==mode->w) &&
598 (SDL_CurrentDisplay.display_modes[it].h==mode->h) &&
599 (SDL_CurrentDisplay.display_modes[it].format==mode->format))
600 {
601 /* Find the lowest refresh rate available */
602 if (tempmode.refresh_rate>SDL_CurrentDisplay.display_modes[it].refresh_rate)
603 { 594 {
604 tempmode=SDL_CurrentDisplay.display_modes[it]; 595 /* Find the lowest refresh rate available */
596 if (tempmode.refresh_rate >
597 SDL_CurrentDisplay.display_modes[it].refresh_rate) {
598 tempmode = SDL_CurrentDisplay.display_modes[it];
599 }
605 } 600 }
606 } 601 }
607 } 602 if (tempmode.refresh_rate != 0x0000FFFF) {
608 if (tempmode.refresh_rate!=0x0000FFFF) 603 refresh_rate = tempmode.refresh_rate;
609 { 604 } else {
610 refresh_rate=tempmode.refresh_rate; 605 /* Let video driver decide what to do with this */
611 } 606 refresh_rate = 0;
612 else 607 }
613 { 608 }
614 /* Let video driver decide what to do with this */ 609
615 refresh_rate=0; 610 /* Check if SDL GF driver needs to check custom refresh rate */
616 } 611 if (didata->custom_refresh != 0) {
617 } 612 SDL_DisplayMode tempmode;
618 613
619 /* Check if SDL GF driver needs to check custom refresh rate */ 614 /* Clear display mode structure */
620 if (didata->custom_refresh!=0) 615 SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode));
621 { 616 tempmode.refresh_rate = 0x0000FFFF;
622 SDL_DisplayMode tempmode; 617
623 618 /* Check if window width and height matches one of our modes */
624 /* Clear display mode structure */ 619 for (it = 0; it < SDL_CurrentDisplay.num_display_modes; it++) {
625 SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode)); 620 if ((SDL_CurrentDisplay.display_modes[it].w == mode->w) &&
626 tempmode.refresh_rate=0x0000FFFF; 621 (SDL_CurrentDisplay.display_modes[it].h == mode->h) &&
627 622 (SDL_CurrentDisplay.display_modes[it].format == mode->format))
628 /* Check if window width and height matches one of our modes */
629 for (it=0; it<SDL_CurrentDisplay.num_display_modes; it++)
630 {
631 if ((SDL_CurrentDisplay.display_modes[it].w==mode->w) &&
632 (SDL_CurrentDisplay.display_modes[it].h==mode->h) &&
633 (SDL_CurrentDisplay.display_modes[it].format==mode->format))
634 {
635 /* Find the lowest refresh rate available */
636 if (tempmode.refresh_rate>SDL_CurrentDisplay.display_modes[it].refresh_rate)
637 { 623 {
638 tempmode=SDL_CurrentDisplay.display_modes[it]; 624 /* Find the lowest refresh rate available */
625 if (tempmode.refresh_rate >
626 SDL_CurrentDisplay.display_modes[it].refresh_rate) {
627 tempmode = SDL_CurrentDisplay.display_modes[it];
628 }
629
630 /* Check if requested refresh rate found */
631 if (refresh_rate ==
632 SDL_CurrentDisplay.display_modes[it].refresh_rate) {
633 tempmode = SDL_CurrentDisplay.display_modes[it];
634 break;
635 }
639 } 636 }
640 637 }
641 /* Check if requested refresh rate found */ 638 if (tempmode.refresh_rate != 0x0000FFFF) {
642 if (refresh_rate==SDL_CurrentDisplay.display_modes[it].refresh_rate) 639 refresh_rate = tempmode.refresh_rate;
643 { 640 } else {
644 tempmode=SDL_CurrentDisplay.display_modes[it]; 641 /* Let video driver decide what to do with this */
645 break; 642 refresh_rate = 0;
643 }
644 }
645
646 /* Find photon's video mode number */
647 for (it = 0; it < modes.num_modes; it++) {
648 uint32_t jt;
649 uint32_t foundrefresh;
650
651 /* Get current video mode details */
652 status = PgGetVideoModeInfo(modes.modes[it], &modeinfo);
653 if (status != 0) {
654 /* Maybe something wrong with this particular mode, skip it */
655 continue;
656 }
657 if ((modeinfo.width == mode->w) && (modeinfo.height == mode->h) &&
658 (modeinfo.type == photon_sdl_to_image_pixelformat(mode->format)))
659 {
660 /* Mode is found, find requested refresh rate, this case is for */
661 /* video drivers, which provide non-generic video modes. */
662 jt = 0;
663 foundrefresh = 0;
664 do {
665 if (modeinfo.refresh_rates[jt] != 0) {
666 if (modeinfo.refresh_rates[jt] == refresh_rate) {
667 foundrefresh = 1;
668 break;
669 }
670 jt++;
671 } else {
672 break;
673 }
674 } while (1);
675 if (foundrefresh != 0) {
676 break;
646 } 677 }
647 } 678 }
648 } 679 }
649 if (tempmode.refresh_rate!=0x0000FFFF) 680
650 { 681 /* Check if video mode has not been found */
651 refresh_rate=tempmode.refresh_rate; 682 if (it == modes.num_modes) {
652 } 683 SDL_SetError("Photon: Can't find appropriate video mode");
653 else 684 return -1;
654 { 685 }
655 /* Let video driver decide what to do with this */ 686
656 refresh_rate=0; 687 /* Fill mode settings */
657 } 688 modesettings.flags = 0x00000000;
658 } 689 modesettings.mode = modes.modes[it];
659 690 modesettings.refresh = refresh_rate;
660 /* Find photon's video mode number */ 691
661 for (it=0; it<modes.num_modes; it++) 692 /* Finally set new video mode */
662 { 693 status = PgSetVideoMode(&modesettings);
663 uint32_t jt; 694 if (status != 0) {
664 uint32_t foundrefresh; 695 SDL_SetError("Photon: Can't set new video mode");
665 696 return -1;
666 /* Get current video mode details */ 697 }
667 status=PgGetVideoModeInfo(modes.modes[it], &modeinfo); 698
668 if (status!=0) 699 /* Store new video mode parameters */
669 { 700 didata->current_mode = *mode;
670 /* Maybe something wrong with this particular mode, skip it */ 701 didata->current_mode.refresh_rate = refresh_rate;
671 continue; 702
672 } 703 return 0;
673 if ((modeinfo.width==mode->w) && (modeinfo.height==mode->h) && 704 }
674 (modeinfo.type==photon_sdl_to_image_pixelformat(mode->format))) 705
675 { 706 int
676 /* Mode is found, find requested refresh rate, this case is for */ 707 photon_setdisplaypalette(_THIS, SDL_Palette * palette)
677 /* video drivers, which provide non-generic video modes. */ 708 {
678 jt=0; 709 SDL_DisplayData *didata =
679 foundrefresh=0; 710 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
680 do { 711
681 if (modeinfo.refresh_rates[jt]!=0) 712 /* Setting display palette operation has been failed */
682 { 713 return -1;
683 if (modeinfo.refresh_rates[jt]==refresh_rate) 714 }
684 { 715
685 foundrefresh=1; 716 int
686 break; 717 photon_getdisplaypalette(_THIS, SDL_Palette * palette)
687 } 718 {
688 jt++; 719 SDL_DisplayData *didata =
720 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
721
722 /* Getting display palette operation has been failed */
723 return -1;
724 }
725
726 int
727 photon_setdisplaygammaramp(_THIS, Uint16 * ramp)
728 {
729 SDL_DisplayData *didata =
730 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
731
732 /* Setting display gamma ramp operation has been failed */
733 return -1;
734 }
735
736 int
737 photon_getdisplaygammaramp(_THIS, Uint16 * ramp)
738 {
739 /* Getting display gamma ramp operation has been failed */
740 return -1;
741 }
742
743 int
744 photon_createwindow(_THIS, SDL_Window * window)
745 {
746 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
747 SDL_DisplayData *didata =
748 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
749 SDL_WindowData *wdata;
750 PhDim_t winsize;
751 PhPoint_t winpos;
752 PtArg_t winargs[32];
753 uint32_t winargc = 0;
754 int32_t status;
755 PhRegion_t wregion;
756
757 /* Allocate window internal data */
758 wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
759 if (wdata == NULL) {
760 SDL_OutOfMemory();
761 return -1;
762 }
763
764 /* Setup driver data for this window */
765 window->driverdata = wdata;
766
767 /* Set initial window title */
768 if (window->title != NULL) {
769 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_TITLE, window->title, 0);
770 } else {
771 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_TITLE, "", 0);
772 }
773
774 /* TODO: handle SDL_WINDOW_INPUT_GRABBED */
775
776 /* Disable default window filling on redraw */
777 PtSetArg(&winargs[winargc++], Pt_ARG_BASIC_FLAGS, Pt_TRUE,
778 Pt_BASIC_PREVENT_FILL);
779
780 /* Reset default managed flags to disabled state */
781 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE,
782 Ph_WM_APP_DEF_MANAGED);
783 /* Set which events we will not handle, let WM to handle them */
784 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE,
785 Ph_WM_BACKDROP | Ph_WM_TOFRONT | Ph_WM_COLLAPSE | Ph_WM_FFRONT |
786 Ph_WM_FOCUS | Ph_WM_HELP | Ph_WM_HIDE | Ph_WM_MAX |
787 Ph_WM_MENU | Ph_WM_MOVE | Ph_WM_RESTORE | Ph_WM_TASKBAR |
788 Ph_WM_TOBACK | Ph_WM_RESIZE);
789
790 /* Reset default notify events to disable */
791 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE,
792 Ph_WM_RESIZE | Ph_WM_CLOSE | Ph_WM_HELP);
793 /* Set which events we will handle */
794 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE,
795 Ph_WM_CLOSE | Ph_WM_COLLAPSE | Ph_WM_FOCUS | Ph_WM_MAX |
796 Ph_WM_MOVE | Ph_WM_RESIZE | Ph_WM_RESTORE | Ph_WM_HIDE);
797
798 /* Borderless window can't be resizeable */
799 if ((window->flags & SDL_WINDOW_BORDERLESS) == SDL_WINDOW_BORDERLESS) {
800 window->flags &= ~(SDL_WINDOW_RESIZABLE);
801 }
802
803 /* Reset all default decorations */
804 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE,
805 Ph_WM_APP_DEF_RENDER);
806
807 /* Fullscreen window has its own decorations */
808 if ((window->flags & SDL_WINDOW_FULLSCREEN) == SDL_WINDOW_FULLSCREEN) {
809 window->flags |= SDL_WINDOW_BORDERLESS;
810 window->flags &= ~(SDL_WINDOW_RESIZABLE);
811 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE,
812 Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_TITLE);
813 } else {
814 uint32_t decorations =
815 Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MIN |
816 Ph_WM_RENDER_TITLE | Ph_WM_RENDER_MOVE;
817
818 if ((window->flags & SDL_WINDOW_RESIZABLE) == SDL_WINDOW_RESIZABLE) {
819 decorations |=
820 Ph_WM_RENDER_BORDER | Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX;
821 PtSetArg(&winargs[winargc++], Pt_ARG_RESIZE_FLAGS, Pt_TRUE,
822 Pt_RESIZE_XY_AS_REQUIRED);
823 }
824 if ((window->flags & SDL_WINDOW_BORDERLESS) != SDL_WINDOW_BORDERLESS) {
825 decorations |= Ph_WM_RENDER_BORDER;
826 }
827 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE,
828 decorations);
829 }
830
831 /* Set initial window state */
832 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_FALSE,
833 Ph_WM_STATE_ISFOCUS);
834 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE,
835 Ph_WM_STATE_ISALTKEY);
836
837 /* Set window dimension */
838 winsize.w = window->w;
839 winsize.h = window->h;
840 PtSetArg(&winargs[winargc++], Pt_ARG_DIM, &winsize, 0);
841
842 /* Check if upper level requests WM to position window */
843 if ((window->x == SDL_WINDOWPOS_UNDEFINED)
844 && (window->y == SDL_WINDOWPOS_UNDEFINED)) {
845 /* Do not set widget position, let WM to set it */
846 } else {
847 if (window->x == SDL_WINDOWPOS_UNDEFINED) {
848 window->x = 0;
849 }
850 if (window->y == SDL_WINDOWPOS_UNDEFINED) {
851 window->y = 0;
852 }
853 if (window->x == SDL_WINDOWPOS_CENTERED) {
854 window->x = (didata->current_mode.w - window->w) / 2;
855 }
856 if (window->y == SDL_WINDOWPOS_CENTERED) {
857 window->y = (didata->current_mode.h - window->h) / 2;
858 }
859
860 /* Now set window position */
861 winpos.x = window->x;
862 winpos.y = window->y;
863 PtSetArg(&winargs[winargc++], Pt_ARG_POS, &winpos, 0);
864 }
865
866 /* Check if window must support OpenGL ES rendering */
867 if ((window->flags & SDL_WINDOW_OPENGL) == SDL_WINDOW_OPENGL) {
868 #if defined(SDL_VIDEO_OPENGL_ES)
869 EGLBoolean initstatus;
870
871 /* Check if GF was initialized correctly */
872 if (phdata->gfinitialized == SDL_FALSE) {
873 SDL_SetError
874 ("Photon: GF initialization failed, no OpenGL ES support");
875 return -1;
876 }
877
878 /* Mark this window as OpenGL ES compatible */
879 wdata->uses_gles = SDL_TRUE;
880
881 /* Create connection to OpenGL ES */
882 if (phdata->egldisplay == EGL_NO_DISPLAY) {
883 phdata->egldisplay = eglGetDisplay(phdata->gfdev);
884 if (phdata->egldisplay == EGL_NO_DISPLAY) {
885 SDL_SetError("Photon: Can't get connection to OpenGL ES");
886 return -1;
689 } 887 }
690 else 888
691 { 889 /* Initialize OpenGL ES library, ignore EGL version */
692 break; 890 initstatus = eglInitialize(phdata->egldisplay, NULL, NULL);
891 if (initstatus != EGL_TRUE) {
892 SDL_SetError("Photon: Can't init OpenGL ES library");
893 return -1;
693 } 894 }
694 } while(1); 895 }
695 if (foundrefresh!=0) 896
696 { 897 /* Increment GL ES reference count usage */
697 break; 898 phdata->egl_refcount++;
698 } 899 #else
699 } 900 SDL_SetError("Photon: OpenGL ES support is not compiled in");
700 } 901 return -1;
701 902 #endif /* SDL_VIDEO_OPENGL_ES */
702 /* Check if video mode has not been found */ 903 }
703 if (it==modes.num_modes) 904
704 { 905 /* Finally create the window */
705 SDL_SetError("Photon: Can't find appropriate video mode"); 906 wdata->window = PtCreateWidget(PtWindow, Pt_NO_PARENT, winargc, winargs);
706 return -1; 907 if (wdata->window == NULL) {
707 } 908 SDL_SetError("Photon: Can't create window widget");
708 909 SDL_free(wdata);
709 /* Fill mode settings */ 910 return -1;
710 modesettings.flags=0x00000000; 911 }
711 modesettings.mode=modes.modes[it]; 912
712 modesettings.refresh=refresh_rate; 913 /* Show widget */
713 914 status = PtRealizeWidget(wdata->window);
714 /* Finally set new video mode */ 915 if (status != 0) {
715 status=PgSetVideoMode(&modesettings); 916 SDL_SetError("Photon: Can't realize window widget");
716 if (status!=0) 917 PtDestroyWidget(wdata->window);
717 { 918 SDL_free(wdata);
718 SDL_SetError("Photon: Can't set new video mode"); 919 return;
719 return -1; 920 }
720 } 921
721 922 /* Just created SDL window always gets focus */
722 /* Store new video mode parameters */ 923 window->flags |= SDL_WINDOW_INPUT_FOCUS;
723 didata->current_mode=*mode; 924
724 didata->current_mode.refresh_rate=refresh_rate; 925 /* Create window-specific cursor after creation */
725 926 if (didata->cursor_visible == SDL_TRUE) {
726 return 0; 927 /* Setup cursor type. shape and default color */
727 } 928 PtSetResource(wdata->window, Pt_ARG_CURSOR_COLOR,
728 929 Ph_CURSOR_DEFAULT_COLOR, 0);
729 int photon_setdisplaypalette(_THIS, SDL_Palette* palette) 930 PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0);
730 { 931 PtSetResource(wdata->window, Pt_ARG_BITMAP_CURSOR, didata->cursor,
731 SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata; 932 didata->cursor->hdr.len + sizeof(PhRegionDataHdr_t));
732 933 } else {
733 /* Setting display palette operation has been failed */ 934 PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0);
734 return -1; 935 }
735 } 936
736 937 /* Set window region sensible to mouse motion events */
737 int photon_getdisplaypalette(_THIS, SDL_Palette* palette) 938 status =
738 { 939 PhRegionQuery(PtWidgetRid(wdata->window), &wregion, NULL, NULL, 0);
739 SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata; 940 if (status != 0) {
740 941 SDL_SetError
741 /* Getting display palette operation has been failed */ 942 ("Photon: Can't set region sensivity to mouse motion events");
742 return -1; 943 PtDestroyWidget(wdata->window);
743 } 944 SDL_free(wdata);
744 945 return -1;
745 int photon_setdisplaygammaramp(_THIS, Uint16* ramp) 946 }
746 { 947 wregion.events_sense |=
747 SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata; 948 Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
748 949 status = PhRegionChange(Ph_REGION_EV_SENSE, 0, &wregion, NULL, NULL);
749 /* Setting display gamma ramp operation has been failed */ 950 if (status < 0) {
750 return -1; 951 SDL_SetError("Photon: Can't change region sensivity");
751 } 952 PtDestroyWidget(wdata->window);
752 953 SDL_free(wdata);
753 int photon_getdisplaygammaramp(_THIS, Uint16* ramp) 954 return -1;
754 { 955 }
755 /* Getting display gamma ramp operation has been failed */ 956
756 return -1; 957 /* Flush all widget operations again */
757 } 958 PtFlush();
758 959
759 int photon_createwindow(_THIS, SDL_Window* window) 960 /* By default last created window got a input focus */
760 { 961 SDL_SetKeyboardFocus(0, window->id);
761 SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata; 962
762 SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata; 963 /* Window has been successfully created */
763 SDL_WindowData* wdata; 964 return 0;
764 PhDim_t winsize; 965 }
765 PhPoint_t winpos; 966
766 PtArg_t winargs[32]; 967 int
767 uint32_t winargc=0; 968 photon_createwindowfrom(_THIS, SDL_Window * window, const void *data)
768 int32_t status; 969 {
769 PhRegion_t wregion; 970 /* TODO: it is possible */
770 971
771 /* Allocate window internal data */ 972 /* Failed to create window from another window */
772 wdata=(SDL_WindowData*)SDL_calloc(1, sizeof(SDL_WindowData)); 973 return -1;
773 if (wdata==NULL) 974 }
774 { 975
775 SDL_OutOfMemory(); 976 void
776 return -1; 977 photon_setwindowtitle(_THIS, SDL_Window * window)
777 } 978 {
778 979 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
779 /* Setup driver data for this window */ 980 int32_t status;
780 window->driverdata=wdata; 981
781 982 /* Set window title */
782 /* Set initial window title */ 983 if (window->title != NULL) {
783 if (window->title!=NULL) 984 status =
784 { 985 PtSetResource(wdata->window, Pt_ARG_WINDOW_TITLE, window->title,
785 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_TITLE, window->title, 0); 986 0);
786 } 987 } else {
787 else 988 status = PtSetResource(wdata->window, Pt_ARG_WINDOW_TITLE, "", 0);
788 { 989 }
789 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_TITLE, "", 0); 990
790 } 991 if (status != 0) {
791 992 SDL_SetError("Photon: Can't set window title");
792 /* TODO: handle SDL_WINDOW_INPUT_GRABBED */ 993 }
793 994
794 /* Disable default window filling on redraw */ 995 /* Flush all widget operations */
795 PtSetArg(&winargs[winargc++], Pt_ARG_BASIC_FLAGS, Pt_TRUE, Pt_BASIC_PREVENT_FILL); 996 PtFlush();
796 997 }
797 /* Reset default managed flags to disabled state */ 998
798 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, 999 void
799 Ph_WM_APP_DEF_MANAGED); 1000 photon_setwindowicon(_THIS, SDL_Window * window, SDL_Surface * icon)
800 /* Set which events we will not handle, let WM to handle them */ 1001 {
801 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, 1002 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
802 Ph_WM_BACKDROP | Ph_WM_TOFRONT | Ph_WM_COLLAPSE | Ph_WM_FFRONT | 1003 int32_t status;
803 Ph_WM_FOCUS | Ph_WM_HELP | Ph_WM_HIDE | Ph_WM_MAX | 1004
804 Ph_WM_MENU | Ph_WM_MOVE | Ph_WM_RESTORE | Ph_WM_TASKBAR | 1005 /* TODO: Use iconify ? */
805 Ph_WM_TOBACK | Ph_WM_RESIZE); 1006
806 1007 /* Flush all widget operations */
807 /* Reset default notify events to disable */ 1008 PtFlush();
808 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE, 1009 }
809 Ph_WM_RESIZE | Ph_WM_CLOSE | Ph_WM_HELP); 1010
810 /* Set which events we will handle */ 1011 void
811 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, 1012 photon_setwindowposition(_THIS, SDL_Window * window)
812 Ph_WM_CLOSE | Ph_WM_COLLAPSE | Ph_WM_FOCUS | Ph_WM_MAX | 1013 {
813 Ph_WM_MOVE | Ph_WM_RESIZE | Ph_WM_RESTORE | Ph_WM_HIDE); 1014 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
814 1015 SDL_DisplayData *didata =
815 /* Borderless window can't be resizeable */ 1016 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
816 if ((window->flags & SDL_WINDOW_BORDERLESS)==SDL_WINDOW_BORDERLESS) 1017 PhPoint_t winpos;
817 { 1018 int32_t status;
818 window->flags&=~(SDL_WINDOW_RESIZABLE); 1019
819 } 1020 /* Check if upper level requests WM to position window */
820 1021 if ((window->x == SDL_WINDOWPOS_UNDEFINED)
821 /* Reset all default decorations */ 1022 && (window->y == SDL_WINDOWPOS_UNDEFINED)) {
822 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_APP_DEF_RENDER); 1023 /* Do not set widget position, let WM to set it */
823 1024 } else {
824 /* Fullscreen window has its own decorations */ 1025 if (window->x == SDL_WINDOWPOS_UNDEFINED) {
825 if ((window->flags & SDL_WINDOW_FULLSCREEN)==SDL_WINDOW_FULLSCREEN) 1026 window->x = 0;
826 { 1027 }
827 window->flags|=SDL_WINDOW_BORDERLESS; 1028 if (window->y == SDL_WINDOWPOS_UNDEFINED) {
828 window->flags&=~(SDL_WINDOW_RESIZABLE); 1029 window->y = 0;
829 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, 1030 }
830 Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_TITLE); 1031 if (window->x == SDL_WINDOWPOS_CENTERED) {
831 } 1032 window->x = (didata->current_mode.w - window->w) / 2;
832 else 1033 }
833 { 1034 if (window->y == SDL_WINDOWPOS_CENTERED) {
834 uint32_t decorations=Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MIN | 1035 window->y = (didata->current_mode.h - window->h) / 2;
835 Ph_WM_RENDER_TITLE | Ph_WM_RENDER_MOVE; 1036 }
836 1037
837 if ((window->flags & SDL_WINDOW_RESIZABLE)==SDL_WINDOW_RESIZABLE) 1038 /* Now set window position */
838 { 1039 winpos.x = window->x;
839 decorations|=Ph_WM_RENDER_BORDER | Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX; 1040 winpos.y = window->y;
840 PtSetArg(&winargs[winargc++], Pt_ARG_RESIZE_FLAGS, Pt_TRUE, Pt_RESIZE_XY_AS_REQUIRED); 1041 status = PtSetResource(wdata->window, Pt_ARG_POS, &winpos, 0);
841 } 1042 if (status != 0) {
842 if ((window->flags & SDL_WINDOW_BORDERLESS)!=SDL_WINDOW_BORDERLESS) 1043 SDL_SetError("Photon: Can't set window position");
843 { 1044 }
844 decorations|=Ph_WM_RENDER_BORDER; 1045 }
845 } 1046
846 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, decorations); 1047 /* Flush all widget operations */
847 } 1048 PtFlush();
848 1049 }
849 /* Set initial window state */ 1050
850 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISFOCUS); 1051 void
851 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISALTKEY); 1052 photon_setwindowsize(_THIS, SDL_Window * window)
852 1053 {
853 /* Set window dimension */ 1054 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
854 winsize.w=window->w; 1055 PhDim_t winsize;
855 winsize.h=window->h; 1056 int32_t status;
856 PtSetArg(&winargs[winargc++], Pt_ARG_DIM, &winsize, 0); 1057
857 1058 winsize.w = window->w;
858 /* Check if upper level requests WM to position window */ 1059 winsize.h = window->h;
859 if ((window->x==SDL_WINDOWPOS_UNDEFINED) && (window->y==SDL_WINDOWPOS_UNDEFINED)) 1060
860 { 1061 status = PtSetResource(wdata->window, Pt_ARG_DIM, &winsize, 0);
861 /* Do not set widget position, let WM to set it */ 1062 if (status != 0) {
862 } 1063 SDL_SetError("Photon: Can't set window size");
863 else 1064 }
864 { 1065
865 if (window->x==SDL_WINDOWPOS_UNDEFINED) 1066 /* Flush all widget operations */
866 { 1067 PtFlush();
867 window->x=0; 1068 }
868 } 1069
869 if (window->y==SDL_WINDOWPOS_UNDEFINED) 1070 void
870 { 1071 photon_showwindow(_THIS, SDL_Window * window)
871 window->y=0; 1072 {
872 } 1073 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
873 if (window->x==SDL_WINDOWPOS_CENTERED) 1074 int32_t status;
874 { 1075
875 window->x=(didata->current_mode.w-window->w)/2; 1076 /* Bring focus to window and put it in front of others */
876 } 1077 PtWindowToFront(wdata->window);
877 if (window->y==SDL_WINDOWPOS_CENTERED) 1078
878 { 1079 /* Flush all widget operations */
879 window->y=(didata->current_mode.h-window->h)/2; 1080 PtFlush();
880 } 1081 }
881 1082
882 /* Now set window position */ 1083 void
883 winpos.x=window->x; 1084 photon_hidewindow(_THIS, SDL_Window * window)
884 winpos.y=window->y; 1085 {
885 PtSetArg(&winargs[winargc++], Pt_ARG_POS, &winpos, 0); 1086 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
886 } 1087 PhWindowEvent_t winevent;
887 1088 int32_t status;
888 /* Check if window must support OpenGL ES rendering */ 1089
889 if ((window->flags & SDL_WINDOW_OPENGL)==SDL_WINDOW_OPENGL) 1090 SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t));
890 { 1091 winevent.event_f = Ph_WM_HIDE;
891 #if defined(SDL_VIDEO_OPENGL_ES) 1092 winevent.rid = PtWidgetRid(wdata->window);
892 EGLBoolean initstatus; 1093 winevent.event_state = Ph_WM_EVSTATE_HIDE;
893 1094
894 /* Check if GF was initialized correctly */ 1095 status = PtForwardWindowEvent(&winevent);
895 if (phdata->gfinitialized==SDL_FALSE) 1096 if (status != 0) {
896 { 1097 SDL_SetError("Photon: Can't hide window");
897 SDL_SetError("Photon: GF initialization failed, no OpenGL ES support"); 1098 }
898 return -1; 1099
899 } 1100 /* Flush all widget operations */
900 1101 PtFlush();
901 /* Mark this window as OpenGL ES compatible */ 1102 }
902 wdata->uses_gles=SDL_TRUE; 1103
903 1104 void
904 /* Create connection to OpenGL ES */ 1105 photon_raisewindow(_THIS, SDL_Window * window)
905 if (phdata->egldisplay==EGL_NO_DISPLAY) 1106 {
906 { 1107 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
907 phdata->egldisplay=eglGetDisplay(phdata->gfdev); 1108 PhWindowEvent_t winevent;
908 if (phdata->egldisplay==EGL_NO_DISPLAY) 1109 int32_t status;
909 { 1110
910 SDL_SetError("Photon: Can't get connection to OpenGL ES"); 1111 SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t));
911 return -1; 1112 winevent.event_f = Ph_WM_HIDE;
1113 winevent.rid = PtWidgetRid(wdata->window);
1114 winevent.event_state = Ph_WM_EVSTATE_UNHIDE;
1115
1116 status = PtForwardWindowEvent(&winevent);
1117 if (status != 0) {
1118 SDL_SetError("Photon: Can't hide window");
1119 }
1120
1121 /* Flush all widget operations */
1122 PtFlush();
1123 }
1124
1125 void
1126 photon_maximizewindow(_THIS, SDL_Window * window)
1127 {
1128 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
1129 PhWindowEvent_t winevent;
1130 int32_t status;
1131
1132 /* Flush all widget operations */
1133 PtFlush();
1134 }
1135
1136 void
1137 photon_minimizewindow(_THIS, SDL_Window * window)
1138 {
1139 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
1140 PhWindowEvent_t winevent;
1141 int32_t status;
1142
1143 SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t));
1144 winevent.event_f = Ph_WM_HIDE;
1145 winevent.rid = PtWidgetRid(wdata->window);
1146 winevent.event_state = Ph_WM_EVSTATE_HIDE;
1147
1148 status = PtForwardWindowEvent(&winevent);
1149 if (status != 0) {
1150 SDL_SetError("Photon: Can't hide window");
1151 }
1152
1153 /* Flush all widget operations */
1154 PtFlush();
1155 }
1156
1157 void
1158 photon_restorewindow(_THIS, SDL_Window * window)
1159 {
1160 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
1161 PhWindowEvent_t winevent;
1162 int32_t status;
1163
1164 /* Flush all widget operations */
1165 PtFlush();
1166 }
1167
1168 void
1169 photon_setwindowgrab(_THIS, SDL_Window * window)
1170 {
1171 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
1172 PhWindowEvent_t winevent;
1173 int32_t status;
1174
1175 /* Flush all widget operations */
1176 PtFlush();
1177 }
1178
1179 void
1180 photon_destroywindow(_THIS, SDL_Window * window)
1181 {
1182 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
1183 SDL_DisplayData *didata =
1184 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
1185 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
1186 int32_t status;
1187
1188 if (wdata != NULL) {
1189 status = PtDestroyWidget(wdata->window);
1190 if (status != 0) {
1191 SDL_SetError("Photon: Can't destroy window widget");
1192 }
1193 wdata->window = NULL;
1194
1195 #if defined(SDL_VIDEO_OPENGL_ES)
1196 if (phdata->gfinitialized == SDL_TRUE) {
1197 /* Destroy OpenGL ES surface if it was created */
1198 if (wdata->gles_surface != EGL_NO_SURFACE) {
1199 eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
912 } 1200 }
913 1201
914 /* Initialize OpenGL ES library, ignore EGL version */ 1202 /* Free OpenGL ES target surface */
915 initstatus=eglInitialize(phdata->egldisplay, NULL, NULL); 1203 if (wdata->gfsurface != NULL) {
916 if (initstatus!=EGL_TRUE) 1204 gf_surface_free(wdata->gfsurface);
917 {
918 SDL_SetError("Photon: Can't init OpenGL ES library");
919 return -1;
920 } 1205 }
921 } 1206
922 1207 phdata->egl_refcount--;
923 /* Increment GL ES reference count usage */ 1208 if (phdata->egl_refcount == 0) {
924 phdata->egl_refcount++; 1209 /* Terminate connection to OpenGL ES */
925 #else 1210 if (phdata->egldisplay != EGL_NO_DISPLAY) {
926 SDL_SetError("Photon: OpenGL ES support is not compiled in"); 1211 eglTerminate(phdata->egldisplay);
927 return -1; 1212 phdata->egldisplay = EGL_NO_DISPLAY;
928 #endif /* SDL_VIDEO_OPENGL_ES */ 1213 }
929 }
930
931 /* Finally create the window */
932 wdata->window=PtCreateWidget(PtWindow, Pt_NO_PARENT, winargc, winargs);
933 if (wdata->window==NULL)
934 {
935 SDL_SetError("Photon: Can't create window widget");
936 SDL_free(wdata);
937 return -1;
938 }
939
940 /* Show widget */
941 status=PtRealizeWidget(wdata->window);
942 if (status!=0)
943 {
944 SDL_SetError("Photon: Can't realize window widget");
945 PtDestroyWidget(wdata->window);
946 SDL_free(wdata);
947 return;
948 }
949
950 /* Just created SDL window always gets focus */
951 window->flags|=SDL_WINDOW_INPUT_FOCUS;
952
953 /* Create window-specific cursor after creation */
954 if (didata->cursor_visible==SDL_TRUE)
955 {
956 /* Setup cursor type. shape and default color */
957 PtSetResource(wdata->window, Pt_ARG_CURSOR_COLOR, Ph_CURSOR_DEFAULT_COLOR, 0);
958 PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0);
959 PtSetResource(wdata->window, Pt_ARG_BITMAP_CURSOR, didata->cursor, didata->cursor->hdr.len+sizeof(PhRegionDataHdr_t));
960 }
961 else
962 {
963 PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0);
964 }
965
966 /* Set window region sensible to mouse motion events */
967 status=PhRegionQuery(PtWidgetRid(wdata->window), &wregion, NULL, NULL, 0);
968 if (status!=0)
969 {
970 SDL_SetError("Photon: Can't set region sensivity to mouse motion events");
971 PtDestroyWidget(wdata->window);
972 SDL_free(wdata);
973 return -1;
974 }
975 wregion.events_sense|=Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
976 status=PhRegionChange(Ph_REGION_EV_SENSE, 0, &wregion, NULL, NULL);
977 if (status<0)
978 {
979 SDL_SetError("Photon: Can't change region sensivity");
980 PtDestroyWidget(wdata->window);
981 SDL_free(wdata);
982 return -1;
983 }
984
985 /* Flush all widget operations again */
986 PtFlush();
987
988 /* By default last created window got a input focus */
989 SDL_SetKeyboardFocus(0, window->id);
990
991 /* Window has been successfully created */
992 return 0;
993 }
994
995 int photon_createwindowfrom(_THIS, SDL_Window* window, const void* data)
996 {
997 /* TODO: it is possible */
998
999 /* Failed to create window from another window */
1000 return -1;
1001 }
1002
1003 void photon_setwindowtitle(_THIS, SDL_Window* window)
1004 {
1005 SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
1006 int32_t status;
1007
1008 /* Set window title */
1009 if (window->title!=NULL)
1010 {
1011 status=PtSetResource(wdata->window, Pt_ARG_WINDOW_TITLE, window->title, 0);
1012 }
1013 else
1014 {
1015 status=PtSetResource(wdata->window, Pt_ARG_WINDOW_TITLE, "", 0);
1016 }
1017
1018 if (status!=0)
1019 {
1020 SDL_SetError("Photon: Can't set window title");
1021 }
1022
1023 /* Flush all widget operations */
1024 PtFlush();
1025 }
1026
1027 void photon_setwindowicon(_THIS, SDL_Window* window, SDL_Surface* icon)
1028 {
1029 SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
1030 int32_t status;
1031
1032 /* TODO: Use iconify ? */
1033
1034 /* Flush all widget operations */
1035 PtFlush();
1036 }
1037
1038 void photon_setwindowposition(_THIS, SDL_Window* window)
1039 {
1040 SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
1041 SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
1042 PhPoint_t winpos;
1043 int32_t status;
1044
1045 /* Check if upper level requests WM to position window */
1046 if ((window->x==SDL_WINDOWPOS_UNDEFINED) && (window->y==SDL_WINDOWPOS_UNDEFINED))
1047 {
1048 /* Do not set widget position, let WM to set it */
1049 }
1050 else
1051 {
1052 if (window->x==SDL_WINDOWPOS_UNDEFINED)
1053 {
1054 window->x=0;
1055 }
1056 if (window->y==SDL_WINDOWPOS_UNDEFINED)
1057 {
1058 window->y=0;
1059 }
1060 if (window->x==SDL_WINDOWPOS_CENTERED)
1061 {
1062 window->x=(didata->current_mode.w-window->w)/2;
1063 }
1064 if (window->y==SDL_WINDOWPOS_CENTERED)
1065 {
1066 window->y=(didata->current_mode.h-window->h)/2;
1067 }
1068
1069 /* Now set window position */
1070 winpos.x=window->x;
1071 winpos.y=window->y;
1072 status=PtSetResource(wdata->window, Pt_ARG_POS, &winpos, 0);
1073 if (status!=0)
1074 {
1075 SDL_SetError("Photon: Can't set window position");
1076 }
1077 }
1078
1079 /* Flush all widget operations */
1080 PtFlush();
1081 }
1082
1083 void photon_setwindowsize(_THIS, SDL_Window* window)
1084 {
1085 SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
1086 PhDim_t winsize;
1087 int32_t status;
1088
1089 winsize.w=window->w;
1090 winsize.h=window->h;
1091
1092 status=PtSetResource(wdata->window, Pt_ARG_DIM, &winsize, 0);
1093 if (status!=0)
1094 {
1095 SDL_SetError("Photon: Can't set window size");
1096 }
1097
1098 /* Flush all widget operations */
1099 PtFlush();
1100 }
1101
1102 void photon_showwindow(_THIS, SDL_Window* window)
1103 {
1104 SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
1105 int32_t status;
1106
1107 /* Bring focus to window and put it in front of others */
1108 PtWindowToFront(wdata->window);
1109
1110 /* Flush all widget operations */
1111 PtFlush();
1112 }
1113
1114 void photon_hidewindow(_THIS, SDL_Window* window)
1115 {
1116 SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
1117 PhWindowEvent_t winevent;
1118 int32_t status;
1119
1120 SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t));
1121 winevent.event_f=Ph_WM_HIDE;
1122 winevent.rid=PtWidgetRid(wdata->window);
1123 winevent.event_state=Ph_WM_EVSTATE_HIDE;
1124
1125 status=PtForwardWindowEvent(&winevent);
1126 if (status!=0)
1127 {
1128 SDL_SetError("Photon: Can't hide window");
1129 }
1130
1131 /* Flush all widget operations */
1132 PtFlush();
1133 }
1134
1135 void photon_raisewindow(_THIS, SDL_Window* window)
1136 {
1137 SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
1138 PhWindowEvent_t winevent;
1139 int32_t status;
1140
1141 SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t));
1142 winevent.event_f=Ph_WM_HIDE;
1143 winevent.rid=PtWidgetRid(wdata->window);
1144 winevent.event_state=Ph_WM_EVSTATE_UNHIDE;
1145
1146 status=PtForwardWindowEvent(&winevent);
1147 if (status!=0)
1148 {
1149 SDL_SetError("Photon: Can't hide window");
1150 }
1151
1152 /* Flush all widget operations */
1153 PtFlush();
1154 }
1155
1156 void photon_maximizewindow(_THIS, SDL_Window* window)
1157 {
1158 SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
1159 PhWindowEvent_t winevent;
1160 int32_t status;
1161
1162 /* Flush all widget operations */
1163 PtFlush();
1164 }
1165
1166 void photon_minimizewindow(_THIS, SDL_Window* window)
1167 {
1168 SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
1169 PhWindowEvent_t winevent;
1170 int32_t status;
1171
1172 SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t));
1173 winevent.event_f=Ph_WM_HIDE;
1174 winevent.rid=PtWidgetRid(wdata->window);
1175 winevent.event_state=Ph_WM_EVSTATE_HIDE;
1176
1177 status=PtForwardWindowEvent(&winevent);
1178 if (status!=0)
1179 {
1180 SDL_SetError("Photon: Can't hide window");
1181 }
1182
1183 /* Flush all widget operations */
1184 PtFlush();
1185 }
1186
1187 void photon_restorewindow(_THIS, SDL_Window* window)
1188 {
1189 SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
1190 PhWindowEvent_t winevent;
1191 int32_t status;
1192
1193 /* Flush all widget operations */
1194 PtFlush();
1195 }
1196
1197 void photon_setwindowgrab(_THIS, SDL_Window* window)
1198 {
1199 SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
1200 PhWindowEvent_t winevent;
1201 int32_t status;
1202
1203 /* Flush all widget operations */
1204 PtFlush();
1205 }
1206
1207 void photon_destroywindow(_THIS, SDL_Window* window)
1208 {
1209 SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
1210 SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
1211 SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
1212 int32_t status;
1213
1214 if (wdata!=NULL)
1215 {
1216 status=PtDestroyWidget(wdata->window);
1217 if (status!=0)
1218 {
1219 SDL_SetError("Photon: Can't destroy window widget");
1220 }
1221 wdata->window=NULL;
1222
1223 #if defined(SDL_VIDEO_OPENGL_ES)
1224 if (phdata->gfinitialized==SDL_TRUE)
1225 {
1226 /* Destroy OpenGL ES surface if it was created */
1227 if (wdata->gles_surface!=EGL_NO_SURFACE)
1228 {
1229 eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
1230 } 1214 }
1231 1215 }
1232 /* Free OpenGL ES target surface */ 1216 #endif /* SDL_VIDEO_OPENGL_ES */
1233 if (wdata->gfsurface!=NULL) 1217 }
1234 { 1218
1235 gf_surface_free(wdata->gfsurface); 1219 /* Flush all widget operations */
1236 } 1220 PtFlush();
1237
1238 phdata->egl_refcount--;
1239 if (phdata->egl_refcount==0)
1240 {
1241 /* Terminate connection to OpenGL ES */
1242 if (phdata->egldisplay!=EGL_NO_DISPLAY)
1243 {
1244 eglTerminate(phdata->egldisplay);
1245 phdata->egldisplay=EGL_NO_DISPLAY;
1246 }
1247 }
1248 }
1249 #endif /* SDL_VIDEO_OPENGL_ES */
1250 }
1251
1252 /* Flush all widget operations */
1253 PtFlush();
1254 } 1221 }
1255 1222
1256 /*****************************************************************************/ 1223 /*****************************************************************************/
1257 /* SDL Window Manager function */ 1224 /* SDL Window Manager function */
1258 /*****************************************************************************/ 1225 /*****************************************************************************/
1259 SDL_bool photon_getwindowwminfo(_THIS, SDL_Window* window, struct SDL_SysWMinfo* info) 1226 SDL_bool
1260 { 1227 photon_getwindowwminfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
1261 if (info->version.major<=SDL_MAJOR_VERSION) 1228 {
1262 { 1229 if (info->version.major <= SDL_MAJOR_VERSION) {
1263 return SDL_TRUE; 1230 return SDL_TRUE;
1264 } 1231 } else {
1265 else 1232 SDL_SetError("application not compiled with SDL %d.%d\n",
1266 { 1233 SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
1267 SDL_SetError("application not compiled with SDL %d.%d\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION); 1234 return SDL_FALSE;
1268 return SDL_FALSE; 1235 }
1269 } 1236
1270 1237 /* Failed to get window manager information */
1271 /* Failed to get window manager information */ 1238 return SDL_FALSE;
1272 return SDL_FALSE;
1273 } 1239 }
1274 1240
1275 /*****************************************************************************/ 1241 /*****************************************************************************/
1276 /* SDL OpenGL/OpenGL ES functions */ 1242 /* SDL OpenGL/OpenGL ES functions */
1277 /*****************************************************************************/ 1243 /*****************************************************************************/
1278 int photon_gl_loadlibrary(_THIS, const char* path) 1244 int
1279 { 1245 photon_gl_loadlibrary(_THIS, const char *path)
1280 #if defined(SDL_VIDEO_OPENGL_ES) 1246 {
1281 SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata; 1247 #if defined(SDL_VIDEO_OPENGL_ES)
1282 1248 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
1283 if (phdata->gfinitialized!=SDL_TRUE) 1249
1284 { 1250 if (phdata->gfinitialized != SDL_TRUE) {
1285 SDL_SetError("Photon: GF initialization failed, no OpenGL ES support"); 1251 SDL_SetError
1286 return NULL; 1252 ("Photon: GF initialization failed, no OpenGL ES support");
1287 } 1253 return NULL;
1288 1254 }
1289 /* Check if OpenGL ES library is specified for GF driver */ 1255
1290 if (path==NULL) 1256 /* Check if OpenGL ES library is specified for GF driver */
1291 { 1257 if (path == NULL) {
1292 path=SDL_getenv("SDL_OPENGL_LIBRARY"); 1258 path = SDL_getenv("SDL_OPENGL_LIBRARY");
1293 if (path==NULL) 1259 if (path == NULL) {
1294 { 1260 path = SDL_getenv("SDL_OPENGLES_LIBRARY");
1295 path=SDL_getenv("SDL_OPENGLES_LIBRARY"); 1261 }
1296 } 1262 }
1297 } 1263
1298 1264 /* Check if default library loading requested */
1299 /* Check if default library loading requested */ 1265 if (path == NULL) {
1300 if (path==NULL) 1266 /* Already linked with GF library which provides egl* subset of */
1301 { 1267 /* functions, use Common profile of OpenGL ES library by default */
1302 /* Already linked with GF library which provides egl* subset of */ 1268 path = "/usr/lib/libGLES_CM.so.1";
1303 /* functions, use Common profile of OpenGL ES library by default */ 1269 }
1304 path="/usr/lib/libGLES_CM.so.1"; 1270
1305 } 1271 /* Load dynamic library */
1306 1272 _this->gl_config.dll_handle = SDL_LoadObject(path);
1307 /* Load dynamic library */ 1273 if (!_this->gl_config.dll_handle) {
1308 _this->gl_config.dll_handle=SDL_LoadObject(path); 1274 /* Failed to load new GL ES library */
1309 if (!_this->gl_config.dll_handle) 1275 SDL_SetError("Photon: Failed to locate OpenGL ES library");
1310 { 1276 return -1;
1311 /* Failed to load new GL ES library */ 1277 }
1312 SDL_SetError("Photon: Failed to locate OpenGL ES library"); 1278
1313 return -1; 1279 /* Store OpenGL ES library path and name */
1314 } 1280 SDL_strlcpy(_this->gl_config.driver_path, path,
1315 1281 SDL_arraysize(_this->gl_config.driver_path));
1316 /* Store OpenGL ES library path and name */ 1282
1317 SDL_strlcpy(_this->gl_config.driver_path, path, SDL_arraysize(_this->gl_config.driver_path)); 1283 /* New OpenGL ES library is loaded */
1318 1284 return 0;
1319 /* New OpenGL ES library is loaded */ 1285 #else
1320 return 0; 1286 SDL_SetError("Photon: OpenGL ES support is not compiled in");
1321 #else 1287 return -1;
1322 SDL_SetError("Photon: OpenGL ES support is not compiled in"); 1288 #endif /* SDL_VIDEO_OPENGL_ES */
1323 return -1; 1289 }
1324 #endif /* SDL_VIDEO_OPENGL_ES */ 1290
1325 } 1291 void *
1326 1292 photon_gl_getprocaddres(_THIS, const char *proc)
1327 void* photon_gl_getprocaddres(_THIS, const char* proc) 1293 {
1328 { 1294 #if defined(SDL_VIDEO_OPENGL_ES)
1329 #if defined(SDL_VIDEO_OPENGL_ES) 1295 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
1330 SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata; 1296 void *function_address;
1331 void* function_address; 1297
1332 1298 if (phdata->gfinitialized != SDL_TRUE) {
1333 if (phdata->gfinitialized!=SDL_TRUE) 1299 SDL_SetError
1334 { 1300 ("Photon: GF initialization failed, no OpenGL ES support");
1335 SDL_SetError("Photon: GF initialization failed, no OpenGL ES support"); 1301 return NULL;
1336 return NULL; 1302 }
1337 } 1303
1338 1304 /* Try to get function address through the egl interface */
1339 /* Try to get function address through the egl interface */ 1305 function_address = eglGetProcAddress(proc);
1340 function_address=eglGetProcAddress(proc); 1306 if (function_address != NULL) {
1341 if (function_address!=NULL) 1307 return function_address;
1342 { 1308 }
1343 return function_address; 1309
1344 } 1310 /* Then try to get function in the OpenGL ES library */
1345 1311 if (_this->gl_config.dll_handle) {
1346 /* Then try to get function in the OpenGL ES library */ 1312 function_address =
1347 if (_this->gl_config.dll_handle) 1313 SDL_LoadFunction(_this->gl_config.dll_handle, proc);
1348 { 1314 if (function_address != NULL) {
1349 function_address=SDL_LoadFunction(_this->gl_config.dll_handle, proc);
1350 if (function_address!=NULL)
1351 {
1352 return function_address; 1315 return function_address;
1353 } 1316 }
1354 } 1317 }
1355 1318
1356 /* Add emulated OpenGL ES 1.1 functions */ 1319 /* Add emulated OpenGL ES 1.1 functions */
1357 if (SDL_strcmp(proc, "glTexParameteri")==0) 1320 if (SDL_strcmp(proc, "glTexParameteri") == 0) {
1358 { 1321 return glTexParameteri;
1359 return glTexParameteri; 1322 }
1360 } 1323 if (SDL_strcmp(proc, "glTexParameteriv") == 0) {
1361 if (SDL_strcmp(proc, "glTexParameteriv")==0) 1324 return glTexParameteriv;
1362 { 1325 }
1363 return glTexParameteriv; 1326 if (SDL_strcmp(proc, "glColor4ub") == 0) {
1364 } 1327 return glColor4ub;
1365 if (SDL_strcmp(proc, "glColor4ub")==0) 1328 }
1366 { 1329
1367 return glColor4ub; 1330 /* Failed to get GL ES function address pointer */
1368 } 1331 SDL_SetError("Photon: Cannot locate OpenGL ES function name");
1369 1332 return NULL;
1370 /* Failed to get GL ES function address pointer */ 1333 #else
1371 SDL_SetError("Photon: Cannot locate OpenGL ES function name"); 1334 SDL_SetError("Photon: OpenGL ES support is not compiled in");
1372 return NULL; 1335 return NULL;
1373 #else 1336 #endif /* SDL_VIDEO_OPENGL_ES */
1374 SDL_SetError("Photon: OpenGL ES support is not compiled in"); 1337 }
1375 return NULL; 1338
1376 #endif /* SDL_VIDEO_OPENGL_ES */ 1339 void
1377 } 1340 photon_gl_unloadlibrary(_THIS)
1378 1341 {
1379 void photon_gl_unloadlibrary(_THIS) 1342 #if defined(SDL_VIDEO_OPENGL_ES)
1380 { 1343 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
1381 #if defined(SDL_VIDEO_OPENGL_ES) 1344
1382 SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata; 1345 if (phdata->gfinitialized == SDL_TRUE) {
1383 1346 /* Unload OpenGL ES library */
1384 if (phdata->gfinitialized==SDL_TRUE) 1347 if (_this->gl_config.dll_handle) {
1385 {
1386 /* Unload OpenGL ES library */
1387 if (_this->gl_config.dll_handle)
1388 {
1389 SDL_UnloadObject(_this->gl_config.dll_handle); 1348 SDL_UnloadObject(_this->gl_config.dll_handle);
1390 _this->gl_config.dll_handle=NULL; 1349 _this->gl_config.dll_handle = NULL;
1391 } 1350 }
1392 } 1351 } else {
1393 else 1352 SDL_SetError
1394 { 1353 ("Photon: GF initialization failed, no OpenGL ES support");
1395 SDL_SetError("Photon: GF initialization failed, no OpenGL ES support"); 1354 }
1396 } 1355 #else
1397 #else 1356 SDL_SetError("Photon: OpenGL ES support is not compiled in");
1398 SDL_SetError("Photon: OpenGL ES support is not compiled in"); 1357 return;
1399 return; 1358 #endif /* SDL_VIDEO_OPENGL_ES */
1400 #endif /* SDL_VIDEO_OPENGL_ES */ 1359 }
1401 } 1360
1402 1361 SDL_GLContext
1403 SDL_GLContext photon_gl_createcontext(_THIS, SDL_Window* window) 1362 photon_gl_createcontext(_THIS, SDL_Window * window)
1404 { 1363 {
1405 #if defined(SDL_VIDEO_OPENGL_ES) 1364 #if defined(SDL_VIDEO_OPENGL_ES)
1406 SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata; 1365 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
1407 SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata; 1366 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
1408 SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata; 1367 SDL_DisplayData *didata =
1409 EGLBoolean status; 1368 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
1410 int32_t gfstatus; 1369 EGLBoolean status;
1411 EGLint configs; 1370 int32_t gfstatus;
1412 uint32_t attr_pos; 1371 EGLint configs;
1413 EGLint attr_value; 1372 uint32_t attr_pos;
1414 EGLint cit; 1373 EGLint attr_value;
1415 1374 EGLint cit;
1416 /* Check if GF was initialized */ 1375
1417 if (phdata->gfinitialized!=SDL_TRUE) 1376 /* Check if GF was initialized */
1418 { 1377 if (phdata->gfinitialized != SDL_TRUE) {
1419 SDL_SetError("Photon: GF initialization failed, no OpenGL ES support"); 1378 SDL_SetError
1420 return NULL; 1379 ("Photon: GF initialization failed, no OpenGL ES support");
1421 } 1380 return NULL;
1422 1381 }
1423 /* Prepare attributes list to pass them to OpenGL ES */ 1382
1424 attr_pos=0; 1383 /* Prepare attributes list to pass them to OpenGL ES */
1425 wdata->gles_attributes[attr_pos++]=EGL_NATIVE_VISUAL_ID; 1384 attr_pos = 0;
1426 wdata->gles_attributes[attr_pos++]=qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format); 1385 wdata->gles_attributes[attr_pos++] = EGL_NATIVE_VISUAL_ID;
1427 wdata->gles_attributes[attr_pos++]=EGL_RED_SIZE; 1386 wdata->gles_attributes[attr_pos++] =
1428 wdata->gles_attributes[attr_pos++]=_this->gl_config.red_size; 1387 qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format);
1429 wdata->gles_attributes[attr_pos++]=EGL_GREEN_SIZE; 1388 wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE;
1430 wdata->gles_attributes[attr_pos++]=_this->gl_config.green_size; 1389 wdata->gles_attributes[attr_pos++] = _this->gl_config.red_size;
1431 wdata->gles_attributes[attr_pos++]=EGL_BLUE_SIZE; 1390 wdata->gles_attributes[attr_pos++] = EGL_GREEN_SIZE;
1432 wdata->gles_attributes[attr_pos++]=_this->gl_config.blue_size; 1391 wdata->gles_attributes[attr_pos++] = _this->gl_config.green_size;
1433 wdata->gles_attributes[attr_pos++]=EGL_ALPHA_SIZE; 1392 wdata->gles_attributes[attr_pos++] = EGL_BLUE_SIZE;
1434 1393 wdata->gles_attributes[attr_pos++] = _this->gl_config.blue_size;
1435 /* Setup alpha size in bits */ 1394 wdata->gles_attributes[attr_pos++] = EGL_ALPHA_SIZE;
1436 if (_this->gl_config.alpha_size) 1395
1437 { 1396 /* Setup alpha size in bits */
1438 wdata->gles_attributes[attr_pos++]=_this->gl_config.alpha_size; 1397 if (_this->gl_config.alpha_size) {
1439 } 1398 wdata->gles_attributes[attr_pos++] = _this->gl_config.alpha_size;
1440 else 1399 } else {
1441 { 1400 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
1442 wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE; 1401 }
1443 } 1402
1444 1403 /* Setup color buffer size */
1445 /* Setup color buffer size */ 1404 if (_this->gl_config.buffer_size) {
1446 if (_this->gl_config.buffer_size) 1405 wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
1447 { 1406 wdata->gles_attributes[attr_pos++] = _this->gl_config.buffer_size;
1448 wdata->gles_attributes[attr_pos++]=EGL_BUFFER_SIZE; 1407 } else {
1449 wdata->gles_attributes[attr_pos++]=_this->gl_config.buffer_size; 1408 wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
1450 } 1409 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
1451 else 1410 }
1452 { 1411
1453 wdata->gles_attributes[attr_pos++]=EGL_BUFFER_SIZE; 1412 /* Setup depth buffer bits */
1454 wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE; 1413 wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
1455 } 1414 wdata->gles_attributes[attr_pos++] = _this->gl_config.depth_size;
1456 1415
1457 /* Setup depth buffer bits */ 1416 /* Setup stencil bits */
1458 wdata->gles_attributes[attr_pos++]=EGL_DEPTH_SIZE; 1417 if (_this->gl_config.stencil_size) {
1459 wdata->gles_attributes[attr_pos++]=_this->gl_config.depth_size; 1418 wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
1460 1419 wdata->gles_attributes[attr_pos++] = _this->gl_config.buffer_size;
1461 /* Setup stencil bits */ 1420 } else {
1462 if (_this->gl_config.stencil_size) 1421 wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
1463 { 1422 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
1464 wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE; 1423 }
1465 wdata->gles_attributes[attr_pos++]=_this->gl_config.buffer_size; 1424
1466 } 1425 /* Set number of samples in multisampling */
1467 else 1426 if (_this->gl_config.multisamplesamples) {
1468 { 1427 wdata->gles_attributes[attr_pos++] = EGL_SAMPLES;
1469 wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE; 1428 wdata->gles_attributes[attr_pos++] =
1470 wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE; 1429 _this->gl_config.multisamplesamples;
1471 } 1430 }
1472 1431
1473 /* Set number of samples in multisampling */ 1432 /* Multisample buffers, OpenGL ES 1.0 spec defines 0 or 1 buffer */
1474 if (_this->gl_config.multisamplesamples) 1433 if (_this->gl_config.multisamplebuffers) {
1475 { 1434 wdata->gles_attributes[attr_pos++] = EGL_SAMPLE_BUFFERS;
1476 wdata->gles_attributes[attr_pos++]=EGL_SAMPLES; 1435 wdata->gles_attributes[attr_pos++] =
1477 wdata->gles_attributes[attr_pos++]=_this->gl_config.multisamplesamples; 1436 _this->gl_config.multisamplebuffers;
1478 } 1437 }
1479 1438
1480 /* Multisample buffers, OpenGL ES 1.0 spec defines 0 or 1 buffer */ 1439 /* Finish attributes list */
1481 if (_this->gl_config.multisamplebuffers) 1440 wdata->gles_attributes[attr_pos] = EGL_NONE;
1482 { 1441
1483 wdata->gles_attributes[attr_pos++]=EGL_SAMPLE_BUFFERS; 1442 /* Request first suitable framebuffer configuration */
1484 wdata->gles_attributes[attr_pos++]=_this->gl_config.multisamplebuffers; 1443 status = eglChooseConfig(phdata->egldisplay, wdata->gles_attributes,
1485 } 1444 wdata->gles_configs, SDL_VIDEO_GF_OPENGLES_CONFS,
1486 1445 &configs);
1487 /* Finish attributes list */ 1446 if (status != EGL_TRUE) {
1488 wdata->gles_attributes[attr_pos]=EGL_NONE; 1447 SDL_SetError
1489 1448 ("Photon: Can't find closest configuration for OpenGL ES");
1490 /* Request first suitable framebuffer configuration */ 1449 return NULL;
1491 status=eglChooseConfig(phdata->egldisplay, wdata->gles_attributes, 1450 }
1492 wdata->gles_configs, SDL_VIDEO_GF_OPENGLES_CONFS, &configs); 1451
1493 if (status!=EGL_TRUE) 1452 /* Check if nothing has been found, try "don't care" settings */
1494 { 1453 if (configs == 0) {
1495 SDL_SetError("Photon: Can't find closest configuration for OpenGL ES"); 1454 int32_t it;
1496 return NULL; 1455 int32_t jt;
1497 } 1456 GLint depthbits[4] = { 32, 24, 16, EGL_DONT_CARE };
1498 1457
1499 /* Check if nothing has been found, try "don't care" settings */ 1458 for (it = 0; it < 4; it++) {
1500 if (configs==0) 1459 for (jt = 16; jt >= 0; jt--) {
1501 { 1460 /* Don't care about color buffer bits, use what exist */
1502 int32_t it; 1461 /* Replace previous set data with EGL_DONT_CARE */
1503 int32_t jt; 1462 attr_pos = 0;
1504 GLint depthbits[4]={32, 24, 16, EGL_DONT_CARE}; 1463 wdata->gles_attributes[attr_pos++] = EGL_NATIVE_VISUAL_ID;
1505 1464 wdata->gles_attributes[attr_pos++] =
1506 for (it=0; it<4; it++) 1465 qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format);
1507 { 1466 wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE;
1508 for (jt=16; jt>=0; jt--) 1467 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
1509 { 1468 wdata->gles_attributes[attr_pos++] = EGL_GREEN_SIZE;
1510 /* Don't care about color buffer bits, use what exist */ 1469 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
1511 /* Replace previous set data with EGL_DONT_CARE */ 1470 wdata->gles_attributes[attr_pos++] = EGL_BLUE_SIZE;
1512 attr_pos=0; 1471 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
1513 wdata->gles_attributes[attr_pos++]=EGL_NATIVE_VISUAL_ID; 1472 wdata->gles_attributes[attr_pos++] = EGL_ALPHA_SIZE;
1514 wdata->gles_attributes[attr_pos++]=qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format); 1473 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
1515 wdata->gles_attributes[attr_pos++]=EGL_RED_SIZE; 1474 wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
1516 wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE; 1475 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
1517 wdata->gles_attributes[attr_pos++]=EGL_GREEN_SIZE; 1476
1518 wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE; 1477 /* Try to find requested or smallest depth */
1519 wdata->gles_attributes[attr_pos++]=EGL_BLUE_SIZE; 1478 if (_this->gl_config.depth_size) {
1520 wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE; 1479 wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
1521 wdata->gles_attributes[attr_pos++]=EGL_ALPHA_SIZE; 1480 wdata->gles_attributes[attr_pos++] = depthbits[it];
1522 wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE; 1481 } else {
1523 wdata->gles_attributes[attr_pos++]=EGL_BUFFER_SIZE; 1482 wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
1524 wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE; 1483 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
1525 1484 }
1526 /* Try to find requested or smallest depth */ 1485
1527 if (_this->gl_config.depth_size) 1486 if (_this->gl_config.stencil_size) {
1528 { 1487 wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
1529 wdata->gles_attributes[attr_pos++]=EGL_DEPTH_SIZE; 1488 wdata->gles_attributes[attr_pos++] = jt;
1530 wdata->gles_attributes[attr_pos++]=depthbits[it]; 1489 } else {
1531 } 1490 wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
1532 else 1491 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
1533 { 1492 }
1534 wdata->gles_attributes[attr_pos++]=EGL_DEPTH_SIZE; 1493
1535 wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE; 1494 wdata->gles_attributes[attr_pos++] = EGL_SAMPLES;
1536 } 1495 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
1537 1496 wdata->gles_attributes[attr_pos++] = EGL_SAMPLE_BUFFERS;
1538 if (_this->gl_config.stencil_size) 1497 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
1539 { 1498 wdata->gles_attributes[attr_pos] = EGL_NONE;
1540 wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE; 1499
1541 wdata->gles_attributes[attr_pos++]=jt; 1500 /* Request first suitable framebuffer configuration */
1542 } 1501 status =
1543 else 1502 eglChooseConfig(phdata->egldisplay,
1544 { 1503 wdata->gles_attributes,
1545 wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE; 1504 wdata->gles_configs,
1546 wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE; 1505 SDL_VIDEO_GF_OPENGLES_CONFS, &configs);
1547 } 1506 if (status != EGL_TRUE) {
1548 1507 SDL_SetError
1549 wdata->gles_attributes[attr_pos++]=EGL_SAMPLES; 1508 ("Photon: Can't find closest configuration for OpenGL ES");
1550 wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE; 1509 return NULL;
1551 wdata->gles_attributes[attr_pos++]=EGL_SAMPLE_BUFFERS; 1510 }
1552 wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE; 1511 if (configs != 0) {
1553 wdata->gles_attributes[attr_pos]=EGL_NONE; 1512 break;
1554 1513 }
1555 /* Request first suitable framebuffer configuration */
1556 status=eglChooseConfig(phdata->egldisplay, wdata->gles_attributes,
1557 wdata->gles_configs, SDL_VIDEO_GF_OPENGLES_CONFS, &configs);
1558 if (status!=EGL_TRUE)
1559 {
1560 SDL_SetError("Photon: Can't find closest configuration for OpenGL ES");
1561 return NULL;
1562 }
1563 if (configs!=0)
1564 {
1565 break;
1566 }
1567 } 1514 }
1568 if (configs!=0) 1515 if (configs != 0) {
1569 { 1516 break;
1570 break;
1571 } 1517 }
1572 } 1518 }
1573 1519
1574 /* No available configs */ 1520 /* No available configs */
1575 if (configs==0) 1521 if (configs == 0) {
1576 { 1522 SDL_SetError
1577 SDL_SetError("Photon: Can't find any configuration for OpenGL ES"); 1523 ("Photon: Can't find any configuration for OpenGL ES");
1578 return NULL; 1524 return NULL;
1579 } 1525 }
1580 } 1526 }
1581 1527
1582 /* Initialize config index */ 1528 /* Initialize config index */
1583 wdata->gles_config=0; 1529 wdata->gles_config = 0;
1584 1530
1585 /* Now check each configuration to find out the best */ 1531 /* Now check each configuration to find out the best */
1586 for (cit=0; cit<configs; cit++) 1532 for (cit = 0; cit < configs; cit++) {
1587 { 1533 uint32_t stencil_found;
1588 uint32_t stencil_found; 1534 uint32_t depth_found;
1589 uint32_t depth_found; 1535
1590 1536 stencil_found = 0;
1591 stencil_found=0; 1537 depth_found = 0;
1592 depth_found=0; 1538
1593 1539 if (_this->gl_config.stencil_size) {
1594 if (_this->gl_config.stencil_size) 1540 status =
1595 { 1541 eglGetConfigAttrib(phdata->egldisplay,
1596 status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[cit], EGL_STENCIL_SIZE, &attr_value); 1542 wdata->gles_configs[cit], EGL_STENCIL_SIZE,
1597 if (status==EGL_TRUE) 1543 &attr_value);
1598 { 1544 if (status == EGL_TRUE) {
1599 if (attr_value!=0) 1545 if (attr_value != 0) {
1600 { 1546 stencil_found = 1;
1601 stencil_found=1; 1547 }
1602 }
1603 } 1548 }
1604 } 1549 } else {
1605 else 1550 stencil_found = 1;
1606 { 1551 }
1607 stencil_found=1; 1552
1608 } 1553 if (_this->gl_config.depth_size) {
1609 1554 status =
1610 if (_this->gl_config.depth_size) 1555 eglGetConfigAttrib(phdata->egldisplay,
1611 { 1556 wdata->gles_configs[cit], EGL_DEPTH_SIZE,
1612 status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[cit], EGL_DEPTH_SIZE, &attr_value); 1557 &attr_value);
1613 if (status==EGL_TRUE) 1558 if (status == EGL_TRUE) {
1614 { 1559 if (attr_value != 0) {
1615 if (attr_value!=0) 1560 depth_found = 1;
1616 { 1561 }
1617 depth_found=1;
1618 }
1619 } 1562 }
1620 } 1563 } else {
1621 else 1564 depth_found = 1;
1622 { 1565 }
1623 depth_found=1; 1566
1624 } 1567 /* Exit from loop if found appropriate configuration */
1625 1568 if ((depth_found != 0) && (stencil_found != 0)) {
1626 /* Exit from loop if found appropriate configuration */
1627 if ((depth_found!=0) && (stencil_found!=0))
1628 {
1629 break; 1569 break;
1630 } 1570 }
1631 } 1571 }
1632 1572
1633 /* If best could not be found, use first */ 1573 /* If best could not be found, use first */
1634 if (cit==configs) 1574 if (cit == configs) {
1635 { 1575 cit = 0;
1636 cit=0; 1576 }
1637 } 1577 wdata->gles_config = cit;
1638 wdata->gles_config=cit; 1578
1639 1579 /* Create OpenGL ES context */
1640 /* Create OpenGL ES context */ 1580 wdata->gles_context =
1641 wdata->gles_context=eglCreateContext(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_NO_CONTEXT, NULL); 1581 eglCreateContext(phdata->egldisplay,
1642 if (wdata->gles_context==EGL_NO_CONTEXT) 1582 wdata->gles_configs[wdata->gles_config],
1643 { 1583 EGL_NO_CONTEXT, NULL);
1644 SDL_SetError("Photon: OpenGL ES context creation has been failed"); 1584 if (wdata->gles_context == EGL_NO_CONTEXT) {
1645 return NULL; 1585 SDL_SetError("Photon: OpenGL ES context creation has been failed");
1646 } 1586 return NULL;
1647 1587 }
1648 /* Check if surface is exist */ 1588
1649 if (wdata->gfsurface!=NULL) 1589 /* Check if surface is exist */
1650 { 1590 if (wdata->gfsurface != NULL) {
1651 gf_surface_free(wdata->gfsurface); 1591 gf_surface_free(wdata->gfsurface);
1652 wdata->gfsurface=NULL; 1592 wdata->gfsurface = NULL;
1653 } 1593 }
1654 1594
1655 /* Create GF surface */ 1595 /* Create GF surface */
1656 gfstatus=gf_surface_create(&wdata->gfsurface, phdata->gfdev, window->w, window->h, 1596 gfstatus =
1657 qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format), NULL, 1597 gf_surface_create(&wdata->gfsurface, phdata->gfdev, window->w,
1658 GF_SURFACE_CREATE_2D_ACCESSIBLE | GF_SURFACE_CREATE_3D_ACCESSIBLE | 1598 window->h,
1659 GF_SURFACE_CREATE_SHAREABLE); 1599 qnxgf_sdl_to_gf_pixelformat(didata->current_mode.
1660 if (gfstatus!=GF_ERR_OK) 1600 format), NULL,
1661 { 1601 GF_SURFACE_CREATE_2D_ACCESSIBLE |
1662 eglDestroyContext(phdata->egldisplay, wdata->gles_context); 1602 GF_SURFACE_CREATE_3D_ACCESSIBLE |
1663 wdata->gles_context=EGL_NO_CONTEXT; 1603 GF_SURFACE_CREATE_SHAREABLE);
1664 SDL_SetError("Photon: Can't create GF 3D surface (%08X)", gfstatus); 1604 if (gfstatus != GF_ERR_OK) {
1665 return NULL; 1605 eglDestroyContext(phdata->egldisplay, wdata->gles_context);
1666 } 1606 wdata->gles_context = EGL_NO_CONTEXT;
1667 1607 SDL_SetError("Photon: Can't create GF 3D surface (%08X)", gfstatus);
1668 /* Create pixmap 3D target surface */ 1608 return NULL;
1669 wdata->gles_surface=eglCreatePixmapSurface(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], wdata->gfsurface, NULL); 1609 }
1670 if (wdata->gles_surface==EGL_NO_SURFACE) 1610
1671 { 1611 /* Create pixmap 3D target surface */
1672 gf_surface_free(wdata->gfsurface); 1612 wdata->gles_surface =
1673 eglDestroyContext(phdata->egldisplay, wdata->gles_context); 1613 eglCreatePixmapSurface(phdata->egldisplay,
1674 wdata->gles_context=EGL_NO_CONTEXT; 1614 wdata->gles_configs[wdata->gles_config],
1675 SDL_SetError("Photon: Can't create EGL pixmap surface"); 1615 wdata->gfsurface, NULL);
1676 return NULL; 1616 if (wdata->gles_surface == EGL_NO_SURFACE) {
1677 } 1617 gf_surface_free(wdata->gfsurface);
1678 1618 eglDestroyContext(phdata->egldisplay, wdata->gles_context);
1679 /* Make just created context current */ 1619 wdata->gles_context = EGL_NO_CONTEXT;
1680 status=eglMakeCurrent(phdata->egldisplay, wdata->gles_surface, wdata->gles_surface, wdata->gles_context); 1620 SDL_SetError("Photon: Can't create EGL pixmap surface");
1681 if (status!=EGL_TRUE) 1621 return NULL;
1682 { 1622 }
1683 /* Destroy OpenGL ES surface */ 1623
1684 eglDestroySurface(phdata->egldisplay, wdata->gles_surface); 1624 /* Make just created context current */
1685 gf_surface_free(wdata->gfsurface); 1625 status =
1686 eglDestroyContext(phdata->egldisplay, wdata->gles_context); 1626 eglMakeCurrent(phdata->egldisplay, wdata->gles_surface,
1687 wdata->gles_context=EGL_NO_CONTEXT; 1627 wdata->gles_surface, wdata->gles_context);
1688 SDL_SetError("Photon: Can't set OpenGL ES context on creation"); 1628 if (status != EGL_TRUE) {
1689 return NULL; 1629 /* Destroy OpenGL ES surface */
1690 } 1630 eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
1691 1631 gf_surface_free(wdata->gfsurface);
1692 /* Setup into SDL internals state of OpenGL ES: */ 1632 eglDestroyContext(phdata->egldisplay, wdata->gles_context);
1693 /* it is accelerated or not */ 1633 wdata->gles_context = EGL_NO_CONTEXT;
1694 if ((didata->caps & SDL_PHOTON_ACCELERATED_3D)==SDL_PHOTON_ACCELERATED_3D) 1634 SDL_SetError("Photon: Can't set OpenGL ES context on creation");
1695 { 1635 return NULL;
1696 _this->gl_config.accelerated=1; 1636 }
1697 } 1637
1698 else 1638 /* Setup into SDL internals state of OpenGL ES: */
1699 { 1639 /* it is accelerated or not */
1700 _this->gl_config.accelerated=0; 1640 if ((didata->caps & SDL_PHOTON_ACCELERATED_3D) ==
1701 } 1641 SDL_PHOTON_ACCELERATED_3D) {
1702 1642 _this->gl_config.accelerated = 1;
1703 /* Always clear stereo enable, since OpenGL ES do not supports stereo */ 1643 } else {
1704 _this->gl_config.stereo=0; 1644 _this->gl_config.accelerated = 0;
1705 1645 }
1706 /* Get back samples and samplebuffers configurations. Rest framebuffer */ 1646
1707 /* parameters could be obtained through the OpenGL ES API */ 1647 /* Always clear stereo enable, since OpenGL ES do not supports stereo */
1708 status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_SAMPLES, &attr_value); 1648 _this->gl_config.stereo = 0;
1709 if (status==EGL_TRUE) 1649
1710 { 1650 /* Get back samples and samplebuffers configurations. Rest framebuffer */
1711 _this->gl_config.multisamplesamples=attr_value; 1651 /* parameters could be obtained through the OpenGL ES API */
1712 } 1652 status =
1713 status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_SAMPLE_BUFFERS, &attr_value); 1653 eglGetConfigAttrib(phdata->egldisplay,
1714 if (status==EGL_TRUE) 1654 wdata->gles_configs[wdata->gles_config],
1715 { 1655 EGL_SAMPLES, &attr_value);
1716 _this->gl_config.multisamplebuffers=attr_value; 1656 if (status == EGL_TRUE) {
1717 } 1657 _this->gl_config.multisamplesamples = attr_value;
1718 1658 }
1719 /* Get back stencil and depth buffer sizes */ 1659 status =
1720 status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_DEPTH_SIZE, &attr_value); 1660 eglGetConfigAttrib(phdata->egldisplay,
1721 if (status==EGL_TRUE) 1661 wdata->gles_configs[wdata->gles_config],
1722 { 1662 EGL_SAMPLE_BUFFERS, &attr_value);
1723 _this->gl_config.depth_size=attr_value; 1663 if (status == EGL_TRUE) {
1724 } 1664 _this->gl_config.multisamplebuffers = attr_value;
1725 status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_STENCIL_SIZE, &attr_value); 1665 }
1726 if (status==EGL_TRUE) 1666
1727 { 1667 /* Get back stencil and depth buffer sizes */
1728 _this->gl_config.stencil_size=attr_value; 1668 status =
1729 } 1669 eglGetConfigAttrib(phdata->egldisplay,
1730 1670 wdata->gles_configs[wdata->gles_config],
1731 /* Under Photon OpenGL ES output can't be double buffered */ 1671 EGL_DEPTH_SIZE, &attr_value);
1732 _this->gl_config.double_buffer=0; 1672 if (status == EGL_TRUE) {
1733 1673 _this->gl_config.depth_size = attr_value;
1734 /* Check if current device is not the same as target */ 1674 }
1735 if (phdata->current_device_id!=didata->device_id) 1675 status =
1736 { 1676 eglGetConfigAttrib(phdata->egldisplay,
1737 /* Set target device as default for Pd and Pg functions */ 1677 wdata->gles_configs[wdata->gles_config],
1738 status=PdSetTargetDevice(NULL, phdata->rid[didata->device_id]); 1678 EGL_STENCIL_SIZE, &attr_value);
1739 if (status!=0) 1679 if (status == EGL_TRUE) {
1740 { 1680 _this->gl_config.stencil_size = attr_value;
1681 }
1682
1683 /* Under Photon OpenGL ES output can't be double buffered */
1684 _this->gl_config.double_buffer = 0;
1685
1686 /* Check if current device is not the same as target */
1687 if (phdata->current_device_id != didata->device_id) {
1688 /* Set target device as default for Pd and Pg functions */
1689 status = PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
1690 if (status != 0) {
1741 /* Destroy OpenGL ES surface */ 1691 /* Destroy OpenGL ES surface */
1742 eglDestroySurface(phdata->egldisplay, wdata->gles_surface); 1692 eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
1743 gf_surface_free(wdata->gfsurface); 1693 gf_surface_free(wdata->gfsurface);
1744 eglDestroyContext(phdata->egldisplay, wdata->gles_context); 1694 eglDestroyContext(phdata->egldisplay, wdata->gles_context);
1745 wdata->gles_context=EGL_NO_CONTEXT; 1695 wdata->gles_context = EGL_NO_CONTEXT;
1746 SDL_SetError("Photon: Can't set default target device\n"); 1696 SDL_SetError("Photon: Can't set default target device\n");
1747 return NULL; 1697 return NULL;
1748 } 1698 }
1749 phdata->current_device_id=didata->device_id; 1699 phdata->current_device_id = didata->device_id;
1750 } 1700 }
1751 1701
1752 wdata->phsurface=PdCreateOffscreenContextGF(wdata->gfsurface); 1702 wdata->phsurface = PdCreateOffscreenContextGF(wdata->gfsurface);
1753 if (wdata->phsurface==NULL) 1703 if (wdata->phsurface == NULL) {
1754 { 1704 /* Destroy OpenGL ES surface */
1755 /* Destroy OpenGL ES surface */ 1705 eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
1756 eglDestroySurface(phdata->egldisplay, wdata->gles_surface); 1706 gf_surface_free(wdata->gfsurface);
1757 gf_surface_free(wdata->gfsurface); 1707 eglDestroyContext(phdata->egldisplay, wdata->gles_context);
1758 eglDestroyContext(phdata->egldisplay, wdata->gles_context); 1708 wdata->gles_context = EGL_NO_CONTEXT;
1759 wdata->gles_context=EGL_NO_CONTEXT; 1709 SDL_SetError("Photon: Can't bind GF surface to Photon\n");
1760 SDL_SetError("Photon: Can't bind GF surface to Photon\n"); 1710 return NULL;
1761 return NULL; 1711 }
1762 } 1712
1763 1713 /* GL ES context was successfully created */
1764 /* GL ES context was successfully created */ 1714 return wdata->gles_context;
1765 return wdata->gles_context; 1715 #else
1766 #else 1716 SDL_SetError("Photon: OpenGL ES support is not compiled in");
1767 SDL_SetError("Photon: OpenGL ES support is not compiled in"); 1717 return NULL;
1768 return NULL; 1718 #endif /* SDL_VIDEO_OPENGL_ES */
1769 #endif /* SDL_VIDEO_OPENGL_ES */ 1719 }
1770 } 1720
1771 1721 int
1772 int photon_gl_makecurrent(_THIS, SDL_Window* window, SDL_GLContext context) 1722 photon_gl_makecurrent(_THIS, SDL_Window * window, SDL_GLContext context)
1773 { 1723 {
1774 #if defined(SDL_VIDEO_OPENGL_ES) 1724 #if defined(SDL_VIDEO_OPENGL_ES)
1775 SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata; 1725 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
1776 SDL_WindowData* wdata; 1726 SDL_WindowData *wdata;
1777 EGLBoolean status; 1727 EGLBoolean status;
1778 1728
1779 if (phdata->gfinitialized!=SDL_TRUE) 1729 if (phdata->gfinitialized != SDL_TRUE) {
1780 { 1730 SDL_SetError
1781 SDL_SetError("Photon: GF initialization failed, no OpenGL ES support"); 1731 ("Photon: GF initialization failed, no OpenGL ES support");
1782 return -1; 1732 return -1;
1783 } 1733 }
1784 1734
1785 if ((window==NULL) && (context==NULL)) 1735 if ((window == NULL) && (context == NULL)) {
1786 { 1736 status =
1787 status=eglMakeCurrent(phdata->egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); 1737 eglMakeCurrent(phdata->egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE,
1788 if (status!=EGL_TRUE) 1738 EGL_NO_CONTEXT);
1789 { 1739 if (status != EGL_TRUE) {
1790 /* Failed to set current GL ES context */ 1740 /* Failed to set current GL ES context */
1791 SDL_SetError("Photon: Can't set OpenGL ES context"); 1741 SDL_SetError("Photon: Can't set OpenGL ES context");
1792 return -1; 1742 return -1;
1793 } 1743 }
1794 } 1744 } else {
1795 else 1745 wdata = (SDL_WindowData *) window->driverdata;
1796 { 1746 if (wdata->gles_surface == EGL_NO_SURFACE) {
1797 wdata=(SDL_WindowData*)window->driverdata; 1747 SDL_SetError
1798 if (wdata->gles_surface==EGL_NO_SURFACE) 1748 ("Photon: OpenGL ES surface is not initialized for this window");
1799 {
1800 SDL_SetError("Photon: OpenGL ES surface is not initialized for this window");
1801 return -1; 1749 return -1;
1802 } 1750 }
1803 if (wdata->gles_context==EGL_NO_CONTEXT) 1751 if (wdata->gles_context == EGL_NO_CONTEXT) {
1804 { 1752 SDL_SetError
1805 SDL_SetError("Photon: OpenGL ES context is not initialized for this window"); 1753 ("Photon: OpenGL ES context is not initialized for this window");
1806 return -1; 1754 return -1;
1807 } 1755 }
1808 if (wdata->gles_context!=context) 1756 if (wdata->gles_context != context) {
1809 { 1757 SDL_SetError
1810 SDL_SetError("Photon: OpenGL ES context is not belong to this window"); 1758 ("Photon: OpenGL ES context is not belong to this window");
1811 return -1; 1759 return -1;
1812 } 1760 }
1813 status=eglMakeCurrent(phdata->egldisplay, wdata->gles_surface, wdata->gles_surface, wdata->gles_context); 1761 status =
1814 if (status!=EGL_TRUE) 1762 eglMakeCurrent(phdata->egldisplay, wdata->gles_surface,
1815 { 1763 wdata->gles_surface, wdata->gles_context);
1764 if (status != EGL_TRUE) {
1816 /* Failed to set current GL ES context */ 1765 /* Failed to set current GL ES context */
1817 SDL_SetError("Photon: Can't set OpenGL ES context"); 1766 SDL_SetError("Photon: Can't set OpenGL ES context");
1818 return -1; 1767 return -1;
1819 } 1768 }
1820 } 1769 }
1821 1770
1822 return 0; 1771 return 0;
1823 #else 1772 #else
1824 SDL_SetError("Photon: OpenGL ES support is not compiled in"); 1773 SDL_SetError("Photon: OpenGL ES support is not compiled in");
1825 return -1; 1774 return -1;
1826 #endif /* SDL_VIDEO_OPENGL_ES */ 1775 #endif /* SDL_VIDEO_OPENGL_ES */
1827 } 1776 }
1828 1777
1829 int photon_gl_setswapinterval(_THIS, int interval) 1778 int
1830 { 1779 photon_gl_setswapinterval(_THIS, int interval)
1831 #if defined(SDL_VIDEO_OPENGL_ES) 1780 {
1832 SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata; 1781 #if defined(SDL_VIDEO_OPENGL_ES)
1833 EGLBoolean status; 1782 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
1834 1783 EGLBoolean status;
1835 if (phdata->gfinitialized!=SDL_TRUE) 1784
1836 { 1785 if (phdata->gfinitialized != SDL_TRUE) {
1837 SDL_SetError("Photon: GF initialization failed, no OpenGL ES support"); 1786 SDL_SetError
1838 return -1; 1787 ("Photon: GF initialization failed, no OpenGL ES support");
1839 } 1788 return -1;
1840 1789 }
1841 /* Check if OpenGL ES connection has been initialized */ 1790
1842 if (phdata->egldisplay!=EGL_NO_DISPLAY) 1791 /* Check if OpenGL ES connection has been initialized */
1843 { 1792 if (phdata->egldisplay != EGL_NO_DISPLAY) {
1844 /* Set swap OpenGL ES interval */ 1793 /* Set swap OpenGL ES interval */
1845 status=eglSwapInterval(phdata->egldisplay, interval); 1794 status = eglSwapInterval(phdata->egldisplay, interval);
1846 if (status==EGL_TRUE) 1795 if (status == EGL_TRUE) {
1847 {
1848 /* Return success to upper level */ 1796 /* Return success to upper level */
1849 phdata->swapinterval=interval; 1797 phdata->swapinterval = interval;
1850 return 0; 1798 return 0;
1851 } 1799 }
1852 } 1800 }
1853 1801
1854 /* Failed to set swap interval */ 1802 /* Failed to set swap interval */
1855 SDL_SetError("Photon: Cannot set swap interval"); 1803 SDL_SetError("Photon: Cannot set swap interval");
1856 return -1; 1804 return -1;
1857 #else 1805 #else
1858 SDL_SetError("Photon: OpenGL ES support is not compiled in"); 1806 SDL_SetError("Photon: OpenGL ES support is not compiled in");
1859 return -1; 1807 return -1;
1860 #endif /* SDL_VIDEO_OPENGL_ES */ 1808 #endif /* SDL_VIDEO_OPENGL_ES */
1861 } 1809 }
1862 1810
1863 int photon_gl_getswapinterval(_THIS) 1811 int
1864 { 1812 photon_gl_getswapinterval(_THIS)
1865 #if defined(SDL_VIDEO_OPENGL_ES) 1813 {
1866 SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata; 1814 #if defined(SDL_VIDEO_OPENGL_ES)
1867 1815 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
1868 if (phdata->gfinitialized!=SDL_TRUE) 1816
1869 { 1817 if (phdata->gfinitialized != SDL_TRUE) {
1870 SDL_SetError("Photon: GF initialization failed, no OpenGL ES support"); 1818 SDL_SetError
1871 return -1; 1819 ("Photon: GF initialization failed, no OpenGL ES support");
1872 } 1820 return -1;
1873 1821 }
1874 /* Return default swap interval value */ 1822
1875 return phdata->swapinterval; 1823 /* Return default swap interval value */
1876 #else 1824 return phdata->swapinterval;
1877 SDL_SetError("Photon: OpenGL ES support is not compiled in"); 1825 #else
1878 return -1; 1826 SDL_SetError("Photon: OpenGL ES support is not compiled in");
1879 #endif /* SDL_VIDEO_OPENGL_ES */ 1827 return -1;
1880 } 1828 #endif /* SDL_VIDEO_OPENGL_ES */
1881 1829 }
1882 void photon_gl_swapwindow(_THIS, SDL_Window* window) 1830
1883 { 1831 void
1884 #if defined(SDL_VIDEO_OPENGL_ES) 1832 photon_gl_swapwindow(_THIS, SDL_Window * window)
1885 SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata; 1833 {
1886 SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata; 1834 #if defined(SDL_VIDEO_OPENGL_ES)
1887 SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata; 1835 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
1888 PhRect_t dst_rect; 1836 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
1889 PhRect_t src_rect; 1837 SDL_DisplayData *didata =
1890 1838 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
1891 if (phdata->gfinitialized!=SDL_TRUE) 1839 PhRect_t dst_rect;
1892 { 1840 PhRect_t src_rect;
1893 SDL_SetError("Photon: GF initialization failed, no OpenGL ES support"); 1841
1894 return; 1842 if (phdata->gfinitialized != SDL_TRUE) {
1895 } 1843 SDL_SetError
1896 1844 ("Photon: GF initialization failed, no OpenGL ES support");
1897 /* Many applications do not uses glFinish(), so we call it for them */ 1845 return;
1898 glFinish(); 1846 }
1899 1847
1900 /* Wait until OpenGL ES rendering is completed */ 1848 /* Many applications do not uses glFinish(), so we call it for them */
1901 eglWaitGL(); 1849 glFinish();
1902 1850
1903 /* Wait for VSYNC manually, if it was enabled */ 1851 /* Wait until OpenGL ES rendering is completed */
1904 if (phdata->swapinterval!=0) 1852 eglWaitGL();
1905 { 1853
1906 /* Wait for VSYNC, we use GF function, since Photon requires */ 1854 /* Wait for VSYNC manually, if it was enabled */
1907 /* to enter to the Direct mode to call PgWaitVSync() */ 1855 if (phdata->swapinterval != 0) {
1908 gf_display_wait_vsync(didata->display); 1856 /* Wait for VSYNC, we use GF function, since Photon requires */
1909 } 1857 /* to enter to the Direct mode to call PgWaitVSync() */
1910 1858 gf_display_wait_vsync(didata->display);
1911 /* Set blit area */ 1859 }
1912 dst_rect=*PtGetCanvas(wdata->window); 1860
1913 src_rect.ul.x=0; 1861 /* Set blit area */
1914 src_rect.ul.y=0; 1862 dst_rect = *PtGetCanvas(wdata->window);
1915 src_rect.lr.x=window->w-1; 1863 src_rect.ul.x = 0;
1916 src_rect.lr.y=window->h-1; 1864 src_rect.ul.y = 0;
1917 1865 src_rect.lr.x = window->w - 1;
1918 /* Blit OpenGL ES pixmap surface directly to window region */ 1866 src_rect.lr.y = window->h - 1;
1919 PgFFlush(Ph_START_DRAW); 1867
1920 PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window)); 1868 /* Blit OpenGL ES pixmap surface directly to window region */
1921 PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent())); 1869 PgFFlush(Ph_START_DRAW);
1922 PgContextBlit(wdata->phsurface, &src_rect, NULL, &dst_rect); 1870 PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window));
1923 PgFFlush(Ph_DONE_DRAW); 1871 PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent()));
1924 PgWaitHWIdle(); 1872 PgContextBlit(wdata->phsurface, &src_rect, NULL, &dst_rect);
1925 1873 PgFFlush(Ph_DONE_DRAW);
1926 eglSwapBuffers(phdata->egldisplay, wdata->gles_surface); 1874 PgWaitHWIdle();
1927 #else 1875
1928 SDL_SetError("Photon: OpenGL ES support is not compiled in"); 1876 eglSwapBuffers(phdata->egldisplay, wdata->gles_surface);
1929 return; 1877 #else
1930 #endif /* SDL_VIDEO_OPENGL_ES */ 1878 SDL_SetError("Photon: OpenGL ES support is not compiled in");
1931 } 1879 return;
1932 1880 #endif /* SDL_VIDEO_OPENGL_ES */
1933 void photon_gl_deletecontext(_THIS, SDL_GLContext context) 1881 }
1934 { 1882
1935 #if defined(SDL_VIDEO_OPENGL_ES) 1883 void
1936 SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata; 1884 photon_gl_deletecontext(_THIS, SDL_GLContext context)
1937 EGLBoolean status; 1885 {
1938 1886 #if defined(SDL_VIDEO_OPENGL_ES)
1939 if (phdata->gfinitialized!=SDL_TRUE) 1887 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
1940 { 1888 EGLBoolean status;
1941 SDL_SetError("Photon: GF initialization failed, no OpenGL ES support"); 1889
1942 return; 1890 if (phdata->gfinitialized != SDL_TRUE) {
1943 } 1891 SDL_SetError
1944 1892 ("Photon: GF initialization failed, no OpenGL ES support");
1945 /* Check if OpenGL ES connection has been initialized */ 1893 return;
1946 if (phdata->egldisplay!=EGL_NO_DISPLAY) 1894 }
1947 { 1895
1948 if (context!=EGL_NO_CONTEXT) 1896 /* Check if OpenGL ES connection has been initialized */
1949 { 1897 if (phdata->egldisplay != EGL_NO_DISPLAY) {
1950 status=eglDestroyContext(phdata->egldisplay, context); 1898 if (context != EGL_NO_CONTEXT) {
1951 if (status!=EGL_TRUE) 1899 status = eglDestroyContext(phdata->egldisplay, context);
1952 { 1900 if (status != EGL_TRUE) {
1953 /* Error during OpenGL ES context destroying */ 1901 /* Error during OpenGL ES context destroying */
1954 SDL_SetError("Photon: OpenGL ES context destroy error"); 1902 SDL_SetError("Photon: OpenGL ES context destroy error");
1955 return; 1903 return;
1956 } 1904 }
1957 } 1905 }
1958 } 1906 }
1959 1907
1960 return; 1908 return;
1961 #else 1909 #else
1962 SDL_SetError("Photon: OpenGL ES support is not compiled in"); 1910 SDL_SetError("Photon: OpenGL ES support is not compiled in");
1963 return; 1911 return;
1964 #endif /* SDL_VIDEO_OPENGL_ES */ 1912 #endif /* SDL_VIDEO_OPENGL_ES */
1965 } 1913 }
1966 1914
1967 /*****************************************************************************/ 1915 /*****************************************************************************/
1968 /* SDL Event handling function */ 1916 /* SDL Event handling function */
1969 /*****************************************************************************/ 1917 /*****************************************************************************/
1970 void photon_pumpevents(_THIS) 1918 void
1971 { 1919 photon_pumpevents(_THIS)
1972 uint8_t eventbuffer[SDL_VIDEO_PHOTON_EVENT_SIZE]; 1920 {
1973 PhEvent_t* event=(PhEvent_t*)eventbuffer; 1921 uint8_t eventbuffer[SDL_VIDEO_PHOTON_EVENT_SIZE];
1974 int32_t status; 1922 PhEvent_t *event = (PhEvent_t *) eventbuffer;
1975 uint32_t finish=0; 1923 int32_t status;
1976 uint32_t it; 1924 uint32_t finish = 0;
1977 SDL_Window* window; 1925 uint32_t it;
1978 SDL_WindowData* wdata; 1926 SDL_Window *window;
1979 1927 SDL_WindowData *wdata;
1980 do { 1928
1981 status=PhEventPeek(event, SDL_VIDEO_PHOTON_EVENT_SIZE); 1929 do {
1982 switch (status) 1930 status = PhEventPeek(event, SDL_VIDEO_PHOTON_EVENT_SIZE);
1983 { 1931 switch (status) {
1984 case Ph_RESIZE_MSG: 1932 case Ph_RESIZE_MSG:
1985 { 1933 {
1986 SDL_SetError("Photon: Event size too much for buffer"); 1934 SDL_SetError("Photon: Event size too much for buffer");
1987 return; 1935 return;
1988 } 1936 }
1989 break; 1937 break;
1990 case Ph_EVENT_MSG: 1938 case Ph_EVENT_MSG:
1991 { 1939 {
1992 /* Find a window, to which this handle destinated */ 1940 /* Find a window, to which this handle destinated */
1993 status=0; 1941 status = 0;
1994 for (it=0; it<SDL_CurrentDisplay.num_windows; it++) 1942 for (it = 0; it < SDL_CurrentDisplay.num_windows; it++) {
1995 { 1943 wdata =
1996 wdata=(SDL_WindowData*)SDL_CurrentDisplay.windows[it].driverdata; 1944 (SDL_WindowData *) SDL_CurrentDisplay.windows[it].
1945 driverdata;
1997 1946
1998 /* Find the proper window */ 1947 /* Find the proper window */
1999 if (wdata->window!=NULL) 1948 if (wdata->window != NULL) {
1949 if (PtWidgetRid(wdata->window) ==
1950 event->collector.rid) {
1951 window =
1952 (SDL_Window *) & SDL_CurrentDisplay.
1953 windows[it];
1954 status = 1;
1955 break;
1956 }
1957 } else {
1958 continue;
1959 }
1960 }
1961 if (status == 0) {
1962 window = NULL;
1963 wdata = NULL;
1964 }
1965
1966 /* Event is ready */
1967 switch (event->type) {
1968 case Ph_EV_BOUNDARY:
2000 { 1969 {
2001 if (PtWidgetRid(wdata->window)==event->collector.rid) 1970 switch (event->subtype) {
2002 { 1971 case Ph_EV_PTR_ENTER:
2003 window=(SDL_Window*)&SDL_CurrentDisplay.windows[it]; 1972 {
2004 status=1; 1973 /* Mouse cursor over handled window */
2005 break; 1974 if (window != NULL) {
2006 } 1975 SDL_SendWindowEvent(window->id,
1976 SDL_WINDOWEVENT_ENTER,
1977 0, 0);
1978 SDL_SetMouseFocus(0, window->id);
1979 }
1980 }
1981 break;
1982 case Ph_EV_PTR_LEAVE:
1983 {
1984 /* Mouse cursor out of handled window */
1985 if (window != NULL) {
1986 SDL_SendWindowEvent(window->id,
1987 SDL_WINDOWEVENT_LEAVE,
1988 0, 0);
1989 }
1990 }
1991 break;
1992 }
2007 } 1993 }
2008 else 1994 break;
1995 case Ph_EV_PTR_MOTION_BUTTON:
1996 case Ph_EV_PTR_MOTION_NOBUTTON:
2009 { 1997 {
2010 continue; 1998 PhPointerEvent_t *pevent = NULL;
1999 PhRect_t *prects = NULL;
2000
2001 /* Get event data */
2002 pevent = PhGetData(event);
2003 /* Get associated event rectangles */
2004 prects = PhGetRects(event);
2005 if ((pevent != NULL) && (prects != NULL)) {
2006 SDL_SendMouseMotion(0, 0, prects->ul.x,
2007 prects->ul.y, 0);
2008 }
2011 } 2009 }
2012 } 2010 break;
2013 if (status==0) 2011 case Ph_EV_BUT_PRESS:
2014 { 2012 {
2015 window=NULL; 2013 /* Button press event */
2016 wdata=NULL; 2014 PhPointerEvent_t *pevent = NULL;
2017 } 2015 uint32_t sdlbutton = 0x00000000;
2018 2016
2019 /* Event is ready */ 2017 /* Get event data */
2020 switch(event->type) 2018 pevent = PhGetData(event);
2021 { 2019 if (pevent != NULL) {
2022 case Ph_EV_BOUNDARY: 2020 for (it = 0; it < sizeof(pevent->buttons) * 8;
2023 { 2021 it++) {
2024 switch(event->subtype) 2022 if ((pevent->buttons & (0x0001 << it)) ==
2023 (0x0001 << it)) {
2024 switch (it) {
2025 case 0:
2026 {
2027 sdlbutton = SDL_BUTTON_RIGHT;
2028 }
2029 break;
2030 case 1:
2031 {
2032 sdlbutton = SDL_BUTTON_MIDDLE;
2033 }
2034 break;
2035 case 2:
2036 {
2037 sdlbutton = SDL_BUTTON_LEFT;
2038 }
2039 break;
2040 default:
2041 {
2042 sdlbutton = it + 1;
2043 }
2044 break;
2045 }
2046 SDL_SendMouseButton(0, SDL_PRESSED,
2047 sdlbutton);
2048 }
2049 }
2050 }
2051 }
2052 break;
2053 case Ph_EV_BUT_RELEASE:
2054 {
2055 /* Button press event */
2056 PhPointerEvent_t *pevent = NULL;
2057 uint32_t sdlbutton = 0x00000000;
2058
2059 /* Get event data */
2060 pevent = PhGetData(event);
2061 if (pevent != NULL) {
2062 for (it = 0; it < sizeof(pevent->buttons) * 8;
2063 it++) {
2064 if ((pevent->buttons & (0x0001 << it)) ==
2065 (0x0001 << it)) {
2066 switch (it) {
2067 case 0:
2068 {
2069 sdlbutton = SDL_BUTTON_RIGHT;
2070 }
2071 break;
2072 case 1:
2073 {
2074 sdlbutton = SDL_BUTTON_MIDDLE;
2075 }
2076 break;
2077 case 2:
2078 {
2079 sdlbutton = SDL_BUTTON_LEFT;
2080 }
2081 break;
2082 default:
2083 {
2084 sdlbutton = it + 1;
2085 }
2086 break;
2087 }
2088 }
2089 }
2090 }
2091
2092 switch (event->subtype) {
2093 case Ph_EV_RELEASE_REAL:
2025 { 2094 {
2026 case Ph_EV_PTR_ENTER: 2095 /* Real release button event */
2027 { 2096 SDL_SendMouseButton(0, SDL_RELEASED,
2028 /* Mouse cursor over handled window */ 2097 sdlbutton);
2029 if (window!=NULL) 2098 }
2030 { 2099 break;
2031 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_ENTER, 0, 0); 2100 case Ph_EV_RELEASE_PHANTOM:
2032 SDL_SetMouseFocus(0, window->id); 2101 {
2033 } 2102 /* We will get phantom button release */
2103 /* event in case if it was unpressed */
2104 /* outside of window */
2105 if (window != NULL) {
2106 if ((window->
2107 flags & SDL_WINDOW_MOUSE_FOCUS) !=
2108 SDL_WINDOW_MOUSE_FOCUS) {
2109 /* Send phantom button release */
2110 SDL_SendMouseButton(0, SDL_RELEASED,
2111 sdlbutton);
2034 } 2112 }
2035 break; 2113 }
2036 case Ph_EV_PTR_LEAVE: 2114 }
2037 { 2115 break;
2038 /* Mouse cursor out of handled window */ 2116 }
2039 if (window!=NULL) 2117 }
2040 { 2118 break;
2041 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_LEAVE, 0, 0); 2119 case Ph_EV_EXPOSE:
2042 } 2120 {
2121 switch (event->subtype) {
2122 case Ph_NORMAL_EXPOSE:
2123 {
2124 PhRect_t *rects = NULL;
2125
2126 /* Get array of rectangles to be updated */
2127 rects = PhGetRects(event);
2128 if (rects == NULL) {
2129 break;
2130 }
2131
2132 /* Check if expose come to one of the our windows */
2133 if ((wdata != NULL) && (window != NULL)) {
2134 /* Check if window uses OpenGL ES */
2135 if (wdata->uses_gles == SDL_TRUE) {
2136 PhRect_t dst_rect;
2137 PhRect_t src_rect;
2138
2139 /* Cycle through each rectangle */
2140 for (it = 0; it < event->num_rects;
2141 it++) {
2142 /* Blit OpenGL ES pixmap surface directly to window region */
2143 PgFFlush(Ph_START_DRAW);
2144 PgSetRegionCx(PhDCGetCurrent(),
2145 PtWidgetRid(wdata->
2146 window));
2147 PgClearTranslationCx(PgGetGCCx
2148 (PhDCGetCurrent
2149 ()));
2150 PgContextBlit(wdata->phsurface,
2151 &rects[it], NULL,
2152 &rects[it]);
2153 PgFFlush(Ph_DONE_DRAW);
2154 PgWaitHWIdle();
2155 }
2156 } else {
2157 /* Normal window */
2158 /* TODO: update the damaged rectangles */
2043 } 2159 }
2044 break; 2160 }
2161
2162 /* Flush all blittings */
2163 PgFlush();
2045 } 2164 }
2046 } 2165 break;
2047 break; 2166 case Ph_CAPTURE_EXPOSE:
2048 case Ph_EV_PTR_MOTION_BUTTON:
2049 case Ph_EV_PTR_MOTION_NOBUTTON:
2050 {
2051 PhPointerEvent_t* pevent=NULL;
2052 PhRect_t* prects=NULL;
2053
2054 /* Get event data */
2055 pevent=PhGetData(event);
2056 /* Get associated event rectangles */
2057 prects=PhGetRects(event);
2058 if ((pevent!=NULL) && (prects!=NULL))
2059 { 2167 {
2060 SDL_SendMouseMotion(0, 0, prects->ul.x, prects->ul.y, 0); 2168 /* Check if expose come to one of the our windows */
2169 if ((wdata != NULL) && (window != NULL)) {
2170 /* Check if window uses OpenGL ES */
2171 if (wdata->uses_gles == SDL_TRUE) {
2172 PhRect_t dst_rect;
2173 PhRect_t src_rect;
2174
2175 /* Set blit area */
2176 dst_rect =
2177 *PtGetCanvas(wdata->window);
2178 src_rect.ul.x = 0;
2179 src_rect.ul.y = 0;
2180 src_rect.lr.x = window->w - 1;
2181 src_rect.lr.y = window->h - 1;
2182
2183 /* We need to redraw entire window */
2184 PgFFlush(Ph_START_DRAW);
2185 PgSetRegionCx(PhDCGetCurrent(),
2186 PtWidgetRid(wdata->
2187 window));
2188 PgClearTranslationCx(PgGetGCCx
2189 (PhDCGetCurrent
2190 ()));
2191 PgContextBlit(wdata->phsurface,
2192 &src_rect, NULL,
2193 &dst_rect);
2194 PgFFlush(Ph_DONE_DRAW);
2195 PgWaitHWIdle();
2196 } else {
2197 /* Normal window */
2198 /* TODO: update the damaged rectangles */
2199
2200 /* We need to redraw entire window */
2201 }
2202 }
2061 } 2203 }
2062 } 2204 break;
2063 break; 2205 case Ph_GRAPHIC_EXPOSE:
2064 case Ph_EV_BUT_PRESS:
2065 {
2066 /* Button press event */
2067 PhPointerEvent_t* pevent=NULL;
2068 uint32_t sdlbutton=0x00000000;
2069
2070 /* Get event data */
2071 pevent=PhGetData(event);
2072 if (pevent!=NULL)
2073 { 2206 {
2074 for (it=0; it<sizeof(pevent->buttons)*8; it++) 2207 /* TODO: What this event means ? */
2075 {
2076 if ((pevent->buttons&(0x0001<<it))==(0x0001<<it))
2077 {
2078 switch (it)
2079 {
2080 case 0:
2081 {
2082 sdlbutton=SDL_BUTTON_RIGHT;
2083 }
2084 break;
2085 case 1:
2086 {
2087 sdlbutton=SDL_BUTTON_MIDDLE;
2088 }
2089 break;
2090 case 2:
2091 {
2092 sdlbutton=SDL_BUTTON_LEFT;
2093 }
2094 break;
2095 default:
2096 {
2097 sdlbutton=it+1;
2098 }
2099 break;
2100 }
2101 SDL_SendMouseButton(0, SDL_PRESSED, sdlbutton);
2102 }
2103 }
2104 } 2208 }
2105 } 2209 break;
2106 break; 2210 }
2107 case Ph_EV_BUT_RELEASE: 2211 }
2108 { 2212 break;
2109 /* Button press event */ 2213 case Ph_EV_INFO:
2110 PhPointerEvent_t* pevent=NULL; 2214 {
2111 uint32_t sdlbutton=0x00000000; 2215 }
2112 2216 break;
2113 /* Get event data */ 2217 case Ph_EV_KEY:
2114 pevent=PhGetData(event); 2218 {
2115 if (pevent!=NULL) 2219 PhKeyEvent_t *keyevent = NULL;
2220 SDL_scancode scancode = SDL_SCANCODE_UNKNOWN;
2221 SDL_bool pressed = SDL_FALSE;
2222
2223 keyevent = PhGetData(event);
2224 if (keyevent == NULL) {
2225 break;
2226 }
2227
2228 /* Check if key is repeated */
2229 if ((keyevent->key_flags & Pk_KF_Key_Repeat) ==
2230 Pk_KF_Key_Repeat) {
2231 /* Ignore such events */
2232 break;
2233 }
2234
2235 /* Check if key has its own scancode */
2236 if ((keyevent->key_flags & Pk_KF_Scan_Valid) ==
2237 Pk_KF_Scan_Valid) {
2238 if ((keyevent->key_flags & Pk_KF_Key_Down) ==
2239 Pk_KF_Key_Down) {
2240 pressed = SDL_TRUE;
2241 } else {
2242 pressed = SDL_FALSE;
2243 }
2244 scancode =
2245 photon_to_sdl_keymap(keyevent->key_scan);
2246
2247 /* Add details for the pressed key */
2248 if ((keyevent->key_flags & Pk_KF_Cap_Valid) ==
2249 Pk_KF_Cap_Valid) {
2250 switch (keyevent->key_cap) {
2251 case Pk_Hyper_R: /* Right windows flag key */
2252 scancode = SDL_SCANCODE_RGUI;
2253 break;
2254 case Pk_Control_R: /* Right Ctrl key */
2255 scancode = SDL_SCANCODE_RCTRL;
2256 break;
2257 case Pk_Alt_R: /* Right Alt key */
2258 scancode = SDL_SCANCODE_RALT;
2259 break;
2260 case Pk_Up: /* Up key but with invalid scan */
2261 if (scancode != SDL_SCANCODE_UP) {
2262 /* This is a mouse wheel event */
2263 SDL_SendMouseWheel(0, 0, 1);
2264 return;
2265 }
2266 break;
2267 case Pk_KP_8: /* Up arrow or 8 on keypad */
2268 scancode = SDL_SCANCODE_KP_8;
2269 break;
2270 case Pk_Down: /* Down key but with invalid scan */
2271 if (scancode != SDL_SCANCODE_DOWN) {
2272 /* This is a mouse wheel event */
2273 SDL_SendMouseWheel(0, 0, -1);
2274 return;
2275 }
2276 break;
2277 case Pk_KP_2: /* Down arrow or 2 on keypad */
2278 scancode = SDL_SCANCODE_KP_2;
2279 break;
2280 case Pk_Left: /* Left arrow key */
2281 scancode = SDL_SCANCODE_LEFT;
2282 break;
2283 case Pk_KP_4: /* Left arrow or 4 on keypad */
2284 scancode = SDL_SCANCODE_KP_4;
2285 break;
2286 case Pk_Right: /* Right arrow key */
2287 scancode = SDL_SCANCODE_RIGHT;
2288 break;
2289 case Pk_KP_6: /* Right arrow or 6 on keypad */
2290 scancode = SDL_SCANCODE_KP_6;
2291 break;
2292 case Pk_Insert: /* Insert key */
2293 scancode = SDL_SCANCODE_INSERT;
2294 break;
2295 case Pk_KP_0: /* Insert or 0 on keypad */
2296 scancode = SDL_SCANCODE_KP_0;
2297 break;
2298 case Pk_Home: /* Home key */
2299 scancode = SDL_SCANCODE_HOME;
2300 break;
2301 case Pk_KP_7: /* Home or 7 on keypad */
2302 scancode = SDL_SCANCODE_KP_7;
2303 break;
2304 case Pk_Pg_Up: /* PageUp key */
2305 scancode = SDL_SCANCODE_PAGEUP;
2306 break;
2307 case Pk_KP_9: /* PgUp or 9 on keypad */
2308 scancode = SDL_SCANCODE_KP_9;
2309 break;
2310 case Pk_Delete: /* Delete key */
2311 scancode = SDL_SCANCODE_DELETE;
2312 break;
2313 case Pk_KP_Decimal: /* Del or . on keypad */
2314 scancode = SDL_SCANCODE_KP_PERIOD;
2315 break;
2316 case Pk_End: /* End key */
2317 scancode = SDL_SCANCODE_END;
2318 break;
2319 case Pk_KP_1: /* End or 1 on keypad */
2320 scancode = SDL_SCANCODE_KP_1;
2321 break;
2322 case Pk_Pg_Down: /* PageDown key */
2323 scancode = SDL_SCANCODE_PAGEDOWN;
2324 break;
2325 case Pk_KP_3: /* PgDn or 3 on keypad */
2326 scancode = SDL_SCANCODE_KP_3;
2327 break;
2328 case Pk_KP_5: /* 5 on keypad */
2329 scancode = SDL_SCANCODE_KP_5;
2330 break;
2331 case Pk_KP_Enter:
2332 scancode = SDL_SCANCODE_KP_ENTER;
2333 break;
2334 case Pk_KP_Add:
2335 scancode = SDL_SCANCODE_KP_PLUS;
2336 break;
2337 case Pk_KP_Subtract:
2338 scancode = SDL_SCANCODE_KP_MINUS;
2339 break;
2340 case Pk_KP_Multiply:
2341 scancode = SDL_SCANCODE_KP_MULTIPLY;
2342 break;
2343 case Pk_KP_Divide:
2344 scancode = SDL_SCANCODE_KP_DIVIDE;
2345 break;
2346 case Pk_Pause:
2347 scancode = SDL_SCANCODE_PAUSE;
2348 break;
2349 }
2350 }
2351
2352 /* Finally check if scancode has been decoded */
2353 if (scancode == SDL_SCANCODE_UNKNOWN) {
2354 /* Something was pressed, which is not supported */
2355 break;
2356 }
2357
2358 /* Report pressed/released key to SDL */
2359 if (pressed == SDL_TRUE) {
2360 SDL_SendKeyboardKey(0, SDL_PRESSED, scancode);
2361 } else {
2362 SDL_SendKeyboardKey(0, SDL_RELEASED,
2363 scancode);
2364 }
2365
2366 /* Photon doesn't send a release event for PrnScr key */
2367 if ((scancode == SDL_SCANCODE_PRINTSCREEN)
2368 && (pressed)) {
2369 SDL_SendKeyboardKey(0, SDL_RELEASED,
2370 scancode);
2371 }
2372 }
2373 }
2374 break;
2375 case Ph_EV_SERVICE:
2376 {
2377 }
2378 break;
2379 case Ph_EV_SYSTEM:
2380 {
2381 }
2382 break;
2383 case Ph_EV_WM:
2384 {
2385 PhWindowEvent_t *wmevent = NULL;
2386
2387 /* Get associated event data */
2388 wmevent = PhGetData(event);
2389 if (wmevent == NULL) {
2390 break;
2391 }
2392
2393 switch (wmevent->event_f) {
2394 case Ph_WM_CLOSE:
2116 { 2395 {
2117 for (it=0; it<sizeof(pevent->buttons)*8; it++) 2396 if (window != NULL) {
2118 { 2397 SDL_SendWindowEvent(window->id,
2119 if ((pevent->buttons&(0x0001<<it))==(0x0001<<it)) 2398 SDL_WINDOWEVENT_CLOSE,
2120 { 2399 0, 0);
2121 switch (it) 2400 }
2122 {
2123 case 0:
2124 {
2125 sdlbutton=SDL_BUTTON_RIGHT;
2126 }
2127 break;
2128 case 1:
2129 {
2130 sdlbutton=SDL_BUTTON_MIDDLE;
2131 }
2132 break;
2133 case 2:
2134 {
2135 sdlbutton=SDL_BUTTON_LEFT;
2136 }
2137 break;
2138 default:
2139 {
2140 sdlbutton=it+1;
2141 }
2142 break;
2143 }
2144 }
2145 }
2146 } 2401 }
2147 2402 break;
2148 switch(event->subtype) 2403 case Ph_WM_FOCUS:
2149 { 2404 {
2150 case Ph_EV_RELEASE_REAL: 2405 if (wmevent->event_state ==
2151 { 2406 Ph_WM_EVSTATE_FOCUS) {
2152 /* Real release button event */ 2407 if (window != NULL) {
2153 SDL_SendMouseButton(0, SDL_RELEASED, sdlbutton); 2408 PhRegion_t wregion;
2409
2410 SDL_SendWindowEvent(window->id,
2411 SDL_WINDOWEVENT_FOCUS_GAINED,
2412 0, 0);
2413 SDL_SetKeyboardFocus(0, window->id);
2414
2415 /* Set window region sensible to mouse motion events */
2416 PhRegionQuery(PtWidgetRid
2417 (wdata->window),
2418 &wregion, NULL, NULL,
2419 0);
2420 wregion.events_sense |=
2421 Ph_EV_PTR_MOTION_BUTTON |
2422 Ph_EV_PTR_MOTION_NOBUTTON;
2423 PhRegionChange(Ph_REGION_EV_SENSE, 0,
2424 &wregion, NULL, NULL);
2425
2426 /* If window got a focus, the it is visible */
2427 SDL_SendWindowEvent(window->id,
2428 SDL_WINDOWEVENT_SHOWN,
2429 0, 0);
2154 } 2430 }
2155 break; 2431 }
2156 case Ph_EV_RELEASE_PHANTOM: 2432 if (wmevent->event_state ==
2157 { 2433 Ph_WM_EVSTATE_FOCUSLOST) {
2158 /* We will get phantom button release */ 2434 if (window != NULL) {
2159 /* event in case if it was unpressed */ 2435 PhRegion_t wregion;
2160 /* outside of window */ 2436
2161 if (window!=NULL) 2437 SDL_SendWindowEvent(window->id,
2162 { 2438 SDL_WINDOWEVENT_FOCUS_LOST,
2163 if ((window->flags & SDL_WINDOW_MOUSE_FOCUS)!=SDL_WINDOW_MOUSE_FOCUS) 2439 0, 0);
2164 { 2440
2165 /* Send phantom button release */ 2441 /* Set window region ignore mouse motion events */
2166 SDL_SendMouseButton(0, SDL_RELEASED, sdlbutton); 2442 PhRegionQuery(PtWidgetRid
2167 } 2443 (wdata->window),
2168 } 2444 &wregion, NULL, NULL,
2445 0);
2446 wregion.events_sense &=
2447 ~(Ph_EV_PTR_MOTION_BUTTON |
2448 Ph_EV_PTR_MOTION_NOBUTTON);
2449 PhRegionChange(Ph_REGION_EV_SENSE, 0,
2450 &wregion, NULL, NULL);
2169 } 2451 }
2170 break; 2452 }
2171 } 2453 }
2172 } 2454 break;
2173 break; 2455 case Ph_WM_MOVE:
2174 case Ph_EV_EXPOSE:
2175 {
2176 switch(event->subtype)
2177 { 2456 {
2178 case Ph_NORMAL_EXPOSE: 2457 if (window != NULL) {
2179 { 2458 SDL_SendWindowEvent(window->id,
2180 PhRect_t* rects=NULL; 2459 SDL_WINDOWEVENT_MOVED,
2181 2460 wmevent->pos.x,
2182 /* Get array of rectangles to be updated */ 2461 wmevent->pos.y);
2183 rects=PhGetRects(event); 2462 }
2184 if (rects==NULL)
2185 {
2186 break;
2187 }
2188
2189 /* Check if expose come to one of the our windows */
2190 if ((wdata!=NULL) && (window!=NULL))
2191 {
2192 /* Check if window uses OpenGL ES */
2193 if (wdata->uses_gles==SDL_TRUE)
2194 {
2195 PhRect_t dst_rect;
2196 PhRect_t src_rect;
2197
2198 /* Cycle through each rectangle */
2199 for (it=0; it<event->num_rects; it++)
2200 {
2201 /* Blit OpenGL ES pixmap surface directly to window region */
2202 PgFFlush(Ph_START_DRAW);
2203 PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window));
2204 PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent()));
2205 PgContextBlit(wdata->phsurface, &rects[it], NULL, &rects[it]);
2206 PgFFlush(Ph_DONE_DRAW);
2207 PgWaitHWIdle();
2208 }
2209 }
2210 else
2211 {
2212 /* Normal window */
2213 /* TODO: update the damaged rectangles */
2214 }
2215 }
2216
2217 /* Flush all blittings */
2218 PgFlush();
2219 }
2220 break;
2221 case Ph_CAPTURE_EXPOSE:
2222 {
2223 /* Check if expose come to one of the our windows */
2224 if ((wdata!=NULL) && (window!=NULL))
2225 {
2226 /* Check if window uses OpenGL ES */
2227 if (wdata->uses_gles==SDL_TRUE)
2228 {
2229 PhRect_t dst_rect;
2230 PhRect_t src_rect;
2231
2232 /* Set blit area */
2233 dst_rect=*PtGetCanvas(wdata->window);
2234 src_rect.ul.x=0;
2235 src_rect.ul.y=0;
2236 src_rect.lr.x=window->w-1;
2237 src_rect.lr.y=window->h-1;
2238
2239 /* We need to redraw entire window */
2240 PgFFlush(Ph_START_DRAW);
2241 PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window));
2242 PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent()));
2243 PgContextBlit(wdata->phsurface, &src_rect, NULL, &dst_rect);
2244 PgFFlush(Ph_DONE_DRAW);
2245 PgWaitHWIdle();
2246 }
2247 else
2248 {
2249 /* Normal window */
2250 /* TODO: update the damaged rectangles */
2251
2252 /* We need to redraw entire window */
2253 }
2254 }
2255 }
2256 break;
2257 case Ph_GRAPHIC_EXPOSE:
2258 {
2259 /* TODO: What this event means ? */
2260 }
2261 break;
2262 } 2463 }
2263 } 2464 break;
2264 break; 2465 case Ph_WM_RESIZE:
2265 case Ph_EV_INFO:
2266 {
2267 }
2268 break;
2269 case Ph_EV_KEY:
2270 {
2271 PhKeyEvent_t* keyevent=NULL;
2272 SDL_scancode scancode=SDL_SCANCODE_UNKNOWN;
2273 SDL_bool pressed=SDL_FALSE;
2274
2275 keyevent=PhGetData(event);
2276 if (keyevent==NULL)
2277 { 2466 {
2278 break; 2467 if (window != NULL) {
2468 /* Set new window position after resize */
2469 SDL_SendWindowEvent(window->id,
2470 SDL_WINDOWEVENT_MOVED,
2471 wmevent->pos.x,
2472 wmevent->pos.y);
2473 /* Set new window size after resize */
2474 SDL_SendWindowEvent(window->id,
2475 SDL_WINDOWEVENT_RESIZED,
2476 wmevent->size.w,
2477 wmevent->size.h);
2478 }
2279 } 2479 }
2280 2480 break;
2281 /* Check if key is repeated */ 2481 case Ph_WM_HIDE:
2282 if ((keyevent->key_flags & Pk_KF_Key_Repeat)==Pk_KF_Key_Repeat)
2283 { 2482 {
2284 /* Ignore such events */ 2483 if (window != NULL) {
2285 break; 2484 /* Send new window state: minimized */
2485 SDL_SendWindowEvent(window->id,
2486 SDL_WINDOWEVENT_MINIMIZED,
2487 0, 0);
2488 /* In case window is minimized, then it is hidden */
2489 SDL_SendWindowEvent(window->id,
2490 SDL_WINDOWEVENT_HIDDEN,
2491 0, 0);
2492 }
2286 } 2493 }
2287 2494 break;
2288 /* Check if key has its own scancode */ 2495 case Ph_WM_MAX:
2289 if ((keyevent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid)
2290 { 2496 {
2291 if ((keyevent->key_flags & Pk_KF_Key_Down)==Pk_KF_Key_Down) 2497 if (window != NULL) {
2292 { 2498 SDL_SendWindowEvent(window->id,
2293 pressed=SDL_TRUE; 2499 SDL_WINDOWEVENT_MAXIMIZED,
2294 } 2500 0, 0);
2295 else 2501 }
2296 {
2297 pressed=SDL_FALSE;
2298 }
2299 scancode=photon_to_sdl_keymap(keyevent->key_scan);
2300
2301 /* Add details for the pressed key */
2302 if ((keyevent->key_flags & Pk_KF_Cap_Valid)==Pk_KF_Cap_Valid)
2303 {
2304 switch(keyevent->key_cap)
2305 {
2306 case Pk_Hyper_R: /* Right windows flag key */
2307 scancode=SDL_SCANCODE_RGUI;
2308 break;
2309 case Pk_Control_R: /* Right Ctrl key */
2310 scancode=SDL_SCANCODE_RCTRL;
2311 break;
2312 case Pk_Alt_R: /* Right Alt key */
2313 scancode=SDL_SCANCODE_RALT;
2314 break;
2315 case Pk_Up: /* Up key but with invalid scan */
2316 if (scancode!=SDL_SCANCODE_UP)
2317 {
2318 /* This is a mouse wheel event */
2319 SDL_SendMouseWheel(0, 0, 1);
2320 return;
2321 }
2322 break;
2323 case Pk_KP_8: /* Up arrow or 8 on keypad */
2324 scancode=SDL_SCANCODE_KP_8;
2325 break;
2326 case Pk_Down: /* Down key but with invalid scan */
2327 if (scancode!=SDL_SCANCODE_DOWN)
2328 {
2329 /* This is a mouse wheel event */
2330 SDL_SendMouseWheel(0, 0, -1);
2331 return;
2332 }
2333 break;
2334 case Pk_KP_2: /* Down arrow or 2 on keypad */
2335 scancode=SDL_SCANCODE_KP_2;
2336 break;
2337 case Pk_Left: /* Left arrow key */
2338 scancode=SDL_SCANCODE_LEFT;
2339 break;
2340 case Pk_KP_4: /* Left arrow or 4 on keypad */
2341 scancode=SDL_SCANCODE_KP_4;
2342 break;
2343 case Pk_Right: /* Right arrow key */
2344 scancode=SDL_SCANCODE_RIGHT;
2345 break;
2346 case Pk_KP_6: /* Right arrow or 6 on keypad */
2347 scancode=SDL_SCANCODE_KP_6;
2348 break;
2349 case Pk_Insert: /* Insert key */
2350 scancode=SDL_SCANCODE_INSERT;
2351 break;
2352 case Pk_KP_0: /* Insert or 0 on keypad */
2353 scancode=SDL_SCANCODE_KP_0;
2354 break;
2355 case Pk_Home: /* Home key */
2356 scancode=SDL_SCANCODE_HOME;
2357 break;
2358 case Pk_KP_7: /* Home or 7 on keypad */
2359 scancode=SDL_SCANCODE_KP_7;
2360 break;
2361 case Pk_Pg_Up: /* PageUp key */
2362 scancode=SDL_SCANCODE_PAGEUP;
2363 break;
2364 case Pk_KP_9: /* PgUp or 9 on keypad */
2365 scancode=SDL_SCANCODE_KP_9;
2366 break;
2367 case Pk_Delete: /* Delete key */
2368 scancode=SDL_SCANCODE_DELETE;
2369 break;
2370 case Pk_KP_Decimal: /* Del or . on keypad */
2371 scancode=SDL_SCANCODE_KP_PERIOD;
2372 break;
2373 case Pk_End: /* End key */
2374 scancode=SDL_SCANCODE_END;
2375 break;
2376 case Pk_KP_1: /* End or 1 on keypad */
2377 scancode=SDL_SCANCODE_KP_1;
2378 break;
2379 case Pk_Pg_Down: /* PageDown key */
2380 scancode=SDL_SCANCODE_PAGEDOWN;
2381 break;
2382 case Pk_KP_3: /* PgDn or 3 on keypad */
2383 scancode=SDL_SCANCODE_KP_3;
2384 break;
2385 case Pk_KP_5: /* 5 on keypad */
2386 scancode=SDL_SCANCODE_KP_5;
2387 break;
2388 case Pk_KP_Enter:
2389 scancode=SDL_SCANCODE_KP_ENTER;
2390 break;
2391 case Pk_KP_Add:
2392 scancode=SDL_SCANCODE_KP_PLUS;
2393 break;
2394 case Pk_KP_Subtract:
2395 scancode=SDL_SCANCODE_KP_MINUS;
2396 break;
2397 case Pk_KP_Multiply:
2398 scancode=SDL_SCANCODE_KP_MULTIPLY;
2399 break;
2400 case Pk_KP_Divide:
2401 scancode=SDL_SCANCODE_KP_DIVIDE;
2402 break;
2403 case Pk_Pause:
2404 scancode=SDL_SCANCODE_PAUSE;
2405 break;
2406 }
2407 }
2408
2409 /* Finally check if scancode has been decoded */
2410 if (scancode==SDL_SCANCODE_UNKNOWN)
2411 {
2412 /* Something was pressed, which is not supported */
2413 break;
2414 }
2415
2416 /* Report pressed/released key to SDL */
2417 if (pressed==SDL_TRUE)
2418 {
2419 SDL_SendKeyboardKey(0, SDL_PRESSED, scancode);
2420 }
2421 else
2422 {
2423 SDL_SendKeyboardKey(0, SDL_RELEASED, scancode);
2424 }
2425
2426 /* Photon doesn't send a release event for PrnScr key */
2427 if ((scancode==SDL_SCANCODE_PRINTSCREEN) && (pressed))
2428 {
2429 SDL_SendKeyboardKey(0, SDL_RELEASED, scancode);
2430 }
2431 } 2502 }
2432 } 2503 break;
2433 break; 2504 case Ph_WM_RESTORE:
2434 case Ph_EV_SERVICE:
2435 {
2436 }
2437 break;
2438 case Ph_EV_SYSTEM:
2439 {
2440 }
2441 break;
2442 case Ph_EV_WM:
2443 {
2444 PhWindowEvent_t* wmevent=NULL;
2445
2446 /* Get associated event data */
2447 wmevent=PhGetData(event);
2448 if (wmevent==NULL)
2449 { 2505 {
2450 break; 2506 if (window != NULL) {
2507 SDL_SendWindowEvent(window->id,
2508 SDL_WINDOWEVENT_RESTORED,
2509 0, 0);
2510 }
2451 } 2511 }
2452 2512 break;
2453 switch(wmevent->event_f) 2513 }
2454 { 2514 }
2455 case Ph_WM_CLOSE: 2515 break;
2456 { 2516 }
2457 if (window!=NULL) 2517 PtEventHandler(event);
2458 { 2518 }
2459 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_CLOSE, 0, 0); 2519 break;
2460 } 2520 case 0:
2461 } 2521 {
2462 break; 2522 /* All events are read */
2463 case Ph_WM_FOCUS: 2523 finish = 1;
2464 { 2524 break;
2465 if (wmevent->event_state==Ph_WM_EVSTATE_FOCUS) 2525 }
2466 { 2526 case -1:
2467 if (window!=NULL) 2527 {
2468 { 2528 /* Error occured in event reading */
2469 PhRegion_t wregion; 2529 SDL_SetError("Photon: Can't read event");
2470 2530 return;
2471 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0); 2531 }
2472 SDL_SetKeyboardFocus(0, window->id); 2532 break;
2473 2533 }
2474 /* Set window region sensible to mouse motion events */ 2534 if (finish != 0) {
2475 PhRegionQuery(PtWidgetRid(wdata->window), &wregion, NULL, NULL, 0); 2535 break;
2476 wregion.events_sense|=Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON; 2536 }
2477 PhRegionChange(Ph_REGION_EV_SENSE, 0, &wregion, NULL, NULL); 2537 } while (1);
2478
2479 /* If window got a focus, the it is visible */
2480 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_SHOWN, 0, 0);
2481 }
2482 }
2483 if (wmevent->event_state==Ph_WM_EVSTATE_FOCUSLOST)
2484 {
2485 if (window!=NULL)
2486 {
2487 PhRegion_t wregion;
2488
2489 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
2490
2491 /* Set window region ignore mouse motion events */
2492 PhRegionQuery(PtWidgetRid(wdata->window), &wregion, NULL, NULL, 0);
2493 wregion.events_sense&=~(Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON);
2494 PhRegionChange(Ph_REGION_EV_SENSE, 0, &wregion, NULL, NULL);
2495 }
2496 }
2497 }
2498 break;
2499 case Ph_WM_MOVE:
2500 {
2501 if (window!=NULL)
2502 {
2503 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MOVED, wmevent->pos.x, wmevent->pos.y);
2504 }
2505 }
2506 break;
2507 case Ph_WM_RESIZE:
2508 {
2509 if (window!=NULL)
2510 {
2511 /* Set new window position after resize */
2512 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MOVED, wmevent->pos.x, wmevent->pos.y);
2513 /* Set new window size after resize */
2514 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESIZED, wmevent->size.w, wmevent->size.h);
2515 }
2516 }
2517 break;
2518 case Ph_WM_HIDE:
2519 {
2520 if (window!=NULL)
2521 {
2522 /* Send new window state: minimized */
2523 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
2524 /* In case window is minimized, then it is hidden */
2525 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_HIDDEN, 0, 0);
2526 }
2527 }
2528 break;
2529 case Ph_WM_MAX:
2530 {
2531 if (window!=NULL)
2532 {
2533 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
2534 }
2535 }
2536 break;
2537 case Ph_WM_RESTORE:
2538 {
2539 if (window!=NULL)
2540 {
2541 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESTORED, 0, 0);
2542 }
2543 }
2544 break;
2545 }
2546 }
2547 break;
2548 }
2549 PtEventHandler(event);
2550 }
2551 break;
2552 case 0:
2553 {
2554 /* All events are read */
2555 finish=1;
2556 break;
2557 }
2558 case -1:
2559 {
2560 /* Error occured in event reading */
2561 SDL_SetError("Photon: Can't read event");
2562 return;
2563 }
2564 break;
2565 }
2566 if (finish!=0)
2567 {
2568 break;
2569 }
2570 } while(1);
2571 } 2538 }
2572 2539
2573 /*****************************************************************************/ 2540 /*****************************************************************************/
2574 /* SDL screen saver related functions */ 2541 /* SDL screen saver related functions */
2575 /*****************************************************************************/ 2542 /*****************************************************************************/
2576 void photon_suspendscreensaver(_THIS) 2543 void
2577 { 2544 photon_suspendscreensaver(_THIS)
2578 /* There is no screensaver in pure console, it may exist when running */ 2545 {
2579 /* GF under Photon, but I do not know, how to disable screensaver */ 2546 /* There is no screensaver in pure console, it may exist when running */
2547 /* GF under Photon, but I do not know, how to disable screensaver */
2580 } 2548 }
2581 2549
2582 /* vi: set ts=4 sw=4 expandtab: */ 2550 /* vi: set ts=4 sw=4 expandtab: */