|
@@ -12,6 +12,9 @@
|
|
|
|
|
|
|
|
namespace {
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
+// Maximum number of cached placeholder textures to prevent unbounded growth
|
|
|
|
|
+constexpr size_t kMaxPlaceholderCacheSize = 8;
|
|
|
|
|
+
|
|
|
Glib::RefPtr<Gdk::Texture> make_placeholder_texture(int width, int height) {
|
|
Glib::RefPtr<Gdk::Texture> make_placeholder_texture(int width, int height) {
|
|
|
using Key = std::pair<int, int>;
|
|
using Key = std::pair<int, int>;
|
|
|
static std::map<Key, Glib::RefPtr<Gdk::Texture>> cache;
|
|
static std::map<Key, Glib::RefPtr<Gdk::Texture>> cache;
|
|
@@ -20,6 +23,11 @@ Glib::RefPtr<Gdk::Texture> make_placeholder_texture(int width, int height) {
|
|
|
if (auto it = cache.find(key); it != cache.end())
|
|
if (auto it = cache.find(key); it != cache.end())
|
|
|
return it->second;
|
|
return it->second;
|
|
|
|
|
|
|
|
|
|
+ // Limit cache size - remove oldest entry if full
|
|
|
|
|
+ if (cache.size() >= kMaxPlaceholderCacheSize) {
|
|
|
|
|
+ cache.erase(cache.begin());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const int stride = width * 4;
|
|
const int stride = width * 4;
|
|
|
std::vector<guint8> pixels(static_cast<std::size_t>(stride) * height);
|
|
std::vector<guint8> pixels(static_cast<std::size_t>(stride) * height);
|
|
|
|
|
|