| 1 | /**************************************************************************/ |
| 2 | /* display_server_android.cpp */ |
| 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 | |
| 31 | #include "display_server_android.h" |
| 32 | |
| 33 | #include "java_godot_io_wrapper.h" |
| 34 | #include "java_godot_wrapper.h" |
| 35 | #include "os_android.h" |
| 36 | #include "tts_android.h" |
| 37 | |
| 38 | #include "core/config/project_settings.h" |
| 39 | |
| 40 | #if defined(RD_ENABLED) |
| 41 | #include "servers/rendering/renderer_rd/renderer_compositor_rd.h" |
| 42 | #include "servers/rendering/rendering_device.h" |
| 43 | |
| 44 | #if defined(VULKAN_ENABLED) |
| 45 | #include "rendering_context_driver_vulkan_android.h" |
| 46 | #endif |
| 47 | #endif |
| 48 | |
| 49 | #ifdef GLES3_ENABLED |
| 50 | #include "drivers/gles3/rasterizer_gles3.h" |
| 51 | |
| 52 | #include <EGL/egl.h> |
| 53 | #endif |
| 54 | |
| 55 | DisplayServerAndroid *DisplayServerAndroid::get_singleton() { |
| 56 | return static_cast<DisplayServerAndroid *>(DisplayServer::get_singleton()); |
| 57 | } |
| 58 | |
| 59 | bool DisplayServerAndroid::has_feature(Feature p_feature) const { |
| 60 | switch (p_feature) { |
| 61 | #ifndef DISABLE_DEPRECATED |
| 62 | case FEATURE_GLOBAL_MENU: { |
| 63 | return (native_menu && native_menu->has_feature(NativeMenu::FEATURE_GLOBAL_MENU)); |
| 64 | } break; |
| 65 | #endif |
| 66 | case FEATURE_CURSOR_SHAPE: |
| 67 | //case FEATURE_CUSTOM_CURSOR_SHAPE: |
| 68 | //case FEATURE_HIDPI: |
| 69 | //case FEATURE_ICON: |
| 70 | //case FEATURE_IME: |
| 71 | case FEATURE_MOUSE: |
| 72 | //case FEATURE_MOUSE_WARP: |
| 73 | case FEATURE_NATIVE_DIALOG: |
| 74 | case FEATURE_NATIVE_DIALOG_INPUT: |
| 75 | case FEATURE_NATIVE_DIALOG_FILE: |
| 76 | //case FEATURE_NATIVE_DIALOG_FILE_EXTRA: |
| 77 | case FEATURE_NATIVE_DIALOG_FILE_MIME: |
| 78 | //case FEATURE_NATIVE_ICON: |
| 79 | case FEATURE_WINDOW_TRANSPARENCY: |
| 80 | case FEATURE_CLIPBOARD: |
| 81 | case FEATURE_KEEP_SCREEN_ON: |
| 82 | case FEATURE_ORIENTATION: |
| 83 | case FEATURE_TOUCHSCREEN: |
| 84 | case FEATURE_VIRTUAL_KEYBOARD: |
| 85 | case FEATURE_TEXT_TO_SPEECH: |
| 86 | return true; |
| 87 | default: |
| 88 | return false; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | String DisplayServerAndroid::get_name() const { |
| 93 | return "Android"; |
| 94 | } |
| 95 | |
| 96 | bool DisplayServerAndroid::tts_is_speaking() const { |
| 97 | return TTS_Android::is_speaking(); |
| 98 | } |
| 99 | |
| 100 | bool DisplayServerAndroid::tts_is_paused() const { |
| 101 | return TTS_Android::is_paused(); |
| 102 | } |
| 103 | |
| 104 | TypedArray<Dictionary> DisplayServerAndroid::tts_get_voices() const { |
| 105 | return TTS_Android::get_voices(); |
| 106 | } |
| 107 | |
| 108 | void DisplayServerAndroid::tts_speak(const String &p_text, const String &p_voice, int p_volume, float p_pitch, float p_rate, int64_t p_utterance_id, bool p_interrupt) { |
| 109 | TTS_Android::speak(p_text, p_voice, p_volume, p_pitch, p_rate, p_utterance_id, p_interrupt); |
| 110 | } |
| 111 | |
| 112 | void DisplayServerAndroid::tts_pause() { |
| 113 | TTS_Android::pause(); |
| 114 | } |
| 115 | |
| 116 | void DisplayServerAndroid::tts_resume() { |
| 117 | TTS_Android::resume(); |
| 118 | } |
| 119 | |
| 120 | void DisplayServerAndroid::tts_stop() { |
| 121 | TTS_Android::stop(); |
| 122 | } |
| 123 | |
| 124 | bool DisplayServerAndroid::is_dark_mode_supported() const { |
| 125 | GodotJavaWrapper *godot_java = OS_Android::get_singleton()->get_godot_java(); |
| 126 | ERR_FAIL_NULL_V(godot_java, false); |
| 127 | |
| 128 | return godot_java->is_dark_mode_supported(); |
| 129 | } |
| 130 | |
| 131 | bool DisplayServerAndroid::is_dark_mode() const { |
| 132 | GodotJavaWrapper *godot_java = OS_Android::get_singleton()->get_godot_java(); |
| 133 | ERR_FAIL_NULL_V(godot_java, false); |
| 134 | |
| 135 | return godot_java->is_dark_mode(); |
| 136 | } |
| 137 | |
| 138 | void DisplayServerAndroid::set_system_theme_change_callback(const Callable &p_callable) { |
| 139 | system_theme_changed = p_callable; |
| 140 | } |
| 141 | |
| 142 | void DisplayServerAndroid::emit_system_theme_changed() { |
| 143 | if (system_theme_changed.is_valid()) { |
| 144 | system_theme_changed.call_deferred(); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | void DisplayServerAndroid::set_hardware_keyboard_connection_change_callback(const Callable &p_callable) { |
| 149 | hardware_keyboard_connection_changed = p_callable; |
| 150 | } |
| 151 | |
| 152 | void DisplayServerAndroid::emit_hardware_keyboard_connection_changed(bool p_connected) { |
| 153 | if (hardware_keyboard_connection_changed.is_valid()) { |
| 154 | hardware_keyboard_connection_changed.call_deferred(p_connected); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | void DisplayServerAndroid::clipboard_set(const String &p_text) { |
| 159 | GodotJavaWrapper *godot_java = OS_Android::get_singleton()->get_godot_java(); |
| 160 | ERR_FAIL_NULL(godot_java); |
| 161 | |
| 162 | if (godot_java->has_set_clipboard()) { |
| 163 | godot_java->set_clipboard(p_text); |
| 164 | } else { |
| 165 | DisplayServer::clipboard_set(p_text); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | String DisplayServerAndroid::clipboard_get() const { |
| 170 | GodotJavaWrapper *godot_java = OS_Android::get_singleton()->get_godot_java(); |
| 171 | ERR_FAIL_NULL_V(godot_java, String()); |
| 172 | |
| 173 | if (godot_java->has_get_clipboard()) { |
| 174 | return godot_java->get_clipboard(); |
| 175 | } else { |
| 176 | return DisplayServer::clipboard_get(); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | bool DisplayServerAndroid::clipboard_has() const { |
| 181 | GodotJavaWrapper *godot_java = OS_Android::get_singleton()->get_godot_java(); |
| 182 | ERR_FAIL_NULL_V(godot_java, false); |
| 183 | |
| 184 | if (godot_java->has_has_clipboard()) { |
| 185 | return godot_java->has_clipboard(); |
| 186 | } else { |
| 187 | return DisplayServer::clipboard_has(); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | Error DisplayServerAndroid::dialog_show(String p_title, String p_description, Vector<String> p_buttons, const Callable &p_callback) { |
| 192 | GodotJavaWrapper *godot_java = OS_Android::get_singleton()->get_godot_java(); |
| 193 | ERR_FAIL_NULL_V(godot_java, FAILED); |
| 194 | dialog_callback = p_callback; |
| 195 | return godot_java->show_dialog(p_title, p_description, p_buttons); |
| 196 | } |
| 197 | |
| 198 | void DisplayServerAndroid::emit_dialog_callback(int p_button_index) { |
| 199 | if (dialog_callback.is_valid()) { |
| 200 | dialog_callback.call_deferred(p_button_index); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | Error DisplayServerAndroid::dialog_input_text(String p_title, String p_description, String p_partial, const Callable &p_callback) { |
| 205 | GodotJavaWrapper *godot_java = OS_Android::get_singleton()->get_godot_java(); |
| 206 | ERR_FAIL_NULL_V(godot_java, FAILED); |
| 207 | input_dialog_callback = p_callback; |
| 208 | return godot_java->show_input_dialog(p_title, p_description, p_partial); |
| 209 | } |
| 210 | |
| 211 | void DisplayServerAndroid::emit_input_dialog_callback(String p_text) { |
| 212 | if (input_dialog_callback.is_valid()) { |
| 213 | input_dialog_callback.call_deferred(p_text); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | Error DisplayServerAndroid::file_dialog_show(const String &p_title, const String &p_current_directory, const String &p_filename, bool p_show_hidden, FileDialogMode p_mode, const Vector<String> &p_filters, const Callable &p_callback, WindowID p_window_id) { |
| 218 | GodotJavaWrapper *godot_java = OS_Android::get_singleton()->get_godot_java(); |
| 219 | ERR_FAIL_NULL_V(godot_java, FAILED); |
| 220 | file_picker_callback = p_callback; |
| 221 | return godot_java->show_file_picker(p_current_directory, p_filename, p_mode, p_filters); |
| 222 | } |
| 223 | |
| 224 | void DisplayServerAndroid::emit_file_picker_callback(bool p_ok, const Vector<String> &p_selected_paths) { |
| 225 | if (file_picker_callback.is_valid()) { |
| 226 | file_picker_callback.call_deferred(p_ok, p_selected_paths, 0); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | Color DisplayServerAndroid::get_accent_color() const { |
| 231 | GodotJavaWrapper *godot_java = OS_Android::get_singleton()->get_godot_java(); |
| 232 | ERR_FAIL_NULL_V(godot_java, Color(0, 0, 0, 0)); |
| 233 | return godot_java->get_accent_color(); |
| 234 | } |
| 235 | |
| 236 | Color DisplayServerAndroid::get_base_color() const { |
| 237 | GodotJavaWrapper *godot_java = OS_Android::get_singleton()->get_godot_java(); |
| 238 | ERR_FAIL_NULL_V(godot_java, Color(0, 0, 0, 0)); |
| 239 | return godot_java->get_base_color(); |
| 240 | } |
| 241 | |
| 242 | TypedArray<Rect2> DisplayServerAndroid::get_display_cutouts() const { |
| 243 | GodotIOJavaWrapper *godot_io_java = OS_Android::get_singleton()->get_godot_io_java(); |
| 244 | ERR_FAIL_NULL_V(godot_io_java, Array()); |
| 245 | return godot_io_java->get_display_cutouts(); |
| 246 | } |
| 247 | |
| 248 | Rect2i DisplayServerAndroid::get_display_safe_area() const { |
| 249 | GodotIOJavaWrapper *godot_io_java = OS_Android::get_singleton()->get_godot_io_java(); |
| 250 | ERR_FAIL_NULL_V(godot_io_java, Rect2i()); |
| 251 | return godot_io_java->get_display_safe_area(); |
| 252 | } |
| 253 | |
| 254 | void DisplayServerAndroid::screen_set_keep_on(bool p_enable) { |
| 255 | GodotJavaWrapper *godot_java = OS_Android::get_singleton()->get_godot_java(); |
| 256 | ERR_FAIL_NULL(godot_java); |
| 257 | |
| 258 | godot_java->set_keep_screen_on(p_enable); |
| 259 | keep_screen_on = p_enable; |
| 260 | } |
| 261 | |
| 262 | bool DisplayServerAndroid::screen_is_kept_on() const { |
| 263 | return keep_screen_on; |
| 264 | } |
| 265 | |
| 266 | void DisplayServerAndroid::screen_set_orientation(DisplayServer::ScreenOrientation p_orientation, int p_screen) { |
| 267 | p_screen = _get_screen_index(p_screen); |
| 268 | int screen_count = get_screen_count(); |
| 269 | ERR_FAIL_INDEX(p_screen, screen_count); |
| 270 | |
| 271 | GodotIOJavaWrapper *godot_io_java = OS_Android::get_singleton()->get_godot_io_java(); |
| 272 | ERR_FAIL_NULL(godot_io_java); |
| 273 | |
| 274 | godot_io_java->set_screen_orientation(p_orientation); |
| 275 | } |
| 276 | |
| 277 | DisplayServer::ScreenOrientation DisplayServerAndroid::screen_get_orientation(int p_screen) const { |
| 278 | p_screen = _get_screen_index(p_screen); |
| 279 | int screen_count = get_screen_count(); |
| 280 | ERR_FAIL_INDEX_V(p_screen, screen_count, SCREEN_LANDSCAPE); |
| 281 | |
| 282 | GodotIOJavaWrapper *godot_io_java = OS_Android::get_singleton()->get_godot_io_java(); |
| 283 | ERR_FAIL_NULL_V(godot_io_java, SCREEN_LANDSCAPE); |
| 284 | |
| 285 | const int orientation = godot_io_java->get_screen_orientation(); |
| 286 | ERR_FAIL_INDEX_V_MSG(orientation, 7, SCREEN_LANDSCAPE, "Unrecognized screen orientation"); |
| 287 | return (ScreenOrientation)orientation; |
| 288 | } |
| 289 | |
| 290 | int DisplayServerAndroid::get_display_rotation() const { |
| 291 | GodotIOJavaWrapper *godot_io_java = OS_Android::get_singleton()->get_godot_io_java(); |
| 292 | ERR_FAIL_NULL_V(godot_io_java, 0); |
| 293 | |
| 294 | return godot_io_java->get_display_rotation(); |
| 295 | } |
| 296 | |
| 297 | int DisplayServerAndroid::get_screen_count() const { |
| 298 | return 1; |
| 299 | } |
| 300 | |
| 301 | int DisplayServerAndroid::get_primary_screen() const { |
| 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | Point2i DisplayServerAndroid::screen_get_position(int p_screen) const { |
| 306 | p_screen = _get_screen_index(p_screen); |
| 307 | int screen_count = get_screen_count(); |
| 308 | ERR_FAIL_INDEX_V(p_screen, screen_count, Point2i()); |
| 309 | |
| 310 | return Point2i(0, 0); |
| 311 | } |
| 312 | |
| 313 | Size2i DisplayServerAndroid::screen_get_size(int p_screen) const { |
| 314 | p_screen = _get_screen_index(p_screen); |
| 315 | int screen_count = get_screen_count(); |
| 316 | ERR_FAIL_INDEX_V(p_screen, screen_count, Size2i()); |
| 317 | |
| 318 | return OS_Android::get_singleton()->get_display_size(); |
| 319 | } |
| 320 | |
| 321 | Rect2i DisplayServerAndroid::screen_get_usable_rect(int p_screen) const { |
| 322 | p_screen = _get_screen_index(p_screen); |
| 323 | int screen_count = get_screen_count(); |
| 324 | ERR_FAIL_INDEX_V(p_screen, screen_count, Rect2i()); |
| 325 | |
| 326 | Size2i display_size = OS_Android::get_singleton()->get_display_size(); |
| 327 | return Rect2i(0, 0, display_size.width, display_size.height); |
| 328 | } |
| 329 | |
| 330 | int DisplayServerAndroid::screen_get_dpi(int p_screen) const { |
| 331 | p_screen = _get_screen_index(p_screen); |
| 332 | int screen_count = get_screen_count(); |
| 333 | ERR_FAIL_INDEX_V(p_screen, screen_count, 160); |
| 334 | |
| 335 | GodotIOJavaWrapper *godot_io_java = OS_Android::get_singleton()->get_godot_io_java(); |
| 336 | ERR_FAIL_NULL_V(godot_io_java, 160); |
| 337 | |
| 338 | return godot_io_java->get_screen_dpi(); |
| 339 | } |
| 340 | |
| 341 | float DisplayServerAndroid::screen_get_scale(int p_screen) const { |
| 342 | p_screen = _get_screen_index(p_screen); |
| 343 | int screen_count = get_screen_count(); |
| 344 | ERR_FAIL_INDEX_V(p_screen, screen_count, 1.0f); |
| 345 | |
| 346 | GodotIOJavaWrapper *godot_io_java = OS_Android::get_singleton()->get_godot_io_java(); |
| 347 | ERR_FAIL_NULL_V(godot_io_java, 1.0f); |
| 348 | |
| 349 | float screen_scale = godot_io_java->get_scaled_density(); |
| 350 | |
| 351 | // Update the scale to avoid cropping. |
| 352 | Size2i screen_size = screen_get_size(p_screen); |
| 353 | if (screen_size != Size2i()) { |
| 354 | float width_scale = screen_size.width / (float)OS_Android::DEFAULT_WINDOW_WIDTH; |
| 355 | float height_scale = screen_size.height / (float)OS_Android::DEFAULT_WINDOW_HEIGHT; |
| 356 | screen_scale = MIN(screen_scale, MIN(width_scale, height_scale)); |
| 357 | } |
| 358 | |
| 359 | return screen_scale; |
| 360 | } |
| 361 | |
| 362 | float DisplayServerAndroid::screen_get_refresh_rate(int p_screen) const { |
| 363 | p_screen = _get_screen_index(p_screen); |
| 364 | int screen_count = get_screen_count(); |
| 365 | ERR_FAIL_INDEX_V(p_screen, screen_count, SCREEN_REFRESH_RATE_FALLBACK); |
| 366 | |
| 367 | GodotIOJavaWrapper *godot_io_java = OS_Android::get_singleton()->get_godot_io_java(); |
| 368 | if (!godot_io_java) { |
| 369 | ERR_PRINT("An error occurred while trying to get the screen refresh rate."); |
| 370 | return SCREEN_REFRESH_RATE_FALLBACK; |
| 371 | } |
| 372 | |
| 373 | return godot_io_java->get_screen_refresh_rate(SCREEN_REFRESH_RATE_FALLBACK); |
| 374 | } |
| 375 | |
| 376 | bool DisplayServerAndroid::is_touchscreen_available() const { |
| 377 | return true; |
| 378 | } |
| 379 | |
| 380 | void DisplayServerAndroid::virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_length, int p_cursor_start, int p_cursor_end) { |
| 381 | GodotIOJavaWrapper *godot_io_java = OS_Android::get_singleton()->get_godot_io_java(); |
| 382 | ERR_FAIL_NULL(godot_io_java); |
| 383 | |
| 384 | if (godot_io_java->has_vk()) { |
| 385 | godot_io_java->show_vk(p_existing_text, (int)p_type, p_max_length, p_cursor_start, p_cursor_end); |
| 386 | } else { |
| 387 | ERR_PRINT("Virtual keyboard not available"); |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | void DisplayServerAndroid::virtual_keyboard_hide() { |
| 392 | GodotIOJavaWrapper *godot_io_java = OS_Android::get_singleton()->get_godot_io_java(); |
| 393 | ERR_FAIL_NULL(godot_io_java); |
| 394 | |
| 395 | if (godot_io_java->has_vk()) { |
| 396 | godot_io_java->hide_vk(); |
| 397 | } else { |
| 398 | ERR_PRINT("Virtual keyboard not available"); |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | int DisplayServerAndroid::virtual_keyboard_get_height() const { |
| 403 | GodotIOJavaWrapper *godot_io_java = OS_Android::get_singleton()->get_godot_io_java(); |
| 404 | ERR_FAIL_NULL_V(godot_io_java, 0); |
| 405 | |
| 406 | return godot_io_java->get_vk_height(); |
| 407 | } |
| 408 | |
| 409 | bool DisplayServerAndroid::has_hardware_keyboard() const { |
| 410 | GodotIOJavaWrapper *godot_io_java = OS_Android::get_singleton()->get_godot_io_java(); |
| 411 | ERR_FAIL_NULL_V(godot_io_java, false); |
| 412 | |
| 413 | return godot_io_java->has_hardware_keyboard(); |
| 414 | } |
| 415 | |
| 416 | void DisplayServerAndroid::window_set_window_event_callback(const Callable &p_callable, DisplayServer::WindowID p_window) { |
| 417 | window_event_callback = p_callable; |
| 418 | } |
| 419 | |
| 420 | void DisplayServerAndroid::window_set_input_event_callback(const Callable &p_callable, DisplayServer::WindowID p_window) { |
| 421 | input_event_callback = p_callable; |
| 422 | } |
| 423 | |
| 424 | void DisplayServerAndroid::window_set_input_text_callback(const Callable &p_callable, DisplayServer::WindowID p_window) { |
| 425 | input_text_callback = p_callable; |
| 426 | } |
| 427 | |
| 428 | void DisplayServerAndroid::window_set_rect_changed_callback(const Callable &p_callable, DisplayServer::WindowID p_window) { |
| 429 | rect_changed_callback = p_callable; |
| 430 | } |
| 431 | |
| 432 | void DisplayServerAndroid::window_set_drop_files_callback(const Callable &p_callable, DisplayServer::WindowID p_window) { |
| 433 | // Not supported on Android. |
| 434 | } |
| 435 | |
| 436 | template <typename... Args> |
| 437 | void DisplayServerAndroid::_window_callback(const Callable &p_callable, bool p_deferred, const Args &...p_rest_args) const { |
| 438 | if (p_callable.is_valid()) { |
| 439 | if (p_deferred) { |
| 440 | p_callable.call_deferred(p_rest_args...); |
| 441 | } else { |
| 442 | p_callable.call(p_rest_args...); |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | void DisplayServerAndroid::send_window_event(DisplayServer::WindowEvent p_event, bool p_deferred) const { |
| 448 | _window_callback(window_event_callback, p_deferred, int(p_event)); |
| 449 | } |
| 450 | |
| 451 | void DisplayServerAndroid::send_input_event(const Ref<InputEvent> &p_event) const { |
| 452 | _window_callback(input_event_callback, false, p_event); |
| 453 | } |
| 454 | |
| 455 | void DisplayServerAndroid::send_input_text(const String &p_text) const { |
| 456 | _window_callback(input_text_callback, false, p_text, false); |
| 457 | } |
| 458 | |
| 459 | void DisplayServerAndroid::_dispatch_input_events(const Ref<InputEvent> &p_event) { |
| 460 | DisplayServerAndroid::get_singleton()->send_input_event(p_event); |
| 461 | } |
| 462 | |
| 463 | Vector<DisplayServer::WindowID> DisplayServerAndroid::get_window_list() const { |
| 464 | Vector<WindowID> ret; |
| 465 | ret.push_back(MAIN_WINDOW_ID); |
| 466 | return ret; |
| 467 | } |
| 468 | |
| 469 | DisplayServer::WindowID DisplayServerAndroid::get_window_at_screen_position(const Point2i &p_position) const { |
| 470 | return MAIN_WINDOW_ID; |
| 471 | } |
| 472 | |
| 473 | int64_t DisplayServerAndroid::window_get_native_handle(HandleType p_handle_type, WindowID p_window) const { |
| 474 | ERR_FAIL_COND_V(p_window != MAIN_WINDOW_ID, 0); |
| 475 | switch (p_handle_type) { |
| 476 | case WINDOW_HANDLE: { |
| 477 | return reinterpret_cast<int64_t>(static_cast<OS_Android *>(OS::get_singleton())->get_godot_java()->get_activity()); |
| 478 | } |
| 479 | case WINDOW_VIEW: { |
| 480 | return 0; // Not supported. |
| 481 | } |
| 482 | #ifdef GLES3_ENABLED |
| 483 | case DISPLAY_HANDLE: { |
| 484 | if (rendering_driver == "opengl3") { |
| 485 | return reinterpret_cast<int64_t>(eglGetCurrentDisplay()); |
| 486 | } |
| 487 | return 0; |
| 488 | } |
| 489 | case OPENGL_CONTEXT: { |
| 490 | if (rendering_driver == "opengl3") { |
| 491 | return reinterpret_cast<int64_t>(eglGetCurrentContext()); |
| 492 | } |
| 493 | return 0; |
| 494 | } |
| 495 | case EGL_DISPLAY: { |
| 496 | // @todo Find a way to get this from the Java side. |
| 497 | return 0; |
| 498 | } |
| 499 | case EGL_CONFIG: { |
| 500 | // @todo Find a way to get this from the Java side. |
| 501 | return 0; |
| 502 | } |
| 503 | #endif |
| 504 | default: { |
| 505 | return 0; |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | void DisplayServerAndroid::window_attach_instance_id(ObjectID p_instance, DisplayServer::WindowID p_window) { |
| 511 | window_attached_instance_id = p_instance; |
| 512 | } |
| 513 | |
| 514 | ObjectID DisplayServerAndroid::window_get_attached_instance_id(DisplayServer::WindowID p_window) const { |
| 515 | return window_attached_instance_id; |
| 516 | } |
| 517 | |
| 518 | void DisplayServerAndroid::window_set_title(const String &p_title, DisplayServer::WindowID p_window) { |
| 519 | // Not supported on Android. |
| 520 | } |
| 521 | |
| 522 | int DisplayServerAndroid::window_get_current_screen(DisplayServer::WindowID p_window) const { |
| 523 | ERR_FAIL_COND_V(p_window != MAIN_WINDOW_ID, INVALID_SCREEN); |
| 524 | return 0; |
| 525 | } |
| 526 | |
| 527 | void DisplayServerAndroid::window_set_current_screen(int p_screen, DisplayServer::WindowID p_window) { |
| 528 | // Not supported on Android. |
| 529 | } |
| 530 | |
| 531 | Point2i DisplayServerAndroid::window_get_position(DisplayServer::WindowID p_window) const { |
| 532 | return Point2i(); |
| 533 | } |
| 534 | |
| 535 | Point2i DisplayServerAndroid::window_get_position_with_decorations(DisplayServer::WindowID p_window) const { |
| 536 | return Point2i(); |
| 537 | } |
| 538 | |
| 539 | void DisplayServerAndroid::window_set_position(const Point2i &p_position, DisplayServer::WindowID p_window) { |
| 540 | // Not supported on Android. |
| 541 | } |
| 542 | |
| 543 | void DisplayServerAndroid::window_set_transient(DisplayServer::WindowID p_window, DisplayServer::WindowID p_parent) { |
| 544 | // Not supported on Android. |
| 545 | } |
| 546 | |
| 547 | void DisplayServerAndroid::window_set_max_size(const Size2i p_size, DisplayServer::WindowID p_window) { |
| 548 | // Not supported on Android. |
| 549 | } |
| 550 | |
| 551 | Size2i DisplayServerAndroid::window_get_max_size(DisplayServer::WindowID p_window) const { |
| 552 | return Size2i(); |
| 553 | } |
| 554 | |
| 555 | void DisplayServerAndroid::window_set_min_size(const Size2i p_size, DisplayServer::WindowID p_window) { |
| 556 | // Not supported on Android. |
| 557 | } |
| 558 | |
| 559 | Size2i DisplayServerAndroid::window_get_min_size(DisplayServer::WindowID p_window) const { |
| 560 | return Size2i(); |
| 561 | } |
| 562 | |
| 563 | void DisplayServerAndroid::window_set_size(const Size2i p_size, DisplayServer::WindowID p_window) { |
| 564 | // Not supported on Android. |
| 565 | } |
| 566 | |
| 567 | Size2i DisplayServerAndroid::window_get_size(DisplayServer::WindowID p_window) const { |
| 568 | return OS_Android::get_singleton()->get_display_size(); |
| 569 | } |
| 570 | |
| 571 | Size2i DisplayServerAndroid::window_get_size_with_decorations(DisplayServer::WindowID p_window) const { |
| 572 | return OS_Android::get_singleton()->get_display_size(); |
| 573 | } |
| 574 | |
| 575 | void DisplayServerAndroid::window_set_mode(DisplayServer::WindowMode p_mode, DisplayServer::WindowID p_window) { |
| 576 | OS_Android::get_singleton()->get_godot_java()->enable_immersive_mode(p_mode == WINDOW_MODE_FULLSCREEN || p_mode == WINDOW_MODE_EXCLUSIVE_FULLSCREEN); |
| 577 | } |
| 578 | |
| 579 | DisplayServer::WindowMode DisplayServerAndroid::window_get_mode(DisplayServer::WindowID p_window) const { |
| 580 | if (OS_Android::get_singleton()->get_godot_java()->is_in_immersive_mode()) { |
| 581 | return WINDOW_MODE_FULLSCREEN; |
| 582 | } else { |
| 583 | return WINDOW_MODE_MAXIMIZED; |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | bool DisplayServerAndroid::window_is_maximize_allowed(DisplayServer::WindowID p_window) const { |
| 588 | return false; |
| 589 | } |
| 590 | |
| 591 | void DisplayServerAndroid::window_set_flag(DisplayServer::WindowFlags p_flag, bool p_enabled, DisplayServer::WindowID p_window) { |
| 592 | // Not supported on Android. |
| 593 | } |
| 594 | |
| 595 | bool DisplayServerAndroid::window_get_flag(DisplayServer::WindowFlags p_flag, DisplayServer::WindowID p_window) const { |
| 596 | ERR_FAIL_COND_V(p_window != MAIN_WINDOW_ID, false); |
| 597 | switch (p_flag) { |
| 598 | case WindowFlags::WINDOW_FLAG_TRANSPARENT: |
| 599 | return is_window_transparency_available(); |
| 600 | |
| 601 | default: |
| 602 | return false; |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | void DisplayServerAndroid::window_request_attention(DisplayServer::WindowID p_window) { |
| 607 | // Not supported on Android. |
| 608 | } |
| 609 | |
| 610 | void DisplayServerAndroid::window_move_to_foreground(DisplayServer::WindowID p_window) { |
| 611 | // Not supported on Android. |
| 612 | } |
| 613 | |
| 614 | bool DisplayServerAndroid::window_is_focused(WindowID p_window) const { |
| 615 | return true; |
| 616 | } |
| 617 | |
| 618 | bool DisplayServerAndroid::window_can_draw(DisplayServer::WindowID p_window) const { |
| 619 | return true; |
| 620 | } |
| 621 | |
| 622 | bool DisplayServerAndroid::can_any_window_draw() const { |
| 623 | return true; |
| 624 | } |
| 625 | |
| 626 | void DisplayServerAndroid::window_set_color(const Color &p_color) { |
| 627 | GodotJavaWrapper *godot_java = OS_Android::get_singleton()->get_godot_java(); |
| 628 | ERR_FAIL_NULL(godot_java); |
| 629 | godot_java->set_window_color(p_color); |
| 630 | } |
| 631 | |
| 632 | void DisplayServerAndroid::process_events() { |
| 633 | Input::get_singleton()->flush_buffered_events(); |
| 634 | } |
| 635 | |
| 636 | Vector<String> DisplayServerAndroid::get_rendering_drivers_func() { |
| 637 | Vector<String> drivers; |
| 638 | |
| 639 | #ifdef GLES3_ENABLED |
| 640 | drivers.push_back("opengl3"); |
| 641 | #endif |
| 642 | #ifdef VULKAN_ENABLED |
| 643 | drivers.push_back("vulkan"); |
| 644 | #endif |
| 645 | |
| 646 | return drivers; |
| 647 | } |
| 648 | |
| 649 | DisplayServer *DisplayServerAndroid::create_func(const String &p_rendering_driver, DisplayServer::WindowMode p_mode, DisplayServer::VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Context p_context, int64_t p_parent_window, Error &r_error) { |
| 650 | DisplayServer *ds = memnew(DisplayServerAndroid(p_rendering_driver, p_mode, p_vsync_mode, p_flags, p_position, p_resolution, p_screen, p_context, p_parent_window, r_error)); |
| 651 | if (r_error != OK) { |
| 652 | if (p_rendering_driver == "vulkan") { |
| 653 | OS::get_singleton()->alert( |
| 654 | "Your device seems not to support the required Vulkan version.\n\n" |
| 655 | "Please try exporting your game using the 'gl_compatibility' renderer.", |
| 656 | "Unable to initialize Vulkan video driver"); |
| 657 | } else { |
| 658 | OS::get_singleton()->alert( |
| 659 | "Your device seems not to support the required OpenGL ES 3.0 version.", |
| 660 | "Unable to initialize OpenGL video driver"); |
| 661 | } |
| 662 | } |
| 663 | return ds; |
| 664 | } |
| 665 | |
| 666 | void DisplayServerAndroid::register_android_driver() { |
| 667 | register_create_function("android", create_func, get_rendering_drivers_func); |
| 668 | } |
| 669 | |
| 670 | void DisplayServerAndroid::reset_window() { |
| 671 | #if defined(RD_ENABLED) |
| 672 | if (rendering_context) { |
| 673 | if (rendering_device) { |
| 674 | rendering_device->screen_free(MAIN_WINDOW_ID); |
| 675 | } |
| 676 | |
| 677 | VSyncMode last_vsync_mode = rendering_context->window_get_vsync_mode(MAIN_WINDOW_ID); |
| 678 | rendering_context->window_destroy(MAIN_WINDOW_ID); |
| 679 | |
| 680 | union { |
| 681 | #ifdef VULKAN_ENABLED |
| 682 | RenderingContextDriverVulkanAndroid::WindowPlatformData vulkan; |
| 683 | #endif |
| 684 | } wpd; |
| 685 | #ifdef VULKAN_ENABLED |
| 686 | if (rendering_driver == "vulkan") { |
| 687 | ANativeWindow *native_window = OS_Android::get_singleton()->get_native_window(); |
| 688 | ERR_FAIL_NULL(native_window); |
| 689 | wpd.vulkan.window = native_window; |
| 690 | } |
| 691 | #endif |
| 692 | |
| 693 | if (rendering_context->window_create(MAIN_WINDOW_ID, &wpd) != OK) { |
| 694 | ERR_PRINT(vformat("Failed to reset %s window.", rendering_driver)); |
| 695 | memdelete(rendering_context); |
| 696 | rendering_context = nullptr; |
| 697 | return; |
| 698 | } |
| 699 | |
| 700 | Size2i display_size = OS_Android::get_singleton()->get_display_size(); |
| 701 | rendering_context->window_set_size(MAIN_WINDOW_ID, display_size.width, display_size.height); |
| 702 | rendering_context->window_set_vsync_mode(MAIN_WINDOW_ID, last_vsync_mode); |
| 703 | |
| 704 | if (rendering_device) { |
| 705 | rendering_device->screen_create(MAIN_WINDOW_ID); |
| 706 | } |
| 707 | } |
| 708 | #endif |
| 709 | } |
| 710 | |
| 711 | void DisplayServerAndroid::notify_surface_changed(int p_width, int p_height) { |
| 712 | if (rect_changed_callback.is_valid()) { |
| 713 | rect_changed_callback.call(Rect2i(0, 0, p_width, p_height)); |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | void DisplayServerAndroid::notify_application_paused() { |
| 718 | #if defined(RD_ENABLED) |
| 719 | if (rendering_device) { |
| 720 | rendering_device->update_pipeline_cache(); |
| 721 | } |
| 722 | #endif // defined(RD_ENABLED) |
| 723 | } |
| 724 | |
| 725 | DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, DisplayServer::WindowMode p_mode, DisplayServer::VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Context p_context, int64_t p_parent_window, Error &r_error) { |
| 726 | rendering_driver = p_rendering_driver; |
| 727 | |
| 728 | keep_screen_on = GLOBAL_GET("display/window/energy_saving/keep_screen_on"); |
| 729 | |
| 730 | native_menu = memnew(NativeMenu); |
| 731 | |
| 732 | #if defined(RD_ENABLED) |
| 733 | rendering_context = nullptr; |
| 734 | rendering_device = nullptr; |
| 735 | |
| 736 | #if defined(VULKAN_ENABLED) |
| 737 | if (rendering_driver == "vulkan") { |
| 738 | rendering_context = memnew(RenderingContextDriverVulkanAndroid); |
| 739 | } |
| 740 | #endif |
| 741 | |
| 742 | if (rendering_context) { |
| 743 | if (rendering_context->initialize() != OK) { |
| 744 | memdelete(rendering_context); |
| 745 | rendering_context = nullptr; |
| 746 | #if defined(GLES3_ENABLED) |
| 747 | bool fallback_to_opengl3 = GLOBAL_GET("rendering/rendering_device/fallback_to_opengl3"); |
| 748 | if (fallback_to_opengl3 && rendering_driver != "opengl3") { |
| 749 | WARN_PRINT("Your device does not seem to support Vulkan, switching to OpenGL 3."); |
| 750 | rendering_driver = "opengl3"; |
| 751 | OS::get_singleton()->set_current_rendering_method("gl_compatibility"); |
| 752 | OS::get_singleton()->set_current_rendering_driver_name(rendering_driver); |
| 753 | } else |
| 754 | #endif |
| 755 | { |
| 756 | ERR_PRINT(vformat("Failed to initialize %s context", rendering_driver)); |
| 757 | r_error = ERR_UNAVAILABLE; |
| 758 | return; |
| 759 | } |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | if (rendering_context) { |
| 764 | union { |
| 765 | #ifdef VULKAN_ENABLED |
| 766 | RenderingContextDriverVulkanAndroid::WindowPlatformData vulkan; |
| 767 | #endif |
| 768 | } wpd; |
| 769 | #ifdef VULKAN_ENABLED |
| 770 | if (rendering_driver == "vulkan") { |
| 771 | ANativeWindow *native_window = OS_Android::get_singleton()->get_native_window(); |
| 772 | ERR_FAIL_NULL(native_window); |
| 773 | wpd.vulkan.window = native_window; |
| 774 | } |
| 775 | #endif |
| 776 | |
| 777 | if (rendering_context->window_create(MAIN_WINDOW_ID, &wpd) != OK) { |
| 778 | ERR_PRINT(vformat("Failed to create %s window.", rendering_driver)); |
| 779 | memdelete(rendering_context); |
| 780 | rendering_context = nullptr; |
| 781 | r_error = ERR_UNAVAILABLE; |
| 782 | return; |
| 783 | } |
| 784 | |
| 785 | Size2i display_size = OS_Android::get_singleton()->get_display_size(); |
| 786 | rendering_context->window_set_size(MAIN_WINDOW_ID, display_size.width, display_size.height); |
| 787 | rendering_context->window_set_vsync_mode(MAIN_WINDOW_ID, p_vsync_mode); |
| 788 | |
| 789 | rendering_device = memnew(RenderingDevice); |
| 790 | if (rendering_device->initialize(rendering_context, MAIN_WINDOW_ID) != OK) { |
| 791 | rendering_device = nullptr; |
| 792 | memdelete(rendering_context); |
| 793 | rendering_context = nullptr; |
| 794 | r_error = ERR_UNAVAILABLE; |
| 795 | return; |
| 796 | } |
| 797 | rendering_device->screen_create(MAIN_WINDOW_ID); |
| 798 | |
| 799 | RendererCompositorRD::make_current(); |
| 800 | } |
| 801 | #endif |
| 802 | |
| 803 | #if defined(GLES3_ENABLED) |
| 804 | if (rendering_driver == "opengl3") { |
| 805 | RasterizerGLES3::make_current(false); |
| 806 | } |
| 807 | #endif |
| 808 | |
| 809 | Input::get_singleton()->set_event_dispatch_function(_dispatch_input_events); |
| 810 | |
| 811 | r_error = OK; |
| 812 | } |
| 813 | |
| 814 | DisplayServerAndroid::~DisplayServerAndroid() { |
| 815 | if (native_menu) { |
| 816 | memdelete(native_menu); |
| 817 | native_menu = nullptr; |
| 818 | } |
| 819 | |
| 820 | #if defined(RD_ENABLED) |
| 821 | if (rendering_device) { |
| 822 | memdelete(rendering_device); |
| 823 | } |
| 824 | if (rendering_context) { |
| 825 | memdelete(rendering_context); |
| 826 | } |
| 827 | #endif |
| 828 | } |
| 829 | |
| 830 | void DisplayServerAndroid::process_accelerometer(const Vector3 &p_accelerometer) { |
| 831 | Input::get_singleton()->set_accelerometer(p_accelerometer); |
| 832 | } |
| 833 | |
| 834 | void DisplayServerAndroid::process_gravity(const Vector3 &p_gravity) { |
| 835 | Input::get_singleton()->set_gravity(p_gravity); |
| 836 | } |
| 837 | |
| 838 | void DisplayServerAndroid::process_magnetometer(const Vector3 &p_magnetometer) { |
| 839 | Input::get_singleton()->set_magnetometer(p_magnetometer); |
| 840 | } |
| 841 | |
| 842 | void DisplayServerAndroid::process_gyroscope(const Vector3 &p_gyroscope) { |
| 843 | Input::get_singleton()->set_gyroscope(p_gyroscope); |
| 844 | } |
| 845 | |
| 846 | void DisplayServerAndroid::_mouse_update_mode() { |
| 847 | MouseMode wanted_mouse_mode = mouse_mode_override_enabled |
| 848 | ? mouse_mode_override |
| 849 | : mouse_mode_base; |
| 850 | |
| 851 | if (!OS_Android::get_singleton()->get_godot_java()->get_godot_view()->can_update_pointer_icon() || !OS_Android::get_singleton()->get_godot_java()->get_godot_view()->can_capture_pointer()) { |
| 852 | return; |
| 853 | } |
| 854 | if (mouse_mode == wanted_mouse_mode) { |
| 855 | return; |
| 856 | } |
| 857 | |
| 858 | if (wanted_mouse_mode == MouseMode::MOUSE_MODE_HIDDEN) { |
| 859 | OS_Android::get_singleton()->get_godot_java()->get_godot_view()->set_pointer_icon(CURSOR_TYPE_NULL); |
| 860 | } else { |
| 861 | cursor_set_shape(cursor_shape); |
| 862 | } |
| 863 | |
| 864 | if (wanted_mouse_mode == MouseMode::MOUSE_MODE_CAPTURED) { |
| 865 | OS_Android::get_singleton()->get_godot_java()->get_godot_view()->request_pointer_capture(); |
| 866 | } else { |
| 867 | OS_Android::get_singleton()->get_godot_java()->get_godot_view()->release_pointer_capture(); |
| 868 | } |
| 869 | |
| 870 | mouse_mode = wanted_mouse_mode; |
| 871 | } |
| 872 | |
| 873 | void DisplayServerAndroid::mouse_set_mode(MouseMode p_mode) { |
| 874 | ERR_FAIL_INDEX(p_mode, MouseMode::MOUSE_MODE_MAX); |
| 875 | if (p_mode == mouse_mode_base) { |
| 876 | return; |
| 877 | } |
| 878 | mouse_mode_base = p_mode; |
| 879 | _mouse_update_mode(); |
| 880 | } |
| 881 | |
| 882 | DisplayServer::MouseMode DisplayServerAndroid::mouse_get_mode() const { |
| 883 | return mouse_mode; |
| 884 | } |
| 885 | |
| 886 | void DisplayServerAndroid::mouse_set_mode_override(MouseMode p_mode) { |
| 887 | ERR_FAIL_INDEX(p_mode, MouseMode::MOUSE_MODE_MAX); |
| 888 | if (p_mode == mouse_mode_override) { |
| 889 | return; |
| 890 | } |
| 891 | mouse_mode_override = p_mode; |
| 892 | _mouse_update_mode(); |
| 893 | } |
| 894 | |
| 895 | DisplayServer::MouseMode DisplayServerAndroid::mouse_get_mode_override() const { |
| 896 | return mouse_mode_override; |
| 897 | } |
| 898 | |
| 899 | void DisplayServerAndroid::mouse_set_mode_override_enabled(bool p_override_enabled) { |
| 900 | mouse_mode_override_enabled = p_override_enabled; |
| 901 | _mouse_update_mode(); |
| 902 | } |
| 903 | |
| 904 | bool DisplayServerAndroid::mouse_is_mode_override_enabled() const { |
| 905 | return mouse_mode_override_enabled; |
| 906 | } |
| 907 | |
| 908 | Point2i DisplayServerAndroid::mouse_get_position() const { |
| 909 | return Input::get_singleton()->get_mouse_position(); |
| 910 | } |
| 911 | |
| 912 | BitField<MouseButtonMask> DisplayServerAndroid::mouse_get_button_state() const { |
| 913 | return Input::get_singleton()->get_mouse_button_mask(); |
| 914 | } |
| 915 | |
| 916 | void DisplayServerAndroid::_cursor_set_shape_helper(CursorShape p_shape, bool force) { |
| 917 | if (!OS_Android::get_singleton()->get_godot_java()->get_godot_view()->can_update_pointer_icon()) { |
| 918 | return; |
| 919 | } |
| 920 | if (cursor_shape == p_shape && !force) { |
| 921 | return; |
| 922 | } |
| 923 | |
| 924 | cursor_shape = p_shape; |
| 925 | |
| 926 | if (mouse_mode == MouseMode::MOUSE_MODE_VISIBLE || mouse_mode == MouseMode::MOUSE_MODE_CONFINED) { |
| 927 | OS_Android::get_singleton()->get_godot_java()->get_godot_view()->set_pointer_icon(android_cursors[cursor_shape]); |
| 928 | } |
| 929 | } |
| 930 | |
| 931 | void DisplayServerAndroid::cursor_set_shape(DisplayServer::CursorShape p_shape) { |
| 932 | ERR_FAIL_INDEX(p_shape, CURSOR_MAX); |
| 933 | _cursor_set_shape_helper(p_shape); |
| 934 | } |
| 935 | |
| 936 | DisplayServer::CursorShape DisplayServerAndroid::cursor_get_shape() const { |
| 937 | return cursor_shape; |
| 938 | } |
| 939 | |
| 940 | void DisplayServerAndroid::cursor_set_custom_image(const Ref<Resource> &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) { |
| 941 | ERR_FAIL_INDEX(p_shape, CURSOR_MAX); |
| 942 | String cursor_path = p_cursor.is_valid() ? p_cursor->get_path() : ""; |
| 943 | if (!cursor_path.is_empty()) { |
| 944 | cursor_path = ProjectSettings::get_singleton()->globalize_path(cursor_path); |
| 945 | } |
| 946 | OS_Android::get_singleton()->get_godot_java()->get_godot_view()->configure_pointer_icon(android_cursors[cursor_shape], cursor_path, p_hotspot); |
| 947 | _cursor_set_shape_helper(p_shape, true); |
| 948 | } |
| 949 | |
| 950 | void DisplayServerAndroid::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window) { |
| 951 | #if defined(RD_ENABLED) |
| 952 | if (rendering_context) { |
| 953 | rendering_context->window_set_vsync_mode(p_window, p_vsync_mode); |
| 954 | } |
| 955 | #endif |
| 956 | } |
| 957 | |
| 958 | DisplayServer::VSyncMode DisplayServerAndroid::window_get_vsync_mode(WindowID p_window) const { |
| 959 | #if defined(RD_ENABLED) |
| 960 | if (rendering_context) { |
| 961 | return rendering_context->window_get_vsync_mode(p_window); |
| 962 | } |
| 963 | #endif |
| 964 | return DisplayServer::VSYNC_ENABLED; |
| 965 | } |
| 966 | |
| 967 | void DisplayServerAndroid::reset_swap_buffers_flag() { |
| 968 | swap_buffers_flag = false; |
| 969 | } |
| 970 | |
| 971 | bool DisplayServerAndroid::should_swap_buffers() const { |
| 972 | return swap_buffers_flag; |
| 973 | } |
| 974 | |
| 975 | void DisplayServerAndroid::swap_buffers() { |
| 976 | swap_buffers_flag = true; |
| 977 | } |
| 978 | |
| 979 | void DisplayServerAndroid::set_native_icon(const String &p_filename) { |
| 980 | // NOT SUPPORTED |
| 981 | } |
| 982 | |
| 983 | void DisplayServerAndroid::set_icon(const Ref<Image> &p_icon) { |
| 984 | // NOT SUPPORTED |
| 985 | } |
| 986 | |
| 987 | bool DisplayServerAndroid::is_window_transparency_available() const { |
| 988 | return GLOBAL_GET_CACHED(bool, "display/window/per_pixel_transparency/allowed"); |
| 989 | } |