19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL - Simple DirectMedia Layer 39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Copyright (C) 1997-2012 Sam Lantinga 49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is free software; you can redistribute it and/or 69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall modify it under the terms of the GNU Lesser General Public 79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License as published by the Free Software Foundation; either 89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall version 2.1 of the License, or (at your option) any later version. 99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is distributed in the hope that it will be useful, 119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall but WITHOUT ANY WARRANTY; without even the implied warranty of 129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Lesser General Public License for more details. 149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall You should have received a copy of the GNU Lesser General Public 169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License along with this library; if not, write to the Free Software 179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Sam Lantinga 209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall slouken@libsdl.org 219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/ 229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h" 239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Qtopia based framebuffer implementation */ 259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <unistd.h> 279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <qapplication.h> 299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <qpe/qpeapplication.h> 309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_timer.h" 329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_QWin.h" 349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern "C" { 369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../SDL_sysvideo.h" 389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../../events/SDL_events_c.h" 399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_sysevents_c.h" 409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_sysmouse_c.h" 419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_syswm_c.h" 429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_lowvideo.h" 439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall //#define QTOPIA_DEBUG 459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define QT_HIDDEN_SIZE 32 /* starting hidden window size */ 469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Name of the environment variable used to invert the screen rotation or not: 489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Possible values: 499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall !=0 : Screen is 270� rotated 509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0: Screen is 90� rotated*/ 519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define SDL_QT_ROTATION_ENV_NAME "SDL_QT_INVERT_ROTATION" 529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Initialization/Query functions */ 549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static int QT_VideoInit(_THIS, SDL_PixelFormat *vformat); 559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static SDL_Rect **QT_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); 569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static SDL_Surface *QT_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); 579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static void QT_UpdateMouse(_THIS); 589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static int QT_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); 599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static void QT_VideoQuit(_THIS); 609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Hardware surface functions */ 629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static int QT_AllocHWSurface(_THIS, SDL_Surface *surface); 639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static int QT_LockHWSurface(_THIS, SDL_Surface *surface); 649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static void QT_UnlockHWSurface(_THIS, SDL_Surface *surface); 659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static void QT_FreeHWSurface(_THIS, SDL_Surface *surface); 669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static int QT_ToggleFullScreen(_THIS, int fullscreen); 689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static int QT_IconifyWindow(_THIS); 709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static SDL_GrabMode QT_GrabInput(_THIS, SDL_GrabMode mode); 719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* FB driver bootstrap functions */ 739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static int QT_Available(void) 759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(1); 779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static void QT_DeleteDevice(SDL_VideoDevice *device) 809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(device->hidden); 829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(device); 839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static SDL_VideoDevice *QT_CreateDevice(int devindex) 869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *device; 889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Initialize all variables that we clean on shutdown */ 909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); 919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( device ) { 929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memset(device, 0, (sizeof *device)); 939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->hidden = (struct SDL_PrivateVideoData *) 949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_malloc((sizeof *device->hidden)); 959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (device == NULL) || (device->hidden == NULL) ) { 979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_OutOfMemory(); 989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( device ) { 999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(device); 1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memset(device->hidden, 0, (sizeof *device->hidden)); 1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Set the function pointers */ 1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->VideoInit = QT_VideoInit; 1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->ListModes = QT_ListModes; 1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->SetVideoMode = QT_SetVideoMode; 1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->UpdateMouse = QT_UpdateMouse; 1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->SetColors = QT_SetColors; 1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->UpdateRects = NULL; 1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->VideoQuit = QT_VideoQuit; 1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->AllocHWSurface = QT_AllocHWSurface; 1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->CheckHWBlit = NULL; 1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->FillHWRect = NULL; 1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->SetHWColorKey = NULL; 1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->SetHWAlpha = NULL; 1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->LockHWSurface = QT_LockHWSurface; 1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->UnlockHWSurface = QT_UnlockHWSurface; 1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->FlipHWSurface = NULL; 1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->FreeHWSurface = QT_FreeHWSurface; 1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->SetIcon = NULL; 1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->SetCaption = QT_SetWMCaption; 1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->IconifyWindow = QT_IconifyWindow; 1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->GrabInput = QT_GrabInput; 1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->GetWMInfo = NULL; 1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->FreeWMCursor = QT_FreeWMCursor; 1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->CreateWMCursor = QT_CreateWMCursor; 1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->ShowWMCursor = QT_ShowWMCursor; 1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->WarpWMCursor = QT_WarpWMCursor; 1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->InitOSKeymap = QT_InitOSKeymap; 1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->PumpEvents = QT_PumpEvents; 1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->free = QT_DeleteDevice; 1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->ToggleFullScreen = QT_ToggleFullScreen; 1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Set the driver flags */ 1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->handles_any_size = 0; 1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return device; 1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall VideoBootStrap Qtopia_bootstrap = { 1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall "qtopia", "Qtopia / QPE graphics", 1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall QT_Available, QT_CreateDevice 1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall }; 1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Function to sort the display_list */ 1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static int CompareModes(const void *A, const void *B) 1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if 0 1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const display_mode *a = (display_mode *)A; 1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const display_mode *b = (display_mode *)B; 1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( a->space == b->space ) { 1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return((b->virtual_width*b->virtual_height)- 1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (a->virtual_width*a->virtual_height)); 1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(ColorSpaceToBitsPerPixel(b->space)- 1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ColorSpaceToBitsPerPixel(a->space)); 1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return 0; 1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Yes, this isn't the fastest it could be, but it works nicely */ 1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static int QT_AddMode(_THIS, int index, unsigned int w, unsigned int h) 1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Rect *mode; 1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int i; 1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int next_mode; 1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Check to see if we already have this mode */ 1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_nummodes[index] > 0 ) { 1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( i=SDL_nummodes[index]-1; i >= 0; --i ) { 1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode = SDL_modelist[index][i]; 1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (mode->w == w) && (mode->h == h) ) { 1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Set up the new video mode rectangle */ 1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode = (SDL_Rect *)SDL_malloc(sizeof *mode); 1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( mode == NULL ) { 1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_OutOfMemory(); 1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(-1); 1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode->x = 0; 1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode->y = 0; 1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode->w = w; 1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode->h = h; 1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef QTOPIA_DEBUG 1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, "Adding mode %dx%d at %d bytes per pixel\n", w, h, index+1); 1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Allocate the new list of modes, and fill in the new mode */ 1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall next_mode = SDL_nummodes[index]; 1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_modelist[index] = (SDL_Rect **) 2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *)); 2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_modelist[index] == NULL ) { 2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_OutOfMemory(); 2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_nummodes[index] = 0; 2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(mode); 2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(-1); 2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_modelist[index][next_mode] = mode; 2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_modelist[index][next_mode+1] = NULL; 2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_nummodes[index]++; 2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int QT_VideoInit(_THIS, SDL_PixelFormat *vformat) 2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Initialize the QPE Application */ 2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Determine the screen depth */ 2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vformat->BitsPerPixel = QPixmap::defaultDepth(); 2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // For now we hardcode the current depth because anything else 2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // might as well be emulated by SDL rather than by Qtopia. 2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall QSize desktop_size = qApp->desktop()->size(); 2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall QT_AddMode(_this, ((vformat->BitsPerPixel+7)/8)-1, 2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall desktop_size.width(), desktop_size.height()); 2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall QT_AddMode(_this, ((vformat->BitsPerPixel+7)/8)-1, 2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall desktop_size.height(), desktop_size.width()); 2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Determine the current screen size */ 2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall _this->info.current_w = desktop_size.width(); 2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall _this->info.current_h = desktop_size.height(); 2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Create the window / widget */ 2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Win = new SDL_QWin(QSize(QT_HIDDEN_SIZE, QT_HIDDEN_SIZE)); 2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ((QPEApplication*)qApp)->showMainWidget(SDL_Win); 2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Fill in some window manager capabilities */ 2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall _this->info.wm_available = 0; 2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* We're done! */ 2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* We support any dimension at our bit-depth */ 2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Rect **QT_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) 2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Rect **modes; 2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall modes = ((SDL_Rect **)0); 2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { 2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall modes = SDL_modelist[((format->BitsPerPixel+7)/8)-1]; 2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( format->BitsPerPixel == 2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall _this->screen->format->BitsPerPixel ) { 2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall modes = ((SDL_Rect **)-1); 2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(modes); 2589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Various screen update functions available */ 2619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static void QT_NormalUpdate(_THIS, int numrects, SDL_Rect *rects); 2629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static int QT_SetFullScreen(_THIS, SDL_Surface *screen, int fullscreen) 2659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return -1; 2679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static int QT_ToggleFullScreen(_THIS, int fullscreen) 2709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return -1; 2729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* FIXME: check return values and cleanup here */ 2759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Surface *QT_SetVideoMode(_THIS, SDL_Surface *current, 2769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int width, int height, int bpp, Uint32 flags) 2779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall QImage *qimage; 2809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall QSize desktop_size = qApp->desktop()->size(); 2819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current->flags = 0; //SDL_FULLSCREEN; // We always run fullscreen. 2849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(width <= desktop_size.width() 2869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall && height <= desktop_size.height()) { 2879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current->w = desktop_size.width(); 2889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current->h = desktop_size.height(); 2899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else if(width <= desktop_size.height() && height <= desktop_size.width()) { 2909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Landscape mode 2919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall char * envString = SDL_getenv(SDL_QT_ROTATION_ENV_NAME); 2929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int envValue = envString ? atoi(envString) : 0; 2939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall screenRotation = envValue ? SDL_QT_ROTATION_270 : SDL_QT_ROTATION_90; 2949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current->h = desktop_size.width(); 2959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current->w = desktop_size.height(); 2969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 2979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Unsupported resolution, %dx%d\n", width, height); 2989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( flags & SDL_OPENGL ) { 3009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("OpenGL not supported"); 3019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 3029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Create the QImage framebuffer */ 3049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall qimage = new QImage(current->w, current->h, bpp); 3059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (qimage->isNull()) { 3069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Couldn't create screen bitmap"); 3079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall delete qimage; 3089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 3099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current->pitch = qimage->bytesPerLine(); 3119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current->pixels = (void *)qimage->bits(); 3129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Win->setImage(qimage); 3139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall _this->UpdateRects = QT_NormalUpdate; 3149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Win->setFullscreen(true); 3159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* We're done */ 3169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(current); 3179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Update the current mouse state and position */ 3209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void QT_UpdateMouse(_THIS) 3219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall QPoint point(-1, -1); 3239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_Win->isActiveWindow() ) { 3249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall point = SDL_Win->mousePos(); 3259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (point.x() >= 0) && (point.x() < SDL_VideoSurface->w) && 3289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (point.y() >= 0) && (point.y() < SDL_VideoSurface->h) ) { 3299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); 3309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateMouseMotion(0, 0, 3319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (Sint16)point.x(), (Sint16)point.y()); 3329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 3339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); 3349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* We don't actually allow hardware surfaces other than the main one */ 3389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static int QT_AllocHWSurface(_THIS, SDL_Surface *surface) 3399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(-1); 3419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static void QT_FreeHWSurface(_THIS, SDL_Surface *surface) 3439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 3459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static int QT_LockHWSurface(_THIS, SDL_Surface *surface) 3479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 3499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static void QT_UnlockHWSurface(_THIS, SDL_Surface *surface) 3519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 3539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static void QT_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) 3569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(SDL_Win->lockScreen()) { 3589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for(int i=0; i<numrects; ++i ) { 3599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall QRect rect(rects[i].x, rects[i].y, 3609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rects[i].w, rects[i].h); 3619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Win->repaintRect(rect); 3629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Win->unlockScreen(); 3649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Is the system palette settable? */ 3679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int QT_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) 3689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return -1; 3709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void QT_VideoQuit(_THIS) 3739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // This is dumb, but if I free this, the app doesn't exit correctly. 3759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Of course, this will leak memory if init video is done more than once. 3769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Sucks but such is life. 3779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // -- David Hedbor 3799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // delete SDL_Win; 3809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // SDL_Win = 0; 3819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall _this->screen->pixels = NULL; 3829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall QT_GrabInput(_this, SDL_GRAB_OFF); 3839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static int QT_IconifyWindow(_THIS) { 3869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Win->hide(); 3879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return true; 3899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall static SDL_GrabMode QT_GrabInput(_THIS, SDL_GrabMode mode) { 3929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(mode == SDL_GRAB_OFF) { 3939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall QPEApplication::grabKeyboard(); 3949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall qApp->processEvents(); 3959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall QPEApplication::ungrabKeyboard(); 3969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 3979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall QPEApplication::grabKeyboard(); 3989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall qApp->processEvents(); 4009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return mode; 4019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}; /* Extern C */ 404