xbmc
LinuxRendererGLES.h
1 /*
2  * Copyright (C) 2010-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 <vector>
12 
13 #include "system_gl.h"
14 
15 #include "BaseRenderer.h"
16 #include "cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodec.h"
17 #include "cores/VideoSettings.h"
18 #include "FrameBufferObject.h"
19 #include "guilib/Shader.h"
20 #include "RenderFlags.h"
21 #include "RenderInfo.h"
22 #include "windowing/GraphicContext.h"
23 
24 extern "C" {
25 #include <libavutil/mastering_display_metadata.h>
26 }
27 
28 class CRenderCapture;
29 class CRenderSystemGLES;
30 
31 class CTexture;
32 namespace Shaders
33 {
34 namespace GLES
35 {
36 class BaseYUV2RGBGLSLShader;
37 class BaseVideoFilterShader;
38 }
39 } // namespace Shaders
40 
41 enum RenderMethod
42 {
43  RENDER_GLSL = 0x01,
44  RENDER_CUSTOM = 0x02,
45 };
46 
47 enum RenderQuality
48 {
49  RQ_LOW = 1,
50  RQ_SINGLEPASS,
51  RQ_MULTIPASS,
52  RQ_SOFTWARE
53 };
54 
55 class CEvent;
56 
58 {
59 public:
61  ~CLinuxRendererGLES() override;
62 
63  // Registration
64  static CBaseRenderer* Create(CVideoBuffer *buffer);
65  static bool Register();
66 
67  // Player functions
68  bool Configure(const VideoPicture& picture, float fps, unsigned int orientation) override;
69  bool IsConfigured() override { return m_bConfigured; }
70  void AddVideoPicture(const VideoPicture& picture, int index) override;
71  void UnInit() override;
72  bool Flush(bool saveBuffers) override;
73  void SetBufferSize(int numBuffers) override { m_NumYV12Buffers = numBuffers; }
74  bool IsGuiLayer() override;
75  void ReleaseBuffer(int idx) override;
76  void RenderUpdate(int index, int index2, bool clear, unsigned int flags, unsigned int alpha) override;
77  void Update() override;
78  bool RenderCapture(CRenderCapture* capture) override;
79  CRenderInfo GetRenderInfo() override;
80  bool ConfigChanged(const VideoPicture& picture) override;
81 
82  // Feature support
83  bool SupportsMultiPassRendering() override;
84  bool Supports(ERENDERFEATURE feature) const override;
85  bool Supports(ESCALINGMETHOD method) const override;
86 
87  CRenderCapture* GetRenderCapture() override;
88 
89 protected:
90  static const int FIELD_FULL{0};
91  static const int FIELD_TOP{1};
92  static const int FIELD_BOT{2};
93 
94  virtual void Render(unsigned int flags, int index);
95  virtual void RenderUpdateVideo(bool clear, unsigned int flags = 0, unsigned int alpha = 255);
96 
97  int NextYV12Texture();
98  virtual bool ValidateRenderTarget();
99  virtual void LoadShaders(int field=FIELD_FULL);
100  virtual void ReleaseShaders();
101  void SetTextureFilter(GLenum method);
102  void UpdateVideoFilter();
103  AVColorPrimaries GetSrcPrimaries(AVColorPrimaries srcPrimaries, unsigned int width, unsigned int height);
104 
105  // textures
106  virtual bool UploadTexture(int index);
107  virtual void DeleteTexture(int index);
108  virtual bool CreateTexture(int index);
109 
110  bool UploadYV12Texture(int index);
111  void DeleteYV12Texture(int index);
112  bool CreateYV12Texture(int index);
113  virtual bool SkipUploadYV12(int index) { return false; }
114 
115  bool UploadNV12Texture(int index);
116  void DeleteNV12Texture(int index);
117  bool CreateNV12Texture(int index);
118 
119  void CalculateTextureSourceRects(int source, int num_planes);
120 
121  // renderers
122  void RenderToFBO(int index, int field);
123  void RenderFromFBO();
124  void RenderSinglePass(int index, int field); // single pass glsl renderer
125 
126  // hooks for HwDec Renderered
127  virtual bool LoadShadersHook() { return false; }
128  virtual bool RenderHook(int idx) { return false; }
129  virtual void AfterRenderHook(int idx) {}
130 
131  struct
132  {
133  CFrameBufferObject fbo;
134  float width{0.0};
135  float height{0.0};
136  } m_fbo;
137 
138  int m_iYV12RenderBuffer{0};
139  int m_NumYV12Buffers{0};
140 
141  bool m_bConfigured{false};
142  bool m_bValidated{false};
143  GLenum m_textureTarget = GL_TEXTURE_2D;
144  int m_renderMethod{RENDER_GLSL};
145  RenderQuality m_renderQuality{RQ_SINGLEPASS};
146 
147  // Raw data used by renderer
148  int m_currentField{FIELD_FULL};
149  int m_reloadShaders{0};
150  CRenderSystemGLES *m_renderSystem{nullptr};
151  GLenum m_pixelStoreKey{0};
152 
153  struct CYuvPlane
154  {
155  GLuint id{0};
156  CRect rect{0, 0, 0, 0};
157 
158  float width{0.0};
159  float height{0.0};
160 
161  unsigned texwidth{0};
162  unsigned texheight{0};
163 
164  //pixels per texel
165  unsigned pixpertex_x{0};
166  unsigned pixpertex_y{0};
167  };
168 
170  {
171  CYuvPlane fields[MAX_FIELDS][YuvImage::MAX_PLANES];
172  YuvImage image;
173 
174  CVideoBuffer *videoBuffer{nullptr};
175  bool loaded{false};
176 
177  AVColorPrimaries m_srcPrimaries;
178  AVColorSpace m_srcColSpace;
179  int m_srcBits{8};
180  int m_srcTextureBits{8};
181  bool m_srcFullRange;
182 
183  bool hasDisplayMetadata{false};
184  AVMasteringDisplayMetadata displayMetadata;
185  bool hasLightMetadata{false};
186  AVContentLightMetadata lightMetadata;
187  };
188 
189  // YV12 decoder textures
190  // field index 0 is full image, 1 is odd scanlines, 2 is even scanlines
191  CPictureBuffer m_buffers[NUM_BUFFERS];
192 
193  void LoadPlane(CYuvPlane& plane, int type,
194  unsigned width, unsigned height,
195  int stride, int bpp, void* data);
196 
197  Shaders::GLES::BaseYUV2RGBGLSLShader* m_pYUVProgShader{nullptr};
198  Shaders::GLES::BaseYUV2RGBGLSLShader* m_pYUVBobShader{nullptr};
199  Shaders::GLES::BaseVideoFilterShader* m_pVideoFilterShader{nullptr};
200  ESCALINGMETHOD m_scalingMethod{VS_SCALINGMETHOD_LINEAR};
201  ESCALINGMETHOD m_scalingMethodGui{VS_SCALINGMETHOD_MAX};
202  bool m_fullRange;
203  AVColorPrimaries m_srcPrimaries;
204  bool m_toneMap = false;
205  ETONEMAPMETHOD m_toneMapMethod = VS_TONEMAPMETHOD_OFF;
206  bool m_passthroughHDR = false;
207  unsigned char* m_planeBuffer = nullptr;
208  size_t m_planeBufferSize = 0;
209 
210  // clear colour for "black" bars
211  float m_clearColour{0.0f};
212  CRect m_viewRect;
213 
214 private:
215  void DrawBlackBars();
216 };
This is an Event class built from a ConditionVariable.
Definition: Event.h:35
Definition: VideoBuffer.h:85
Definition: RenderCapture.h:23
Definition: RenderInfo.h:19
Definition: RenderSystemGLES.h:73
Definition: LinuxRendererGLES.h:169
Definition: VideoFilterShaderGLES.h:20
Definition: VideoBuffer.h:24
Definition: LinuxRendererGL.h:30
Base texture class, subclasses of which depend on the render spec (DX, GL etc.)
Definition: Texture.h:34
Definition: DVDVideoCodec.h:36
Definition: LinuxRendererGLES.h:153
Definition: LinuxRendererGLES.h:57
Definition: BaseRenderer.h:48
Definition: FrameBufferObject.h:32
Definition: YUV2RGBShaderGLES.h:26