Skip to content

Latest commit

 

History

History
745 lines (643 loc) · 21.1 KB

SDL_ph_video.c

File metadata and controls

745 lines (643 loc) · 21.1 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Mar 6, 2002
Mar 6, 2002
3
Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id$";
#endif
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include "SDL.h"
#include "SDL_error.h"
#include "SDL_timer.h"
#include "SDL_thread.h"
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "SDL_endian.h"
#include "SDL_sysvideo.h"
#include "SDL_pixels_c.h"
#include "SDL_events_c.h"
#include "SDL_ph_video.h"
#include "SDL_ph_modes_c.h"
#include "SDL_ph_image_c.h"
#include "SDL_ph_events_c.h"
#include "SDL_ph_mouse_c.h"
May 10, 2001
May 10, 2001
49
#include "SDL_ph_wm_c.h"
Apr 26, 2001
Apr 26, 2001
50
51
52
53
54
55
56
57
58
#include "SDL_phyuv_c.h"
#include "blank_cursor.h"
static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat);
static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
int width, int height, int bpp, Uint32 flags);
static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
static void ph_VideoQuit(_THIS);
static void ph_DeleteDevice(SDL_VideoDevice *device);
Jan 20, 2003
Jan 20, 2003
59
static void ph_UpdateMouse(_THIS);
Mar 2, 2002
Mar 2, 2002
60
61
#ifdef HAVE_OPENGL
Aug 4, 2003
Aug 4, 2003
62
static int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags);
Jan 18, 2002
Jan 18, 2002
63
static void ph_GL_SwapBuffers(_THIS);
Mar 2, 2002
Mar 2, 2002
64
static int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value);
Aug 4, 2003
Aug 4, 2003
65
66
67
static int ph_GL_LoadLibrary(_THIS, const char* path);
static void* ph_GL_GetProcAddress(_THIS, const char* proc);
Mar 2, 2002
Mar 2, 2002
68
#endif /* HAVE_OPENGL */
Jan 18, 2002
Jan 18, 2002
69
Apr 26, 2001
Apr 26, 2001
70
71
static int ph_Available(void)
{
Mar 11, 2002
Mar 11, 2002
72
73
74
75
76
77
78
79
80
81
82
int phstat=-1;
phstat=PtInit(0);
if (phstat==0)
{
return 1;
}
else
{
return 0;
}
Apr 26, 2001
Apr 26, 2001
83
84
85
86
87
88
89
90
}
static SDL_VideoDevice *ph_CreateDevice(int devindex)
{
SDL_VideoDevice *device;
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
Mar 11, 2002
Mar 11, 2002
91
if (device) {
Apr 26, 2001
Apr 26, 2001
92
93
94
95
96
memset(device, 0, (sizeof *device));
device->hidden = (struct SDL_PrivateVideoData *)
malloc((sizeof *device->hidden));
device->gl_data = NULL;
}
Jan 20, 2003
Jan 20, 2003
97
if ((device == NULL) || (device->hidden == NULL)) {
Apr 26, 2001
Apr 26, 2001
98
99
100
101
102
103
104
SDL_OutOfMemory();
ph_DeleteDevice(device);
return(0);
}
memset(device->hidden, 0, (sizeof *device->hidden));
/* Set the driver flags */
Feb 14, 2002
Feb 14, 2002
105
device->handles_any_size = 1; /* JB not true for fullscreen */
Apr 26, 2001
Apr 26, 2001
106
107
/* Set the function pointers */
Jan 18, 2002
Jan 18, 2002
108
device->CreateYUVOverlay = ph_CreateYUVOverlay;
Apr 26, 2001
Apr 26, 2001
109
110
111
device->VideoInit = ph_VideoInit;
device->ListModes = ph_ListModes;
device->SetVideoMode = ph_SetVideoMode;
Mar 11, 2002
Mar 11, 2002
112
device->ToggleFullScreen = ph_ToggleFullScreen;
Jan 20, 2003
Jan 20, 2003
113
device->UpdateMouse = ph_UpdateMouse;
Apr 26, 2001
Apr 26, 2001
114
device->SetColors = ph_SetColors;
Aug 4, 2003
Aug 4, 2003
115
device->UpdateRects = NULL; /* set up in ph_SetupUpdateFunction */
Apr 26, 2001
Apr 26, 2001
116
117
118
119
120
121
122
123
124
125
device->VideoQuit = ph_VideoQuit;
device->AllocHWSurface = ph_AllocHWSurface;
device->CheckHWBlit = NULL;
device->FillHWRect = NULL;
device->SetHWColorKey = NULL;
device->SetHWAlpha = NULL;
device->LockHWSurface = ph_LockHWSurface;
device->UnlockHWSurface = ph_UnlockHWSurface;
device->FlipHWSurface = ph_FlipHWSurface;
device->FreeHWSurface = ph_FreeHWSurface;
May 10, 2001
May 10, 2001
126
device->SetCaption = ph_SetCaption;
Apr 26, 2001
Apr 26, 2001
127
device->SetIcon = NULL;
May 10, 2001
May 10, 2001
128
device->IconifyWindow = ph_IconifyWindow;
Feb 20, 2002
Feb 20, 2002
129
device->GrabInput = ph_GrabInput;
Mar 2, 2002
Mar 2, 2002
130
device->GetWMInfo = ph_GetWMInfo;
Apr 26, 2001
Apr 26, 2001
131
132
133
134
135
136
137
138
device->FreeWMCursor = ph_FreeWMCursor;
device->CreateWMCursor = ph_CreateWMCursor;
device->ShowWMCursor = ph_ShowWMCursor;
device->WarpWMCursor = ph_WarpWMCursor;
device->CheckMouseMode = ph_CheckMouseMode;
device->InitOSKeymap = ph_InitOSKeymap;
device->PumpEvents = ph_PumpEvents;
Feb 14, 2002
Feb 14, 2002
139
/* OpenGL support. */
Jan 18, 2002
Jan 18, 2002
140
device->GL_MakeCurrent = NULL;
Feb 14, 2002
Feb 14, 2002
141
#ifdef HAVE_OPENGL
Jan 18, 2002
Jan 18, 2002
142
device->GL_SwapBuffers = ph_GL_SwapBuffers;
Mar 2, 2002
Mar 2, 2002
143
device->GL_GetAttribute = ph_GL_GetAttribute;
Aug 4, 2003
Aug 4, 2003
144
145
device->GL_LoadLibrary = ph_GL_LoadLibrary;
device->GL_GetProcAddress = ph_GL_GetProcAddress;
Feb 14, 2002
Feb 14, 2002
146
147
#else
device->GL_SwapBuffers = NULL;
Mar 2, 2002
Mar 2, 2002
148
device->GL_GetAttribute = NULL;
Aug 4, 2003
Aug 4, 2003
149
150
device->GL_LoadLibrary = NULL;
device->GL_GetProcAddress = NULL;
Feb 14, 2002
Feb 14, 2002
151
#endif /* HAVE_OPENGL */
Jan 18, 2002
Jan 18, 2002
152
Apr 26, 2001
Apr 26, 2001
153
device->free = ph_DeleteDevice;
Aug 4, 2003
Aug 4, 2003
154
Apr 26, 2001
Apr 26, 2001
155
156
157
return device;
}
May 10, 2001
May 10, 2001
158
VideoBootStrap ph_bootstrap = {
Mar 23, 2002
Mar 23, 2002
159
160
"photon", "QNX Photon video output",
ph_Available, ph_CreateDevice
Apr 26, 2001
Apr 26, 2001
161
162
163
164
};
static void ph_DeleteDevice(SDL_VideoDevice *device)
{
Mar 11, 2002
Mar 11, 2002
165
166
167
168
if (device)
{
if (device->hidden)
{
Apr 26, 2001
Apr 26, 2001
169
170
171
free(device->hidden);
device->hidden = NULL;
}
Mar 11, 2002
Mar 11, 2002
172
173
if (device->gl_data)
{
Apr 26, 2001
Apr 26, 2001
174
175
176
177
178
179
180
181
free(device->gl_data);
device->gl_data = NULL;
}
free(device);
device = NULL;
}
}
Jan 20, 2003
Jan 20, 2003
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
static PtWidget_t *ph_CreateWindow(_THIS)
{
PtWidget_t *widget;
widget = PtCreateWidget(PtWindow, NULL, 0, 0);
return widget;
}
static int ph_SetupWindow(_THIS, int w, int h, int flags)
{
PtArg_t args[32];
PhPoint_t pos = {0, 0};
PhDim_t dim = {w, h};
int nargs = 0;
PtSetArg(&args[nargs++], Pt_ARG_DIM, &dim, 0);
PtSetArg(&args[nargs++], Pt_ARG_FILL_COLOR, Pg_BLACK, 0);
if ((flags & SDL_RESIZABLE) == SDL_RESIZABLE)
{
Aug 4, 2003
Aug 4, 2003
203
204
205
206
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_CLOSE);
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_MAX | Ph_WM_RESTORE);
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);
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);
Jan 20, 2003
Jan 20, 2003
207
208
209
}
else
{
Aug 4, 2003
Aug 4, 2003
210
211
212
213
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX | Ph_WM_RESTORE | Ph_WM_CLOSE);
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX | Ph_WM_RESTORE);
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_MOVE | Ph_WM_CLOSE);
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);
Jan 20, 2003
Jan 20, 2003
214
215
216
217
}
if (((flags & SDL_NOFRAME)==SDL_NOFRAME) || ((flags & SDL_FULLSCREEN)==SDL_FULLSCREEN))
{
Aug 4, 2003
Aug 4, 2003
218
219
220
221
222
223
224
225
226
if ((flags & SDL_RESIZABLE) != SDL_RESIZABLE)
{
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Pt_TRUE);
}
else
{
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Pt_TRUE);
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_BORDER);
}
Jan 20, 2003
Jan 20, 2003
227
228
229
230
}
else
{
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_BORDER | Ph_WM_RENDER_TITLE |
Aug 4, 2003
Aug 4, 2003
231
Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MIN);
Jan 20, 2003
Jan 20, 2003
232
233
}
Aug 4, 2003
Aug 4, 2003
234
if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
Jan 20, 2003
Jan 20, 2003
235
236
237
238
239
240
241
242
243
244
{
PtSetArg(&args[nargs++], Pt_ARG_POS, &pos, 0);
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_FFRONT | Ph_WM_MAX);
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISMAX |
Ph_WM_STATE_ISFOCUS | Ph_WM_STATE_ISALTKEY);
}
else
{
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISMAX | Ph_WM_STATE_ISALTKEY);
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_HIDE);
Aug 4, 2003
Aug 4, 2003
245
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_HIDE);
Jan 20, 2003
Jan 20, 2003
246
247
248
249
250
251
252
253
254
PtSetArg(&args[nargs++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, Pt_RESIZE_XY_AS_REQUIRED);
}
PtSetResources(window, nargs, args);
PtRealizeWidget(window);
return 0;
}
Aug 4, 2003
Aug 4, 2003
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
static const struct ColourMasks* ph_GetColourMasks(int bpp)
{
/* The alpha mask doesn't appears to be needed */
static const struct ColourMasks phColorMasks[5] = {
/* 8 bit */ {0, 0, 0, 0, 8},
/* 15 bit ARGB */ {0x7C00, 0x03E0, 0x001F, 0x8000, 15},
/* 16 bit RGB */ {0xF800, 0x07E0, 0x001F, 0x0000, 16},
/* 24 bit RGB */ {0xFF0000, 0x00FF00, 0x0000FF, 0x000000, 24},
/* 32 bit ARGB */ {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000, 32},
};
switch (bpp)
{
case 8:
return &phColorMasks[0];
case 15:
return &phColorMasks[1];
case 16:
return &phColorMasks[2];
case 24:
return &phColorMasks[3];
case 32:
return &phColorMasks[4];
}
return NULL;
}
Apr 26, 2001
Apr 26, 2001
282
283
static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
Mar 11, 2002
Mar 11, 2002
284
285
PgVideoModeInfo_t my_mode_info;
PgHWCaps_t my_hwcaps;
Aug 4, 2003
Aug 4, 2003
286
int i;
Apr 26, 2001
Apr 26, 2001
287
Mar 11, 2002
Mar 11, 2002
288
window=NULL;
Mar 23, 2002
Mar 23, 2002
289
desktoppal=SDLPH_PAL_NONE;
Mar 28, 2002
Mar 28, 2002
290
291
292
#ifdef HAVE_OPENGL
oglctx=NULL;
#endif /* HAVE_OPENGL */
Mar 23, 2002
Mar 23, 2002
293
294
295
old_video_mode=-1;
old_refresh_rate=-1;
Apr 26, 2001
Apr 26, 2001
296
Mar 11, 2002
Mar 11, 2002
297
298
if (NULL == (event = malloc(EVENT_SIZE)))
{
Jan 20, 2003
Jan 20, 2003
299
300
SDL_OutOfMemory();
return -1;
Mar 11, 2002
Mar 11, 2002
301
}
May 28, 2002
May 28, 2002
302
memset(event, 0x00, EVENT_SIZE);
Mar 11, 2002
Mar 11, 2002
303
Jan 20, 2003
Jan 20, 2003
304
305
306
window = ph_CreateWindow(this);
if (window == NULL)
{
Aug 4, 2003
Aug 4, 2003
307
SDL_SetError("ph_VideoInit(): Couldn't create video window !\n");
Jan 20, 2003
Jan 20, 2003
308
309
310
return -1;
}
Mar 11, 2002
Mar 11, 2002
311
312
313
314
315
316
317
/* Create the blank cursor */
SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask,
(int)BLANK_CWIDTH, (int)BLANK_CHEIGHT,
(int)BLANK_CHOTX, (int)BLANK_CHOTY);
if (SDL_BlankCursor == NULL)
{
Aug 4, 2003
Aug 4, 2003
318
return -1;
Mar 11, 2002
Mar 11, 2002
319
320
321
322
}
if (PgGetGraphicsHWCaps(&my_hwcaps) < 0)
{
Aug 4, 2003
Aug 4, 2003
323
324
325
SDL_SetError("ph_VideoInit(): GetGraphicsHWCaps function failed !\n");
this->FreeWMCursor(this, SDL_BlankCursor);
return -1;
Mar 11, 2002
Mar 11, 2002
326
327
328
329
}
if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &my_mode_info) < 0)
{
Aug 4, 2003
Aug 4, 2003
330
331
332
SDL_SetError("ph_VideoInit(): PgGetVideoModeInfo function failed !\n");
this->FreeWMCursor(this, SDL_BlankCursor);
return -1;
Mar 11, 2002
Mar 11, 2002
333
334
335
336
337
}
/* We need to return BytesPerPixel as it in used by CreateRGBsurface */
vformat->BitsPerPixel = my_mode_info.bits_per_pixel;
vformat->BytesPerPixel = my_mode_info.bytes_per_scanline/my_mode_info.width;
Mar 23, 2002
Mar 23, 2002
338
desktopbpp = my_mode_info.bits_per_pixel;
Mar 28, 2002
Mar 28, 2002
339
340
341
/* save current palette */
if (desktopbpp==8)
Mar 11, 2002
Mar 11, 2002
342
{
Jan 20, 2003
Jan 20, 2003
343
344
PgGetPalette(savedpal);
PgGetPalette(syspalph);
Mar 11, 2002
Mar 11, 2002
345
}
Aug 4, 2003
Aug 4, 2003
346
347
348
349
350
351
352
353
else
{
for(i=0; i<_Pg_MAX_PALETTE; i++)
{
savedpal[i]=PgRGB(0, 0, 0);
syspalph[i]=PgRGB(0, 0, 0);
}
}
Mar 28, 2002
Mar 28, 2002
354
May 10, 2001
May 10, 2001
355
currently_fullscreen = 0;
Aug 4, 2003
Aug 4, 2003
356
357
358
359
360
361
362
363
364
365
366
currently_hided = 0;
current_overlay = NULL;
OCImage.direct_context = NULL;
OCImage.offscreen_context = NULL;
OCImage.offscreen_backcontext = NULL;
OCImage.oldDC = NULL;
OCImage.CurrentFrameData = NULL;
OCImage.FrameData0 = NULL;
OCImage.FrameData1 = NULL;
May 10, 2001
May 10, 2001
367
368
369
this->info.wm_available = 1;
Apr 26, 2001
Apr 26, 2001
370
371
372
373
374
375
return 0;
}
static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
int width, int height, int bpp, Uint32 flags)
{
Aug 4, 2003
Aug 4, 2003
376
const struct ColourMasks* mask;
Apr 26, 2001
Apr 26, 2001
377
378
379
380
/* Lock the event thread, in multi-threading environments */
SDL_Lock_EventThread();
Mar 28, 2002
Mar 28, 2002
381
382
current->flags = flags;
Aug 4, 2003
Aug 4, 2003
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
/* if we do not have desired fullscreen mode, then fallback into window mode */
if (((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) && (ph_GetVideoMode(width, height, bpp)==0))
{
current->flags &= ~SDL_FULLSCREEN;
current->flags &= ~SDL_NOFRAME;
current->flags &= ~SDL_RESIZABLE;
}
ph_SetupWindow(this, width, height, current->flags);
mask = ph_GetColourMasks(bpp);
if (mask != NULL)
{
SDL_ReallocFormat(current, mask->bpp, mask->red, mask->green, mask->blue, 0);
}
else
{
SDL_SetError("ph_SetVideoMode(): desired bpp is not supported by photon !\n");
return NULL;
}
Apr 26, 2001
Apr 26, 2001
403
Mar 11, 2002
Mar 11, 2002
404
#ifdef HAVE_OPENGL
Jan 20, 2003
Jan 20, 2003
405
if (current->flags & SDL_OPENGL)
Apr 26, 2001
Apr 26, 2001
406
{
Mar 11, 2002
Mar 11, 2002
407
408
409
/* ph_SetupOpenGLContext creates also window as need */
if (ph_SetupOpenGLContext(this, width, height, bpp, flags)==0)
{
Jan 20, 2003
Jan 20, 2003
410
ph_SetupUpdateFunction(this, current, flags);
Mar 11, 2002
Mar 11, 2002
411
412
413
414
}
else
{
/* if context creation fail, report no OpenGL to high level */
Jan 20, 2003
Jan 20, 2003
415
current->flags &= ~SDL_OPENGL;
Aug 4, 2003
Aug 4, 2003
416
return NULL;
Mar 11, 2002
Mar 11, 2002
417
}
Mar 2, 2002
Mar 2, 2002
418
#else
Jan 20, 2003
Jan 20, 2003
419
if (current->flags & SDL_OPENGL) /* if no built-in OpenGL support */
Mar 11, 2002
Mar 11, 2002
420
{
Aug 4, 2003
Aug 4, 2003
421
SDL_SetError("ph_SetVideoMode(): no OpenGL support, try to recompile library.\n");
Jan 20, 2003
Jan 20, 2003
422
current->flags &= ~SDL_OPENGL;
Mar 11, 2002
Mar 11, 2002
423
return NULL;
Feb 14, 2002
Feb 14, 2002
424
#endif /* HAVE_OPENGL */
Apr 26, 2001
Apr 26, 2001
425
}
Mar 11, 2002
Mar 11, 2002
426
427
else
{
Aug 4, 2003
Aug 4, 2003
428
429
/* Initialize internal variables */
if ((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
Mar 11, 2002
Mar 11, 2002
430
{
Mar 23, 2002
Mar 23, 2002
431
432
433
434
if (bpp==8)
{
desktoppal=SDLPH_PAL_SYSTEM;
}
Apr 26, 2001
Apr 26, 2001
435
Jan 20, 2003
Jan 20, 2003
436
current->flags &= ~SDL_RESIZABLE; /* no resize for Direct Context */
Aug 4, 2003
Aug 4, 2003
437
}
Mar 11, 2002
Mar 11, 2002
438
439
else
{
Aug 4, 2003
Aug 4, 2003
440
441
442
443
444
/* remove this if we'll support non-fullscreen sw/hw+doublebuf */
current->flags &= ~SDL_DOUBLEBUF;
/* Use offscreen memory if SDL_HWSURFACE flag is set */
if ((current->flags & SDL_HWSURFACE) == SDL_HWSURFACE)
Mar 11, 2002
Mar 11, 2002
445
{
Aug 4, 2003
Aug 4, 2003
446
447
448
449
450
if (desktopbpp!=bpp)
{
current->flags &= ~SDL_HWSURFACE;
}
Mar 11, 2002
Mar 11, 2002
451
}
Mar 28, 2002
Mar 28, 2002
452
Mar 23, 2002
Mar 23, 2002
453
454
455
456
457
/* using palette emulation code in window mode */
if (bpp==8)
{
if (desktopbpp>=15)
{
Aug 4, 2003
Aug 4, 2003
458
desktoppal = SDLPH_PAL_EMULATE;
Mar 23, 2002
Mar 23, 2002
459
460
461
}
else
{
Aug 4, 2003
Aug 4, 2003
462
desktoppal = SDLPH_PAL_SYSTEM;
Jan 20, 2003
Jan 20, 2003
463
464
465
}
}
else
Mar 11, 2002
Mar 11, 2002
466
{
Aug 4, 2003
Aug 4, 2003
467
desktoppal = SDLPH_PAL_NONE;
Mar 11, 2002
Mar 11, 2002
468
}
Jan 18, 2002
Jan 18, 2002
469
}
Mar 11, 2002
Mar 11, 2002
470
471
472
473
}
current->w = width;
current->h = height;
Jan 20, 2003
Jan 20, 2003
474
Aug 4, 2003
Aug 4, 2003
475
476
477
478
if (desktoppal==SDLPH_PAL_SYSTEM)
{
current->flags|=SDL_HWPALETTE;
}
May 19, 2002
May 19, 2002
479
Aug 4, 2003
Aug 4, 2003
480
481
/* Must call at least once for setup image planes */
if (ph_SetupUpdateFunction(this, current, current->flags)==-1)
May 19, 2002
May 19, 2002
482
483
484
{
return NULL;
}
Mar 11, 2002
Mar 11, 2002
485
Aug 4, 2003
Aug 4, 2003
486
487
488
489
490
/* finish window drawing, if we are not in fullscreen, of course */
if ((current->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN)
{
PtFlush();
}
Mar 28, 2002
Mar 28, 2002
491
Apr 26, 2001
Apr 26, 2001
492
493
494
SDL_Unlock_EventThread();
/* We're done! */
Mar 23, 2002
Mar 23, 2002
495
return (current);
Apr 26, 2001
Apr 26, 2001
496
497
498
499
}
static void ph_VideoQuit(_THIS)
{
Mar 28, 2002
Mar 28, 2002
500
#ifdef HAVE_OPENGL
Mar 11, 2002
Mar 11, 2002
501
PhRegion_t region_info;
Mar 28, 2002
Mar 28, 2002
502
#endif /* HAVE_OPENGL */
Mar 11, 2002
Mar 11, 2002
503
Aug 4, 2003
Aug 4, 2003
504
505
/* restore palette */
if (desktopbpp==8)
Feb 14, 2002
Feb 14, 2002
506
{
Aug 4, 2003
Aug 4, 2003
507
508
509
PgSetPalette(syspalph, 0, -1, 0, 0, 0);
PgSetPalette(savedpal, 0, 0, _Pg_MAX_PALETTE, Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0);
PgFlush();
Feb 14, 2002
Feb 14, 2002
510
}
Apr 26, 2001
Apr 26, 2001
511
Aug 4, 2003
Aug 4, 2003
512
513
ph_DestroyImage(this, SDL_VideoSurface);
Mar 11, 2002
Mar 11, 2002
514
#ifdef HAVE_OPENGL
Mar 28, 2002
Mar 28, 2002
515
/* prevent double SEGFAULT during parachute mode */
Mar 23, 2002
Mar 23, 2002
516
if (this->screen)
Mar 11, 2002
Mar 11, 2002
517
{
Mar 23, 2002
Mar 23, 2002
518
519
520
521
522
523
524
if (((this->screen->flags & SDL_FULLSCREEN)==SDL_FULLSCREEN) &&
((this->screen->flags & SDL_OPENGL)==SDL_OPENGL))
{
region_info.cursor_type=Ph_CURSOR_POINTER;
region_info.rid=PtWidgetRid(window);
PhRegionChange(Ph_REGION_CURSOR, 0, &region_info, NULL, NULL);
}
Mar 11, 2002
Mar 11, 2002
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
}
PtFlush();
#endif /* HAVE_OPENGL */
if (window)
{
PtUnrealizeWidget(window);
PtDestroyWidget(window);
window=NULL;
}
#ifdef HAVE_OPENGL
if (oglctx)
{
PhDCSetCurrent(NULL);
PhDCRelease(oglctx);
oglctx=NULL;
}
#endif /* HAVE_OPENGL */
Jan 20, 2003
Jan 20, 2003
545
546
547
548
549
550
if (event!=NULL)
{
free(event);
event=NULL;
}
Mar 11, 2002
Mar 11, 2002
551
}
Apr 26, 2001
Apr 26, 2001
552
553
554
static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
{
Mar 23, 2002
Mar 23, 2002
555
int i;
Jan 20, 2003
Jan 20, 2003
556
557
558
559
560
SDL_Rect updaterect;
updaterect.x = updaterect.y = 0;
updaterect.w = this->screen->w;
updaterect.h = this->screen->h;
Apr 26, 2001
Apr 26, 2001
561
Mar 23, 2002
Mar 23, 2002
562
563
564
565
566
567
568
/* palette emulation code, using palette of the PhImage_t struct */
if (desktoppal==SDLPH_PAL_EMULATE)
{
if ((SDL_Image) && (SDL_Image->palette))
{
for (i=firstcolor; i<firstcolor+ncolors; i++)
{
Jan 20, 2003
Jan 20, 2003
569
570
syspalph[i] = PgRGB(colors[i-firstcolor].r, colors[i-firstcolor].g, colors[i-firstcolor].b);
SDL_Image->palette[i] = syspalph[i];
Mar 23, 2002
Mar 23, 2002
571
}
Aug 4, 2003
Aug 4, 2003
572
Jan 20, 2003
Jan 20, 2003
573
574
/* image needs to be redrawn */
this->UpdateRects(this, 1, &updaterect);
Mar 23, 2002
Mar 23, 2002
575
}
Apr 26, 2001
Apr 26, 2001
576
}
Mar 23, 2002
Mar 23, 2002
577
578
579
else
{
if (desktoppal==SDLPH_PAL_SYSTEM)
Apr 26, 2001
Apr 26, 2001
580
{
Mar 23, 2002
Mar 23, 2002
581
582
for (i=firstcolor; i<firstcolor+ncolors; i++)
{
Jan 20, 2003
Jan 20, 2003
583
syspalph[i] = PgRGB(colors[i-firstcolor].r, colors[i-firstcolor].g, colors[i-firstcolor].b);
Mar 23, 2002
Mar 23, 2002
584
585
586
587
}
if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN)
{
Jan 20, 2003
Jan 20, 2003
588
/* window mode must use soft palette */
Aug 4, 2003
Aug 4, 2003
589
PgSetPalette(&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0);
Jan 20, 2003
Jan 20, 2003
590
591
/* image needs to be redrawn */
this->UpdateRects(this, 1, &updaterect);
Mar 23, 2002
Mar 23, 2002
592
593
594
595
}
else
{
/* fullscreen mode must use hardware palette */
Aug 4, 2003
Aug 4, 2003
596
PgSetPalette(&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0);
Mar 23, 2002
Mar 23, 2002
597
}
Apr 26, 2001
Apr 26, 2001
598
}
Mar 23, 2002
Mar 23, 2002
599
else
Apr 26, 2001
Apr 26, 2001
600
{
Mar 23, 2002
Mar 23, 2002
601
/* SDLPH_PAL_NONE do nothing */
Apr 26, 2001
Apr 26, 2001
602
}
Mar 23, 2002
Mar 23, 2002
603
604
605
}
return 1;
Apr 26, 2001
Apr 26, 2001
606
607
}
Feb 14, 2002
Feb 14, 2002
608
#ifdef HAVE_OPENGL
Mar 11, 2002
Mar 11, 2002
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags)
{
PhDim_t dim;
uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS];
int OGLargc;
dim.w=width;
dim.h=height;
if (oglctx!=NULL)
{
PhDCSetCurrent(NULL);
PhDCRelease(oglctx);
oglctx=NULL;
}
OGLargc=0;
if (this->gl_config.depth_size)
{
OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DEPTH_BITS;
OGLAttrib[OGLargc++]=this->gl_config.depth_size;
}
if (this->gl_config.stencil_size)
{
OGLAttrib[OGLargc++]=PHOGL_ATTRIB_STENCIL_BITS;
OGLAttrib[OGLargc++]=this->gl_config.stencil_size;
}
OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FORCE_SW;
if (flags & SDL_FULLSCREEN)
{
OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN;
OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DIRECT;
OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_BEST;
OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_CENTER;
}
OGLAttrib[OGLargc++]=PHOGL_ATTRIB_NONE;
if (this->gl_config.double_buffer)
{
oglctx=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib);
}
else
{
oglctx=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib);
}
Mar 28, 2002
Mar 28, 2002
655
Mar 11, 2002
Mar 11, 2002
656
657
if (oglctx==NULL)
{
Aug 4, 2003
Aug 4, 2003
658
SDL_SetError("ph_SetupOpenGLContext(): cannot create OpenGL context !\n");
Mar 11, 2002
Mar 11, 2002
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
return (-1);
}
PhDCSetCurrent(oglctx);
/* disable mouse for fullscreen */
if (flags & SDL_FULLSCREEN)
{
PhRegion_t region_info;
region_info.cursor_type=Ph_CURSOR_NONE;
region_info.rid=PtWidgetRid(window);
PhRegionChange(Ph_REGION_CURSOR, 0, &region_info, NULL, NULL);
}
PtFlush();
return 0;
}
Jan 18, 2002
Jan 18, 2002
679
680
void ph_GL_SwapBuffers(_THIS)
{
Mar 2, 2002
Mar 2, 2002
681
PgSetRegion(PtWidgetRid(window));
Mar 11, 2002
Mar 11, 2002
682
PdOpenGLContextSwapBuffers(oglctx);
Jan 18, 2002
Jan 18, 2002
683
684
}
Mar 2, 2002
Mar 2, 2002
685
int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
Apr 26, 2001
Apr 26, 2001
686
{
Mar 2, 2002
Mar 2, 2002
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
switch (attrib)
{
case SDL_GL_DOUBLEBUFFER:
*value=this->gl_config.double_buffer;
break;
case SDL_GL_STENCIL_SIZE:
*value=this->gl_config.stencil_size;
break;
case SDL_GL_DEPTH_SIZE:
*value=this->gl_config.depth_size;
break;
default:
*value=0;
return(-1);
}
return 0;
Apr 26, 2001
Apr 26, 2001
703
}
Mar 2, 2002
Mar 2, 2002
704
Aug 4, 2003
Aug 4, 2003
705
706
707
708
709
710
711
712
713
714
715
716
717
int ph_GL_LoadLibrary(_THIS, const char* path)
{
/* if code compiled with HAVE_OPENGL, the library already linked */
this->gl_config.driver_loaded = 1;
return 0;
}
void* ph_GL_GetProcAddress(_THIS, const char* proc)
{
return NULL;
}
Mar 2, 2002
Mar 2, 2002
718
#endif /* HAVE_OPENGL */
Jan 20, 2003
Jan 20, 2003
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
static void ph_UpdateMouse(_THIS)
{
PhCursorInfo_t phcursor;
short abs_x;
short abs_y;
/* Lock the event thread, in multi-threading environments */
SDL_Lock_EventThread();
/* synchronizing photon mouse cursor position and SDL mouse position, if cursor appears over window. */
PtGetAbsPosition(window, &abs_x, &abs_y);
PhQueryCursor(PhInputGroup(NULL), &phcursor);
if (((phcursor.pos.x >= abs_x) && (phcursor.pos.x <= abs_x + this->screen->w)) &&
((phcursor.pos.y >= abs_y) && (phcursor.pos.y <= abs_y + this->screen->h)))
{
SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
SDL_PrivateMouseMotion(0, 0, phcursor.pos.x-abs_x, phcursor.pos.y-abs_y);
}
else
{
SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
}
/* Unlock the event thread, in multi-threading environments */
SDL_Unlock_EventThread();
}