ScummVM API documentation
android.h
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 modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (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, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef _ANDROID_H_
23#define _ANDROID_H_
24
25#include <android/log.h>
26
27#include "common/fs.h"
28#include "common/archive.h"
29#include "common/mutex.h"
30#include "common/ustr.h"
31#include "backends/modular-backend.h"
32#include "backends/plugins/posix/posix-provider.h"
33#include "backends/fs/posix/posix-fs-factory.h"
34#include "backends/fs/posix/posix-fs-factory.h"
35#include "backends/log/log.h"
36#include "backends/platform/android/touchcontrols.h"
37#include "engines/engine.h"
38
39#include <pthread.h>
40
41// toggles start
42//#define ANDROID_DEBUG_ENTER
43//#define ANDROID_DEBUG_GL
44//#define ANDROID_DEBUG_GL_CALLS
45// toggles end
46
47extern const char *android_log_tag;
48
49#define _ANDROID_LOG(prio, fmt, args...) __android_log_print(prio, android_log_tag, fmt, ## args)
50#define LOGD(fmt, args...) _ANDROID_LOG(ANDROID_LOG_DEBUG, fmt, ##args)
51#define LOGI(fmt, args...) _ANDROID_LOG(ANDROID_LOG_INFO, fmt, ##args)
52#define LOGW(fmt, args...) _ANDROID_LOG(ANDROID_LOG_WARN, fmt, ##args)
53#define LOGE(fmt, args...) _ANDROID_LOG(ANDROID_LOG_ERROR, fmt, ##args)
54
55#define MAX_ANDROID_SCUMMVM_LOG_FILESIZE_IN_BYTES (100*1024)
56
57#ifdef ANDROID_DEBUG_ENTER
58#define ENTER(fmt, args...) LOGD("%s(" fmt ")", __FUNCTION__, ##args)
59#else
60#define ENTER(fmt, args...) do { } while (false)
61#endif
62
63#ifdef ANDROID_DEBUG_GL
64extern void checkGlError(const char *expr, const char *file, int line);
65
66#ifdef ANDROID_DEBUG_GL_CALLS
67#define GLCALLLOG(x, before) \
68 do { \
69 if (before) \
70 LOGD("calling '%s' (%s:%d)", x, __FILE__, __LINE__); \
71 else \
72 LOGD("returned from '%s' (%s:%d)", x, __FILE__, __LINE__); \
73 } while (false)
74#else
75#define GLCALLLOG(x, before) do { } while (false)
76#endif
77
78#define GLCALL(x) \
79 do { \
80 GLCALLLOG(#x, true); \
81 (x); \
82 GLCALLLOG(#x, false); \
83 checkGlError(#x, __FILE__, __LINE__); \
84 } while (false)
85
86#define GLTHREADCHECK \
87 do { \
88 assert(dynamic_cast<OSystem_Android *>(g_system)->isRunningInMainThread()); \
89 } while (false)
90
91#else
92#define GLCALL(x) do { (x); } while (false)
93#define GLTHREADCHECK do { } while (false)
94#endif
95
96void *androidGLgetProcAddress(const char *name);
97
99private:
100 static const int kQueuedInputEventDelay = 50;
101
102 struct EventWithDelay : public Common::Event {
104 uint32 originTimeMillis;
105
107 uint32 referTimeMillis;
108
110 uint32 delayMillis;
111
113 Common::EventType connectedType;
114
116 bool connectedTypeExecuted;
117
118 EventWithDelay() : originTimeMillis(0), referTimeMillis(0), delayMillis(0), connectedType(Common::EVENT_INVALID), connectedTypeExecuted(false) {
119 }
120
121 void reset() {
122 originTimeMillis = 0;
123 referTimeMillis = 0;
124 delayMillis = 0;
125 connectedType = Common::EVENT_INVALID;
126 connectedTypeExecuted = false;
127 }
128 };
129
130 int _screen_changeid;
131
132 pthread_t _main_thread;
133
134 bool _timer_thread_exit;
135 pthread_t _timer_thread;
136
137 bool _virtkeybd_on;
138
139 timeval _startTime;
140
141 PauseToken _pauseToken;
142
143 Common::Queue<Common::Event> _event_queue;
144 EventWithDelay _delayedMouseBtnUpEvent;
145 EventWithDelay _delayedMouseBtnDownEvent;
146 Common::Mutex *_event_queue_lock;
147
148 Common::Point _touch_pt_down, _touch_pt_scroll, _touch_pt_dt, _touch_pt_multi;
149 int _eventScaleX;
150 int _eventScaleY;
151 int _touch_mode;
152 int _touchpad_scale; // Used in events.cpp
153 int _trackball_scale; // Used in events.cpp
154 int _dpad_scale; // Used in events.cpp
155 int _joystick_scale; // TODO This seems currently unused. Is it needed?
156// int _fingersDown;
157 int _firstPointerId;
158 int _secondPointerId;
159 int _thirdPointerId;
160
161 TouchControls _touchControls;
162
163 bool _engineRunning;
164
165 Common::Path _defaultConfigFileName;
166 Common::Path _defaultLogFileName;
167 Common::String _systemPropertiesSummaryStr;
168 Common::String _systemSDKdetectedStr;
169
170 Backends::Log::Log *_logger;
171
172#if defined(USE_OPENGL) && defined(USE_GLAD)
173 // Cached dlopen object
174 mutable void *_gles2DL;
175#endif
176
177 static void *timerThreadFunc(void *arg);
178 void initAudio();
179 Common::String getSystemProperty(const char *name) const;
180
181 Common::WriteStream *createLogFileForAppending();
182
183public:
184 enum {
185 TOUCH_MODE_TOUCHPAD = 0,
186 TOUCH_MODE_MOUSE = 1,
187 TOUCH_MODE_GAMEPAD = 2,
188 TOUCH_MODE_MAX = 3
189 };
190
191 enum {
192 SCREEN_ORIENTATION_UNSPECIFIED = 0xffffffff,
193 SCREEN_ORIENTATION_LANDSCAPE = 0,
194 SCREEN_ORIENTATION_PORTRAIT = 1
195 };
196
197 enum {
198 SHOW_ON_SCREEN_NONE = 0,
199 SHOW_ON_SCREEN_MENU = 1,
200 SHOW_ON_SCREEN_INPUT_MODE = 2,
201 SHOW_ON_SCREEN_ALL = 0xffffffff,
202 };
203
205 virtual ~OSystem_Android();
206
207 void initBackend() override;
208 void engineInit() override;
209 void engineDone() override;
210
211 void updateStartSettings(const Common::String &executable, Common::String &command, Common::StringMap &startSettings, Common::StringArray& additionalArgs) override;
212
213 bool hasFeature(OSystem::Feature f) override;
214 void setFeatureState(OSystem::Feature f, bool enable) override;
216
217 void setPause(bool pause);
218
219 void pushEvent(int type, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6);
220 void pushEvent(const Common::Event &event);
221 void pushEvent(const Common::Event &event1, const Common::Event &event2);
222 void pushDelayedTouchMouseBtnEvents();
223
224 TouchControls &getTouchControls() { return _touchControls; }
225 void applyTouchSettings(bool _3dMode, bool overlayShown);
226 void setupTouchMode(int oldValue, int newValue);
227
228 void applyOrientationSettings();
229
230 void updateOnScreenControls();
231
232 bool pollEvent(Common::Event &event) override;
236
239
240 void registerDefaultSettings(const Common::String &target) const override;
242 void applyBackendSettings() override;
243
244 uint32 getMillis(bool skipRecord = false) override;
245 void delayMillis(uint msecs) override;
247
248 void quit() override;
249
250 void setWindowCaption(const Common::U32String &caption) override;
251
252 void getTimeAndDate(TimeDate &td, bool skipRecord = false) const override;
253 void logMessage(LogMessageType::Type type, const char *message) override;
254 void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0) override;
255 bool openUrl(const Common::String &url) override;
256 bool hasTextInClipboard() override;
258 bool setTextInClipboard(const Common::U32String &text) override;
259 bool isConnectionLimited() override;
261
262#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS)
263 OpenGL::ContextType getOpenGLType() const override { return OpenGL::kContextGLES2; }
265#endif
266#if defined(USE_OPENGL) && defined(USE_GLAD)
267 void *getOpenGLProcAddress(const char *name) const override;
268#endif
269
270#ifdef ANDROID_DEBUG_GL
271 bool isRunningInMainThread() { return pthread_self() == _main_thread; }
272#endif
273
274 const char * const *buildHelpDialogData() override;
275};
276
277#endif
Definition: log.h:41
Definition: events.h:278
Definition: hardware-input.h:199
Definition: keymapper-defaults.h:32
Definition: mutex.h:67
Definition: mutex.h:40
Definition: path.h:52
Definition: archive.h:330
Definition: str.h:59
Definition: ustr.h:57
Definition: stream.h:77
Definition: object.h:60
Definition: widget.h:542
Definition: modular-backend.h:48
Definition: modular-backend.h:152
Definition: android.h:98
void delayMillis(uint msecs) override
void initBackend() override
void engineInit() override
uint32 getMillis(bool skipRecord=false) override
bool hasTextInClipboard() override
void registerDefaultSettings(const Common::String &target) const override
void quit() override
void getTimeAndDate(TimeDate &td, bool skipRecord=false) const override
void updateStartSettings(const Common::String &executable, Common::String &command, Common::StringMap &startSettings, Common::StringArray &additionalArgs) override
bool hasFeature(OSystem::Feature f) override
bool openUrl(const Common::String &url) override
bool pollEvent(Common::Event &event) override
Common::U32String getTextFromClipboard() override
bool getFeatureState(OSystem::Feature f) override
void engineDone() override
void setWindowCaption(const Common::U32String &caption) override
Common::MutexInternal * createMutex() override
void logMessage(LogMessageType::Type type, const char *message) override
bool setTextInClipboard(const Common::U32String &text) override
Common::HardwareInputSet * getHardwareInputSet() override
bool isConnectionLimited() override
void addSysArchivesToSearchSet(Common::SearchSet &s, int priority=0) override
Common::Path getDefaultConfigFileName() override
GUI::OptionsContainerWidget * buildBackendOptionsWidget(GUI::GuiObject *boss, const Common::String &name, const Common::String &target) const override
Common::KeymapperDefaultBindings * getKeymapperDefaultBindings() override
Common::KeymapArray getGlobalKeymaps() override
Common::String getSystemLanguage() const override
void setFeatureState(OSystem::Feature f, bool enable) override
void applyBackendSettings() override
Common::Path getDefaultLogFileName() override
const char *const * buildHelpDialogData() override
Definition: engine.h:110
Definition: touchcontrols.h:41
EventType
Definition: events.h:49
Feature
Definition: system.h:415
virtual OpenGL::ContextType getOpenGLType() const
Definition: system.h:901
virtual Common::Array< uint > getSupportedAntiAliasingLevels() const
Definition: system.h:887
Type
Definition: log.h:33
Definition: events.h:218
Definition: rect.h:144
Definition: system.h:111