import 'config.dart'; /// A deterministic input sequence; independent of Flutter, decoding and sampling. class ViewportBenchWorkload { const ViewportBenchWorkload({ required this.scenario, required this.hz, required this.count, required this.firstFrame, required this.lastFrame, required this.steps, required this.paired, required this.localSpanFrames, required this.timelineEndFrame, }); final int scenario, hz, count, firstFrame, lastFrame, steps, localSpanFrames; final bool paired; final double timelineEndFrame; bool get local => paired && scenario == 1; double get durationMs => 1000 * count / hz; int get warmFrame => idealFrame(0) - 1; int get cameraBaseFrame => firstFrame - 17; int idealFrame(int i) { if (local) { final phase = i % (2 * localSpanFrames); return firstFrame + (phase <= localSpanFrames ? phase : 2 * localSpanFrames - phase); } if (paired) { final half = count ~/ 2; final phase = i % count; final index = phase < half ? phase : count - 1 - phase; return (timelineEndFrame * (.05 + .9 * index / (half - 1))).round(); } final period = 2 * (steps - 1); final phase = i % period; final index = switch (scenario) { 0 => i, 1 => steps - 1 - i, _ => phase < steps ? phase : period - phase, }; return (firstFrame * (steps - 1) + (lastFrame - firstFrame) * index + (steps - 1) ~/ 2) ~/ (steps - 1); } static List forTimeline( ViewportBenchConfig config, double endFrame, ) { if (!endFrame.isFinite || endFrame < 2 * config.edgeMarginFrames + 2 || (config.expectedFrames != null && (endFrame - config.expectedFrames!).abs() > 2)) { throw StateError('Unexpected normal timeline length: $endFrame'); } final localStart = config.localStartFrame ?? (endFrame * .28).round(); if (config.paired && (localStart < 18 || localStart + config.localSpanFrames >= endFrame)) { throw StateError('Local benchmark range falls outside the timeline'); } final steps = config.inputCount ~/ 3; return List.generate(config.paired ? 2 : 5, (scenario) { final hz = config.paired ? config.inputHz : config.inputHz * [1, 2, 1, 2, 4][scenario]; final count = config.paired ? config.inputCount : [ steps, steps, config.inputCount, config.inputCount * 2, config.inputCount * 4, ][scenario]; return ViewportBenchWorkload( scenario: scenario, hz: hz, count: count, firstFrame: config.paired ? (scenario == 0 ? (endFrame * .05).round() : localStart) : config.edgeMarginFrames, lastFrame: config.paired ? (endFrame * .95).round() : endFrame.round() - config.edgeMarginFrames - 1, steps: steps, paired: config.paired, localSpanFrames: config.localSpanFrames, timelineEndFrame: endFrame, ); }); } }