SDL  2.0
SDL_androidwindow.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 #include "SDL_syswm.h"
26 #include "../SDL_sysvideo.h"
27 #include "../../events/SDL_keyboard_c.h"
28 #include "../../events/SDL_mouse_c.h"
29 
30 #include "SDL_androidvideo.h"
31 #include "SDL_androidwindow.h"
32 
33 int
35 {
37 
38  if (Android_Window) {
39  return SDL_SetError("Android only supports one window");
40  }
41 
44 
45  /* Adjust the window data to match the screen */
46  window->x = 0;
47  window->y = 0;
48  window->w = Android_ScreenWidth;
49  window->h = Android_ScreenHeight;
50 
51  window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */
52  window->flags |= SDL_WINDOW_FULLSCREEN; /* window is always fullscreen */
53  window->flags &= ~SDL_WINDOW_HIDDEN;
54  window->flags |= SDL_WINDOW_SHOWN; /* only one window on Android */
55  window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */
56 
57  /* One window, it always has focus */
58  SDL_SetMouseFocus(window);
59  SDL_SetKeyboardFocus(window);
60 
61  data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
62  if (!data) {
63  return SDL_OutOfMemory();
64  }
65 
67 
68  if (!data->native_window) {
69  SDL_free(data);
70  return SDL_SetError("Could not fetch native window");
71  }
72 
73  data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->native_window);
74 
75  if (data->egl_surface == EGL_NO_SURFACE) {
76  ANativeWindow_release(data->native_window);
77  SDL_free(data);
78  return SDL_SetError("Could not create GLES window surface");
79  }
80 
81  window->driverdata = data;
83 
84  return 0;
85 }
86 
87 void
89 {
91 }
92 
93 void
95 {
97 
98  if (window == Android_Window) {
104 
105  if(window->driverdata) {
106  data = (SDL_WindowData *) window->driverdata;
107  if (data->egl_surface != EGL_NO_SURFACE) {
108  SDL_EGL_DestroySurface(_this, data->egl_surface);
109  }
110  if (data->native_window) {
111  ANativeWindow_release(data->native_window);
112  }
113  SDL_free(window->driverdata);
114  window->driverdata = NULL;
115  }
116  }
117 }
118 
119 SDL_bool
121 {
122  SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
123 
124  if (info->version.major == SDL_MAJOR_VERSION &&
125  info->version.minor == SDL_MINOR_VERSION) {
127  info->info.android.window = data->native_window;
128  info->info.android.surface = data->egl_surface;
129  return SDL_TRUE;
130  } else {
131  SDL_SetError("Application not compiled with SDL %d.%d\n",
133  return SDL_FALSE;
134  }
135 }
136 
137 #endif /* SDL_VIDEO_DRIVER_ANDROID */
138 
139 /* vi: set ts=4 sw=4 expandtab: */
#define SDL_MINOR_VERSION
Definition: SDL_version.h:61
void SDL_SetKeyboardFocus(SDL_Window *window)
Definition: SDL_keyboard.c:612
void Android_DestroyWindow(_THIS, SDL_Window *window)
struct wl_surface * surface
Definition: SDL_syswm.h:254
#define SDL_MAJOR_VERSION
Definition: SDL_version.h:60
#define SDL_CreateSemaphore
static SDL_Window * window
int Android_ScreenHeight
void Android_JNI_SetActivityTitle(const char *title)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld [DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp local skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
SDL_version version
Definition: SDL_syswm.h:195
Uint8 major
Definition: SDL_version.h:53
SDL_SYSWM_TYPE subsystem
Definition: SDL_syswm.h:196
void SDL_SetMouseFocus(SDL_Window *window)
Definition: SDL_mouse.c:103
SDL_sem * Android_PauseSem
static SDL_VideoDevice * _this
Definition: SDL_video.c:118
void * SDL_calloc(size_t nmemb, size_t size)
#define _THIS
void SDL_free(void *mem)
SDL_Window * Android_Window
Uint8 minor
Definition: SDL_version.h:54
char * title
Definition: SDL_sysvideo.h:75
int Android_ScreenWidth
Window window
Definition: SDL_syswm.h:216
#define NULL
Definition: begin_code.h:143
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_bool
Definition: SDL_stdinc.h:130
void Android_SetWindowTitle(_THIS, SDL_Window *window)
ANativeWindow * Android_JNI_GetNativeWindow(void)
#define SDL_SetError
SDL_sem * Android_ResumeSem
The type used to identify a window.
Definition: SDL_sysvideo.h:71
int Android_CreateWindow(_THIS, SDL_Window *window)
#define SDL_DestroySemaphore
SDL_bool Android_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
union SDL_SysWMinfo::@18 info
void * driverdata
Definition: SDL_sysvideo.h:109
ANativeWindow * native_window
Uint32 flags
Definition: SDL_sysvideo.h:81
EGLSurface egl_surface