forked from xbmc/xbmc
/
LinuxRendererGLES.h
313 lines (249 loc) · 8.48 KB
/
LinuxRendererGLES.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#ifndef LINUXRENDERERGLES_RENDERER
#define LINUXRENDERERGLES_RENDERER
/*
* Copyright (C) 2010 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#if HAS_GLES == 2
#include "system_gl.h"
#include "xbmc/guilib/FrameBufferObject.h"
#include "xbmc/guilib/Shader.h"
#include "settings/VideoSettings.h"
#include "RenderFlags.h"
#include "guilib/GraphicContext.h"
#include "BaseRenderer.h"
#include "xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodec.h"
class CRenderCapture;
class CBaseTexture;
namespace Shaders { class BaseYUV2RGBShader; }
namespace Shaders { class BaseVideoFilterShader; }
class COpenMaxVideo;
#define NUM_BUFFERS 3
#undef ALIGN
#define ALIGN(value, alignment) (((value)+((alignment)-1))&~((alignment)-1))
#define CLAMP(a, min, max) ((a) > (max) ? (max) : ( (a) < (min) ? (min) : a ))
#define AUTOSOURCE -1
#define IMAGE_FLAG_WRITING 0x01 /* image is in use after a call to GetImage, caller may be reading or writing */
#define IMAGE_FLAG_READING 0x02 /* image is in use after a call to GetImage, caller is only reading */
#define IMAGE_FLAG_DYNAMIC 0x04 /* image was allocated due to a call to GetImage */
#define IMAGE_FLAG_RESERVED 0x08 /* image is reserved, must be asked for specifically used to preserve images */
#define IMAGE_FLAG_READY 0x16 /* image is ready to be uploaded to texture memory */
#define IMAGE_FLAG_INUSE (IMAGE_FLAG_WRITING | IMAGE_FLAG_READING | IMAGE_FLAG_RESERVED)
struct DRAWRECT
{
float left;
float top;
float right;
float bottom;
};
struct YUVRANGE
{
int y_min, y_max;
int u_min, u_max;
int v_min, v_max;
};
struct YUVCOEF
{
float r_up, r_vp;
float g_up, g_vp;
float b_up, b_vp;
};
enum RenderMethod
{
RENDER_GLSL = 0x001,
RENDER_SW = 0x004,
RENDER_POT = 0x010,
RENDER_OMXEGL = 0x040,
RENDER_CVREF = 0x080,
RENDER_BYPASS = 0x100,
RENDER_VAAPI = 0x200
};
enum RenderQuality
{
RQ_LOW=1,
RQ_SINGLEPASS,
RQ_MULTIPASS,
RQ_SOFTWARE
};
#define PLANE_Y 0
#define PLANE_U 1
#define PLANE_V 2
#define FIELD_FULL 0
#define FIELD_TOP 1
#define FIELD_BOT 2
extern YUVRANGE yuv_range_lim;
extern YUVRANGE yuv_range_full;
extern YUVCOEF yuv_coef_bt601;
extern YUVCOEF yuv_coef_bt709;
extern YUVCOEF yuv_coef_ebu;
extern YUVCOEF yuv_coef_smtp240m;
class DllSwScale;
struct SwsContext;
class CEvent;
class CLinuxRendererGLES : public CBaseRenderer
{
public:
CLinuxRendererGLES();
virtual ~CLinuxRendererGLES();
virtual void Update(bool bPauseDrawing);
virtual void SetupScreenshot() {};
bool RenderCapture(CRenderCapture* capture);
// Player functions
virtual bool Configure(unsigned int width, unsigned int height, unsigned int d_width, unsigned int d_height, float fps, unsigned flags, ERenderFormat format, unsigned extended_formatunsigned, unsigned int orientation);
virtual bool IsConfigured() { return m_bConfigured; }
virtual int GetImage(YV12Image *image, int source = AUTOSOURCE, bool readonly = false);
virtual void ReleaseImage(int source, bool preserve = false);
virtual void FlipPage(int source);
virtual unsigned int PreInit();
virtual void UnInit();
virtual void Reset(); /* resets renderer after seek for example */
virtual void ReorderDrawPoints();
virtual void RenderUpdate(bool clear, DWORD flags = 0, DWORD alpha = 255);
// Feature support
virtual bool SupportsMultiPassRendering();
virtual bool Supports(ERENDERFEATURE feature);
virtual bool Supports(EDEINTERLACEMODE mode);
virtual bool Supports(EINTERLACEMETHOD method);
virtual bool Supports(ESCALINGMETHOD method);
virtual EINTERLACEMETHOD AutoInterlaceMethod();
virtual std::vector<ERenderFormat> SupportedFormats() { return m_formats; }
#ifdef HAVE_LIBVA
virtual void AddProcessor(VAAPI::CHolder& holder);
#endif
#ifdef HAVE_LIBOPENMAX
virtual void AddProcessor(COpenMax* openMax, DVDVideoPicture *picture);
#endif
#ifdef HAVE_VIDEOTOOLBOXDECODER
virtual void AddProcessor(struct __CVBuffer *cvBufferRef);
#endif
protected:
virtual void Render(DWORD flags, int index);
virtual void ManageTextures();
int NextYV12Texture();
virtual bool ValidateRenderTarget();
virtual void LoadShaders(int field=FIELD_FULL);
void SetTextureFilter(GLenum method);
void UpdateVideoFilter();
// textures
void (CLinuxRendererGLES::*m_textureUpload)(int index);
void (CLinuxRendererGLES::*m_textureDelete)(int index);
bool (CLinuxRendererGLES::*m_textureCreate)(int index);
void UploadYV12Texture(int index);
void DeleteYV12Texture(int index);
bool CreateYV12Texture(int index);
void UploadVAAPITexture(int index);
void DeleteVAAPITexture(int index);
bool CreateVAAPITexture(int index);
void UploadCVRefTexture(int index);
void DeleteCVRefTexture(int index);
bool CreateCVRefTexture(int index);
void UploadBYPASSTexture(int index);
void DeleteBYPASSTexture(int index);
bool CreateBYPASSTexture(int index);
void CalculateTextureSourceRects(int source, int num_planes);
// renderers
void RenderMultiPass(int index, int field); // multi pass glsl renderer
void RenderSinglePass(int index, int field); // single pass glsl renderer
void RenderSoftware(int index, int field); // single pass s/w yuv2rgb renderer
void RenderVAAPI(int index, int field); // VA-API surface
void RenderOpenMax(int index, int field); // OpenMAX rgb texture
void RenderCoreVideoRef(int index, int field); // CoreVideo reference
CFrameBufferObject m_fbo;
int m_iYV12RenderBuffer;
int m_NumYV12Buffers;
int m_iLastRenderBuffer;
bool m_bConfigured;
bool m_bValidated;
std::vector<ERenderFormat> m_formats;
bool m_bImageReady;
unsigned m_iFlags;
ERenderFormat m_format;
GLenum m_textureTarget;
unsigned short m_renderMethod;
unsigned short m_oldRenderMethod;
RenderQuality m_renderQuality;
unsigned int m_flipindex; // just a counter to keep track of if a image has been uploaded
bool m_StrictBinding;
// Raw data used by renderer
int m_currentField;
int m_reloadShaders;
struct YUVPLANE
{
GLuint id;
CRect rect;
float width;
float height;
unsigned texwidth;
unsigned texheight;
unsigned flipindex;
};
typedef YUVPLANE YUVPLANES[MAX_PLANES];
typedef YUVPLANES YUVFIELDS[MAX_FIELDS];
void RenderRGB(const YUVPLANE& plane);
void RenderYUV(const YUVPLANES& planes, int numPlanes);
struct YUVBUFFER
{
YUVBUFFER();
~YUVBUFFER();
YUVFIELDS fields;
YV12Image image;
unsigned flipindex; /* used to decide if this has been uploaded */
#ifdef HAVE_LIBVA
VAAPI::CHolder& vaapi;
#endif
#ifdef HAVE_LIBOPENMAX
OpenMaxVideoBuffer *openMaxBuffer;
#endif
#ifdef HAVE_VIDEOTOOLBOXDECODER
struct __CVBuffer *cvBufferRef;
#endif
};
typedef YUVBUFFER YUVBUFFERS[NUM_BUFFERS];
// YV12 decoder textures
// field index 0 is full image, 1 is odd scanlines, 2 is even scanlines
YUVBUFFERS m_buffers;
void LoadPlane( YUVPLANE& plane, int type, unsigned flipindex
, unsigned width, unsigned height
, int stride, void* data );
ERenderFormat m_YUVShaderFormat;
Shaders::BaseYUV2RGBShader *m_pYUVShader;
Shaders::BaseVideoFilterShader *m_pVideoFilterShader;
ESCALINGMETHOD m_scalingMethod;
ESCALINGMETHOD m_scalingMethodGui;
// clear colour for "black" bars
float m_clearColour;
// software scale libraries (fallback if required gl version is not available)
DllSwScale *m_dllSwScale;
struct SwsContext *m_sw_context;
BYTE *m_rgbBuffer; // if software scale is used, this will hold the result image
unsigned int m_rgbBufferSize;
CEvent* m_eventTexturesDone[NUM_BUFFERS];
};
inline int NP2( unsigned x )
{
--x;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
return ++x;
}
#endif
#endif