kodi
RenderSystemDX.h
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 "DeviceResources.h"
12 #include "rendering/RenderSystem.h"
13 #include "threads/Condition.h"
14 #include "threads/CriticalSection.h"
15 #include "threads/SystemClock.h"
16 #include "utils/ColorUtils.h"
17 
18 #include <wrl/client.h>
19 
20 class ID3DResource;
21 class CGUIShaderDX;
22 enum AVPixelFormat;
23 enum AVPixelFormat;
24 
25 class CRenderSystemDX : public CRenderSystemBase, DX::IDeviceNotify
26 {
27 public:
29  virtual ~CRenderSystemDX();
30 
31  // CRenderBase overrides
32  bool InitRenderSystem() override;
33  bool DestroyRenderSystem() override;
34  bool BeginRender() override;
35  bool EndRender() override;
36  void PresentRender(bool rendered, bool videoLayer) override;
37  bool ClearBuffers(UTILS::COLOR::Color color) override;
38  void SetViewPort(const CRect& viewPort) override;
39  void GetViewPort(CRect& viewPort) override;
40  void RestoreViewPort() override;
41  CRect ClipRectToScissorRect(const CRect &rect) override;
42  bool ScissorsCanEffectClipping() override;
43  void SetScissors(const CRect &rect) override;
44  void ResetScissors() override;
45  void CaptureStateBlock() override;
46  void ApplyStateBlock() override;
47  void SetCameraPosition(const CPoint &camera, int screenWidth, int screenHeight, float stereoFactor = 0.f) override;
48  void SetStereoMode(RENDER_STEREO_MODE mode, RENDER_STEREO_VIEW view) override;
49  bool SupportsStereo(RENDER_STEREO_MODE mode) const override;
50  void Project(float &x, float &y, float &z) override;
51  bool SupportsNPOT(bool dxt) const override;
52 
53  // IDeviceNotify overrides
54  void OnDXDeviceLost() override;
55  void OnDXDeviceRestored() override;
56 
57  // CRenderSystemDX methods
58  CGUIShaderDX* GetGUIShader() const { return m_pGUIShader; }
59  bool IsFormatSupport(DXGI_FORMAT format, unsigned int usage) const;
60  CRect GetBackBufferRect();
61  CD3DTexture& GetBackBuffer();
62 
63  void FlushGPU() const;
64  void RequestDecodingTime();
65  void ReleaseDecodingTime();
66  void SetAlphaBlendEnable(bool enable);
67 
68  // empty overrides
69  bool IsExtSupported(const char* extension) const override { return false; }
70  bool ResetRenderSystem(int width, int height) override { return true; }
71 
72 protected:
73  virtual void PresentRenderImpl(bool rendered) = 0;
74 
75  bool CreateStates();
76  bool InitGUIShader();
77  void OnResize();
78  void CheckInterlacedStereoView(void);
79  void CheckDeviceCaps();
80 
81  CCriticalSection m_resourceSection;
82  CCriticalSection m_decoderSection;
83 
84  // our adapter could change as we go
85  bool m_inScene{ false };
86  bool m_BlendEnabled{ false };
87  bool m_ScissorsEnabled{ false };
88  D3D11_VIEWPORT m_viewPort;
89  CRect m_scissor;
90  CGUIShaderDX* m_pGUIShader{ nullptr };
91  Microsoft::WRL::ComPtr<ID3D11DepthStencilState> m_depthStencilState;
92  Microsoft::WRL::ComPtr<ID3D11BlendState> m_BlendEnableState;
93  Microsoft::WRL::ComPtr<ID3D11BlendState> m_BlendDisableState;
94  Microsoft::WRL::ComPtr<ID3D11RasterizerState> m_RSScissorDisable;
95  Microsoft::WRL::ComPtr<ID3D11RasterizerState> m_RSScissorEnable;
96  // stereo interlaced/checkerboard intermediate target
97  CD3DTexture m_rightEyeTex;
98 
99  XbmcThreads::EndTime<> m_decodingTimer;
100  XbmcThreads::ConditionVariable m_decodingEvent;
101 
102  std::shared_ptr<DX::DeviceResources> m_deviceResources;
103 };
104 
Definition: D3DResource.h:90
bool m_inScene
True if we&#39;re in a BeginScene()/EndScene() block.
Definition: RenderSystemDX.h:85
Definition: SystemClock.h:31
Definition: RenderSystemDX.h:25
void Project(float &x, float &y, float &z) override
Project (x,y,z) 3d scene coordinates to (x,y) 2d screen coordinates.
Definition: RenderSystemDX.cpp:436
Definition: RenderSystem.h:27
Definition: GUIShaderDX.h:36
Definition: D3DResource.h:36
This is a thin wrapper around std::condition_variable_any.
Definition: Condition.h:26