Mercurial > sdl-ios-xcode
comparison src/video/photon/SDL_ph_video.c @ 571:8e3ce997621c
Date: Thu, 16 Jan 2003 13:48:31 +0200
From: "Mike Gorchak"
Subject: All QNX patches
whole patches concerning QNX. Almost all code has been rewritten by Julian
and me. Added initial support for hw overlays in QNX and many many others
fixes.
P.S. This patches has been reviewed by Dave Rempel from QSSL and included in
SDL 1.2.5 distribution, which coming on 3rd party CD for newest 6.2.1
version of QNX, which will be available soon.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 20 Jan 2003 01:38:37 +0000 |
parents | bce7171e7a85 |
children | 8bedd6d61642 |
comparison
equal
deleted
inserted
replaced
570:04d6411da49d | 571:8e3ce997621c |
---|---|
54 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, | 54 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, |
55 int width, int height, int bpp, Uint32 flags); | 55 int width, int height, int bpp, Uint32 flags); |
56 static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); | 56 static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); |
57 static void ph_VideoQuit(_THIS); | 57 static void ph_VideoQuit(_THIS); |
58 static void ph_DeleteDevice(SDL_VideoDevice *device); | 58 static void ph_DeleteDevice(SDL_VideoDevice *device); |
59 static void ph_UpdateMouse(_THIS); | |
59 | 60 |
60 #ifdef HAVE_OPENGL | 61 #ifdef HAVE_OPENGL |
61 int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags); | 62 int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags); |
62 static void ph_GL_SwapBuffers(_THIS); | 63 static void ph_GL_SwapBuffers(_THIS); |
63 static int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value); | 64 static int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value); |
88 memset(device, 0, (sizeof *device)); | 89 memset(device, 0, (sizeof *device)); |
89 device->hidden = (struct SDL_PrivateVideoData *) | 90 device->hidden = (struct SDL_PrivateVideoData *) |
90 malloc((sizeof *device->hidden)); | 91 malloc((sizeof *device->hidden)); |
91 device->gl_data = NULL; | 92 device->gl_data = NULL; |
92 } | 93 } |
93 if ( (device == NULL) || (device->hidden == NULL) ) { | 94 if ((device == NULL) || (device->hidden == NULL)) { |
94 SDL_OutOfMemory(); | 95 SDL_OutOfMemory(); |
95 ph_DeleteDevice(device); | 96 ph_DeleteDevice(device); |
96 return(0); | 97 return(0); |
97 } | 98 } |
98 memset(device->hidden, 0, (sizeof *device->hidden)); | 99 memset(device->hidden, 0, (sizeof *device->hidden)); |
104 device->CreateYUVOverlay = ph_CreateYUVOverlay; | 105 device->CreateYUVOverlay = ph_CreateYUVOverlay; |
105 device->VideoInit = ph_VideoInit; | 106 device->VideoInit = ph_VideoInit; |
106 device->ListModes = ph_ListModes; | 107 device->ListModes = ph_ListModes; |
107 device->SetVideoMode = ph_SetVideoMode; | 108 device->SetVideoMode = ph_SetVideoMode; |
108 device->ToggleFullScreen = ph_ToggleFullScreen; | 109 device->ToggleFullScreen = ph_ToggleFullScreen; |
109 device->UpdateMouse = NULL; | 110 device->UpdateMouse = ph_UpdateMouse; |
110 device->SetColors = ph_SetColors; | 111 device->SetColors = ph_SetColors; |
111 device->UpdateRects = NULL; /* ph_ResizeImage */ | 112 device->UpdateRects = NULL; /* ph_SetupUpdateFunction */ |
112 device->VideoQuit = ph_VideoQuit; | 113 device->VideoQuit = ph_VideoQuit; |
113 device->AllocHWSurface = ph_AllocHWSurface; | 114 device->AllocHWSurface = ph_AllocHWSurface; |
114 device->CheckHWBlit = NULL; | 115 device->CheckHWBlit = NULL; |
115 device->FillHWRect = NULL; | 116 device->FillHWRect = NULL; |
116 device->SetHWColorKey = NULL; | 117 device->SetHWColorKey = NULL; |
171 free(device); | 172 free(device); |
172 device = NULL; | 173 device = NULL; |
173 } | 174 } |
174 } | 175 } |
175 | 176 |
177 static PtWidget_t *ph_CreateWindow(_THIS) | |
178 { | |
179 PtWidget_t *widget; | |
180 | |
181 widget = PtCreateWidget(PtWindow, NULL, 0, 0); | |
182 if (widget == NULL) | |
183 { | |
184 SDL_SetError("Couldn't create video window"); | |
185 } | |
186 | |
187 return widget; | |
188 } | |
189 | |
190 static int ph_SetupWindow(_THIS, int w, int h, int flags) | |
191 { | |
192 PtArg_t args[32]; | |
193 PhPoint_t pos = {0, 0}; | |
194 PhDim_t dim = {w, h}; | |
195 int nargs = 0; | |
196 | |
197 PtSetArg(&args[nargs++], Pt_ARG_DIM, &dim, 0); | |
198 PtSetArg(&args[nargs++], Pt_ARG_FILL_COLOR, Pg_BLACK, 0); | |
199 | |
200 if ((flags & SDL_RESIZABLE) == SDL_RESIZABLE) | |
201 { | |
202 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX); | |
203 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_RESIZE | Ph_WM_MAX); | |
204 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX); | |
205 } | |
206 else | |
207 { | |
208 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX); | |
209 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX); | |
210 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX | Ph_WM_RENDER_COLLAPSE); | |
211 } | |
212 | |
213 if (((flags & SDL_NOFRAME)==SDL_NOFRAME) || ((flags & SDL_FULLSCREEN)==SDL_FULLSCREEN)) | |
214 { | |
215 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Pt_TRUE); | |
216 } | |
217 else | |
218 { | |
219 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_BORDER | Ph_WM_RENDER_TITLE | | |
220 Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MIN); | |
221 } | |
222 | |
223 if (flags & SDL_FULLSCREEN) | |
224 { | |
225 PtSetArg(&args[nargs++], Pt_ARG_POS, &pos, 0); | |
226 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_FFRONT | Ph_WM_MAX); | |
227 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISMAX | | |
228 Ph_WM_STATE_ISFOCUS | Ph_WM_STATE_ISALTKEY); | |
229 } | |
230 else | |
231 { | |
232 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISMAX | Ph_WM_STATE_ISALTKEY); | |
233 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_HIDE); | |
234 PtSetArg(&args[nargs++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, Pt_RESIZE_XY_AS_REQUIRED); | |
235 } | |
236 | |
237 PtSetResources(window, nargs, args); | |
238 PtRealizeWidget(window); | |
239 | |
240 return 0; | |
241 } | |
242 | |
176 static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat) | 243 static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat) |
177 { | 244 { |
178 PgVideoModeInfo_t my_mode_info; | 245 PgVideoModeInfo_t my_mode_info; |
179 PgHWCaps_t my_hwcaps; | 246 PgHWCaps_t my_hwcaps; |
180 | 247 |
182 desktoppal=SDLPH_PAL_NONE; | 249 desktoppal=SDLPH_PAL_NONE; |
183 #ifdef HAVE_OPENGL | 250 #ifdef HAVE_OPENGL |
184 oglctx=NULL; | 251 oglctx=NULL; |
185 #endif /* HAVE_OPENGL */ | 252 #endif /* HAVE_OPENGL */ |
186 | 253 |
187 captionflag=0; | |
188 old_video_mode=-1; | 254 old_video_mode=-1; |
189 old_refresh_rate=-1; | 255 old_refresh_rate=-1; |
190 | 256 |
191 if (NULL == (event = malloc(EVENT_SIZE))) | 257 if (NULL == (event = malloc(EVENT_SIZE))) |
192 { | 258 { |
193 exit(EXIT_FAILURE); | 259 SDL_OutOfMemory(); |
260 return -1; | |
194 } | 261 } |
195 memset(event, 0x00, EVENT_SIZE); | 262 memset(event, 0x00, EVENT_SIZE); |
263 | |
264 window = ph_CreateWindow(this); | |
265 if (window == NULL) | |
266 { | |
267 return -1; | |
268 } | |
196 | 269 |
197 /* Create the blank cursor */ | 270 /* Create the blank cursor */ |
198 SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask, | 271 SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask, |
199 (int)BLANK_CWIDTH, (int)BLANK_CHEIGHT, | 272 (int)BLANK_CWIDTH, (int)BLANK_CHEIGHT, |
200 (int)BLANK_CHOTX, (int)BLANK_CHOTY); | 273 (int)BLANK_CHOTX, (int)BLANK_CHOTY); |
201 | 274 |
202 if (SDL_BlankCursor == NULL) | 275 if (SDL_BlankCursor == NULL) |
203 { | 276 { |
204 printf("ph_VideoInit(): could not create blank cursor !\n"); | 277 fprintf(stderr, "ph_VideoInit(): could not create blank cursor !\n"); |
205 } | 278 } |
206 | 279 |
207 if (PgGetGraphicsHWCaps(&my_hwcaps) < 0) | 280 if (PgGetGraphicsHWCaps(&my_hwcaps) < 0) |
208 { | 281 { |
209 fprintf(stderr,"ph_VideoInit(): GetGraphicsHWCaps failed !\n"); | 282 fprintf(stderr,"ph_VideoInit(): GetGraphicsHWCaps failed !\n"); |
220 desktopbpp = my_mode_info.bits_per_pixel; | 293 desktopbpp = my_mode_info.bits_per_pixel; |
221 | 294 |
222 /* save current palette */ | 295 /* save current palette */ |
223 if (desktopbpp==8) | 296 if (desktopbpp==8) |
224 { | 297 { |
225 PgGetPalette(ph_palette); | 298 PgGetPalette(savedpal); |
299 PgGetPalette(syspalph); | |
226 } | 300 } |
227 | 301 |
228 currently_fullscreen = 0; | 302 currently_fullscreen = 0; |
229 | 303 |
230 this->info.wm_available = 1; | 304 this->info.wm_available = 1; |
234 | 308 |
235 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, | 309 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, |
236 int width, int height, int bpp, Uint32 flags) | 310 int width, int height, int bpp, Uint32 flags) |
237 { | 311 { |
238 PgDisplaySettings_t settings; | 312 PgDisplaySettings_t settings; |
313 SDL_Color* colors; | |
239 int mode; | 314 int mode; |
240 PtArg_t arg[32]; | |
241 PhDim_t dim; | |
242 int rtnval; | 315 int rtnval; |
243 int i; | 316 int i; |
244 unsigned long *tempptr; | |
245 int pargc; | |
246 | |
247 dim.w=width; | |
248 dim.h=height; | |
249 | 317 |
250 /* Lock the event thread, in multi-threading environments */ | 318 /* Lock the event thread, in multi-threading environments */ |
251 SDL_Lock_EventThread(); | 319 SDL_Lock_EventThread(); |
252 | 320 |
253 current->flags = flags; | 321 current->flags = flags; |
254 | 322 |
255 /* create window if no OpenGL support selected */ | 323 ph_SetupWindow(this, width, height, flags); |
256 if ((flags & SDL_OPENGL)!=SDL_OPENGL) | |
257 { | |
258 pargc=0; | |
259 | |
260 // prevent using HWSURFACE in window mode if desktop bpp != chosen bpp | |
261 if ((flags & SDL_HWSURFACE) && (!(flags & SDL_FULLSCREEN))) | |
262 { | |
263 if (desktopbpp!=bpp) | |
264 { | |
265 fprintf(stderr, "ph_SetVideoMode(): SDL_HWSURFACE available only with chosen bpp equal desktop bpp !\n"); | |
266 return NULL; | |
267 } | |
268 } | |
269 | |
270 PtSetArg(&arg[pargc++], Pt_ARG_DIM, &dim, 0); | |
271 PtSetArg(&arg[pargc++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, Pt_RESIZE_XY_AS_REQUIRED); | |
272 | |
273 /* enable window minimizing */ | |
274 PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_HIDE); | |
275 | |
276 /* remove border and caption if no frame flag selected */ | |
277 if ((flags & SDL_NOFRAME) == SDL_NOFRAME) | |
278 { | |
279 PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_RENDER_TITLE | Ph_WM_RENDER_BORDER); | |
280 } | |
281 else | |
282 { | |
283 PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_TITLE | Ph_WM_RENDER_BORDER); | |
284 } | |
285 | |
286 /* if window is not resizable then remove resize handles and maximize button */ | |
287 if ((flags & SDL_RESIZABLE) != SDL_RESIZABLE) | |
288 { | |
289 PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX); | |
290 PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX); | |
291 PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX); | |
292 } | |
293 else | |
294 { | |
295 PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX); | |
296 /* it is need to be Pt_FALSE to allow the application to process the resize callback */ | |
297 PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX); | |
298 PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_RESIZE | Ph_WM_MAX); | |
299 } | |
300 | |
301 if (window!=NULL) | |
302 { | |
303 PtUnrealizeWidget(window); | |
304 PtDestroyWidget(window); | |
305 window=NULL; | |
306 } | |
307 | |
308 window=PtCreateWidget(PtWindow, NULL, pargc, arg); | |
309 PtRealizeWidget(window); | |
310 | |
311 PtFlush(); | |
312 } | |
313 | 324 |
314 #ifdef HAVE_OPENGL | 325 #ifdef HAVE_OPENGL |
315 if (flags & SDL_OPENGL) | 326 if (current->flags & SDL_OPENGL) |
316 { | 327 { |
317 /* ph_SetupOpenGLContext creates also window as need */ | 328 /* ph_SetupOpenGLContext creates also window as need */ |
318 if (ph_SetupOpenGLContext(this, width, height, bpp, flags)==0) | 329 if (ph_SetupOpenGLContext(this, width, height, bpp, flags)==0) |
319 { | 330 { |
320 /* setup OGL update function ... ugly method */ | 331 ph_SetupUpdateFunction(this, current, flags); |
321 ph_ResizeImage(this, current, flags); | |
322 } | 332 } |
323 else | 333 else |
324 { | 334 { |
325 /* if context creation fail, report no OpenGL to high level */ | 335 /* if context creation fail, report no OpenGL to high level */ |
326 current->flags=(flags & (~SDL_OPENGL)); | 336 current->flags &= ~SDL_OPENGL; |
327 } | 337 } |
328 #else | 338 #else |
329 if (flags & SDL_OPENGL) /* if no built-in OpenGL support */ | 339 if (current->flags & SDL_OPENGL) /* if no built-in OpenGL support */ |
330 { | 340 { |
331 fprintf(stderr, "ph_SetVideoMode(): no OpenGL support, try to recompile library.\n"); | 341 fprintf(stderr, "ph_SetVideoMode(): no OpenGL support, try to recompile library.\n"); |
332 current->flags=(flags & (~SDL_OPENGL)); | 342 current->flags &= ~SDL_OPENGL; |
333 return NULL; | 343 return NULL; |
334 #endif /* HAVE_OPENGL */ | 344 #endif /* HAVE_OPENGL */ |
335 } | 345 } |
336 else | 346 else |
337 { | 347 { |
338 /* Initialize the window */ | 348 /* Initialize the window */ |
339 if (flags & SDL_FULLSCREEN) /* Direct Context , assume SDL_HWSURFACE also set */ | 349 if (current->flags & SDL_FULLSCREEN) /* Direct Context , assume SDL_HWSURFACE also set */ |
340 { | 350 { |
341 /* Get the video mode and set it */ | 351 /* Get the video mode and set it */ |
342 if (flags & SDL_ANYFORMAT) | 352 if (current->flags & SDL_ANYFORMAT) |
343 { | 353 { |
344 if ((mode = get_mode_any_format(width, height, bpp)) == 0) | 354 if ((mode = get_mode_any_format(width, height, bpp)) == 0) |
345 { | 355 { |
346 fprintf(stderr,"ph_SetVideoMode(): get_mode_any_format failed !\n"); | 356 fprintf(stderr,"ph_SetVideoMode(): get_mode_any_format failed !\n"); |
347 exit(1); | 357 exit(1); |
374 if (PgSetVideoMode(&settings) < 0) | 384 if (PgSetVideoMode(&settings) < 0) |
375 { | 385 { |
376 fprintf(stderr,"ph_SetVideoMode(): PgSetVideoMode failed !\n"); | 386 fprintf(stderr,"ph_SetVideoMode(): PgSetVideoMode failed !\n"); |
377 } | 387 } |
378 | 388 |
379 current->flags = (flags & (~SDL_RESIZABLE)); /* no resize for Direct Context */ | 389 current->flags &= ~SDL_RESIZABLE; /* no resize for Direct Context */ |
390 current->flags |= SDL_HWSURFACE; | |
380 | 391 |
381 /* Begin direct mode */ | 392 /* Begin direct mode */ |
382 ph_EnterFullScreen(this); | 393 ph_EnterFullScreen(this); |
383 | 394 |
384 } /* end fullscreen flag */ | 395 } /* end fullscreen flag */ |
385 else | 396 else |
386 { | 397 { |
387 /* Use offscreen memory iff SDL_HWSURFACE flag is set */ | 398 /* Use offscreen memory iff SDL_HWSURFACE flag is set */ |
388 if (flags & SDL_HWSURFACE) | 399 if (current->flags & SDL_HWSURFACE) |
389 { | 400 { |
390 /* no stretch blit in offscreen context */ | 401 /* no stretch blit in offscreen context */ |
391 current->flags = (flags & (~SDL_RESIZABLE)); | 402 current->flags &= ~SDL_RESIZABLE; |
392 } | 403 } |
393 | 404 |
394 /* using palette emulation code in window mode */ | 405 /* using palette emulation code in window mode */ |
395 if (bpp==8) | 406 if (bpp==8) |
396 { | 407 { |
400 } | 411 } |
401 else | 412 else |
402 { | 413 { |
403 desktoppal=SDLPH_PAL_SYSTEM; | 414 desktoppal=SDLPH_PAL_SYSTEM; |
404 } | 415 } |
416 | |
417 /* fill the palette */ | |
418 PgGetPalette(savedpal); | |
419 PgGetPalette(syspalph); | |
420 | |
421 current->format->palette = calloc(1, sizeof(SDL_Palette)); | |
422 current->format->palette->ncolors = _Pg_MAX_PALETTE; | |
423 current->format->palette->colors = (SDL_Color *)calloc(_Pg_MAX_PALETTE, sizeof(SDL_Color)); | |
424 | |
425 colors = current->format->palette->colors; | |
426 | |
427 for(i=0; i<256; i++) | |
428 { | |
429 colors[i].r = PgRedValue(syspalph[i]); | |
430 colors[i].g = PgGreenValue(syspalph[i]); | |
431 colors[i].b = PgBlueValue(syspalph[i]); | |
432 } | |
405 } | 433 } |
406 else | 434 else |
407 { | 435 { |
408 desktoppal=SDLPH_PAL_NONE; | 436 desktoppal=SDLPH_PAL_NONE; |
409 } | 437 } |
410 } | 438 } |
411 | |
412 /* If we are setting video to use the palette make sure we have allocated memory for it */ | |
413 if (bpp==8) | |
414 { | |
415 current->format->palette = malloc(sizeof(SDL_Palette)); | |
416 memset(current->format->palette, 0, sizeof(SDL_Palette)); | |
417 current->format->palette->ncolors = 256; | |
418 current->format->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color)); | |
419 /* fill the palette */ | |
420 rtnval = PgGetPalette(ph_palette); | |
421 | |
422 tempptr = (unsigned long *)current->format->palette->colors; | |
423 | |
424 for(i=0; i<256; i++) | |
425 { | |
426 *tempptr = (((unsigned long)ph_palette[i]) << 8); | |
427 tempptr++; | |
428 } | |
429 } | |
430 | |
431 } | 439 } |
432 | 440 |
433 current->w = width; | 441 current->w = width; |
434 current->h = height; | 442 current->h = height; |
443 | |
444 /* These values can be overridden in ph_SetupUpdateFunction() */ | |
435 current->format->BitsPerPixel = bpp; | 445 current->format->BitsPerPixel = bpp; |
436 current->format->BytesPerPixel = (bpp+7)/8; | 446 current->format->BytesPerPixel = (bpp+7)/8; |
437 current->pitch = SDL_CalculatePitch(current); | 447 current->pitch = SDL_CalculatePitch(current); |
438 | 448 |
439 /* Must call at least once it setup image planes */ | 449 /* Must call at least once it setup image planes */ |
440 rtnval = ph_ResizeImage(this, current, flags); | 450 rtnval = ph_SetupUpdateFunction(this, current, current->flags); |
441 | 451 |
442 if (rtnval==-1) | 452 if (rtnval==-1) |
443 { | 453 { |
444 fprintf(stderr,"ph_SetVideoMode(): ph_ResizeImage failed !\n"); | 454 fprintf(stderr,"ph_SetVideoMode(): ph_SetupUpdateFunction failed !\n"); |
445 return NULL; | 455 return NULL; |
446 } | |
447 | |
448 /* delayed set caption call */ | |
449 if (captionflag) | |
450 { | |
451 ph_SetCaption(this, this->wm_title, NULL); | |
452 } | 456 } |
453 | 457 |
454 /* finish window drawing */ | 458 /* finish window drawing */ |
455 PtFlush(); | 459 PtFlush(); |
456 | 460 |
493 { | 497 { |
494 PtUnrealizeWidget(window); | 498 PtUnrealizeWidget(window); |
495 PtDestroyWidget(window); | 499 PtDestroyWidget(window); |
496 window=NULL; | 500 window=NULL; |
497 } | 501 } |
498 | |
499 /* restore palette */ | |
500 if (desktoppal!=SDLPH_PAL_NONE) | |
501 { | |
502 PgSetPalette(ph_palette, 0, 0, _Pg_MAX_PALETTE, Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0); | |
503 } | |
504 | 502 |
505 #ifdef HAVE_OPENGL | 503 #ifdef HAVE_OPENGL |
506 if (oglctx) | 504 if (oglctx) |
507 { | 505 { |
508 PhDCSetCurrent(NULL); | 506 PhDCSetCurrent(NULL); |
509 PhDCRelease(oglctx); | 507 PhDCRelease(oglctx); |
510 oglctx=NULL; | 508 oglctx=NULL; |
511 } | 509 } |
512 #endif /* HAVE_OPENGL */ | 510 #endif /* HAVE_OPENGL */ |
511 | |
512 /* restore palette */ | |
513 if (desktoppal!=SDLPH_PAL_NONE) | |
514 { | |
515 PgSetPalette(savedpal, 1, 0, _Pg_MAX_PALETTE, Pg_PALSET_HARD | Pg_PALSET_FORCE_EXPOSE, 0); | |
516 /* pass -1, to force release palette */ | |
517 PgSetPalette(savedpal, 1, 0, -1, Pg_PALSET_HARD | Pg_PALSET_FORCE_EXPOSE, 0); | |
518 } | |
519 | |
520 if (event!=NULL) | |
521 { | |
522 free(event); | |
523 event=NULL; | |
524 } | |
513 } | 525 } |
514 | 526 |
515 static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | 527 static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) |
516 { | 528 { |
517 int i; | 529 int i; |
518 PhPoint_t point={0, 0}; | 530 SDL_Rect updaterect; |
519 PgColor_t syspalph[_Pg_MAX_PALETTE]; | 531 |
532 updaterect.x = updaterect.y = 0; | |
533 updaterect.w = this->screen->w; | |
534 updaterect.h = this->screen->h; | |
520 | 535 |
521 /* palette emulation code, using palette of the PhImage_t struct */ | 536 /* palette emulation code, using palette of the PhImage_t struct */ |
522 if (desktoppal==SDLPH_PAL_EMULATE) | 537 if (desktoppal==SDLPH_PAL_EMULATE) |
523 { | 538 { |
524 if ((SDL_Image) && (SDL_Image->palette)) | 539 if ((SDL_Image) && (SDL_Image->palette)) |
525 { | 540 { |
526 for (i=firstcolor; i<firstcolor+ncolors; i++) | 541 for (i=firstcolor; i<firstcolor+ncolors; i++) |
527 { | 542 { |
528 SDL_Image->palette[i] = 0x00000000UL; | 543 syspalph[i] = PgRGB(colors[i-firstcolor].r, colors[i-firstcolor].g, colors[i-firstcolor].b); |
529 SDL_Image->palette[i] |= colors[i-firstcolor].r<<16; | 544 SDL_Image->palette[i] = syspalph[i]; |
530 SDL_Image->palette[i] |= colors[i-firstcolor].g<<8; | 545 } |
531 SDL_Image->palette[i] |= colors[i-firstcolor].b; | 546 /* image needs to be redrawn */ |
532 } | 547 this->UpdateRects(this, 1, &updaterect); |
533 | |
534 /* image needs to be redrawed, very slow method */ | |
535 PgDrawPhImage(&point, SDL_Image, 0); | |
536 } | 548 } |
537 } | 549 } |
538 else | 550 else |
539 { | 551 { |
540 if (desktoppal==SDLPH_PAL_SYSTEM) | 552 if (desktoppal==SDLPH_PAL_SYSTEM) |
541 { | 553 { |
542 for (i=firstcolor; i<firstcolor+ncolors; i++) | 554 for (i=firstcolor; i<firstcolor+ncolors; i++) |
543 { | 555 { |
544 syspalph[i] = 0x00000000UL; | 556 syspalph[i] = PgRGB(colors[i-firstcolor].r, colors[i-firstcolor].g, colors[i-firstcolor].b); |
545 syspalph[i] |= colors[i-firstcolor].r<<16; | |
546 syspalph[i] |= colors[i-firstcolor].g<<8; | |
547 syspalph[i] |= colors[i-firstcolor].b; | |
548 } | 557 } |
549 | 558 |
550 if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) | 559 if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) |
551 { | 560 { |
552 /* window mode must use soft palette */ | 561 /* window mode must use soft palette */ |
553 PgSetPalette((PgColor_t*)&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_SOFT, 0); | 562 PgSetPalette(&syspalph[firstcolor], 1, firstcolor, ncolors, Pg_PALSET_SOFT, 0); |
554 /* image needs to be redrawed, very slow method */ | 563 /* image needs to be redrawn */ |
555 if (SDL_Image) | 564 this->UpdateRects(this, 1, &updaterect); |
556 { | |
557 PgDrawPhImage(&point, SDL_Image, 0); | |
558 } | |
559 } | 565 } |
560 else | 566 else |
561 { | 567 { |
562 /* fullscreen mode must use hardware palette */ | 568 /* fullscreen mode must use hardware palette */ |
563 PgSetPalette((PgColor_t*)&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0); | 569 PgSetPalette(&syspalph[firstcolor], 1, firstcolor, ncolors, Pg_PALSET_HARDLOCKED, 0); |
564 } | 570 } |
565 } | 571 } |
566 else | 572 else |
567 { | 573 { |
568 /* SDLPH_PAL_NONE do nothing */ | 574 /* SDLPH_PAL_NONE do nothing */ |
574 | 580 |
575 #ifdef HAVE_OPENGL | 581 #ifdef HAVE_OPENGL |
576 | 582 |
577 int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags) | 583 int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags) |
578 { | 584 { |
579 PtArg_t args[8]; | |
580 PhDim_t dim; | 585 PhDim_t dim; |
581 uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS]; | 586 uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS]; |
582 int OGLargc; | 587 int OGLargc; |
583 int pargc; | |
584 | 588 |
585 dim.w=width; | 589 dim.w=width; |
586 dim.h=height; | 590 dim.h=height; |
587 | 591 |
588 if (oglctx!=NULL) | 592 if (oglctx!=NULL) |
627 fprintf(stderr,"ph_SetupOpenGLContext(): cannot create OpenGL context.\n"); | 631 fprintf(stderr,"ph_SetupOpenGLContext(): cannot create OpenGL context.\n"); |
628 return (-1); | 632 return (-1); |
629 } | 633 } |
630 | 634 |
631 PhDCSetCurrent(oglctx); | 635 PhDCSetCurrent(oglctx); |
632 | |
633 pargc=0; | |
634 | |
635 PtSetArg(&args[pargc++], Pt_ARG_DIM, &dim, 0); | |
636 PtSetArg(&args[pargc++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, Pt_RESIZE_XY_AS_REQUIRED); | |
637 PtSetArg(&args[pargc++], Pt_ARG_FILL_COLOR, Pg_BLACK, 0); | |
638 | |
639 if (flags & SDL_FULLSCREEN) | |
640 { | |
641 PhPoint_t pos; | |
642 | |
643 pos.x=0; | |
644 pos.y=0; | |
645 | |
646 PtSetArg(&args[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, ~0); | |
647 PtSetArg(&args[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_FFRONT | Ph_WM_CLOSE | Ph_WM_TOFRONT | Ph_WM_CONSWITCH); | |
648 PtSetArg(&args[pargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISFOCUS); | |
649 PtSetArg(&args[pargc++], Pt_ARG_POS, &pos, 0); | |
650 } | |
651 else | |
652 { | |
653 /* remove border and caption if no frame flag selected */ | |
654 if ((flags & SDL_NOFRAME) == SDL_NOFRAME) | |
655 { | |
656 PtSetArg(&args[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, 0, Ph_WM_RENDER_TITLE | Ph_WM_RENDER_BORDER); | |
657 } | |
658 else | |
659 { | |
660 /* if window is not resizable then remove resize handles */ | |
661 if ((flags & SDL_RESIZABLE) != SDL_RESIZABLE) | |
662 { | |
663 PtSetArg(&args[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, 0, Ph_WM_RENDER_RESIZE); | |
664 } | |
665 } | |
666 } | |
667 | |
668 if (window!=NULL) | |
669 { | |
670 PtUnrealizeWidget(window); | |
671 PtDestroyWidget(window); | |
672 window=NULL; | |
673 } | |
674 | |
675 window=PtCreateWidget(PtWindow, NULL, pargc, args); | |
676 PtRealizeWidget(window); | |
677 | 636 |
678 /* disable mouse for fullscreen */ | 637 /* disable mouse for fullscreen */ |
679 if (flags & SDL_FULLSCREEN) | 638 if (flags & SDL_FULLSCREEN) |
680 { | 639 { |
681 PhRegion_t region_info; | 640 PhRegion_t region_info; |
715 } | 674 } |
716 return 0; | 675 return 0; |
717 } | 676 } |
718 | 677 |
719 #endif /* HAVE_OPENGL */ | 678 #endif /* HAVE_OPENGL */ |
679 | |
680 static void ph_UpdateMouse(_THIS) | |
681 { | |
682 PhCursorInfo_t phcursor; | |
683 short abs_x; | |
684 short abs_y; | |
685 | |
686 /* Lock the event thread, in multi-threading environments */ | |
687 SDL_Lock_EventThread(); | |
688 | |
689 /* synchronizing photon mouse cursor position and SDL mouse position, if cursor appears over window. */ | |
690 PtGetAbsPosition(window, &abs_x, &abs_y); | |
691 PhQueryCursor(PhInputGroup(NULL), &phcursor); | |
692 if (((phcursor.pos.x >= abs_x) && (phcursor.pos.x <= abs_x + this->screen->w)) && | |
693 ((phcursor.pos.y >= abs_y) && (phcursor.pos.y <= abs_y + this->screen->h))) | |
694 { | |
695 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); | |
696 SDL_PrivateMouseMotion(0, 0, phcursor.pos.x-abs_x, phcursor.pos.y-abs_y); | |
697 } | |
698 else | |
699 { | |
700 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); | |
701 } | |
702 | |
703 /* Unlock the event thread, in multi-threading environments */ | |
704 SDL_Unlock_EventThread(); | |
705 } |