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.lazy_shader_mode =
63 p_settings.impeller_enable_lazy_shader_mode;
64 settings.impeller_flags.antialiased_lines =
65 p_settings.impeller_antialiased_lines;
71 const std::shared_ptr<AndroidContext>& context,
73 bool lazy_shader_mode)
74 : android_context_(context),
75 enable_impeller_(enable_impeller),
76 lazy_shader_mode_(lazy_shader_mode) {}
81 if (android_context_->IsDynamicSelection()) {
82 auto cast_ptr = std::static_pointer_cast<AndroidContextDynamicImpeller>(
84 return std::make_unique<AndroidSurfaceDynamicImpeller>(cast_ptr);
86 switch (android_context_->RenderingApi()) {
89 return std::make_unique<AndroidSurfaceSoftware>();
91 return std::make_unique<AndroidSurfaceGLSkia>(
92 std::static_pointer_cast<AndroidContextGLSkia>(android_context_));
95 return std::make_unique<AndroidSurfaceGLImpeller>(
96 std::static_pointer_cast<AndroidContextGLImpeller>(android_context_));
98 return std::make_unique<AndroidSurfaceVKImpeller>(
99 std::static_pointer_cast<AndroidContextVKImpeller>(android_context_));
101 auto cast_ptr = std::static_pointer_cast<AndroidContextDynamicImpeller>(
103 return std::make_unique<AndroidSurfaceDynamicImpeller>(cast_ptr);
112 bool enable_opengl_gpu_tracing,
114 switch (android_rendering_api) {
119 return std::make_unique<AndroidContextGLSkia>(
120 fml::MakeRefCounted<AndroidEnvironmentGL>(),
125 return std::make_unique<AndroidContextVKImpeller>(settings);
127 return std::make_unique<AndroidContextGLImpeller>(
128 std::make_unique<impeller::egl::Display>(),
129 enable_opengl_gpu_tracing);
132 return std::make_unique<AndroidContextDynamicImpeller>(settings);
140 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade,
149 delegate.OnPlatformViewGetSettings().enable_opengl_gpu_tracing,
150 CreateContextSettings(delegate.OnPlatformViewGetSettings()))) {}
155 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade,
156 const std::shared_ptr<flutter::AndroidContext>& android_context)
158 jni_facade_(jni_facade),
159 android_context_(android_context),
160 platform_view_android_delegate_(jni_facade),
162 if (android_context_) {
164 <<
"Could not create surface from invalid Android context.";
165 surface_factory_ = std::make_shared<AndroidSurfaceFactoryImpl>(
171 android_surface_ = surface_factory_->CreateSurface();
172 android_meets_hcpp_criteria_ =
174 android_get_device_api_level() >= kMinAPILevelHCPP &&
176 FML_CHECK(android_surface_ && android_surface_->IsValid())
177 <<
"Could not create an OpenGL, Vulkan or Software surface to set "
187 if (android_surface_) {
188 InstallFirstFrameCallback();
193 [&latch,
surface = android_surface_.get(),
194 native_window = std::move(native_window), jni_facade = jni_facade_]() {
195 surface->SetNativeWindow(native_window, jni_facade);
206 if (android_surface_) {
210 [&latch,
surface = android_surface_.get(),
211 native_window = std::move(native_window), jni_facade = jni_facade_]() {
212 surface->TeardownOnScreenContext();
213 surface->SetNativeWindow(native_window, jni_facade);
225 if (android_surface_) {
229 [&latch,
surface = android_surface_.get()]() {
230 surface->TeardownOnScreenContext();
238 if (!android_surface_) {
244 [&latch,
surface = android_surface_.get(),
size]() {
245 surface->OnScreenSurfaceResize(size);
253 jobject java_message_data,
254 jint java_message_position,
256 uint8_t* message_data =
257 static_cast<uint8_t*
>(env->GetDirectBufferAddress(java_message_data));
263 response = fml::MakeRefCounted<PlatformMessageResponseAndroid>(
268 std::make_unique<flutter::PlatformMessage>(
269 std::move(
name), std::move(
message), std::move(response)));
277 response = fml::MakeRefCounted<PlatformMessageResponseAndroid>(
282 std::make_unique<flutter::PlatformMessage>(std::move(
name),
283 std::move(response)));
287void PlatformViewAndroid::HandlePlatformMessage(
288 std::unique_ptr<flutter::PlatformMessage>
message) {
290 platform_message_handler_->HandlePlatformMessage(std::move(
message));
294void PlatformViewAndroid::OnPreEngineRestart()
const {
295 jni_facade_->FlutterViewOnPreEngineRestart();
302 jint args_position) {
305 if (env->IsSameObject(
args, NULL)) {
312 uint8_t* args_data =
static_cast<uint8_t*
>(env->GetDirectBufferAddress(
args));
317 std::move(args_vector));
321void PlatformViewAndroid::UpdateSemantics(
329void PlatformViewAndroid::SetApplicationLocale(std::string locale) {
330 jni_facade_->FlutterViewSetApplicationLocale(std::move(locale));
334void PlatformViewAndroid::SetSemanticsTreeEnabled(
bool enabled) {
335 jni_facade_->FlutterViewSetSemanticsTreeEnabled(enabled);
341 switch (android_context_->RenderingApi()) {
344 RegisterTexture(std::make_shared<SurfaceTextureExternalTextureGLImpeller>(
345 std::static_pointer_cast<impeller::ContextGLES>(
346 android_context_->GetImpellerContext()),
362 FML_LOG(INFO) <<
"Software rendering does not support external textures.";
367 <<
"Flutter recommends migrating plugins that create and "
368 "register surface textures to the new surface producer "
369 "API. See https://docs.flutter.dev/release/breaking-changes/"
370 "android-surface-plugins";
371 RegisterTexture(std::make_shared<SurfaceTextureExternalTextureVKImpeller>(
372 std::static_pointer_cast<impeller::ContextVK>(
373 android_context_->GetImpellerContext()),
390 switch (android_context_->RenderingApi()) {
395 std::static_pointer_cast<AndroidContextGLSkia>(android_context_),
396 texture_id, image_texture_entry, jni_facade_, lifecycle));
399 FML_LOG(INFO) <<
"Software rendering does not support external textures.";
405 std::static_pointer_cast<impeller::ContextGLES>(
406 android_context_->GetImpellerContext()),
407 texture_id, image_texture_entry, jni_facade_, lifecycle));
411 std::static_pointer_cast<impeller::ContextVK>(
412 android_context_->GetImpellerContext()),
413 texture_id, image_texture_entry, jni_facade_, lifecycle));
422std::unique_ptr<VsyncWaiter> PlatformViewAndroid::CreateVSyncWaiter() {
427std::unique_ptr<Surface> PlatformViewAndroid::CreateRenderingSurface() {
428 if (!android_surface_) {
431 return android_surface_->CreateGPUSurface(
432 android_context_->GetMainSkiaContext().get());
436std::shared_ptr<ExternalViewEmbedder>
437PlatformViewAndroid::CreateExternalViewEmbedder() {
438 return std::make_shared<AndroidExternalViewEmbedderWrapper>(
439 android_meets_hcpp_criteria_, *android_context_, jni_facade_,
444std::unique_ptr<SnapshotSurfaceProducer>
445PlatformViewAndroid::CreateSnapshotSurfaceProducer() {
446 if (!android_surface_) {
449 return std::make_unique<AndroidSnapshotSurfaceProducer>(*android_surface_);
453sk_sp<GrDirectContext> PlatformViewAndroid::CreateResourceContext()
const {
454 if (!android_surface_) {
458 sk_sp<GrDirectContext> resource_context;
459 if (android_surface_->ResourceContextMakeCurrent()) {
464 GrBackendApi::kOpenGL,
467 FML_DLOG(ERROR) <<
"Could not make the resource context current.";
469 return resource_context;
471 android_surface_->ResourceContextMakeCurrent();
477void PlatformViewAndroid::ReleaseResourceContext()
const {
478 if (android_surface_) {
479 android_surface_->ResourceContextClearCurrent();
484std::shared_ptr<impeller::Context> PlatformViewAndroid::GetImpellerContext()
486 if (android_surface_) {
487 return android_surface_->GetImpellerContext();
489 return android_context_->GetImpellerContext();
493std::unique_ptr<std::vector<std::string>>
494PlatformViewAndroid::ComputePlatformResolvedLocales(
495 const std::vector<std::string>& supported_locale_data) {
496 return jni_facade_->FlutterViewComputePlatformResolvedLocale(
497 supported_locale_data);
501void PlatformViewAndroid::RequestDartDeferredLibrary(intptr_t loading_unit_id) {
502 if (jni_facade_->RequestDartDeferredLibrary(loading_unit_id)) {
510 intptr_t loading_unit_id,
511 std::unique_ptr<const fml::Mapping> snapshot_data,
512 std::unique_ptr<const fml::Mapping> snapshot_instructions) {
514 std::move(snapshot_instructions));
519 intptr_t loading_unit_id,
520 const std::string error_message,
528 std::unique_ptr<AssetResolver> updated_asset_resolver,
533void PlatformViewAndroid::InstallFirstFrameCallback() {
539 platform_task_runner->PostTask([platform_view]() {
542 reinterpret_cast<PlatformViewAndroid*>(platform_view.get())
543 ->FireFirstFrameCallback();
549void PlatformViewAndroid::FireFirstFrameCallback() {
550 jni_facade_->FlutterViewOnFirstFrame();
553double PlatformViewAndroid::GetScaledFontSize(
double unscaled_font_size,
554 int configuration_id)
const {
555 return jni_facade_->FlutterViewGetScaledFontSize(unscaled_font_size,
559bool PlatformViewAndroid::IsSurfaceControlEnabled()
const {
561 return android_meets_hcpp_criteria_ &&
562 android_context_->RenderingApi() ==
563 AndroidRenderingAPI::kImpellerVulkan &&
568void PlatformViewAndroid::SetupImpellerContext() {
569 android_context_->SetupImpellerContext();
570 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