Mercurial > sdl-ios-xcode
comparison src/video/photon/SDL_ph_video.c @ 663:8bedd6d61642
Date: Sat, 2 Aug 2003 16:22:51 +0300
From: "Mike Gorchak"
Subject: New patches for QNX6
Here my patches for the SDL/QNX:
QNXSDL.diff - diff to non-QNX related sources:
- updated BUGS file, I think QNX6 is now will be officially supported
- configure.in - added shared library support for QNX, and removed dependency between the ALSA and QNX6.
- SDL_audio.c - added QNX NTO sound bootstrap insted of ALSA's.
- SDL_sysaudio.h - the same.
- SDL_nto_audio.c - the same.
- SDL_video.c - right now, QNX doesn't offer any method to obtain pointers to the OpenGL functions by function name, so they must be hardcoded in library, otherwise OpenGL will not be supported.
- testsprite.c - fixed: do not draw vertical red line if we are in non-double-buffered mode.
sdlqnxph.tar.gz - archive of the ./src/video/photon/* . Too many changes in code to make diffs :) :
+ Added stub for support hide/unhide window event
+ Added full YUV overlays support.
+ Added window maximize support.
+ Added mouse wheel events.
+ Added support for some specific key codes in Unicode mode (like ESC).
+ Added more checks to the all memory allocation code.
+ Added SDL_DOUBLEBUF support in all fullscreen modes.
+ Added fallback to window mode, if desired fullscreen mode is not supported.
+ Added stub support for the GL_LoadLibrary and GL_GetProcAddress functions.
+ Added resizable window support without caption.
! Fixed bug in the Ph_EV_EXPOSE event handler, when rectangles to update is 0 and when width or height of the rectangle is 0.
! Fixed bug in the event handler code. Events has not been passed to the window widget handler.
! Fixed codes for Win keys (Super/Hyper/Menu).
! Fixed memory leak, when deallocation palette.
! Fixed palette emulation code bugs.
! Fixed fullscreen and hwsurface handling.
! Fixed CLOSE button bug. First event was passed to the handler, but second terminated the application. Now all events passed to the application correctly.
- Removed all printfs in code, now SDL_SetError used instead of them.
- Disabled ToggleFullScreen function.
README.QNX - updated README.QNX file. Added much more issues.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 04 Aug 2003 00:52:42 +0000 |
parents | 8e3ce997621c |
children | 04dd6c6d7c30 |
comparison
equal
deleted
inserted
replaced
662:66c02f83f5bf | 663:8bedd6d61642 |
---|---|
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 static void ph_UpdateMouse(_THIS); |
60 | 60 |
61 #ifdef HAVE_OPENGL | 61 #ifdef HAVE_OPENGL |
62 int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags); | 62 static int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags); |
63 static void ph_GL_SwapBuffers(_THIS); | 63 static void ph_GL_SwapBuffers(_THIS); |
64 static int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value); | 64 static int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value); |
65 static int ph_GL_LoadLibrary(_THIS, const char* path); | |
66 static void* ph_GL_GetProcAddress(_THIS, const char* proc); | |
67 | |
65 #endif /* HAVE_OPENGL */ | 68 #endif /* HAVE_OPENGL */ |
66 | 69 |
67 static int ph_Available(void) | 70 static int ph_Available(void) |
68 { | 71 { |
69 int phstat=-1; | 72 int phstat=-1; |
107 device->ListModes = ph_ListModes; | 110 device->ListModes = ph_ListModes; |
108 device->SetVideoMode = ph_SetVideoMode; | 111 device->SetVideoMode = ph_SetVideoMode; |
109 device->ToggleFullScreen = ph_ToggleFullScreen; | 112 device->ToggleFullScreen = ph_ToggleFullScreen; |
110 device->UpdateMouse = ph_UpdateMouse; | 113 device->UpdateMouse = ph_UpdateMouse; |
111 device->SetColors = ph_SetColors; | 114 device->SetColors = ph_SetColors; |
112 device->UpdateRects = NULL; /* ph_SetupUpdateFunction */ | 115 device->UpdateRects = NULL; /* set up in ph_SetupUpdateFunction */ |
113 device->VideoQuit = ph_VideoQuit; | 116 device->VideoQuit = ph_VideoQuit; |
114 device->AllocHWSurface = ph_AllocHWSurface; | 117 device->AllocHWSurface = ph_AllocHWSurface; |
115 device->CheckHWBlit = NULL; | 118 device->CheckHWBlit = NULL; |
116 device->FillHWRect = NULL; | 119 device->FillHWRect = NULL; |
117 device->SetHWColorKey = NULL; | 120 device->SetHWColorKey = NULL; |
132 device->CheckMouseMode = ph_CheckMouseMode; | 135 device->CheckMouseMode = ph_CheckMouseMode; |
133 device->InitOSKeymap = ph_InitOSKeymap; | 136 device->InitOSKeymap = ph_InitOSKeymap; |
134 device->PumpEvents = ph_PumpEvents; | 137 device->PumpEvents = ph_PumpEvents; |
135 | 138 |
136 /* OpenGL support. */ | 139 /* OpenGL support. */ |
137 device->GL_LoadLibrary = NULL; | |
138 device->GL_GetProcAddress = NULL; | |
139 device->GL_MakeCurrent = NULL; | 140 device->GL_MakeCurrent = NULL; |
140 #ifdef HAVE_OPENGL | 141 #ifdef HAVE_OPENGL |
141 device->GL_SwapBuffers = ph_GL_SwapBuffers; | 142 device->GL_SwapBuffers = ph_GL_SwapBuffers; |
142 device->GL_GetAttribute = ph_GL_GetAttribute; | 143 device->GL_GetAttribute = ph_GL_GetAttribute; |
144 device->GL_LoadLibrary = ph_GL_LoadLibrary; | |
145 device->GL_GetProcAddress = ph_GL_GetProcAddress; | |
143 #else | 146 #else |
144 device->GL_SwapBuffers = NULL; | 147 device->GL_SwapBuffers = NULL; |
145 device->GL_GetAttribute = NULL; | 148 device->GL_GetAttribute = NULL; |
149 device->GL_LoadLibrary = NULL; | |
150 device->GL_GetProcAddress = NULL; | |
146 #endif /* HAVE_OPENGL */ | 151 #endif /* HAVE_OPENGL */ |
147 | 152 |
148 device->free = ph_DeleteDevice; | 153 device->free = ph_DeleteDevice; |
149 | 154 |
150 return device; | 155 return device; |
151 } | 156 } |
152 | 157 |
153 VideoBootStrap ph_bootstrap = { | 158 VideoBootStrap ph_bootstrap = { |
154 "photon", "QNX Photon video output", | 159 "photon", "QNX Photon video output", |
177 static PtWidget_t *ph_CreateWindow(_THIS) | 182 static PtWidget_t *ph_CreateWindow(_THIS) |
178 { | 183 { |
179 PtWidget_t *widget; | 184 PtWidget_t *widget; |
180 | 185 |
181 widget = PtCreateWidget(PtWindow, NULL, 0, 0); | 186 widget = PtCreateWidget(PtWindow, NULL, 0, 0); |
182 if (widget == NULL) | |
183 { | |
184 SDL_SetError("Couldn't create video window"); | |
185 } | |
186 | 187 |
187 return widget; | 188 return widget; |
188 } | 189 } |
189 | 190 |
190 static int ph_SetupWindow(_THIS, int w, int h, int flags) | 191 static int ph_SetupWindow(_THIS, int w, int h, int flags) |
197 PtSetArg(&args[nargs++], Pt_ARG_DIM, &dim, 0); | 198 PtSetArg(&args[nargs++], Pt_ARG_DIM, &dim, 0); |
198 PtSetArg(&args[nargs++], Pt_ARG_FILL_COLOR, Pg_BLACK, 0); | 199 PtSetArg(&args[nargs++], Pt_ARG_FILL_COLOR, Pg_BLACK, 0); |
199 | 200 |
200 if ((flags & SDL_RESIZABLE) == SDL_RESIZABLE) | 201 if ((flags & SDL_RESIZABLE) == SDL_RESIZABLE) |
201 { | 202 { |
202 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX); | 203 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_CLOSE); |
203 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_RESIZE | Ph_WM_MAX); | 204 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_MAX | Ph_WM_RESTORE); |
204 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX); | 205 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_RESIZE | Ph_WM_MOVE | Ph_WM_MAX | Ph_WM_RESTORE | Ph_WM_CLOSE); |
205 } | 206 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX | Ph_WM_RENDER_COLLAPSE | Ph_WM_RENDER_RETURN); |
206 else | 207 } |
207 { | 208 else |
208 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX); | 209 { |
209 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX); | 210 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX | Ph_WM_RESTORE | Ph_WM_CLOSE); |
210 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX | Ph_WM_RENDER_COLLAPSE); | 211 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX | Ph_WM_RESTORE); |
212 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_MOVE | Ph_WM_CLOSE); | |
213 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX | Ph_WM_RENDER_COLLAPSE | Ph_WM_RENDER_RETURN); | |
211 } | 214 } |
212 | 215 |
213 if (((flags & SDL_NOFRAME)==SDL_NOFRAME) || ((flags & SDL_FULLSCREEN)==SDL_FULLSCREEN)) | 216 if (((flags & SDL_NOFRAME)==SDL_NOFRAME) || ((flags & SDL_FULLSCREEN)==SDL_FULLSCREEN)) |
214 { | 217 { |
215 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Pt_TRUE); | 218 if ((flags & SDL_RESIZABLE) != SDL_RESIZABLE) |
219 { | |
220 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Pt_TRUE); | |
221 } | |
222 else | |
223 { | |
224 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Pt_TRUE); | |
225 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_BORDER); | |
226 } | |
216 } | 227 } |
217 else | 228 else |
218 { | 229 { |
219 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_BORDER | Ph_WM_RENDER_TITLE | | 230 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); | 231 Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MIN); |
221 } | 232 } |
222 | 233 |
223 if (flags & SDL_FULLSCREEN) | 234 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) |
224 { | 235 { |
225 PtSetArg(&args[nargs++], Pt_ARG_POS, &pos, 0); | 236 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); | 237 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 | | 238 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); | 239 Ph_WM_STATE_ISFOCUS | Ph_WM_STATE_ISALTKEY); |
229 } | 240 } |
230 else | 241 else |
231 { | 242 { |
232 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISMAX | Ph_WM_STATE_ISALTKEY); | 243 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); | 244 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_HIDE); |
245 PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_HIDE); | |
234 PtSetArg(&args[nargs++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, Pt_RESIZE_XY_AS_REQUIRED); | 246 PtSetArg(&args[nargs++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, Pt_RESIZE_XY_AS_REQUIRED); |
235 } | 247 } |
236 | 248 |
237 PtSetResources(window, nargs, args); | 249 PtSetResources(window, nargs, args); |
238 PtRealizeWidget(window); | 250 PtRealizeWidget(window); |
239 | 251 |
240 return 0; | 252 return 0; |
241 } | 253 } |
242 | 254 |
255 static const struct ColourMasks* ph_GetColourMasks(int bpp) | |
256 { | |
257 /* The alpha mask doesn't appears to be needed */ | |
258 static const struct ColourMasks phColorMasks[5] = { | |
259 /* 8 bit */ {0, 0, 0, 0, 8}, | |
260 /* 15 bit ARGB */ {0x7C00, 0x03E0, 0x001F, 0x8000, 15}, | |
261 /* 16 bit RGB */ {0xF800, 0x07E0, 0x001F, 0x0000, 16}, | |
262 /* 24 bit RGB */ {0xFF0000, 0x00FF00, 0x0000FF, 0x000000, 24}, | |
263 /* 32 bit ARGB */ {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000, 32}, | |
264 }; | |
265 | |
266 switch (bpp) | |
267 { | |
268 case 8: | |
269 return &phColorMasks[0]; | |
270 case 15: | |
271 return &phColorMasks[1]; | |
272 case 16: | |
273 return &phColorMasks[2]; | |
274 case 24: | |
275 return &phColorMasks[3]; | |
276 case 32: | |
277 return &phColorMasks[4]; | |
278 } | |
279 return NULL; | |
280 } | |
281 | |
243 static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat) | 282 static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat) |
244 { | 283 { |
245 PgVideoModeInfo_t my_mode_info; | 284 PgVideoModeInfo_t my_mode_info; |
246 PgHWCaps_t my_hwcaps; | 285 PgHWCaps_t my_hwcaps; |
286 int i; | |
247 | 287 |
248 window=NULL; | 288 window=NULL; |
249 desktoppal=SDLPH_PAL_NONE; | 289 desktoppal=SDLPH_PAL_NONE; |
250 #ifdef HAVE_OPENGL | 290 #ifdef HAVE_OPENGL |
251 oglctx=NULL; | 291 oglctx=NULL; |
262 memset(event, 0x00, EVENT_SIZE); | 302 memset(event, 0x00, EVENT_SIZE); |
263 | 303 |
264 window = ph_CreateWindow(this); | 304 window = ph_CreateWindow(this); |
265 if (window == NULL) | 305 if (window == NULL) |
266 { | 306 { |
307 SDL_SetError("ph_VideoInit(): Couldn't create video window !\n"); | |
267 return -1; | 308 return -1; |
268 } | 309 } |
269 | 310 |
270 /* Create the blank cursor */ | 311 /* Create the blank cursor */ |
271 SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask, | 312 SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask, |
272 (int)BLANK_CWIDTH, (int)BLANK_CHEIGHT, | 313 (int)BLANK_CWIDTH, (int)BLANK_CHEIGHT, |
273 (int)BLANK_CHOTX, (int)BLANK_CHOTY); | 314 (int)BLANK_CHOTX, (int)BLANK_CHOTY); |
274 | 315 |
275 if (SDL_BlankCursor == NULL) | 316 if (SDL_BlankCursor == NULL) |
276 { | 317 { |
277 fprintf(stderr, "ph_VideoInit(): could not create blank cursor !\n"); | 318 return -1; |
278 } | 319 } |
279 | 320 |
280 if (PgGetGraphicsHWCaps(&my_hwcaps) < 0) | 321 if (PgGetGraphicsHWCaps(&my_hwcaps) < 0) |
281 { | 322 { |
282 fprintf(stderr,"ph_VideoInit(): GetGraphicsHWCaps failed !\n"); | 323 SDL_SetError("ph_VideoInit(): GetGraphicsHWCaps function failed !\n"); |
324 this->FreeWMCursor(this, SDL_BlankCursor); | |
325 return -1; | |
283 } | 326 } |
284 | 327 |
285 if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &my_mode_info) < 0) | 328 if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &my_mode_info) < 0) |
286 { | 329 { |
287 fprintf(stderr,"ph_VideoInit(): PgGetVideoModeInfo failed !\n"); | 330 SDL_SetError("ph_VideoInit(): PgGetVideoModeInfo function failed !\n"); |
331 this->FreeWMCursor(this, SDL_BlankCursor); | |
332 return -1; | |
288 } | 333 } |
289 | 334 |
290 /* We need to return BytesPerPixel as it in used by CreateRGBsurface */ | 335 /* We need to return BytesPerPixel as it in used by CreateRGBsurface */ |
291 vformat->BitsPerPixel = my_mode_info.bits_per_pixel; | 336 vformat->BitsPerPixel = my_mode_info.bits_per_pixel; |
292 vformat->BytesPerPixel = my_mode_info.bytes_per_scanline/my_mode_info.width; | 337 vformat->BytesPerPixel = my_mode_info.bytes_per_scanline/my_mode_info.width; |
296 if (desktopbpp==8) | 341 if (desktopbpp==8) |
297 { | 342 { |
298 PgGetPalette(savedpal); | 343 PgGetPalette(savedpal); |
299 PgGetPalette(syspalph); | 344 PgGetPalette(syspalph); |
300 } | 345 } |
346 else | |
347 { | |
348 for(i=0; i<_Pg_MAX_PALETTE; i++) | |
349 { | |
350 savedpal[i]=PgRGB(0, 0, 0); | |
351 syspalph[i]=PgRGB(0, 0, 0); | |
352 } | |
353 } | |
301 | 354 |
302 currently_fullscreen = 0; | 355 currently_fullscreen = 0; |
356 currently_hided = 0; | |
357 current_overlay = NULL; | |
358 | |
359 OCImage.direct_context = NULL; | |
360 OCImage.offscreen_context = NULL; | |
361 OCImage.offscreen_backcontext = NULL; | |
362 OCImage.oldDC = NULL; | |
363 OCImage.CurrentFrameData = NULL; | |
364 OCImage.FrameData0 = NULL; | |
365 OCImage.FrameData1 = NULL; | |
366 | |
303 | 367 |
304 this->info.wm_available = 1; | 368 this->info.wm_available = 1; |
305 | 369 |
306 return 0; | 370 return 0; |
307 } | 371 } |
308 | 372 |
309 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, | 373 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, |
310 int width, int height, int bpp, Uint32 flags) | 374 int width, int height, int bpp, Uint32 flags) |
311 { | 375 { |
312 PgDisplaySettings_t settings; | 376 const struct ColourMasks* mask; |
313 SDL_Color* colors; | |
314 int mode; | |
315 int rtnval; | |
316 int i; | |
317 | 377 |
318 /* Lock the event thread, in multi-threading environments */ | 378 /* Lock the event thread, in multi-threading environments */ |
319 SDL_Lock_EventThread(); | 379 SDL_Lock_EventThread(); |
320 | 380 |
321 current->flags = flags; | 381 current->flags = flags; |
322 | 382 |
323 ph_SetupWindow(this, width, height, flags); | 383 /* if we do not have desired fullscreen mode, then fallback into window mode */ |
384 if (((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) && (ph_GetVideoMode(width, height, bpp)==0)) | |
385 { | |
386 current->flags &= ~SDL_FULLSCREEN; | |
387 current->flags &= ~SDL_NOFRAME; | |
388 current->flags &= ~SDL_RESIZABLE; | |
389 } | |
390 | |
391 ph_SetupWindow(this, width, height, current->flags); | |
392 | |
393 mask = ph_GetColourMasks(bpp); | |
394 if (mask != NULL) | |
395 { | |
396 SDL_ReallocFormat(current, mask->bpp, mask->red, mask->green, mask->blue, 0); | |
397 } | |
398 else | |
399 { | |
400 SDL_SetError("ph_SetVideoMode(): desired bpp is not supported by photon !\n"); | |
401 return NULL; | |
402 } | |
324 | 403 |
325 #ifdef HAVE_OPENGL | 404 #ifdef HAVE_OPENGL |
326 if (current->flags & SDL_OPENGL) | 405 if (current->flags & SDL_OPENGL) |
327 { | 406 { |
328 /* ph_SetupOpenGLContext creates also window as need */ | 407 /* ph_SetupOpenGLContext creates also window as need */ |
332 } | 411 } |
333 else | 412 else |
334 { | 413 { |
335 /* if context creation fail, report no OpenGL to high level */ | 414 /* if context creation fail, report no OpenGL to high level */ |
336 current->flags &= ~SDL_OPENGL; | 415 current->flags &= ~SDL_OPENGL; |
416 return NULL; | |
337 } | 417 } |
338 #else | 418 #else |
339 if (current->flags & SDL_OPENGL) /* if no built-in OpenGL support */ | 419 if (current->flags & SDL_OPENGL) /* if no built-in OpenGL support */ |
340 { | 420 { |
341 fprintf(stderr, "ph_SetVideoMode(): no OpenGL support, try to recompile library.\n"); | 421 SDL_SetError("ph_SetVideoMode(): no OpenGL support, try to recompile library.\n"); |
342 current->flags &= ~SDL_OPENGL; | 422 current->flags &= ~SDL_OPENGL; |
343 return NULL; | 423 return NULL; |
344 #endif /* HAVE_OPENGL */ | 424 #endif /* HAVE_OPENGL */ |
345 } | 425 } |
346 else | 426 else |
347 { | 427 { |
348 /* Initialize the window */ | 428 /* Initialize internal variables */ |
349 if (current->flags & SDL_FULLSCREEN) /* Direct Context , assume SDL_HWSURFACE also set */ | 429 if ((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) |
350 { | 430 { |
351 /* Get the video mode and set it */ | |
352 if (current->flags & SDL_ANYFORMAT) | |
353 { | |
354 if ((mode = get_mode_any_format(width, height, bpp)) == 0) | |
355 { | |
356 fprintf(stderr,"ph_SetVideoMode(): get_mode_any_format failed !\n"); | |
357 exit(1); | |
358 } | |
359 } | |
360 else | |
361 { | |
362 if ((mode = get_mode(width, height, bpp)) == 0) | |
363 { | |
364 fprintf(stderr,"ph_SetVideoMode(): get_mode failed !\n"); | |
365 exit(1); | |
366 } | |
367 } | |
368 | |
369 if (bpp==8) | 431 if (bpp==8) |
370 { | 432 { |
371 desktoppal=SDLPH_PAL_SYSTEM; | 433 desktoppal=SDLPH_PAL_SYSTEM; |
372 } | 434 } |
373 | 435 |
374 /* save old video mode caps */ | 436 current->flags &= ~SDL_RESIZABLE; /* no resize for Direct Context */ |
375 PgGetVideoMode(&settings); | 437 } |
376 old_video_mode=settings.mode; | 438 else |
377 old_refresh_rate=settings.refresh; | 439 { |
378 | 440 /* remove this if we'll support non-fullscreen sw/hw+doublebuf */ |
379 /* setup new video mode */ | 441 current->flags &= ~SDL_DOUBLEBUF; |
380 settings.mode = mode; | 442 |
381 settings.refresh = 0; | 443 /* Use offscreen memory if SDL_HWSURFACE flag is set */ |
382 settings.flags = 0; | 444 if ((current->flags & SDL_HWSURFACE) == SDL_HWSURFACE) |
383 | |
384 if (PgSetVideoMode(&settings) < 0) | |
385 { | 445 { |
386 fprintf(stderr,"ph_SetVideoMode(): PgSetVideoMode failed !\n"); | 446 |
387 } | 447 if (desktopbpp!=bpp) |
388 | 448 { |
389 current->flags &= ~SDL_RESIZABLE; /* no resize for Direct Context */ | 449 current->flags &= ~SDL_HWSURFACE; |
390 current->flags |= SDL_HWSURFACE; | 450 } |
391 | |
392 /* Begin direct mode */ | |
393 ph_EnterFullScreen(this); | |
394 | |
395 } /* end fullscreen flag */ | |
396 else | |
397 { | |
398 /* Use offscreen memory iff SDL_HWSURFACE flag is set */ | |
399 if (current->flags & SDL_HWSURFACE) | |
400 { | |
401 /* no stretch blit in offscreen context */ | |
402 current->flags &= ~SDL_RESIZABLE; | |
403 } | 451 } |
404 | 452 |
405 /* using palette emulation code in window mode */ | 453 /* using palette emulation code in window mode */ |
406 if (bpp==8) | 454 if (bpp==8) |
407 { | 455 { |
408 if (desktopbpp>=15) | 456 if (desktopbpp>=15) |
409 { | 457 { |
410 desktoppal=SDLPH_PAL_EMULATE; | 458 desktoppal = SDLPH_PAL_EMULATE; |
411 } | 459 } |
412 else | 460 else |
413 { | 461 { |
414 desktoppal=SDLPH_PAL_SYSTEM; | 462 desktoppal = SDLPH_PAL_SYSTEM; |
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 } | 463 } |
433 } | 464 } |
434 else | 465 else |
435 { | 466 { |
436 desktoppal=SDLPH_PAL_NONE; | 467 desktoppal = SDLPH_PAL_NONE; |
437 } | 468 } |
438 } | 469 } |
439 } | 470 } |
440 | 471 |
441 current->w = width; | 472 current->w = width; |
442 current->h = height; | 473 current->h = height; |
443 | 474 |
444 /* These values can be overridden in ph_SetupUpdateFunction() */ | 475 if (desktoppal==SDLPH_PAL_SYSTEM) |
445 current->format->BitsPerPixel = bpp; | 476 { |
446 current->format->BytesPerPixel = (bpp+7)/8; | 477 current->flags|=SDL_HWPALETTE; |
447 current->pitch = SDL_CalculatePitch(current); | 478 } |
448 | 479 |
449 /* Must call at least once it setup image planes */ | 480 /* Must call at least once for setup image planes */ |
450 rtnval = ph_SetupUpdateFunction(this, current, current->flags); | 481 if (ph_SetupUpdateFunction(this, current, current->flags)==-1) |
451 | 482 { |
452 if (rtnval==-1) | |
453 { | |
454 fprintf(stderr,"ph_SetVideoMode(): ph_SetupUpdateFunction failed !\n"); | |
455 return NULL; | 483 return NULL; |
456 } | 484 } |
457 | 485 |
458 /* finish window drawing */ | 486 /* finish window drawing, if we are not in fullscreen, of course */ |
459 PtFlush(); | 487 if ((current->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) |
488 { | |
489 PtFlush(); | |
490 } | |
460 | 491 |
461 SDL_Unlock_EventThread(); | 492 SDL_Unlock_EventThread(); |
462 | 493 |
463 /* We're done! */ | 494 /* We're done! */ |
464 return (current); | 495 return (current); |
468 { | 499 { |
469 #ifdef HAVE_OPENGL | 500 #ifdef HAVE_OPENGL |
470 PhRegion_t region_info; | 501 PhRegion_t region_info; |
471 #endif /* HAVE_OPENGL */ | 502 #endif /* HAVE_OPENGL */ |
472 | 503 |
504 /* restore palette */ | |
505 if (desktopbpp==8) | |
506 { | |
507 PgSetPalette(syspalph, 0, -1, 0, 0, 0); | |
508 PgSetPalette(savedpal, 0, 0, _Pg_MAX_PALETTE, Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0); | |
509 PgFlush(); | |
510 } | |
511 | |
473 ph_DestroyImage(this, SDL_VideoSurface); | 512 ph_DestroyImage(this, SDL_VideoSurface); |
474 | |
475 if (currently_fullscreen) | |
476 { | |
477 ph_LeaveFullScreen(this); | |
478 } | |
479 | 513 |
480 #ifdef HAVE_OPENGL | 514 #ifdef HAVE_OPENGL |
481 /* prevent double SEGFAULT during parachute mode */ | 515 /* prevent double SEGFAULT during parachute mode */ |
482 if (this->screen) | 516 if (this->screen) |
483 { | 517 { |
506 PhDCSetCurrent(NULL); | 540 PhDCSetCurrent(NULL); |
507 PhDCRelease(oglctx); | 541 PhDCRelease(oglctx); |
508 oglctx=NULL; | 542 oglctx=NULL; |
509 } | 543 } |
510 #endif /* HAVE_OPENGL */ | 544 #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 | 545 |
520 if (event!=NULL) | 546 if (event!=NULL) |
521 { | 547 { |
522 free(event); | 548 free(event); |
523 event=NULL; | 549 event=NULL; |
541 for (i=firstcolor; i<firstcolor+ncolors; i++) | 567 for (i=firstcolor; i<firstcolor+ncolors; i++) |
542 { | 568 { |
543 syspalph[i] = PgRGB(colors[i-firstcolor].r, colors[i-firstcolor].g, colors[i-firstcolor].b); | 569 syspalph[i] = PgRGB(colors[i-firstcolor].r, colors[i-firstcolor].g, colors[i-firstcolor].b); |
544 SDL_Image->palette[i] = syspalph[i]; | 570 SDL_Image->palette[i] = syspalph[i]; |
545 } | 571 } |
572 | |
546 /* image needs to be redrawn */ | 573 /* image needs to be redrawn */ |
547 this->UpdateRects(this, 1, &updaterect); | 574 this->UpdateRects(this, 1, &updaterect); |
548 } | 575 } |
549 } | 576 } |
550 else | 577 else |
557 } | 584 } |
558 | 585 |
559 if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) | 586 if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) |
560 { | 587 { |
561 /* window mode must use soft palette */ | 588 /* window mode must use soft palette */ |
562 PgSetPalette(&syspalph[firstcolor], 1, firstcolor, ncolors, Pg_PALSET_SOFT, 0); | 589 PgSetPalette(&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0); |
563 /* image needs to be redrawn */ | 590 /* image needs to be redrawn */ |
564 this->UpdateRects(this, 1, &updaterect); | 591 this->UpdateRects(this, 1, &updaterect); |
565 } | 592 } |
566 else | 593 else |
567 { | 594 { |
568 /* fullscreen mode must use hardware palette */ | 595 /* fullscreen mode must use hardware palette */ |
569 PgSetPalette(&syspalph[firstcolor], 1, firstcolor, ncolors, Pg_PALSET_HARDLOCKED, 0); | 596 PgSetPalette(&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0); |
570 } | 597 } |
571 } | 598 } |
572 else | 599 else |
573 { | 600 { |
574 /* SDLPH_PAL_NONE do nothing */ | 601 /* SDLPH_PAL_NONE do nothing */ |
626 oglctx=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib); | 653 oglctx=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib); |
627 } | 654 } |
628 | 655 |
629 if (oglctx==NULL) | 656 if (oglctx==NULL) |
630 { | 657 { |
631 fprintf(stderr,"ph_SetupOpenGLContext(): cannot create OpenGL context.\n"); | 658 SDL_SetError("ph_SetupOpenGLContext(): cannot create OpenGL context !\n"); |
632 return (-1); | 659 return (-1); |
633 } | 660 } |
634 | 661 |
635 PhDCSetCurrent(oglctx); | 662 PhDCSetCurrent(oglctx); |
636 | 663 |
673 return(-1); | 700 return(-1); |
674 } | 701 } |
675 return 0; | 702 return 0; |
676 } | 703 } |
677 | 704 |
705 int ph_GL_LoadLibrary(_THIS, const char* path) | |
706 { | |
707 /* if code compiled with HAVE_OPENGL, the library already linked */ | |
708 this->gl_config.driver_loaded = 1; | |
709 | |
710 return 0; | |
711 } | |
712 | |
713 void* ph_GL_GetProcAddress(_THIS, const char* proc) | |
714 { | |
715 return NULL; | |
716 } | |
717 | |
678 #endif /* HAVE_OPENGL */ | 718 #endif /* HAVE_OPENGL */ |
679 | 719 |
680 static void ph_UpdateMouse(_THIS) | 720 static void ph_UpdateMouse(_THIS) |
681 { | 721 { |
682 PhCursorInfo_t phcursor; | 722 PhCursorInfo_t phcursor; |