diff options
Diffstat (limited to 'apps/plugins/sdl/src/video/nanox')
-rw-r--r-- | apps/plugins/sdl/src/video/nanox/SDL_nxevents.c | 382 | ||||
-rw-r--r-- | apps/plugins/sdl/src/video/nanox/SDL_nxevents_c.h | 32 | ||||
-rw-r--r-- | apps/plugins/sdl/src/video/nanox/SDL_nximage.c | 230 | ||||
-rw-r--r-- | apps/plugins/sdl/src/video/nanox/SDL_nximage_c.h | 35 | ||||
-rw-r--r-- | apps/plugins/sdl/src/video/nanox/SDL_nxmodes.c | 84 | ||||
-rw-r--r-- | apps/plugins/sdl/src/video/nanox/SDL_nxmodes_c.h | 34 | ||||
-rw-r--r-- | apps/plugins/sdl/src/video/nanox/SDL_nxmouse.c | 79 | ||||
-rw-r--r-- | apps/plugins/sdl/src/video/nanox/SDL_nxmouse_c.h | 29 | ||||
-rw-r--r-- | apps/plugins/sdl/src/video/nanox/SDL_nxvideo.c | 544 | ||||
-rw-r--r-- | apps/plugins/sdl/src/video/nanox/SDL_nxvideo.h | 96 | ||||
-rw-r--r-- | apps/plugins/sdl/src/video/nanox/SDL_nxwm.c | 61 | ||||
-rw-r--r-- | apps/plugins/sdl/src/video/nanox/SDL_nxwm_c.h | 32 |
12 files changed, 1638 insertions, 0 deletions
diff --git a/apps/plugins/sdl/src/video/nanox/SDL_nxevents.c b/apps/plugins/sdl/src/video/nanox/SDL_nxevents.c new file mode 100644 index 0000000000..788c794d2d --- /dev/null +++ b/apps/plugins/sdl/src/video/nanox/SDL_nxevents.c | |||
@@ -0,0 +1,382 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | Copyright (C) 2001 Hsieh-Fu Tsai | ||
5 | Copyright (C) 2002 Greg Haerr <greg@censoft.com> | ||
6 | |||
7 | This library is free software; you can redistribute it and/or | ||
8 | modify it under the terms of the GNU Library General Public | ||
9 | License as published by the Free Software Foundation; either | ||
10 | version 2 of the License, or (at your option) any later version. | ||
11 | |||
12 | This library is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | Library General Public License for more details. | ||
16 | |||
17 | You should have received a copy of the GNU Library General Public | ||
18 | License along with this library; if not, write to the Free | ||
19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | |||
21 | Sam Lantinga | ||
22 | slouken@libsdl.org | ||
23 | |||
24 | Hsieh-Fu Tsai | ||
25 | clare@setabox.com | ||
26 | */ | ||
27 | #include "SDL_config.h" | ||
28 | |||
29 | #include "SDL_keysym.h" | ||
30 | #include "../../events/SDL_events_c.h" | ||
31 | |||
32 | #include "SDL_nxevents_c.h" | ||
33 | #include "SDL_nximage_c.h" | ||
34 | |||
35 | // The translation tables from a nanox keysym to a SDL keysym | ||
36 | static SDLKey NX_NONASCII_keymap [MWKEY_LAST + 1] ; | ||
37 | |||
38 | void NX_InitOSKeymap (_THIS) | ||
39 | { | ||
40 | int i ; | ||
41 | |||
42 | Dprintf ("enter NX_InitOSKeymap\n") ; | ||
43 | |||
44 | // Map the nanox scancodes to SDL keysyms | ||
45 | for (i = 0; i < SDL_arraysize (NX_NONASCII_keymap); ++ i) | ||
46 | NX_NONASCII_keymap [i] = SDLK_UNKNOWN ; | ||
47 | |||
48 | NX_NONASCII_keymap [MWKEY_LEFT & 0xFF] = SDLK_LEFT ; | ||
49 | NX_NONASCII_keymap [MWKEY_RIGHT & 0xFF] = SDLK_RIGHT ; | ||
50 | NX_NONASCII_keymap [MWKEY_UP & 0xFF] = SDLK_UP ; | ||
51 | NX_NONASCII_keymap [MWKEY_DOWN & 0xFF] = SDLK_DOWN ; | ||
52 | NX_NONASCII_keymap [MWKEY_INSERT & 0xFF] = SDLK_INSERT ; | ||
53 | NX_NONASCII_keymap [MWKEY_DELETE & 0xFF] = SDLK_DELETE ; | ||
54 | NX_NONASCII_keymap [MWKEY_HOME & 0xFF] = SDLK_HOME ; | ||
55 | NX_NONASCII_keymap [MWKEY_END & 0xFF] = SDLK_END ; | ||
56 | NX_NONASCII_keymap [MWKEY_PAGEUP & 0xFF] = SDLK_PAGEUP ; | ||
57 | NX_NONASCII_keymap [MWKEY_PAGEDOWN & 0xFF] = SDLK_PAGEDOWN ; | ||
58 | |||
59 | NX_NONASCII_keymap [MWKEY_KP0 & 0xFF] = SDLK_KP0 ; | ||
60 | NX_NONASCII_keymap [MWKEY_KP1 & 0xFF] = SDLK_KP1 ; | ||
61 | NX_NONASCII_keymap [MWKEY_KP2 & 0xFF] = SDLK_KP2 ; | ||
62 | NX_NONASCII_keymap [MWKEY_KP3 & 0xFF] = SDLK_KP3 ; | ||
63 | NX_NONASCII_keymap [MWKEY_KP4 & 0xFF] = SDLK_KP4 ; | ||
64 | NX_NONASCII_keymap [MWKEY_KP5 & 0xFF] = SDLK_KP5 ; | ||
65 | NX_NONASCII_keymap [MWKEY_KP6 & 0xFF] = SDLK_KP6 ; | ||
66 | NX_NONASCII_keymap [MWKEY_KP7 & 0xFF] = SDLK_KP7 ; | ||
67 | NX_NONASCII_keymap [MWKEY_KP8 & 0xFF] = SDLK_KP8 ; | ||
68 | NX_NONASCII_keymap [MWKEY_KP9 & 0xFF] = SDLK_KP9 ; | ||
69 | NX_NONASCII_keymap [MWKEY_KP_PERIOD & 0xFF] = SDLK_KP_PERIOD ; | ||
70 | NX_NONASCII_keymap [MWKEY_KP_DIVIDE & 0xFF] = SDLK_KP_DIVIDE ; | ||
71 | NX_NONASCII_keymap [MWKEY_KP_MULTIPLY & 0xFF] = SDLK_KP_MULTIPLY ; | ||
72 | NX_NONASCII_keymap [MWKEY_KP_MINUS & 0xFF] = SDLK_KP_MINUS ; | ||
73 | NX_NONASCII_keymap [MWKEY_KP_PLUS & 0xFF] = SDLK_KP_PLUS ; | ||
74 | NX_NONASCII_keymap [MWKEY_KP_ENTER & 0xFF] = SDLK_KP_ENTER ; | ||
75 | NX_NONASCII_keymap [MWKEY_KP_EQUALS & 0xFF] = SDLK_KP_EQUALS ; | ||
76 | |||
77 | NX_NONASCII_keymap [MWKEY_F1 & 0xFF] = SDLK_F1 ; | ||
78 | NX_NONASCII_keymap [MWKEY_F2 & 0xFF] = SDLK_F2 ; | ||
79 | NX_NONASCII_keymap [MWKEY_F3 & 0xFF] = SDLK_F3 ; | ||
80 | NX_NONASCII_keymap [MWKEY_F4 & 0xFF] = SDLK_F4 ; | ||
81 | NX_NONASCII_keymap [MWKEY_F5 & 0xFF] = SDLK_F5 ; | ||
82 | NX_NONASCII_keymap [MWKEY_F6 & 0xFF] = SDLK_F6 ; | ||
83 | NX_NONASCII_keymap [MWKEY_F7 & 0xFF] = SDLK_F7 ; | ||
84 | NX_NONASCII_keymap [MWKEY_F8 & 0xFF] = SDLK_F8 ; | ||
85 | NX_NONASCII_keymap [MWKEY_F9 & 0xFF] = SDLK_F9 ; | ||
86 | NX_NONASCII_keymap [MWKEY_F10 & 0xFF] = SDLK_F10 ; | ||
87 | NX_NONASCII_keymap [MWKEY_F11 & 0xFF] = SDLK_F11 ; | ||
88 | NX_NONASCII_keymap [MWKEY_F12 & 0xFF] = SDLK_F12 ; | ||
89 | |||
90 | NX_NONASCII_keymap [MWKEY_NUMLOCK & 0xFF] = SDLK_NUMLOCK ; | ||
91 | NX_NONASCII_keymap [MWKEY_CAPSLOCK & 0xFF] = SDLK_CAPSLOCK ; | ||
92 | NX_NONASCII_keymap [MWKEY_SCROLLOCK & 0xFF] = SDLK_SCROLLOCK ; | ||
93 | NX_NONASCII_keymap [MWKEY_LSHIFT & 0xFF] = SDLK_LSHIFT ; | ||
94 | NX_NONASCII_keymap [MWKEY_RSHIFT & 0xFF] = SDLK_RSHIFT ; | ||
95 | NX_NONASCII_keymap [MWKEY_LCTRL & 0xFF] = SDLK_LCTRL ; | ||
96 | NX_NONASCII_keymap [MWKEY_RCTRL & 0xFF] = SDLK_RCTRL ; | ||
97 | NX_NONASCII_keymap [MWKEY_LALT & 0xFF] = SDLK_LALT ; | ||
98 | NX_NONASCII_keymap [MWKEY_RALT & 0xFF] = SDLK_RALT ; | ||
99 | NX_NONASCII_keymap [MWKEY_LMETA & 0xFF] = SDLK_LMETA ; | ||
100 | NX_NONASCII_keymap [MWKEY_RMETA & 0xFF] = SDLK_RMETA ; | ||
101 | NX_NONASCII_keymap [MWKEY_ALTGR & 0xFF] = SDLK_MODE ; | ||
102 | |||
103 | NX_NONASCII_keymap [MWKEY_PRINT & 0xFF] = SDLK_PRINT ; | ||
104 | NX_NONASCII_keymap [MWKEY_SYSREQ & 0xFF] = SDLK_SYSREQ ; | ||
105 | NX_NONASCII_keymap [MWKEY_PAUSE & 0xFF] = SDLK_PAUSE ; | ||
106 | NX_NONASCII_keymap [MWKEY_BREAK & 0xFF] = SDLK_BREAK ; | ||
107 | NX_NONASCII_keymap [MWKEY_MENU & 0xFF] = SDLK_MENU ; | ||
108 | |||
109 | Dprintf ("leave NX_InitOSKeymap\n") ; | ||
110 | } | ||
111 | |||
112 | SDL_keysym * NX_TranslateKey (GR_EVENT_KEYSTROKE * keystroke, SDL_keysym * keysym) | ||
113 | { | ||
114 | GR_KEY ch = keystroke -> ch ; | ||
115 | |||
116 | Dprintf ("enter NX_TranslateKey\n") ; | ||
117 | |||
118 | keysym -> scancode = keystroke -> scancode ; | ||
119 | keysym -> sym = SDLK_UNKNOWN ; | ||
120 | |||
121 | if (ch & MWKEY_NONASCII_MASK) { | ||
122 | keysym -> sym = NX_NONASCII_keymap [ch & 0xFF] ; | ||
123 | } else { | ||
124 | keysym -> sym = ch & 0x7F ; | ||
125 | } | ||
126 | |||
127 | keysym -> mod = KMOD_NONE ; | ||
128 | |||
129 | #if 1 // Retrieve more mode information | ||
130 | { | ||
131 | GR_KEYMOD mod = keystroke -> modifiers ; | ||
132 | |||
133 | if (mod & MWKMOD_LSHIFT) | ||
134 | keysym -> mod |= KMOD_LSHIFT ; | ||
135 | if (mod & MWKMOD_RSHIFT) | ||
136 | keysym -> mod |= KMOD_RSHIFT ; | ||
137 | if (mod & MWKMOD_LCTRL) | ||
138 | keysym -> mod |= KMOD_LCTRL ; | ||
139 | if (mod & MWKMOD_RCTRL) | ||
140 | keysym -> mod |= KMOD_RCTRL ; | ||
141 | if (mod & MWKMOD_LALT) | ||
142 | keysym -> mod |= KMOD_LALT ; | ||
143 | if (mod & MWKMOD_RALT) | ||
144 | keysym -> mod |= KMOD_RALT ; | ||
145 | if (mod & MWKMOD_LMETA) | ||
146 | keysym -> mod |= KMOD_LMETA ; | ||
147 | if (mod & MWKMOD_RMETA) | ||
148 | keysym -> mod |= KMOD_RMETA ; | ||
149 | if (mod & MWKMOD_NUM) | ||
150 | keysym -> mod |= KMOD_NUM ; | ||
151 | if (mod & MWKMOD_CAPS) | ||
152 | keysym -> mod |= KMOD_CAPS ; | ||
153 | if (mod & MWKMOD_ALTGR) | ||
154 | keysym -> mod |= KMOD_MODE ; | ||
155 | } | ||
156 | #endif | ||
157 | |||
158 | keysym -> unicode = ch ; | ||
159 | |||
160 | Dprintf ("leave NX_TranslateKey\n") ; | ||
161 | return keysym ; | ||
162 | } | ||
163 | |||
164 | static int check_boundary (_THIS, int x, int y) | ||
165 | { | ||
166 | if (x < OffsetX || y < OffsetY || x > OffsetX + this -> screen -> w || | ||
167 | y > OffsetY + this -> screen -> h) | ||
168 | return 0 ; | ||
169 | |||
170 | return 1 ; | ||
171 | } | ||
172 | |||
173 | void NX_PumpEvents (_THIS) | ||
174 | { | ||
175 | GR_EVENT event ; | ||
176 | static GR_BUTTON last_button_down = 0 ; | ||
177 | |||
178 | GrCheckNextEvent (& event) ; | ||
179 | while (event.type != GR_EVENT_TYPE_NONE) { | ||
180 | |||
181 | // dispatch event | ||
182 | switch (event.type) { | ||
183 | case GR_EVENT_TYPE_MOUSE_ENTER : | ||
184 | { | ||
185 | Dprintf ("mouse enter\n") ; | ||
186 | SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS) ; | ||
187 | break ; | ||
188 | } | ||
189 | |||
190 | case GR_EVENT_TYPE_MOUSE_EXIT : | ||
191 | { | ||
192 | Dprintf ("mouse exit\n") ; | ||
193 | SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS) ; | ||
194 | break ; | ||
195 | } | ||
196 | |||
197 | case GR_EVENT_TYPE_FOCUS_IN : | ||
198 | { | ||
199 | Dprintf ("focus in\n") ; | ||
200 | SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS) ; | ||
201 | break ; | ||
202 | } | ||
203 | |||
204 | case GR_EVENT_TYPE_FOCUS_OUT : | ||
205 | { | ||
206 | Dprintf ("focus out\n") ; | ||
207 | SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS) ; | ||
208 | break ; | ||
209 | } | ||
210 | |||
211 | case GR_EVENT_TYPE_MOUSE_MOTION : | ||
212 | { | ||
213 | Dprintf ("mouse motion\n") ; | ||
214 | |||
215 | if (SDL_VideoSurface) { | ||
216 | if (currently_fullscreen) { | ||
217 | if (check_boundary (this, event.button.x, event.button.y)) { | ||
218 | SDL_PrivateMouseMotion (0, 0, event.button.x - OffsetX, | ||
219 | event.button.y - OffsetY) ; | ||
220 | } | ||
221 | } else { | ||
222 | SDL_PrivateMouseMotion (0, 0, event.button.x, event.button.y) ; | ||
223 | } | ||
224 | } | ||
225 | break ; | ||
226 | } | ||
227 | |||
228 | case GR_EVENT_TYPE_BUTTON_DOWN : | ||
229 | { | ||
230 | int button = event.button.buttons ; | ||
231 | |||
232 | Dprintf ("button down\n") ; | ||
233 | |||
234 | switch (button) { | ||
235 | case MWBUTTON_L : | ||
236 | button = 1 ; | ||
237 | break ; | ||
238 | case MWBUTTON_M : | ||
239 | button = 2 ; | ||
240 | break ; | ||
241 | case MWBUTTON_R : | ||
242 | button = 3 ; | ||
243 | break ; | ||
244 | default : | ||
245 | button = 0 ; | ||
246 | } | ||
247 | last_button_down = button ; | ||
248 | |||
249 | if (currently_fullscreen) { | ||
250 | if (check_boundary (this, event.button.x, event.button.y)) { | ||
251 | SDL_PrivateMouseButton (SDL_PRESSED, button, | ||
252 | event.button.x - OffsetX, event.button.y - OffsetY) ; | ||
253 | } | ||
254 | } else { | ||
255 | SDL_PrivateMouseButton (SDL_PRESSED, button, | ||
256 | event.button.x, event.button.y) ; | ||
257 | } | ||
258 | break ; | ||
259 | } | ||
260 | |||
261 | // do not konw which button is released | ||
262 | case GR_EVENT_TYPE_BUTTON_UP : | ||
263 | { | ||
264 | Dprintf ("button up\n") ; | ||
265 | |||
266 | if (currently_fullscreen) { | ||
267 | if (check_boundary (this, event.button.x, event.button.y)) { | ||
268 | SDL_PrivateMouseButton (SDL_RELEASED, last_button_down, | ||
269 | event.button.x - OffsetX, event.button.y - OffsetY) ; | ||
270 | } | ||
271 | } else { | ||
272 | SDL_PrivateMouseButton (SDL_RELEASED, last_button_down, | ||
273 | event.button.x, event.button.y) ; | ||
274 | } | ||
275 | last_button_down = 0 ; | ||
276 | break ; | ||
277 | } | ||
278 | |||
279 | case GR_EVENT_TYPE_KEY_DOWN : | ||
280 | { | ||
281 | SDL_keysym keysym ; | ||
282 | |||
283 | Dprintf ("key down\n") ; | ||
284 | SDL_PrivateKeyboard (SDL_PRESSED, | ||
285 | NX_TranslateKey (& event.keystroke, & keysym)) ; | ||
286 | break ; | ||
287 | } | ||
288 | |||
289 | case GR_EVENT_TYPE_KEY_UP : | ||
290 | { | ||
291 | SDL_keysym keysym ; | ||
292 | |||
293 | Dprintf ("key up\n") ; | ||
294 | SDL_PrivateKeyboard (SDL_RELEASED, | ||
295 | NX_TranslateKey (& event.keystroke, & keysym)) ; | ||
296 | break ; | ||
297 | } | ||
298 | |||
299 | case GR_EVENT_TYPE_CLOSE_REQ : | ||
300 | { | ||
301 | Dprintf ("close require\n") ; | ||
302 | SDL_PrivateQuit () ; | ||
303 | break ; | ||
304 | } | ||
305 | |||
306 | case GR_EVENT_TYPE_EXPOSURE : | ||
307 | { | ||
308 | Dprintf ("event_type_exposure\n") ; | ||
309 | if (SDL_VideoSurface) { | ||
310 | NX_RefreshDisplay (this) ;//, & event.exposure) ; | ||
311 | } | ||
312 | break ; | ||
313 | } | ||
314 | |||
315 | case GR_EVENT_TYPE_UPDATE : | ||
316 | { | ||
317 | switch (event.update.utype) { | ||
318 | case GR_UPDATE_MAP : | ||
319 | { | ||
320 | Dprintf ("GR_UPDATE_MAP\n") ; | ||
321 | // If we're not active, make ourselves active | ||
322 | if (!(SDL_GetAppState () & SDL_APPACTIVE)) { | ||
323 | // Send an internal activate event | ||
324 | SDL_PrivateAppActive (1, SDL_APPACTIVE) ; | ||
325 | } | ||
326 | if (SDL_VideoSurface) { | ||
327 | NX_RefreshDisplay (this) ; | ||
328 | } | ||
329 | break ; | ||
330 | } | ||
331 | |||
332 | case GR_UPDATE_UNMAP : | ||
333 | case GR_UPDATE_UNMAPTEMP : | ||
334 | { | ||
335 | Dprintf ("GR_UPDATE_UNMAP or GR_UPDATE_UNMAPTEMP\n") ; | ||
336 | // If we're active, make ourselves inactive | ||
337 | if (SDL_GetAppState () & SDL_APPACTIVE) { | ||
338 | // Send an internal deactivate event | ||
339 | SDL_PrivateAppActive (0, SDL_APPACTIVE | SDL_APPINPUTFOCUS) ; | ||
340 | } | ||
341 | break ; | ||
342 | } | ||
343 | |||
344 | case GR_UPDATE_SIZE : | ||
345 | { | ||
346 | Dprintf ("GR_UPDATE_SIZE\n") ; | ||
347 | SDL_PrivateResize (event.update.width, event.update.height) ; | ||
348 | break ; | ||
349 | } | ||
350 | |||
351 | case GR_UPDATE_MOVE : | ||
352 | case GR_UPDATE_REPARENT : | ||
353 | { | ||
354 | Dprintf ("GR_UPDATE_MOVE or GR_UPDATE_REPARENT\n") ; | ||
355 | #ifdef ENABLE_NANOX_DIRECT_FB | ||
356 | if (Clientfb) { | ||
357 | /* Get current window position and fb pointer*/ | ||
358 | if (currently_fullscreen) | ||
359 | GrGetWindowFBInfo(FSwindow, &fbinfo); | ||
360 | else | ||
361 | GrGetWindowFBInfo(SDL_Window, &fbinfo); | ||
362 | } | ||
363 | #endif | ||
364 | break ; | ||
365 | } | ||
366 | |||
367 | default : | ||
368 | Dprintf ("unknown GR_EVENT_TYPE_UPDATE\n") ; | ||
369 | break ; | ||
370 | } | ||
371 | break ; | ||
372 | } | ||
373 | |||
374 | default : | ||
375 | { | ||
376 | Dprintf ("pump event default\n") ; | ||
377 | } | ||
378 | } | ||
379 | |||
380 | GrCheckNextEvent (& event) ; | ||
381 | } | ||
382 | } | ||
diff --git a/apps/plugins/sdl/src/video/nanox/SDL_nxevents_c.h b/apps/plugins/sdl/src/video/nanox/SDL_nxevents_c.h new file mode 100644 index 0000000000..b3b4f979bb --- /dev/null +++ b/apps/plugins/sdl/src/video/nanox/SDL_nxevents_c.h | |||
@@ -0,0 +1,32 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | Copyright (C) 2001 Hsieh-Fu Tsai | ||
5 | |||
6 | This library is free software; you can redistribute it and/or | ||
7 | modify it under the terms of the GNU Library General Public | ||
8 | License as published by the Free Software Foundation; either | ||
9 | version 2 of the License, or (at your option) any later version. | ||
10 | |||
11 | This library is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | Library General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU Library General Public | ||
17 | License along with this library; if not, write to the Free | ||
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | |||
20 | Sam Lantinga | ||
21 | slouken@libsdl.org | ||
22 | |||
23 | Hsieh-Fu Tsai | ||
24 | clare@setabox.com | ||
25 | */ | ||
26 | #include "SDL_config.h" | ||
27 | |||
28 | #include "SDL_nxvideo.h" | ||
29 | |||
30 | // Functions to be exported | ||
31 | extern void NX_InitOSKeymap (_THIS) ; | ||
32 | extern void NX_PumpEvents (_THIS) ; | ||
diff --git a/apps/plugins/sdl/src/video/nanox/SDL_nximage.c b/apps/plugins/sdl/src/video/nanox/SDL_nximage.c new file mode 100644 index 0000000000..23d3157cb0 --- /dev/null +++ b/apps/plugins/sdl/src/video/nanox/SDL_nximage.c | |||
@@ -0,0 +1,230 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | Copyright (C) 2001 Hsieh-Fu Tsai | ||
5 | Copyright (C) 2002 Greg Haerr <greg@censoft.com> | ||
6 | |||
7 | This library is free software; you can redistribute it and/or | ||
8 | modify it under the terms of the GNU Library General Public | ||
9 | License as published by the Free Software Foundation; either | ||
10 | version 2 of the License, or (at your option) any later version. | ||
11 | |||
12 | This library is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | Library General Public License for more details. | ||
16 | |||
17 | You should have received a copy of the GNU Library General Public | ||
18 | License along with this library; if not, write to the Free | ||
19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | |||
21 | Sam Lantinga | ||
22 | slouken@libsdl.org | ||
23 | |||
24 | Hsieh-Fu Tsai | ||
25 | clare@setabox.com | ||
26 | */ | ||
27 | #include "SDL_config.h" | ||
28 | |||
29 | #include "SDL_nximage_c.h" | ||
30 | |||
31 | void NX_NormalUpdate (_THIS, int numrects, SDL_Rect * rects) | ||
32 | { | ||
33 | int i, j, xinc, yinc, destinc, rowinc ; | ||
34 | int x, y, w, h ; | ||
35 | unsigned char * src = NULL, * dest = NULL ; | ||
36 | |||
37 | Dprintf ("enter NX_NormalUpdate\n") ; | ||
38 | |||
39 | /* These are the values for the incoming image */ | ||
40 | xinc = this -> screen -> format -> BytesPerPixel ; | ||
41 | yinc = this -> screen -> pitch ; | ||
42 | |||
43 | for (i = 0; i < numrects; ++ i) { | ||
44 | x = rects [i].x, y = rects [i].y ; | ||
45 | w = rects [i].w, h = rects [i].h ; | ||
46 | src = SDL_Image + y * yinc + x * xinc ; | ||
47 | #ifdef ENABLE_NANOX_DIRECT_FB | ||
48 | if (Clientfb) { | ||
49 | if (currently_fullscreen) | ||
50 | dest = fbinfo.winpixels + (((y+OffsetY) * fbinfo.pitch) + | ||
51 | ((x+OffsetX) * fbinfo.bytespp)); | ||
52 | else | ||
53 | dest = fbinfo.winpixels + ((y * fbinfo.pitch) + (x * fbinfo.bytespp)); | ||
54 | destinc = fbinfo.pitch; | ||
55 | } | ||
56 | else | ||
57 | #endif | ||
58 | { | ||
59 | dest = Image_buff ; | ||
60 | destinc = w * xinc ; | ||
61 | } | ||
62 | rowinc = w * xinc; | ||
63 | |||
64 | // apply GammaRamp table | ||
65 | if ((pixel_type == MWPF_TRUECOLOR0888 || pixel_type == MWPF_TRUECOLOR888) | ||
66 | && GammaRamp_R && GammaRamp_G && GammaRamp_B) { | ||
67 | Uint8 * ptrsrc ; | ||
68 | Uint8 * ptrdst ; | ||
69 | int k ; | ||
70 | |||
71 | for (j = h; j > 0; -- j, src += yinc, dest += destinc) { | ||
72 | ptrsrc = src ; | ||
73 | ptrdst = dest ; | ||
74 | for (k = w; k > 0; -- k) { | ||
75 | *ptrdst++ = GammaRamp_B [*ptrsrc++] >> 8; | ||
76 | *ptrdst++ = GammaRamp_G [*ptrsrc++] >> 8; | ||
77 | *ptrdst++ = GammaRamp_R [*ptrsrc++] >> 8; | ||
78 | *ptrdst++ = 0; | ||
79 | ++ptrsrc; | ||
80 | } | ||
81 | } | ||
82 | } | ||
83 | #if 1 /* This is needed for microwindows 0.90 or older */ | ||
84 | else if (pixel_type == MWPF_TRUECOLOR0888 || pixel_type == MWPF_TRUECOLOR888) { | ||
85 | Uint8 * ptrsrc ; | ||
86 | Uint8 * ptrdst ; | ||
87 | int k ; | ||
88 | |||
89 | for (j = h; j > 0; -- j, src += yinc, dest += destinc) { | ||
90 | ptrsrc = src ; | ||
91 | ptrdst = dest ; | ||
92 | for (k = w; k > 0; -- k) { | ||
93 | *ptrdst++ = *ptrsrc++; | ||
94 | *ptrdst++ = *ptrsrc++; | ||
95 | *ptrdst++ = *ptrsrc++; | ||
96 | *ptrdst++ = 0; | ||
97 | ++ptrsrc; | ||
98 | } | ||
99 | } | ||
100 | } | ||
101 | #endif | ||
102 | else | ||
103 | { | ||
104 | for (j = h; j > 0; -- j, src += yinc, dest += destinc) | ||
105 | SDL_memcpy (dest, src, rowinc) ; | ||
106 | } | ||
107 | if (!Clientfb) { | ||
108 | if (currently_fullscreen) { | ||
109 | GrArea (FSwindow, SDL_GC, x + OffsetX, y + OffsetY, w, h, Image_buff, | ||
110 | pixel_type) ; | ||
111 | } else { | ||
112 | GrArea (SDL_Window, SDL_GC, x, y, w, h, Image_buff, pixel_type) ; | ||
113 | } | ||
114 | } | ||
115 | } | ||
116 | GrFlush(); | ||
117 | |||
118 | Dprintf ("leave NX_NormalUpdate\n") ; | ||
119 | } | ||
120 | |||
121 | int NX_SetupImage (_THIS, SDL_Surface * screen) | ||
122 | { | ||
123 | int size = screen -> h * screen -> pitch ; | ||
124 | |||
125 | Dprintf ("enter NX_SetupImage\n") ; | ||
126 | |||
127 | screen -> pixels = (void *) SDL_malloc (size) ; | ||
128 | |||
129 | if (!Clientfb) { | ||
130 | Image_buff = (unsigned char *) SDL_malloc (size) ; | ||
131 | if (screen -> pixels == NULL || Image_buff == NULL) { | ||
132 | SDL_free (screen -> pixels) ; | ||
133 | SDL_free (Image_buff) ; | ||
134 | SDL_OutOfMemory () ; | ||
135 | return -1 ; | ||
136 | } | ||
137 | } | ||
138 | |||
139 | SDL_Image = (unsigned char *) screen -> pixels ; | ||
140 | |||
141 | this -> UpdateRects = NX_NormalUpdate ; | ||
142 | |||
143 | Dprintf ("leave NX_SetupImage\n") ; | ||
144 | return 0 ; | ||
145 | } | ||
146 | |||
147 | void NX_DestroyImage (_THIS, SDL_Surface * screen) | ||
148 | { | ||
149 | Dprintf ("enter NX_DestroyImage\n") ; | ||
150 | |||
151 | if (SDL_Image) SDL_free (SDL_Image) ; | ||
152 | if (Image_buff) SDL_free (Image_buff) ; | ||
153 | if (screen) screen -> pixels = NULL ; | ||
154 | |||
155 | Dprintf ("leave NX_DestroyImage\n") ; | ||
156 | } | ||
157 | |||
158 | int NX_ResizeImage (_THIS, SDL_Surface * screen, Uint32 flags) | ||
159 | { | ||
160 | int retval ; | ||
161 | GR_SCREEN_INFO si ; | ||
162 | |||
163 | Dprintf ("enter NX_ResizeImage\n") ; | ||
164 | |||
165 | NX_DestroyImage (this, screen) ; | ||
166 | retval = NX_SetupImage (this, screen) ; | ||
167 | |||
168 | GrGetScreenInfo (& si) ; | ||
169 | OffsetX = (si.cols - screen -> w) / 2 ; | ||
170 | OffsetY = (si.rows - screen -> h) / 2 ; | ||
171 | |||
172 | #ifdef ENABLE_NANOX_DIRECT_FB | ||
173 | if (Clientfb) { | ||
174 | /* Get current window position and fb pointer*/ | ||
175 | if (currently_fullscreen) | ||
176 | GrGetWindowFBInfo(FSwindow, &fbinfo); | ||
177 | else | ||
178 | GrGetWindowFBInfo(SDL_Window, &fbinfo); | ||
179 | } | ||
180 | #endif | ||
181 | Dprintf ("leave NX_ResizeImage\n") ; | ||
182 | return retval ; | ||
183 | } | ||
184 | |||
185 | void NX_RefreshDisplay (_THIS) | ||
186 | { | ||
187 | Dprintf ("enter NX_RefreshDisplay\n") ; | ||
188 | |||
189 | // Don't refresh a display that doesn't have an image (like GL) | ||
190 | if (! SDL_Image) { | ||
191 | return; | ||
192 | } | ||
193 | |||
194 | #ifdef ENABLE_NANOX_DIRECT_FB | ||
195 | if (Clientfb) { | ||
196 | int j; | ||
197 | char *src, *dest = NULL; | ||
198 | int xinc, yinc, rowinc; | ||
199 | |||
200 | GrGetWindowFBInfo(SDL_Window, &fbinfo); | ||
201 | |||
202 | xinc = this -> screen -> format -> BytesPerPixel ; | ||
203 | yinc = this -> screen -> pitch ; | ||
204 | |||
205 | src = SDL_Image; | ||
206 | if (currently_fullscreen) | ||
207 | dest = fbinfo.winpixels + ((OffsetY * fbinfo.pitch) + | ||
208 | (OffsetX * fbinfo.bytespp)); | ||
209 | else | ||
210 | dest = fbinfo.winpixels; | ||
211 | rowinc = xinc * this -> screen -> w; | ||
212 | |||
213 | for (j = this -> screen -> h; j > 0; -- j, src += yinc, dest += fbinfo.pitch) | ||
214 | SDL_memcpy (dest, src, rowinc) ; | ||
215 | } | ||
216 | else | ||
217 | #endif | ||
218 | { | ||
219 | if (currently_fullscreen) { | ||
220 | GrArea (FSwindow, SDL_GC, OffsetX, OffsetY, this -> screen -> w, | ||
221 | this -> screen -> h, SDL_Image, pixel_type) ; | ||
222 | } else { | ||
223 | GrArea (SDL_Window, SDL_GC, 0, 0, this -> screen -> w, | ||
224 | this -> screen -> h, SDL_Image, pixel_type) ; | ||
225 | } | ||
226 | } | ||
227 | GrFlush(); | ||
228 | |||
229 | Dprintf ("leave NX_RefreshDisplay\n") ; | ||
230 | } | ||
diff --git a/apps/plugins/sdl/src/video/nanox/SDL_nximage_c.h b/apps/plugins/sdl/src/video/nanox/SDL_nximage_c.h new file mode 100644 index 0000000000..0bf29e561a --- /dev/null +++ b/apps/plugins/sdl/src/video/nanox/SDL_nximage_c.h | |||
@@ -0,0 +1,35 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | Copyright (C) 2001 Hsieh-Fu Tsai | ||
5 | |||
6 | This library is free software; you can redistribute it and/or | ||
7 | modify it under the terms of the GNU Library General Public | ||
8 | License as published by the Free Software Foundation; either | ||
9 | version 2 of the License, or (at your option) any later version. | ||
10 | |||
11 | This library is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | Library General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU Library General Public | ||
17 | License along with this library; if not, write to the Free | ||
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | |||
20 | Sam Lantinga | ||
21 | slouken@libsdl.org | ||
22 | |||
23 | Hsieh-Fu Tsai | ||
24 | clare@setabox.com | ||
25 | */ | ||
26 | #include "SDL_config.h" | ||
27 | |||
28 | #include "SDL_nxvideo.h" | ||
29 | |||
30 | extern int NX_SetupImage (_THIS, SDL_Surface * screen) ; | ||
31 | extern void NX_DestroyImage (_THIS, SDL_Surface * screen) ; | ||
32 | extern int NX_ResizeImage (_THIS, SDL_Surface * screen, Uint32 flags) ; | ||
33 | |||
34 | extern void NX_NormalUpdate (_THIS, int numrects, SDL_Rect * rects) ; | ||
35 | extern void NX_RefreshDisplay (_THIS) ; | ||
diff --git a/apps/plugins/sdl/src/video/nanox/SDL_nxmodes.c b/apps/plugins/sdl/src/video/nanox/SDL_nxmodes.c new file mode 100644 index 0000000000..bcf74e50cc --- /dev/null +++ b/apps/plugins/sdl/src/video/nanox/SDL_nxmodes.c | |||
@@ -0,0 +1,84 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | Copyright (C) 2001 Hsieh-Fu Tsai | ||
5 | |||
6 | This library is free software; you can redistribute it and/or | ||
7 | modify it under the terms of the GNU Library General Public | ||
8 | License as published by the Free Software Foundation; either | ||
9 | version 2 of the License, or (at your option) any later version. | ||
10 | |||
11 | This library is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | Library General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU Library General Public | ||
17 | License along with this library; if not, write to the Free | ||
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | |||
20 | Sam Lantinga | ||
21 | slouken@libsdl.org | ||
22 | |||
23 | Hsieh-Fu Tsai | ||
24 | clare@setabox.com | ||
25 | */ | ||
26 | #include "SDL_config.h" | ||
27 | |||
28 | #include "SDL_stdinc.h" | ||
29 | #include "SDL_nxmodes_c.h" | ||
30 | |||
31 | SDL_Rect ** NX_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) | ||
32 | { | ||
33 | if (flags & SDL_FULLSCREEN) | ||
34 | return SDL_modelist ; | ||
35 | |||
36 | if (SDL_Visual.bpp == format -> BitsPerPixel) { | ||
37 | return ((SDL_Rect **) -1) ; | ||
38 | } else { | ||
39 | return ((SDL_Rect **) 0) ; | ||
40 | } | ||
41 | } | ||
42 | |||
43 | void NX_FreeVideoModes (_THIS) | ||
44 | { | ||
45 | int i ; | ||
46 | |||
47 | if (SDL_modelist) { | ||
48 | for (i = 0; SDL_modelist [i]; ++ i) { | ||
49 | SDL_free (SDL_modelist [i]) ; | ||
50 | } | ||
51 | SDL_free (SDL_modelist) ; | ||
52 | SDL_modelist = NULL; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | int NX_EnterFullScreen (_THIS) | ||
57 | { | ||
58 | if (! currently_fullscreen) { | ||
59 | GR_SCREEN_INFO si ; | ||
60 | |||
61 | GrGetScreenInfo (& si) ; | ||
62 | GrResizeWindow (FSwindow, si.cols, si.rows) ; | ||
63 | GrUnmapWindow (SDL_Window) ; | ||
64 | GrMapWindow (FSwindow) ; | ||
65 | GrRaiseWindow (FSwindow) ; | ||
66 | GrSetFocus (FSwindow) ; | ||
67 | currently_fullscreen = 1 ; | ||
68 | } | ||
69 | |||
70 | return 1 ; | ||
71 | } | ||
72 | |||
73 | int NX_LeaveFullScreen (_THIS) | ||
74 | { | ||
75 | if (currently_fullscreen) { | ||
76 | GrUnmapWindow (FSwindow) ; | ||
77 | GrMapWindow (SDL_Window) ; | ||
78 | GrRaiseWindow (SDL_Window) ; | ||
79 | GrSetFocus (SDL_Window) ; | ||
80 | currently_fullscreen = 0 ; | ||
81 | } | ||
82 | |||
83 | return 0 ; | ||
84 | } | ||
diff --git a/apps/plugins/sdl/src/video/nanox/SDL_nxmodes_c.h b/apps/plugins/sdl/src/video/nanox/SDL_nxmodes_c.h new file mode 100644 index 0000000000..fe2e655e98 --- /dev/null +++ b/apps/plugins/sdl/src/video/nanox/SDL_nxmodes_c.h | |||
@@ -0,0 +1,34 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | Copyright (C) 2001 Hsieh-Fu Tsai | ||
5 | |||
6 | This library is free software; you can redistribute it and/or | ||
7 | modify it under the terms of the GNU Library General Public | ||
8 | License as published by the Free Software Foundation; either | ||
9 | version 2 of the License, or (at your option) any later version. | ||
10 | |||
11 | This library is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | Library General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU Library General Public | ||
17 | License along with this library; if not, write to the Free | ||
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | |||
20 | Sam Lantinga | ||
21 | slouken@libsdl.org | ||
22 | |||
23 | Hsieh-Fu Tsai | ||
24 | clare@setabox.com | ||
25 | */ | ||
26 | #include "SDL_config.h" | ||
27 | |||
28 | #include "SDL_nxvideo.h" | ||
29 | #include <SDL.h> | ||
30 | |||
31 | extern SDL_Rect ** NX_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) ; | ||
32 | extern void NX_FreeVideoModes (_THIS) ; | ||
33 | extern int NX_EnterFullScreen (_THIS) ; | ||
34 | extern int NX_LeaveFullScreen (_THIS) ; | ||
diff --git a/apps/plugins/sdl/src/video/nanox/SDL_nxmouse.c b/apps/plugins/sdl/src/video/nanox/SDL_nxmouse.c new file mode 100644 index 0000000000..9c8f38205d --- /dev/null +++ b/apps/plugins/sdl/src/video/nanox/SDL_nxmouse.c | |||
@@ -0,0 +1,79 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | Copyright (C) 2001 Hsieh-Fu Tsai | ||
5 | |||
6 | This library is free software; you can redistribute it and/or | ||
7 | modify it under the terms of the GNU Library General Public | ||
8 | License as published by the Free Software Foundation; either | ||
9 | version 2 of the License, or (at your option) any later version. | ||
10 | |||
11 | This library is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | Library General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU Library General Public | ||
17 | License along with this library; if not, write to the Free | ||
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | |||
20 | Sam Lantinga | ||
21 | slouken@libsdl.org | ||
22 | |||
23 | Hsieh-Fu Tsai | ||
24 | clare@setabox.com | ||
25 | */ | ||
26 | #include "SDL_config.h" | ||
27 | |||
28 | #include "../../events/SDL_events_c.h" | ||
29 | |||
30 | #include "SDL_nxmouse_c.h" | ||
31 | |||
32 | // The implementation dependent data for the window manager cursor | ||
33 | struct WMcursor { | ||
34 | int unused ; | ||
35 | } ; | ||
36 | |||
37 | WMcursor * NX_CreateWMCursor (_THIS, | ||
38 | Uint8 * data, Uint8 * mask, int w, int h, int hot_x, int hot_y) | ||
39 | { | ||
40 | WMcursor * cursor ; | ||
41 | |||
42 | Dprintf ("enter NX_CreateWMCursor\n") ; | ||
43 | |||
44 | cursor = (WMcursor *) SDL_malloc (sizeof (WMcursor)) ; | ||
45 | if (cursor == NULL) { | ||
46 | SDL_OutOfMemory () ; | ||
47 | return NULL ; | ||
48 | } | ||
49 | |||
50 | Dprintf ("leave NX_CreateWMCursor\n") ; | ||
51 | return cursor ; | ||
52 | } | ||
53 | |||
54 | void NX_FreeWMCursor (_THIS, WMcursor * cursor) | ||
55 | { | ||
56 | Dprintf ("NX_FreeWMCursor\n") ; | ||
57 | SDL_free (cursor) ; | ||
58 | return ; | ||
59 | } | ||
60 | |||
61 | void NX_WarpWMCursor(_THIS, Uint16 x, Uint16 y) | ||
62 | { | ||
63 | GR_WINDOW_INFO info ; | ||
64 | |||
65 | Dprintf ("enter NX_WarpWMCursor\n") ; | ||
66 | SDL_Lock_EventThread () ; | ||
67 | |||
68 | GrGetWindowInfo (SDL_Window, & info) ; | ||
69 | GrMoveCursor (info.x + x, info.y + y) ; | ||
70 | |||
71 | SDL_Unlock_EventThread () ; | ||
72 | Dprintf ("leave NX_WarpWMCursor\n") ; | ||
73 | } | ||
74 | |||
75 | int NX_ShowWMCursor (_THIS, WMcursor * cursor) | ||
76 | { | ||
77 | Dprintf ("NX_ShowWMCursor\n") ; | ||
78 | return 1 ; | ||
79 | } | ||
diff --git a/apps/plugins/sdl/src/video/nanox/SDL_nxmouse_c.h b/apps/plugins/sdl/src/video/nanox/SDL_nxmouse_c.h new file mode 100644 index 0000000000..d7fedb5362 --- /dev/null +++ b/apps/plugins/sdl/src/video/nanox/SDL_nxmouse_c.h | |||
@@ -0,0 +1,29 @@ | |||
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_nxvideo.h" | ||
25 | |||
26 | extern WMcursor * NX_CreateWMCursor (_THIS, Uint8 * data, Uint8 * mask, int w, int h, int hot_x, int hot_y) ; | ||
27 | void NX_FreeWMCursor (_THIS, WMcursor * cursor) ; | ||
28 | extern void NX_WarpWMCursor (_THIS, Uint16 x, Uint16 y) ; | ||
29 | extern int NX_ShowWMCursor (_THIS, WMcursor * cursor) ; | ||
diff --git a/apps/plugins/sdl/src/video/nanox/SDL_nxvideo.c b/apps/plugins/sdl/src/video/nanox/SDL_nxvideo.c new file mode 100644 index 0000000000..b188e09581 --- /dev/null +++ b/apps/plugins/sdl/src/video/nanox/SDL_nxvideo.c | |||
@@ -0,0 +1,544 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | Copyright (C) 2001 Hsieh-Fu Tsai | ||
5 | Copyright (C) 2002 Greg Haerr <greg@censoft.com> | ||
6 | |||
7 | This library is free software; you can redistribute it and/or | ||
8 | modify it under the terms of the GNU Library General Public | ||
9 | License as published by the Free Software Foundation; either | ||
10 | version 2 of the License, or (at your option) any later version. | ||
11 | |||
12 | This library is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | Library General Public License for more details. | ||
16 | |||
17 | You should have received a copy of the GNU Library General Public | ||
18 | License along with this library; if not, write to the Free | ||
19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | |||
21 | Sam Lantinga | ||
22 | slouken@libsdl.org | ||
23 | |||
24 | Hsieh-Fu Tsai | ||
25 | clare@setabox.com | ||
26 | */ | ||
27 | #include "SDL_config.h" | ||
28 | |||
29 | #include "SDL_thread.h" | ||
30 | #include "SDL_video.h" | ||
31 | #include "../SDL_pixels_c.h" | ||
32 | #include "../../events/SDL_events_c.h" | ||
33 | |||
34 | #define MWINCLUDECOLORS | ||
35 | #include "SDL_nxvideo.h" | ||
36 | #include "SDL_nxmodes_c.h" | ||
37 | #include "SDL_nxwm_c.h" | ||
38 | #include "SDL_nxmouse_c.h" | ||
39 | #include "SDL_nximage_c.h" | ||
40 | #include "SDL_nxevents_c.h" | ||
41 | |||
42 | // Initialization/Query functions | ||
43 | static int NX_VideoInit (_THIS, SDL_PixelFormat * vformat) ; | ||
44 | static SDL_Surface * NX_SetVideoMode (_THIS, SDL_Surface * current, int width, int height, int bpp, Uint32 flags) ; | ||
45 | static int NX_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) ; | ||
46 | static void NX_VideoQuit (_THIS) ; | ||
47 | static void NX_DestroyWindow (_THIS, SDL_Surface * screen) ; | ||
48 | static int NX_ToggleFullScreen (_THIS, int on) ; | ||
49 | static void NX_UpdateMouse (_THIS) ; | ||
50 | static int NX_SetGammaRamp (_THIS, Uint16 * ramp) ; | ||
51 | static int NX_GetGammaRamp (_THIS, Uint16 * ramp) ; | ||
52 | |||
53 | // Microwin driver bootstrap functions | ||
54 | static int NX_Available () | ||
55 | { | ||
56 | Dprintf ("enter NX_Available\n") ; | ||
57 | |||
58 | if (GrOpen () < 0) return 0 ; | ||
59 | GrClose () ; | ||
60 | |||
61 | Dprintf ("leave NX_Available\n") ; | ||
62 | return 1 ; | ||
63 | } | ||
64 | |||
65 | static void NX_DeleteDevice (SDL_VideoDevice * device) | ||
66 | { | ||
67 | Dprintf ("enter NX_DeleteDevice\n") ; | ||
68 | |||
69 | if (device) { | ||
70 | if (device -> hidden) SDL_free (device -> hidden) ; | ||
71 | if (device -> gl_data) SDL_free (device -> gl_data) ; | ||
72 | SDL_free (device) ; | ||
73 | } | ||
74 | |||
75 | Dprintf ("leave NX_DeleteDevice\n") ; | ||
76 | } | ||
77 | |||
78 | static SDL_VideoDevice * NX_CreateDevice (int devindex) | ||
79 | { | ||
80 | SDL_VideoDevice * device ; | ||
81 | |||
82 | Dprintf ("enter NX_CreateDevice\n") ; | ||
83 | |||
84 | // Initialize all variables that we clean on shutdown | ||
85 | device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)) ; | ||
86 | if (device) { | ||
87 | SDL_memset (device, 0, (sizeof * device)) ; | ||
88 | device -> hidden = (struct SDL_PrivateVideoData *) | ||
89 | SDL_malloc ((sizeof * device -> hidden)) ; | ||
90 | device -> gl_data = NULL ; | ||
91 | } | ||
92 | if ((device == NULL) || (device -> hidden == NULL)) { | ||
93 | SDL_OutOfMemory () ; | ||
94 | NX_DeleteDevice (device) ; | ||
95 | return 0 ; | ||
96 | } | ||
97 | SDL_memset (device -> hidden, 0, (sizeof * device -> hidden)) ; | ||
98 | |||
99 | // Set the function pointers | ||
100 | device -> VideoInit = NX_VideoInit ; | ||
101 | device -> ListModes = NX_ListModes ; | ||
102 | device -> SetVideoMode = NX_SetVideoMode ; | ||
103 | device -> ToggleFullScreen = NX_ToggleFullScreen ; | ||
104 | device -> UpdateMouse = NX_UpdateMouse ; | ||
105 | device -> CreateYUVOverlay = NULL ; | ||
106 | device -> SetColors = NX_SetColors ; | ||
107 | device -> UpdateRects = NULL ; | ||
108 | device -> VideoQuit = NX_VideoQuit; | ||
109 | device -> AllocHWSurface = NULL ; | ||
110 | device -> CheckHWBlit = NULL ; | ||
111 | device -> FillHWRect = NULL ; | ||
112 | device -> SetHWColorKey = NULL ; | ||
113 | device -> SetHWAlpha = NULL ; | ||
114 | device -> LockHWSurface = NULL ; | ||
115 | device -> UnlockHWSurface = NULL ; | ||
116 | device -> FlipHWSurface = NULL ; | ||
117 | device -> FreeHWSurface = NULL ; | ||
118 | device -> SetGamma = NULL ; | ||
119 | device -> GetGamma = NULL ; | ||
120 | device -> SetGammaRamp = NX_SetGammaRamp ; | ||
121 | device -> GetGammaRamp = NX_GetGammaRamp ; | ||
122 | |||
123 | #if SDL_VIDEO_OPENGL | ||
124 | device -> GL_LoadLibrary = NULL ; | ||
125 | device -> GL_GetProcAddress = NULL ; | ||
126 | device -> GL_GetAttribute = NULL ; | ||
127 | device -> GL_MakeCurrent = NULL ; | ||
128 | device -> GL_SwapBuffers = NULL ; | ||
129 | #endif | ||
130 | |||
131 | device -> SetIcon = NULL ; | ||
132 | device -> SetCaption = NX_SetCaption; | ||
133 | device -> IconifyWindow = NULL ; | ||
134 | device -> GrabInput = NULL ; | ||
135 | device -> GetWMInfo = NX_GetWMInfo ; | ||
136 | device -> FreeWMCursor = NX_FreeWMCursor ; | ||
137 | device -> CreateWMCursor = NX_CreateWMCursor ; | ||
138 | device -> ShowWMCursor = NX_ShowWMCursor ; | ||
139 | device -> WarpWMCursor = NX_WarpWMCursor ; | ||
140 | device -> CheckMouseMode = NULL ; | ||
141 | device -> InitOSKeymap = NX_InitOSKeymap ; | ||
142 | device -> PumpEvents = NX_PumpEvents ; | ||
143 | |||
144 | device -> free = NX_DeleteDevice ; | ||
145 | |||
146 | Dprintf ("leave NX_CreateDevice\n") ; | ||
147 | return device ; | ||
148 | } | ||
149 | |||
150 | VideoBootStrap NX_bootstrap = { | ||
151 | "nanox", "nanox", NX_Available, NX_CreateDevice | ||
152 | } ; | ||
153 | |||
154 | static void create_aux_windows (_THIS) | ||
155 | { | ||
156 | GR_WM_PROPERTIES props ; | ||
157 | |||
158 | Dprintf ("enter create_aux_windows\n") ; | ||
159 | |||
160 | // Don't create any extra windows if we are being managed | ||
161 | if (SDL_windowid) { | ||
162 | FSwindow = 0 ; | ||
163 | return ; | ||
164 | } | ||
165 | |||
166 | if (FSwindow && FSwindow != GR_ROOT_WINDOW_ID) { | ||
167 | GrDestroyWindow (FSwindow) ; | ||
168 | } | ||
169 | |||
170 | FSwindow = GrNewWindow (GR_ROOT_WINDOW_ID, 0, 0, 1, 1, 0, BLACK, BLACK) ; | ||
171 | props.flags = GR_WM_FLAGS_PROPS ; | ||
172 | props.props = GR_WM_PROPS_NODECORATE ; | ||
173 | GrSetWMProperties (FSwindow, & props) ; | ||
174 | |||
175 | GrSelectEvents (FSwindow, (GR_EVENT_MASK_EXPOSURE | | ||
176 | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP | | ||
177 | GR_EVENT_MASK_FOCUS_IN | GR_EVENT_MASK_FOCUS_OUT | | ||
178 | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP | | ||
179 | GR_EVENT_MASK_MOUSE_ENTER | GR_EVENT_MASK_MOUSE_EXIT | | ||
180 | GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_UPDATE | | ||
181 | GR_EVENT_MASK_CLOSE_REQ)) ; | ||
182 | |||
183 | Dprintf ("leave create_aux_windows\n") ; | ||
184 | } | ||
185 | |||
186 | int NX_VideoInit (_THIS, SDL_PixelFormat * vformat) | ||
187 | { | ||
188 | GR_SCREEN_INFO si ; | ||
189 | |||
190 | Dprintf ("enter NX_VideoInit\n") ; | ||
191 | |||
192 | if (GrOpen () < 0) { | ||
193 | SDL_SetError ("GrOpen() fail") ; | ||
194 | return -1 ; | ||
195 | } | ||
196 | |||
197 | // use share memory to speed up | ||
198 | #ifdef NANOX_SHARE_MEMORY | ||
199 | GrReqShmCmds (0xFFFF); | ||
200 | #endif | ||
201 | |||
202 | SDL_Window = 0 ; | ||
203 | FSwindow = 0 ; | ||
204 | |||
205 | GammaRamp_R = NULL ; | ||
206 | GammaRamp_G = NULL ; | ||
207 | GammaRamp_B = NULL ; | ||
208 | |||
209 | GrGetScreenInfo (& si) ; | ||
210 | SDL_Visual.bpp = si.bpp ; | ||
211 | |||
212 | /* Determine the current screen size */ | ||
213 | this->info.current_w = si.cols ; | ||
214 | this->info.current_h = si.rows ; | ||
215 | |||
216 | // GetVideoMode | ||
217 | SDL_modelist = (SDL_Rect **) SDL_malloc (sizeof (SDL_Rect *) * 2) ; | ||
218 | if (SDL_modelist) { | ||
219 | SDL_modelist [0] = (SDL_Rect *) SDL_malloc (sizeof(SDL_Rect)) ; | ||
220 | if (SDL_modelist [0]) { | ||
221 | SDL_modelist [0] -> x = 0 ; | ||
222 | SDL_modelist [0] -> y = 0 ; | ||
223 | SDL_modelist [0] -> w = si.cols ; | ||
224 | SDL_modelist [0] -> h = si.rows ; | ||
225 | } | ||
226 | SDL_modelist [1] = NULL ; | ||
227 | } | ||
228 | |||
229 | pixel_type = si.pixtype; | ||
230 | SDL_Visual.red_mask = si.rmask; | ||
231 | SDL_Visual.green_mask = si.gmask; | ||
232 | SDL_Visual.blue_mask = si.bmask; | ||
233 | |||
234 | vformat -> BitsPerPixel = SDL_Visual.bpp ; | ||
235 | if (vformat -> BitsPerPixel > 8) { | ||
236 | vformat -> Rmask = SDL_Visual.red_mask ; | ||
237 | vformat -> Gmask = SDL_Visual.green_mask ; | ||
238 | vformat -> Bmask = SDL_Visual.blue_mask ; | ||
239 | } | ||
240 | |||
241 | // See if we have been passed a window to use | ||
242 | SDL_windowid = getenv ("SDL_WINDOWID") ; | ||
243 | |||
244 | // Create the fullscreen (and managed windows : no implement) | ||
245 | create_aux_windows (this) ; | ||
246 | |||
247 | Dprintf ("leave NX_VideoInit\n") ; | ||
248 | return 0 ; | ||
249 | } | ||
250 | |||
251 | void NX_VideoQuit (_THIS) | ||
252 | { | ||
253 | Dprintf ("enter NX_VideoQuit\n") ; | ||
254 | |||
255 | // Start shutting down the windows | ||
256 | NX_DestroyImage (this, this -> screen) ; | ||
257 | NX_DestroyWindow (this, this -> screen) ; | ||
258 | if (FSwindow && FSwindow != GR_ROOT_WINDOW_ID) { | ||
259 | GrDestroyWindow (FSwindow) ; | ||
260 | } | ||
261 | NX_FreeVideoModes (this) ; | ||
262 | SDL_free (GammaRamp_R) ; | ||
263 | SDL_free (GammaRamp_G) ; | ||
264 | SDL_free (GammaRamp_B) ; | ||
265 | |||
266 | #ifdef ENABLE_NANOX_DIRECT_FB | ||
267 | if (Clientfb) | ||
268 | GrCloseClientFramebuffer(); | ||
269 | #endif | ||
270 | GrClose () ; | ||
271 | |||
272 | Dprintf ("leave NX_VideoQuit\n") ; | ||
273 | } | ||
274 | |||
275 | static void NX_DestroyWindow (_THIS, SDL_Surface * screen) | ||
276 | { | ||
277 | Dprintf ("enter NX_DestroyWindow\n") ; | ||
278 | |||
279 | if (! SDL_windowid) { | ||
280 | if (screen && (screen -> flags & SDL_FULLSCREEN)) { | ||
281 | screen -> flags &= ~ SDL_FULLSCREEN ; | ||
282 | NX_LeaveFullScreen (this) ; | ||
283 | } | ||
284 | |||
285 | // Destroy the output window | ||
286 | if (SDL_Window && SDL_Window != GR_ROOT_WINDOW_ID) { | ||
287 | GrDestroyWindow (SDL_Window) ; | ||
288 | } | ||
289 | } | ||
290 | |||
291 | // Free the graphics context | ||
292 | if (! SDL_GC) { | ||
293 | GrDestroyGC (SDL_GC) ; | ||
294 | SDL_GC = 0; | ||
295 | } | ||
296 | |||
297 | Dprintf ("leave NX_DestroyWindow\n") ; | ||
298 | } | ||
299 | |||
300 | static int NX_CreateWindow (_THIS, SDL_Surface * screen, | ||
301 | int w, int h, int bpp, Uint32 flags) | ||
302 | { | ||
303 | Dprintf ("enter NX_CreateWindow\n") ; | ||
304 | |||
305 | // If a window is already present, destroy it and start fresh | ||
306 | if (SDL_Window && SDL_Window != GR_ROOT_WINDOW_ID) { | ||
307 | NX_DestroyWindow (this, screen) ; | ||
308 | } | ||
309 | |||
310 | // See if we have been given a window id | ||
311 | if (SDL_windowid) { | ||
312 | SDL_Window = SDL_strtol (SDL_windowid, NULL, 0) ; | ||
313 | } else { | ||
314 | SDL_Window = 0 ; | ||
315 | } | ||
316 | |||
317 | if ( ! SDL_ReallocFormat (screen, bpp, SDL_Visual.red_mask, | ||
318 | SDL_Visual.green_mask, SDL_Visual.blue_mask, 0)) | ||
319 | return -1; | ||
320 | |||
321 | // Create (or use) the nanox display window | ||
322 | if (! SDL_windowid) { | ||
323 | |||
324 | SDL_Window = GrNewWindow (GR_ROOT_WINDOW_ID, 0, 0, w, h, 0, BLACK, WHITE) ; | ||
325 | |||
326 | GrSelectEvents (SDL_Window, (GR_EVENT_MASK_EXPOSURE | | ||
327 | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP | | ||
328 | GR_EVENT_MASK_FOCUS_IN | GR_EVENT_MASK_FOCUS_OUT | | ||
329 | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP | | ||
330 | GR_EVENT_MASK_MOUSE_ENTER | GR_EVENT_MASK_MOUSE_EXIT | | ||
331 | GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_UPDATE | | ||
332 | GR_EVENT_MASK_CLOSE_REQ)) ; | ||
333 | } | ||
334 | |||
335 | /* Create the graphics context here, once we have a window */ | ||
336 | SDL_GC = GrNewGC () ; | ||
337 | if (SDL_GC == 0) { | ||
338 | SDL_SetError("Couldn't create graphics context"); | ||
339 | return(-1); | ||
340 | } | ||
341 | |||
342 | // Map them both and go fullscreen, if requested | ||
343 | if (! SDL_windowid) { | ||
344 | GrMapWindow (SDL_Window) ; | ||
345 | if (flags & SDL_FULLSCREEN) { | ||
346 | screen -> flags |= SDL_FULLSCREEN ; | ||
347 | NX_EnterFullScreen (this) ; | ||
348 | } else { | ||
349 | screen -> flags &= ~ SDL_FULLSCREEN ; | ||
350 | } | ||
351 | } | ||
352 | |||
353 | #ifdef ENABLE_NANOX_DIRECT_FB | ||
354 | /* attempt allocating the client side framebuffer */ | ||
355 | Clientfb = GrOpenClientFramebuffer(); | ||
356 | /* NULL return will default to using GrArea()*/ | ||
357 | #endif | ||
358 | |||
359 | Dprintf ("leave NX_CreateWindow\n") ; | ||
360 | return 0 ; | ||
361 | } | ||
362 | |||
363 | SDL_Surface * NX_SetVideoMode (_THIS, SDL_Surface * current, | ||
364 | int width, int height, int bpp, Uint32 flags) | ||
365 | { | ||
366 | Dprintf ("enter NX_SetVideoMode\n") ; | ||
367 | |||
368 | // Lock the event thread, in multi-threading environments | ||
369 | SDL_Lock_EventThread () ; | ||
370 | |||
371 | bpp = SDL_Visual.bpp ; | ||
372 | if (NX_CreateWindow (this, current, width, height, bpp, flags) < 0) { | ||
373 | current = NULL; | ||
374 | goto done; | ||
375 | } | ||
376 | |||
377 | if (current -> w != width || current -> h != height) { | ||
378 | current -> w = width ; | ||
379 | current -> h = height ; | ||
380 | current -> pitch = SDL_CalculatePitch (current) ; | ||
381 | NX_ResizeImage (this, current, flags) ; | ||
382 | } | ||
383 | |||
384 | /* Clear these flags and set them only if they are in the new set. */ | ||
385 | current -> flags &= ~(SDL_RESIZABLE|SDL_NOFRAME); | ||
386 | current -> flags |= (flags & (SDL_RESIZABLE | SDL_NOFRAME)) ; | ||
387 | |||
388 | done: | ||
389 | SDL_Unlock_EventThread () ; | ||
390 | |||
391 | Dprintf ("leave NX_SetVideoMode\n") ; | ||
392 | |||
393 | // We're done! | ||
394 | return current ; | ||
395 | } | ||
396 | |||
397 | // ncolors <= 256 | ||
398 | int NX_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) | ||
399 | { | ||
400 | int i ; | ||
401 | GR_PALETTE pal ; | ||
402 | |||
403 | Dprintf ("enter NX_SetColors\n") ; | ||
404 | |||
405 | if (ncolors > 256) return 0 ; | ||
406 | |||
407 | pal.count = ncolors ; | ||
408 | for (i = 0; i < ncolors; ++ i) { | ||
409 | pal.palette [i].r = colors [i].r ; | ||
410 | pal.palette [i].g = colors [i].g ; | ||
411 | pal.palette [i].b = colors [i].b ; | ||
412 | } | ||
413 | GrSetSystemPalette (firstcolor, & pal) ; | ||
414 | |||
415 | Dprintf ("leave NX_SetColors\n") ; | ||
416 | return 1 ; | ||
417 | } | ||
418 | |||
419 | static int NX_ToggleFullScreen (_THIS, int on) | ||
420 | { | ||
421 | SDL_Rect rect ; | ||
422 | Uint32 event_thread ; | ||
423 | |||
424 | Dprintf ("enter NX_ToggleFullScreen\n") ; | ||
425 | |||
426 | // Don't switch if we don't own the window | ||
427 | if (SDL_windowid) return 0 ; | ||
428 | |||
429 | // Don't lock if we are the event thread | ||
430 | event_thread = SDL_EventThreadID () ; | ||
431 | if (event_thread && (SDL_ThreadID () == event_thread)) { | ||
432 | event_thread = 0 ; | ||
433 | } | ||
434 | if (event_thread) { | ||
435 | SDL_Lock_EventThread() ; | ||
436 | } | ||
437 | |||
438 | if (on) { | ||
439 | NX_EnterFullScreen (this) ; | ||
440 | } else { | ||
441 | this -> screen -> flags &= ~ SDL_FULLSCREEN ; | ||
442 | NX_LeaveFullScreen (this) ; | ||
443 | } | ||
444 | |||
445 | rect.x = rect.y = 0 ; | ||
446 | rect.w = this -> screen -> w, rect.h = this -> screen -> h ; | ||
447 | NX_NormalUpdate (this, 1, & rect) ; | ||
448 | |||
449 | if (event_thread) { | ||
450 | SDL_Unlock_EventThread () ; | ||
451 | } | ||
452 | |||
453 | Dprintf ("leave NX_ToggleFullScreen\n") ; | ||
454 | return 1 ; | ||
455 | } | ||
456 | |||
457 | // Update the current mouse state and position | ||
458 | static void NX_UpdateMouse (_THIS) | ||
459 | { | ||
460 | int x, y ; | ||
461 | GR_WINDOW_INFO info ; | ||
462 | GR_SCREEN_INFO si ; | ||
463 | |||
464 | |||
465 | Dprintf ("enter NX_UpdateMouse\n") ; | ||
466 | |||
467 | // Lock the event thread, in multi-threading environments | ||
468 | SDL_Lock_EventThread () ; | ||
469 | |||
470 | GrGetScreenInfo (& si) ; | ||
471 | GrGetWindowInfo (SDL_Window, & info) ; | ||
472 | x = si.xpos - info.x ; | ||
473 | y = si.ypos - info.y ; | ||
474 | if (x >= 0 && x <= info.width && y >= 0 && y <= info.height) { | ||
475 | SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS) ; | ||
476 | SDL_PrivateMouseMotion (0, 0, x, y); | ||
477 | } else { | ||
478 | SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS) ; | ||
479 | } | ||
480 | |||
481 | SDL_Unlock_EventThread () ; | ||
482 | Dprintf ("leave NX_UpdateMouse\n") ; | ||
483 | } | ||
484 | |||
485 | static int NX_SetGammaRamp (_THIS, Uint16 * ramp) | ||
486 | { | ||
487 | int i ; | ||
488 | Uint16 * red, * green, * blue ; | ||
489 | |||
490 | Dprintf ("enter NX_SetGammaRamp\n") ; | ||
491 | |||
492 | if (SDL_Visual.bpp != 32 && SDL_Visual.bpp != 24) return -1 ; | ||
493 | |||
494 | if (! GammaRamp_R) GammaRamp_R = (Uint16 *) SDL_malloc (sizeof (Uint16) * CI_SIZE) ; | ||
495 | if (! GammaRamp_G) GammaRamp_G = (Uint16 *) SDL_malloc (sizeof (Uint16) * CI_SIZE) ; | ||
496 | if (! GammaRamp_B) GammaRamp_B = (Uint16 *) SDL_malloc (sizeof (Uint16) * CI_SIZE) ; | ||
497 | if ((! GammaRamp_R) || (! GammaRamp_G) || (! GammaRamp_B)) { | ||
498 | SDL_OutOfMemory () ; | ||
499 | return -1 ; | ||
500 | } | ||
501 | |||
502 | for (i = 0; i < CI_SIZE; ++ i) | ||
503 | GammaRamp_R [i] = GammaRamp_G [i] = GammaRamp_B [i] = i ; | ||
504 | |||
505 | red = ramp ; | ||
506 | green = ramp + CI_SIZE ; | ||
507 | blue = green + CI_SIZE ; | ||
508 | |||
509 | for (i = 0; i < CI_SIZE; ++ i) { | ||
510 | GammaRamp_R [i] = red [i] ; | ||
511 | GammaRamp_G [i] = green [i] ; | ||
512 | GammaRamp_B [i] = blue [i] ; | ||
513 | } | ||
514 | SDL_UpdateRect(this->screen, 0, 0, 0, 0); | ||
515 | |||
516 | Dprintf ("leave NX_SetGammaRamp\n") ; | ||
517 | return 0 ; | ||
518 | } | ||
519 | |||
520 | static int NX_GetGammaRamp (_THIS, Uint16 * ramp) | ||
521 | { | ||
522 | int i ; | ||
523 | Uint16 * red, * green, * blue ; | ||
524 | |||
525 | Dprintf ("enter NX_GetGammaRamp\n") ; | ||
526 | |||
527 | if (SDL_Visual.bpp != 32 && SDL_Visual.bpp != 24) return -1 ; | ||
528 | red = ramp ; | ||
529 | green = ramp + CI_SIZE ; | ||
530 | blue = green + CI_SIZE ; | ||
531 | if (GammaRamp_R && GammaRamp_G && GammaRamp_B) { | ||
532 | for (i = 0; i < CI_SIZE; ++ i) { | ||
533 | red [i] = GammaRamp_R [i] ; | ||
534 | green [i] = GammaRamp_G [i] ; | ||
535 | blue [i] = GammaRamp_B [i] ; | ||
536 | } | ||
537 | } else { | ||
538 | for (i = 0; i < CI_SIZE; ++ i) | ||
539 | red [i] = green [i] = blue [i] = i ; | ||
540 | } | ||
541 | |||
542 | Dprintf ("leave NX_GetGammaRamp\n") ; | ||
543 | return 0 ; | ||
544 | } | ||
diff --git a/apps/plugins/sdl/src/video/nanox/SDL_nxvideo.h b/apps/plugins/sdl/src/video/nanox/SDL_nxvideo.h new file mode 100644 index 0000000000..1d858d96f2 --- /dev/null +++ b/apps/plugins/sdl/src/video/nanox/SDL_nxvideo.h | |||
@@ -0,0 +1,96 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | Copyright (C) 2001 Hsieh-Fu Tsai | ||
5 | |||
6 | This library is free software; you can redistribute it and/or | ||
7 | modify it under the terms of the GNU Library General Public | ||
8 | License as published by the Free Software Foundation; either | ||
9 | version 2 of the License, or (at your option) any later version. | ||
10 | |||
11 | This library is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | Library General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU Library General Public | ||
17 | License along with this library; if not, write to the Free | ||
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | |||
20 | Sam Lantinga | ||
21 | slouken@libsdl.org | ||
22 | |||
23 | Hsieh-Fu Tsai | ||
24 | clare@setabox.com | ||
25 | */ | ||
26 | #include "SDL_config.h" | ||
27 | |||
28 | #ifndef _SDL_nxvideo_h | ||
29 | #define _SDL_nxvideo_h | ||
30 | |||
31 | #include <microwin/nano-X.h> | ||
32 | |||
33 | #include "../SDL_sysvideo.h" | ||
34 | |||
35 | #ifdef ENABLE_NANOX_DEBUG | ||
36 | #define Dprintf printf | ||
37 | #else | ||
38 | #define Dprintf(ignore...) | ||
39 | #endif | ||
40 | |||
41 | // Hidden "this" pointer for the video functions | ||
42 | #define _THIS SDL_VideoDevice * this | ||
43 | |||
44 | // Private display data | ||
45 | typedef struct NX_SDL_VISUAL { | ||
46 | int bpp ; | ||
47 | Uint32 red_mask ; | ||
48 | Uint32 green_mask ; | ||
49 | Uint32 blue_mask ; | ||
50 | } nx_sdl_visual_t ; | ||
51 | |||
52 | struct SDL_PrivateVideoData { | ||
53 | GR_WINDOW_ID SDL_Window ; | ||
54 | GR_WINDOW_ID FSwindow ; | ||
55 | // Flag: true if we have been passed a window | ||
56 | char * SDL_windowid ; | ||
57 | GR_GC_ID GC ; | ||
58 | unsigned char * Image ; | ||
59 | unsigned char * Image_buff ; /* for GrArea*/ | ||
60 | unsigned char * Clientfb; /* for DirectFB*/ | ||
61 | nx_sdl_visual_t SDL_Visual ; | ||
62 | // The current list of available video modes | ||
63 | SDL_Rect ** modelist ; | ||
64 | int currently_fullscreen ; | ||
65 | // for fullscreen | ||
66 | int OffsetX, OffsetY ; | ||
67 | // for GammaRamp | ||
68 | Uint16 * GammaRamp_R, * GammaRamp_G, * GammaRamp_B ; | ||
69 | // for GrArea, r_mask, g_mask, b_mask | ||
70 | int pixel_type ; | ||
71 | #ifdef ENABLE_NANOX_DIRECT_FB | ||
72 | GR_WINDOW_FB_INFO fbinfo; | ||
73 | #endif | ||
74 | } ; | ||
75 | |||
76 | #define SDL_Window (this -> hidden -> SDL_Window) | ||
77 | #define FSwindow (this -> hidden -> FSwindow) | ||
78 | #define SDL_windowid (this -> hidden -> SDL_windowid) | ||
79 | #define SDL_GC (this -> hidden -> GC) | ||
80 | #define SDL_Image (this -> hidden -> Image) | ||
81 | #define Image_buff (this -> hidden -> Image_buff) | ||
82 | #define Clientfb (this -> hidden -> Clientfb) | ||
83 | #define SDL_Visual (this -> hidden -> SDL_Visual) | ||
84 | #define SDL_modelist (this -> hidden -> modelist) | ||
85 | #define currently_fullscreen (this -> hidden -> currently_fullscreen) | ||
86 | #define OffsetX (this -> hidden -> OffsetX) | ||
87 | #define OffsetY (this -> hidden -> OffsetY) | ||
88 | #define GammaRamp_R (this -> hidden -> GammaRamp_R) | ||
89 | #define GammaRamp_G (this -> hidden -> GammaRamp_G) | ||
90 | #define GammaRamp_B (this -> hidden -> GammaRamp_B) | ||
91 | #define pixel_type (this -> hidden -> pixel_type) | ||
92 | #define fbinfo (this -> hidden -> fbinfo) | ||
93 | |||
94 | #define CI_SIZE 256 // color index size | ||
95 | |||
96 | #endif // _SDL_nxvideo_h | ||
diff --git a/apps/plugins/sdl/src/video/nanox/SDL_nxwm.c b/apps/plugins/sdl/src/video/nanox/SDL_nxwm.c new file mode 100644 index 0000000000..c60ebb0461 --- /dev/null +++ b/apps/plugins/sdl/src/video/nanox/SDL_nxwm.c | |||
@@ -0,0 +1,61 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | Copyright (C) 2001 Hsieh-Fu Tsai | ||
5 | |||
6 | This library is free software; you can redistribute it and/or | ||
7 | modify it under the terms of the GNU Library General Public | ||
8 | License as published by the Free Software Foundation; either | ||
9 | version 2 of the License, or (at your option) any later version. | ||
10 | |||
11 | This library is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | Library General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU Library General Public | ||
17 | License along with this library; if not, write to the Free | ||
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | |||
20 | Sam Lantinga | ||
21 | slouken@libsdl.org | ||
22 | |||
23 | Hsieh-Fu Tsai | ||
24 | clare@setabox.com | ||
25 | */ | ||
26 | #include "SDL_config.h" | ||
27 | |||
28 | #include "SDL_syswm.h" | ||
29 | #include "../../events/SDL_events_c.h" | ||
30 | |||
31 | #include "SDL_nxwm_c.h" | ||
32 | |||
33 | void NX_SetCaption (_THIS, const char * title, const char * icon) | ||
34 | { | ||
35 | Dprintf ("enter NX_SetCaption\n") ; | ||
36 | |||
37 | // Lock the event thread, in multi-threading environments | ||
38 | SDL_Lock_EventThread () ; | ||
39 | |||
40 | if (SDL_Window) | ||
41 | GrSetWindowTitle (SDL_Window, title) ; | ||
42 | |||
43 | SDL_Unlock_EventThread () ; | ||
44 | Dprintf ("leave NX_SetCaption\n") ; | ||
45 | } | ||
46 | |||
47 | int NX_GetWMInfo (_THIS, SDL_SysWMinfo * info) | ||
48 | { | ||
49 | Dprintf ("enter NX_GetWMInfo\n") ; | ||
50 | |||
51 | if (info -> version.major <= SDL_MAJOR_VERSION) { | ||
52 | info -> window = SDL_Window ; | ||
53 | return 1 ; | ||
54 | } else { | ||
55 | SDL_SetError("Application not compiled with SDL %d.%d\n", | ||
56 | SDL_MAJOR_VERSION, SDL_MINOR_VERSION) ; | ||
57 | return -1 ; | ||
58 | } | ||
59 | |||
60 | Dprintf ("leave NX_GetWMInfo\n") ; | ||
61 | } | ||
diff --git a/apps/plugins/sdl/src/video/nanox/SDL_nxwm_c.h b/apps/plugins/sdl/src/video/nanox/SDL_nxwm_c.h new file mode 100644 index 0000000000..77be794f2c --- /dev/null +++ b/apps/plugins/sdl/src/video/nanox/SDL_nxwm_c.h | |||
@@ -0,0 +1,32 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | Copyright (C) 2001 Hsieh-Fu Tsai | ||
5 | |||
6 | This library is free software; you can redistribute it and/or | ||
7 | modify it under the terms of the GNU Library General Public | ||
8 | License as published by the Free Software Foundation; either | ||
9 | version 2 of the License, or (at your option) any later version. | ||
10 | |||
11 | This library is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | Library General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU Library General Public | ||
17 | License along with this library; if not, write to the Free | ||
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | |||
20 | Sam Lantinga | ||
21 | slouken@libsdl.org | ||
22 | |||
23 | Hsieh-Fu Tsai | ||
24 | clare@setabox.com | ||
25 | */ | ||
26 | #include "SDL_config.h" | ||
27 | |||
28 | #include "SDL_nxvideo.h" | ||
29 | |||
30 | // Functions to be exported | ||
31 | extern void NX_SetCaption (_THIS, const char * title, const char * icon) ; | ||
32 | extern int NX_GetWMInfo (_THIS, SDL_SysWMinfo * info) ; | ||