[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:
parent
148db22e34
commit
a3fced5da1
@ -5,7 +5,9 @@
|
|||||||
#define FML_USED_ON_EMBEDDER
|
#define FML_USED_ON_EMBEDDER
|
||||||
|
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
|
#include <sys/system_properties.h>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
@ -230,6 +232,11 @@ bool FlutterMain::Register(JNIEnv* env) {
|
|||||||
return env->RegisterNatives(clazz, methods, std::size(methods)) == 0;
|
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
|
// static
|
||||||
AndroidRenderingAPI FlutterMain::SelectedRenderingAPI(
|
AndroidRenderingAPI FlutterMain::SelectedRenderingAPI(
|
||||||
const flutter::Settings& settings) {
|
const flutter::Settings& settings) {
|
||||||
@ -266,6 +273,13 @@ AndroidRenderingAPI FlutterMain::SelectedRenderingAPI(
|
|||||||
if (api_level < kMinimumAndroidApiLevelForVulkan) {
|
if (api_level < kMinimumAndroidApiLevelForVulkan) {
|
||||||
return kVulkanUnsupportedFallback;
|
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
|
// Determine if Vulkan is supported by creating a Vulkan context and
|
||||||
// checking if it is valid.
|
// checking if it is valid.
|
||||||
impeller::ScopedValidationDisable disable_validation;
|
impeller::ScopedValidationDisable disable_validation;
|
||||||
|
@ -26,6 +26,8 @@ class FlutterMain {
|
|||||||
static AndroidRenderingAPI SelectedRenderingAPI(
|
static AndroidRenderingAPI SelectedRenderingAPI(
|
||||||
const flutter::Settings& settings);
|
const flutter::Settings& settings);
|
||||||
|
|
||||||
|
static bool IsDeviceEmulator(std::string_view product_model);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const flutter::Settings settings_;
|
const flutter::Settings settings_;
|
||||||
DartServiceIsolate::CallbackHandle vm_service_uri_callback_ = 0;
|
DartServiceIsolate::CallbackHandle vm_service_uri_callback_ = 0;
|
||||||
|
@ -34,5 +34,13 @@ TEST(AndroidPlatformView, SoftwareRenderingNotSupportedWithImpeller) {
|
|||||||
ASSERT_DEATH(FlutterMain::SelectedRenderingAPI(settings), "");
|
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 testing
|
||||||
} // namespace flutter
|
} // namespace flutter
|
||||||
|
Loading…
x
Reference in New Issue
Block a user