summaryrefslogtreecommitdiff
path: root/apps/plugins/sdl/src/video/photon
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2018-02-07 20:04:46 -0500
committerFranklin Wei <git@fwei.tk>2018-03-12 20:52:01 -0400
commit6039eb05ba6d82ef56f2868c96654c552d117bf9 (patch)
tree9db7016bcbf66cfdf7b9bc998d84c6eaff9c8378 /apps/plugins/sdl/src/video/photon
parentef373c03b96b0be08babca581d9f10bccfd4931f (diff)
downloadrockbox-6039eb05ba6d82ef56f2868c96654c552d117bf9.tar.gz
rockbox-6039eb05ba6d82ef56f2868c96654c552d117bf9.zip
sdl: remove non-rockbox drivers
We never use any of these other drivers, so having them around just takes up space. Change-Id: Iced812162df1fef3fd55522b7e700acb6c3bcd41
Diffstat (limited to 'apps/plugins/sdl/src/video/photon')
-rw-r--r--apps/plugins/sdl/src/video/photon/SDL_ph_events.c624
-rw-r--r--apps/plugins/sdl/src/video/photon/SDL_ph_events_c.h37
-rw-r--r--apps/plugins/sdl/src/video/photon/SDL_ph_gl.c406
-rw-r--r--apps/plugins/sdl/src/video/photon/SDL_ph_gl.h41
-rw-r--r--apps/plugins/sdl/src/video/photon/SDL_ph_image.c1059
-rw-r--r--apps/plugins/sdl/src/video/photon/SDL_ph_image_c.h59
-rw-r--r--apps/plugins/sdl/src/video/photon/SDL_ph_modes.c390
-rw-r--r--apps/plugins/sdl/src/video/photon/SDL_ph_modes_c.h43
-rw-r--r--apps/plugins/sdl/src/video/photon/SDL_ph_mouse.c220
-rw-r--r--apps/plugins/sdl/src/video/photon/SDL_ph_mouse_c.h39
-rw-r--r--apps/plugins/sdl/src/video/photon/SDL_ph_video.c648
-rw-r--r--apps/plugins/sdl/src/video/photon/SDL_ph_video.h157
-rw-r--r--apps/plugins/sdl/src/video/photon/SDL_ph_wm.c118
-rw-r--r--apps/plugins/sdl/src/video/photon/SDL_ph_wm_c.h37
-rw-r--r--apps/plugins/sdl/src/video/photon/SDL_phyuv.c504
-rw-r--r--apps/plugins/sdl/src/video/photon/SDL_phyuv_c.h62
16 files changed, 0 insertions, 4444 deletions
diff --git a/apps/plugins/sdl/src/video/photon/SDL_ph_events.c b/apps/plugins/sdl/src/video/photon/SDL_ph_events.c
deleted file mode 100644
index 9b7538c4b0..0000000000
--- a/apps/plugins/sdl/src/video/photon/SDL_ph_events.c
+++ /dev/null
@@ -1,624 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24/* Handle the event stream, converting photon events into SDL events */
25
26#include <stdio.h>
27#include <setjmp.h>
28#include <sys/time.h>
29
30#include <Ph.h>
31#include <photon/PkKeyDef.h>
32
33#include "SDL.h"
34#include "SDL_syswm.h"
35#include "../SDL_sysvideo.h"
36#include "../../events/SDL_sysevents.h"
37#include "../../events/SDL_events_c.h"
38#include "SDL_ph_video.h"
39#include "SDL_ph_modes_c.h"
40#include "SDL_ph_image_c.h"
41#include "SDL_ph_events_c.h"
42#include "SDL_phyuv_c.h"
43
44/* The translation tables from a photon keysym to a SDL keysym */
45static SDLKey ODD_keymap[256];
46static SDLKey MISC_keymap[0xFF + 1];
47SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym);
48
49/* Check to see if this is a repeated key.
50 (idea shamelessly lifted from GII -- thanks guys! :) */
51static int ph_WarpedMotion(_THIS, PhEvent_t *winEvent)
52{
53 PhRect_t *rect = PhGetRects( winEvent );
54
55 int centre_x, centre_y;
56 int dx, dy;
57 short abs_x, abs_y;
58 int posted;
59
60 centre_x = SDL_VideoSurface->w / 2;
61 centre_y = SDL_VideoSurface->h / 2;
62
63 dx = rect->ul.x - centre_x;
64 dy = rect->ul.y - centre_y;
65
66 posted = SDL_PrivateMouseMotion( 0, 1, dx, dy );
67
68 /* Move mouse cursor to middle of the window */
69 PtGetAbsPosition( window, &abs_x, &abs_y );
70 PhMoveCursorAbs(PhInputGroup(NULL), abs_x + centre_x, abs_y + centre_y);
71
72 return (posted);
73}
74
75/* Control which motion flags the window has set, a flags value of -1 sets
76 * MOTION_BUTTON and MOTION_NOBUTTON */
77
78static void set_motion_sensitivity(_THIS, unsigned int flags)
79{
80 int rid;
81 int fields = Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
82 PhRegion_t region;
83
84 if( window )
85 {
86 rid = PtWidgetRid(window);
87 if( rid != 0 && PhRegionQuery(rid, &region, NULL, NULL, 0) == 0 )
88 {
89 region.events_sense=(region.events_sense & ~fields)|(flags & fields);
90 PhRegionChange(Ph_REGION_EV_SENSE, 0, &region, NULL, NULL);
91 }
92 }
93}
94
95/* Convert the photon button state value to an SDL value */
96static Uint8 ph2sdl_mousebutton(unsigned short button_state)
97{
98 Uint8 mouse_button = 0;
99
100 if (button_state & Ph_BUTTON_SELECT)
101 mouse_button |= SDL_BUTTON_LEFT;
102 if (button_state & Ph_BUTTON_MENU)
103 mouse_button |= SDL_BUTTON_RIGHT;
104 if (button_state & Ph_BUTTON_ADJUST)
105 mouse_button |= SDL_BUTTON_MIDDLE;
106
107 return (mouse_button);
108}
109
110static int ph_DispatchEvent(_THIS)
111{
112 int posted;
113 PhRect_t* rect;
114 PhPointerEvent_t* pointerEvent;
115 PhKeyEvent_t* keyEvent;
116 PhWindowEvent_t* winEvent;
117 int i, buttons;
118 SDL_Rect sdlrects[PH_SDL_MAX_RECTS];
119
120 posted = 0;
121
122 switch (phevent->type)
123 {
124 case Ph_EV_BOUNDARY:
125 {
126 if (phevent->subtype == Ph_EV_PTR_ENTER)
127 {
128 posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
129 }
130 else if (phevent->subtype ==Ph_EV_PTR_LEAVE)
131 {
132 posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
133 }
134 }
135 break;
136
137 case Ph_EV_PTR_MOTION_BUTTON:
138 case Ph_EV_PTR_MOTION_NOBUTTON:
139 {
140 if (SDL_VideoSurface)
141 {
142 pointerEvent = PhGetData(phevent);
143 rect = PhGetRects(phevent);
144
145 if (mouse_relative)
146 {
147 posted = ph_WarpedMotion(this, phevent);
148 }
149 else
150 {
151 posted = SDL_PrivateMouseMotion(0, 0, rect->ul.x, rect->ul.y);
152 }
153 }
154 }
155 break;
156
157 case Ph_EV_BUT_PRESS:
158 {
159 pointerEvent = PhGetData(phevent);
160 buttons = ph2sdl_mousebutton(pointerEvent->buttons);
161 if (buttons != 0)
162 {
163 posted = SDL_PrivateMouseButton(SDL_PRESSED, buttons, 0, 0);
164 }
165 }
166 break;
167
168 case Ph_EV_BUT_RELEASE:
169 {
170 pointerEvent = PhGetData(phevent);
171 buttons = ph2sdl_mousebutton(pointerEvent->buttons);
172 if (phevent->subtype == Ph_EV_RELEASE_REAL && buttons != 0)
173 {
174 posted = SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0);
175 }
176 else if(phevent->subtype == Ph_EV_RELEASE_PHANTOM)
177 {
178 /* If the mouse is outside the window,
179 * only a phantom release event is sent, so
180 * check if the window doesn't have mouse focus.
181 * Not perfect, maybe checking the mouse button
182 * state for Ph_EV_BOUNDARY events would be
183 * better. */
184 if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) == 0)
185 {
186 posted = SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0);
187 }
188 }
189 }
190 break;
191
192 case Ph_EV_WM:
193 {
194 winEvent = PhGetData(phevent);
195
196 /* losing focus */
197 if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST))
198 {
199 set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON);
200 posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
201 }
202 /* gaining focus */
203 else if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUS))
204 {
205 set_motion_sensitivity(this, -1);
206 posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
207 }
208 /* request quit */
209 else if (winEvent->event_f==Ph_WM_CLOSE)
210 {
211 posted = SDL_PrivateQuit();
212 }
213 /* request hide/unhide */
214 else if (winEvent->event_f==Ph_WM_HIDE)
215 {
216 if (currently_hided)
217 {
218 /* got unhide window event */
219 /* TODO: restore application's palette if in palette mode */
220 currently_hided=0;
221 }
222 else
223 {
224 /* got hide window event */
225 /* TODO: restore original palette if in palette mode */
226 currently_hided=1;
227 }
228 }
229 /* request to resize */
230 else if (winEvent->event_f==Ph_WM_RESIZE)
231 {
232 currently_maximized=0;
233 #if (_NTO_VERSION < 630)
234 SDL_PrivateResize(winEvent->size.w+1, winEvent->size.h+1);
235 #else
236 /* QNX 6.3.0 have this bug fixed */
237 SDL_PrivateResize(winEvent->size.w, winEvent->size.h);
238 #endif /* _NTO_VERSION */
239 }
240 /* request to move */
241 else if (winEvent->event_f==Ph_WM_MOVE)
242 {
243 if (current_overlay!=NULL)
244 {
245 int lockedstate=current_overlay->hwdata->locked;
246 int chromastate=current_overlay->hwdata->ischromakey;
247 int error;
248 SDL_Rect src, dst;
249
250 current_overlay->hwdata->locked=1;
251 src.x = 0;
252 src.y = 0;
253 src.w = current_overlay->w;
254 src.y = current_overlay->h;
255 dst.x=current_overlay->hwdata->CurrentViewPort.pos.x;
256 dst.y=current_overlay->hwdata->CurrentViewPort.pos.y;
257 dst.w=current_overlay->hwdata->CurrentViewPort.size.w;
258 dst.h=current_overlay->hwdata->CurrentViewPort.size.h;
259 current_overlay->hwdata->ischromakey=0;
260 error=ph_DisplayYUVOverlay(this, current_overlay, &src, &dst);
261 if (!error)
262 {
263 current_overlay->hwdata->ischromakey=chromastate;
264 current_overlay->hwdata->locked=lockedstate;
265 }
266 }
267 }
268 /* maximize request */
269 else if (winEvent->event_f==Ph_WM_MAX)
270 {
271 /* window already moved and resized here */
272 currently_maximized=1;
273 }
274 /* restore request */
275 else if (winEvent->event_f==Ph_WM_RESTORE)
276 {
277 /* window already moved and resized here */
278 currently_maximized=0;
279 }
280 }
281 break;
282
283 /* window has been resized, moved or removed */
284 case Ph_EV_EXPOSE:
285 {
286 if (phevent->num_rects!=0)
287 {
288 int numrects;
289
290 if (SDL_VideoSurface)
291 {
292 rect = PhGetRects(phevent);
293 if (phevent->num_rects>PH_SDL_MAX_RECTS)
294 {
295 /* sorry, buffers underrun, we'll update only first PH_SDL_MAX_RECTS rects */
296 numrects=PH_SDL_MAX_RECTS;
297 }
298
299 for(i=0; i<phevent->num_rects; i++)
300 {
301 sdlrects[i].x = rect[i].ul.x;
302 sdlrects[i].y = rect[i].ul.y;
303 sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1;
304 sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1;
305 }
306
307 this->UpdateRects(this, phevent->num_rects, sdlrects);
308
309 if (current_overlay!=NULL)
310 {
311 int lockedstate=current_overlay->hwdata->locked;
312 int error;
313 SDL_Rect src, dst;
314
315 current_overlay->hwdata->locked=1;
316 src.x = 0;
317 src.y = 0;
318 src.w = current_overlay->w;
319 src.y = current_overlay->h;
320 dst.x=current_overlay->hwdata->CurrentViewPort.pos.x;
321 dst.y=current_overlay->hwdata->CurrentViewPort.pos.y;
322 dst.w=current_overlay->hwdata->CurrentViewPort.size.w;
323 dst.h=current_overlay->hwdata->CurrentViewPort.size.h;
324 current_overlay->hwdata->forcedredraw=1;
325 error=ph_DisplayYUVOverlay(this, current_overlay, &src, &dst);
326 if (!error)
327 {
328 current_overlay->hwdata->forcedredraw=0;
329 current_overlay->hwdata->locked=lockedstate;
330 }
331 }
332 }
333 }
334 }
335 break;
336
337 case Ph_EV_KEY:
338 {
339 SDL_keysym keysym;
340
341 posted = 0;
342
343 keyEvent = PhGetData(phevent);
344
345 if (Pk_KF_Key_Down & keyEvent->key_flags)
346 {
347 /* split the wheel events from real key events */
348 if ((keyEvent->key_cap==Pk_Up) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
349 {
350 posted = SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELUP, 0, 0);
351 break;
352 }
353 if ((keyEvent->key_cap==Pk_Down) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
354 {
355 posted = SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELDOWN, 0, 0);
356 break;
357 }
358 posted = SDL_PrivateKeyboard(SDL_PRESSED, ph_TranslateKey(keyEvent, &keysym));
359 }
360 else /* must be key release */
361 {
362 /* split the wheel events from real key events */
363 if ((keyEvent->key_cap==Pk_Up) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
364 {
365 posted = SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELUP, 0, 0);
366 break;
367 }
368 if ((keyEvent->key_cap==Pk_Down) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
369 {
370 posted = SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELDOWN, 0, 0);
371 break;
372 }
373 posted = SDL_PrivateKeyboard(SDL_RELEASED, ph_TranslateKey( keyEvent, &keysym));
374 }
375 }
376 break;
377
378 case Ph_EV_INFO:
379 {
380 if (phevent->subtype==Ph_OFFSCREEN_INVALID)
381 {
382 unsigned long* EvInfoData;
383
384 EvInfoData=(unsigned long*)PhGetData(phevent);
385
386 switch (*EvInfoData)
387 {
388 case Pg_VIDEO_MODE_SWITCHED:
389 {
390 }
391 break;
392 case Pg_ENTERED_DIRECT:
393 {
394 }
395 break;
396 case Pg_EXITED_DIRECT:
397 {
398 }
399 break;
400 case Pg_DRIVER_STARTED:
401 {
402 }
403 break;
404 }
405 }
406 }
407 break;
408 }
409
410 return(posted);
411}
412
413/* perform a blocking read if no events available */
414int ph_Pending(_THIS)
415{
416 /* Flush the display connection and look to see if events are queued */
417 PgFlush();
418
419 while (1)
420 {
421 switch(PhEventPeek(phevent, EVENT_SIZE))
422 {
423 case Ph_EVENT_MSG:
424 return 1;
425 case -1:
426 SDL_SetError("ph_Pending(): PhEventNext failed.\n");
427 return 0;
428 default:
429 return 0;
430 }
431 }
432
433 /* Oh well, nothing is ready .. */
434 return(0);
435}
436
437void ph_PumpEvents(_THIS)
438{
439 /* Flush the display connection and look to see if events are queued */
440 PgFlush();
441
442 while (ph_Pending(this))
443 {
444 PtEventHandler(phevent);
445 ph_DispatchEvent(this);
446 }
447}
448
449void ph_InitKeymap(void)
450{
451 int i;
452
453 /* Odd keys used in international keyboards */
454 for (i=0; i<SDL_arraysize(ODD_keymap); ++i)
455 {
456 ODD_keymap[i] = SDLK_UNKNOWN;
457 }
458
459 /* Map the miscellaneous keys */
460 for (i=0; i<SDL_arraysize(MISC_keymap); ++i)
461 {
462 MISC_keymap[i] = SDLK_UNKNOWN;
463 }
464
465 MISC_keymap[Pk_BackSpace&0xFF] = SDLK_BACKSPACE;
466 MISC_keymap[Pk_Tab&0xFF] = SDLK_TAB;
467 MISC_keymap[Pk_Clear&0xFF] = SDLK_CLEAR;
468 MISC_keymap[Pk_Return&0xFF] = SDLK_RETURN;
469 MISC_keymap[Pk_Pause&0xFF] = SDLK_PAUSE;
470 MISC_keymap[Pk_Escape&0xFF] = SDLK_ESCAPE;
471 MISC_keymap[Pk_Delete&0xFF] = SDLK_DELETE;
472
473 MISC_keymap[Pk_KP_0&0xFF] = SDLK_KP0;
474 MISC_keymap[Pk_KP_1&0xFF] = SDLK_KP1;
475 MISC_keymap[Pk_KP_2&0xFF] = SDLK_KP2;
476 MISC_keymap[Pk_KP_3&0xFF] = SDLK_KP3;
477 MISC_keymap[Pk_KP_4&0xFF] = SDLK_KP4;
478 MISC_keymap[Pk_KP_5&0xFF] = SDLK_KP5;
479 MISC_keymap[Pk_KP_6&0xFF] = SDLK_KP6;
480 MISC_keymap[Pk_KP_7&0xFF] = SDLK_KP7;
481 MISC_keymap[Pk_KP_8&0xFF] = SDLK_KP8;
482 MISC_keymap[Pk_KP_9&0xFF] = SDLK_KP9;
483
484 MISC_keymap[Pk_KP_Decimal&0xFF] = SDLK_KP_PERIOD;
485 MISC_keymap[Pk_KP_Divide&0xFF] = SDLK_KP_DIVIDE;
486 MISC_keymap[Pk_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY;
487 MISC_keymap[Pk_KP_Subtract&0xFF] = SDLK_KP_MINUS;
488 MISC_keymap[Pk_KP_Add&0xFF] = SDLK_KP_PLUS;
489 MISC_keymap[Pk_KP_Enter&0xFF] = SDLK_KP_ENTER;
490 MISC_keymap[Pk_KP_Equal&0xFF] = SDLK_KP_EQUALS;
491
492 MISC_keymap[Pk_Up&0xFF] = SDLK_UP;
493 MISC_keymap[Pk_Down&0xFF] = SDLK_DOWN;
494 MISC_keymap[Pk_Right&0xFF] = SDLK_RIGHT;
495 MISC_keymap[Pk_Left&0xFF] = SDLK_LEFT;
496 MISC_keymap[Pk_Insert&0xFF] = SDLK_INSERT;
497 MISC_keymap[Pk_Home&0xFF] = SDLK_HOME;
498 MISC_keymap[Pk_End&0xFF] = SDLK_END;
499 MISC_keymap[Pk_Pg_Up&0xFF] = SDLK_PAGEUP;
500 MISC_keymap[Pk_Pg_Down&0xFF] = SDLK_PAGEDOWN;
501
502 MISC_keymap[Pk_F1&0xFF] = SDLK_F1;
503 MISC_keymap[Pk_F2&0xFF] = SDLK_F2;
504 MISC_keymap[Pk_F3&0xFF] = SDLK_F3;
505 MISC_keymap[Pk_F4&0xFF] = SDLK_F4;
506 MISC_keymap[Pk_F5&0xFF] = SDLK_F5;
507 MISC_keymap[Pk_F6&0xFF] = SDLK_F6;
508 MISC_keymap[Pk_F7&0xFF] = SDLK_F7;
509 MISC_keymap[Pk_F8&0xFF] = SDLK_F8;
510 MISC_keymap[Pk_F9&0xFF] = SDLK_F9;
511 MISC_keymap[Pk_F10&0xFF] = SDLK_F10;
512 MISC_keymap[Pk_F11&0xFF] = SDLK_F11;
513 MISC_keymap[Pk_F12&0xFF] = SDLK_F12;
514 MISC_keymap[Pk_F13&0xFF] = SDLK_F13;
515 MISC_keymap[Pk_F14&0xFF] = SDLK_F14;
516 MISC_keymap[Pk_F15&0xFF] = SDLK_F15;
517
518 MISC_keymap[Pk_Num_Lock&0xFF] = SDLK_NUMLOCK;
519 MISC_keymap[Pk_Caps_Lock&0xFF] = SDLK_CAPSLOCK;
520 MISC_keymap[Pk_Scroll_Lock&0xFF] = SDLK_SCROLLOCK;
521 MISC_keymap[Pk_Shift_R&0xFF] = SDLK_RSHIFT;
522 MISC_keymap[Pk_Shift_L&0xFF] = SDLK_LSHIFT;
523 MISC_keymap[Pk_Control_R&0xFF] = SDLK_RCTRL;
524 MISC_keymap[Pk_Control_L&0xFF] = SDLK_LCTRL;
525 MISC_keymap[Pk_Alt_R&0xFF] = SDLK_RALT;
526 MISC_keymap[Pk_Alt_L&0xFF] = SDLK_LALT;
527 MISC_keymap[Pk_Meta_R&0xFF] = SDLK_RMETA;
528 MISC_keymap[Pk_Meta_L&0xFF] = SDLK_LMETA;
529 MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER;
530 MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER;
531 MISC_keymap[Pk_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key */
532
533 MISC_keymap[Pk_Help&0xFF] = SDLK_HELP;
534 MISC_keymap[Pk_Print&0xFF] = SDLK_PRINT;
535 MISC_keymap[Pk_Break&0xFF] = SDLK_BREAK;
536 MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU; /* Windows "Menu" key */
537
538 MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_RSUPER; /* Right "Windows" */
539
540 /* Left "Windows" key, but it can't be catched by application */
541 MISC_keymap[Pk_Hyper_L&0xFF] = SDLK_LSUPER;
542}
543
544static unsigned long cap;
545
546SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym)
547{
548 /* 'sym' is set to the value of the key with modifiers applied to it.
549 This member is valid only if Pk_KF_Sym_Valid is set in the key_flags.
550 We will assume it is valid. */
551
552 /* FIXME: This needs to check whether the cap & scancode is valid */
553
554 cap = key->key_cap;
555
556 switch (cap>>8)
557 {
558 case 0x00: /* Latin 1 */
559 case 0x01: /* Latin 2 */
560 case 0x02: /* Latin 3 */
561 case 0x03: /* Latin 4 */
562 case 0x04: /* Katakana */
563 case 0x05: /* Arabic */
564 case 0x06: /* Cyrillic */
565 case 0x07: /* Greek */
566 case 0x08: /* Technical */
567 case 0x0A: /* Publishing */
568 case 0x0C: /* Hebrew */
569 case 0x0D: /* Thai */
570 keysym->sym = (SDLKey)(cap&0xFF);
571 /* Map capital letter syms to lowercase */
572 if ((keysym->sym >= 'A')&&(keysym->sym <= 'Z'))
573 keysym->sym += ('a'-'A');
574 break;
575 case 0xF0:
576 keysym->sym = MISC_keymap[cap&0xFF];
577 break;
578 default:
579 keysym->sym = SDLK_UNKNOWN;
580 break;
581 }
582
583 keysym->scancode = key->key_scan;
584 keysym->unicode = 0;
585
586 if (SDL_TranslateUNICODE)
587 {
588 char utf8[MB_CUR_MAX];
589 int utf8len;
590 wchar_t unicode;
591
592 switch (keysym->scancode)
593 {
594 /* Esc key */
595 case 0x01: keysym->unicode = 27;
596 break;
597 /* BackSpace key */
598 case 0x0E: keysym->unicode = 127;
599 break;
600 /* Enter key */
601 case 0x1C: keysym->unicode = 10;
602 break;
603 default:
604 utf8len = PhKeyToMb(utf8, key);
605 if (utf8len > 0)
606 {
607 utf8len = mbtowc(&unicode, utf8, utf8len);
608 if (utf8len > 0)
609 {
610 keysym->unicode = unicode;
611 }
612 }
613 break;
614 }
615
616 }
617
618 return (keysym);
619}
620
621void ph_InitOSKeymap(_THIS)
622{
623 ph_InitKeymap();
624}
diff --git a/apps/plugins/sdl/src/video/photon/SDL_ph_events_c.h b/apps/plugins/sdl/src/video/photon/SDL_ph_events_c.h
deleted file mode 100644
index 4aa939b3d9..0000000000
--- a/apps/plugins/sdl/src/video/photon/SDL_ph_events_c.h
+++ /dev/null
@@ -1,37 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#ifndef __SDL_PH_EVENTS_H__
25#define __SDL_PH_EVENTS_H__
26
27#include "SDL_ph_video.h"
28
29#define PH_SDL_MAX_RECTS 256
30#define PH_EVENT_SAFETY_POOL 512
31#define EVENT_SIZE (sizeof(PhEvent_t) + 1000 + PH_EVENT_SAFETY_POOL)
32
33/* Functions to be exported */
34extern void ph_InitOSKeymap(_THIS);
35extern void ph_PumpEvents(_THIS);
36
37#endif /* __SDL_PH_EVENTS_H__ */
diff --git a/apps/plugins/sdl/src/video/photon/SDL_ph_gl.c b/apps/plugins/sdl/src/video/photon/SDL_ph_gl.c
deleted file mode 100644
index 3121777639..0000000000
--- a/apps/plugins/sdl/src/video/photon/SDL_ph_gl.c
+++ /dev/null
@@ -1,406 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#include <dlfcn.h>
25#include "SDL.h"
26#include "SDL_ph_gl.h"
27
28#if SDL_VIDEO_OPENGL
29
30#if (_NTO_VERSION >= 630)
31 /* PhotonGL functions */
32 GLPH_DECLARE_FUNCS;
33#endif /* 6.3.0 */
34
35#if (_NTO_VERSION < 630)
36void ph_GL_SwapBuffers(_THIS)
37{
38 PgSetRegion(PtWidgetRid(window));
39 PdOpenGLContextSwapBuffers(oglctx);
40}
41#else
42void ph_GL_SwapBuffers(_THIS)
43{
44 qnxgl_swap_buffers(oglbuffers);
45}
46#endif /* 6.3.0 */
47
48int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
49{
50 switch (attrib)
51 {
52 case SDL_GL_DOUBLEBUFFER:
53 *value=this->gl_config.double_buffer;
54 break;
55 case SDL_GL_STENCIL_SIZE:
56 *value=this->gl_config.stencil_size;
57 break;
58 case SDL_GL_DEPTH_SIZE:
59 *value=this->gl_config.depth_size;
60 break;
61#if (_NTO_VERSION >= 630)
62 case SDL_GL_RED_SIZE:
63 *value=this->gl_config.red_size;
64 break;
65 case SDL_GL_GREEN_SIZE:
66 *value=this->gl_config.green_size;
67 break;
68 case SDL_GL_BLUE_SIZE:
69 *value=this->gl_config.blue_size;
70 break;
71 case SDL_GL_ALPHA_SIZE:
72 *value=this->gl_config.alpha_size;
73 break;
74 case SDL_GL_ACCUM_RED_SIZE:
75 *value=this->gl_config.accum_red_size;
76 break;
77 case SDL_GL_ACCUM_GREEN_SIZE:
78 *value=this->gl_config.accum_green_size;
79 break;
80 case SDL_GL_ACCUM_BLUE_SIZE:
81 *value=this->gl_config.accum_blue_size;
82 break;
83 case SDL_GL_ACCUM_ALPHA_SIZE:
84 *value=this->gl_config.accum_alpha_size;
85 break;
86 case SDL_GL_STEREO:
87 *value=this->gl_config.stereo;
88 break;
89#endif /* 6.3.0 */
90 default:
91 *value=0;
92 return(-1);
93 }
94 return 0;
95}
96
97#if (_NTO_VERSION < 630)
98int ph_GL_LoadLibrary(_THIS, const char* path)
99{
100 /* if code compiled with SDL_VIDEO_OPENGL, that mean that library already linked */
101 this->gl_config.driver_loaded = 1;
102
103 return 0;
104}
105#else
106int ph_GL_LoadLibrary(_THIS, const char* path)
107{
108 void* handle;
109 int dlopen_flags=RTLD_WORLD | RTLD_GROUP;
110
111 if (this->gl_config.dll_handle!=NULL)
112 {
113 return 0;
114 }
115
116 handle = dlopen(path, dlopen_flags);
117
118 if (handle==NULL)
119 {
120 SDL_SetError("ph_GL_LoadLibrary(): Could not load OpenGL library");
121 return -1;
122 }
123
124 this->gl_config.dll_handle = handle;
125 this->gl_config.driver_loaded = 1;
126
127 SDL_strlcpy(this->gl_config.driver_path, path, SDL_arraysize(this->gl_config.driver_path));
128
129 return 0;
130}
131#endif /* 6.3.0 */
132
133#if (_NTO_VERSION < 630)
134void* ph_GL_GetProcAddress(_THIS, const char* proc)
135{
136 return NULL;
137}
138#else
139void* ph_GL_GetProcAddress(_THIS, const char* proc)
140{
141 void* function;
142
143 if (this->gl_config.dll_handle==NULL)
144 {
145 ph_GL_LoadLibrary(this, DEFAULT_OPENGL);
146 if (this->gl_config.dll_handle==NULL)
147 {
148 return NULL;
149 }
150 }
151
152 function=qnxgl_get_func(proc, oglctx, 0);
153 if (function==NULL)
154 {
155 function=dlsym(this->gl_config.dll_handle, proc);
156 }
157
158 return function;
159}
160#endif /* 6.3.0 */
161
162#if (_NTO_VERSION < 630)
163int ph_GL_MakeCurrent(_THIS)
164{
165 PgSetRegion(PtWidgetRid(window));
166
167 if (oglctx!=NULL)
168 {
169 PhDCSetCurrent(oglctx);
170 }
171
172 return 0;
173}
174#else
175int ph_GL_MakeCurrent(_THIS)
176{
177 PgSetRegion(PtWidgetRid(window));
178
179 if (oglctx!=NULL)
180 {
181 if (qnxgl_set_current(oglctx) == -1)
182 {
183 return -1;
184 }
185 }
186
187 return 0;
188}
189#endif /* 6.3.0 */
190
191#if (_NTO_VERSION < 630)
192
193/* This code is actual for the Photon3D Runtime which was available prior to 6.3 only */
194
195int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags)
196{
197 PhDim_t dim;
198 uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS];
199 int exposepost=0;
200 int OGLargc;
201
202 dim.w=width;
203 dim.h=height;
204
205 if ((oglctx!=NULL) && (oglflags==flags) && (oglbpp==bpp))
206 {
207 PdOpenGLContextResize(oglctx, &dim);
208 PhDCSetCurrent(oglctx);
209 return 0;
210 }
211 else
212 {
213 if (oglctx!=NULL)
214 {
215 PhDCSetCurrent(NULL);
216 PhDCRelease(oglctx);
217 oglctx=NULL;
218 exposepost=1;
219 }
220 }
221
222 OGLargc=0;
223 if (this->gl_config.depth_size)
224 {
225 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DEPTH_BITS;
226 OGLAttrib[OGLargc++]=this->gl_config.depth_size;
227 }
228 if (this->gl_config.stencil_size)
229 {
230 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_STENCIL_BITS;
231 OGLAttrib[OGLargc++]=this->gl_config.stencil_size;
232 }
233 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FORCE_SW;
234 if (flags & SDL_FULLSCREEN)
235 {
236 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN;
237 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DIRECT;
238 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_BEST;
239 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_CENTER;
240 }
241 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_NONE;
242
243 if (this->gl_config.double_buffer)
244 {
245 oglctx=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib);
246 }
247 else
248 {
249 oglctx=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib);
250 }
251
252 if (oglctx==NULL)
253 {
254 SDL_SetError("ph_SetupOpenGLContext(): cannot create OpenGL context !\n");
255 return -1;
256 }
257
258 PhDCSetCurrent(oglctx);
259
260 PtFlush();
261
262 oglflags=flags;
263 oglbpp=bpp;
264
265 if (exposepost!=0)
266 {
267 /* OpenGL context has been recreated, so report about this fact */
268 SDL_PrivateExpose();
269 }
270
271 return 0;
272}
273
274#else /* _NTO_VERSION */
275
276/* This code is actual for the built-in PhGL support, which became available since 6.3 */
277
278int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags)
279{
280 qnxgl_buf_attrib_t qnxgl_attribs[PH_OGL_MAX_ATTRIBS];
281 qnxgl_buf_attrib_t* qnxgl_attribs_slide;
282 int num_interfaces = 0;
283 int num_buffers = 0;
284
285 /* Initialize the OpenGL subsystem */
286
287 num_interfaces = qnxgl_init(NULL, NULL, 0);
288
289 if (num_interfaces < 0)
290 {
291 SDL_SetError("ph_SetupOpenGLContext(): cannot initialize OpenGL subsystem !\n");
292 return -1;
293 }
294 if (num_interfaces == 0)
295 {
296 SDL_SetError("ph_SetupOpenGLContext(): there are no available OpenGL renderers was found !\n");
297 return -1;
298 }
299
300 /* Driver is linked */
301 this->gl_config.driver_loaded=1;
302
303 /* Initialize the OpenGL context attributes */
304 qnxgl_attribs_slide=qnxgl_attribs;
305
306 /* Depth size */
307 if (this->gl_config.depth_size)
308 {
309 fprintf(stderr, "setted depth size %d\n", this->gl_config.depth_size);
310 qnxgl_attribs_slide = qnxgl_attrib_set_depth(qnxgl_attribs_slide, this->gl_config.depth_size);
311 }
312
313 /* Stencil size */
314 if (this->gl_config.stencil_size)
315 {
316 qnxgl_attribs_slide = qnxgl_attrib_set_stencil(qnxgl_attribs_slide, this->gl_config.stencil_size);
317 }
318
319 /* The sum of the accum bits of each channel */
320 if ((this->gl_config.accum_red_size != 0) && (this->gl_config.accum_blue_size != 0) &&
321 (this->gl_config.accum_green_size != 0))
322 {
323 qnxgl_attribs_slide = qnxgl_attrib_set_accum(qnxgl_attribs_slide,
324 this->gl_config.accum_red_size + this->gl_config.accum_blue_size +
325 this->gl_config.accum_green_size + this->gl_config.accum_alpha_size);
326 }
327
328 /* Stereo mode */
329 if (this->gl_config.stereo)
330 {
331 qnxgl_attribs_slide = qnxgl_attrib_set_stereo(qnxgl_attribs_slide);
332 }
333
334 /* Fullscreen mode */
335 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
336 {
337 qnxgl_attribs_slide = qnxgl_attrib_set_hint_fullscreen(qnxgl_attribs_slide);
338 }
339
340 /* Double buffering mode */
341 if (this->gl_config.double_buffer)
342 {
343 num_buffers=2;
344 }
345 else
346 {
347 num_buffers=1;
348 }
349
350 /* Loading the function pointers so we can use the extensions */
351 GLPH_LOAD_FUNCS_GC(oglctx);
352
353 /* Set the buffers region to be that of our window's region */
354 qnxgl_attribs_slide = glph_attrib_set_region(qnxgl_attribs_slide, PtWidgetRid(window));
355
356 /* End of the attributes array */
357 qnxgl_attribs_slide = qnxgl_attrib_set_end(qnxgl_attribs_slide);
358
359 /* Create the buffers with the specified color model */
360 fprintf(stderr, "ARGB: %d, %d, %d, %d\n", this->gl_config.alpha_size, this->gl_config.red_size, this->gl_config.green_size, this->gl_config.blue_size);
361 oglbuffers = qnxgl_buffers_create(
362 QNXGL_FORMAT_BEST_RGB,
363/* __QNXGL_BUILD_FORMAT(0, __QNXGL_COLOR_MODEL_RGB, this->gl_config.alpha_size,
364 this->gl_config.red_size, this->gl_config.green_size, this->gl_config.blue_size), */
365 num_buffers, width, height, qnxgl_attribs, -1);
366
367
368 if (oglbuffers == NULL)
369 {
370 SDL_SetError("ph_SetupOpenGLContext(): failed to create OpenGL buffers !\n");
371 qnxgl_finish();
372 return -1;
373 }
374
375 /* Create a QNXGL context for the previously created buffer */
376 oglctx = qnxgl_context_create(oglbuffers, NULL);
377
378 if (oglctx == NULL)
379 {
380 SDL_SetError("ph_SetupOpenGLContext(): failed to create OpenGL context !\n");
381 qnxgl_buffers_destroy(oglbuffers);
382 qnxgl_finish();
383 return -1;
384 }
385
386 /* Attempt to make the context current so we can use OpenGL commands */
387 if (qnxgl_set_current(oglctx) == -1)
388 {
389 SDL_SetError("ph_SetupOpenGLContext(): failed to make the OpenGL context current !\n");
390 qnxgl_context_destroy(oglctx);
391 qnxgl_buffers_destroy(oglbuffers);
392 qnxgl_finish();
393 return -1;
394 }
395
396 PtFlush();
397
398 oglflags=flags;
399 oglbpp=bpp;
400
401 return 0;
402}
403
404#endif /* _NTO_VERSION */
405
406#endif /* SDL_VIDEO_OPENGL */
diff --git a/apps/plugins/sdl/src/video/photon/SDL_ph_gl.h b/apps/plugins/sdl/src/video/photon/SDL_ph_gl.h
deleted file mode 100644
index 1fb134abf3..0000000000
--- a/apps/plugins/sdl/src/video/photon/SDL_ph_gl.h
+++ /dev/null
@@ -1,41 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#ifndef __SDL_PH_GL_H__
25#define __SDL_PH_GL_H__
26
27#include "SDL_ph_video.h"
28
29#define DEFAULT_OPENGL "/usr/lib/libGL.so"
30
31#if SDL_VIDEO_OPENGL
32 void ph_GL_SwapBuffers(_THIS);
33 int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value);
34 int ph_GL_LoadLibrary(_THIS, const char* path);
35 void* ph_GL_GetProcAddress(_THIS, const char* proc);
36 int ph_GL_MakeCurrent(_THIS);
37
38 int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags);
39#endif /* SDL_VIDEO_OPENGL */
40
41#endif /* __SDL_PH_GL_H__ */
diff --git a/apps/plugins/sdl/src/video/photon/SDL_ph_image.c b/apps/plugins/sdl/src/video/photon/SDL_ph_image.c
deleted file mode 100644
index 7d64970ce6..0000000000
--- a/apps/plugins/sdl/src/video/photon/SDL_ph_image.c
+++ /dev/null
@@ -1,1059 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#include <Ph.h>
25#include <photon/Pg.h>
26
27#include "SDL_endian.h"
28#include "SDL_video.h"
29#include "../SDL_pixels_c.h"
30#include "SDL_ph_video.h"
31#include "SDL_ph_image_c.h"
32#include "SDL_ph_modes_c.h"
33#include "SDL_ph_gl.h"
34
35int ph_SetupImage(_THIS, SDL_Surface *screen)
36{
37 PgColor_t* palette=NULL;
38 int type=0;
39 int bpp;
40
41 bpp=screen->format->BitsPerPixel;
42
43 /* Determine image type */
44 switch(bpp)
45 {
46 case 8:{
47 type = Pg_IMAGE_PALETTE_BYTE;
48 }
49 break;
50 case 15:{
51 type = Pg_IMAGE_DIRECT_555;
52 }
53 break;
54 case 16:{
55 type = Pg_IMAGE_DIRECT_565;
56 }
57 break;
58 case 24:{
59 type = Pg_IMAGE_DIRECT_888;
60 }
61 break;
62 case 32:{
63 type = Pg_IMAGE_DIRECT_8888;
64 }
65 break;
66 default:{
67 SDL_SetError("ph_SetupImage(): unsupported bpp=%d !\n", bpp);
68 return -1;
69 }
70 break;
71 }
72
73 /* palette emulation code */
74 if ((bpp==8) && (desktoppal==SDLPH_PAL_EMULATE))
75 {
76 /* creating image palette */
77 palette=SDL_malloc(_Pg_MAX_PALETTE*sizeof(PgColor_t));
78 if (palette==NULL)
79 {
80 SDL_SetError("ph_SetupImage(): can't allocate memory for palette !\n");
81 return -1;
82 }
83 PgGetPalette(palette);
84
85 /* using shared memory for speed (set last param to 1) */
86 if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, palette, _Pg_MAX_PALETTE, 1)) == NULL)
87 {
88 SDL_SetError("ph_SetupImage(): PhCreateImage() failed for bpp=8 !\n");
89 SDL_free(palette);
90 return -1;
91 }
92 }
93 else
94 {
95 /* using shared memory for speed (set last param to 1) */
96 if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, NULL, 0, 1)) == NULL)
97 {
98 SDL_SetError("ph_SetupImage(): PhCreateImage() failed for bpp=%d !\n", bpp);
99 return -1;
100 }
101 }
102
103 screen->pixels = SDL_Image->image;
104 screen->pitch = SDL_Image->bpl;
105
106 this->UpdateRects = ph_NormalUpdate;
107
108 return 0;
109}
110
111int ph_SetupOCImage(_THIS, SDL_Surface *screen)
112{
113 int type = 0;
114 int bpp;
115
116 OCImage.flags = screen->flags;
117
118 bpp=screen->format->BitsPerPixel;
119
120 /* Determine image type */
121 switch(bpp)
122 {
123 case 8: {
124 type = Pg_IMAGE_PALETTE_BYTE;
125 }
126 break;
127 case 15:{
128 type = Pg_IMAGE_DIRECT_555;
129 }
130 break;
131 case 16:{
132 type = Pg_IMAGE_DIRECT_565;
133 }
134 break;
135 case 24:{
136 type = Pg_IMAGE_DIRECT_888;
137 }
138 break;
139 case 32:{
140 type = Pg_IMAGE_DIRECT_8888;
141 }
142 break;
143 default:{
144 SDL_SetError("ph_SetupOCImage(): unsupported bpp=%d !\n", bpp);
145 return -1;
146 }
147 break;
148 }
149
150 /* Currently offscreen contexts with the same bit depth as display bpp only can be created */
151 OCImage.offscreen_context = PdCreateOffscreenContext(0, screen->w, screen->h, Pg_OSC_MEM_PAGE_ALIGN);
152
153 if (OCImage.offscreen_context == NULL)
154 {
155 SDL_SetError("ph_SetupOCImage(): PdCreateOffscreenContext() function failed !\n");
156 return -1;
157 }
158
159 screen->pitch = OCImage.offscreen_context->pitch;
160
161 OCImage.dc_ptr = (unsigned char *)PdGetOffscreenContextPtr(OCImage.offscreen_context);
162
163 if (OCImage.dc_ptr == NULL)
164 {
165 SDL_SetError("ph_SetupOCImage(): PdGetOffscreenContextPtr function failed !\n");
166 PhDCRelease(OCImage.offscreen_context);
167 return -1;
168 }
169
170 OCImage.FrameData0 = OCImage.dc_ptr;
171 OCImage.CurrentFrameData = OCImage.FrameData0;
172 OCImage.current = 0;
173
174 PhDCSetCurrent(OCImage.offscreen_context);
175
176 screen->pixels = OCImage.CurrentFrameData;
177
178 this->UpdateRects = ph_OCUpdate;
179
180 return 0;
181}
182
183int ph_SetupFullScreenImage(_THIS, SDL_Surface* screen)
184{
185 OCImage.flags = screen->flags;
186
187 /* Begin direct and fullscreen mode */
188 if (!ph_EnterFullScreen(this, screen, PH_ENTER_DIRECTMODE))
189 {
190 return -1;
191 }
192
193 /* store palette for fullscreen */
194 if ((screen->format->BitsPerPixel==8) && (desktopbpp!=8))
195 {
196 PgGetPalette(savedpal);
197 PgGetPalette(syspalph);
198 }
199
200 OCImage.offscreen_context = PdCreateOffscreenContext(0, 0, 0, Pg_OSC_MAIN_DISPLAY | Pg_OSC_MEM_PAGE_ALIGN | Pg_OSC_CRTC_SAFE);
201 if (OCImage.offscreen_context == NULL)
202 {
203 SDL_SetError("ph_SetupFullScreenImage(): PdCreateOffscreenContext() function failed !\n");
204 return -1;
205 }
206
207 if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF)
208 {
209 OCImage.offscreen_backcontext = PdDupOffscreenContext(OCImage.offscreen_context, Pg_OSC_MEM_PAGE_ALIGN | Pg_OSC_CRTC_SAFE);
210 if (OCImage.offscreen_backcontext == NULL)
211 {
212 SDL_SetError("ph_SetupFullScreenImage(): PdCreateOffscreenContext(back) function failed !\n");
213 return -1;
214 }
215 }
216
217 OCImage.FrameData0 = (unsigned char *)PdGetOffscreenContextPtr(OCImage.offscreen_context);
218 if (OCImage.FrameData0 == NULL)
219 {
220 SDL_SetError("ph_SetupFullScreenImage(): PdGetOffscreenContextPtr() function failed !\n");
221 ph_DestroyImage(this, screen);
222 return -1;
223 }
224
225 if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF)
226 {
227 OCImage.FrameData1 = (unsigned char *)PdGetOffscreenContextPtr(OCImage.offscreen_backcontext);
228 if (OCImage.FrameData1 == NULL)
229 {
230 SDL_SetError("ph_SetupFullScreenImage(back): PdGetOffscreenContextPtr() function failed !\n");
231 ph_DestroyImage(this, screen);
232 return -1;
233 }
234 }
235
236 /* wait for the hardware */
237 PgFlush();
238 PgWaitHWIdle();
239
240 if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF)
241 {
242 OCImage.current = 0;
243 PhDCSetCurrent(OCImage.offscreen_context);
244 screen->pitch = OCImage.offscreen_context->pitch;
245 screen->pixels = OCImage.FrameData0;
246
247 /* emulate 640x400 videomode */
248 if (videomode_emulatemode==1)
249 {
250 int i;
251
252 for (i=0; i<40; i++)
253 {
254 SDL_memset(screen->pixels+screen->pitch*i, 0x00, screen->pitch);
255 }
256 for (i=440; i<480; i++)
257 {
258 SDL_memset(screen->pixels+screen->pitch*i, 0x00, screen->pitch);
259 }
260 screen->pixels+=screen->pitch*40;
261 }
262 PgSwapDisplay(OCImage.offscreen_backcontext, 0);
263 }
264 else
265 {
266 OCImage.current = 0;
267 PhDCSetCurrent(OCImage.offscreen_context);
268 screen->pitch = OCImage.offscreen_context->pitch;
269 screen->pixels = OCImage.FrameData0;
270
271 /* emulate 640x400 videomode */
272 if (videomode_emulatemode==1)
273 {
274 int i;
275
276 for (i=0; i<40; i++)
277 {
278 SDL_memset(screen->pixels+screen->pitch*i, 0x00, screen->pitch);
279 }
280 for (i=440; i<480; i++)
281 {
282 SDL_memset(screen->pixels+screen->pitch*i, 0x00, screen->pitch);
283 }
284 screen->pixels+=screen->pitch*40;
285 }
286 }
287
288 this->UpdateRects = ph_OCDCUpdate;
289
290 /* wait for the hardware */
291 PgFlush();
292 PgWaitHWIdle();
293
294 return 0;
295}
296
297#if SDL_VIDEO_OPENGL
298
299int ph_SetupOpenGLImage(_THIS, SDL_Surface* screen)
300{
301 this->UpdateRects = ph_OpenGLUpdate;
302 screen->pixels=NULL;
303 screen->pitch=NULL;
304
305 #if (_NTO_VERSION >= 630)
306 if ((screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
307 {
308 if (!ph_EnterFullScreen(this, screen, PH_IGNORE_DIRECTMODE))
309 {
310 screen->flags &= ~SDL_FULLSCREEN;
311 return -1;
312 }
313 }
314 #endif /* 6.3.0 */
315
316 if (ph_SetupOpenGLContext(this, screen->w, screen->h, screen->format->BitsPerPixel, screen->flags)!=0)
317 {
318 screen->flags &= ~SDL_OPENGL;
319 return -1;
320 }
321
322 return 0;
323}
324
325#endif /* SDL_VIDEO_OPENGL */
326
327void ph_DestroyImage(_THIS, SDL_Surface* screen)
328{
329
330#if SDL_VIDEO_OPENGL
331 if ((screen->flags & SDL_OPENGL)==SDL_OPENGL)
332 {
333 if (oglctx)
334 {
335 #if (_NTO_VERSION < 630)
336 PhDCSetCurrent(NULL);
337 PhDCRelease(oglctx);
338 #else
339 qnxgl_context_destroy(oglctx);
340 qnxgl_buffers_destroy(oglbuffers);
341 qnxgl_finish();
342 #endif /* 6.3.0 */
343 oglctx=NULL;
344 oglbuffers=NULL;
345 oglflags=0;
346 oglbpp=0;
347 }
348
349 #if (_NTO_VERSION >= 630)
350 if (currently_fullscreen)
351 {
352 ph_LeaveFullScreen(this);
353 }
354 #endif /* 6.3.0 */
355
356 return;
357 }
358#endif /* SDL_VIDEO_OPENGL */
359
360 if (currently_fullscreen)
361 {
362 /* if we right now in 8bpp fullscreen we must release palette */
363 if ((screen->format->BitsPerPixel==8) && (desktopbpp!=8))
364 {
365 PgSetPalette(syspalph, 0, -1, 0, 0, 0);
366 PgSetPalette(savedpal, 0, 0, _Pg_MAX_PALETTE, Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0);
367 PgFlush();
368 }
369 ph_LeaveFullScreen(this);
370 }
371
372 if (OCImage.offscreen_context != NULL)
373 {
374 PhDCRelease(OCImage.offscreen_context);
375 OCImage.offscreen_context = NULL;
376 OCImage.FrameData0 = NULL;
377 }
378 if (OCImage.offscreen_backcontext != NULL)
379 {
380 PhDCRelease(OCImage.offscreen_backcontext);
381 OCImage.offscreen_backcontext = NULL;
382 OCImage.FrameData1 = NULL;
383 }
384 OCImage.CurrentFrameData = NULL;
385
386 if (SDL_Image)
387 {
388 /* if palette allocated, free it */
389 if (SDL_Image->palette)
390 {
391 SDL_free(SDL_Image->palette);
392 }
393 PgShmemDestroy(SDL_Image->image);
394 SDL_free(SDL_Image);
395 }
396
397 /* Must be zeroed everytime */
398 SDL_Image = NULL;
399
400 if (screen)
401 {
402 screen->pixels = NULL;
403 }
404}
405
406int ph_UpdateHWInfo(_THIS)
407{
408 PgVideoModeInfo_t vmode;
409 PgHWCaps_t hwcaps;
410
411 /* Update video ram amount */
412 if (PgGetGraphicsHWCaps(&hwcaps) < 0)
413 {
414 SDL_SetError("ph_UpdateHWInfo(): GetGraphicsHWCaps() function failed !\n");
415 return -1;
416 }
417 this->info.video_mem=hwcaps.currently_available_video_ram/1024;
418
419 /* obtain current mode capabilities */
420 if (PgGetVideoModeInfo(hwcaps.current_video_mode, &vmode) < 0)
421 {
422 SDL_SetError("ph_UpdateHWInfo(): GetVideoModeInfo() function failed !\n");
423 return -1;
424 }
425
426 if ((vmode.mode_capabilities1 & PgVM_MODE_CAP1_OFFSCREEN) == PgVM_MODE_CAP1_OFFSCREEN)
427 {
428 /* this is a special test for drivers which tries to lie about offscreen capability */
429 if (hwcaps.currently_available_video_ram!=0)
430 {
431 this->info.hw_available = 1;
432 }
433 else
434 {
435 this->info.hw_available = 0;
436 }
437 }
438 else
439 {
440 this->info.hw_available = 0;
441 }
442
443 if ((vmode.mode_capabilities2 & PgVM_MODE_CAP2_RECTANGLE) == PgVM_MODE_CAP2_RECTANGLE)
444 {
445 this->info.blit_fill = 1;
446 }
447 else
448 {
449 this->info.blit_fill = 0;
450 }
451
452 if ((vmode.mode_capabilities2 & PgVM_MODE_CAP2_BITBLT) == PgVM_MODE_CAP2_BITBLT)
453 {
454 this->info.blit_hw = 1;
455 }
456 else
457 {
458 this->info.blit_hw = 0;
459 }
460
461 if ((vmode.mode_capabilities2 & PgVM_MODE_CAP2_ALPHA_BLEND) == PgVM_MODE_CAP2_ALPHA_BLEND)
462 {
463 this->info.blit_hw_A = 1;
464 }
465 else
466 {
467 this->info.blit_hw_A = 0;
468 }
469
470 if ((vmode.mode_capabilities2 & PgVM_MODE_CAP2_CHROMA) == PgVM_MODE_CAP2_CHROMA)
471 {
472 this->info.blit_hw_CC = 1;
473 }
474 else
475 {
476 this->info.blit_hw_CC = 0;
477 }
478
479 return 0;
480}
481
482int ph_SetupUpdateFunction(_THIS, SDL_Surface* screen, Uint32 flags)
483{
484 int setupresult=-1;
485
486 ph_DestroyImage(this, screen);
487
488#if SDL_VIDEO_OPENGL
489 if ((flags & SDL_OPENGL)==SDL_OPENGL)
490 {
491 setupresult=ph_SetupOpenGLImage(this, screen);
492 }
493 else
494 {
495#endif
496 if ((flags & SDL_FULLSCREEN)==SDL_FULLSCREEN)
497 {
498 setupresult=ph_SetupFullScreenImage(this, screen);
499 }
500 else
501 {
502 if ((flags & SDL_HWSURFACE)==SDL_HWSURFACE)
503 {
504 setupresult=ph_SetupOCImage(this, screen);
505 }
506 else
507 {
508 setupresult=ph_SetupImage(this, screen);
509 }
510 }
511#if SDL_VIDEO_OPENGL
512 }
513#endif
514 if (setupresult!=-1)
515 {
516 ph_UpdateHWInfo(this);
517 }
518
519 return setupresult;
520}
521
522int ph_AllocHWSurface(_THIS, SDL_Surface* surface)
523{
524 PgHWCaps_t hwcaps;
525
526 if (surface->hwdata!=NULL)
527 {
528 SDL_SetError("ph_AllocHWSurface(): hwdata already exists!\n");
529 return -1;
530 }
531 surface->hwdata=SDL_malloc(sizeof(struct private_hwdata));
532 SDL_memset(surface->hwdata, 0x00, sizeof(struct private_hwdata));
533 surface->hwdata->offscreenctx=PdCreateOffscreenContext(0, surface->w, surface->h, Pg_OSC_MEM_PAGE_ALIGN);
534 if (surface->hwdata->offscreenctx == NULL)
535 {
536 SDL_SetError("ph_AllocHWSurface(): PdCreateOffscreenContext() function failed !\n");
537 return -1;
538 }
539 surface->pixels=PdGetOffscreenContextPtr(surface->hwdata->offscreenctx);
540 if (surface->pixels==NULL)
541 {
542 PhDCRelease(surface->hwdata->offscreenctx);
543 SDL_SetError("ph_AllocHWSurface(): PdGetOffscreenContextPtr() function failed !\n");
544 return -1;
545 }
546 surface->pitch=surface->hwdata->offscreenctx->pitch;
547 surface->flags|=SDL_HWSURFACE;
548 surface->flags|=SDL_PREALLOC;
549
550#if 0 /* FIXME */
551 /* create simple offscreen lock */
552 surface->hwdata->crlockparam.flags=0;
553 if (PdCreateOffscreenLock(surface->hwdata->offscreenctx, &surface->hwdata->crlockparam)!=EOK)
554 {
555 PhDCRelease(surface->hwdata->offscreenctx);
556 SDL_SetError("ph_AllocHWSurface(): Can't create offscreen lock !\n");
557 return -1;
558 }
559#endif /* 0 */
560
561 /* Update video ram amount */
562 if (PgGetGraphicsHWCaps(&hwcaps) < 0)
563 {
564 PdDestroyOffscreenLock(surface->hwdata->offscreenctx);
565 PhDCRelease(surface->hwdata->offscreenctx);
566 SDL_SetError("ph_AllocHWSurface(): GetGraphicsHWCaps() function failed !\n");
567 return -1;
568 }
569 this->info.video_mem=hwcaps.currently_available_video_ram/1024;
570
571 return 0;
572}
573
574void ph_FreeHWSurface(_THIS, SDL_Surface* surface)
575{
576 PgHWCaps_t hwcaps;
577
578 if (surface->hwdata==NULL)
579 {
580 SDL_SetError("ph_FreeHWSurface(): no hwdata!\n");
581 return;
582 }
583 if (surface->hwdata->offscreenctx == NULL)
584 {
585 SDL_SetError("ph_FreeHWSurface(): no offscreen context to delete!\n");
586 return;
587 }
588
589#if 0 /* FIXME */
590 /* unlock the offscreen context if it has been locked before destroy it */
591 if (PdIsOffscreenLocked(surface->hwdata->offscreenctx)==Pg_OSC_LOCKED)
592 {
593 PdUnlockOffscreen(surface->hwdata->offscreenctx);
594 }
595
596 PdDestroyOffscreenLock(surface->hwdata->offscreenctx);
597#endif /* 0 */
598
599 PhDCRelease(surface->hwdata->offscreenctx);
600
601 SDL_free(surface->hwdata);
602 surface->hwdata=NULL;
603
604 /* Update video ram amount */
605 if (PgGetGraphicsHWCaps(&hwcaps) < 0)
606 {
607 SDL_SetError("ph_FreeHWSurface(): GetGraphicsHWCaps() function failed !\n");
608 return;
609 }
610 this->info.video_mem=hwcaps.currently_available_video_ram/1024;
611
612 return;
613}
614
615int ph_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst)
616{
617 if ((src->hwdata==NULL) && (src != this->screen))
618 {
619 SDL_SetError("ph_CheckHWBlit(): Source surface haven't hardware specific data.\n");
620 src->flags&=~SDL_HWACCEL;
621 return -1;
622 }
623 if ((src->flags & SDL_HWSURFACE) != SDL_HWSURFACE)
624 {
625 SDL_SetError("ph_CheckHWBlit(): Source surface isn't a hardware surface.\n");
626 src->flags&=~SDL_HWACCEL;
627 return -1;
628 }
629
630 if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY)
631 {
632 if (this->info.blit_hw_CC!=1)
633 {
634 src->flags&=~SDL_HWACCEL;
635 src->map->hw_blit=NULL;
636 return -1;
637 }
638 }
639
640 if ((src->flags & SDL_SRCALPHA) == SDL_SRCALPHA)
641 {
642 if (this->info.blit_hw_A!=1)
643 {
644 src->flags&=~SDL_HWACCEL;
645 src->map->hw_blit=NULL;
646 return -1;
647 }
648 }
649
650 src->flags|=SDL_HWACCEL;
651 src->map->hw_blit = ph_HWAccelBlit;
652
653 return 1;
654}
655
656PgColor_t ph_ExpandColor(_THIS, SDL_Surface* surface, Uint32 color)
657{
658 Uint32 truecolor;
659
660 /* Photon API accepts true colors only during hw filling operations */
661 switch(surface->format->BitsPerPixel)
662 {
663 case 8:
664 {
665 if ((surface->format->palette) && (color<=surface->format->palette->ncolors))
666 {
667 truecolor=PgRGB(surface->format->palette->colors[color].r,
668 surface->format->palette->colors[color].g,
669 surface->format->palette->colors[color].b);
670 }
671 else
672 {
673 SDL_SetError("ph_ExpandColor(): Color out of range for the 8bpp mode !\n");
674 return 0xFFFFFFFFUL;
675 }
676 }
677 break;
678 case 15:
679 {
680 truecolor = ((color & 0x00007C00UL) << 9) | /* R */
681 ((color & 0x000003E0UL) << 6) | /* G */
682 ((color & 0x0000001FUL) << 3) | /* B */
683 ((color & 0x00007000UL) << 4) | /* R compensation */
684 ((color & 0x00000380UL) << 1) | /* G compensation */
685 ((color & 0x0000001CUL) >> 2); /* B compensation */
686 }
687 break;
688 case 16:
689 {
690 truecolor = ((color & 0x0000F800UL) << 8) | /* R */
691 ((color & 0x000007E0UL) << 5) | /* G */
692 ((color & 0x0000001FUL) << 3) | /* B */
693 ((color & 0x0000E000UL) << 3) | /* R compensation */
694 ((color & 0x00000600UL) >> 1) | /* G compensation */
695 ((color & 0x0000001CUL) >> 2); /* B compensation */
696
697 }
698 break;
699 case 24:
700 {
701 truecolor=color & 0x00FFFFFFUL;
702 }
703 break;
704 case 32:
705 {
706 truecolor=color;
707 }
708 break;
709 default:
710 {
711 SDL_SetError("ph_ExpandColor(): Unsupported depth for the hardware operations !\n");
712 return 0xFFFFFFFFUL;
713 }
714 }
715
716 return truecolor;
717}
718
719int ph_FillHWRect(_THIS, SDL_Surface* surface, SDL_Rect* rect, Uint32 color)
720{
721 PgColor_t oldcolor;
722 Uint32 truecolor;
723 int ydisp=0;
724
725 if (this->info.blit_fill!=1)
726 {
727 return -1;
728 }
729
730 truecolor=ph_ExpandColor(this, surface, color);
731 if (truecolor==0xFFFFFFFFUL)
732 {
733 return -1;
734 }
735
736 oldcolor=PgSetFillColor(truecolor);
737
738 /* 640x400 videomode emulation */
739 if (videomode_emulatemode==1)
740 {
741 ydisp+=40;
742 }
743
744 PgDrawIRect(rect->x, rect->y+ydisp, rect->w+rect->x-1, rect->h+rect->y+ydisp-1, Pg_DRAW_FILL);
745 PgSetFillColor(oldcolor);
746 PgFlush();
747 PgWaitHWIdle();
748
749 return 0;
750}
751
752int ph_FlipHWSurface(_THIS, SDL_Surface* screen)
753{
754 PhArea_t farea;
755
756 if ((screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
757 {
758 /* flush all drawing ops before blitting */
759 PgFlush();
760 PgWaitHWIdle();
761
762 farea.pos.x=0;
763 farea.pos.y=0;
764 farea.size.w=screen->w;
765 farea.size.h=screen->h;
766
767 /* emulate 640x400 videomode */
768 if (videomode_emulatemode==1)
769 {
770 farea.pos.y+=40;
771 }
772
773 PgContextBlitArea(OCImage.offscreen_context, &farea, OCImage.offscreen_backcontext, &farea);
774
775 /* flush the blitting */
776 PgFlush();
777 PgWaitHWIdle();
778 }
779 return 0;
780}
781
782int ph_LockHWSurface(_THIS, SDL_Surface* surface)
783{
784
785#if 0 /* FIXME */
786 int lockresult;
787
788 if (surface->hwdata == NULL)
789 {
790 return;
791 }
792
793 surface->hwdata->lockparam.flags=0;
794 surface->hwdata->lockparam.time_out=NULL;
795 lockresult=PdLockOffscreen(surface->hwdata->offscreenctx, &surface->hwdata->lockparam);
796
797 switch (lockresult)
798 {
799 case EOK:
800 break;
801 case Pg_OSC_LOCK_DEADLOCK:
802 SDL_SetError("ph_LockHWSurface(): Deadlock detected !\n");
803 return -1;
804 case Pg_OSC_LOCK_INVALID:
805 SDL_SetError("ph_LockHWSurface(): Lock invalid !\n");
806 return -1;
807 default:
808 SDL_SetError("ph_LockHWSurface(): Can't lock the surface !\n");
809 return -1;
810 }
811#endif /* 0 */
812
813 return 0;
814}
815
816void ph_UnlockHWSurface(_THIS, SDL_Surface* surface)
817{
818
819#if 0 /* FIXME */
820 int unlockresult;
821
822 if ((surface == NULL) || (surface->hwdata == NULL))
823 {
824 return;
825 }
826
827 if (PdIsOffscreenLocked(surface->hwdata->offscreenctx)==Pg_OSC_LOCKED)
828 {
829 unlockresult=PdUnlockOffscreen(surface->hwdata->offscreenctx);
830 }
831#endif /* 0 */
832
833 return;
834}
835
836int ph_HWAccelBlit(SDL_Surface* src, SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect)
837{
838 SDL_VideoDevice* this=current_video;
839 PhArea_t srcarea;
840 PhArea_t dstarea;
841 int ydisp=0;
842
843 /* 640x400 videomode emulation */
844 if (videomode_emulatemode==1)
845 {
846 ydisp+=40;
847 }
848
849 srcarea.pos.x=srcrect->x;
850 srcarea.pos.y=srcrect->y;
851 srcarea.size.w=srcrect->w;
852 srcarea.size.h=srcrect->h;
853
854 dstarea.pos.x=dstrect->x;
855 dstarea.pos.y=dstrect->y;
856 dstarea.size.w=dstrect->w;
857 dstarea.size.h=dstrect->h;
858
859 if (((src == this->screen) || (src->hwdata!=NULL)) && ((dst == this->screen) || (dst->hwdata!=NULL)))
860 {
861 if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY)
862 {
863 ph_SetHWColorKey(this, src, src->format->colorkey);
864 PgChromaOn();
865 }
866
867 if ((src->flags & SDL_SRCALPHA) == SDL_SRCALPHA)
868 {
869 ph_SetHWAlpha(this, src, src->format->alpha);
870 PgAlphaOn();
871 }
872
873 if (dst == this->screen)
874 {
875 if (src == this->screen)
876 {
877 /* blitting from main screen to main screen */
878 dstarea.pos.y+=ydisp;
879 srcarea.pos.y+=ydisp;
880 PgContextBlitArea(OCImage.offscreen_context, &srcarea, OCImage.offscreen_context, &dstarea);
881 }
882 else
883 {
884 /* blitting from offscreen to main screen */
885 dstarea.pos.y+=ydisp;
886 PgContextBlitArea(src->hwdata->offscreenctx, &srcarea, OCImage.offscreen_context, &dstarea);
887 }
888 }
889 else
890 {
891 if (src == this->screen)
892 {
893 /* blitting from main screen to offscreen */
894 srcarea.pos.y+=ydisp;
895 PgContextBlitArea(OCImage.offscreen_context, &srcarea, dst->hwdata->offscreenctx, &dstarea);
896 }
897 else
898 {
899 /* blitting offscreen to offscreen */
900 PgContextBlitArea(src->hwdata->offscreenctx, &srcarea, dst->hwdata->offscreenctx, &dstarea);
901 }
902 }
903
904 if ((src->flags & SDL_SRCALPHA) == SDL_SRCALPHA)
905 {
906 PgAlphaOff();
907 }
908
909 if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY)
910 {
911 PgChromaOff();
912 }
913 }
914 else
915 {
916 SDL_SetError("ph_HWAccelBlit(): Source or target surface is not a hardware surface !\n");
917 return -1;
918 }
919
920 PgFlush();
921 PgWaitHWIdle();
922
923 return 0;
924}
925
926int ph_SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key)
927{
928 if (this->info.blit_hw_CC!=1)
929 {
930 return -1;
931 }
932
933 if (surface->hwdata!=NULL)
934 {
935 surface->hwdata->colorkey=ph_ExpandColor(this, surface, key);
936 if (surface->hwdata->colorkey==0xFFFFFFFFUL)
937 {
938 return -1;
939 }
940 }
941 PgSetChroma(surface->hwdata->colorkey, Pg_CHROMA_SRC_MATCH | Pg_CHROMA_NODRAW);
942
943 return 0;
944}
945
946int ph_SetHWAlpha(_THIS, SDL_Surface* surface, Uint8 alpha)
947{
948 if (this->info.blit_hw_A!=1)
949 {
950 return -1;
951 }
952
953 PgSetAlphaBlend(NULL, alpha);
954
955 return 0;
956}
957
958#if SDL_VIDEO_OPENGL
959void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect* rects)
960{
961 this->GL_SwapBuffers(this);
962
963 return;
964}
965#endif /* SDL_VIDEO_OPENGL */
966
967void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects)
968{
969 PhPoint_t ph_pos;
970 PhRect_t ph_rect;
971 int i;
972
973 for (i=0; i<numrects; ++i)
974 {
975 if (rects[i].w==0) /* Clipped? dunno why but this occurs sometime. */
976 {
977 continue;
978 }
979
980 if (rects[i].h==0) /* Clipped? dunno why but this occurs sometime. */
981 {
982 continue;
983 }
984
985 ph_pos.x = rects[i].x;
986 ph_pos.y = rects[i].y;
987 ph_rect.ul.x = rects[i].x;
988 ph_rect.ul.y = rects[i].y;
989 ph_rect.lr.x = rects[i].x + rects[i].w;
990 ph_rect.lr.y = rects[i].y + rects[i].h;
991
992 if (PgDrawPhImageRectmx(&ph_pos, SDL_Image, &ph_rect, 0) < 0)
993 {
994 SDL_SetError("ph_NormalUpdate(): PgDrawPhImageRectmx failed!\n");
995 return;
996 }
997 }
998
999 if (PgFlush() < 0)
1000 {
1001 SDL_SetError("ph_NormalUpdate(): PgFlush() function failed!\n");
1002 }
1003}
1004
1005void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects)
1006{
1007 int i;
1008
1009 PhPoint_t zero = {0, 0};
1010 PhArea_t src_rect;
1011 PhArea_t dest_rect;
1012
1013 PgSetTranslation(&zero, 0);
1014 PgSetRegion(PtWidgetRid(window));
1015 PgSetClipping(0, NULL);
1016
1017 PgFlush();
1018 PgWaitHWIdle();
1019
1020 for (i=0; i<numrects; ++i)
1021 {
1022 if (rects[i].w == 0) /* Clipped? */
1023 {
1024 continue;
1025 }
1026
1027 if (rects[i].h == 0) /* Clipped? */
1028 {
1029 continue;
1030 }
1031
1032 src_rect.pos.x=rects[i].x;
1033 src_rect.pos.y=rects[i].y;
1034 dest_rect.pos.x=rects[i].x;
1035 dest_rect.pos.y=rects[i].y;
1036
1037 src_rect.size.w=rects[i].w;
1038 src_rect.size.h=rects[i].h;
1039 dest_rect.size.w=rects[i].w;
1040 dest_rect.size.h=rects[i].h;
1041
1042 PgContextBlitArea(OCImage.offscreen_context, &src_rect, NULL, &dest_rect);
1043 }
1044
1045 if (PgFlush() < 0)
1046 {
1047 SDL_SetError("ph_OCUpdate(): PgFlush failed.\n");
1048 }
1049}
1050
1051void ph_OCDCUpdate(_THIS, int numrects, SDL_Rect *rects)
1052{
1053 PgWaitHWIdle();
1054
1055 if (PgFlush() < 0)
1056 {
1057 SDL_SetError("ph_OCDCUpdate(): PgFlush failed.\n");
1058 }
1059}
diff --git a/apps/plugins/sdl/src/video/photon/SDL_ph_image_c.h b/apps/plugins/sdl/src/video/photon/SDL_ph_image_c.h
deleted file mode 100644
index cfd96698c4..0000000000
--- a/apps/plugins/sdl/src/video/photon/SDL_ph_image_c.h
+++ /dev/null
@@ -1,59 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#ifndef __SDL_PH_IMAGE_H__
25#define __SDL_PH_IMAGE_H__
26
27#include "../../events/SDL_events_c.h"
28#include "SDL_ph_video.h"
29
30struct private_hwdata
31{
32 PdOffscreenContext_t* offscreenctx;
33 PdOSCCreateLockParams_t crlockparam;
34 PdOSCLockParams_t lockparam;
35 Uint32 colorkey;
36};
37
38extern int ph_SetupImage(_THIS, SDL_Surface* screen);
39extern void ph_DestroyImage(_THIS, SDL_Surface* screen);
40extern int ph_SetupUpdateFunction(_THIS, SDL_Surface* screen, Uint32 flags);
41
42extern int ph_AllocHWSurface(_THIS, SDL_Surface* surface);
43extern void ph_FreeHWSurface(_THIS, SDL_Surface* surface);
44extern int ph_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst);
45extern int ph_FillHWRect(_THIS, SDL_Surface* surface, SDL_Rect* rect, Uint32 color);
46extern int ph_LockHWSurface(_THIS, SDL_Surface* surface);
47extern void ph_UnlockHWSurface(_THIS, SDL_Surface* surface);
48extern int ph_FlipHWSurface(_THIS, SDL_Surface* surface);
49extern int ph_SetHWColorKey(_THIS, SDL_Surface* surface, Uint32 key);
50extern int ph_SetHWAlpha(_THIS, SDL_Surface* surface, Uint8 alpha);
51extern int ph_HWAccelBlit(SDL_Surface* src, SDL_Rect *srcrect, SDL_Surface* dst, SDL_Rect* dstrect);
52extern int ph_UpdateHWInfo(_THIS);
53
54extern void ph_NormalUpdate(_THIS, int numrects, SDL_Rect* rects);
55extern void ph_OCUpdate(_THIS, int numrects, SDL_Rect* rects);
56extern void ph_OCDCUpdate(_THIS, int numrects, SDL_Rect* rects);
57extern void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect* rects);
58
59#endif /* __SDL_PH_IMAGE_H__ */
diff --git a/apps/plugins/sdl/src/video/photon/SDL_ph_modes.c b/apps/plugins/sdl/src/video/photon/SDL_ph_modes.c
deleted file mode 100644
index 8c2bf7e4bf..0000000000
--- a/apps/plugins/sdl/src/video/photon/SDL_ph_modes.c
+++ /dev/null
@@ -1,390 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#include "SDL_ph_modes_c.h"
25
26static PgVideoModeInfo_t mode_info;
27static PgVideoModes_t mode_list;
28
29/* The current list of available video modes */
30SDL_Rect SDL_modelist[PH_MAX_VIDEOMODES];
31SDL_Rect* SDL_modearray[PH_MAX_VIDEOMODES];
32
33static int compare_modes_by_res(const void* mode1, const void* mode2)
34{
35 PgVideoModeInfo_t mode1_info;
36 PgVideoModeInfo_t mode2_info;
37
38 if (PgGetVideoModeInfo(*(unsigned short*)mode1, &mode1_info) < 0)
39 {
40 return 0;
41 }
42
43 if (PgGetVideoModeInfo(*(unsigned short*)mode2, &mode2_info) < 0)
44 {
45 return 0;
46 }
47
48 if (mode1_info.width == mode2_info.width)
49 {
50 return mode2_info.height - mode1_info.height;
51 }
52 else
53 {
54 return mode2_info.width - mode1_info.width;
55 }
56}
57
58SDL_Rect **ph_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
59{
60 int i = 0;
61 int j = 0;
62 SDL_Rect Amodelist[PH_MAX_VIDEOMODES];
63
64 for (i=0; i<PH_MAX_VIDEOMODES; i++)
65 {
66 SDL_modearray[i]=&SDL_modelist[i];
67 }
68
69 if (PgGetVideoModeList(&mode_list) < 0)
70 {
71 SDL_SetError("ph_ListModes(): PgGetVideoModeList() function failed !\n");
72 return NULL;
73 }
74
75 mode_info.bits_per_pixel = 0;
76
77 for (i=0; i < mode_list.num_modes; i++)
78 {
79 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
80 {
81 SDL_SetError("ph_ListModes(): PgGetVideoModeInfo() function failed on mode: 0x%X.\n", mode_list.modes[i]);
82 return NULL;
83 }
84 if(mode_info.bits_per_pixel == format->BitsPerPixel)
85 {
86 Amodelist[j].w = mode_info.width;
87 Amodelist[j].h = mode_info.height;
88 Amodelist[j].x = 0;
89 Amodelist[j].y = 0;
90 j++;
91 }
92 }
93
94 /* reorder biggest for smallest, assume width dominates */
95
96 for(i=0; i<j; i++)
97 {
98 SDL_modelist[i].w = Amodelist[j - i - 1].w;
99 SDL_modelist[i].h = Amodelist[j - i - 1].h;
100 SDL_modelist[i].x = Amodelist[j - i - 1].x;
101 SDL_modelist[i].y = Amodelist[j - i - 1].y;
102 }
103 SDL_modearray[j]=NULL;
104
105 return SDL_modearray;
106}
107
108void ph_FreeVideoModes(_THIS)
109{
110 return;
111}
112
113/* return the mode associated with width, height and bpp */
114/* if there is no mode then zero is returned */
115int ph_GetVideoMode(int width, int height, int bpp)
116{
117 int i;
118 int modestage=0;
119 int closestmode=0;
120
121 if (PgGetVideoModeList(&mode_list) < 0)
122 {
123 return -1;
124 }
125
126 /* special case for the double-sized 320x200 mode */
127 if ((width==640) && (height==400))
128 {
129 modestage=1;
130 }
131
132 /* search list for exact match */
133 for (i=0; i<mode_list.num_modes; i++)
134 {
135 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
136 {
137 return 0;
138 }
139
140 if ((mode_info.width == width) && (mode_info.height == height) &&
141 (mode_info.bits_per_pixel == bpp))
142 {
143 return mode_list.modes[i];
144 }
145 else
146 {
147 if ((modestage) && (mode_info.width == width) && (mode_info.height == height+80) &&
148 (mode_info.bits_per_pixel == bpp))
149 {
150 modestage=2;
151 closestmode=mode_list.modes[i];
152 }
153 }
154 }
155
156 /* if we are here, then no 640x400xbpp mode found and we'll emulate it via 640x480xbpp mode */
157 if (modestage==2)
158 {
159 return closestmode;
160 }
161
162 return (i == mode_list.num_modes) ? 0 : mode_list.modes[i];
163}
164
165/* return the mode associated with width, height and bpp */
166/* if requested bpp is not found the mode with closest bpp is returned */
167int get_mode_any_format(int width, int height, int bpp)
168{
169 int i, closest, delta, min_delta;
170
171 if (PgGetVideoModeList(&mode_list) < 0)
172 {
173 return -1;
174 }
175
176 SDL_qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_res);
177
178 for(i=0;i<mode_list.num_modes;i++)
179 {
180 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
181 {
182 return 0;
183 }
184 if ((mode_info.width == width) && (mode_info.height == height))
185 {
186 break;
187 }
188 }
189
190 if (i<mode_list.num_modes)
191 {
192 /* get closest bpp */
193 closest = i++;
194 if (mode_info.bits_per_pixel == bpp)
195 {
196 return mode_list.modes[closest];
197 }
198
199 min_delta = abs(mode_info.bits_per_pixel - bpp);
200
201 while(1)
202 {
203 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
204 {
205 return 0;
206 }
207
208 if ((mode_info.width != width) || (mode_info.height != height))
209 {
210 break;
211 }
212 else
213 {
214 if (mode_info.bits_per_pixel == bpp)
215 {
216 closest = i;
217 break;
218 }
219 else
220 {
221 delta = abs(mode_info.bits_per_pixel - bpp);
222 if (delta < min_delta)
223 {
224 closest = i;
225 min_delta = delta;
226 }
227 i++;
228 }
229 }
230 }
231 return mode_list.modes[closest];
232 }
233
234 return 0;
235}
236
237int ph_ToggleFullScreen(_THIS, int on)
238{
239 return -1;
240}
241
242int ph_EnterFullScreen(_THIS, SDL_Surface* screen, int fmode)
243{
244 PgDisplaySettings_t settings;
245 int mode;
246 char* refreshrate;
247 int refreshratenum;
248
249 if (!currently_fullscreen)
250 {
251 /* Get the video mode and set it */
252 if (screen->flags & SDL_ANYFORMAT)
253 {
254 if ((mode = get_mode_any_format(screen->w, screen->h, screen->format->BitsPerPixel)) == 0)
255 {
256 SDL_SetError("ph_EnterFullScreen(): can't find appropriate video mode !\n");
257 return 0;
258 }
259 }
260 else
261 {
262 if ((mode = ph_GetVideoMode(screen->w, screen->h, screen->format->BitsPerPixel)) == 0)
263 {
264 SDL_SetError("ph_EnterFullScreen(): can't find appropriate video mode !\n");
265 return 0;
266 }
267 if (PgGetVideoModeInfo(mode, &mode_info) < 0)
268 {
269 SDL_SetError("ph_EnterFullScreen(): can't get video mode capabilities !\n");
270 return 0;
271 }
272 if (mode_info.height != screen->h)
273 {
274 if ((mode_info.height==480) && (screen->h==400))
275 {
276 videomode_emulatemode=1;
277 }
278 }
279 else
280 {
281 videomode_emulatemode=0;
282 }
283 }
284
285 /* save old video mode caps */
286 PgGetVideoMode(&settings);
287 old_video_mode=settings.mode;
288 old_refresh_rate=settings.refresh;
289
290 /* setup new video mode */
291 settings.mode = mode;
292 settings.refresh = 0;
293 settings.flags = 0;
294
295 refreshrate=SDL_getenv("SDL_PHOTON_FULLSCREEN_REFRESH");
296 if (refreshrate!=NULL)
297 {
298 if (SDL_sscanf(refreshrate, "%d", &refreshratenum)==1)
299 {
300 settings.refresh = refreshratenum;
301 }
302 }
303
304 if (PgSetVideoMode(&settings) < 0)
305 {
306 SDL_SetError("ph_EnterFullScreen(): PgSetVideoMode() call failed !\n");
307 return 0;
308 }
309
310 if (this->screen)
311 {
312 if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)
313 {
314#if !SDL_VIDEO_OPENGL || (_NTO_VERSION < 630)
315 return 0; /* 6.3.0 */
316#endif
317 }
318 }
319
320 if (fmode==0)
321 {
322 if (OCImage.direct_context==NULL)
323 {
324 OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext();
325 if (!OCImage.direct_context)
326 {
327 SDL_SetError("ph_EnterFullScreen(): Can't create direct context !\n");
328 ph_LeaveFullScreen(this);
329 return 0;
330 }
331 }
332 OCImage.oldDC=PdDirectStart(OCImage.direct_context);
333 }
334
335 currently_fullscreen = 1;
336 }
337 PgFlush();
338
339 return 1;
340}
341
342int ph_LeaveFullScreen(_THIS)
343{
344 PgDisplaySettings_t oldmode_settings;
345
346 if (currently_fullscreen)
347 {
348 if ((this->screen) && ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL))
349 {
350#if !SDL_VIDEO_OPENGL || (_NTO_VERSION < 630)
351 return 0;
352#endif
353 }
354
355 /* release routines starts here */
356 {
357 if (OCImage.direct_context)
358 {
359 PdDirectStop(OCImage.direct_context);
360 PdReleaseDirectContext(OCImage.direct_context);
361 OCImage.direct_context=NULL;
362 }
363 if (OCImage.oldDC)
364 {
365 PhDCSetCurrent(OCImage.oldDC);
366 OCImage.oldDC=NULL;
367 }
368
369 currently_fullscreen=0;
370
371 /* Restore old video mode */
372 if (old_video_mode != -1)
373 {
374 oldmode_settings.mode = (unsigned short) old_video_mode;
375 oldmode_settings.refresh = (unsigned short) old_refresh_rate;
376 oldmode_settings.flags = 0;
377
378 if (PgSetVideoMode(&oldmode_settings) < 0)
379 {
380 SDL_SetError("Ph_LeaveFullScreen(): PgSetVideoMode() function failed !\n");
381 return 0;
382 }
383 }
384
385 old_video_mode=-1;
386 old_refresh_rate=-1;
387 }
388 }
389 return 1;
390}
diff --git a/apps/plugins/sdl/src/video/photon/SDL_ph_modes_c.h b/apps/plugins/sdl/src/video/photon/SDL_ph_modes_c.h
deleted file mode 100644
index 117c5a3a91..0000000000
--- a/apps/plugins/sdl/src/video/photon/SDL_ph_modes_c.h
+++ /dev/null
@@ -1,43 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#ifndef __SDL_PH_MODES_H__
25#define __SDL_PH_MODES_H__
26
27#include "SDL_ph_video.h"
28
29#define PH_MAX_VIDEOMODES 127
30
31#define PH_ENTER_DIRECTMODE 0
32#define PH_IGNORE_DIRECTMODE 1
33
34extern SDL_Rect **ph_ListModes(_THIS,SDL_PixelFormat *format, Uint32 flags);
35extern void ph_FreeVideoModes(_THIS);
36extern int ph_ResizeFullScreen(_THIS);
37extern int ph_EnterFullScreen(_THIS, SDL_Surface* screen, int fmode);
38extern int ph_LeaveFullScreen(_THIS);
39extern int ph_GetVideoMode(int width, int height, int bpp);
40extern int get_mode_any_format(int width, int height, int bpp);
41extern int ph_ToggleFullScreen(_THIS, int on);
42
43#endif /* __SDL_PH_MODES_H__ */
diff --git a/apps/plugins/sdl/src/video/photon/SDL_ph_mouse.c b/apps/plugins/sdl/src/video/photon/SDL_ph_mouse.c
deleted file mode 100644
index a25aa1fc85..0000000000
--- a/apps/plugins/sdl/src/video/photon/SDL_ph_mouse.c
+++ /dev/null
@@ -1,220 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#include "SDL_mouse.h"
25#include "../../events/SDL_events_c.h"
26#include "../SDL_cursor_c.h"
27#include "SDL_ph_mouse_c.h"
28
29struct WMcursor
30{
31 PhCursorDef_t *ph_cursor ;
32};
33
34void ph_FreeWMCursor(_THIS, WMcursor *cursor)
35{
36 if (window != NULL)
37 {
38 SDL_Lock_EventThread();
39
40 if (PtSetResource(window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_INHERIT, 0) < 0)
41 {
42 /* TODO: output error msg */
43 }
44
45 SDL_Unlock_EventThread();
46 }
47
48 SDL_free(cursor);
49}
50
51WMcursor *ph_CreateWMCursor(_THIS, Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
52{
53 WMcursor* cursor;
54 int clen, i;
55 unsigned char bit, databit, maskbit;
56
57 /* Allocate and initialize the cursor memory */
58 if ((cursor = (WMcursor*)SDL_malloc(sizeof(WMcursor))) == NULL)
59 {
60 SDL_OutOfMemory();
61 return(NULL);
62 }
63 SDL_memset(cursor,0,sizeof(WMcursor));
64
65 cursor->ph_cursor = (PhCursorDef_t *) SDL_malloc(sizeof(PhCursorDef_t) + 32*4*2);
66
67 if (cursor->ph_cursor == NULL)
68 {
69 SDL_SetError("ph_CreateWMCursor(): cursor malloc failed !\n");
70 return NULL;
71 }
72
73 SDL_memset(cursor->ph_cursor,0,(sizeof(PhCursorDef_t) + 32*4*2));
74
75 cursor->ph_cursor->hdr.type =Ph_RDATA_CURSOR;
76 cursor->ph_cursor->size1.x = (short)w;
77 cursor->ph_cursor->size1.y = (short)h;
78 cursor->ph_cursor->offset1.x = (short)hot_x;
79 cursor->ph_cursor->offset1.y = (short)hot_y;
80 cursor->ph_cursor->bytesperline1 = (char)w/8;
81 cursor->ph_cursor->color1 = Pg_WHITE;
82 cursor->ph_cursor->size2.x = (short)w;
83 cursor->ph_cursor->size2.y = (short)h;
84 cursor->ph_cursor->offset2.x = (short)hot_x;
85 cursor->ph_cursor->offset2.y = (short)hot_y;
86 cursor->ph_cursor->bytesperline2 = (char)w/8;
87 cursor->ph_cursor->color2 = Pg_BLACK;
88
89 clen = (w/8)*h;
90
91 /* Copy the mask and the data to different bitmap planes */
92 for (i=0; i<clen; ++i)
93 {
94 for (bit = 0; bit < 8; bit++)
95 {
96 databit = data[i] & (1 << bit);
97 maskbit = mask[i] & (1 << bit);
98
99 cursor->ph_cursor->images[i] |= (databit == 0) ? maskbit : 0;
100 /* If the databit != 0, treat it as a black pixel and
101 * ignore the maskbit (can't do an inverted color) */
102 cursor->ph_cursor->images[i+clen] |= databit;
103 }
104 }
105
106 /* #bytes following the hdr struct */
107 cursor->ph_cursor->hdr.len =sizeof(PhCursorDef_t) + clen*2 - sizeof(PhRegionDataHdr_t);
108
109 return (cursor);
110}
111
112PhCursorDef_t ph_GetWMPhCursor(WMcursor *cursor)
113{
114 return (*cursor->ph_cursor);
115}
116
117int ph_ShowWMCursor(_THIS, WMcursor* cursor)
118{
119 PtArg_t args[3];
120 int nargs = 0;
121
122 /* Don't do anything if the display is gone */
123 if (window == NULL)
124 {
125 return (0);
126 }
127
128 /* looks like photon can't draw mouse cursor in direct mode */
129 if ((this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
130 {
131 /* disable the fake mouse in the fullscreen OpenGL mode */
132 if ((this->screen->flags & SDL_OPENGL) == SDL_OPENGL)
133 {
134 cursor=NULL;
135 }
136 else
137 {
138 return (0);
139 }
140 }
141
142 /* Set the photon cursor, or blank if cursor is NULL */
143 if (cursor!=NULL)
144 {
145 PtSetArg(&args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0);
146 /* Could set next to any PgColor_t value */
147 PtSetArg(&args[1], Pt_ARG_CURSOR_COLOR, Ph_CURSOR_DEFAULT_COLOR , 0);
148 PtSetArg(&args[2], Pt_ARG_BITMAP_CURSOR, cursor->ph_cursor, (cursor->ph_cursor->hdr.len + sizeof(PhRegionDataHdr_t)));
149 nargs = 3;
150 }
151 else /* Ph_CURSOR_NONE */
152 {
153 PtSetArg(&args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0);
154 nargs = 1;
155 }
156
157 SDL_Lock_EventThread();
158
159 if (PtSetResources(window, nargs, args) < 0 )
160 {
161 return (0);
162 }
163
164 SDL_Unlock_EventThread();
165
166 return (1);
167}
168
169
170void ph_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
171{
172 short abs_x, abs_y;
173
174 SDL_Lock_EventThread();
175 PtGetAbsPosition( window, &abs_x, &abs_y );
176 PhMoveCursorAbs( PhInputGroup(NULL), x + abs_x, y + abs_y );
177 SDL_Unlock_EventThread();
178}
179
180
181void ph_CheckMouseMode(_THIS)
182{
183 /* If the mouse is hidden and input is grabbed, we use relative mode */
184 if ( !(SDL_cursorstate & CURSOR_VISIBLE) && (this->input_grab != SDL_GRAB_OFF))
185 {
186 mouse_relative = 1;
187 }
188 else
189 {
190 mouse_relative = 0;
191 }
192}
193
194
195void ph_UpdateMouse(_THIS)
196{
197 PhCursorInfo_t phcursor;
198 short abs_x;
199 short abs_y;
200
201 /* Lock the event thread, in multi-threading environments */
202 SDL_Lock_EventThread();
203
204 /* synchronizing photon mouse cursor position and SDL mouse position, if cursor appears over window. */
205 PtGetAbsPosition(window, &abs_x, &abs_y);
206 PhQueryCursor(PhInputGroup(NULL), &phcursor);
207 if (((phcursor.pos.x >= abs_x) && (phcursor.pos.x <= abs_x + this->screen->w)) &&
208 ((phcursor.pos.y >= abs_y) && (phcursor.pos.y <= abs_y + this->screen->h)))
209 {
210 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
211 SDL_PrivateMouseMotion(0, 0, phcursor.pos.x-abs_x, phcursor.pos.y-abs_y);
212 }
213 else
214 {
215 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
216 }
217
218 /* Unlock the event thread, in multi-threading environments */
219 SDL_Unlock_EventThread();
220}
diff --git a/apps/plugins/sdl/src/video/photon/SDL_ph_mouse_c.h b/apps/plugins/sdl/src/video/photon/SDL_ph_mouse_c.h
deleted file mode 100644
index 55a92b606b..0000000000
--- a/apps/plugins/sdl/src/video/photon/SDL_ph_mouse_c.h
+++ /dev/null
@@ -1,39 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#ifndef __SDL_PH_MOUSE_H__
25#define __SDL_PH_MOUSE_H__
26
27#include "SDL_ph_video.h"
28
29/* Functions to be exported */
30extern void ph_FreeWMCursor(_THIS, WMcursor *cursor);
31extern WMcursor *ph_CreateWMCursor(_THIS,
32 Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y);
33extern PhCursorDef_t ph_GetWMPhCursor(WMcursor *cursor);
34extern int ph_ShowWMCursor(_THIS, WMcursor *cursor);
35extern void ph_WarpWMCursor(_THIS, Uint16 x, Uint16 y);
36extern void ph_CheckMouseMode(_THIS);
37extern void ph_UpdateMouse(_THIS);
38
39#endif /* __SDL_PH_MOUSE_H__ */
diff --git a/apps/plugins/sdl/src/video/photon/SDL_ph_video.c b/apps/plugins/sdl/src/video/photon/SDL_ph_video.c
deleted file mode 100644
index 5e1a82b0ea..0000000000
--- a/apps/plugins/sdl/src/video/photon/SDL_ph_video.c
+++ /dev/null
@@ -1,648 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#include <unistd.h>
25#include <sys/ioctl.h>
26
27#include "SDL_endian.h"
28#include "SDL_timer.h"
29#include "SDL_thread.h"
30#include "SDL_video.h"
31#include "SDL_mouse.h"
32#include "../SDL_sysvideo.h"
33#include "../SDL_pixels_c.h"
34#include "../../events/SDL_events_c.h"
35#include "SDL_ph_video.h"
36#include "SDL_ph_modes_c.h"
37#include "SDL_ph_image_c.h"
38#include "SDL_ph_events_c.h"
39#include "SDL_ph_mouse_c.h"
40#include "SDL_ph_wm_c.h"
41#include "SDL_ph_gl.h"
42#include "SDL_phyuv_c.h"
43#include "../blank_cursor.h"
44
45static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat);
46static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
47static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
48static void ph_VideoQuit(_THIS);
49static void ph_DeleteDevice(SDL_VideoDevice *device);
50
51static int phstatus=-1;
52
53static int ph_Available(void)
54{
55 if (phstatus!=0)
56 {
57 phstatus=PtInit(NULL);
58 if (phstatus==0)
59 {
60 return 1;
61 }
62 else
63 {
64 return 0;
65 }
66 }
67 return 1;
68}
69
70static SDL_VideoDevice* ph_CreateDevice(int devindex)
71{
72 SDL_VideoDevice* device;
73
74 /* Initialize all variables that we clean on shutdown */
75 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
76 if (device)
77 {
78 SDL_memset(device, 0, (sizeof *device));
79 device->hidden = (struct SDL_PrivateVideoData*)SDL_malloc((sizeof *device->hidden));
80 device->gl_data = NULL;
81 }
82 if ((device == NULL) || (device->hidden == NULL))
83 {
84 SDL_OutOfMemory();
85 ph_DeleteDevice(device);
86 return NULL;
87 }
88 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
89
90 /* Set the driver flags */
91 device->handles_any_size = 1;
92
93 /* Set the function pointers */
94 device->CreateYUVOverlay = ph_CreateYUVOverlay;
95 device->VideoInit = ph_VideoInit;
96 device->ListModes = ph_ListModes;
97 device->SetVideoMode = ph_SetVideoMode;
98 device->ToggleFullScreen = ph_ToggleFullScreen;
99 device->UpdateMouse = ph_UpdateMouse;
100 device->SetColors = ph_SetColors;
101 device->UpdateRects = NULL; /* set up in ph_SetupUpdateFunction */
102 device->VideoQuit = ph_VideoQuit;
103 device->AllocHWSurface = ph_AllocHWSurface;
104 device->CheckHWBlit = ph_CheckHWBlit;
105 device->FillHWRect = ph_FillHWRect;
106 device->SetHWColorKey = ph_SetHWColorKey;
107 device->SetHWAlpha = ph_SetHWAlpha;
108 device->LockHWSurface = ph_LockHWSurface;
109 device->UnlockHWSurface = ph_UnlockHWSurface;
110 device->FlipHWSurface = ph_FlipHWSurface;
111 device->FreeHWSurface = ph_FreeHWSurface;
112 device->SetCaption = ph_SetCaption;
113 device->SetIcon = NULL;
114 device->IconifyWindow = ph_IconifyWindow;
115 device->GrabInput = ph_GrabInput;
116 device->GetWMInfo = ph_GetWMInfo;
117 device->FreeWMCursor = ph_FreeWMCursor;
118 device->CreateWMCursor = ph_CreateWMCursor;
119 device->ShowWMCursor = ph_ShowWMCursor;
120 device->WarpWMCursor = ph_WarpWMCursor;
121 device->MoveWMCursor = NULL;
122 device->CheckMouseMode = ph_CheckMouseMode;
123 device->InitOSKeymap = ph_InitOSKeymap;
124 device->PumpEvents = ph_PumpEvents;
125
126 /* OpenGL support. */
127#if SDL_VIDEO_OPENGL
128 device->GL_MakeCurrent = ph_GL_MakeCurrent;
129 device->GL_SwapBuffers = ph_GL_SwapBuffers;
130 device->GL_GetAttribute = ph_GL_GetAttribute;
131 device->GL_LoadLibrary = ph_GL_LoadLibrary;
132 device->GL_GetProcAddress = ph_GL_GetProcAddress;
133#endif /* SDL_VIDEO_OPENGL */
134
135 device->free = ph_DeleteDevice;
136
137 return device;
138}
139
140VideoBootStrap ph_bootstrap = {
141 "photon", "QNX Photon video output",
142 ph_Available, ph_CreateDevice
143};
144
145static void ph_DeleteDevice(SDL_VideoDevice *device)
146{
147 if (device)
148 {
149 if (device->hidden)
150 {
151 SDL_free(device->hidden);
152 device->hidden = NULL;
153 }
154 if (device->gl_data)
155 {
156 SDL_free(device->gl_data);
157 device->gl_data = NULL;
158 }
159 SDL_free(device);
160 device = NULL;
161 }
162}
163
164static PtWidget_t *ph_CreateWindow(_THIS)
165{
166 PtWidget_t *widget;
167
168 widget = PtCreateWidget(PtWindow, NULL, 0, NULL);
169
170 return widget;
171}
172
173static int ph_SetupWindow(_THIS, int w, int h, int flags)
174{
175 PtArg_t args[32];
176 PhPoint_t pos = {0, 0};
177 PhDim_t* olddim;
178 PhDim_t dim = {w, h};
179 PhRect_t desktopextent;
180 int nargs = 0;
181 const char* windowpos;
182 const char* iscentered;
183 int x, y;
184
185 /* check if window size has been changed by Window Manager */
186 PtGetResource(window, Pt_ARG_DIM, &olddim, 0);
187 if ((olddim->w!=w) || (olddim->h!=h))
188 {
189 PtSetArg(&args[nargs++], Pt_ARG_DIM, &dim, 0);
190 }
191
192 if ((flags & SDL_RESIZABLE) == SDL_RESIZABLE)
193 {
194 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_CLOSE);
195 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_MAX | Ph_WM_RESTORE | Ph_WM_RESIZE);
196 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_RESIZE | Ph_WM_MOVE | Ph_WM_CLOSE | Ph_WM_MAX | Ph_WM_RESTORE);
197 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX | Ph_WM_RENDER_COLLAPSE | Ph_WM_RENDER_RETURN);
198 PtSetArg(&args[nargs++], Pt_ARG_RESIZE_FLAGS, Pt_TRUE, Pt_RESIZE_XY_AS_REQUIRED);
199 }
200 else
201 {
202 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX | Ph_WM_RESTORE | Ph_WM_CLOSE);
203 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX | Ph_WM_RESTORE);
204 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_MOVE | Ph_WM_CLOSE);
205 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX | Ph_WM_RENDER_COLLAPSE | Ph_WM_RENDER_RETURN);
206 PtSetArg(&args[nargs++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, Pt_RESIZE_XY_AS_REQUIRED);
207 }
208
209 if (((flags & SDL_NOFRAME)==SDL_NOFRAME) || ((flags & SDL_FULLSCREEN)==SDL_FULLSCREEN))
210 {
211 if ((flags & SDL_RESIZABLE) != SDL_RESIZABLE)
212 {
213 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Pt_TRUE);
214 }
215 else
216 {
217 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Pt_TRUE);
218 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_BORDER);
219 }
220 }
221 else
222 {
223 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_BORDER | Ph_WM_RENDER_TITLE |
224 Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MIN);
225 }
226
227 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
228 {
229 PtSetArg(&args[nargs++], Pt_ARG_POS, &pos, 0);
230 PtSetArg(&args[nargs++], Pt_ARG_BASIC_FLAGS, Pt_TRUE, Pt_BASIC_PREVENT_FILL);
231 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_FFRONT | Ph_WM_MAX | Ph_WM_TOFRONT | Ph_WM_CONSWITCH);
232 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISFOCUS | Ph_WM_STATE_ISALTKEY);
233 }
234 else
235 {
236 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_FFRONT | Ph_WM_CONSWITCH);
237 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISFRONT);
238 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISALTKEY);
239
240 if ((flags & SDL_HWSURFACE) == SDL_HWSURFACE)
241 {
242 PtSetArg(&args[nargs++], Pt_ARG_BASIC_FLAGS, Pt_TRUE, Pt_BASIC_PREVENT_FILL);
243 }
244 else
245 {
246 PtSetArg(&args[nargs++], Pt_ARG_FILL_COLOR, Pg_BLACK, 0);
247 }
248 if (!currently_maximized)
249 {
250 windowpos = SDL_getenv("SDL_VIDEO_WINDOW_POS");
251 iscentered = SDL_getenv("SDL_VIDEO_CENTERED");
252
253 if ((iscentered) || ((windowpos) && (SDL_strcmp(windowpos, "center")==0)))
254 {
255 PhWindowQueryVisible(Ph_QUERY_CONSOLE, 0, 0, &desktopextent);
256 if (desktop_mode.width>w)
257 {
258 pos.x = (desktop_mode.width - w)/2;
259 }
260 if (desktop_mode.height>h)
261 {
262 pos.y = (desktop_mode.height - h)/2;
263 }
264
265 pos.x+=desktopextent.ul.x;
266 pos.y+=desktopextent.ul.y;
267 PtSetArg(&args[nargs++], Pt_ARG_POS, &pos, 0);
268 }
269 else
270 {
271 if (windowpos)
272 {
273 if (SDL_sscanf(windowpos, "%d,%d", &x, &y) == 2)
274 {
275 if ((x<desktop_mode.width) && (y<desktop_mode.height))
276 {
277 PhWindowQueryVisible(Ph_QUERY_CONSOLE, 0, 0, &desktopextent);
278 pos.x=x+desktopextent.ul.x;
279 pos.y=y+desktopextent.ul.y;
280 }
281 PtSetArg(&args[nargs++], Pt_ARG_POS, &pos, 0);
282 }
283 }
284 }
285 }
286
287 /* if window is maximized render it as maximized */
288 if (currently_maximized)
289 {
290 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISMAX);
291 }
292 else
293 {
294 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISMAX);
295 }
296
297 /* do not grab the keyboard by default */
298 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISALTKEY);
299
300 /* bring the focus to the window */
301 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFOCUS);
302
303 /* allow to catch hide event */
304 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_HIDE);
305 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_HIDE);
306 }
307
308 PtSetResources(window, nargs, args);
309 PtRealizeWidget(window);
310 PtWindowToFront(window);
311
312#if 0 /* FIXME */
313 PtGetResource(window, Pt_ARG_POS, &olddim, 0);
314 fprintf(stderr, "POSITION: %d, %d\n", olddim->w, olddim->h);
315#endif
316
317 return 0;
318}
319
320static const struct ColourMasks* ph_GetColourMasks(int bpp)
321{
322 /* The alpha mask doesn't appears to be needed */
323 static const struct ColourMasks phColorMasks[5] = {
324 /* 8 bit */ {0, 0, 0, 0, 8},
325 /* 15 bit ARGB */ {0x7C00, 0x03E0, 0x001F, 0x8000, 15},
326 /* 16 bit RGB */ {0xF800, 0x07E0, 0x001F, 0x0000, 16},
327 /* 24 bit RGB */ {0xFF0000, 0x00FF00, 0x0000FF, 0x000000, 24},
328 /* 32 bit ARGB */ {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000, 32},
329 };
330
331 switch (bpp)
332 {
333 case 8:
334 return &phColorMasks[0];
335 case 15:
336 return &phColorMasks[1];
337 case 16:
338 return &phColorMasks[2];
339 case 24:
340 return &phColorMasks[3];
341 case 32:
342 return &phColorMasks[4];
343 }
344 return NULL;
345}
346
347static int ph_VideoInit(_THIS, SDL_PixelFormat* vformat)
348{
349 PgHWCaps_t hwcaps;
350 int i;
351
352 window=NULL;
353 desktoppal=SDLPH_PAL_NONE;
354
355#if SDL_VIDEO_OPENGL
356 oglctx=NULL;
357 oglbuffers=NULL;
358 oglflags=0;
359 oglbpp=0;
360#endif
361
362 old_video_mode=-1;
363 old_refresh_rate=-1;
364
365 if (NULL == (phevent = SDL_malloc(EVENT_SIZE)))
366 {
367 SDL_OutOfMemory();
368 return -1;
369 }
370 SDL_memset(phevent, 0x00, EVENT_SIZE);
371
372 window = ph_CreateWindow(this);
373 if (window == NULL)
374 {
375 SDL_SetError("ph_VideoInit(): Couldn't create video window !\n");
376 return -1;
377 }
378
379 /* Create the blank cursor */
380 SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask,
381 (int)BLANK_CWIDTH, (int)BLANK_CHEIGHT,
382 (int)BLANK_CHOTX, (int)BLANK_CHOTY);
383
384 if (SDL_BlankCursor == NULL)
385 {
386 return -1;
387 }
388
389 if (PgGetGraphicsHWCaps(&hwcaps) < 0)
390 {
391 SDL_SetError("ph_VideoInit(): GetGraphicsHWCaps function failed !\n");
392 this->FreeWMCursor(this, SDL_BlankCursor);
393 return -1;
394 }
395
396 if (PgGetVideoModeInfo(hwcaps.current_video_mode, &desktop_mode) < 0)
397 {
398 SDL_SetError("ph_VideoInit(): PgGetVideoModeInfo function failed !\n");
399 this->FreeWMCursor(this, SDL_BlankCursor);
400 return -1;
401 }
402
403 /* Determine the current screen size */
404 this->info.current_w = desktop_mode.width;
405 this->info.current_h = desktop_mode.height;
406
407 /* We need to return BytesPerPixel as it in used by CreateRGBsurface */
408 vformat->BitsPerPixel = desktop_mode.bits_per_pixel;
409 vformat->BytesPerPixel = desktop_mode.bytes_per_scanline/desktop_mode.width;
410 desktopbpp = desktop_mode.bits_per_pixel;
411
412 /* save current palette */
413 if (desktopbpp==8)
414 {
415 PgGetPalette(savedpal);
416 PgGetPalette(syspalph);
417 }
418 else
419 {
420 for(i=0; i<_Pg_MAX_PALETTE; i++)
421 {
422 savedpal[i]=PgRGB(0, 0, 0);
423 syspalph[i]=PgRGB(0, 0, 0);
424 }
425 }
426
427 currently_fullscreen = 0;
428 currently_hided = 0;
429 currently_maximized = 0;
430 current_overlay = NULL;
431
432 OCImage.direct_context = NULL;
433 OCImage.offscreen_context = NULL;
434 OCImage.offscreen_backcontext = NULL;
435 OCImage.oldDC = NULL;
436 OCImage.CurrentFrameData = NULL;
437 OCImage.FrameData0 = NULL;
438 OCImage.FrameData1 = NULL;
439 videomode_emulatemode = 0;
440
441 this->info.wm_available = 1;
442
443 ph_UpdateHWInfo(this);
444
445 return 0;
446}
447
448static SDL_Surface* ph_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags)
449{
450 const struct ColourMasks* mask;
451
452 /* Lock the event thread, in multi-threading environments */
453 SDL_Lock_EventThread();
454
455 current->flags = flags;
456
457 /* if we do not have desired fullscreen mode, then fallback into window mode */
458 if (((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) && (ph_GetVideoMode(width, height, bpp)==0))
459 {
460 current->flags &= ~SDL_FULLSCREEN;
461 current->flags &= ~SDL_NOFRAME;
462 current->flags &= ~SDL_RESIZABLE;
463 }
464
465 ph_SetupWindow(this, width, height, current->flags);
466
467 mask = ph_GetColourMasks(bpp);
468 if (mask != NULL)
469 {
470 SDL_ReallocFormat(current, mask->bpp, mask->red, mask->green, mask->blue, 0);
471 }
472 else
473 {
474 SDL_SetError("ph_SetVideoMode(): desired bpp is not supported by photon !\n");
475 return NULL;
476 }
477
478 if ((current->flags & SDL_OPENGL)==SDL_OPENGL)
479 {
480#if !SDL_VIDEO_OPENGL
481 /* if no built-in OpenGL support */
482 SDL_SetError("ph_SetVideoMode(): no OpenGL support, you need to recompile SDL.\n");
483 current->flags &= ~SDL_OPENGL;
484 return NULL;
485#endif /* SDL_VIDEO_OPENGL */
486 }
487 else
488 {
489 /* Initialize internal variables */
490 if ((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
491 {
492 if (bpp==8)
493 {
494 desktoppal=SDLPH_PAL_SYSTEM;
495 }
496
497 current->flags &= ~SDL_RESIZABLE; /* no resize for Direct Context */
498 current->flags |= SDL_HWSURFACE;
499 }
500 else
501 {
502 /* remove this if we'll have support for the non-fullscreen sw/hw+doublebuf one day */
503 current->flags &= ~SDL_DOUBLEBUF;
504
505 /* Use offscreen memory if SDL_HWSURFACE flag is set */
506 if ((current->flags & SDL_HWSURFACE) == SDL_HWSURFACE)
507 {
508 if (desktopbpp!=bpp)
509 {
510 current->flags &= ~SDL_HWSURFACE;
511 }
512 }
513
514 /* using palette emulation code in window mode */
515 if (bpp==8)
516 {
517 if (desktopbpp>=15)
518 {
519 desktoppal = SDLPH_PAL_EMULATE;
520 }
521 else
522 {
523 desktoppal = SDLPH_PAL_SYSTEM;
524 }
525 }
526 else
527 {
528 desktoppal = SDLPH_PAL_NONE;
529 }
530 }
531 }
532
533 current->w = width;
534 current->h = height;
535
536 if (desktoppal==SDLPH_PAL_SYSTEM)
537 {
538 current->flags|=SDL_HWPALETTE;
539 }
540
541 /* Must call at least once for setup image planes */
542 if (ph_SetupUpdateFunction(this, current, current->flags)==-1)
543 {
544 /* Error string was filled in the ph_SetupUpdateFunction() */
545 return NULL;
546 }
547
548 /* finish window drawing, if we are not in fullscreen, of course */
549 if ((current->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN)
550 {
551 PtFlush();
552 }
553 else
554 {
555 PgFlush();
556 }
557
558 visualbpp=bpp;
559
560 ph_UpdateHWInfo(this);
561
562 SDL_Unlock_EventThread();
563
564 /* We've done! */
565 return (current);
566}
567
568static void ph_VideoQuit(_THIS)
569{
570 /* restore palette */
571 if (desktopbpp==8)
572 {
573 PgSetPalette(syspalph, 0, -1, 0, 0, 0);
574 PgSetPalette(savedpal, 0, 0, _Pg_MAX_PALETTE, Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0);
575 PgFlush();
576 }
577
578 ph_DestroyImage(this, SDL_VideoSurface);
579
580 if (window)
581 {
582 PtUnrealizeWidget(window);
583 PtDestroyWidget(window);
584 window=NULL;
585 }
586
587 if (phevent!=NULL)
588 {
589 SDL_free(phevent);
590 phevent=NULL;
591 }
592}
593
594static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
595{
596 int i;
597 SDL_Rect updaterect;
598
599 updaterect.x = updaterect.y = 0;
600 updaterect.w = this->screen->w;
601 updaterect.h = this->screen->h;
602
603 /* palette emulation code, using palette of the PhImage_t struct */
604 if (desktoppal==SDLPH_PAL_EMULATE)
605 {
606 if ((SDL_Image) && (SDL_Image->palette))
607 {
608 for (i=firstcolor; i<firstcolor+ncolors; i++)
609 {
610 syspalph[i] = PgRGB(colors[i-firstcolor].r, colors[i-firstcolor].g, colors[i-firstcolor].b);
611 SDL_Image->palette[i] = syspalph[i];
612 }
613
614 /* image needs to be redrawn */
615 this->UpdateRects(this, 1, &updaterect);
616 }
617 }
618 else
619 {
620 if (desktoppal==SDLPH_PAL_SYSTEM)
621 {
622 for (i=firstcolor; i<firstcolor+ncolors; i++)
623 {
624 syspalph[i] = PgRGB(colors[i-firstcolor].r, colors[i-firstcolor].g, colors[i-firstcolor].b);
625 }
626
627 if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN)
628 {
629 /* window mode must use soft palette */
630 PgSetPalette(&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0);
631 /* image needs to be redrawn */
632 this->UpdateRects(this, 1, &updaterect);
633 }
634 else
635 {
636 /* fullscreen mode must use hardware palette */
637 PgSetPalette(&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0);
638 }
639 }
640 else
641 {
642 /* SDLPH_PAL_NONE do nothing */
643 }
644 }
645
646 return 1;
647}
648
diff --git a/apps/plugins/sdl/src/video/photon/SDL_ph_video.h b/apps/plugins/sdl/src/video/photon/SDL_ph_video.h
deleted file mode 100644
index 3995d3505e..0000000000
--- a/apps/plugins/sdl/src/video/photon/SDL_ph_video.h
+++ /dev/null
@@ -1,157 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#ifndef __SDL_PH_VIDEO_H__
25#define __SDL_PH_VIDEO_H__
26
27#include "SDL_mouse.h"
28#include "../SDL_sysvideo.h"
29
30#include <sys/neutrino.h>
31
32#include <Ph.h>
33#include <Pt.h>
34#include <photon/Pg.h>
35#include <photon/PdDirect.h>
36
37#if SDL_VIDEO_OPENGL
38 #if (_NTO_VERSION < 630)
39 #include <photon/PdGL.h>
40 #else
41 #include <GL/qnxgl.h>
42 #include <GL/GLPh.h>
43 #endif /* 6.3.0 */
44#endif /* SDL_VIDEO_OPENGL */
45
46/* Hidden "this" pointer for the video functions */
47#define _THIS SDL_VideoDevice* this
48
49#define PH_OGL_MAX_ATTRIBS 32
50
51#define SDLPH_PAL_NONE 0x00000000L
52#define SDLPH_PAL_EMULATE 0x00000001L
53#define SDLPH_PAL_SYSTEM 0x00000002L
54
55typedef struct
56{
57 unsigned char* Y;
58 unsigned char* V;
59 unsigned char* U;
60} FRAMEDATA;
61
62/* Mask values for SDL_ReallocFormat() */
63struct ColourMasks
64{
65 Uint32 red;
66 Uint32 green;
67 Uint32 blue;
68 Uint32 alpha;
69 Uint32 bpp;
70};
71
72/* Private display data */
73struct SDL_PrivateVideoData
74{
75 PgDisplaySettings_t mode_settings;
76 PtWidget_t *Window; /* used to handle input events */
77 PhImage_t *image; /* used to display image */
78#if SDL_VIDEO_OPENGL
79 #if (_NTO_VERSION < 630)
80 PdOpenGLContext_t* OGLContext; /* OpenGL context */
81 void* OGLBuffers; /* OpenGL buffers (unused) */
82 #else
83 qnxglc_t* OGLContext; /* OpenGL context for the 6.3 */
84 qnxgl_bufs_t* OGLBuffers; /* OpenGL buffers for the 6.3 */
85 #endif /* 630 */
86
87 Uint32 OGLFlags; /* OpenGL flags */
88 Uint32 OGLBPP; /* OpenGL bpp */
89#endif /* SDL_VIDEO_OPENGL */
90 PgColor_t savedpal[_Pg_MAX_PALETTE];
91 PgColor_t syspalph[_Pg_MAX_PALETTE];
92
93 struct
94 {
95 PdDirectContext_t* direct_context;
96 PdOffscreenContext_t* offscreen_context;
97 PdOffscreenContext_t* offscreen_backcontext;
98 PhDrawContext_t* oldDC;
99 uint8_t* dc_ptr;
100 unsigned char* CurrentFrameData;
101 unsigned char* FrameData0;
102 unsigned char* FrameData1;
103 Uint32 current;
104 Uint32 flags;
105 } ocimage;
106
107 PgHWCaps_t graphics_card_caps; /* Graphics card caps at the moment of start */
108 PgVideoModeInfo_t desktop_mode; /* Current desktop video mode information */
109 int old_video_mode; /* Stored mode before fullscreen switch */
110 int old_refresh_rate; /* Stored refresh rate befor fullscreen switch */
111
112 int mouse_relative;
113 WMcursor* BlankCursor;
114 uint32_t videomode_emulatemode;
115
116 Uint32 visualbpp; /* current visual bpp */
117 Uint32 desktopbpp; /* bpp of desktop at the moment of start */
118 Uint32 desktoppal; /* palette mode emulation or system */
119
120 int currently_fullscreen;
121 int currently_hided; /* 1 - window hided (minimazed), 0 - normal */
122 int currently_maximized; /* 1 - window hided (minimazed), 0 - normal */
123
124 PhEvent_t* event;
125 SDL_Overlay* overlay;
126};
127
128#define mode_settings (this->hidden->mode_settings)
129#define window (this->hidden->Window)
130#define SDL_Image (this->hidden->image)
131#define OCImage (this->hidden->ocimage)
132#define old_video_mode (this->hidden->old_video_mode)
133#define old_refresh_rate (this->hidden->old_refresh_rate)
134#define graphics_card_caps (this->hidden->graphics_card_caps)
135#define desktopbpp (this->hidden->desktopbpp)
136#define visualbpp (this->hidden->visualbpp)
137#define desktoppal (this->hidden->desktoppal)
138#define savedpal (this->hidden->savedpal)
139#define syspalph (this->hidden->syspalph)
140#define currently_fullscreen (this->hidden->currently_fullscreen)
141#define currently_hided (this->hidden->currently_hided)
142#define currently_maximized (this->hidden->currently_maximized)
143#define phevent (this->hidden->event)
144#define current_overlay (this->hidden->overlay)
145#define desktop_mode (this->hidden->desktop_mode)
146#define mouse_relative (this->hidden->mouse_relative)
147#define SDL_BlankCursor (this->hidden->BlankCursor)
148#define videomode_emulatemode (this->hidden->videomode_emulatemode)
149
150#if SDL_VIDEO_OPENGL
151 #define oglctx (this->hidden->OGLContext)
152 #define oglbuffers (this->hidden->OGLBuffers)
153 #define oglflags (this->hidden->OGLFlags)
154 #define oglbpp (this->hidden->OGLBPP)
155#endif /* SDL_VIDEO_OPENGL */
156
157#endif /* __SDL_PH_VIDEO_H__ */
diff --git a/apps/plugins/sdl/src/video/photon/SDL_ph_wm.c b/apps/plugins/sdl/src/video/photon/SDL_ph_wm.c
deleted file mode 100644
index 8e75d0b577..0000000000
--- a/apps/plugins/sdl/src/video/photon/SDL_ph_wm.c
+++ /dev/null
@@ -1,118 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#include <Ph.h>
25#include <photon/PpProto.h>
26#include <photon/PhWm.h>
27#include <photon/wmapi.h>
28
29#include "SDL_version.h"
30#include "SDL_timer.h"
31#include "SDL_video.h"
32#include "SDL_syswm.h"
33#include "../SDL_pixels_c.h"
34#include "../../events/SDL_events_c.h"
35#include "SDL_ph_modes_c.h"
36#include "SDL_ph_wm_c.h"
37
38void ph_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask)
39{
40 return;
41}
42
43/* Set window caption */
44void ph_SetCaption(_THIS, const char *title, const char *icon)
45{
46 SDL_Lock_EventThread();
47
48 /* sanity check for set caption call before window init */
49 if (window!=NULL)
50 {
51 PtSetResource(window, Pt_ARG_WINDOW_TITLE, title, 0);
52 }
53
54 SDL_Unlock_EventThread();
55}
56
57/* Iconify current window */
58int ph_IconifyWindow(_THIS)
59{
60 PhWindowEvent_t windowevent;
61
62 SDL_Lock_EventThread();
63
64 SDL_memset(&windowevent, 0, sizeof(windowevent));
65 windowevent.event_f = Ph_WM_HIDE;
66 windowevent.event_state = Ph_WM_EVSTATE_HIDE;
67 windowevent.rid = PtWidgetRid(window);
68 PtForwardWindowEvent(&windowevent);
69
70 SDL_Unlock_EventThread();
71
72 return 0;
73}
74
75SDL_GrabMode ph_GrabInputNoLock(_THIS, SDL_GrabMode mode)
76{
77 short abs_x, abs_y;
78
79 if( mode == SDL_GRAB_OFF )
80 {
81 PtSetResource(window, Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISALTKEY);
82 }
83 else
84 {
85 PtSetResource(window, Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISALTKEY);
86
87 PtGetAbsPosition(window, &abs_x, &abs_y);
88 PhMoveCursorAbs(PhInputGroup(NULL), abs_x + SDL_VideoSurface->w/2, abs_y + SDL_VideoSurface->h/2);
89 }
90
91 SDL_Unlock_EventThread();
92
93 return(mode);
94}
95
96SDL_GrabMode ph_GrabInput(_THIS, SDL_GrabMode mode)
97{
98 SDL_Lock_EventThread();
99 mode = ph_GrabInputNoLock(this, mode);
100 SDL_Unlock_EventThread();
101
102 return(mode);
103}
104
105
106int ph_GetWMInfo(_THIS, SDL_SysWMinfo *info)
107{
108 if (info->version.major <= SDL_MAJOR_VERSION)
109 {
110 return 1;
111 }
112 else
113 {
114 SDL_SetError("Application not compiled with SDL %d.%d\n",
115 SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
116 return -1;
117 }
118}
diff --git a/apps/plugins/sdl/src/video/photon/SDL_ph_wm_c.h b/apps/plugins/sdl/src/video/photon/SDL_ph_wm_c.h
deleted file mode 100644
index 72bbfd217d..0000000000
--- a/apps/plugins/sdl/src/video/photon/SDL_ph_wm_c.h
+++ /dev/null
@@ -1,37 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#ifndef __SDL_PH_WM_H__
25#define __SDL_PH_WM_H__
26
27#include "SDL_ph_video.h"
28
29/* Functions to be exported */
30extern void ph_SetCaption(_THIS, const char *title, const char *icon);
31extern void ph_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask);
32extern int ph_IconifyWindow(_THIS);
33extern SDL_GrabMode ph_GrabInputNoLock(_THIS, SDL_GrabMode mode);
34extern SDL_GrabMode ph_GrabInput(_THIS, SDL_GrabMode mode);
35extern int ph_GetWMInfo(_THIS, SDL_SysWMinfo *info);
36
37#endif /* __SDL_PH_WM_H__ */
diff --git a/apps/plugins/sdl/src/video/photon/SDL_phyuv.c b/apps/plugins/sdl/src/video/photon/SDL_phyuv.c
deleted file mode 100644
index 06c72fded4..0000000000
--- a/apps/plugins/sdl/src/video/photon/SDL_phyuv.c
+++ /dev/null
@@ -1,504 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24/* This is the QNX Realtime Platform version of SDL YUV video overlays */
25
26#include <errno.h>
27
28#include <Ph.h>
29#include <Pt.h>
30
31#include "SDL_video.h"
32#include "SDL_phyuv_c.h"
33#include "../SDL_yuvfuncs.h"
34
35#define OVERLAY_STATE_UNINIT 0
36#define OVERLAY_STATE_ACTIVE 1
37
38/* The functions are used to manipulate software video overlays */
39static struct private_yuvhwfuncs ph_yuvfuncs =
40{
41 ph_LockYUVOverlay,
42 ph_UnlockYUVOverlay,
43 ph_DisplayYUVOverlay,
44 ph_FreeYUVOverlay
45};
46
47int grab_ptrs2(PgVideoChannel_t* channel, FRAMEDATA* Frame0, FRAMEDATA* Frame1)
48{
49 int planes = 0;
50
51 /* Buffers have moved; re-obtain the pointers */
52 Frame0->Y = (unsigned char *)PdGetOffscreenContextPtr(channel->yplane1);
53 Frame1->Y = (unsigned char *)PdGetOffscreenContextPtr(channel->yplane2);
54 Frame0->U = (unsigned char *)PdGetOffscreenContextPtr(channel->vplane1);
55 Frame1->U = (unsigned char *)PdGetOffscreenContextPtr(channel->vplane2);
56 Frame0->V = (unsigned char *)PdGetOffscreenContextPtr(channel->uplane1);
57 Frame1->V = (unsigned char *)PdGetOffscreenContextPtr(channel->uplane2);
58
59 if (Frame0->Y)
60 planes++;
61
62 if (Frame0->U)
63 planes++;
64
65 if (Frame0->V)
66 planes++;
67
68 return planes;
69}
70
71SDL_Overlay* ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface* display)
72{
73 SDL_Overlay* overlay;
74 struct private_yuvhwdata* hwdata;
75 int vidport;
76 int rtncode;
77 int planes;
78 int i=0;
79 PhPoint_t pos;
80
81 /* Create the overlay structure */
82 overlay = SDL_calloc(1, sizeof(SDL_Overlay));
83
84 if (overlay == NULL)
85 {
86 SDL_OutOfMemory();
87 return NULL;
88 }
89
90 /* Fill in the basic members */
91 overlay->format = format;
92 overlay->w = width;
93 overlay->h = height;
94 overlay->hwdata = NULL;
95
96 /* Set up the YUV surface function structure */
97 overlay->hwfuncs = &ph_yuvfuncs;
98
99 /* Create the pixel data and lookup tables */
100 hwdata = SDL_calloc(1, sizeof(struct private_yuvhwdata));
101
102 if (hwdata == NULL)
103 {
104 SDL_OutOfMemory();
105 SDL_FreeYUVOverlay(overlay);
106 return NULL;
107 }
108
109 overlay->hwdata = hwdata;
110
111 PhDCSetCurrent(0);
112 if (overlay->hwdata->channel == NULL)
113 {
114 if ((overlay->hwdata->channel = PgCreateVideoChannel(Pg_VIDEO_CHANNEL_SCALER, 0)) == NULL)
115 {
116 SDL_SetError("ph_CreateYUVOverlay(): Create channel failed: %s\n", strerror(errno));
117 SDL_FreeYUVOverlay(overlay);
118 return NULL;
119
120 }
121 }
122
123 overlay->hwdata->forcedredraw=0;
124
125 PtGetAbsPosition(window, &pos.x, &pos.y);
126 overlay->hwdata->CurrentWindowPos.x = pos.x;
127 overlay->hwdata->CurrentWindowPos.y = pos.y;
128 overlay->hwdata->CurrentViewPort.pos.x = 0;
129 overlay->hwdata->CurrentViewPort.pos.y = 0;
130 overlay->hwdata->CurrentViewPort.size.w = width;
131 overlay->hwdata->CurrentViewPort.size.h = height;
132 overlay->hwdata->State = OVERLAY_STATE_UNINIT;
133 overlay->hwdata->FrameData0 = (FRAMEDATA *) SDL_calloc(1, sizeof(FRAMEDATA));
134 overlay->hwdata->FrameData1 = (FRAMEDATA *) SDL_calloc(1, sizeof(FRAMEDATA));
135
136 vidport = -1;
137 i=0;
138
139 overlay->hwdata->ischromakey=0;
140
141 do {
142 SDL_memset(&overlay->hwdata->caps, 0x00, sizeof(PgScalerCaps_t));
143 overlay->hwdata->caps.size = sizeof(PgScalerCaps_t);
144 rtncode = PgGetScalerCapabilities(overlay->hwdata->channel, i, &overlay->hwdata->caps);
145 if (rtncode==0)
146 {
147 if (overlay->hwdata->caps.format==format)
148 {
149 if ((overlay->hwdata->caps.flags & Pg_SCALER_CAP_DST_CHROMA_KEY) == Pg_SCALER_CAP_DST_CHROMA_KEY)
150 {
151 overlay->hwdata->ischromakey=1;
152 }
153 vidport=1;
154 break;
155 }
156 }
157 else
158 {
159 break;
160 }
161 i++;
162 } while(1);
163
164
165 if (vidport == -1)
166 {
167 SDL_SetError("No available video ports for requested format\n");
168 SDL_FreeYUVOverlay(overlay);
169 return NULL;
170 }
171
172 overlay->hwdata->format = format;
173 overlay->hwdata->props.format = format;
174 overlay->hwdata->props.size = sizeof(PgScalerProps_t);
175 overlay->hwdata->props.src_dim.w = width;
176 overlay->hwdata->props.src_dim.h = height;
177
178 /* overlay->hwdata->chromakey = PgGetOverlayChromaColor(); */
179 overlay->hwdata->chromakey = PgRGB(12, 6, 12); /* very dark pink color */
180 overlay->hwdata->props.color_key = overlay->hwdata->chromakey;
181
182 PhAreaToRect(&overlay->hwdata->CurrentViewPort, &overlay->hwdata->props.viewport);
183
184 overlay->hwdata->props.flags = Pg_SCALER_PROP_DOUBLE_BUFFER;
185
186 if ((overlay->hwdata->ischromakey)&&(overlay->hwdata->chromakey))
187 {
188 overlay->hwdata->props.flags |= Pg_SCALER_PROP_CHROMA_ENABLE;
189 overlay->hwdata->props.flags |= Pg_SCALER_PROP_CHROMA_SPECIFY_KEY_MASK;
190 }
191 else
192 {
193 overlay->hwdata->props.flags &= ~Pg_SCALER_PROP_CHROMA_ENABLE;
194 }
195
196 rtncode = PgConfigScalerChannel(overlay->hwdata->channel, &overlay->hwdata->props);
197
198 switch(rtncode)
199 {
200 case -1: SDL_SetError("PgConfigScalerChannel failed\n");
201 SDL_FreeYUVOverlay(overlay);
202 return NULL;
203 case 1:
204 case 0:
205 default:
206 break;
207 }
208
209 planes = grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
210
211 if(overlay->hwdata->channel->yplane1 != NULL)
212 overlay->hwdata->YStride = overlay->hwdata->channel->yplane1->pitch;
213 if(overlay->hwdata->channel->vplane1 != NULL)
214 overlay->hwdata->UStride = overlay->hwdata->channel->vplane1->pitch;
215 if(overlay->hwdata->channel->uplane1 != NULL)
216 overlay->hwdata->VStride = overlay->hwdata->channel->uplane1->pitch;
217
218 /* check for the validness of all planes */
219 if ((overlay->hwdata->channel->yplane1 == NULL) &&
220 (overlay->hwdata->channel->uplane1 == NULL) &&
221 (overlay->hwdata->channel->vplane1 == NULL))
222 {
223 SDL_FreeYUVOverlay(overlay);
224 SDL_SetError("PgConfigScaler() returns all planes equal NULL\n");
225 return NULL;
226 }
227/*
228 overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
229
230 if (overlay->hwdata->current==0)
231 {
232 overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
233 }
234 else
235 {
236 overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
237 }
238*/
239 overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
240
241/*
242 overlay->hwdata->locked = 1;
243*/
244
245 /* Find the pitch and offset values for the overlay */
246 overlay->planes = planes;
247 overlay->pitches = SDL_calloc(overlay->planes, sizeof(Uint16));
248 overlay->pixels = SDL_calloc(overlay->planes, sizeof(Uint8*));
249 if (!overlay->pitches || !overlay->pixels)
250 {
251 SDL_OutOfMemory();
252 SDL_FreeYUVOverlay(overlay);
253 return(NULL);
254 }
255
256 if (overlay->planes > 0)
257 {
258 overlay->pitches[0] = overlay->hwdata->channel->yplane1->pitch;
259 overlay->pixels[0] = overlay->hwdata->CurrentFrameData->Y;
260 }
261 if (overlay->planes > 1)
262 {
263 overlay->pitches[1] = overlay->hwdata->channel->vplane1->pitch;
264 overlay->pixels[1] = overlay->hwdata->CurrentFrameData->U;
265 }
266 if (overlay->planes > 2)
267 {
268 overlay->pitches[2] = overlay->hwdata->channel->uplane1->pitch;
269 overlay->pixels[2] = overlay->hwdata->CurrentFrameData->V;
270 }
271
272 overlay->hwdata->State = OVERLAY_STATE_ACTIVE;
273 overlay->hwdata->scaler_on = 0;
274 overlay->hw_overlay = 1;
275
276 current_overlay=overlay;
277
278 return overlay;
279}
280
281int ph_LockYUVOverlay(_THIS, SDL_Overlay* overlay)
282{
283 if (overlay == NULL)
284 {
285 return -1;
286 }
287
288 overlay->hwdata->locked = 1;
289
290/* overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
291 if (overlay->hwdata->current == -1)
292 {
293 SDL_SetError("ph_LockYUVOverlay: PgNextFrame() failed, bailing out\n");
294 SDL_FreeYUVOverlay(overlay);
295 return 0;
296 }
297
298 if (overlay->hwdata->current == 0)
299 {
300 overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
301 }
302 else
303 {
304 overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
305 }
306
307 if (overlay->planes > 0)
308 {
309 overlay->pitches[0] = overlay->hwdata->channel->yplane1->pitch;
310 overlay->pixels[0] = overlay->hwdata->CurrentFrameData->Y;
311 }
312 if (overlay->planes > 1)
313 {
314 overlay->pitches[1] = overlay->hwdata->channel->uplane1->pitch;
315 overlay->pixels[1] = overlay->hwdata->CurrentFrameData->U;
316 }
317 if (overlay->planes > 2)
318 {
319 overlay->pitches[2] = overlay->hwdata->channel->vplane1->pitch;
320 overlay->pixels[2] = overlay->hwdata->CurrentFrameData->V;
321 }
322*/
323
324 return(0);
325}
326
327void ph_UnlockYUVOverlay(_THIS, SDL_Overlay* overlay)
328{
329 if (overlay == NULL)
330 {
331 return;
332 }
333
334 overlay->hwdata->locked = 0;
335}
336
337int ph_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* src, SDL_Rect* dst)
338{
339 int rtncode;
340 PhPoint_t pos;
341 SDL_Rect backrect;
342 PhRect_t windowextent;
343 int winchanged=0;
344
345 if ((overlay == NULL) || (overlay->hwdata==NULL))
346 {
347 return -1;
348 }
349
350 if (overlay->hwdata->State == OVERLAY_STATE_UNINIT)
351 {
352 return -1;
353 }
354
355 PtGetAbsPosition(window, &pos.x, &pos.y);
356 if ((pos.x!=overlay->hwdata->CurrentWindowPos.x) ||
357 (pos.y!=overlay->hwdata->CurrentWindowPos.y))
358 {
359 winchanged=1;
360 overlay->hwdata->CurrentWindowPos.x=pos.x;
361 overlay->hwdata->CurrentWindowPos.y=pos.y;
362 }
363
364 /* If CurrentViewPort position/size has been changed, then move/resize the viewport */
365 if ((overlay->hwdata->CurrentViewPort.pos.x != dst->x) ||
366 (overlay->hwdata->CurrentViewPort.pos.y != dst->y) ||
367 (overlay->hwdata->CurrentViewPort.size.w != dst->w) ||
368 (overlay->hwdata->CurrentViewPort.size.h != dst->h) ||
369 (overlay->hwdata->scaler_on==0) || (winchanged==1) ||
370 (overlay->hwdata->forcedredraw==1))
371 {
372
373 if (overlay->hwdata->ischromakey==1)
374 {
375 /* restore screen behind the overlay/chroma color. */
376 backrect.x=overlay->hwdata->CurrentViewPort.pos.x;
377 backrect.y=overlay->hwdata->CurrentViewPort.pos.y;
378 backrect.w=overlay->hwdata->CurrentViewPort.size.w;
379 backrect.h=overlay->hwdata->CurrentViewPort.size.h;
380 this->UpdateRects(this, 1, &backrect);
381
382 /* Draw the new rectangle of the chroma color at the viewport position */
383 PgSetFillColor(overlay->hwdata->chromakey);
384 PgDrawIRect(dst->x, dst->y, dst->x+dst->w-1, dst->y+dst->h-1, Pg_DRAW_FILL);
385 PgFlush();
386 }
387
388 overlay->hwdata->props.flags |= Pg_SCALER_PROP_SCALER_ENABLE;
389 overlay->hwdata->scaler_on = 1;
390
391 PhWindowQueryVisible(Ph_QUERY_CONSOLE, 0, PtWidgetRid(window), &windowextent);
392 overlay->hwdata->CurrentViewPort.pos.x = pos.x-windowextent.ul.x+dst->x;
393 overlay->hwdata->CurrentViewPort.pos.y = pos.y-windowextent.ul.y+dst->y;
394 overlay->hwdata->CurrentViewPort.size.w = dst->w;
395 overlay->hwdata->CurrentViewPort.size.h = dst->h;
396 PhAreaToRect(&overlay->hwdata->CurrentViewPort, &overlay->hwdata->props.viewport);
397 overlay->hwdata->CurrentViewPort.pos.x = dst->x;
398 overlay->hwdata->CurrentViewPort.pos.y = dst->y;
399
400 rtncode = PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
401
402 switch(rtncode)
403 {
404 case -1:
405 SDL_SetError("PgConfigScalerChannel() function failed\n");
406 SDL_FreeYUVOverlay(overlay);
407 return -1;
408 case 1:
409 grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
410 break;
411 case 0:
412 default:
413 break;
414 }
415 }
416
417
418/*
419 if (overlay->hwdata->locked==0)
420 {
421 overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
422 if (overlay->hwdata->current == -1)
423 {
424 SDL_SetError("ph_LockYUVOverlay: PgNextFrame() failed, bailing out\n");
425 SDL_FreeYUVOverlay(overlay);
426 return 0;
427 }
428
429 if (overlay->hwdata->current == 0)
430 {
431 overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
432 }
433 else
434 {
435 overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
436 }
437
438 if (overlay->planes > 0)
439 {
440 overlay->pitches[0] = overlay->hwdata->channel->yplane1->pitch;
441 overlay->pixels[0] = overlay->hwdata->CurrentFrameData->Y;
442 }
443 if (overlay->planes > 1)
444 {
445 overlay->pitches[1] = overlay->hwdata->channel->uplane1->pitch;
446 overlay->pixels[1] = overlay->hwdata->CurrentFrameData->U;
447 }
448 if (overlay->planes > 2)
449 {
450 overlay->pitches[2] = overlay->hwdata->channel->vplane1->pitch;
451 overlay->pixels[2] = overlay->hwdata->CurrentFrameData->V;
452 }
453 }
454*/
455
456 return 0;
457}
458
459void ph_FreeYUVOverlay(_THIS, SDL_Overlay *overlay)
460{
461 SDL_Rect backrect;
462
463 if (overlay == NULL)
464 {
465 return;
466 }
467
468 if (overlay->hwdata == NULL)
469 {
470 return;
471 }
472
473 current_overlay=NULL;
474
475 /* restore screen behind the overlay/chroma color. */
476 backrect.x=overlay->hwdata->CurrentViewPort.pos.x;
477 backrect.y=overlay->hwdata->CurrentViewPort.pos.y;
478 backrect.w=overlay->hwdata->CurrentViewPort.size.w;
479 backrect.h=overlay->hwdata->CurrentViewPort.size.h;
480 this->UpdateRects(this, 1, &backrect);
481
482 /* it is need for some buggy drivers, that can't hide overlay before */
483 /* freeing buffer, so we got trash on the srceen */
484 overlay->hwdata->props.flags &= ~Pg_SCALER_PROP_SCALER_ENABLE;
485 PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
486
487 overlay->hwdata->scaler_on = 0;
488 overlay->hwdata->State = OVERLAY_STATE_UNINIT;
489
490 if (overlay->hwdata->channel != NULL)
491 {
492 PgDestroyVideoChannel(overlay->hwdata->channel);
493 overlay->hwdata->channel = NULL;
494 return;
495 }
496
497 overlay->hwdata->CurrentFrameData = NULL;
498
499 SDL_free(overlay->hwdata->FrameData0);
500 SDL_free(overlay->hwdata->FrameData1);
501 overlay->hwdata->FrameData0 = NULL;
502 overlay->hwdata->FrameData1 = NULL;
503 SDL_free(overlay->hwdata);
504}
diff --git a/apps/plugins/sdl/src/video/photon/SDL_phyuv_c.h b/apps/plugins/sdl/src/video/photon/SDL_phyuv_c.h
deleted file mode 100644
index c6f73feb9f..0000000000
--- a/apps/plugins/sdl/src/video/photon/SDL_phyuv_c.h
+++ /dev/null
@@ -1,62 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#ifndef __SDL_PH_YUV_H__
25#define __SDL_PH_YUV_H__
26
27/* This is the photon implementation of YUV video overlays */
28
29#include "SDL_video.h"
30#include "SDL_ph_video.h"
31
32struct private_yuvhwdata
33{
34 FRAMEDATA* CurrentFrameData;
35 FRAMEDATA* FrameData0;
36 FRAMEDATA* FrameData1;
37 PgScalerProps_t props;
38 PgScalerCaps_t caps;
39 PgVideoChannel_t* channel;
40 PhArea_t CurrentViewPort;
41 PhPoint_t CurrentWindowPos;
42 long format;
43 int scaler_on;
44 int current;
45 long YStride;
46 long VStride;
47 long UStride;
48 int ischromakey;
49 long chromakey;
50 int forcedredraw;
51 unsigned long State;
52 long flags;
53 int locked;
54};
55
56extern SDL_Overlay* ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface* display);
57extern int ph_LockYUVOverlay(_THIS, SDL_Overlay* overlay);
58extern void ph_UnlockYUVOverlay(_THIS, SDL_Overlay* overlay);
59extern int ph_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* src, SDL_Rect* dst);
60extern void ph_FreeYUVOverlay(_THIS, SDL_Overlay* overlay);
61
62#endif /* __SDL_PH_YUV_H__ */