Slightly improve recovery from losing GL context.
This is still somewhat broken but at least it doesn't crash
due to reentrance. We should probably rethink how GLContext
lifetime is managed in general.
BUG=
R=abarth@google.com
Review URL: https://codereview.chromium.org/1687653003 .
diff --git a/mojo/skia/ganesh_context.cc b/mojo/skia/ganesh_context.cc
index 735a902..b684231 100644
--- a/mojo/skia/ganesh_context.cc
+++ b/mojo/skia/ganesh_context.cc
@@ -46,7 +46,9 @@
}
void GaneshContext::OnContextLost() {
- ReleaseContext();
+ context_lost_ = true;
+ if (!scope_entered_)
+ ReleaseContext();
}
void GaneshContext::ReleaseContext() {
@@ -76,12 +78,17 @@
CHECK(scope_entered_);
scope_entered_ = false;
- // Flush the Ganesh context when exiting its scope.
- if (gr_context_)
- gr_context_->flush();
+ if (gl_context_) {
+ // Flush the Ganesh context when exiting its scope.
+ if (gr_context_)
+ gr_context_->flush();
- MGLMakeCurrent(previous_mgl_context_);
- previous_mgl_context_ = MGL_NO_CONTEXT;
+ MGLMakeCurrent(previous_mgl_context_);
+ previous_mgl_context_ = MGL_NO_CONTEXT;
+
+ if (context_lost_)
+ ReleaseContext();
+ }
}
} // namespace skia
diff --git a/mojo/skia/ganesh_context.h b/mojo/skia/ganesh_context.h
index e3f72db..d7edf31 100644
--- a/mojo/skia/ganesh_context.h
+++ b/mojo/skia/ganesh_context.h
@@ -79,6 +79,7 @@
::skia::RefPtr<GrContext> gr_context_;
bool scope_entered_ = false;
+ bool context_lost_ = false;
MGLContext previous_mgl_context_ = MGL_NO_CONTEXT;
DISALLOW_COPY_AND_ASSIGN(GaneshContext);