Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::view::AssetManager Class Reference

#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.

Constructor & Destructor Documentation

◆ AssetManager()

pulp::view::AssetManager::AssetManager ( )

◆ ~AssetManager()

pulp::view::AssetManager::~AssetManager ( )

Member Function Documentation

◆ cache_count()

size_t pulp::view::AssetManager::cache_count ( ) const

Number of cached entries.

◆ cache_usage()

size_t pulp::view::AssetManager::cache_usage ( ) const
inline

Current cache usage in bytes.

◆ clear_cache()

void pulp::view::AssetManager::clear_cache ( )

Clear all cached assets.

◆ decode_data_uri_bytes()

std::vector< uint8_t > pulp::view::AssetManager::decode_data_uri_bytes ( std::string_view uri)
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.

◆ display_scale()

float pulp::view::AssetManager::display_scale ( ) const
inline

◆ evict_lru()

void pulp::view::AssetManager::evict_lru ( )

Evict least-recently-used entries until cache fits within max size.

◆ font_fallback()

const std::vector< std::string > & pulp::view::AssetManager::font_fallback ( ) const
inline

◆ font_for_family()

FontData pulp::view::AssetManager::font_for_family ( const std::string & family) const

Get font data for a family name (walks fallback chain).

◆ has_embedded()

bool pulp::view::AssetManager::has_embedded ( const std::string & name) const

Check if an embedded resource exists.

◆ instance()

AssetManager & pulp::view::AssetManager::instance ( )
static

Get the singleton instance.

◆ load_blob()

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().

◆ load_blob_embedded()

BlobData pulp::view::AssetManager::load_blob_embedded ( const std::string & name)

Load raw bytes from embedded resource.

◆ load_font()

FontData pulp::view::AssetManager::load_font ( const std::string & path)

Load font from file path.

◆ load_font_embedded()

FontData pulp::view::AssetManager::load_font_embedded ( const std::string & name)

Load font from embedded resource.

◆ load_image()

ImageData pulp::view::AssetManager::load_image ( const std::string & path)

Load image from file path. Returns cached if available.

◆ load_image_async()

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).

◆ load_image_embedded()

ImageData pulp::view::AssetManager::load_image_embedded ( const std::string & name)

Load image from embedded resource by name.

◆ load_image_from_data_uri()

ImageData pulp::view::AssetManager::load_image_from_data_uri ( const std::string & uri)

Load image from data: URI (base64-encoded PNG/JPEG).

◆ load_image_from_memory()

ImageData pulp::view::AssetManager::load_image_from_memory ( const uint8_t * data,
size_t size )

Load image from memory buffer (PNG/JPEG bytes).

◆ load_shader()

ShaderData pulp::view::AssetManager::load_shader ( const std::string & path)

Load shader source from file path.

◆ load_shader_embedded()

ShaderData pulp::view::AssetManager::load_shader_embedded ( const std::string & name)

Load shader from embedded resource.

◆ max_cache_size()

size_t pulp::view::AssetManager::max_cache_size ( ) const
inline

◆ max_file_bytes()

size_t pulp::view::AssetManager::max_file_bytes ( ) const
inline

◆ register_embedded()

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).

◆ register_font_family()

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.

◆ register_shader()

void pulp::view::AssetManager::register_shader ( const std::string & name,
std::string source )

Register a shader string directly.

◆ set_display_scale()

void pulp::view::AssetManager::set_display_scale ( float scale)
inline

Set display scale for retina-aware asset resolution.

When loading "icon.png" at scale 2, will try "icon@2x.png" first.

◆ set_font_fallback()

void pulp::view::AssetManager::set_font_fallback ( std::vector< std::string > families)

Set the font fallback chain.

◆ set_max_cache_size()

void pulp::view::AssetManager::set_max_cache_size ( size_t bytes)

Set maximum cache size in bytes. Default: 64 MB.

◆ set_max_file_bytes()

void pulp::view::AssetManager::set_max_file_bytes ( size_t bytes)

◆ shader()

ShaderData pulp::view::AssetManager::shader ( const std::string & name) const

Get a registered/loaded shader by name.

Member Data Documentation

◆ kDefaultMaxFileBytes

size_t pulp::view::AssetManager::kDefaultMaxFileBytes = size_t{256} * 1024 * 1024
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.


The documentation for this class was generated from the following file: