#include <asset_manager.hpp>
Public Member Functions | |
| AssetManager () | |
| ~AssetManager () | |
| void | register_embedded (const std::string &name, const uint8_t *data, size_t size) |
| Register an embedded resource (called by generated code from pulp_add_binary_data). | |
| bool | has_embedded (const std::string &name) const |
| Check if an embedded resource exists. | |
| ImageData | load_image (const std::string &path) |
| Load image from file path. Returns cached if available. | |
| ImageData | load_image_from_memory (const uint8_t *data, size_t size) |
| Load image from memory buffer (PNG/JPEG bytes). | |
| ImageData | load_image_embedded (const std::string &name) |
| Load image from embedded resource by name. | |
| ImageData | load_image_from_data_uri (const std::string &uri) |
| Load image from data: URI (base64-encoded PNG/JPEG). | |
| FontData | load_font (const std::string &path) |
| Load font from file path. | |
| FontData | load_font_embedded (const std::string &name) |
| Load font from embedded resource. | |
| void | register_font_family (const std::string &family, const std::string &path_or_name) |
| Register a font in the font fallback chain. | |
| FontData | font_for_family (const std::string &family) const |
| Get font data for a family name (walks fallback chain). | |
| void | set_font_fallback (std::vector< std::string > families) |
| Set the font fallback chain. | |
| const std::vector< std::string > & | font_fallback () const |
| ShaderData | load_shader (const std::string &path) |
| Load shader source from file path. | |
| ShaderData | load_shader_embedded (const std::string &name) |
| Load shader from embedded resource. | |
| void | register_shader (const std::string &name, std::string source) |
| Register a shader string directly. | |
| ShaderData | shader (const std::string &name) const |
| Get a registered/loaded shader by name. | |
| BlobData | load_blob (const std::string &path) |
| Load raw bytes from file path. | |
| void | set_max_file_bytes (size_t bytes) |
| size_t | max_file_bytes () const |
| BlobData | load_blob_embedded (const std::string &name) |
| Load raw bytes from embedded resource. | |
| void | load_image_async (const std::string &path, std::function< void(ImageData)> callback) |
| Load an image asynchronously. | |
| void | set_max_cache_size (size_t bytes) |
| Set maximum cache size in bytes. Default: 64 MB. | |
| size_t | max_cache_size () const |
| size_t | cache_usage () const |
| Current cache usage in bytes. | |
| size_t | cache_count () const |
| Number of cached entries. | |
| void | clear_cache () |
| Clear all cached assets. | |
| void | evict_lru () |
| Evict least-recently-used entries until cache fits within max size. | |
| void | set_display_scale (float scale) |
| Set display scale for retina-aware asset resolution. | |
| float | display_scale () const |
Static Public Member Functions | |
| static AssetManager & | instance () |
| Get the singleton instance. | |
| static std::vector< uint8_t > | decode_data_uri_bytes (std::string_view uri) |
| The payload of a data: URI as encoded bytes, whatever their format; dimensions are left to a decoder. | |
Static Public Attributes | |
| static constexpr size_t | kDefaultMaxFileBytes = size_t{256} * 1024 * 1024 |
| Ceiling for one file read through load_blob / load_image / load_font / load_shader. | |
| pulp::view::AssetManager::AssetManager | ( | ) |
| pulp::view::AssetManager::~AssetManager | ( | ) |
| size_t pulp::view::AssetManager::cache_count | ( | ) | const |
Number of cached entries.
|
inline |
Current cache usage in bytes.
| void pulp::view::AssetManager::clear_cache | ( | ) |
Clear all cached assets.
|
static |
The payload of a data: URI as encoded bytes, whatever their format; dimensions are left to a decoder.
Per RFC 2397 a payload marked ;base64 is base64-decoded (leniently) and any other payload is percent-decoded. Empty when the URI has no comma, no payload, or a malformed percent escape.
|
inline |
| void pulp::view::AssetManager::evict_lru | ( | ) |
Evict least-recently-used entries until cache fits within max size.
|
inline |
| FontData pulp::view::AssetManager::font_for_family | ( | const std::string & | family | ) | const |
Get font data for a family name (walks fallback chain).
| bool pulp::view::AssetManager::has_embedded | ( | const std::string & | name | ) | const |
Check if an embedded resource exists.
|
static |
Get the singleton instance.
| BlobData pulp::view::AssetManager::load_blob | ( | const std::string & | path | ) |
Load raw bytes from file path.
Refused (invalid blob) when the file is larger than max_file_bytes().
| BlobData pulp::view::AssetManager::load_blob_embedded | ( | const std::string & | name | ) |
Load raw bytes from embedded resource.
| FontData pulp::view::AssetManager::load_font | ( | const std::string & | path | ) |
Load font from file path.
| FontData pulp::view::AssetManager::load_font_embedded | ( | const std::string & | name | ) |
Load font from embedded resource.
| ImageData pulp::view::AssetManager::load_image | ( | const std::string & | path | ) |
Load image from file path. Returns cached if available.
| void pulp::view::AssetManager::load_image_async | ( | const std::string & | path, |
| std::function< void(ImageData)> | callback ) |
Load an image asynchronously.
Callback is called on the calling thread's next poll() or on a background thread (implementation-defined).
| ImageData pulp::view::AssetManager::load_image_embedded | ( | const std::string & | name | ) |
Load image from embedded resource by name.
| ImageData pulp::view::AssetManager::load_image_from_data_uri | ( | const std::string & | uri | ) |
Load image from data: URI (base64-encoded PNG/JPEG).
| ImageData pulp::view::AssetManager::load_image_from_memory | ( | const uint8_t * | data, |
| size_t | size ) |
Load image from memory buffer (PNG/JPEG bytes).
| ShaderData pulp::view::AssetManager::load_shader | ( | const std::string & | path | ) |
Load shader source from file path.
| ShaderData pulp::view::AssetManager::load_shader_embedded | ( | const std::string & | name | ) |
Load shader from embedded resource.
|
inline |
|
inline |
| void pulp::view::AssetManager::register_embedded | ( | const std::string & | name, |
| const uint8_t * | data, | ||
| size_t | size ) |
Register an embedded resource (called by generated code from pulp_add_binary_data).
| void pulp::view::AssetManager::register_font_family | ( | const std::string & | family, |
| const std::string & | path_or_name ) |
Register a font in the font fallback chain.
| void pulp::view::AssetManager::register_shader | ( | const std::string & | name, |
| std::string | source ) |
Register a shader string directly.
|
inline |
Set display scale for retina-aware asset resolution.
When loading "icon.png" at scale 2, will try "icon@2x.png" first.
| void pulp::view::AssetManager::set_font_fallback | ( | std::vector< std::string > | families | ) |
Set the font fallback chain.
| void pulp::view::AssetManager::set_max_cache_size | ( | size_t | bytes | ) |
Set maximum cache size in bytes. Default: 64 MB.
| void pulp::view::AssetManager::set_max_file_bytes | ( | size_t | bytes | ) |
| ShaderData pulp::view::AssetManager::shader | ( | const std::string & | name | ) | const |
Get a registered/loaded shader by name.
|
staticconstexpr |
Ceiling for one file read through load_blob / load_image / load_font / load_shader.
A script-chosen path reaches these loaders through the widget bridge, so an uncapped read lets a UI pin an arbitrarily large file into memory. Default 256 MiB; 0 disables the ceiling.