diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index c395d681dc..83870d5bff 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -924,7 +924,7 @@ public: // PIC1 is the loading image, so let's only draw if it's available. if (ginfo && ginfo->pic1.texture) { - Draw::Texture *texture = ginfo->pic1.texture->GetTexture(); + Draw::Texture *texture = ginfo->pic1.texture; if (texture) { dc.GetDrawContext()->BindTexture(0, texture); diff --git a/UI/GameInfoCache.cpp b/UI/GameInfoCache.cpp index c3eb894c94..2a76287d2e 100644 --- a/UI/GameInfoCache.cpp +++ b/UI/GameInfoCache.cpp @@ -816,7 +816,7 @@ void GameInfoCache::SetupTexture(std::shared_ptr &info, Draw::DrawCont using namespace Draw; if (tex.data.size()) { if (!tex.texture) { - tex.texture = CreateManagedTextureFromFileData(thin3d, (const uint8_t *)tex.data.data(), (int)tex.data.size(), ImageFileType::DETECT, false, info->GetTitle().c_str()); + tex.texture = CreateTextureFromFileData(thin3d, (const uint8_t *)tex.data.data(), (int)tex.data.size(), ImageFileType::DETECT, false, info->GetTitle().c_str()); if (tex.texture) { tex.timeLoaded = time_now_d(); } else { diff --git a/UI/GameInfoCache.h b/UI/GameInfoCache.h index 6ec6b0ddfa..17fd529e1b 100644 --- a/UI/GameInfoCache.h +++ b/UI/GameInfoCache.h @@ -64,18 +64,22 @@ enum class IdentifiedFileType; struct GameInfoTex { std::string data; - std::unique_ptr texture; + Draw::Texture *texture = nullptr; // The time at which the Icon and the BG were loaded. // Can be useful to fade them in smoothly once they appear. double timeLoaded = 0.0; std::atomic dataLoaded{}; + // Can ONLY be called from the main thread! void Clear() { if (!data.empty()) { data.clear(); dataLoaded = false; } - texture.reset(nullptr); + if (texture) { + texture->Release(); + texture = nullptr; + } } }; diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 43dab5c025..2de67dd0ce 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -231,7 +231,7 @@ void GameButton::Draw(UIContext &dc) { using namespace UI; if (ginfo->icon.texture) { - texture = ginfo->icon.texture->GetTexture(); + texture = ginfo->icon.texture; } int x = bounds_.x; @@ -1425,7 +1425,7 @@ bool MainScreen::DrawBackgroundFor(UIContext &dc, const Path &gamePath, float pr } auto pic = ginfo->GetBGPic(); - Draw::Texture *texture = pic ? pic->texture->GetTexture() : nullptr; + Draw::Texture *texture = pic ? pic->texture : nullptr; uint32_t color = whiteAlpha(ease(progress)) & 0xFFc0c0c0; if (texture) { diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index 89dc438d65..9c1d05d75f 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -269,7 +269,7 @@ private: if (!pic) return; - dc.GetDrawContext()->BindTexture(0, pic->texture->GetTexture()); + dc.GetDrawContext()->BindTexture(0, pic->texture); uint32_t color = whiteAlpha(amount) & 0xFFc0c0c0; dc.Draw()->DrawTexRect(dc.GetBounds(), 0, 0, 1, 1, color); dc.Flush(); @@ -379,7 +379,7 @@ void DrawGameBackground(UIContext &dc, const Path &gamePath, float x, float y, f GameInfoTex *pic = ginfo ? ginfo->GetBGPic() : nullptr; if (pic) { - dc.GetDrawContext()->BindTexture(0, pic->texture->GetTexture()); + dc.GetDrawContext()->BindTexture(0, pic->texture); uint32_t color = whiteAlpha(ease((time_now_d() - pic->timeLoaded) * 3)) & 0xFFc0c0c0; dc.Draw()->DrawTexRect(dc.GetBounds(), 0,0,1,1, color); dc.Flush(); diff --git a/UI/SavedataScreen.cpp b/UI/SavedataScreen.cpp index de24b953b0..8d970a9988 100644 --- a/UI/SavedataScreen.cpp +++ b/UI/SavedataScreen.cpp @@ -300,7 +300,7 @@ void SavedataButton::Draw(UIContext &dc) { using namespace UI; if (ginfo->icon.texture) { - texture = ginfo->icon.texture->GetTexture(); + texture = ginfo->icon.texture; } int x = bounds_.x; @@ -736,7 +736,7 @@ void GameIconView::Draw(UIContext &dc) { float nw = std::min(bounds_.h * textureWidth_ / textureHeight_, (float)bounds_.w); dc.Flush(); - dc.GetDrawContext()->BindTexture(0, info->icon.texture->GetTexture()); + dc.GetDrawContext()->BindTexture(0, info->icon.texture); dc.Draw()->Rect(bounds_.x, bounds_.y, nw, bounds_.h, color); dc.Flush(); dc.RebindTexture();