src/video/nanox/SDL_nxvideo.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 06 Jan 2006 13:20:10 +0000
changeset 1234 73676c1f56ee
parent 769 b8d311d90021
child 1338 604d73db6802
permissions -rw-r--r--
For sanity's sake, removed the '&' when passing copy_row array to asm.
slouken@30
     1
/*
slouken@30
     2
    SDL - Simple DirectMedia Layer
slouken@769
     3
    Copyright (C) 1997-2004 Sam Lantinga
slouken@30
     4
    Copyright (C) 2001  Hsieh-Fu Tsai
slouken@471
     5
    Copyright (C) 2002  Greg Haerr <greg@censoft.com>
slouken@30
     6
slouken@30
     7
    This library is free software; you can redistribute it and/or
slouken@30
     8
    modify it under the terms of the GNU Library General Public
slouken@30
     9
    License as published by the Free Software Foundation; either
slouken@30
    10
    version 2 of the License, or (at your option) any later version.
slouken@30
    11
slouken@30
    12
    This library is distributed in the hope that it will be useful,
slouken@30
    13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@30
    14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@30
    15
    Library General Public License for more details.
slouken@30
    16
slouken@30
    17
    You should have received a copy of the GNU Library General Public
slouken@30
    18
    License along with this library; if not, write to the Free
slouken@30
    19
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@30
    20
slouken@30
    21
    Sam Lantinga
slouken@252
    22
    slouken@libsdl.org
slouken@30
    23
    
slouken@30
    24
    Hsieh-Fu Tsai
slouken@30
    25
    clare@setabox.com
slouken@30
    26
*/
slouken@30
    27
slouken@30
    28
#include <stdlib.h>
slouken@698
    29
#include <string.h>
slouken@30
    30
slouken@30
    31
#include "SDL_video.h"
slouken@30
    32
#include "SDL_pixels_c.h"
slouken@30
    33
#include "SDL_events_c.h"
slouken@30
    34
#include "SDL_thread.h"
slouken@30
    35
slouken@30
    36
#define MWINCLUDECOLORS
slouken@30
    37
#include "SDL_nxvideo.h"
slouken@30
    38
#include "SDL_nxmodes_c.h"
slouken@30
    39
#include "SDL_nxwm_c.h"
slouken@30
    40
#include "SDL_nxmouse_c.h"
slouken@30
    41
#include "SDL_nximage_c.h"
slouken@30
    42
#include "SDL_nxevents_c.h"
slouken@30
    43
slouken@30
    44
// Initialization/Query functions
slouken@30
    45
static int NX_VideoInit (_THIS, SDL_PixelFormat * vformat) ;
slouken@30
    46
static SDL_Surface * NX_SetVideoMode (_THIS, SDL_Surface * current, int width, int height, int bpp, Uint32 flags) ;
slouken@30
    47
static int NX_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) ;
slouken@30
    48
static void NX_VideoQuit (_THIS) ;
slouken@30
    49
static void NX_DestroyWindow (_THIS, SDL_Surface * screen) ;
slouken@30
    50
static int NX_ToggleFullScreen (_THIS, int on) ;
slouken@30
    51
static void NX_UpdateMouse (_THIS) ;
slouken@30
    52
static int NX_SetGammaRamp (_THIS, Uint16 * ramp) ;
slouken@30
    53
static int NX_GetGammaRamp (_THIS, Uint16 * ramp) ;
slouken@30
    54
slouken@30
    55
// Microwin driver bootstrap functions
slouken@30
    56
static int NX_Available ()
slouken@30
    57
{
slouken@30
    58
    Dprintf ("enter NX_Available\n") ;
slouken@30
    59
slouken@30
    60
    if (GrOpen () < 0) return 0 ;
slouken@30
    61
        GrClose () ;
slouken@30
    62
    
slouken@30
    63
    Dprintf ("leave NX_Available\n") ;
slouken@30
    64
    return 1 ;
slouken@30
    65
}
slouken@30
    66
slouken@30
    67
