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