start method
void
start()
Starts the adapter.
Runs Phase 1 (static probe) synchronously. If the probe does not force a terminal quality, registers a SchedulerBinding.addTimingsCallback and begins Phase 2 (warm-up).
Safe to call multiple times — subsequent calls are no-ops if already running.
Implementation
void start() {
if (_running) return;
// Phase 1 — static probe
_phase = AdaptivePhase.probe;
if (!skipStaticProbeForTesting) {
final forced = _staticProbe();
if (forced != null) {
_lastChangeReason = GlassQualityChangeReason.staticProbe;
_lastP75Ms = null;
_lastP95Ms = null;
_lastFramesMeasured = 0;
// Respect minQuality even when the static probe forces a low quality.
// e.g. minQuality: GlassQuality.standard prevents fallback to minimal
// on devices where isShaderFilterSupported is a false negative.
_applyQuality(_floorQuality(forced, minQuality));
// No frame callback needed — static probe gives us a definitive answer.
return;
}
}
// Check for a usable cached quality — either developer-provided
// (initialQuality) or in-session cache (_sessionSettledQuality).
// Developer-provided takes priority over the session cache.
final cached = initialQuality ?? _sessionSettledQuality;
if (cached != null) {
// Apply the settled quality from the cache and skip Phase 2.
// Keep it within [minQuality, maxQuality] in case the config changed.
final clamped =
_floorQuality(_capQuality(maxQuality, cached), minQuality);
_lastChangeReason = GlassQualityChangeReason.restoredFromCache;
_lastP75Ms = null;
_lastP95Ms = null;
_lastFramesMeasured = 0;
_applyQuality(clamped);
_phase = AdaptivePhase.runtime;
_usedCachedQuality = true;
_running = true;
SchedulerBinding.instance.addTimingsCallback(_onFrameTimings);
return;
}
// Phase 2 — warm-up begins (no cache available)
_phase = AdaptivePhase.warmup;
_running = true;
SchedulerBinding.instance.addTimingsCallback(_onFrameTimings);
}