Raxol.Terminal.Rendering.AdaptiveFrameRate (Raxol v2.0.1)
View SourceAdaptive frame rate system for smart refresh optimization in Raxol terminals.
This module provides intelligent refresh rate management that adapts to:
- Content change frequency (static text vs animations)
- System performance and battery life
- User interaction patterns (active typing vs idle)
- Terminal focus state and visibility
- Hardware capabilities and thermal constraints
- Network latency for remote terminals
Features
Adaptive Refresh Strategies
- Content-Aware: Reduces frame rate for static content
- Interaction-Based: Higher rates during active user input
- Performance-Scaled: Adapts to system load and thermal state
- Battery-Optimized: Lower rates on battery power
- Focus-Aware: Pauses rendering when terminal is not visible
- Network-Adaptive: Adjusts for remote terminal latency
Performance Benefits
- Reduced CPU/GPU usage during idle periods
- Extended battery life on mobile devices
- Lower thermal generation and fan noise
- Better responsiveness during high-activity periods
- Smoother animations with variable refresh rates
Usage
# Initialize adaptive frame rate manager
{:ok, afr} = AdaptiveFrameRate.start_link(
target_fps: 60,
min_fps: 1,
max_fps: 120,
strategy: :adaptive
)
# Register content change
AdaptiveFrameRate.content_changed(afr, change_type: :text_update)
# Register user interaction
AdaptiveFrameRate.user_interaction(afr, interaction_type: :keystroke)
# Get current optimal frame rate
fps = AdaptiveFrameRate.get_current_fps(afr)
# Enable battery optimization
AdaptiveFrameRate.set_power_mode(afr, :battery)
Summary
Functions
Returns a specification to start this module under a supervisor.
Registers a content change to influence frame rate decisions.
Forces a specific frame rate (overrides adaptive behavior).
Gets the current optimal frame rate.
Gets comprehensive frame rate statistics.
Calculates optimal frame rate for specific content type.
Resumes adaptive frame rate behavior after forcing.
Sets the terminal focus state.
Updates the power management mode.
Updates the refresh strategy.
Enables or disables VSync.
Suggests power optimization settings based on usage pattern.
Registers user interaction to boost frame rate temporarily.
Types
@type config() :: %{ target_fps: fps(), min_fps: fps(), max_fps: fps(), strategy: refresh_strategy(), power_mode: power_mode(), enable_vsync: boolean(), thermal_throttling: boolean(), network_adaptive: boolean() }
@type content_change_type() ::
:text_update | :cursor_move | :scroll | :color_change | :animation
@type focus_state() :: :focused | :unfocused | :minimized | :occluded
@type fps() :: number()
@type interaction_type() ::
:keystroke | :mouse_move | :mouse_click | :scroll | :resize
@type power_mode() :: :performance | :balanced | :battery | :eco
@type refresh_strategy() :: :fixed | :adaptive | :content_aware | :battery_optimized
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Registers a content change to influence frame rate decisions.
Forces a specific frame rate (overrides adaptive behavior).
Gets the current optimal frame rate.
Gets comprehensive frame rate statistics.
Calculates optimal frame rate for specific content type.
Resumes adaptive frame rate behavior after forcing.
Sets the terminal focus state.
Updates the power management mode.
Updates the refresh strategy.
Enables or disables VSync.
Suggests power optimization settings based on usage pattern.
Registers user interaction to boost frame rate temporarily.