From f448c6e291cc4207e3978ff5510c66f0d4d8dd29 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 21 Dec 2015 14:11:01 -0500 Subject: [PATCH] FramebufferManagerBase: Get rid of explicit delete and new --- .../VideoBackends/D3D/FramebufferManager.cpp | 9 +++-- .../VideoBackends/D3D/FramebufferManager.h | 9 ++--- .../VideoBackends/OGL/FramebufferManager.cpp | 6 ++-- .../VideoBackends/OGL/FramebufferManager.h | 6 ++-- .../VideoCommon/FramebufferManagerBase.cpp | 35 +++++++------------ .../Core/VideoCommon/FramebufferManagerBase.h | 10 +++--- 6 files changed, 37 insertions(+), 38 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/FramebufferManager.cpp b/Source/Core/VideoBackends/D3D/FramebufferManager.cpp index c4881ec0f2..968337a1b0 100644 --- a/Source/Core/VideoBackends/D3D/FramebufferManager.cpp +++ b/Source/Core/VideoBackends/D3D/FramebufferManager.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include + #include "Core/HW/Memmap.h" #include "VideoBackends/D3D/D3DBase.h" #include "VideoBackends/D3D/D3DUtil.h" @@ -13,7 +15,8 @@ #include "VideoBackends/D3D/XFBEncoder.h" #include "VideoCommon/VideoConfig.h" -namespace DX11 { +namespace DX11 +{ static XFBEncoder s_xfbEncoder; @@ -176,9 +179,9 @@ void FramebufferManager::CopyToRealXFB(u32 xfbAddr, u32 fbStride, u32 fbHeight, s_xfbEncoder.Encode(dst, fbStride/2, fbHeight, sourceRc, Gamma); } -XFBSourceBase* FramebufferManager::CreateXFBSource(unsigned int target_width, unsigned int target_height, unsigned int layers) +std::unique_ptr FramebufferManager::CreateXFBSource(unsigned int target_width, unsigned int target_height, unsigned int layers) { - return new XFBSource(D3DTexture2D::Create(target_width, target_height, + return std::make_unique(D3DTexture2D::Create(target_width, target_height, (D3D11_BIND_FLAG)(D3D11_BIND_RENDER_TARGET|D3D11_BIND_SHADER_RESOURCE), D3D11_USAGE_DEFAULT, DXGI_FORMAT_R8G8B8A8_UNORM, 1, layers), layers); } diff --git a/Source/Core/VideoBackends/D3D/FramebufferManager.h b/Source/Core/VideoBackends/D3D/FramebufferManager.h index 9151c7ef56..8c9deffe7e 100644 --- a/Source/Core/VideoBackends/D3D/FramebufferManager.h +++ b/Source/Core/VideoBackends/D3D/FramebufferManager.h @@ -4,13 +4,14 @@ #pragma once -#include "d3d11.h" +#include +#include #include "VideoBackends/D3D/D3DTexture.h" #include "VideoCommon/FramebufferManagerBase.h" -namespace DX11 { - +namespace DX11 +{ // On the GameCube, the game sends a request for the graphics processor to // transfer its internal EFB (Embedded Framebuffer) to an area in GameCube RAM // called the XFB (External Framebuffer). The size and location of the XFB is @@ -80,7 +81,7 @@ public: } private: - XFBSourceBase* CreateXFBSource(unsigned int target_width, unsigned int target_height, unsigned int layers) override; + std::unique_ptr CreateXFBSource(unsigned int target_width, unsigned int target_height, unsigned int layers) override; void GetTargetSize(unsigned int *width, unsigned int *height) override; void CopyToRealXFB(u32 xfbAddr, u32 fbStride, u32 fbHeight, const EFBRectangle& sourceRc,float Gamma) override; diff --git a/Source/Core/VideoBackends/OGL/FramebufferManager.cpp b/Source/Core/VideoBackends/OGL/FramebufferManager.cpp index 6bde570d66..e59af17e25 100644 --- a/Source/Core/VideoBackends/OGL/FramebufferManager.cpp +++ b/Source/Core/VideoBackends/OGL/FramebufferManager.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include + #include "Common/Common.h" #include "Common/CommonFuncs.h" #include "Common/GL/GLInterfaceBase.h" @@ -623,7 +625,7 @@ void XFBSource::CopyEFB(float Gamma) } -XFBSourceBase* FramebufferManager::CreateXFBSource(unsigned int target_width, unsigned int target_height, unsigned int layers) +std::unique_ptr FramebufferManager::CreateXFBSource(unsigned int target_width, unsigned int target_height, unsigned int layers) { GLuint texture; @@ -634,7 +636,7 @@ XFBSourceBase* FramebufferManager::CreateXFBSource(unsigned int target_width, un glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0); glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA, target_width, target_height, layers, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); - return new XFBSource(texture, layers); + return std::make_unique(texture, layers); } void FramebufferManager::GetTargetSize(unsigned int *width, unsigned int *height) diff --git a/Source/Core/VideoBackends/OGL/FramebufferManager.h b/Source/Core/VideoBackends/OGL/FramebufferManager.h index a1d2895562..0aeffeb680 100644 --- a/Source/Core/VideoBackends/OGL/FramebufferManager.h +++ b/Source/Core/VideoBackends/OGL/FramebufferManager.h @@ -4,11 +4,11 @@ #pragma once -#include "Common/GL/GLUtil.h" +#include +#include "Common/GL/GLUtil.h" #include "VideoBackends/OGL/ProgramShaderCache.h" #include "VideoBackends/OGL/Render.h" - #include "VideoCommon/FramebufferManagerBase.h" // On the GameCube, the game sends a request for the graphics processor to @@ -95,7 +95,7 @@ public: static void PokeEFB(EFBAccessType type, const std::vector& data); private: - XFBSourceBase* CreateXFBSource(unsigned int target_width, unsigned int target_height, unsigned int layers) override; + std::unique_ptr CreateXFBSource(unsigned int target_width, unsigned int target_height, unsigned int layers) override; void GetTargetSize(unsigned int *width, unsigned int *height) override; void CopyToRealXFB(u32 xfbAddr, u32 fbStride, u32 fbHeight, const EFBRectangle& sourceRc,float Gamma) override; diff --git a/Source/Core/VideoCommon/FramebufferManagerBase.cpp b/Source/Core/VideoCommon/FramebufferManagerBase.cpp index b01c39a5f3..c6d5567d57 100644 --- a/Source/Core/VideoCommon/FramebufferManagerBase.cpp +++ b/Source/Core/VideoCommon/FramebufferManagerBase.cpp @@ -3,15 +3,17 @@ // Refer to the license.txt file included. #include +#include +#include #include "VideoCommon/FramebufferManagerBase.h" #include "VideoCommon/RenderBase.h" #include "VideoCommon/VideoConfig.h" FramebufferManagerBase *g_framebuffer_manager; -XFBSourceBase *FramebufferManagerBase::m_realXFBSource; // Only used in Real XFB mode +std::unique_ptr FramebufferManagerBase::m_realXFBSource; // Only used in Real XFB mode FramebufferManagerBase::VirtualXFBListType FramebufferManagerBase::m_virtualXFBList; // Only used in Virtual XFB mode -const XFBSourceBase* FramebufferManagerBase::m_overlappingXFBArray[MAX_VIRTUAL_XFB]; +std::array FramebufferManagerBase::m_overlappingXFBArray; unsigned int FramebufferManagerBase::s_last_xfb_width = 1; unsigned int FramebufferManagerBase::s_last_xfb_height = 1; @@ -20,21 +22,16 @@ unsigned int FramebufferManagerBase::m_EFBLayers = 1; FramebufferManagerBase::FramebufferManagerBase() { - m_realXFBSource = nullptr; - - // can't hurt - memset(m_overlappingXFBArray, 0, sizeof(m_overlappingXFBArray)); + // Can't hurt + m_overlappingXFBArray.fill(nullptr); } FramebufferManagerBase::~FramebufferManagerBase() { - for (VirtualXFB& vxfb : m_virtualXFBList) - { - delete vxfb.xfbSource; - } + // Necessary, as these are static members + // (they really shouldn't be and should be refactored at some point). m_virtualXFBList.clear(); - - delete m_realXFBSource; + m_realXFBSource.reset(); } const XFBSourceBase* const* FramebufferManagerBase::GetXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight, u32* xfbCountP) @@ -54,10 +51,7 @@ const XFBSourceBase* const* FramebufferManagerBase::GetRealXFBSource(u32 xfbAddr // recreate if needed if (m_realXFBSource && (m_realXFBSource->texWidth != fbWidth || m_realXFBSource->texHeight != fbHeight)) - { - delete m_realXFBSource; - m_realXFBSource = nullptr; - } + m_realXFBSource.reset(); if (!m_realXFBSource && g_framebuffer_manager) m_realXFBSource = g_framebuffer_manager->CreateXFBSource(fbWidth, fbHeight, 1); @@ -83,7 +77,7 @@ const XFBSourceBase* const* FramebufferManagerBase::GetRealXFBSource(u32 xfbAddr // Decode YUYV data from GameCube RAM m_realXFBSource->DecodeToTexture(xfbAddr, fbWidth, fbHeight); - m_overlappingXFBArray[0] = m_realXFBSource; + m_overlappingXFBArray[0] = m_realXFBSource.get(); return &m_overlappingXFBArray[0]; } @@ -109,7 +103,7 @@ const XFBSourceBase* const* FramebufferManagerBase::GetVirtualXFBSource(u32 xfbA if (AddressRangesOverlap(srcLower, srcUpper, dstLower, dstUpper)) { - m_overlappingXFBArray[xfbCount] = vxfb->xfbSource; + m_overlappingXFBArray[xfbCount] = vxfb->xfbSource.get(); ++xfbCount; } } @@ -163,10 +157,7 @@ void FramebufferManagerBase::CopyToVirtualXFB(u32 xfbAddr, u32 fbStride, u32 fbH // recreate if needed if (vxfb->xfbSource && (vxfb->xfbSource->texWidth != target_width || vxfb->xfbSource->texHeight != target_height)) - { - delete vxfb->xfbSource; - vxfb->xfbSource = nullptr; - } + vxfb->xfbSource.reset(); if (!vxfb->xfbSource) { diff --git a/Source/Core/VideoCommon/FramebufferManagerBase.h b/Source/Core/VideoCommon/FramebufferManagerBase.h index 6127037268..078652feb5 100644 --- a/Source/Core/VideoCommon/FramebufferManagerBase.h +++ b/Source/Core/VideoCommon/FramebufferManagerBase.h @@ -4,7 +4,9 @@ #pragma once +#include #include +#include #include "VideoCommon/VideoCommon.h" @@ -70,7 +72,7 @@ protected: u32 xfbWidth = 0; u32 xfbHeight = 0; - XFBSourceBase* xfbSource = nullptr; + std::unique_ptr xfbSource; }; typedef std::list VirtualXFBListType; @@ -78,7 +80,7 @@ protected: static unsigned int m_EFBLayers; private: - virtual XFBSourceBase* CreateXFBSource(unsigned int target_width, unsigned int target_height, unsigned int layers) = 0; + virtual std::unique_ptr CreateXFBSource(unsigned int target_width, unsigned int target_height, unsigned int layers) = 0; // TODO: figure out why OGL is different for this guy virtual void GetTargetSize(unsigned int *width, unsigned int *height) = 0; @@ -93,10 +95,10 @@ private: static const XFBSourceBase* const* GetRealXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight, u32* xfbCount); static const XFBSourceBase* const* GetVirtualXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight, u32* xfbCount); - static XFBSourceBase *m_realXFBSource; // Only used in Real XFB mode + static std::unique_ptr m_realXFBSource; // Only used in Real XFB mode static VirtualXFBListType m_virtualXFBList; // Only used in Virtual XFB mode - static const XFBSourceBase* m_overlappingXFBArray[MAX_VIRTUAL_XFB]; + static std::array m_overlappingXFBArray; static unsigned int s_last_xfb_width; static unsigned int s_last_xfb_height;