Raxol.Terminal.Rendering.Backend behaviour (Raxol v2.0.1)

View Source

Behaviour definition for terminal rendering backends.

This module defines the interface that all rendering backends must implement, including GPU-accelerated backends (OpenGL, Metal, Vulkan) and software rendering.

Summary

Callbacks

Checks if the backend is available on the current system.

Gets the backend's capabilities and supported features.

Creates a rendering surface with the specified options.

Destroys a rendering surface and releases its resources.

Disables a visual effect.

Enables a visual effect on the rendering backend.

Gets rendering performance statistics.

Initializes the rendering backend with the given configuration.

Renders terminal content to the specified surface.

Updates the backend configuration.

Types

effect_type()

@type effect_type() :: :blur | :glow | :scanlines | :chromatic_aberration | :vignette

render_opts()

@type render_opts() :: [
  viewport: {integer(), integer(), pos_integer(), pos_integer()},
  scale: float(),
  vsync: boolean(),
  effects: list()
]

stats()

@type stats() :: %{
  fps: float(),
  frame_time: float(),
  draw_calls: non_neg_integer(),
  vertices: non_neg_integer(),
  memory_usage: non_neg_integer()
}

surface()

@type surface() :: %{
  id: String.t(),
  width: pos_integer(),
  height: pos_integer(),
  format: atom(),
  backend: atom()
}

terminal_buffer()

@type terminal_buffer() :: %{
  lines: list(),
  width: pos_integer(),
  height: pos_integer(),
  cursor: map(),
  colors: map()
}

Callbacks

available?()

@callback available?() :: boolean()

Checks if the backend is available on the current system.

capabilities()

@callback capabilities() :: %{
  max_texture_size: pos_integer(),
  supports_shaders: boolean(),
  supports_effects: [effect_type()],
  hardware_accelerated: boolean()
}

Gets the backend's capabilities and supported features.

create_surface(state, opts)

@callback create_surface(state :: term(), opts :: keyword()) ::
  {:ok, surface(), new_state :: term()} | {:error, reason :: term()}

Creates a rendering surface with the specified options.

destroy_surface(state, surface)

@callback destroy_surface(state :: term(), surface :: surface()) ::
  {:ok, new_state :: term()} | {:error, reason :: term()}

Destroys a rendering surface and releases its resources.

disable_effect(state, effect)

@callback disable_effect(state :: term(), effect :: effect_type()) ::
  {:ok, new_state :: term()} | {:error, reason :: term()}

Disables a visual effect.

enable_effect(state, effect, params)

@callback enable_effect(
  state :: term(),
  effect :: effect_type(),
  params :: keyword()
) :: {:ok, new_state :: term()} | {:error, reason :: term()}

Enables a visual effect on the rendering backend.

get_stats(state)

@callback get_stats(state :: term()) :: {:ok, stats(), new_state :: term()}

Gets rendering performance statistics.

init(config)

@callback init(config :: map()) :: {:ok, state :: term()} | {:error, reason :: term()}

Initializes the rendering backend with the given configuration.

render(state, surface, buffer, opts)

@callback render(
  state :: term(),
  surface :: surface(),
  buffer :: terminal_buffer(),
  opts :: render_opts()
) :: {:ok, new_state :: term()} | {:error, reason :: term()}

Renders terminal content to the specified surface.

update_config(state, config)

@callback update_config(state :: term(), config :: map()) ::
  {:ok, new_state :: term()} | {:error, reason :: term()}

Updates the backend configuration.