summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bunnei2023-02-18 23:31:39 -0800
committerGravatar bunnei2023-06-03 00:05:31 -0700
commitae099d583cf93175fe54359ea2b7c5b665398c8b (patch)
treeaa9d91cdf741cc159fa2aba7a0c00f1efbf69eb3
parentcommon: dynamic_library: Add ctor for existing handle. (diff)
downloadyuzu-ae099d583cf93175fe54359ea2b7c5b665398c8b.tar.gz
yuzu-ae099d583cf93175fe54359ea2b7c5b665398c8b.tar.xz
yuzu-ae099d583cf93175fe54359ea2b7c5b665398c8b.zip
core: frontend: Refactor GraphicsContext to its own module.
-rw-r--r--src/core/CMakeLists.txt1
-rw-r--r--src/core/frontend/emu_window.cpp2
-rw-r--r--src/core/frontend/emu_window.h48
-rw-r--r--src/core/frontend/graphics_context.h69
-rw-r--r--src/video_core/gpu.cpp1
-rw-r--r--src/video_core/gpu_thread.cpp2
-rw-r--r--src/video_core/renderer_base.cpp1
-rw-r--r--src/video_core/renderer_base.h2
-rw-r--r--src/video_core/renderer_null/renderer_null.cpp2
-rw-r--r--src/video_core/renderer_opengl/gl_shader_context.h1
-rw-r--r--src/video_core/renderer_vulkan/renderer_vulkan.cpp2
-rw-r--r--src/yuzu/bootmanager.cpp1
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2.h2
13 files changed, 84 insertions, 50 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 45328158f..157858c82 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -140,6 +140,7 @@ add_library(core STATIC
140 frontend/emu_window.h 140 frontend/emu_window.h
141 frontend/framebuffer_layout.cpp 141 frontend/framebuffer_layout.cpp
142 frontend/framebuffer_layout.h 142 frontend/framebuffer_layout.h
143 frontend/graphics_context.h
143 hid/emulated_console.cpp 144 hid/emulated_console.cpp
144 hid/emulated_console.h 145 hid/emulated_console.h
145 hid/emulated_controller.cpp 146 hid/emulated_controller.cpp
diff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cpp
index 1be2dccb0..d1f1ca8c9 100644
--- a/src/core/frontend/emu_window.cpp
+++ b/src/core/frontend/emu_window.cpp
@@ -6,8 +6,6 @@
6 6
7namespace Core::Frontend { 7namespace Core::Frontend {
8 8
9GraphicsContext::~GraphicsContext() = default;
10
11EmuWindow::EmuWindow() { 9EmuWindow::EmuWindow() {
12 // TODO: Find a better place to set this. 10 // TODO: Find a better place to set this.
13 config.min_client_area_size = 11 config.min_client_area_size =
diff --git a/src/core/frontend/emu_window.h b/src/core/frontend/emu_window.h
index 1093800f6..a72df034e 100644
--- a/src/core/frontend/emu_window.h
+++ b/src/core/frontend/emu_window.h
@@ -5,11 +5,14 @@
5 5
6#include <memory> 6#include <memory>
7#include <utility> 7#include <utility>
8
8#include "common/common_types.h" 9#include "common/common_types.h"
9#include "core/frontend/framebuffer_layout.h" 10#include "core/frontend/framebuffer_layout.h"
10 11
11namespace Core::Frontend { 12namespace Core::Frontend {
12 13
14class GraphicsContext;
15
13/// Information for the Graphics Backends signifying what type of screen pointer is in 16/// Information for the Graphics Backends signifying what type of screen pointer is in
14/// WindowInformation 17/// WindowInformation
15enum class WindowSystemType { 18enum class WindowSystemType {
@@ -22,51 +25,6 @@ enum class WindowSystemType {
22}; 25};
23 26
24/** 27/**
25 * Represents a drawing context that supports graphics operations.
26 */
27class GraphicsContext {
28public:
29 virtual ~GraphicsContext();
30
31 /// Inform the driver to swap the front/back buffers and present the current image
32 virtual void SwapBuffers() {}
33
34 /// Makes the graphics context current for the caller thread
35 virtual void MakeCurrent() {}
36
37 /// Releases (dunno if this is the "right" word) the context from the caller thread
38 virtual void DoneCurrent() {}
39
40 class Scoped {
41 public:
42 [[nodiscard]] explicit Scoped(GraphicsContext& context_) : context(context_) {
43 context.MakeCurrent();
44 }
45 ~Scoped() {
46 if (active) {
47 context.DoneCurrent();
48 }
49 }
50
51 /// In the event that context was destroyed before the Scoped is destroyed, this provides a
52 /// mechanism to prevent calling a destroyed object's method during the deconstructor
53 void Cancel() {
54 active = false;
55 }
56
57 private:
58 GraphicsContext& context;
59 bool active{true};
60 };
61
62 /// Calls MakeCurrent on the context and calls DoneCurrent when the scope for the returned value
63 /// ends
64 [[nodiscard]] Scoped Acquire() {
65 return Scoped{*this};
66 }
67};
68
69/**
70 * Abstraction class used to provide an interface between emulation code and the frontend 28 * Abstraction class used to provide an interface between emulation code and the frontend
71 * (e.g. SDL, QGLWidget, GLFW, etc...). 29 * (e.g. SDL, QGLWidget, GLFW, etc...).
72 * 30 *
diff --git a/src/core/frontend/graphics_context.h b/src/core/frontend/graphics_context.h
new file mode 100644
index 000000000..064b19a96
--- /dev/null
+++ b/src/core/frontend/graphics_context.h
@@ -0,0 +1,69 @@
1// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include <optional>
7#include <string>
8
9namespace Core::Frontend {
10
11/**
12 * Represents a drawing context that supports graphics operations.
13 */
14class GraphicsContext {
15public:
16 virtual ~GraphicsContext() = default;
17
18 /// Inform the driver to swap the front/back buffers and present the current image
19 virtual void SwapBuffers() {}
20
21 /// Makes the graphics context current for the caller thread
22 virtual void MakeCurrent() {}
23
24 /// Releases (dunno if this is the "right" word) the context from the caller thread
25 virtual void DoneCurrent() {}
26
27 /// Parameters used to configure custom drivers (used by Android only)
28 struct CustomDriverParameters {
29 std::string hook_lib_dir;
30 std::string custom_driver_dir;
31 std::string custom_driver_name;
32 std::string file_redirect_dir;
33 };
34
35 /// Gets custom driver parameters configured by the frontend (used by Android only)
36 virtual std::optional<CustomDriverParameters> GetCustomDriverParameters() {
37 return {};
38 }
39
40 class Scoped {
41 public:
42 [[nodiscard]] explicit Scoped(GraphicsContext& context_) : context(context_) {
43 context.MakeCurrent();
44 }
45 ~Scoped() {
46 if (active) {
47 context.DoneCurrent();
48 }
49 }
50
51 /// In the event that context was destroyed before the Scoped is destroyed, this provides a
52 /// mechanism to prevent calling a destroyed object's method during the deconstructor
53 void Cancel() {
54 active = false;
55 }
56
57 private:
58 GraphicsContext& context;
59 bool active{true};
60 };
61
62 /// Calls MakeCurrent on the context and calls DoneCurrent when the scope for the returned value
63 /// ends
64 [[nodiscard]] Scoped Acquire() {
65 return Scoped{*this};
66 }
67};
68
69} // namespace Core::Frontend
diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp
index 295a416a8..456f733cf 100644
--- a/src/video_core/gpu.cpp
+++ b/src/video_core/gpu.cpp
@@ -14,6 +14,7 @@
14#include "core/core.h" 14#include "core/core.h"
15#include "core/core_timing.h" 15#include "core/core_timing.h"
16#include "core/frontend/emu_window.h" 16#include "core/frontend/emu_window.h"
17#include "core/frontend/graphics_context.h"
17#include "core/hle/service/nvdrv/nvdata.h" 18#include "core/hle/service/nvdrv/nvdata.h"
18#include "core/perf_stats.h" 19#include "core/perf_stats.h"
19#include "video_core/cdma_pusher.h" 20#include "video_core/cdma_pusher.h"
diff --git a/src/video_core/gpu_thread.cpp b/src/video_core/gpu_thread.cpp
index 3c5317777..889144f38 100644
--- a/src/video_core/gpu_thread.cpp
+++ b/src/video_core/gpu_thread.cpp
@@ -7,7 +7,7 @@
7#include "common/settings.h" 7#include "common/settings.h"
8#include "common/thread.h" 8#include "common/thread.h"
9#include "core/core.h" 9#include "core/core.h"
10#include "core/frontend/emu_window.h" 10#include "core/frontend/graphics_context.h"
11#include "video_core/control/scheduler.h" 11#include "video_core/control/scheduler.h"
12#include "video_core/dma_pusher.h" 12#include "video_core/dma_pusher.h"
13#include "video_core/gpu.h" 13#include "video_core/gpu.h"
diff --git a/src/video_core/renderer_base.cpp b/src/video_core/renderer_base.cpp
index e8761a747..2d3f58201 100644
--- a/src/video_core/renderer_base.cpp
+++ b/src/video_core/renderer_base.cpp
@@ -5,6 +5,7 @@
5 5
6#include "common/logging/log.h" 6#include "common/logging/log.h"
7#include "core/frontend/emu_window.h" 7#include "core/frontend/emu_window.h"
8#include "core/frontend/graphics_context.h"
8#include "video_core/renderer_base.h" 9#include "video_core/renderer_base.h"
9 10
10namespace VideoCore { 11namespace VideoCore {
diff --git a/src/video_core/renderer_base.h b/src/video_core/renderer_base.h
index 8d20cbece..78ea5208b 100644
--- a/src/video_core/renderer_base.h
+++ b/src/video_core/renderer_base.h
@@ -9,7 +9,7 @@
9 9
10#include "common/common_funcs.h" 10#include "common/common_funcs.h"
11#include "common/common_types.h" 11#include "common/common_types.h"
12#include "core/frontend/emu_window.h" 12#include "core/frontend/framebuffer_layout.h"
13#include "video_core/gpu.h" 13#include "video_core/gpu.h"
14#include "video_core/rasterizer_interface.h" 14#include "video_core/rasterizer_interface.h"
15 15
diff --git a/src/video_core/renderer_null/renderer_null.cpp b/src/video_core/renderer_null/renderer_null.cpp
index e2a189b63..be92cc2f4 100644
--- a/src/video_core/renderer_null/renderer_null.cpp
+++ b/src/video_core/renderer_null/renderer_null.cpp
@@ -1,6 +1,8 @@
1// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project 1// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include "core/frontend/emu_window.h"
5#include "core/frontend/graphics_context.h"
4#include "video_core/renderer_null/renderer_null.h" 6#include "video_core/renderer_null/renderer_null.h"
5 7
6namespace Null { 8namespace Null {
diff --git a/src/video_core/renderer_opengl/gl_shader_context.h b/src/video_core/renderer_opengl/gl_shader_context.h
index ca2bd8e8e..207a75d42 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 @@
4#pragma once 4#pragma once
5 5
6#include "core/frontend/emu_window.h" 6#include "core/frontend/emu_window.h"
7#include "core/frontend/graphics_context.h"
7#include "shader_recompiler/frontend/ir/basic_block.h" 8#include "shader_recompiler/frontend/ir/basic_block.h"
8#include "shader_recompiler/frontend/maxwell/control_flow.h" 9#include "shader_recompiler/frontend/maxwell/control_flow.h"
9 10
diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.cpp b/src/video_core/renderer_vulkan/renderer_vulkan.cpp
index 8e31eba34..fbcf4c1d3 100644
--- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp
+++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp
@@ -16,7 +16,7 @@
16#include "common/settings.h" 16#include "common/settings.h"
17#include "common/telemetry.h" 17#include "common/telemetry.h"
18#include "core/core_timing.h" 18#include "core/core_timing.h"
19#include "core/frontend/emu_window.h" 19#include "core/frontend/graphics_context.h"
20#include "core/telemetry_session.h" 20#include "core/telemetry_session.h"
21#include "video_core/gpu.h" 21#include "video_core/gpu.h"
22#include "video_core/renderer_vulkan/renderer_vulkan.h" 22#include "video_core/renderer_vulkan/renderer_vulkan.h"
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp
index 59d226113..cc6b6a25a 100644
--- a/src/yuzu/bootmanager.cpp
+++ b/src/yuzu/bootmanager.cpp
@@ -46,6 +46,7 @@
46#include "core/core.h" 46#include "core/core.h"
47#include "core/cpu_manager.h" 47#include "core/cpu_manager.h"
48#include "core/frontend/framebuffer_layout.h" 48#include "core/frontend/framebuffer_layout.h"
49#include "core/frontend/graphics_context.h"
49#include "input_common/drivers/camera.h" 50#include "input_common/drivers/camera.h"
50#include "input_common/drivers/keyboard.h" 51#include "input_common/drivers/keyboard.h"
51#include "input_common/drivers/mouse.h" 52#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.h
index d9b453dee..4ad05e0e1 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 @@
4#pragma once 4#pragma once
5 5
6#include <utility> 6#include <utility>
7
7#include "core/frontend/emu_window.h" 8#include "core/frontend/emu_window.h"
9#include "core/frontend/graphics_context.h"
8 10
9struct SDL_Window; 11struct SDL_Window;
10 12