19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL - Simple DirectMedia Layer 39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Copyright (C) 1997-2012 Sam Lantinga 49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Copyright (C) 2001 Hsieh-Fu Tsai 59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Copyright (C) 2002 Greg Haerr <greg@censoft.com> 69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is free software; you can redistribute it and/or 89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall modify it under the terms of the GNU Library General Public 99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License as published by the Free Software Foundation; either 109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall version 2 of the License, or (at your option) any later version. 119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is distributed in the hope that it will be useful, 139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall but WITHOUT ANY WARRANTY; without even the implied warranty of 149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Library General Public License for more details. 169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall You should have received a copy of the GNU Library General Public 189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License along with this library; if not, write to the Free 199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Sam Lantinga 229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall slouken@libsdl.org 239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Hsieh-Fu Tsai 259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall clare@setabox.com 269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/ 279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h" 289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_thread.h" 309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_video.h" 319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../SDL_pixels_c.h" 329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../../events/SDL_events_c.h" 339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define MWINCLUDECOLORS 359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_nxvideo.h" 369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_nxmodes_c.h" 379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_nxwm_c.h" 389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_nxmouse_c.h" 399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_nximage_c.h" 409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_nxevents_c.h" 419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall// Initialization/Query functions 439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int NX_VideoInit (_THIS, SDL_PixelFormat * vformat) ; 449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic SDL_Surface * NX_SetVideoMode (_THIS, SDL_Surface * current, int width, int height, int bpp, Uint32 flags) ; 459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int NX_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) ; 469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void NX_VideoQuit (_THIS) ; 479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void NX_DestroyWindow (_THIS, SDL_Surface * screen) ; 489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int NX_ToggleFullScreen (_THIS, int on) ; 499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void NX_UpdateMouse (_THIS) ; 509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int NX_SetGammaRamp (_THIS, Uint16 * ramp) ; 519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int NX_GetGammaRamp (_THIS, Uint16 * ramp) ; 529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall// Microwin driver bootstrap functions 549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int NX_Available () 559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("enter NX_Available\n") ; 579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (GrOpen () < 0) return 0 ; 599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GrClose () ; 609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("leave NX_Available\n") ; 629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return 1 ; 639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void NX_DeleteDevice (SDL_VideoDevice * device) 669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("enter NX_DeleteDevice\n") ; 689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (device) { 709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (device -> hidden) SDL_free (device -> hidden) ; 719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (device -> gl_data) SDL_free (device -> gl_data) ; 729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free (device) ; 739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("leave NX_DeleteDevice\n") ; 769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic SDL_VideoDevice * NX_CreateDevice (int devindex) 799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_VideoDevice * device ; 819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("enter NX_CreateDevice\n") ; 839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Initialize all variables that we clean on shutdown 859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)) ; 869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (device) { 879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memset (device, 0, (sizeof * device)) ; 889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> hidden = (struct SDL_PrivateVideoData *) 899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_malloc ((sizeof * device -> hidden)) ; 909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> gl_data = NULL ; 919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ((device == NULL) || (device -> hidden == NULL)) { 939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_OutOfMemory () ; 949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall NX_DeleteDevice (device) ; 959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return 0 ; 969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memset (device -> hidden, 0, (sizeof * device -> hidden)) ; 989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Set the function pointers 1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> VideoInit = NX_VideoInit ; 1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> ListModes = NX_ListModes ; 1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> SetVideoMode = NX_SetVideoMode ; 1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> ToggleFullScreen = NX_ToggleFullScreen ; 1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> UpdateMouse = NX_UpdateMouse ; 1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> CreateYUVOverlay = NULL ; 1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> SetColors = NX_SetColors ; 1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> UpdateRects = NULL ; 1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> VideoQuit = NX_VideoQuit; 1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> AllocHWSurface = NULL ; 1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> CheckHWBlit = NULL ; 1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> FillHWRect = NULL ; 1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> SetHWColorKey = NULL ; 1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> SetHWAlpha = NULL ; 1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> LockHWSurface = NULL ; 1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> UnlockHWSurface = NULL ; 1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> FlipHWSurface = NULL ; 1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> FreeHWSurface = NULL ; 1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> SetGamma = NULL ; 1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> GetGamma = NULL ; 1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> SetGammaRamp = NX_SetGammaRamp ; 1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> GetGammaRamp = NX_GetGammaRamp ; 1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_OPENGL 1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> GL_LoadLibrary = NULL ; 1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> GL_GetProcAddress = NULL ; 1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> GL_GetAttribute = NULL ; 1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> GL_MakeCurrent = NULL ; 1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> GL_SwapBuffers = NULL ; 1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> SetIcon = NULL ; 1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> SetCaption = NX_SetCaption; 1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> IconifyWindow = NULL ; 1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> GrabInput = NULL ; 1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> GetWMInfo = NX_GetWMInfo ; 1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> FreeWMCursor = NX_FreeWMCursor ; 1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> CreateWMCursor = NX_CreateWMCursor ; 1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> ShowWMCursor = NX_ShowWMCursor ; 1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> WarpWMCursor = NX_WarpWMCursor ; 1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> CheckMouseMode = NULL ; 1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> InitOSKeymap = NX_InitOSKeymap ; 1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> PumpEvents = NX_PumpEvents ; 1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device -> free = NX_DeleteDevice ; 1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("leave NX_CreateDevice\n") ; 1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return device ; 1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallVideoBootStrap NX_bootstrap = { 1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall "nanox", "nanox", NX_Available, NX_CreateDevice 1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} ; 1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void create_aux_windows (_THIS) 1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GR_WM_PROPERTIES props ; 1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("enter create_aux_windows\n") ; 1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Don't create any extra windows if we are being managed 1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (SDL_windowid) { 1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall FSwindow = 0 ; 1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return ; 1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (FSwindow && FSwindow != GR_ROOT_WINDOW_ID) { 1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GrDestroyWindow (FSwindow) ; 1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall FSwindow = GrNewWindow (GR_ROOT_WINDOW_ID, 0, 0, 1, 1, 0, BLACK, BLACK) ; 1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall props.flags = GR_WM_FLAGS_PROPS ; 1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall props.props = GR_WM_PROPS_NODECORATE ; 1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GrSetWMProperties (FSwindow, & props) ; 1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GrSelectEvents (FSwindow, (GR_EVENT_MASK_EXPOSURE | 1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP | 1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GR_EVENT_MASK_FOCUS_IN | GR_EVENT_MASK_FOCUS_OUT | 1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP | 1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GR_EVENT_MASK_MOUSE_ENTER | GR_EVENT_MASK_MOUSE_EXIT | 1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_UPDATE | 1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GR_EVENT_MASK_CLOSE_REQ)) ; 1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("leave create_aux_windows\n") ; 1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint NX_VideoInit (_THIS, SDL_PixelFormat * vformat) 1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GR_SCREEN_INFO si ; 1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("enter NX_VideoInit\n") ; 1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (GrOpen () < 0) { 1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError ("GrOpen() fail") ; 1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return -1 ; 1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // use share memory to speed up 1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef NANOX_SHARE_MEMORY 1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GrReqShmCmds (0xFFFF); 2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Window = 0 ; 2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall FSwindow = 0 ; 2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GammaRamp_R = NULL ; 2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GammaRamp_G = NULL ; 2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GammaRamp_B = NULL ; 2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GrGetScreenInfo (& si) ; 2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Visual.bpp = si.bpp ; 2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Determine the current screen size */ 2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->info.current_w = si.cols ; 2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->info.current_h = si.rows ; 2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // GetVideoMode 2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_modelist = (SDL_Rect **) SDL_malloc (sizeof (SDL_Rect *) * 2) ; 2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (SDL_modelist) { 2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_modelist [0] = (SDL_Rect *) SDL_malloc (sizeof(SDL_Rect)) ; 2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (SDL_modelist [0]) { 2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_modelist [0] -> x = 0 ; 2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_modelist [0] -> y = 0 ; 2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_modelist [0] -> w = si.cols ; 2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_modelist [0] -> h = si.rows ; 2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_modelist [1] = NULL ; 2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pixel_type = si.pixtype; 2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Visual.red_mask = si.rmask; 2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Visual.green_mask = si.gmask; 2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Visual.blue_mask = si.bmask; 2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vformat -> BitsPerPixel = SDL_Visual.bpp ; 2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (vformat -> BitsPerPixel > 8) { 2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vformat -> Rmask = SDL_Visual.red_mask ; 2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vformat -> Gmask = SDL_Visual.green_mask ; 2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vformat -> Bmask = SDL_Visual.blue_mask ; 2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // See if we have been passed a window to use 2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_windowid = getenv ("SDL_WINDOWID") ; 2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Create the fullscreen (and managed windows : no implement) 2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall create_aux_windows (this) ; 2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("leave NX_VideoInit\n") ; 2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return 0 ; 2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid NX_VideoQuit (_THIS) 2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("enter NX_VideoQuit\n") ; 2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Start shutting down the windows 2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall NX_DestroyImage (this, this -> screen) ; 2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall NX_DestroyWindow (this, this -> screen) ; 2589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (FSwindow && FSwindow != GR_ROOT_WINDOW_ID) { 2599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GrDestroyWindow (FSwindow) ; 2609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall NX_FreeVideoModes (this) ; 2629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free (GammaRamp_R) ; 2639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free (GammaRamp_G) ; 2649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free (GammaRamp_B) ; 2659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef ENABLE_NANOX_DIRECT_FB 2679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (Clientfb) 2689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GrCloseClientFramebuffer(); 2699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 2709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GrClose () ; 2719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("leave NX_VideoQuit\n") ; 2739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void NX_DestroyWindow (_THIS, SDL_Surface * screen) 2769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 2779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("enter NX_DestroyWindow\n") ; 2789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (! SDL_windowid) { 2809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (screen && (screen -> flags & SDL_FULLSCREEN)) { 2819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall screen -> flags &= ~ SDL_FULLSCREEN ; 2829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall NX_LeaveFullScreen (this) ; 2839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Destroy the output window 2869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (SDL_Window && SDL_Window != GR_ROOT_WINDOW_ID) { 2879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GrDestroyWindow (SDL_Window) ; 2889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Free the graphics context 2929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (! SDL_GC) { 2939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GrDestroyGC (SDL_GC) ; 2949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_GC = 0; 2959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("leave NX_DestroyWindow\n") ; 2989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int NX_CreateWindow (_THIS, SDL_Surface * screen, 3019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int w, int h, int bpp, Uint32 flags) 3029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("enter NX_CreateWindow\n") ; 3049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // If a window is already present, destroy it and start fresh 3069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (SDL_Window && SDL_Window != GR_ROOT_WINDOW_ID) { 3079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall NX_DestroyWindow (this, screen) ; 3089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // See if we have been given a window id 3119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (SDL_windowid) { 3129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Window = SDL_strtol (SDL_windowid, NULL, 0) ; 3139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 3149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Window = 0 ; 3159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ! SDL_ReallocFormat (screen, bpp, SDL_Visual.red_mask, 3189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Visual.green_mask, SDL_Visual.blue_mask, 0)) 3199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return -1; 3209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Create (or use) the nanox display window 3229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (! SDL_windowid) { 3239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Window = GrNewWindow (GR_ROOT_WINDOW_ID, 0, 0, w, h, 0, BLACK, WHITE) ; 3259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GrSelectEvents (SDL_Window, (GR_EVENT_MASK_EXPOSURE | 3279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP | 3289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GR_EVENT_MASK_FOCUS_IN | GR_EVENT_MASK_FOCUS_OUT | 3299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP | 3309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GR_EVENT_MASK_MOUSE_ENTER | GR_EVENT_MASK_MOUSE_EXIT | 3319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_UPDATE | 3329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GR_EVENT_MASK_CLOSE_REQ)) ; 3339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Create the graphics context here, once we have a window */ 3369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_GC = GrNewGC () ; 3379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (SDL_GC == 0) { 3389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Couldn't create graphics context"); 3399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(-1); 3409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Map them both and go fullscreen, if requested 3439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (! SDL_windowid) { 3449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GrMapWindow (SDL_Window) ; 3459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (flags & SDL_FULLSCREEN) { 3469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall screen -> flags |= SDL_FULLSCREEN ; 3479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall NX_EnterFullScreen (this) ; 3489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 3499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall screen -> flags &= ~ SDL_FULLSCREEN ; 3509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef ENABLE_NANOX_DIRECT_FB 3549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* attempt allocating the client side framebuffer */ 3559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Clientfb = GrOpenClientFramebuffer(); 3569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* NULL return will default to using GrArea()*/ 3579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 3589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("leave NX_CreateWindow\n") ; 3609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return 0 ; 3619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_Surface * NX_SetVideoMode (_THIS, SDL_Surface * current, 3649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int width, int height, int bpp, Uint32 flags) 3659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("enter NX_SetVideoMode\n") ; 3679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Lock the event thread, in multi-threading environments 3699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Lock_EventThread () ; 3709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bpp = SDL_Visual.bpp ; 3729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (NX_CreateWindow (this, current, width, height, bpp, flags) < 0) { 3739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current = NULL; 3749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall goto done; 3759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (current -> w != width || current -> h != height) { 3789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current -> w = width ; 3799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current -> h = height ; 3809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current -> pitch = SDL_CalculatePitch (current) ; 3819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall NX_ResizeImage (this, current, flags) ; 3829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Clear these flags and set them only if they are in the new set. */ 3859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current -> flags &= ~(SDL_RESIZABLE|SDL_NOFRAME); 3869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current -> flags |= (flags & (SDL_RESIZABLE | SDL_NOFRAME)) ; 3879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall done: 3899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Unlock_EventThread () ; 3909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("leave NX_SetVideoMode\n") ; 3929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // We're done! 3949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return current ; 3959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall// ncolors <= 256 3989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint NX_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) 3999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 4009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int i ; 4019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GR_PALETTE pal ; 4029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("enter NX_SetColors\n") ; 4049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (ncolors > 256) return 0 ; 4069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pal.count = ncolors ; 4089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for (i = 0; i < ncolors; ++ i) { 4099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pal.palette [i].r = colors [i].r ; 4109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pal.palette [i].g = colors [i].g ; 4119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pal.palette [i].b = colors [i].b ; 4129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GrSetSystemPalette (firstcolor, & pal) ; 4149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("leave NX_SetColors\n") ; 4169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return 1 ; 4179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 4189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int NX_ToggleFullScreen (_THIS, int on) 4209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 4219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Rect rect ; 4229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 event_thread ; 4239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("enter NX_ToggleFullScreen\n") ; 4259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Don't switch if we don't own the window 4279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (SDL_windowid) return 0 ; 4289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Don't lock if we are the event thread 4309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall event_thread = SDL_EventThreadID () ; 4319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (event_thread && (SDL_ThreadID () == event_thread)) { 4329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall event_thread = 0 ; 4339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (event_thread) { 4359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Lock_EventThread() ; 4369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (on) { 4399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall NX_EnterFullScreen (this) ; 4409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 4419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this -> screen -> flags &= ~ SDL_FULLSCREEN ; 4429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall NX_LeaveFullScreen (this) ; 4439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.x = rect.y = 0 ; 4469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.w = this -> screen -> w, rect.h = this -> screen -> h ; 4479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall NX_NormalUpdate (this, 1, & rect) ; 4489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (event_thread) { 4509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Unlock_EventThread () ; 4519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("leave NX_ToggleFullScreen\n") ; 4549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return 1 ; 4559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 4569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall// Update the current mouse state and position 4589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void NX_UpdateMouse (_THIS) 4599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 4609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int x, y ; 4619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GR_WINDOW_INFO info ; 4629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GR_SCREEN_INFO si ; 4639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("enter NX_UpdateMouse\n") ; 4669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Lock the event thread, in multi-threading environments 4689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Lock_EventThread () ; 4699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GrGetScreenInfo (& si) ; 4719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GrGetWindowInfo (SDL_Window, & info) ; 4729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall x = si.xpos - info.x ; 4739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall y = si.ypos - info.y ; 4749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (x >= 0 && x <= info.width && y >= 0 && y <= info.height) { 4759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS) ; 4769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateMouseMotion (0, 0, x, y); 4779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 4789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS) ; 4799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Unlock_EventThread () ; 4829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("leave NX_UpdateMouse\n") ; 4839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 4849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int NX_SetGammaRamp (_THIS, Uint16 * ramp) 4869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 4879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int i ; 4889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint16 * red, * green, * blue ; 4899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("enter NX_SetGammaRamp\n") ; 4919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (SDL_Visual.bpp != 32 && SDL_Visual.bpp != 24) return -1 ; 4939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (! GammaRamp_R) GammaRamp_R = (Uint16 *) SDL_malloc (sizeof (Uint16) * CI_SIZE) ; 4959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (! GammaRamp_G) GammaRamp_G = (Uint16 *) SDL_malloc (sizeof (Uint16) * CI_SIZE) ; 4969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (! GammaRamp_B) GammaRamp_B = (Uint16 *) SDL_malloc (sizeof (Uint16) * CI_SIZE) ; 4979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ((! GammaRamp_R) || (! GammaRamp_G) || (! GammaRamp_B)) { 4989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_OutOfMemory () ; 4999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return -1 ; 5009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for (i = 0; i < CI_SIZE; ++ i) 5039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GammaRamp_R [i] = GammaRamp_G [i] = GammaRamp_B [i] = i ; 5049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall red = ramp ; 5069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall green = ramp + CI_SIZE ; 5079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall blue = green + CI_SIZE ; 5089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for (i = 0; i < CI_SIZE; ++ i) { 5109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GammaRamp_R [i] = red [i] ; 5119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GammaRamp_G [i] = green [i] ; 5129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GammaRamp_B [i] = blue [i] ; 5139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_UpdateRect(this->screen, 0, 0, 0, 0); 5159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("leave NX_SetGammaRamp\n") ; 5179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return 0 ; 5189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 5199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int NX_GetGammaRamp (_THIS, Uint16 * ramp) 5219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 5229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int i ; 5239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint16 * red, * green, * blue ; 5249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("enter NX_GetGammaRamp\n") ; 5269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (SDL_Visual.bpp != 32 && SDL_Visual.bpp != 24) return -1 ; 5289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall red = ramp ; 5299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall green = ramp + CI_SIZE ; 5309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall blue = green + CI_SIZE ; 5319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (GammaRamp_R && GammaRamp_G && GammaRamp_B) { 5329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for (i = 0; i < CI_SIZE; ++ i) { 5339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall red [i] = GammaRamp_R [i] ; 5349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall green [i] = GammaRamp_G [i] ; 5359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall blue [i] = GammaRamp_B [i] ; 5369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 5389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for (i = 0; i < CI_SIZE; ++ i) 5399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall red [i] = green [i] = blue [i] = i ; 5409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Dprintf ("leave NX_GetGammaRamp\n") ; 5439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return 0 ; 5449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 545