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

Latest commit

 

History

History
414 lines (352 loc) · 13.2 KB

SDL_sysvideo.cc

File metadata and controls

414 lines (352 loc) · 13.2 KB
 
May 19, 2002
May 19, 2002
1
/*
Feb 1, 2006
Feb 1, 2006
2
3
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
May 19, 2002
May 19, 2002
4
Feb 1, 2006
Feb 1, 2006
5
6
7
8
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
May 19, 2002
May 19, 2002
9
Feb 1, 2006
Feb 1, 2006
10
11
12
13
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
Lesser General Public License for more details.
May 19, 2002
May 19, 2002
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
May 19, 2002
May 19, 2002
18
Feb 1, 2006
Feb 1, 2006
19
20
Sam Lantinga
slouken@libsdl.org
May 19, 2002
May 19, 2002
21
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
May 19, 2002
May 19, 2002
23
24
25
26
27
28
/* Qtopia based framebuffer implementation */
#include <unistd.h>
#include <qapplication.h>
May 28, 2002
May 28, 2002
29
#include <qpe/qpeapplication.h>
May 19, 2002
May 19, 2002
30
31
32
33
34
#include "SDL_timer.h"
#include "SDL_QWin.h"
May 28, 2006
May 28, 2006
35
36
extern "C"
{
May 19, 2002
May 19, 2002
37
Feb 16, 2006
Feb 16, 2006
38
39
#include "../SDL_sysvideo.h"
#include "../../events/SDL_events_c.h"
May 19, 2002
May 19, 2002
40
#include "SDL_sysevents_c.h"
Feb 16, 2006
Feb 16, 2006
41
#include "SDL_sysmouse_c.h"
May 19, 2002
May 19, 2002
42
43
44
#include "SDL_syswm_c.h"
#include "SDL_lowvideo.h"
May 28, 2006
May 28, 2006
45
46
//#define QTOPIA_DEBUG
#define QT_HIDDEN_SIZE 32 /* starting hidden window size */
May 19, 2002
May 19, 2002
47
May 28, 2006
May 28, 2006
48
49
50
51
/* Name of the environment variable used to invert the screen rotation or not:
Possible values:
!=0 : Screen is 270° rotated
0: Screen is 90° rotated */
Sep 1, 2002
Sep 1, 2002
52
#define SDL_QT_ROTATION_ENV_NAME "SDL_QT_INVERT_ROTATION"
May 28, 2006
May 28, 2006
53
54
/* Initialization/Query functions */
May 29, 2006
May 29, 2006
55
56
57
58
59
60
61
62
63
64
static int QT_VideoInit(_THIS, SDL_PixelFormat * vformat);
static SDL_Rect **QT_ListModes(_THIS, SDL_PixelFormat * format,
Uint32 flags);
static SDL_Surface *QT_SetVideoMode(_THIS, SDL_Surface * current,
int width, int height, int bpp,
Uint32 flags);
static void QT_UpdateMouse(_THIS);
static int QT_SetColors(_THIS, int firstcolor, int ncolors,
SDL_Color * colors);
static void QT_VideoQuit(_THIS);
May 28, 2006
May 28, 2006
65
66
/* Hardware surface functions */
May 29, 2006
May 29, 2006
67
68
69
70
static int QT_AllocHWSurface(_THIS, SDL_Surface * surface);
static int QT_LockHWSurface(_THIS, SDL_Surface * surface);
static void QT_UnlockHWSurface(_THIS, SDL_Surface * surface);
static void QT_FreeHWSurface(_THIS, SDL_Surface * surface);
May 28, 2006
May 28, 2006
71
May 29, 2006
May 29, 2006
72
static int QT_ToggleFullScreen(_THIS, int fullscreen);
May 28, 2006
May 28, 2006
73
May 29, 2006
May 29, 2006
74
75
static int QT_IconifyWindow(_THIS);
static SDL_GrabMode QT_GrabInput(_THIS, SDL_GrabMode mode);
May 28, 2006
May 28, 2006
76
77
78
/* FB driver bootstrap functions */
May 29, 2006
May 29, 2006
79
static int QT_Available(void)
May 28, 2006
May 28, 2006
80
81
{
return (1);
May 19, 2002
May 19, 2002
82
}
May 28, 2006
May 28, 2006
83
May 29, 2006
May 29, 2006
84
static void QT_DeleteDevice(SDL_VideoDevice * device)
May 28, 2006
May 28, 2006
85
{
May 29, 2006
May 29, 2006
86
87
SDL_free(device->hidden);
SDL_free(device);
May 19, 2002
May 19, 2002
88
}
May 28, 2006
May 28, 2006
89
May 29, 2006
May 29, 2006
90
static SDL_VideoDevice *QT_CreateDevice(int devindex)
May 28, 2006
May 28, 2006
91
92
93
94
{
SDL_VideoDevice *device;
/* Initialize all variables that we clean on shutdown */
May 29, 2006
May 29, 2006
95
device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
May 28, 2006
May 28, 2006
96
if (device) {
May 29, 2006
May 29, 2006
97
SDL_memset(device, 0, (sizeof *device));
May 28, 2006
May 28, 2006
98
device->hidden = (struct SDL_PrivateVideoData *)
May 29, 2006
May 29, 2006
99
SDL_malloc((sizeof *device->hidden));
May 28, 2006
May 28, 2006
100
101
}
if ((device == NULL) || (device->hidden == NULL)) {
May 29, 2006
May 29, 2006
102
SDL_OutOfMemory();
May 28, 2006
May 28, 2006
103
if (device) {
May 29, 2006
May 29, 2006
104
SDL_free(device);
May 28, 2006
May 28, 2006
105
106
107
}
return (0);
}
May 29, 2006
May 29, 2006
108
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
May 28, 2006
May 28, 2006
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* Set the function pointers */
device->VideoInit = QT_VideoInit;
device->ListModes = QT_ListModes;
device->SetVideoMode = QT_SetVideoMode;
device->UpdateMouse = QT_UpdateMouse;
device->SetColors = QT_SetColors;
device->UpdateRects = NULL;
device->VideoQuit = QT_VideoQuit;
device->AllocHWSurface = QT_AllocHWSurface;
device->CheckHWBlit = NULL;
device->FillHWRect = NULL;
device->SetHWColorKey = NULL;
device->SetHWAlpha = NULL;
device->LockHWSurface = QT_LockHWSurface;
device->UnlockHWSurface = QT_UnlockHWSurface;
device->FlipHWSurface = NULL;
device->FreeHWSurface = QT_FreeHWSurface;
device->SetIcon = NULL;
device->SetCaption = QT_SetWMCaption;
device->IconifyWindow = QT_IconifyWindow;
device->GrabInput = QT_GrabInput;
device->GetWMInfo = NULL;
device->FreeWMCursor = QT_FreeWMCursor;
device->CreateWMCursor = QT_CreateWMCursor;
device->ShowWMCursor = QT_ShowWMCursor;
device->WarpWMCursor = QT_WarpWMCursor;
device->InitOSKeymap = QT_InitOSKeymap;
device->PumpEvents = QT_PumpEvents;
device->free = QT_DeleteDevice;
device->ToggleFullScreen = QT_ToggleFullScreen;
/* Set the driver flags */
device->handles_any_size = 0;
return device;
May 19, 2002
May 19, 2002
146
}
May 28, 2006
May 28, 2006
147
148
149
150
151
152
153
VideoBootStrap Qtopia_bootstrap = {
"qtopia", "Qtopia / QPE graphics",
QT_Available, QT_CreateDevice
};
/* Function to sort the display_list */
May 29, 2006
May 29, 2006
154
static int CompareModes(const void *A, const void *B)
May 28, 2006
May 28, 2006
155
156
157
158
159
160
161
162
163
{
#if 0
const display_mode *a = (display_mode *) A;
const display_mode *b = (display_mode *) B;
if (a->space == b->space) {
return ((b->virtual_width * b->virtual_height) -
(a->virtual_width * a->virtual_height));
} else {
May 29, 2006
May 29, 2006
164
165
return (ColorSpaceToBitsPerPixel(b->space) -
ColorSpaceToBitsPerPixel(a->space));
May 28, 2006
May 28, 2006
166
}
May 19, 2002
May 19, 2002
167
#endif
May 28, 2006
May 28, 2006
168
return 0;
May 19, 2002
May 19, 2002
169
170
}
May 28, 2006
May 28, 2006
171
/* Yes, this isn't the fastest it could be, but it works nicely */
May 29, 2006
May 29, 2006
172
static int QT_AddMode(_THIS, int index, unsigned int w, unsigned int h)
May 28, 2006
May 28, 2006
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
{
SDL_Rect *mode;
int i;
int next_mode;
/* Check to see if we already have this mode */
if (SDL_nummodes[index] > 0) {
for (i = SDL_nummodes[index] - 1; i >= 0; --i) {
mode = SDL_modelist[index][i];
if ((mode->w == w) && (mode->h == h)) {
return (0);
}
}
}
/* Set up the new video mode rectangle */
May 29, 2006
May 29, 2006
189
mode = (SDL_Rect *) SDL_malloc(sizeof *mode);
May 28, 2006
May 28, 2006
190
if (mode == NULL) {
May 29, 2006
May 29, 2006
191
SDL_OutOfMemory();
May 28, 2006
May 28, 2006
192
193
194
195
196
197
return (-1);
}
mode->x = 0;
mode->y = 0;
mode->w = w;
mode->h = h;
May 19, 2002
May 19, 2002
198
#ifdef QTOPIA_DEBUG
May 29, 2006
May 29, 2006
199
200
fprintf(stderr, "Adding mode %dx%d at %d bytes per pixel\n", w, h,
index + 1);
May 19, 2002
May 19, 2002
201
202
#endif
May 28, 2006
May 28, 2006
203
204
205
/* Allocate the new list of modes, and fill in the new mode */
next_mode = SDL_nummodes[index];
SDL_modelist[index] = (SDL_Rect **)
May 29, 2006
May 29, 2006
206
207
SDL_realloc(SDL_modelist[index],
(1 + next_mode + 1) * sizeof(SDL_Rect *));
May 28, 2006
May 28, 2006
208
if (SDL_modelist[index] == NULL) {
May 29, 2006
May 29, 2006
209
SDL_OutOfMemory();
May 28, 2006
May 28, 2006
210
SDL_nummodes[index] = 0;
May 29, 2006
May 29, 2006
211
SDL_free(mode);
May 28, 2006
May 28, 2006
212
213
214
215
216
217
218
219
220
return (-1);
}
SDL_modelist[index][next_mode] = mode;
SDL_modelist[index][next_mode + 1] = NULL;
SDL_nummodes[index]++;
return (0);
}
May 29, 2006
May 29, 2006
221
int QT_VideoInit(_THIS, SDL_PixelFormat * vformat)
May 28, 2006
May 28, 2006
222
223
224
{
/* Initialize the QPE Application */
/* Determine the screen depth */
May 29, 2006
May 29, 2006
225
vformat->BitsPerPixel = QPixmap::defaultDepth();
May 28, 2006
May 28, 2006
226
227
228
229
// For now we hardcode the current depth because anything else
// might as well be emulated by SDL rather than by Qtopia.
May 29, 2006
May 29, 2006
230
231
232
233
234
QSize desktop_size = qApp->desktop()->size();
QT_AddMode(_this, ((vformat->BitsPerPixel + 7) / 8) - 1,
desktop_size.width(), desktop_size.height());
QT_AddMode(_this, ((vformat->BitsPerPixel + 7) / 8) - 1,
desktop_size.height(), desktop_size.width());
May 28, 2006
May 28, 2006
235
236
/* Determine the current screen size */
May 29, 2006
May 29, 2006
237
238
this->info.current_w = desktop_size.width();
this->info.current_h = desktop_size.height();
May 28, 2006
May 28, 2006
239
240
/* Create the window / widget */
May 29, 2006
May 29, 2006
241
242
SDL_Win = new SDL_QWin(QSize(QT_HIDDEN_SIZE, QT_HIDDEN_SIZE));
((QPEApplication *) qApp)->showMainWidget(SDL_Win);
May 28, 2006
May 28, 2006
243
244
245
246
247
248
249
250
/* Fill in some window manager capabilities */
_this->info.wm_available = 0;
/* We're done! */
return (0);
}
/* We support any dimension at our bit-depth */
May 29, 2006
May 29, 2006
251
SDL_Rect **QT_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
May 28, 2006
May 28, 2006
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
{
SDL_Rect **modes;
modes = ((SDL_Rect **) 0);
if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
modes = SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1];
} else {
if (format->BitsPerPixel == _this->screen->format->BitsPerPixel) {
modes = ((SDL_Rect **) - 1);
}
}
return (modes);
}
/* Various screen update functions available */
May 29, 2006
May 29, 2006
267
static void QT_NormalUpdate(_THIS, int numrects, SDL_Rect * rects);
May 28, 2006
May 28, 2006
268
269
May 29, 2006
May 29, 2006
270
static int QT_SetFullScreen(_THIS, SDL_Surface * screen, int fullscreen)
May 28, 2006
May 28, 2006
271
272
{
return -1;
May 19, 2002
May 19, 2002
273
}
May 28, 2006
May 28, 2006
274
May 29, 2006
May 29, 2006
275
static int QT_ToggleFullScreen(_THIS, int fullscreen)
May 28, 2006
May 28, 2006
276
277
278
279
280
{
return -1;
}
/* FIXME: check return values and cleanup here */
May 29, 2006
May 29, 2006
281
282
SDL_Surface *QT_SetVideoMode(_THIS, SDL_Surface * current,
int width, int height, int bpp, Uint32 flags)
May 28, 2006
May 28, 2006
283
284
285
{
QImage *qimage;
May 29, 2006
May 29, 2006
286
QSize desktop_size = qApp->desktop()->size();
May 28, 2006
May 28, 2006
287
288
289
290
current->flags = 0; //SDL_FULLSCREEN; // We always run fullscreen.
May 29, 2006
May 29, 2006
291
292
293
294
295
296
if (width <= desktop_size.width()
&& height <= desktop_size.height()) {
current->w = desktop_size.width();
current->h = desktop_size.height();
} else if (width <= desktop_size.height()
&& height <= desktop_size.width()) {
May 28, 2006
May 28, 2006
297
// Landscape mode
May 29, 2006
May 29, 2006
298
299
char *envString = SDL_getenv(SDL_QT_ROTATION_ENV_NAME);
int envValue = envString ? atoi(envString) : 0;
May 28, 2006
May 28, 2006
300
301
screenRotation =
envValue ? SDL_QT_ROTATION_270 : SDL_QT_ROTATION_90;
May 29, 2006
May 29, 2006
302
303
current->h = desktop_size.width();
current->w = desktop_size.height();
May 28, 2006
May 28, 2006
304
} else {
May 29, 2006
May 29, 2006
305
SDL_SetError("Unsupported resolution, %dx%d\n", width, height);
May 28, 2006
May 28, 2006
306
307
}
if (flags & SDL_INTERNALOPENGL) {
May 29, 2006
May 29, 2006
308
SDL_SetError("OpenGL not supported");
May 28, 2006
May 28, 2006
309
310
311
return (NULL);
}
/* Create the QImage framebuffer */
May 29, 2006
May 29, 2006
312
313
314
qimage = new QImage(current->w, current->h, bpp);
if (qimage->isNull()) {
SDL_SetError("Couldn't create screen bitmap");
May 28, 2006
May 28, 2006
315
316
317
delete qimage;
return (NULL);
}
May 29, 2006
May 29, 2006
318
319
320
current->pitch = qimage->bytesPerLine();
current->pixels = (void *) qimage->bits();
SDL_Win->setImage(qimage);
May 28, 2006
May 28, 2006
321
_this->UpdateRects = QT_NormalUpdate;
May 29, 2006
May 29, 2006
322
SDL_Win->setFullscreen(true);
May 28, 2006
May 28, 2006
323
324
325
326
327
/* We're done */
return (current);
}
/* Update the current mouse state and position */
May 29, 2006
May 29, 2006
328
void QT_UpdateMouse(_THIS)
May 28, 2006
May 28, 2006
329
{
May 29, 2006
May 29, 2006
330
331
332
QPoint point(-1, -1);
if (SDL_Win->isActiveWindow()) {
point = SDL_Win->mousePos();
May 28, 2006
May 28, 2006
333
334
}
May 29, 2006
May 29, 2006
335
336
337
338
339
if ((point.x() >= 0) && (point.x() < SDL_VideoSurface->w) &&
(point.y() >= 0) && (point.y() < SDL_VideoSurface->h)) {
SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
SDL_PrivateMouseMotion(0, 0,
(Sint16) point.x(), (Sint16) point.y());
May 28, 2006
May 28, 2006
340
} else {
May 29, 2006
May 29, 2006
341
SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
May 28, 2006
May 28, 2006
342
343
344
345
}
}
/* We don't actually allow hardware surfaces other than the main one */
May 29, 2006
May 29, 2006
346
static int QT_AllocHWSurface(_THIS, SDL_Surface * surface)
May 28, 2006
May 28, 2006
347
348
349
{
return (-1);
}
May 29, 2006
May 29, 2006
350
static void QT_FreeHWSurface(_THIS, SDL_Surface * surface)
May 28, 2006
May 28, 2006
351
352
{
return;
May 19, 2002
May 19, 2002
353
}
May 29, 2006
May 29, 2006
354
static int QT_LockHWSurface(_THIS, SDL_Surface * surface)
May 28, 2006
May 28, 2006
355
356
{
return (0);
May 19, 2002
May 19, 2002
357
}
May 29, 2006
May 29, 2006
358
static void QT_UnlockHWSurface(_THIS, SDL_Surface * surface)
May 28, 2006
May 28, 2006
359
360
{
return;
May 19, 2002
May 19, 2002
361
}
May 28, 2006
May 28, 2006
362
May 29, 2006
May 29, 2006
363
static void QT_NormalUpdate(_THIS, int numrects, SDL_Rect * rects)
May 28, 2006
May 28, 2006
364
{
May 29, 2006
May 29, 2006
365
if (SDL_Win->lockScreen()) {
May 28, 2006
May 28, 2006
366
for (int i = 0; i < numrects; ++i) {
May 29, 2006
May 29, 2006
367
368
QRect rect(rects[i].x, rects[i].y, rects[i].w, rects[i].h);
SDL_Win->repaintRect(rect);
May 28, 2006
May 28, 2006
369
}
May 29, 2006
May 29, 2006
370
SDL_Win->unlockScreen();
May 28, 2006
May 28, 2006
371
372
373
}
}
/* Is the system palette settable? */
May 29, 2006
May 29, 2006
374
int QT_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
May 28, 2006
May 28, 2006
375
376
{
return -1;
May 19, 2002
May 19, 2002
377
}
May 28, 2006
May 28, 2006
378
May 29, 2006
May 29, 2006
379
void QT_VideoQuit(_THIS)
May 28, 2006
May 28, 2006
380
381
382
383
384
385
386
387
388
{
// This is dumb, but if I free this, the app doesn't exit correctly.
// Of course, this will leak memory if init video is done more than once.
// Sucks but such is life.
// -- David Hedbor
// delete SDL_Win;
// SDL_Win = 0;
_this->screen->pixels = NULL;
May 29, 2006
May 29, 2006
389
QT_GrabInput(_this, SDL_GRAB_OFF);
May 19, 2002
May 19, 2002
390
}
May 28, 2006
May 28, 2006
391
May 29, 2006
May 29, 2006
392
static int QT_IconifyWindow(_THIS)
May 28, 2006
May 28, 2006
393
{
May 29, 2006
May 29, 2006
394
SDL_Win->hide();
May 28, 2006
May 28, 2006
395
396
return true;
May 19, 2002
May 19, 2002
397
}
May 28, 2006
May 28, 2006
398
May 29, 2006
May 29, 2006
399
static SDL_GrabMode QT_GrabInput(_THIS, SDL_GrabMode mode)
May 28, 2006
May 28, 2006
400
401
{
if (mode == SDL_GRAB_OFF) {
May 29, 2006
May 29, 2006
402
403
404
QPEApplication::grabKeyboard();
qApp->processEvents();
QPEApplication::ungrabKeyboard();
May 28, 2006
May 28, 2006
405
} else {
May 29, 2006
May 29, 2006
406
QPEApplication::grabKeyboard();
May 28, 2006
May 28, 2006
407
}
May 29, 2006
May 29, 2006
408
qApp->processEvents();
May 28, 2006
May 28, 2006
409
return mode;
Jan 20, 2003
Jan 20, 2003
410
}
May 28, 2006
May 28, 2006
411
412
413
414
}; /* Extern C */
/* vi: set ts=4 sw=4 expandtab: */