static void NX_DeleteDevice (SDL_VideoDevice * device)
slouken@30
    68
{
slouken@30
    69
    Dprintf ("enter NX_DeleteDevice\n") ;
slouken@30
    70
slouken@30
    71
    if (device) {
slouken@30
    72
        if (device -> hidden) free (device -> hidden) ;
slouken@30
    73
        if (device -> gl_data) free (device -> gl_data) ;
slouken@30
    74
            free (device) ;
slouken@30
    75
    }
slouken@30
    76
slouken@30
    77
    Dprintf ("leave NX_DeleteDevice\n") ;
slouken@30
    78
}
slouken@30
    79
    
slouken@30
    80
static SDL_VideoDevice * NX_CreateDevice (int devindex)
slouken@30
    81
{
slouken@30
    82
    SDL_VideoDevice * device ;
slouken@30
    83
slouken@30
    84
    Dprintf ("enter NX_CreateDevice\n") ;
slouken@30
    85
slouken@30
    86
    // Initialize all variables that we clean on shutdown
slouken@30
    87
    device = (SDL_VideoDevice *) malloc (sizeof (SDL_VideoDevice)) ;
slouken@30
    88
    if (device) {
slouken@30
    89
        memset (device, 0, (sizeof * device)) ;
slouken@30
    90
        device -> hidden = (struct SDL_PrivateVideoData *)
slouken@30
    91
                malloc ((sizeof * device -> hidden)) ;
slouken@30
    92
        device -> gl_data = NULL ;
slouken@30
    93
    }
slouken@30
    94
    if ((device == NULL) || (device -> hidden == NULL)) {
slouken@30
    95
        SDL_OutOfMemory () ;
slouken@30
    96
        NX_DeleteDevice (device) ;
slouken@30
    97
        return 0 ;
slouken@30
    98
    }
slouken@30
    99
    memset (device -> hidden, 0, (sizeof * device -> hidden)) ;
slouken@30
   100
slouken@30
   101
    // Set the function pointers
slouken@30
   102
    device -> VideoInit = NX_VideoInit ;
slouken@30
   103
    device -> ListModes = NX_ListModes ;
slouken@30
   104
    device -> SetVideoMode = NX_SetVideoMode ;
slouken@30
   105
    device -> ToggleFullScreen = NX_ToggleFullScreen ;
slouken@30
   106
    device -> UpdateMouse = NX_UpdateMouse ;
slouken@30
   107
    device -> CreateYUVOverlay = NULL ;
slouken@30
   108
    device -> SetColors = NX_SetColors ;
slouken@30
   109
    device -> UpdateRects = NULL ;
slouken@30
   110
    device -> VideoQuit = NX_VideoQuit;
slouken@30
   111
    device -> AllocHWSurface = NULL ;
slouken@30
   112
    device -> CheckHWBlit = NULL ;
slouken@30
   113
    device -> FillHWRect = NULL ;
slouken@30
   114
    device -> SetHWColorKey = NULL ;
slouken@30
   115
    device -> SetHWAlpha = NULL ;
slouken@30
   116
    device -> LockHWSurface = NULL ;
slouken@30
   117
    device -> UnlockHWSurface = NULL ;
slouken@30
   118
    device -> FlipHWSurface = NULL ;
slouken@30
   119
    device -> FreeHWSurface = NULL ;
slouken@30
   120
    device -> SetGamma = NULL ;
slouken@30
   121
    device -> GetGamma = NULL ;
slouken@30
   122
    device -> SetGammaRamp = NX_SetGammaRamp ;
slouken@30
   123
    device -> GetGammaRamp = NX_GetGammaRamp ;
slouken@30
   124
slouken@30
   125
#ifdef HAVE_OPENGL
slouken@30
   126
    device -> GL_LoadLibrary = NULL ;
slouken@30
   127
    device -> GL_GetProcAddress = NULL ;
slouken@30
   128
    device -> GL_GetAttribute = NULL ;
slouken@30
   129
    device -> GL_MakeCurrent = NULL ;
slouken@30
   130
    device -> GL_SwapBuffers = NULL ;
slouken@30
   131
#endif
slouken@30
   132
slouken@30
   133
    device -> SetIcon = NULL ;
slouken@30
   134
    device -> SetCaption = NX_SetCaption;
slouken@30
   135
    device -> IconifyWindow = NULL ;
slouken@30
   136
    device -> GrabInput = NULL ;
slouken@30
   137
    device -> GetWMInfo = NX_GetWMInfo ;
slouken@30
   138
    device -> FreeWMCursor =  NX_FreeWMCursor ;
slouken@30
   139
    device -> CreateWMCursor = NX_CreateWMCursor ;
slouken@30
   140
    device -> ShowWMCursor = NX_ShowWMCursor ;
slouken@30
   141
    device -> WarpWMCursor = NX_WarpWMCursor ;
slouken@30
   142
    device -> CheckMouseMode = NULL ;
slouken@30
   143
    device -> InitOSKeymap = NX_InitOSKeymap ;
slouken@30
   144
    device -> PumpEvents = NX_PumpEvents ;
slouken@30
   145
slouken@30
   146
    device -> free = NX_DeleteDevice ;
slouken@30
   147
slouken@30
   148
    Dprintf ("leave NX_CreateDevice\n") ;
slouken@30
   149
    return device ;
slouken@30
   150
}
slouken@30
   151
