[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 https://github.com/flutter/flutter/issues/160442
Fixes https://github.com/flutter/flutter/issues/160439
Fixes https://github.com/flutter/flutter/issues/155973
This commit is contained in:
Jonah Williams 2025-01-30 11:41:04 -08:00 committed by GitHub
parent 148db22e34
commit a3fced5da1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 0 deletions

View File

@ -5,7 +5,9 @@
#define FML_USED_ON_EMBEDDER
#include <android/log.h>
#include <sys/system_properties.h>
#include <optional>
#include <string>
#include <vector>
#include "common/settings.h"
@ -230,6 +232,11 @@ bool FlutterMain::Register(JNIEnv* env) {
return env->RegisterNatives(clazz, methods, std::size(methods)) == 0;
}
// static
bool FlutterMain::IsDeviceEmulator(std::string_view product_model) {
return std::string(product_model).find("gphone") != std::string::npos;
}
// static
AndroidRenderingAPI FlutterMain::SelectedRenderingAPI(
const flutter::Settings& settings) {
@ -266,6 +273,13 @@ AndroidRenderingAPI FlutterMain::SelectedRenderingAPI(
if (api_level < kMinimumAndroidApiLevelForVulkan) {
return kVulkanUnsupportedFallback;
}
char product_model[PROP_VALUE_MAX];
__system_property_get("ro.product.model", product_model);
if (IsDeviceEmulator(product_model)) {
// Avoid using Vulkan on known emulators.
return kVulkanUnsupportedFallback;
}
// Determine if Vulkan is supported by creating a Vulkan context and
// checking if it is valid.
impeller::ScopedValidationDisable disable_validation;

View File

@ -26,6 +26,8 @@ class FlutterMain {
static AndroidRenderingAPI SelectedRenderingAPI(
const flutter::Settings& settings);
static bool IsDeviceEmulator(std::string_view product_model);
private:
const flutter::Settings settings_;
DartServiceIsolate::CallbackHandle vm_service_uri_callback_ = 0;

View File

@ -34,5 +34,13 @@ TEST(AndroidPlatformView, SoftwareRenderingNotSupportedWithImpeller) {
ASSERT_DEATH(FlutterMain::SelectedRenderingAPI(settings), "");
}
TEST(AndroidPlatformView, FallsBackToGLESonEmulator) {
std::string emulator_product = "gphone_x64";
std::string device_product = "smg1234";
EXPECT_TRUE(FlutterMain::IsDeviceEmulator(emulator_product));
EXPECT_FALSE(FlutterMain::IsDeviceEmulator(device_product));
}
} // namespace testing
} // namespace flutter