2 * Copyright (C) 2010-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
13 #include "system_gl.h"
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"
25 #include <libavutil/mastering_display_metadata.h>
29 class CRenderSystemGLES
;
36 class BaseYUV2RGBGLSLShader
;
37 class BaseVideoFilterShader
;
39 } // namespace Shaders
57 class CLinuxRendererGLES
: public CBaseRenderer
61 ~CLinuxRendererGLES() override
;
64 static CBaseRenderer
* Create(CVideoBuffer
*buffer
);
65 static bool Register();
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(int index
, CRenderCapture
* capture
) override
;
79 CRenderInfo
GetRenderInfo() override
;
80 bool ConfigChanged(const VideoPicture
& picture
) override
;
83 bool SupportsMultiPassRendering() override
;
84 bool Supports(ERENDERFEATURE feature
) const override
;
85 bool Supports(ESCALINGMETHOD method
) const override
;
87 CRenderCapture
* GetRenderCapture() override
;
90 static const int FIELD_FULL
{0};
91 static const int FIELD_TOP
{1};
92 static const int FIELD_BOT
{2};
94 virtual bool Render(unsigned int flags
, int index
);
95 virtual void RenderUpdateVideo(bool clear
, unsigned int flags
= 0, unsigned int alpha
= 255);
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 void CheckVideoParameters(int index
);
104 AVColorPrimaries
GetSrcPrimaries(AVColorPrimaries srcPrimaries
, unsigned int width
, unsigned int height
);
107 virtual bool UploadTexture(int index
);
108 virtual void DeleteTexture(int index
);
109 virtual bool CreateTexture(int index
);
111 bool UploadYV12Texture(int index
);
112 void DeleteYV12Texture(int index
);
113 bool CreateYV12Texture(int index
);
114 virtual bool SkipUploadYV12(int index
) { return false; }
116 bool UploadNV12Texture(int index
);
117 void DeleteNV12Texture(int index
);
118 bool CreateNV12Texture(int index
);
120 void CalculateTextureSourceRects(int source
, int num_planes
);
123 void RenderToFBO(int index
, int field
);
124 void RenderFromFBO();
125 void RenderSinglePass(int index
, int field
); // single pass glsl renderer
127 // hooks for HwDec Renderered
128 virtual bool LoadShadersHook() { return false; }
129 virtual bool RenderHook(int idx
) { return false; }
130 virtual void AfterRenderHook(int idx
) {}
134 CFrameBufferObject fbo
;
139 int m_iYV12RenderBuffer
{0};
140 int m_NumYV12Buffers
{0};
142 bool m_bConfigured
{false};
143 bool m_bValidated
{false};
144 GLenum m_textureTarget
= GL_TEXTURE_2D
;
145 int m_renderMethod
{RENDER_GLSL
};
146 RenderQuality m_renderQuality
{RQ_SINGLEPASS
};
148 // Raw data used by renderer
149 int m_currentField
{FIELD_FULL
};
150 int m_reloadShaders
{0};
151 CRenderSystemGLES
*m_renderSystem
{nullptr};
152 GLenum m_pixelStoreKey
{0};
157 CRect rect
{0, 0, 0, 0};
162 unsigned texwidth
{0};
163 unsigned texheight
{0};
166 unsigned pixpertex_x
{0};
167 unsigned pixpertex_y
{0};
170 struct CPictureBuffer
172 CYuvPlane fields
[MAX_FIELDS
][YuvImage::MAX_PLANES
];
175 CVideoBuffer
*videoBuffer
{nullptr};
178 AVColorPrimaries m_srcPrimaries
;
179 AVColorSpace m_srcColSpace
;
180 AVColorTransferCharacteristic m_srcColTransfer
;
183 int m_srcTextureBits
{8};
186 bool hasDisplayMetadata
{false};
187 AVMasteringDisplayMetadata displayMetadata
;
188 bool hasLightMetadata
{false};
189 AVContentLightMetadata lightMetadata
;
192 // YV12 decoder textures
193 // field index 0 is full image, 1 is odd scanlines, 2 is even scanlines
194 CPictureBuffer m_buffers
[NUM_BUFFERS
];
196 void LoadPlane(CYuvPlane
& plane
, int type
,
197 unsigned width
, unsigned height
,
198 int stride
, int bpp
, void* data
);
200 Shaders::GLES::BaseYUV2RGBGLSLShader
* m_pYUVProgShader
{nullptr};
201 Shaders::GLES::BaseYUV2RGBGLSLShader
* m_pYUVBobShader
{nullptr};
202 Shaders::GLES::BaseVideoFilterShader
* m_pVideoFilterShader
{nullptr};
203 ESCALINGMETHOD m_scalingMethod
{VS_SCALINGMETHOD_LINEAR
};
204 ESCALINGMETHOD m_scalingMethodGui
{VS_SCALINGMETHOD_MAX
};
206 AVColorPrimaries m_srcPrimaries
;
207 bool m_toneMap
= false;
208 ETONEMAPMETHOD m_toneMapMethod
= VS_TONEMAPMETHOD_OFF
;
209 bool m_passthroughHDR
= false;
210 unsigned char* m_planeBuffer
= nullptr;
211 size_t m_planeBufferSize
= 0;
213 // clear colour for "black" bars
214 float m_clearColour
{0.0f
};
218 void ClearBackBuffer();
219 void ClearBackBufferQuad();
220 void DrawBlackBars();