SDL  2.0
SDL_androidvideo.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2016 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_internal.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_androidtouch.h"
40 #include "SDL_androidwindow.h"
41 
42 #define ANDROID_VID_DRIVER_NAME "Android"
43 
44 /* Initialization/Query functions */
45 static int Android_VideoInit(_THIS);
46 static void Android_VideoQuit(_THIS);
47 
48 #include "../SDL_egl_c.h"
49 /* GL functions (SDL_androidgl.c) */
50 extern SDL_GLContext Android_GLES_CreateContext(_THIS, SDL_Window * window);
51 extern int Android_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
52 extern void Android_GLES_SwapWindow(_THIS, SDL_Window * window);
53 extern int Android_GLES_LoadLibrary(_THIS, const char *path);
54 #define Android_GLES_GetProcAddress SDL_EGL_GetProcAddress
55 #define Android_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
56 #define Android_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
57 #define Android_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
58 #define Android_GLES_DeleteContext SDL_EGL_DeleteContext
59 
60 /* Android driver bootstrap functions */
61 
62 
63 /* These are filled in with real values in Android_SetScreenResolution on init (before SDL_main()) */
64 int Android_ScreenWidth = 0;
65 int Android_ScreenHeight = 0;
67 int Android_ScreenRate = 0;
68 
70 
71 /* Currently only one window */
73 
74 static int
75 Android_Available(void)
76 {
77  return 1;
78 }
79 
80 static void
81 Android_SuspendScreenSaver(_THIS)
82 {
84 }
85 
86 static void
87 Android_DeleteDevice(SDL_VideoDevice * device)
88 {
89  SDL_free(device->driverdata);
90  SDL_free(device);
91 }
92 
93 static SDL_VideoDevice *
94 Android_CreateDevice(int devindex)
95 {
96  SDL_VideoDevice *device;
98 
99  /* Initialize all variables that we clean on shutdown */
100  device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
101  if (!device) {
102  SDL_OutOfMemory();
103  return NULL;
104  }
105 
106  data = (SDL_VideoData*) SDL_calloc(1, sizeof(SDL_VideoData));
107  if (!data) {
108  SDL_OutOfMemory();
109  SDL_free(device);
110  return NULL;
111  }
112 
113  device->driverdata = data;
114 
115  /* Set the function pointers */
116  device->VideoInit = Android_VideoInit;
117  device->VideoQuit = Android_VideoQuit;
118  device->PumpEvents = Android_PumpEvents;
119 
124 
125  device->free = Android_DeleteDevice;
126 
127  /* GL pointers */
128  device->GL_LoadLibrary = Android_GLES_LoadLibrary;
129  device->GL_GetProcAddress = Android_GLES_GetProcAddress;
130  device->GL_UnloadLibrary = Android_GLES_UnloadLibrary;
131  device->GL_CreateContext = Android_GLES_CreateContext;
132  device->GL_MakeCurrent = Android_GLES_MakeCurrent;
133  device->GL_SetSwapInterval = Android_GLES_SetSwapInterval;
134  device->GL_GetSwapInterval = Android_GLES_GetSwapInterval;
135  device->GL_SwapWindow = Android_GLES_SwapWindow;
136  device->GL_DeleteContext = Android_GLES_DeleteContext;
137 
138  /* Screensaver */
139  device->SuspendScreenSaver = Android_SuspendScreenSaver;
140 
141  /* Text input */
145 
146  /* Screen keyboard */
149 
150  /* Clipboard */
154 
155  return device;
156 }
157 
158 VideoBootStrap Android_bootstrap = {
159  ANDROID_VID_DRIVER_NAME, "SDL Android video driver",
160  Android_Available, Android_CreateDevice
161 };
162 
163 
164 int
165 Android_VideoInit(_THIS)
166 {
168 
170  mode.w = Android_ScreenWidth;
171  mode.h = Android_ScreenHeight;
172  mode.refresh_rate = Android_ScreenRate;
173  mode.driverdata = NULL;
174  if (SDL_AddBasicVideoDisplay(&mode) < 0) {
175  return -1;
176  }
177 
178  SDL_AddDisplayMode(&_this->displays[0], &mode);
179 
181 
183 
184  /* We're done! */
185  return 0;
186 }
187 
188 void
189 Android_VideoQuit(_THIS)
190 {
192 }
193 
194 /* This function gets called before VideoInit() */
195 void
197 {
201  Android_ScreenRate = rate;
202 
203  if (Android_Window) {
204  SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESIZED, width, height);
205  }
206 }
207 
208 #endif /* SDL_VIDEO_DRIVER_ANDROID */
209 
210 /* vi: set ts=4 sw=4 expandtab: */
void Android_SetScreenResolution(int width, int height, Uint32 format, float rate)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1565
GLint GLint GLsizei width
Definition: SDL_opengl.h:1565
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:155
void Android_DestroyWindow(_THIS, SDL_Window *window)
SDL_bool Android_HasScreenKeyboardSupport(_THIS)
SDL_bool(* IsScreenKeyboardShown)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:263
SDL_Window * window
char * Android_GetClipboardText(_THIS)
void(* free)(_THIS)
Definition: SDL_sysvideo.h:345
int Android_ScreenHeight
int SDL_AddBasicVideoDisplay(const SDL_DisplayMode *desktop_mode)
Definition: SDL_video.c:579
int(* GL_SetSwapInterval)(_THIS, int interval)
Definition: SDL_sysvideo.h:240
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
The structure that defines a display mode.
Definition: SDL_video.h:53
void(* StartTextInput)(_THIS)
Definition: SDL_sysvideo.h:255
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
void(* GL_SwapWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:242
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1565
void Android_InitKeyboard(void)
void Android_InitTouch(void)
int(* GL_LoadLibrary)(_THIS, const char *path)
Definition: SDL_sysvideo.h:234
SDL_sem * Android_PauseSem
static SDL_VideoDevice * _this
Definition: SDL_video.c:114
void(* SetTextInputRect)(_THIS, SDL_Rect *rect)
Definition: SDL_sysvideo.h:257
void * SDL_calloc(size_t nmemb, size_t size)
void * SDL_GLContext
An opaque handle to an OpenGL context.
Definition: SDL_video.h:164
SDL_bool(* GetWindowWMInfo)(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
Definition: SDL_sysvideo.h:227
int Android_SetClipboardText(_THIS, const char *text)
SDL_GLContext(* GL_CreateContext)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:237
#define _THIS
int(* GL_MakeCurrent)(_THIS, SDL_Window *window, SDL_GLContext context)
Definition: SDL_sysvideo.h:238
void SDL_free(void *mem)
void * driverdata
Definition: SDL_video.h:59
Uint32 Android_ScreenFormat
SDL_Window * Android_Window
GLenum mode
SDL_VideoDisplay * displays
Definition: SDL_sysvideo.h:280
void(* DestroyWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:214
void Android_PumpEvents(_THIS)
void(* StopTextInput)(_THIS)
Definition: SDL_sysvideo.h:256
void Android_StartTextInput(_THIS)
void Android_JNI_SuspendScreenSaver(SDL_bool suspend)
int Android_ScreenWidth
SDL_bool(* HasScreenKeyboardSupport)(_THIS)
Definition: SDL_sysvideo.h:260
void Android_SetTextInputRect(_THIS, SDL_Rect *rect)
void(* GL_UnloadLibrary)(_THIS)
Definition: SDL_sysvideo.h:236
#define NULL
Definition: begin_code.h:143
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
void Android_SetWindowTitle(_THIS, SDL_Window *window)
void(* VideoQuit)(_THIS)
Definition: SDL_sysvideo.h:161
SDL_sem * Android_ResumeSem
int(* CreateWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:195
The type used to identify a window.
Definition: SDL_sysvideo.h:71
int Android_CreateWindow(_THIS, SDL_Window *window)
void Android_StopTextInput(_THIS)
SDL_bool Android_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
SDL_bool(* HasClipboardText)(_THIS)
Definition: SDL_sysvideo.h:268
SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
Definition: SDL_video.c:709
int(* VideoInit)(_THIS)
Definition: SDL_sysvideo.h:155
SDL_bool suspend_screensaver
Definition: SDL_sysvideo.h:278
GLsizei const GLchar *const * path
void(* GL_DeleteContext)(_THIS, SDL_GLContext context)
Definition: SDL_sysvideo.h:243
char *(* GetClipboardText)(_THIS)
Definition: SDL_sysvideo.h:267
Uint32 format
Definition: SDL_video.h:55
void(* SetWindowTitle)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:197
int(* GL_GetSwapInterval)(_THIS)
Definition: SDL_sysvideo.h:241
int(* SetClipboardText)(_THIS, const char *text)
Definition: SDL_sysvideo.h:266
SDL_bool Android_HasClipboardText(_THIS)
void(* SuspendScreenSaver)(_THIS)
Definition: SDL_sysvideo.h:252
SDL_bool Android_IsScreenKeyboardShown(_THIS, SDL_Window *window)
void *(* GL_GetProcAddress)(_THIS, const char *proc)
Definition: SDL_sysvideo.h:235
void Android_QuitTouch(void)
void(* PumpEvents)(_THIS)
Definition: SDL_sysvideo.h:249