Skip to content

Commit 7e88acf

Browse files
authored
[flutter_tool] Adds a flag to disable Impeller (flutter#122960)
1 parent e260dd2 commit 7e88acf

20 files changed

+104
-47
lines changed

packages/flutter_tools/lib/src/android/android_device.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,10 @@ class AndroidDevice extends Device {
660660
...<String>['--ez', 'cache-sksl', 'true'],
661661
if (debuggingOptions.purgePersistentCache)
662662
...<String>['--ez', 'purge-persistent-cache', 'true'],
663-
if (debuggingOptions.enableImpeller)
663+
if (debuggingOptions.enableImpeller == ImpellerStatus.enabled)
664664
...<String>['--ez', 'enable-impeller', 'true'],
665+
if (debuggingOptions.enableImpeller == ImpellerStatus.disabled)
666+
...<String>['--ez', 'enable-impeller', 'false'],
665667
if (debuggingOptions.debuggingEnabled) ...<String>[
666668
if (debuggingOptions.buildInfo.isDebug) ...<String>[
667669
...<String>['--ez', 'enable-checked-mode', 'true'],

packages/flutter_tools/lib/src/build_system/targets/shader_compiler.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import '../../base/logger.dart';
1717
import '../../build_info.dart';
1818
import '../../convert.dart';
1919
import '../../devfs.dart';
20+
import '../../device.dart';
2021
import '../build_system.dart';
2122

2223
/// The output shader format that should be used by the [ShaderCompiler].
@@ -51,7 +52,7 @@ class DevelopmentShaderCompiler {
5152

5253
/// Configure the output format of the shader compiler for a particular
5354
/// flutter device.
54-
void configureCompiler(TargetPlatform? platform, { required bool enableImpeller }) {
55+
void configureCompiler(TargetPlatform? platform, { required ImpellerStatus impellerStatus }) {
5556
switch (platform) {
5657
case TargetPlatform.ios:
5758
_shaderTarget = ShaderTarget.impelleriOS;
@@ -61,7 +62,9 @@ class DevelopmentShaderCompiler {
6162
case TargetPlatform.android_x86:
6263
case TargetPlatform.android_arm:
6364
case TargetPlatform.android:
64-
_shaderTarget = enableImpeller ? ShaderTarget.impellerAndroid : ShaderTarget.sksl;
65+
_shaderTarget = impellerStatus == ImpellerStatus.enabled
66+
? ShaderTarget.impellerAndroid
67+
: ShaderTarget.sksl;
6568
break;
6669
case TargetPlatform.darwin:
6770
case TargetPlatform.linux_x64:
@@ -70,11 +73,11 @@ class DevelopmentShaderCompiler {
7073
case TargetPlatform.fuchsia_arm64:
7174
case TargetPlatform.fuchsia_x64:
7275
case TargetPlatform.tester:
73-
assert(!enableImpeller);
76+
assert(impellerStatus != ImpellerStatus.enabled);
7477
_shaderTarget = ShaderTarget.sksl;
7578
break;
7679
case TargetPlatform.web_javascript:
77-
assert(!enableImpeller);
80+
assert(impellerStatus != ImpellerStatus.enabled);
7881
_shaderTarget = ShaderTarget.sksl;
7982
_jsonMode = true;
8083
break;

packages/flutter_tools/lib/src/commands/run.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
193193
bool get cacheStartupProfile => boolArg('cache-startup-profile');
194194
bool get runningWithPrebuiltApplication => argResults![FlutterOptions.kUseApplicationBinary] != null;
195195
bool get trackWidgetCreation => boolArg('track-widget-creation');
196-
bool get enableImpeller => boolArg('enable-impeller');
196+
ImpellerStatus get enableImpeller => ImpellerStatus.fromBool(argResults!['enable-impeller'] as bool?);
197197
bool get uninstallFirst => boolArg('uninstall-first');
198198
bool get enableEmbedderApi => boolArg('enable-embedder-api');
199199

@@ -478,7 +478,7 @@ class RunCommand extends RunCommandBase {
478478
commandRunProjectModule: FlutterProject.current().isModule,
479479
commandRunProjectHostLanguage: hostLanguage.join(','),
480480
commandRunAndroidEmbeddingVersion: androidEmbeddingVersion,
481-
commandRunEnableImpeller: enableImpeller,
481+
commandRunEnableImpeller: enableImpeller.asBool,
482482
commandRunIOSInterfaceType: iOSInterfaceType,
483483
);
484484
}

packages/flutter_tools/lib/src/device.dart

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,23 @@ class _NoMemoryInfo implements MemoryInfo {
877877
Map<String, Object> toJson() => <String, Object>{};
878878
}
879879

880+
enum ImpellerStatus {
881+
platformDefault._(null),
882+
enabled._(true),
883+
disabled._(false);
884+
885+
const ImpellerStatus._(this.asBool);
886+
887+
factory ImpellerStatus.fromBool(bool? b) {
888+
if (b == null) {
889+
return platformDefault;
890+
}
891+
return b ? enabled : disabled;
892+
}
893+
894+
final bool? asBool;
895+
}
896+
880897
class DebuggingOptions {
881898
DebuggingOptions.enabled(
882899
this.buildInfo, {
@@ -917,7 +934,7 @@ class DebuggingOptions {
917934
this.vmserviceOutFile,
918935
this.fastStart = false,
919936
this.nativeNullAssertions = false,
920-
this.enableImpeller = false,
937+
this.enableImpeller = ImpellerStatus.platformDefault,
921938
this.uninstallFirst = false,
922939
this.serveObservatory = true,
923940
this.enableDartProfiling = true,
@@ -938,7 +955,7 @@ class DebuggingOptions {
938955
this.webLaunchUrl,
939956
this.cacheSkSL = false,
940957
this.traceAllowlist,
941-
this.enableImpeller = false,
958+
this.enableImpeller = ImpellerStatus.platformDefault,
942959
this.uninstallFirst = false,
943960
this.enableDartProfiling = true,
944961
this.enableEmbedderApi = false,
@@ -1048,7 +1065,7 @@ class DebuggingOptions {
10481065
final bool webUseSseForDebugProxy;
10491066
final bool webUseSseForDebugBackend;
10501067
final bool webUseSseForInjectedClient;
1051-
final bool enableImpeller;
1068+
final ImpellerStatus enableImpeller;
10521069
final bool serveObservatory;
10531070
final bool enableDartProfiling;
10541071
final bool enableEmbedderApi;
@@ -1123,7 +1140,8 @@ class DebuggingOptions {
11231140
if (purgePersistentCache) '--purge-persistent-cache',
11241141
if (route != null) '--route=$route',
11251142
if (platformArgs['trace-startup'] as bool? ?? false) '--trace-startup',
1126-
if (enableImpeller) '--enable-impeller',
1143+
if (enableImpeller == ImpellerStatus.enabled) '--enable-impeller=true',
1144+
if (enableImpeller == ImpellerStatus.disabled) '--enable-impeller=false',
11271145
if (environmentType == EnvironmentType.physical && deviceVmServicePort != null)
11281146
'--vm-service-port=$deviceVmServicePort',
11291147
// The simulator "device" is actually on the host machine so no ports will be forwarded.
@@ -1176,7 +1194,7 @@ class DebuggingOptions {
11761194
'vmserviceOutFile': vmserviceOutFile,
11771195
'fastStart': fastStart,
11781196
'nativeNullAssertions': nativeNullAssertions,
1179-
'enableImpeller': enableImpeller,
1197+
'enableImpeller': enableImpeller.asBool,
11801198
'serveObservatory': serveObservatory,
11811199
'enableDartProfiling': enableDartProfiling,
11821200
'enableEmbedderApi': enableEmbedderApi,
@@ -1223,7 +1241,7 @@ class DebuggingOptions {
12231241
vmserviceOutFile: json['vmserviceOutFile'] as String?,
12241242
fastStart: json['fastStart']! as bool,
12251243
nativeNullAssertions: json['nativeNullAssertions']! as bool,
1226-
enableImpeller: (json['enableImpeller'] as bool?) ?? false,
1244+
enableImpeller: ImpellerStatus.fromBool(json['enableImpeller'] as bool?),
12271245
uninstallFirst: (json['uninstallFirst'] as bool?) ?? false,
12281246
serveObservatory: (json['serveObservatory'] as bool?) ?? false,
12291247
enableDartProfiling: (json['enableDartProfiling'] as bool?) ?? true,

packages/flutter_tools/lib/src/run_hot.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ class HotRunner extends ResidentRunner {
253253
await device!.initLogReader();
254254
device
255255
.developmentShaderCompiler
256-
.configureCompiler(device.targetPlatform, enableImpeller: debuggingOptions.enableImpeller);
256+
.configureCompiler(
257+
device.targetPlatform,
258+
impellerStatus: debuggingOptions.enableImpeller,
259+
);
257260
}
258261
try {
259262
final List<Uri?> baseUris = await _initDevFS();

packages/flutter_tools/lib/src/runner/flutter_command.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,11 +1017,13 @@ abstract class FlutterCommand extends Command<void> {
10171017

10181018
void addEnableImpellerFlag({required bool verboseHelp}) {
10191019
argParser.addFlag('enable-impeller',
1020-
negatable: false,
10211020
hide: !verboseHelp,
1022-
help: 'Whether to enable the experimental Impeller rendering engine. '
1023-
'Impeller is currently only supported on iOS and Android. This flag will '
1024-
'be ignored when targeting other platforms.',
1021+
defaultsTo: null,
1022+
help: 'Whether to enable the Impeller rendering engine. '
1023+
'Impeller is the default renderer on iOS. On Android, Impeller '
1024+
'is available but not the default. This flag will cause Impeller '
1025+
'to be used on Android. On other platforms, this flag will be '
1026+
'ignored.',
10251027
);
10261028
}
10271029

packages/flutter_tools/test/commands.shard/hermetic/drive_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ void main() {
397397
expect(options.traceSystrace, true);
398398
expect(options.verboseSystemLogs, true);
399399
expect(options.nativeNullAssertions, true);
400-
expect(options.enableImpeller, true);
400+
expect(options.enableImpeller, ImpellerStatus.enabled);
401401
expect(options.traceSystrace, true);
402402
expect(options.enableSoftwareRendering, true);
403403
expect(options.skiaDeterministicRendering, true);

packages/flutter_tools/test/commands.shard/hermetic/run_test.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ void main() {
428428
TestUsageCommand('run', parameters: CustomDimensions.fromMap(<String, String>{
429429
'cd3': 'false', 'cd4': 'ios', 'cd22': 'iOS 13',
430430
'cd23': 'debug', 'cd18': 'false', 'cd15': 'swift', 'cd31': 'true',
431-
'cd56': 'false', 'cd57': 'usb',
431+
'cd57': 'usb',
432432
})
433433
)));
434434
}, overrides: <Type, Generator>{
@@ -699,7 +699,6 @@ void main() {
699699
commandRunModeName: 'debug',
700700
commandRunProjectModule: false,
701701
commandRunProjectHostLanguage: '',
702-
commandRunEnableImpeller: false,
703702
));
704703
}, overrides: <Type, Generator>{
705704
DeviceManager: () => testDeviceManager,
@@ -739,7 +738,6 @@ void main() {
739738
commandRunModeName: 'debug',
740739
commandRunProjectModule: false,
741740
commandRunProjectHostLanguage: '',
742-
commandRunEnableImpeller: false,
743741
commandRunIOSInterfaceType: 'usb',
744742
));
745743
}, overrides: <Type, Generator>{
@@ -783,7 +781,6 @@ void main() {
783781
commandRunModeName: 'debug',
784782
commandRunProjectModule: false,
785783
commandRunProjectHostLanguage: '',
786-
commandRunEnableImpeller: false,
787784
commandRunIOSInterfaceType: 'wireless',
788785
));
789786
}, overrides: <Type, Generator>{
@@ -827,7 +824,6 @@ void main() {
827824
commandRunModeName: 'debug',
828825
commandRunProjectModule: false,
829826
commandRunProjectHostLanguage: '',
830-
commandRunEnableImpeller: false,
831827
commandRunIOSInterfaceType: 'wireless',
832828
));
833829
}, overrides: <Type, Generator>{
@@ -1023,7 +1019,7 @@ void main() {
10231019
expect(options.verboseSystemLogs, true);
10241020
expect(options.nativeNullAssertions, true);
10251021
expect(options.traceSystrace, true);
1026-
expect(options.enableImpeller, true);
1022+
expect(options.enableImpeller, ImpellerStatus.enabled);
10271023
expect(options.enableSoftwareRendering, true);
10281024
expect(options.skiaDeterministicRendering, true);
10291025
}, overrides: <Type, Generator>{

packages/flutter_tools/test/general.shard/android/android_device_start_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ void main() {
278278
purgePersistentCache: true,
279279
useTestFonts: true,
280280
verboseSystemLogs: true,
281-
enableImpeller: true,
281+
enableImpeller: ImpellerStatus.enabled,
282282
),
283283
platformArgs: <String, dynamic>{},
284284
userIdentifier: '10',

packages/flutter_tools/test/general.shard/build_system/targets/shader_compiler_test.dart

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:flutter_tools/src/base/logger.dart';
1111
import 'package:flutter_tools/src/build_info.dart';
1212
import 'package:flutter_tools/src/build_system/targets/shader_compiler.dart';
1313
import 'package:flutter_tools/src/devfs.dart';
14+
import 'package:flutter_tools/src/device.dart';
1415

1516
import '../../../src/common.dart';
1617
import '../../../src/fake_process_manager.dart';
@@ -272,7 +273,10 @@ void main() {
272273
random: math.Random(0),
273274
);
274275

275-
developmentShaderCompiler.configureCompiler(TargetPlatform.android, enableImpeller: false);
276+
developmentShaderCompiler.configureCompiler(
277+
TargetPlatform.android,
278+
impellerStatus: ImpellerStatus.disabled,
279+
);
276280

277281
final DevFSContent? content = await developmentShaderCompiler
278282
.recompileShader(DevFSFileContent(fileSystem.file(fragPath)));
@@ -317,7 +321,10 @@ void main() {
317321
random: math.Random(0),
318322
);
319323

320-
developmentShaderCompiler.configureCompiler(TargetPlatform.android, enableImpeller: true);
324+
developmentShaderCompiler.configureCompiler(
325+
TargetPlatform.android,
326+
impellerStatus: ImpellerStatus.enabled,
327+
);
321328

322329
final DevFSContent? content = await developmentShaderCompiler
323330
.recompileShader(DevFSFileContent(fileSystem.file(fragPath)));
@@ -363,7 +370,10 @@ void main() {
363370
random: math.Random(0),
364371
);
365372

366-
developmentShaderCompiler.configureCompiler(TargetPlatform.web_javascript, enableImpeller: false);
373+
developmentShaderCompiler.configureCompiler(
374+
TargetPlatform.web_javascript,
375+
impellerStatus: ImpellerStatus.disabled,
376+
);
367377

368378
final DevFSContent? content = await developmentShaderCompiler
369379
.recompileShader(DevFSFileContent(fileSystem.file(fragPath)));

0 commit comments

Comments
 (0)