4 * Copyright (C) 2005-2013 Team XBMC
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)
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.
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/>.
25 #include "cores/VideoRenderers/BaseRenderer.h"
26 #include "guilib/Geometry.h"
27 #include "guilib/Resolution.h"
28 #include "threads/SharedSection.h"
29 #include "threads/Thread.h"
30 #include "settings/VideoSettings.h"
31 #include "OverlayRenderer.h"
36 namespace DXVA { class CProcessor; }
37 namespace VAAPI { class CSurfaceHolder; }
39 struct DVDVideoPicture;
41 #define ERRORBUFFSIZE 30
45 class CLinuxRendererGL;
46 class CLinuxRendererGLES;
48 class CXBMCRenderManager
52 ~CXBMCRenderManager();
54 // Functions called from the GUI
55 void GetVideoRect(CRect &source, CRect &dest);
56 float GetAspectRatio();
60 bool FrameWait(int ms);
61 void Render(bool clear, DWORD flags = 0, DWORD alpha = 255);
62 void SetupScreenshot();
64 CRenderCapture* AllocRenderCapture();
65 void ReleaseRenderCapture(CRenderCapture* capture);
66 void Capture(CRenderCapture *capture, unsigned int width, unsigned int height, int flags);
67 void ManageCaptures();
69 void SetViewMode(int iViewMode);
71 // Functions called from mplayer
73 * Called by video player to configure renderer
74 * @param width width of decoded frame
75 * @param height height of decoded frame
76 * @param d_width displayed width of frame (aspect ratio)
77 * @param d_height displayed height of frame
78 * @param fps frames per second of video
79 * @param flags see RenderFlags.h
80 * @param format see RenderFormats.h
81 * @param extended_format used by DXVA
83 * @param numbers of kept buffer references
85 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);
86 bool IsConfigured() const;
88 int AddVideoPicture(DVDVideoPicture& picture);
91 * Called by video player to flip render buffers
92 * If buffering is enabled this method does not block. In case of disabled buffering
93 * this method blocks waiting for the render thread to pass by.
94 * When buffering is used there might be no free buffer available after the call to
95 * this method. Player has to call WaitForBuffer. A free buffer will become
96 * available after the main thread has flipped front / back buffers.
98 * @param bStop reference to stop flag of calling thread
99 * @param timestamp of frame delivered with AddVideoPicture
100 * @param source depreciated
101 * @param sync signals frame, top, or bottom field
103 void FlipPage(volatile bool& bStop, double timestamp = 0.0, int source = -1, EFIELDSYNC sync = FS_NONE);
104 unsigned int PreInit();
108 void AddOverlay(CDVDOverlay* o, double pts)
110 CSharedLock lock(m_sharedSection);
111 m_overlays.AddOverlay(o, pts, m_free.front());
114 void AddCleanup(OVERLAY::COverlay* o)
116 CSharedLock lock(m_sharedSection);
117 m_overlays.AddCleanup(o);
122 RESOLUTION GetResolution();
124 static float GetMaximumFPS();
125 inline bool IsStarted() { return m_bIsStarted;}
126 double GetDisplayLatency() { return m_displayLatency; }
127 int GetSkippedFrames() { return m_QueueSkip; }
129 bool Supports(ERENDERFEATURE feature);
130 bool Supports(EDEINTERLACEMODE method);
131 bool Supports(EINTERLACEMETHOD method);
132 bool Supports(ESCALINGMETHOD method);
134 EINTERLACEMETHOD AutoInterlaceMethod(EINTERLACEMETHOD mInt);
136 static double GetPresentTime();
137 void WaitPresentTime(double presenttime);
139 CStdString GetVSyncState();
141 void UpdateResolution();
143 bool RendererHandlesPresent() const;
146 CLinuxRendererGL *m_pRenderer;
148 CLinuxRendererGLES *m_pRenderer;
149 #elif defined(HAS_DX)
150 CWinRenderer *m_pRenderer;
151 #elif defined(HAS_SDL)
152 CLinuxRenderer *m_pRenderer;
155 unsigned int GetProcessorSize();
157 // Supported pixel formats, can be called before configure
158 std::vector<ERenderFormat> SupportedFormats();
160 void Recover(); // called after resolution switch if something special is needed
162 CSharedSection& GetSection() { return m_sharedSection; };
164 void RegisterRenderUpdateCallBack(const void *ctx, RenderUpdateCallBackFn fn);
165 void RegisterRenderFeaturesCallBack(const void *ctx, RenderFeaturesCallBackFn fn);
168 * If player uses buffering it has to wait for a buffer before it calls
169 * AddVideoPicture and AddOverlay. It waits for max 50 ms before it returns -1
170 * in case no buffer is available. Player may call this in a loop and decides
171 * by itself when it wants to drop a frame.
172 * If no buffering is requested in Configure, player does not need to call this,
173 * because FlipPage will block.
175 int WaitForBuffer(volatile bool& bStop, int timeout = 100);
178 * Video player call this on flush in oder to discard any queued frames
180 void DiscardBuffer();
184 void PresentSingle(bool clear, DWORD flags, DWORD alpha);
185 void PresentFields(bool clear, DWORD flags, DWORD alpha);
186 void PresentBlend(bool clear, DWORD flags, DWORD alpha);
188 void PrepareNextRender();
190 EINTERLACEMETHOD AutoInterlaceMethodInternal(EINTERLACEMETHOD mInt);
193 CSharedSection m_sharedSection;
195 bool m_bReconfigured;
210 PRESENT_METHOD_SINGLE = 0,
211 PRESENT_METHOD_BLEND,
212 PRESENT_METHOD_WEAVE,
216 double m_displayLatency;
217 void UpdateDisplayLatency();
225 EFIELDSYNC presentfield;
226 EPRESENTMETHOD presentmethod;
227 } m_Queue[NUM_BUFFERS];
229 std::deque<int> m_free;
230 std::deque<int> m_queued;
231 std::deque<int> m_discard;
233 ERenderFormat m_format;
235 double m_presentcorr;
237 double m_errorbuff[ERRORBUFFSIZE];
239 EPRESENTSTEP m_presentstep;
241 XbmcThreads::ConditionVariable m_presentevent;
242 CCriticalSection m_presentlock;
246 OVERLAY::CRenderer m_overlays;
248 void RenderCapture(CRenderCapture* capture);
249 void RemoveCapture(CRenderCapture* capture);
250 CCriticalSection m_captCritSect;
251 std::list<CRenderCapture*> m_captures;
252 //set to true when adding something to m_captures, set to false when m_captures is made empty
253 //std::list::empty() isn't thread safe, using an extra bool will save a lock per render when no captures are requested
256 // temporary fix for RendererHandlesPresent after #2811
257 bool m_firstFlipPage;
260 extern CXBMCRenderManager g_renderManager;