Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
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
4 changes: 4 additions & 0 deletions shell/common/platform_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ std::unique_ptr<Surface> PlatformView::CreateRenderingSurface() {
return nullptr;
}

void PlatformView::ReleaseSurfaceContext() {
// Do nothing by default
}

std::shared_ptr<ExternalViewEmbedder>
PlatformView::CreateExternalViewEmbedder() {
FML_DLOG(WARNING)
Expand Down
10 changes: 10 additions & 0 deletions shell/common/platform_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,16 @@ class PlatformView {
virtual std::unique_ptr<SnapshotSurfaceProducer>
CreateSnapshotSurfaceProducer();

//----------------------------------------------------------------------------
/// @brief Used by the shell to notify the embedder that all the
/// rendering surface previously obtained via a call to
/// `CreateRenderingSurface()` are being collected. The embedder
/// should collect the shared context of surfaces
///
/// @attention This should be called on the rasterizer task runner.
///
virtual void ReleaseSurfaceContext();

protected:
PlatformView::Delegate& delegate_;
const TaskRunners task_runners_;
Expand Down
16 changes: 10 additions & 6 deletions shell/common/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,16 @@ Shell::~Shell() {

fml::TaskRunner::RunNowOrPostTask(
task_runners_.GetRasterTaskRunner(),
fml::MakeCopyable(
[this, rasterizer = std::move(rasterizer_), &gpu_latch]() mutable {
rasterizer.reset();
this->weak_factory_gpu_.reset();
gpu_latch.Signal();
}));
fml::MakeCopyable([this, rasterizer = std::move(rasterizer_),
platform_view = platform_view_.get(),
&gpu_latch]() mutable {
rasterizer.reset();
this->weak_factory_gpu_.reset();
if (platform_view) {
platform_view->ReleaseSurfaceContext();
}
gpu_latch.Signal();
}));
gpu_latch.Wait();

fml::TaskRunner::RunNowOrPostTask(
Expand Down
13 changes: 12 additions & 1 deletion shell/platform/android/platform_view_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ AndroidSurfaceFactoryImpl::~AndroidSurfaceFactoryImpl() = default;
std::unique_ptr<AndroidSurface> AndroidSurfaceFactoryImpl::CreateSurface() {
switch (android_context_->RenderingApi()) {
case AndroidRenderingAPI::kSoftware:
FML_DCHECK(android_context_);
return std::make_unique<AndroidSurfaceSoftware>(android_context_,
jni_facade_);
case AndroidRenderingAPI::kOpenGLES:
FML_DCHECK(android_context_);
return std::make_unique<AndroidSurfaceGL>(android_context_, jni_facade_);
default:
FML_DCHECK(false);
Expand Down Expand Up @@ -290,16 +292,25 @@ std::unique_ptr<VsyncWaiter> PlatformViewAndroid::CreateVSyncWaiter() {

// |PlatformView|
std::unique_ptr<Surface> PlatformViewAndroid::CreateRenderingSurface() {
if (!android_surface_) {
if (!android_surface_ || !android_context_) {
return nullptr;
}
return android_surface_->CreateGPUSurface(
android_context_->GetMainSkiaContext().get());
}

// |PlatformView|
void PlatformViewAndroid::ReleaseSurfaceContext() {
FML_DCHECK(task_runners_.GetRasterTaskRunner()->RunsTasksOnCurrentThread());
if (android_context_) {
android_context_.reset();
}
}

// |PlatformView|
std::shared_ptr<ExternalViewEmbedder>
PlatformViewAndroid::CreateExternalViewEmbedder() {
FML_DCHECK(android_context_);
return std::make_shared<AndroidExternalViewEmbedder>(
*android_context_, jni_facade_, surface_factory_);
}
Expand Down
3 changes: 3 additions & 0 deletions shell/platform/android/platform_view_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ class PlatformViewAndroid final : public PlatformView {
// |PlatformView|
std::unique_ptr<Surface> CreateRenderingSurface() override;

// |PlatformView|
void ReleaseSurfaceContext() override;

// |PlatformView|
std::shared_ptr<ExternalViewEmbedder> CreateExternalViewEmbedder() override;

Expand Down
3 changes: 3 additions & 0 deletions shell/platform/darwin/ios/platform_view_ios.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ class PlatformViewIOS final : public PlatformView {
// |PlatformView|
std::unique_ptr<Surface> CreateRenderingSurface() override;

// |PlatformView|
void ReleaseSurfaceContext() override;

// |PlatformView|
std::shared_ptr<ExternalViewEmbedder> CreateExternalViewEmbedder() override;

Expand Down
13 changes: 13 additions & 0 deletions shell/platform/darwin/ios/platform_view_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@

void PlatformViewIOS::attachView() {
FML_DCHECK(owner_controller_);
FML_DCHECK(ios_context_);
FML_DCHECK(owner_controller_.get().isViewLoaded)
<< "FlutterViewController's view should be loaded "
"before attaching to PlatformViewIOS.";
Expand All @@ -135,13 +136,15 @@

void PlatformViewIOS::RegisterExternalTexture(int64_t texture_id,
NSObject<FlutterTexture>* texture) {
FML_DCHECK(ios_context_);
RegisterTexture(ios_context_->CreateExternalTexture(
texture_id, fml::scoped_nsobject<NSObject<FlutterTexture>>{[texture retain]}));
}

// |PlatformView|
std::unique_ptr<Surface> PlatformViewIOS::CreateRenderingSurface() {
FML_DCHECK(task_runners_.GetRasterTaskRunner()->RunsTasksOnCurrentThread());
FML_DCHECK(ios_context_);
std::lock_guard<std::mutex> guard(ios_surface_mutex_);
if (!ios_surface_) {
FML_DLOG(INFO) << "Could not CreateRenderingSurface, this PlatformViewIOS "
Expand All @@ -151,13 +154,23 @@
return ios_surface_->CreateGPUSurface(ios_context_->GetMainContext().get());
}

// |PlatformView|
void PlatformViewIOS::ReleaseSurfaceContext() {
FML_DCHECK(task_runners_.GetRasterTaskRunner()->RunsTasksOnCurrentThread());
if (ios_context_) {
ios_context_.reset();
}
}

// |PlatformView|
std::shared_ptr<ExternalViewEmbedder> PlatformViewIOS::CreateExternalViewEmbedder() {
FML_DCHECK(ios_context_);
return std::make_shared<IOSExternalViewEmbedder>(platform_views_controller_, ios_context_);
}

// |PlatformView|
sk_sp<GrDirectContext> PlatformViewIOS::CreateResourceContext() const {
FML_DCHECK(ios_context_);
return ios_context_->CreateResourceContext();
}

Expand Down