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