src/video/android/SDL_androidvideo.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Fri, 23 Jan 2015 20:29:08 +0100
changeset 9314 8d826bc39a45
parent 9173 c677ab1148c5
child 9317 a8350b28a05c
permissions -rw-r--r--
Fixed bug 2816 - [patch] Android: Expose screen refresh rate Jonas Kulla Display::getRefreshRate() is available on all API levels.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     2
  Simple DirectMedia Layer
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     7
  arising from the use of this software.
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    11
  freely, subject to the following restrictions:
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    20
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 8021
diff changeset
    21
#include "../../SDL_internal.h"
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    22
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    23
#if SDL_VIDEO_DRIVER_ANDROID
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    24
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    25
/* Android SDL video driver implementation
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    26
*/
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    27
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    28
#include "SDL_video.h"
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    29
#include "SDL_mouse.h"
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    30
#include "../SDL_sysvideo.h"
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    31
#include "../SDL_pixels_c.h"
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    32
#include "../../events/SDL_events_c.h"
5001
77df56570442 Added "mouse" support for the Android touch screen
Sam Lantinga <slouken@libsdl.org>
parents: 4998
diff changeset
    33
#include "../../events/SDL_windowevents_c.h"
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    34
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    35
#include "SDL_androidvideo.h"
6464
ab55284b389f Fixed bug 1573 - SDL does not support system clipboard on Android.
Sam Lantinga <slouken@libsdl.org>
parents: 6392
diff changeset
    36
#include "SDL_androidclipboard.h"
4703
c93b44ddc63e Fixed #includes to fix naming conventions
Paul Hunkin <paul@bieh.net>
parents: 4701
diff changeset
    37
#include "SDL_androidevents.h"
4980
d9fdff945ec9 A bit of cleanup in the Android driver
Sam Lantinga <slouken@libsdl.org>
parents: 4963
diff changeset
    38
#include "SDL_androidkeyboard.h"
7786
cfc1285375e1 Added detection of touch devices before first touch events happen on Android.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7659
diff changeset
    39
#include "SDL_androidtouch.h"
4998
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents: 4981
diff changeset
    40
#include "SDL_androidwindow.h"
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    41
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    42
#define ANDROID_VID_DRIVER_NAME "Android"
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    43
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    44
/* Initialization/Query functions */
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    45
static int Android_VideoInit(_THIS);
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    46
static void Android_VideoQuit(_THIS);
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    47
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7786
diff changeset
    48
#include "../SDL_egl_c.h"
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    49
/* GL functions (SDL_androidgl.c) */
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7253
diff changeset
    50
extern SDL_GLContext Android_GLES_CreateContext(_THIS, SDL_Window * window);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7253
diff changeset
    51
extern int Android_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7253
diff changeset
    52
extern void Android_GLES_SwapWindow(_THIS, SDL_Window * window);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7253
diff changeset
    53
extern int Android_GLES_LoadLibrary(_THIS, const char *path);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7253
diff changeset
    54
#define Android_GLES_GetProcAddress SDL_EGL_GetProcAddress
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7253
diff changeset
    55
#define Android_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7253
diff changeset
    56
#define Android_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7253
diff changeset
    57
#define Android_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7253
diff changeset
    58
#define Android_GLES_DeleteContext SDL_EGL_DeleteContext
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    59
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    60
/* Android driver bootstrap functions */
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    61
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    62
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7135
diff changeset
    63
/* These are filled in with real values in Android_SetScreenResolution on init (before SDL_main()) */
4998
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents: 4981
diff changeset
    64
int Android_ScreenWidth = 0;
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents: 4981
diff changeset
    65
int Android_ScreenHeight = 0;
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents: 4981
diff changeset
    66
Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
9314
8d826bc39a45 Fixed bug 2816 - [patch] Android: Expose screen refresh rate
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9173
diff changeset
    67
int Android_ScreenRate = 0;
8d826bc39a45 Fixed bug 2816 - [patch] Android: Expose screen refresh rate
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9173
diff changeset
    68
6330
0fa55ca2efdd Fixes #1422, restores GL context automatically under Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
    69
SDL_sem *Android_PauseSem = NULL, *Android_ResumeSem = NULL;
4716
f2c2a33a1a38 Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents: 4713
diff changeset
    70
5001
77df56570442 Added "mouse" support for the Android touch screen
Sam Lantinga <slouken@libsdl.org>
parents: 4998
diff changeset
    71
/* Currently only one window */
77df56570442 Added "mouse" support for the Android touch screen
Sam Lantinga <slouken@libsdl.org>
parents: 4998
diff changeset
    72
