src/video/android/SDL_androidvideo.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 13 Jan 2011 15:10:17 -0800
changeset 4998 a514bfe6952a
parent 4981 55b82067815b
child 5001 77df56570442
permissions -rw-r--r--
The window is changed to reflect the actual screen dimensions, for now.
Implemented SDL_SetWindowTitle(), which turned out to be fairly complex
     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 #include "SDL_androidwindow.h"
    37 
    38 #define ANDROID_VID_DRIVER_NAME "Android"
    39 
    40 /* Initialization/Query functions */
    41 static int Android_VideoInit(_THIS);
    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 int Android_ScreenWidth = 0;
    63 int Android_ScreenHeight = 0;
    64 Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
    65 
    66 
    67 static int
    68 Android_Available(void)
    69 {
    70     return 1;
    71 }
    72 
    73 static void
    74 Android_DeleteDevice(SDL_VideoDevice * device)
    75 {
    76     SDL_free(device);
    77 }
    78 
    79 static SDL_VideoDevice *
    80 Android_CreateDevice(int devindex)
    81 {
    82     printf("Creating video device\n");
    83     SDL_VideoDevice *device;
    84 
    85     /* Initialize all variables that we clean on shutdown */
    86     device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
    87     if (!device) {
    88         SDL_OutOfMemory();
    89         if (device) {
    90             SDL_free(device);
    91         }
    92         return (0);
    93     }
    94 
    95     /* Set the function pointers */
    96     device->VideoInit = Android_VideoInit;
    97     device->VideoQuit = Android_VideoQuit;
    98     device->PumpEvents = Android_PumpEvents;
    99 
   100     device->CreateWindow = Android_CreateWindow;
   101     device->SetWindowTitle = Android_SetWindowTitle;
   102     device->DestroyWindow = Android_DestroyWindow;
   103 
   104     device->free = Android_DeleteDevice;
   105 
   106     /* GL pointers */
   107     device->GL_LoadLibrary = Android_GL_LoadLibrary;
   108     device->GL_GetProcAddress = Android_GL_GetProcAddress;
   109     device->GL_UnloadLibrary = Android_GL_UnloadLibrary;
   110     device->GL_CreateContext = Android_GL_CreateContext;
   111     device->GL_MakeCurrent = Android_GL_MakeCurrent;
   112     device->GL_SetSwapInterval = Android_GL_SetSwapInterval;
   113     device->GL_GetSwapInterval = Android_GL_GetSwapInterval;
   114     device->GL_SwapWindow = Android_GL_SwapWindow;
   115     device->GL_DeleteContext = Android_GL_DeleteContext;
   116 
   117     return device;
   118 }
   119 
   120 VideoBootStrap Android_bootstrap = {
   121     ANDROID_VID_DRIVER_NAME, "SDL Android video driver",
   122     Android_Available, Android_CreateDevice
   123 };
   124 
   125 
   126 int
   127 Android_VideoInit(_THIS)
   128 {
   129     SDL_DisplayMode mode;
   130 
   131     mode.format = Android_ScreenFormat;
   132     mode.w = Android_ScreenWidth;
   133     mode.h = Android_ScreenHeight;
   134     mode.refresh_rate = 0;
   135     mode.driverdata = NULL;
   136     if (SDL_AddBasicVideoDisplay(&mode) < 0) {
   137         return -1;
   138     }
   139 
   140     SDL_zero(mode);
   141     SDL_AddDisplayMode(&_this->displays[0], &mode);
   142 
   143     Android_InitKeyboard();
   144 
   145     /* We're done! */
   146     return 0;
   147 }
   148 
   149 void
   150 Android_VideoQuit(_THIS)
   151 {
   152 }
   153 
   154 /* This function gets called before VideoInit() */
   155 void
   156 Android_SetScreenResolution(int width, int height, Uint32 format)
   157 {
   158     Android_ScreenWidth = width;
   159     Android_ScreenHeight = height;   
   160     Android_ScreenFormat = format;
   161 }
   162 
   163 /* vi: set ts=4 sw=4 expandtab: */