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