Skip to content

Commit 2739356

Browse files
committed
Unify and clean-up Godot Android surface allocation and render thread logic
1 parent c81fd6c commit 2739356

33 files changed

+1507
-1289
lines changed

platform/android/SCsub

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ android_files = [
2323
"java_godot_lib_jni.cpp",
2424
"java_class_wrapper.cpp",
2525
"java_godot_wrapper.cpp",
26-
"java_godot_view_wrapper.cpp",
2726
"java_godot_io_wrapper.cpp",
2827
"jni_utils.cpp",
2928
"android_keys_utils.cpp",

platform/android/display_server_android.cpp

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "tts_android.h"
3737

3838
#include "core/config/project_settings.h"
39+
#include "main/main.h"
3940

4041
#if defined(RD_ENABLED)
4142
#include "servers/rendering/renderer_rd/renderer_compositor_rd.h"
@@ -703,6 +704,9 @@ void DisplayServerAndroid::reset_window() {
703704
}
704705
}
705706
#endif
707+
708+
// We force redraw to ensure we render at least once when the window is reset.
709+
Main::force_redraw();
706710
}
707711

708712
void DisplayServerAndroid::notify_surface_changed(int p_width, int p_height) {
@@ -837,23 +841,23 @@ void DisplayServerAndroid::_mouse_update_mode() {
837841
? mouse_mode_override
838842
: mouse_mode_base;
839843

840-
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()) {
844+
if (!OS_Android::get_singleton()->get_godot_java()->can_capture_pointer()) {
841845
return;
842846
}
843847
if (mouse_mode == wanted_mouse_mode) {
844848
return;
845849
}
846850

847851
if (wanted_mouse_mode == MouseMode::MOUSE_MODE_HIDDEN) {
848-
OS_Android::get_singleton()->get_godot_java()->get_godot_view()->set_pointer_icon(CURSOR_TYPE_NULL);
852+
OS_Android::get_singleton()->get_godot_java()->set_pointer_icon(CURSOR_TYPE_NULL);
849853
} else {
850854
cursor_set_shape(cursor_shape);
851855
}
852856

853857
if (wanted_mouse_mode == MouseMode::MOUSE_MODE_CAPTURED) {
854-
OS_Android::get_singleton()->get_godot_java()->get_godot_view()->request_pointer_capture();
858+
OS_Android::get_singleton()->get_godot_java()->request_pointer_capture();
855859
} else {
856-
OS_Android::get_singleton()->get_godot_java()->get_godot_view()->release_pointer_capture();
860+
OS_Android::get_singleton()->get_godot_java()->release_pointer_capture();
857861
}
858862

859863
mouse_mode = wanted_mouse_mode;
@@ -903,17 +907,14 @@ BitField<MouseButtonMask> DisplayServerAndroid::mouse_get_button_state() const {
903907
}
904908

905909
void DisplayServerAndroid::_cursor_set_shape_helper(CursorShape p_shape, bool force) {
906-
if (!OS_Android::get_singleton()->get_godot_java()->get_godot_view()->can_update_pointer_icon()) {
907-
return;
908-
}
909910
if (cursor_shape == p_shape && !force) {
910911
return;
911912
}
912913

913914
cursor_shape = p_shape;
914915

915916
if (mouse_mode == MouseMode::MOUSE_MODE_VISIBLE || mouse_mode == MouseMode::MOUSE_MODE_CONFINED) {
916-
OS_Android::get_singleton()->get_godot_java()->get_godot_view()->set_pointer_icon(android_cursors[cursor_shape]);
917+
OS_Android::get_singleton()->get_godot_java()->set_pointer_icon(android_cursors[cursor_shape]);
917918
}
918919
}
919920

@@ -932,7 +933,7 @@ void DisplayServerAndroid::cursor_set_custom_image(const Ref<Resource> &p_cursor
932933
if (!cursor_path.is_empty()) {
933934
cursor_path = ProjectSettings::get_singleton()->globalize_path(cursor_path);
934935
}
935-
OS_Android::get_singleton()->get_godot_java()->get_godot_view()->configure_pointer_icon(android_cursors[cursor_shape], cursor_path, p_hotspot);
936+
OS_Android::get_singleton()->get_godot_java()->configure_pointer_icon(android_cursors[cursor_shape], cursor_path, p_hotspot);
936937
_cursor_set_shape_helper(p_shape, true);
937938
}
938939

@@ -953,16 +954,24 @@ DisplayServer::VSyncMode DisplayServerAndroid::window_get_vsync_mode(WindowID p_
953954
return DisplayServer::VSYNC_ENABLED;
954955
}
955956

956-
void DisplayServerAndroid::reset_swap_buffers_flag() {
957-
swap_buffers_flag = false;
958-
}
957+
void DisplayServerAndroid::release_rendering_thread() {
958+
if (egl_current_window_id == INVALID_WINDOW_ID) {
959+
return;
960+
}
959961

960-
bool DisplayServerAndroid::should_swap_buffers() const {
961-
return swap_buffers_flag;
962+
GodotJavaWrapper *godot_java = OS_Android::get_singleton()->get_godot_java();
963+
ERR_FAIL_NULL(godot_java);
964+
godot_java->release_current_gl_window(egl_current_window_id);
962965
}
963966

964967
void DisplayServerAndroid::swap_buffers() {
965-
swap_buffers_flag = true;
968+
if (egl_current_window_id == INVALID_WINDOW_ID) {
969+
return;
970+
}
971+
972+
GodotJavaWrapper *godot_java = OS_Android::get_singleton()->get_godot_java();
973+
ERR_FAIL_NULL(godot_java);
974+
godot_java->egl_swap_buffers(egl_current_window_id);
966975
}
967976

968977
void DisplayServerAndroid::set_native_icon(const String &p_filename) {
@@ -976,3 +985,18 @@ void DisplayServerAndroid::set_icon(const Ref<Image> &p_icon) {
976985
bool DisplayServerAndroid::is_window_transparency_available() const {
977986
return GLOBAL_GET_CACHED(bool, "display/window/per_pixel_transparency/allowed");
978987
}
988+
989+
void DisplayServerAndroid::gl_window_make_current(DisplayServer::WindowID p_window_id) {
990+
if (p_window_id == INVALID_WINDOW_ID) {
991+
return;
992+
}
993+
994+
if (egl_current_window_id == p_window_id) {
995+
return;
996+
}
997+
998+
GodotJavaWrapper *godot_java = OS_Android::get_singleton()->get_godot_java();
999+
ERR_FAIL_NULL(godot_java);
1000+
godot_java->make_gl_window_current(p_window_id);
1001+
egl_current_window_id = p_window_id;
1002+
}

platform/android/display_server_android.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class DisplayServerAndroid : public DisplayServer {
7171
void _mouse_update_mode();
7272

7373
bool keep_screen_on;
74-
bool swap_buffers_flag;
74+
WindowID egl_current_window_id = MAIN_WINDOW_ID;
7575

7676
CursorShape cursor_shape = CursorShape::CURSOR_ARROW;
7777

@@ -249,15 +249,16 @@ class DisplayServerAndroid : public DisplayServer {
249249
virtual Point2i mouse_get_position() const override;
250250
virtual BitField<MouseButtonMask> mouse_get_button_state() const override;
251251

252-
void reset_swap_buffers_flag();
253-
bool should_swap_buffers() const;
252+
virtual void release_rendering_thread() override;
254253
virtual void swap_buffers() override;
255254

256255
virtual void set_native_icon(const String &p_filename) override;
257256
virtual void set_icon(const Ref<Image> &p_icon) override;
258257

259258
virtual bool is_window_transparency_available() const override;
260259

260+
virtual void gl_window_make_current(WindowID p_window_id) override;
261+
261262
DisplayServerAndroid(const String &p_rendering_driver, 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);
262263
~DisplayServerAndroid();
263264
};

platform/android/java/editor/src/main/java/org/godotengine/editor/BaseGodotEditor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ abstract class BaseGodotEditor : GodotActivity(), GameMenuFragment.GameMenuListe
316316

317317
runOnUiThread {
318318
// Enable long press, panning and scaling gestures
319-
godotFragment?.godot?.renderView?.inputHandler?.apply {
319+
godotFragment?.godot?.godotInputHandler?.apply {
320320
enableLongPress(longPressEnabled)
321321
enablePanningAndScalingGestures(panScaleEnabled)
322322
setOverrideVolumeButtons(overrideVolumeButtonsEnabled)

0 commit comments

Comments
 (0)