From 9644a6a181dde21cd7f68b9deae6dd560a8d70df Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 15 Nov 2023 12:53:30 -0800 Subject: [PATCH 01/11] [Impeller] Select OpenGLES if Android API < 29 --- .../standalone/linux_android_emulator.json | 20 +++ shell/platform/android/BUILD.gn | 1 + .../platform/android/platform_view_android.cc | 24 ++++ .../platform_view_android_unittests.cc | 133 ++++++++++++++++++ 4 files changed, 178 insertions(+) create mode 100644 shell/platform/android/platform_view_android_unittests.cc diff --git a/ci/builders/standalone/linux_android_emulator.json b/ci/builders/standalone/linux_android_emulator.json index 307e47905fae9..421449fb33dea 100644 --- a/ci/builders/standalone/linux_android_emulator.json +++ b/ci/builders/standalone/linux_android_emulator.json @@ -39,6 +39,26 @@ "android" ] }, + { + "language": "python3", + "name": "Android Unit Tests (API 28)", + "test_dependencies": [ + { + "dependency": "android_virtual_device", + "version": "28" + } + ], + "contexts": [ + "android_virtual_device" + ], + "script": "flutter/testing/run_tests.py", + "parameters": [ + "--android-variant", + "android_debug_x64", + "--type", + "android" + ] + }, { "language": "bash", "name": "Scenario App Integration Tests", diff --git a/shell/platform/android/BUILD.gn b/shell/platform/android/BUILD.gn index 5d8458973481f..10aa924ccca41 100644 --- a/shell/platform/android/BUILD.gn +++ b/shell/platform/android/BUILD.gn @@ -47,6 +47,7 @@ executable("flutter_shell_native_unittests") { "android_shell_holder_unittests.cc", "apk_asset_provider_unittests.cc", "flutter_shell_native_unittests.cc", + "platform_view_android_unittests.cc", ] public_configs = [ "//flutter:config" ] deps = [ diff --git a/shell/platform/android/platform_view_android.cc b/shell/platform/android/platform_view_android.cc index d5854c530f02b..ba979963e51e9 100644 --- a/shell/platform/android/platform_view_android.cc +++ b/shell/platform/android/platform_view_android.cc @@ -4,6 +4,7 @@ #include "flutter/shell/platform/android/platform_view_android.h" +#include #include #include @@ -33,6 +34,8 @@ namespace flutter { +constexpr int kMinimumAndroidApiLevelForVulkan = 29; + AndroidSurfaceFactoryImpl::AndroidSurfaceFactoryImpl( const std::shared_ptr& context, bool enable_impeller) @@ -73,9 +76,30 @@ static std::shared_ptr CreateAndroidContext( bool enable_vulkan_validation, bool enable_opengl_gpu_tracing) { if (use_software_rendering) { + FML_DCHECK(!enable_impeller); return std::make_shared(AndroidRenderingAPI::kSoftware); } if (enable_impeller) { + // Vulkan must only be used on API level 29+, as older API levels do not + // have requisite features to support platform views. + // + // Even if this check returns true, Impeller may determine it cannot use + // Vulkan for some other reason, such as a missing required extension or + // feature. + int api_level = android_get_device_api_level(); + if (api_level < kMinimumAndroidApiLevelForVulkan) { + if (impeller_backend.value_or("") == "vulkan") { + FML_LOG(WARNING) + << "Impeller Vulkan requested, but detected Android API level " + << api_level + << " does not support required features for Vulkan with platform " + "views. Falling back to OpenGLES."; + } + return std::make_unique( + std::make_unique(), + enable_opengl_gpu_tracing); + } + // Default value is Vulkan with GLES fallback. AndroidRenderingAPI backend = AndroidRenderingAPI::kAutoselect; if (impeller_backend.has_value()) { diff --git a/shell/platform/android/platform_view_android_unittests.cc b/shell/platform/android/platform_view_android_unittests.cc new file mode 100644 index 0000000000000..c757c71001508 --- /dev/null +++ b/shell/platform/android/platform_view_android_unittests.cc @@ -0,0 +1,133 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/shell/platform/android/platform_view_android.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" +#include "shell/platform/android/context/android_context.h" +#include "third_party/googletest/googlemock/include/gmock/gmock-nice-strict.h" + +namespace flutter { +namespace testing { + +using ::testing::NiceMock; +using ::testing::ReturnRef; + +namespace { +class MockPlatformViewDelegate : public PlatformView::Delegate { + public: + MOCK_METHOD(void, + OnPlatformViewCreated, + (std::unique_ptr surface), + (override)); + + MOCK_METHOD(void, OnPlatformViewDestroyed, (), (override)); + + MOCK_METHOD(void, OnPlatformViewScheduleFrame, (), (override)); + + MOCK_METHOD(void, + OnPlatformViewSetNextFrameCallback, + (const fml::closure& closure), + (override)); + + MOCK_METHOD(void, + OnPlatformViewSetViewportMetrics, + (int64_t view_id, const ViewportMetrics& metrics), + (override)); + + MOCK_METHOD(void, + OnPlatformViewDispatchPlatformMessage, + (std::unique_ptr message), + (override)); + + MOCK_METHOD(void, + OnPlatformViewDispatchPointerDataPacket, + (std::unique_ptr packet), + (override)); + + MOCK_METHOD(void, + OnPlatformViewDispatchSemanticsAction, + (int32_t id, SemanticsAction action, fml::MallocMapping args), + (override)); + + MOCK_METHOD(void, + OnPlatformViewSetSemanticsEnabled, + (bool enabled), + (override)); + + MOCK_METHOD(void, + OnPlatformViewSetAccessibilityFeatures, + (int32_t flags), + (override)); + + MOCK_METHOD(void, + OnPlatformViewRegisterTexture, + (std::shared_ptr texture), + (override)); + + MOCK_METHOD(void, + OnPlatformViewUnregisterTexture, + (int64_t texture_id), + (override)); + + MOCK_METHOD(void, + OnPlatformViewMarkTextureFrameAvailable, + (int64_t texture_id), + (override)); + + MOCK_METHOD(const Settings&, + OnPlatformViewGetSettings, + (), + (const, override)); + + MOCK_METHOD(void, + LoadDartDeferredLibrary, + (intptr_t loading_unit_id, + std::unique_ptr snapshot_data, + std::unique_ptr snapshot_instructions), + (override)); + + MOCK_METHOD(void, + LoadDartDeferredLibraryError, + (intptr_t loading_unit_id, + const std::string error_message, + bool transient), + (override)); + + MOCK_METHOD(void, + UpdateAssetResolverByType, + (std::unique_ptr updated_asset_resolver, + AssetResolver::AssetResolverType type), + (override)); +}; +} // namespace + +TEST(AndroidPlatformView, SelectsVulkanBasedOnApiLevel) { + Settings settings; + settings.enable_software_rendering = false; + settings.enable_impeller = true; + settings.impeller_backend = "vulkan"; + NiceMock mock_delegate; + EXPECT_CALL(mock_delegate, OnPlatformViewGetSettings) + .WillRepeatedly(ReturnRef(settings)); + + TaskRunners task_runners("test", nullptr, nullptr, nullptr, nullptr); + PlatformViewAndroid platform_view(/*delegate=*/mock_delegate, + /*task_runners=*/task_runners, + /*jni_facade=*/nullptr, + /*use_software_rendering=*/false, + /*msaa_samples=*/1); + auto context = platform_view.GetAndroidContext(); + EXPECT_TRUE(context); + int api_level = android_get_device_api_level(); + EXPECT_GT(api_level, 0); + if (api_level >= 29) { + EXPECT_TRUE(context->RenderingApi() == AndroidRenderingAPI::kVulkan); + } else { + EXPECT_TRUE(context->RenderingApi() == AndroidRenderingAPI::kOpenGLES); + } +} + +} // namespace testing +} // namespace flutter From 0963ae17ebcede88c723a8fc7b7489cead451711 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 15 Nov 2023 13:03:35 -0800 Subject: [PATCH 02/11] ci From cf575164838ed7b69270a48dcb5c519bf744bbb7 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 15 Nov 2023 15:04:03 -0800 Subject: [PATCH 03/11] API 28 is x86 --- .../standalone/linux_android_emulator.json | 158 ++++++++++-------- ci/licenses_golden/excluded_files | 1 + 2 files changed, 93 insertions(+), 66 deletions(-) diff --git a/ci/builders/standalone/linux_android_emulator.json b/ci/builders/standalone/linux_android_emulator.json index 421449fb33dea..955132a7761d6 100644 --- a/ci/builders/standalone/linux_android_emulator.json +++ b/ci/builders/standalone/linux_android_emulator.json @@ -1,79 +1,105 @@ { - "drone_dimensions": [ - "device_type=none", - "os=Linux" - ], - "gn": [ - "--android", - "--android-cpu=x64", - "--no-lto", - "--rbe", - "--no-goma" - ], - "name": "android_debug_x64", - "ninja": { - "config": "android_debug_x64", - "targets": [ - "flutter/shell/platform/android:flutter_shell_native_unittests", - "flutter/testing/scenario_app" - ] - }, - "tests": [ + "builds": [ { - "language": "python3", - "name": "Android Unit Tests", - "test_dependencies": [ - { - "dependency": "android_virtual_device", - "version": "34" - } - ], - "contexts": [ - "android_virtual_device" + "drone_dimensions": [ + "device_type=none", + "os=Linux" ], - "script": "flutter/testing/run_tests.py", - "parameters": [ - "--android-variant", - "android_debug_x64", - "--type", - "android" - ] - }, - { - "language": "python3", - "name": "Android Unit Tests (API 28)", - "test_dependencies": [ + "gn": [ + "--android", + "--android-cpu=x64", + "--no-lto", + "--rbe", + "--no-goma" + ], + "name": "android_debug_x64", + "ninja": { + "config": "android_debug_x64", + "targets": [ + "flutter/shell/platform/android:flutter_shell_native_unittests", + "flutter/testing/scenario_app" + ] + }, + "tests": [ { - "dependency": "android_virtual_device", - "version": "28" + "language": "python3", + "name": "Android Unit Tests", + "test_dependencies": [ + { + "dependency": "android_virtual_device", + "version": "34" + } + ], + "contexts": [ + "android_virtual_device" + ], + "script": "flutter/testing/run_tests.py", + "parameters": [ + "--android-variant", + "android_debug_x64", + "--type", + "android" + ] + }, + { + "language": "bash", + "name": "Scenario App Integration Tests", + "test_dependencies": [ + { + "dependency": "android_virtual_device", + "version": "34" + } + ], + "contexts": [ + "android_virtual_device" + ], + "script": "flutter/testing/scenario_app/run_android_tests.sh", + "parameters": [ + "android_debug_x64" + ] } - ], - "contexts": [ - "android_virtual_device" - ], - "script": "flutter/testing/run_tests.py", - "parameters": [ - "--android-variant", - "android_debug_x64", - "--type", - "android" ] }, { - "language": "bash", - "name": "Scenario App Integration Tests", - "test_dependencies": [ + "drone_dimensions": [ + "device_type=none", + "os=Linux" + ], + "gn": [ + "--android", + "--android-cpu=x86", + "--no-lto", + "--rbe", + "--no-goma" + ], + "name": "android_debug_x86", + "ninja": { + "config": "android_debug_x86", + "targets": [ + "flutter/shell/platform/android:flutter_shell_native_unittests" + ] + }, + "tests": [ { - "dependency": "android_virtual_device", - "version": "34" + "language": "python3", + "name": "Android Unit Tests (API 28)", + "test_dependencies": [ + { + "dependency": "android_virtual_device", + "version": "28" + } + ], + "contexts": [ + "android_virtual_device" + ], + "script": "flutter/testing/run_tests.py", + "parameters": [ + "--android-variant", + "android_debug_x64", + "--type", + "android" + ] } - ], - "contexts": [ - "android_virtual_device" - ], - "script": "flutter/testing/scenario_app/run_android_tests.sh", - "parameters": [ - "android_debug_x64" ] } ] diff --git a/ci/licenses_golden/excluded_files b/ci/licenses_golden/excluded_files index e518702b32318..3a1fb4786371c 100644 --- a/ci/licenses_golden/excluded_files +++ b/ci/licenses_golden/excluded_files @@ -267,6 +267,7 @@ ../../../flutter/shell/platform/android/flutter_shell_native_unittests.cc ../../../flutter/shell/platform/android/jni/jni_mock_unittest.cc ../../../flutter/shell/platform/android/platform_view_android_delegate/platform_view_android_delegate_unittests.cc +../../../flutter/shell/platform/android/platform_view_android_unittests.cc ../../../flutter/shell/platform/android/test ../../../flutter/shell/platform/android/test_runner ../../../flutter/shell/platform/common/accessibility_bridge_unittests.cc From eb47fdbebd5d5a32dc6ce956518cc6b4548bd87b Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 15 Nov 2023 15:11:17 -0800 Subject: [PATCH 04/11] missing line --- ci/builders/standalone/linux_android_emulator.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/builders/standalone/linux_android_emulator.json b/ci/builders/standalone/linux_android_emulator.json index 955132a7761d6..7699aebe6dbb1 100644 --- a/ci/builders/standalone/linux_android_emulator.json +++ b/ci/builders/standalone/linux_android_emulator.json @@ -95,7 +95,7 @@ "script": "flutter/testing/run_tests.py", "parameters": [ "--android-variant", - "android_debug_x64", + "android_debug_x86", "--type", "android" ] From b87b71afecf9868e42278b70322f808edf7d34e1 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 15 Nov 2023 15:26:42 -0800 Subject: [PATCH 05/11] not standalone anymore --- ci/builders/{standalone => }/linux_android_emulator.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ci/builders/{standalone => }/linux_android_emulator.json (100%) diff --git a/ci/builders/standalone/linux_android_emulator.json b/ci/builders/linux_android_emulator.json similarity index 100% rename from ci/builders/standalone/linux_android_emulator.json rename to ci/builders/linux_android_emulator.json From db11ec97d219d8c66b9eb10dcc44a41b62e62c66 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 15 Nov 2023 15:33:24 -0800 Subject: [PATCH 06/11] more --- .ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci.yaml b/.ci.yaml index 1e0a19ec8790d..d73ccaa893fb6 100644 --- a/.ci.yaml +++ b/.ci.yaml @@ -88,7 +88,7 @@ targets: - name: Linux linux_android_emulator_tests enabled_branches: - main - recipe: engine_v2/builder + recipe: engine_v2/engine_v2 presubmit: false properties: config_name: linux_android_emulator From 6ec3e4a332c1c3535e5b6f96bc9ae2a0349933e5 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 15 Nov 2023 15:57:52 -0800 Subject: [PATCH 07/11] make it run in presubmit --- .ci.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.ci.yaml b/.ci.yaml index d73ccaa893fb6..fadaa3b2c4798 100644 --- a/.ci.yaml +++ b/.ci.yaml @@ -89,7 +89,6 @@ targets: enabled_branches: - main recipe: engine_v2/engine_v2 - presubmit: false properties: config_name: linux_android_emulator timeout: 60 From b4fb2d52d6bed6933a2df72d7c6bbb1f947aacdf Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 15 Nov 2023 16:54:12 -0800 Subject: [PATCH 08/11] kvm --- ci/builders/linux_android_emulator.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ci/builders/linux_android_emulator.json b/ci/builders/linux_android_emulator.json index 7699aebe6dbb1..107c84cab39c0 100644 --- a/ci/builders/linux_android_emulator.json +++ b/ci/builders/linux_android_emulator.json @@ -3,7 +3,9 @@ { "drone_dimensions": [ "device_type=none", - "os=Linux" + "os=Linux", + "kvm=\"1\"", + "cores=8" ], "gn": [ "--android", @@ -63,7 +65,9 @@ { "drone_dimensions": [ "device_type=none", - "os=Linux" + "os=Linux", + "kvm=\"1\"", + "cores=8" ], "gn": [ "--android", From 257e640667bdd45d45d5bc54eb6a7d0437c342c8 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 15 Nov 2023 16:59:28 -0800 Subject: [PATCH 09/11] kvm=1 --- ci/builders/linux_android_emulator.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/builders/linux_android_emulator.json b/ci/builders/linux_android_emulator.json index 107c84cab39c0..847d161edbe47 100644 --- a/ci/builders/linux_android_emulator.json +++ b/ci/builders/linux_android_emulator.json @@ -4,7 +4,7 @@ "drone_dimensions": [ "device_type=none", "os=Linux", - "kvm=\"1\"", + "kvm=1", "cores=8" ], "gn": [ @@ -66,7 +66,7 @@ "drone_dimensions": [ "device_type=none", "os=Linux", - "kvm=\"1\"", + "kvm=1", "cores=8" ], "gn": [ From 2b8378d731073cb079a1e4225d013e74ddc33d93 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 15 Nov 2023 17:12:08 -0800 Subject: [PATCH 10/11] bringup, build scenario app for x86 too --- ci/builders/linux_android_emulator.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/builders/linux_android_emulator.json b/ci/builders/linux_android_emulator.json index 847d161edbe47..735ee538747c4 100644 --- a/ci/builders/linux_android_emulator.json +++ b/ci/builders/linux_android_emulator.json @@ -80,7 +80,8 @@ "ninja": { "config": "android_debug_x86", "targets": [ - "flutter/shell/platform/android:flutter_shell_native_unittests" + "flutter/shell/platform/android:flutter_shell_native_unittests", + "flutter/testing/scenario_app" ] }, "tests": [ From ce4bfa10ebe7badefe3946020cb91888027c5432 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 15 Nov 2023 17:14:31 -0800 Subject: [PATCH 11/11] runIf --- .ci.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.ci.yaml b/.ci.yaml index fadaa3b2c4798..cb313b499ce7f 100644 --- a/.ci.yaml +++ b/.ci.yaml @@ -89,9 +89,14 @@ targets: enabled_branches: - main recipe: engine_v2/engine_v2 + bringup: true properties: config_name: linux_android_emulator timeout: 60 + runIf: + - .ci.yaml + - lib/ui/** + - shell/platform/android/** - name: Linux builder_cache enabled_branches: