From a94acde5191e8de731beba81376ff87d9815c3a0 Mon Sep 17 00:00:00 2001 From: SachinVin <26602104+SachinVin@users.noreply.github.com> Date: Sun, 9 Apr 2023 10:59:25 +0530 Subject: [PATCH] =?UTF-8?q?core\frontend\framebuffer=5Flayout:=20GetCardbo?= =?UTF-8?q?ardSettings:=20clean=20up=20floa=E2=80=A6=20(#6399)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * core\frontend\framebuffer_layout: GetCardboardSettings: clean up float to u32 conversion warnings + style fixes * clang format * fix signedness --- src/common/settings.h | 2 +- src/core/frontend/framebuffer_layout.cpp | 93 ++++++++++++------------ src/core/frontend/framebuffer_layout.h | 8 +- 3 files changed, 53 insertions(+), 50 deletions(-) diff --git a/src/common/settings.h b/src/common/settings.h index 9180a52c9e..40cc5e0b7e 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -458,7 +458,7 @@ struct Values { SwitchableSetting mono_render_option{MonoRenderOption::LeftEye, "mono_render_option"}; - Setting cardboard_screen_size{85, "cardboard_screen_size"}; + Setting cardboard_screen_size{85, "cardboard_screen_size"}; Setting cardboard_x_shift{0, "cardboard_x_shift"}; Setting cardboard_y_shift{0, "cardboard_y_shift"}; diff --git a/src/core/frontend/framebuffer_layout.cpp b/src/core/frontend/framebuffer_layout.cpp index 0928120533..19ed5bfd13 100644 --- a/src/core/frontend/framebuffer_layout.cpp +++ b/src/core/frontend/framebuffer_layout.cpp @@ -11,13 +11,13 @@ namespace Layout { -static const float TOP_SCREEN_ASPECT_RATIO = +static constexpr float TOP_SCREEN_ASPECT_RATIO = static_cast(Core::kScreenTopHeight) / Core::kScreenTopWidth; -static const float BOT_SCREEN_ASPECT_RATIO = +static constexpr float BOT_SCREEN_ASPECT_RATIO = static_cast(Core::kScreenBottomHeight) / Core::kScreenBottomWidth; -static const float TOP_SCREEN_UPRIGHT_ASPECT_RATIO = +static constexpr float TOP_SCREEN_UPRIGHT_ASPECT_RATIO = static_cast(Core::kScreenTopWidth) / Core::kScreenTopHeight; -static const float BOT_SCREEN_UPRIGHT_ASPECT_RATIO = +static constexpr float BOT_SCREEN_UPRIGHT_ASPECT_RATIO = static_cast(Core::kScreenBottomWidth) / Core::kScreenBottomHeight; u32 FramebufferLayout::GetScalingRatio() const { @@ -499,30 +499,31 @@ FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale, bool is_secondar return layout; } -FramebufferLayout GetCardboardSettings(FramebufferLayout layout) { - FramebufferLayout newLayout = layout; - float top_screen_left = 0; - float top_screen_top = 0; - float bottom_screen_left = 0; - float bottom_screen_top = 0; +FramebufferLayout GetCardboardSettings(const FramebufferLayout& layout) { + u32 top_screen_left = 0; + u32 top_screen_top = 0; + u32 bottom_screen_left = 0; + u32 bottom_screen_top = 0; - float cardboardScreenScale = Settings::values.cardboard_screen_size.GetValue() / 100.0f; - float top_screen_width = layout.top_screen.GetWidth() / 2.0f * cardboardScreenScale; - float top_screen_height = layout.top_screen.GetHeight() / 2.0f * cardboardScreenScale; - float bottom_screen_width = layout.bottom_screen.GetWidth() / 2.0f * cardboardScreenScale; - float bottom_screen_height = layout.bottom_screen.GetHeight() / 2.0f * cardboardScreenScale; + u32 cardboard_screen_scale = Settings::values.cardboard_screen_size.GetValue(); + u32 top_screen_width = ((layout.top_screen.GetWidth() / 2) * cardboard_screen_scale) / 100; + u32 top_screen_height = ((layout.top_screen.GetHeight() / 2) * cardboard_screen_scale) / 100; + u32 bottom_screen_width = + ((layout.bottom_screen.GetWidth() / 2) * cardboard_screen_scale) / 100; + u32 bottom_screen_height = + ((layout.bottom_screen.GetHeight() / 2) * cardboard_screen_scale) / 100; const bool is_swapped = Settings::values.swap_screen.GetValue(); const bool is_portrait = layout.height > layout.width; - float cardboardScreenWidth; - float cardboardScreenHeight; + u32 cardboard_screen_width; + u32 cardboard_screen_height; switch (Settings::values.layout_option.GetValue()) { case Settings::LayoutOption::MobileLandscape: case Settings::LayoutOption::SideScreen: // If orientation is portrait, only use MobilePortrait if (!is_portrait) { - cardboardScreenWidth = top_screen_width + bottom_screen_width; - cardboardScreenHeight = is_swapped ? bottom_screen_height : top_screen_height; + cardboard_screen_width = top_screen_width + bottom_screen_width; + cardboard_screen_height = is_swapped ? bottom_screen_height : top_screen_height; if (is_swapped) top_screen_left += bottom_screen_width; else @@ -535,50 +536,52 @@ FramebufferLayout GetCardboardSettings(FramebufferLayout layout) { default: if (!is_portrait) { // Default values when using LayoutOption::SingleScreen - cardboardScreenWidth = is_swapped ? bottom_screen_width : top_screen_width; - cardboardScreenHeight = is_swapped ? bottom_screen_height : top_screen_height; + cardboard_screen_width = is_swapped ? bottom_screen_width : top_screen_width; + cardboard_screen_height = is_swapped ? bottom_screen_height : top_screen_height; break; } else { [[fallthrough]]; } case Settings::LayoutOption::MobilePortrait: - cardboardScreenWidth = top_screen_width; - cardboardScreenHeight = top_screen_height + bottom_screen_height; - bottom_screen_left += (top_screen_width - bottom_screen_width) / 2.0f; + cardboard_screen_width = top_screen_width; + cardboard_screen_height = top_screen_height + bottom_screen_height; + bottom_screen_left += (top_screen_width - bottom_screen_width) / 2; if (is_swapped) top_screen_top += bottom_screen_height; else bottom_screen_top += top_screen_height; break; } - float cardboardMaxXShift = (layout.width / 2.0f - cardboardScreenWidth) / 2.0f; - float cardboardUserXShift = - (Settings::values.cardboard_x_shift.GetValue() / 100.0f) * cardboardMaxXShift; - float cardboardMaxYShift = ((float)layout.height - cardboardScreenHeight) / 2.0f; - float cardboardUserYShift = - (Settings::values.cardboard_y_shift.GetValue() / 100.0f) * cardboardMaxYShift; + s32 cardboard_max_x_shift = (layout.width / 2 - cardboard_screen_width) / 2; + s32 cardboard_user_x_shift = + (Settings::values.cardboard_x_shift.GetValue() * cardboard_max_x_shift) / 100; + s32 cardboard_max_y_shift = (layout.height - cardboard_screen_height) / 2; + s32 cardboard_user_y_shift = + (Settings::values.cardboard_y_shift.GetValue() * cardboard_max_y_shift) / 100; // Center the screens and apply user Y shift - newLayout.top_screen.left = top_screen_left + cardboardMaxXShift; - newLayout.top_screen.top = top_screen_top + cardboardMaxYShift + cardboardUserYShift; - newLayout.bottom_screen.left = bottom_screen_left + cardboardMaxXShift; - newLayout.bottom_screen.top = bottom_screen_top + cardboardMaxYShift + cardboardUserYShift; + FramebufferLayout new_layout = layout; + new_layout.top_screen.left = top_screen_left + cardboard_max_x_shift; + new_layout.top_screen.top = top_screen_top + cardboard_max_y_shift + cardboard_user_y_shift; + new_layout.bottom_screen.left = bottom_screen_left + cardboard_max_x_shift; + new_layout.bottom_screen.top = + bottom_screen_top + cardboard_max_y_shift + cardboard_user_y_shift; // Set the X coordinates for the right eye and apply user X shift - newLayout.cardboard.top_screen_right_eye = newLayout.top_screen.left - cardboardUserXShift; - newLayout.top_screen.left += cardboardUserXShift; - newLayout.cardboard.bottom_screen_right_eye = - newLayout.bottom_screen.left - cardboardUserXShift; - newLayout.bottom_screen.left += cardboardUserXShift; - newLayout.cardboard.user_x_shift = cardboardUserXShift; + new_layout.cardboard.top_screen_right_eye = new_layout.top_screen.left - cardboard_user_x_shift; + new_layout.top_screen.left += cardboard_user_x_shift; + new_layout.cardboard.bottom_screen_right_eye = + new_layout.bottom_screen.left - cardboard_user_x_shift; + new_layout.bottom_screen.left += cardboard_user_x_shift; + new_layout.cardboard.user_x_shift = cardboard_user_x_shift; // Update right/bottom instead of passing new variables for width/height - newLayout.top_screen.right = newLayout.top_screen.left + top_screen_width; - newLayout.top_screen.bottom = newLayout.top_screen.top + top_screen_height; - newLayout.bottom_screen.right = newLayout.bottom_screen.left + bottom_screen_width; - newLayout.bottom_screen.bottom = newLayout.bottom_screen.top + bottom_screen_height; + new_layout.top_screen.right = new_layout.top_screen.left + top_screen_width; + new_layout.top_screen.bottom = new_layout.top_screen.top + top_screen_height; + new_layout.bottom_screen.right = new_layout.bottom_screen.left + bottom_screen_width; + new_layout.bottom_screen.bottom = new_layout.bottom_screen.top + bottom_screen_height; - return newLayout; + return new_layout; } std::pair GetMinimumSizeFromLayout(Settings::LayoutOption layout, diff --git a/src/core/frontend/framebuffer_layout.h b/src/core/frontend/framebuffer_layout.h index 36a983ee37..192e79b4ac 100644 --- a/src/core/frontend/framebuffer_layout.h +++ b/src/core/frontend/framebuffer_layout.h @@ -11,9 +11,9 @@ namespace Layout { /// Describes the horizontal coordinates for the right eye screen when using Cardboard VR struct CardboardSettings { - float top_screen_right_eye; - float bottom_screen_right_eye; - float user_x_shift; + u32 top_screen_right_eye; + u32 bottom_screen_right_eye; + s32 user_x_shift; }; /// Describes the layout of the window framebuffer (size and top/bottom screen positions) @@ -130,7 +130,7 @@ FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale, bool is_secondar * @param layout frame layout to transform * @return layout transformed with the user cardboard settings */ -FramebufferLayout GetCardboardSettings(FramebufferLayout layout); +FramebufferLayout GetCardboardSettings(const FramebufferLayout& layout); std::pair GetMinimumSizeFromLayout(Settings::LayoutOption layout, bool upright_screen);