2025-09-21 21:58:59 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
2022-04-23 04:59:50 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2016-05-03 00:07:17 -06:00
|
|
|
|
2018-01-11 22:24:09 -05:00
|
|
|
#include <cmath>
|
|
|
|
|
|
2016-05-03 00:07:17 -06:00
|
|
|
#include "common/assert.h"
|
2021-04-14 16:07:40 -07:00
|
|
|
#include "common/settings.h"
|
2023-08-21 16:03:30 -04:00
|
|
|
#include "common/settings_enums.h"
|
2017-05-27 16:10:25 -07:00
|
|
|
#include "core/frontend/framebuffer_layout.h"
|
2016-05-03 00:07:17 -06:00
|
|
|
|
|
|
|
|
namespace Layout {
|
|
|
|
|
|
2016-11-05 01:47:05 -06:00
|
|
|
// Finds the largest size subrectangle contained in window area that is confined to the aspect ratio
|
2025-10-21 21:39:09 +02:00
|
|
|
static Common::Rectangle<u32> MaxRectangle(Common::Rectangle<u32> window_area, float screen_aspect_ratio) noexcept {
|
|
|
|
|
const float scale = (std::min)(float(window_area.GetWidth()), float(window_area.GetHeight()) / screen_aspect_ratio);
|
|
|
|
|
return Common::Rectangle<u32>{0, 0, u32(std::round(scale)), u32(std::round(scale * screen_aspect_ratio))};
|
2016-05-03 00:07:17 -06:00
|
|
|
}
|
|
|
|
|
|
2025-10-21 21:39:09 +02:00
|
|
|
/// @brief Factory method for constructing a default FramebufferLayout
|
|
|
|
|
/// @param width Window framebuffer width in pixels
|
|
|
|
|
/// @param height Window framebuffer height in pixels
|
|
|
|
|
/// @return Newly created FramebufferLayout object with default screen regions initialized
|
|
|
|
|
FramebufferLayout DefaultFrameLayout(u32 width, u32 height) noexcept {
|
|
|
|
|
ASSERT(width > 0 && height > 0);
|
|
|
|
|
auto const window_aspect_ratio = float(height) / float(width);
|
|
|
|
|
auto const emulation_aspect_ratio = EmulationAspectRatio(Settings::values.aspect_ratio.GetValue(), window_aspect_ratio);
|
|
|
|
|
Common::Rectangle<u32> const screen_window_area{0, 0, width, height};
|
|
|
|
|
auto screen = MaxRectangle(screen_window_area, emulation_aspect_ratio);
|
|
|
|
|
if (window_aspect_ratio < emulation_aspect_ratio) {
|
|
|
|
|
screen = screen.TranslateX((screen_window_area.GetWidth() - screen.GetWidth()) / 2);
|
|
|
|
|
} else {
|
|
|
|
|
screen = screen.TranslateY((height - screen.GetHeight()) / 2);
|
|
|
|
|
}
|
2016-11-05 01:47:05 -06:00
|
|
|
// The drawing code needs at least somewhat valid values for both screens
|
|
|
|
|
// so just calculate them both even if the other isn't showing.
|
2025-10-21 21:39:09 +02:00
|
|
|
return FramebufferLayout{
|
2021-11-20 17:48:22 -05:00
|
|
|
.width = width,
|
|
|
|
|
.height = height,
|
2025-10-21 21:39:09 +02:00
|
|
|
.screen = screen,
|
2021-11-20 17:48:22 -05:00
|
|
|
.is_srgb = false,
|
|
|
|
|
};
|
2018-08-31 14:16:16 +08:00
|
|
|
}
|
|
|
|
|
|
2025-10-21 21:39:09 +02:00
|
|
|
/// @brief Convenience method to determine emulation aspect ratio
|
|
|
|
|
/// @param aspect Represents the index of aspect ratio stored in Settings::values.aspect_ratio
|
|
|
|
|
/// @param window_aspect_ratio Current window aspect ratio
|
|
|
|
|
/// @return Emulation render window aspect ratio
|
|
|
|
|
float EmulationAspectRatio(Settings::AspectRatio aspect, float window_aspect_ratio) noexcept {
|
2020-02-14 00:06:26 -05:00
|
|
|
switch (aspect) {
|
2025-10-21 21:39:09 +02:00
|
|
|
case Settings::AspectRatio::R16_9:
|
|
|
|
|
return 9.0f / 16.0f;
|
|
|
|
|
case Settings::AspectRatio::R4_3:
|
2020-02-14 14:39:04 -05:00
|
|
|
return 3.0f / 4.0f;
|
2025-10-21 21:39:09 +02:00
|
|
|
case Settings::AspectRatio::R21_9:
|
2020-02-14 00:06:26 -05:00
|
|
|
return 9.0f / 21.0f;
|
2025-10-21 21:39:09 +02:00
|
|
|
case Settings::AspectRatio::R16_10:
|
2022-10-10 13:32:09 -05:00
|
|
|
return 10.0f / 16.0f;
|
2025-10-21 21:39:09 +02:00
|
|
|
case Settings::AspectRatio::Stretch:
|
2020-02-14 00:06:26 -05:00
|
|
|
return window_aspect_ratio;
|
|
|
|
|
default:
|
2025-10-21 21:39:09 +02:00
|
|
|
return float(ScreenUndocked::Height) / ScreenUndocked::Width;
|
2020-02-14 00:06:26 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-25 23:53:07 +02:00
|
|
|
} // namespace Layout
|