Detach the EGL surface from the GPU thread and then destroy it during the FlutterView surfaceDestroyed callback (flutter/engine#3316)

Fixes https://github.com/flutter/flutter/issues/7147
This commit is contained in:
Jason Simmons
2016-12-16 15:36:33 -08:00
committed by GitHub
parent a56d9c1666
commit 49424e1b4f
9 changed files with 25 additions and 1 deletions

View File

@@ -12,12 +12,17 @@ void NullRasterizer::Setup(
std::unique_ptr<Surface> surface_or_null,
ftl::Closure rasterizer_continuation,
ftl::AutoResetWaitableEvent* setup_completion_event) {
surface_ = std::move(surface_or_null);
rasterizer_continuation();
setup_completion_event->Signal();
}
void NullRasterizer::Teardown(
ftl::AutoResetWaitableEvent* teardown_completion_event) {
if (surface_) {
surface_->Teardown();
surface_.reset();
}
teardown_completion_event->Signal();
}

View File

@@ -32,6 +32,7 @@ class NullRasterizer : public Rasterizer {
private:
ftl::WeakPtrFactory<NullRasterizer> weak_factory_;
std::unique_ptr<Surface> surface_;
FTL_DISALLOW_COPY_AND_ASSIGN(NullRasterizer);
};

View File

@@ -39,6 +39,8 @@ class Surface {
virtual bool Setup() = 0;
virtual void Teardown() = 0;
virtual bool IsValid() = 0;
virtual std::unique_ptr<SurfaceFrame> AcquireFrame(const SkISize& size) = 0;

View File

@@ -65,7 +65,10 @@ void GPURasterizer::Clear(SkColor color, const SkISize& size) {
void GPURasterizer::Teardown(
ftl::AutoResetWaitableEvent* teardown_completion_event) {
surface_.reset();
if (surface_) {
surface_->Teardown();
surface_.reset();
}
last_layer_tree_.reset();
compositor_context_.OnGrContextDestroyed();
teardown_completion_event->Signal();

View File

@@ -94,6 +94,10 @@ bool GPUSurfaceGL::Setup() {
return true;
}
void GPUSurfaceGL::Teardown() {
delegate_->GLContextClearCurrent();
}
bool GPUSurfaceGL::IsValid() {
return context_ != nullptr;
}

View File

@@ -31,6 +31,8 @@ class GPUSurfaceGL : public Surface {
bool Setup() override;
void Teardown() override;
bool IsValid() override;
std::unique_ptr<SurfaceFrame> AcquireFrame(const SkISize& size) override;

View File

@@ -79,6 +79,10 @@ bool AndroidSurfaceGL::SetNativeWindowForOnScreenContext(
return true;
}
void AndroidSurfaceGL::TeardownOnScreenContext() {
onscreen_context_ = nullptr;
}
bool AndroidSurfaceGL::IsValid() const {
if (!onscreen_context_ || !offscreen_context_) {
return false;

View File

@@ -24,6 +24,8 @@ class AndroidSurfaceGL : public GPUSurfaceGLDelegate {
AndroidNativeWindow window,
PlatformView::SurfaceConfig onscreen_config);
void TeardownOnScreenContext();
bool IsValid() const;
SkISize OnScreenSurfaceSize() const;

View File

@@ -319,6 +319,7 @@ void PlatformViewAndroid::SetSemanticsEnabled(JNIEnv* env,
void PlatformViewAndroid::ReleaseSurface() {
NotifyDestroyed();
surface_gl_->TeardownOnScreenContext();
}
VsyncWaiter* PlatformViewAndroid::GetVsyncWaiter() {