Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m47s
Gitea CI / Check code and tests (push) Successful in 7m15s
Gitea CI / Build Android APK (push) Successful in 4m6s
Gitea CI / Build Windows x64 app (push) Successful in 3m34s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m29s
Gitea CI / Gitea CI passed (push) Successful in 1s
Gitea Release / Prepare draft Release (push) Failing after 8s
Gitea Release / Upload Android to draft Release (push) Skipped
Gitea Release / Upload Windows to draft Release (push) Skipped
Gitea Release / Verify and publish Release (push) Skipped
260 lines
8.7 KiB
Dart
260 lines
8.7 KiB
Dart
import 'dart:async';
|
|
import 'dart:io';
|
|
|
|
import 'package:cutdex/features/preview/preview_panel.dart';
|
|
import 'package:cutdex_core/editor.dart';
|
|
import 'package:cutdex_native_flutter/cutdex_native_flutter.dart';
|
|
import 'package:cutdex_core/timeline/model.dart';
|
|
import 'package:cutdex_core/timeline/layout.dart';
|
|
import 'package:cutdex_timeline_ui/cutdex_timeline_ui.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'capture.dart';
|
|
import 'config.dart';
|
|
import 'diagnostics.dart';
|
|
import 'drag.dart';
|
|
import 'records.dart';
|
|
import 'workload.dart';
|
|
|
|
Future<void> _sleep(int ms) => Future<void>.delayed(Duration(milliseconds: ms));
|
|
|
|
/// Orchestrates existing editor state, real input, exact-stop validation and output.
|
|
Future<void> runFullAppViewportBench(ViewportBenchConfig config) async {
|
|
final output = Directory(config.outputPath);
|
|
final clock = Stopwatch()..start();
|
|
BenchCapture? capture;
|
|
BenchDiagnostics? diagnostics;
|
|
BenchRecords? records;
|
|
BenchPlayheadDrag? activeDrag;
|
|
await output.create(recursive: true);
|
|
try {
|
|
await _sleep(6000);
|
|
if (config.startGate case final gatePath?) {
|
|
final gate = File(gatePath);
|
|
for (var i = 0; !await gate.exists() && i < 240; i++) {
|
|
await _sleep(500);
|
|
}
|
|
if (!await gate.exists()) {
|
|
throw StateError('Benchmark start gate timed out');
|
|
}
|
|
}
|
|
Element? previewElement;
|
|
TimelineViewport? timeline;
|
|
RenderBox? ruler;
|
|
void visit(Element element) {
|
|
if (element.widget is EditorPreviewPanel) previewElement = element;
|
|
if (element.widget is TimelineViewport) {
|
|
timeline = element.widget as TimelineViewport;
|
|
}
|
|
if (element.widget is TimelineRuler) {
|
|
ruler = element.findRenderObject() as RenderBox?;
|
|
}
|
|
element.visitChildElements(visit);
|
|
}
|
|
|
|
WidgetsBinding.instance.rootElement!.visitChildElements(visit);
|
|
if (previewElement == null || timeline == null || ruler == null) {
|
|
throw StateError('Full normal editor is not open');
|
|
}
|
|
final panel = previewElement!.widget as EditorPreviewPanel;
|
|
final container = ProviderScope.containerOf(previewElement!);
|
|
final preview = container
|
|
.read(editorPreviewProvider(panel.projectId, panel.timelineId))
|
|
.asData
|
|
?.value;
|
|
if (preview?.session == null || preview!.error != null) {
|
|
throw StateError('Normal preview unavailable');
|
|
}
|
|
final sequence = preview.activeSequence()!;
|
|
final view = timeline!.controller;
|
|
final endTime = TimelineClock.standard.fromTicks(view.contentEndTick);
|
|
final endFrame =
|
|
endTime.numerator * config.timelineFps / endTime.denominator;
|
|
final workloads = ViewportBenchWorkload.forTimeline(config, endFrame);
|
|
view.fitTimeline();
|
|
await _sleep(500);
|
|
final viewport = TimelineViewportRect(
|
|
width: ruler!.size.width,
|
|
height: ruler!.size.height,
|
|
);
|
|
final scale = View.of(previewElement!).devicePixelRatio;
|
|
final clipStart = view.camera.screenXForTick(0, viewport);
|
|
final clipEnd = view.camera.screenXForTick(view.contentEndTick, viewport);
|
|
if (clipStart < 0 || clipEnd > viewport.width) {
|
|
throw StateError('Clip outside viewport');
|
|
}
|
|
final native = diagnostics = BenchDiagnostics(preview.session!, clock);
|
|
await native.calibrate();
|
|
capture = await BenchCapture.start(config, output);
|
|
final record = records = BenchRecords(output);
|
|
native.startSamples(record.samples, config.sampleIntervalMs);
|
|
int tick(int frame) =>
|
|
TimelineClock.standard.toTicks(RationalTime(frame, config.timelineFps));
|
|
|
|
for (var round = 1; round <= config.rounds; round++) {
|
|
for (final workload in workloads) {
|
|
final scenario = workload.scenario;
|
|
if (config.paired) {
|
|
if (workload.local) {
|
|
view.setCamera(
|
|
TimelineCamera(
|
|
baseTick: tick(workload.cameraBaseFrame),
|
|
pixelsPerTick: config.localPixelsPerFrame / tick(1),
|
|
verticalOffset: view.camera.verticalOffset,
|
|
),
|
|
);
|
|
} else {
|
|
view.fitTimeline();
|
|
}
|
|
await _sleep(100);
|
|
}
|
|
final warm = workload.warmFrame;
|
|
final drag = activeDrag = BenchPlayheadDrag(
|
|
view: view,
|
|
ruler: ruler!,
|
|
viewport: viewport,
|
|
scale: scale,
|
|
clock: clock,
|
|
pointer: 100 + round * 10 + scenario,
|
|
warmFrame: warm,
|
|
fps: config.timelineFps,
|
|
);
|
|
await preview.controlPreview(
|
|
sequence,
|
|
PreviewAction.seek,
|
|
at: CommandTime(warm, config.timelineFps),
|
|
);
|
|
await _sleep(80);
|
|
if (config.silent) {
|
|
await preview.session!.beginSkimming(mode: SkimmingMode.silent);
|
|
}
|
|
await drag.begin();
|
|
drag.moveTo(workload.idealFrame(0));
|
|
await _sleep(350);
|
|
final before = await native.read();
|
|
final start = native.now();
|
|
for (var i = 0; i < workload.count; i++) {
|
|
final due = start + 1000 * i / workload.hz;
|
|
await native.until(due);
|
|
final begin = native.now();
|
|
final ideal = workload.idealFrame(i);
|
|
drag.moveTo(ideal);
|
|
record.input(
|
|
round,
|
|
scenario,
|
|
i,
|
|
drag.target(ideal),
|
|
begin,
|
|
due,
|
|
native.now(),
|
|
);
|
|
}
|
|
await native.until(start + workload.durationMs);
|
|
final end = native.now();
|
|
final release = native.now();
|
|
drag.end();
|
|
activeDrag = null;
|
|
await preview.waitForPendingPreview();
|
|
final settled = await preview.session!.refresh();
|
|
final settledAt = native.now();
|
|
await _sleep(350);
|
|
final frozenBegin = native.now();
|
|
await _sleep(350);
|
|
final snapshot = await preview.session!.refresh();
|
|
final after = await native.read();
|
|
record.stages.add({
|
|
'round': round,
|
|
'scenario': scenario,
|
|
'before': before,
|
|
'after': after,
|
|
'settledAtMs': settledAt,
|
|
'settledClock':
|
|
'${settled.position.numerator}/${settled.position.denominator}',
|
|
});
|
|
final actual =
|
|
snapshot.position.numerator *
|
|
config.timelineFps /
|
|
snapshot.position.denominator;
|
|
final finalTarget = drag.target(
|
|
workload.idealFrame(workload.count - 1),
|
|
);
|
|
if ((actual - finalTarget).abs() > .01 || preview.error != null) {
|
|
throw StateError('Final precision failure $actual');
|
|
}
|
|
native.check();
|
|
record.checks.add({
|
|
'round': round,
|
|
'scenario': scenario,
|
|
'finalClockFrame': actual,
|
|
'target': finalTarget,
|
|
'state': snapshot.state.name,
|
|
});
|
|
record.phase(
|
|
round,
|
|
scenario,
|
|
start,
|
|
end,
|
|
release,
|
|
finalTarget,
|
|
actual,
|
|
frozenBegin,
|
|
native.now(),
|
|
);
|
|
}
|
|
await record.progress(round);
|
|
}
|
|
await capture?.stop();
|
|
capture = null;
|
|
await native.stopSamples();
|
|
await record.close();
|
|
await record.complete({
|
|
'status': 'passed',
|
|
'entrypoint': 'lib/main.dart',
|
|
'fullApp': true,
|
|
'startGateUsed': config.startGate != null,
|
|
'configuration': config.toJson(),
|
|
'projectId': panel.projectId,
|
|
'timelineId': panel.timelineId,
|
|
'sequenceId': sequence.value,
|
|
'timelineEndFramesAt30Hz': endFrame * 30 / config.timelineFps,
|
|
'firstSampleFrameAt30Hz':
|
|
config.edgeMarginFrames * 30 / config.timelineFps,
|
|
'lastSampleFrameAt30Hz':
|
|
(endFrame.round() - config.edgeMarginFrames - 1) *
|
|
30 /
|
|
config.timelineFps,
|
|
'clipStartX': clipStart,
|
|
'clipEndX': clipEnd,
|
|
'viewportWidth': viewport.width,
|
|
'devicePixelRatio': scale,
|
|
'qpcCalibrationRoundTripMs': native.uncertaintyMs,
|
|
'inputRoute': 'GestureBinding -> real normal TimelineViewport playhead handle -> production preview/runtime/native presenter',
|
|
'physicalPixelInput': true,
|
|
'rounds': config.rounds,
|
|
'pairedWideLocal': config.paired,
|
|
'nativeOnly': config.nativeOnly,
|
|
'silentOverride': config.silent,
|
|
'skimmingPolicy': preview.policy.skimmingMode.name,
|
|
'canvas': {
|
|
'width': preview.canvas.width,
|
|
'height': preview.canvas.height,
|
|
},
|
|
'timelineSettings': preview.timeline.settings,
|
|
});
|
|
// Leave the normal editor paused with the complete clip visible.
|
|
view.fitTimeline();
|
|
} finally {
|
|
activeDrag?.cancel();
|
|
try {
|
|
await capture?.stop();
|
|
} finally {
|
|
try {
|
|
await diagnostics?.stopSamples();
|
|
} finally {
|
|
await records?.close();
|
|
}
|
|
}
|
|
}
|
|
}
|