comparison src/video/photon/SDL_ph_video.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
40 #include "SDL_ph_wm_c.h" 40 #include "SDL_ph_wm_c.h"
41 #include "SDL_ph_gl.h" 41 #include "SDL_ph_gl.h"
42 #include "SDL_phyuv_c.h" 42 #include "SDL_phyuv_c.h"
43 #include "../blank_cursor.h" 43 #include "../blank_cursor.h"
44 44
45 static int ph_VideoInit (_THIS, SDL_PixelFormat * vformat); 45 static int ph_VideoInit(_THIS, SDL_PixelFormat * vformat);
46 static SDL_Surface *ph_SetVideoMode (_THIS, SDL_Surface * current, int width, 46 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface * current, int width,
47 int height, int bpp, Uint32 flags); 47 int height, int bpp, Uint32 flags);
48 static int ph_SetColors (_THIS, int firstcolor, int ncolors, 48 static int ph_SetColors(_THIS, int firstcolor, int ncolors,
49 SDL_Color * colors); 49 SDL_Color * colors);
50 static void ph_VideoQuit (_THIS); 50 static void ph_VideoQuit(_THIS);
51 static void ph_DeleteDevice (SDL_VideoDevice * device); 51 static void ph_DeleteDevice(SDL_VideoDevice * device);
52 52
53 static int phstatus = -1; 53 static int phstatus = -1;
54 54
55 static int 55 static int
56 ph_Available (void) 56 ph_Available(void)
57 { 57 {
58 if (phstatus != 0) { 58 if (phstatus != 0) {
59 phstatus = PtInit (NULL); 59 phstatus = PtInit(NULL);
60 if (phstatus == 0) { 60 if (phstatus == 0) {
61 return 1; 61 return 1;
62 } else { 62 } else {
63 return 0; 63 return 0;
64 } 64 }
65 } 65 }
66 return 1; 66 return 1;
67 } 67 }
68 68
69 static SDL_VideoDevice * 69 static SDL_VideoDevice *
70 ph_CreateDevice (int devindex) 70 ph_CreateDevice(int devindex)
71 { 71 {
72 SDL_VideoDevice *device; 72 SDL_VideoDevice *device;
73 73
74 /* Initialize all variables that we clean on shutdown */ 74 /* Initialize all variables that we clean on shutdown */
75 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)); 75 device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
76 if (device) { 76 if (device) {
77 SDL_memset (device, 0, (sizeof *device)); 77 SDL_memset(device, 0, (sizeof *device));
78 device->hidden = (struct SDL_PrivateVideoData *) 78 device->hidden = (struct SDL_PrivateVideoData *)
79 SDL_malloc ((sizeof *device->hidden)); 79 SDL_malloc((sizeof *device->hidden));
80 device->gl_data = NULL; 80 device->gl_data = NULL;
81 } 81 }
82 if ((device == NULL) || (device->hidden == NULL)) { 82 if ((device == NULL) || (device->hidden == NULL)) {
83 SDL_OutOfMemory (); 83 SDL_OutOfMemory();
84 ph_DeleteDevice (device); 84 ph_DeleteDevice(device);
85 return NULL; 85 return NULL;
86 } 86 }
87 SDL_memset (device->hidden, 0, (sizeof *device->hidden)); 87 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
88 88
89 /* Set the driver flags */ 89 /* Set the driver flags */
90 device->handles_any_size = 1; 90 device->handles_any_size = 1;
91 91
92 /* Set the function pointers */ 92 /* Set the function pointers */
140 "photon", "QNX Photon video output", 140 "photon", "QNX Photon video output",
141 ph_Available, ph_CreateDevice 141 ph_Available, ph_CreateDevice
142 }; 142 };
143 143
144 static void 144 static void
145 ph_DeleteDevice (SDL_VideoDevice * device) 145 ph_DeleteDevice(SDL_VideoDevice * device)
146 { 146 {
147 if (device) { 147 if (device) {
148 if (device->hidden) { 148 if (device->hidden) {
149 SDL_free (device->hidden); 149 SDL_free(device->hidden);
150 device->hidden = NULL; 150 device->hidden = NULL;
151 } 151 }
152 if (device->gl_data) { 152 if (device->gl_data) {
153 SDL_free (device->gl_data); 153 SDL_free(device->gl_data);
154 device->gl_data = NULL; 154 device->gl_data = NULL;
155 } 155 }
156 SDL_free (device); 156 SDL_free(device);
157 device = NULL; 157 device = NULL;
158 } 158 }
159 } 159 }
160 160
161 static PtWidget_t * 161 static PtWidget_t *
162 ph_CreateWindow (_THIS) 162 ph_CreateWindow(_THIS)
163 { 163 {
164 PtWidget_t *widget; 164 PtWidget_t *widget;
165 165
166 widget = PtCreateWidget (PtWindow, NULL, 0, NULL); 166 widget = PtCreateWidget(PtWindow, NULL, 0, NULL);
167 167
168 return widget; 168 return widget;
169 } 169 }
170 170
171 static int 171 static int
172 ph_SetupWindow (_THIS, int w, int h, int flags) 172 ph_SetupWindow(_THIS, int w, int h, int flags)
173 { 173 {
174 PtArg_t args[32]; 174 PtArg_t args[32];
175 PhPoint_t pos = { 0, 0 }; 175 PhPoint_t pos = { 0, 0 };
176 PhDim_t *olddim; 176 PhDim_t *olddim;
177 PhDim_t dim = { w, h }; 177 PhDim_t dim = { w, h };
180 const char *windowpos; 180 const char *windowpos;
181 const char *iscentered; 181 const char *iscentered;
182 int x, y; 182 int x, y;
183 183
184 /* check if window size has been changed by Window Manager */ 184 /* check if window size has been changed by Window Manager */
185 PtGetResource (window, Pt_ARG_DIM, &olddim, 0); 185 PtGetResource(window, Pt_ARG_DIM, &olddim, 0);
186 if ((olddim->w != w) || (olddim->h != h)) { 186 if ((olddim->w != w) || (olddim->h != h)) {
187 PtSetArg (&args[nargs++], Pt_ARG_DIM, &dim, 0); 187 PtSetArg(&args[nargs++], Pt_ARG_DIM, &dim, 0);
188 } 188 }
189 189
190 if ((flags & SDL_RESIZABLE) == SDL_RESIZABLE) { 190 if ((flags & SDL_RESIZABLE) == SDL_RESIZABLE) {
191 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, 191 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE,
192 Ph_WM_CLOSE); 192 Ph_WM_CLOSE);
193 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, 193 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE,
194 Ph_WM_MAX | Ph_WM_RESTORE | Ph_WM_RESIZE); 194 Ph_WM_MAX | Ph_WM_RESTORE | Ph_WM_RESIZE);
195 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, 195 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE,
196 Ph_WM_RESIZE | Ph_WM_MOVE | Ph_WM_CLOSE | Ph_WM_MAX | 196 Ph_WM_RESIZE | Ph_WM_MOVE | Ph_WM_CLOSE | Ph_WM_MAX |
197 Ph_WM_RESTORE); 197 Ph_WM_RESTORE);
198 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, 198 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE,
199 Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX | 199 Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX |
200 Ph_WM_RENDER_COLLAPSE | Ph_WM_RENDER_RETURN); 200 Ph_WM_RENDER_COLLAPSE | Ph_WM_RENDER_RETURN);
201 PtSetArg (&args[nargs++], Pt_ARG_RESIZE_FLAGS, Pt_TRUE, 201 PtSetArg(&args[nargs++], Pt_ARG_RESIZE_FLAGS, Pt_TRUE,
202 Pt_RESIZE_XY_AS_REQUIRED); 202 Pt_RESIZE_XY_AS_REQUIRED);
203 } else { 203 } else {
204 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, 204 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE,
205 Ph_WM_RESIZE | Ph_WM_MAX | Ph_WM_RESTORE | Ph_WM_CLOSE); 205 Ph_WM_RESIZE | Ph_WM_MAX | Ph_WM_RESTORE | Ph_WM_CLOSE);
206 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE, 206 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE,
207 Ph_WM_RESIZE | Ph_WM_MAX | Ph_WM_RESTORE); 207 Ph_WM_RESIZE | Ph_WM_MAX | Ph_WM_RESTORE);
208 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, 208 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE,
209 Ph_WM_MOVE | Ph_WM_CLOSE); 209 Ph_WM_MOVE | Ph_WM_CLOSE);
210 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, 210 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE,
211 Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX | 211 Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX |
212 Ph_WM_RENDER_COLLAPSE | Ph_WM_RENDER_RETURN); 212 Ph_WM_RENDER_COLLAPSE | Ph_WM_RENDER_RETURN);
213 PtSetArg (&args[nargs++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, 213 PtSetArg(&args[nargs++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE,
214 Pt_RESIZE_XY_AS_REQUIRED); 214 Pt_RESIZE_XY_AS_REQUIRED);
215 } 215 }
216 216
217 if (((flags & SDL_NOFRAME) == SDL_NOFRAME) 217 if (((flags & SDL_NOFRAME) == SDL_NOFRAME)
218 || ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)) { 218 || ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)) {
219 if ((flags & SDL_RESIZABLE) != SDL_RESIZABLE) { 219 if ((flags & SDL_RESIZABLE) != SDL_RESIZABLE) {
220 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, 220 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS,
221 Pt_FALSE, Pt_TRUE); 221 Pt_FALSE, Pt_TRUE);
222 } else { 222 } else {
223 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, 223 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS,
224 Pt_FALSE, Pt_TRUE); 224 Pt_FALSE, Pt_TRUE);
225 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, 225 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE,
226 Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_BORDER); 226 Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_BORDER);
227 } 227 }
228 } else { 228 } else {
229 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, 229 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE,
230 Ph_WM_RENDER_BORDER | Ph_WM_RENDER_TITLE | 230 Ph_WM_RENDER_BORDER | Ph_WM_RENDER_TITLE |
231 Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MIN); 231 Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MIN);
232 } 232 }
233 233
234 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { 234 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
235 PtSetArg (&args[nargs++], Pt_ARG_POS, &pos, 0); 235 PtSetArg(&args[nargs++], Pt_ARG_POS, &pos, 0);
236 PtSetArg (&args[nargs++], Pt_ARG_BASIC_FLAGS, Pt_TRUE, 236 PtSetArg(&args[nargs++], Pt_ARG_BASIC_FLAGS, Pt_TRUE,
237 Pt_BASIC_PREVENT_FILL); 237 Pt_BASIC_PREVENT_FILL);
238 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, 238 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE,
239 Ph_WM_FFRONT | Ph_WM_MAX | Ph_WM_TOFRONT | Ph_WM_CONSWITCH); 239 Ph_WM_FFRONT | Ph_WM_MAX | Ph_WM_TOFRONT | Ph_WM_CONSWITCH);
240 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE, 240 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE,
241 Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISFOCUS | 241 Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISFOCUS |
242 Ph_WM_STATE_ISALTKEY); 242 Ph_WM_STATE_ISALTKEY);
243 } else { 243 } else {
244 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, 244 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE,
245 Ph_WM_FFRONT | Ph_WM_CONSWITCH); 245 Ph_WM_FFRONT | Ph_WM_CONSWITCH);
246 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE, 246 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE,
247 Ph_WM_STATE_ISFRONT); 247 Ph_WM_STATE_ISFRONT);
248 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE, 248 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE,
249 Ph_WM_STATE_ISALTKEY); 249 Ph_WM_STATE_ISALTKEY);
250 250
251 if ((flags & SDL_HWSURFACE) == SDL_HWSURFACE) { 251 if ((flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
252 PtSetArg (&args[nargs++], Pt_ARG_BASIC_FLAGS, Pt_TRUE, 252 PtSetArg(&args[nargs++], Pt_ARG_BASIC_FLAGS, Pt_TRUE,
253 Pt_BASIC_PREVENT_FILL); 253 Pt_BASIC_PREVENT_FILL);
254 } else { 254 } else {
255 PtSetArg (&args[nargs++], Pt_ARG_FILL_COLOR, Pg_BLACK, 0); 255 PtSetArg(&args[nargs++], Pt_ARG_FILL_COLOR, Pg_BLACK, 0);
256 } 256 }
257 if (!currently_maximized) { 257 if (!currently_maximized) {
258 windowpos = SDL_getenv ("SDL_VIDEO_WINDOW_POS"); 258 windowpos = SDL_getenv("SDL_VIDEO_WINDOW_POS");
259 iscentered = SDL_getenv ("SDL_VIDEO_CENTERED"); 259 iscentered = SDL_getenv("SDL_VIDEO_CENTERED");
260 260
261 if ((iscentered) 261 if ((iscentered)
262 || ((windowpos) 262 || ((windowpos)
263 && (SDL_strcmp (windowpos, "center") == 0))) { 263 && (SDL_strcmp(windowpos, "center") == 0))) {
264 PhWindowQueryVisible (Ph_QUERY_CONSOLE, 0, 0, &desktopextent); 264 PhWindowQueryVisible(Ph_QUERY_CONSOLE, 0, 0, &desktopextent);
265 if (desktop_mode.width > w) { 265 if (desktop_mode.width > w) {
266 pos.x = (desktop_mode.width - w) / 2; 266 pos.x = (desktop_mode.width - w) / 2;
267 } 267 }
268 if (desktop_mode.height > h) { 268 if (desktop_mode.height > h) {
269 pos.y = (desktop_mode.height - h) / 2; 269 pos.y = (desktop_mode.height - h) / 2;
270 } 270 }
271 271
272 pos.x += desktopextent.ul.x; 272 pos.x += desktopextent.ul.x;
273 pos.y += desktopextent.ul.y; 273 pos.y += desktopextent.ul.y;
274 PtSetArg (&args[nargs++], Pt_ARG_POS, &pos, 0); 274 PtSetArg(&args[nargs++], Pt_ARG_POS, &pos, 0);
275 } else { 275 } else {
276 if (windowpos) { 276 if (windowpos) {
277 if (SDL_sscanf (windowpos, "%d,%d", &x, &y) == 2) { 277 if (SDL_sscanf(windowpos, "%d,%d", &x, &y) == 2) {
278 if ((x < desktop_mode.width) 278 if ((x < desktop_mode.width)
279 && (y < desktop_mode.height)) { 279 && (y < desktop_mode.height)) {
280 PhWindowQueryVisible 280 PhWindowQueryVisible
281 (Ph_QUERY_CONSOLE, 0, 0, &desktopextent); 281 (Ph_QUERY_CONSOLE, 0, 0, &desktopextent);
282 pos.x = x + desktopextent.ul.x; 282 pos.x = x + desktopextent.ul.x;
283 pos.y = y + desktopextent.ul.y; 283 pos.y = y + desktopextent.ul.y;
284 } 284 }
285 PtSetArg (&args[nargs++], Pt_ARG_POS, &pos, 0); 285 PtSetArg(&args[nargs++], Pt_ARG_POS, &pos, 0);
286 } 286 }
287 } 287 }
288 } 288 }
289 } 289 }
290 290
291 /* if window is maximized render it as maximized */ 291 /* if window is maximized render it as maximized */
292 if (currently_maximized) { 292 if (currently_maximized) {
293 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE, 293 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE,
294 Ph_WM_STATE_ISMAX); 294 Ph_WM_STATE_ISMAX);
295 } else { 295 } else {
296 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE, 296 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE,
297 Ph_WM_STATE_ISMAX); 297 Ph_WM_STATE_ISMAX);
298 } 298 }
299 299
300 /* do not grab the keyboard by default */ 300 /* do not grab the keyboard by default */
301 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE, 301 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE,
302 Ph_WM_STATE_ISALTKEY); 302 Ph_WM_STATE_ISALTKEY);
303 303
304 /* bring the focus to the window */ 304 /* bring the focus to the window */
305 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE, 305 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE,
306 Ph_WM_STATE_ISFOCUS); 306 Ph_WM_STATE_ISFOCUS);
307 307
308 /* allow to catch hide event */ 308 /* allow to catch hide event */
309 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, 309 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE,
310 Ph_WM_HIDE); 310 Ph_WM_HIDE);
311 PtSetArg (&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, 311 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE,
312 Ph_WM_HIDE); 312 Ph_WM_HIDE);
313 } 313 }
314 314
315 PtSetResources (window, nargs, args); 315 PtSetResources(window, nargs, args);
316 PtRealizeWidget (window); 316 PtRealizeWidget(window);
317 PtWindowToFront (window); 317 PtWindowToFront(window);
318 318
319 #if 0 /* FIXME */ 319 #if 0 /* FIXME */
320 PtGetResource (window, Pt_ARG_POS, &olddim, 0); 320 PtGetResource(window, Pt_ARG_POS, &olddim, 0);
321 fprintf (stderr, "POSITION: %d, %d\n", olddim->w, olddim->h); 321 fprintf(stderr, "POSITION: %d, %d\n", olddim->w, olddim->h);
322 #endif 322 #endif
323 323
324 return 0; 324 return 0;
325 } 325 }
326 326
327 static const struct ColourMasks * 327 static const struct ColourMasks *
328 ph_GetColourMasks (int bpp) 328 ph_GetColourMasks(int bpp)
329 { 329 {
330 /* The alpha mask doesn't appears to be needed */ 330 /* The alpha mask doesn't appears to be needed */
331 static const struct ColourMasks phColorMasks[5] = { 331 static const struct ColourMasks phColorMasks[5] = {
332 /* 8 bit */ {0, 0, 0, 0, 8}, 332 /* 8 bit */ {0, 0, 0, 0, 8},
333 /* 15 bit ARGB */ {0x7C00, 0x03E0, 0x001F, 0x8000, 15}, 333 /* 15 bit ARGB */ {0x7C00, 0x03E0, 0x001F, 0x8000, 15},
351 } 351 }
352 return NULL; 352 return NULL;
353 } 353 }
354 354
355 static int 355 static int
356 ph_VideoInit (_THIS, SDL_PixelFormat * vformat) 356 ph_VideoInit(_THIS, SDL_PixelFormat * vformat)
357 { 357 {
358 PgHWCaps_t hwcaps; 358 PgHWCaps_t hwcaps;
359 int i; 359 int i;
360 360
361 window = NULL; 361 window = NULL;
369 #endif 369 #endif
370 370
371 old_video_mode = -1; 371 old_video_mode = -1;
372 old_refresh_rate = -1; 372 old_refresh_rate = -1;
373 373
374 if (NULL == (phevent = SDL_malloc (EVENT_SIZE))) { 374 if (NULL == (phevent = SDL_malloc(EVENT_SIZE))) {
375 SDL_OutOfMemory (); 375 SDL_OutOfMemory();
376 return -1; 376 return -1;
377 } 377 }
378 SDL_memset (phevent, 0x00, EVENT_SIZE); 378 SDL_memset(phevent, 0x00, EVENT_SIZE);
379 379
380 window = ph_CreateWindow (this); 380 window = ph_CreateWindow(this);
381 if (window == NULL) { 381 if (window == NULL) {
382 SDL_SetError ("ph_VideoInit(): Couldn't create video window !\n"); 382 SDL_SetError("ph_VideoInit(): Couldn't create video window !\n");
383 return -1; 383 return -1;
384 } 384 }
385 385
386 /* Create the blank cursor */ 386 /* Create the blank cursor */
387 SDL_BlankCursor = this->CreateWMCursor (this, blank_cdata, blank_cmask, 387 SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask,
388 (int) BLANK_CWIDTH, 388 (int) BLANK_CWIDTH,
389 (int) BLANK_CHEIGHT, 389 (int) BLANK_CHEIGHT,
390 (int) BLANK_CHOTX, 390 (int) BLANK_CHOTX,
391 (int) BLANK_CHOTY); 391 (int) BLANK_CHOTY);
392 392
393 if (SDL_BlankCursor == NULL) { 393 if (SDL_BlankCursor == NULL) {
394 return -1; 394 return -1;
395 } 395 }
396 396
397 if (PgGetGraphicsHWCaps (&hwcaps) < 0) { 397 if (PgGetGraphicsHWCaps(&hwcaps) < 0) {
398 SDL_SetError 398 SDL_SetError("ph_VideoInit(): GetGraphicsHWCaps function failed !\n");
399 ("ph_VideoInit(): GetGraphicsHWCaps function failed !\n"); 399 this->FreeWMCursor(this, SDL_BlankCursor);
400 this->FreeWMCursor (this, SDL_BlankCursor);
401 return -1; 400 return -1;
402 } 401 }
403 402
404 if (PgGetVideoModeInfo (hwcaps.current_video_mode, &desktop_mode) < 0) { 403 if (PgGetVideoModeInfo(hwcaps.current_video_mode, &desktop_mode) < 0) {
405 SDL_SetError 404 SDL_SetError
406 ("ph_VideoInit(): PgGetVideoModeInfo function failed !\n"); 405 ("ph_VideoInit(): PgGetVideoModeInfo function failed !\n");
407 this->FreeWMCursor (this, SDL_BlankCursor); 406 this->FreeWMCursor(this, SDL_BlankCursor);
408 return -1; 407 return -1;
409 } 408 }
410 409
411 /* Determine the current screen size */ 410 /* Determine the current screen size */
412 this->info.current_w = desktop_mode.width; 411 this->info.current_w = desktop_mode.width;
418 desktop_mode.bytes_per_scanline / desktop_mode.width; 417 desktop_mode.bytes_per_scanline / desktop_mode.width;
419 desktopbpp = desktop_mode.bits_per_pixel; 418 desktopbpp = desktop_mode.bits_per_pixel;
420 419
421 /* save current palette */ 420 /* save current palette */
422 if (desktopbpp == 8) { 421 if (desktopbpp == 8) {
423 PgGetPalette (savedpal); 422 PgGetPalette(savedpal);
424 PgGetPalette (syspalph); 423 PgGetPalette(syspalph);
425 } else { 424 } else {
426 for (i = 0; i < _Pg_MAX_PALETTE; i++) { 425 for (i = 0; i < _Pg_MAX_PALETTE; i++) {
427 savedpal[i] = PgRGB (0, 0, 0); 426 savedpal[i] = PgRGB(0, 0, 0);
428 syspalph[i] = PgRGB (0, 0, 0); 427 syspalph[i] = PgRGB(0, 0, 0);
429 } 428 }
430 } 429 }
431 430
432 currently_fullscreen = 0; 431 currently_fullscreen = 0;
433 currently_hided = 0; 432 currently_hided = 0;
443 OCImage.FrameData1 = NULL; 442 OCImage.FrameData1 = NULL;
444 videomode_emulatemode = 0; 443 videomode_emulatemode = 0;
445 444
446 this->info.wm_available = 1; 445 this->info.wm_available = 1;
447 446
448 ph_UpdateHWInfo (this); 447 ph_UpdateHWInfo(this);
449 448
450 return 0; 449 return 0;
451 } 450 }
452 451
453 static SDL_Surface * 452 static SDL_Surface *
454 ph_SetVideoMode (_THIS, SDL_Surface * current, int width, int height, int bpp, 453 ph_SetVideoMode(_THIS, SDL_Surface * current, int width, int height, int bpp,
455 Uint32 flags) 454 Uint32 flags)
456 { 455 {
457 const struct ColourMasks *mask; 456 const struct ColourMasks *mask;
458 457
459 /* Lock the event thread, in multi-threading environments */ 458 /* Lock the event thread, in multi-threading environments */
460 SDL_Lock_EventThread (); 459 SDL_Lock_EventThread();
461 460
462 current->flags = flags; 461 current->flags = flags;
463 462
464 /* if we do not have desired fullscreen mode, then fallback into window mode */ 463 /* if we do not have desired fullscreen mode, then fallback into window mode */
465 if (((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) 464 if (((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
466 && (ph_GetVideoMode (width, height, bpp) == 0)) { 465 && (ph_GetVideoMode(width, height, bpp) == 0)) {
467 current->flags &= ~SDL_FULLSCREEN; 466 current->flags &= ~SDL_FULLSCREEN;
468 current->flags &= ~SDL_NOFRAME; 467 current->flags &= ~SDL_NOFRAME;
469 current->flags &= ~SDL_RESIZABLE; 468 current->flags &= ~SDL_RESIZABLE;
470 } 469 }
471 470
472 ph_SetupWindow (this, width, height, current->flags); 471 ph_SetupWindow(this, width, height, current->flags);
473 472
474 mask = ph_GetColourMasks (bpp); 473 mask = ph_GetColourMasks(bpp);
475 if (mask != NULL) { 474 if (mask != NULL) {
476 SDL_ReallocFormat (current, mask->bpp, mask->red, mask->green, 475 SDL_ReallocFormat(current, mask->bpp, mask->red, mask->green,
477 mask->blue, 0); 476 mask->blue, 0);
478 } else { 477 } else {
479 SDL_SetError 478 SDL_SetError
480 ("ph_SetVideoMode(): desired bpp is not supported by photon !\n"); 479 ("ph_SetVideoMode(): desired bpp is not supported by photon !\n");
481 return NULL; 480 return NULL;
482 } 481 }
528 if (desktoppal == SDLPH_PAL_SYSTEM) { 527 if (desktoppal == SDLPH_PAL_SYSTEM) {
529 current->flags |= SDL_HWPALETTE; 528 current->flags |= SDL_HWPALETTE;
530 } 529 }
531 530
532 /* Must call at least once for setup image planes */ 531 /* Must call at least once for setup image planes */
533 if (ph_SetupUpdateFunction (this, current, current->flags) == -1) { 532 if (ph_SetupUpdateFunction(this, current, current->flags) == -1) {
534 /* Error string was filled in the ph_SetupUpdateFunction() */ 533 /* Error string was filled in the ph_SetupUpdateFunction() */
535 return NULL; 534 return NULL;
536 } 535 }
537 536
538 /* finish window drawing, if we are not in fullscreen, of course */ 537 /* finish window drawing, if we are not in fullscreen, of course */
539 if ((current->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) { 538 if ((current->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) {
540 PtFlush (); 539 PtFlush();
541 } else { 540 } else {
542 PgFlush (); 541 PgFlush();
543 } 542 }
544 543
545 visualbpp = bpp; 544 visualbpp = bpp;
546 545
547 ph_UpdateHWInfo (this); 546 ph_UpdateHWInfo(this);
548 547
549 SDL_Unlock_EventThread (); 548 SDL_Unlock_EventThread();
550 549
551 /* We've done! */ 550 /* We've done! */
552 return (current); 551 return (current);
553 } 552 }
554 553
555 static void 554 static void
556 ph_VideoQuit (_THIS) 555 ph_VideoQuit(_THIS)
557 { 556 {
558 /* restore palette */ 557 /* restore palette */
559 if (desktopbpp == 8) { 558 if (desktopbpp == 8) {
560 PgSetPalette (syspalph, 0, -1, 0, 0, 0); 559 PgSetPalette(syspalph, 0, -1, 0, 0, 0);
561 PgSetPalette (savedpal, 0, 0, _Pg_MAX_PALETTE, 560 PgSetPalette(savedpal, 0, 0, _Pg_MAX_PALETTE,
562 Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0); 561 Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0);
563 PgFlush (); 562 PgFlush();
564 } 563 }
565 564
566 ph_DestroyImage (this, SDL_VideoSurface); 565 ph_DestroyImage(this, SDL_VideoSurface);
567 566
568 if (window) { 567 if (window) {
569 PtUnrealizeWidget (window); 568 PtUnrealizeWidget(window);
570 PtDestroyWidget (window); 569 PtDestroyWidget(window);
571 window = NULL; 570 window = NULL;
572 } 571 }
573 572
574 if (phevent != NULL) { 573 if (phevent != NULL) {
575 SDL_free (phevent); 574 SDL_free(phevent);
576 phevent = NULL; 575 phevent = NULL;
577 } 576 }
578 } 577 }
579 578
580 static int 579 static int
581 ph_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) 580 ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
582 { 581 {
583 int i; 582 int i;
584 SDL_Rect updaterect; 583 SDL_Rect updaterect;
585 584
586 updaterect.x = updaterect.y = 0; 585 updaterect.x = updaterect.y = 0;
590 /* palette emulation code, using palette of the PhImage_t struct */ 589 /* palette emulation code, using palette of the PhImage_t struct */
591 if (desktoppal == SDLPH_PAL_EMULATE) { 590 if (desktoppal == SDLPH_PAL_EMULATE) {
592 if ((SDL_Image) && (SDL_Image->palette)) { 591 if ((SDL_Image) && (SDL_Image->palette)) {
593 for (i = firstcolor; i < firstcolor + ncolors; i++) { 592 for (i = firstcolor; i < firstcolor + ncolors; i++) {
594 syspalph[i] = 593 syspalph[i] =
595 PgRGB (colors[i - firstcolor].r, 594 PgRGB(colors[i - firstcolor].r,
596 colors[i - firstcolor].g, 595 colors[i - firstcolor].g, colors[i - firstcolor].b);
597 colors[i - firstcolor].b);
598 SDL_Image->palette[i] = syspalph[i]; 596 SDL_Image->palette[i] = syspalph[i];
599 } 597 }
600 598
601 /* image needs to be redrawn */ 599 /* image needs to be redrawn */
602 this->UpdateRects (this, 1, &updaterect); 600 this->UpdateRects(this, 1, &updaterect);
603 } 601 }
604 } else { 602 } else {
605 if (desktoppal == SDLPH_PAL_SYSTEM) { 603 if (desktoppal == SDLPH_PAL_SYSTEM) {
606 for (i = firstcolor; i < firstcolor + ncolors; i++) { 604 for (i = firstcolor; i < firstcolor + ncolors; i++) {
607 syspalph[i] = 605 syspalph[i] =
608 PgRGB (colors[i - firstcolor].r, 606 PgRGB(colors[i - firstcolor].r,
609 colors[i - firstcolor].g, 607 colors[i - firstcolor].g, colors[i - firstcolor].b);
610 colors[i - firstcolor].b);
611 } 608 }
612 609
613 if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) { 610 if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) {
614 /* window mode must use soft palette */ 611 /* window mode must use soft palette */
615 PgSetPalette (&syspalph[firstcolor], 0, firstcolor, 612 PgSetPalette(&syspalph[firstcolor], 0, firstcolor,
616 ncolors, Pg_PALSET_GLOBAL, 0); 613 ncolors, Pg_PALSET_GLOBAL, 0);
617 /* image needs to be redrawn */ 614 /* image needs to be redrawn */
618 this->UpdateRects (this, 1, &updaterect); 615 this->UpdateRects(this, 1, &updaterect);
619 } else { 616 } else {
620 /* fullscreen mode must use hardware palette */ 617 /* fullscreen mode must use hardware palette */
621 PgSetPalette (&syspalph[firstcolor], 0, firstcolor, 618 PgSetPalette(&syspalph[firstcolor], 0, firstcolor,
622 ncolors, Pg_PALSET_GLOBAL, 0); 619 ncolors, Pg_PALSET_GLOBAL, 0);
623 } 620 }
624 } else { 621 } else {
625 /* SDLPH_PAL_NONE do nothing */ 622 /* SDLPH_PAL_NONE do nothing */
626 } 623 }
627 } 624 }