slouken@30
   152
VideoBootStrap NX_bootstrap = {
slouken@30
   153
    "nanox", "nanox", NX_Available, NX_CreateDevice
slouken@30
   154
} ;
slouken@30
   155
slouken@30
   156
static void create_aux_windows (_THIS)
slouken@30
   157
{
slouken@30
   158
    GR_WM_PROPERTIES props ;
slouken@30
   159
slouken@30
   160
    Dprintf ("enter create_aux_windows\n") ;
slouken@30
   161
slouken@30
   162
    // Don't create any extra windows if we are being managed
slouken@30
   163
    if (SDL_windowid) {
slouken@30
   164
        FSwindow = 0 ;
slouken@30
   165
        return ;
slouken@30
   166
    }
slouken@30
   167
    
slouken@30
   168
    if (FSwindow && FSwindow != GR_ROOT_WINDOW_ID) {
slouken@30
   169
        GrDestroyWindow (FSwindow) ;
slouken@30
   170
    }
slouken@30
   171
    
slouken@30
   172
    FSwindow = GrNewWindow (GR_ROOT_WINDOW_ID, 0, 0, 1, 1, 0, BLACK, BLACK) ;
slouken@30
   173
    props.flags = GR_WM_FLAGS_PROPS ;
slouken@30
   174
    props.props = GR_WM_PROPS_NODECORATE ;
slouken@30
   175
    GrSetWMProperties (FSwindow, & props) ;
slouken@30
   176
slouken@30
   177
    GrSelectEvents (FSwindow, (GR_EVENT_MASK_EXPOSURE         |
slouken@30
   178
        GR_EVENT_MASK_BUTTON_DOWN  | GR_EVENT_MASK_BUTTON_UP  |
slouken@30
   179
        GR_EVENT_MASK_FOCUS_IN     | GR_EVENT_MASK_FOCUS_OUT  |
slouken@30
   180
        GR_EVENT_MASK_KEY_DOWN     | GR_EVENT_MASK_KEY_UP     |
slouken@30
   181
        GR_EVENT_MASK_MOUSE_ENTER  | GR_EVENT_MASK_MOUSE_EXIT |
slouken@30
   182
        GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_UPDATE     |
slouken@30
   183
        GR_EVENT_MASK_CLOSE_REQ)) ;
slouken@30
   184
slouken@30
   185
    Dprintf ("leave create_aux_windows\n") ;
slouken@30
   186
}
slouken@30
   187
slouken@30
   188
