mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-16 16:00:30 +02:00
- Prune expired failed_ entries, which otherwise grew for the whole session. - When CreateTexture fails, wait 5 seconds before decoding and uploading again, instead of retrying every frame. - Bind a newly created texture. Callers draw right after BindIconTexture, and got whatever was bound before for the first frame. - Make DiskCacheEntry's padding explicit. 32-bit x86 Linux aligns double to 4, so its icon.cache didn't match other builds. The layout is unchanged elsewhere. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
79 lines
1.9 KiB
C++
79 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include <map>
|
|
#include <set>
|
|
#include <string_view>
|
|
#include <mutex>
|
|
#include <cstdint>
|
|
|
|
#include "Common/File/Path.h"
|
|
|
|
|
|
class UIContext;
|
|
|
|
enum class IconFormat : uint32_t {
|
|
PNG,
|
|
};
|
|
|
|
namespace Draw {
|
|
class Texture;
|
|
}
|
|
|
|
// TODO: Possibly make this smarter and use instead of ManagedTexture?
|
|
|
|
struct IconCacheStats {
|
|
size_t cachedCount;
|
|
size_t textureCount; // number of cached images that are "live" textures
|
|
size_t pending;
|
|
size_t dataSize;
|
|
};
|
|
|
|
class IconCache {
|
|
public:
|
|
// NOTE: Don't store the returned texture. Only use it to look up dimensions or other properties,
|
|
// instead call BindIconTexture every time you want to use it.
|
|
Draw::Texture *BindIconTexture(UIContext *context, std::string_view key);
|
|
|
|
// It's okay to call these from any thread.
|
|
bool MarkPending(std::string_view key); // returns false if already pending or loaded
|
|
void CancelPending(std::string_view key);
|
|
// Like CancelPending, but MarkPending refuses the key for a while, so a failing download isn't retried every frame.
|
|
void MarkFailed(std::string_view key);
|
|
bool InsertIcon(std::string_view key, IconFormat format, std::string &&pngData);
|
|
bool GetDimensions(std::string_view key, int *width, int *height);
|
|
bool Contains(std::string_view key);
|
|
|
|
void SaveToFile(FILE *file);
|
|
bool LoadFromFile(FILE *file);
|
|
|
|
void FrameUpdate();
|
|
|
|
void ClearTextures();
|
|
void ClearData();
|
|
|
|
IconCacheStats GetStats();
|
|
|
|
private:
|
|
void Decimate(int64_t maxSize);
|
|
|
|
struct Entry {
|
|
std::string data;
|
|
IconFormat format;
|
|
Draw::Texture *texture;
|
|
double insertedTimeStamp;
|
|
double usedTimeStamp;
|
|
double uploadFailedTime; // When CreateTexture last failed, or 0.
|
|
};
|
|
|
|
std::map<std::string, Entry, std::less<>> cache_;
|
|
std::set<std::string, std::less<>> pending_;
|
|
std::map<std::string, double, std::less<>> failed_; // key -> time of failure
|
|
|
|
std::mutex lock_;
|
|
|
|
double lastUpdate_ = 0.0;
|
|
double lastDecimate_ = 0.0;
|
|
};
|
|
|
|
extern IconCache g_iconCache;
|