Skip to content
Browse files

Use a proper virtual destructor instead of a custom mechanism.

It did the same with more code and more room for errors down the line.
  • Loading branch information...
1 parent 01c6596 commit 9a8927040acedcdde2b2cf5d3be37b99e30dc3b5 @CrystalP CrystalP committed Jul 27, 2011
View
52 xbmc/cores/VideoRenderers/VideoShaders/WinVideoFilter.cpp
@@ -85,9 +85,17 @@ D3DXMATRIX* CYUV2RGBMatrix::Matrix()
//===================================================================
+CWinShader::~CWinShader()
+{
+ if (m_effect.Get())
+ m_effect.Release();
+
+ if (m_vb.Get())
+ m_vb.Release();
+}
+
void CWinShader::Release()
{
- ReleaseInternal(); // virtual, so calls the child function, which is supposed to call down the hierarchy
delete this;
}
@@ -122,17 +130,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());
@@ -280,6 +277,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,
@@ -354,15 +360,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 };
@@ -446,6 +443,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))
@@ -571,13 +574,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()
View
6 xbmc/cores/VideoRenderers/VideoShaders/WinVideoFilter.h
@@ -46,6 +46,7 @@ class CWinShader
{
protected:
CWinShader() {}
+ virtual ~CWinShader();
public:
void Release(); // for user code only, like the SAFE_RELEASE() construct
@@ -54,7 +55,6 @@ class 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();
@@ -78,6 +78,7 @@ class CYUV2RGBShader : public CWinShader
float brightness,
unsigned int flags,
YUVBuffer* YUVbuf);
+ virtual ~CYUV2RGBShader();
protected:
virtual void PrepareParameters(CRect sourceRect,
@@ -86,7 +87,6 @@ class CYUV2RGBShader : public CWinShader
float brightness,
unsigned int flags);
virtual void SetShaderParameters(YUVBuffer* YUVbuf);
- virtual void ReleaseInternal();
virtual bool UploadToGPU(YUVBuffer* YUVbuf);
private:
@@ -113,6 +113,7 @@ class CConvolutionShader : public CWinShader
unsigned int sourceWidth, unsigned int sourceHeight,
CRect sourceRect,
CRect destRect);
+ virtual ~CConvolutionShader();
protected:
virtual bool KernelTexFormat();
@@ -121,7 +122,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;

0 comments on commit 9a89270

Please sign in to comment.
Something went wrong with that request. Please try again.