int NX_VideoInit (_THIS, SDL_PixelFormat * vformat)
slouken@30
   189
{
slouken@30
   190
    GR_SCREEN_INFO si ;
slouken@30
   191
slouken@30
   192
    Dprintf ("enter NX_VideoInit\n") ;
slouken@30
   193
    
slouken@30
   194
    if (GrOpen () < 0) {
slouken@30
   195
        SDL_SetError ("GrOpen() fail") ;
slouken@30
   196
        return -1 ;
slouken@30
   197
    }
slouken@30
   198
slouken@30
   199
    // use share memory to speed up
slouken@30
   200
#ifdef NANOX_SHARE_MEMORY
slouken@30
   201
    GrReqShmCmds (0xFFFF);
slouken@30
   202
#endif
slouken@30
   203
slouken@30
   204
    SDL_Window = 0 ;
slouken@30
   205
    FSwindow = 0 ;
slouken@30
   206
slouken@30
   207
    GammaRamp_R = NULL ;
slouken@30
   208
    GammaRamp_G = NULL ;
slouken@30
   209
    GammaRamp_B = NULL ;    
slouken@30
   210
slouken@30
   211
    GrGetScreenInfo (& si) ;
slouken@30
   212
    SDL_Visual.bpp = si.bpp ;
slouken@30
   213
slouken@30
   214
    // GetVideoMode
slouken@30
   215
    SDL_modelist = (SDL_Rect **) malloc (sizeof (SDL_Rect *) * 2) ;
slouken@30
   216
    if (SDL_modelist) {
slouken@30
   217
        SDL_modelist [0] = (SDL_Rect *) malloc (sizeof(SDL_Rect)) ;
slouken@30
   218
        if (SDL_modelist [0]) {
slouken@30
   219
            SDL_modelist [0] -> x = 0 ;
slouken@30
   220
            SDL_modelist [0] -> y = 0 ;
slouken@30
   221
            SDL_modelist [0] -> w = si.cols ;
slouken@30
   222
            SDL_modelist [0] -> h = si.rows ;
slouken@30
   223
        }
slouken@30
   224
        SDL_modelist [1] = NULL ;
slouken@30
   225
    }
slouken@30
   226
slouken@471
   227
    pixel_type = si.pixtype;
slouken@471
   228
    SDL_Visual.red_mask = si.rmask;
slouken@471
   229
    SDL_Visual.green_mask = si.gmask;
slouken@471
   230
    SDL_Visual.blue_mask = si.bmask;
slouken@30
   231
slouken@30
   232
    vformat -> BitsPerPixel = SDL_Visual.bpp ;
slouken@30
   233
    if (vformat -> BitsPerPixel > 8) {
slouken@30
   234
        vformat -> Rmask = SDL_Visual.red_mask ;
slouken@30
   235
        vformat -> Gmask = SDL_Visual.green_mask ;
slouken@30
   236
        vformat -> Bmask = SDL_Visual.blue_mask ;
slouken@30
   237
    }
slouken@30
   238
slouken@30
   239
    // See if we have been passed a window to use
slouken@30
   240
    SDL_windowid = getenv ("SDL_WINDOWID") ;
slouken@30
   241
    
slouken@30
   242
    // Create the fullscreen (and managed windows : no implement)
slouken@30
   243
    create_aux_windows (this) ;
slouken@30
   244
slouken@30
   245
    Dprintf ("leave NX_VideoInit\n") ;
slouken@30
   246
    return 0 ;
slouken@30
   247
}
slouken@30
   248
slouken@30
   249
void NX_VideoQuit (_THIS)
slouken@30
   250
{
slouken@30
   251
    Dprintf ("enter NX_VideoQuit\n") ;
slouken@30
   252
slouken@30
   253
    // Start shutting down the windows
slouken@30
   254
    NX_DestroyImage (this, this -> screen) ;
slouken@30
   255
    NX_DestroyWindow (this, this -> screen) ;
slouken@30
   256
    if (FSwindow && FSwindow != GR_ROOT_WINDOW_ID) {
slouken@30
   257
        GrDestroyWindow (FSwindow) ;
slouken@30
   258
    }
slouken@30
   259
    NX_FreeVideoModes (this) ;
slouken@30
   260
    free (GammaRamp_R) ;
slouken@30
   261
    free (GammaRamp_G) ;
slouken@30
   262
    free (GammaRamp_B) ;
slouken@471
   263
slouken@471
   264
#ifdef ENABLE_NANOX_DIRECT_FB
slouken@471
   265
    if (Clientfb)
slouken@471
   266
        GrCloseClientFramebuffer();
slouken@471
   267
#endif
slouken@30
   268
    GrClose () ;
slouken@30
   269
slouken@30
   270
    Dprintf ("leave NX_VideoQuit\n") ;
slouken@30
   271
}
slouken@30
   272
