2010-06-10 18:54:23 +12:00
|
|
|
/*
|
2011-04-08 13:03:26 -07:00
|
|
|
Simple DirectMedia Layer
|
2014-02-02 00:53:27 -08:00
|
|
|
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
|
2011-04-08 13:03:26 -07:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
2010-06-10 18:54:23 +12:00
|
|
|
*/
|
2013-11-24 23:56:17 -05:00
|
|
|
#include "../../SDL_internal.h"
|
2010-06-10 18:54:23 +12:00
|
|
|
|
2011-10-31 05:56:58 -04:00
|
|
|
#if SDL_VIDEO_DRIVER_ANDROID
|
|
|
|
|
2010-06-10 18:54:23 +12:00
|
|
|
/* Android SDL video driver implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SDL_video.h"
|
|
|
|
#include "SDL_mouse.h"
|
|
|
|
#include "../SDL_sysvideo.h"
|
|
|
|
#include "../SDL_pixels_c.h"
|
|
|
|
#include "../../events/SDL_events_c.h"
|
2011-01-13 18:31:15 -08:00
|
|
|
#include "../../events/SDL_windowevents_c.h"
|
2010-06-10 18:54:23 +12:00
|
|
|
|
|
|
|
#include "SDL_androidvideo.h"
|
2012-09-26 20:14:37 -07:00
|
|
|
#include "SDL_androidclipboard.h"
|
2010-06-10 19:25:55 +12:00
|
|
|
#include "SDL_androidevents.h"
|
2011-01-12 13:52:41 -08:00
|
|
|
#include "SDL_androidkeyboard.h"
|
2013-10-05 17:08:19 +02:00
|
|
|
#include "SDL_androidtouch.h"
|
2011-01-13 15:10:17 -08:00
|
|
|
#include "SDL_androidwindow.h"
|
2010-06-10 18:54:23 +12:00
|
|
|
|
|
|
|
#define ANDROID_VID_DRIVER_NAME "Android"
|
|
|
|
|
|
|
|
/* Initialization/Query functions */
|
|
|
|
static int Android_VideoInit(_THIS);
|
|
|
|
static void Android_VideoQuit(_THIS);
|
|
|
|
|
2013-11-22 13:24:53 -03:00
|
|
|
#include "../SDL_egl_c.h"
|
2010-06-10 18:54:23 +12:00
|
|
|
/* GL functions (SDL_androidgl.c) */
|
2013-08-19 16:29:46 -03:00
|
|
|
extern SDL_GLContext Android_GLES_CreateContext(_THIS, SDL_Window * window);
|
|
|
|
extern int Android_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
|
|
|
|
extern void Android_GLES_SwapWindow(_THIS, SDL_Window * window);
|
|
|
|
extern int Android_GLES_LoadLibrary(_THIS, const char *path);
|
|
|
|
#define Android_GLES_GetProcAddress SDL_EGL_GetProcAddress
|
|
|
|
#define Android_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
|
|
|
|
#define Android_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
|
|
|
|
#define Android_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
|
|
|
|
#define Android_GLES_DeleteContext SDL_EGL_DeleteContext
|
2010-06-10 18:54:23 +12:00
|
|
|
|
|
|
|
/* Android driver bootstrap functions */
|
|
|
|
|
|
|
|
|
2013-05-18 14:17:52 -07:00
|
|
|
/* These are filled in with real values in Android_SetScreenResolution on init (before SDL_main()) */
|
2011-01-13 15:10:17 -08:00
|
|
|
int Android_ScreenWidth = 0;
|
|
|
|
int Android_ScreenHeight = 0;
|
|
|
|
Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
|
2015-01-23 20:29:08 +01:00
|
|
|
int Android_ScreenRate = 0;
|
|
|
|
|
2012-06-19 13:57:42 -03:00
|
|
|
SDL_sem *Android_PauseSem = NULL, *Android_ResumeSem = NULL;
|
2010-07-27 10:49:11 +02:00
|
|
|
|
2011-01-13 18:31:15 -08:00
|
|
|
/* Currently only one window */
|
|
|
|
SDL_Window *Android_Window = NULL;
|
2010-07-27 10:49:11 +02:00
|
|
|
|
2010-06-10 18:54:23 +12:00
|
|
|
static int
|
|
|
|
Android_Available(void)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-10-20 10:10:39 -03:00
|
|
|
static void
|
|
|
|
Android_SuspendScreenSaver(_THIS)
|
|
|
|
{
|
|
|
|
Android_JNI_SuspendScreenSaver(_this->suspend_screensaver);
|
|
|
|
}
|
|
|
|
|
2010-06-10 18:54:23 +12:00
|
|
|
static void
|
|
|
|
Android_DeleteDevice(SDL_VideoDevice * device)
|
|
|
|
{
|
2015-01-26 22:12:38 +01:00
|
|
|
SDL_free(device->driverdata);
|
2010-06-10 18:54:23 +12:00
|
|
|
SDL_free(device);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SDL_VideoDevice *
|
|
|
|
Android_CreateDevice(int devindex)
|
|
|
|
{
|
|
|
|
SDL_VideoDevice *device;
|
2012-10-03 20:49:16 -07:00
|
|
|
SDL_VideoData *data;
|
2010-06-10 18:54:23 +12:00
|
|
|
|
|
|
|
/* Initialize all variables that we clean on shutdown */
|
|
|
|
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
|
|
|
|
if (!device) {
|
|
|
|
SDL_OutOfMemory();
|
2012-10-03 20:49:16 -07:00
|
|
|
return NULL;
|
2010-06-10 18:54:23 +12:00
|
|
|
}
|
|
|
|
|
2012-10-03 20:49:16 -07:00
|
|
|
data = (SDL_VideoData*) SDL_calloc(1, sizeof(SDL_VideoData));
|
|
|
|
if (!data) {
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
SDL_free(device);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
device->driverdata = data;
|
|
|
|
|
2010-06-10 18:54:23 +12:00
|
|
|
/* Set the function pointers */
|
|
|
|
device->VideoInit = Android_VideoInit;
|
|
|
|
device->VideoQuit = Android_VideoQuit;
|
|
|
|
device->PumpEvents = Android_PumpEvents;
|
2011-01-12 13:52:41 -08:00
|
|
|
|
2011-01-13 15:10:17 -08:00
|
|
|
device->CreateWindow = Android_CreateWindow;
|
|
|
|
device->SetWindowTitle = Android_SetWindowTitle;
|
|
|
|
device->DestroyWindow = Android_DestroyWindow;
|
2014-06-02 09:01:26 -07:00
|
|
|
device->GetWindowWMInfo = Android_GetWindowWMInfo;
|
2011-01-13 15:10:17 -08:00
|
|
|
|
2010-06-10 18:54:23 +12:00
|
|
|
device->free = Android_DeleteDevice;
|
|
|
|
|
|
|
|
/* GL pointers */
|
2013-08-19 16:29:46 -03:00
|
|
|
device->GL_LoadLibrary = Android_GLES_LoadLibrary;
|
|
|
|
device->GL_GetProcAddress = Android_GLES_GetProcAddress;
|
|
|
|
device->GL_UnloadLibrary = Android_GLES_UnloadLibrary;
|
|
|
|
device->GL_CreateContext = Android_GLES_CreateContext;
|
|
|
|
device->GL_MakeCurrent = Android_GLES_MakeCurrent;
|
|
|
|
device->GL_SetSwapInterval = Android_GLES_SetSwapInterval;
|
|
|
|
device->GL_GetSwapInterval = Android_GLES_GetSwapInterval;
|
|
|
|
device->GL_SwapWindow = Android_GLES_SwapWindow;
|
|
|
|
device->GL_DeleteContext = Android_GLES_DeleteContext;
|
2010-06-10 18:54:23 +12:00
|
|
|
|
2014-10-20 10:10:39 -03:00
|
|
|
/* Screensaver */
|
|
|
|
device->SuspendScreenSaver = Android_SuspendScreenSaver;
|
|
|
|
|
2012-11-04 21:53:28 -08:00
|
|
|
/* Text input */
|
|
|
|
device->StartTextInput = Android_StartTextInput;
|
|
|
|
device->StopTextInput = Android_StopTextInput;
|
|
|
|
device->SetTextInputRect = Android_SetTextInputRect;
|
|
|
|
|
2012-08-11 10:15:59 -07:00
|
|
|
/* Screen keyboard */
|
2013-05-02 23:12:03 +02:00
|
|
|
device->HasScreenKeyboardSupport = Android_HasScreenKeyboardSupport;
|
|
|
|
device->IsScreenKeyboardShown = Android_IsScreenKeyboardShown;
|
2012-08-11 10:15:59 -07:00
|
|
|
|
2012-09-26 20:14:37 -07:00
|
|
|
/* Clipboard */
|
|
|
|
device->SetClipboardText = Android_SetClipboardText;
|
|
|
|
device->GetClipboardText = Android_GetClipboardText;
|
|
|
|
device->HasClipboardText = Android_HasClipboardText;
|
|
|
|
|
2010-06-10 18:54:23 +12:00
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoBootStrap Android_bootstrap = {
|
|
|
|
ANDROID_VID_DRIVER_NAME, "SDL Android video driver",
|
|
|
|
Android_Available, Android_CreateDevice
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
Android_VideoInit(_THIS)
|
|
|
|
{
|
|
|
|
SDL_DisplayMode mode;
|
|
|
|
|
2011-01-13 15:10:17 -08:00
|
|
|
mode.format = Android_ScreenFormat;
|
|
|
|
mode.w = Android_ScreenWidth;
|
|
|
|
mode.h = Android_ScreenHeight;
|
2015-01-23 20:29:08 +01:00
|
|
|
mode.refresh_rate = Android_ScreenRate;
|
2010-06-10 18:54:23 +12:00
|
|
|
mode.driverdata = NULL;
|
|
|
|
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_AddDisplayMode(&_this->displays[0], &mode);
|
|
|
|
|
2011-01-12 13:52:41 -08:00
|
|
|
Android_InitKeyboard();
|
2010-07-07 00:43:23 +12:00
|
|
|
|
2013-10-05 17:08:19 +02:00
|
|
|
Android_InitTouch();
|
|
|
|
|
2010-06-10 18:54:23 +12:00
|
|
|
/* We're done! */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Android_VideoQuit(_THIS)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-01-13 15:10:17 -08:00
|
|
|
/* This function gets called before VideoInit() */
|
2011-01-12 14:29:01 -08:00
|
|
|
void
|
2015-01-23 20:29:08 +01:00
|
|
|
Android_SetScreenResolution(int width, int height, Uint32 format, float rate)
|
2011-01-12 14:29:01 -08:00
|
|
|
{
|
2011-01-13 15:10:17 -08:00
|
|
|
Android_ScreenWidth = width;
|
2013-05-18 14:17:52 -07:00
|
|
|
Android_ScreenHeight = height;
|
2011-01-13 15:10:17 -08:00
|
|
|
Android_ScreenFormat = format;
|
2015-01-23 20:29:08 +01:00
|
|
|
Android_ScreenRate = rate;
|
2011-01-13 18:31:15 -08:00
|
|
|
|
|
|
|
if (Android_Window) {
|
|
|
|
SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESIZED, width, height);
|
|
|
|
}
|
2010-07-27 10:49:11 +02:00
|
|
|
}
|
|
|
|
|
2011-10-31 05:56:58 -04:00
|
|
|
#endif /* SDL_VIDEO_DRIVER_ANDROID */
|
|
|
|
|
2010-06-10 18:54:23 +12:00
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|