kodi
RPBaseRenderer.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 "cores/GameSettings.h"
12 #include "cores/RetroPlayer/rendering/RenderSettings.h"
13 #include "utils/Geometry.h"
14 
15 extern "C"
16 {
17 #include <libavutil/pixfmt.h>
18 }
19 
20 #include <array>
21 #include <memory>
22 #include <stdint.h>
23 
24 namespace KODI
25 {
26 namespace RETRO
27 {
28 class CRenderContext;
29 class IRenderBuffer;
30 class IRenderBufferPool;
31 
33 {
34 public:
35  CRPBaseRenderer(const CRenderSettings& renderSettings,
36  CRenderContext& context,
37  std::shared_ptr<IRenderBufferPool> bufferPool);
38  virtual ~CRPBaseRenderer();
39 
43  IRenderBufferPool* GetBufferPool() { return m_bufferPool.get(); }
44 
45  // Player functions
46  bool Configure(AVPixelFormat format);
47  void FrameMove();
51  void PreRender(bool clear);
52  void SetBuffer(IRenderBuffer* buffer);
53  void RenderFrame(bool clear, uint8_t alpha);
54 
55  // Feature support
56  virtual bool Supports(RENDERFEATURE feature) const = 0;
57  bool IsCompatible(const CRenderVideoSettings& settings) const;
58  virtual SCALINGMETHOD GetDefaultScalingMethod() const = 0;
59 
60  // Public renderer interface
61  virtual void Flush();
62 
63  // Get render settings
64  const CRenderSettings& GetRenderSettings() const { return m_renderSettings; }
65 
66  // Set render settings
67  void SetScalingMethod(SCALINGMETHOD method);
68  void SetStretchMode(STRETCHMODE stretchMode);
69  void SetRenderRotation(unsigned int rotationDegCCW);
70  void SetPixels(const std::string& pixelPath);
71 
72  // Rendering properties
73  bool IsVisible() const;
74  IRenderBuffer* GetRenderBuffer() const;
75 
76 protected:
77  // Protected renderer interface
78  virtual bool ConfigureInternal() { return true; }
79  virtual void RenderInternal(bool clear, uint8_t alpha) = 0;
80  virtual void FlushInternal() {}
81 
82  // Construction parameters
83  CRenderContext& m_context;
84  std::shared_ptr<IRenderBufferPool> m_bufferPool;
85 
86  // Stream properties
87  bool m_bConfigured = false;
88  AVPixelFormat m_format = AV_PIX_FMT_NONE;
89 
90  // Rendering properties
91  CRenderSettings m_renderSettings;
92  IRenderBuffer* m_renderBuffer = nullptr;
93 
94  // Geometry properties
95  CRect m_sourceRect;
96  std::array<CPoint, 4> m_rotatedDestCoords{};
97 
98 private:
102  virtual void ManageRenderArea(const IRenderBuffer& renderBuffer);
103 
107  void PostRender();
108 
109  void MarkDirty();
110 
111  // Utility functions
112  void GetScreenDimensions(float& screenWidth, float& screenHeight, float& screenPixelRatio);
113 
114  uint64_t m_renderFrameCount = 0;
115  uint64_t m_lastRender = 0;
116 };
117 } // namespace RETRO
118 } // namespace KODI
Definition: IRenderBuffer.h:27
void PreRender(bool clear)
Performs whatever necessary before rendering the frame.
Definition: RPBaseRenderer.cpp:213
Definition: AudioDecoder.h:18
Definition: IRenderBufferPool.h:30
STRETCHMODE
Methods for stretching the game to the viewing area.
Definition: GameSettings.h:29
Definition: RenderContext.h:43
Definition: settings.py:1
Video settings provided by the rendering system.
Definition: RenderVideoSettings.h:22
IRenderBufferPool * GetBufferPool()
Get the buffer pool used by this renderer.
Definition: RPBaseRenderer.h:43
Definition: RPBaseRenderer.h:32
Definition: RenderSettings.h:17