slouken@30
   273
static void NX_DestroyWindow (_THIS, SDL_Surface * screen)
slouken@30
   274
{
slouken@30
   275
    Dprintf ("enter NX_DestroyWindow\n") ;
slouken@30
   276
slouken@30
   277
    if (! SDL_windowid) {
slouken@30
   278
        if (screen && (screen -> flags & SDL_FULLSCREEN)) {
slouken@30
   279
            screen -> flags &= ~ SDL_FULLSCREEN ;
slouken@30
   280
            NX_LeaveFullScreen (this) ;
slouken@30
   281
        }
slouken@30
   282
slouken@30
   283
        // Destroy the output window
slouken@30
   284
        if (SDL_Window && SDL_Window != GR_ROOT_WINDOW_ID) {
slouken@30
   285
            GrDestroyWindow (SDL_Window) ;
slouken@30
   286
        }
slouken@30
   287
    }
slouken@30
   288
    
slouken@30
   289
    // Free the graphics context
slouken@30
   290
    if (! SDL_GC) {
slouken@30
   291
        GrDestroyGC (SDL_GC) ;
slouken@30
   292
        SDL_GC = 0;
slouken@30
   293
    }
slouken@30
   294
slouken@30
   295
    Dprintf ("leave NX_DestroyWindow\n") ;
slouken@30
   296
}
slouken@30
   297
slouken@30
   298
static int NX_CreateWindow (_THIS, SDL_Surface * screen,
slouken@30
   299
                int w, int h, int bpp, Uint32 flags)
slouken@30
   300
{
slouken@30
   301
    Dprintf ("enter NX_CreateWindow\n") ;
slouken@30
   302
slouken@30
   303
    // If a window is already present, destroy it and start fresh
slouken@30
   304
    if (SDL_Window && SDL_Window != GR_ROOT_WINDOW_ID) {
slouken@30
   305
        NX_DestroyWindow (this, screen) ;
slouken@30
   306
    }
slouken@30
   307
slouken@30
   308
    // See if we have been given a window id
slouken@30
   309
    if (SDL_windowid) {
slouken@30
   310
        SDL_Window = strtol (SDL_windowid, NULL, 0) ;
slouken@30
   311
    } else {
slouken@30
   312
        SDL_Window = 0 ;
slouken@30
   313
    }
slouken@30
   314
    
slouken@30
   315
    if ( ! SDL_ReallocFormat (screen, bpp, SDL_Visual.red_mask, 
slouken@30
   316
        SDL_Visual.green_mask, SDL_Visual.blue_mask, 0))
slouken@30
   317
        return -1;
slouken@30
   318
slouken@30
   319
    // Create (or use) the nanox display window
slouken@30
   320
    if (! SDL_windowid) {
slouken@30
   321
slouken@30
   322
        SDL_Window = GrNewWindow (GR_ROOT_WINDOW_ID, 0, 0, w, h, 0, BLACK, WHITE) ;
slouken@30
   323
slouken@30
   324
        GrSelectEvents (SDL_Window, (GR_EVENT_MASK_EXPOSURE       |
slouken@30
   325
            GR_EVENT_MASK_BUTTON_DOWN  | GR_EVENT_MASK_BUTTON_UP  |
slouken@30
   326
            GR_EVENT_MASK_FOCUS_IN     | GR_EVENT_MASK_FOCUS_OUT  |
slouken@30
   327
            GR_EVENT_MASK_KEY_DOWN     | GR_EVENT_MASK_KEY_UP     |
slouken@30
   328
            GR_EVENT_MASK_MOUSE_ENTER  | GR_EVENT_MASK_MOUSE_EXIT |
slouken@30
   329
            GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_UPDATE     |
slouken@30
   330
            GR_EVENT_MASK_CLOSE_REQ)) ;
slouken@30
   331
    }
slouken@30
   332
    
slouken@30
   333
    /* Create the graphics context here, once we have a window */
slouken@30
   334
    SDL_GC = GrNewGC () ;
slouken@30
   335
    if (SDL_GC == 0) {
slouken@30
   336
        SDL_SetError("Couldn't create graphics context");
slouken@30
   337
        return(-1);
slouken@30
   338
    }
slouken@30
   339
slouken@30
   340
    // Map them both and go fullscreen, if requested
slouken@30
   341
    if (! SDL_windowid) {
slouken@30
   342
        GrMapWindow (SDL_Window) ;
slouken@30
   343
        if (flags & SDL_FULLSCREEN) {
slouken@30
   344
            screen -> flags |= SDL_FULLSCREEN ;
slouken@30
   345
            NX_EnterFullScreen (this) ;
slouken@30
   346
        } else {
slouken@30
   347
            screen -> flags &= ~ SDL_FULLSCREEN ;
slouken@30
   348
        }
slouken@30
   349
    }
slouken@30
   350
slouken@471
   351
#ifdef ENABLE_NANOX_DIRECT_FB
slouken@471
   352
    /* attempt allocating the client side framebuffer */
slouken@471
   353
    Clientfb = GrOpenClientFramebuffer();
slouken@471
   354
    /* NULL return will default to using GrArea()*/
slouken@471
   355
#endif
slouken@471
   356
slouken@30
   357
    Dprintf ("leave NX_CreateWindow\n") ;
slouken@30
   358
    return 0 ;
slouken@30
   359
}
slouken@30
   360
