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