mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-29 00:05:40 +00:00
Update to SDL2.0.10
This commit is contained in:
parent
600859bd63
commit
c932bda8dd
915 changed files with 116675 additions and 21754 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -22,16 +22,15 @@
|
|||
|
||||
#if SDL_VIDEO_DRIVER_ANDROID
|
||||
|
||||
/* We're going to do this by default */
|
||||
#define SDL_ANDROID_BLOCK_ON_PAUSE 1
|
||||
|
||||
#include "SDL_androidevents.h"
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_androidkeyboard.h"
|
||||
#include "SDL_androidwindow.h"
|
||||
|
||||
#if !SDL_AUDIO_DISABLED
|
||||
/* Can't include sysaudio "../../audio/android/SDL_androidaudio.h"
|
||||
* because of THIS redefinition */
|
||||
|
||||
#if !SDL_AUDIO_DISABLED && SDL_AUDIO_DRIVER_ANDROID
|
||||
extern void ANDROIDAUDIO_ResumeDevices(void);
|
||||
extern void ANDROIDAUDIO_PauseDevices(void);
|
||||
#else
|
||||
|
|
@ -39,82 +38,159 @@ static void ANDROIDAUDIO_ResumeDevices(void) {}
|
|||
static void ANDROIDAUDIO_PauseDevices(void) {}
|
||||
#endif
|
||||
|
||||
static void
|
||||
android_egl_context_restore()
|
||||
#if !SDL_AUDIO_DISABLED && SDL_AUDIO_DRIVER_OPENSLES
|
||||
extern void openslES_ResumeDevices(void);
|
||||
extern void openslES_PauseDevices(void);
|
||||
#else
|
||||
static void openslES_ResumeDevices(void) {}
|
||||
static void openslES_PauseDevices(void) {}
|
||||
#endif
|
||||
|
||||
/* Number of 'type' events in the event queue */
|
||||
static int
|
||||
SDL_NumberOfEvents(Uint32 type)
|
||||
{
|
||||
SDL_Event event;
|
||||
SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata;
|
||||
if (SDL_GL_MakeCurrent(Android_Window, (SDL_GLContext) data->egl_context) < 0) {
|
||||
/* The context is no longer valid, create a new one */
|
||||
data->egl_context = (EGLContext) SDL_GL_CreateContext(Android_Window);
|
||||
SDL_GL_MakeCurrent(Android_Window, (SDL_GLContext) data->egl_context);
|
||||
event.type = SDL_RENDER_DEVICE_RESET;
|
||||
SDL_PushEvent(&event);
|
||||
return SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, type, type);
|
||||
}
|
||||
|
||||
static void
|
||||
android_egl_context_restore(SDL_Window *window)
|
||||
{
|
||||
if (window) {
|
||||
SDL_Event event;
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
if (SDL_GL_MakeCurrent(window, (SDL_GLContext) data->egl_context) < 0) {
|
||||
/* The context is no longer valid, create a new one */
|
||||
data->egl_context = (EGLContext) SDL_GL_CreateContext(window);
|
||||
SDL_GL_MakeCurrent(window, (SDL_GLContext) data->egl_context);
|
||||
event.type = SDL_RENDER_DEVICE_RESET;
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
android_egl_context_backup()
|
||||
static void
|
||||
android_egl_context_backup(SDL_Window *window)
|
||||
{
|
||||
/* Keep a copy of the EGL Context so we can try to restore it when we resume */
|
||||
SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata;
|
||||
data->egl_context = SDL_GL_GetCurrentContext();
|
||||
/* We need to do this so the EGLSurface can be freed */
|
||||
SDL_GL_MakeCurrent(Android_Window, NULL);
|
||||
if (window) {
|
||||
/* Keep a copy of the EGL Context so we can try to restore it when we resume */
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
data->egl_context = SDL_GL_GetCurrentContext();
|
||||
/* We need to do this so the EGLSurface can be freed */
|
||||
SDL_GL_MakeCurrent(window, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Android_ResumeSem and Android_PauseSem are signaled from Java_org_libsdl_app_SDLActivity_nativePause and Java_org_libsdl_app_SDLActivity_nativeResume
|
||||
* When the pause semaphore is signaled, if Android_PumpEvents_Blocking is used, the event loop will block until the resume signal is emitted.
|
||||
*
|
||||
* No polling necessary
|
||||
*/
|
||||
|
||||
void
|
||||
Android_PumpEvents_Blocking(_THIS)
|
||||
{
|
||||
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
|
||||
|
||||
if (videodata->isPaused) {
|
||||
|
||||
/* Make sure this is the last thing we do before pausing */
|
||||
SDL_LockMutex(Android_ActivityMutex);
|
||||
android_egl_context_backup(Android_Window);
|
||||
SDL_UnlockMutex(Android_ActivityMutex);
|
||||
|
||||
ANDROIDAUDIO_PauseDevices();
|
||||
openslES_PauseDevices();
|
||||
|
||||
if (SDL_SemWait(Android_ResumeSem) == 0) {
|
||||
|
||||
videodata->isPaused = 0;
|
||||
|
||||
ANDROIDAUDIO_ResumeDevices();
|
||||
openslES_ResumeDevices();
|
||||
|
||||
/* Restore the GL Context from here, as this operation is thread dependent */
|
||||
if (!SDL_HasEvent(SDL_QUIT)) {
|
||||
SDL_LockMutex(Android_ActivityMutex);
|
||||
android_egl_context_restore(Android_Window);
|
||||
SDL_UnlockMutex(Android_ActivityMutex);
|
||||
}
|
||||
|
||||
/* Make sure SW Keyboard is restored when an app becomes foreground */
|
||||
if (SDL_IsTextInputActive()) {
|
||||
Android_StartTextInput(_this); /* Only showTextInput */
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (videodata->isPausing || SDL_SemTryWait(Android_PauseSem) == 0) {
|
||||
/* We've been signaled to pause (potentially several times), but before we block ourselves,
|
||||
* we need to make sure that the very last event (of the first pause sequence, if several)
|
||||
* has reached the app */
|
||||
if (SDL_NumberOfEvents(SDL_APP_DIDENTERBACKGROUND) > SDL_SemValue(Android_PauseSem)) {
|
||||
videodata->isPausing = 1;
|
||||
} else {
|
||||
videodata->isPausing = 0;
|
||||
videodata->isPaused = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Android_PumpEvents(_THIS)
|
||||
Android_PumpEvents_NonBlocking(_THIS)
|
||||
{
|
||||
static int isPaused = 0;
|
||||
#if SDL_ANDROID_BLOCK_ON_PAUSE
|
||||
static int isPausing = 0;
|
||||
#endif
|
||||
/* No polling necessary */
|
||||
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
|
||||
static int backup_context = 0;
|
||||
|
||||
/*
|
||||
* Android_ResumeSem and Android_PauseSem are signaled from Java_org_libsdl_app_SDLActivity_nativePause and Java_org_libsdl_app_SDLActivity_nativeResume
|
||||
* When the pause semaphore is signaled, if SDL_ANDROID_BLOCK_ON_PAUSE is defined the event loop will block until the resume signal is emitted.
|
||||
*/
|
||||
if (videodata->isPaused) {
|
||||
|
||||
if (backup_context) {
|
||||
|
||||
SDL_LockMutex(Android_ActivityMutex);
|
||||
android_egl_context_backup(Android_Window);
|
||||
SDL_UnlockMutex(Android_ActivityMutex);
|
||||
|
||||
ANDROIDAUDIO_PauseDevices();
|
||||
openslES_PauseDevices();
|
||||
|
||||
backup_context = 0;
|
||||
}
|
||||
|
||||
|
||||
if (SDL_SemTryWait(Android_ResumeSem) == 0) {
|
||||
|
||||
videodata->isPaused = 0;
|
||||
|
||||
#if SDL_ANDROID_BLOCK_ON_PAUSE
|
||||
if (isPaused && !isPausing) {
|
||||
/* Make sure this is the last thing we do before pausing */
|
||||
android_egl_context_backup();
|
||||
ANDROIDAUDIO_PauseDevices();
|
||||
if(SDL_SemWait(Android_ResumeSem) == 0) {
|
||||
#else
|
||||
if (isPaused) {
|
||||
if(SDL_SemTryWait(Android_ResumeSem) == 0) {
|
||||
#endif
|
||||
isPaused = 0;
|
||||
ANDROIDAUDIO_ResumeDevices();
|
||||
openslES_ResumeDevices();
|
||||
|
||||
/* Restore the GL Context from here, as this operation is thread dependent */
|
||||
if (!SDL_HasEvent(SDL_QUIT)) {
|
||||
android_egl_context_restore();
|
||||
SDL_LockMutex(Android_ActivityMutex);
|
||||
android_egl_context_restore(Android_Window);
|
||||
SDL_UnlockMutex(Android_ActivityMutex);
|
||||
}
|
||||
|
||||
/* Make sure SW Keyboard is restored when an app becomes foreground */
|
||||
if (SDL_IsTextInputActive()) {
|
||||
Android_StartTextInput(_this); /* Only showTextInput */
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
#if SDL_ANDROID_BLOCK_ON_PAUSE
|
||||
if( isPausing || SDL_SemTryWait(Android_PauseSem) == 0 ) {
|
||||
/* We've been signaled to pause, but before we block ourselves,
|
||||
we need to make sure that certain key events have reached the app */
|
||||
if (SDL_HasEvent(SDL_WINDOWEVENT) || SDL_HasEvent(SDL_APP_WILLENTERBACKGROUND) || SDL_HasEvent(SDL_APP_DIDENTERBACKGROUND) ) {
|
||||
isPausing = 1;
|
||||
}
|
||||
else {
|
||||
isPausing = 0;
|
||||
isPaused = 1;
|
||||
} else {
|
||||
if (videodata->isPausing || SDL_SemTryWait(Android_PauseSem) == 0) {
|
||||
/* We've been signaled to pause (potentially several times), but before we block ourselves,
|
||||
* we need to make sure that the very last event (of the first pause sequence, if several)
|
||||
* has reached the app */
|
||||
if (SDL_NumberOfEvents(SDL_APP_DIDENTERBACKGROUND) > SDL_SemValue(Android_PauseSem)) {
|
||||
videodata->isPausing = 1;
|
||||
} else {
|
||||
videodata->isPausing = 0;
|
||||
videodata->isPaused = 1;
|
||||
backup_context = 1;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if(SDL_SemTryWait(Android_PauseSem) == 0) {
|
||||
android_egl_context_backup();
|
||||
ANDROIDAUDIO_PauseDevices();
|
||||
isPaused = 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "SDL_androidvideo.h"
|
||||
|
||||
extern void Android_PumpEvents(_THIS);
|
||||
extern void Android_PumpEvents_Blocking(_THIS);
|
||||
extern void Android_PumpEvents_NonBlocking(_THIS);
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -36,20 +36,49 @@
|
|||
|
||||
#include <dlfcn.h>
|
||||
|
||||
SDL_EGL_CreateContext_impl(Android)
|
||||
SDL_EGL_MakeCurrent_impl(Android)
|
||||
int
|
||||
Android_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
|
||||
{
|
||||
if (window && context) {
|
||||
return SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *) window->driverdata)->egl_surface, context);
|
||||
} else {
|
||||
return SDL_EGL_MakeCurrent(_this, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_GLContext
|
||||
Android_GLES_CreateContext(_THIS, SDL_Window * window)
|
||||
{
|
||||
SDL_GLContext ret;
|
||||
|
||||
Android_ActivityMutex_Lock_Running();
|
||||
|
||||
ret = SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
|
||||
|
||||
SDL_UnlockMutex(Android_ActivityMutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
Android_GLES_SwapWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
int retval;
|
||||
|
||||
SDL_LockMutex(Android_ActivityMutex);
|
||||
|
||||
/* The following two calls existed in the original Java code
|
||||
* If you happen to have a device that's affected by their removal,
|
||||
* please report to Bugzilla. -- Gabriel
|
||||
*/
|
||||
|
||||
|
||||
/*_this->egl_data->eglWaitNative(EGL_CORE_NATIVE_ENGINE);
|
||||
_this->egl_data->eglWaitGL();*/
|
||||
return SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
|
||||
retval = SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
|
||||
|
||||
SDL_UnlockMutex(Android_ActivityMutex);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -42,15 +42,164 @@
|
|||
#define BUTTON_BACK 8
|
||||
#define BUTTON_FORWARD 16
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int custom_cursor;
|
||||
int system_cursor;
|
||||
|
||||
} SDL_AndroidCursorData;
|
||||
|
||||
/* Last known Android mouse button state (includes all buttons) */
|
||||
static int last_state;
|
||||
|
||||
/* Blank cursor */
|
||||
static SDL_Cursor *empty_cursor;
|
||||
|
||||
static SDL_Cursor *
|
||||
Android_WrapCursor(int custom_cursor, int system_cursor)
|
||||
{
|
||||
SDL_Cursor *cursor;
|
||||
|
||||
cursor = SDL_calloc(1, sizeof(*cursor));
|
||||
if (cursor) {
|
||||
SDL_AndroidCursorData *data = (SDL_AndroidCursorData *)SDL_calloc(1, sizeof(*data));
|
||||
if (data) {
|
||||
data->custom_cursor = custom_cursor;
|
||||
data->system_cursor = system_cursor;
|
||||
cursor->driverdata = data;
|
||||
} else {
|
||||
SDL_free(cursor);
|
||||
cursor = NULL;
|
||||
SDL_OutOfMemory();
|
||||
}
|
||||
} else {
|
||||
SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
static SDL_Cursor *
|
||||
Android_CreateDefaultCursor()
|
||||
{
|
||||
return Android_WrapCursor(0, SDL_SYSTEM_CURSOR_ARROW);
|
||||
}
|
||||
|
||||
static SDL_Cursor *
|
||||
Android_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
|
||||
{
|
||||
int custom_cursor;
|
||||
SDL_Surface *converted;
|
||||
|
||||
converted = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ARGB8888, 0);
|
||||
if (!converted) {
|
||||
return NULL;
|
||||
}
|
||||
custom_cursor = Android_JNI_CreateCustomCursor(converted, hot_x, hot_y);
|
||||
SDL_FreeSurface(converted);
|
||||
if (!custom_cursor) {
|
||||
SDL_Unsupported();
|
||||
return NULL;
|
||||
}
|
||||
return Android_WrapCursor(custom_cursor, 0);
|
||||
}
|
||||
|
||||
static SDL_Cursor *
|
||||
Android_CreateSystemCursor(SDL_SystemCursor id)
|
||||
{
|
||||
return Android_WrapCursor(0, id);
|
||||
}
|
||||
|
||||
static void
|
||||
Android_FreeCursor(SDL_Cursor * cursor)
|
||||
{
|
||||
SDL_free(cursor->driverdata);
|
||||
SDL_free(cursor);
|
||||
}
|
||||
|
||||
static SDL_Cursor *
|
||||
Android_CreateEmptyCursor()
|
||||
{
|
||||
if (!empty_cursor) {
|
||||
SDL_Surface *empty_surface = SDL_CreateRGBSurfaceWithFormat(0, 1, 1, 32, SDL_PIXELFORMAT_ARGB8888);
|
||||
if (empty_surface) {
|
||||
SDL_memset(empty_surface->pixels, 0, empty_surface->h * empty_surface->pitch);
|
||||
empty_cursor = Android_CreateCursor(empty_surface, 0, 0);
|
||||
SDL_FreeSurface(empty_surface);
|
||||
}
|
||||
}
|
||||
return empty_cursor;
|
||||
}
|
||||
|
||||
static void
|
||||
Android_DestroyEmptyCursor()
|
||||
{
|
||||
if (empty_cursor) {
|
||||
Android_FreeCursor(empty_cursor);
|
||||
empty_cursor = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
Android_ShowCursor(SDL_Cursor *cursor)
|
||||
{
|
||||
if (!cursor) {
|
||||
cursor = Android_CreateEmptyCursor();
|
||||
}
|
||||
if (cursor) {
|
||||
SDL_AndroidCursorData *data = (SDL_AndroidCursorData *)cursor->driverdata;
|
||||
if (data->custom_cursor) {
|
||||
if (!Android_JNI_SetCustomCursor(data->custom_cursor)) {
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
} else {
|
||||
if (!Android_JNI_SetSystemCursor(data->system_cursor)) {
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
/* SDL error set inside Android_CreateEmptyCursor() */
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
Android_SetRelativeMouseMode(SDL_bool enabled)
|
||||
{
|
||||
if (!Android_JNI_SupportsRelativeMouse()) {
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
if (!Android_JNI_SetRelativeMouseEnabled(enabled)) {
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
Android_InitMouse(void)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
mouse->CreateCursor = Android_CreateCursor;
|
||||
mouse->CreateSystemCursor = Android_CreateSystemCursor;
|
||||
mouse->ShowCursor = Android_ShowCursor;
|
||||
mouse->FreeCursor = Android_FreeCursor;
|
||||
mouse->SetRelativeMouseMode = Android_SetRelativeMouseMode;
|
||||
|
||||
SDL_SetDefaultCursor(Android_CreateDefaultCursor());
|
||||
|
||||
last_state = 0;
|
||||
}
|
||||
|
||||
void
|
||||
Android_QuitMouse(void)
|
||||
{
|
||||
Android_DestroyEmptyCursor();
|
||||
}
|
||||
|
||||
/* Translate Android mouse button state to SDL mouse button */
|
||||
static Uint8
|
||||
TranslateButton(int state)
|
||||
|
|
@ -71,12 +220,12 @@ TranslateButton(int state)
|
|||
}
|
||||
|
||||
void
|
||||
Android_OnMouse(int state, int action, float x, float y)
|
||||
Android_OnMouse(SDL_Window *window, int state, int action, float x, float y, SDL_bool relative)
|
||||
{
|
||||
int changes;
|
||||
Uint8 button;
|
||||
|
||||
if (!Android_Window) {
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -85,25 +234,25 @@ Android_OnMouse(int state, int action, float x, float y)
|
|||
changes = state & ~last_state;
|
||||
button = TranslateButton(changes);
|
||||
last_state = state;
|
||||
SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
|
||||
SDL_SendMouseButton(Android_Window, 0, SDL_PRESSED, button);
|
||||
SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
|
||||
SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
|
||||
break;
|
||||
|
||||
case ACTION_UP:
|
||||
changes = last_state & ~state;
|
||||
button = TranslateButton(changes);
|
||||
last_state = state;
|
||||
SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
|
||||
SDL_SendMouseButton(Android_Window, 0, SDL_RELEASED, button);
|
||||
SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
|
||||
SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
|
||||
break;
|
||||
|
||||
case ACTION_MOVE:
|
||||
case ACTION_HOVER_MOVE:
|
||||
SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
|
||||
SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
|
||||
break;
|
||||
|
||||
case ACTION_SCROLL:
|
||||
SDL_SendMouseWheel(Android_Window, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
|
||||
SDL_SendMouseWheel(window, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -25,7 +25,8 @@
|
|||
#include "SDL_androidvideo.h"
|
||||
|
||||
extern void Android_InitMouse(void);
|
||||
extern void Android_OnMouse( int button, int action, float x, float y);
|
||||
extern void Android_OnMouse(SDL_Window *window, int button, int action, float x, float y, SDL_bool relative);
|
||||
extern void Android_QuitMouse(void);
|
||||
|
||||
#endif /* SDL_androidmouse_h_ */
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -40,104 +40,44 @@
|
|||
#define ACTION_POINTER_DOWN 5
|
||||
#define ACTION_POINTER_UP 6
|
||||
|
||||
static void Android_GetWindowCoordinates(float x, float y,
|
||||
int *window_x, int *window_y)
|
||||
{
|
||||
int window_w, window_h;
|
||||
|
||||
SDL_GetWindowSize(Android_Window, &window_w, &window_h);
|
||||
*window_x = (int)(x * window_w);
|
||||
*window_y = (int)(y * window_h);
|
||||
}
|
||||
|
||||
static SDL_bool separate_mouse_and_touch = SDL_FALSE;
|
||||
|
||||
static void SDLCALL
|
||||
SeparateEventsHintWatcher(void *userdata, const char *name,
|
||||
const char *oldValue, const char *newValue)
|
||||
{
|
||||
separate_mouse_and_touch = (newValue && (SDL_strcmp(newValue, "1") == 0));
|
||||
|
||||
Android_JNI_SetSeparateMouseAndTouch(separate_mouse_and_touch);
|
||||
}
|
||||
|
||||
void Android_InitTouch(void)
|
||||
{
|
||||
int i;
|
||||
int* ids;
|
||||
const int number = Android_JNI_GetTouchDeviceIds(&ids);
|
||||
|
||||
SDL_AddHintCallback(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH,
|
||||
SeparateEventsHintWatcher, NULL);
|
||||
|
||||
if (0 < number) {
|
||||
for (i = 0; i < number; ++i) {
|
||||
SDL_AddTouch((SDL_TouchID) ids[i], ""); /* no error handling */
|
||||
}
|
||||
SDL_free(ids);
|
||||
}
|
||||
/* Add all touch devices */
|
||||
Android_JNI_InitTouch();
|
||||
}
|
||||
|
||||
void Android_QuitTouch(void)
|
||||
{
|
||||
SDL_DelHintCallback(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH,
|
||||
SeparateEventsHintWatcher, NULL);
|
||||
separate_mouse_and_touch = SDL_FALSE;
|
||||
return;
|
||||
}
|
||||
|
||||
void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
|
||||
void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
|
||||
{
|
||||
SDL_TouchID touchDeviceId = 0;
|
||||
SDL_FingerID fingerId = 0;
|
||||
int window_x, window_y;
|
||||
static SDL_FingerID pointerFingerID = 0;
|
||||
|
||||
if (!Android_Window) {
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
|
||||
touchDeviceId = (SDL_TouchID)touch_device_id_in;
|
||||
if (SDL_AddTouch(touchDeviceId, "") < 0) {
|
||||
if (SDL_AddTouch(touchDeviceId, SDL_TOUCH_DEVICE_DIRECT, "") < 0) {
|
||||
SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
fingerId = (SDL_FingerID)pointer_finger_id_in;
|
||||
switch (action) {
|
||||
case ACTION_DOWN:
|
||||
/* Primary pointer down */
|
||||
if (!separate_mouse_and_touch) {
|
||||
Android_GetWindowCoordinates(x, y, &window_x, &window_y);
|
||||
/* send moved event */
|
||||
SDL_SendMouseMotion(Android_Window, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
|
||||
/* send mouse down event */
|
||||
SDL_SendMouseButton(Android_Window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
|
||||
}
|
||||
pointerFingerID = fingerId;
|
||||
case ACTION_POINTER_DOWN:
|
||||
/* Non primary pointer down */
|
||||
SDL_SendTouch(touchDeviceId, fingerId, SDL_TRUE, x, y, p);
|
||||
break;
|
||||
|
||||
case ACTION_MOVE:
|
||||
if (!pointerFingerID) {
|
||||
if (!separate_mouse_and_touch) {
|
||||
Android_GetWindowCoordinates(x, y, &window_x, &window_y);
|
||||
/* send moved event */
|
||||
SDL_SendMouseMotion(Android_Window, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
|
||||
}
|
||||
}
|
||||
SDL_SendTouchMotion(touchDeviceId, fingerId, x, y, p);
|
||||
break;
|
||||
|
||||
case ACTION_UP:
|
||||
/* Primary pointer up */
|
||||
if (!separate_mouse_and_touch) {
|
||||
/* send mouse up */
|
||||
SDL_SendMouseButton(Android_Window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
|
||||
}
|
||||
pointerFingerID = (SDL_FingerID) 0;
|
||||
case ACTION_POINTER_UP:
|
||||
/* Non primary pointer up */
|
||||
SDL_SendTouch(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
|
||||
break;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -24,6 +24,6 @@
|
|||
|
||||
extern void Android_InitTouch(void);
|
||||
extern void Android_QuitTouch(void);
|
||||
extern void Android_OnTouch( int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p);
|
||||
extern void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p);
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -22,11 +22,11 @@
|
|||
|
||||
#if SDL_VIDEO_DRIVER_ANDROID
|
||||
|
||||
/* Android SDL video driver implementation
|
||||
*/
|
||||
/* Android SDL video driver implementation */
|
||||
|
||||
#include "SDL_video.h"
|
||||
#include "SDL_mouse.h"
|
||||
#include "SDL_hints.h"
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "../SDL_pixels_c.h"
|
||||
#include "../../events/SDL_events_c.h"
|
||||
|
|
@ -47,7 +47,7 @@
|
|||
/* Initialization/Query functions */
|
||||
static int Android_VideoInit(_THIS);
|
||||
static void Android_VideoQuit(_THIS);
|
||||
int Android_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi);
|
||||
int Android_GetDisplayDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi);
|
||||
|
||||
#include "../SDL_egl_c.h"
|
||||
#define Android_GLES_GetProcAddress SDL_EGL_GetProcAddress
|
||||
|
|
@ -60,15 +60,15 @@ int Android_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float
|
|||
|
||||
|
||||
/* These are filled in with real values in Android_SetScreenResolution on init (before SDL_main()) */
|
||||
int Android_ScreenWidth = 0;
|
||||
int Android_ScreenHeight = 0;
|
||||
Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
|
||||
static int Android_ScreenRate = 0;
|
||||
|
||||
SDL_sem *Android_PauseSem = NULL, *Android_ResumeSem = NULL;
|
||||
|
||||
/* Currently only one window */
|
||||
SDL_Window *Android_Window = NULL;
|
||||
int Android_SurfaceWidth = 0;
|
||||
int Android_SurfaceHeight = 0;
|
||||
static int Android_DeviceWidth = 0;
|
||||
static int Android_DeviceHeight = 0;
|
||||
static Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
|
||||
static int Android_ScreenRate = 0;
|
||||
SDL_sem *Android_PauseSem = NULL;
|
||||
SDL_sem *Android_ResumeSem = NULL;
|
||||
SDL_mutex *Android_ActivityMutex = NULL;
|
||||
|
||||
static int
|
||||
Android_Available(void)
|
||||
|
|
@ -83,7 +83,7 @@ Android_SuspendScreenSaver(_THIS)
|
|||
}
|
||||
|
||||
static void
|
||||
Android_DeleteDevice(SDL_VideoDevice * device)
|
||||
Android_DeleteDevice(SDL_VideoDevice *device)
|
||||
{
|
||||
SDL_free(device->driverdata);
|
||||
SDL_free(device);
|
||||
|
|
@ -94,6 +94,7 @@ Android_CreateDevice(int devindex)
|
|||
{
|
||||
SDL_VideoDevice *device;
|
||||
SDL_VideoData *data;
|
||||
SDL_bool block_on_pause;
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
|
||||
|
|
@ -102,7 +103,7 @@ Android_CreateDevice(int devindex)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
data = (SDL_VideoData*) SDL_calloc(1, sizeof(SDL_VideoData));
|
||||
data = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
|
||||
if (!data) {
|
||||
SDL_OutOfMemory();
|
||||
SDL_free(device);
|
||||
|
|
@ -114,13 +115,19 @@ Android_CreateDevice(int devindex)
|
|||
/* Set the function pointers */
|
||||
device->VideoInit = Android_VideoInit;
|
||||
device->VideoQuit = Android_VideoQuit;
|
||||
device->PumpEvents = Android_PumpEvents;
|
||||
block_on_pause = SDL_GetHintBoolean(SDL_HINT_ANDROID_BLOCK_ON_PAUSE, SDL_TRUE);
|
||||
if (block_on_pause) {
|
||||
device->PumpEvents = Android_PumpEvents_Blocking;
|
||||
} else {
|
||||
device->PumpEvents = Android_PumpEvents_NonBlocking;
|
||||
}
|
||||
|
||||
device->GetDisplayDPI = Android_GetDisplayDPI;
|
||||
|
||||
device->CreateSDLWindow = Android_CreateWindow;
|
||||
device->SetWindowTitle = Android_SetWindowTitle;
|
||||
device->SetWindowFullscreen = Android_SetWindowFullscreen;
|
||||
device->MinimizeWindow = Android_MinimizeWindow;
|
||||
device->DestroyWindow = Android_DestroyWindow;
|
||||
device->GetWindowWMInfo = Android_GetWindowWMInfo;
|
||||
|
||||
|
|
@ -173,16 +180,26 @@ VideoBootStrap Android_bootstrap = {
|
|||
int
|
||||
Android_VideoInit(_THIS)
|
||||
{
|
||||
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
|
||||
int display_index;
|
||||
SDL_VideoDisplay *display;
|
||||
SDL_DisplayMode mode;
|
||||
|
||||
mode.format = Android_ScreenFormat;
|
||||
mode.w = Android_ScreenWidth;
|
||||
mode.h = Android_ScreenHeight;
|
||||
mode.refresh_rate = Android_ScreenRate;
|
||||
mode.driverdata = NULL;
|
||||
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
|
||||
videodata->isPaused = SDL_FALSE;
|
||||
videodata->isPausing = SDL_FALSE;
|
||||
|
||||
mode.format = Android_ScreenFormat;
|
||||
mode.w = Android_DeviceWidth;
|
||||
mode.h = Android_DeviceHeight;
|
||||
mode.refresh_rate = Android_ScreenRate;
|
||||
mode.driverdata = NULL;
|
||||
|
||||
display_index = SDL_AddBasicVideoDisplay(&mode);
|
||||
if (display_index < 0) {
|
||||
return -1;
|
||||
}
|
||||
display = SDL_GetDisplay(display_index);
|
||||
display->orientation = Android_JNI_GetDisplayOrientation();
|
||||
|
||||
SDL_AddDisplayMode(&_this->displays[0], &mode);
|
||||
|
||||
|
|
@ -199,53 +216,56 @@ Android_VideoInit(_THIS)
|
|||
void
|
||||
Android_VideoQuit(_THIS)
|
||||
{
|
||||
Android_QuitMouse();
|
||||
Android_QuitTouch();
|
||||
}
|
||||
|
||||
int
|
||||
Android_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi)
|
||||
Android_GetDisplayDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi)
|
||||
{
|
||||
return Android_JNI_GetDisplayDPI(ddpi, hdpi, vdpi);
|
||||
}
|
||||
|
||||
void
|
||||
Android_SetScreenResolution(int width, int height, Uint32 format, float rate)
|
||||
Android_SetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, Uint32 format, float rate)
|
||||
{
|
||||
SDL_VideoDevice* device;
|
||||
SDL_VideoDisplay *display;
|
||||
Android_ScreenWidth = width;
|
||||
Android_ScreenHeight = height;
|
||||
Android_ScreenFormat = format;
|
||||
Android_ScreenRate = rate;
|
||||
Android_SurfaceWidth = surfaceWidth;
|
||||
Android_SurfaceHeight = surfaceHeight;
|
||||
Android_DeviceWidth = deviceWidth;
|
||||
Android_DeviceHeight = deviceHeight;
|
||||
Android_ScreenFormat = format;
|
||||
Android_ScreenRate = (int)rate;
|
||||
}
|
||||
|
||||
void Android_SendResize(SDL_Window *window)
|
||||
{
|
||||
/*
|
||||
Update the resolution of the desktop mode, so that the window
|
||||
can be properly resized. The screen resolution change can for
|
||||
example happen when the Activity enters or exits immersive mode,
|
||||
which can happen after VideoInit().
|
||||
*/
|
||||
device = SDL_GetVideoDevice();
|
||||
SDL_VideoDevice *device = SDL_GetVideoDevice();
|
||||
if (device && device->num_displays > 0)
|
||||
{
|
||||
display = &device->displays[0];
|
||||
display->desktop_mode.format = Android_ScreenFormat;
|
||||
display->desktop_mode.w = Android_ScreenWidth;
|
||||
display->desktop_mode.h = Android_ScreenHeight;
|
||||
display->desktop_mode.refresh_rate = Android_ScreenRate;
|
||||
SDL_VideoDisplay *display = &device->displays[0];
|
||||
display->desktop_mode.format = Android_ScreenFormat;
|
||||
display->desktop_mode.w = Android_DeviceWidth;
|
||||
display->desktop_mode.h = Android_DeviceHeight;
|
||||
display->desktop_mode.refresh_rate = Android_ScreenRate;
|
||||
}
|
||||
|
||||
if (Android_Window) {
|
||||
if (window) {
|
||||
/* Force the current mode to match the resize otherwise the SDL_WINDOWEVENT_RESTORED event
|
||||
* will fall back to the old mode */
|
||||
display = SDL_GetDisplayForWindow(Android_Window);
|
||||
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
||||
display->display_modes[0].format = Android_ScreenFormat;
|
||||
display->display_modes[0].w = Android_DeviceWidth;
|
||||
display->display_modes[0].h = Android_DeviceHeight;
|
||||
display->display_modes[0].refresh_rate = Android_ScreenRate;
|
||||
display->current_mode = display->display_modes[0];
|
||||
|
||||
display->display_modes[0].format = format;
|
||||
display->display_modes[0].w = width;
|
||||
display->display_modes[0].h = height;
|
||||
display->display_modes[0].refresh_rate = rate;
|
||||
display->current_mode = display->display_modes[0];
|
||||
|
||||
SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESIZED, width, height);
|
||||
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, Android_SurfaceWidth, Android_SurfaceHeight);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -28,21 +28,22 @@
|
|||
#include "../SDL_sysvideo.h"
|
||||
|
||||
/* Called by the JNI layer when the screen changes size or format */
|
||||
extern void Android_SetScreenResolution(int width, int height, Uint32 format, float rate);
|
||||
extern void Android_SetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, Uint32 format, float rate);
|
||||
extern void Android_SendResize(SDL_Window *window);
|
||||
|
||||
/* Private display data */
|
||||
|
||||
typedef struct SDL_VideoData
|
||||
{
|
||||
SDL_Rect textRect;
|
||||
SDL_Rect textRect;
|
||||
int isPaused;
|
||||
int isPausing;
|
||||
} SDL_VideoData;
|
||||
|
||||
extern int Android_ScreenWidth;
|
||||
extern int Android_ScreenHeight;
|
||||
extern Uint32 Android_ScreenFormat;
|
||||
extern int Android_SurfaceWidth;
|
||||
extern int Android_SurfaceHeight;
|
||||
extern SDL_sem *Android_PauseSem, *Android_ResumeSem;
|
||||
extern SDL_Window *Android_Window;
|
||||
|
||||
extern SDL_mutex *Android_ActivityMutex;
|
||||
|
||||
#endif /* SDL_androidvideo_h_ */
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -26,22 +26,28 @@
|
|||
#include "../SDL_sysvideo.h"
|
||||
#include "../../events/SDL_keyboard_c.h"
|
||||
#include "../../events/SDL_mouse_c.h"
|
||||
#include "../../events/SDL_windowevents_c.h"
|
||||
#include "../../core/android/SDL_android.h"
|
||||
|
||||
#include "SDL_androidvideo.h"
|
||||
#include "SDL_androidwindow.h"
|
||||
#include "SDL_hints.h"
|
||||
|
||||
/* Currently only one window */
|
||||
SDL_Window *Android_Window = NULL;
|
||||
|
||||
int
|
||||
Android_CreateWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
SDL_WindowData *data;
|
||||
|
||||
int retval = 0;
|
||||
|
||||
Android_ActivityMutex_Lock_Running();
|
||||
|
||||
if (Android_Window) {
|
||||
return SDL_SetError("Android only supports one window");
|
||||
retval = SDL_SetError("Android only supports one window");
|
||||
goto endfunction;
|
||||
}
|
||||
|
||||
Android_PauseSem = SDL_CreateSemaphore(0);
|
||||
Android_ResumeSem = SDL_CreateSemaphore(0);
|
||||
|
||||
/* Set orientation */
|
||||
Android_JNI_SetOrientation(window->w, window->h, window->flags & SDL_WINDOW_RESIZABLE, SDL_GetHint(SDL_HINT_ORIENTATIONS));
|
||||
|
|
@ -49,28 +55,29 @@ Android_CreateWindow(_THIS, SDL_Window * window)
|
|||
/* Adjust the window data to match the screen */
|
||||
window->x = 0;
|
||||
window->y = 0;
|
||||
window->w = Android_ScreenWidth;
|
||||
window->h = Android_ScreenHeight;
|
||||
window->w = Android_SurfaceWidth;
|
||||
window->h = Android_SurfaceHeight;
|
||||
|
||||
window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */
|
||||
window->flags &= ~SDL_WINDOW_HIDDEN;
|
||||
window->flags |= SDL_WINDOW_SHOWN; /* only one window on Android */
|
||||
window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */
|
||||
|
||||
/* One window, it always has focus */
|
||||
SDL_SetMouseFocus(window);
|
||||
SDL_SetKeyboardFocus(window);
|
||||
|
||||
|
||||
data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
|
||||
if (!data) {
|
||||
return SDL_OutOfMemory();
|
||||
retval = SDL_OutOfMemory();
|
||||
goto endfunction;
|
||||
}
|
||||
|
||||
|
||||
data->native_window = Android_JNI_GetNativeWindow();
|
||||
|
||||
|
||||
if (!data->native_window) {
|
||||
SDL_free(data);
|
||||
return SDL_SetError("Could not fetch native window");
|
||||
retval = SDL_SetError("Could not fetch native window");
|
||||
goto endfunction;
|
||||
}
|
||||
|
||||
/* Do not create EGLSurface for Vulkan window since it will then make the window
|
||||
|
|
@ -81,42 +88,94 @@ Android_CreateWindow(_THIS, SDL_Window * window)
|
|||
if (data->egl_surface == EGL_NO_SURFACE) {
|
||||
ANativeWindow_release(data->native_window);
|
||||
SDL_free(data);
|
||||
return SDL_SetError("Could not create GLES window surface");
|
||||
retval = -1;
|
||||
goto endfunction;
|
||||
}
|
||||
}
|
||||
|
||||
window->driverdata = data;
|
||||
Android_Window = window;
|
||||
|
||||
return 0;
|
||||
|
||||
endfunction:
|
||||
|
||||
SDL_UnlockMutex(Android_ActivityMutex);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
void
|
||||
Android_SetWindowTitle(_THIS, SDL_Window * window)
|
||||
Android_SetWindowTitle(_THIS, SDL_Window *window)
|
||||
{
|
||||
Android_JNI_SetActivityTitle(window->title);
|
||||
}
|
||||
|
||||
void
|
||||
Android_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
|
||||
Android_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
|
||||
{
|
||||
Android_JNI_SetWindowStyle(fullscreen);
|
||||
SDL_LockMutex(Android_ActivityMutex);
|
||||
|
||||
if (window == Android_Window) {
|
||||
|
||||
/* If the window is being destroyed don't change visible state */
|
||||
if (!window->is_destroying) {
|
||||
Android_JNI_SetWindowStyle(fullscreen);
|
||||
}
|
||||
|
||||
/* Ensure our size matches reality after we've executed the window style change.
|
||||
*
|
||||
* It is possible that we've set width and height to the full-size display, but on
|
||||
* Samsung DeX or Chromebooks or other windowed Android environemtns, our window may
|
||||
* still not be the full display size.
|
||||
*/
|
||||
if (!SDL_IsDeXMode() && !SDL_IsChromebook()) {
|
||||
goto endfunction;
|
||||
}
|
||||
|
||||
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
|
||||
|
||||
if (!data || !data->native_window) {
|
||||
if (data && !data->native_window) {
|
||||
SDL_SetError("Missing native window");
|
||||
}
|
||||
goto endfunction;
|
||||
}
|
||||
|
||||
int old_w = window->w;
|
||||
int old_h = window->h;
|
||||
|
||||
int new_w = ANativeWindow_getWidth(data->native_window);
|
||||
int new_h = ANativeWindow_getHeight(data->native_window);
|
||||
|
||||
if (new_w < 0 || new_h < 0) {
|
||||
SDL_SetError("ANativeWindow_getWidth/Height() fails");
|
||||
}
|
||||
|
||||
if (old_w != new_w || old_h != new_h) {
|
||||
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, new_w, new_h);
|
||||
}
|
||||
}
|
||||
|
||||
endfunction:
|
||||
|
||||
SDL_UnlockMutex(Android_ActivityMutex);
|
||||
}
|
||||
|
||||
void
|
||||
Android_DestroyWindow(_THIS, SDL_Window * window)
|
||||
Android_MinimizeWindow(_THIS, SDL_Window *window)
|
||||
{
|
||||
SDL_WindowData *data;
|
||||
|
||||
Android_JNI_MinizeWindow();
|
||||
}
|
||||
|
||||
void
|
||||
Android_DestroyWindow(_THIS, SDL_Window *window)
|
||||
{
|
||||
SDL_LockMutex(Android_ActivityMutex);
|
||||
|
||||
if (window == Android_Window) {
|
||||
Android_Window = NULL;
|
||||
if (Android_PauseSem) SDL_DestroySemaphore(Android_PauseSem);
|
||||
if (Android_ResumeSem) SDL_DestroySemaphore(Android_ResumeSem);
|
||||
Android_PauseSem = NULL;
|
||||
Android_ResumeSem = NULL;
|
||||
|
||||
if(window->driverdata) {
|
||||
data = (SDL_WindowData *) window->driverdata;
|
||||
|
||||
if (window->driverdata) {
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
if (data->egl_surface != EGL_NO_SURFACE) {
|
||||
SDL_EGL_DestroySurface(_this, data->egl_surface);
|
||||
}
|
||||
|
|
@ -127,10 +186,12 @@ Android_DestroyWindow(_THIS, SDL_Window * window)
|
|||
window->driverdata = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_UnlockMutex(Android_ActivityMutex);
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
Android_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
|
||||
Android_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
|
||||
{
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -26,17 +26,20 @@
|
|||
#include "../../core/android/SDL_android.h"
|
||||
#include "../SDL_egl_c.h"
|
||||
|
||||
extern int Android_CreateWindow(_THIS, SDL_Window * window);
|
||||
extern void Android_SetWindowTitle(_THIS, SDL_Window * window);
|
||||
extern void Android_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
|
||||
extern void Android_DestroyWindow(_THIS, SDL_Window * window);
|
||||
extern SDL_bool Android_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo * info);
|
||||
extern int Android_CreateWindow(_THIS, SDL_Window *window);
|
||||
extern void Android_SetWindowTitle(_THIS, SDL_Window *window);
|
||||
extern void Android_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen);
|
||||
extern void Android_MinimizeWindow(_THIS, SDL_Window *window);
|
||||
|
||||
extern void Android_DestroyWindow(_THIS, SDL_Window *window);
|
||||
extern SDL_bool Android_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info);
|
||||
extern SDL_Window *Android_Window;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
EGLSurface egl_surface;
|
||||
EGLContext egl_context; /* We use this to preserve the context when losing focus */
|
||||
ANativeWindow* native_window;
|
||||
ANativeWindow *native_window;
|
||||
|
||||
} SDL_WindowData;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue