xbmc
RPWinRenderer.h
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 "RPBaseRenderer.h"
12 #include "cores/RetroPlayer/buffers/BaseRenderBufferPool.h"
13 #include "cores/RetroPlayer/buffers/video/RenderBufferSysMem.h"
14 #include "cores/RetroPlayer/process/RPProcessInfo.h"
15 
16 #include <memory>
17 #include <stdint.h>
18 #include <vector>
19 
20 #include <dxgi.h>
21 
22 class CD3DTexture;
23 struct SwsContext;
24 
25 namespace KODI
26 {
27 namespace RETRO
28 {
29 class CRenderContext;
30 class CRPWinOutputShader;
31 
33 {
34 public:
35  virtual ~CWinRendererFactory() = default;
36 
37  // implementation of IRendererFactory
38  std::string RenderSystemName() const override;
40  CRenderContext& context,
41  std::shared_ptr<IRenderBufferPool> bufferPool) override;
42  RenderBufferPoolVector CreateBufferPools(CRenderContext& context) override;
43 };
44 
46 {
47 public:
48  CWinRenderBuffer(AVPixelFormat pixFormat, DXGI_FORMAT dxFormat);
49  ~CWinRenderBuffer() override = default;
50 
51  // implementation of IRenderBuffer via CRenderBufferSysMem
52  bool UploadTexture() override;
53 
54  CD3DTexture* GetTarget() { return m_intermediateTarget.get(); }
55 
56 private:
57  bool CreateTexture();
58  bool GetTexture(uint8_t*& data, unsigned int& stride);
59  bool ReleaseTexture();
60 
61  bool CreateScalingContext();
62  void ScalePixels(uint8_t* source,
63  unsigned int sourceStride,
64  uint8_t* target,
65  unsigned int targetStride);
66 
67  static AVPixelFormat GetPixFormat(DXGI_FORMAT dxFormat);
68 
69  // Construction parameters
70  const AVPixelFormat m_pixFormat;
71  const DXGI_FORMAT m_targetDxFormat;
72 
73  AVPixelFormat m_targetPixFormat;
74  std::unique_ptr<CD3DTexture> m_intermediateTarget;
75 
76  SwsContext* m_swsContext = nullptr;
77 };
78 
80 {
81 public:
83  ~CWinRenderBufferPool() override = default;
84 
85  // implementation of IRenderBufferPool via CRenderBufferPoolSysMem
86  bool IsCompatible(const CRenderVideoSettings& renderSettings) const override;
87 
88  // implementation of CBaseRenderBufferPool via CRenderBufferPoolSysMem
89  IRenderBuffer* CreateRenderBuffer(void* header = nullptr) override;
90 
91  // DirectX interface
92  bool ConfigureDX(DXGI_FORMAT dxFormat);
93  CRPWinOutputShader* GetShader(SCALINGMETHOD scalingMethod) const;
94 
95 private:
96  static const std::vector<SCALINGMETHOD>& GetScalingMethods();
97 
98  void CompileOutputShaders();
99 
100  DXGI_FORMAT m_targetDxFormat = DXGI_FORMAT_UNKNOWN;
101  std::map<SCALINGMETHOD, std::unique_ptr<CRPWinOutputShader>> m_outputShaders;
102 };
103 
105 {
106 public:
107  CRPWinRenderer(const CRenderSettings& renderSettings,
108  CRenderContext& context,
109  std::shared_ptr<IRenderBufferPool> bufferPool);
110  ~CRPWinRenderer() override = default;
111 
112  // implementation of CRPBaseRenderer
113  bool Supports(RENDERFEATURE feature) const override;
114  SCALINGMETHOD GetDefaultScalingMethod() const override { return DEFAULT_SCALING_METHOD; }
115 
116  static bool SupportsScalingMethod(SCALINGMETHOD method);
117 
121  static const SCALINGMETHOD DEFAULT_SCALING_METHOD = SCALINGMETHOD::NEAREST;
122 
123 protected:
124  // implementation of CRPBaseRenderer
125  bool ConfigureInternal() override;
126  void RenderInternal(bool clear, uint8_t alpha) override;
127 
128 private:
129  void Render(CD3DTexture& target);
130 };
131 } // namespace RETRO
132 } // namespace KODI
Definition: D3DResource.h:90
Definition: BaseRenderBufferPool.h:22
Definition: RPWinRenderer.h:104
Definition: RPWinRenderer.h:32
RenderBufferPoolVector CreateBufferPools(CRenderContext &context) override
Create buffer pools to manager buffers.
Definition: RPWinRenderer.cpp:43
Definition: IRenderBuffer.h:27
std::string RenderSystemName() const override
Get a description name of the rendering system.
Definition: RPWinRenderer.cpp:31
Definition: RPWinOutputShader.h:19
Definition: RenderBufferSysMem.h:25
Controller configuration window.
Definition: AudioDecoder.h:18
Rendering factory.
Definition: RPProcessInfo.h:43
Definition: RenderContext.h:43
Definition: settings.py:1
Definition: RPWinRenderer.h:79
Video settings provided by the rendering system.
Definition: RenderVideoSettings.h:22
Definition: RPWinRenderer.h:45
CRPBaseRenderer * CreateRenderer(const CRenderSettings &settings, CRenderContext &context, std::shared_ptr< IRenderBufferPool > bufferPool) override
Create a renderer.
Definition: RPWinRenderer.cpp:36
Definition: RPBaseRenderer.h:32
Definition: RenderSettings.h:17