Permalink
Browse files

Merge pull request #310 from CrystalP/refactor-winshaders

Refactor the Windows Shaders destruction
  • Loading branch information...
2 parents b9e483e + d2ed754 commit bbf9ea510b8d2eea8be958d0bbe7917a98710113 CrystalP committed Jul 28, 2011
@@ -85,10 +85,13 @@ D3DXMATRIX* CYUV2RGBMatrix::Matrix()
//===================================================================
-void CWinShader::Release()
+CWinShader::~CWinShader()
{
- ReleaseInternal(); // virtual, so calls the child function, which is supposed to call down the hierarchy
- delete this;
+ if (m_effect.Get())
+ m_effect.Release();
+
+ if (m_vb.Get())
+ m_vb.Release();
}
bool CWinShader::CreateVertexBuffer(DWORD FVF, unsigned int vertCount, unsigned int vertSize, unsigned int primitivesCount)
@@ -122,17 +125,6 @@ bool CWinShader::UnlockVertexBuffer()
return true;
}
-void CWinShader::ReleaseInternal()
-{
- if (m_effect.Get())
- m_effect.Release();
-
- if (m_vb.Get())
- m_vb.Release();
-
- //derived classes: always call Base::ReleaseInternal() at the end
-}
-
bool CWinShader::LoadEffect(CStdString filename, DefinesMap* defines)
{
CLog::Log(LOGDEBUG, __FUNCTION__" - loading shader %s", filename.c_str());
@@ -194,8 +186,6 @@ bool CWinShader::Execute()
bool CYUV2RGBShader::Create(unsigned int sourceWidth, unsigned int sourceHeight, BufferFormat fmt)
{
- ReleaseInternal();
-
CWinShader::CreateVertexBuffer(D3DFVF_XYZRHW | D3DFVF_TEX3, 4, sizeof(CUSTOMVERTEX), 2);
m_sourceWidth = sourceWidth;
@@ -282,6 +272,15 @@ void CYUV2RGBShader::Render(CRect sourceRect, CRect destRect,
Execute();
}
+CYUV2RGBShader::~CYUV2RGBShader()
+{
+ for(unsigned i = 0; i < MAX_PLANES; i++)
+ {
+ if (m_YUVPlanes[i].Get())
+ m_YUVPlanes[i].Release();
+ }
+}
+
void CYUV2RGBShader::PrepareParameters(CRect sourceRect,
CRect destRect,
float contrast,
@@ -356,15 +355,6 @@ void CYUV2RGBShader::SetShaderParameters(YUVBuffer* YUVbuf)
m_effect.SetFloatArray("g_StepXY", m_texSteps, sizeof(m_texSteps)/sizeof(m_texSteps[0]));
}
-void CYUV2RGBShader::ReleaseInternal()
-{
- for(unsigned i = 0; i < MAX_PLANES; i++)
- {
- if (m_YUVPlanes[i].Get())
- m_YUVPlanes[i].Release();
- }
-}
-
bool CYUV2RGBShader::UploadToGPU(YUVBuffer* YUVbuf)
{
const POINT point = { 0, 0 };
@@ -395,8 +385,6 @@ bool CYUV2RGBShader::UploadToGPU(YUVBuffer* YUVbuf)
bool CConvolutionShader::Create(ESCALINGMETHOD method)
{
- ReleaseInternal();
-
CStdString effectString;
switch(method)
{
@@ -450,6 +438,12 @@ void CConvolutionShader::Render(CD3DTexture &sourceTexture,
Execute();
}
+CConvolutionShader::~CConvolutionShader()
+{
+ if(m_HQKernelTexture.Get())
+ m_HQKernelTexture.Release();
+}
+
bool CConvolutionShader::KernelTexFormat()
{
if (g_Windowing.IsTextureFormatOk(D3DFMT_A16B16G16R16F, 0))
@@ -575,13 +569,6 @@ void CConvolutionShader::SetShaderParameters(CD3DTexture &sourceTexture, float*
m_effect.SetFloatArray("g_StepXY", texSteps, texStepsCount);
}
-void CConvolutionShader::ReleaseInternal()
-{
- if(m_HQKernelTexture.Get())
- m_HQKernelTexture.Release();
- CWinShader::ReleaseInternal();
-}
-
//==========================================================
bool CTestShader::Create()
@@ -26,11 +26,6 @@
#include "../../guilib/Geometry.h"
#include "../WinRenderer.h"
-/*
-class CBaseVideoFilter
-{
-};
-*/
class CYUV2RGBMatrix
{
@@ -51,15 +46,10 @@ class CWinShader
{
protected:
CWinShader() {}
-
-public:
- void Release(); // for user code only, like the SAFE_RELEASE() construct
-
-protected:
+ virtual ~CWinShader();
virtual bool CreateVertexBuffer(DWORD FVF, unsigned int vertCount, unsigned int vertSize, unsigned int primitivesCount);
virtual bool LockVertexBuffer(void **data);
virtual bool UnlockVertexBuffer();
- virtual void ReleaseInternal();
virtual bool LoadEffect(CStdString filename, DefinesMap* defines);
virtual bool Execute();
@@ -83,6 +73,7 @@ class CYUV2RGBShader : public CWinShader
float brightness,
unsigned int flags,
YUVBuffer* YUVbuf);
+ virtual ~CYUV2RGBShader();
protected:
virtual void PrepareParameters(CRect sourceRect,
@@ -91,7 +82,6 @@ class CYUV2RGBShader : public CWinShader
float brightness,
unsigned int flags);
virtual void SetShaderParameters(YUVBuffer* YUVbuf);
- virtual void ReleaseInternal();
virtual bool UploadToGPU(YUVBuffer* YUVbuf);
private:
@@ -118,6 +108,7 @@ class CConvolutionShader : public CWinShader
unsigned int sourceWidth, unsigned int sourceHeight,
CRect sourceRect,
CRect destRect);
+ virtual ~CConvolutionShader();
protected:
virtual bool KernelTexFormat();
@@ -126,7 +117,6 @@ class CConvolutionShader : public CWinShader
CRect sourceRect,
CRect destRect);
virtual void SetShaderParameters(CD3DTexture &sourceTexture, float* texSteps, int texStepsCount);
- virtual void ReleaseInternal();
private:
CD3DTexture m_HQKernelTexture;
@@ -164,18 +164,16 @@ void CWinRenderer::SelectRenderMethod()
// Try the pixel shaders support
if (m_deviceCaps.PixelShaderVersion >= D3DPS_VERSION(2, 0))
{
- CTestShader* shader = new CTestShader;
- if (shader->Create())
+ CTestShader shader;
+ if (shader.Create())
{
m_renderMethod = RENDER_PS;
- shader->Release();
break;
}
else
{
CLog::Log(LOGNOTICE, "D3D: unable to load test shader - D3D installation is most likely incomplete");
CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Warning, "DirectX", g_localizeStrings.Get(2101));
- shader->Release();
}
}
else
@@ -393,8 +391,8 @@ void CWinRenderer::UnInit()
if (m_IntermediateTarget.Get())
m_IntermediateTarget.Release();
- SAFE_RELEASE(m_colorShader);
- SAFE_RELEASE(m_scalerShader);
+ SAFE_DELETE(m_colorShader);
+ SAFE_DELETE(m_scalerShader);
m_bConfigured = false;
m_bFilterInitialized = false;
@@ -507,14 +505,14 @@ void CWinRenderer::SelectPSVideoFilter()
void CWinRenderer::UpdatePSVideoFilter()
{
- SAFE_RELEASE(m_scalerShader);
+ SAFE_DELETE(m_scalerShader);
if (m_bUseHQScaler)
{
m_scalerShader = new CConvolutionShader();
if (!m_scalerShader->Create(m_scalingMethod))
{
- SAFE_RELEASE(m_scalerShader);
+ SAFE_DELETE(m_scalerShader);
CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Error, "Video Renderering", "Failed to init video scaler, falling back to bilinear scaling.");
m_bUseHQScaler = false;
}
@@ -525,11 +523,11 @@ void CWinRenderer::UpdatePSVideoFilter()
if (m_bUseHQScaler && !CreateIntermediateRenderTarget())
{
- SAFE_RELEASE(m_scalerShader);
+ SAFE_DELETE(m_scalerShader);
m_bUseHQScaler = false;
}
- SAFE_RELEASE(m_colorShader);
+ SAFE_DELETE(m_colorShader);
BufferFormat format = BufferFormatFromFlags(m_flags);
@@ -540,8 +538,8 @@ void CWinRenderer::UpdatePSVideoFilter()
{
// Try again after disabling the HQ scaler and freeing its resources
m_IntermediateTarget.Release();
- SAFE_RELEASE(m_scalerShader);
- SAFE_RELEASE(m_colorShader);
+ SAFE_DELETE(m_scalerShader);
+ SAFE_DELETE(m_colorShader);
m_bUseHQScaler = false;
}
}
@@ -550,7 +548,7 @@ void CWinRenderer::UpdatePSVideoFilter()
{
m_colorShader = new CYUV2RGBShader();
if (!m_colorShader->Create(m_sourceWidth, m_sourceHeight, format))
- SAFE_RELEASE(m_colorShader);
+ SAFE_DELETE(m_colorShader);
// we're in big trouble - should fallback on D3D accelerated or sw method
}
}

0 comments on commit bbf9ea5

Please sign in to comment.