Debian Codegraph @

xbmc/windowing/WinSystem.h

raw
1 /*
2 * Copyright (C) 2005-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 "HDRStatus.h"
12 #include "OSScreenSaver.h"
13 #include "Resolution.h"
14 #include "VideoSync.h"
15 #include "WinEvents.h"
16 #include "cores/VideoPlayer/VideoRenderers/DebugInfo.h"
17 #include "guilib/DispResource.h"
18 #include "utils/HDRCapabilities.h"
19
20 #include <memory>
21 #include <string>
22 #include <vector>
23
24 struct RESOLUTION_WHR
25 {
26 int width;
27 int height;
28 int m_screenWidth;
29 int m_screenHeight;
30 int flags; //< only D3DPRESENTFLAG_MODEMASK flags
31 int ResInfo_Index;
32 std::string id;
33 };
34
35 struct REFRESHRATE
36 {
37 float RefreshRate;
38 int ResInfo_Index;
39 };
40
41 class CDPMSSupport;
42 class CGraphicContext;
43 class CRenderSystemBase;
44 class IRenderLoop;
45 class CVideoReferenceClock;
46
47 struct VideoPicture;
48
49 class CWinSystemBase
50 {
51 public:
52 CWinSystemBase();
53 virtual ~CWinSystemBase();
54
55 static std::unique_ptr<CWinSystemBase> CreateWinSystem();
56
57 // Access render system interface
58 virtual CRenderSystemBase *GetRenderSystem() { return nullptr; }
59
60 virtual const std::string GetName() { return "platform default"; }
61
62 // windowing interfaces
63 virtual bool InitWindowSystem();
64 virtual bool DestroyWindowSystem();
65 virtual bool CreateNewWindow(const std::string& name, bool fullScreen, RESOLUTION_INFO& res) = 0;
66 virtual bool DestroyWindow(){ return false; }
67 virtual bool ResizeWindow(int newWidth, int newHeight, int newLeft, int newTop) = 0;
68 virtual bool SetFullScreen(bool fullScreen, RESOLUTION_INFO& res, bool blankOtherDisplays) = 0;
69 virtual bool DisplayHardwareScalingEnabled() { return false; }
70 virtual void UpdateDisplayHardwareScaling(const RESOLUTION_INFO& resInfo) { }
71 virtual bool MoveWindow(int topLeft, int topRight){return false;}
72 virtual void FinishModeChange(RESOLUTION res){}
73 virtual void FinishWindowResize(int newWidth, int newHeight) {ResizeWindow(newWidth, newHeight, -1, -1);}
74 virtual bool CenterWindow(){return false;}
75 virtual bool IsCreated(){ return m_bWindowCreated; }
76 virtual void NotifyAppFocusChange(bool bGaining) {}
77 virtual void NotifyAppActiveChange(bool bActivated) {}
78 virtual void ShowOSMouse(bool show) {}
79 virtual bool HasCursor(){ return true; }
80 //some platforms have api for gesture inertial scrolling - default to false and use the InertialScrollingHandler
81 virtual bool HasInertialGestures(){ return false; }
82 //does the output expect limited color range (ie 16-235)
83 virtual bool UseLimitedColor();
84 //the number of presentation buffers
85 virtual int NoOfBuffers();
86
87 /*!
88 * \brief Forces the window to fullscreen provided the window resolution
89 * \param resInfo - the resolution info
90 */
91 virtual void ForceFullScreen(const RESOLUTION_INFO& resInfo) {}
92
93 /*!
94 * \brief Get average display latency
95 *
96 * The latency should be measured as the time between finishing the rendering
97 * of a frame, i.e. calling PresentRender, and the rendered content becoming
98 * visible on the screen.
99 *
100 * \return average display latency in seconds, or negative value if unknown
101 */
102 virtual float GetDisplayLatency() { return -1.0f; }
103
104 /*!
105 * \brief Get time that should be subtracted from the display latency for this frame
106 * in milliseconds
107 *
108 * Contrary to \ref GetDisplayLatency, this value is calculated ad-hoc
109 * for the frame currently being rendered and not a value that is calculated/
110 * averaged from past frames and their presentation times
111 */
112 virtual float GetFrameLatencyAdjustment() { return 0.0; }
113
114 virtual bool Minimize() { return false; }
115 virtual bool Restore() { return false; }
116 virtual bool Hide() { return false; }
117 virtual bool Show(bool raise = true) { return false; }
118
119 // videosync
120 virtual std::unique_ptr<CVideoSync> GetVideoSync(CVideoReferenceClock* clock) { return nullptr; }
121
122 // notifications
123 virtual void OnMove(int x, int y) {}
124
125 /*!
126 * \brief Get the screen ID provided the screen name
127 *
128 * \param screen the name of the screen as presented on the application display settings
129 * \return the screen index as known by the windowing system implementation (or the default screen by default)
130 */
131 virtual unsigned int GetScreenId(const std::string& screen) { return 0; }
132
133 /*!
134 * \brief Window was requested to move to the given screen
135 *
136 * \param screenIdx the screen index as known by the windowing system implementation
137 */
138 virtual void MoveToScreen(unsigned int screenIdx) {}
139
140 /*!
141 * \brief Used to signal the windowing system about the change of the current screen
142 *
143 * \param screenIdx the screen index as known by the windowing system implementation
144 */
145 virtual void OnChangeScreen(unsigned int screenIdx) {}
146
147 // OS System screensaver
148 /*!
149 * \brief Get OS screen saver inhibit implementation if available
150 *
151 * \return OS screen saver implementation that can be used with this windowing system
152 * or nullptr if unsupported.
153 * Lifetime of the returned object will usually end with \ref DestroyWindowSystem, so
154 * do not use any more after calling that.
155 */
156 KODI::WINDOWING::COSScreenSaverManager* GetOSScreenSaver();
157
158 // resolution interfaces
159 unsigned int GetWidth() { return m_nWidth; }
160 unsigned int GetHeight() { return m_nHeight; }
161 virtual bool CanDoWindowed() { return true; }
162 bool IsFullScreen() { return m_bFullScreen; }
163
164 /*!
165 * \brief Check if the windowing system supports moving windows across screens
166 *
167 * \return true if the windowing system supports moving windows across screens, false otherwise
168 */
169 virtual bool SupportsScreenMove() { return true; }
170
171 virtual void UpdateResolutions();
172 void SetWindowResolution(int width, int height);
173 std::vector<RESOLUTION_WHR> ScreenResolutions(float refreshrate);
174 std::vector<REFRESHRATE> RefreshRates(int width, int height, uint32_t dwFlags);
175 REFRESHRATE DefaultRefreshRate(const std::vector<REFRESHRATE>& rates);
176 virtual bool HasCalibration(const RESOLUTION_INFO& resInfo) { return true; }
177
178 // text input interface
179 virtual std::string GetClipboardText(void);
180
181 // Display event callback
182 virtual void Register(IDispResource *resource) = 0;
183 virtual void Unregister(IDispResource *resource) = 0;
184
185 // render loop
186 void RegisterRenderLoop(IRenderLoop *client);
187 void UnregisterRenderLoop(IRenderLoop *client);
188 void DriveRenderLoop();
189
190 // winsystem events
191 virtual bool MessagePump() { return false; }
192
193 // Access render system interface
194 virtual CGraphicContext& GetGfxContext() const;
195
196 /*!
197 * \brief Get OS specific hardware context
198 *
199 * \return OS specific context or nullptr if OS not have
200 *
201 * \note This function is currently only related to Windows with DirectX,
202 * all other OS where use GL returns nullptr.
203 * Returned Windows class pointer is ID3D11DeviceContext1.
204 */
205 virtual void* GetHWContext() { return nullptr; }
206
207 std::shared_ptr<CDPMSSupport> GetDPMSManager();
208
209 /*!
210 * \brief Set the HDR metadata. Passing nullptr as the parameter should
211 * disable HDR.
212 *
213 */
214 virtual bool SetHDR(const VideoPicture* videoPicture) { return false; }
215 virtual bool IsHDRDisplay() { return false; }
216 virtual HDR_STATUS ToggleHDR() { return HDR_STATUS::HDR_UNSUPPORTED; }
217 virtual HDR_STATUS GetOSHDRStatus() { return HDR_STATUS::HDR_UNSUPPORTED; }
218 virtual CHDRCapabilities GetDisplayHDRCapabilities() const { return {}; }
219 static const char* SETTING_WINSYSTEM_IS_HDR_DISPLAY;
220 virtual float GetGuiSdrPeakLuminance() const { return .0f; }
221 virtual bool HasSystemSdrPeakLuminance() { return false; }
222
223 /*!
224 * \brief System supports Video Super Resolution HW upscaler i.e.:
225 * "NVIDIA RTX Video Super Resolution" or "Intel Video Super Resolution"
226 *
227 */
228 virtual bool SupportsVideoSuperResolution() { return false; }
229
230 /*!
231 * \brief Gets debug info from video renderer for use in "Debug Info OSD" (Alt + O)
232 *
233 */
234 virtual DEBUG_INFO_RENDER GetDebugInfo() { return {}; }
235
236 virtual std::vector<std::string> GetConnectedOutputs() { return {}; }
237
238 /*!
239 * \brief Return true when HDR display is available and enabled in settings
240 *
241 */
242 bool IsHDRDisplaySettingEnabled();
243
244 /*!
245 * \brief Return true when "Video Super Resolution" is supported and enabled in settings
246 *
247 */
248 bool IsVideoSuperResolutionSettingEnabled();
249
250 /*!
251 * \brief Return true when setting "High Precision Processing" is enabled
252 *
253 */
254 bool IsHighPrecisionProcessingSettingEnabled();
255
256 /*!
257 * \brief Get dither settings
258 *
259 * \return std::pair containing dither enabled (bool) and dither depth (int)
260 */
261 std::pair<bool, int> GetDitherSettings();
262
263 protected:
264 void UpdateDesktopResolution(RESOLUTION_INFO& newRes, const std::string &output, int width, int height, float refreshRate, uint32_t dwFlags);
265 void UpdateDesktopResolution(RESOLUTION_INFO& newRes,
266 const std::string& output,
267 int width,
268 int height,
269 int screenWidth,
270 int screenHeight,
271 float refreshRate,
272 uint32_t dwFlags);
273 virtual std::unique_ptr<KODI::WINDOWING::IOSScreenSaver> GetOSScreenSaverImpl() { return nullptr; }
274
275 int m_nWidth = 0;
276 int m_nHeight = 0;
277 int m_nTop = 0;
278 int m_nLeft = 0;
279 bool m_bWindowCreated = false;
280 bool m_bFullScreen = false;
281 bool m_bBlankOtherDisplay = false;
282 float m_fRefreshRate = 0.0f;
283 std::unique_ptr<KODI::WINDOWING::COSScreenSaverManager> m_screenSaverManager;
284 CCriticalSection m_renderLoopSection;
285 std::vector<IRenderLoop*> m_renderLoopClients;
286
287 std::unique_ptr<IWinEvents> m_winEvents;
288 std::unique_ptr<CGraphicContext> m_gfxContext;
289 std::shared_ptr<CDPMSSupport> m_dpms;
290 };