Skip to content

Commit a3fced5

Browse files
author
Jonah Williams
authored
[Impeller] Disable Vulkan on Emulators. (#162454)
Forces known android emulators to use OpenGLES. This is a very conservative check that could be expanded over time if need be. For testing emulators can still use the debug flags. Fixes #160442 Fixes #160439 Fixes #155973
1 parent 148db22 commit a3fced5

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

engine/src/flutter/shell/platform/android/flutter_main.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
#define FML_USED_ON_EMBEDDER
66

77
#include <android/log.h>
8+
#include <sys/system_properties.h>
89
#include <optional>
10+
#include <string>
911
#include <vector>
1012

1113
#include "common/settings.h"
@@ -230,6 +232,11 @@ bool FlutterMain::Register(JNIEnv* env) {
230232
return env->RegisterNatives(clazz, methods, std::size(methods)) == 0;
231233
}
232234

235+
// static
236+
bool FlutterMain::IsDeviceEmulator(std::string_view product_model) {
237+
return std::string(product_model).find("gphone") != std::string::npos;
238+
}
239+
233240
// static
234241
AndroidRenderingAPI FlutterMain::SelectedRenderingAPI(
235242
const flutter::Settings& settings) {
@@ -266,6 +273,13 @@ AndroidRenderingAPI FlutterMain::SelectedRenderingAPI(
266273
if (api_level < kMinimumAndroidApiLevelForVulkan) {
267274
return kVulkanUnsupportedFallback;
268275
}
276+
char product_model[PROP_VALUE_MAX];
277+
__system_property_get("ro.product.model", product_model);
278+
if (IsDeviceEmulator(product_model)) {
279+
// Avoid using Vulkan on known emulators.
280+
return kVulkanUnsupportedFallback;
281+
}
282+
269283
// Determine if Vulkan is supported by creating a Vulkan context and
270284
// checking if it is valid.
271285
impeller::ScopedValidationDisable disable_validation;

engine/src/flutter/shell/platform/android/flutter_main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class FlutterMain {
2626
static AndroidRenderingAPI SelectedRenderingAPI(
2727
const flutter::Settings& settings);
2828

29+
static bool IsDeviceEmulator(std::string_view product_model);
30+
2931
private:
3032
const flutter::Settings settings_;
3133
DartServiceIsolate::CallbackHandle vm_service_uri_callback_ = 0;

engine/src/flutter/shell/platform/android/platform_view_android_unittests.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,13 @@ TEST(AndroidPlatformView, SoftwareRenderingNotSupportedWithImpeller) {
3434
ASSERT_DEATH(FlutterMain::SelectedRenderingAPI(settings), "");
3535
}
3636

37+
TEST(AndroidPlatformView, FallsBackToGLESonEmulator) {
38+
std::string emulator_product = "gphone_x64";
39+
std::string device_product = "smg1234";
40+
41+
EXPECT_TRUE(FlutterMain::IsDeviceEmulator(emulator_product));
42+
EXPECT_FALSE(FlutterMain::IsDeviceEmulator(device_product));
43+
}
44+
3745
} // namespace testing
3846
} // namespace flutter

0 commit comments

Comments
 (0)