src/video/android/SDL_androidvideo.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 12 Jan 2011 13:52:41 -0800
changeset 4980 d9fdff945ec9
parent 4963 604077962776
child 4981 55b82067815b
permissions -rw-r--r--
A bit of cleanup in the Android driver
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2010 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 /* Android SDL video driver implementation
    25 */
    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_androidvideo.h"
    34 #include "SDL_androidevents.h"
    35 #include "SDL_androidkeyboard.h"
    36 
    37 #define ANDROID_VID_DRIVER_NAME "Android"
    38 
    39 /* Initialization/Query functions */
    40 static int Android_VideoInit(_THIS);
    41 static void Android_VideoQuit(_THIS);
    42 
    43 /* GL functions (SDL_androidgl.c) */
    44 extern int Android_GL_LoadLibrary(_THIS, const char *path);
    45 extern void *Android_GL_GetProcAddress(_THIS, const char *proc);
    46 extern void Android_GL_UnloadLibrary(_THIS);
    47 //extern int *Android_GL_GetVisual(_THIS, Display * display, int screen);
    48 extern SDL_GLContext Android_GL_CreateContext(_THIS, SDL_Window * window);
    49 extern int Android_GL_MakeCurrent(_THIS, SDL_Window * window,
    50                               SDL_GLContext context);
    51 extern int Android_GL_SetSwapInterval(_THIS, int interval);
    52 extern int Android_GL_GetSwapInterval(_THIS);
    53 extern void Android_GL_SwapWindow(_THIS, SDL_Window * window);
    54 extern void Android_GL_DeleteContext(_THIS, SDL_GLContext context);
    55 
    56 /* Android driver bootstrap functions */
    57 
    58 
    59 //These are filled in with real values in Android_SetScreenResolution on 
    60 //init (before SDL_Main())
    61 static int iScreenWidth = 320;
    62 static int iScreenHeight = 240;
    63 
    64 
    65 static int
    66 Android_Available(void)
    67 {
    68     return 1;
    69 }
    70 
    71 static void
    72 Android_DeleteDevice(SDL_VideoDevice * device)
    73 {
    74     SDL_free(device);
    75 }
    76 
    77 static SDL_VideoDevice *
    78 Android_CreateDevice(int devindex)
    79 {
    80     printf("Creating video device\n");
    81     SDL_VideoDevice *device;
    82 
    83     /* Initialize all variables that we clean on shutdown */
    84     device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
    85     if (!device) {
    86         SDL_OutOfMemory();
    87         if (device) {
    88             SDL_free(device);
    89         }
    90         return (0);
    91     }
    92 
    93     /* Set the function pointers */
    94     device->VideoInit = Android_VideoInit;
    95     device->VideoQuit = Android_VideoQuit;
    96     device->PumpEvents = Android_PumpEvents;
    97 
    98     device->free = Android_DeleteDevice;
    99 
   100     /* GL pointers */
   101     device->GL_LoadLibrary = Android_GL_LoadLibrary;
   102     device->GL_GetProcAddress = Android_GL_GetProcAddress;
   103     device->GL_UnloadLibrary = Android_GL_UnloadLibrary;
   104     device->GL_CreateContext = Android_GL_CreateContext;
   105     device->GL_MakeCurrent = Android_GL_MakeCurrent;
   106     device->GL_SetSwapInterval = Android_GL_SetSwapInterval;
   107     device->GL_GetSwapInterval = Android_GL_GetSwapInterval;
   108     device->GL_SwapWindow = Android_GL_SwapWindow;
   109     device->GL_DeleteContext = Android_GL_DeleteContext;
   110 
   111     return device;
   112 }
   113 
   114 VideoBootStrap Android_bootstrap = {
   115     ANDROID_VID_DRIVER_NAME, "SDL Android video driver",
   116     Android_Available, Android_CreateDevice
   117 };
   118 
   119 
   120 int
   121 Android_VideoInit(_THIS)
   122 {
   123     SDL_DisplayMode mode;
   124 
   125     /* Use a fake 32-bpp desktop mode */
   126     mode.format = SDL_PIXELFORMAT_BGR888;
   127     mode.w = iScreenWidth;
   128     mode.h = iScreenHeight;
   129     mode.refresh_rate = 0;
   130     mode.driverdata = NULL;
   131     if (SDL_AddBasicVideoDisplay(&mode) < 0) {
   132         return -1;
   133     }
   134 
   135     SDL_zero(mode);
   136     SDL_AddDisplayMode(&_this->displays[0], &mode);
   137 
   138     Android_InitKeyboard();
   139 
   140     /* We're done! */
   141     return 0;
   142 }
   143 
   144 void
   145 Android_VideoQuit(_THIS)
   146 {
   147 }
   148 
   149 
   150 void Android_SetScreenResolution(int width, int height){
   151     iScreenWidth = width;
   152     iScreenHeight = height;   
   153 }
   154 
   155 
   156 /* vi: set ts=4 sw=4 expandtab: */