From e8d881d426badb372032440cec72095b5df550cc Mon Sep 17 00:00:00 2001 From: sievers Date: Thu, 6 Aug 2015 13:01:35 -0700 Subject: [PATCH] Android: Fix null onscreen surface Make sure the current onscreen surface is registered as long as the OutputSurface is alive, so that the GPU thread will not see a null handle. BUG=517279,517283 Review URL: https://codereview.chromium.org/1277653003 Cr-Commit-Position: refs/heads/master@{#342186} --- content/browser/renderer_host/compositor_impl_android.cc | 11 +++++++---- content/common/gpu/image_transport_surface_android.cc | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/content/browser/renderer_host/compositor_impl_android.cc b/content/browser/renderer_host/compositor_impl_android.cc index 2a5b357d5738..358ac519981e 100644 --- a/content/browser/renderer_host/compositor_impl_android.cc +++ b/content/browser/renderer_host/compositor_impl_android.cc @@ -391,11 +391,12 @@ void CompositorImpl::SetWindowSurface(ANativeWindow* window) { GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); if (window_) { + // Shut down GL context before unregistering surface. + SetVisible(false); tracker->RemoveSurface(surface_id_); ANativeWindow_release(window_); window_ = NULL; surface_id_ = 0; - SetVisible(false); } if (window) { @@ -413,10 +414,12 @@ void CompositorImpl::SetSurface(jobject surface) { JNIEnv* env = base::android::AttachCurrentThread(); base::android::ScopedJavaLocalRef j_surface(env, surface); - // First, cleanup any existing surface references. - if (surface_id_) - UnregisterViewSurface(surface_id_); + // First, shut down the GL context. + int surface_id = surface_id_; SetWindowSurface(NULL); + // Then, cleanup any existing surface references. + if (surface_id) + UnregisterViewSurface(surface_id); // Now, set the new surface if we have one. ANativeWindow* window = NULL; diff --git a/content/common/gpu/image_transport_surface_android.cc b/content/common/gpu/image_transport_surface_android.cc index 56030ef080b2..1d3ac9cc471b 100644 --- a/content/common/gpu/image_transport_surface_android.cc +++ b/content/common/gpu/image_transport_surface_android.cc @@ -150,6 +150,7 @@ scoped_refptr ImageTransportSurface::CreateNativeSurface( ANativeWindow* window = GpuSurfaceLookup::GetInstance()->AcquireNativeWidget( stub->surface_id()); + CHECK(window) << "Failed to retrieve window handle."; scoped_refptr surface = new gfx::NativeViewGLSurfaceEGL(window); bool initialize_success = surface->Initialize(); -- 2.11.4.GIT