os_android.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*************************************************************************/
  2. /* os_android.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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_opensl.h"
  33. #include "core/os/main_loop.h"
  34. #include "drivers/unix/os_unix.h"
  35. #include "main/input_default.h"
  36. #include "servers/audio_server.h"
  37. #include "servers/visual/rasterizer.h"
  38. class GodotJavaWrapper;
  39. class GodotIOJavaWrapper;
  40. class OS_Android : public OS_Unix {
  41. bool use_gl2;
  42. bool use_apk_expansion;
  43. bool use_16bits_fbo;
  44. VisualServer *visual_server;
  45. mutable String data_dir_cache;
  46. AudioDriverOpenSL audio_driver_android;
  47. const char *gl_extensions;
  48. InputDefault *input;
  49. VideoMode default_videomode;
  50. MainLoop *main_loop;
  51. GodotJavaWrapper *godot_java;
  52. GodotIOJavaWrapper *godot_io_java;
  53. //PowerAndroid *power_manager_func;
  54. int video_driver_index;
  55. bool transparency_enabled = false;
  56. public:
  57. // functions used by main to initialize/deinitialize the OS
  58. virtual int get_video_driver_count() const;
  59. virtual const char *get_video_driver_name(int p_driver) const;
  60. virtual int get_audio_driver_count() const;
  61. virtual const char *get_audio_driver_name(int p_driver) const;
  62. virtual int get_current_video_driver() const;
  63. virtual void initialize_core();
  64. virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
  65. virtual void set_main_loop(MainLoop *p_main_loop);
  66. virtual void delete_main_loop();
  67. virtual void finalize();
  68. typedef int64_t ProcessID;
  69. static OS *get_singleton();
  70. GodotJavaWrapper *get_godot_java();
  71. GodotIOJavaWrapper *get_godot_io_java();
  72. virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
  73. virtual bool request_permission(const String &p_name);
  74. virtual bool request_permissions();
  75. virtual Vector<String> get_granted_permissions() const;
  76. virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false);
  77. virtual void set_mouse_show(bool p_show);
  78. virtual void set_mouse_grab(bool p_grab);
  79. virtual bool is_mouse_grab_enabled() const;
  80. virtual Point2 get_mouse_position() const;
  81. virtual int get_mouse_button_state() const;
  82. virtual void set_window_title(const String &p_title);
  83. virtual void set_video_mode(const VideoMode &p_video_mode, int p_screen = 0);
  84. virtual VideoMode get_video_mode(int p_screen = 0) const;
  85. virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const;
  86. virtual void set_keep_screen_on(bool p_enabled);
  87. virtual Size2 get_window_size() const;
  88. virtual Rect2 get_window_safe_area() const;
  89. virtual String get_name() const;
  90. virtual MainLoop *get_main_loop() const;
  91. virtual bool can_draw() const;
  92. void main_loop_begin();
  93. bool main_loop_iterate();
  94. void main_loop_end();
  95. void main_loop_focusout();
  96. void main_loop_focusin();
  97. virtual bool has_touchscreen_ui_hint() const;
  98. virtual bool has_virtual_keyboard() const;
  99. virtual void show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), bool p_multiline = false, int p_max_input_length = -1, int p_cursor_start = -1, int p_cursor_end = -1);
  100. virtual void hide_virtual_keyboard();
  101. virtual int get_virtual_keyboard_height() const;
  102. void set_opengl_extensions(const char *p_gl_extensions);
  103. void set_display_size(Size2 p_size);
  104. void set_context_is_16_bits(bool p_is_16);
  105. virtual void set_screen_orientation(ScreenOrientation p_orientation);
  106. virtual ScreenOrientation get_screen_orientation() const;
  107. virtual Error shell_open(String p_uri);
  108. virtual String get_user_data_dir() const;
  109. virtual String get_data_path() const;
  110. virtual String get_cache_path() const;
  111. virtual String get_resource_dir() const;
  112. virtual String get_locale() const;
  113. virtual void set_clipboard(const String &p_text);
  114. virtual String get_clipboard() const;
  115. virtual String get_model_name() const;
  116. virtual int get_screen_dpi(int p_screen = 0) const;
  117. virtual bool get_window_per_pixel_transparency_enabled() const { return transparency_enabled; }
  118. virtual void set_window_per_pixel_transparency_enabled(bool p_enabled) { ERR_FAIL_MSG("Setting per-pixel transparency is not supported at runtime, please set it in project settings instead."); }
  119. virtual String get_unique_id() const;
  120. virtual String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const;
  121. void process_accelerometer(const Vector3 &p_accelerometer);
  122. void process_gravity(const Vector3 &p_gravity);
  123. void process_magnetometer(const Vector3 &p_magnetometer);
  124. void process_gyroscope(const Vector3 &p_gyroscope);
  125. void init_video_mode(int p_video_width, int p_video_height);
  126. virtual bool is_joy_known(int p_device);
  127. virtual String get_joy_guid(int p_device) const;
  128. void vibrate_handheld(int p_duration_ms);
  129. virtual bool _check_internal_feature_support(const String &p_feature);
  130. OS_Android(GodotJavaWrapper *p_godot_java, GodotIOJavaWrapper *p_godot_io_java, bool p_use_apk_expansion);
  131. ~OS_Android();
  132. };
  133. #endif