From aaa0e2fddfead4a31afddc07a26cd6af0c19dacd Mon Sep 17 00:00:00 2001 From: "Matias N. Goldberg" Date: Sun, 5 May 2024 19:15:56 -0300 Subject: Add Swappy & Pre-Transformed Swapchain - Adds Swappy for Android for stable frame pacing - Implements pre-transformed Swapchain so that Godot's compositor is in charge of rotating the screen instead of Android's compositor (performance optimization for phones that don't have HW rotator) ============================ The work was performed by collaboration of TheForge and Google. I am merely splitting it up into smaller PRs and cleaning it up. Changes from original PR: - Removed "display/window/frame_pacing/android/target_frame_rate" option to use Engine::get_max_fps instead. - Target framerate can be changed at runtime using Engine::set_max_fps. - Swappy is enabled by default. - Added documentation. - enable_auto_swap setting is replaced with swappy_mode. --- .../lib/src/org/godotengine/godot/GodotIO.java | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'platform/android/java') diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java b/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java index f060c7aaff..5543745444 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java @@ -47,6 +47,7 @@ import android.util.DisplayMetrics; import android.util.Log; import android.view.Display; import android.view.DisplayCutout; +import android.view.Surface; import android.view.WindowInsets; import androidx.core.content.FileProvider; @@ -295,6 +296,28 @@ public class GodotIO { } } + /** + This function is used by DisplayServer::screen_get_internal_current_rotation (C++) + and is used to implement a performance optimization in devices that do not offer + a HW rotator. + @return + Rotation in degrees, in multiples of 90° + */ + public int getInternalCurrentScreenRotation() { + int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); + + switch (rotation) { + case Surface.ROTATION_90: + return 90; + case Surface.ROTATION_180: + return 180; + case Surface.ROTATION_270: + return 270; + default: + return 0; + } + } + public void setEdit(GodotEditText _edit) { edit = _edit; } -- cgit v1.2.3