5#include "flutter/shell/platform/android/platform_view_android.h"
7#include <android/api-level.h>
11#include "flutter/common/graphics/texture.h"
12#include "flutter/fml/synchronization/waitable_event.h"
13#include "flutter/shell/common/shell_io_manager.h"
14#include "flutter/shell/gpu/gpu_surface_gl_delegate.h"
15#include "flutter/shell/platform/android/android_context_gl_impeller.h"
16#include "flutter/shell/platform/android/android_context_gl_skia.h"
17#include "flutter/shell/platform/android/android_context_vulkan_impeller.h"
18#include "flutter/shell/platform/android/android_surface_gl_impeller.h"
19#include "flutter/shell/platform/android/android_surface_gl_skia.h"
20#include "flutter/shell/platform/android/android_surface_software.h"
21#include "flutter/shell/platform/android/image_external_texture_gl.h"
22#include "flutter/shell/platform/android/surface_texture_external_texture_gl.h"
24#if IMPELLER_ENABLE_VULKAN
25#include "flutter/shell/platform/android/android_surface_vulkan_impeller.h"
26#include "flutter/shell/platform/android/image_external_texture_vk.h"
28#include "flutter/shell/platform/android/context/android_context.h"
29#include "flutter/shell/platform/android/external_view_embedder/external_view_embedder.h"
30#include "flutter/shell/platform/android/jni/platform_view_android_jni.h"
31#include "flutter/shell/platform/android/platform_message_response_android.h"
32#include "flutter/shell/platform/android/surface/android_surface.h"
33#include "flutter/shell/platform/android/surface/snapshot_surface_producer.h"
34#include "flutter/shell/platform/android/vsync_waiter_android.h"
39 const std::shared_ptr<AndroidContext>& context,
41 : android_context_(context), enable_impeller_(enable_impeller) {}
46 switch (android_context_->RenderingApi()) {
48 return std::make_unique<AndroidSurfaceSoftware>();
50 return std::make_unique<AndroidSurfaceGLImpeller>(
51 std::static_pointer_cast<AndroidContextGLImpeller>(android_context_));
53 return std::make_unique<AndroidSurfaceGLSkia>(
54 std::static_pointer_cast<AndroidContextGLSkia>(android_context_));
56 return std::make_unique<AndroidSurfaceVulkanImpeller>(
57 std::static_pointer_cast<AndroidContextVulkanImpeller>(
64 bool use_software_rendering,
68 bool enable_vulkan_validation,
69 bool enable_opengl_gpu_tracing,
70 bool enable_vulkan_gpu_tracing) {
71 switch (android_rendering_api) {
75 return std::make_unique<AndroidContextGLImpeller>(
76 std::make_unique<impeller::egl::Display>(),
77 enable_opengl_gpu_tracing);
79 return std::make_unique<AndroidContextVulkanImpeller>(
80 enable_vulkan_validation, enable_vulkan_gpu_tracing);
82 return std::make_unique<AndroidContextGLSkia>(
83 fml::MakeRefCounted<AndroidEnvironmentGL>(),
94 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade,
95 bool use_software_rendering,
102 use_software_rendering,
105 delegate.OnPlatformViewGetSettings().android_rendering_api,
106 delegate.OnPlatformViewGetSettings().enable_vulkan_validation,
107 delegate.OnPlatformViewGetSettings().enable_opengl_gpu_tracing,
108 delegate.OnPlatformViewGetSettings().enable_vulkan_gpu_tracing)) {
114 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade,
115 const std::shared_ptr<flutter::AndroidContext>& android_context)
117 jni_facade_(jni_facade),
118 android_context_(android_context),
119 platform_view_android_delegate_(jni_facade),
121 if (android_context_) {
123 <<
"Could not create surface from invalid Android context.";
124 surface_factory_ = std::make_shared<AndroidSurfaceFactoryImpl>(
128 android_surface_ = surface_factory_->CreateSurface();
129 FML_CHECK(android_surface_ && android_surface_->IsValid())
130 <<
"Could not create an OpenGL, Vulkan or Software surface to set up "
139 if (android_surface_) {
140 InstallFirstFrameCallback();
145 [&latch,
surface = android_surface_.get(),
146 native_window = std::move(native_window)]() {
147 surface->SetNativeWindow(native_window);
158 if (android_surface_) {
162 [&latch,
surface = android_surface_.get(),
163 native_window = std::move(native_window)]() {
164 surface->TeardownOnScreenContext();
165 surface->SetNativeWindow(native_window);
177 if (android_surface_) {
181 [&latch,
surface = android_surface_.get()]() {
182 surface->TeardownOnScreenContext();
190 if (!android_surface_) {
196 [&latch,
surface = android_surface_.get(),
size]() {
197 surface->OnScreenSurfaceResize(size);
205 jobject java_message_data,
206 jint java_message_position,
208 uint8_t* message_data =
209 static_cast<uint8_t*
>(
env->GetDirectBufferAddress(java_message_data));
215 response = fml::MakeRefCounted<PlatformMessageResponseAndroid>(
220 std::make_unique<flutter::PlatformMessage>(
221 std::move(
name), std::move(
message), std::move(response)));
229 response = fml::MakeRefCounted<PlatformMessageResponseAndroid>(
234 std::make_unique<flutter::PlatformMessage>(std::move(
name),
235 std::move(response)));
240 std::unique_ptr<flutter::PlatformMessage>
message) {
242 platform_message_handler_->HandlePlatformMessage(std::move(
message));
247 jni_facade_->FlutterViewOnPreEngineRestart();
254 jint args_position) {
255 if (
env->IsSameObject(
args, NULL)) {
262 uint8_t* args_data =
static_cast<uint8_t*
>(
env->GetDirectBufferAddress(
args));
267 std::move(args_vector));
280 switch (android_context_->RenderingApi()) {
283 RegisterTexture(std::make_shared<SurfaceTextureExternalTextureImpellerGL>(
284 std::static_pointer_cast<impeller::ContextGLES>(
285 android_context_->GetImpellerContext()),
296 <<
"Attempted to use a SurfaceTextureExternalTexture with an "
297 "unsupported rendering API.";
305 switch (android_context_->RenderingApi()) {
309 std::static_pointer_cast<impeller::ContextGLES>(
310 android_context_->GetImpellerContext()),
311 texture_id, image_texture_entry, jni_facade_));
316 std::static_pointer_cast<AndroidContextGLSkia>(android_context_),
317 texture_id, image_texture_entry, jni_facade_));
321 std::static_pointer_cast<impeller::ContextVK>(
322 android_context_->GetImpellerContext()),
323 texture_id, image_texture_entry, jni_facade_));
327 <<
"Attempted to use a SurfaceTextureExternalTexture with an "
328 "unsupported rendering API.";
340 if (!android_surface_) {
343 return android_surface_->CreateGPUSurface(
344 android_context_->GetMainSkiaContext().get());
348std::shared_ptr<ExternalViewEmbedder>
350 return std::make_shared<AndroidExternalViewEmbedder>(
351 *android_context_, jni_facade_, surface_factory_,
task_runners_);
355std::unique_ptr<SnapshotSurfaceProducer>
357 if (!android_surface_) {
360 return std::make_unique<AndroidSnapshotSurfaceProducer>(*android_surface_);
365 if (!android_surface_) {
369 if (android_surface_->ResourceContextMakeCurrent()) {
377 FML_DLOG(
ERROR) <<
"Could not make the resource context current.";
380 return resource_context;
385 if (android_surface_) {
386 android_surface_->ResourceContextClearCurrent();
393 if (android_surface_) {
394 return android_surface_->GetImpellerContext();
400std::unique_ptr<std::vector<std::string>>
402 const std::vector<std::string>& supported_locale_data) {
403 return jni_facade_->FlutterViewComputePlatformResolvedLocale(
404 supported_locale_data);
409 if (jni_facade_->RequestDartDeferredLibrary(loading_unit_id)) {
417 intptr_t loading_unit_id,
418 std::unique_ptr<const fml::Mapping> snapshot_data,
419 std::unique_ptr<const fml::Mapping> snapshot_instructions) {
421 std::move(snapshot_instructions));
426 intptr_t loading_unit_id,
427 const std::string error_message,
435 std::unique_ptr<AssetResolver> updated_asset_resolver,
440void PlatformViewAndroid::InstallFirstFrameCallback() {
446 platform_task_runner->PostTask([platform_view]() {
449 reinterpret_cast<PlatformViewAndroid*>(platform_view.get())
450 ->FireFirstFrameCallback();
456void PlatformViewAndroid::FireFirstFrameCallback() {
457 jni_facade_->FlutterViewOnFirstFrame();
460double PlatformViewAndroid::GetScaledFontSize(
double unscaled_font_size,
461 int configuration_id)
const {
462 return jni_facade_->FlutterViewGetScaledFontSize(unscaled_font_size,
std::unique_ptr< AndroidSurface > CreateSurface() override
AndroidSurfaceFactoryImpl(const std::shared_ptr< AndroidContext > &context, bool enable_impeller)
~AndroidSurfaceFactoryImpl() override
AssetResolverType
Identifies the type of AssetResolver an instance is.
static sk_sp< const GrGLInterface > GetDefaultPlatformGLInterface()
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)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
#define FML_DLOG(severity)
#define FML_LOG(severity)
#define FML_CHECK(condition)
#define FML_UNREACHABLE()
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
static std::shared_ptr< flutter::AndroidContext > CreateAndroidContext(bool use_software_rendering, const flutter::TaskRunners &task_runners, uint8_t msaa_samples, AndroidRenderingAPI android_rendering_api, bool enable_vulkan_validation, bool enable_opengl_gpu_tracing, bool enable_vulkan_gpu_tracing)
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
DEF_SWITCHES_START aot vmservice shared library name
it will be possible to load the file into Perfetto s trace viewer 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