os_android.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 "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. AudioDriverOpenSL audio_driver_android;
  52. MainLoop *main_loop = nullptr;
  53. GodotJavaWrapper *godot_java = nullptr;
  54. GodotIOJavaWrapper *godot_io_java = nullptr;
  55. public:
  56. static const char *ANDROID_EXEC_PATH;
  57. virtual void initialize_core() override;
  58. virtual void initialize() override;
  59. virtual void initialize_joypads() override;
  60. virtual void set_main_loop(MainLoop *p_main_loop) override;
  61. virtual void delete_main_loop() override;
  62. virtual void finalize() override;
  63. typedef int64_t ProcessID;
  64. static OS_Android *get_singleton();
  65. GodotJavaWrapper *get_godot_java();
  66. GodotIOJavaWrapper *get_godot_io_java();
  67. virtual bool request_permission(const String &p_name) override;
  68. virtual bool request_permissions() override;
  69. virtual Vector<String> get_granted_permissions() const override;
  70. virtual void alert(const String &p_alert, const String &p_title) override;
  71. virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false, String *r_resolved_path = nullptr) override;
  72. virtual String get_name() const override;
  73. virtual MainLoop *get_main_loop() const override;
  74. void main_loop_begin();
  75. bool main_loop_iterate(bool *r_should_swap_buffers = nullptr);
  76. void main_loop_end();
  77. void main_loop_focusout();
  78. void main_loop_focusin();
  79. void set_display_size(const Size2i &p_size);
  80. Size2i get_display_size() const;
  81. void set_opengl_extensions(const char *p_gl_extensions);
  82. void set_native_window(ANativeWindow *p_native_window);
  83. ANativeWindow *get_native_window() const;
  84. virtual Error shell_open(String p_uri) override;
  85. virtual String get_executable_path() const override;
  86. virtual String get_user_data_dir() const override;
  87. virtual String get_data_path() const override;
  88. virtual String get_cache_path() const override;
  89. virtual String get_resource_dir() const override;
  90. virtual String get_locale() const override;
  91. virtual String get_model_name() const override;
  92. virtual String get_unique_id() const override;
  93. virtual String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const override;
  94. virtual Error move_to_trash(const String &p_path) override;
  95. void vibrate_handheld(int p_duration_ms) override;
  96. virtual String get_config_path() const override;
  97. 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;
  98. virtual Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr, bool p_open_console = false) override;
  99. virtual Error create_instance(const List<String> &p_arguments, ProcessID *r_child_id = nullptr) override;
  100. virtual bool _check_internal_feature_support(const String &p_feature) override;
  101. OS_Android(GodotJavaWrapper *p_godot_java, GodotIOJavaWrapper *p_godot_io_java, bool p_use_apk_expansion);
  102. ~OS_Android();
  103. };
  104. #endif // OS_ANDROID_H