PageRenderTime 38ms CodeModel.GetById 21ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/xbmc/cores/VideoRenderers/LinuxRendererGLES.h

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