diff options
author | bunnei <bunneidev@gmail.com> | 2023-06-06 06:43:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-06 06:43:43 +0200 |
commit | cb95d7fe1b6d81899fe6b279400da2c991e3132c (patch) | |
tree | a856ac45b1053009c4c11ee141c49d7faa4c8a19 /src/core/frontend/graphics_context.h | |
parent | Merge pull request #10611 from liamwhite/audio-deadlock (diff) | |
parent | Merge pull request #10633 from t895/variable-surface-ratio (diff) | |
download | yuzu-cb95d7fe1b6d81899fe6b279400da2c991e3132c.tar yuzu-cb95d7fe1b6d81899fe6b279400da2c991e3132c.tar.gz yuzu-cb95d7fe1b6d81899fe6b279400da2c991e3132c.tar.bz2 yuzu-cb95d7fe1b6d81899fe6b279400da2c991e3132c.tar.lz yuzu-cb95d7fe1b6d81899fe6b279400da2c991e3132c.tar.xz yuzu-cb95d7fe1b6d81899fe6b279400da2c991e3132c.tar.zst yuzu-cb95d7fe1b6d81899fe6b279400da2c991e3132c.zip |
Diffstat (limited to 'src/core/frontend/graphics_context.h')
-rw-r--r-- | src/core/frontend/graphics_context.h | 62 |
1 files changed, 62 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..7554c1583 --- /dev/null +++ b/src/core/frontend/graphics_context.h @@ -0,0 +1,62 @@ +// SPDX-FileCopyrightText: 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include <memory> + +#include "common/dynamic_library.h" + +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() {} + + /// Gets the GPU driver library (used by Android only) + virtual std::shared_ptr<Common::DynamicLibrary> GetDriverLibrary() { + 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 |