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/RetroPlayerTypes.h" 13 #include "threads/CriticalSection.h" 14 15 #include <memory> 16 #include <string> 17 #include <vector> 18 19 #include <libavutil/pixfmt.h> 20 21 class CDataCacheCore; 22 23 namespace KODI 24 { 25 namespace RETRO 26 { 27 class CRenderBufferManager; 28 class CRenderContext; 29 class CRenderSettings; 30 class CRPBaseRenderer; 31 class CRPProcessInfo; 32 class IRenderBufferPool; 33 34 /*! 35 * \brief Process info factory 36 */ 37 using CreateRPProcessControl = CRPProcessInfo* (*)(); 38 39 /*! 40 * \brief Rendering factory 41 */ 42 class IRendererFactory 43 { 44 public: 45 virtual ~IRendererFactory() = default; 46 47 /*! 48 * \brief Get a description name of the rendering system 49 */ 50 virtual std::string RenderSystemName() const = 0; 51 52 /*! 53 * \brief Create a renderer 54 * 55 * \param settings The renderer's initial settings 56 * \param context The rendering context 57 * \param bufferPool The buffer pool to which buffers are returned 58 */ 59 virtual CRPBaseRenderer* CreateRenderer(const CRenderSettings& settings, 60 CRenderContext& context, 61 std::shared_ptr<IRenderBufferPool> bufferPool) = 0; 62 63 /*! 64 * \brief Create buffer pools to manager buffers 65 * 66 * \param context The rendering context shared with the buffer pools 67 * 68 * \return The buffer pools supported by the rendering system 69 */ 70 virtual RenderBufferPoolVector CreateBufferPools(CRenderContext& context) = 0; 71 }; 72 73 /*! 74 * \brief Player process info 75 */ 76 class CRPProcessInfo 77 { 78 public: 79 static CRPProcessInfo* CreateInstance(); 80 static void RegisterProcessControl(CreateRPProcessControl createFunc); 81 static void RegisterRendererFactory(IRendererFactory* factory); 82 83 virtual ~CRPProcessInfo(); 84 85 /*! 86 * \brief Get the descriptive name of the platform 87 * 88 * \return The name of the platform as set by windowing 89 */ GetPlatformName()90 const std::string& GetPlatformName() const { return m_platformName; } 91 92 /*! 93 * \brief Get the descriptive name of the rendering system 94 * 95 * \param renderBufferPool A pool belonging to the rendering system 96 * 97 * \return The name of the rendering system as set by windowing 98 */ 99 std::string GetRenderSystemName(IRenderBufferPool* renderBufferPool) const; 100 101 /*! 102 * \brief Create a renderer 103 * 104 * \param renderBufferPool The buffer pool used to return render buffers 105 * \param renderSettings The settings for this renderer 106 * 107 * \return The renderer, or nullptr on failure 108 */ 109 CRPBaseRenderer* CreateRenderer(IRenderBufferPool* renderBufferPool, 110 const CRenderSettings& renderSettings); 111 112 /*! 113 * \brief Set data cache 114 */ 115 void SetDataCache(CDataCacheCore* cache); 116 117 /*! 118 * \brief Reset data cache info 119 */ 120 void ResetInfo(); 121 122 /// @name Rendering functions 123 ///{ 124 125 /*! 126 * \brief Get the context shared by the rendering system 127 */ GetRenderContext()128 CRenderContext& GetRenderContext() { return *m_renderContext; } 129 130 /*! 131 * \brief Get the buffer manager that owns the buffer pools 132 */ GetBufferManager()133 CRenderBufferManager& GetBufferManager() { return *m_renderBufferManager; } 134 135 /*! 136 * \brief Check if a buffer pool supports the given scaling method 137 */ 138 bool HasScalingMethod(SCALINGMETHOD scalingMethod) const; 139 140 /*! 141 * \brief Get the default scaling method for this rendering system 142 */ GetDefaultScalingMethod()143 SCALINGMETHOD GetDefaultScalingMethod() const { return m_defaultScalingMethod; } 144 145 ///} 146 147 /// @name Player video info 148 ///{ 149 void SetVideoPixelFormat(AVPixelFormat pixFormat); 150 void SetVideoDimensions(int width, int height); 151 void SetVideoFps(float fps); 152 ///} 153 154 /// @name Player audio info 155 ///{ 156 void SetAudioChannels(const std::string& channels); 157 void SetAudioSampleRate(int sampleRate); 158 void SetAudioBitsPerSample(int bitsPerSample); 159 ///} 160 161 /// @name Player states 162 ///{ 163 void SetSpeed(float speed); 164 void SetPlayTimes(time_t start, int64_t current, int64_t min, int64_t max); 165 ///} 166 167 protected: 168 /*! 169 * \brief Constructor 170 * 171 * \param platformName A descriptive name of the platform 172 */ 173 CRPProcessInfo(std::string platformName); 174 175 /*! 176 * \brief Get all scaling methods available to the rendering system 177 */ 178 static std::vector<SCALINGMETHOD> GetScalingMethods(); 179 180 // Static factories 181 static CreateRPProcessControl m_processControl; 182 static std::vector<std::unique_ptr<IRendererFactory>> m_rendererFactories; 183 static CCriticalSection m_createSection; 184 185 // Construction parameters 186 const std::string m_platformName; 187 188 // Info parameters 189 CDataCacheCore* m_dataCache = nullptr; 190 191 // Rendering parameters 192 std::unique_ptr<CRenderBufferManager> m_renderBufferManager; 193 194 private: 195 // Rendering parameters 196 std::unique_ptr<CRenderContext> m_renderContext; 197 SCALINGMETHOD m_defaultScalingMethod = SCALINGMETHOD::AUTO; 198 }; 199 200 } // namespace RETRO 201 } // namespace KODI 202