7#include <android/api-level.h>
8#include <sys/system_properties.h>
37#if IMPELLER_ENABLE_VULKAN
53static constexpr int kMinAPILevelHCPP = 34;
56AndroidContext::ContextSettings CreateContextSettings(
57 const Settings& p_settings) {
58 AndroidContext::ContextSettings settings;
59 settings.enable_gpu_tracing = p_settings.enable_vulkan_gpu_tracing;
60 settings.enable_validation = p_settings.enable_vulkan_validation;
61 settings.enable_surface_control = p_settings.enable_surface_control;
62 settings.impeller_flags.antialiased_lines =
63 p_settings.impeller_antialiased_lines;
69 const std::shared_ptr<AndroidContext>& context,
71 bool lazy_shader_mode)
72 : android_context_(context),
73 enable_impeller_(enable_impeller),
74 lazy_shader_mode_(lazy_shader_mode) {}
79 if (android_context_->IsDynamicSelection()) {
80 auto cast_ptr = std::static_pointer_cast<AndroidContextDynamicImpeller>(
82 return std::make_unique<AndroidSurfaceDynamicImpeller>(cast_ptr);
84 switch (android_context_->RenderingApi()) {
87 return std::make_unique<AndroidSurfaceSoftware>();
89 return std::make_unique<AndroidSurfaceGLSkia>(
90 std::static_pointer_cast<AndroidContextGLSkia>(android_context_));
93 return std::make_unique<AndroidSurfaceGLImpeller>(
94 std::static_pointer_cast<AndroidContextGLImpeller>(android_context_));
96 return std::make_unique<AndroidSurfaceVKImpeller>(
97 std::static_pointer_cast<AndroidContextVKImpeller>(android_context_));
99 auto cast_ptr = std::static_pointer_cast<AndroidContextDynamicImpeller>(
101 return std::make_unique<AndroidSurfaceDynamicImpeller>(cast_ptr);
110 bool enable_opengl_gpu_tracing,
112 switch (android_rendering_api) {
117 return std::make_unique<AndroidContextGLSkia>(
118 fml::MakeRefCounted<AndroidEnvironmentGL>(),
123 return std::make_unique<AndroidContextVKImpeller>(settings);
125 return std::make_unique<AndroidContextGLImpeller>(
126 std::make_unique<impeller::egl::Display>(),
127 enable_opengl_gpu_tracing);
130 return std::make_unique<AndroidContextDynamicImpeller>(settings);
138 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade,
147 delegate.OnPlatformViewGetSettings().enable_opengl_gpu_tracing,
148 CreateContextSettings(delegate.OnPlatformViewGetSettings()))) {}
153 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade,
154 const std::shared_ptr<flutter::AndroidContext>& android_context)
156 jni_facade_(jni_facade),
157 android_context_(android_context),
158 platform_view_android_delegate_(jni_facade),
160 if (android_context_) {
162 <<
"Could not create surface from invalid Android context.";
163 surface_factory_ = std::make_shared<AndroidSurfaceFactoryImpl>(
169 android_surface_ = surface_factory_->CreateSurface();
170 android_meets_hcpp_criteria_ =
172 android_get_device_api_level() >= kMinAPILevelHCPP &&
174 FML_CHECK(android_surface_ && android_surface_->IsValid())
175 <<
"Could not create an OpenGL, Vulkan or Software surface to set "
185 if (android_surface_) {
186 InstallFirstFrameCallback();
191 [&latch,
surface = android_surface_.get(),
192 native_window = std::move(native_window), jni_facade = jni_facade_]() {
193 surface->SetNativeWindow(native_window, jni_facade);
204 if (android_surface_) {
208 [&latch,
surface = android_surface_.get(),
209 native_window = std::move(native_window), jni_facade = jni_facade_]() {
210 surface->TeardownOnScreenContext();
211 surface->SetNativeWindow(native_window, jni_facade);
223 if (android_surface_) {
227 [&latch,
surface = android_surface_.get()]() {
228 surface->TeardownOnScreenContext();
236 if (!android_surface_) {
242 [&latch,
surface = android_surface_.get(),
size]() {
243 surface->OnScreenSurfaceResize(size);
251 jobject java_message_data,
252 jint java_message_position,
254 uint8_t* message_data =
255 static_cast<uint8_t*
>(env->GetDirectBufferAddress(java_message_data));
261 response = fml::MakeRefCounted<PlatformMessageResponseAndroid>(
266 std::make_unique<flutter::PlatformMessage>(
267 std::move(
name), std::move(
message), std::move(response)));
275 response = fml::MakeRefCounted<PlatformMessageResponseAndroid>(
280 std::make_unique<flutter::PlatformMessage>(std::move(
name),
281 std::move(response)));
285void PlatformViewAndroid::HandlePlatformMessage(
286 std::unique_ptr<flutter::PlatformMessage>
message) {
288 platform_message_handler_->HandlePlatformMessage(std::move(
message));
292void PlatformViewAndroid::OnPreEngineRestart()
const {
293 jni_facade_->FlutterViewOnPreEngineRestart();
300 jint args_position) {
303 if (env->IsSameObject(
args, NULL)) {
310 uint8_t* args_data =
static_cast<uint8_t*
>(env->GetDirectBufferAddress(
args));
315 std::move(args_vector));
319void PlatformViewAndroid::UpdateSemantics(
327void PlatformViewAndroid::SetApplicationLocale(std::string locale) {
328 jni_facade_->FlutterViewSetApplicationLocale(std::move(locale));
332void PlatformViewAndroid::SetSemanticsTreeEnabled(
bool enabled) {
333 jni_facade_->FlutterViewSetSemanticsTreeEnabled(enabled);
339 switch (android_context_->RenderingApi()) {
342 RegisterTexture(std::make_shared<SurfaceTextureExternalTextureGLImpeller>(
343 std::static_pointer_cast<impeller::ContextGLES>(
344 android_context_->GetImpellerContext()),
360 FML_LOG(INFO) <<
"Software rendering does not support external textures.";
365 <<
"Flutter recommends migrating plugins that create and "
366 "register surface textures to the new surface producer "
367 "API. See https://docs.flutter.dev/release/breaking-changes/"
368 "android-surface-plugins";
369 RegisterTexture(std::make_shared<SurfaceTextureExternalTextureVKImpeller>(
370 std::static_pointer_cast<impeller::ContextVK>(
371 android_context_->GetImpellerContext()),
388 switch (android_context_->RenderingApi()) {
393 std::static_pointer_cast<AndroidContextGLSkia>(android_context_),
394 texture_id, image_texture_entry, jni_facade_, lifecycle));
397 FML_LOG(INFO) <<
"Software rendering does not support external textures.";
403 std::static_pointer_cast<impeller::ContextGLES>(
404 android_context_->GetImpellerContext()),
405 texture_id, image_texture_entry, jni_facade_, lifecycle));
409 std::static_pointer_cast<impeller::ContextVK>(
410 android_context_->GetImpellerContext()),
411 texture_id, image_texture_entry, jni_facade_, lifecycle));
420std::unique_ptr<VsyncWaiter> PlatformViewAndroid::CreateVSyncWaiter() {
425std::unique_ptr<Surface> PlatformViewAndroid::CreateRenderingSurface() {
426 if (!android_surface_) {
429 return android_surface_->CreateGPUSurface(
430 android_context_->GetMainSkiaContext().get());
434std::shared_ptr<ExternalViewEmbedder>
435PlatformViewAndroid::CreateExternalViewEmbedder() {
436 return std::make_shared<AndroidExternalViewEmbedderWrapper>(
437 android_meets_hcpp_criteria_, *android_context_, jni_facade_,
442std::unique_ptr<SnapshotSurfaceProducer>
443PlatformViewAndroid::CreateSnapshotSurfaceProducer() {
444 if (!android_surface_) {
447 return std::make_unique<AndroidSnapshotSurfaceProducer>(*android_surface_);
451sk_sp<GrDirectContext> PlatformViewAndroid::CreateResourceContext()
const {
452 if (!android_surface_) {
456 sk_sp<GrDirectContext> resource_context;
457 if (android_surface_->ResourceContextMakeCurrent()) {
462 GrBackendApi::kOpenGL,
465 FML_DLOG(ERROR) <<
"Could not make the resource context current.";
467 return resource_context;
469 android_surface_->ResourceContextMakeCurrent();
475void PlatformViewAndroid::ReleaseResourceContext()
const {
476 if (android_surface_) {
477 android_surface_->ResourceContextClearCurrent();
482std::shared_ptr<impeller::Context> PlatformViewAndroid::GetImpellerContext()
484 if (android_surface_) {
485 return android_surface_->GetImpellerContext();
487 return android_context_->GetImpellerContext();
491std::unique_ptr<std::vector<std::string>>
492PlatformViewAndroid::ComputePlatformResolvedLocales(
493 const std::vector<std::string>& supported_locale_data) {
494 return jni_facade_->FlutterViewComputePlatformResolvedLocale(
495 supported_locale_data);
499void PlatformViewAndroid::RequestDartDeferredLibrary(intptr_t loading_unit_id) {
500 if (jni_facade_->RequestDartDeferredLibrary(loading_unit_id)) {
508 intptr_t loading_unit_id,
509 std::unique_ptr<const fml::Mapping> snapshot_data,
510 std::unique_ptr<const fml::Mapping> snapshot_instructions) {
512 std::move(snapshot_instructions));
517 intptr_t loading_unit_id,
518 const std::string error_message,
526 std::unique_ptr<AssetResolver> updated_asset_resolver,
531void PlatformViewAndroid::InstallFirstFrameCallback() {
537 platform_task_runner->PostTask([platform_view]() {
540 reinterpret_cast<PlatformViewAndroid*>(platform_view.get())
541 ->FireFirstFrameCallback();
547void PlatformViewAndroid::FireFirstFrameCallback() {
548 jni_facade_->FlutterViewOnFirstFrame();
551double PlatformViewAndroid::GetScaledFontSize(
double unscaled_font_size,
552 int configuration_id)
const {
553 return jni_facade_->FlutterViewGetScaledFontSize(unscaled_font_size,
557bool PlatformViewAndroid::IsSurfaceControlEnabled()
const {
559 return android_meets_hcpp_criteria_ &&
560 android_context_->RenderingApi() ==
561 AndroidRenderingAPI::kImpellerVulkan &&
566void PlatformViewAndroid::SetupImpellerContext() {
567 android_context_->SetupImpellerContext();
568 android_surface_->SetupImpellerSurface();
std::unique_ptr< AndroidSurface > CreateSurface() override
~AndroidSurfaceFactoryImpl() override
AndroidSurfaceFactoryImpl(const std::shared_ptr< AndroidContext > &context, bool enable_impeller, bool lazy_shader_mode)
AssetResolverType
Identifies the type of AssetResolver an instance is.
static sk_sp< const GrGLInterface > GetDefaultPlatformGLInterface()
ImageLifecycle
Whether the last image should be reset when the context is destroyed.
static sk_sp< GrDirectContext > CreateCompatibleResourceLoadingContext(GrBackendApi backend, const sk_sp< const GrGLInterface > &gl_interface)
fml::RefPtr< fml::TaskRunner > GetRasterTaskRunner() const
fml::RefPtr< fml::TaskRunner > GetPlatformTaskRunner() const
A Mapping like NonOwnedMapping, but uses Free as its release proc.
static MallocMapping Copy(const T *begin, const T *end)
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
static ContextVK & Cast(Context &base)
bool GetShouldEnableSurfaceControlSwapchain() const
Whether the Android Surface control based swapchain should be enabled.
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
G_BEGIN_DECLS FlutterViewId view_id
#define FML_DLOG(severity)
#define FML_LOG(severity)
#define FML_CHECK(condition)
#define FML_UNREACHABLE()
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
DEF_SWITCHES_START aot vmservice shared library name
constexpr FlutterViewId kImplicitViewId
static std::shared_ptr< flutter::AndroidContext > CreateAndroidContext(const flutter::TaskRunners &task_runners, AndroidRenderingAPI android_rendering_api, bool enable_opengl_gpu_tracing, const AndroidContext::ContextSettings &settings)
bool impeller_enable_lazy_shader_mode
bool enable_surface_control