From 8f1cb92a046484c5abf99f19592cb7f1f6ffdcd4 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Mon, 12 Sep 2022 16:24:19 -0700 Subject: [PATCH] [Impeller] expose renderer choice in service extensions (flutter/engine#36103) --- engine/src/flutter/lib/ui/natives.dart | 20 +++++++++++ .../observatory/vmservice_methods_test.dart | 35 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/engine/src/flutter/lib/ui/natives.dart b/engine/src/flutter/lib/ui/natives.dart index 4d924b1fbf..49a567e5b5 100644 --- a/engine/src/flutter/lib/ui/natives.dart +++ b/engine/src/flutter/lib/ui/natives.dart @@ -73,6 +73,16 @@ Future _reinitializeShader( })); } +Future _getImpellerEnabled( + String method, + Map parameters, +) async { + return developer.ServiceExtensionResponse.result(json.encode({ + 'type': 'Success', + 'enabled': _impellerEnabled, + })); +} + @pragma('vm:entry-point') void _setupHooks() { assert(() { @@ -86,8 +96,18 @@ void _setupHooks() { ); return true; }()); + + // In debug and profile mode, allow tools to display the current rendering backend. + if (!_kReleaseMode) { + developer.registerExtension( + 'ext.ui.window.impellerEnabled', + _getImpellerEnabled, + ); + } } +const bool _kReleaseMode = bool.fromEnvironment('dart.vm.product'); + /// Returns runtime Dart compilation trace as a UTF-8 encoded memory buffer. /// /// The buffer contains a list of symbols compiled by the Dart JIT at runtime up diff --git a/engine/src/flutter/testing/dart/observatory/vmservice_methods_test.dart b/engine/src/flutter/testing/dart/observatory/vmservice_methods_test.dart index ed62cb80cc..6fe14f0d5e 100644 --- a/engine/src/flutter/testing/dart/observatory/vmservice_methods_test.dart +++ b/engine/src/flutter/testing/dart/observatory/vmservice_methods_test.dart @@ -41,6 +41,30 @@ void main() { } }); + + test('Can return whether or not impeller is enabled', () async { + vms.VmService? vmService; + try { + final developer.ServiceProtocolInfo info = await developer.Service.getInfo(); + if (info.serverUri == null) { + fail('This test must not be run with --disable-observatory.'); + } + + vmService = await vmServiceConnectUri( + 'ws://localhost:${info.serverUri!.port}${info.serverUri!.path}ws', + ); + final String? isolateId = await getIsolateId(vmService); + + final vms.Response response = await vmService.callServiceExtension( + 'ext.ui.window.impellerEnabled', + isolateId: isolateId, + ); + expect(response.json!['enabled'], false); + } finally { + await vmService?.dispose(); + } + }); + test('Reload fonts request sends font change notification', () async { vms.VmService? vmService; try { @@ -87,6 +111,17 @@ Future getViewId(vms.VmService vmService) async { return (rawViews![0]! as Map?)!['id']! as String; } +Future getIsolateId(vms.VmService vmService) async { + final vms.VM vm = await vmService.getVM(); + for (final vms.IsolateRef isolate in vm.isolates!) { + if (isolate.isSystemIsolate ?? false) { + continue; + } + return isolate.id; + } + return null; +} + class PlatformResponse { const PlatformResponse({ required this.name,