src/video/uikit/SDL_uikitvideo.m
author Holmes Futrell
Fri, 15 Aug 2008 00:42:14 +0000
branchgsoc2008_iphone
changeset 2425 491958a6c881
parent 2352 1ecbeff9eb4c
child 2451 28286ecb3f15
permissions -rw-r--r--
Removed log messages (printf and NSLog)
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 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     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 /* Dummy SDL video driver implementation; this is just enough to make an
    25  *  SDL-based application THINK it's got a working video driver, for
    26  *  applications that call SDL_Init(SDL_INIT_VIDEO) when they don't need it,
    27  *  and also for use as a collection of stubs when porting SDL to a new
    28  *  platform for which you haven't yet written a valid video driver.
    29  *
    30  * This is also a great way to determine bottlenecks: if you think that SDL
    31  *  is a performance problem for a given platform, enable this driver, and
    32  *  then see if your application runs faster without video overhead.
    33  *
    34  * Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion
    35  *  of this was cut-and-pasted from Stephane Peter's work in the AAlib
    36  *  SDL video driver.  Renamed to "DUMMY" by Sam Lantinga.
    37  */
    38 
    39 #include "SDL_video.h"
    40 #include "SDL_mouse.h"
    41 #include "../SDL_sysvideo.h"
    42 #include "../SDL_pixels_c.h"
    43 #include "../../events/SDL_events_c.h"
    44 
    45 #include "SDL_uikitvideo.h"
    46 #include "SDL_uikitevents.h"
    47 #include "SDL_uikitwindow.h"
    48 #include "SDL_uikitopengles.h"
    49 
    50 #include "SDL_renderer_sw.h"
    51 #include "SDL_renderer_gles.h"
    52 
    53 #define UIKITVID_DRIVER_NAME "uikit"
    54 
    55 /* Initialization/Query functions */
    56 static int UIKit_VideoInit(_THIS);
    57 static int UIKit_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
    58 static void UIKit_VideoQuit(_THIS);
    59 
    60 /* DUMMY driver bootstrap functions */
    61 
    62 static int
    63 UIKit_Available(void)
    64 {
    65 	return (1);
    66 }
    67 
    68 static void UIKit_DeleteDevice(SDL_VideoDevice * device)
    69 {
    70     SDL_free(device);
    71 }
    72 
    73 static SDL_VideoDevice *
    74 UIKit_CreateDevice(int devindex)
    75 {
    76     SDL_VideoDevice *device;
    77 
    78     /* Initialize all variables that we clean on shutdown */
    79     device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
    80     if (!device) {
    81         SDL_OutOfMemory();
    82         if (device) {
    83             SDL_free(device);
    84         }
    85         return (0);
    86     }
    87 
    88     /* Set the function pointers */
    89     device->VideoInit = UIKit_VideoInit;
    90     device->VideoQuit = UIKit_VideoQuit;
    91     device->SetDisplayMode = UIKit_SetDisplayMode;
    92     device->PumpEvents = UIKit_PumpEvents;
    93 	device->CreateWindow = UIKit_CreateWindow;
    94 	device->DestroyWindow = UIKit_DestroyWindow;
    95 	
    96 	
    97 	/* OpenGL (ES) functions */
    98 	device->GL_MakeCurrent		= UIKit_GL_MakeCurrent;
    99 	device->GL_SwapWindow		= UIKit_GL_SwapWindow;
   100 	device->GL_CreateContext	= UIKit_GL_CreateContext;
   101 	device->GL_DeleteContext    = UIKit_GL_DeleteContext;
   102 	device->GL_GetProcAddress   = UIKit_GL_GetProcAddress;
   103 	device->GL_LoadLibrary	    = UIKit_GL_LoadLibrary;
   104 	device->free = UIKit_DeleteDevice;
   105 
   106 	device->gl_config.accelerated = 1;
   107 	
   108     return device;
   109 }
   110 
   111 VideoBootStrap UIKIT_bootstrap = {
   112     UIKITVID_DRIVER_NAME, "SDL UIKit video driver",
   113     UIKit_Available, UIKit_CreateDevice
   114 };
   115 
   116 
   117 int
   118 UIKit_VideoInit(_THIS)
   119 {
   120     SDL_DisplayMode mode;
   121 		
   122 	_this->gl_config.driver_loaded = 1;
   123 
   124 	SDL_VideoDisplay display;
   125 	SDL_zero(display);
   126 
   127     /* Use a 32-bpp desktop mode */
   128     SDL_zero(mode);
   129 	mode.format = SDL_PIXELFORMAT_ABGR8888;
   130     mode.w = 320;
   131     mode.h = 480;
   132     mode.refresh_rate = 0;
   133     mode.driverdata = NULL;
   134 		
   135 	display.num_display_modes = 1;
   136 	display.max_display_modes = 1;
   137 	display.display_modes = (SDL_DisplayMode *)SDL_malloc(display.max_display_modes * sizeof(SDL_DisplayMode));
   138 	
   139 	display.display_modes[0] = mode;
   140 	display.desktop_mode = mode;
   141 	display.fullscreen_mode = mode;
   142 	display.current_mode = mode;
   143 		
   144 	SDL_AddVideoDisplay(&display);
   145 
   146     /* We're done! */
   147     return 0;
   148 }
   149 
   150 static int
   151 UIKit_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
   152 {
   153     return 0;
   154 }
   155 
   156 void
   157 UIKit_VideoQuit(_THIS)
   158 {
   159 }
   160 
   161 /* vi: set ts=4 sw=4 expandtab: */