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 19 #include <memory> 20 #include <vector> 21 22 struct RESOLUTION_WHR 23 { 24 int width; 25 int height; 26 int flags; //< only D3DPRESENTFLAG_MODEMASK flags 27 int ResInfo_Index; 28 }; 29 30 struct REFRESHRATE 31 { 32 float RefreshRate; 33 int ResInfo_Index; 34 }; 35 36 class CDPMSSupport; 37 class CGraphicContext; 38 class CRenderSystemBase; 39 class IRenderLoop; 40 41 struct VideoPicture; 42 43 class CWinSystemBase 44 { 45 public: 46 CWinSystemBase(); 47 virtual ~CWinSystemBase(); 48 49 static std::unique_ptr<CWinSystemBase> CreateWinSystem(); 50 51 // Access render system interface GetRenderSystem()52 virtual CRenderSystemBase *GetRenderSystem() { return nullptr; } 53 GetName()54 virtual const std::string GetName() { return "platform default"; } 55 56 // windowing interfaces 57 virtual bool InitWindowSystem(); 58 virtual bool DestroyWindowSystem(); 59 virtual bool CreateNewWindow(const std::string& name, bool fullScreen, RESOLUTION_INFO& res) = 0; DestroyWindow()60 virtual bool DestroyWindow(){ return false; } 61 virtual bool ResizeWindow(int newWidth, int newHeight, int newLeft, int newTop) = 0; 62 virtual bool SetFullScreen(bool fullScreen, RESOLUTION_INFO& res, bool blankOtherDisplays) = 0; DisplayHardwareScalingEnabled()63 virtual bool DisplayHardwareScalingEnabled() { return false; } UpdateDisplayHardwareScaling(const RESOLUTION_INFO & resInfo)64 virtual void UpdateDisplayHardwareScaling(const RESOLUTION_INFO& resInfo) { } MoveWindow(int topLeft,int topRight)65 virtual bool MoveWindow(int topLeft, int topRight){return false;} FinishModeChange(RESOLUTION res)66 virtual void FinishModeChange(RESOLUTION res){} FinishWindowResize(int newWidth,int newHeight)67 virtual void FinishWindowResize(int newWidth, int newHeight) {ResizeWindow(newWidth, newHeight, -1, -1);} CenterWindow()68 virtual bool CenterWindow(){return false;} IsCreated()69 virtual bool IsCreated(){ return m_bWindowCreated; } NotifyAppFocusChange(bool bGaining)70 virtual void NotifyAppFocusChange(bool bGaining) {} NotifyAppActiveChange(bool bActivated)71 virtual void NotifyAppActiveChange(bool bActivated) {} ShowOSMouse(bool show)72 virtual void ShowOSMouse(bool show) {}; HasCursor()73 virtual bool HasCursor(){ return true; } 74 //some platforms have api for gesture inertial scrolling - default to false and use the InertialScrollingHandler HasInertialGestures()75 virtual bool HasInertialGestures(){ return false; } 76 //does the output expect limited color range (ie 16-235) 77 virtual bool UseLimitedColor(); 78 //the number of presentation buffers 79 virtual int NoOfBuffers(); 80 /** 81 * Get average display latency 82 * 83 * The latency should be measured as the time between finishing the rendering 84 * of a frame, i.e. calling PresentRender, and the rendered content becoming 85 * visible on the screen. 86 * 87 * \return average display latency in seconds, or negative value if unknown 88 */ GetDisplayLatency()89 virtual float GetDisplayLatency() { return -1.0f; } 90 /** 91 * Get time that should be subtracted from the display latency for this frame 92 * in milliseconds 93 * 94 * Contrary to \ref GetDisplayLatency, this value is calculated ad-hoc 95 * for the frame currently being rendered and not a value that is calculated/ 96 * averaged from past frames and their presentation times 97 */ GetFrameLatencyAdjustment()98 virtual float GetFrameLatencyAdjustment() { return 0.0; } 99 Minimize()100 virtual bool Minimize() { return false; } Restore()101 virtual bool Restore() { return false; } Hide()102 virtual bool Hide() { return false; } 103 virtual bool Show(bool raise = true) { return false; } 104 105 // videosync GetVideoSync(void * clock)106 virtual std::unique_ptr<CVideoSync> GetVideoSync(void *clock) { return nullptr; } 107 108 // notifications OnMove(int x,int y)109 virtual void OnMove(int x, int y) {} 110 111 // OS System screensaver 112 /** 113 * Get OS screen saver inhibit implementation if available 114 * 115 * \return OS screen saver implementation that can be used with this windowing system 116 * or nullptr if unsupported. 117 * Lifetime of the returned object will usually end with \ref DestroyWindowSystem, so 118 * do not use any more after calling that. 119 */ 120 KODI::WINDOWING::COSScreenSaverManager* GetOSScreenSaver(); 121 122 // resolution interfaces GetWidth()123 unsigned int GetWidth() { return m_nWidth; } GetHeight()124 unsigned int GetHeight() { return m_nHeight; } CanDoWindowed()125 virtual bool CanDoWindowed() { return true; } IsFullScreen()126 bool IsFullScreen() { return m_bFullScreen; } 127 virtual void UpdateResolutions(); 128 void SetWindowResolution(int width, int height); 129 std::vector<RESOLUTION_WHR> ScreenResolutions(float refreshrate); 130 std::vector<REFRESHRATE> RefreshRates(int width, int height, uint32_t dwFlags); 131 REFRESHRATE DefaultRefreshRate(std::vector<REFRESHRATE> rates); HasCalibration(const RESOLUTION_INFO & resInfo)132 virtual bool HasCalibration(const RESOLUTION_INFO &resInfo) { return true; }; 133 134 // text input interface 135 virtual std::string GetClipboardText(void); 136 137 // Display event callback 138 virtual void Register(IDispResource *resource) = 0; 139 virtual void Unregister(IDispResource *resource) = 0; 140 141 // render loop 142 void RegisterRenderLoop(IRenderLoop *client); 143 void UnregisterRenderLoop(IRenderLoop *client); 144 void DriveRenderLoop(); 145 146 // winsystem events MessagePump()147 virtual bool MessagePump() { return false; } 148 149 // Access render system interface 150 CGraphicContext& GetGfxContext(); 151 152 /** 153 * Get OS specific hardware context 154 * 155 * \return OS specific context or nullptr if OS not have 156 * 157 * \note This function is currently only related to Windows with DirectX, 158 * all other OS where use GL returns nullptr. 159 * Returned Windows class pointer is ID3D11DeviceContext1. 160 */ GetHWContext()161 virtual void* GetHWContext() { return nullptr; } 162 163 std::shared_ptr<CDPMSSupport> GetDPMSManager(); SetHDR(const VideoPicture * videoPicture)164 virtual bool SetHDR(const VideoPicture* videoPicture) { return false; }; IsHDRDisplay()165 virtual bool IsHDRDisplay() { return false; }; ToggleHDR()166 virtual HDR_STATUS ToggleHDR() { return HDR_STATUS::HDR_UNSUPPORTED; }; GetOSHDRStatus()167 virtual HDR_STATUS GetOSHDRStatus() { return HDR_STATUS::HDR_UNSUPPORTED; }; 168 169 static const char* SETTING_WINSYSTEM_IS_HDR_DISPLAY; 170 171 // Gets debug info from video renderer GetDebugInfo()172 virtual DEBUG_INFO_RENDER GetDebugInfo() { return {}; }; 173 174 protected: 175 void UpdateDesktopResolution(RESOLUTION_INFO& newRes, const std::string &output, int width, int height, float refreshRate, uint32_t dwFlags); GetOSScreenSaverImpl()176 virtual std::unique_ptr<KODI::WINDOWING::IOSScreenSaver> GetOSScreenSaverImpl() { return nullptr; } 177 178 int m_nWidth = 0; 179 int m_nHeight = 0; 180 int m_nTop = 0; 181 int m_nLeft = 0; 182 bool m_bWindowCreated = false; 183 bool m_bFullScreen = false; 184 bool m_bBlankOtherDisplay = false; 185 float m_fRefreshRate = 0.0f; 186 std::unique_ptr<KODI::WINDOWING::COSScreenSaverManager> m_screenSaverManager; 187 CCriticalSection m_renderLoopSection; 188 std::vector<IRenderLoop*> m_renderLoopClients; 189 190 std::unique_ptr<IWinEvents> m_winEvents; 191 std::unique_ptr<CGraphicContext> m_gfxContext; 192 std::shared_ptr<CDPMSSupport> m_dpms; 193 }; 194