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"
33 #include "PlatformDefs.h"
37 namespace DXVA { class CProcessor; }
38 namespace VAAPI { class CSurfaceHolder; }
39 namespace VDPAU { class CVdpauRenderPicture; }
40 struct DVDVideoPicture;
42 #define ERRORBUFFSIZE 30
46 class CLinuxRendererGL;
47 class CLinuxRendererGLES;
49 class CXBMCRenderManager
53 ~CXBMCRenderManager();
55 // Functions called from the GUI
56 void GetVideoRect(CRect &source, CRect &dest);
57 float GetAspectRatio();
61 bool FrameWait(int ms);
62 void Render(bool clear, DWORD flags = 0, DWORD alpha = 255);
63 void SetupScreenshot();
65 CRenderCapture* AllocRenderCapture();
66 void ReleaseRenderCapture(CRenderCapture* capture);
67 void Capture(CRenderCapture *capture, unsigned int width, unsigned int height, int flags);
68 void ManageCaptures();
70 void SetViewMode(int iViewMode);
72 // Functions called from mplayer
74 * Called by video player to configure renderer
75 * @param width width of decoded frame
76 * @param height height of decoded frame
77 * @param d_width displayed width of frame (aspect ratio)
78 * @param d_height displayed height of frame
79 * @param fps frames per second of video
80 * @param flags see RenderFlags.h
81 * @param format see RenderFormats.h
82 * @param extended_format used by DXVA
84 * @param numbers of kept buffer references
86 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);
87 bool IsConfigured() const;
89 int AddVideoPicture(DVDVideoPicture& picture);
92 * Called by video player to flip render buffers
93 * If buffering is enabled this method does not block. In case of disabled buffering
94 * this method blocks waiting for the render thread to pass by.
95 * When buffering is used there might be no free buffer available after the call to
96 * this method. Player has to call WaitForBuffer. A free buffer will become
97 * available after the main thread has flipped front / back buffers.
99 * @param bStop reference to stop flag of calling thread
100 * @param timestamp of frame delivered with AddVideoPicture
101 * @param source depreciated
102 * @param sync signals frame, top, or bottom field
104 void FlipPage(volatile bool& bStop, double timestamp = 0.0, int source = -1, EFIELDSYNC sync = FS_NONE);
105 unsigned int PreInit();
109 void AddOverlay(CDVDOverlay* o, double pts)
111 CSharedLock lock(m_sharedSection);
112 m_overlays.AddOverlay(o, pts, m_free.front());
115 void AddCleanup(OVERLAY::COverlay* o)
117 CSharedLock lock(m_sharedSection);
118 m_overlays.AddCleanup(o);
123 RESOLUTION GetResolution();
125 static float GetMaximumFPS();
126 inline bool IsStarted() { return m_bIsStarted;}
127 double GetDisplayLatency() { return m_displayLatency; }
128 int GetSkippedFrames() { return m_QueueSkip; }
130 bool Supports(ERENDERFEATURE feature);
131 bool Supports(EDEINTERLACEMODE method);
132 bool Supports(EINTERLACEMETHOD method);
133 bool Supports(ESCALINGMETHOD method);
135 EINTERLACEMETHOD AutoInterlaceMethod(EINTERLACEMETHOD mInt);
137 static double GetPresentTime();
138 void WaitPresentTime(double presenttime);
140 CStdString GetVSyncState();
142 void UpdateResolution();
144 bool RendererHandlesPresent() const;
147 CLinuxRendererGL *m_pRenderer;
149 CLinuxRendererGLES *m_pRenderer;
150 #elif defined(HAS_DX)
151 CWinRenderer *m_pRenderer;
152 #elif defined(HAS_SDL)
153 CLinuxRenderer *m_pRenderer;
156 unsigned int GetProcessorSize();
158 // Supported pixel formats, can be called before configure
159 std::vector<ERenderFormat> SupportedFormats();
161 void Recover(); // called after resolution switch if something special is needed
163 CSharedSection& GetSection() { return m_sharedSection; };
165 void RegisterRenderUpdateCallBack(const void *ctx, RenderUpdateCallBackFn fn);
166 void RegisterRenderFeaturesCallBack(const void *ctx, RenderFeaturesCallBackFn fn);
169 * If player uses buffering it has to wait for a buffer before it calls
170 * AddVideoPicture and AddOverlay. It waits for max 50 ms before it returns -1
171 * in case no buffer is available. Player may call this in a loop and decides
172 * by itself when it wants to drop a frame.
173 * If no buffering is requested in Configure, player does not need to call this,
174 * because FlipPage will block.
176 int WaitForBuffer(volatile bool& bStop, int timeout = 100);
179 * Video player call this on flush in oder to discard any queued frames
181 void DiscardBuffer();
185 void PresentSingle(bool clear, DWORD flags, DWORD alpha);
186 void PresentFields(bool clear, DWORD flags, DWORD alpha);
187 void PresentBlend(bool clear, DWORD flags, DWORD alpha);
189 void PrepareNextRender();
191 EINTERLACEMETHOD AutoInterlaceMethodInternal(EINTERLACEMETHOD mInt);
194 CSharedSection m_sharedSection;
196 bool m_bReconfigured;
211 PRESENT_METHOD_SINGLE = 0,
212 PRESENT_METHOD_BLEND,
213 PRESENT_METHOD_WEAVE,
217 double m_displayLatency;
218 void UpdateDisplayLatency();
226 EFIELDSYNC presentfield;
227 EPRESENTMETHOD presentmethod;
228 } m_Queue[NUM_BUFFERS];
230 std::deque<int> m_free;
231 std::deque<int> m_queued;
232 std::deque<int> m_discard;
234 ERenderFormat m_format;
236 double m_presentcorr;
238 double m_errorbuff[ERRORBUFFSIZE];
240 EPRESENTSTEP m_presentstep;
242 XbmcThreads::ConditionVariable m_presentevent;
243 CCriticalSection m_presentlock;
247 OVERLAY::CRenderer m_overlays;
249 void RenderCapture(CRenderCapture* capture);
250 void RemoveCapture(CRenderCapture* capture);
251 CCriticalSection m_captCritSect;
252 std::list<CRenderCapture*> m_captures;
253 //set to true when adding something to m_captures, set to false when m_captures is made empty
254 //std::list::empty() isn't thread safe, using an extra bool will save a lock per render when no captures are requested
257 // temporary fix for RendererHandlesPresent after #2811
258 bool m_firstFlipPage;
261 extern CXBMCRenderManager g_renderManager;