comparison src/video/qtopia/SDL_sysvideo.cc @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
50 !=0 : Screen is 270° rotated 50 !=0 : Screen is 270° rotated
51 0: Screen is 90° rotated */ 51 0: Screen is 90° rotated */
52 #define SDL_QT_ROTATION_ENV_NAME "SDL_QT_INVERT_ROTATION" 52 #define SDL_QT_ROTATION_ENV_NAME "SDL_QT_INVERT_ROTATION"
53 53
54 /* Initialization/Query functions */ 54 /* Initialization/Query functions */
55 static int QT_VideoInit (_THIS, SDL_PixelFormat * vformat); 55 static int QT_VideoInit(_THIS, SDL_PixelFormat * vformat);
56 static SDL_Rect **QT_ListModes (_THIS, SDL_PixelFormat * format, 56 static SDL_Rect **QT_ListModes(_THIS, SDL_PixelFormat * format,
57 Uint32 flags); 57 Uint32 flags);
58 static SDL_Surface *QT_SetVideoMode (_THIS, SDL_Surface * current, 58 static SDL_Surface *QT_SetVideoMode(_THIS, SDL_Surface * current,
59 int width, int height, int bpp, 59 int width, int height, int bpp,
60 Uint32 flags); 60 Uint32 flags);
61 static void QT_UpdateMouse (_THIS); 61 static void QT_UpdateMouse(_THIS);
62 static int QT_SetColors (_THIS, int firstcolor, int ncolors, 62 static int QT_SetColors(_THIS, int firstcolor, int ncolors,
63 SDL_Color * colors); 63 SDL_Color * colors);
64 static void QT_VideoQuit (_THIS); 64 static void QT_VideoQuit(_THIS);
65 65
66 /* Hardware surface functions */ 66 /* Hardware surface functions */
67 static int QT_AllocHWSurface (_THIS, SDL_Surface * surface); 67 static int QT_AllocHWSurface(_THIS, SDL_Surface * surface);
68 static int QT_LockHWSurface (_THIS, SDL_Surface * surface); 68 static int QT_LockHWSurface(_THIS, SDL_Surface * surface);
69 static void QT_UnlockHWSurface (_THIS, SDL_Surface * surface); 69 static void QT_UnlockHWSurface(_THIS, SDL_Surface * surface);
70 static void QT_FreeHWSurface (_THIS, SDL_Surface * surface); 70 static void QT_FreeHWSurface(_THIS, SDL_Surface * surface);
71 71
72 static int QT_ToggleFullScreen (_THIS, int fullscreen); 72 static int QT_ToggleFullScreen(_THIS, int fullscreen);
73 73
74 static int QT_IconifyWindow (_THIS); 74 static int QT_IconifyWindow(_THIS);
75 static SDL_GrabMode QT_GrabInput (_THIS, SDL_GrabMode mode); 75 static SDL_GrabMode QT_GrabInput(_THIS, SDL_GrabMode mode);
76 76
77 /* FB driver bootstrap functions */ 77 /* FB driver bootstrap functions */
78 78
79 static int QT_Available (void) 79 static int QT_Available(void)
80 { 80 {
81 return (1); 81 return (1);
82 } 82 }
83 83
84 static void QT_DeleteDevice (SDL_VideoDevice * device) 84 static void QT_DeleteDevice(SDL_VideoDevice * device)
85 { 85 {
86 SDL_free (device->hidden); 86 SDL_free(device->hidden);
87 SDL_free (device); 87 SDL_free(device);
88 } 88 }
89 89
90 static SDL_VideoDevice *QT_CreateDevice (int devindex) 90 static SDL_VideoDevice *QT_CreateDevice(int devindex)
91 { 91 {
92 SDL_VideoDevice *device; 92 SDL_VideoDevice *device;
93 93
94 /* Initialize all variables that we clean on shutdown */ 94 /* Initialize all variables that we clean on shutdown */
95 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)); 95 device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
96 if (device) { 96 if (device) {
97 SDL_memset (device, 0, (sizeof *device)); 97 SDL_memset(device, 0, (sizeof *device));
98 device->hidden = (struct SDL_PrivateVideoData *) 98 device->hidden = (struct SDL_PrivateVideoData *)
99 SDL_malloc ((sizeof *device->hidden)); 99 SDL_malloc((sizeof *device->hidden));
100 } 100 }
101 if ((device == NULL) || (device->hidden == NULL)) { 101 if ((device == NULL) || (device->hidden == NULL)) {
102 SDL_OutOfMemory (); 102 SDL_OutOfMemory();
103 if (device) { 103 if (device) {
104 SDL_free (device); 104 SDL_free(device);
105 } 105 }
106 return (0); 106 return (0);
107 } 107 }
108 SDL_memset (device->hidden, 0, (sizeof *device->hidden)); 108 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
109 109
110 /* Set the function pointers */ 110 /* Set the function pointers */
111 device->VideoInit = QT_VideoInit; 111 device->VideoInit = QT_VideoInit;
112 device->ListModes = QT_ListModes; 112 device->ListModes = QT_ListModes;
113 device->SetVideoMode = QT_SetVideoMode; 113 device->SetVideoMode = QT_SetVideoMode;
149 "qtopia", "Qtopia / QPE graphics", 149 "qtopia", "Qtopia / QPE graphics",
150 QT_Available, QT_CreateDevice 150 QT_Available, QT_CreateDevice
151 }; 151 };
152 152
153 /* Function to sort the display_list */ 153 /* Function to sort the display_list */
154 static int CompareModes (const void *A, const void *B) 154 static int CompareModes(const void *A, const void *B)
155 { 155 {
156 #if 0 156 #if 0
157 const display_mode *a = (display_mode *) A; 157 const display_mode *a = (display_mode *) A;
158 const display_mode *b = (display_mode *) B; 158 const display_mode *b = (display_mode *) B;
159 159
160 if (a->space == b->space) { 160 if (a->space == b->space) {
161 return ((b->virtual_width * b->virtual_height) - 161 return ((b->virtual_width * b->virtual_height) -
162 (a->virtual_width * a->virtual_height)); 162 (a->virtual_width * a->virtual_height));
163 } else { 163 } else {
164 return (ColorSpaceToBitsPerPixel (b->space) - 164 return (ColorSpaceToBitsPerPixel(b->space) -
165 ColorSpaceToBitsPerPixel (a->space)); 165 ColorSpaceToBitsPerPixel(a->space));
166 } 166 }
167 #endif 167 #endif
168 return 0; 168 return 0;
169 } 169 }
170 170
171 /* Yes, this isn't the fastest it could be, but it works nicely */ 171 /* Yes, this isn't the fastest it could be, but it works nicely */
172 static int QT_AddMode (_THIS, int index, unsigned int w, unsigned int h) 172 static int QT_AddMode(_THIS, int index, unsigned int w, unsigned int h)
173 { 173 {
174 SDL_Rect *mode; 174 SDL_Rect *mode;
175 int i; 175 int i;
176 int next_mode; 176 int next_mode;
177 177
184 } 184 }
185 } 185 }
186 } 186 }
187 187
188 /* Set up the new video mode rectangle */ 188 /* Set up the new video mode rectangle */
189 mode = (SDL_Rect *) SDL_malloc (sizeof *mode); 189 mode = (SDL_Rect *) SDL_malloc(sizeof *mode);
190 if (mode == NULL) { 190 if (mode == NULL) {
191 SDL_OutOfMemory (); 191 SDL_OutOfMemory();
192 return (-1); 192 return (-1);
193 } 193 }
194 mode->x = 0; 194 mode->x = 0;
195 mode->y = 0; 195 mode->y = 0;
196 mode->w = w; 196 mode->w = w;
197 mode->h = h; 197 mode->h = h;
198 #ifdef QTOPIA_DEBUG 198 #ifdef QTOPIA_DEBUG
199 fprintf (stderr, "Adding mode %dx%d at %d bytes per pixel\n", w, h, 199 fprintf(stderr, "Adding mode %dx%d at %d bytes per pixel\n", w, h,
200 index + 1); 200 index + 1);
201 #endif 201 #endif
202 202
203 /* Allocate the new list of modes, and fill in the new mode */ 203 /* Allocate the new list of modes, and fill in the new mode */
204 next_mode = SDL_nummodes[index]; 204 next_mode = SDL_nummodes[index];
205 SDL_modelist[index] = (SDL_Rect **) 205 SDL_modelist[index] = (SDL_Rect **)
206 SDL_realloc (SDL_modelist[index], 206 SDL_realloc(SDL_modelist[index],
207 (1 + next_mode + 1) * sizeof (SDL_Rect *)); 207 (1 + next_mode + 1) * sizeof(SDL_Rect *));
208 if (SDL_modelist[index] == NULL) { 208 if (SDL_modelist[index] == NULL) {
209 SDL_OutOfMemory (); 209 SDL_OutOfMemory();
210 SDL_nummodes[index] = 0; 210 SDL_nummodes[index] = 0;
211 SDL_free (mode); 211 SDL_free(mode);
212 return (-1); 212 return (-1);
213 } 213 }
214 SDL_modelist[index][next_mode] = mode; 214 SDL_modelist[index][next_mode] = mode;
215 SDL_modelist[index][next_mode + 1] = NULL; 215 SDL_modelist[index][next_mode + 1] = NULL;
216 SDL_nummodes[index]++; 216 SDL_nummodes[index]++;
217 217
218 return (0); 218 return (0);
219 } 219 }
220 220
221 int QT_VideoInit (_THIS, SDL_PixelFormat * vformat) 221 int QT_VideoInit(_THIS, SDL_PixelFormat * vformat)
222 { 222 {
223 /* Initialize the QPE Application */ 223 /* Initialize the QPE Application */
224 /* Determine the screen depth */ 224 /* Determine the screen depth */
225 vformat->BitsPerPixel = QPixmap::defaultDepth (); 225 vformat->BitsPerPixel = QPixmap::defaultDepth();
226 226
227 // For now we hardcode the current depth because anything else 227 // For now we hardcode the current depth because anything else
228 // might as well be emulated by SDL rather than by Qtopia. 228 // might as well be emulated by SDL rather than by Qtopia.
229 229
230 QSize desktop_size = qApp->desktop ()->size (); 230 QSize desktop_size = qApp->desktop()->size();
231 QT_AddMode (_this, ((vformat->BitsPerPixel + 7) / 8) - 1, 231 QT_AddMode(_this, ((vformat->BitsPerPixel + 7) / 8) - 1,
232 desktop_size.width (), desktop_size.height ()); 232 desktop_size.width(), desktop_size.height());
233 QT_AddMode (_this, ((vformat->BitsPerPixel + 7) / 8) - 1, 233 QT_AddMode(_this, ((vformat->BitsPerPixel + 7) / 8) - 1,
234 desktop_size.height (), desktop_size.width ()); 234 desktop_size.height(), desktop_size.width());
235 235
236 /* Determine the current screen size */ 236 /* Determine the current screen size */
237 this->info.current_w = desktop_size.width (); 237 this->info.current_w = desktop_size.width();
238 this->info.current_h = desktop_size.height (); 238 this->info.current_h = desktop_size.height();
239 239
240 /* Create the window / widget */ 240 /* Create the window / widget */
241 SDL_Win = new SDL_QWin (QSize (QT_HIDDEN_SIZE, QT_HIDDEN_SIZE)); 241 SDL_Win = new SDL_QWin(QSize(QT_HIDDEN_SIZE, QT_HIDDEN_SIZE));
242 ((QPEApplication *) qApp)->showMainWidget (SDL_Win); 242 ((QPEApplication *) qApp)->showMainWidget(SDL_Win);
243 /* Fill in some window manager capabilities */ 243 /* Fill in some window manager capabilities */
244 _this->info.wm_available = 0; 244 _this->info.wm_available = 0;
245 245
246 /* We're done! */ 246 /* We're done! */
247 return (0); 247 return (0);
248 } 248 }
249 249
250 /* We support any dimension at our bit-depth */ 250 /* We support any dimension at our bit-depth */
251 SDL_Rect **QT_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) 251 SDL_Rect **QT_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
252 { 252 {
253 SDL_Rect **modes; 253 SDL_Rect **modes;
254 254
255 modes = ((SDL_Rect **) 0); 255 modes = ((SDL_Rect **) 0);
256 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { 256 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
262 } 262 }
263 return (modes); 263 return (modes);
264 } 264 }
265 265
266 /* Various screen update functions available */ 266 /* Various screen update functions available */
267 static void QT_NormalUpdate (_THIS, int numrects, SDL_Rect * rects); 267 static void QT_NormalUpdate(_THIS, int numrects, SDL_Rect * rects);
268 268
269 269
270 static int QT_SetFullScreen (_THIS, SDL_Surface * screen, int fullscreen) 270 static int QT_SetFullScreen(_THIS, SDL_Surface * screen, int fullscreen)
271 { 271 {
272 return -1; 272 return -1;
273 } 273 }
274 274
275 static int QT_ToggleFullScreen (_THIS, int fullscreen) 275 static int QT_ToggleFullScreen(_THIS, int fullscreen)
276 { 276 {
277 return -1; 277 return -1;
278 } 278 }
279 279
280 /* FIXME: check return values and cleanup here */ 280 /* FIXME: check return values and cleanup here */
281 SDL_Surface *QT_SetVideoMode (_THIS, SDL_Surface * current, 281 SDL_Surface *QT_SetVideoMode(_THIS, SDL_Surface * current,
282 int width, int height, int bpp, 282 int width, int height, int bpp, Uint32 flags)
283 Uint32 flags)
284 { 283 {
285 284
286 QImage *qimage; 285 QImage *qimage;
287 QSize desktop_size = qApp->desktop ()->size (); 286 QSize desktop_size = qApp->desktop()->size();
288 287
289 288
290 current->flags = 0; //SDL_FULLSCREEN; // We always run fullscreen. 289 current->flags = 0; //SDL_FULLSCREEN; // We always run fullscreen.
291 290
292 if (width <= desktop_size.width () 291 if (width <= desktop_size.width()
293 && height <= desktop_size.height ()) { 292 && height <= desktop_size.height()) {
294 current->w = desktop_size.width (); 293 current->w = desktop_size.width();
295 current->h = desktop_size.height (); 294 current->h = desktop_size.height();
296 } else if (width <= desktop_size.height () 295 } else if (width <= desktop_size.height()
297 && height <= desktop_size.width ()) { 296 && height <= desktop_size.width()) {
298 // Landscape mode 297 // Landscape mode
299 char *envString = SDL_getenv (SDL_QT_ROTATION_ENV_NAME); 298 char *envString = SDL_getenv(SDL_QT_ROTATION_ENV_NAME);
300 int envValue = envString ? atoi (envString) : 0; 299 int envValue = envString ? atoi(envString) : 0;
301 screenRotation = 300 screenRotation =
302 envValue ? SDL_QT_ROTATION_270 : SDL_QT_ROTATION_90; 301 envValue ? SDL_QT_ROTATION_270 : SDL_QT_ROTATION_90;
303 current->h = desktop_size.width (); 302 current->h = desktop_size.width();
304 current->w = desktop_size.height (); 303 current->w = desktop_size.height();
305 } else { 304 } else {
306 SDL_SetError ("Unsupported resolution, %dx%d\n", width, height); 305 SDL_SetError("Unsupported resolution, %dx%d\n", width, height);
307 } 306 }
308 if (flags & SDL_INTERNALOPENGL) { 307 if (flags & SDL_INTERNALOPENGL) {
309 SDL_SetError ("OpenGL not supported"); 308 SDL_SetError("OpenGL not supported");
310 return (NULL); 309 return (NULL);
311 } 310 }
312 /* Create the QImage framebuffer */ 311 /* Create the QImage framebuffer */
313 qimage = new QImage (current->w, current->h, bpp); 312 qimage = new QImage(current->w, current->h, bpp);
314 if (qimage->isNull ()) { 313 if (qimage->isNull()) {
315 SDL_SetError ("Couldn't create screen bitmap"); 314 SDL_SetError("Couldn't create screen bitmap");
316 delete qimage; 315 delete qimage;
317 return (NULL); 316 return (NULL);
318 } 317 }
319 current->pitch = qimage->bytesPerLine (); 318 current->pitch = qimage->bytesPerLine();
320 current->pixels = (void *) qimage->bits (); 319 current->pixels = (void *) qimage->bits();
321 SDL_Win->setImage (qimage); 320 SDL_Win->setImage(qimage);
322 _this->UpdateRects = QT_NormalUpdate; 321 _this->UpdateRects = QT_NormalUpdate;
323 SDL_Win->setFullscreen (true); 322 SDL_Win->setFullscreen(true);
324 /* We're done */ 323 /* We're done */
325 return (current); 324 return (current);
326 } 325 }
327 326
328 /* Update the current mouse state and position */ 327 /* Update the current mouse state and position */
329 void QT_UpdateMouse (_THIS) 328 void QT_UpdateMouse(_THIS)
330 { 329 {
331 QPoint point (-1, -1); 330 QPoint point(-1, -1);
332 if (SDL_Win->isActiveWindow ()) { 331 if (SDL_Win->isActiveWindow()) {
333 point = SDL_Win->mousePos (); 332 point = SDL_Win->mousePos();
334 } 333 }
335 334
336 if ((point.x () >= 0) && (point.x () < SDL_VideoSurface->w) && 335 if ((point.x() >= 0) && (point.x() < SDL_VideoSurface->w) &&
337 (point.y () >= 0) && (point.y () < SDL_VideoSurface->h)) { 336 (point.y() >= 0) && (point.y() < SDL_VideoSurface->h)) {
338 SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS); 337 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
339 SDL_PrivateMouseMotion (0, 0, 338 SDL_PrivateMouseMotion(0, 0,
340 (Sint16) point.x (), (Sint16) point.y ()); 339 (Sint16) point.x(), (Sint16) point.y());
341 } else { 340 } else {
342 SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS); 341 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
343 } 342 }
344 } 343 }
345 344
346 /* We don't actually allow hardware surfaces other than the main one */ 345 /* We don't actually allow hardware surfaces other than the main one */
347 static int QT_AllocHWSurface (_THIS, SDL_Surface * surface) 346 static int QT_AllocHWSurface(_THIS, SDL_Surface * surface)
348 { 347 {
349 return (-1); 348 return (-1);
350 } 349 }
351 static void QT_FreeHWSurface (_THIS, SDL_Surface * surface) 350 static void QT_FreeHWSurface(_THIS, SDL_Surface * surface)
352 { 351 {
353 return; 352 return;
354 } 353 }
355 static int QT_LockHWSurface (_THIS, SDL_Surface * surface) 354 static int QT_LockHWSurface(_THIS, SDL_Surface * surface)
356 { 355 {
357 return (0); 356 return (0);
358 } 357 }
359 static void QT_UnlockHWSurface (_THIS, SDL_Surface * surface) 358 static void QT_UnlockHWSurface(_THIS, SDL_Surface * surface)
360 { 359 {
361 return; 360 return;
362 } 361 }
363 362
364 static void QT_NormalUpdate (_THIS, int numrects, SDL_Rect * rects) 363 static void QT_NormalUpdate(_THIS, int numrects, SDL_Rect * rects)
365 { 364 {
366 if (SDL_Win->lockScreen ()) { 365 if (SDL_Win->lockScreen()) {
367 for (int i = 0; i < numrects; ++i) { 366 for (int i = 0; i < numrects; ++i) {
368 QRect rect (rects[i].x, rects[i].y, rects[i].w, rects[i].h); 367 QRect rect(rects[i].x, rects[i].y, rects[i].w, rects[i].h);
369 SDL_Win->repaintRect (rect); 368 SDL_Win->repaintRect(rect);
370 } 369 }
371 SDL_Win->unlockScreen (); 370 SDL_Win->unlockScreen();
372 } 371 }
373 } 372 }
374 /* Is the system palette settable? */ 373 /* Is the system palette settable? */
375 int QT_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) 374 int QT_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
376 { 375 {
377 return -1; 376 return -1;
378 } 377 }
379 378
380 void QT_VideoQuit (_THIS) 379 void QT_VideoQuit(_THIS)
381 { 380 {
382 // This is dumb, but if I free this, the app doesn't exit correctly. 381 // This is dumb, but if I free this, the app doesn't exit correctly.
383 // Of course, this will leak memory if init video is done more than once. 382 // Of course, this will leak memory if init video is done more than once.
384 // Sucks but such is life. 383 // Sucks but such is life.
385 384
386 // -- David Hedbor 385 // -- David Hedbor
387 // delete SDL_Win; 386 // delete SDL_Win;
388 // SDL_Win = 0; 387 // SDL_Win = 0;
389 _this->screen->pixels = NULL; 388 _this->screen->pixels = NULL;
390 QT_GrabInput (_this, SDL_GRAB_OFF); 389 QT_GrabInput(_this, SDL_GRAB_OFF);
391 } 390 }
392 391
393 static int QT_IconifyWindow (_THIS) 392 static int QT_IconifyWindow(_THIS)
394 { 393 {
395 SDL_Win->hide (); 394 SDL_Win->hide();
396 395
397 return true; 396 return true;
398 } 397 }
399 398
400 static SDL_GrabMode QT_GrabInput (_THIS, SDL_GrabMode mode) 399 static SDL_GrabMode QT_GrabInput(_THIS, SDL_GrabMode mode)
401 { 400 {
402 if (mode == SDL_GRAB_OFF) { 401 if (mode == SDL_GRAB_OFF) {
403 QPEApplication::grabKeyboard (); 402 QPEApplication::grabKeyboard();
404 qApp->processEvents (); 403 qApp->processEvents();
405 QPEApplication::ungrabKeyboard (); 404 QPEApplication::ungrabKeyboard();
406 } else { 405 } else {
407 QPEApplication::grabKeyboard (); 406 QPEApplication::grabKeyboard();
408 } 407 }
409 qApp->processEvents (); 408 qApp->processEvents();
410 return mode; 409 return mode;
411 } 410 }
412 411
413 }; /* Extern C */ 412 }; /* Extern C */
414 413