Merge pull request #48422 from szymonm-google/android_orientation_fix

Fixed changing screen orientation on Android
This commit is contained in:
Rémi Verschelde 2021-05-25 18:06:00 +02:00 committed by GitHub
commit 72a7ddaddc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 1 deletions

View File

@ -196,7 +196,7 @@ void DisplayServerAndroid::window_set_input_text_callback(const Callable &p_call
} }
void DisplayServerAndroid::window_set_rect_changed_callback(const Callable &p_callable, DisplayServer::WindowID p_window) { void DisplayServerAndroid::window_set_rect_changed_callback(const Callable &p_callable, DisplayServer::WindowID p_window) {
// Not supported on Android. rect_changed_callback = p_callable;
} }
void DisplayServerAndroid::window_set_drop_files_callback(const Callable &p_callable, DisplayServer::WindowID p_window) { void DisplayServerAndroid::window_set_drop_files_callback(const Callable &p_callable, DisplayServer::WindowID p_window) {
@ -389,6 +389,19 @@ void DisplayServerAndroid::reset_window() {
#endif #endif
} }
void DisplayServerAndroid::notify_surface_changed(int p_width, int p_height) {
if (rect_changed_callback.is_null()) {
return;
}
const Variant size = Rect2i(0, 0, p_width, p_height);
const Variant *sizep = &size;
Variant ret;
Callable::CallError ce;
rect_changed_callback.call(reinterpret_cast<const Variant **>(&sizep), 1, ret, ce);
}
DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, DisplayServer::WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, DisplayServer::WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) {
rendering_driver = p_rendering_driver; rendering_driver = p_rendering_driver;

View File

@ -112,6 +112,7 @@ private:
Callable window_event_callback; Callable window_event_callback;
Callable input_event_callback; Callable input_event_callback;
Callable input_text_callback; Callable input_text_callback;
Callable rect_changed_callback;
void _window_callback(const Callable &p_callable, const Variant &p_arg) const; void _window_callback(const Callable &p_callable, const Variant &p_arg) const;
@ -215,6 +216,7 @@ public:
static void register_android_driver(); static void register_android_driver();
void reset_window(); void reset_window();
void notify_surface_changed(int p_width, int p_height);
virtual Point2i mouse_get_position() const; virtual Point2i mouse_get_position() const;
virtual int mouse_get_button_state() const; virtual int mouse_get_button_state() const;

View File

@ -61,6 +61,7 @@ internal class VkThread(private val vkSurfaceView: VkSurfaceView, private val vk
private var rendererInitialized = false private var rendererInitialized = false
private var rendererResumed = false private var rendererResumed = false
private var resumed = false private var resumed = false
private var surfaceChanged = false
private var hasSurface = false private var hasSurface = false
private var width = 0 private var width = 0
private var height = 0 private var height = 0
@ -141,8 +142,10 @@ internal class VkThread(private val vkSurfaceView: VkSurfaceView, private val vk
fun onSurfaceChanged(width: Int, height: Int) { fun onSurfaceChanged(width: Int, height: Int) {
lock.withLock { lock.withLock {
hasSurface = true hasSurface = true
surfaceChanged = true;
this.width = width this.width = width
this.height = height this.height = height
lockCondition.signalAll() lockCondition.signalAll()
} }
} }
@ -188,8 +191,11 @@ internal class VkThread(private val vkSurfaceView: VkSurfaceView, private val vk
rendererInitialized = true rendererInitialized = true
vkRenderer.onVkSurfaceCreated(vkSurfaceView.holder.surface) vkRenderer.onVkSurfaceCreated(vkSurfaceView.holder.surface)
} }
}
if (surfaceChanged) {
vkRenderer.onVkSurfaceChanged(vkSurfaceView.holder.surface, width, height) vkRenderer.onVkSurfaceChanged(vkSurfaceView.holder.surface, width, height)
surfaceChanged = false
} }
// Break out of the loop so drawing can occur without holding onto the lock. // Break out of the loop so drawing can occur without holding onto the lock.

View File

@ -173,6 +173,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_resize(JNIEnv *env, j
os_android->set_native_window(native_window); os_android->set_native_window(native_window);
DisplayServerAndroid::get_singleton()->reset_window(); DisplayServerAndroid::get_singleton()->reset_window();
DisplayServerAndroid::get_singleton()->notify_surface_changed(p_width, p_height);
} }
} }
} }