zenilib  0.5.3.0
 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
34 {
36 
37  if (Android_Window) {
38  return SDL_SetError("Android only supports one window");
39  }
40 
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 
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
87 {
89 }
90 
91 void
93 {
95 
96  if (window == Android_Window) {
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: */
DECLSPEC SDL_sem *SDLCALL SDL_CreateSemaphore(Uint32 initial_value)
Definition: SDL_syssem.c:85
void SDL_SetKeyboardFocus(SDL_Window *window)
Definition: SDL_keyboard.c:611
DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size)
void Android_DestroyWindow(_THIS, SDL_Window *window)
#define NULL
Definition: ftobjs.h:61
#define EGL_NO_SURFACE
Definition: egl.h:71
int Android_ScreenHeight
void Android_JNI_SetActivityTitle(const char *title)
DECLSPEC void SDLCALL SDL_free(void *mem)
void SDL_SetMouseFocus(SDL_Window *window)
Definition: SDL_mouse.c:93
SDL_sem * Android_PauseSem
static SDL_VideoDevice * _this
Definition: SDL_video.c:92
EGLNativeWindowType NativeWindowType
Definition: eglplatform.h:117
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
#define _THIS
SDL_Window * Android_Window
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
Definition: SDL_error.c:53
char * title
Definition: SDL_sysvideo.h:75
int Android_ScreenWidth
DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem *sem)
Definition: SDL_syssem.c:111
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
void Android_SetWindowTitle(_THIS, SDL_Window *window)
ANativeWindow * Android_JNI_GetNativeWindow(void)
SDL_sem * Android_ResumeSem
int Android_CreateWindow(_THIS, SDL_Window *window)
void * driverdata
Definition: SDL_sysvideo.h:99
ANativeWindow * native_window
Uint32 flags
Definition: SDL_sysvideo.h:81
EGLSurface egl_surface