SDL_Window *Android_Window = NULL;
4716
f2c2a33a1a38 Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents: 4713
diff changeset
    73
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    74
static int
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    75
Android_Available(void)
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    76
{
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    77
    return 1;
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    78
}
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    79
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    80
static void
9173
c677ab1148c5 Bug 2739 - [Android] No support for SDL_DisableScreenSaver by Martin Gerhardy
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8799
diff changeset
    81
Android_SuspendScreenSaver(_THIS)
c677ab1148c5 Bug 2739 - [Android] No support for SDL_DisableScreenSaver by Martin Gerhardy
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8799
diff changeset
    82
{
c677ab1148c5 Bug 2739 - [Android] No support for SDL_DisableScreenSaver by Martin Gerhardy
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8799
diff changeset
    83
    Android_JNI_SuspendScreenSaver(_this->suspend_screensaver);
c677ab1148c5 Bug 2739 - [Android] No support for SDL_DisableScreenSaver by Martin Gerhardy
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8799
diff changeset
    84
}
c677ab1148c5 Bug 2739 - [Android] No support for SDL_DisableScreenSaver by Martin Gerhardy
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8799
diff changeset
    85
c677ab1148c5 Bug 2739 - [Android] No support for SDL_DisableScreenSaver by Martin Gerhardy
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8799
diff changeset
    86
