src/video/android/SDL_androidvideo.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 12 Jan 2011 14:29:01 -0800
changeset 4981 55b82067815b
parent 4980 d9fdff945ec9
child 4998 a514bfe6952a
permissions -rw-r--r--
Fill in the video mode with the correct screen format
     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 Uint32 iScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
    62 static int iScreenWidth = 0;
    63 static int iScreenHeight = 0;
    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->PumpEvents = Android_PumpEvents;
    98 
    99     device->free = Android_DeleteDevice;
   100 
   101     /* GL pointers */
   102     device->GL_LoadLibrary = Android_GL_LoadLibrary;
   103     device->GL_GetProcAddress = Android_GL_GetProcAddress;
   104     device->GL_UnloadLibrary = Android_GL_UnloadLibrary;
   105     device->GL_CreateContext = Android_GL_CreateContext;
   106     device->GL_MakeCurrent = Android_GL_MakeCurrent;
   107     device->GL_SetSwapInterval = Android_GL_SetSwapInterval;
   108     device->GL_GetSwapInterval = Android_GL_GetSwapInterval;
   109     device->GL_SwapWindow = Android_GL_SwapWindow;
   110     device->GL_DeleteContext = Android_GL_DeleteContext;
   111 
   112     return device;
   113 }
   114 
   115 VideoBootStrap Android_bootstrap = {
   116     ANDROID_VID_DRIVER_NAME, "SDL Android video driver",
   117     Android_Available, Android_CreateDevice
   118 };
   119 
   120 
   121 int
   122 Android_VideoInit(_THIS)
   123 {
   124     SDL_DisplayMode mode;
   125 
   126     mode.format = iScreenFormat;
   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 void
   150 Android_SetScreenResolution(int width, int height, Uint32 format)
   151 {
   152     iScreenWidth = width;
   153     iScreenHeight = height;   
   154     iScreenFormat = format;
   155 }
   156 
   157 /* vi: set ts=4 sw=4 expandtab: */