1 #ifndef LINUXRENDERERGLES_RENDERER
2 #define LINUXRENDERERGLES_RENDERER
5 * Copyright (C) 2010-2013 Team XBMC
8 * This Program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
13 * This Program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with XBMC; see the file COPYING. If not, see
20 * <http://www.gnu.org/licenses/>.
26 #include "system_gl.h"
28 #include "xbmc/guilib/FrameBufferObject.h"
29 #include "xbmc/guilib/Shader.h"
30 #include "settings/VideoSettings.h"
31 #include "RenderFlags.h"
32 #include "guilib/GraphicContext.h"
33 #include "BaseRenderer.h"
34 #include "xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodec.h"
39 namespace Shaders { class BaseYUV2RGBShader; }
40 namespace Shaders { class BaseVideoFilterShader; }
42 typedef std::vector<int> Features;
48 #define ALIGN(value, alignment) (((value)+((alignment)-1))&~((alignment)-1))
49 #define CLAMP(a, min, max) ((a) > (max) ? (max) : ( (a) < (min) ? (min) : a ))
53 #define IMAGE_FLAG_WRITING 0x01 /* image is in use after a call to GetImage, caller may be reading or writing */
54 #define IMAGE_FLAG_READING 0x02 /* image is in use after a call to GetImage, caller is only reading */
55 #define IMAGE_FLAG_DYNAMIC 0x04 /* image was allocated due to a call to GetImage */
56 #define IMAGE_FLAG_RESERVED 0x08 /* image is reserved, must be asked for specifically used to preserve images */
57 #define IMAGE_FLAG_READY 0x16 /* image is ready to be uploaded to texture memory */
58 #define IMAGE_FLAG_INUSE (IMAGE_FLAG_WRITING | IMAGE_FLAG_READING | IMAGE_FLAG_RESERVED)
87 RENDER_OMXEGL = 0x040,
108 extern YUVRANGE yuv_range_lim;
109 extern YUVRANGE yuv_range_full;
110 extern YUVCOEF yuv_coef_bt601;
111 extern YUVCOEF yuv_coef_bt709;
112 extern YUVCOEF yuv_coef_ebu;
113 extern YUVCOEF yuv_coef_smtp240m;
120 class CLinuxRendererGLES : public CBaseRenderer
123 CLinuxRendererGLES();
124 virtual ~CLinuxRendererGLES();
126 virtual void Update(bool bPauseDrawing);
127 virtual void SetupScreenshot() {};
129 bool RenderCapture(CRenderCapture* capture);
132 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);
133 virtual bool IsConfigured() { return m_bConfigured; }
134 virtual int GetImage(YV12Image *image, int source = AUTOSOURCE, bool readonly = false);
135 virtual void ReleaseImage(int source, bool preserve = false);
136 virtual void FlipPage(int source);
137 virtual unsigned int PreInit();
138 virtual void UnInit();
139 virtual void Reset(); /* resets renderer after seek for example */
140 virtual void ReorderDrawPoints();
142 virtual void RenderUpdate(bool clear, DWORD flags = 0, DWORD alpha = 255);
145 virtual bool SupportsMultiPassRendering();
146 virtual bool Supports(ERENDERFEATURE feature);
147 virtual bool Supports(EDEINTERLACEMODE mode);
148 virtual bool Supports(EINTERLACEMETHOD method);
149 virtual bool Supports(ESCALINGMETHOD method);
151 virtual EINTERLACEMETHOD AutoInterlaceMethod();
153 virtual std::vector<ERenderFormat> SupportedFormats() { return m_formats; }
155 #ifdef HAVE_LIBOPENMAX
156 virtual void AddProcessor(COpenMax* openMax, DVDVideoPicture *picture);
158 #ifdef HAVE_VIDEOTOOLBOXDECODER
159 virtual void AddProcessor(struct __CVBuffer *cvBufferRef);
163 virtual void Render(DWORD flags, int index);
165 virtual void ManageTextures();
166 int NextYV12Texture();
167 virtual bool ValidateRenderTarget();
168 virtual void LoadShaders(int field=FIELD_FULL);
169 void SetTextureFilter(GLenum method);
170 void UpdateVideoFilter();
173 void (CLinuxRendererGLES::*m_textureUpload)(int index);
174 void (CLinuxRendererGLES::*m_textureDelete)(int index);
175 bool (CLinuxRendererGLES::*m_textureCreate)(int index);
177 void UploadYV12Texture(int index);
178 void DeleteYV12Texture(int index);
179 bool CreateYV12Texture(int index);
181 void UploadCVRefTexture(int index);
182 void DeleteCVRefTexture(int index);
183 bool CreateCVRefTexture(int index);
185 void UploadBYPASSTexture(int index);
186 void DeleteBYPASSTexture(int index);
187 bool CreateBYPASSTexture(int index);
189 void CalculateTextureSourceRects(int source, int num_planes);
192 void RenderMultiPass(int index, int field); // multi pass glsl renderer
193 void RenderSinglePass(int index, int field); // single pass glsl renderer
194 void RenderSoftware(int index, int field); // single pass s/w yuv2rgb renderer
195 void RenderOpenMax(int index, int field); // OpenMAX rgb texture
196 void RenderCoreVideoRef(int index, int field); // CoreVideo reference
198 CFrameBufferObject m_fbo;
200 int m_iYV12RenderBuffer;
201 int m_NumYV12Buffers;
202 int m_iLastRenderBuffer;
206 std::vector<ERenderFormat> m_formats;
208 ERenderFormat m_format;
209 GLenum m_textureTarget;
210 unsigned short m_renderMethod;
211 unsigned short m_oldRenderMethod;
212 RenderQuality m_renderQuality;
213 unsigned int m_flipindex; // just a counter to keep track of if a image has been uploaded
214 bool m_StrictBinding;
216 // Raw data used by renderer
234 typedef YUVPLANE YUVPLANES[MAX_PLANES];
235 typedef YUVPLANES YUVFIELDS[MAX_FIELDS];
244 unsigned flipindex; /* used to decide if this has been uploaded */
246 #ifdef HAVE_LIBOPENMAX
247 OpenMaxVideoBuffer *openMaxBuffer;
249 #ifdef HAVE_VIDEOTOOLBOXDECODER
250 struct __CVBuffer *cvBufferRef;
255 typedef YUVBUFFER YUVBUFFERS[NUM_BUFFERS];
257 // YV12 decoder textures
258 // field index 0 is full image, 1 is odd scanlines, 2 is even scanlines
259 YUVBUFFERS m_buffers;
261 void LoadPlane( YUVPLANE& plane, int type, unsigned flipindex
262 , unsigned width, unsigned height
263 , int stride, void* data );
265 Shaders::BaseYUV2RGBShader *m_pYUVShader;
266 Shaders::BaseVideoFilterShader *m_pVideoFilterShader;
267 ESCALINGMETHOD m_scalingMethod;
268 ESCALINGMETHOD m_scalingMethodGui;
270 Features m_renderFeatures;
271 Features m_deinterlaceMethods;
272 Features m_deinterlaceModes;
273 Features m_scalingMethods;
275 // clear colour for "black" bars
278 // software scale libraries (fallback if required gl version is not available)
279 DllSwScale *m_dllSwScale;
280 struct SwsContext *m_sw_context;
281 BYTE *m_rgbBuffer; // if software scale is used, this will hold the result image
282 unsigned int m_rgbBufferSize;
284 CEvent* m_eventTexturesDone[NUM_BUFFERS];
289 inline int NP2( unsigned x )