Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
632 lines (547 loc) · 20.3 KB

SDL_ph_video.c

File metadata and controls

632 lines (547 loc) · 20.3 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Feb 1, 2006
Feb 1, 2006
3
Copyright (C) 1997-2006 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
Apr 26, 2001
Apr 26, 2001
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
Apr 26, 2001
Apr 26, 2001
9
10
11
12
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
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Apr 26, 2001
Apr 26, 2001
14
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Apr 26, 2001
Apr 26, 2001
18
19
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
23
24
25
26
#include <unistd.h>
#include <sys/ioctl.h>
Feb 10, 2006
Feb 10, 2006
27
#include "SDL_endian.h"
Apr 26, 2001
Apr 26, 2001
28
29
30
31
#include "SDL_timer.h"
#include "SDL_thread.h"
#include "SDL_video.h"
#include "SDL_mouse.h"
Feb 16, 2006
Feb 16, 2006
32
33
34
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
Apr 26, 2001
Apr 26, 2001
35
36
37
38
39
#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
40
#include "SDL_ph_wm_c.h"
Jul 18, 2004
Jul 18, 2004
41
#include "SDL_ph_gl.h"
Apr 26, 2001
Apr 26, 2001
42
#include "SDL_phyuv_c.h"
Feb 16, 2006
Feb 16, 2006
43
#include "../blank_cursor.h"
Apr 26, 2001
Apr 26, 2001
44
May 28, 2006
May 28, 2006
45
46
47
48
49
50
51
52
53
54
55
56
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);
static int phstatus = -1;
static int
ph_Available (void)
Apr 26, 2001
Apr 26, 2001
57
{
May 28, 2006
May 28, 2006
58
59
60
61
62
63
if (phstatus != 0) {
phstatus = PtInit (NULL);
if (phstatus == 0) {
return 1;
} else {
return 0;
Sep 21, 2003
Sep 21, 2003
64
}
Mar 11, 2002
Mar 11, 2002
65
}
Sep 21, 2003
Sep 21, 2003
66
return 1;
Apr 26, 2001
Apr 26, 2001
67
68
}
May 28, 2006
May 28, 2006
69
70
static SDL_VideoDevice *
ph_CreateDevice (int devindex)
Apr 26, 2001
Apr 26, 2001
71
{
May 28, 2006
May 28, 2006
72
SDL_VideoDevice *device;
Apr 26, 2001
Apr 26, 2001
73
74
/* Initialize all variables that we clean on shutdown */
May 28, 2006
May 28, 2006
75
76
77
78
79
device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice));
if (device) {
SDL_memset (device, 0, (sizeof *device));
device->hidden = (struct SDL_PrivateVideoData *)
SDL_malloc ((sizeof *device->hidden));
Apr 26, 2001
Apr 26, 2001
80
81
device->gl_data = NULL;
}
May 28, 2006
May 28, 2006
82
83
84
if ((device == NULL) || (device->hidden == NULL)) {
SDL_OutOfMemory ();
ph_DeleteDevice (device);
May 6, 2004
May 6, 2004
85
return NULL;
Apr 26, 2001
Apr 26, 2001
86
}
May 28, 2006
May 28, 2006
87
SDL_memset (device->hidden, 0, (sizeof *device->hidden));
Apr 26, 2001
Apr 26, 2001
88
89
/* Set the driver flags */
May 6, 2004
May 6, 2004
90
device->handles_any_size = 1;
Apr 26, 2001
Apr 26, 2001
91
92
/* Set the function pointers */
Jan 18, 2002
Jan 18, 2002
93
device->CreateYUVOverlay = ph_CreateYUVOverlay;
Apr 26, 2001
Apr 26, 2001
94
95
96
device->VideoInit = ph_VideoInit;
device->ListModes = ph_ListModes;
device->SetVideoMode = ph_SetVideoMode;
Mar 11, 2002
Mar 11, 2002
97
device->ToggleFullScreen = ph_ToggleFullScreen;
Jan 20, 2003
Jan 20, 2003
98
device->UpdateMouse = ph_UpdateMouse;
Apr 26, 2001
Apr 26, 2001
99
device->SetColors = ph_SetColors;
May 28, 2006
May 28, 2006
100
device->UpdateRects = NULL; /* set up in ph_SetupUpdateFunction */
Apr 26, 2001
Apr 26, 2001
101
102
device->VideoQuit = ph_VideoQuit;
device->AllocHWSurface = ph_AllocHWSurface;
Feb 14, 2004
Feb 14, 2004
103
104
105
106
device->CheckHWBlit = ph_CheckHWBlit;
device->FillHWRect = ph_FillHWRect;
device->SetHWColorKey = ph_SetHWColorKey;
device->SetHWAlpha = ph_SetHWAlpha;
Apr 26, 2001
Apr 26, 2001
107
108
109
110
device->LockHWSurface = ph_LockHWSurface;
device->UnlockHWSurface = ph_UnlockHWSurface;
device->FlipHWSurface = ph_FlipHWSurface;
device->FreeHWSurface = ph_FreeHWSurface;
May 10, 2001
May 10, 2001
111
device->SetCaption = ph_SetCaption;
Apr 26, 2001
Apr 26, 2001
112
device->SetIcon = NULL;
May 10, 2001
May 10, 2001
113
device->IconifyWindow = ph_IconifyWindow;
Feb 20, 2002
Feb 20, 2002
114
device->GrabInput = ph_GrabInput;
Mar 2, 2002
Mar 2, 2002
115
device->GetWMInfo = ph_GetWMInfo;
Apr 26, 2001
Apr 26, 2001
116
117
118
119
device->FreeWMCursor = ph_FreeWMCursor;
device->CreateWMCursor = ph_CreateWMCursor;
device->ShowWMCursor = ph_ShowWMCursor;
device->WarpWMCursor = ph_WarpWMCursor;
Aug 30, 2003
Aug 30, 2003
120
device->MoveWMCursor = NULL;
Apr 26, 2001
Apr 26, 2001
121
122
123
124
device->CheckMouseMode = ph_CheckMouseMode;
device->InitOSKeymap = ph_InitOSKeymap;
device->PumpEvents = ph_PumpEvents;
Feb 14, 2002
Feb 14, 2002
125
/* OpenGL support. */
Feb 16, 2006
Feb 16, 2006
126
#if SDL_VIDEO_OPENGL
Aug 30, 2003
Aug 30, 2003
127
device->GL_MakeCurrent = ph_GL_MakeCurrent;
Jan 18, 2002
Jan 18, 2002
128
device->GL_SwapBuffers = ph_GL_SwapBuffers;
Mar 2, 2002
Mar 2, 2002
129
device->GL_GetAttribute = ph_GL_GetAttribute;
Aug 4, 2003
Aug 4, 2003
130
131
device->GL_LoadLibrary = ph_GL_LoadLibrary;
device->GL_GetProcAddress = ph_GL_GetProcAddress;
Feb 16, 2006
Feb 16, 2006
132
#endif /* SDL_VIDEO_OPENGL */
Jan 18, 2002
Jan 18, 2002
133
Apr 26, 2001
Apr 26, 2001
134
device->free = ph_DeleteDevice;
May 28, 2006
May 28, 2006
135
Apr 26, 2001
Apr 26, 2001
136
137
138
return device;
}
May 10, 2001
May 10, 2001
139
VideoBootStrap ph_bootstrap = {
Mar 23, 2002
Mar 23, 2002
140
141
"photon", "QNX Photon video output",
ph_Available, ph_CreateDevice
Apr 26, 2001
Apr 26, 2001
142
143
};
May 28, 2006
May 28, 2006
144
145
static void
ph_DeleteDevice (SDL_VideoDevice * device)
Apr 26, 2001
Apr 26, 2001
146
{
May 28, 2006
May 28, 2006
147
148
149
if (device) {
if (device->hidden) {
SDL_free (device->hidden);
Apr 26, 2001
Apr 26, 2001
150
151
device->hidden = NULL;
}
May 28, 2006
May 28, 2006
152
153
if (device->gl_data) {
SDL_free (device->gl_data);
Apr 26, 2001
Apr 26, 2001
154
155
device->gl_data = NULL;
}
May 28, 2006
May 28, 2006
156
SDL_free (device);
Apr 26, 2001
Apr 26, 2001
157
158
159
160
device = NULL;
}
}
May 28, 2006
May 28, 2006
161
162
static PtWidget_t *
ph_CreateWindow (_THIS)
Jan 20, 2003
Jan 20, 2003
163
164
{
PtWidget_t *widget;
May 28, 2006
May 28, 2006
165
166
widget = PtCreateWidget (PtWindow, NULL, 0, NULL);
Jan 20, 2003
Jan 20, 2003
167
168
169
170
return widget;
}
May 28, 2006
May 28, 2006
171
172
static int
ph_SetupWindow (_THIS, int w, int h, int flags)
Jan 20, 2003
Jan 20, 2003
173
{
May 28, 2006
May 28, 2006
174
175
176
177
178
179
180
181
182
PtArg_t args[32];
PhPoint_t pos = { 0, 0 };
PhDim_t *olddim;
PhDim_t dim = { w, h };
PhRect_t desktopextent;
int nargs = 0;
const char *windowpos;
const char *iscentered;
int x, y;
Jan 20, 2003
Jan 20, 2003
183
Dec 10, 2003
Dec 10, 2003
184
/* check if window size has been changed by Window Manager */
May 28, 2006
May 28, 2006
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
PtGetResource (window, Pt_ARG_DIM, &olddim, 0);
if ((olddim->w != w) || (olddim->h != h)) {
PtSetArg (&args[nargs++], Pt_ARG_DIM, &dim, 0);
}
if ((flags & SDL_RESIZABLE) == SDL_RESIZABLE) {
PtSetArg (&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE,
Ph_WM_CLOSE);
PtSetArg (&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE,
Ph_WM_MAX | Ph_WM_RESTORE | Ph_WM_RESIZE);
PtSetArg (&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE,
Ph_WM_RESIZE | Ph_WM_MOVE | Ph_WM_CLOSE | Ph_WM_MAX |
Ph_WM_RESTORE);
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);
PtSetArg (&args[nargs++], Pt_ARG_RESIZE_FLAGS, Pt_TRUE,
Pt_RESIZE_XY_AS_REQUIRED);
} else {
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);
PtSetArg (&args[nargs++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE,
Pt_RESIZE_XY_AS_REQUIRED);
}
if (((flags & SDL_NOFRAME) == SDL_NOFRAME)
|| ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)) {
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);
Feb 14, 2004
Feb 14, 2004
227
}
May 28, 2006
May 28, 2006
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
} else {
PtSetArg (&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE,
Ph_WM_RENDER_BORDER | Ph_WM_RENDER_TITLE |
Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MIN);
}
if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
PtSetArg (&args[nargs++], Pt_ARG_POS, &pos, 0);
PtSetArg (&args[nargs++], Pt_ARG_BASIC_FLAGS, Pt_TRUE,
Pt_BASIC_PREVENT_FILL);
PtSetArg (&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE,
Ph_WM_FFRONT | Ph_WM_MAX | Ph_WM_TOFRONT | Ph_WM_CONSWITCH);
PtSetArg (&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE,
Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISFOCUS |
Ph_WM_STATE_ISALTKEY);
} else {
PtSetArg (&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE,
Ph_WM_FFRONT | Ph_WM_CONSWITCH);
PtSetArg (&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE,
Ph_WM_STATE_ISFRONT);
PtSetArg (&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE,
Ph_WM_STATE_ISALTKEY);
if ((flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
PtSetArg (&args[nargs++], Pt_ARG_BASIC_FLAGS, Pt_TRUE,
Pt_BASIC_PREVENT_FILL);
} else {
PtSetArg (&args[nargs++], Pt_ARG_FILL_COLOR, Pg_BLACK, 0);
Feb 14, 2004
Feb 14, 2004
256
}
May 28, 2006
May 28, 2006
257
258
259
260
261
262
263
264
265
266
if (!currently_maximized) {
windowpos = SDL_getenv ("SDL_VIDEO_WINDOW_POS");
iscentered = SDL_getenv ("SDL_VIDEO_CENTERED");
if ((iscentered)
|| ((windowpos)
&& (SDL_strcmp (windowpos, "center") == 0))) {
PhWindowQueryVisible (Ph_QUERY_CONSOLE, 0, 0, &desktopextent);
if (desktop_mode.width > w) {
pos.x = (desktop_mode.width - w) / 2;
Dec 10, 2003
Dec 10, 2003
267
}
May 28, 2006
May 28, 2006
268
269
if (desktop_mode.height > h) {
pos.y = (desktop_mode.height - h) / 2;
Aug 23, 2003
Aug 23, 2003
270
271
}
May 28, 2006
May 28, 2006
272
273
274
275
276
277
278
279
280
281
282
283
pos.x += desktopextent.ul.x;
pos.y += desktopextent.ul.y;
PtSetArg (&args[nargs++], Pt_ARG_POS, &pos, 0);
} else {
if (windowpos) {
if (SDL_sscanf (windowpos, "%d,%d", &x, &y) == 2) {
if ((x < desktop_mode.width)
&& (y < desktop_mode.height)) {
PhWindowQueryVisible
(Ph_QUERY_CONSOLE, 0, 0, &desktopextent);
pos.x = x + desktopextent.ul.x;
pos.y = y + desktopextent.ul.y;
Dec 10, 2003
Dec 10, 2003
284
}
May 28, 2006
May 28, 2006
285
PtSetArg (&args[nargs++], Pt_ARG_POS, &pos, 0);
Dec 10, 2003
Dec 10, 2003
286
287
288
289
}
}
}
}
Aug 23, 2003
Aug 23, 2003
290
Dec 10, 2003
Dec 10, 2003
291
/* if window is maximized render it as maximized */
May 28, 2006
May 28, 2006
292
293
294
295
296
297
if (currently_maximized) {
PtSetArg (&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE,
Ph_WM_STATE_ISMAX);
} else {
PtSetArg (&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE,
Ph_WM_STATE_ISMAX);
Dec 10, 2003
Dec 10, 2003
298
299
300
}
/* do not grab the keyboard by default */
May 28, 2006
May 28, 2006
301
302
PtSetArg (&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE,
Ph_WM_STATE_ISALTKEY);
Dec 10, 2003
Dec 10, 2003
303
304
/* bring the focus to the window */
May 28, 2006
May 28, 2006
305
306
PtSetArg (&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE,
Ph_WM_STATE_ISFOCUS);
Dec 10, 2003
Dec 10, 2003
307
Feb 14, 2004
Feb 14, 2004
308
/* allow to catch hide event */
May 28, 2006
May 28, 2006
309
310
311
312
PtSetArg (&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE,
Ph_WM_HIDE);
PtSetArg (&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE,
Ph_WM_HIDE);
Jan 20, 2003
Jan 20, 2003
313
314
}
May 28, 2006
May 28, 2006
315
316
317
PtSetResources (window, nargs, args);
PtRealizeWidget (window);
PtWindowToFront (window);
Jan 20, 2003
Jan 20, 2003
318
May 28, 2006
May 28, 2006
319
320
321
#if 0 /* FIXME */
PtGetResource (window, Pt_ARG_POS, &olddim, 0);
fprintf (stderr, "POSITION: %d, %d\n", olddim->w, olddim->h);
Feb 14, 2004
Feb 14, 2004
322
323
#endif
Jan 20, 2003
Jan 20, 2003
324
325
326
return 0;
}
May 28, 2006
May 28, 2006
327
328
static const struct ColourMasks *
ph_GetColourMasks (int bpp)
Aug 4, 2003
Aug 4, 2003
329
330
331
{
/* The alpha mask doesn't appears to be needed */
static const struct ColourMasks phColorMasks[5] = {
May 28, 2006
May 28, 2006
332
333
334
335
336
337
/* 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},
Aug 4, 2003
Aug 4, 2003
338
339
};
May 28, 2006
May 28, 2006
340
341
342
343
344
345
346
347
348
349
350
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];
Aug 4, 2003
Aug 4, 2003
351
352
353
354
}
return NULL;
}
May 28, 2006
May 28, 2006
355
356
static int
ph_VideoInit (_THIS, SDL_PixelFormat * vformat)
Apr 26, 2001
Apr 26, 2001
357
{
Feb 14, 2004
Feb 14, 2004
358
PgHWCaps_t hwcaps;
Aug 4, 2003
Aug 4, 2003
359
int i;
Apr 26, 2001
Apr 26, 2001
360
May 28, 2006
May 28, 2006
361
362
window = NULL;
desktoppal = SDLPH_PAL_NONE;
Aug 30, 2003
Aug 30, 2003
363
Feb 16, 2006
Feb 16, 2006
364
#if SDL_VIDEO_OPENGL
May 28, 2006
May 28, 2006
365
366
367
368
oglctx = NULL;
oglbuffers = NULL;
oglflags = 0;
oglbpp = 0;
Feb 16, 2006
Feb 16, 2006
369
#endif
May 28, 2006
May 28, 2006
370
371
372
373
374
375
old_video_mode = -1;
old_refresh_rate = -1;
if (NULL == (phevent = SDL_malloc (EVENT_SIZE))) {
SDL_OutOfMemory ();
Jan 20, 2003
Jan 20, 2003
376
return -1;
Mar 11, 2002
Mar 11, 2002
377
}
May 28, 2006
May 28, 2006
378
SDL_memset (phevent, 0x00, EVENT_SIZE);
Mar 11, 2002
Mar 11, 2002
379
May 28, 2006
May 28, 2006
380
381
382
window = ph_CreateWindow (this);
if (window == NULL) {
SDL_SetError ("ph_VideoInit(): Couldn't create video window !\n");
Jan 20, 2003
Jan 20, 2003
383
384
385
return -1;
}
Mar 11, 2002
Mar 11, 2002
386
/* Create the blank cursor */
May 28, 2006
May 28, 2006
387
388
389
390
391
SDL_BlankCursor = this->CreateWMCursor (this, blank_cdata, blank_cmask,
(int) BLANK_CWIDTH,
(int) BLANK_CHEIGHT,
(int) BLANK_CHOTX,
(int) BLANK_CHOTY);
Mar 11, 2002
Mar 11, 2002
392
May 28, 2006
May 28, 2006
393
if (SDL_BlankCursor == NULL) {
Aug 4, 2003
Aug 4, 2003
394
return -1;
Mar 11, 2002
Mar 11, 2002
395
396
}
May 28, 2006
May 28, 2006
397
398
399
400
if (PgGetGraphicsHWCaps (&hwcaps) < 0) {
SDL_SetError
("ph_VideoInit(): GetGraphicsHWCaps function failed !\n");
this->FreeWMCursor (this, SDL_BlankCursor);
Aug 4, 2003
Aug 4, 2003
401
return -1;
Mar 11, 2002
Mar 11, 2002
402
403
}
May 28, 2006
May 28, 2006
404
405
406
407
if (PgGetVideoModeInfo (hwcaps.current_video_mode, &desktop_mode) < 0) {
SDL_SetError
("ph_VideoInit(): PgGetVideoModeInfo function failed !\n");
this->FreeWMCursor (this, SDL_BlankCursor);
Aug 4, 2003
Aug 4, 2003
408
return -1;
Mar 11, 2002
Mar 11, 2002
409
410
}
May 28, 2006
May 28, 2006
411
412
413
/* Determine the current screen size */
this->info.current_w = desktop_mode.width;
this->info.current_h = desktop_mode.height;
Mar 15, 2006
Mar 15, 2006
414
Mar 11, 2002
Mar 11, 2002
415
/* We need to return BytesPerPixel as it in used by CreateRGBsurface */
Aug 23, 2003
Aug 23, 2003
416
vformat->BitsPerPixel = desktop_mode.bits_per_pixel;
May 28, 2006
May 28, 2006
417
418
vformat->BytesPerPixel =
desktop_mode.bytes_per_scanline / desktop_mode.width;
Aug 23, 2003
Aug 23, 2003
419
desktopbpp = desktop_mode.bits_per_pixel;
May 28, 2006
May 28, 2006
420
Mar 28, 2002
Mar 28, 2002
421
/* save current palette */
May 28, 2006
May 28, 2006
422
423
424
425
426
427
428
if (desktopbpp == 8) {
PgGetPalette (savedpal);
PgGetPalette (syspalph);
} else {
for (i = 0; i < _Pg_MAX_PALETTE; i++) {
savedpal[i] = PgRGB (0, 0, 0);
syspalph[i] = PgRGB (0, 0, 0);
Aug 4, 2003
Aug 4, 2003
429
430
}
}
May 28, 2006
May 28, 2006
431
May 10, 2001
May 10, 2001
432
currently_fullscreen = 0;
Aug 4, 2003
Aug 4, 2003
433
currently_hided = 0;
Dec 10, 2003
Dec 10, 2003
434
currently_maximized = 0;
Aug 4, 2003
Aug 4, 2003
435
436
437
438
439
440
441
442
443
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;
Feb 14, 2004
Feb 14, 2004
444
videomode_emulatemode = 0;
May 28, 2006
May 28, 2006
445
May 10, 2001
May 10, 2001
446
this->info.wm_available = 1;
May 6, 2004
May 6, 2004
447
May 28, 2006
May 28, 2006
448
449
ph_UpdateHWInfo (this);
Apr 26, 2001
Apr 26, 2001
450
451
452
return 0;
}
May 28, 2006
May 28, 2006
453
454
455
static SDL_Surface *
ph_SetVideoMode (_THIS, SDL_Surface * current, int width, int height, int bpp,
Uint32 flags)
Apr 26, 2001
Apr 26, 2001
456
{
May 28, 2006
May 28, 2006
457
const struct ColourMasks *mask;
Apr 26, 2001
Apr 26, 2001
458
459
/* Lock the event thread, in multi-threading environments */
May 28, 2006
May 28, 2006
460
SDL_Lock_EventThread ();
Apr 26, 2001
Apr 26, 2001
461
Mar 28, 2002
Mar 28, 2002
462
463
current->flags = flags;
Aug 4, 2003
Aug 4, 2003
464
/* if we do not have desired fullscreen mode, then fallback into window mode */
May 28, 2006
May 28, 2006
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
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");
Aug 4, 2003
Aug 4, 2003
481
482
return NULL;
}
Apr 26, 2001
Apr 26, 2001
483
May 28, 2006
May 28, 2006
484
if (current->flags & SDL_INTERNALOPENGL) {
Feb 16, 2006
Feb 16, 2006
485
#if !SDL_VIDEO_OPENGL
Feb 14, 2004
Feb 14, 2004
486
/* if no built-in OpenGL support */
May 28, 2006
May 28, 2006
487
488
SDL_SetError
("ph_SetVideoMode(): no OpenGL support, you need to recompile SDL.\n");
May 1, 2006
May 1, 2006
489
current->flags &= ~SDL_INTERNALOPENGL;
Mar 11, 2002
Mar 11, 2002
490
return NULL;
Feb 16, 2006
Feb 16, 2006
491
#endif /* SDL_VIDEO_OPENGL */
May 28, 2006
May 28, 2006
492
} else {
Aug 4, 2003
Aug 4, 2003
493
/* Initialize internal variables */
May 28, 2006
May 28, 2006
494
495
496
if ((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
if (bpp == 8) {
desktoppal = SDLPH_PAL_SYSTEM;
Mar 23, 2002
Mar 23, 2002
497
}
Apr 26, 2001
Apr 26, 2001
498
May 28, 2006
May 28, 2006
499
current->flags &= ~SDL_RESIZABLE; /* no resize for Direct Context */
Aug 23, 2003
Aug 23, 2003
500
current->flags |= SDL_HWSURFACE;
May 28, 2006
May 28, 2006
501
} else {
Feb 14, 2004
Feb 14, 2004
502
/* remove this if we'll have support for the non-fullscreen sw/hw+doublebuf one day */
Aug 4, 2003
Aug 4, 2003
503
504
505
current->flags &= ~SDL_DOUBLEBUF;
/* Use offscreen memory if SDL_HWSURFACE flag is set */
May 28, 2006
May 28, 2006
506
507
508
if ((current->flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
if (desktopbpp != bpp) {
current->flags &= ~SDL_HWSURFACE;
Aug 4, 2003
Aug 4, 2003
509
}
Mar 11, 2002
Mar 11, 2002
510
}
Mar 28, 2002
Mar 28, 2002
511
Mar 23, 2002
Mar 23, 2002
512
/* using palette emulation code in window mode */
May 28, 2006
May 28, 2006
513
514
if (bpp == 8) {
if (desktopbpp >= 15) {
Aug 4, 2003
Aug 4, 2003
515
desktoppal = SDLPH_PAL_EMULATE;
May 28, 2006
May 28, 2006
516
} else {
Aug 4, 2003
Aug 4, 2003
517
desktoppal = SDLPH_PAL_SYSTEM;
Jan 20, 2003
Jan 20, 2003
518
}
May 28, 2006
May 28, 2006
519
520
} else {
desktoppal = SDLPH_PAL_NONE;
Mar 11, 2002
Mar 11, 2002
521
}
Jan 18, 2002
Jan 18, 2002
522
}
Mar 11, 2002
Mar 11, 2002
523
524
525
526
}
current->w = width;
current->h = height;
Jan 20, 2003
Jan 20, 2003
527
May 28, 2006
May 28, 2006
528
529
if (desktoppal == SDLPH_PAL_SYSTEM) {
current->flags |= SDL_HWPALETTE;
Aug 4, 2003
Aug 4, 2003
530
}
May 19, 2002
May 19, 2002
531
Aug 4, 2003
Aug 4, 2003
532
/* Must call at least once for setup image planes */
May 28, 2006
May 28, 2006
533
if (ph_SetupUpdateFunction (this, current, current->flags) == -1) {
May 6, 2004
May 6, 2004
534
/* Error string was filled in the ph_SetupUpdateFunction() */
May 19, 2002
May 19, 2002
535
536
return NULL;
}
Mar 11, 2002
Mar 11, 2002
537
Aug 4, 2003
Aug 4, 2003
538
/* finish window drawing, if we are not in fullscreen, of course */
May 28, 2006
May 28, 2006
539
540
541
542
if ((current->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) {
PtFlush ();
} else {
PgFlush ();
Aug 23, 2003
Aug 23, 2003
543
}
Mar 28, 2002
Mar 28, 2002
544
May 28, 2006
May 28, 2006
545
visualbpp = bpp;
Feb 14, 2004
Feb 14, 2004
546
May 28, 2006
May 28, 2006
547
ph_UpdateHWInfo (this);
Feb 14, 2004
Feb 14, 2004
548
May 28, 2006
May 28, 2006
549
SDL_Unlock_EventThread ();
Apr 26, 2001
Apr 26, 2001
550
Feb 14, 2004
Feb 14, 2004
551
/* We've done! */
Mar 23, 2002
Mar 23, 2002
552
return (current);
Apr 26, 2001
Apr 26, 2001
553
554
}
May 28, 2006
May 28, 2006
555
556
static void
ph_VideoQuit (_THIS)
Apr 26, 2001
Apr 26, 2001
557
{
Aug 4, 2003
Aug 4, 2003
558
/* restore palette */
May 28, 2006
May 28, 2006
559
560
561
562
563
if (desktopbpp == 8) {
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
564
}
Apr 26, 2001
Apr 26, 2001
565
May 28, 2006
May 28, 2006
566
ph_DestroyImage (this, SDL_VideoSurface);
Aug 4, 2003
Aug 4, 2003
567
May 28, 2006
May 28, 2006
568
569
570
571
if (window) {
PtUnrealizeWidget (window);
PtDestroyWidget (window);
window = NULL;
Mar 11, 2002
Mar 11, 2002
572
573
}
May 28, 2006
May 28, 2006
574
575
576
if (phevent != NULL) {
SDL_free (phevent);
phevent = NULL;
Jan 20, 2003
Jan 20, 2003
577
}
Mar 11, 2002
Mar 11, 2002
578
}
Apr 26, 2001
Apr 26, 2001
579
May 28, 2006
May 28, 2006
580
581
static int
ph_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors)
Apr 26, 2001
Apr 26, 2001
582
{
Mar 23, 2002
Mar 23, 2002
583
int i;
Jan 20, 2003
Jan 20, 2003
584
585
586
587
588
SDL_Rect updaterect;
updaterect.x = updaterect.y = 0;
updaterect.w = this->screen->w;
updaterect.h = this->screen->h;
Apr 26, 2001
Apr 26, 2001
589
Mar 23, 2002
Mar 23, 2002
590
/* palette emulation code, using palette of the PhImage_t struct */
May 28, 2006
May 28, 2006
591
592
593
594
595
596
597
if (desktoppal == SDLPH_PAL_EMULATE) {
if ((SDL_Image) && (SDL_Image->palette)) {
for (i = firstcolor; i < firstcolor + ncolors; i++) {
syspalph[i] =
PgRGB (colors[i - firstcolor].r,
colors[i - firstcolor].g,
colors[i - firstcolor].b);
Jan 20, 2003
Jan 20, 2003
598
SDL_Image->palette[i] = syspalph[i];
Mar 23, 2002
Mar 23, 2002
599
}
Aug 4, 2003
Aug 4, 2003
600
Jan 20, 2003
Jan 20, 2003
601
/* image needs to be redrawn */
May 28, 2006
May 28, 2006
602
this->UpdateRects (this, 1, &updaterect);
Mar 23, 2002
Mar 23, 2002
603
}
May 28, 2006
May 28, 2006
604
605
606
607
608
609
610
} else {
if (desktoppal == SDLPH_PAL_SYSTEM) {
for (i = firstcolor; i < firstcolor + ncolors; i++) {
syspalph[i] =
PgRGB (colors[i - firstcolor].r,
colors[i - firstcolor].g,
colors[i - firstcolor].b);
Mar 23, 2002
Mar 23, 2002
611
612
}
May 28, 2006
May 28, 2006
613
614
615
616
if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) {
/* window mode must use soft palette */
PgSetPalette (&syspalph[firstcolor], 0, firstcolor,
ncolors, Pg_PALSET_GLOBAL, 0);
Jan 20, 2003
Jan 20, 2003
617
/* image needs to be redrawn */
May 28, 2006
May 28, 2006
618
619
this->UpdateRects (this, 1, &updaterect);
} else {
Mar 23, 2002
Mar 23, 2002
620
/* fullscreen mode must use hardware palette */
May 28, 2006
May 28, 2006
621
622
PgSetPalette (&syspalph[firstcolor], 0, firstcolor,
ncolors, Pg_PALSET_GLOBAL, 0);
Mar 23, 2002
Mar 23, 2002
623
}
May 28, 2006
May 28, 2006
624
} else {
Mar 23, 2002
Mar 23, 2002
625
/* SDLPH_PAL_NONE do nothing */
Apr 26, 2001
Apr 26, 2001
626
}
Mar 23, 2002
Mar 23, 2002
627
}
May 28, 2006
May 28, 2006
628
Mar 23, 2002
Mar 23, 2002
629
return 1;
Apr 26, 2001
Apr 26, 2001
630
631
}
May 28, 2006
May 28, 2006
632
/* vi: set ts=4 sw=4 expandtab: */