Fixed screen orientation on Android

This commit is contained in:
Szymon Majewski 2021-05-03 09:23:05 -07:00
parent af03e9c830
commit 5634093703
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) {
// Not supported on Android.
rect_changed_callback = p_callable;
}
void DisplayServerAndroid::window_set_drop_files_callback(const Callable &p_callable, DisplayServer::WindowID p_window) {
@ -389,6 +389,19 @@ void DisplayServerAndroid::reset_window() {
#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) {
rendering_driver = p_rendering_driver;

View file

@ -112,6 +112,7 @@ private:
Callable window_event_callback;
Callable input_event_callback;
Callable input_text_callback;
Callable rect_changed_callback;
void _window_callback(const Callable &p_callable, const Variant &p_arg) const;
@ -215,6 +216,7 @@ public:
static void register_android_driver();
void reset_window();
void notify_surface_changed(int p_width, int p_height);
virtual Point2i mouse_get_position() 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 rendererResumed = false
private var resumed = false
private var surfaceChanged = false
private var hasSurface = false
private var width = 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) {
lock.withLock {
hasSurface = true
surfaceChanged = true;
this.width = width
this.height = height
lockCondition.signalAll()
}
}
@ -188,8 +191,11 @@ internal class VkThread(private val vkSurfaceView: VkSurfaceView, private val vk
rendererInitialized = true
vkRenderer.onVkSurfaceCreated(vkSurfaceView.holder.surface)
}
}
if (surfaceChanged) {
vkRenderer.onVkSurfaceChanged(vkSurfaceView.holder.surface, width, height)
surfaceChanged = false
}
// 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);
DisplayServerAndroid::get_singleton()->reset_window();
DisplayServerAndroid::get_singleton()->notify_surface_changed(p_width, p_height);
}
}
}