Skip to content

Commit

Permalink
Don't use ManagedTexture in GameInfoCache, not needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Dec 12, 2023
1 parent 82bdc9e commit 75e96df
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ class GameInfoBGView : public UI::InertView {

// 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);

Expand Down
2 changes: 1 addition & 1 deletion UI/GameInfoCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ void GameInfoCache::SetupTexture(std::shared_ptr<GameInfo> &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 {
Expand Down
8 changes: 6 additions & 2 deletions UI/GameInfoCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,22 @@ enum class IdentifiedFileType;

struct GameInfoTex {
std::string data;
std::unique_ptr<ManagedTexture> 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<bool> 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;
}
}
};

Expand Down
4 changes: 2 additions & 2 deletions UI/MainScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions UI/MiscScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class RecentGamesAnimation : public Animation {
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();
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions UI/SavedataScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 75e96df

Please sign in to comment.