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/* The high-level video driver subsystem */ 259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL.h" 279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_sysvideo.h" 289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_blit.h" 299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_pixels_c.h" 309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_cursor_c.h" 319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../events/SDL_sysevents.h" 329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../events/SDL_events_c.h" 339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Available video drivers */ 359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic VideoBootStrap *bootstrap[] = { 369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_QUARTZ 379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &QZ_bootstrap, 389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_X11 409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &X11_bootstrap, 419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_DGA 439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &DGA_bootstrap, 449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_NANOX 469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &NX_bootstrap, 479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_IPOD 499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &iPod_bootstrap, 509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_QTOPIA 529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &Qtopia_bootstrap, 539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_WSCONS 559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &WSCONS_bootstrap, 569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_FBCON 589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &FBCON_bootstrap, 599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_DIRECTFB 619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &DirectFB_bootstrap, 629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_PS2GS 649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &PS2GS_bootstrap, 659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_PS3 679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &PS3_bootstrap, 689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_GGI 709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &GGI_bootstrap, 719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_VGL 739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &VGL_bootstrap, 749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_SVGALIB 769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &SVGALIB_bootstrap, 779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_GAPI 799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &GAPI_bootstrap, 809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_WINDIB 829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &WINDIB_bootstrap, 839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_DDRAW 859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &DIRECTX_bootstrap, 869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_BWINDOW 889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &BWINDOW_bootstrap, 899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_TOOLBOX 919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &TOOLBOX_bootstrap, 929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_DRAWSPROCKET 949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &DSp_bootstrap, 959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_PHOTON 979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &ph_bootstrap, 989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_EPOC 1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &EPOC_bootstrap, 1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_XBIOS 1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &XBIOS_bootstrap, 1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_GEM 1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &GEM_bootstrap, 1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_PICOGUI 1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &PG_bootstrap, 1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_DC 1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &DC_bootstrap, 1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_NDS 1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &NDS_bootstrap, 1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_RISCOS 1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &RISCOS_bootstrap, 1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_OS2FS 1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &OS2FSLib_bootstrap, 1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_AALIB 1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &AALIB_bootstrap, 1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_CACA 1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &CACA_bootstrap, 1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_DRIVER_DUMMY 1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall &DUMMY_bootstrap, 1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall NULL 1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}; 1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_VideoDevice *current_video = NULL; 1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Various local functions */ 1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_VideoInit(const char *driver_name, Uint32 flags); 1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_VideoQuit(void); 1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_GL_UpdateRectsLock(SDL_VideoDevice* this, int numrects, SDL_Rect* rects); 1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic SDL_GrabMode SDL_WM_GrabInputOff(void); 1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_OPENGL 1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int lock_count = 0; 1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Initialize the video and event subsystems -- determine native pixel format 1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_VideoInit (const char *driver_name, Uint32 flags) 1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *video; 1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int index; 1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int i; 1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PixelFormat vformat; 1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 video_flags; 1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Toggle the event thread flags, based on OS requirements */ 1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(MUST_THREAD_EVENTS) 1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall flags |= SDL_INIT_EVENTTHREAD; 1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#elif defined(CANT_THREAD_EVENTS) 1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD ) { 1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("OS doesn't support threaded events"); 1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(-1); 1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Check to make sure we don't overwrite 'current_video' */ 1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( current_video != NULL ) { 1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoQuit(); 1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Select the proper video driver */ 1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall index = 0; 1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video = NULL; 1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( driver_name != NULL ) { 1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if 0 /* This will be replaced with a better driver selection API */ 1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_strrchr(driver_name, ':') != NULL ) { 1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall index = atoi(SDL_strrchr(driver_name, ':')+1); 1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( i=0; bootstrap[i]; ++i ) { 1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_strcasecmp(bootstrap[i]->name, driver_name) == 0) { 1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( bootstrap[i]->available() ) { 1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video = bootstrap[i]->create(index); 1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( i=0; bootstrap[i]; ++i ) { 1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( bootstrap[i]->available() ) { 1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video = bootstrap[i]->create(index); 1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video != NULL ) { 1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video == NULL ) { 2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("No available video device"); 2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(-1); 2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current_video = video; 2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current_video->name = bootstrap[i]->name; 2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Do some basic variable initialization */ 2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->screen = NULL; 2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->shadow = NULL; 2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->visible = NULL; 2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->physpal = NULL; 2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gammacols = NULL; 2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gamma = NULL; 2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->wm_title = NULL; 2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->wm_icon = NULL; 2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->offset_x = 0; 2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->offset_y = 0; 2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memset(&video->info, 0, (sizeof video->info)); 2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->displayformatalphapixel = NULL; 2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Set some very sane GL defaults */ 2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.driver_loaded = 0; 2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.dll_handle = NULL; 2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.red_size = 3; 2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.green_size = 3; 2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.blue_size = 2; 2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.alpha_size = 0; 2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.buffer_size = 0; 2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.depth_size = 16; 2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.stencil_size = 0; 2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.double_buffer = 1; 2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.accum_red_size = 0; 2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.accum_green_size = 0; 2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.accum_blue_size = 0; 2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.accum_alpha_size = 0; 2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.stereo = 0; 2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.multisamplebuffers = 0; 2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.multisamplesamples = 0; 2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.accelerated = -1; /* not known, don't set */ 2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.swap_control = -1; /* not known, don't set */ 2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Initialize the video subsystem */ 2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memset(&vformat, 0, sizeof(vformat)); 2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->VideoInit(video, &vformat) < 0 ) { 2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoQuit(); 2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(-1); 2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Create a zero sized video surface of the appropriate format */ 2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video_flags = SDL_SWSURFACE; 2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoSurface = SDL_CreateRGBSurface(video_flags, 0, 0, 2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vformat.BitsPerPixel, 2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vformat.Rmask, vformat.Gmask, vformat.Bmask, 0); 2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_VideoSurface == NULL ) { 2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoQuit(); 2589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(-1); 2599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PublicSurface = NULL; /* Until SDL_SetVideoMode() */ 2619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if 0 /* Don't change the current palette - may be used by other programs. 2639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * The application can't do anything with the display surface until 2649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * a video mode has been set anyway. :) 2659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 2669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If we have a palettized surface, create a default palette */ 2679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_VideoSurface->format->palette ) { 2689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PixelFormat *vf = SDL_VideoSurface->format; 2699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_DitherColors(vf->palette->colors, vf->BitsPerPixel); 2709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->SetColors(video, 2719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0, vf->palette->ncolors, vf->palette->colors); 2729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 2749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->info.vfmt = SDL_VideoSurface->format; 2759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Start the event loop */ 2779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_StartEventLoop(flags) < 0 ) { 2789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoQuit(); 2799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(-1); 2809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_CursorInit(flags & SDL_INIT_EVENTTHREAD); 2829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* We're ready to go! */ 2849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 2859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallchar *SDL_VideoDriverName(char *namebuf, int maxlen) 2889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 2899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( current_video != NULL ) { 2909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_strlcpy(namebuf, current_video->name, maxlen); 2919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(namebuf); 2929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 2949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 2979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Get the current display surface 2989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 2999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_Surface *SDL_GetVideoSurface(void) 3009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Surface *visible; 3029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall visible = NULL; 3049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( current_video ) { 3059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall visible = current_video->visible; 3069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(visible); 3089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 3119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Get the current information about the video hardware 3129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 3139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallconst SDL_VideoInfo *SDL_GetVideoInfo(void) 3149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const SDL_VideoInfo *info; 3169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall info = NULL; 3189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( current_video ) { 3199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall info = ¤t_video->info; 3209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(info); 3229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 3259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Return a pointer to an array of available screen dimensions for the 3269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * given format, sorted largest to smallest. Returns NULL if there are 3279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * no dimensions available for a particular format, or (SDL_Rect **)-1 3289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * if any dimension is okay for the given format. If 'format' is NULL, 3299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * the mode list will be for the format given by SDL_GetVideoInfo()->vfmt 3309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 3319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_Rect ** SDL_ListModes (SDL_PixelFormat *format, Uint32 flags) 3329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *video = current_video; 3349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *this = current_video; 3359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Rect **modes; 3369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall modes = NULL; 3389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_VideoSurface ) { 3399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( format == NULL ) { 3409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format = SDL_VideoSurface->format; 3419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall modes = video->ListModes(this, format, flags); 3439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(modes); 3459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 3489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Check to see if a particular video mode is supported. 3499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * It returns 0 if the requested mode is not supported under any bit depth, 3509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * or returns the bits-per-pixel of the closest available mode with the 3519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * given width and height. If this bits-per-pixel is different from the 3529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * one used when setting the video mode, SDL_SetVideoMode() will succeed, 3539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * but will emulate the requested bits-per-pixel with a shadow surface. 3549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 3559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic Uint8 SDL_closest_depths[4][8] = { 3569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 8 bit closest depth ordering */ 3579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 0, 8, 16, 15, 32, 24, 0, 0 }, 3589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 15,16 bit closest depth ordering */ 3599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 0, 16, 15, 32, 24, 8, 0, 0 }, 3609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 24 bit closest depth ordering */ 3619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 0, 24, 32, 16, 15, 8, 0, 0 }, 3629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 32 bit closest depth ordering */ 3639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 0, 32, 16, 15, 24, 8, 0, 0 } 3649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}; 3659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef __MACOS__ /* MPW optimization bug? */ 3689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define NEGATIVE_ONE 0xFFFFFFFF 3699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 3709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define NEGATIVE_ONE -1 3719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 3729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_VideoModeOK (int width, int height, int bpp, Uint32 flags) 3749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int table, b, i; 3769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int supported; 3779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PixelFormat format; 3789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Rect **sizes; 3799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Currently 1 and 4 bpp are not supported */ 3819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( bpp < 8 || bpp > 32 ) { 3829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 3839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (width <= 0) || (height <= 0) ) { 3859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 3869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Search through the list valid of modes */ 3899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memset(&format, 0, sizeof(format)); 3909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall supported = 0; 3919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall table = ((bpp+7)/8)-1; 3929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_closest_depths[table][0] = bpp; 3939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_closest_depths[table][7] = 0; 3949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( b = 0; !supported && SDL_closest_depths[table][b]; ++b ) { 3959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.BitsPerPixel = SDL_closest_depths[table][b]; 3969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sizes = SDL_ListModes(&format, flags); 3979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( sizes == (SDL_Rect **)0 ) { 3989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* No sizes supported at this bit-depth */ 3999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall continue; 4009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 4019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (sizes == (SDL_Rect **)NEGATIVE_ONE) { 4029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Any size supported at this bit-depth */ 4039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall supported = 1; 4049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall continue; 4059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else if (current_video->handles_any_size) { 4069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Driver can center a smaller surface to simulate fullscreen */ 4079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( i=0; sizes[i]; ++i ) { 4089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ((sizes[i]->w >= width) && (sizes[i]->h >= height)) { 4099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall supported = 1; /* this mode can fit the centered window. */ 4109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 4119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 4149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( i=0; sizes[i]; ++i ) { 4159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ((sizes[i]->w == width) && (sizes[i]->h == height)) { 4169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall supported = 1; 4179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 4189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( supported ) { 4229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall --b; 4239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(SDL_closest_depths[table][b]); 4249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 4259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 4269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 4289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 4309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Get the closest non-emulated video mode to the one requested 4319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 4329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_GetVideoMode (int *w, int *h, int *BitsPerPixel, Uint32 flags) 4339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 4349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int table, b, i; 4359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int supported; 4369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int native_bpp; 4379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PixelFormat format; 4389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Rect **sizes; 4399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Check parameters */ 4419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( *BitsPerPixel < 8 || *BitsPerPixel > 32 ) { 4429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Invalid bits per pixel (range is {8...32})"); 4439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 4449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ((*w <= 0) || (*h <= 0)) { 4469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Invalid width or height"); 4479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 4489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Try the original video mode, get the closest depth */ 4519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall native_bpp = SDL_VideoModeOK(*w, *h, *BitsPerPixel, flags); 4529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( native_bpp == *BitsPerPixel ) { 4539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(1); 4549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( native_bpp > 0 ) { 4569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *BitsPerPixel = native_bpp; 4579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(1); 4589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* No exact size match at any depth, look for closest match */ 4619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memset(&format, 0, sizeof(format)); 4629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall supported = 0; 4639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall table = ((*BitsPerPixel+7)/8)-1; 4649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_closest_depths[table][0] = *BitsPerPixel; 4659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_closest_depths[table][7] = SDL_VideoSurface->format->BitsPerPixel; 4669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( b = 0; !supported && SDL_closest_depths[table][b]; ++b ) { 4679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int best; 4689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.BitsPerPixel = SDL_closest_depths[table][b]; 4709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sizes = SDL_ListModes(&format, flags); 4719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( sizes == (SDL_Rect **)0 ) { 4729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* No sizes supported at this bit-depth */ 4739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall continue; 4749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall best=0; 4769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( i=0; sizes[i]; ++i ) { 4779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Mode with both dimensions bigger or equal than asked ? */ 4789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ((sizes[i]->w >= *w) && (sizes[i]->h >= *h)) { 4799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Mode with any dimension smaller or equal than current best ? */ 4809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ((sizes[i]->w <= sizes[best]->w) || (sizes[i]->h <= sizes[best]->h)) { 4819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Now choose the mode that has less pixels */ 4829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ((sizes[i]->w * sizes[i]->h) <= (sizes[best]->w * sizes[best]->h)) { 4839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall best=i; 4849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall supported = 1; 4859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (supported) { 4909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *w=sizes[best]->w; 4919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *h=sizes[best]->h; 4929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *BitsPerPixel = SDL_closest_depths[table][b]; 4939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ! supported ) { 4969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("No video mode large enough for %dx%d", *w, *h); 4979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(supported); 4999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 5009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* This should probably go somewhere else -- like SDL_surface.c */ 5029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void SDL_ClearSurface(SDL_Surface *surface) 5039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 5049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 black; 5059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall black = SDL_MapRGB(surface->format, 0, 0, 0); 5079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_FillRect(surface, NULL, black); 5089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ((surface->flags&SDL_HWSURFACE) && (surface->flags&SDL_DOUBLEBUF)) { 5099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Flip(surface); 5109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_FillRect(surface, NULL, black); 5119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (surface->flags&SDL_FULLSCREEN) { 5139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Flip(surface); 5149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 5169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 5189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Create a shadow surface suitable for fooling the app. :-) 5199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 5209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void SDL_CreateShadowSurface(int depth) 5219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 5229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 Rmask, Gmask, Bmask; 5239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Allocate the shadow surface */ 5259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( depth == (SDL_VideoSurface->format)->BitsPerPixel ) { 5269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Rmask = (SDL_VideoSurface->format)->Rmask; 5279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Gmask = (SDL_VideoSurface->format)->Gmask; 5289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Bmask = (SDL_VideoSurface->format)->Bmask; 5299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 5309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Rmask = Gmask = Bmask = 0; 5319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_ShadowSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 5339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoSurface->w, SDL_VideoSurface->h, 5349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall depth, Rmask, Gmask, Bmask, 0); 5359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_ShadowSurface == NULL ) { 5369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 5379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 8-bit shadow surfaces report that they have exclusive palette */ 5409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_ShadowSurface->format->palette ) { 5419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_ShadowSurface->flags |= SDL_HWPALETTE; 5429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( depth == (SDL_VideoSurface->format)->BitsPerPixel ) { 5439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memcpy(SDL_ShadowSurface->format->palette->colors, 5449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoSurface->format->palette->colors, 5459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoSurface->format->palette->ncolors* 5469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sizeof(SDL_Color)); 5479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 5489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_DitherColors( 5499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_ShadowSurface->format->palette->colors, depth); 5509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If the video surface is resizable, the shadow should say so */ 5549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (SDL_VideoSurface->flags & SDL_RESIZABLE) == SDL_RESIZABLE ) { 5559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_ShadowSurface->flags |= SDL_RESIZABLE; 5569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If the video surface has no frame, the shadow should say so */ 5589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (SDL_VideoSurface->flags & SDL_NOFRAME) == SDL_NOFRAME ) { 5599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_ShadowSurface->flags |= SDL_NOFRAME; 5609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If the video surface is fullscreen, the shadow should say so */ 5629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { 5639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_ShadowSurface->flags |= SDL_FULLSCREEN; 5649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If the video surface is flippable, the shadow should say so */ 5669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (SDL_VideoSurface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) { 5679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_ShadowSurface->flags |= SDL_DOUBLEBUF; 5689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 5709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 5719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef __QNXNTO__ 5739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall #include <sys/neutrino.h> 5749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* __QNXNTO__ */ 5759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef WIN32 5779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall extern int sysevents_mouse_pressed; 5789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 5799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 5819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Set the requested video mode, allocating a shadow buffer if necessary. 5829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 5839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags) 5849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 5859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *video, *this; 5869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Surface *prev_mode, *mode; 5879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int video_w; 5889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int video_h; 5899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int video_bpp; 5909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int is_opengl; 5919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_GrabMode saved_grab; 5929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall #ifdef WIN32 5949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sysevents_mouse_pressed = 0; 5959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall #endif 5969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Start up the video driver, if necessary.. 5989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall WARNING: This is the only function protected this way! 5999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 6009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ! current_video ) { 6019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE) < 0 ) { 6029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 6039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 6049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 6059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this = video = current_video; 6069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Default to the current width and height */ 6089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( width == 0 ) { 6099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall width = video->info.current_w; 6109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 6119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( height == 0 ) { 6129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall height = video->info.current_h; 6139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 6149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Default to the current video bpp */ 6159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( bpp == 0 ) { 6169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall flags |= SDL_ANYFORMAT; 6179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bpp = SDL_VideoSurface->format->BitsPerPixel; 6189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 6199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Get a good video mode, the closest one possible */ 6219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video_w = width; 6229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video_h = height; 6239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video_bpp = bpp; 6249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ! SDL_GetVideoMode(&video_w, &video_h, &video_bpp, flags) ) { 6259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 6269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 6279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Check the requested flags */ 6299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* There's no palette in > 8 bits-per-pixel mode */ 6309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video_bpp > 8 ) { 6319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall flags &= ~SDL_HWPALETTE; 6329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 6339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if 0 6349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (flags&SDL_FULLSCREEN) != SDL_FULLSCREEN ) { 6359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* There's no windowed double-buffering */ 6369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall flags &= ~SDL_DOUBLEBUF; 6379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 6389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 6399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (flags&SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) { 6409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Use hardware surfaces when double-buffering */ 6419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall flags |= SDL_HWSURFACE; 6429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 6439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall is_opengl = ( ( flags & SDL_OPENGL ) == SDL_OPENGL ); 6459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( is_opengl ) { 6469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* These flags are for 2D video modes only */ 6479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall flags &= ~(SDL_HWSURFACE|SDL_DOUBLEBUF); 6489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 6499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Reset the keyboard here so event callbacks can run */ 6519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_ResetKeyboard(); 6529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_ResetMouse(); 6539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetMouseRange(width, height); 6549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_cursorstate &= ~CURSOR_USINGSW; 6559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Clean up any previous video mode */ 6579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_PublicSurface != NULL ) { 6589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PublicSurface = NULL; 6599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 6609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_ShadowSurface != NULL ) { 6619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Surface *ready_to_go; 6629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ready_to_go = SDL_ShadowSurface; 6639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_ShadowSurface = NULL; 6649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_FreeSurface(ready_to_go); 6659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 6669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->physpal ) { 6679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(video->physpal->colors); 6689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(video->physpal); 6699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->physpal = NULL; 6709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 6719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if( video->gammacols) { 6729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(video->gammacols); 6739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gammacols = NULL; 6749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 6759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Save the previous grab state and turn off grab for mode switch */ 6779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall saved_grab = SDL_WM_GrabInputOff(); 6789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Try to set the video mode, along with offset and clipping */ 6809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall prev_mode = SDL_VideoSurface; 6819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_LockCursor(); 6829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoSurface = NULL; /* In case it's freed by driver */ 6839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode = video->SetVideoMode(this, prev_mode,video_w,video_h,video_bpp,flags); 6849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( mode ) { /* Prevent resize events from mode change */ 6859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* But not on OS/2 */ 6869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef __OS2__ 6879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateResize(mode->w, mode->h); 6889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 6899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Sam - If we asked for OpenGL mode, and didn't get it, fail */ 6919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( is_opengl && !(mode->flags & SDL_OPENGL) ) { 6929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode = NULL; 6939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("OpenGL not available"); 6949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 6959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 6969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 6979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * rcg11292000 6989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * If you try to set an SDL_OPENGL surface, and fail to find a 6999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * matching visual, then the next call to SDL_SetVideoMode() 7009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * will segfault, since we no longer point to a dummy surface, 7019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * but rather NULL. 7029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Sam 11/29/00 7039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * WARNING, we need to make sure that the previous mode hasn't 7049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * already been freed by the video driver. What do we do in 7059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * that case? Should we call SDL_VideoInit() again? 7069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 7079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoSurface = (mode != NULL) ? mode : prev_mode; 7089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (mode != NULL) && (!is_opengl) ) { 7109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Sanity check */ 7119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (mode->w < width) || (mode->h < height) ) { 7129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Video mode smaller than requested"); 7139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 7149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 7159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If we have a palettized surface, create a default palette */ 7179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( mode->format->palette ) { 7189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PixelFormat *vf = mode->format; 7199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_DitherColors(vf->palette->colors, vf->BitsPerPixel); 7209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->SetColors(this, 0, vf->palette->ncolors, 7219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vf->palette->colors); 7229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 7239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Clear the surface to black */ 7259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->offset_x = 0; 7269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->offset_y = 0; 7279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode->offset = 0; 7289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetClipRect(mode, NULL); 7299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_ClearSurface(mode); 7309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Now adjust the offsets to match the desired mode */ 7329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->offset_x = (mode->w-width)/2; 7339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->offset_y = (mode->h-height)/2; 7349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode->offset = video->offset_y*mode->pitch + 7359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->offset_x*mode->format->BytesPerPixel; 7369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef DEBUG_VIDEO 7379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, 7389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall "Requested mode: %dx%dx%d, obtained mode %dx%dx%d (offset %d)\n", 7399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall width, height, bpp, 7409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode->w, mode->h, mode->format->BitsPerPixel, mode->offset); 7419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 7429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode->w = width; 7439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode->h = height; 7449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetClipRect(mode, NULL); 7459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 7469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_ResetCursor(); 7479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_UnlockCursor(); 7489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If we failed setting a video mode, return NULL... (Uh Oh!) */ 7509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( mode == NULL ) { 7519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 7529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 7539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If there is no window manager, set the SDL_NOFRAME flag */ 7559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ! video->info.wm_available ) { 7569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode->flags |= SDL_NOFRAME; 7579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 7589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Reset the mouse cursor and grab for new video mode */ 7609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetCursor(NULL); 7619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->UpdateMouse ) { 7629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->UpdateMouse(this); 7639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 7649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_WM_GrabInput(saved_grab); 7659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_GetRelativeMouseState(NULL, NULL); /* Clear first large delta */ 7669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_OPENGL 7689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Load GL symbols (before MakeCurrent, where we need glGetString). */ 7699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( flags & (SDL_OPENGL | SDL_OPENGLBLIT) ) { 7709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__QNXNTO__) && (_NTO_VERSION < 630) 7729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define __SDL_NOGETPROCADDR__ 7739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#elif defined(__MINT__) 7749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define __SDL_NOGETPROCADDR__ 7759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 7769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef __SDL_NOGETPROCADDR__ 7779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall #define SDL_PROC(ret,func,params) video->func=func; 7789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 7799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall #define SDL_PROC(ret,func,params) \ 7809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall do { \ 7819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->func = SDL_GL_GetProcAddress(#func); \ 7829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ! video->func ) { \ 7839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \ 7849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); \ 7859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } \ 7869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } while ( 0 ); 7879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* __SDL_NOGETPROCADDR__ */ 7899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_glfuncs.h" 7919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#undef SDL_PROC 7929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 7939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* SDL_VIDEO_OPENGL */ 7949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If we're running OpenGL, make the context current */ 7969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (video->screen->flags & SDL_OPENGL) && 7979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->GL_MakeCurrent ) { 7989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->GL_MakeCurrent(this) < 0 ) { 7999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 8009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 8019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 8029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 8039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Set up a fake SDL surface for OpenGL "blitting" */ 8049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (flags & SDL_OPENGLBLIT) == SDL_OPENGLBLIT ) { 8059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Load GL functions for performing the texture updates */ 8069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_OPENGL 8079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 8089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Create a software surface for blitting */ 8099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef GL_VERSION_1_2 8109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If the implementation either supports the packed pixels 8119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall extension, or implements the core OpenGL 1.2 API, it will 8129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall support the GL_UNSIGNED_SHORT_5_6_5 texture format. 8139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 8149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (bpp == 16) && 8159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (SDL_strstr((const char *)video->glGetString(GL_EXTENSIONS), "GL_EXT_packed_pixels") || 8169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (SDL_atof((const char *)video->glGetString(GL_VERSION)) >= 1.2f)) 8179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ) { 8189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->is_32bit = 0; 8199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoSurface = SDL_CreateRGBSurface( 8209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall flags, 8219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall width, 8229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall height, 8239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 16, 8249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 31 << 11, 8259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 63 << 5, 8269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 31, 8279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0 8289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ); 8299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 8309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else 8319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* OpenGL 1.2 */ 8329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 8339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->is_32bit = 1; 8349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoSurface = SDL_CreateRGBSurface( 8359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall flags, 8369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall width, 8379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall height, 8389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 32, 8399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_BYTEORDER == SDL_LIL_ENDIAN 8409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x000000FF, 8419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x0000FF00, 8429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x00FF0000, 8439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xFF000000 8449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 8459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0xFF000000, 8469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x00FF0000, 8479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x0000FF00, 8489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0x000000FF 8499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 8509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ); 8519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 8529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ! SDL_VideoSurface ) { 8539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 8549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 8559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoSurface->flags = mode->flags | SDL_OPENGLBLIT; 8569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 8579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Free the original video mode surface (is this safe?) */ 8589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_FreeSurface(mode); 8599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 8609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Set the surface completely opaque & white by default */ 8619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memset( SDL_VideoSurface->pixels, 255, SDL_VideoSurface->h * SDL_VideoSurface->pitch ); 8629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->glGenTextures( 1, &video->texture ); 8639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->glBindTexture( GL_TEXTURE_2D, video->texture ); 8649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->glTexImage2D( 8659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GL_TEXTURE_2D, 8669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0, 8679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->is_32bit ? GL_RGBA : GL_RGB, 8689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 256, 8699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 256, 8709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0, 8719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->is_32bit ? GL_RGBA : GL_RGB, 8729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef GL_VERSION_1_2 8739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->is_32bit ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT_5_6_5, 8749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 8759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GL_UNSIGNED_BYTE, 8769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 8779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall NULL); 8789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 8799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->UpdateRects = SDL_GL_UpdateRectsLock; 8809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 8819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Somebody forgot to #define SDL_VIDEO_OPENGL"); 8829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 8839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 8849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 8859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 8869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Create a shadow surface if necessary */ 8879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* There are three conditions under which we create a shadow surface: 8889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1. We need a particular bits-per-pixel that we didn't get. 8899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2. We need a hardware palette and didn't get one. 8909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3. We need a software surface and got a hardware surface. 8919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 8929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( !(SDL_VideoSurface->flags & SDL_OPENGL) && 8939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ( 8949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ( !(flags&SDL_ANYFORMAT) && 8959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (SDL_VideoSurface->format->BitsPerPixel != bpp)) || 8969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ( (flags&SDL_HWPALETTE) && 8979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall !(SDL_VideoSurface->flags&SDL_HWPALETTE)) || 8989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If the surface is in hardware, video writes are visible 8999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall as soon as they are performed, so we need to buffer them 9009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 9019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ( ((flags&SDL_HWSURFACE) == SDL_SWSURFACE) && 9029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (SDL_VideoSurface->flags&SDL_HWSURFACE)) || 9039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ( (flags&SDL_DOUBLEBUF) && 9049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (SDL_VideoSurface->flags&SDL_HWSURFACE) && 9059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall !(SDL_VideoSurface->flags&SDL_DOUBLEBUF)) 9069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ) ) { 9079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_CreateShadowSurface(bpp); 9089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_ShadowSurface == NULL ) { 9099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Couldn't create shadow surface"); 9109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 9119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 9129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PublicSurface = SDL_ShadowSurface; 9139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 9149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PublicSurface = SDL_VideoSurface; 9159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 9169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->info.vfmt = SDL_VideoSurface->format; 9179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->info.current_w = SDL_VideoSurface->w; 9189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->info.current_h = SDL_VideoSurface->h; 9199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 9209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* We're done! */ 9219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(SDL_PublicSurface); 9229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 9239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 9249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 9259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Convert a surface into the video pixel format. 9269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 9279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_Surface * SDL_DisplayFormat (SDL_Surface *surface) 9289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 9299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 flags; 9309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 9319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ! SDL_PublicSurface ) { 9329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("No video mode has been set"); 9339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 9349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 9359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Set the flags appropriate for copying to display surface */ 9369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (((SDL_PublicSurface->flags&SDL_HWSURFACE) == SDL_HWSURFACE) && current_video->info.blit_hw) 9379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall flags = SDL_HWSURFACE; 9389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else 9399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall flags = SDL_SWSURFACE; 9409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef AUTORLE_DISPLAYFORMAT 9419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall flags |= (surface->flags & (SDL_SRCCOLORKEY|SDL_SRCALPHA)); 9429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall flags |= SDL_RLEACCELOK; 9439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 9449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall flags |= surface->flags & (SDL_SRCCOLORKEY|SDL_SRCALPHA|SDL_RLEACCELOK); 9459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 9469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(SDL_ConvertSurface(surface, SDL_PublicSurface->format, flags)); 9479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 9489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 9499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 9509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Convert a surface into a format that's suitable for blitting to 9519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * the screen, but including an alpha channel. 9529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 9539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_Surface *SDL_DisplayFormatAlpha(SDL_Surface *surface) 9549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 9559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PixelFormat *vf; 9569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PixelFormat *format; 9579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Surface *converted; 9589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 flags; 9599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* default to ARGB8888 */ 9609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 amask = 0xff000000; 9619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 rmask = 0x00ff0000; 9629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 gmask = 0x0000ff00; 9639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 bmask = 0x000000ff; 9649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 9659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ! SDL_PublicSurface ) { 9669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("No video mode has been set"); 9679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 9689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 9699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vf = SDL_PublicSurface->format; 9709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 9719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall switch(vf->BytesPerPixel) { 9729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 2: 9739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* For XGY5[56]5, use, AXGY8888, where {X, Y} = {R, B}. 9749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall For anything else (like ARGB4444) it doesn't matter 9759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall since we have no special code for it anyway */ 9769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (vf->Rmask == 0x1f) && 9779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (vf->Bmask == 0xf800 || vf->Bmask == 0x7c00)) { 9789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rmask = 0xff; 9799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bmask = 0xff0000; 9809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 9819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 9829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 9839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 3: 9849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 4: 9859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Keep the video format, as long as the high 8 bits are 9869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unused or alpha */ 9879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (vf->Rmask == 0xff) && (vf->Bmask == 0xff0000) ) { 9889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rmask = 0xff; 9899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bmask = 0xff0000; 9909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else if ( vf->Rmask == 0xFF00 && (vf->Bmask == 0xFF000000) ) { 9919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall amask = 0x000000FF; 9929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rmask = 0x0000FF00; 9939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall gmask = 0x00FF0000; 9949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bmask = 0xFF000000; 9959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 9969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 9979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 9989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall default: 9999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* We have no other optimised formats right now. When/if a new 10009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall optimised alpha format is written, add the converter here */ 10019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 10029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format = SDL_AllocFormat(32, rmask, gmask, bmask, amask); 10049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall flags = SDL_PublicSurface->flags & SDL_HWSURFACE; 10059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall flags |= surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK); 10069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall converted = SDL_ConvertSurface(surface, format, flags); 10079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_FreeFormat(format); 10089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(converted); 10099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 10109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 10119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 10129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Update a specific portion of the physical screen 10139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 10149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_UpdateRect(SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h) 10159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 10169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( screen ) { 10179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Rect rect; 10189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 10199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Perform some checking */ 10209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( w == 0 ) 10219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall w = screen->w; 10229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( h == 0 ) 10239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall h = screen->h; 10249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (int)(x+w) > screen->w ) 10259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 10269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (int)(y+h) > screen->h ) 10279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 10289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 10299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Fill the rectangle */ 10309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.x = (Sint16)x; 10319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.y = (Sint16)y; 10329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.w = (Uint16)w; 10339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.h = (Uint16)h; 10349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_UpdateRects(screen, 1, &rect); 10359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 10379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_UpdateRects (SDL_Surface *screen, int numrects, SDL_Rect *rects) 10389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 10399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int i; 10409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *video = current_video; 10419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *this = current_video; 10429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 10439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (screen->flags & (SDL_OPENGL | SDL_OPENGLBLIT)) == SDL_OPENGL ) { 10449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("OpenGL active, use SDL_GL_SwapBuffers()"); 10459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 10469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( screen == SDL_ShadowSurface ) { 10489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Blit the shadow surface using saved mapping */ 10499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Palette *pal = screen->format->palette; 10509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Color *saved_colors = NULL; 10519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( pal && !(SDL_VideoSurface->flags & SDL_HWPALETTE) ) { 10529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* simulated 8bpp, use correct physical palette */ 10539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall saved_colors = pal->colors; 10549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->gammacols ) { 10559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* gamma-corrected palette */ 10569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pal->colors = video->gammacols; 10579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else if ( video->physpal ) { 10589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* physical palette different from logical */ 10599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pal->colors = video->physpal->colors; 10609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SHOULD_DRAWCURSOR(SDL_cursorstate) ) { 10639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_LockCursor(); 10649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_DrawCursor(SDL_ShadowSurface); 10659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( i=0; i<numrects; ++i ) { 10669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_LowerBlit(SDL_ShadowSurface, &rects[i], 10679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoSurface, &rects[i]); 10689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_EraseCursor(SDL_ShadowSurface); 10709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_UnlockCursor(); 10719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 10729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( i=0; i<numrects; ++i ) { 10739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_LowerBlit(SDL_ShadowSurface, &rects[i], 10749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoSurface, &rects[i]); 10759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( saved_colors ) { 10789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pal->colors = saved_colors; 10799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 10819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Fall through to video surface update */ 10829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall screen = SDL_VideoSurface; 10839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( screen == SDL_VideoSurface ) { 10859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Update the video surface */ 10869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( screen->offset ) { 10879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( i=0; i<numrects; ++i ) { 10889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rects[i].x += video->offset_x; 10899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rects[i].y += video->offset_y; 10909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->UpdateRects(this, numrects, rects); 10929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( i=0; i<numrects; ++i ) { 10939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rects[i].x -= video->offset_x; 10949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rects[i].y -= video->offset_y; 10959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 10979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->UpdateRects(this, numrects, rects); 10989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 11009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 11019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 11029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 11039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Performs hardware double buffering, if possible, or a full update if not. 11049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 11059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_Flip(SDL_Surface *screen) 11069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 11079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *video = current_video; 11089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Copy the shadow surface to the video surface */ 11099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( screen == SDL_ShadowSurface ) { 11109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Rect rect; 11119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Palette *pal = screen->format->palette; 11129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Color *saved_colors = NULL; 11139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( pal && !(SDL_VideoSurface->flags & SDL_HWPALETTE) ) { 11149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* simulated 8bpp, use correct physical palette */ 11159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall saved_colors = pal->colors; 11169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->gammacols ) { 11179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* gamma-corrected palette */ 11189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pal->colors = video->gammacols; 11199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else if ( video->physpal ) { 11209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* physical palette different from logical */ 11219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pal->colors = video->physpal->colors; 11229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 11239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 11249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 11259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.x = 0; 11269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.y = 0; 11279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.w = screen->w; 11289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.h = screen->h; 11299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SHOULD_DRAWCURSOR(SDL_cursorstate) ) { 11309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_LockCursor(); 11319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_DrawCursor(SDL_ShadowSurface); 11329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_LowerBlit(SDL_ShadowSurface, &rect, 11339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoSurface, &rect); 11349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_EraseCursor(SDL_ShadowSurface); 11359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_UnlockCursor(); 11369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 11379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_LowerBlit(SDL_ShadowSurface, &rect, 11389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoSurface, &rect); 11399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 11409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( saved_colors ) { 11419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pal->colors = saved_colors; 11429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 11439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 11449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Fall through to video surface update */ 11459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall screen = SDL_VideoSurface; 11469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 11479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) { 11489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *this = current_video; 11499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(video->FlipHWSurface(this, SDL_VideoSurface)); 11509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 11519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_UpdateRect(screen, 0, 0, 0, 0); 11529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 11539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 11549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 11559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 11569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void SetPalette_logical(SDL_Surface *screen, SDL_Color *colors, 11579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int firstcolor, int ncolors) 11589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 11599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Palette *pal = screen->format->palette; 11609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Palette *vidpal; 11619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 11629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( colors != (pal->colors + firstcolor) ) { 11639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memcpy(pal->colors + firstcolor, colors, 11649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ncolors * sizeof(*colors)); 11659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 11669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 11679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( current_video && SDL_VideoSurface ) { 11689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vidpal = SDL_VideoSurface->format->palette; 11699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (screen == SDL_ShadowSurface) && vidpal ) { 11709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 11719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * This is a shadow surface, and the physical 11729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * framebuffer is also indexed. Propagate the 11739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * changes to its logical palette so that 11749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * updates are always identity blits 11759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 11769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memcpy(vidpal->colors + firstcolor, colors, 11779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ncolors * sizeof(*colors)); 11789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 11799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 11809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_FormatChanged(screen); 11819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 11829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 11839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SetPalette_physical(SDL_Surface *screen, 11849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Color *colors, int firstcolor, int ncolors) 11859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 11869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *video = current_video; 11879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int gotall = 1; 11889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 11899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->physpal ) { 11909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* We need to copy the new colors, since we haven't 11919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * already done the copy in the logical set above. 11929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 11939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memcpy(video->physpal->colors + firstcolor, 11949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall colors, ncolors * sizeof(*colors)); 11959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 11969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( screen == SDL_ShadowSurface ) { 11979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_VideoSurface->flags & SDL_HWPALETTE ) { 11989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 11999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * The real screen is also indexed - set its physical 12009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * palette. The physical palette does not include the 12019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * gamma modification, we apply it directly instead, 12029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * but this only happens if we have hardware palette. 12039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 12049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall screen = SDL_VideoSurface; 12059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 12069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 12079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * The video surface is not indexed - invalidate any 12089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * active shadow-to-video blit mappings. 12099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 12109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( screen->map->dst == SDL_VideoSurface ) { 12119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_InvalidateMap(screen->map); 12129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->gamma ) { 12149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if( ! video->gammacols ) { 12159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Palette *pp = video->physpal; 12169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(!pp) 12179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pp = screen->format->palette; 12189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gammacols = SDL_malloc(pp->ncolors 12199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * sizeof(SDL_Color)); 12209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_ApplyGamma(video->gamma, 12219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pp->colors, 12229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gammacols, 12239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pp->ncolors); 12249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 12259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_ApplyGamma(video->gamma, colors, 12269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gammacols 12279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall + firstcolor, 12289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ncolors); 12299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_UpdateRect(screen, 0, 0, 0, 0); 12329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 12359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( screen == SDL_VideoSurface ) { 12369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Color gcolors[256]; 12379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 12389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->gamma ) { 12399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_ApplyGamma(video->gamma, colors, gcolors, ncolors); 12409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall colors = gcolors; 12419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall gotall = video->SetColors(video, firstcolor, ncolors, colors); 12439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ! gotall ) { 12449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* The video flags shouldn't have SDL_HWPALETTE, and 12459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall the video driver is responsible for copying back the 12469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall correct colors into the video surface palette. 12479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 12489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ; 12499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_CursorPaletteChanged(); 12519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return gotall; 12539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 12549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 12559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 12569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Set the physical and/or logical colormap of a surface: 12579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Only the screen has a physical colormap. It determines what is actually 12589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * sent to the display. 12599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * The logical colormap is used to map blits to/from the surface. 12609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 'which' is one or both of SDL_LOGPAL, SDL_PHYSPAL 12619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 12629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Return nonzero if all colours were set as requested, or 0 otherwise. 12639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 12649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_SetPalette(SDL_Surface *screen, int which, 12659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Color *colors, int firstcolor, int ncolors) 12669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 12679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Palette *pal; 12689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int gotall; 12699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int palsize; 12709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 12719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( !screen ) { 12729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return 0; 12739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( !current_video || screen != SDL_PublicSurface ) { 12759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* only screens have physical palettes */ 12769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall which &= ~SDL_PHYSPAL; 12779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else if ( (screen->flags & SDL_HWPALETTE) != SDL_HWPALETTE ) { 12789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* hardware palettes required for split colormaps */ 12799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall which |= SDL_PHYSPAL | SDL_LOGPAL; 12809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 12829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Verify the parameters */ 12839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pal = screen->format->palette; 12849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if( !pal ) { 12859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return 0; /* not a palettized surface */ 12869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall gotall = 1; 12889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall palsize = 1 << screen->format->BitsPerPixel; 12899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ncolors > (palsize - firstcolor) ) { 12909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ncolors = (palsize - firstcolor); 12919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall gotall = 0; 12929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 12949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( which & SDL_LOGPAL ) { 12959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 12969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Logical palette change: The actual screen isn't affected, 12979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * but the internal colormap is altered so that the 12989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * interpretation of the pixel values (for blits etc) is 12999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * changed. 13009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 13019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SetPalette_logical(screen, colors, firstcolor, ncolors); 13029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 13039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( which & SDL_PHYSPAL ) { 13049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *video = current_video; 13059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 13069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Physical palette change: This doesn't affect the 13079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * program's idea of what the screen looks like, but changes 13089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * its actual appearance. 13099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 13109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( !video->physpal && !(which & SDL_LOGPAL) ) { 13119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Lazy physical palette allocation */ 13129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int size; 13139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Palette *pp = SDL_malloc(sizeof(*pp)); 13149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( !pp ) { 13159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return 0; 13169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 13179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->physpal = pp; 13189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pp->ncolors = pal->ncolors; 13199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall size = pp->ncolors * sizeof(SDL_Color); 13209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pp->colors = SDL_malloc(size); 13219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( !pp->colors ) { 13229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return 0; 13239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 13249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memcpy(pp->colors, pal->colors, size); 13259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 13269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ! SetPalette_physical(screen, 13279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall colors, firstcolor, ncolors) ) { 13289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall gotall = 0; 13299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 13309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 13319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return gotall; 13329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 13339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 13349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_SetColors(SDL_Surface *screen, SDL_Color *colors, int firstcolor, 13359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int ncolors) 13369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 13379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return SDL_SetPalette(screen, SDL_LOGPAL | SDL_PHYSPAL, 13389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall colors, firstcolor, ncolors); 13399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 13409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 13419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 13429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Clean up the video subsystem 13439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 13449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_VideoQuit (void) 13459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 13469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Surface *ready_to_go; 13479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 13489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( current_video ) { 13499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *video = current_video; 13509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *this = current_video; 13519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 13529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Halt event processing before doing anything else */ 13539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_StopEventLoop(); 13549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 13559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Clean up allocated window manager items */ 13569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_PublicSurface ) { 13579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PublicSurface = NULL; 13589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 13599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_CursorQuit(); 13609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 13619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Just in case... */ 13629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_WM_GrabInputOff(); 13639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 13649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Clean up the system video */ 13659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->VideoQuit(this); 13669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 13679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Free any lingering surfaces */ 13689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ready_to_go = SDL_ShadowSurface; 13699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_ShadowSurface = NULL; 13709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_FreeSurface(ready_to_go); 13719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_VideoSurface != NULL ) { 13729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ready_to_go = SDL_VideoSurface; 13739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoSurface = NULL; 13749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_FreeSurface(ready_to_go); 13759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 13769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PublicSurface = NULL; 13779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 13789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Clean up miscellaneous memory */ 13799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->physpal ) { 13809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(video->physpal->colors); 13819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(video->physpal); 13829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->physpal = NULL; 13839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 13849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->gammacols ) { 13859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(video->gammacols); 13869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gammacols = NULL; 13879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 13889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->gamma ) { 13899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(video->gamma); 13909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gamma = NULL; 13919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 13929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->wm_title != NULL ) { 13939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(video->wm_title); 13949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->wm_title = NULL; 13959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 13969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->wm_icon != NULL ) { 13979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(video->wm_icon); 13989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->wm_icon = NULL; 13999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 14009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 14019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Finish cleaning up video subsystem */ 14029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->free(this); 14039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current_video = NULL; 14049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 14059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 14069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 14079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 14089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Load the GL driver library */ 14099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_GL_LoadLibrary(const char *path) 14109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 14119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *video = current_video; 14129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *this = current_video; 14139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int retval; 14149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 14159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall retval = -1; 14169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video == NULL ) { 14179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Video subsystem has not been initialized"); 14189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 14199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->GL_LoadLibrary ) { 14209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall retval = video->GL_LoadLibrary(this, path); 14219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 14229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("No dynamic GL support in video driver"); 14239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 14249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 14259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(retval); 14269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 14279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 14289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid *SDL_GL_GetProcAddress(const char* proc) 14299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 14309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *video = current_video; 14319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *this = current_video; 14329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void *func; 14339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 14349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall func = NULL; 14359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->GL_GetProcAddress ) { 14369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->gl_config.driver_loaded ) { 14379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall func = video->GL_GetProcAddress(this, proc); 14389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 14399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("No GL driver has been loaded"); 14409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 14419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 14429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("No dynamic GL support in video driver"); 14439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 14449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return func; 14459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 14469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 14479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Set the specified GL attribute for setting up a GL video mode */ 14489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_GL_SetAttribute( SDL_GLattr attr, int value ) 14499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 14509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int retval; 14519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *video = current_video; 14529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 14539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall retval = 0; 14549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall switch (attr) { 14559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_GL_RED_SIZE: 14569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.red_size = value; 14579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 14589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_GL_GREEN_SIZE: 14599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.green_size = value; 14609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 14619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_GL_BLUE_SIZE: 14629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.blue_size = value; 14639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 14649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_GL_ALPHA_SIZE: 14659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.alpha_size = value; 14669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 14679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_GL_DOUBLEBUFFER: 14689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.double_buffer = value; 14699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 14709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_GL_BUFFER_SIZE: 14719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.buffer_size = value; 14729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 14739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_GL_DEPTH_SIZE: 14749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.depth_size = value; 14759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 14769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_GL_STENCIL_SIZE: 14779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.stencil_size = value; 14789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 14799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_GL_ACCUM_RED_SIZE: 14809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.accum_red_size = value; 14819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 14829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_GL_ACCUM_GREEN_SIZE: 14839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.accum_green_size = value; 14849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 14859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_GL_ACCUM_BLUE_SIZE: 14869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.accum_blue_size = value; 14879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 14889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_GL_ACCUM_ALPHA_SIZE: 14899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.accum_alpha_size = value; 14909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 14919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_GL_STEREO: 14929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.stereo = value; 14939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 14949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_GL_MULTISAMPLEBUFFERS: 14959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.multisamplebuffers = value; 14969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 14979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_GL_MULTISAMPLESAMPLES: 14989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.multisamplesamples = value; 14999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 15009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_GL_ACCELERATED_VISUAL: 15019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.accelerated = value; 15029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 15039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_GL_SWAP_CONTROL: 15049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->gl_config.swap_control = value; 15059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 15069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall default: 15079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Unknown OpenGL attribute"); 15089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall retval = -1; 15099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 15109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 15119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(retval); 15129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 15139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 15149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Retrieve an attribute value from the windowing system. */ 15159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_GL_GetAttribute(SDL_GLattr attr, int* value) 15169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 15179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int retval = -1; 15189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice* video = current_video; 15199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice* this = current_video; 15209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 15219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->GL_GetAttribute ) { 15229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall retval = this->GL_GetAttribute(this, attr, value); 15239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 15249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *value = 0; 15259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("GL_GetAttribute not supported"); 15269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 15279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return retval; 15289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 15299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 15309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Perform a GL buffer swap on the current GL context */ 15319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_GL_SwapBuffers(void) 15329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 15339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *video = current_video; 15349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *this = current_video; 15359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 15369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->screen->flags & SDL_OPENGL ) { 15379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->GL_SwapBuffers(this); 15389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 15399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("OpenGL video mode has not been set"); 15409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 15419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 15429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 15439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Update rects with locking */ 15449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_GL_UpdateRectsLock(SDL_VideoDevice* this, int numrects, SDL_Rect *rects) 15459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 15469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_GL_Lock(); 15479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_GL_UpdateRects(numrects, rects); 15489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_GL_Unlock(); 15499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 15509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 15519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Update rects without state setting and changing (the caller is responsible for it) */ 15529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_GL_UpdateRects(int numrects, SDL_Rect *rects) 15539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 15549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_OPENGL 15559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *this = current_video; 15569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Rect update, tmp; 15579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int x, y, i; 15589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 15599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( i = 0; i < numrects; i++ ) 15609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 15619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall tmp.y = rects[i].y; 15629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall tmp.h = rects[i].h; 15639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( y = 0; y <= rects[i].h / 256; y++ ) 15649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 15659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall tmp.x = rects[i].x; 15669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall tmp.w = rects[i].w; 15679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( x = 0; x <= rects[i].w / 256; x++ ) 15689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 15699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall update.x = tmp.x; 15709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall update.y = tmp.y; 15719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall update.w = tmp.w; 15729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall update.h = tmp.h; 15739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 15749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( update.w > 256 ) 15759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall update.w = 256; 15769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 15779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( update.h > 256 ) 15789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall update.h = 256; 15799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 15809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glFlush(); 15819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glTexSubImage2D( 15829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GL_TEXTURE_2D, 15839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0, 15849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0, 15859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 0, 15869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall update.w, 15879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall update.h, 15889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->is_32bit? GL_RGBA : GL_RGB, 15899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef GL_VERSION_1_2 15909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->is_32bit ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT_5_6_5, 15919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 15929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GL_UNSIGNED_BYTE, 15939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 15949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (Uint8 *)this->screen->pixels + 15959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->screen->format->BytesPerPixel * update.x + 15969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall update.y * this->screen->pitch ); 15979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 15989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glFlush(); 15999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 16009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Note the parens around the function name: 16019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * This is because some OpenGL implementations define glTexCoord etc 16029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * as macros, and we don't want them expanded here. 16039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 16049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glBegin(GL_TRIANGLE_STRIP); 16059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (this->glTexCoord2f)( 0.0, 0.0 ); 16069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (this->glVertex2i)( update.x, update.y ); 16079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (this->glTexCoord2f)( (float)(update.w / 256.0), 0.0 ); 16089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (this->glVertex2i)( update.x + update.w, update.y ); 16099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (this->glTexCoord2f)( 0.0, (float)(update.h / 256.0) ); 16109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (this->glVertex2i)( update.x, update.y + update.h ); 16119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (this->glTexCoord2f)( (float)(update.w / 256.0), (float)(update.h / 256.0) ); 16129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (this->glVertex2i)( update.x + update.w , update.y + update.h ); 16139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glEnd(); 16149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 16159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall tmp.x += 256; 16169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall tmp.w -= 256; 16179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 16189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall tmp.y += 256; 16199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall tmp.h -= 256; 16209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 16219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 16229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 16239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 16249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 16259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Lock == save current state */ 16269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_GL_Lock() 16279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 16289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_OPENGL 16299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lock_count--; 16309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (lock_count==-1) 16319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 16329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *this = current_video; 16339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 16349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glPushAttrib( GL_ALL_ATTRIB_BITS ); /* TODO: narrow range of what is saved */ 16359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef GL_CLIENT_PIXEL_STORE_BIT 16369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT ); 16379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 16389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 16399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glEnable(GL_TEXTURE_2D); 16409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glEnable(GL_BLEND); 16419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glDisable(GL_FOG); 16429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glDisable(GL_ALPHA_TEST); 16439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glDisable(GL_DEPTH_TEST); 16449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glDisable(GL_SCISSOR_TEST); 16459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glDisable(GL_STENCIL_TEST); 16469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glDisable(GL_CULL_FACE); 16479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 16489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glBindTexture( GL_TEXTURE_2D, this->texture ); 16499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); 16509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); 16519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); 16529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); 16539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); 16549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 16559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glPixelStorei( GL_UNPACK_ROW_LENGTH, this->screen->pitch / this->screen->format->BytesPerPixel ); 16569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 16579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (this->glColor4f)(1.0, 1.0, 1.0, 1.0); /* Solaris workaround */ 16589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 16599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glViewport(0, 0, this->screen->w, this->screen->h); 16609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glMatrixMode(GL_PROJECTION); 16619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glPushMatrix(); 16629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glLoadIdentity(); 16639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 16649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glOrtho(0.0, (GLdouble) this->screen->w, (GLdouble) this->screen->h, 0.0, 0.0, 1.0); 16659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 16669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glMatrixMode(GL_MODELVIEW); 16679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glPushMatrix(); 16689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glLoadIdentity(); 16699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 16709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 16719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 16729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 16739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Unlock == restore saved state */ 16749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_GL_Unlock() 16759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 16769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_OPENGL 16779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lock_count++; 16789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (lock_count==0) 16799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 16809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *this = current_video; 16819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 16829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glPopMatrix(); 16839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glMatrixMode(GL_PROJECTION); 16849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glPopMatrix(); 16859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 16869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glPopClientAttrib(); 16879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->glPopAttrib(); 16889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 16899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 16909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 16919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 16923cee084cdc822249fd535b6c02c7112f63848c4dJesse Hall#if SDL_AUDIO_DRIVER_PULSE 16939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_Audio_SetCaption(const char *caption); 16943cee084cdc822249fd535b6c02c7112f63848c4dJesse Hall#endif 16959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 16969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 16979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Sets/Gets the title and icon text of the display window, if any. 16989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 16999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_WM_SetCaption (const char *title, const char *icon) 17009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 17019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *video = current_video; 17029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *this = current_video; 17039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 17049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video ) { 17059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( title ) { 17069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->wm_title ) { 17079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(video->wm_title); 17089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->wm_title = SDL_strdup(title); 17109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( icon ) { 17129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->wm_icon ) { 17139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(video->wm_icon); 17149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->wm_icon = SDL_strdup(icon); 17169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (title || icon) && (video->SetCaption != NULL) ) { 17189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->SetCaption(this, video->wm_title,video->wm_icon); 17199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 17223cee084cdc822249fd535b6c02c7112f63848c4dJesse Hall#if SDL_AUDIO_DRIVER_PULSE 17239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* PulseAudio can make use of this information. */ 17249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Audio_SetCaption(title); 17253cee084cdc822249fd535b6c02c7112f63848c4dJesse Hall#endif 17269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 17279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 17289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_WM_GetCaption (char **title, char **icon) 17299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 17309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *video = current_video; 17319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 17329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video ) { 17339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( title ) { 17349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *title = video->wm_title; 17359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( icon ) { 17379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *icon = video->wm_icon; 17389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 17419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 17429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Utility function used by SDL_WM_SetIcon(); 17439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * flags & 1 for color key, flags & 2 for alpha channel. */ 17449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void CreateMaskFromColorKeyOrAlpha(SDL_Surface *icon, Uint8 *mask, int flags) 17459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 17469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int x, y; 17479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 colorkey; 17489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define SET_MASKBIT(icon, x, y, mask) \ 17499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8))) 17509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 17519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall colorkey = icon->format->colorkey; 17529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall switch (icon->format->BytesPerPixel) { 17539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 1: { Uint8 *pixels; 17549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( y=0; y<icon->h; ++y ) { 17559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pixels = (Uint8 *)icon->pixels + y*icon->pitch; 17569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( x=0; x<icon->w; ++x ) { 17579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( *pixels++ == colorkey ) { 17589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SET_MASKBIT(icon, x, y, mask); 17599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 17649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 17659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 2: { Uint16 *pixels; 17669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( y=0; y<icon->h; ++y ) { 17679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pixels = (Uint16 *)icon->pixels + 17689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall y*icon->pitch/2; 17699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( x=0; x<icon->w; ++x ) { 17709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (flags & 1) && *pixels == colorkey ) { 17719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SET_MASKBIT(icon, x, y, mask); 17729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else if((flags & 2) && (*pixels & icon->format->Amask) == 0) { 17739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SET_MASKBIT(icon, x, y, mask); 17749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pixels++; 17769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 17809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 17819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 4: { Uint32 *pixels; 17829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( y=0; y<icon->h; ++y ) { 17839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pixels = (Uint32 *)icon->pixels + 17849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall y*icon->pitch/4; 17859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( x=0; x<icon->w; ++x ) { 17869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (flags & 1) && *pixels == colorkey ) { 17879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SET_MASKBIT(icon, x, y, mask); 17889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else if((flags & 2) && (*pixels & icon->format->Amask) == 0) { 17899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SET_MASKBIT(icon, x, y, mask); 17909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pixels++; 17929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 17969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 17979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 17989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 17999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 18009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Sets the window manager icon for the display window. 18019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 18029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_WM_SetIcon (SDL_Surface *icon, Uint8 *mask) 18039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 18049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *video = current_video; 18059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *this = current_video; 18069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 18079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( icon && video->SetIcon ) { 18089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Generate a mask if necessary, and create the icon! */ 18099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( mask == NULL ) { 18109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int mask_len = icon->h*(icon->w+7)/8; 18119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int flags = 0; 18129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mask = (Uint8 *)SDL_malloc(mask_len); 18139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( mask == NULL ) { 18149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 18159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 18169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memset(mask, ~0, mask_len); 18179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( icon->flags & SDL_SRCCOLORKEY ) flags |= 1; 18189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( icon->flags & SDL_SRCALPHA ) flags |= 2; 18199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if( flags ) { 18209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall CreateMaskFromColorKeyOrAlpha(icon, mask, flags); 18219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 18229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->SetIcon(video, icon, mask); 18239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(mask); 18249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 18259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->SetIcon(this, icon, mask); 18269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 18279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 18289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 18299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 18309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 18319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Grab or ungrab the keyboard and mouse input. 18329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * This function returns the final grab mode after calling the 18339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * driver dependent function. 18349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 18359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic SDL_GrabMode SDL_WM_GrabInputRaw(SDL_GrabMode mode) 18369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 18379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *video = current_video; 18389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *this = current_video; 18399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 18409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Only do something if we have support for grabs */ 18419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->GrabInput == NULL ) { 18429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(video->input_grab); 18439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 18449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 18459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If the final grab mode if off, only then do we actually grab */ 18469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef DEBUG_GRAB 18479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall printf("SDL_WM_GrabInputRaw(%d) ... ", mode); 18489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 18499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( mode == SDL_GRAB_OFF ) { 18509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->input_grab != SDL_GRAB_OFF ) { 18519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode = video->GrabInput(this, mode); 18529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 18539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 18549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->input_grab == SDL_GRAB_OFF ) { 18559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode = video->GrabInput(this, mode); 18569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 18579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 18589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( mode != video->input_grab ) { 18599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->input_grab = mode; 18609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->CheckMouseMode ) { 18619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->CheckMouseMode(this); 18629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 18639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 18649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef DEBUG_GRAB 18659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall printf("Final mode %d\n", video->input_grab); 18669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 18679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 18689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Return the final grab state */ 18699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( mode >= SDL_GRAB_FULLSCREEN ) { 18709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode -= SDL_GRAB_FULLSCREEN; 18719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 18729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(mode); 18739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 18749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode) 18759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 18769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *video = current_video; 18779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 18789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If the video isn't initialized yet, we can't do anything */ 18799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ! video ) { 18809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return SDL_GRAB_OFF; 18819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 18829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 18839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Return the current mode on query */ 18849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( mode == SDL_GRAB_QUERY ) { 18859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode = video->input_grab; 18869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( mode >= SDL_GRAB_FULLSCREEN ) { 18879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode -= SDL_GRAB_FULLSCREEN; 18889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 18899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(mode); 18909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 18919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 18929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef DEBUG_GRAB 18939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall printf("SDL_WM_GrabInput(%d) ... ", mode); 18949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 18959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If the video surface is fullscreen, we always grab */ 18969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( mode >= SDL_GRAB_FULLSCREEN ) { 18979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode -= SDL_GRAB_FULLSCREEN; 18989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 18999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_VideoSurface && (SDL_VideoSurface->flags & SDL_FULLSCREEN) ) { 19009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode += SDL_GRAB_FULLSCREEN; 19019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 19029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(SDL_WM_GrabInputRaw(mode)); 19039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 19049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic SDL_GrabMode SDL_WM_GrabInputOff(void) 19059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 19069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_GrabMode mode; 19079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 19089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* First query the current grab state */ 19099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mode = SDL_WM_GrabInput(SDL_GRAB_QUERY); 19109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 19119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Now explicitly turn off input grab */ 19129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_WM_GrabInputRaw(SDL_GRAB_OFF); 19139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 19149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Return the old state */ 19159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(mode); 19169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 19179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 19189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 19199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Iconify the window in window managed environments. 19209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * A successful iconification will result in an SDL_APPACTIVE loss event. 19219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 19229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_WM_IconifyWindow(void) 19239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 19249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *video = current_video; 19259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *this = current_video; 19269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int retval; 19279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 19289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall retval = 0; 19299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video->IconifyWindow ) { 19309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall retval = video->IconifyWindow(this); 19319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 19329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(retval); 19339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 19349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 19359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 19369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Toggle fullscreen mode 19379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 19389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_WM_ToggleFullScreen(SDL_Surface *surface) 19399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 19409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *video = current_video; 19419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *this = current_video; 19429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int toggled; 19439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 19449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall toggled = 0; 19459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_PublicSurface && (surface == SDL_PublicSurface) && 19469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video->ToggleFullScreen ) { 19479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( surface->flags & SDL_FULLSCREEN ) { 19489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall toggled = video->ToggleFullScreen(this, 0); 19499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( toggled ) { 19509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoSurface->flags &= ~SDL_FULLSCREEN; 19519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PublicSurface->flags &= ~SDL_FULLSCREEN; 19529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 19539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 19549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall toggled = video->ToggleFullScreen(this, 1); 19559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( toggled ) { 19569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoSurface->flags |= SDL_FULLSCREEN; 19579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PublicSurface->flags |= SDL_FULLSCREEN; 19589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 19599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 19609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Double-check the grab state inside SDL_WM_GrabInput() */ 19619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( toggled ) { 19629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_WM_GrabInput(video->input_grab); 19639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 19649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 19659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(toggled); 19669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 19679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 19689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 1969e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall * Set window position 1970e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall */ 1971e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hallvoid SDL_WM_SetPos(int x, int y) 1972e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall{ 1973e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall SDL_VideoDevice* video = current_video; 1974e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall 1975e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall if (video && video->SetWindowPos) 1976e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall video->SetWindowPos(video, x, y); 1977e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall} 1978e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall 1979e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall/* 1980e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall * Get window position 1981e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall */ 1982e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hallvoid SDL_WM_GetPos(int *px, int *py) 1983e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall{ 1984e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall SDL_VideoDevice* video = current_video; 1985e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall 1986e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall if (video && video->GetWindowPos) 1987e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall video->GetWindowPos(video, px, py); 1988e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall else { 1989e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall *px = 100; 1990e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall *py = 100; 1991e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall } 1992e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall} 1993e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall 1994e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hallint SDL_WM_IsFullyVisible( int recenter ) 1995e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall{ 1996e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall int result = 1; 1997e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall 1998e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall SDL_VideoDevice* video = current_video; 1999e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall 2000e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall if (video && video->IsWindowVisible) { 2001e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall result = video->IsWindowVisible(video, recenter); 2002e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall } 2003e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall return result; 2004e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall} 2005e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall 2006e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hallint SDL_WM_GetMonitorDPI( int *xDpi, int *yDpi ) 2007e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall{ 2008e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall int result = -1; 2009e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall SDL_VideoDevice* video = current_video; 2010e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall 2011e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall if (video && video->GetMonitorDPI) { 2012e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall result = video->GetMonitorDPI(video, xDpi, yDpi); 2013e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall } 2014e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall return result; 2015e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall} 2016e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall 2017e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hallint SDL_WM_GetMonitorRect( SDL_Rect *rect ) 2018e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall{ 2019e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall int result = -1; 2020e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall SDL_VideoDevice* video = current_video; 2021e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall 2022e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall if (video && video->GetMonitorRect) { 2023e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall result = video->GetMonitorRect(video, rect); 2024e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall } 2025e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall return result; 2026e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall} 2027e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall 2028e4c5d95ed37611acc6a186522315195b4ebfb9efJesse Hall/* 20299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Get some platform dependent window manager information 20309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 20319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_GetWMInfo (SDL_SysWMinfo *info) 20329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 20339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *video = current_video; 20349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice *this = current_video; 20359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 20369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( video && video->GetWMInfo ) { 20379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(video->GetWMInfo(this, info)); 20389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 20399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 20409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 20419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2042