src/video/android/SDL_androidvideo.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Sat, 01 Jun 2013 21:11:52 +0200
changeset 7253 eee81780005e
parent 7191 75360622e65f
child 7659 ac4ce59c40e7
permissions -rw-r--r--
Removed debug output.
     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_ANDROID
    24 
    25 /* Android SDL video driver implementation
    26 */
    27 
    28 #include "SDL_video.h"
    29 #include "SDL_mouse.h"
    30 #include "../SDL_sysvideo.h"
    31 #include "../SDL_pixels_c.h"
    32 #include "../../events/SDL_events_c.h"
    33 #include "../../events/SDL_windowevents_c.h"
    34 
    35 #include "SDL_androidvideo.h"
    36 #include "SDL_androidclipboard.h"
    37 #include "SDL_androidevents.h"
    38 #include "SDL_androidkeyboard.h"
    39 #include "SDL_androidwindow.h"
    40 
    41 #define ANDROID_VID_DRIVER_NAME "Android"
    42 
    43 /* Initialization/Query functions */
    44 static int Android_VideoInit(_THIS);
    45 static void Android_VideoQuit(_THIS);
    46 
    47 /* GL functions (SDL_androidgl.c) */
    48 extern int Android_GL_LoadLibrary(_THIS, const char *path);
    49 extern void *Android_GL_GetProcAddress(_THIS, const char *proc);
    50 extern void Android_GL_UnloadLibrary(_THIS);
    51 extern SDL_GLContext Android_GL_CreateContext(_THIS, SDL_Window * window);
    52 extern int Android_GL_MakeCurrent(_THIS, SDL_Window * window,
    53                               SDL_GLContext context);
    54 extern int Android_GL_SetSwapInterval(_THIS, int interval);
    55 extern int Android_GL_GetSwapInterval(_THIS);
    56 extern void Android_GL_SwapWindow(_THIS, SDL_Window * window);
    57 extern void Android_GL_DeleteContext(_THIS, SDL_GLContext context);
    58 
    59 /* Android driver bootstrap functions */
    60 
    61 
    62 /* These are filled in with real values in Android_SetScreenResolution on init (before SDL_main()) */
    63 int Android_ScreenWidth = 0;
    64 int Android_ScreenHeight = 0;
    65 Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
    66 SDL_sem *Android_PauseSem = NULL, *Android_ResumeSem = NULL;
    67 
    68 /* Currently only one window */
    69 SDL_Window *Android_Window = NULL;
    70 
    71 static int
    72 Android_Available(void)
    73 {
    74     return 1;
    75 }
    76 
    77 static void
    78 Android_DeleteDevice(SDL_VideoDevice * device)
    79 {
    80     SDL_free(device);
    81 }
    82 
    83 static SDL_VideoDevice *
    84 Android_CreateDevice(int devindex)
    85 {
    86     SDL_VideoDevice *device;
    87     SDL_VideoData *data;
    88 
    89     /* Initialize all variables that we clean on shutdown */
    90     device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
    91     if (!device) {
    92         SDL_OutOfMemory();
    93         return NULL;
    94     }
    95 
    96     data = (SDL_VideoData*) SDL_calloc(1, sizeof(SDL_VideoData));
    97     if (!data) {
    98         SDL_OutOfMemory();
    99         SDL_free(device);
   100         return NULL;
   101     }
   102 
   103     device->driverdata = data;
   104 
   105     /* Set the function pointers */
   106     device->VideoInit = Android_VideoInit;
   107     device->VideoQuit = Android_VideoQuit;
   108     device->PumpEvents = Android_PumpEvents;
   109 
   110     device->CreateWindow = Android_CreateWindow;
   111     device->SetWindowTitle = Android_SetWindowTitle;
   112     device->DestroyWindow = Android_DestroyWindow;
   113 
   114     device->free = Android_DeleteDevice;
   115 
   116     /* GL pointers */
   117     device->GL_LoadLibrary = Android_GL_LoadLibrary;
   118     device->GL_GetProcAddress = Android_GL_GetProcAddress;
   119     device->GL_UnloadLibrary = Android_GL_UnloadLibrary;
   120     device->GL_CreateContext = Android_GL_CreateContext;
   121     device->GL_MakeCurrent = Android_GL_MakeCurrent;
   122     device->GL_SetSwapInterval = Android_GL_SetSwapInterval;
   123     device->GL_GetSwapInterval = Android_GL_GetSwapInterval;
   124     device->GL_SwapWindow = Android_GL_SwapWindow;
   125     device->GL_DeleteContext = Android_GL_DeleteContext;
   126 
   127     /* Text input */
   128     device->StartTextInput = Android_StartTextInput;
   129     device->StopTextInput = Android_StopTextInput;
   130     device->SetTextInputRect = Android_SetTextInputRect;
   131 
   132     /* Screen keyboard */
   133     device->HasScreenKeyboardSupport = Android_HasScreenKeyboardSupport;
   134     device->IsScreenKeyboardShown = Android_IsScreenKeyboardShown;
   135 
   136     /* Clipboard */
   137     device->SetClipboardText = Android_SetClipboardText;
   138     device->GetClipboardText = Android_GetClipboardText;
   139     device->HasClipboardText = Android_HasClipboardText;
   140 
   141     return device;
   142 }
   143 
   144 VideoBootStrap Android_bootstrap = {
   145     ANDROID_VID_DRIVER_NAME, "SDL Android video driver",
   146     Android_Available, Android_CreateDevice
   147 };
   148 
   149 
   150 int
   151 Android_VideoInit(_THIS)
   152 {
   153     SDL_DisplayMode mode;
   154 
   155     mode.format = Android_ScreenFormat;
   156     mode.w = Android_ScreenWidth;
   157     mode.h = Android_ScreenHeight;
   158     mode.refresh_rate = 0;
   159     mode.driverdata = NULL;
   160     if (SDL_AddBasicVideoDisplay(&mode) < 0) {
   161         return -1;
   162     }
   163 
   164     SDL_AddDisplayMode(&_this->displays[0], &mode);
   165 
   166     Android_InitKeyboard();
   167 
   168     /* We're done! */
   169     return 0;
   170 }
   171 
   172 void
   173 Android_VideoQuit(_THIS)
   174 {
   175 }
   176 
   177 /* This function gets called before VideoInit() */
   178 void
   179 Android_SetScreenResolution(int width, int height, Uint32 format)
   180 {
   181     Android_ScreenWidth = width;
   182     Android_ScreenHeight = height;
   183     Android_ScreenFormat = format;
   184 
   185     if (Android_Window) {
   186         SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESIZED, width, height);
   187     }
   188 }
   189 
   190 #endif /* SDL_VIDEO_DRIVER_ANDROID */
   191 
   192 /* vi: set ts=4 sw=4 expandtab: */