Debian Codegraph @

xbmc/cores/RetroPlayer/guibridge/GUIGameRenderManager.h

raw
1 /*
2 * Copyright (C) 2017-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #pragma once
10
11 #include "cores/GameSettings.h"
12 #include "threads/CriticalSection.h"
13
14 #include <map>
15 #include <memory>
16
17 namespace KODI
18 {
19 namespace GAME
20 {
21 class CDialogGameAdvancedSettings;
22 class CDialogGameVideoSelect;
23 } // namespace GAME
24
25 namespace RETRO
26 {
27 class CGameWindowFullScreen;
28 class CGUIGameControl;
29 class CGUIGameSettingsHandle;
30 class CGUIGameVideoHandle;
31 class CGUIRenderTargetFactory;
32 class CGUIRenderHandle;
33 class CGUIRenderTarget;
34 class IGameCallback;
35 class IRenderCallback;
36 class IPlayback;
37
38 /*!
39 * \brief Class to safely route commands between the GUI and RetroPlayer
40 *
41 * This class is brought up before the GUI and player core factory. It
42 * provides the GUI with safe access to a registered player.
43 *
44 * Access to the player is done through handles. When a handle is no
45 * longer needed, it should be destroyed.
46 *
47 * Three kinds of handles are provided:
48 *
49 * - CGUIRenderHandle
50 * Allows the holder to invoke render events
51 *
52 * - CGUIGameVideoHandle
53 * Allows the holder to query video properties, such as the filter
54 * or view mode.
55 *
56 * - CGUIGameSettingsHandle
57 * Allows the holder to query game properties, such as the ID of the
58 * game client or the game's filename.
59 *
60 * Each manager fulfills the following design requirements:
61 *
62 * 1. No assumption of player lifetimes
63 *
64 * 2. No assumption of GUI element lifetimes, as long as handles are
65 * destroyed before this class is destructed
66 *
67 * 3. No limit on the number of handles
68 */
69 class CGUIGameRenderManager
70 {
71 // Classes that call into the protected interface
72 friend class CGUIGameSettingsHandle;
73 friend class CGUIGameVideoHandle;
74 friend class CGUIRenderHandle;
75
76 public:
77 CGUIGameRenderManager() = default;
78 ~CGUIGameRenderManager();
79
80 /*!
81 * \brief Register a RetroPlayer instance
82 *
83 * \param factory The interface for creating render targets exposed to the GUI
84 * \param callback The interface for querying video properties
85 * \param gameCallback The interface for querying game properties
86 */
87 void RegisterPlayer(CGUIRenderTargetFactory* factory,
88 IRenderCallback* callback,
89 IGameCallback* gameCallback);
90
91 /*!
92 * \brief Unregister a RetroPlayer instance
93 */
94 void UnregisterPlayer();
95
96 /*!
97 * \brief Register a GUI game control ("gamewindow" skin control)
98 *
99 * \param control The game control
100 *
101 * \return A handle to invoke render events
102 */
103 std::shared_ptr<CGUIRenderHandle> RegisterControl(CGUIGameControl& control);
104
105 /*!
106 * \brief Register a fullscreen game window ("FullscreenGame" window)
107 *
108 * \param window The game window
109 *
110 * \return A handle to invoke render events
111 */
112 std::shared_ptr<CGUIRenderHandle> RegisterWindow(CGameWindowFullScreen& window);
113
114 /*!
115 * \brief Register a video select dialog (for selecting video filters,
116 * view modes, etc.)
117 *
118 * \param dialog The video select dialog
119 *
120 * \return A handle to query game and video properties
121 */
122 std::shared_ptr<CGUIGameVideoHandle> RegisterDialog(GAME::CDialogGameVideoSelect& dialog);
123
124 /*!
125 * \brief Register a game settings dialog
126 *
127 * \return A handle to query game properties
128 */
129 std::shared_ptr<CGUIGameSettingsHandle> RegisterGameSettingsDialog();
130
131 protected:
132 // Functions exposed to friend class CGUIRenderHandle
133 void UnregisterHandle(CGUIRenderHandle* handle);
134 void Render(CGUIRenderHandle* handle);
135 void RenderEx(CGUIRenderHandle* handle);
136 void ClearBackground(CGUIRenderHandle* handle);
137 bool IsDirty(CGUIRenderHandle* handle);
138
139 // Functions exposed to friend class CGUIGameVideoHandle
140 void UnregisterHandle(CGUIGameVideoHandle* handle) {}
141 bool IsPlayingGame();
142 bool SupportsRenderFeature(RENDERFEATURE feature);
143 bool SupportsScalingMethod(SCALINGMETHOD method);
144
145 // Functions exposed to CGUIGameSettingsHandle
146 void UnregisterHandle(CGUIGameSettingsHandle* handle) {}
147 std::string GameClientID();
148 std::string GetPlayingGame();
149 std::string CreateSavestate(bool autosave);
150 bool UpdateSavestate(const std::string& savestatePath);
151 bool LoadSavestate(const std::string& savestatePath);
152 void FreeSavestateResources(const std::string& savestatePath);
153 void CloseOSD();
154
155 private:
156 /*!
157 * \brief Helper function to create or destroy render targets when a
158 * factory is registered/unregistered
159 */
160 void UpdateRenderTargets();
161
162 /*!
163 * \brief Helper function to create a render target
164 *
165 * \param handle The handle given to the registered GUI element
166 *
167 * \return A target to receive rendering commands
168 */
169 CGUIRenderTarget* CreateRenderTarget(CGUIRenderHandle* handle);
170
171 // Render events
172 CGUIRenderTargetFactory* m_factory = nullptr;
173 std::map<CGUIRenderHandle*, std::shared_ptr<CGUIRenderTarget>> m_renderTargets;
174 CCriticalSection m_targetMutex;
175
176 // Video properties
177 IRenderCallback* m_callback = nullptr;
178 CCriticalSection m_callbackMutex;
179
180 // Game properties
181 IGameCallback* m_gameCallback = nullptr;
182 CCriticalSection m_gameCallbackMutex;
183 };
184 } // namespace RETRO
185 } // namespace KODI