1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 // Allow use of stuff in <time.h>
24 #define FORBIDDEN_SYMBOL_EXCEPTION_time_h
25
26 // Disable printf override in common/forbidden.h to avoid
27 // clashes with log.h from the Android SDK.
28 // That header file uses
29 // __attribute__ ((format(printf, 3, 4)))
30 // which gets messed up by our override mechanism; this could
31 // be avoided by either changing the Android SDK to use the equally
32 // legal and valid
33 // __attribute__ ((format(printf, 3, 4)))
34 // or by refining our printf override to use a varadic macro
35 // (which then wouldn't be portable, though).
36 // Anyway, for now we just disable the printf override globally
37 // for the Android port
38 #define FORBIDDEN_SYMBOL_EXCEPTION_printf
39
40 #include "backends/platform/android/android.h"
41 #include "backends/platform/android/graphics.h"
42 #include "backends/platform/android/jni-android.h"
43
44 //
45 // AndroidGraphicsManager
46 //
AndroidGraphicsManager()47 AndroidGraphicsManager::AndroidGraphicsManager() {
48 ENTER();
49
50 // Initialize our OpenGL ES context.
51 initSurface();
52
53 }
54
~AndroidGraphicsManager()55 AndroidGraphicsManager::~AndroidGraphicsManager() {
56 ENTER();
57
58 deinitSurface();
59 }
60
initSurface()61 void AndroidGraphicsManager::initSurface() {
62 LOGD("initializing surface");
63
64 assert(!JNI::haveSurface());
65 JNI::initSurface();
66
67 // Notify the OpenGL code about our context.
68 // FIXME: Support OpenGL ES 2 contexts
69 setContextType(OpenGL::kContextGLES);
70
71 // We default to RGB565 and RGBA5551 which is closest to the actual output
72 // mode we setup.
73 notifyContextCreate(Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0), Graphics::PixelFormat(2, 5, 5, 5, 1, 11, 6, 1, 0));
74
75 float dpi[2];
76 JNI::getDPI(dpi);
77 handleResize(JNI::egl_surface_width, JNI::egl_surface_height, dpi[0], dpi[1]);
78 }
79
deinitSurface()80 void AndroidGraphicsManager::deinitSurface() {
81 if (!JNI::haveSurface())
82 return;
83
84 LOGD("deinitializing surface");
85
86 notifyContextDestroy();
87
88 JNI::deinitSurface();
89 }
90
updateScreen()91 void AndroidGraphicsManager::updateScreen() {
92 //ENTER();
93
94 if (!JNI::haveSurface())
95 return;
96
97 OpenGLGraphicsManager::updateScreen();
98 }
99
displayMessageOnOSD(const char * msg)100 void AndroidGraphicsManager::displayMessageOnOSD(const char *msg) {
101 ENTER("%s", msg);
102
103 JNI::displayMessageOnOSD(msg);
104 }
105
loadVideoMode(uint requestedWidth,uint requestedHeight,const Graphics::PixelFormat & format)106 bool AndroidGraphicsManager::loadVideoMode(uint requestedWidth, uint requestedHeight, const Graphics::PixelFormat &format) {
107 ENTER("%d, %d, %s", requestedWidth, requestedHeight, format.toString().c_str());
108
109 // We get this whenever a new resolution is requested. Since Android is
110 // using a fixed output size we do nothing like that here.
111 // TODO: Support screen rotation
112 return true;
113 }
114
refreshScreen()115 void AndroidGraphicsManager::refreshScreen() {
116 //ENTER();
117
118 JNI::swapBuffers();
119 }
120
getProcAddress(const char * name) const121 void *AndroidGraphicsManager::getProcAddress(const char *name) const {
122 ENTER("%s", name);
123
124 // TODO: Support dynamically loaded OpenGL
125 return nullptr;
126 }
127
notifyMousePosition(Common::Point & mouse)128 bool AndroidGraphicsManager::notifyMousePosition(Common::Point &mouse) {
129 mouse.x = CLIP<int16>(mouse.x, _activeArea.drawRect.left, _activeArea.drawRect.right);
130 mouse.y = CLIP<int16>(mouse.y, _activeArea.drawRect.top, _activeArea.drawRect.bottom);
131
132 setMousePosition(mouse.x, mouse.y);
133 mouse = convertWindowToVirtual(mouse.x, mouse.y);
134
135 return true;
136 }
137