From 09e15e750dd9f195ae02d2af9d0dc7aeeb4b20ae Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 20 Jul 2019 22:59:38 -0400 Subject: [PATCH] android: frontend: Add MobileLandscape layout profile for mobile devices. --- src/android/app/src/main/jni/native.cpp | 2 + src/core/frontend/emu_window.cpp | 7 +++- src/core/frontend/framebuffer_layout.cpp | 53 ++++++++++++++++++++++++ src/core/frontend/framebuffer_layout.h | 14 +++++++ src/core/settings.h | 4 ++ 5 files changed, 78 insertions(+), 2 deletions(-) diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp index 129a2053f..774491236 100644 --- a/src/android/app/src/main/jni/native.cpp +++ b/src/android/app/src/main/jni/native.cpp @@ -194,6 +194,8 @@ void Java_org_citra_citra_1android_NativeLibrary_CacheClassesAndMethods(JNIEnv* void Java_org_citra_citra_1android_NativeLibrary_SwitchScreenLayout(JNIEnv* env, jobject obj) { if (Settings::values.layout_option == Settings::LayoutOption::MobilePortrait) { + Settings::values.layout_option = Settings::LayoutOption::MobileLandscape; + } else if (Settings::values.layout_option == Settings::LayoutOption::MobileLandscape) { Settings::values.layout_option = Settings::LayoutOption::SingleScreen; } else if (Settings::values.layout_option == Settings::LayoutOption::SingleScreen) { Settings::values.layout_option = Settings::LayoutOption::LargeScreen; diff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cpp index c92322f90..2a954c554 100644 --- a/src/core/frontend/emu_window.cpp +++ b/src/core/frontend/emu_window.cpp @@ -170,8 +170,11 @@ void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height) Settings::values.upright_screen); break; case Settings::LayoutOption::MobilePortrait: - layout = - Layout::DefaultFrameLayout(width, height, Settings::values.swap_screen, true, true); + layout = Layout::MobilePortraitFrameLayout(width, height, Settings::values.swap_screen); + break; + case Settings::LayoutOption::MobileLandscape: + layout = Layout::MobileLandscapeFrameLayout(width, height, Settings::values.swap_screen, + 2.25f, false); break; case Settings::LayoutOption::Default: default: diff --git a/src/core/frontend/framebuffer_layout.cpp b/src/core/frontend/framebuffer_layout.cpp index c3d937b1e..7e2df617c 100644 --- a/src/core/frontend/framebuffer_layout.cpp +++ b/src/core/frontend/framebuffer_layout.cpp @@ -151,6 +151,48 @@ FramebufferLayout MobilePortraitFrameLayout(u32 width, u32 height, bool swapped) return res; } +FramebufferLayout MobileLandscapeFrameLayout(u32 width, u32 height, bool swapped, + float scale_factor, bool center_vertical) { + ASSERT(width > 0); + ASSERT(height > 0); + + FramebufferLayout res{width, height, true, true, {}, {}}; + // Split the window into two parts. Give 4x width to the main screen and 1x width to the small + // To do that, find the total emulation box and maximize that based on window size + float window_aspect_ratio = static_cast(height) / width; + float emulation_aspect_ratio = + swapped ? Core::kScreenBottomHeight * scale_factor / + (Core::kScreenBottomWidth * scale_factor + Core::kScreenTopWidth) + : Core::kScreenTopHeight * scale_factor / + (Core::kScreenTopWidth * scale_factor + Core::kScreenBottomWidth); + float large_screen_aspect_ratio = swapped ? BOT_SCREEN_ASPECT_RATIO : TOP_SCREEN_ASPECT_RATIO; + float small_screen_aspect_ratio = swapped ? TOP_SCREEN_ASPECT_RATIO : BOT_SCREEN_ASPECT_RATIO; + + Common::Rectangle screen_window_area{0, 0, width, height}; + Common::Rectangle total_rect = maxRectangle(screen_window_area, emulation_aspect_ratio); + Common::Rectangle large_screen = maxRectangle(total_rect, large_screen_aspect_ratio); + Common::Rectangle fourth_size_rect = total_rect.Scale(1.f / scale_factor); + Common::Rectangle small_screen = maxRectangle(fourth_size_rect, small_screen_aspect_ratio); + + if (window_aspect_ratio < emulation_aspect_ratio) { + large_screen = + large_screen.TranslateX((screen_window_area.GetWidth() - total_rect.GetWidth()) / 2); + } else if (center_vertical) { + large_screen = large_screen.TranslateY((height - total_rect.GetHeight()) / 2); + } + + // Shift the small screen to the bottom right corner + small_screen = small_screen.TranslateX(large_screen.right); + if (center_vertical) { + small_screen.TranslateY(large_screen.GetHeight() + large_screen.top - + small_screen.GetHeight()); + } + + res.top_screen = swapped ? small_screen : large_screen; + res.bottom_screen = swapped ? large_screen : small_screen; + return res; +} + FramebufferLayout SingleFrameLayout(u32 width, u32 height, bool swapped, bool upright) { ASSERT(width > 0); ASSERT(height > 0); @@ -385,6 +427,17 @@ FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale) { height = (Core::kScreenTopHeight + Core::kScreenBottomHeight) * res_scale; layout = MobilePortraitFrameLayout(width, height, Settings::values.swap_screen); break; + case Settings::LayoutOption::MobileLandscape: + if (Settings::values.swap_screen) { + width = (Core::kScreenBottomWidth + Core::kScreenTopWidth / 2.25f) * res_scale; + height = Core::kScreenBottomHeight * res_scale; + } else { + width = (Core::kScreenTopWidth + Core::kScreenBottomWidth / 2.25f) * res_scale; + height = Core::kScreenTopHeight * res_scale; + } + layout = MobileLandscapeFrameLayout(width, height, Settings::values.swap_screen, 2.25f, + false); + break; case Settings::LayoutOption::Default: default: if (Settings::values.upright_screen) { diff --git a/src/core/frontend/framebuffer_layout.h b/src/core/frontend/framebuffer_layout.h index 5aead06f7..ddbe86a2b 100644 --- a/src/core/frontend/framebuffer_layout.h +++ b/src/core/frontend/framebuffer_layout.h @@ -44,6 +44,20 @@ FramebufferLayout DefaultFrameLayout(u32 width, u32 height, bool is_swapped, boo */ FramebufferLayout MobilePortraitFrameLayout(u32 width, u32 height, bool is_swapped); +/** + * Factory method for constructing a Frame with the a 4x size Top screen with a 1x size bottom + * screen on the right + * This is useful in particular because it matches well with a 1920x1080 resolution monitor + * @param width Window framebuffer width in pixels + * @param height Window framebuffer height in pixels + * @param is_swapped if true, the bottom screen will be the large display + * @param scale_factor Scale factor to use for bottom screen with respect to top screen + * @param center_vertical When true, centers the top and bottom screens vertically + * @return Newly created FramebufferLayout object with default screen regions initialized + */ +FramebufferLayout MobileLandscapeFrameLayout(u32 width, u32 height, bool is_swapped, + float scale_factor, bool center_vertical); + /** * Factory method for constructing a FramebufferLayout with only the top or bottom screen * @param width Window framebuffer width in pixels diff --git a/src/core/settings.h b/src/core/settings.h index 80c1dee9f..4773f8900 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -28,6 +28,10 @@ enum class LayoutOption { // Similiar to default, but better for mobile devices in portrait mode. Top screen in clamped to // the top of the frame, and the bottom screen is enlarged to match the top screen. MobilePortrait, + + // Similiar to LargeScreen, but better for mobile devices in landscape mode. The screens are + // clamped to the top of the frame, and the bottom screen is a bit bigger. + MobileLandscape, }; enum class MicInputType {