Dala.Media.Texture (dala v0.3.2)

Copy Markdown View Source

GPU texture pool to avoid constant allocation/deallocation.

Pre-allocates a pool of GPU textures and recycles them. Critical for avoiding stutter and memory fragmentation during video playback.

Example

{:ok, pool} = Dala.Media.Texture.new_pool(1920, 1088, count: 8)

# Acquire a texture (blocks if none available)
texture_id = Dala.Media.Texture.acquire(pool)

# Use the texture...
Dala.Gpu.blit(surface, texture_id, 0, 0)

# Release back to pool
Dala.Media.Texture.release(pool, texture_id)

Summary

Functions

Acquire a texture from the pool. Returns texture_id.

Returns a specification to start this module under a supervisor.

Destroy the pool and release all textures.

Create a texture pool with the given dimensions.

Release a texture back to the pool.

Get pool statistics.

Types

pool_ref()

@type pool_ref() :: pid()

texture_id()

@type texture_id() :: non_neg_integer()

Functions

acquire(pid, timeout \\ 5000)

@spec acquire(pool_ref(), timeout()) :: texture_id() | nil

Acquire a texture from the pool. Returns texture_id.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

destroy_pool(pid)

@spec destroy_pool(pool_ref()) :: :ok

Destroy the pool and release all textures.

new_pool(width, height, opts \\ [])

@spec new_pool(non_neg_integer(), non_neg_integer(), keyword()) ::
  {:ok, pool_ref()} | {:error, term()}

Create a texture pool with the given dimensions.

release(pid, texture_id)

@spec release(pool_ref(), texture_id()) :: :ok

Release a texture back to the pool.

stats(pid)

@spec stats(pool_ref()) :: %{
  available: non_neg_integer(),
  in_use: non_neg_integer(),
  total: non_neg_integer()
}

Get pool statistics.