7#include <android/api-level.h>
8#include <sys/system_properties.h>
14namespace fs = std::filesystem;
20static const constexpr char* kAndroidHuawei =
"android-huawei";
22static constexpr const char* kBadSocs[] = {
43static bool IsDeviceEmulator() {
44 char property[PROP_VALUE_MAX];
46 __system_property_get(
"ro.hardware", property);
47 std::string_view hardware_prop(property);
48 if (hardware_prop ==
"goldfish" || hardware_prop ==
"ranchu" ||
49 hardware_prop ==
"qemu") {
53 __system_property_get(
"ro.product.model", property);
54 std::string_view model_prop(property);
55 if (model_prop.find(
"gphone") != std::string::npos) {
59 if (::access(
"/dev/qemu_pipe", F_OK) == 0) {
66static bool IsKnownBadSOC(std::string_view hardware) {
69 for (
const auto& board : kBadSocs) {
70 if (strcmp(board, hardware.data()) == 0) {
77static std::shared_ptr<AndroidContextVKImpeller>
78GetActualRenderingAPIForImpeller(
80 const AndroidContext::ContextSettings& settings) {
81 constexpr int kMinimumAndroidApiLevelForMediaTekVulkan = 31;
88 if (IsDeviceEmulator()) {
93 char property[PROP_VALUE_MAX];
94 __system_property_get(
"ro.com.google.clientidbase", property);
95 if (strcmp(property, kAndroidHuawei) == 0) {
101 if (api_level < kMinimumAndroidApiLevelForMediaTekVulkan &&
102 __system_property_find(
"ro.vendor.mediatek.platform") !=
nullptr) {
108 __system_property_get(
"ro.product.board", property);
109 if (IsKnownBadSOC(property)) {
111 <<
"Known bad Vulkan driver encountered, falling back to OpenGLES.";
118 auto vulkan_backend = std::make_shared<AndroidContextVKImpeller>(
119 AndroidContext::ContextSettings{
120#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
121 .enable_validation = settings.enable_validation,
123 .enable_validation =
false,
125 .enable_gpu_tracing = settings.enable_gpu_tracing,
126 .enable_surface_control = settings.enable_surface_control,
129 .lazy_shader_mode = settings.impeller_flags.lazy_shader_mode,
131 settings.impeller_flags.antialiased_lines,
134 if (!vulkan_backend->IsValid()) {
137 return vulkan_backend;
158std::shared_ptr<impeller::Context>
161 return vk_context_->GetImpellerContext();
164 return gl_context_->GetImpellerContext();
169std::shared_ptr<AndroidContextGLImpeller>
174std::shared_ptr<AndroidContextVKImpeller>
180 if (vk_context_ || gl_context_) {
183 vk_context_ = GetActualRenderingAPIForImpeller(android_get_device_api_level(),
186 gl_context_ = std::make_shared<AndroidContextGLImpeller>(
187 std::make_unique<impeller::egl::Display>(),
void SetupImpellerContext() override
Perform deferred setup for the impeller Context.
AndroidContextDynamicImpeller(const AndroidContext::ContextSettings &settings)
std::shared_ptr< AndroidContextVKImpeller > GetVKContext() const
Retrieve the VK context if it was created, or nullptr.
std::shared_ptr< AndroidContextGLImpeller > GetGLContext() const
Retrieve the GL Context if it was created, or nullptr.
~AndroidContextDynamicImpeller()
AndroidRenderingAPI RenderingApi() const override
std::shared_ptr< impeller::Context > GetImpellerContext() const override
Accessor for the Impeller context associated with AndroidSurfaces and the raster thread.
Holds state that is shared across Android surfaces.
#define FML_LOG(severity)