Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions shell/platform/android/platform_view_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,28 @@ namespace flutter {

AndroidSurfaceFactoryImpl::AndroidSurfaceFactoryImpl(
std::shared_ptr<AndroidContext> context,
std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
android_context_ = context;
jni_facade_ = jni_facade;
}
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
std::weak_ptr<AndroidExternalViewEmbedder> external_view_embedder)
: android_context_(context), jni_facade_(jni_facade),
external_view_embedder_(external_view_embedder) {}

AndroidSurfaceFactoryImpl::~AndroidSurfaceFactoryImpl() = default;

void AndroidSurfaceFactoryImpl::SetExternalViewEmbedder(
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder) {
external_view_embedder_ = external_view_embedder;
}

std::unique_ptr<AndroidSurface> AndroidSurfaceFactoryImpl::CreateSurface() {
FML_CHECK(external_view_embedder_);
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder =
external_view_embedder_.lock();
FML_CHECK(external_view_embedder);
switch (android_context_->RenderingApi()) {
case AndroidRenderingAPI::kSoftware:
return std::make_unique<AndroidSurfaceSoftware>(
android_context_, jni_facade_, external_view_embedder_);
android_context_, jni_facade_, external_view_embedder);
case AndroidRenderingAPI::kOpenGLES:
return std::make_unique<AndroidSurfaceGL>(android_context_, jni_facade_,
external_view_embedder_);
external_view_embedder);
case AndroidRenderingAPI::kVulkan:
#if SHELL_ENABLE_VULKAN
return std::make_unique<AndroidSurfaceVulkan>(
android_context_, jni_facade_, external_view_embedder_);
android_context_, jni_facade_, external_view_embedder);
#endif // SHELL_ENABLE_VULKAN
default:
return nullptr;
Expand Down Expand Up @@ -87,11 +84,12 @@ PlatformViewAndroid::PlatformViewAndroid(
FML_CHECK(android_context && android_context->IsValid())
<< "Could not create an Android context.";

external_view_embedder_ =
std::make_shared<AndroidExternalViewEmbedder>(android_context, jni_facade,
surface_factory_);
surface_factory_ =
std::make_shared<AndroidSurfaceFactoryImpl>(android_context, jni_facade);
surface_factory_->SetExternalViewEmbedder(
std::make_shared<AndroidExternalViewEmbedder>(android_context, jni_facade,
surface_factory_));
std::make_shared<AndroidSurfaceFactoryImpl>(android_context, jni_facade,
external_view_embedder_);

android_surface_ = surface_factory_->CreateSurface();
FML_CHECK(android_surface_ && android_surface_->IsValid())
Expand Down
10 changes: 4 additions & 6 deletions shell/platform/android/platform_view_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,17 @@ namespace flutter {
class AndroidSurfaceFactoryImpl : public AndroidSurfaceFactory {
public:
AndroidSurfaceFactoryImpl(std::shared_ptr<AndroidContext> context,
std::shared_ptr<PlatformViewAndroidJNI> jni_facade);
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
std::weak_ptr<AndroidExternalViewEmbedder> external_view_embedder);

~AndroidSurfaceFactoryImpl() override;

std::unique_ptr<AndroidSurface> CreateSurface() override;

void SetExternalViewEmbedder(
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder);

private:
std::shared_ptr<AndroidContext> android_context_;
std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder_;

std::weak_ptr<AndroidExternalViewEmbedder> external_view_embedder_;
};

class PlatformViewAndroid final : public PlatformView {
Expand Down Expand Up @@ -99,6 +96,7 @@ class PlatformViewAndroid final : public PlatformView {

private:
const std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder_;
std::shared_ptr<AndroidSurfaceFactoryImpl> surface_factory_;

PlatformViewAndroidDelegate platform_view_android_delegate_;
Expand Down