Merge pull request #26126 from stephan49/fix-pipewire-unlock-error
[xbmc.git] / xbmc / cores / VideoPlayer / VideoRenderers / LinuxRendererGLES.h
blob973428db1daad74f12896c1c29d08694743b0614
1 /*
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.
7 */
9 #pragma once
11 #include <vector>
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"
24 extern "C" {
25 #include <libavutil/mastering_display_metadata.h>
28 class CRenderCapture;
29 class CRenderSystemGLES;
31 class CTexture;
32 namespace Shaders
34 namespace GLES
36 class BaseYUV2RGBGLSLShader;
37 class BaseVideoFilterShader;
39 } // namespace Shaders
41 enum RenderMethod
43 RENDER_GLSL = 0x01,
44 RENDER_CUSTOM = 0x02,
47 enum RenderQuality
49 RQ_LOW = 1,
50 RQ_SINGLEPASS,
51 RQ_MULTIPASS,
52 RQ_SOFTWARE
55 class CEvent;
57 class CLinuxRendererGLES : public CBaseRenderer
59 public:
60 CLinuxRendererGLES();
61 ~CLinuxRendererGLES() override;
63 // Registration
64 static CBaseRenderer* Create(CVideoBuffer *buffer);
65 static bool Register();
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(int index, CRenderCapture* capture) override;
79 CRenderInfo GetRenderInfo() override;
80 bool ConfigChanged(const VideoPicture& picture) override;
82 // Feature support
83 bool SupportsMultiPassRendering() override;
84 bool Supports(ERENDERFEATURE feature) const override;
85 bool Supports(ESCALINGMETHOD method) const override;
87 CRenderCapture* GetRenderCapture() override;
89 protected:
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);
106 // textures
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);
122 // renderers
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) {}
132 struct
134 CFrameBufferObject fbo;
135 float width{0.0};
136 float height{0.0};
137 } m_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};
154 struct CYuvPlane
156 GLuint id{0};
157 CRect rect{0, 0, 0, 0};
159 float width{0.0};
160 float height{0.0};
162 unsigned texwidth{0};
163 unsigned texheight{0};
165 //pixels per texel
166 unsigned pixpertex_x{0};
167 unsigned pixpertex_y{0};
170 struct CPictureBuffer
172 CYuvPlane fields[MAX_FIELDS][YuvImage::MAX_PLANES];
173 YuvImage image;
175 CVideoBuffer *videoBuffer{nullptr};
176 bool loaded{false};
178 AVColorPrimaries m_srcPrimaries;
179 AVColorSpace m_srcColSpace;
180 AVColorTransferCharacteristic m_srcColTransfer;
182 int m_srcBits{8};
183 int m_srcTextureBits{8};
184 bool m_srcFullRange;
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};
205 bool m_fullRange;
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};
215 CRect m_viewRect;
217 private:
218 void ClearBackBuffer();
219 void ClearBackBufferQuad();
220 void DrawBlackBars();