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/>.
23 #if !defined(TARGET_POSIX) && !defined(HAS_GL)
25 #include "guilib/GraphicContext.h"
26 #include "RenderFlags.h"
27 #include "RenderFormats.h"
28 #include "BaseRenderer.h"
29 #include "guilib/D3DResource.h"
30 #include "RenderCapture.h"
31 #include "settings/VideoSettings.h"
32 #include "cores/dvdplayer/DVDCodecs/Video/DXVA.h"
33 #include "cores/dvdplayer/DVDCodecs/Video/DXVAHD.h"
34 #include "cores/VideoRenderers/RenderFlags.h"
35 #include "cores/VideoRenderers/RenderFormats.h"
37 #define ALIGN(value, alignment) (((value)+((alignment)-1))&~((alignment)-1))
38 #define CLAMP(a, min, max) ((a) > (max) ? (max) : ( (a) < (min) ? (min) : a ))
42 #define IMAGE_FLAG_WRITING 0x01 /* image is in use after a call to GetImage, caller may be reading or writing */
43 #define IMAGE_FLAG_READING 0x02 /* image is in use after a call to GetImage, caller is only reading */
44 #define IMAGE_FLAG_DYNAMIC 0x04 /* image was allocated due to a call to GetImage */
45 #define IMAGE_FLAG_RESERVED 0x08 /* image is reserved, must be asked for specifically used to preserve images */
47 #define IMAGE_FLAG_INUSE (IMAGE_FLAG_WRITING | IMAGE_FLAG_READING | IMAGE_FLAG_RESERVED)
51 class CConvolutionShader;
57 struct DVDVideoPicture;
76 RENDER_INVALID = 0x00,
93 virtual ~SVideoBuffer() {}
94 virtual void Release() {}; // Release any allocated resource
95 virtual void StartDecode() {}; // Prepare the buffer to receive data from dvdplayer
96 virtual void StartRender() {}; // dvdplayer finished filling the buffer with data
97 virtual void Clear() {}; // clear the buffer with solid black
100 // YV12 decoder textures
104 D3DLOCKED_RECT rect; // rect.pBits != NULL is used to know if the texture is locked
107 struct YUVBuffer : SVideoBuffer
109 YUVBuffer() : m_width (0), m_height(0), m_format(RENDER_FMT_NONE), m_activeplanes(0) {}
111 bool Create(ERenderFormat format, unsigned int width, unsigned int height);
112 virtual void Release();
113 virtual void StartDecode();
114 virtual void StartRender();
115 virtual void Clear();
116 unsigned int GetActivePlanes() { return m_activeplanes; }
118 SVideoPlane planes[MAX_PLANES];
121 unsigned int m_width;
122 unsigned int m_height;
123 ERenderFormat m_format;
124 unsigned int m_activeplanes;
127 struct DXVABuffer : SVideoBuffer
134 virtual void Release();
135 virtual void StartDecode();
140 class CWinRenderer : public CBaseRenderer
146 virtual void Update();
147 virtual void SetupScreenshot() {};
149 bool RenderCapture(CRenderCapture* capture);
152 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_format, unsigned int orientation);
153 virtual int GetImage(YV12Image *image, int source = AUTOSOURCE, bool readonly = false);
154 virtual void ReleaseImage(int source, bool preserve = false);
155 virtual bool AddVideoPicture(DVDVideoPicture* picture, int index);
156 virtual void FlipPage(int source);
157 virtual unsigned int PreInit();
158 virtual void UnInit();
159 virtual void Reset(); /* resets renderer after seek for example */
160 virtual bool IsConfigured() { return m_bConfigured; }
162 virtual std::vector<ERenderFormat> SupportedFormats() { return m_formats; }
164 virtual bool Supports(ERENDERFEATURE feature);
165 virtual bool Supports(EDEINTERLACEMODE mode);
166 virtual bool Supports(EINTERLACEMETHOD method);
167 virtual bool Supports(ESCALINGMETHOD method);
169 virtual EINTERLACEMETHOD AutoInterlaceMethod();
171 void RenderUpdate(bool clear, DWORD flags = 0, DWORD alpha = 255);
173 virtual unsigned int GetProcessorSize();
174 virtual void SetBufferSize(int numBuffers) { m_neededBuffers = numBuffers; }
175 virtual unsigned int GetMaxBufferSize() { return NUM_BUFFERS; }
178 virtual void Render(DWORD flags);
183 void ScaleFixedPipeline();
184 void CopyAlpha(int w, int h, unsigned char* src, unsigned char *srca, int srcstride, unsigned char* dst, unsigned char* dsta, int dststride);
185 virtual void ManageTextures();
186 void DeleteYV12Texture(int index);
187 bool CreateYV12Texture(int index);
188 void CopyYV12Texture(int dest);
189 int NextYV12Texture();
191 void SelectRenderMethod();
192 bool UpdateRenderMethod();
194 void UpdateVideoFilter();
195 void SelectSWVideoFilter();
196 void SelectPSVideoFilter();
197 void UpdatePSVideoFilter();
198 bool CreateIntermediateRenderTarget(unsigned int width, unsigned int height);
200 void RenderProcessor(DWORD flags);
201 int m_iYV12RenderBuffer;
202 int m_NumYV12Buffers;
205 SVideoBuffer *m_VideoBuffers[NUM_BUFFERS];
206 RenderMethod m_renderMethod;
207 DXVA::CProcessor *m_processor;
208 std::vector<ERenderFormat> m_formats;
210 // software scale libraries (fallback if required pixel shaders version is not available)
211 DllAvUtil *m_dllAvUtil;
212 DllAvCodec *m_dllAvCodec;
213 DllSwScale *m_dllSwScale;
214 struct SwsContext *m_sw_scale_ctx;
216 // Software rendering
217 D3DTEXTUREFILTERTYPE m_TextureFilter;
218 CD3DTexture m_SWTarget;
222 CD3DTexture m_IntermediateTarget;
224 CYUV2RGBShader* m_colorShader;
225 CConvolutionShader* m_scalerShader;
227 ESCALINGMETHOD m_scalingMethod;
228 ESCALINGMETHOD m_scalingMethodGui;
230 D3DCAPS9 m_deviceCaps;
232 bool m_bFilterInitialized;
234 int m_iRequestedMethod;
236 // clear colour for "black" bars
238 ERenderFormat m_format;
239 unsigned int m_extended_format;
241 // Width and height of the render target
242 // the separable HQ scalers need this info, but could the m_destRect be used instead?
243 unsigned int m_destWidth;
244 unsigned int m_destHeight;
250 #include "LinuxRenderer.h"