os_android.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /**************************************************************************/
  2. /* os_android.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 "servers/audio_server.h"
  36. class GodotJavaWrapper;
  37. class GodotIOJavaWrapper;
  38. struct ANativeWindow;
  39. class OS_Android : public OS_Unix {
  40. private:
  41. Size2i display_size;
  42. bool use_apk_expansion;
  43. #if defined(GLES3_ENABLED)
  44. const char *gl_extensions;
  45. #endif
  46. #if defined(VULKAN_ENABLED)
  47. ANativeWindow *native_window = nullptr;
  48. #endif
  49. mutable String data_dir_cache;
  50. mutable String cache_dir_cache;
  51. mutable String remote_fs_dir;
  52. AudioDriverOpenSL audio_driver_android;
  53. MainLoop *main_loop = nullptr;
  54. struct FontInfo {
  55. String font_name;
  56. HashSet<String> lang;
  57. HashSet<String> script;
  58. int weight = 400;
  59. int stretch = 100;
  60. bool italic = false;
  61. int priority = 0;
  62. String filename;
  63. };
  64. HashMap<String, String> font_aliases;
  65. List<FontInfo> fonts;
  66. HashSet<String> font_names;
  67. bool font_config_loaded = false;
  68. GodotJavaWrapper *godot_java = nullptr;
  69. GodotIOJavaWrapper *godot_io_java = nullptr;
  70. void _load_system_font_config();
  71. String get_system_property(const char *key) const;
  72. public:
  73. static const char *ANDROID_EXEC_PATH;
  74. static const int DEFAULT_WINDOW_WIDTH = 800;
  75. static const int DEFAULT_WINDOW_HEIGHT = 600;
  76. virtual void initialize_core() override;
  77. virtual void initialize() override;
  78. virtual void initialize_joypads() override;
  79. virtual void set_main_loop(MainLoop *p_main_loop) override;
  80. virtual void delete_main_loop() override;
  81. virtual void finalize() override;
  82. typedef int64_t ProcessID;
  83. static OS_Android *get_singleton();
  84. GodotJavaWrapper *get_godot_java();
  85. GodotIOJavaWrapper *get_godot_io_java();
  86. virtual bool request_permission(const String &p_name) override;
  87. virtual bool request_permissions() override;
  88. virtual Vector<String> get_granted_permissions() const override;
  89. virtual void alert(const String &p_alert, const String &p_title) override;
  90. virtual Error open_dynamic_library(const String &p_path, void *&p_library_handle, GDExtensionData *p_data = nullptr) override;
  91. virtual String get_name() const override;
  92. virtual String get_distribution_name() const override;
  93. virtual String get_version() const override;
  94. virtual MainLoop *get_main_loop() const override;
  95. void main_loop_begin();
  96. bool main_loop_iterate(bool *r_should_swap_buffers = nullptr);
  97. void main_loop_end();
  98. void main_loop_focusout();
  99. void main_loop_focusin();
  100. void set_display_size(const Size2i &p_size);
  101. Size2i get_display_size() const;
  102. void set_opengl_extensions(const char *p_gl_extensions);
  103. void set_native_window(ANativeWindow *p_native_window);
  104. ANativeWindow *get_native_window() const;
  105. virtual Error shell_open(const String &p_uri) override;
  106. virtual Vector<String> get_system_fonts() const override;
  107. virtual String get_system_font_path(const String &p_font_name, int p_weight = 400, int p_stretch = 100, bool p_italic = false) const override;
  108. virtual Vector<String> get_system_font_path_for_text(const String &p_font_name, const String &p_text, const String &p_locale = String(), const String &p_script = String(), int p_weight = 400, int p_stretch = 100, bool p_italic = false) const override;
  109. virtual String get_executable_path() const override;
  110. virtual String get_user_data_dir() const override;
  111. virtual String get_data_path() const override;
  112. virtual String get_cache_path() const override;
  113. virtual String get_resource_dir() const override;
  114. virtual String get_locale() const override;
  115. virtual String get_model_name() const override;
  116. virtual String get_unique_id() const override;
  117. virtual String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const override;
  118. virtual Error move_to_trash(const String &p_path) override;
  119. void vibrate_handheld(int p_duration_ms, float p_amplitude = -1.0) override;
  120. virtual String get_config_path() const override;
  121. virtual Error execute(const String &p_path, const List<String> &p_arguments, String *r_pipe = nullptr, int *r_exitcode = nullptr, bool read_stderr = false, Mutex *p_pipe_mutex = nullptr, bool p_open_console = false) override;
  122. virtual Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr, bool p_open_console = false) override;
  123. virtual Error create_instance(const List<String> &p_arguments, ProcessID *r_child_id = nullptr) override;
  124. virtual Error kill(const ProcessID &p_pid) override;
  125. virtual String get_system_ca_certificates() override;
  126. virtual Error setup_remote_filesystem(const String &p_server_host, int p_port, const String &p_password, String &r_project_path) override;
  127. virtual void benchmark_begin_measure(const String &p_context, const String &p_what) override;
  128. virtual void benchmark_end_measure(const String &p_context, const String &p_what) override;
  129. virtual void benchmark_dump() override;
  130. virtual void load_platform_gdextensions() const override;
  131. virtual bool _check_internal_feature_support(const String &p_feature) override;
  132. OS_Android(GodotJavaWrapper *p_godot_java, GodotIOJavaWrapper *p_godot_io_java, bool p_use_apk_expansion);
  133. ~OS_Android();
  134. private:
  135. // Location where we relocate external dynamic libraries to make them accessible.
  136. String get_dynamic_libraries_path() const;
  137. // Copy a dynamic library to the given location to make it accessible for loading.
  138. bool copy_dynamic_library(const String &p_library_path, const String &p_target_dir, String *r_copy_path = nullptr);
  139. };
  140. #endif // OS_ANDROID_H