perf(editor): native Windows preview and UI-first timeline navigation (#11)
Gitea CI / Check code and tests (push) Successful in 8m7s
Gitea CI / Build Windows x64 app (push) Successful in 5m48s
Gitea CI / Build Android APK (push) Successful in 5m59s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m17s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m22s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea CI / Check code and tests (push) Successful in 8m7s
Gitea CI / Build Windows x64 app (push) Successful in 5m48s
Gitea CI / Build Android APK (push) Successful in 5m59s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m17s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m22s
Gitea CI / Gitea CI passed (push) Successful in 2s
This commit was merged in pull request #11.
This commit is contained in:
1 parent
0ecf920669
commit
b4cb12cbe3
36 files changed
+3292
-148
No files matched your search
@@ -0,0 +1,220 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cutdex_sdk/timeline/layout.dart';
|
||||
import 'package:cutdex_sdk/timeline_ui.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
bool _replayActive = false;
|
||||
|
||||
/// Replays trackpad input through the normal full-app timeline hit-test path.
|
||||
/// An independent opt-in trace can also record physical driver events.
|
||||
void startTimelineGestureBenchFromEnvironment() {
|
||||
final trace = Platform.environment['CUTDEX_TIMELINE_GESTURE_TRACE'];
|
||||
if (trace != null && trace.isNotEmpty) {
|
||||
final file = File(trace)..parent.createSync(recursive: true);
|
||||
final sink = file.openWrite(mode: FileMode.append);
|
||||
Timer.periodic(const Duration(seconds: 1), (_) => unawaited(sink.flush()));
|
||||
GestureBinding.instance.pointerRouter.addGlobalRoute((event) {
|
||||
if (event is! PointerPanZoomStartEvent &&
|
||||
event is! PointerPanZoomUpdateEvent &&
|
||||
event is! PointerPanZoomEndEvent &&
|
||||
event is! PointerScrollEvent) {
|
||||
return;
|
||||
}
|
||||
sink.writeln(
|
||||
jsonEncode({
|
||||
'at': DateTime.now().toUtc().toIso8601String(),
|
||||
'type': event.runtimeType.toString(),
|
||||
'source': _replayActive ? 'protocol-replay' : 'driver',
|
||||
'device': event.device,
|
||||
'kind': event.kind.name,
|
||||
'control': HardwareKeyboard.instance.isControlPressed,
|
||||
'meta': HardwareKeyboard.instance.isMetaPressed,
|
||||
if (event is PointerPanZoomUpdateEvent) ...{
|
||||
'pan': [event.pan.dx, event.pan.dy],
|
||||
'scale': event.scale,
|
||||
},
|
||||
if (event is PointerScrollEvent)
|
||||
'scroll': [event.scrollDelta.dx, event.scrollDelta.dy],
|
||||
}),
|
||||
);
|
||||
});
|
||||
}
|
||||
final output = Platform.environment['CUTDEX_TIMELINE_GESTURE_BENCH'];
|
||||
if (output == null || output.isEmpty) return;
|
||||
unawaited(
|
||||
_run(output).catchError((Object error, StackTrace stack) async {
|
||||
await Directory(output).create(recursive: true);
|
||||
await File('$output/error.txt').writeAsString('$error\n$stack');
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Element? _surface() {
|
||||
Element? result;
|
||||
void visit(Element element) {
|
||||
if (element.widget case TimelineInteractionRegion(ruler: false)) {
|
||||
result = element;
|
||||
}
|
||||
element.visitChildElements(visit);
|
||||
}
|
||||
|
||||
WidgetsBinding.instance.rootElement?.visitChildElements(visit);
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<void> _run(String output) async {
|
||||
await Directory(output).create(recursive: true);
|
||||
await Future<void>.delayed(const Duration(seconds: 6));
|
||||
final element = _surface();
|
||||
if (element == null) throw StateError('Normal timeline surface is not open');
|
||||
if (HardwareKeyboard.instance.logicalKeysPressed.isNotEmpty) {
|
||||
throw StateError('Release keyboard modifiers before replay');
|
||||
}
|
||||
final region = element.widget as TimelineInteractionRegion;
|
||||
final c = region.controller;
|
||||
final box = element.findRenderObject()! as RenderBox;
|
||||
final viewport = TimelineViewportRect(
|
||||
width: box.size.width,
|
||||
height: box.size.height,
|
||||
);
|
||||
final position = box.localToGlobal(
|
||||
Offset(box.size.width * .8, box.size.height * .5),
|
||||
);
|
||||
final saved = c.camera;
|
||||
final playhead = c.playheadTick;
|
||||
final version = c.version;
|
||||
final x = saved.screenXForTick(playhead, viewport);
|
||||
if (x < 0 || x > viewport.width) throw StateError('Playhead must be visible');
|
||||
final rows = <Map<String, Object?>>[];
|
||||
const device = 7200;
|
||||
void send(PointerEvent event) =>
|
||||
GestureBinding.instance.handlePointerEvent(event);
|
||||
void start(int pointer) => send(
|
||||
PointerPanZoomStartEvent(
|
||||
pointer: pointer,
|
||||
device: device,
|
||||
position: position,
|
||||
),
|
||||
);
|
||||
void update(int pointer, Offset pan, double scale) => send(
|
||||
PointerPanZoomUpdateEvent(
|
||||
pointer: pointer,
|
||||
device: device,
|
||||
position: position,
|
||||
pan: pan,
|
||||
scale: scale,
|
||||
),
|
||||
);
|
||||
void end(int pointer) => send(
|
||||
PointerPanZoomEndEvent(
|
||||
pointer: pointer,
|
||||
device: device,
|
||||
position: position,
|
||||
),
|
||||
);
|
||||
void record(String name, {bool anchor = true}) {
|
||||
final drift = c.camera.screenXForTick(playhead, viewport) - x;
|
||||
final unchanged =
|
||||
c.playheadTick == playhead && identical(c.version, version);
|
||||
rows.add({
|
||||
'scenario': name,
|
||||
'playheadPixelDrift': drift,
|
||||
'scaleRatio': c.camera.pixelsPerTick / saved.pixelsPerTick,
|
||||
'verticalDrift': c.camera.verticalOffset - saved.verticalOffset,
|
||||
'timelineUnchanged': unchanged,
|
||||
'cameraBaseTick': c.camera.baseTick,
|
||||
'savedCameraBaseTick': saved.baseTick,
|
||||
});
|
||||
File('$output/progress.json').writeAsStringSync(jsonEncode(rows));
|
||||
if (!unchanged || (anchor && drift.abs() > .001)) {
|
||||
throw StateError('$name changed the timeline or moved the zoom anchor');
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
_replayActive = true;
|
||||
send(
|
||||
PointerAddedEvent(
|
||||
device: device,
|
||||
kind: PointerDeviceKind.trackpad,
|
||||
position: position,
|
||||
),
|
||||
);
|
||||
start(7201);
|
||||
update(7201, const Offset(50, 30), 1.2);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 16));
|
||||
update(7201, const Offset(100, 60), 1.5);
|
||||
await WidgetsBinding.instance.endOfFrame;
|
||||
record('native-pinch-with-translation');
|
||||
final pinchCamera = c.camera;
|
||||
update(7201, const Offset(140, 90), 1.5);
|
||||
await WidgetsBinding.instance.endOfFrame;
|
||||
record('pinch-scale-pauses');
|
||||
if (c.camera != pinchCamera) throw StateError('Pinch tail became a pan');
|
||||
end(7201);
|
||||
c.setCamera(saved);
|
||||
HardwareKeyboard.instance.handleKeyEvent(
|
||||
const KeyDownEvent(
|
||||
physicalKey: PhysicalKeyboardKey.controlLeft,
|
||||
logicalKey: LogicalKeyboardKey.controlLeft,
|
||||
timeStamp: Duration.zero,
|
||||
),
|
||||
);
|
||||
try {
|
||||
send(
|
||||
PointerScrollEvent(
|
||||
position: position,
|
||||
scrollDelta: const Offset(0, -120),
|
||||
),
|
||||
);
|
||||
} finally {
|
||||
HardwareKeyboard.instance.handleKeyEvent(
|
||||
const KeyUpEvent(
|
||||
physicalKey: PhysicalKeyboardKey.controlLeft,
|
||||
logicalKey: LogicalKeyboardKey.controlLeft,
|
||||
timeStamp: Duration(milliseconds: 1),
|
||||
),
|
||||
);
|
||||
}
|
||||
await WidgetsBinding.instance.endOfFrame;
|
||||
record('control-scroll-zoom');
|
||||
c.setCamera(saved);
|
||||
start(7202);
|
||||
update(7202, const Offset(-30, 0), 1);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 16));
|
||||
update(7202, const Offset(-70, 0), 1);
|
||||
await WidgetsBinding.instance.endOfFrame;
|
||||
record('plain-two-finger-pan', anchor: false);
|
||||
end(7202);
|
||||
if ((c.camera.screenXForTick(playhead, viewport) - x).abs() < 1 ||
|
||||
c.camera.pixelsPerTick != saved.pixelsPerTick) {
|
||||
throw StateError('Ordinary pan stopped working');
|
||||
}
|
||||
await File('$output/results.json').writeAsString(
|
||||
jsonEncode({
|
||||
'inputRoute':
|
||||
'GestureBinding -> normal full-app TimelineInteractionRegion',
|
||||
'inputKind': 'synthetic driver-protocol replay; not physical fingers',
|
||||
'playheadTick': playhead,
|
||||
'playheadScreenX': x,
|
||||
'rows': rows,
|
||||
}),
|
||||
);
|
||||
} finally {
|
||||
send(
|
||||
PointerRemovedEvent(
|
||||
device: device,
|
||||
kind: PointerDeviceKind.trackpad,
|
||||
position: position,
|
||||
),
|
||||
);
|
||||
c.setCamera(saved);
|
||||
_replayActive = false;
|
||||
}
|
||||
await File('$output/done.json').writeAsString(jsonEncode({'complete': true}));
|
||||
}
|
||||
Reference in new issue
Block a user