pub struct RenderBudget { /* private fields */ }Expand description
Render time budget with graceful degradation.
Tracks elapsed time within a frame and manages degradation level to maintain responsive rendering under load.
Implementations§
Source§impl RenderBudget
impl RenderBudget
Sourcepub fn from_config(config: &FrameBudgetConfig) -> Self
pub fn from_config(config: &FrameBudgetConfig) -> Self
Create a budget from configuration.
Sourcepub fn with_controller(self, config: BudgetControllerConfig) -> Self
pub fn with_controller(self, config: BudgetControllerConfig) -> Self
Attach an adaptive budget controller to this render budget.
When a controller is attached, next_frame() feeds the measured frame
duration to the controller and applies its degradation decisions
instead of the simple threshold-based upgrade logic.
§Example
use ftui_render::budget::{RenderBudget, BudgetControllerConfig};
use std::time::Duration;
let budget = RenderBudget::new(Duration::from_millis(16))
.with_controller(BudgetControllerConfig::default());Sourcepub fn remaining_fraction(&self) -> f32
pub fn remaining_fraction(&self) -> f32
Get the remaining time as a fraction of total (0.0 to 1.0).
Sourcepub fn should_degrade(&self, estimated_cost: Duration) -> bool
pub fn should_degrade(&self, estimated_cost: Duration) -> bool
Check if we should degrade given an estimated operation cost.
Returns true if the estimated cost exceeds remaining budget.
Sourcepub fn degradation(&self) -> DegradationLevel
pub fn degradation(&self) -> DegradationLevel
Get the current degradation level.
Sourcepub fn set_degradation(&mut self, level: DegradationLevel)
pub fn set_degradation(&mut self, level: DegradationLevel)
Set the degradation level directly.
Use with caution - prefer degrade() and upgrade() for gradual changes.
Sourcepub fn exhausted(&self) -> bool
pub fn exhausted(&self) -> bool
Check if the budget is exhausted.
Returns true if no time remains OR if at SkipFrame level.
Sourcepub fn should_upgrade(&self) -> bool
pub fn should_upgrade(&self) -> bool
Check if we should attempt to upgrade quality.
Returns true if more than upgrade_threshold of budget remains
and we’re not already at full quality, and cooldown has passed.
Sourcepub fn upgrade(&mut self)
pub fn upgrade(&mut self)
Upgrade to the previous (better quality) level.
Logs when upgrade occurs.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the budget for a new frame.
Keeps the current degradation level but resets timing.
Sourcepub fn next_frame(&mut self)
pub fn next_frame(&mut self)
Reset the budget and attempt upgrade if conditions are met.
Call this at the start of each frame to enable recovery.
When an adaptive controller is attached (via with_controller),
the measured frame duration is fed to the controller and its decision
(degrade / upgrade / hold) is applied automatically. The simple
threshold-based upgrade path is skipped in that case.
Sourcepub fn record_frame_time(&mut self, elapsed: Duration)
pub fn record_frame_time(&mut self, elapsed: Duration)
Record the measured render+present time for the last frame.
Sourcepub fn telemetry(&self) -> Option<BudgetTelemetry>
pub fn telemetry(&self) -> Option<BudgetTelemetry>
Get a telemetry snapshot from the adaptive controller, if attached.
Returns None if no controller is attached.
This is allocation-free and safe to call every frame.
Sourcepub fn controller(&self) -> Option<&BudgetController>
pub fn controller(&self) -> Option<&BudgetController>
Get a reference to the adaptive controller, if attached.
Sourcepub fn phase_budgets(&self) -> &PhaseBudgets
pub fn phase_budgets(&self) -> &PhaseBudgets
Get the phase budgets.
Sourcepub fn phase_has_budget(&self, phase: Phase) -> bool
pub fn phase_has_budget(&self, phase: Phase) -> bool
Check if a specific phase has budget remaining.
Sourcepub fn phase_budget(&self, phase: Phase) -> Self
pub fn phase_budget(&self, phase: Phase) -> Self
Create a sub-budget for a specific phase.
The sub-budget shares the same start time but has a phase-specific total.
Trait Implementations§
Source§impl Clone for RenderBudget
impl Clone for RenderBudget
Source§fn clone(&self) -> RenderBudget
fn clone(&self) -> RenderBudget
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more