From 6a9e4511b569e6390cfd7706861c79af1229ec15 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 29 Dec 2015 07:17:59 -0500 Subject: HiresTextures: Remove unnecessary header includes --- Source/Core/VideoCommon/HiresTextures.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Source/Core/VideoCommon/HiresTextures.cpp') diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp index b90dddb557..a552b63f39 100644 --- a/Source/Core/VideoCommon/HiresTextures.cpp +++ b/Source/Core/VideoCommon/HiresTextures.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -16,6 +17,7 @@ #include "Common/FileSearch.h" #include "Common/FileUtil.h" #include "Common/Flag.h" +#include "Common/Hash.h" #include "Common/MemoryUtil.h" #include "Common/StringUtil.h" #include "Common/Thread.h" -- cgit v1.2.3 From 1d01fbd2175968dea6e7e0fcf4ba6bfb83bf32b8 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 29 Dec 2015 07:21:51 -0500 Subject: HiresTextures: Make Load return a unique_ptr --- Source/Core/VideoCommon/HiresTextures.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Source/Core/VideoCommon/HiresTextures.cpp') diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp index a552b63f39..60123b9cce 100644 --- a/Source/Core/VideoCommon/HiresTextures.cpp +++ b/Source/Core/VideoCommon/HiresTextures.cpp @@ -167,11 +167,11 @@ void HiresTexture::Prefetch() // But bad luck, SOIL isn't, so TODO: remove SOIL usage here and use libpng directly // Also TODO: remove s_textureCacheAquireMutex afterwards. It won't be needed as the main mutex will be locked rarely //lk.unlock(); - HiresTexture* t = Load(base_filename, 0, 0); + std::unique_ptr texture = Load(base_filename, 0, 0); //lk.lock(); - if (t) + if (texture) { - std::shared_ptr ptr(t); + std::shared_ptr ptr(std::move(texture)); iter = s_textureCache.insert(iter, std::make_pair(base_filename, ptr)); } } @@ -366,9 +366,9 @@ std::shared_ptr HiresTexture::Search(const u8* texture, size_t tex return ptr; } -HiresTexture* HiresTexture::Load(const std::string& base_filename, u32 width, u32 height) +std::unique_ptr HiresTexture::Load(const std::string& base_filename, u32 width, u32 height) { - HiresTexture* ret = nullptr; + std::unique_ptr ret; for (int level = 0;; level++) { std::string filename = base_filename; @@ -420,7 +420,7 @@ HiresTexture* HiresTexture::Load(const std::string& base_filename, u32 width, u3 height >>= 1; if (!ret) - ret = new HiresTexture(); + ret = std::unique_ptr(new HiresTexture); ret->m_levels.push_back(l); } else -- cgit v1.2.3 From e082ebad1a08bf861957c38692bd152c3dce0975 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 29 Dec 2015 07:32:39 -0500 Subject: HiresTextures: Remove the need to explicitly free SOIL allocated data --- Source/Core/VideoCommon/HiresTextures.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'Source/Core/VideoCommon/HiresTextures.cpp') diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp index 60123b9cce..c76f389cbf 100644 --- a/Source/Core/VideoCommon/HiresTextures.cpp +++ b/Source/Core/VideoCommon/HiresTextures.cpp @@ -41,6 +41,11 @@ static std::thread s_prefetcher; static const std::string s_format_prefix = "tex1_"; +HiresTexture::Level::Level() + : data(nullptr, SOIL_free_image_data) +{ +} + void HiresTexture::Init() { s_check_native_format = false; @@ -387,7 +392,7 @@ std::unique_ptr HiresTexture::Load(const std::string& base_filenam file.ReadBytes(buffer.data(), file.GetSize()); int channels; - l.data = SOIL_load_image_from_memory(buffer.data(), (int)buffer.size(), (int*)&l.width, (int*)&l.height, &channels, SOIL_LOAD_RGBA); + l.data = SOILPointer(SOIL_load_image_from_memory(buffer.data(), (int)buffer.size(), (int*)&l.width, (int*)&l.height, &channels, SOIL_LOAD_RGBA), SOIL_free_image_data); l.data_size = (size_t)l.width * l.height * 4; if (l.data == nullptr) @@ -411,7 +416,7 @@ std::unique_ptr HiresTexture::Load(const std::string& base_filenam { ERROR_LOG(VIDEO, "Invalid custom texture size %dx%d for texture %s. This mipmap layer _must_ be %dx%d.", l.width, l.height, filename.c_str(), width, height); - SOIL_free_image_data(l.data); + l.data.reset(); break; } @@ -421,7 +426,7 @@ std::unique_ptr HiresTexture::Load(const std::string& base_filenam if (!ret) ret = std::unique_ptr(new HiresTexture); - ret->m_levels.push_back(l); + ret->m_levels.push_back(std::move(l)); } else { @@ -434,9 +439,4 @@ std::unique_ptr HiresTexture::Load(const std::string& base_filenam HiresTexture::~HiresTexture() { - for (auto& l : m_levels) - { - SOIL_free_image_data(l.data); - } } - -- cgit v1.2.3