diff options
Diffstat (limited to 'src/core/frontend/emu_window.h')
| -rw-r--r-- | src/core/frontend/emu_window.h | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/src/core/frontend/emu_window.h b/src/core/frontend/emu_window.h index 5eb87fb63..bb283d844 100644 --- a/src/core/frontend/emu_window.h +++ b/src/core/frontend/emu_window.h | |||
| @@ -13,19 +13,39 @@ | |||
| 13 | namespace Core::Frontend { | 13 | namespace Core::Frontend { |
| 14 | 14 | ||
| 15 | /** | 15 | /** |
| 16 | * Represents a graphics context that can be used for background computation or drawing. If the | 16 | * Represents a drawing context that supports graphics operations. |
| 17 | * graphics backend doesn't require the context, then the implementation of these methods can be | ||
| 18 | * stubs | ||
| 19 | */ | 17 | */ |
| 20 | class GraphicsContext { | 18 | class GraphicsContext { |
| 21 | public: | 19 | public: |
| 22 | virtual ~GraphicsContext(); | 20 | virtual ~GraphicsContext(); |
| 23 | 21 | ||
| 22 | /// Inform the driver to swap the front/back buffers and present the current image | ||
| 23 | virtual void SwapBuffers() {} | ||
| 24 | |||
| 24 | /// Makes the graphics context current for the caller thread | 25 | /// Makes the graphics context current for the caller thread |
| 25 | virtual void MakeCurrent() = 0; | 26 | virtual void MakeCurrent() {} |
| 26 | 27 | ||
| 27 | /// Releases (dunno if this is the "right" word) the context from the caller thread | 28 | /// Releases (dunno if this is the "right" word) the context from the caller thread |
| 28 | virtual void DoneCurrent() = 0; | 29 | virtual void DoneCurrent() {} |
| 30 | |||
| 31 | class Scoped { | ||
| 32 | public: | ||
| 33 | Scoped(GraphicsContext& context_) : context(context_) { | ||
| 34 | context.MakeCurrent(); | ||
| 35 | } | ||
| 36 | ~Scoped() { | ||
| 37 | context.DoneCurrent(); | ||
| 38 | } | ||
| 39 | |||
| 40 | private: | ||
| 41 | GraphicsContext& context; | ||
| 42 | }; | ||
| 43 | |||
| 44 | /// Calls MakeCurrent on the context and calls DoneCurrent when the scope for the returned value | ||
| 45 | /// ends | ||
| 46 | Scoped Acquire() { | ||
| 47 | return Scoped{*this}; | ||
| 48 | } | ||
| 29 | }; | 49 | }; |
| 30 | 50 | ||
| 31 | /** | 51 | /** |
| @@ -46,7 +66,7 @@ public: | |||
| 46 | * - DO NOT TREAT THIS CLASS AS A GUI TOOLKIT ABSTRACTION LAYER. That's not what it is. Please | 66 | * - DO NOT TREAT THIS CLASS AS A GUI TOOLKIT ABSTRACTION LAYER. That's not what it is. Please |
| 47 | * re-read the upper points again and think about it if you don't see this. | 67 | * re-read the upper points again and think about it if you don't see this. |
| 48 | */ | 68 | */ |
| 49 | class EmuWindow : public GraphicsContext { | 69 | class EmuWindow { |
| 50 | public: | 70 | public: |
| 51 | /// Data structure to store emuwindow configuration | 71 | /// Data structure to store emuwindow configuration |
| 52 | struct WindowConfig { | 72 | struct WindowConfig { |
| @@ -60,17 +80,9 @@ public: | |||
| 60 | virtual void PollEvents() = 0; | 80 | virtual void PollEvents() = 0; |
| 61 | 81 | ||
| 62 | /** | 82 | /** |
| 63 | * Returns a GraphicsContext that the frontend provides that is shared with the emu window. This | 83 | * Returns a GraphicsContext that the frontend provides to be used for rendering. |
| 64 | * context can be used from other threads for background graphics computation. If the frontend | ||
| 65 | * is using a graphics backend that doesn't need anything specific to run on a different thread, | ||
| 66 | * then it can use a stubbed implemenation for GraphicsContext. | ||
| 67 | * | ||
| 68 | * If the return value is null, then the core should assume that the frontend cannot provide a | ||
| 69 | * Shared Context | ||
| 70 | */ | 84 | */ |
| 71 | virtual std::unique_ptr<GraphicsContext> CreateSharedContext() const { | 85 | virtual std::unique_ptr<GraphicsContext> CreateSharedContext() const = 0; |
| 72 | return nullptr; | ||
| 73 | } | ||
| 74 | 86 | ||
| 75 | /// Returns if window is shown (not minimized) | 87 | /// Returns if window is shown (not minimized) |
| 76 | virtual bool IsShown() const = 0; | 88 | virtual bool IsShown() const = 0; |