static void
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    87
Android_DeleteDevice(SDL_VideoDevice * device)
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    88
{
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    89
    SDL_free(device);
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    90
}
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    91
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    92
static SDL_VideoDevice *
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    93
Android_CreateDevice(int devindex)
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    94
{
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    95
    SDL_VideoDevice *device;
6555
f2c03c06d987 Fixed bug 1614 - SDL for Android does not implement TextInput API
Sam Lantinga <slouken@libsdl.org>
parents: 6464
diff changeset
    96
    SDL_VideoData *data;
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    97
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    98
    /* Initialize all variables that we clean on shutdown */
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    99
    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   100
    if (!device) {
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   101
        SDL_OutOfMemory();
6555
f2c03c06d987 Fixed bug 1614 - SDL for Android does not implement TextInput API
Sam Lantinga <slouken@libsdl.org>
parents: 6464
diff changeset
   102
        return NULL;
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   103
    }
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   104
6555
f2c03c06d987 Fixed bug 1614 - SDL for Android does not implement TextInput API
Sam Lantinga <slouken@libsdl.org>
parents: 6464
diff changeset
   105
    data = (SDL_VideoData*) SDL_calloc(1, sizeof(SDL_VideoData));
f2c03c06d987 Fixed bug 1614 - SDL for Android does not implement TextInput API
Sam Lantinga <slouken@libsdl.org>
parents: 6464
diff changeset
   106
    if (!data) {
f2c03c06d987 Fixed bug 1614 - SDL for Android does not implement TextInput API
Sam Lantinga <slouken@libsdl.org>
parents: 6464
diff changeset
   107
        SDL_OutOfMemory();
f2c03c06d987 Fixed bug 1614 - SDL for Android does not implement TextInput API
Sam Lantinga <slouken@libsdl.org>
parents: 6464
diff changeset
   108
        SDL_free(device);
f2c03c06d987 Fixed bug 1614 - SDL for Android does not implement TextInput API
Sam Lantinga <slouken@libsdl.org>
parents: 6464
diff changeset
   109
        return NULL;
f2c03c06d987 Fixed bug 1614 - SDL for Android does not implement TextInput API
Sam Lantinga <slouken@libsdl.org>
parents: 6464
diff changeset
   110
    }
f2c03c06d987 Fixed bug 1614 - SDL for Android does not implement TextInput API
Sam Lantinga <slouken@libsdl.org>
parents: 6464
diff changeset
   111
f2c03c06d987 Fixed bug 1614 - SDL for Android does not implement TextInput API
Sam Lantinga <slouken@libsdl.org>
parents: 6464
diff changeset
   112
    device->driverdata = data;
f2c03c06d987 Fixed bug 1614 - SDL for Android does not implement TextInput API
Sam Lantinga <slouken@libsdl.org>
parents: 6464
diff changeset
   113
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   114
    /* Set the function pointers */
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   115
    device->VideoInit = Android_VideoInit;
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   116
    device->VideoQuit = Android_VideoQuit;
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   117
    device->PumpEvents = Android_PumpEvents;
4980
d9fdff945ec9 A bit of cleanup in the Android driver
Sam Lantinga <slouken@libsdl.org>
parents: 4963
diff changeset
   118
4998
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents: 4981
diff changeset
   119
    device->CreateWindow = Android_CreateWindow;
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents: 4981
diff changeset
   120
    device->SetWindowTitle = Android_SetWindowTitle;
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents: 4981
diff changeset
   121
    device->DestroyWindow = Android_DestroyWindow;
8799
e2fd743d84ea Added a way to get the native Android window and EGL context
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   122
    device->GetWindowWMInfo = Android_GetWindowWMInfo;
4998
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents: 4981
diff changeset
   123
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   124
    device->free = Android_DeleteDevice;
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   125
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   126
    /* GL pointers */
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7253
diff changeset
   127
    device->GL_LoadLibrary = Android_GLES_LoadLibrary;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7253
diff changeset
   128
    device->GL_GetProcAddress = Android_GLES_GetProcAddress;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7253
diff changeset
   129
    device->GL_UnloadLibrary = Android_GLES_UnloadLibrary;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7253
diff changeset
   130
    device->GL_CreateContext = Android_GLES_CreateContext;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7253
diff changeset
   131
    device->GL_MakeCurrent = Android_GLES_MakeCurrent;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7253
diff changeset
   132
    device->GL_SetSwapInterval = Android_GLES_SetSwapInterval;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7253
diff changeset
   133
    device->GL_GetSwapInterval = Android_GLES_GetSwapInterval;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7253
diff changeset
   134
    device->GL_SwapWindow = Android_GLES_SwapWindow;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7253
diff changeset
   135
    device->GL_DeleteContext = Android_GLES_DeleteContext;
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   136
9173
c677ab1148c5 Bug 2739 - [Android] No support for SDL_DisableScreenSaver by Martin Gerhardy
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8799
diff changeset
   137
    /* Screensaver */
c677ab1148c5 Bug 2739 - [Android] No support for SDL_DisableScreenSaver by Martin Gerhardy
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8799
diff changeset
   138
    device->SuspendScreenSaver = Android_SuspendScreenSaver;
c677ab1148c5 Bug 2739 - [Android] No support for SDL_DisableScreenSaver by Martin Gerhardy
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8799
diff changeset
   139
6654
2ecfb25be1e2 Synchronized the on-screen keyboard state with whether we are accepting text input.
Sam Lantinga <slouken@libsdl.org>
parents: 6555
diff changeset
   140
    /* Text input */
2ecfb25be1e2 Synchronized the on-screen keyboard state with whether we are accepting text input.
Sam Lantinga <slouken@libsdl.org>
parents: 6555
diff changeset
   141
    device->StartTextInput = Android_StartTextInput;
2ecfb25be1e2 Synchronized the on-screen keyboard state with whether we are accepting text input.
Sam Lantinga <slouken@libsdl.org>
parents: 6555
diff changeset
   142
    device->StopTextInput = Android_StopTextInput;
2ecfb25be1e2 Synchronized the on-screen keyboard state with whether we are accepting text input.
Sam Lantinga <slouken@libsdl.org>
parents: 6555
diff changeset
   143
    device->SetTextInputRect = Android_SetTextInputRect;
2ecfb25be1e2 Synchronized the on-screen keyboard state with whether we are accepting text input.
Sam Lantinga <slouken@libsdl.org>
parents: 6555
diff changeset
   144
6392
fa7eb111f994 Fixed bug 1564 - SDL has no function to open a screen keyboard on Android.
Sam Lantinga <slouken@libsdl.org>
parents: 6330
diff changeset
   145
    /* Screen keyboard */
7135
20db445af8c7 Removed SDL prefix from internal function pointers for screen keyboard access.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 6885
diff changeset
   146
    device->HasScreenKeyboardSupport = Android_HasScreenKeyboardSupport;
20db445af8c7 Removed SDL prefix from internal function pointers for screen keyboard access.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 6885
diff changeset
   147
    device->IsScreenKeyboardShown = Android_IsScreenKeyboardShown;
6392
fa7eb111f994 Fixed bug 1564 - SDL has no function to open a screen keyboard on Android.
Sam Lantinga <slouken@libsdl.org>
parents: 6330
diff changeset
   148
6464
ab55284b389f Fixed bug 1573 - SDL does not support system clipboard on Android.
Sam Lantinga <slouken@libsdl.org>
parents: 6392
diff changeset
   149
    /* Clipboard */
ab55284b389f Fixed bug 1573 - SDL does not support system clipboard on Android.
Sam Lantinga <slouken@libsdl.org>
parents: 6392
diff changeset
   150
    device->SetClipboardText = Android_SetClipboardText;
ab55284b389f Fixed bug 1573 - SDL does not support system clipboard on Android.
Sam Lantinga <slouken@libsdl.org>
parents: 6392
diff changeset
   151
    device->GetClipboardText = Android_GetClipboardText;
ab55284b389f Fixed bug 1573 - SDL does not support system clipboard on Android.
Sam Lantinga <slouken@libsdl.org>
parents: 6392
diff changeset
   152
    device->HasClipboardText = Android_HasClipboardText;
ab55284b389f Fixed bug 1573 - SDL does not support system clipboard on Android.
Sam Lantinga <slouken@libsdl.org>
parents: 6392
diff changeset
   153
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   154
    return device;
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   155
}
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   156
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   157
VideoBootStrap Android_bootstrap = {
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   158
    ANDROID_VID_DRIVER_NAME, "SDL Android video driver",
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   159
    Android_Available, Android_CreateDevice
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   160
};
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   161
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   162
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   163
int
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   164
Android_VideoInit(_THIS)
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   165
{
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   166
    SDL_DisplayMode mode;
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   167
4998
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents: 4981
diff changeset
   168
    mode.format = Android_ScreenFormat;
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents: 4981
diff changeset
   169
    mode.w = Android_ScreenWidth;
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents: 4981
diff changeset
   170
    mode.h = Android_ScreenHeight;
9314
8d826bc39a45 Fixed bug 2816 - [patch] Android: Expose screen refresh rate
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9173
diff changeset
   171
    mode.refresh_rate = Android_ScreenRate;
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   172
    mode.driverdata = NULL;
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   173
    if (SDL_AddBasicVideoDisplay(&mode) < 0) {
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   174
        return -1;
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   175
    }
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   176
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   177
    SDL_AddDisplayMode(&_this->displays[0], &mode);
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   178
4980
d9fdff945ec9 A bit of cleanup in the Android driver
Sam Lantinga <slouken@libsdl.org>
parents: 4963
diff changeset
   179
    Android_InitKeyboard();
4713
ba38983b10c2 Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents: 4707
diff changeset
   180
7786
cfc1285375e1 Added detection of touch devices before first touch events happen on Android.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7659
diff changeset
   181
    Android_InitTouch();
cfc1285375e1 Added detection of touch devices before first touch events happen on Android.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7659
diff changeset
   182
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   183
    /* We're done! */
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   184
    return 0;
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   185
}
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   186
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   187
void
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   188
Android_VideoQuit(_THIS)
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   189
{
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   190
}
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   191
4998
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents: 4981
diff changeset
   192
