zenilib: zenilib/jni/external/sdl/src/video/android/SDL_androidwindow.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_androidwindow.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 #include "../SDL_sysvideo.h"
26 #include "../../events/SDL_keyboard_c.h"
27 #include "../../events/SDL_mouse_c.h"
28
29 #include "SDL_androidvideo.h"
30 #include "SDL_androidwindow.h"
31
32 int
33 Android_CreateWindow(_THIS, SDL_Window * window)
34 {
35 SDL_WindowData *data;
36
37 if (Android_Window) {
38 return SDL_SetError("Android only supports one window");
39 }
40
41 Android_PauseSem = SDL_CreateSemaphore(0);
42 Android_ResumeSem = SDL_CreateSemaphore(0);
43
44 /* Adjust the window data to match the screen */
45 window->x = 0;
46 window->y = 0;
47 window->w = Android_ScreenWidth;
48 window->h = Android_ScreenHeight;
49
50 window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */
51 window->flags |= SDL_WINDOW_FULLSCREEN; /* window is always fullscreen */
52 window->flags &= ~SDL_WINDOW_HIDDEN;
53 window->flags |= SDL_WINDOW_SHOWN; /* only one window on Android */
54 window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */
55
56 /* One window, it always has focus */
57 SDL_SetMouseFocus(window);
58 SDL_SetKeyboardFocus(window);
59
60 data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
61 if (!data) {
62 return SDL_OutOfMemory();
63 }
64
65 data->native_window = Android_JNI_GetNativeWindow();
66
67 if (!data->native_window) {
68 SDL_free(data);
69 return SDL_SetError("Could not fetch native window");
70 }
71
72 data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->native_window);
73
74 if (data->egl_surface == EGL_NO_SURFACE) {
75 SDL_free(data);
76 return SDL_SetError("Could not create GLES window surface");
77 }
78
79 window->driverdata = data;
80 Android_Window = window;
81
82 return 0;
83 }
84
85 void
86 Android_SetWindowTitle(_THIS, SDL_Window * window)
87 {
88 Android_JNI_SetActivityTitle(window->title);
89 }
90
91 void
92 Android_DestroyWindow(_THIS, SDL_Window * window)
93 {
94 SDL_WindowData *data;
95
96 if (window == Android_Window) {
97 Android_Window = NULL;
98 if (Android_PauseSem) SDL_DestroySemaphore(Android_PauseSem);
99 if (Android_ResumeSem) SDL_DestroySemaphore(Android_ResumeSem);
100 Android_PauseSem = NULL;
101 Android_ResumeSem = NULL;
102
103 if(window->driverdata) {
104 data = (SDL_WindowData *) window->driverdata;
105 if(data->native_window) {
106 ANativeWindow_release(data->native_window);
107 }
108 SDL_free(window->driverdata);
109 window->driverdata = NULL;
110 }
111 }
112 }
113
114 #endif /* SDL_VIDEO_DRIVER_ANDROID */
115
116 /* vi: set ts=4 sw=4 expandtab: */
SDL_CreateSemaphore
DECLSPEC SDL_sem *SDLCALL SDL_CreateSemaphore(Uint32 initial_value)
Definition: SDL_syssem.c:85
SDL_androidwindow.h
SDL_SetKeyboardFocus
void SDL_SetKeyboardFocus(SDL_Window *window)
Definition: SDL_keyboard.c:611
SDL_calloc
DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size)
Android_DestroyWindow
void Android_DestroyWindow(_THIS, SDL_Window *window)
SDL_Window::w
int w
Definition: SDL_sysvideo.h:78
NULL
#define NULL
Definition: ftobjs.h:61
EGL_NO_SURFACE
#define EGL_NO_SURFACE
Definition: egl.h:71
SDL_Window::x
int x
Definition: SDL_sysvideo.h:77
Android_ScreenHeight
int Android_ScreenHeight
Android_JNI_SetActivityTitle
void Android_JNI_SetActivityTitle(const char *title)
SDL_free
DECLSPEC void SDLCALL SDL_free(void *mem)
SDL_SetMouseFocus
void SDL_SetMouseFocus(SDL_Window *window)
Definition: SDL_mouse.c:93
SDL_WINDOW_HIDDEN
Definition: SDL_video.h:101
SDL_androidvideo.h
SDL_config.h
SDL_WINDOW_SHOWN
Definition: SDL_video.h:100
SDL_WindowData
Definition: SDL_androidwindow.h:33
Android_PauseSem
SDL_sem * Android_PauseSem
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:92
NativeWindowType
EGLNativeWindowType NativeWindowType
Definition: eglplatform.h:117
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
Android_Window
SDL_Window * Android_Window
SDL_SetError
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
Definition: SDL_error.c:53
SDL_Window::title
char * title
Definition: SDL_sysvideo.h:75
SDL_Window::y
int y
Definition: SDL_sysvideo.h:77
Android_ScreenWidth
int Android_ScreenWidth
SDL_DestroySemaphore
DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem *sem)
Definition: SDL_syssem.c:111
SDL_Window::h
int h
Definition: SDL_sysvideo.h:78
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_WINDOW_INPUT_FOCUS
Definition: SDL_video.h:107
Android_SetWindowTitle
void Android_SetWindowTitle(_THIS, SDL_Window *window)
SDL_WINDOW_RESIZABLE
Definition: SDL_video.h:103
Android_JNI_GetNativeWindow
ANativeWindow * Android_JNI_GetNativeWindow(void)
Android_ResumeSem
SDL_sem * Android_ResumeSem
SDL_Window
Definition: SDL_sysvideo.h:71
Android_CreateWindow
int Android_CreateWindow(_THIS, SDL_Window *window)
SDL_WINDOW_FULLSCREEN
Definition: SDL_video.h:98
SDL_Window::driverdata
void * driverdata
Definition: SDL_sysvideo.h:99
SDL_WindowData::native_window
ANativeWindow * native_window
Definition: SDL_androidwindow.h:37
SDL_Window::flags
Uint32 flags
Definition: SDL_sysvideo.h:81
SDL_WindowData::egl_surface
EGLSurface egl_surface
Definition: SDL_androidwindow.h:35