From 4c3f82da55a4e9a9f2860e198b3cd9de77608bf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 12 Dec 2023 22:44:03 +0100 Subject: [PATCH] Remove ManagedTexture from HttpImageView --- Common/GPU/Vulkan/thin3d_vulkan.cpp | 2 +- Common/GPU/thin3d.h | 5 +++-- UI/Store.cpp | 10 ++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Common/GPU/Vulkan/thin3d_vulkan.cpp b/Common/GPU/Vulkan/thin3d_vulkan.cpp index ddcbd0f9a7..7a24231d3c 100644 --- a/Common/GPU/Vulkan/thin3d_vulkan.cpp +++ b/Common/GPU/Vulkan/thin3d_vulkan.cpp @@ -1685,7 +1685,7 @@ void VKContext::BindFramebufferAsTexture(Framebuffer *fbo, int binding, FBChanne break; } - boundTextures_[binding].clear(); + boundTextures_[binding].reset(nullptr); boundImageView_[binding] = renderManager_.BindFramebufferAsTexture(fb->GetFB(), binding, aspect, layer); } diff --git a/Common/GPU/thin3d.h b/Common/GPU/thin3d.h index 5f66db4a03..47ef9295a3 100644 --- a/Common/GPU/thin3d.h +++ b/Common/GPU/thin3d.h @@ -419,11 +419,12 @@ struct AutoRef { return ptr != nullptr; } - void clear() { + // Takes over ownership over newItem, so we don't need to AddRef it, the number of owners didn't change. + void reset(T *newItem) { if (ptr) { ptr->Release(); - ptr = nullptr; } + ptr = newItem; } T *ptr = nullptr; diff --git a/UI/Store.cpp b/UI/Store.cpp index 14773af044..8f31b27119 100644 --- a/UI/Store.cpp +++ b/UI/Store.cpp @@ -112,7 +112,7 @@ private: std::shared_ptr download_; std::string textureData_; - std::unique_ptr texture_; + Draw::AutoRef texture_; bool textureFailed_ = false; float fixedSizeW_ = 0.0f; float fixedSizeH_ = 0.0f; @@ -154,7 +154,9 @@ void HttpImageFileView::SetFilename(std::string filename) { if (!useIconCache_ && path_ != filename) { textureFailed_ = false; path_ = filename; - texture_.reset(nullptr); + if (texture_) { + texture_.reset(nullptr); + } } } @@ -181,7 +183,7 @@ void HttpImageFileView::Draw(UIContext &dc) { } if (!textureData_.empty()) { - texture_ = CreateManagedTextureFromFileData(dc.GetDrawContext(), (const uint8_t *)(textureData_.data()), (int)textureData_.size(), DETECT, false, "store_icon"); + texture_ = CreateTextureFromFileData(dc.GetDrawContext(), (const uint8_t *)(textureData_.data()), (int)textureData_.size(), DETECT, false, "store_icon"); if (!texture_) textureFailed_ = true; textureData_.clear(); @@ -198,7 +200,7 @@ void HttpImageFileView::Draw(UIContext &dc) { if (useIconCache_) { texture = g_iconCache.BindIconTexture(&dc, path_); } else { - texture = texture_->GetTexture(); + texture = texture_; } if (texture) {