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/* GGI-based SDL video driver implementation. 259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/ 269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <fcntl.h> 289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <unistd.h> 299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <sys/mman.h> 309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <ggi/ggi.h> 329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <ggi/gii.h> 339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_video.h" 359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_mouse.h" 369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../SDL_sysvideo.h" 379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../SDL_pixels_c.h" 389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../../events/SDL_events_c.h" 399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_ggivideo.h" 409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_ggimouse_c.h" 419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_ggievents_c.h" 429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstruct private_hwdata 459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggi_visual_t vis; 479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}; 489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallggi_visual_t VIS; 509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Initialization/Query functions */ 529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int GGI_VideoInit(_THIS, SDL_PixelFormat *vformat); 539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic SDL_Rect **GGI_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); 549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic SDL_Surface *GGI_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); 559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int GGI_SetColors(_THIS, int firstcolor, int ncolors, 569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Color *colors); 579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void GGI_VideoQuit(_THIS); 589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Hardware surface functions */ 609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int GGI_AllocHWSurface(_THIS, SDL_Surface *surface); 619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int GGI_LockHWSurface(_THIS, SDL_Surface *surface); 629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void GGI_UnlockHWSurface(_THIS, SDL_Surface *surface); 639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void GGI_FreeHWSurface(_THIS, SDL_Surface *surface); 649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* GGI driver bootstrap functions */ 669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int GGI_Available(void) 689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggi_visual_t *vis; 709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vis = NULL; 729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (ggiInit() == 0) { 739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vis = ggiOpen(NULL); 749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (vis != NULL) { 759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggiClose(vis); 769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return (vis != NULL); 799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void GGI_DeleteDevice(SDL_VideoDevice *device) 829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(device->hidden); 849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(device); 859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic SDL_VideoDevice *GGI_CreateDevice(int devindex) 889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *device; 909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Initialize all variables that we clean on shutdown */ 929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); 939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( device ) { 949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memset(device, 0, (sizeof *device)); 959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->hidden = (struct SDL_PrivateVideoData *) 969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_malloc((sizeof *device->hidden)); 979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (device == NULL) || (device->hidden == NULL) ) { 999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_OutOfMemory(); 1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( device ) { 1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(device); 1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memset(device->hidden, 0, (sizeof *device->hidden)); 1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Set the function pointers */ 1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->VideoInit = GGI_VideoInit; 1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->ListModes = GGI_ListModes; 1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->SetVideoMode = GGI_SetVideoMode; 1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->SetColors = GGI_SetColors; 1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->UpdateRects = NULL; 1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->VideoQuit = GGI_VideoQuit; 1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->AllocHWSurface = GGI_AllocHWSurface; 1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->CheckHWBlit = NULL; 1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->FillHWRect = NULL; 1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->SetHWColorKey = NULL; 1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->SetHWAlpha = NULL; 1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->LockHWSurface = GGI_LockHWSurface; 1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->UnlockHWSurface = GGI_UnlockHWSurface; 1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->FlipHWSurface = NULL; 1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->FreeHWSurface = GGI_FreeHWSurface; 1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->SetCaption = NULL; 1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->SetIcon = NULL; 1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->IconifyWindow = NULL; 1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->GrabInput = NULL; 1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->GetWMInfo = NULL; 1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->InitOSKeymap = GGI_InitOSKeymap; 1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->PumpEvents = GGI_PumpEvents; 1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device->free = GGI_DeleteDevice; 1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return device; 1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallVideoBootStrap GGI_bootstrap = { 1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall "ggi", "General Graphics Interface (GGI)", 1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GGI_Available, GGI_CreateDevice 1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}; 1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic SDL_Rect video_mode; 1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic SDL_Rect *SDL_modelist[4] = { NULL, NULL, NULL, NULL }; 1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint GGI_VideoInit(_THIS, SDL_PixelFormat *vformat) 1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggi_mode mode = 1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1, 1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { GGI_AUTO, GGI_AUTO }, 1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { GGI_AUTO, GGI_AUTO }, 1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 0, 0 }, 1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GT_AUTO, 1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { GGI_AUTO, GGI_AUTO } 1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall }; 1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall struct private_hwdata *priv; 1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggi_color pal[256], map[256]; 1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const ggi_directbuffer *db; 1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int err, num_bufs; 1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggi_pixel white, black; 1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall priv = SDL_malloc(sizeof(struct private_hwdata)); 1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (priv == NULL) 1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Unhandled GGI mode type!\n"); 1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GGI_VideoQuit(NULL); 1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (ggiInit() != 0) 1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Unable to initialize GGI!\n"); 1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GGI_VideoQuit(NULL); 1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall VIS = ggiOpen(NULL); 1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (VIS == NULL) 1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Unable to open default GGI visual!\n"); 1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggiExit(); 1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GGI_VideoQuit(NULL); 1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggiSetFlags(VIS, GGIFLAG_ASYNC); 1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Validate mode, autodetecting any GGI_AUTO or GT_AUTO fields */ 1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggiCheckMode(VIS, &mode); 1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* At this point we should have a valid mode - try to set it */ 1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall err = ggiSetMode(VIS, &mode); 1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If we couldn't set _any_ modes, something is very wrong */ 1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (err) 1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Can't set a mode!\n"); 1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggiClose(VIS); 1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggiExit(); 1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GGI_VideoQuit(NULL); 1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Determine the current screen size */ 2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->info.current_w = mode.virt.x; 2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->info.current_h = mode.virt.y; 2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Set a palette for palletized modes */ 2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (GT_SCHEME(mode.graphtype) == GT_PALETTE) 2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggiSetColorfulPalette(VIS); 2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggiGetPalette(VIS, 0, 1 << vformat->BitsPerPixel, pal); 2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Now we try to get the DirectBuffer info, which determines whether 2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * SDL can access hardware surfaces directly. */ 2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall num_bufs = ggiDBGetNumBuffers(VIS); 2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (num_bufs > 0) 2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall db = ggiDBGetBuffer(VIS, 0); /* Only handle one DB for now */ 2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vformat->BitsPerPixel = db->buffer.plb.pixelformat->depth; 2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vformat->Rmask = db->buffer.plb.pixelformat->red_mask; 2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vformat->Gmask = db->buffer.plb.pixelformat->green_mask; 2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vformat->Bmask = db->buffer.plb.pixelformat->blue_mask; 2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Fill in our hardware acceleration capabilities */ 2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->info.wm_available = 0; 2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->info.hw_available = 1; 2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->info.video_mem = db->buffer.plb.stride * mode.virt.y; 2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video_mode.x = 0; 2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video_mode.y = 0; 2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video_mode.w = mode.virt.x; 2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video_mode.h = mode.virt.y; 2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_modelist[((vformat->BitsPerPixel + 7) / 8) - 1] = &video_mode; 2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* We're done! */ 2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic SDL_Rect **GGI_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) 2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(&SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1]); 2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Various screen update functions available */ 2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void GGI_DirectUpdate(_THIS, int numrects, SDL_Rect *rects); 2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_Surface *GGI_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) 2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggi_mode mode = 2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1, 2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { GGI_AUTO, GGI_AUTO }, 2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { GGI_AUTO, GGI_AUTO }, 2589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 0, 0 }, 2599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GT_AUTO, 2609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { GGI_AUTO, GGI_AUTO } 2619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall }; 2629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const ggi_directbuffer *db; 2639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggi_color pal[256]; 2649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int err; 2659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, "GGI_SetVideoMode()\n"); 2679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode.visible.x = mode.virt.x = width; 2699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode.visible.y = mode.virt.y = height; 2709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Translate requested SDL bit depth into a GGI mode */ 2729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall switch (bpp) 2739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 1: mode.graphtype = GT_1BIT; break; 2759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 2: mode.graphtype = GT_2BIT; break; 2769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 4: mode.graphtype = GT_4BIT; break; 2779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 8: mode.graphtype = GT_8BIT; break; 2789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 15: mode.graphtype = GT_15BIT; break; 2799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 16: mode.graphtype = GT_16BIT; break; 2809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 24: mode.graphtype = GT_24BIT; break; 2819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 32: mode.graphtype = GT_32BIT; break; 2829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall default: 2839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Unknown SDL bit depth, using GT_AUTO....\n"); 2849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode.graphtype = GT_AUTO; 2859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Validate mode, autodetecting any GGI_AUTO or GT_AUTO fields */ 2889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggiCheckMode(VIS, &mode); 2899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* At this point we should have a valid mode - try to set it */ 2919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall err = ggiSetMode(VIS, &mode); 2929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If we couldn't set _any_ modes, something is very wrong */ 2949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (err) 2959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Can't set a mode!\n"); 2979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggiClose(VIS); 2989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggiExit(); 2999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GGI_VideoQuit(NULL); 3009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Set a palette for palletized modes */ 3039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (GT_SCHEME(mode.graphtype) == GT_PALETTE) 3049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggiSetColorfulPalette(VIS); 3069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggiGetPalette(VIS, 0, 1 << bpp, pal); 3079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall db = ggiDBGetBuffer(VIS, 0); 3109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Set up the new mode framebuffer */ 3129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current->flags = (SDL_FULLSCREEN | SDL_HWSURFACE); 3139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current->w = mode.virt.x; 3149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current->h = mode.virt.y; 3159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current->pitch = db->buffer.plb.stride; 3169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current->pixels = db->read; 3179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Set the blit function */ 3199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->UpdateRects = GGI_DirectUpdate; 3209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* We're done */ 3229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(current); 3239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int GGI_AllocHWSurface(_THIS, SDL_Surface *surface) 3269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(-1); 3289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void GGI_FreeHWSurface(_THIS, SDL_Surface *surface) 3309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 3329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int GGI_LockHWSurface(_THIS, SDL_Surface *surface) 3349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 3369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void GGI_UnlockHWSurface(_THIS, SDL_Surface *surface) 3389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 3409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void GGI_DirectUpdate(_THIS, int numrects, SDL_Rect *rects) 3439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int i; 3459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* ggiFlush(VIS); */ 3479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for (i = 0; i < numrects; i++) 3499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggiFlushRegion(VIS, rects[i].x, rects[i].y, rects[i].w, rects[i].h); 3519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 3539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint GGI_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) 3569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int i; 3589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggi_color pal[256]; 3599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Set up the colormap */ 3619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for (i = 0; i < ncolors; i++) 3629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pal[i].r = (colors[i].r << 8) | colors[i].r; 3649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pal[i].g = (colors[i].g << 8) | colors[i].g; 3659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pal[i].b = (colors[i].b << 8) | colors[i].b; 3669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ggiSetPalette(VIS, firstcolor, ncolors, pal); 3699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return 1; 3719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid GGI_VideoQuit(_THIS) 3749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid GGI_FinalQuit(void) 3779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 379