src/video/uikit/SDL_uikitvideo.m
author Sam Lantinga <slouken@libsdl.org>
Fri, 15 Feb 2013 08:47:44 -0800
changeset 6885 700f1b25f77f
parent 6714 146d1d7ecdc4
child 7037 3fedf1f25b94
permissions -rw-r--r--
Happy New Year!
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 #include "SDL_config.h"
    22 
    23 #if SDL_VIDEO_DRIVER_UIKIT
    24 
    25 #import <UIKit/UIKit.h>
    26 
    27 #include "SDL_video.h"
    28 #include "SDL_mouse.h"
    29 #include "../SDL_sysvideo.h"
    30 #include "../SDL_pixels_c.h"
    31 #include "../../events/SDL_events_c.h"
    32 
    33 #include "SDL_uikitvideo.h"
    34 #include "SDL_uikitevents.h"
    35 #include "SDL_uikitmodes.h"
    36 #include "SDL_uikitwindow.h"
    37 #include "SDL_uikitopengles.h"
    38 
    39 #define UIKITVID_DRIVER_NAME "uikit"
    40 
    41 /* Initialization/Query functions */
    42 static int UIKit_VideoInit(_THIS);
    43 static void UIKit_VideoQuit(_THIS);
    44 
    45 /* DUMMY driver bootstrap functions */
    46 
    47 static int
    48 UIKit_Available(void)
    49 {
    50     return 1;
    51 }
    52 
    53 static void UIKit_DeleteDevice(SDL_VideoDevice * device)
    54 {
    55     SDL_free(device);
    56 }
    57 
    58 static SDL_VideoDevice *
    59 UIKit_CreateDevice(int devindex)
    60 {
    61     SDL_VideoDevice *device;
    62 
    63     /* Initialize all variables that we clean on shutdown */
    64     device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
    65     if (!device) {
    66         SDL_OutOfMemory();
    67         if (device) {
    68             SDL_free(device);
    69         }
    70         return (0);
    71     }
    72 
    73     /* Set the function pointers */
    74     device->VideoInit = UIKit_VideoInit;
    75     device->VideoQuit = UIKit_VideoQuit;
    76     device->GetDisplayModes = UIKit_GetDisplayModes;
    77     device->SetDisplayMode = UIKit_SetDisplayMode;
    78     device->PumpEvents = UIKit_PumpEvents;
    79     device->CreateWindow = UIKit_CreateWindow;
    80     device->ShowWindow = UIKit_ShowWindow;
    81     device->HideWindow = UIKit_HideWindow;
    82     device->RaiseWindow = UIKit_RaiseWindow;
    83     device->SetWindowFullscreen = UIKit_SetWindowFullscreen;
    84     device->DestroyWindow = UIKit_DestroyWindow;
    85     device->GetWindowWMInfo = UIKit_GetWindowWMInfo;
    86 
    87     /* !!! FIXME: implement SetWindowBordered */
    88 
    89     device->SDL_HasScreenKeyboardSupport = UIKit_HasScreenKeyboardSupport;
    90     device->SDL_ShowScreenKeyboard = UIKit_ShowScreenKeyboard;
    91     device->SDL_HideScreenKeyboard = UIKit_HideScreenKeyboard;
    92     device->SDL_IsScreenKeyboardShown = UIKit_IsScreenKeyboardShown;
    93 
    94     /* OpenGL (ES) functions */
    95     device->GL_MakeCurrent        = UIKit_GL_MakeCurrent;
    96     device->GL_SwapWindow        = UIKit_GL_SwapWindow;
    97     device->GL_CreateContext    = UIKit_GL_CreateContext;
    98     device->GL_DeleteContext    = UIKit_GL_DeleteContext;
    99     device->GL_GetProcAddress   = UIKit_GL_GetProcAddress;
   100     device->GL_LoadLibrary        = UIKit_GL_LoadLibrary;
   101     device->free = UIKit_DeleteDevice;
   102 
   103     device->gl_config.accelerated = 1;
   104 
   105     return device;
   106 }
   107 
   108 VideoBootStrap UIKIT_bootstrap = {
   109     UIKITVID_DRIVER_NAME, "SDL UIKit video driver",
   110     UIKit_Available, UIKit_CreateDevice
   111 };
   112 
   113 
   114 int
   115 UIKit_VideoInit(_THIS)
   116 {
   117     _this->gl_config.driver_loaded = 1;
   118 
   119     if (UIKit_InitModes(_this) < 0) {
   120         return -1;
   121     }
   122     return 0;
   123 }
   124 
   125 void
   126 UIKit_VideoQuit(_THIS)
   127 {
   128     UIKit_QuitModes(_this);
   129 }
   130 
   131 /*
   132  * iOS log support.
   133  *
   134  * This doesn't really have aything to do with the interfaces of the SDL video
   135  *  subsystem, but we need to stuff this into an Objective-C source code file.
   136  */
   137 
   138 void SDL_NSLog(const char *text)
   139 {
   140     NSLog(@"%s", text);
   141 }
   142 
   143 #endif /* SDL_VIDEO_DRIVER_UIKIT */
   144 
   145 /* vi: set ts=4 sw=4 expandtab: */