Clear the GPU thread's EGL context only after the GPUSurfaceGL has been destroyed (flutter/engine#3346)

The GPUSurfaceGL holds references to Skia objects that may own GL objects.
If the GL objects are destructed on the GPU thread after the EGL context has been
dropped, then the GL delete calls will not take effect.
This commit is contained in:
Jason Simmons
2017-01-18 17:19:50 -08:00
committed by GitHub
parent 97184fe85d
commit e5a2958d0a
6 changed files with 9 additions and 10 deletions

View File

@@ -20,7 +20,6 @@ void NullRasterizer::Setup(
void NullRasterizer::Teardown(
ftl::AutoResetWaitableEvent* teardown_completion_event) {
if (surface_) {
surface_->Teardown();
surface_.reset();
}
teardown_completion_event->Signal();

View File

@@ -39,8 +39,6 @@ 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

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

View File

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

View File

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

View File

@@ -319,6 +319,15 @@ void PlatformViewAndroid::SetSemanticsEnabled(JNIEnv* env,
void PlatformViewAndroid::ReleaseSurface() {
NotifyDestroyed();
ftl::AutoResetWaitableEvent latch;
blink::Threads::Gpu()->PostTask([this, &latch]() {
if (surface_gl_->IsValid())
surface_gl_->GLContextClearCurrent();
latch.Signal();
});
latch.Wait();
surface_gl_->TeardownOnScreenContext();
}