slouken@30
   361
SDL_Surface * NX_SetVideoMode (_THIS, SDL_Surface * current,
slouken@30
   362
                int width, int height, int bpp, Uint32 flags)
slouken@30
   363
{
slouken@30
   364
    Dprintf ("enter NX_SetVideoMode\n") ;
slouken@30
   365
slouken@30
   366
    // Lock the event thread, in multi-threading environments
slouken@30
   367
    SDL_Lock_EventThread () ;
slouken@30
   368
slouken@30
   369
    bpp = SDL_Visual.bpp ;
slouken@30
   370
    if (NX_CreateWindow (this, current, width, height, bpp, flags) < 0) {
slouken@30
   371
        current = NULL;
slouken@30
   372
        goto done;
slouken@30
   373
    }
slouken@30
   374
slouken@30
   375
    if (current -> w != width || current -> h != height) {
slouken@30
   376
        current -> w = width ;
slouken@30
   377
        current -> h = height ;
slouken@30
   378
        current -> pitch = SDL_CalculatePitch (current) ;
slouken@30
   379
        NX_ResizeImage (this, current, flags) ;
slouken@30
   380
    }
slouken@30
   381
    current -> flags |= (flags & (SDL_RESIZABLE | SDL_NOFRAME)) ;
slouken@30
   382
slouken@30
   383
  done:
slouken@30
   384
    SDL_Unlock_EventThread () ;
slouken@30
   385
slouken@30
   386
    Dprintf ("leave NX_SetVideoMode\n") ;
slouken@30
   387
slouken@30
   388
    // We're done!
slouken@30
   389
    return current ;
slouken@30
   390
}
slouken@30
   391
slouken@30
   392
// ncolors <= 256
slouken@30
   393
