xbmc
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 Interlaced() const { return m_interlaced; }
60  bool IsFormatSupport(DXGI_FORMAT format, unsigned int usage) const;
61  CRect GetBackBufferRect();
62  CD3DTexture& GetBackBuffer();
63 
64  void FlushGPU() const;
65  void RequestDecodingTime();
66  void ReleaseDecodingTime();
67  void SetAlphaBlendEnable(bool enable);
68 
69  // empty overrides
70  bool IsExtSupported(const char* extension) const override { return false; }
71  bool ResetRenderSystem(int width, int height) override { return true; }
72 
73 protected:
74  virtual void PresentRenderImpl(bool rendered) = 0;
75 
76  bool CreateStates();
77  bool InitGUIShader();
78  void OnResize();
79  void CheckInterlacedStereoView(void);
80  void CheckDeviceCaps();
81 
82  CCriticalSection m_resourceSection;
83  CCriticalSection m_decoderSection;
84 
85  // our adapter could change as we go
86  bool m_interlaced;
87  bool m_inScene{ false };
88  bool m_BlendEnabled{ false };
89  bool m_ScissorsEnabled{ false };
90  D3D11_VIEWPORT m_viewPort;
91  CRect m_scissor;
92  CGUIShaderDX* m_pGUIShader{ nullptr };
93  Microsoft::WRL::ComPtr<ID3D11DepthStencilState> m_depthStencilState;
94  Microsoft::WRL::ComPtr<ID3D11BlendState> m_BlendEnableState;
95  Microsoft::WRL::ComPtr<ID3D11BlendState> m_BlendDisableState;
96  Microsoft::WRL::ComPtr<ID3D11RasterizerState> m_RSScissorDisable;
97  Microsoft::WRL::ComPtr<ID3D11RasterizerState> m_RSScissorEnable;
98  // stereo interlaced/checkerboard intermediate target
99  CD3DTexture m_rightEyeTex;
100 
101  XbmcThreads::EndTime<> m_decodingTimer;
102  XbmcThreads::ConditionVariable m_decodingEvent;
103 
104  std::shared_ptr<DX::DeviceResources> m_deviceResources;
105 };
106 
Definition: D3DResource.h:90
bool m_inScene
True if we&#39;re in a BeginScene()/EndScene() block.
Definition: RenderSystemDX.h:87
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:438
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