[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / cores / VideoRenderers / RenderManager.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2005-2013 Team XBMC
5  *      http://www.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
23 #include <list>
24
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"
32
33 class CRenderCapture;
34
35 namespace DXVA { class CProcessor; }
36 namespace VAAPI { class CSurfaceHolder; }
37 class CVDPAU;
38 struct DVDVideoPicture;
39
40 #define ERRORBUFFSIZE 30
41
42 class CWinRenderer;
43 class CLinuxRenderer;
44 class CLinuxRendererGL;
45 class CLinuxRendererGLES;
46
47 class CXBMCRenderManager
48 {
49 public:
50   CXBMCRenderManager();
51   ~CXBMCRenderManager();
52
53   // Functions called from the GUI
54   void GetVideoRect(CRect &source, CRect &dest);
55   float GetAspectRatio();
56   void Update(bool bPauseDrawing);
57   void RenderUpdate(bool clear, DWORD flags = 0, DWORD alpha = 255);
58   void SetupScreenshot();
59
60   CRenderCapture* AllocRenderCapture();
61   void ReleaseRenderCapture(CRenderCapture* capture);
62   void Capture(CRenderCapture *capture, unsigned int width, unsigned int height, int flags);
63   void ManageCaptures();
64
65   void SetViewMode(int iViewMode);
66
67   // Functions called from mplayer
68   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);
69   bool IsConfigured();
70
71   int AddVideoPicture(DVDVideoPicture& picture);
72
73   void FlipPage(volatile bool& bStop, double timestamp = 0.0, int source = -1, EFIELDSYNC sync = FS_NONE);
74   unsigned int PreInit();
75   void UnInit();
76   bool Flush();
77
78   void AddOverlay(CDVDOverlay* o, double pts)
79   {
80     CSharedLock lock(m_sharedSection);
81     m_overlays.AddOverlay(o, pts);
82   }
83
84   void AddCleanup(OVERLAY::COverlay* o)
85   {
86     CSharedLock lock(m_sharedSection);
87     m_overlays.AddCleanup(o);
88   }
89
90   void Reset();
91
92   RESOLUTION GetResolution();
93
94   float GetMaximumFPS();
95   inline bool Paused() { return m_bPauseDrawing; };
96   inline bool IsStarted() { return m_bIsStarted;}
97   double GetDisplayLatency() { return m_displayLatency; }
98
99   bool Supports(ERENDERFEATURE feature);
100   bool Supports(EDEINTERLACEMODE method);
101   bool Supports(EINTERLACEMETHOD method);
102   bool Supports(ESCALINGMETHOD method);
103
104   EINTERLACEMETHOD AutoInterlaceMethod(EINTERLACEMETHOD mInt);
105
106   double GetPresentTime();
107   void  WaitPresentTime(double presenttime);
108
109   CStdString GetVSyncState();
110
111   void UpdateResolution();
112
113 #ifdef HAS_GL
114   CLinuxRendererGL    *m_pRenderer;
115 #elif HAS_GLES == 2
116   CLinuxRendererGLES  *m_pRenderer;
117 #elif defined(HAS_DX)
118   CWinRenderer        *m_pRenderer;
119 #elif defined(HAS_SDL)
120   CLinuxRenderer      *m_pRenderer;
121 #endif
122
123   unsigned int GetProcessorSize();
124
125   // Supported pixel formats, can be called before configure
126   std::vector<ERenderFormat> SupportedFormats();
127
128   void Present();
129   void Recover(); // called after resolution switch if something special is needed
130
131   CSharedSection& GetSection() { return m_sharedSection; };
132
133   void RegisterRenderUpdateCallBack(const void *ctx, RenderUpdateCallBackFn fn);
134
135 protected:
136   void Render(bool clear, DWORD flags, DWORD alpha);
137
138   void PresentSingle(bool clear, DWORD flags, DWORD alpha);
139   void PresentFields(bool clear, DWORD flags, DWORD alpha);
140   void PresentBlend(bool clear, DWORD flags, DWORD alpha);
141
142   EINTERLACEMETHOD AutoInterlaceMethodInternal(EINTERLACEMETHOD mInt);
143
144   bool m_bPauseDrawing;   // true if we should pause rendering
145
146   bool m_bIsStarted;
147   CSharedSection m_sharedSection;
148
149   bool m_bReconfigured;
150
151   int m_rendermethod;
152
153   enum EPRESENTSTEP
154   {
155     PRESENT_IDLE     = 0
156   , PRESENT_FLIP
157   , PRESENT_FRAME
158   , PRESENT_FRAME2
159   };
160
161   enum EPRESENTMETHOD
162   {
163     PRESENT_METHOD_SINGLE = 0,
164     PRESENT_METHOD_BLEND,
165     PRESENT_METHOD_WEAVE,
166     PRESENT_METHOD_BOB,
167   };
168
169   double m_displayLatency;
170   void UpdateDisplayLatency();
171
172   double     m_presenttime;
173   double     m_presentcorr;
174   double     m_presenterr;
175   double     m_errorbuff[ERRORBUFFSIZE];
176   int        m_errorindex;
177   EFIELDSYNC m_presentfield;
178   EPRESENTMETHOD m_presentmethod;
179   EPRESENTSTEP     m_presentstep;
180   int        m_presentsource;
181   CEvent     m_presentevent;
182   CEvent     m_flushEvent;
183
184
185   OVERLAY::CRenderer m_overlays;
186
187   void RenderCapture(CRenderCapture* capture);
188   void RemoveCapture(CRenderCapture* capture);
189   CCriticalSection           m_captCritSect;
190   std::list<CRenderCapture*> m_captures;
191   //set to true when adding something to m_captures, set to false when m_captures is made empty
192   //std::list::empty() isn't thread safe, using an extra bool will save a lock per render when no captures are requested
193   bool                       m_hasCaptures; 
194 };
195
196 extern CXBMCRenderManager g_renderManager;