/* This function gets called before VideoInit() */
4981
55b82067815b Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents: 4980
diff changeset
   193
void
9314
8d826bc39a45 Fixed bug 2816 - [patch] Android: Expose screen refresh rate
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9173
diff changeset
   194
Android_SetScreenResolution(int width, int height, Uint32 format, float rate)
4981
55b82067815b Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents: 4980
diff changeset
   195
{
4998
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents: 4981
diff changeset
   196
    Android_ScreenWidth = width;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7135
diff changeset
   197
    Android_ScreenHeight = height;
4998
a514bfe6952a The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents: 4981
diff changeset
   198
    Android_ScreenFormat = format;
9314
8d826bc39a45 Fixed bug 2816 - [patch] Android: Expose screen refresh rate
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9173
diff changeset
   199
    Android_ScreenRate = rate;
5001
77df56570442 Added "mouse" support for the Android touch screen
Sam Lantinga <slouken@libsdl.org>
parents: 4998
diff changeset
   200
77df56570442 Added "mouse" support for the Android touch screen
Sam Lantinga <slouken@libsdl.org>
parents: 4998
diff changeset
   201
    if (Android_Window) {
77df56570442 Added "mouse" support for the Android touch screen
Sam Lantinga <slouken@libsdl.org>
parents: 4998
diff changeset
   202
        SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESIZED, width, height);
77df56570442 Added "mouse" support for the Android touch screen
Sam Lantinga <slouken@libsdl.org>
parents: 4998
diff changeset
   203
    }
4716
f2c2a33a1a38 Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents: 4713
diff changeset
   204
}
f2c2a33a1a38 Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents: 4713
diff changeset
   205
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   206
#endif /* SDL_VIDEO_DRIVER_ANDROID */
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   207
4701
d40bb3165d2b Added (partially implemented) android video backend and associated files needed to build
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   208
/* vi: set ts=4 sw=4 expandtab: */