From eb10f250254a0153abd789e49a36945d996631a7 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 27 May 2017 18:06:59 -0700 Subject: [PATCH] Move screen size constants from video_core to core video_core didn't even properly use them, and they were the source of many otherwise-unnecessary dependencies from core to video_core. --- src/citra/emu_window/emu_window_sdl2.cpp | 14 ++++++------- src/citra_qt/bootmanager.cpp | 6 ++---- src/core/3ds.h | 21 +++++++++++++++++++ src/core/CMakeLists.txt | 1 + src/core/frontend/emu_window.cpp | 8 +++---- src/core/frontend/framebuffer_layout.cpp | 18 +++++++++------- src/core/frontend/framebuffer_layout.h | 11 +++++++++- .../renderer_opengl/gl_rasterizer_cache.cpp | 20 +++++++----------- src/video_core/video_core.h | 15 ------------- 9 files changed, 63 insertions(+), 51 deletions(-) create mode 100644 src/core/3ds.h diff --git a/src/citra/emu_window/emu_window_sdl2.cpp b/src/citra/emu_window/emu_window_sdl2.cpp index 6bc0b0d001..47aadd60c3 100644 --- a/src/citra/emu_window/emu_window_sdl2.cpp +++ b/src/citra/emu_window/emu_window_sdl2.cpp @@ -12,10 +12,10 @@ #include "common/logging/log.h" #include "common/scm_rev.h" #include "common/string_util.h" +#include "core/3ds.h" #include "core/settings.h" #include "input_common/keyboard.h" #include "input_common/main.h" -#include "video_core/video_core.h" void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { TouchMoved((unsigned)std::max(x, 0), (unsigned)std::max(y, 0)); @@ -80,12 +80,12 @@ EmuWindow_SDL2::EmuWindow_SDL2() { std::string window_title = Common::StringFromFormat("Citra %s| %s-%s ", Common::g_build_name, Common::g_scm_branch, Common::g_scm_desc); - render_window = SDL_CreateWindow( - window_title.c_str(), - SDL_WINDOWPOS_UNDEFINED, // x position - SDL_WINDOWPOS_UNDEFINED, // y position - VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight, - SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); + render_window = + SDL_CreateWindow(window_title.c_str(), + SDL_WINDOWPOS_UNDEFINED, // x position + SDL_WINDOWPOS_UNDEFINED, // y position + Core::kScreenTopWidth, Core::kScreenTopHeight + Core::kScreenBottomHeight, + SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); if (render_window == nullptr) { LOG_CRITICAL(Frontend, "Failed to create SDL2 window! Exiting..."); diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index bae576d6ab..06b62f44c1 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -12,12 +12,11 @@ #include "common/microprofile.h" #include "common/scm_rev.h" #include "common/string_util.h" +#include "core/3ds.h" #include "core/core.h" #include "core/settings.h" #include "input_common/keyboard.h" #include "input_common/main.h" -#include "video_core/debug_utils/debug_utils.h" -#include "video_core/video_core.h" EmuThread::EmuThread(GRenderWindow* render_window) : exec_step(false), running(false), stop_run(false), render_window(render_window) {} @@ -266,8 +265,7 @@ void GRenderWindow::InitRenderTarget() { child = new GGLWidgetInternal(fmt, this); QBoxLayout* layout = new QHBoxLayout(this); - resize(VideoCore::kScreenTopWidth, - VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight); + resize(Core::kScreenTopWidth, Core::kScreenTopHeight + Core::kScreenBottomHeight); layout->addWidget(child); layout->setMargin(0); setLayout(layout); diff --git a/src/core/3ds.h b/src/core/3ds.h new file mode 100644 index 0000000000..8715e27db2 --- /dev/null +++ b/src/core/3ds.h @@ -0,0 +1,21 @@ +// Copyright 2017 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +namespace Core { + +// 3DS Video Constants +// ------------------- + +// NOTE: The LCDs actually rotate the image 90 degrees when displaying. Because of that the +// framebuffers in video memory are stored in column-major order and rendered sideways, causing +// the widths and heights of the framebuffers read by the LCD to be switched compared to the +// heights and widths of the screens listed here. +constexpr int kScreenTopWidth = 400; ///< 3DS top screen width +constexpr int kScreenTopHeight = 240; ///< 3DS top screen height +constexpr int kScreenBottomWidth = 320; ///< 3DS bottom screen width +constexpr int kScreenBottomHeight = 240; ///< 3DS bottom screen height + +} // namespace Core diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index d9618c40c6..cbfd1299cf 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -179,6 +179,7 @@ set(SRCS ) set(HEADERS + 3ds.h arm/arm_interface.h arm/dynarmic/arm_dynarmic.h arm/dynarmic/arm_dynarmic_cp15.h diff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cpp index 5fdb3a7e8f..4f7d54a33a 100644 --- a/src/core/frontend/emu_window.cpp +++ b/src/core/frontend/emu_window.cpp @@ -5,10 +5,10 @@ #include #include #include "common/assert.h" +#include "core/3ds.h" #include "core/core.h" #include "core/frontend/emu_window.h" #include "core/settings.h" -#include "video_core/video_core.h" /** * Check if the given x/y coordinates are within the touchpad specified by the framebuffer layout @@ -38,11 +38,9 @@ void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y) { if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y)) return; - touch_x = VideoCore::kScreenBottomWidth * - (framebuffer_x - framebuffer_layout.bottom_screen.left) / + touch_x = Core::kScreenBottomWidth * (framebuffer_x - framebuffer_layout.bottom_screen.left) / (framebuffer_layout.bottom_screen.right - framebuffer_layout.bottom_screen.left); - touch_y = VideoCore::kScreenBottomHeight * - (framebuffer_y - framebuffer_layout.bottom_screen.top) / + touch_y = Core::kScreenBottomHeight * (framebuffer_y - framebuffer_layout.bottom_screen.top) / (framebuffer_layout.bottom_screen.bottom - framebuffer_layout.bottom_screen.top); touch_pressed = true; diff --git a/src/core/frontend/framebuffer_layout.cpp b/src/core/frontend/framebuffer_layout.cpp index f3815170d5..d2d02f9ff4 100644 --- a/src/core/frontend/framebuffer_layout.cpp +++ b/src/core/frontend/framebuffer_layout.cpp @@ -5,16 +5,20 @@ #include #include "common/assert.h" +#include "core/3ds.h" #include "core/frontend/framebuffer_layout.h" #include "core/settings.h" -#include "video_core/video_core.h" namespace Layout { static const float TOP_SCREEN_ASPECT_RATIO = - static_cast(VideoCore::kScreenTopHeight) / VideoCore::kScreenTopWidth; + static_cast(Core::kScreenTopHeight) / Core::kScreenTopWidth; static const float BOT_SCREEN_ASPECT_RATIO = - static_cast(VideoCore::kScreenBottomHeight) / VideoCore::kScreenBottomWidth; + static_cast(Core::kScreenBottomHeight) / Core::kScreenBottomWidth; + +float FramebufferLayout::GetScalingRatio() const { + return static_cast(top_screen.GetWidth()) / Core::kScreenTopWidth; +} // Finds the largest size subrectangle contained in window area that is confined to the aspect ratio template @@ -106,10 +110,10 @@ FramebufferLayout LargeFrameLayout(unsigned width, unsigned height, bool swapped float window_aspect_ratio = static_cast(height) / width; float emulation_aspect_ratio = swapped - ? VideoCore::kScreenBottomHeight * 4 / - (VideoCore::kScreenBottomWidth * 4.0f + VideoCore::kScreenTopWidth) - : VideoCore::kScreenTopHeight * 4 / - (VideoCore::kScreenTopWidth * 4.0f + VideoCore::kScreenBottomWidth); + ? Core::kScreenBottomHeight * 4 / + (Core::kScreenBottomWidth * 4.0f + Core::kScreenTopWidth) + : Core::kScreenTopHeight * 4 / + (Core::kScreenTopWidth * 4.0f + 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; diff --git a/src/core/frontend/framebuffer_layout.h b/src/core/frontend/framebuffer_layout.h index f1df5c55af..9a7738969b 100644 --- a/src/core/frontend/framebuffer_layout.h +++ b/src/core/frontend/framebuffer_layout.h @@ -5,7 +5,9 @@ #pragma once #include "common/math_util.h" + namespace Layout { + /// Describes the layout of the window framebuffer (size and top/bottom screen positions) struct FramebufferLayout { unsigned width; @@ -14,6 +16,12 @@ struct FramebufferLayout { bool bottom_screen_enabled; MathUtil::Rectangle top_screen; MathUtil::Rectangle bottom_screen; + + /** + * Returns the ration of pixel size of the top screen, compared to the native size of the 3DS + * screen. + */ + float GetScalingRatio() const; }; /** @@ -52,4 +60,5 @@ FramebufferLayout LargeFrameLayout(unsigned width, unsigned height, bool is_swap * @return Newly created FramebufferLayout object with default screen regions initialized */ FramebufferLayout CustomFrameLayout(unsigned width, unsigned height); -} + +} // namespace Layout diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index 456443e86a..8b717e43df 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp @@ -561,20 +561,16 @@ RasterizerCacheOpenGL::GetFramebufferSurfaces( color_params.is_tiled = depth_params.is_tiled = true; // Set the internal resolution, assume the same scaling factor for top and bottom screens - const Layout::FramebufferLayout& layout = VideoCore::g_emu_window->GetFramebufferLayout(); - if (Settings::values.resolution_factor == 0.0f) { + float resolution_scale_factor = Settings::values.resolution_factor; + if (resolution_scale_factor == 0.0f) { // Auto - scale resolution to the window size - color_params.res_scale_width = depth_params.res_scale_width = - (float)layout.top_screen.GetWidth() / VideoCore::kScreenTopWidth; - color_params.res_scale_height = depth_params.res_scale_height = - (float)layout.top_screen.GetHeight() / VideoCore::kScreenTopHeight; - } else { - // Otherwise, scale the resolution by the specified factor - color_params.res_scale_width = Settings::values.resolution_factor; - depth_params.res_scale_width = Settings::values.resolution_factor; - color_params.res_scale_height = Settings::values.resolution_factor; - depth_params.res_scale_height = Settings::values.resolution_factor; + resolution_scale_factor = VideoCore::g_emu_window->GetFramebufferLayout().GetScalingRatio(); } + // Scale the resolution by the specified factor + color_params.res_scale_width = resolution_scale_factor; + depth_params.res_scale_width = resolution_scale_factor; + color_params.res_scale_height = resolution_scale_factor; + depth_params.res_scale_height = resolution_scale_factor; color_params.addr = config.GetColorBufferPhysicalAddress(); color_params.pixel_format = CachedSurface::PixelFormatFromColorFormat(config.color_format); diff --git a/src/video_core/video_core.h b/src/video_core/video_core.h index 4aba19ca04..94e0867f04 100644 --- a/src/video_core/video_core.h +++ b/src/video_core/video_core.h @@ -15,21 +15,6 @@ class RendererBase; namespace VideoCore { -// 3DS Video Constants -// ------------------- - -// NOTE: The LCDs actually rotate the image 90 degrees when displaying. Because of that the -// framebuffers in video memory are stored in column-major order and rendered sideways, causing -// the widths and heights of the framebuffers read by the LCD to be switched compared to the -// heights and widths of the screens listed here. -static const int kScreenTopWidth = 400; ///< 3DS top screen width -static const int kScreenTopHeight = 240; ///< 3DS top screen height -static const int kScreenBottomWidth = 320; ///< 3DS bottom screen width -static const int kScreenBottomHeight = 240; ///< 3DS bottom screen height - -// Video core renderer -// --------------------- - extern std::unique_ptr g_renderer; ///< Renderer plugin extern EmuWindow* g_emu_window; ///< Emu window