src/video/riscos/SDL_riscosvideo.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 29 May 2006 04:04:35 +0000
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
permissions -rw-r--r--
more tweaking indent options
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2004 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Library General Public
     7     License as published by the Free Software Foundation; either
     8     version 2 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Library General Public License for more details.
    14 
    15     You should have received a copy of the GNU Library General Public
    16     License along with this library; if not, write to the Free
    17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 /*
    25      File added by Alan Buckley (alan_baa@hotmail.com) for RISC OS compatability
    26 	 23 March 2003
    27 
    28      Implements RISC OS display device management.
    29 	 Routines for full screen and wimp modes are split
    30 	 into other source files.
    31 */
    32 
    33 #include "SDL_video.h"
    34 #include "SDL_mouse.h"
    35 #include "SDL_syswm.h"
    36 #include "../SDL_sysvideo.h"
    37 #include "../SDL_pixels_c.h"
    38 #include "../../events/SDL_events_c.h"
    39 
    40 #include "SDL_riscostask.h"
    41 #include "SDL_riscosvideo.h"
    42 #include "SDL_riscosevents_c.h"
    43 #include "SDL_riscosmouse_c.h"
    44 
    45 #include "kernel.h"
    46 #include "swis.h"
    47 
    48 #define RISCOSVID_DRIVER_NAME "riscos"
    49 
    50 /* Initialization/Query functions */
    51 static int RISCOS_VideoInit(_THIS, SDL_PixelFormat * vformat);
    52 static void RISCOS_VideoQuit(_THIS);
    53 
    54 static SDL_Rect **RISCOS_ListModes(_THIS, SDL_PixelFormat * format,
    55                                    Uint32 flags);
    56 static SDL_Surface *RISCOS_SetVideoMode(_THIS, SDL_Surface * current,
    57                                         int width, int height, int bpp,
    58                                         Uint32 flags);
    59 
    60 int RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo * info);
    61 
    62 int RISCOS_ToggleFullScreen(_THIS, int fullscreen);
    63 /* Mouse checking */
    64 void RISCOS_CheckMouseMode(_THIS);
    65 extern SDL_GrabMode RISCOS_GrabInput(_THIS, SDL_GrabMode mode);
    66 
    67 /* Fullscreen mode functions */
    68 extern SDL_Surface *FULLSCREEN_SetVideoMode(_THIS, SDL_Surface * current,
    69                                             int width, int height, int bpp,
    70                                             Uint32 flags);
    71 extern void FULLSCREEN_BuildModeList(_THIS);
    72 extern void FULLSCREEN_SetDeviceMode(_THIS);
    73 extern int FULLSCREEN_ToggleFromWimp(_THIS);
    74 
    75 /* Wimp mode functions */
    76 extern SDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface * current,
    77                                       int width, int height, int bpp,
    78                                       Uint32 flags);
    79 extern void WIMP_DeleteWindow(_THIS);
    80 extern int WIMP_ToggleFromFullScreen(_THIS);
    81 
    82 /* Hardware surface functions - common to WIMP and FULLSCREEN */
    83 static int RISCOS_AllocHWSurface(_THIS, SDL_Surface * surface);
    84 static int RISCOS_LockHWSurface(_THIS, SDL_Surface * surface);
    85 static void RISCOS_UnlockHWSurface(_THIS, SDL_Surface * surface);
    86 static void RISCOS_FreeHWSurface(_THIS, SDL_Surface * surface);
    87 
    88 /* RISC OS driver bootstrap functions */
    89 
    90 static int
    91 RISCOS_Available(void)
    92 {
    93     return (1);
    94 }
    95 
    96 static void
    97 RISCOS_DeleteDevice(SDL_VideoDevice * device)
    98 {
    99     SDL_free(device->hidden);
   100     SDL_free(device);
   101 }
   102 
   103 static SDL_VideoDevice *
   104 RISCOS_CreateDevice(int devindex)
   105 {
   106     SDL_VideoDevice *device;
   107 
   108     /* Initialize all variables that we clean on shutdown */
   109     device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
   110     if (device) {
   111         SDL_memset(device, 0, (sizeof *device));
   112         device->hidden = (struct SDL_PrivateVideoData *)
   113             SDL_malloc((sizeof *device->hidden));
   114     }
   115     if ((device == NULL) || (device->hidden == NULL)) {
   116         SDL_OutOfMemory();
   117         if (device) {
   118             SDL_free(device);
   119         }
   120         return (0);
   121     }
   122     SDL_memset(device->hidden, 0, (sizeof *device->hidden));
   123 
   124     /* Set the function pointers */
   125     device->VideoInit = RISCOS_VideoInit;
   126     device->VideoQuit = RISCOS_VideoQuit;
   127 
   128     device->ListModes = RISCOS_ListModes;
   129     device->SetVideoMode = RISCOS_SetVideoMode;
   130     device->CreateYUVOverlay = NULL;
   131     device->AllocHWSurface = RISCOS_AllocHWSurface;
   132     device->CheckHWBlit = NULL;
   133     device->FillHWRect = NULL;
   134     device->SetHWColorKey = NULL;
   135     device->SetHWAlpha = NULL;
   136     device->LockHWSurface = RISCOS_LockHWSurface;
   137     device->UnlockHWSurface = RISCOS_UnlockHWSurface;
   138     device->FreeHWSurface = RISCOS_FreeHWSurface;
   139 
   140     device->FreeWMCursor = RISCOS_FreeWMCursor;
   141     device->CreateWMCursor = RISCOS_CreateWMCursor;
   142     device->CheckMouseMode = RISCOS_CheckMouseMode;
   143     device->GrabInput = RISCOS_GrabInput;
   144 
   145     device->InitOSKeymap = RISCOS_InitOSKeymap;
   146 
   147     device->GetWMInfo = RISCOS_GetWmInfo;
   148 
   149     device->free = RISCOS_DeleteDevice;
   150 
   151 /* Can't get Toggle screen to work if program starts up in Full screen mode so
   152    disable it here and re-enable it when a wimp screen is chosen */
   153     device->ToggleFullScreen = NULL;    /*RISCOS_ToggleFullScreen; */
   154 
   155     /* Set other entries for fullscreen mode */
   156     FULLSCREEN_SetDeviceMode(device);
   157 
   158     /* Mouse pointer needs to use the WIMP ShowCursor version so
   159        that it doesn't modify the pointer until the SDL Window is
   160        entered or the application goes full screen */
   161     device->ShowWMCursor = WIMP_ShowWMCursor;
   162 
   163     return device;
   164 }
   165 
   166 VideoBootStrap RISCOS_bootstrap = {
   167     RISCOSVID_DRIVER_NAME, "RISC OS video driver",
   168     RISCOS_Available, RISCOS_CreateDevice
   169 };
   170 
   171 
   172 int
   173 RISCOS_VideoInit(_THIS, SDL_PixelFormat * vformat)
   174 {
   175     _kernel_swi_regs regs;
   176     int vars[4], vals[3];
   177 
   178     if (RISCOS_InitTask() == 0) {
   179         SDL_SetError("Unable to start task");
   180         return 0;
   181     }
   182 
   183     vars[0] = 9;                /* Log base 2 bpp */
   184     vars[1] = 11;               /* XWndLimit - num x pixels -1 */
   185     vars[2] = 12;               /* YWndLimit - num y pixels -1 */
   186     vars[3] = -1;               /* Terminate list */
   187     regs.r[0] = (int) vars;
   188     regs.r[1] = (int) vals;
   189 
   190     _kernel_swi(OS_ReadVduVariables, &regs, &regs);
   191     vformat->BitsPerPixel = (1 << vals[0]);
   192 
   193     /* Determine the current screen size */
   194     this->info.current_w = vals[1] + 1;
   195     this->info.current_h = vals[2] + 1;
   196 
   197     /* Minimum bpp for SDL is 8 */
   198     if (vformat->BitsPerPixel < 8)
   199         vformat->BitsPerPixel = 8;
   200 
   201 
   202     switch (vformat->BitsPerPixel) {
   203     case 15:
   204     case 16:
   205         vformat->Bmask = 0x00007c00;
   206         vformat->Gmask = 0x000003e0;
   207         vformat->Rmask = 0x0000001f;
   208         vformat->BitsPerPixel = 16;     /* SDL wants actual number of bits used */
   209         vformat->BytesPerPixel = 2;
   210         break;
   211 
   212     case 24:
   213     case 32:
   214         vformat->Bmask = 0x00ff0000;
   215         vformat->Gmask = 0x0000ff00;
   216         vformat->Rmask = 0x000000ff;
   217         vformat->BytesPerPixel = 4;
   218         break;
   219 
   220     default:
   221         vformat->Bmask = 0;
   222         vformat->Gmask = 0;
   223         vformat->Rmask = 0;
   224         vformat->BytesPerPixel = 1;
   225         break;
   226     }
   227 
   228     /* Fill in some window manager capabilities */
   229     this->info.wm_available = 1;
   230 
   231     /* We're done! */
   232     return (0);
   233 }
   234 
   235 /* Note:  If we are terminated, this could be called in the middle of
   236    another SDL video routine -- notably UpdateRects.
   237 */
   238 void
   239 RISCOS_VideoQuit(_THIS)
   240 {
   241     RISCOS_ExitTask();
   242 
   243     if (this->hidden->alloc_bank)
   244         SDL_free(this->hidden->alloc_bank);
   245     this->hidden->alloc_bank = 0;
   246 }
   247 
   248 
   249 SDL_Rect **
   250 RISCOS_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
   251 {
   252     if (flags & SDL_FULLSCREEN) {
   253         /* Build mode list when first required. */
   254         if (SDL_nummodes[0] == 0)
   255             FULLSCREEN_BuildModeList(this);
   256 
   257         return (SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1]);
   258     } else
   259         return (SDL_Rect **) - 1;
   260 }
   261 
   262 
   263 /* Set up video mode */
   264 SDL_Surface *
   265 RISCOS_SetVideoMode(_THIS, SDL_Surface * current,
   266                     int width, int height, int bpp, Uint32 flags)
   267 {
   268     if (flags & SDL_FULLSCREEN) {
   269         RISCOS_StoreWimpMode();
   270         /* Dump wimp window on switch to full screen */
   271         if (this->hidden->window_handle)
   272             WIMP_DeleteWindow(this);
   273 
   274         return FULLSCREEN_SetVideoMode(this, current, width, height, bpp,
   275                                        flags);
   276     } else {
   277         RISCOS_RestoreWimpMode();
   278         return WIMP_SetVideoMode(this, current, width, height, bpp, flags);
   279     }
   280 }
   281 
   282 
   283 /* We don't actually allow hardware surfaces other than the main one */
   284 static int
   285 RISCOS_AllocHWSurface(_THIS, SDL_Surface * surface)
   286 {
   287     return (-1);
   288 }
   289 static void
   290 RISCOS_FreeHWSurface(_THIS, SDL_Surface * surface)
   291 {
   292     return;
   293 }
   294 
   295 /* We need to wait for vertical retrace on page flipped displays */
   296 static int
   297 RISCOS_LockHWSurface(_THIS, SDL_Surface * surface)
   298 {
   299     return (0);
   300 }
   301 
   302 static void
   303 RISCOS_UnlockHWSurface(_THIS, SDL_Surface * surface)
   304 {
   305     return;
   306 }
   307 
   308 
   309 int
   310 RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo * info)
   311 {
   312     SDL_VERSION(&(info->version));
   313     info->wimpVersion = RISCOS_GetWimpVersion();
   314     info->taskHandle = RISCOS_GetTaskHandle();
   315     info->window = this->hidden->window_handle;
   316 
   317     return 1;
   318 }
   319 
   320 /* Toggle full screen mode.
   321    Returns 1 if successful otherwise 0
   322 */
   323 
   324 int
   325 RISCOS_ToggleFullScreen(_THIS, int fullscreen)
   326 {
   327     if (fullscreen) {
   328         return FULLSCREEN_ToggleFromWimp(this);
   329     } else {
   330         return WIMP_ToggleFromFullScreen(this);
   331     }
   332 
   333     return 0;
   334 }
   335 
   336 /* vi: set ts=4 sw=4 expandtab: */