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
227 lines
7.8 KiB
Dart
227 lines
7.8 KiB
Dart
import 'package:cutdex/app/editor_theme.dart';
|
|
import 'package:cutdex/l10n/app_localizations.dart';
|
|
|
|
import 'dart:io';
|
|
import 'dart:ui' as ui;
|
|
|
|
import 'package:cutdex_core/editor.dart';
|
|
import 'package:cutdex/features/preview/preview_panel.dart';
|
|
import 'package:cutdex/features/properties/picture_properties.dart';
|
|
import 'package:cutdex_preview/cutdex_preview.dart';
|
|
import 'package:cutdex_core/execution.dart';
|
|
import 'package:cutdex_native_flutter/cutdex_native_flutter.dart';
|
|
import 'package:cutdex_core/timeline/model.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/rendering.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:integration_test/integration_test.dart';
|
|
|
|
import '../test/support/preview_fixture.dart';
|
|
import 'support/native_media_fixture.dart';
|
|
|
|
void main() {
|
|
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
|
const outputName = String.fromEnvironment('CUTDEX_TEST_OUTPUT');
|
|
testWidgets('native grouped keyframes preview, scrub, play and export', (
|
|
tester,
|
|
) async {
|
|
final output = outputName.isEmpty
|
|
? ''
|
|
: '${(await Directory.systemTemp.createTemp('cutdex-keyframes-')).path}/$outputName';
|
|
final mediaFile = await nativeMediaFixture();
|
|
final f = await createPreviewFixture(
|
|
mediaFile.uri,
|
|
clipDuration: RationalTime.seconds(4),
|
|
renderSize: {'width': 640, 'height': 360},
|
|
);
|
|
final runtime = CutdexRuntime();
|
|
final preview = PreviewController(
|
|
timeline: f.timeline,
|
|
activeSequence: () => f.timeline.activeSequenceId,
|
|
viewForSequence: f.timeline.view,
|
|
runtime: runtime,
|
|
);
|
|
addTearDown(() async {
|
|
await preview.close();
|
|
await f.workspace.close();
|
|
await f.directory.delete(recursive: true);
|
|
});
|
|
await preview.initialize();
|
|
expect(preview.error, isNull);
|
|
final sequence = SequenceId('one');
|
|
final clip = ElementId('clip');
|
|
final view = f.timeline.view(sequence);
|
|
ClipAnimation at(int seconds) {
|
|
final q = view.version.kernelVersion.query();
|
|
return ClipAnimation.at(
|
|
q,
|
|
q.elementById(clip)!,
|
|
seconds * TimelineClock.ticksPerSecond,
|
|
TimelineClock.ticksPerSecond ~/ 30,
|
|
);
|
|
}
|
|
|
|
Future<void> ready() async {
|
|
for (var i = 0; i < 200 && preview.busy; i++) {
|
|
await Future<void>.delayed(const Duration(milliseconds: 25));
|
|
await tester.pump();
|
|
}
|
|
expect(preview.busy, isFalse);
|
|
expect(preview.error, isNull);
|
|
}
|
|
|
|
Future<void> commit(List<ParameterCurveDto> curves) async {
|
|
f.timeline.commitParameters(
|
|
sequence,
|
|
f.timeline.previewParameters(sequence, clip, curves),
|
|
parameterTargets: ClipTransform.targets,
|
|
);
|
|
await ready();
|
|
}
|
|
|
|
await commit(at(0).edit(const ClipTransform(scale: .5)));
|
|
await commit([
|
|
for (final channel in TransformChannel.values) ...at(0).toggle(channel),
|
|
]);
|
|
await commit(
|
|
at(2).edit(
|
|
const ClipTransform(x: .2, y: .1, scale: .7, scaleY: .9, rotation: 45),
|
|
),
|
|
);
|
|
final ids = (f.workspace.project!.info.id, 'project');
|
|
final boundary = GlobalKey();
|
|
Future<void> mount(ThemeData theme, double width) => tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
editorPreviewProvider(
|
|
ids.$1,
|
|
ids.$2,
|
|
).overrideWith((ref) async => preview),
|
|
],
|
|
child: MaterialApp(
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
locale: const Locale('zh'),
|
|
|
|
theme: theme,
|
|
home: Scaffold(
|
|
body: Row(
|
|
children: [
|
|
Expanded(
|
|
child: EditorPreviewPanel(
|
|
projectId: ids.$1,
|
|
timelineId: ids.$2,
|
|
),
|
|
),
|
|
SizedBox(
|
|
width: width,
|
|
child: RepaintBoundary(
|
|
key: boundary,
|
|
child: ColoredBox(
|
|
color: theme.scaffoldBackgroundColor,
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(12),
|
|
child: PictureProperties(
|
|
projectId: ids.$1,
|
|
timelineId: ids.$2,
|
|
session: f.timeline,
|
|
sequence: sequence,
|
|
clip: at(0).record,
|
|
animationView: true,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await mount(EditorTheme.penDark, 280);
|
|
preview.selectVisual(clip);
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
find.descendant(
|
|
of: find.byType(PreviewInteractionOverlay),
|
|
matching: find.byType(CustomPaint),
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
view.seekTo(TimelineClock.ticksPerSecond);
|
|
await Future<void>.delayed(const Duration(milliseconds: 500));
|
|
await tester.pump();
|
|
final visual = preview.visualForProperties(clip)!;
|
|
expect(visual.transform.scaleY, closeTo(.7, 1e-8));
|
|
expect(visual.transform.rotation, closeTo(22.5, 1e-8));
|
|
final drag = preview.transforms.begin(visual)!;
|
|
expect(await drag.prepared, isTrue);
|
|
drag.update(drag.value.copyWith(scaleY: .8));
|
|
await Future<void>.delayed(const Duration(milliseconds: 100));
|
|
await drag.end();
|
|
preview.cancelTransform();
|
|
await ready();
|
|
expect(at(1).value.scaleY, closeTo(.8, 1e-8));
|
|
expect(at(0).value.scaleY, .5);
|
|
expect(at(2).value.scaleY, .9);
|
|
await preview.togglePlayback();
|
|
await Future<void>.delayed(const Duration(milliseconds: 400));
|
|
await tester.pump();
|
|
expect(preview.playing, isTrue);
|
|
expect(preview.selectedVisualIds, {clip});
|
|
expect(
|
|
find.descendant(
|
|
of: find.byType(PreviewInteractionOverlay),
|
|
matching: find.byType(CustomPaint),
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
await preview.pauseForCanvasInteraction();
|
|
final snapshot = await preview.session!.refresh();
|
|
expect(snapshot.position.seconds, greaterThan(1));
|
|
expect(preview.error, isNull);
|
|
for (final (theme, width, name) in [
|
|
(EditorTheme.penDark, 280.0, 'dark'),
|
|
(EditorTheme.penLight, 225.0, 'light'),
|
|
]) {
|
|
await mount(theme, width);
|
|
await tester.pumpAndSettle();
|
|
expect(tester.takeException(), isNull);
|
|
if (output.isNotEmpty) {
|
|
final image =
|
|
await (boundary.currentContext!.findRenderObject()!
|
|
as RenderRepaintBoundary)
|
|
.toImage(pixelRatio: 2);
|
|
final bytes = await image.toByteData(format: ui.ImageByteFormat.png);
|
|
await File('$output-$name.png')
|
|
.writeAsBytes(bytes!.buffer.asUint8List());
|
|
image.dispose();
|
|
}
|
|
}
|
|
if (output.isNotEmpty) {
|
|
final preparedMedia = await prepareEditorMedia(
|
|
session: f.timeline,
|
|
sequence: sequence,
|
|
version: f.timeline.persistence.timeline(sequence).current,
|
|
probe: runtime.probe,
|
|
unknownVideoColorSpace: const PreviewPolicy().unknownVideoColorSpace,
|
|
);
|
|
final compiled = const ExecutionCompiler().compile(
|
|
ExecutionInput(
|
|
timeline: f.timeline.persistence.timeline(sequence),
|
|
renderSize: RenderSize(640, 360),
|
|
parameterTargets: ClipTransform.targets,
|
|
media: preparedMedia.bindings,
|
|
),
|
|
);
|
|
await preview.session!.export(compiled.plan, File('$output.mp4').uri);
|
|
expect(await File('$output.mp4').length(), greaterThan(1000));
|
|
debugPrint('KEYFRAME_ARTIFACTS $output');
|
|
}
|
|
await f.timeline.flush();
|
|
await tester.pumpWidget(const SizedBox());
|
|
});
|
|
}
|