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

This commit was merged in pull request #11.
This commit is contained in:
lingjhf committed 2026-10-07 10:05:14 +00:00
1 parent 0ecf920669
commit b4cb12cbe3
36 files changed
+3292 -148

No files matched your search

@@ -0,0 +1,109 @@
import 'package:cutdex/diagnostics/full_app_viewport_bench/config.dart';
import 'package:cutdex/diagnostics/full_app_viewport_bench/workload.dart';
import 'package:flutter_test/flutter_test.dart';
ViewportBenchConfig config([Map<String, String> values = const {}]) =>
ViewportBenchConfig.fromEnvironment({
'CUTDEX_FULL_APP_VIEWPORT_BENCH': 'benchmark-output',
'CUTDEX_FULL_APP_VIEWPORT_PAIRED': '1',
...values.map(
(key, value) => MapEntry('CUTDEX_FULL_APP_VIEWPORT_$key', value),
),
});
void main() {
group('Full editor benchmark inputs', () {
test('existing MIDE trajectory and six-second schedule stay unchanged', () {
final workloads = ViewportBenchWorkload.forTimeline(
config({'LOCAL_START_FRAME': '60137', 'EXPECTED_FRAMES': '214073.82'}),
214073.82,
);
final wide = workloads[0], local = workloads[1];
expect(wide.count, 360);
expect(wide.hz, 60);
expect(wide.durationMs, 6000);
expect(
[
wide.idealFrame(0),
wide.idealFrame(179),
wide.idealFrame(180),
wide.idealFrame(359),
],
[10704, 203370, 203370, 10704],
);
expect(
[
local.idealFrame(0),
local.idealFrame(20),
local.idealFrame(21),
local.idealFrame(39),
local.idealFrame(359),
],
[60137, 60157, 60156, 60138, 60138],
);
expect(local.cameraBaseFrame, 60120);
expect(local.warmFrame, 60136);
});
test(
'another timeline derives local targets without a media-specific length',
() {
final workloads = ViewportBenchWorkload.forTimeline(config(), 10000);
expect(workloads[1].idealFrame(0), 2800);
expect(workloads[1].idealFrame(20), 2820);
expect(config().expectedFrames, isNull);
expect(config().nativeOnly, isTrue);
expect(config().captureHelper, isNull);
},
);
test('rate, frame count and local span can change without escaping the timeline', () {
final workloads = ViewportBenchWorkload.forTimeline(
config({
'INPUT_HZ': '120',
'INPUT_COUNT': '720',
'LOCAL_START_FRAME': '100',
'LOCAL_SPAN_FRAMES': '8',
}),
10000,
);
for (final workload in workloads) {
expect(workload.durationMs, 6000);
for (var i = 0; i < workload.count; i++) {
expect(workload.idealFrame(i), inInclusiveRange(0, 9999));
}
}
expect(workloads[1].idealFrame(8), 108);
expect(workloads[1].idealFrame(9), 107);
});
test(
'invalid settings fail before starting native capture or a gesture',
() {
expect(() => config({'INPUT_HZ': '0'}), throwsArgumentError);
expect(() => config({'INPUT_COUNT': '359'}), throwsArgumentError);
expect(
() => config({'LOCAL_PIXELS_PER_FRAME': 'NaN'}),
throwsArgumentError,
);
expect(() => config({'ROUNDS': 'oops'}), throwsFormatException);
expect(() => config({'PAIRED': 'yes'}), throwsArgumentError);
expect(() => config({'NATIVE_ONLY': '0'}), throwsArgumentError);
expect(
() => ViewportBenchWorkload.forTimeline(
config({'LOCAL_START_FRAME': '9990'}),
10000,
),
throwsStateError,
);
expect(
() => ViewportBenchWorkload.forTimeline(
config({'EXPECTED_FRAMES': '20000'}),
10000,
),
throwsStateError,
);
},
);
});
}
+146
View File
@@ -0,0 +1,146 @@
import 'package:cutdex/app/editor_theme.dart';
import 'package:cutdex/features/preview/preview_panel.dart';
import 'package:cutdex/features/properties/picture_properties.dart';
import 'package:cutdex/features/properties/properties_inspector_controller.dart';
import 'package:cutdex/l10n/app_localizations.dart';
import 'package:cutdex_sdk/editor.dart';
import 'package:cutdex_sdk/timeline/model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'support/preview_fixture.dart';
void main() {
testWidgets('cursor changes preserve inspector selection subscriptions', (
tester,
) async {
final f = (await tester.runAsync(
() => createPreviewFixture(Uri.file('/test/video.mov')),
))!;
addTearDown(
() => tester.runAsync(() async {
await f.workspace.close();
await f.directory.delete(recursive: true);
}),
);
final inspector = PropertiesInspectorController(f.timeline);
addTearDown(inspector.dispose);
final view = f.timeline.view(SequenceId('one'));
final clip = view.version.kernelVersion.query().elementById(
ElementId('clip'),
)!;
var notifications = 0;
inspector.addListener(() => notifications++);
view.setSelection([clip]);
expect(inspector.selectedClips.single.id, ElementId('clip'));
final selectedCount = notifications;
view.beginScrubbing();
for (var i = 1; i <= 120; i++) {
view.seekTo(i * TimelineClock.ticksPerSecond ~/ 120);
}
view.endScrubbing();
expect(notifications, selectedCount);
view.clearSelection();
expect(notifications, greaterThan(selectedCount));
expect(inspector.selectedClips, isEmpty);
f.timeline.selectSequence(SequenceId('empty'));
expect(inspector.sequence, SequenceId('empty'));
final switchedCount = notifications;
view.setSelection([clip]);
expect(
notifications,
switchedCount,
reason: 'Old sequence listener is detached',
);
});
testWidgets('static controls stay stable and discard edits after a seek', (
tester,
) async {
final f = (await tester.runAsync(
() => createPreviewFixture(
Uri.file('/test/video.mov'),
clipDuration: RationalTime.seconds(5),
),
))!;
addTearDown(
() => tester.runAsync(() async {
await f.workspace.close();
await f.directory.delete(recursive: true);
}),
);
final view = f.timeline.view(SequenceId('one'));
final project = f.workspace.project!.info.id;
ClipAnimation current() {
final query = view.version.kernelVersion.query();
return ClipAnimation.at(
query,
query.elementById(ElementId('clip'))!,
view.playheadTick,
TimelineClock.ticksPerSecond ~/ 30,
);
}
await tester.pumpWidget(
ProviderScope(
overrides: [
editorPreviewProvider(
project,
'project',
).overrideWith((ref) async => throw StateError('No native preview')),
],
child: MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
locale: const Locale('zh'),
theme: EditorTheme.penLight,
home: Scaffold(
body: SizedBox(
width: 280,
child: SingleChildScrollView(
child: PictureProperties(
projectId: project,
timelineId: 'project',
session: f.timeline,
sequence: SequenceId('one'),
clip: current().record,
),
),
),
),
),
),
);
await tester.pumpAndSettle();
final input = find.descendant(
of: find.byKey(const ValueKey('picture-x')),
matching: find.byType(TextField),
);
final initial = tester.widget<TextField>(input);
view.seekTo(TimelineClock.ticksPerSecond);
await tester.pump();
expect(tester.widget<TextField>(input), same(initial));
await tester.ensureVisible(input);
await tester.enterText(input, '999');
await tester.pump();
view.seekTo(2 * TimelineClock.ticksPerSecond);
await tester.pump();
await tester.testTextInput.receiveAction(TextInputAction.done);
await tester.runAsync(f.timeline.flush);
await tester.pumpAndSettle();
expect(current().value.x, 0);
await tester.ensureVisible(
find.byKey(const ValueKey('picture-key-position')),
);
await tester.tap(find.byKey(const ValueKey('picture-key-position')));
await tester.pump();
await tester.runAsync(f.timeline.flush);
await tester.pumpAndSettle();
expect(current().keyTimes(TransformChannel.position), [
2 * TimelineClock.ticksPerSecond,
]);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox.shrink());
});
}
+13 -2
View File
@@ -3608,7 +3608,12 @@ void main() {
of: find.byKey(const Key('timeline-toolbar')),
matching: find.byType(IconButton),
);
expect(toolbarButtons, findsNWidgets(6));
expect(toolbarButtons, findsNWidgets(7));
final fitButton = find.byKey(const ValueKey('timeline-fit'));
expect(
tester.widget<IconButton>(fitButton).tooltip,
localized.fitTimeline,
);
final toolbarBounds = tester.getRect(
find.byKey(const Key('timeline-toolbar')),
);
@@ -3620,7 +3625,9 @@ void main() {
final bounds = tester.getRect(
find.byElementPredicate((e) => e == button),
);
buttonBounds.add(bounds);
if (button.widget.key != const ValueKey('timeline-fit')) {
buttonBounds.add(bounds);
}
expect(
bounds.size,
const Size(AppControlSize.headerButton, AppControlSize.headerButton),
@@ -3628,6 +3635,10 @@ void main() {
expect((button.widget as IconButton).iconSize, AppIconSize.header);
}
expect(buttonBounds.first.left - panelBounds.left, AppSpacing.gap);
expect(
panelBounds.right - tester.getRect(fitButton).right,
AppSpacing.gap,
);
for (var i = 1; i < buttonBounds.length; i++) {
expect(
buttonBounds[i].left - buttonBounds[i - 1].right,
@@ -0,0 +1,372 @@
import 'dart:async';
import 'dart:io';
import 'package:cutdex/features/timeline/timeline_panel.dart';
import 'package:cutdex/features/editor/editor_page.dart';
import 'package:cutdex/app/editor_theme.dart';
import 'package:cutdex/integrations/platform/device_experience.dart';
import 'package:cutdex/l10n/app_localizations.dart';
import 'package:cutdex/persistence/app_settings_repositories.dart';
import 'package:cutdex/workspace/preview_target.dart';
import 'package:cutdex/workspace/project_state.dart';
import 'package:cutdex/workspace/projects.dart';
import 'package:cutdex/workspace/timeline_provider.dart';
import 'package:cutdex/workspace/persistence/recent_projects.dart';
import 'package:cutdex_sdk/project.dart';
import 'package:cutdex_sdk/runtime.dart';
import 'package:cutdex_sdk/timeline/model.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import '../support/memory_app_settings.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
late Directory root;
late ProviderContainer container;
late Projects projects;
late String projectId;
late _ViewSettings views;
late _RecentProjects recent;
final nativeCalls = <String>[];
const native = MethodChannel('timeline-navigation-test');
Future<void> initialize() async {
root = await Directory.systemTemp.createTemp('cutdex-navigation-');
views = _ViewSettings();
recent = _RecentProjects();
nativeCalls.clear();
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(native, (call) async {
nativeCalls.add(call.method);
throw StateError('Preview must not be initialized by navigation');
});
final path = '${root.path}/Project.cutdex';
final file = await ProjectFile.create(
Directory(path),
name: 'Project',
initialTimeline: _document('a'),
);
projectId = file.info.id;
await file.saveTimeline(_document('b', content: true));
await file.saveTimeline(_document('c'));
await file.close();
container = ProviderContainer(
overrides: [
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
recentProjectsProvider.overrideWithValue(recent),
resourceLocationSettingsRepositoryProvider.overrideWithValue(
MemoryResourceLocationSettingsRepository(root.path),
),
timelineViewSettingsRepositoryProvider.overrideWithValue(views),
runtimeConnectionProvider.overrideWithValue(
CutdexRuntime(channel: native),
),
],
);
projects = container.read(projectsProvider.notifier);
expect(await projects.open(path, timelineId: 'a'), isTrue);
}
Future<void> dispose() async {
for (final gate in views.gates.values) {
if (!gate.isCompleted) gate.complete(const TimelineViewState());
}
if (recent.writeGate case final gate?) {
if (!gate.isCompleted) gate.complete();
}
await projects.prepareToQuit();
container.dispose();
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(native, null);
await root.delete(recursive: true);
}
group('navigation controller', () {
setUp(initialize);
tearDown(dispose);
test(
'content selection completes without any native preview initialization',
() async {
expect(await projects.openTimeline(projectId, 'b'), isTrue);
expect(container.read(projectsProvider).requireValue.timeline!.id, 'b');
expect(nativeCalls, isEmpty);
},
);
test(
'latest cold navigation wins despite reverse completion order',
() async {
final bGate = views.block('b');
final b = projects.openTimeline(projectId, 'b');
expect(
container.read(projectsProvider).requireValue.visibleTimelineId,
'b',
);
await views.started('b');
expect(projects.openTimeline(projectId, 'b'), same(b));
final cGate = views.block('c');
final c = projects.openTimeline(projectId, 'c');
expect(
container.read(projectsProvider).requireValue.visibleTimelineId,
'c',
);
await views.started('c');
cGate.complete(const TimelineViewState());
expect(await c, isTrue);
bGate.complete(const TimelineViewState());
expect(await b, isFalse);
final state = container.read(projectsProvider).requireValue;
expect(state.timeline!.id, 'c');
expect(state.openingTimelineId, isNull);
expect(state.error, isNull);
expect(recent.projects[projectId], 'c');
},
);
test(
'returning to a partially prepared cache waits for one restore',
() async {
final gate = views.block('b');
final old = projects.openTimeline(projectId, 'b');
await views.started('b');
expect(await projects.openTimeline(projectId, 'a'), isTrue);
final latest = projects.openTimeline(projectId, 'b');
await Future<void>.delayed(Duration.zero);
expect(
container.read(projectsProvider).requireValue.openingTimelineId,
'b',
);
expect(container.read(projectsProvider).requireValue.timeline!.id, 'a');
gate.complete(const TimelineViewState());
expect(await old, isFalse);
expect(await latest, isTrue);
expect(views.loads.where((id) => id == 'b'), hasLength(1));
expect(container.read(projectsProvider).requireValue.timeline!.id, 'b');
},
);
test('project navigation supersedes a blocked timeline', () async {
final gate = views.block('b');
final old = projects.openTimeline(projectId, 'b');
await views.started('b');
expect(
await projects.open('${root.path}/Other.cutdex', name: 'Other'),
isTrue,
);
final other = container
.read(projectsProvider)
.requireValue
.activeProject!
.id;
gate.complete(const TimelineViewState());
expect(await old, isFalse);
expect(
container.read(projectsProvider).requireValue.activeProject!.id,
other,
);
expect(
container.read(projectsProvider).requireValue.openingTimelineId,
isNull,
);
});
test(
'slow failed preference write cannot overwrite latest selection or error',
() async {
recent.writeGate = Completer<void>();
recent.blockId = 'b';
final b = projects.openTimeline(projectId, 'b');
await recent.writeStarted.future;
final c = projects.openTimeline(projectId, 'c');
await views.started('c');
await Future<void>.delayed(const Duration(milliseconds: 10));
expect(container.read(projectsProvider).requireValue.timeline!.id, 'c');
recent.writeGate!.completeError(StateError('old write failed'));
expect(await b, isTrue);
expect(await c, isTrue);
expect(recent.projects[projectId], 'c');
expect(container.read(projectsProvider).requireValue.error, isNull);
},
);
});
test(
'startup failure is returned once without an unhandled cleanup future',
() async {
final failedContainer = ProviderContainer(
overrides: [projectsProvider.overrideWith(_FailingProjects.new)],
);
addTearDown(failedContainer.dispose);
final failed = failedContainer.read(projectsProvider.notifier);
await expectLater(failed.openTimeline('project', 'a'), throwsA(anything));
await Future<void>.delayed(Duration.zero);
},
);
testWidgets('pending tabs accept a newer real click', (tester) async {
final widgetContainer = ProviderContainer(
overrides: [projectsProvider.overrideWith(_PendingProjects.new)],
);
addTearDown(widgetContainer.dispose);
await tester.pumpWidget(
UncontrolledProviderScope(
container: widgetContainer,
child: MaterialApp(
theme: EditorTheme.penDark,
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: Consumer(
builder: (context, ref, _) {
final state = ref.watch(projectsProvider).value;
if (state == null) return const SizedBox();
return EditorWorkspace(
projectId: 'project',
timelineId: state.visibleTimelineId!,
projectName: 'Project',
integratedTitlebar: false,
headerLeading: const SizedBox(),
timelineLoading: true,
);
},
),
),
),
),
);
await tester.pump();
expect(find.byKey(const Key('timeline-pending')), findsOneWidget);
expect(
widgetContainer.exists(editorTimelineProvider('project', 'b')),
isFalse,
);
final panel = tester.widget<EditorTimelinePanel>(
find.byType(EditorTimelinePanel),
);
expect(panel.timelineId, 'b');
await tester.tap(find.byKey(const ValueKey('timeline-tab-c')));
await tester.pump();
expect(
widgetContainer.read(projectsProvider).requireValue.visibleTimelineId,
'c',
);
expect(
tester
.widget<EditorTimelinePanel>(find.byType(EditorTimelinePanel))
.timelineId,
'c',
);
await tester.pumpWidget(const SizedBox());
});
}
TimelineDocument _document(String id, {bool content = false}) =>
TimelineDocument(
id: id,
name: id,
defaultSequenceId: SequenceId('sequence-$id'),
sequences: [
TimelineDto(
id: SequenceId('sequence-$id'),
name: id,
format: TimelineFormat.fps30,
primaryStorylineId: StorylineId('primary-$id'),
storylines: [
StorylineDto(
id: StorylineId('primary-$id'),
elementIds: [if (content) ElementId('clip')],
),
],
elements: [
if (content)
ElementDto(
id: ElementId('clip'),
name: 'Clip',
structure: ElementStructure.content,
payloadRef: PayloadRef('source'),
duration: RationalTime.seconds(2),
sourceRange: TimeRange(
start: RationalTime.zero,
duration: RationalTime.seconds(2),
),
),
],
),
],
payloads: [
if (content)
PayloadDocument(id: 'source', type: 'video', assetIds: [], data: {}),
],
);
class _ViewSettings implements TimelineViewSettingsRepository {
final gates = <String, Completer<TimelineViewState>>{};
final signals = <String, Completer<void>>{};
final loads = <String>[];
Completer<TimelineViewState> block(String id) =>
gates[id] = Completer<TimelineViewState>();
Future<void> started(String id) => (signals[id] ??= Completer<void>()).future;
@override
Future<TimelineViewState> load(String projectId, String timelineId) async {
loads.add(timelineId);
(signals[timelineId] ??= Completer<void>()).complete();
return gates[timelineId]?.future ?? const TimelineViewState();
}
@override
Future<void> save(
String projectId,
String timelineId,
SequenceId sequenceId,
TimelineSequenceViewState state,
) async {}
}
class _RecentProjects extends MemoryRecentProjectsRepository {
Completer<void>? writeGate;
final writeStarted = Completer<void>();
String? blockId;
@override
Future<void> rememberTimeline(String projectId, String timelineId) async {
if (timelineId == blockId) {
writeStarted.complete();
await writeGate!.future;
}
await super.rememberTimeline(projectId, timelineId);
}
}
class _PendingProjects extends Projects {
@override
Future<ProjectState> build() async => ProjectState(
activeProject: const RecentProject(
id: 'project',
name: 'Project',
path: '/Project.cutdex',
),
timeline: _document('a'),
openingTimelineId: 'b',
timelines: const [
TimelineSummary(id: 'a', name: 'a', revision: 0),
TimelineSummary(id: 'b', name: 'b', revision: 0),
TimelineSummary(id: 'c', name: 'c', revision: 0),
],
);
@override
Future<bool> openTimeline(String projectId, String timelineId) async {
state = AsyncData(
state.requireValue.copyWith(openingTimelineId: timelineId),
);
return true;
}
}
class _FailingProjects extends Projects {
@override
Future<ProjectState> build() async => throw StateError('startup failed');
}