/xbmc/cores/VideoRenderers/RenderManager.h

http://github.com/xbmc/xbmc · C Header · 260 lines · 145 code · 53 blank · 62 comment · 1 complexity · be8de625ae626badfbb9140db0e3728b MD5 · raw file

  1. #pragma once
  2. /*
  3. * Copyright (C) 2005-2013 Team XBMC
  4. * http://xbmc.org
  5. *
  6. * This Program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2, or (at your option)
  9. * any later version.
  10. *
  11. * This Program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with XBMC; see the file COPYING. If not, see
  18. * <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. #include <list>
  22. #include "cores/VideoRenderers/BaseRenderer.h"
  23. #include "guilib/Geometry.h"
  24. #include "guilib/Resolution.h"
  25. #include "threads/SharedSection.h"
  26. #include "threads/Thread.h"
  27. #include "settings/VideoSettings.h"
  28. #include "OverlayRenderer.h"
  29. #include <deque>
  30. class CRenderCapture;
  31. namespace DXVA { class CProcessor; }
  32. namespace VAAPI { class CSurfaceHolder; }
  33. namespace VDPAU { class CVdpauRenderPicture; }
  34. struct DVDVideoPicture;
  35. #define ERRORBUFFSIZE 30
  36. class CWinRenderer;
  37. class CLinuxRenderer;
  38. class CLinuxRendererGL;
  39. class CLinuxRendererGLES;
  40. class CXBMCRenderManager
  41. {
  42. public:
  43. CXBMCRenderManager();
  44. ~CXBMCRenderManager();
  45. // Functions called from the GUI
  46. void GetVideoRect(CRect &source, CRect &dest);
  47. float GetAspectRatio();
  48. void Update();
  49. void FrameMove();
  50. void FrameFinish();
  51. bool FrameWait(int ms);
  52. void Render(bool clear, DWORD flags = 0, DWORD alpha = 255);
  53. void SetupScreenshot();
  54. CRenderCapture* AllocRenderCapture();
  55. void ReleaseRenderCapture(CRenderCapture* capture);
  56. void Capture(CRenderCapture *capture, unsigned int width, unsigned int height, int flags);
  57. void ManageCaptures();
  58. void SetViewMode(int iViewMode);
  59. // Functions called from mplayer
  60. /**
  61. * Called by video player to configure renderer
  62. * @param width width of decoded frame
  63. * @param height height of decoded frame
  64. * @param d_width displayed width of frame (aspect ratio)
  65. * @param d_height displayed height of frame
  66. * @param fps frames per second of video
  67. * @param flags see RenderFlags.h
  68. * @param format see RenderFormats.h
  69. * @param extended_format used by DXVA
  70. * @param orientation
  71. * @param numbers of kept buffer references
  72. */
  73. bool Configure(unsigned int width, unsigned int height, unsigned int d_width, unsigned int d_height, float fps, unsigned flags, ERenderFormat format, unsigned extended_format, unsigned int orientation, int buffers = 0);
  74. bool IsConfigured() const;
  75. int AddVideoPicture(DVDVideoPicture& picture);
  76. /**
  77. * Called by video player to flip render buffers
  78. * If buffering is enabled this method does not block. In case of disabled buffering
  79. * this method blocks waiting for the render thread to pass by.
  80. * When buffering is used there might be no free buffer available after the call to
  81. * this method. Player has to call WaitForBuffer. A free buffer will become
  82. * available after the main thread has flipped front / back buffers.
  83. *
  84. * @param bStop reference to stop flag of calling thread
  85. * @param timestamp of frame delivered with AddVideoPicture
  86. * @param source depreciated
  87. * @param sync signals frame, top, or bottom field
  88. */
  89. void FlipPage(volatile bool& bStop, double timestamp = 0.0, int source = -1, EFIELDSYNC sync = FS_NONE);
  90. unsigned int PreInit();
  91. void UnInit();
  92. bool Flush();
  93. void AddOverlay(CDVDOverlay* o, double pts)
  94. {
  95. CSharedLock lock(m_sharedSection);
  96. m_overlays.AddOverlay(o, pts, m_free.front());
  97. }
  98. void AddCleanup(OVERLAY::COverlay* o)
  99. {
  100. CSharedLock lock(m_sharedSection);
  101. m_overlays.AddCleanup(o);
  102. }
  103. void Reset();
  104. RESOLUTION GetResolution();
  105. static float GetMaximumFPS();
  106. inline bool IsStarted() { return m_bIsStarted;}
  107. double GetDisplayLatency() { return m_displayLatency; }
  108. int GetSkippedFrames() { return m_QueueSkip; }
  109. bool Supports(ERENDERFEATURE feature);
  110. bool Supports(EDEINTERLACEMODE method);
  111. bool Supports(EINTERLACEMETHOD method);
  112. bool Supports(ESCALINGMETHOD method);
  113. EINTERLACEMETHOD AutoInterlaceMethod(EINTERLACEMETHOD mInt);
  114. static double GetPresentTime();
  115. void WaitPresentTime(double presenttime);
  116. CStdString GetVSyncState();
  117. void UpdateResolution();
  118. bool RendererHandlesPresent() const;
  119. #ifdef HAS_GL
  120. CLinuxRendererGL *m_pRenderer;
  121. #elif HAS_GLES == 2
  122. CLinuxRendererGLES *m_pRenderer;
  123. #elif defined(HAS_DX)
  124. CWinRenderer *m_pRenderer;
  125. #elif defined(HAS_SDL)
  126. CLinuxRenderer *m_pRenderer;
  127. #endif
  128. unsigned int GetProcessorSize();
  129. // Supported pixel formats, can be called before configure
  130. std::vector<ERenderFormat> SupportedFormats();
  131. void Recover(); // called after resolution switch if something special is needed
  132. CSharedSection& GetSection() { return m_sharedSection; };
  133. void RegisterRenderUpdateCallBack(const void *ctx, RenderUpdateCallBackFn fn);
  134. void RegisterRenderFeaturesCallBack(const void *ctx, RenderFeaturesCallBackFn fn);
  135. /**
  136. * If player uses buffering it has to wait for a buffer before it calls
  137. * AddVideoPicture and AddOverlay. It waits for max 50 ms before it returns -1
  138. * in case no buffer is available. Player may call this in a loop and decides
  139. * by itself when it wants to drop a frame.
  140. * If no buffering is requested in Configure, player does not need to call this,
  141. * because FlipPage will block.
  142. */
  143. int WaitForBuffer(volatile bool& bStop, int timeout = 100);
  144. /**
  145. * Video player call this on flush in oder to discard any queued frames
  146. */
  147. void DiscardBuffer();
  148. protected:
  149. void PresentSingle(bool clear, DWORD flags, DWORD alpha);
  150. void PresentFields(bool clear, DWORD flags, DWORD alpha);
  151. void PresentBlend(bool clear, DWORD flags, DWORD alpha);
  152. void PrepareNextRender();
  153. EINTERLACEMETHOD AutoInterlaceMethodInternal(EINTERLACEMETHOD mInt);
  154. bool m_bIsStarted;
  155. CSharedSection m_sharedSection;
  156. bool m_bReconfigured;
  157. int m_rendermethod;
  158. enum EPRESENTSTEP
  159. {
  160. PRESENT_IDLE = 0
  161. , PRESENT_FLIP
  162. , PRESENT_FRAME
  163. , PRESENT_FRAME2
  164. , PRESENT_READY
  165. };
  166. enum EPRESENTMETHOD
  167. {
  168. PRESENT_METHOD_SINGLE = 0,
  169. PRESENT_METHOD_BLEND,
  170. PRESENT_METHOD_WEAVE,
  171. PRESENT_METHOD_BOB,
  172. };
  173. double m_displayLatency;
  174. void UpdateDisplayLatency();
  175. int m_QueueSize;
  176. int m_QueueSkip;
  177. struct SPresent
  178. {
  179. double timestamp;
  180. EFIELDSYNC presentfield;
  181. EPRESENTMETHOD presentmethod;
  182. } m_Queue[NUM_BUFFERS];
  183. std::deque<int> m_free;
  184. std::deque<int> m_queued;
  185. std::deque<int> m_discard;
  186. ERenderFormat m_format;
  187. double m_presentcorr;
  188. double m_presenterr;
  189. double m_errorbuff[ERRORBUFFSIZE];
  190. int m_errorindex;
  191. EPRESENTSTEP m_presentstep;
  192. int m_presentsource;
  193. XbmcThreads::ConditionVariable m_presentevent;
  194. CCriticalSection m_presentlock;
  195. CEvent m_flushEvent;
  196. OVERLAY::CRenderer m_overlays;
  197. void RenderCapture(CRenderCapture* capture);
  198. void RemoveCapture(CRenderCapture* capture);
  199. CCriticalSection m_captCritSect;
  200. std::list<CRenderCapture*> m_captures;
  201. //set to true when adding something to m_captures, set to false when m_captures is made empty
  202. //std::list::empty() isn't thread safe, using an extra bool will save a lock per render when no captures are requested
  203. bool m_hasCaptures;
  204. // temporary fix for RendererHandlesPresent after #2811
  205. bool m_firstFlipPage;
  206. };
  207. extern CXBMCRenderManager g_renderManager;