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