Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
image_file_cache.hpp
Go to the documentation of this file.
1#pragma once
2
71
72#ifdef PULP_HAS_SKIA
73
74#include <chrono>
75#include <cstddef>
76#include <cstdint>
77#include <functional>
78#include <string>
79
80#include "include/core/SkRefCnt.h"
81
82class SkImage;
83
84namespace pulp::canvas {
85
86class ImageFileCache {
87public:
88 static ImageFileCache& instance();
89
99 sk_sp<SkImage> get_or_build(
100 const std::string& path,
101 const void* backend_key,
102 const std::function<sk_sp<SkImage>()>& build);
103
106 static constexpr std::size_t kDefaultFileByteBudget = 64u * 1024u * 1024u;
107
109 static constexpr std::chrono::milliseconds kFailureRetryDelay{1000};
110
113 static constexpr std::size_t kDefaultInlineByteBudget = 96u * 1024u * 1024u;
114
122 sk_sp<SkImage> get_or_build_inline(const std::string& content_key, const void* backend_key,
123 std::size_t encoded_size,
124 const std::function<sk_sp<SkImage>()>& build);
125
126 struct Stats {
127 std::uint64_t hits = 0;
128 std::uint64_t builds = 0;
129 std::size_t size = 0;
130 std::size_t bytes = 0;
132 };
134 Stats stats() const;
135
136 struct InlineStats {
137 std::uint64_t hits = 0;
138 std::uint64_t builds = 0;
139 std::uint64_t over_budget = 0;
140 std::size_t size = 0;
141 std::size_t bytes = 0;
142 };
144 InlineStats inline_stats() const;
146 void reset_stats();
147
151 void clear();
152
157 void clear_backend(const void* backend_key);
158
163 void begin_frame(const void* backend_key);
164
168 void set_enabled(bool enabled);
169 bool enabled() const;
170
173 void set_capacity(std::size_t capacity);
174 std::size_t capacity() const;
175
178 void set_byte_budget(std::size_t bytes);
179 std::size_t byte_budget() const;
180
182 void set_inline_byte_budget(std::size_t bytes);
183 std::size_t inline_byte_budget() const;
184
187 void set_clock_for_testing(std::function<std::chrono::steady_clock::time_point()> now);
188
189 private:
190 ImageFileCache() = default;
191 struct Impl;
192 // Defined in image_file_cache.cpp; stateful members live there to keep this
193 // header free of <mutex>/<list>/<unordered_map> and the full SkImage type.
194 static Impl& impl();
195};
196
197} // namespace pulp::canvas
198
199#endif // PULP_HAS_SKIA
Definition affine_transform.hpp:24
@ size
Definition config.hpp:216