zenilib: zenilib/jni/external/sdl/src/video/android/SDL_androidvideo.c Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_androidvideo.c
Go to the documentation of this file.
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 #include "../SDL_egl.h"
48 /* GL functions (SDL_androidgl.c) */
49 extern SDL_GLContext Android_GLES_CreateContext(_THIS, SDL_Window * window);
50 extern int Android_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
51 extern void Android_GLES_SwapWindow(_THIS, SDL_Window * window);
52 extern int Android_GLES_LoadLibrary(_THIS, const char *path);
53 #define Android_GLES_GetProcAddress SDL_EGL_GetProcAddress
54 #define Android_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
55 #define Android_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
56 #define Android_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
57 #define Android_GLES_DeleteContext SDL_EGL_DeleteContext
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_GLES_LoadLibrary;
118 device->GL_GetProcAddress = Android_GLES_GetProcAddress;
119 device->GL_UnloadLibrary = Android_GLES_UnloadLibrary;
120 device->GL_CreateContext = Android_GLES_CreateContext;
121 device->GL_MakeCurrent = Android_GLES_MakeCurrent;
122 device->GL_SetSwapInterval = Android_GLES_SetSwapInterval;
123 device->GL_GetSwapInterval = Android_GLES_GetSwapInterval;
124 device->GL_SwapWindow = Android_GLES_SwapWindow;
125 device->GL_DeleteContext = Android_GLES_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: */
SDL_VideoDevice::IsScreenKeyboardShown
SDL_bool(* IsScreenKeyboardShown)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:251
SDL_androidwindow.h
SDL_VideoDevice::SetClipboardText
int(* SetClipboardText)(_THIS, const char *text)
Definition: SDL_sysvideo.h:254
SDL_calloc
DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size)
SDL_androidevents.h
Android_DestroyWindow
void Android_DestroyWindow(_THIS, SDL_Window *window)
SDL_sem
struct SDL_semaphore SDL_sem
Definition: SDL_mutex.h:107
NULL
#define NULL
Definition: ftobjs.h:61
Android_HasScreenKeyboardSupport
SDL_bool Android_HasScreenKeyboardSupport(_THIS)
SDL_DisplayMode::w
int w
Definition: SDL_video.h:56
SDL_VideoDevice::GL_MakeCurrent
int(* GL_MakeCurrent)(_THIS, SDL_Window *window, SDL_GLContext context)
Definition: SDL_sysvideo.h:226
Android_GetClipboardText
char * Android_GetClipboardText(_THIS)
SDL_VideoDevice::StopTextInput
void(* StopTextInput)(_THIS)
Definition: SDL_sysvideo.h:244
Android_ScreenHeight
int Android_ScreenHeight
SDL_AddBasicVideoDisplay
int SDL_AddBasicVideoDisplay(const SDL_DisplayMode *desktop_mode)
Definition: SDL_video.c:554
SDL_VideoDevice::driverdata
void * driverdata
Definition: SDL_sysvideo.h:314
SDL_androidkeyboard.h
SDL_free
DECLSPEC void SDLCALL SDL_free(void *mem)
SDL_DisplayMode
The structure that defines a display mode.
Definition: SDL_video.h:53
SDL_PIXELFORMAT_UNKNOWN
Definition: SDL_pixels.h:149
height
EGLSurface EGLint EGLint EGLint EGLint height
Definition: eglext.h:293
SDL_GLContext
void * SDL_GLContext
An opaque handle to an OpenGL context.
Definition: SDL_video.h:161
SDL_DisplayMode::refresh_rate
int refresh_rate
Definition: SDL_video.h:58
SDL_VideoDevice::HasScreenKeyboardSupport
SDL_bool(* HasScreenKeyboardSupport)(_THIS)
Definition: SDL_sysvideo.h:248
SDL_SendWindowEvent
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
Definition: SDL_windowevents.c:74
Android_InitKeyboard
void Android_InitKeyboard(void)
SDL_androidvideo.h
path
GLsizei const GLchar *const * path
Definition: glew.h:5828
SDL_config.h
SDL_VideoDevice::free
void(* free)(_THIS)
Definition: SDL_sysvideo.h:327
Android_PauseSem
SDL_sem * Android_PauseSem
SDL_VideoDevice::GL_SetSwapInterval
int(* GL_SetSwapInterval)(_THIS, int interval)
Definition: SDL_sysvideo.h:228
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:92
Uint32
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:145
SDL_VideoDevice::CreateWindow
int(* CreateWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:183
SDL_VideoDevice::GL_UnloadLibrary
void(* GL_UnloadLibrary)(_THIS)
Definition: SDL_sysvideo.h:224
SDL_video.h
Android_SetClipboardText
int Android_SetClipboardText(_THIS, const char *text)
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
width
EGLSurface EGLint EGLint EGLint width
Definition: eglext.h:293
SDL_VideoDevice::VideoInit
int(* VideoInit)(_THIS)
Definition: SDL_sysvideo.h:148
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
SDL_DisplayMode::driverdata
void * driverdata
Definition: SDL_video.h:59
SDL_mouse.h
VideoBootStrap
Definition: SDL_sysvideo.h:330
Android_ScreenFormat
Uint32 Android_ScreenFormat
Android_Window
SDL_Window * Android_Window
SDL_VideoDevice::displays
SDL_VideoDisplay * displays
Definition: SDL_sysvideo.h:265
Android_PumpEvents
void Android_PumpEvents(_THIS)
format
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl2ext.h:845
Android_SetScreenResolution
void Android_SetScreenResolution(int width, int height, Uint32 format)
SDL_DisplayMode::h
int h
Definition: SDL_video.h:57
Android_StartTextInput
void Android_StartTextInput(_THIS)
SDL_VideoDevice::PumpEvents
void(* PumpEvents)(_THIS)
Definition: SDL_sysvideo.h:237
Android_ScreenWidth
int Android_ScreenWidth
Android_SetTextInputRect
void Android_SetTextInputRect(_THIS, SDL_Rect *rect)
SDL_VideoDevice::GL_GetSwapInterval
int(* GL_GetSwapInterval)(_THIS)
Definition: SDL_sysvideo.h:229
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
Android_SetWindowTitle
void Android_SetWindowTitle(_THIS, SDL_Window *window)
SDL_VideoDevice::GL_DeleteContext
void(* GL_DeleteContext)(_THIS, SDL_GLContext context)
Definition: SDL_sysvideo.h:231
SDL_VideoDevice::DestroyWindow
void(* DestroyWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:202
SDL_VideoDevice::SetTextInputRect
void(* SetTextInputRect)(_THIS, SDL_Rect *rect)
Definition: SDL_sysvideo.h:245
Android_ResumeSem
SDL_sem * Android_ResumeSem
SDL_Window
Definition: SDL_sysvideo.h:71
Android_CreateWindow
int Android_CreateWindow(_THIS, SDL_Window *window)
SDL_VideoDevice::GetClipboardText
char *(* GetClipboardText)(_THIS)
Definition: SDL_sysvideo.h:255
SDL_VideoDevice::GL_CreateContext
SDL_GLContext(* GL_CreateContext)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:225
Android_StopTextInput
void Android_StopTextInput(_THIS)
SDL_VideoDevice::GL_LoadLibrary
int(* GL_LoadLibrary)(_THIS, const char *path)
Definition: SDL_sysvideo.h:222
SDL_VideoDevice::GL_SwapWindow
void(* GL_SwapWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:230
SDL_VideoDevice
Definition: SDL_sysvideo.h:135
SDL_VideoDevice::VideoQuit
void(* VideoQuit)(_THIS)
Definition: SDL_sysvideo.h:154
SDL_VideoData
Definition: SDL_androidvideo.h:35
SDL_AddDisplayMode
SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
Definition: SDL_video.c:666
SDL_androidclipboard.h
SDL_VideoDevice::HasClipboardText
SDL_bool(* HasClipboardText)(_THIS)
Definition: SDL_sysvideo.h:256
SDL_WINDOWEVENT_RESIZED
Definition: SDL_video.h:144
SDL_VideoDevice::SetWindowTitle
void(* SetWindowTitle)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:185
SDL_DisplayMode::format
Uint32 format
Definition: SDL_video.h:55
context
TParseContext * context
Definition: glslang_tab.cpp:1907
SDL_VideoDevice::StartTextInput
void(* StartTextInput)(_THIS)
Definition: SDL_sysvideo.h:243
Android_HasClipboardText
SDL_bool Android_HasClipboardText(_THIS)
Android_IsScreenKeyboardShown
SDL_bool Android_IsScreenKeyboardShown(_THIS, SDL_Window *window)
SDL_VideoDevice::GL_GetProcAddress
void *(* GL_GetProcAddress)(_THIS, const char *proc)
Definition: SDL_sysvideo.h:223
mode
GLenum mode
Definition: glew.h:2394