comparison src/video/nanox/SDL_nxvideo.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 8d9bb0cf2c2a
children 99210400e8b9
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
38 #include "SDL_nxmouse_c.h" 38 #include "SDL_nxmouse_c.h"
39 #include "SDL_nximage_c.h" 39 #include "SDL_nximage_c.h"
40 #include "SDL_nxevents_c.h" 40 #include "SDL_nxevents_c.h"
41 41
42 // Initialization/Query functions 42 // Initialization/Query functions
43 static int NX_VideoInit (_THIS, SDL_PixelFormat * vformat) ; 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) ; 44 static SDL_Surface *NX_SetVideoMode(_THIS, SDL_Surface * current, int width,
45 static int NX_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) ; 45 int height, int bpp, Uint32 flags);
46 static void NX_VideoQuit (_THIS) ; 46 static int NX_SetColors(_THIS, int firstcolor, int ncolors,
47 static void NX_DestroyWindow (_THIS, SDL_Surface * screen) ; 47 SDL_Color * colors);
48 static int NX_ToggleFullScreen (_THIS, int on) ; 48 static void NX_VideoQuit(_THIS);
49 static void NX_UpdateMouse (_THIS) ; 49 static void NX_DestroyWindow(_THIS, SDL_Surface * screen);
50 static int NX_SetGammaRamp (_THIS, Uint16 * ramp) ; 50 static int NX_ToggleFullScreen(_THIS, int on);
51 static int NX_GetGammaRamp (_THIS, Uint16 * ramp) ; 51 static void NX_UpdateMouse(_THIS);
52 static int NX_SetGammaRamp(_THIS, Uint16 * ramp);
53 static int NX_GetGammaRamp(_THIS, Uint16 * ramp);
52 54
53 // Microwin driver bootstrap functions 55 // Microwin driver bootstrap functions
54 static int NX_Available () 56 static int
55 { 57 NX_Available()
56 Dprintf ("enter NX_Available\n") ; 58 {
57 59 Dprintf("enter NX_Available\n");
58 if (GrOpen () < 0) return 0 ; 60
59 GrClose () ; 61 if (GrOpen() < 0)
60 62 return 0;
61 Dprintf ("leave NX_Available\n") ; 63 GrClose();
62 return 1 ; 64
63 } 65 Dprintf("leave NX_Available\n");
64 66 return 1;
65 static void NX_DeleteDevice (SDL_VideoDevice * device) 67 }
66 { 68
67 Dprintf ("enter NX_DeleteDevice\n") ; 69 static void
70 NX_DeleteDevice(SDL_VideoDevice * device)
71 {
72 Dprintf("enter NX_DeleteDevice\n");
68 73
69 if (device) { 74 if (device) {
70 if (device -> hidden) SDL_free (device -> hidden) ; 75 if (device->hidden)
71 if (device -> gl_data) SDL_free (device -> gl_data) ; 76 SDL_free(device->hidden);
72 SDL_free (device) ; 77 if (device->gl_data)
73 } 78 SDL_free(device->gl_data);
74 79 SDL_free(device);
75 Dprintf ("leave NX_DeleteDevice\n") ; 80 }
76 } 81
77 82 Dprintf("leave NX_DeleteDevice\n");
78 static SDL_VideoDevice * NX_CreateDevice (int devindex) 83 }
79 { 84
80 SDL_VideoDevice * device ; 85 static SDL_VideoDevice *
81 86 NX_CreateDevice(int devindex)
82 Dprintf ("enter NX_CreateDevice\n") ; 87 {
88 SDL_VideoDevice *device;
89
90 Dprintf("enter NX_CreateDevice\n");
83 91
84 // Initialize all variables that we clean on shutdown 92 // Initialize all variables that we clean on shutdown
85 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)) ; 93 device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
86 if (device) { 94 if (device) {
87 SDL_memset (device, 0, (sizeof * device)) ; 95 SDL_memset(device, 0, (sizeof *device));
88 device -> hidden = (struct SDL_PrivateVideoData *) 96 device->hidden = (struct SDL_PrivateVideoData *)
89 SDL_malloc ((sizeof * device -> hidden)) ; 97 SDL_malloc((sizeof *device->hidden));
90 device -> gl_data = NULL ; 98 device->gl_data = NULL;
91 } 99 }
92 if ((device == NULL) || (device -> hidden == NULL)) { 100 if ((device == NULL) || (device->hidden == NULL)) {
93 SDL_OutOfMemory () ; 101 SDL_OutOfMemory();
94 NX_DeleteDevice (device) ; 102 NX_DeleteDevice(device);
95 return 0 ; 103 return 0;
96 } 104 }
97 SDL_memset (device -> hidden, 0, (sizeof * device -> hidden)) ; 105 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
98 106
99 // Set the function pointers 107 // Set the function pointers
100 device -> VideoInit = NX_VideoInit ; 108 device->VideoInit = NX_VideoInit;
101 device -> ListModes = NX_ListModes ; 109 device->ListModes = NX_ListModes;
102 device -> SetVideoMode = NX_SetVideoMode ; 110 device->SetVideoMode = NX_SetVideoMode;
103 device -> ToggleFullScreen = NX_ToggleFullScreen ; 111 device->ToggleFullScreen = NX_ToggleFullScreen;
104 device -> UpdateMouse = NX_UpdateMouse ; 112 device->UpdateMouse = NX_UpdateMouse;
105 device -> CreateYUVOverlay = NULL ; 113 device->CreateYUVOverlay = NULL;
106 device -> SetColors = NX_SetColors ; 114 device->SetColors = NX_SetColors;
107 device -> UpdateRects = NULL ; 115 device->UpdateRects = NULL;
108 device -> VideoQuit = NX_VideoQuit; 116 device->VideoQuit = NX_VideoQuit;
109 device -> AllocHWSurface = NULL ; 117 device->AllocHWSurface = NULL;
110 device -> CheckHWBlit = NULL ; 118 device->CheckHWBlit = NULL;
111 device -> FillHWRect = NULL ; 119 device->FillHWRect = NULL;
112 device -> SetHWColorKey = NULL ; 120 device->SetHWColorKey = NULL;
113 device -> SetHWAlpha = NULL ; 121 device->SetHWAlpha = NULL;
114 device -> LockHWSurface = NULL ; 122 device->LockHWSurface = NULL;
115 device -> UnlockHWSurface = NULL ; 123 device->UnlockHWSurface = NULL;
116 device -> FlipHWSurface = NULL ; 124 device->FlipHWSurface = NULL;
117 device -> FreeHWSurface = NULL ; 125 device->FreeHWSurface = NULL;
118 device -> SetGamma = NULL ; 126 device->SetGamma = NULL;
119 device -> GetGamma = NULL ; 127 device->GetGamma = NULL;
120 device -> SetGammaRamp = NX_SetGammaRamp ; 128 device->SetGammaRamp = NX_SetGammaRamp;
121 device -> GetGammaRamp = NX_GetGammaRamp ; 129 device->GetGammaRamp = NX_GetGammaRamp;
122 130
123 #if SDL_VIDEO_OPENGL 131 #if SDL_VIDEO_OPENGL
124 device -> GL_LoadLibrary = NULL ; 132 device->GL_LoadLibrary = NULL;
125 device -> GL_GetProcAddress = NULL ; 133 device->GL_GetProcAddress = NULL;
126 device -> GL_GetAttribute = NULL ; 134 device->GL_GetAttribute = NULL;
127 device -> GL_MakeCurrent = NULL ; 135 device->GL_MakeCurrent = NULL;
128 device -> GL_SwapBuffers = NULL ; 136 device->GL_SwapBuffers = NULL;
129 #endif 137 #endif
130 138
131 device -> SetIcon = NULL ; 139 device->SetIcon = NULL;
132 device -> SetCaption = NX_SetCaption; 140 device->SetCaption = NX_SetCaption;
133 device -> IconifyWindow = NULL ; 141 device->IconifyWindow = NULL;
134 device -> GrabInput = NULL ; 142 device->GrabInput = NULL;
135 device -> GetWMInfo = NX_GetWMInfo ; 143 device->GetWMInfo = NX_GetWMInfo;
136 device -> FreeWMCursor = NX_FreeWMCursor ; 144 device->FreeWMCursor = NX_FreeWMCursor;
137 device -> CreateWMCursor = NX_CreateWMCursor ; 145 device->CreateWMCursor = NX_CreateWMCursor;
138 device -> ShowWMCursor = NX_ShowWMCursor ; 146 device->ShowWMCursor = NX_ShowWMCursor;
139 device -> WarpWMCursor = NX_WarpWMCursor ; 147 device->WarpWMCursor = NX_WarpWMCursor;
140 device -> CheckMouseMode = NULL ; 148 device->CheckMouseMode = NULL;
141 device -> InitOSKeymap = NX_InitOSKeymap ; 149 device->InitOSKeymap = NX_InitOSKeymap;
142 device -> PumpEvents = NX_PumpEvents ; 150 device->PumpEvents = NX_PumpEvents;
143 151
144 device -> free = NX_DeleteDevice ; 152 device->free = NX_DeleteDevice;
145 153
146 Dprintf ("leave NX_CreateDevice\n") ; 154 Dprintf("leave NX_CreateDevice\n");
147 return device ; 155 return device;
148 } 156 }
149 157
150 VideoBootStrap NX_bootstrap = { 158 VideoBootStrap NX_bootstrap = {
151 "nanox", "nanox", NX_Available, NX_CreateDevice 159 "nanox", "nanox", NX_Available, NX_CreateDevice
152 } ; 160 };
153 161
154 static void create_aux_windows (_THIS) 162 static void
155 { 163 create_aux_windows(_THIS)
156 GR_WM_PROPERTIES props ; 164 {
157 165 GR_WM_PROPERTIES props;
158 Dprintf ("enter create_aux_windows\n") ; 166
167 Dprintf("enter create_aux_windows\n");
159 168
160 // Don't create any extra windows if we are being managed 169 // Don't create any extra windows if we are being managed
161 if (SDL_windowid) { 170 if (SDL_windowid) {
162 FSwindow = 0 ; 171 FSwindow = 0;
163 return ; 172 return;
164 } 173 }
165 174
166 if (FSwindow && FSwindow != GR_ROOT_WINDOW_ID) { 175 if (FSwindow && FSwindow != GR_ROOT_WINDOW_ID) {
167 GrDestroyWindow (FSwindow) ; 176 GrDestroyWindow(FSwindow);
168 } 177 }
169 178
170 FSwindow = GrNewWindow (GR_ROOT_WINDOW_ID, 0, 0, 1, 1, 0, BLACK, BLACK) ; 179 FSwindow = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, 1, 1, 0, BLACK, BLACK);
171 props.flags = GR_WM_FLAGS_PROPS ; 180 props.flags = GR_WM_FLAGS_PROPS;
172 props.props = GR_WM_PROPS_NODECORATE ; 181 props.props = GR_WM_PROPS_NODECORATE;
173 GrSetWMProperties (FSwindow, & props) ; 182 GrSetWMProperties(FSwindow, &props);
174 183
175 GrSelectEvents (FSwindow, (GR_EVENT_MASK_EXPOSURE | 184 GrSelectEvents(FSwindow, (GR_EVENT_MASK_EXPOSURE |
176 GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP | 185 GR_EVENT_MASK_BUTTON_DOWN |
177 GR_EVENT_MASK_FOCUS_IN | GR_EVENT_MASK_FOCUS_OUT | 186 GR_EVENT_MASK_BUTTON_UP |
178 GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP | 187 GR_EVENT_MASK_FOCUS_IN |
179 GR_EVENT_MASK_MOUSE_ENTER | GR_EVENT_MASK_MOUSE_EXIT | 188 GR_EVENT_MASK_FOCUS_OUT |
180 GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_UPDATE | 189 GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP |
181 GR_EVENT_MASK_CLOSE_REQ)) ; 190 GR_EVENT_MASK_MOUSE_ENTER |
182 191 GR_EVENT_MASK_MOUSE_EXIT |
183 Dprintf ("leave create_aux_windows\n") ; 192 GR_EVENT_MASK_MOUSE_MOTION |
184 } 193 GR_EVENT_MASK_UPDATE |
185 194 GR_EVENT_MASK_CLOSE_REQ));
186 int NX_VideoInit (_THIS, SDL_PixelFormat * vformat) 195
187 { 196 Dprintf("leave create_aux_windows\n");
188 GR_SCREEN_INFO si ; 197 }
189 198
190 Dprintf ("enter NX_VideoInit\n") ; 199 int
191 200 NX_VideoInit(_THIS, SDL_PixelFormat * vformat)
192 if (GrOpen () < 0) { 201 {
193 SDL_SetError ("GrOpen() fail") ; 202 GR_SCREEN_INFO si;
194 return -1 ; 203
195 } 204 Dprintf("enter NX_VideoInit\n");
196 205
206 if (GrOpen() < 0) {
207 SDL_SetError("GrOpen() fail");
208 return -1;
209 }
197 // use share memory to speed up 210 // use share memory to speed up
198 #ifdef NANOX_SHARE_MEMORY 211 #ifdef NANOX_SHARE_MEMORY
199 GrReqShmCmds (0xFFFF); 212 GrReqShmCmds(0xFFFF);
200 #endif 213 #endif
201 214
202 SDL_Window = 0 ; 215 SDL_Window = 0;
203 FSwindow = 0 ; 216 FSwindow = 0;
204 217
205 GammaRamp_R = NULL ; 218 GammaRamp_R = NULL;
206 GammaRamp_G = NULL ; 219 GammaRamp_G = NULL;
207 GammaRamp_B = NULL ; 220 GammaRamp_B = NULL;
208 221
209 GrGetScreenInfo (& si) ; 222 GrGetScreenInfo(&si);
210 SDL_Visual.bpp = si.bpp ; 223 SDL_Visual.bpp = si.bpp;
211 224
212 /* Determine the current screen size */ 225 /* Determine the current screen size */
213 this->info.current_w = si.cols ; 226 this->info.current_w = si.cols;
214 this->info.current_h = si.rows ; 227 this->info.current_h = si.rows;
215 228
216 // GetVideoMode 229 // GetVideoMode
217 SDL_modelist = (SDL_Rect **) SDL_malloc (sizeof (SDL_Rect *) * 2) ; 230 SDL_modelist = (SDL_Rect **) SDL_malloc(sizeof(SDL_Rect *) * 2);
218 if (SDL_modelist) { 231 if (SDL_modelist) {
219 SDL_modelist [0] = (SDL_Rect *) SDL_malloc (sizeof(SDL_Rect)) ; 232 SDL_modelist[0] = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect));
220 if (SDL_modelist [0]) { 233 if (SDL_modelist[0]) {
221 SDL_modelist [0] -> x = 0 ; 234 SDL_modelist[0]->x = 0;
222 SDL_modelist [0] -> y = 0 ; 235 SDL_modelist[0]->y = 0;
223 SDL_modelist [0] -> w = si.cols ; 236 SDL_modelist[0]->w = si.cols;
224 SDL_modelist [0] -> h = si.rows ; 237 SDL_modelist[0]->h = si.rows;
225 } 238 }
226 SDL_modelist [1] = NULL ; 239 SDL_modelist[1] = NULL;
227 } 240 }
228 241
229 pixel_type = si.pixtype; 242 pixel_type = si.pixtype;
230 SDL_Visual.red_mask = si.rmask; 243 SDL_Visual.red_mask = si.rmask;
231 SDL_Visual.green_mask = si.gmask; 244 SDL_Visual.green_mask = si.gmask;
232 SDL_Visual.blue_mask = si.bmask; 245 SDL_Visual.blue_mask = si.bmask;
233 246
234 vformat -> BitsPerPixel = SDL_Visual.bpp ; 247 vformat->BitsPerPixel = SDL_Visual.bpp;
235 if (vformat -> BitsPerPixel > 8) { 248 if (vformat->BitsPerPixel > 8) {
236 vformat -> Rmask = SDL_Visual.red_mask ; 249 vformat->Rmask = SDL_Visual.red_mask;
237 vformat -> Gmask = SDL_Visual.green_mask ; 250 vformat->Gmask = SDL_Visual.green_mask;
238 vformat -> Bmask = SDL_Visual.blue_mask ; 251 vformat->Bmask = SDL_Visual.blue_mask;
239 } 252 }
240
241 // See if we have been passed a window to use 253 // See if we have been passed a window to use
242 SDL_windowid = getenv ("SDL_WINDOWID") ; 254 SDL_windowid = getenv("SDL_WINDOWID");
243 255
244 // Create the fullscreen (and managed windows : no implement) 256 // Create the fullscreen (and managed windows : no implement)
245 create_aux_windows (this) ; 257 create_aux_windows(this);
246 258
247 Dprintf ("leave NX_VideoInit\n") ; 259 Dprintf("leave NX_VideoInit\n");
248 return 0 ; 260 return 0;
249 } 261 }
250 262
251 void NX_VideoQuit (_THIS) 263 void
252 { 264 NX_VideoQuit(_THIS)
253 Dprintf ("enter NX_VideoQuit\n") ; 265 {
266 Dprintf("enter NX_VideoQuit\n");
254 267
255 // Start shutting down the windows 268 // Start shutting down the windows
256 NX_DestroyImage (this, this -> screen) ; 269 NX_DestroyImage(this, this->screen);
257 NX_DestroyWindow (this, this -> screen) ; 270 NX_DestroyWindow(this, this->screen);
258 if (FSwindow && FSwindow != GR_ROOT_WINDOW_ID) { 271 if (FSwindow && FSwindow != GR_ROOT_WINDOW_ID) {
259 GrDestroyWindow (FSwindow) ; 272 GrDestroyWindow(FSwindow);
260 } 273 }
261 NX_FreeVideoModes (this) ; 274 NX_FreeVideoModes(this);
262 SDL_free (GammaRamp_R) ; 275 SDL_free(GammaRamp_R);
263 SDL_free (GammaRamp_G) ; 276 SDL_free(GammaRamp_G);
264 SDL_free (GammaRamp_B) ; 277 SDL_free(GammaRamp_B);
265 278
266 #ifdef ENABLE_NANOX_DIRECT_FB 279 #ifdef ENABLE_NANOX_DIRECT_FB
267 if (Clientfb) 280 if (Clientfb)
268 GrCloseClientFramebuffer(); 281 GrCloseClientFramebuffer();
269 #endif 282 #endif
270 GrClose () ; 283 GrClose();
271 284
272 Dprintf ("leave NX_VideoQuit\n") ; 285 Dprintf("leave NX_VideoQuit\n");
273 } 286 }
274 287
275 static void NX_DestroyWindow (_THIS, SDL_Surface * screen) 288 static void
276 { 289 NX_DestroyWindow(_THIS, SDL_Surface * screen)
277 Dprintf ("enter NX_DestroyWindow\n") ; 290 {
278 291 Dprintf("enter NX_DestroyWindow\n");
279 if (! SDL_windowid) { 292
280 if (screen && (screen -> flags & SDL_FULLSCREEN)) { 293 if (!SDL_windowid) {
281 screen -> flags &= ~ SDL_FULLSCREEN ; 294 if (screen && (screen->flags & SDL_FULLSCREEN)) {
282 NX_LeaveFullScreen (this) ; 295 screen->flags &= ~SDL_FULLSCREEN;
296 NX_LeaveFullScreen(this);
283 } 297 }
284
285 // Destroy the output window 298 // Destroy the output window
286 if (SDL_Window && SDL_Window != GR_ROOT_WINDOW_ID) { 299 if (SDL_Window && SDL_Window != GR_ROOT_WINDOW_ID) {
287 GrDestroyWindow (SDL_Window) ; 300 GrDestroyWindow(SDL_Window);
288 } 301 }
289 } 302 }
290
291 // Free the graphics context 303 // Free the graphics context
292 if (! SDL_GC) { 304 if (!SDL_GC) {
293 GrDestroyGC (SDL_GC) ; 305 GrDestroyGC(SDL_GC);
294 SDL_GC = 0; 306 SDL_GC = 0;
295 } 307 }
296 308
297 Dprintf ("leave NX_DestroyWindow\n") ; 309 Dprintf("leave NX_DestroyWindow\n");
298 } 310 }
299 311
300 static int NX_CreateWindow (_THIS, SDL_Surface * screen, 312 static int
313 NX_CreateWindow(_THIS, SDL_Surface * screen,
301 int w, int h, int bpp, Uint32 flags) 314 int w, int h, int bpp, Uint32 flags)
302 { 315 {
303 Dprintf ("enter NX_CreateWindow\n") ; 316 Dprintf("enter NX_CreateWindow\n");
304 317
305 // If a window is already present, destroy it and start fresh 318 // If a window is already present, destroy it and start fresh
306 if (SDL_Window && SDL_Window != GR_ROOT_WINDOW_ID) { 319 if (SDL_Window && SDL_Window != GR_ROOT_WINDOW_ID) {
307 NX_DestroyWindow (this, screen) ; 320 NX_DestroyWindow(this, screen);
308 } 321 }
309
310 // See if we have been given a window id 322 // See if we have been given a window id
311 if (SDL_windowid) { 323 if (SDL_windowid) {
312 SDL_Window = SDL_strtol (SDL_windowid, NULL, 0) ; 324 SDL_Window = SDL_strtol(SDL_windowid, NULL, 0);
313 } else { 325 } else {
314 SDL_Window = 0 ; 326 SDL_Window = 0;
315 } 327 }
316 328
317 if ( ! SDL_ReallocFormat (screen, bpp, SDL_Visual.red_mask, 329 if (!SDL_ReallocFormat(screen, bpp, SDL_Visual.red_mask,
318 SDL_Visual.green_mask, SDL_Visual.blue_mask, 0)) 330 SDL_Visual.green_mask, SDL_Visual.blue_mask, 0))
319 return -1; 331 return -1;
320 332
321 // Create (or use) the nanox display window 333 // Create (or use) the nanox display window
322 if (! SDL_windowid) { 334 if (!SDL_windowid) {
323 335
324 SDL_Window = GrNewWindow (GR_ROOT_WINDOW_ID, 0, 0, w, h, 0, BLACK, WHITE) ; 336 SDL_Window =
325 337 GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, w, h, 0, BLACK, WHITE);
326 GrSelectEvents (SDL_Window, (GR_EVENT_MASK_EXPOSURE | 338
327 GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP | 339 GrSelectEvents(SDL_Window, (GR_EVENT_MASK_EXPOSURE |
328 GR_EVENT_MASK_FOCUS_IN | GR_EVENT_MASK_FOCUS_OUT | 340 GR_EVENT_MASK_BUTTON_DOWN |
329 GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP | 341 GR_EVENT_MASK_BUTTON_UP |
330 GR_EVENT_MASK_MOUSE_ENTER | GR_EVENT_MASK_MOUSE_EXIT | 342 GR_EVENT_MASK_FOCUS_IN |
331 GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_UPDATE | 343 GR_EVENT_MASK_FOCUS_OUT |
332 GR_EVENT_MASK_CLOSE_REQ)) ; 344 GR_EVENT_MASK_KEY_DOWN |
333 } 345 GR_EVENT_MASK_KEY_UP |
334 346 GR_EVENT_MASK_MOUSE_ENTER |
347 GR_EVENT_MASK_MOUSE_EXIT |
348 GR_EVENT_MASK_MOUSE_MOTION |
349 GR_EVENT_MASK_UPDATE |
350 GR_EVENT_MASK_CLOSE_REQ));
351 }
352
335 /* Create the graphics context here, once we have a window */ 353 /* Create the graphics context here, once we have a window */
336 SDL_GC = GrNewGC () ; 354 SDL_GC = GrNewGC();
337 if (SDL_GC == 0) { 355 if (SDL_GC == 0) {
338 SDL_SetError("Couldn't create graphics context"); 356 SDL_SetError("Couldn't create graphics context");
339 return(-1); 357 return (-1);
340 } 358 }
341
342 // Map them both and go fullscreen, if requested 359 // Map them both and go fullscreen, if requested
343 if (! SDL_windowid) { 360 if (!SDL_windowid) {
344 GrMapWindow (SDL_Window) ; 361 GrMapWindow(SDL_Window);
345 if (flags & SDL_FULLSCREEN) { 362 if (flags & SDL_FULLSCREEN) {
346 screen -> flags |= SDL_FULLSCREEN ; 363 screen->flags |= SDL_FULLSCREEN;
347 NX_EnterFullScreen (this) ; 364 NX_EnterFullScreen(this);
348 } else { 365 } else {
349 screen -> flags &= ~ SDL_FULLSCREEN ; 366 screen->flags &= ~SDL_FULLSCREEN;
350 } 367 }
351 } 368 }
352
353 #ifdef ENABLE_NANOX_DIRECT_FB 369 #ifdef ENABLE_NANOX_DIRECT_FB
354 /* attempt allocating the client side framebuffer */ 370 /* attempt allocating the client side framebuffer */
355 Clientfb = GrOpenClientFramebuffer(); 371 Clientfb = GrOpenClientFramebuffer();
356 /* NULL return will default to using GrArea()*/ 372 /* NULL return will default to using GrArea() */
357 #endif 373 #endif
358 374
359 Dprintf ("leave NX_CreateWindow\n") ; 375 Dprintf("leave NX_CreateWindow\n");
360 return 0 ; 376 return 0;
361 } 377 }
362 378
363 SDL_Surface * NX_SetVideoMode (_THIS, SDL_Surface * current, 379 SDL_Surface *
380 NX_SetVideoMode(_THIS, SDL_Surface * current,
364 int width, int height, int bpp, Uint32 flags) 381 int width, int height, int bpp, Uint32 flags)
365 { 382 {
366 Dprintf ("enter NX_SetVideoMode\n") ; 383 Dprintf("enter NX_SetVideoMode\n");
367 384
368 // Lock the event thread, in multi-threading environments 385 // Lock the event thread, in multi-threading environments
369 SDL_Lock_EventThread () ; 386 SDL_Lock_EventThread();
370 387
371 bpp = SDL_Visual.bpp ; 388 bpp = SDL_Visual.bpp;
372 if (NX_CreateWindow (this, current, width, height, bpp, flags) < 0) { 389 if (NX_CreateWindow(this, current, width, height, bpp, flags) < 0) {
373 current = NULL; 390 current = NULL;
374 goto done; 391 goto done;
375 } 392 }
376 393
377 if (current -> w != width || current -> h != height) { 394 if (current->w != width || current->h != height) {
378 current -> w = width ; 395 current->w = width;
379 current -> h = height ; 396 current->h = height;
380 current -> pitch = SDL_CalculatePitch (current) ; 397 current->pitch = SDL_CalculatePitch(current);
381 NX_ResizeImage (this, current, flags) ; 398 NX_ResizeImage(this, current, flags);
382 } 399 }
383 current -> flags |= (flags & (SDL_RESIZABLE | SDL_NOFRAME)) ; 400 current->flags |= (flags & (SDL_RESIZABLE | SDL_NOFRAME));
384 401
385 done: 402 done:
386 SDL_Unlock_EventThread () ; 403 SDL_Unlock_EventThread();
387 404
388 Dprintf ("leave NX_SetVideoMode\n") ; 405 Dprintf("leave NX_SetVideoMode\n");
389 406
390 // We're done! 407 // We're done!
391 return current ; 408 return current;
392 } 409 }
393 410
394 // ncolors <= 256 411 // ncolors <= 256
395 int NX_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) 412 int
396 { 413 NX_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
397 int i ; 414 {
398 GR_PALETTE pal ; 415 int i;
399 416 GR_PALETTE pal;
400 Dprintf ("enter NX_SetColors\n") ; 417
401 418 Dprintf("enter NX_SetColors\n");
402 if (ncolors > 256) return 0 ; 419
403 420 if (ncolors > 256)
404 pal.count = ncolors ; 421 return 0;
405 for (i = 0; i < ncolors; ++ i) { 422
406 pal.palette [i].r = colors [i].r ; 423 pal.count = ncolors;
407 pal.palette [i].g = colors [i].g ; 424 for (i = 0; i < ncolors; ++i) {
408 pal.palette [i].b = colors [i].b ; 425 pal.palette[i].r = colors[i].r;
409 } 426 pal.palette[i].g = colors[i].g;
410 GrSetSystemPalette (firstcolor, & pal) ; 427 pal.palette[i].b = colors[i].b;
411 428 }
412 Dprintf ("leave NX_SetColors\n") ; 429 GrSetSystemPalette(firstcolor, &pal);
413 return 1 ; 430
414 } 431 Dprintf("leave NX_SetColors\n");
415 432 return 1;
416 static int NX_ToggleFullScreen (_THIS, int on) 433 }
417 { 434
418 SDL_Rect rect ; 435 static int
419 Uint32 event_thread ; 436 NX_ToggleFullScreen(_THIS, int on)
420 437 {
421 Dprintf ("enter NX_ToggleFullScreen\n") ; 438 SDL_Rect rect;
439 Uint32 event_thread;
440
441 Dprintf("enter NX_ToggleFullScreen\n");
422 442
423 // Don't switch if we don't own the window 443 // Don't switch if we don't own the window
424 if (SDL_windowid) return 0 ; 444 if (SDL_windowid)
425 445 return 0;
446
426 // Don't lock if we are the event thread 447 // Don't lock if we are the event thread
427 event_thread = SDL_EventThreadID () ; 448 event_thread = SDL_EventThreadID();
428 if (event_thread && (SDL_ThreadID () == event_thread)) { 449 if (event_thread && (SDL_ThreadID() == event_thread)) {
429 event_thread = 0 ; 450 event_thread = 0;
430 } 451 }
431 if (event_thread) { 452 if (event_thread) {
432 SDL_Lock_EventThread() ; 453 SDL_Lock_EventThread();
433 } 454 }
434 455
435 if (on) { 456 if (on) {
436 NX_EnterFullScreen (this) ; 457 NX_EnterFullScreen(this);
437 } else { 458 } else {
438 this -> screen -> flags &= ~ SDL_FULLSCREEN ; 459 this->screen->flags &= ~SDL_FULLSCREEN;
439 NX_LeaveFullScreen (this) ; 460 NX_LeaveFullScreen(this);
440 } 461 }
441 462
442 rect.x = rect.y = 0 ; 463 rect.x = rect.y = 0;
443 rect.w = this -> screen -> w, rect.h = this -> screen -> h ; 464 rect.w = this->screen->w, rect.h = this->screen->h;
444 NX_NormalUpdate (this, 1, & rect) ; 465 NX_NormalUpdate(this, 1, &rect);
445 466
446 if (event_thread) { 467 if (event_thread) {
447 SDL_Unlock_EventThread () ; 468 SDL_Unlock_EventThread();
448 } 469 }
449 470
450 Dprintf ("leave NX_ToggleFullScreen\n") ; 471 Dprintf("leave NX_ToggleFullScreen\n");
451 return 1 ; 472 return 1;
452 } 473 }
453 474
454 // Update the current mouse state and position 475 // Update the current mouse state and position
455 static void NX_UpdateMouse (_THIS) 476 static void
456 { 477 NX_UpdateMouse(_THIS)
457 int x, y ; 478 {
458 GR_WINDOW_INFO info ; 479 int x, y;
459 GR_SCREEN_INFO si ; 480 GR_WINDOW_INFO info;
460 481 GR_SCREEN_INFO si;
461 482
462 Dprintf ("enter NX_UpdateMouse\n") ; 483
484 Dprintf("enter NX_UpdateMouse\n");
463 485
464 // Lock the event thread, in multi-threading environments 486 // Lock the event thread, in multi-threading environments
465 SDL_Lock_EventThread () ; 487 SDL_Lock_EventThread();
466 488
467 GrGetScreenInfo (& si) ; 489 GrGetScreenInfo(&si);
468 GrGetWindowInfo (SDL_Window, & info) ; 490 GrGetWindowInfo(SDL_Window, &info);
469 x = si.xpos - info.x ; 491 x = si.xpos - info.x;
470 y = si.ypos - info.y ; 492 y = si.ypos - info.y;
471 if (x >= 0 && x <= info.width && y >= 0 && y <= info.height) { 493 if (x >= 0 && x <= info.width && y >= 0 && y <= info.height) {
472 SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS) ; 494 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
473 SDL_PrivateMouseMotion (0, 0, x, y); 495 SDL_PrivateMouseMotion(0, 0, x, y);
474 } else { 496 } else {
475 SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS) ; 497 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
476 } 498 }
477 499
478 SDL_Unlock_EventThread () ; 500 SDL_Unlock_EventThread();
479 Dprintf ("leave NX_UpdateMouse\n") ; 501 Dprintf("leave NX_UpdateMouse\n");
480 } 502 }
481 503
482 static int NX_SetGammaRamp (_THIS, Uint16 * ramp) 504 static int
483 { 505 NX_SetGammaRamp(_THIS, Uint16 * ramp)
484 int i ; 506 {
485 Uint16 * red, * green, * blue ; 507 int i;
486 508 Uint16 *red, *green, *blue;
487 Dprintf ("enter NX_SetGammaRamp\n") ; 509
488 510 Dprintf("enter NX_SetGammaRamp\n");
489 if (SDL_Visual.bpp != 32 && SDL_Visual.bpp != 24) return -1 ; 511
490 512 if (SDL_Visual.bpp != 32 && SDL_Visual.bpp != 24)
491 if (! GammaRamp_R) GammaRamp_R = (Uint16 *) SDL_malloc (sizeof (Uint16) * CI_SIZE) ; 513 return -1;
492 if (! GammaRamp_G) GammaRamp_G = (Uint16 *) SDL_malloc (sizeof (Uint16) * CI_SIZE) ; 514
493 if (! GammaRamp_B) GammaRamp_B = (Uint16 *) SDL_malloc (sizeof (Uint16) * CI_SIZE) ; 515 if (!GammaRamp_R)
494 if ((! GammaRamp_R) || (! GammaRamp_G) || (! GammaRamp_B)) { 516 GammaRamp_R = (Uint16 *) SDL_malloc(sizeof(Uint16) * CI_SIZE);
495 SDL_OutOfMemory () ; 517 if (!GammaRamp_G)
496 return -1 ; 518 GammaRamp_G = (Uint16 *) SDL_malloc(sizeof(Uint16) * CI_SIZE);
497 } 519 if (!GammaRamp_B)
498 520 GammaRamp_B = (Uint16 *) SDL_malloc(sizeof(Uint16) * CI_SIZE);
499 for (i = 0; i < CI_SIZE; ++ i) 521 if ((!GammaRamp_R) || (!GammaRamp_G) || (!GammaRamp_B)) {
500 GammaRamp_R [i] = GammaRamp_G [i] = GammaRamp_B [i] = i ; 522 SDL_OutOfMemory();
501 523 return -1;
502 red = ramp ; 524 }
503 green = ramp + CI_SIZE ; 525
504 blue = green + CI_SIZE ; 526 for (i = 0; i < CI_SIZE; ++i)
505 527 GammaRamp_R[i] = GammaRamp_G[i] = GammaRamp_B[i] = i;
506 for (i = 0; i < CI_SIZE; ++ i) { 528
507 GammaRamp_R [i] = red [i] ; 529 red = ramp;
508 GammaRamp_G [i] = green [i] ; 530 green = ramp + CI_SIZE;
509 GammaRamp_B [i] = blue [i] ; 531 blue = green + CI_SIZE;
532
533 for (i = 0; i < CI_SIZE; ++i) {
534 GammaRamp_R[i] = red[i];
535 GammaRamp_G[i] = green[i];
536 GammaRamp_B[i] = blue[i];
510 } 537 }
511 SDL_UpdateRect(this->screen, 0, 0, 0, 0); 538 SDL_UpdateRect(this->screen, 0, 0, 0, 0);
512 539
513 Dprintf ("leave NX_SetGammaRamp\n") ; 540 Dprintf("leave NX_SetGammaRamp\n");
514 return 0 ; 541 return 0;
515 } 542 }
516 543
517 static int NX_GetGammaRamp (_THIS, Uint16 * ramp) 544 static int
518 { 545 NX_GetGammaRamp(_THIS, Uint16 * ramp)
519 int i ; 546 {
520 Uint16 * red, * green, * blue ; 547 int i;
521 548 Uint16 *red, *green, *blue;
522 Dprintf ("enter NX_GetGammaRamp\n") ; 549
523 550 Dprintf("enter NX_GetGammaRamp\n");
524 if (SDL_Visual.bpp != 32 && SDL_Visual.bpp != 24) return -1 ; 551
525 red = ramp ; 552 if (SDL_Visual.bpp != 32 && SDL_Visual.bpp != 24)
526 green = ramp + CI_SIZE ; 553 return -1;
527 blue = green + CI_SIZE ; 554 red = ramp;
555 green = ramp + CI_SIZE;
556 blue = green + CI_SIZE;
528 if (GammaRamp_R && GammaRamp_G && GammaRamp_B) { 557 if (GammaRamp_R && GammaRamp_G && GammaRamp_B) {
529 for (i = 0; i < CI_SIZE; ++ i) { 558 for (i = 0; i < CI_SIZE; ++i) {
530 red [i] = GammaRamp_R [i] ; 559 red[i] = GammaRamp_R[i];
531 green [i] = GammaRamp_G [i] ; 560 green[i] = GammaRamp_G[i];
532 blue [i] = GammaRamp_B [i] ; 561 blue[i] = GammaRamp_B[i];
533 } 562 }
534 } else { 563 } else {
535 for (i = 0; i < CI_SIZE; ++ i) 564 for (i = 0; i < CI_SIZE; ++i)
536 red [i] = green [i] = blue [i] = i ; 565 red[i] = green[i] = blue[i] = i;
537 } 566 }
538 567
539 Dprintf ("leave NX_GetGammaRamp\n") ; 568 Dprintf("leave NX_GetGammaRamp\n");
540 return 0 ; 569 return 0;
541 } 570 }
571
572 /* vi: set ts=4 sw=4 expandtab: */