src/video/android/SDL_androidvideo.c
author Paul Hunkin <paul@bieh.net>
Tue, 27 Jul 2010 10:49:11 +0200
changeset 4716 f2c2a33a1a38
parent 4713 ba38983b10c2
child 4960 0ab2492f2e17
permissions -rw-r--r--
Added resize hander stub and initial screen size setter
     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_androidrender.h"
    36 
    37 #define ANDROID_VID_DRIVER_NAME "Android"
    38 
    39 /* Initialization/Query functions */
    40 static int Android_VideoInit(_THIS);
    41 static int Android_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
    42 static void Android_VideoQuit(_THIS);
    43 
    44 /* GL functions (SDL_androidgl.c) */
    45 extern int Android_GL_LoadLibrary(_THIS, const char *path);
    46 extern void *Android_GL_GetProcAddress(_THIS, const char *proc);
    47 extern void Android_GL_UnloadLibrary(_THIS);
    48 //extern int *Android_GL_GetVisual(_THIS, Display * display, int screen);
    49 extern SDL_GLContext Android_GL_CreateContext(_THIS, SDL_Window * window);
    50 extern int Android_GL_MakeCurrent(_THIS, SDL_Window * window,
    51                               SDL_GLContext context);
    52 extern int Android_GL_SetSwapInterval(_THIS, int interval);
    53 extern int Android_GL_GetSwapInterval(_THIS);
    54 extern void Android_GL_SwapWindow(_THIS, SDL_Window * window);
    55 extern void Android_GL_DeleteContext(_THIS, SDL_GLContext context);
    56 
    57 /* Android driver bootstrap functions */
    58 
    59 
    60 //These are filled in with real values in Android_SetScreenResolution on 
    61 //init (before SDL_Main())
    62 static int iScreenWidth = 320;
    63 static int iScreenHeight = 240;
    64 
    65 
    66 static int
    67 Android_Available(void)
    68 {
    69     return 1;
    70 }
    71 
    72 static void
    73 Android_DeleteDevice(SDL_VideoDevice * device)
    74 {
    75     SDL_free(device);
    76 }
    77 
    78 static SDL_VideoDevice *
    79 Android_CreateDevice(int devindex)
    80 {
    81     printf("Creating video device\n");
    82     SDL_VideoDevice *device;
    83 
    84     /* Initialize all variables that we clean on shutdown */
    85     device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
    86     if (!device) {
    87         SDL_OutOfMemory();
    88         if (device) {
    89             SDL_free(device);
    90         }
    91         return (0);
    92     }
    93 
    94     /* Set the function pointers */
    95     device->VideoInit = Android_VideoInit;
    96     device->VideoQuit = Android_VideoQuit;
    97     device->SetDisplayMode = Android_SetDisplayMode;
    98     device->PumpEvents = Android_PumpEvents;
    99    
   100     device->free = Android_DeleteDevice;
   101 
   102     /* GL pointers */
   103     device->GL_LoadLibrary = Android_GL_LoadLibrary;
   104     device->GL_GetProcAddress = Android_GL_GetProcAddress;
   105     device->GL_UnloadLibrary = Android_GL_UnloadLibrary;
   106     device->GL_CreateContext = Android_GL_CreateContext;
   107     device->GL_MakeCurrent = Android_GL_MakeCurrent;
   108     device->GL_SetSwapInterval = Android_GL_SetSwapInterval;
   109     device->GL_GetSwapInterval = Android_GL_GetSwapInterval;
   110     device->GL_SwapWindow = Android_GL_SwapWindow;
   111     device->GL_DeleteContext = Android_GL_DeleteContext;
   112 
   113     return device;
   114 }
   115 
   116 VideoBootStrap Android_bootstrap = {
   117     ANDROID_VID_DRIVER_NAME, "SDL Android video driver",
   118     Android_Available, Android_CreateDevice
   119 };
   120 
   121 
   122 int
   123 Android_VideoInit(_THIS)
   124 {
   125     SDL_DisplayMode mode;
   126 
   127     /* Use a fake 32-bpp desktop mode */
   128     mode.format = SDL_PIXELFORMAT_RGB888;
   129     mode.w = iScreenWidth;
   130     mode.h = iScreenHeight;
   131     mode.refresh_rate = 0;
   132     mode.driverdata = NULL;
   133     if (SDL_AddBasicVideoDisplay(&mode) < 0) {
   134         return -1;
   135     }
   136     SDL_AddRenderDriver(&_this->displays[0], &Android_RenderDriver);
   137 
   138     SDL_zero(mode);
   139     SDL_AddDisplayMode(&_this->displays[0], &mode);
   140 
   141     Android_InitEvents();
   142 
   143     /* We're done! */
   144     return 0;
   145 }
   146 
   147 static int
   148 Android_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
   149 {
   150     return 0;
   151 }
   152 
   153 void
   154 Android_VideoQuit(_THIS)
   155 {
   156 }
   157 
   158 
   159 void Android_SetScreenResolution(int width, int height){
   160     iScreenWidth = width;
   161     iScreenHeight = height;   
   162 }
   163 
   164 
   165 
   166 /* vi: set ts=4 sw=4 expandtab: */