From eef941140f3d48b8c2fa9f22d98273a5117d5ab9 Mon Sep 17 00:00:00 2001 From: James Robinson Date: Mon, 28 Sep 2015 14:41:16 -0700 Subject: [PATCH] Handle a picture in a TextureLayer with an empty cull rect If we have a layer with a picture where the cull rect computes down to an empty rectangle attempting to rasterize it into a ganesh surface will fail in the same manner that trying to ganesh rasterize an empty layer will. This teaches LayerHost to check for this case and handle it like an empty layer. Fixes #1337 --- services/sky/compositor/layer_host.cc | 12 ++++++++++++ services/sky/compositor/rasterizer_ganesh.cc | 2 ++ services/sky/compositor/texture_layer.cc | 4 ++++ services/sky/compositor/texture_layer.h | 1 + 4 files changed, 19 insertions(+) diff --git a/services/sky/compositor/layer_host.cc b/services/sky/compositor/layer_host.cc index f8bfb119fe3..a12f165e423 100644 --- a/services/sky/compositor/layer_host.cc +++ b/services/sky/compositor/layer_host.cc @@ -83,6 +83,18 @@ void LayerHost::BeginFrame() { root_layer_->Display(); } + // We may have culled the root layer down to nothing which is equivalent to + // the empty size case above. + // + // TODO(jamesr): This needs to have proper flow control as well to avoid + // spinning when we have nothing to draw. + if (!root_layer_->HaveTexture()) { + base::MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind(&LayerHost::DidCompleteFrame, weak_factory_.GetWeakPtr())); + return; + } + Upload(root_layer_.get()); } diff --git a/services/sky/compositor/rasterizer_ganesh.cc b/services/sky/compositor/rasterizer_ganesh.cc index d5d0e6f2f7a..1d660bee4bb 100644 --- a/services/sky/compositor/rasterizer_ganesh.cc +++ b/services/sky/compositor/rasterizer_ganesh.cc @@ -24,6 +24,8 @@ scoped_ptr RasterizerGanesh::Rasterize(SkPicture* picture) { SkRect cull_rect = picture->cullRect(); gfx::Size size(cull_rect.width(), cull_rect.height()); + if (size.IsEmpty()) + return nullptr; mojo::GaneshSurface surface(host_->ganesh_context(), host_->resource_manager()->CreateTexture(size)); diff --git a/services/sky/compositor/texture_layer.cc b/services/sky/compositor/texture_layer.cc index fc1d5f885cc..134fcf37aca 100644 --- a/services/sky/compositor/texture_layer.cc +++ b/services/sky/compositor/texture_layer.cc @@ -45,6 +45,10 @@ PassRefPtr TextureLayer::RecordPicture() { return adoptRef(recorder.endRecordingAsPicture()); } +bool TextureLayer::HaveTexture() const { + return texture_; +} + scoped_ptr TextureLayer::GetTexture() { return texture_.Pass(); } diff --git a/services/sky/compositor/texture_layer.h b/services/sky/compositor/texture_layer.h index 0bee97cf75a..306d1c8f0ad 100644 --- a/services/sky/compositor/texture_layer.h +++ b/services/sky/compositor/texture_layer.h @@ -24,6 +24,7 @@ class TextureLayer : public base::RefCounted { void SetSize(const gfx::Size& size); void Display(); + bool HaveTexture() const; scoped_ptr GetTexture(); const gfx::Size& size() const { return size_; }