os_android.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*************************************************************************/
  2. /* os_android.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef OS_ANDROID_H
  31. #define OS_ANDROID_H
  32. #include "audio_driver_jandroid.h"
  33. #include "audio_driver_opensl.h"
  34. #include "drivers/unix/os_unix.h"
  35. #include "main/input_default.h"
  36. #include "os/input.h"
  37. #include "os/main_loop.h"
  38. //#include "power_android.h"
  39. #include "servers/audio_server.h"
  40. #include "servers/visual/rasterizer.h"
  41. #ifdef ANDROID_NATIVE_ACTIVITY
  42. #include <android/log.h>
  43. #include <android/sensor.h>
  44. #include <android_native_app_glue.h>
  45. #endif
  46. typedef void (*GFXInitFunc)(void *ud, bool gl2);
  47. typedef int (*OpenURIFunc)(const String &);
  48. typedef String (*GetDataDirFunc)();
  49. typedef String (*GetLocaleFunc)();
  50. typedef String (*GetModelFunc)();
  51. typedef int (*GetScreenDPIFunc)();
  52. typedef String (*GetUniqueIDFunc)();
  53. typedef void (*ShowVirtualKeyboardFunc)(const String &);
  54. typedef void (*HideVirtualKeyboardFunc)();
  55. typedef void (*SetScreenOrientationFunc)(int);
  56. typedef String (*GetSystemDirFunc)(int);
  57. typedef void (*VideoPlayFunc)(const String &);
  58. typedef bool (*VideoIsPlayingFunc)();
  59. typedef void (*VideoPauseFunc)();
  60. typedef void (*VideoStopFunc)();
  61. typedef void (*SetKeepScreenOnFunc)(bool p_enabled);
  62. typedef void (*AlertFunc)(const String &, const String &);
  63. typedef int (*VirtualKeyboardHeightFunc)();
  64. class OS_Android : public OS_Unix {
  65. public:
  66. struct TouchPos {
  67. int id;
  68. Point2 pos;
  69. };
  70. enum {
  71. JOY_EVENT_BUTTON = 0,
  72. JOY_EVENT_AXIS = 1,
  73. JOY_EVENT_HAT = 2
  74. };
  75. struct JoypadEvent {
  76. int device;
  77. int type;
  78. int index;
  79. bool pressed;
  80. float value;
  81. int hat;
  82. };
  83. private:
  84. Vector<TouchPos> touch;
  85. Point2 last_mouse;
  86. GFXInitFunc gfx_init_func;
  87. void *gfx_init_ud;
  88. bool use_gl2;
  89. bool use_reload_hooks;
  90. bool use_apk_expansion;
  91. bool use_16bits_fbo;
  92. VisualServer *visual_server;
  93. mutable String data_dir_cache;
  94. //AudioDriverAndroid audio_driver_android;
  95. AudioDriverOpenSL audio_driver_android;
  96. const char *gl_extensions;
  97. InputDefault *input;
  98. VideoMode default_videomode;
  99. MainLoop *main_loop;
  100. OpenURIFunc open_uri_func;
  101. GetDataDirFunc get_data_dir_func;
  102. GetLocaleFunc get_locale_func;
  103. GetModelFunc get_model_func;
  104. GetScreenDPIFunc get_screen_dpi_func;
  105. ShowVirtualKeyboardFunc show_virtual_keyboard_func;
  106. HideVirtualKeyboardFunc hide_virtual_keyboard_func;
  107. VirtualKeyboardHeightFunc get_virtual_keyboard_height_func;
  108. SetScreenOrientationFunc set_screen_orientation_func;
  109. GetUniqueIDFunc get_unique_id_func;
  110. GetSystemDirFunc get_system_dir_func;
  111. VideoPlayFunc video_play_func;
  112. VideoIsPlayingFunc video_is_playing_func;
  113. VideoPauseFunc video_pause_func;
  114. VideoStopFunc video_stop_func;
  115. SetKeepScreenOnFunc set_keep_screen_on_func;
  116. AlertFunc alert_func;
  117. //power_android *power_manager;
  118. public:
  119. // functions used by main to initialize/deintialize the OS
  120. virtual int get_video_driver_count() const;
  121. virtual const char *get_video_driver_name(int p_driver) const;
  122. virtual VideoMode get_default_video_mode() const;
  123. virtual int get_audio_driver_count() const;
  124. virtual const char *get_audio_driver_name(int p_driver) const;
  125. virtual void initialize_logger();
  126. virtual void initialize_core();
  127. virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
  128. virtual void set_main_loop(MainLoop *p_main_loop);
  129. virtual void delete_main_loop();
  130. virtual void finalize();
  131. typedef int64_t ProcessID;
  132. static OS *get_singleton();
  133. virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
  134. virtual void set_mouse_show(bool p_show);
  135. virtual void set_mouse_grab(bool p_grab);
  136. virtual bool is_mouse_grab_enabled() const;
  137. virtual Point2 get_mouse_position() const;
  138. virtual int get_mouse_button_state() const;
  139. virtual void set_window_title(const String &p_title);
  140. //virtual void set_clipboard(const String& p_text);
  141. //virtual String get_clipboard() const;
  142. virtual void set_video_mode(const VideoMode &p_video_mode, int p_screen = 0);
  143. virtual VideoMode get_video_mode(int p_screen = 0) const;
  144. virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const;
  145. virtual void set_keep_screen_on(bool p_enabled);
  146. virtual Size2 get_window_size() const;
  147. virtual String get_name();
  148. virtual MainLoop *get_main_loop() const;
  149. virtual bool can_draw() const;
  150. virtual void set_cursor_shape(CursorShape p_shape);
  151. void main_loop_begin();
  152. bool main_loop_iterate();
  153. void main_loop_request_go_back();
  154. void main_loop_end();
  155. void main_loop_focusout();
  156. void main_loop_focusin();
  157. virtual bool has_touchscreen_ui_hint() const;
  158. virtual bool has_virtual_keyboard() const;
  159. virtual void show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2());
  160. virtual void hide_virtual_keyboard();
  161. virtual int get_virtual_keyboard_height() const;
  162. void set_opengl_extensions(const char *p_gl_extensions);
  163. void set_display_size(Size2 p_size);
  164. void reload_gfx();
  165. void set_context_is_16_bits(bool p_is_16);
  166. void set_need_reload_hooks(bool p_needs_them);
  167. virtual void set_screen_orientation(ScreenOrientation p_orientation);
  168. virtual Error shell_open(String p_uri);
  169. virtual String get_data_dir() const;
  170. virtual String get_resource_dir() const;
  171. virtual String get_locale() const;
  172. virtual String get_model_name() const;
  173. virtual int get_screen_dpi(int p_screen = 0) const;
  174. virtual String get_unique_id() const;
  175. virtual String get_system_dir(SystemDir p_dir) const;
  176. void process_accelerometer(const Vector3 &p_accelerometer);
  177. void process_magnetometer(const Vector3 &p_magnetometer);
  178. void process_gyroscope(const Vector3 &p_gyroscope);
  179. void process_touch(int p_what, int p_pointer, const Vector<TouchPos> &p_points);
  180. void process_joy_event(JoypadEvent p_event);
  181. void process_event(Ref<InputEvent> p_event);
  182. void init_video_mode(int p_video_width, int p_video_height);
  183. virtual Error native_video_play(String p_path, float p_volume);
  184. virtual bool native_video_is_playing();
  185. virtual void native_video_pause();
  186. virtual void native_video_stop();
  187. virtual bool is_joy_known(int p_device);
  188. virtual String get_joy_guid(int p_device) const;
  189. void joy_connection_changed(int p_device, bool p_connected, String p_name);
  190. virtual bool _check_internal_feature_support(const String &p_feature);
  191. OS_Android(GFXInitFunc p_gfx_init_func, void *p_gfx_init_ud, OpenURIFunc p_open_uri_func, GetDataDirFunc p_get_data_dir_func, GetLocaleFunc p_get_locale_func, GetModelFunc p_get_model_func, GetScreenDPIFunc p_get_screen_dpi_func, ShowVirtualKeyboardFunc p_show_vk, HideVirtualKeyboardFunc p_hide_vk, VirtualKeyboardHeightFunc p_vk_height_func, SetScreenOrientationFunc p_screen_orient, GetUniqueIDFunc p_get_unique_id, GetSystemDirFunc p_get_sdir_func, VideoPlayFunc p_video_play_func, VideoIsPlayingFunc p_video_is_playing_func, VideoPauseFunc p_video_pause_func, VideoStopFunc p_video_stop_func, SetKeepScreenOnFunc p_set_keep_screen_on_func, AlertFunc p_alert_func, bool p_use_apk_expansion);
  192. ~OS_Android();
  193. };
  194. #endif