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
63 lines
1.8 KiB
Dart
63 lines
1.8 KiB
Dart
import 'dart:async';
|
|
import 'dart:io';
|
|
|
|
import 'config.dart';
|
|
|
|
/// Optional desktop capture process; its path is supplied explicitly.
|
|
class BenchCapture {
|
|
BenchCapture._(this.output, this.process);
|
|
final Directory output;
|
|
final Process process;
|
|
|
|
static Future<BenchCapture?> start(
|
|
ViewportBenchConfig config,
|
|
Directory output,
|
|
) async {
|
|
if (config.nativeOnly) return null;
|
|
final helper = config.captureHelper!;
|
|
final probe = await Process.run(helper, ['$pid']);
|
|
if (probe.exitCode != 0) {
|
|
throw StateError('Capture probe failed: ${probe.stderr}');
|
|
}
|
|
final line = probe.stdout
|
|
.toString()
|
|
.split('\n')
|
|
.singleWhere((s) => s.startsWith('CutdexD3D11Preview 1 '));
|
|
final rect = line.trim().split(' ').skip(2).map(int.parse).toList();
|
|
final process = await Process.start(helper, [
|
|
output.path,
|
|
'$pid',
|
|
'${rect[0] + 8}',
|
|
'${rect[1] + 8}',
|
|
'${rect[2] - 8}',
|
|
'${rect[3] - 8}',
|
|
]);
|
|
unawaited(process.stdout.drain<void>());
|
|
unawaited(process.stderr.drain<void>());
|
|
final capture = BenchCapture._(output, process);
|
|
for (
|
|
var i = 0;
|
|
!await File('${output.path}/capture-ready').exists() && i < 500;
|
|
i++
|
|
) {
|
|
await Future<void>.delayed(const Duration(milliseconds: 10));
|
|
}
|
|
if (!await File('${output.path}/capture-ready').exists()) {
|
|
await capture.stop();
|
|
throw StateError('Capture not ready');
|
|
}
|
|
return capture;
|
|
}
|
|
|
|
Future<void> stop() async {
|
|
await File('${output.path}/capture-stop').writeAsString('stop');
|
|
try {
|
|
final code = await process.exitCode.timeout(const Duration(seconds: 10));
|
|
if (code != 0) throw StateError('Capture exit $code');
|
|
} on TimeoutException {
|
|
process.kill();
|
|
rethrow;
|
|
}
|
|
}
|
|
}
|