int NX_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors)
slouken@30
   394
{
slouken@30
   395
    int        i ;
slouken@30
   396
    GR_PALETTE pal ;
slouken@30
   397
slouken@30
   398
    Dprintf ("enter NX_SetColors\n") ;
slouken@30
   399
slouken@30
   400
    if (ncolors > 256) return 0 ;
slouken@30
   401
    
slouken@30
   402
    pal.count = ncolors ;
slouken@30
   403
    for (i = 0; i < ncolors; ++ i) {
slouken@30
   404
        pal.palette [i].r = colors [i].r ;
slouken@30
   405
        pal.palette [i].g = colors [i].g ;
slouken@30
   406
        pal.palette [i].b = colors [i].b ;
slouken@30
   407
    }
slouken@30
   408
    GrSetSystemPalette (firstcolor, & pal) ;
slouken@30
   409
slouken@30
   410
    Dprintf ("leave NX_SetColors\n") ;
slouken@30
   411
    return 1 ;
slouken@30
   412
}
slouken@30
   413
slouken@30
   414
static int NX_ToggleFullScreen (_THIS, int on)
slouken@30
   415
{
slouken@30
   416
    SDL_Rect rect ;
slouken@30
   417
    Uint32   event_thread ;
slouken@30
   418
    
slouken@30
   419
    Dprintf ("enter NX_ToggleFullScreen\n") ;
slouken@30
   420
slouken@30
   421
    // Don't switch if we don't own the window
slouken@30
   422
    if (SDL_windowid) return 0 ;
slouken@30
   423
    
slouken@30
   424
    // Don't lock if we are the event thread
slouken@30
   425
    event_thread = SDL_EventThreadID () ;
slouken@30
   426
    if (event_thread && (SDL_ThreadID () == event_thread)) {
slouken@30
   427
        event_thread = 0 ;
slouken@30
   428
    }
slouken@30
   429
    if (event_thread) {
slouken@30
   430
        SDL_Lock_EventThread() ;
slouken@30
   431
    }
slouken@30
   432
    
slouken@30
   433
    if (on) {
slouken@30
   434
        NX_EnterFullScreen (this) ;
slouken@30
   435
    } else {
slouken@30
   436
        this -> screen -> flags &= ~ SDL_FULLSCREEN ;
slouken@30
   437
        NX_LeaveFullScreen (this) ;
slouken@30
   438
    }
slouken@30
   439
slouken@30
   440
    rect.x = rect.y = 0 ;
slouken@30
   441
    rect.w = this -> screen -> w, rect.h = this -> screen -> h ;
slouken@30
   442
    NX_NormalUpdate (this, 1, & rect) ;
slouken@30
   443
slouken@30
   444
    if (event_thread) {
slouken@30
   445
        SDL_Unlock_EventThread () ;
slouken@30
   446
    }
slouken@30
   447
    
slouken@30
   448
    Dprintf ("leave NX_ToggleFullScreen\n") ;
slouken@30
   449
    return 1 ;
slouken@30
   450
}
slouken@30
   451
slouken@30
   452
// Update the current mouse state and position
slouken@30
   453
static void NX_UpdateMouse (_THIS)
slouken@30
   454
{
slouken@30
   455
    int            x, y ;
slouken@30
   456
    GR_WINDOW_INFO info ;
slouken@30
   457
    GR_SCREEN_INFO si ;
slouken@30
   458
slouken@30
   459
slouken@30
   460
    Dprintf ("enter NX_UpdateMouse\n") ;
slouken@30
   461
slouken@30
   462
    // Lock the event thread, in multi-threading environments
slouken@30
   463
    SDL_Lock_EventThread () ;
slouken@30
   464
    
slouken@30
   465
    GrGetScreenInfo (& si) ;
slouken@30
   466
    GrGetWindowInfo (SDL_Window, & info) ;
slouken@30
   467
    x = si.xpos - info.x ;
slouken@30
   468
    y = si.ypos - info.y ;
slouken@30
   469
    if (x >= 0 && x <= info.width && y >= 0 && y <= info.height) {
slouken@30
   470
        SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS) ;
slouken@30
   471
        SDL_PrivateMouseMotion (0, 0, x, y);
slouken@30
   472
    } else {
slouken@30
   473
        SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS) ;
slouken@30
   474
    }
slouken@30
   475
slouken@30
   476
    SDL_Unlock_EventThread () ;
