From 2160284af8ef9276f83c56d2c1b697ce25867e35 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Sun, 28 Jul 2024 20:35:27 -0700 Subject: [PATCH] [Impeller] Enable on-by-default on Android. (flutter/engine#54156) Developers can control the backend in the following ways: * **Do nothing**: Impeller with Vulkan is used where Vulkan is available with a fallback to Skia with OpenGL. * **In `AndroidManifest.xml`, specify `io.flutter.embedding.android.EnableImpeller` as `false`**: Skia with OpenGL is used. * **On the command line, specify `--no-enable-impeller`**: Skia with OpenGL is used. Manifest options will take priority command line options when there is a conflict. This matches iOS behavior per https://github.com/flutter/flutter/issues/124049 (closed as WAI). Fixes https://github.com/flutter/flutter/issues/149360 --- engine/src/flutter/common/settings.h | 2 +- .../flutter/embedding/engine/FlutterShellArgs.java | 13 +++++++++---- .../embedding/engine/loader/FlutterLoader.java | 8 ++++++-- .../embedding/engine/loader/FlutterLoaderTest.java | 2 +- .../ios/framework/Source/FlutterDartProject.mm | 4 ---- .../androidTest/java/dev/flutter/TestRunner.java | 2 ++ .../testing/scenario_app/bin/run_android_tests.dart | 4 +++- 7 files changed, 22 insertions(+), 13 deletions(-) diff --git a/engine/src/flutter/common/settings.h b/engine/src/flutter/common/settings.h index 49c5311aff..fbdcf8e865 100644 --- a/engine/src/flutter/common/settings.h +++ b/engine/src/flutter/common/settings.h @@ -223,7 +223,7 @@ struct Settings { // Enable the Impeller renderer on supported platforms. Ignored if Impeller is // not supported on the platform. -#if FML_OS_IOS || FML_OS_IOS_SIMULATOR +#if FML_OS_ANDROID || FML_OS_IOS || FML_OS_IOS_SIMULATOR bool enable_impeller = true; #else bool enable_impeller = false; diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterShellArgs.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterShellArgs.java index 338a615a7e..36e5ef6908 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterShellArgs.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterShellArgs.java @@ -44,8 +44,9 @@ public class FlutterShellArgs { public static final String ARG_TRACE_SYSTRACE = "--trace-systrace"; public static final String ARG_KEY_TRACE_TO_FILE = "trace-to-file"; public static final String ARG_TRACE_TO_FILE = "--trace-to-file"; - public static final String ARG_KEY_ENABLE_IMPELLER = "enable-impeller"; - public static final String ARG_ENABLE_IMPELLER = "--enable-impeller"; + public static final String ARG_KEY_TOGGLE_IMPELLER = "enable-impeller"; + public static final String ARG_ENABLE_IMPELLER = "--enable-impeller=true"; + public static final String ARG_DISABLE_IMPELLER = "--enable-impeller=false"; public static final String ARG_KEY_ENABLE_VULKAN_VALIDATION = "enable-vulkan-validation"; public static final String ARG_ENABLE_VULKAN_VALIDATION = "--enable-vulkan-validation"; public static final String ARG_KEY_DUMP_SHADER_SKP_ON_SHADER_COMPILATION = @@ -121,8 +122,12 @@ public class FlutterShellArgs { if (intent.hasExtra(ARG_KEY_TRACE_TO_FILE)) { args.add(ARG_TRACE_TO_FILE + "=" + intent.getStringExtra(ARG_KEY_TRACE_TO_FILE)); } - if (intent.getBooleanExtra(ARG_KEY_ENABLE_IMPELLER, false)) { - args.add(ARG_ENABLE_IMPELLER); + if (intent.hasExtra(ARG_KEY_TOGGLE_IMPELLER)) { + if (intent.getBooleanExtra(ARG_KEY_TOGGLE_IMPELLER, false)) { + args.add(ARG_ENABLE_IMPELLER); + } else { + args.add(ARG_DISABLE_IMPELLER); + } } if (intent.getBooleanExtra(ARG_KEY_ENABLE_VULKAN_VALIDATION, false)) { args.add(ARG_ENABLE_VULKAN_VALIDATION); diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java index 1be3f67701..70302e7f42 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java @@ -345,8 +345,12 @@ public class FlutterLoader { shellArgs.add("--prefetched-default-font-manager"); if (metaData != null) { - if (metaData.getBoolean(ENABLE_IMPELLER_META_DATA_KEY, false)) { - shellArgs.add("--enable-impeller"); + if (metaData.containsKey(ENABLE_IMPELLER_META_DATA_KEY)) { + if (metaData.getBoolean(ENABLE_IMPELLER_META_DATA_KEY)) { + shellArgs.add("--enable-impeller=true"); + } else { + shellArgs.add("--enable-impeller=false"); + } } if (metaData.getBoolean(ENABLE_VULKAN_VALIDATION_META_DATA_KEY, false)) { shellArgs.add("--enable-vulkan-validation"); diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/engine/loader/FlutterLoaderTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/engine/loader/FlutterLoaderTest.java index aa9c108947..98d60d4b78 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/engine/loader/FlutterLoaderTest.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/engine/loader/FlutterLoaderTest.java @@ -228,7 +228,7 @@ public class FlutterLoaderTest { flutterLoader.ensureInitializationComplete(ctx, null); shadowOf(getMainLooper()).idle(); - final String enableImpellerArg = "--enable-impeller"; + final String enableImpellerArg = "--enable-impeller=true"; ArgumentCaptor shellArgsCaptor = ArgumentCaptor.forClass(String[].class); verify(mockFlutterJNI, times(1)) .init(eq(ctx), shellArgsCaptor.capture(), anyString(), anyString(), anyString(), anyLong()); diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm index b7d3eb96c6..0a0377f9bf 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm @@ -176,10 +176,6 @@ flutter::Settings FLTDefaultSettingsForBundle(NSBundle* bundle, NSProcessInfo* p settings.enable_wide_gamut = enableWideGamut; #endif - // TODO(dnfield): We should reverse the order for all these settings so that command line options - // are preferred to plist settings. https://github.com/flutter/flutter/issues/124049 - // Whether to enable Impeller. If the command line explicitly - // specified an option for this, ignore what's in the plist. if (!command_line.HasOption("enable-impeller")) { // Next, look in the app bundle. NSNumber* enableImpeller = [bundle objectForInfoDictionaryKey:@"FLTEnableImpeller"]; diff --git a/engine/src/flutter/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/TestRunner.java b/engine/src/flutter/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/TestRunner.java index 1bf2781123..a8dc96ef5a 100644 --- a/engine/src/flutter/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/TestRunner.java +++ b/engine/src/flutter/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/TestRunner.java @@ -23,6 +23,8 @@ public class TestRunner extends AndroidJUnitRunner { "--enable-impeller=true", "--impeller-backend=" + arguments.getString("impeller-backend", "vulkan") }; + } else { + engineArguments = new String[] {"--enable-impeller=false"}; } FlutterRenderer.debugDisableSurfaceClear = true; if ("true".equals(arguments.getString("force-surface-producer-surface-texture"))) { diff --git a/engine/src/flutter/testing/scenario_app/bin/run_android_tests.dart b/engine/src/flutter/testing/scenario_app/bin/run_android_tests.dart index 51635d9fbe..75982fdc1b 100644 --- a/engine/src/flutter/testing/scenario_app/bin/run_android_tests.dart +++ b/engine/src/flutter/testing/scenario_app/bin/run_android_tests.dart @@ -417,7 +417,9 @@ Future _run({ if (smokeTestFullPath != null) '-e class $smokeTestFullPath', if (enableImpeller) - '-e enable-impeller true', + '-e enable-impeller true' + else + '-e enable-impeller false', if (impellerBackend != null) '-e impeller-backend ${impellerBackend.name}', if (forceSurfaceProducerSurfaceTexture)