fix(android): wire exact preview startup and device benchmarks
Gitea CI / Check code and tests (pull_request) Successful in 11m6s
Gitea CI / Build Android APK (pull_request) Successful in 5m15s
Gitea CI / Build Windows x64 app (pull_request) Successful in 2m41s
Gitea CI / Audit and package Windows x64 (pull_request) Successful in 1m2s
Gitea CI / Assemble and validate CI artifacts (pull_request) Successful in 51s
Gitea CI / Gitea CI passed (pull_request) Successful in 2s

This commit is contained in:
lingjhf committed 2026-10-08 01:37:58 +08:00
1 parent b4cb12cbe3
commit 64a3a5b547
11 files changed
+1577 -30

No files matched your search

+17 -5
View File
@@ -13,6 +13,9 @@ part 'preview_controller_registry.g.dart';
PreviewControllerRegistry previewControllerRegistry(Ref ref) {
final registry = PreviewControllerRegistry(
ref.read(runtimeConnectionProvider),
onChanged: () => scheduleMicrotask(() {
if (ref.mounted) ref.notifyListeners();
}),
);
ref.onDispose(registry.dispose);
return registry;
@@ -21,9 +24,10 @@ PreviewControllerRegistry previewControllerRegistry(Ref ref) {
/// Owns native preview controllers independently of the currently visible
/// timeline. Prepared controllers make timeline selection a synchronous swap.
final class PreviewControllerRegistry {
PreviewControllerRegistry(this._runtime);
PreviewControllerRegistry(this._runtime, {this._onChanged});
final CutdexRuntime _runtime;
final void Function()? _onChanged;
final _controllers = <(String, String), PreviewController>{};
final _preparing = <(String, String), Future<PreviewController>>{};
bool _disposed = false;
@@ -39,10 +43,10 @@ final class PreviewControllerRegistry {
if (sequence == null || timeline.sequenceDurationTicks(sequence) == 0) {
return null;
}
final cached = _controllers[ids];
if (cached != null) return cached;
final pending = _preparing[ids];
if (pending != null) return pending;
final cached = _controllers[ids];
if (cached != null) return cached;
final future = _initialize(ids, timeline);
_preparing[ids] = future;
return future;
@@ -58,15 +62,22 @@ final class PreviewControllerRegistry {
viewForSequence: timeline.view,
runtime: _runtime,
);
// Mount native output while initialization is pending. Android exact seeks
// cannot complete their first frame before the SurfaceView is attached.
_controllers[ids] = controller;
_onChanged?.call();
try {
await controller.initialize();
if (_disposed) {
if (_disposed || !identical(_controllers[ids], controller)) {
await controller.close();
throw StateError('Preview registry is closed');
}
_controllers[ids] = controller;
return controller;
} catch (_) {
if (identical(_controllers[ids], controller)) {
_controllers.remove(ids);
_onChanged?.call();
}
await controller.close().catchError((Object _) {});
rethrow;
} finally {
@@ -76,6 +87,7 @@ final class PreviewControllerRegistry {
Future<void> invalidate((String, String) ids) async {
final controller = _controllers.remove(ids);
if (controller != null) _onChanged?.call();
if (controller != null) await controller.close();
}