slouken@30
   477
    Dprintf ("leave NX_UpdateMouse\n") ;
slouken@30
   478
}
slouken@30
   479
slouken@30
   480
static int NX_SetGammaRamp (_THIS, Uint16 * ramp)
slouken@30
   481
{
slouken@30
   482
    int i ;
slouken@30
   483
    Uint16 * red, * green, * blue ;
slouken@30
   484
    
slouken@30
   485
    Dprintf ("enter NX_SetGammaRamp\n") ;
slouken@30
   486
    
slouken@30
   487
    if (SDL_Visual.bpp != 32 && SDL_Visual.bpp != 24) return -1 ;
slouken@30
   488
slouken@30
   489
    if (! GammaRamp_R) GammaRamp_R = (Uint16 *) malloc (sizeof (Uint16) * CI_SIZE) ;
slouken@30
   490
    if (! GammaRamp_G) GammaRamp_G = (Uint16 *) malloc (sizeof (Uint16) * CI_SIZE) ;
slouken@30
   491
    if (! GammaRamp_B) GammaRamp_B = (Uint16 *) malloc (sizeof (Uint16) * CI_SIZE) ;
slouken@30
   492
    if ((! GammaRamp_R) || (! GammaRamp_G) || (! GammaRamp_B)) {
slouken@30
   493
        SDL_OutOfMemory () ;
slouken@30
   494
        return -1 ;
slouken@30
   495
    }
slouken@30
   496
slouken@30
   497
    for (i = 0; i < CI_SIZE; ++ i)
slouken@30
   498
        GammaRamp_R [i] = GammaRamp_G [i] = GammaRamp_B [i] = i ;
slouken@30
   499
slouken@30
   500
    red   = ramp ;
slouken@30
   501
    green = ramp + CI_SIZE ;
slouken@30
   502
    blue  = green + CI_SIZE ;
slouken@30
   503
        
slouken@30
   504
    for (i = 0; i < CI_SIZE; ++ i) {
slouken@30
   505
        GammaRamp_R [i] = red   [i] ;
slouken@30
   506
        GammaRamp_G [i] = green [i] ;
slouken@30
   507
        GammaRamp_B [i] = blue  [i] ;
slouken@30
   508
    }
slouken@699
   509
    SDL_UpdateRect(this->screen, 0, 0, 0, 0);
slouken@30
   510
slouken@30
   511
    Dprintf ("leave NX_SetGammaRamp\n") ;   
slouken@30
   512
    return 0 ;
slouken@30
   513
}
slouken@30
   514
slouken@30
   515
static int NX_GetGammaRamp (_THIS, Uint16 * ramp)
slouken@30
   516
{
slouken@30
   517
    int i ;
slouken@30
   518
    Uint16 * red, * green, * blue ;
slouken@30
   519
slouken@30
   520
    Dprintf ("enter NX_GetGammaRamp\n") ;   
slouken@30
   521
slouken@30
   522
    if (SDL_Visual.bpp != 32 && SDL_Visual.bpp != 24) return -1 ;
slouken@30
   523
    red   = ramp ;
slouken@30
   524
    green = ramp  + CI_SIZE ;
slouken@30
   525
    blue  = green + CI_SIZE ;
slouken@30
   526
    if (GammaRamp_R && GammaRamp_G && GammaRamp_B) {
slouken@30
   527
        for (i = 0; i < CI_SIZE; ++ i) {
slouken@30
   528
            red   [i] = GammaRamp_R [i] ;
slouken@30
   529
            green [i] = GammaRamp_G [i] ;
slouken@30
   530
            blue  [i] = GammaRamp_B [i] ;
slouken@30
   531
        }
slouken@30
   532
    } else {
slouken@30
   533
        for (i = 0; i < CI_SIZE; ++ i)
slouken@30
   534
            red [i] = green [i] = blue [i] = i ;
slouken@30
   535
    }
slouken@30
   536
slouken@30
   537
    Dprintf ("leave NX_GetGammaRamp\n") ;
slouken@30
   538
    return 0 ;
slouken@30
   539
}