summaryrefslogtreecommitdiffstats
path: root/src/core/frontend/graphics_context.h
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2023-02-19 08:31:39 +0100
committerbunnei <bunneidev@gmail.com>2023-06-03 09:05:31 +0200
commitae099d583cf93175fe54359ea2b7c5b665398c8b (patch)
treeaa9d91cdf741cc159fa2aba7a0c00f1efbf69eb3 /src/core/frontend/graphics_context.h
parentcommon: dynamic_library: Add ctor for existing handle. (diff)
downloadyuzu-ae099d583cf93175fe54359ea2b7c5b665398c8b.tar
yuzu-ae099d583cf93175fe54359ea2b7c5b665398c8b.tar.gz
yuzu-ae099d583cf93175fe54359ea2b7c5b665398c8b.tar.bz2
yuzu-ae099d583cf93175fe54359ea2b7c5b665398c8b.tar.lz
yuzu-ae099d583cf93175fe54359ea2b7c5b665398c8b.tar.xz
yuzu-ae099d583cf93175fe54359ea2b7c5b665398c8b.tar.zst
yuzu-ae099d583cf93175fe54359ea2b7c5b665398c8b.zip
Diffstat (limited to '')
-rw-r--r--src/core/frontend/graphics_context.h69
1 files changed, 69 insertions, 0 deletions
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 @@
+// 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::Frontend