diff options
Diffstat (limited to 'src/core/frontend/graphics_context.h')
| -rw-r--r-- | src/core/frontend/graphics_context.h | 69 |
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 @@ | |||
| 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 | |||
| 9 | namespace Core::Frontend { | ||
| 10 | |||
| 11 | /** | ||
| 12 | * Represents a drawing context that supports graphics operations. | ||
| 13 | */ | ||
| 14 | class GraphicsContext { | ||
| 15 | public: | ||
| 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 | ||