[cosmetics] update date in GPL header
[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 "guilib/GraphicContext.h"
33 #include "BaseRenderer.h"
34 #include "xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodec.h"
35
36 class CRenderCapture;
37
38 class CBaseTexture;
39 namespace Shaders { class BaseYUV2RGBShader; }
40 namespace Shaders { class BaseVideoFilterShader; }
41 class COpenMaxVideo;
42 typedef std::vector<int>     Features;
43
44 #define NUM_BUFFERS 3
45
46
47 #undef ALIGN
48 #define ALIGN(value, alignment) (((value)+((alignment)-1))&~((alignment)-1))
49 #define CLAMP(a, min, max) ((a) > (max) ? (max) : ( (a) < (min) ? (min) : a ))
50
51 #define AUTOSOURCE -1
52
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)
59
60 struct DRAWRECT
61 {
62   float left;
63   float top;
64   float right;
65   float bottom;
66 };
67
68 struct YUVRANGE
69 {
70   int y_min, y_max;
71   int u_min, u_max;
72   int v_min, v_max;
73 };
74
75 struct YUVCOEF
76 {
77   float r_up, r_vp;
78   float g_up, g_vp;
79   float b_up, b_vp;
80 };
81
82 enum RenderMethod
83 {
84   RENDER_GLSL   = 0x001,
85   RENDER_SW     = 0x004,
86   RENDER_POT    = 0x010,
87   RENDER_OMXEGL = 0x040,
88   RENDER_CVREF  = 0x080,
89   RENDER_BYPASS = 0x100
90 };
91
92 enum RenderQuality
93 {
94   RQ_LOW=1,
95   RQ_SINGLEPASS,
96   RQ_MULTIPASS,
97   RQ_SOFTWARE
98 };
99
100 #define PLANE_Y 0
101 #define PLANE_U 1
102 #define PLANE_V 2
103
104 #define FIELD_FULL 0
105 #define FIELD_TOP 1
106 #define FIELD_BOT 2
107
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;
114
115 class DllSwScale;
116 struct SwsContext;
117
118 class CEvent;
119
120 class CLinuxRendererGLES : public CBaseRenderer
121 {
122 public:
123   CLinuxRendererGLES();
124   virtual ~CLinuxRendererGLES();
125
126   virtual void Update(bool bPauseDrawing);
127   virtual void SetupScreenshot() {};
128
129   bool RenderCapture(CRenderCapture* capture);
130
131   // Player functions
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();
141
142   virtual void RenderUpdate(bool clear, DWORD flags = 0, DWORD alpha = 255);
143
144   // Feature support
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);
150
151   virtual EINTERLACEMETHOD AutoInterlaceMethod();
152
153   virtual std::vector<ERenderFormat> SupportedFormats() { return m_formats; }
154
155 #ifdef HAVE_LIBOPENMAX
156   virtual void         AddProcessor(COpenMax* openMax, DVDVideoPicture *picture);
157 #endif
158 #ifdef HAVE_VIDEOTOOLBOXDECODER
159   virtual void         AddProcessor(struct __CVBuffer *cvBufferRef);
160 #endif
161
162 protected:
163   virtual void Render(DWORD flags, int index);
164
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();
171
172   // textures
173   void (CLinuxRendererGLES::*m_textureUpload)(int index);
174   void (CLinuxRendererGLES::*m_textureDelete)(int index);
175   bool (CLinuxRendererGLES::*m_textureCreate)(int index);
176
177   void UploadYV12Texture(int index);
178   void DeleteYV12Texture(int index);
179   bool CreateYV12Texture(int index);
180
181   void UploadCVRefTexture(int index);
182   void DeleteCVRefTexture(int index);
183   bool CreateCVRefTexture(int index);
184
185   void UploadBYPASSTexture(int index);
186   void DeleteBYPASSTexture(int index);
187   bool CreateBYPASSTexture(int index);
188
189   void CalculateTextureSourceRects(int source, int num_planes);
190
191   // renderers
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
197
198   CFrameBufferObject m_fbo;
199
200   int m_iYV12RenderBuffer;
201   int m_NumYV12Buffers;
202   int m_iLastRenderBuffer;
203
204   bool m_bConfigured;
205   bool m_bValidated;
206   std::vector<ERenderFormat> m_formats;
207   bool m_bImageReady;
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;
215
216   // Raw data used by renderer
217   int m_currentField;
218   int m_reloadShaders;
219
220   struct YUVPLANE
221   {
222     GLuint id;
223     CRect  rect;
224
225     float  width;
226     float  height;
227
228     unsigned texwidth;
229     unsigned texheight;
230
231     unsigned flipindex;
232   };
233
234   typedef YUVPLANE           YUVPLANES[MAX_PLANES];
235   typedef YUVPLANES          YUVFIELDS[MAX_FIELDS];
236
237   struct YUVBUFFER
238   {
239     YUVBUFFER();
240    ~YUVBUFFER();
241
242     YUVFIELDS fields;
243     YV12Image image;
244     unsigned  flipindex; /* used to decide if this has been uploaded */
245
246 #ifdef HAVE_LIBOPENMAX
247     OpenMaxVideoBuffer *openMaxBuffer;
248 #endif
249 #ifdef HAVE_VIDEOTOOLBOXDECODER
250   struct __CVBuffer *cvBufferRef;
251 #endif
252
253   };
254
255   typedef YUVBUFFER          YUVBUFFERS[NUM_BUFFERS];
256
257   // YV12 decoder textures
258   // field index 0 is full image, 1 is odd scanlines, 2 is even scanlines
259   YUVBUFFERS m_buffers;
260
261   void LoadPlane( YUVPLANE& plane, int type, unsigned flipindex
262                 , unsigned width,  unsigned height
263                 , int stride, void* data );
264
265   Shaders::BaseYUV2RGBShader     *m_pYUVShader;
266   Shaders::BaseVideoFilterShader *m_pVideoFilterShader;
267   ESCALINGMETHOD m_scalingMethod;
268   ESCALINGMETHOD m_scalingMethodGui;
269
270   Features m_renderFeatures;
271   Features m_deinterlaceMethods;
272   Features m_deinterlaceModes;
273   Features m_scalingMethods;
274
275   // clear colour for "black" bars
276   float m_clearColour;
277
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;
283
284   CEvent* m_eventTexturesDone[NUM_BUFFERS];
285
286 };
287
288
289 inline int NP2( unsigned x )
290 {
291     --x;
292     x |= x >> 1;
293     x |= x >> 2;
294     x |= x >> 4;
295     x |= x >> 8;
296     x |= x >> 16;
297     return ++x;
298 }
299 #endif
300
301 #endif