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