VERY experimental Nintendo Switch 2 emulator
C++
core: frontend: Refactor GraphicsContext to its own module.
bunnei56600190e4dc
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txtindex 45328158f6..157858c82c 100644--- a/src/core/CMakeLists.txt+++ b/src/core/CMakeLists.txt@@ -140,6 +140,7 @@ add_library(core STATICfrontend/emu_window.hfrontend/framebuffer_layout.cppfrontend/framebuffer_layout.h+ frontend/graphics_context.hhid/emulated_console.cpphid/emulated_console.hhid/emulated_controller.cppdiff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cppindex 1be2dccb0b..d1f1ca8c97 100644--- a/src/core/frontend/emu_window.cpp+++ b/src/core/frontend/emu_window.cpp@@ -6,8 +6,6 @@namespace Core::Frontend {-GraphicsContext::~GraphicsContext() = default;-EmuWindow::EmuWindow() {// TODO: Find a better place to set this.config.min_client_area_size =diff --git a/src/core/frontend/emu_window.h b/src/core/frontend/emu_window.hindex 1093800f61..a72df034e4 100644--- a/src/core/frontend/emu_window.h+++ b/src/core/frontend/emu_window.h@@ -5,11 +5,14 @@#include <memory>#include <utility>+#include "common/common_types.h"#include "core/frontend/framebuffer_layout.h"namespace Core::Frontend {+class GraphicsContext;+/// Information for the Graphics Backends signifying what type of screen pointer is in/// WindowInformationenum class WindowSystemType {@@ -21,51 +24,6 @@ enum class WindowSystemType {Android,};-/**- * Represents a drawing context that supports graphics operations.- */-class GraphicsContext {-public:- virtual ~GraphicsContext();-- /// Inform the driver to swap the front/back buffers and present the current image- virtual void SwapBuffers() {}-- /// Makes the graphics context current for the caller thread- virtual void MakeCurrent() {}-- /// Releases (dunno if this is the "right" word) the context from the caller thread- virtual void DoneCurrent() {}-- class Scoped {- public:- [[nodiscard]] explicit Scoped(GraphicsContext& context_) : context(context_) {- context.MakeCurrent();- }- ~Scoped() {- if (active) {- context.DoneCurrent();- }- }-- /// In the event that context was destroyed before the Scoped is destroyed, this provides a- /// mechanism to prevent calling a destroyed object's method during the deconstructor- void Cancel() {- active = false;- }-- private:- GraphicsContext& context;- bool active{true};- };-- /// Calls MakeCurrent on the context and calls DoneCurrent when the scope for the returned value- /// ends- [[nodiscard]] Scoped Acquire() {- return Scoped{*this};- }-};-/*** Abstraction class used to provide an interface between emulation code and the frontend* (e.g. SDL, QGLWidget, GLFW, etc...).diff --git a/src/core/frontend/graphics_context.h b/src/core/frontend/graphics_context.hnew file mode 100644index 0000000000..064b19a965--- /dev/null+++ b/src/core/frontend/graphics_context.h@@ -0,0 +1,69 @@+// SPDX-FileCopyrightText: 2023 yuzu Emulator Project+// SPDX-License-Identifier: GPL-2.0-or-later++#pragma once++#include <optional>+#include <string>++namespace Core::Frontend {++/**+ * Represents a drawing context that supports graphics operations.+ */+class GraphicsContext {+public:+ virtual ~GraphicsContext() = default;++ /// Inform the driver to swap the front/back buffers and present the current image+ virtual void SwapBuffers() {}++ /// Makes the graphics context current for the caller thread+ virtual void MakeCurrent() {}++ /// Releases (dunno if this is the "right" word) the context from the caller thread+ virtual void DoneCurrent() {}++ /// Parameters used to configure custom drivers (used by Android only)+ struct CustomDriverParameters {+ std::string hook_lib_dir;+ std::string custom_driver_dir;+ std::string custom_driver_name;+ std::string file_redirect_dir;+ };++ /// Gets custom driver parameters configured by the frontend (used by Android only)+ virtual std::optional<CustomDriverParameters> GetCustomDriverParameters() {+ return {};+ }++ class Scoped {+ public:+ [[nodiscard]] explicit Scoped(GraphicsContext& context_) : context(context_) {+ context.MakeCurrent();+ }+ ~Scoped() {+ if (active) {+ context.DoneCurrent();+ }+ }++ /// In the event that context was destroyed before the Scoped is destroyed, this provides a+ /// mechanism to prevent calling a destroyed object's method during the deconstructor+ void Cancel() {+ active = false;+ }++ private:+ GraphicsContext& context;+ bool active{true};+ };++ /// Calls MakeCurrent on the context and calls DoneCurrent when the scope for the returned value+ /// ends+ [[nodiscard]] Scoped Acquire() {+ return Scoped{*this};+ }+};++} // namespace Core::Frontenddiff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cppindex 295a416a85..456f733cf3 100644--- a/src/video_core/gpu.cpp+++ b/src/video_core/gpu.cpp@@ -14,6 +14,7 @@#include "core/core.h"#include "core/core_timing.h"#include "core/frontend/emu_window.h"+#include "core/frontend/graphics_context.h"#include "core/hle/service/nvdrv/nvdata.h"#include "core/perf_stats.h"#include "video_core/cdma_pusher.h"diff --git a/src/video_core/gpu_thread.cpp b/src/video_core/gpu_thread.cppindex 3c5317777f..889144f382 100644--- a/src/video_core/gpu_thread.cpp+++ b/src/video_core/gpu_thread.cpp@@ -7,7 +7,7 @@#include "common/settings.h"#include "common/thread.h"#include "core/core.h"-#include "core/frontend/emu_window.h"+#include "core/frontend/graphics_context.h"#include "video_core/control/scheduler.h"#include "video_core/dma_pusher.h"#include "video_core/gpu.h"diff --git a/src/video_core/renderer_base.cpp b/src/video_core/renderer_base.cppindex e8761a747b..2d3f582011 100644--- a/src/video_core/renderer_base.cpp+++ b/src/video_core/renderer_base.cpp@@ -5,6 +5,7 @@#include "common/logging/log.h"#include "core/frontend/emu_window.h"+#include "core/frontend/graphics_context.h"#include "video_core/renderer_base.h"namespace VideoCore {diff --git a/src/video_core/renderer_base.h b/src/video_core/renderer_base.hindex 8d20cbece4..78ea5208b9 100644--- a/src/video_core/renderer_base.h+++ b/src/video_core/renderer_base.h@@ -9,7 +9,7 @@#include "common/common_funcs.h"#include "common/common_types.h"-#include "core/frontend/emu_window.h"+#include "core/frontend/framebuffer_layout.h"#include "video_core/gpu.h"#include "video_core/rasterizer_interface.h"diff --git a/src/video_core/renderer_null/renderer_null.cpp b/src/video_core/renderer_null/renderer_null.cppindex e2a189b63b..be92cc2f44 100644--- a/src/video_core/renderer_null/renderer_null.cpp+++ b/src/video_core/renderer_null/renderer_null.cpp@@ -1,6 +1,8 @@// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project// SPDX-License-Identifier: GPL-2.0-or-later+#include "core/frontend/emu_window.h"+#include "core/frontend/graphics_context.h"#include "video_core/renderer_null/renderer_null.h"namespace Null {diff --git a/src/video_core/renderer_opengl/gl_shader_context.h b/src/video_core/renderer_opengl/gl_shader_context.hindex ca2bd8e8e5..207a75d42d 100644--- a/src/video_core/renderer_opengl/gl_shader_context.h+++ b/src/video_core/renderer_opengl/gl_shader_context.h@@ -4,6 +4,7 @@#pragma once#include "core/frontend/emu_window.h"+#include "core/frontend/graphics_context.h"#include "shader_recompiler/frontend/ir/basic_block.h"#include "shader_recompiler/frontend/maxwell/control_flow.h"diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.cpp b/src/video_core/renderer_vulkan/renderer_vulkan.cppindex 8e31eba34a..fbcf4c1d36 100644--- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp+++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp@@ -16,7 +16,7 @@#include "common/settings.h"#include "common/telemetry.h"#include "core/core_timing.h"-#include "core/frontend/emu_window.h"+#include "core/frontend/graphics_context.h"#include "core/telemetry_session.h"#include "video_core/gpu.h"#include "video_core/renderer_vulkan/renderer_vulkan.h"diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cppindex 59d226113c..cc6b6a25ab 100644--- a/src/yuzu/bootmanager.cpp+++ b/src/yuzu/bootmanager.cpp@@ -46,6 +46,7 @@#include "core/core.h"#include "core/cpu_manager.h"#include "core/frontend/framebuffer_layout.h"+#include "core/frontend/graphics_context.h"#include "input_common/drivers/camera.h"#include "input_common/drivers/keyboard.h"#include "input_common/drivers/mouse.h"diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.h b/src/yuzu_cmd/emu_window/emu_window_sdl2.hindex d9b453dee2..4ad05e0e16 100644--- a/src/yuzu_cmd/emu_window/emu_window_sdl2.h+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.h@@ -4,7 +4,9 @@#pragma once#include <utility>+#include "core/frontend/emu_window.h"+#include "core/frontend/graphics_context.h"struct SDL_Window;