summaryrefslogtreecommitdiffstats
path: root/cc/layers
diff options
context:
space:
mode:
authorawoloszyn@chromium.org <awoloszyn@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-11 17:39:54 +0000
committerawoloszyn@chromium.org <awoloszyn@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-11 17:41:20 +0000
commitad63b2ffb295d0de395b83faeff6125475f0f5c4 (patch)
tree1d867e1db456fd4bb95f5e0a202e7005d5f6ae85 /cc/layers
parent6ebf79234c9c16a3611a05f481e845433ddd7271 (diff)
downloadchromium_src-ad63b2ffb295d0de395b83faeff6125475f0f5c4.zip
chromium_src-ad63b2ffb295d0de395b83faeff6125475f0f5c4.tar.gz
chromium_src-ad63b2ffb295d0de395b83faeff6125475f0f5c4.tar.bz2
Keeping track of descendants that draw content instead of recalcualting
This is a required for removing Render Surface creation from CalcDrawProps. BUG=386788 Review URL: https://codereview.chromium.org/373113003 Cr-Commit-Position: refs/heads/master@{#288740} git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288740 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/layers')
-rw-r--r--cc/layers/content_layer.cc9
-rw-r--r--cc/layers/content_layer.h5
-rw-r--r--cc/layers/delegated_renderer_layer.cc4
-rw-r--r--cc/layers/delegated_renderer_layer.h1
-rw-r--r--cc/layers/delegated_renderer_layer_impl_unittest.cc4
-rw-r--r--cc/layers/delegated_renderer_layer_unittest.cc78
-rw-r--r--cc/layers/draw_properties.h4
-rw-r--r--cc/layers/heads_up_display_layer.cc9
-rw-r--r--cc/layers/heads_up_display_layer.h2
-rw-r--r--cc/layers/image_layer.cc9
-rw-r--r--cc/layers/image_layer.h4
-rw-r--r--cc/layers/io_surface_layer.cc5
-rw-r--r--cc/layers/io_surface_layer.h2
-rw-r--r--cc/layers/layer.cc54
-rw-r--r--cc/layers/layer.h19
-rw-r--r--cc/layers/layer_impl.cc13
-rw-r--r--cc/layers/layer_impl.h4
-rw-r--r--cc/layers/layer_impl_unittest.cc2
-rw-r--r--cc/layers/picture_image_layer.cc5
-rw-r--r--cc/layers/picture_image_layer.h4
-rw-r--r--cc/layers/picture_layer.cc13
-rw-r--r--cc/layers/picture_layer.h4
-rw-r--r--cc/layers/surface_layer.cc5
-rw-r--r--cc/layers/surface_layer.h2
-rw-r--r--cc/layers/texture_layer.cc6
-rw-r--r--cc/layers/texture_layer.h2
-rw-r--r--cc/layers/tiled_layer.cc15
-rw-r--r--cc/layers/tiled_layer.h3
-rw-r--r--cc/layers/ui_resource_layer.cc15
-rw-r--r--cc/layers/ui_resource_layer.h4
30 files changed, 251 insertions, 55 deletions
diff --git a/cc/layers/content_layer.cc b/cc/layers/content_layer.cc
index d720501..c1eec73 100644
--- a/cc/layers/content_layer.cc
+++ b/cc/layers/content_layer.cc
@@ -45,8 +45,13 @@ ContentLayer::ContentLayer(ContentLayerClient* client)
ContentLayer::~ContentLayer() {}
-bool ContentLayer::DrawsContent() const {
- return TiledLayer::DrawsContent() && client_;
+void ContentLayer::ClearClient() {
+ client_ = NULL;
+ UpdateDrawsContent(HasDrawableContent());
+}
+
+bool ContentLayer::HasDrawableContent() const {
+ return client_ && TiledLayer::HasDrawableContent();
}
void ContentLayer::SetLayerTreeHost(LayerTreeHost* host) {
diff --git a/cc/layers/content_layer.h b/cc/layers/content_layer.h
index 9bef22b..c440c6f 100644
--- a/cc/layers/content_layer.h
+++ b/cc/layers/content_layer.h
@@ -38,9 +38,8 @@ class CC_EXPORT ContentLayer : public TiledLayer {
public:
static scoped_refptr<ContentLayer> Create(ContentLayerClient* client);
- void ClearClient() { client_ = NULL; }
+ void ClearClient();
- virtual bool DrawsContent() const OVERRIDE;
virtual void SetLayerTreeHost(LayerTreeHost* layer_tree_host) OVERRIDE;
virtual void SetTexturePriorities(const PriorityCalculator& priority_calc)
OVERRIDE;
@@ -60,6 +59,8 @@ class CC_EXPORT ContentLayer : public TiledLayer {
explicit ContentLayer(ContentLayerClient* client);
virtual ~ContentLayer();
+ virtual bool HasDrawableContent() const OVERRIDE;
+
// TiledLayer implementation.
virtual LayerUpdater* Updater() const OVERRIDE;
diff --git a/cc/layers/delegated_renderer_layer.cc b/cc/layers/delegated_renderer_layer.cc
index c472061..2dd1234 100644
--- a/cc/layers/delegated_renderer_layer.cc
+++ b/cc/layers/delegated_renderer_layer.cc
@@ -98,4 +98,8 @@ bool DelegatedRendererLayer::Update(ResourceUpdateQueue* queue,
return true;
}
+bool DelegatedRendererLayer::HasDelegatedContent() const {
+ return true;
+}
+
} // namespace cc
diff --git a/cc/layers/delegated_renderer_layer.h b/cc/layers/delegated_renderer_layer.h
index 3bc0aa8..0e4b958 100644
--- a/cc/layers/delegated_renderer_layer.h
+++ b/cc/layers/delegated_renderer_layer.h
@@ -32,6 +32,7 @@ class CC_EXPORT DelegatedRendererLayer : public Layer {
// Called by the DelegatedFrameProvider when a new frame is available to be
// picked up.
void ProviderHasNewFrame();
+ virtual bool HasDelegatedContent() const OVERRIDE;
protected:
DelegatedRendererLayer(
diff --git a/cc/layers/delegated_renderer_layer_impl_unittest.cc b/cc/layers/delegated_renderer_layer_impl_unittest.cc
index 18336d1..94050ae 100644
--- a/cc/layers/delegated_renderer_layer_impl_unittest.cc
+++ b/cc/layers/delegated_renderer_layer_impl_unittest.cc
@@ -311,6 +311,8 @@ TEST_F(DelegatedRendererLayerImplTestSimple, DoesOwnARenderSurfaceForOpacity) {
delegated_renderer_layer_->SetOpacity(0.5f);
LayerTreeHostImpl::FrameData frame;
+ FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(
+ host_impl_->active_tree()->root_layer());
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// This test case has quads from multiple layers in the delegated renderer, so
@@ -329,6 +331,8 @@ TEST_F(DelegatedRendererLayerImplTestSimple,
delegated_renderer_layer_->SetTransform(rotation);
LayerTreeHostImpl::FrameData frame;
+ FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(
+ host_impl_->active_tree()->root_layer());
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// This test case has quads from multiple layers in the delegated renderer, so
diff --git a/cc/layers/delegated_renderer_layer_unittest.cc b/cc/layers/delegated_renderer_layer_unittest.cc
new file mode 100644
index 0000000..b997a26
--- /dev/null
+++ b/cc/layers/delegated_renderer_layer_unittest.cc
@@ -0,0 +1,78 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/layers/delegated_renderer_layer.h"
+
+#include "cc/layers/delegated_frame_provider.h"
+#include "cc/layers/delegated_frame_resource_collection.h"
+#include "cc/layers/solid_color_layer.h"
+#include "cc/output/delegated_frame_data.h"
+#include "cc/test/fake_delegated_renderer_layer.h"
+#include "cc/test/fake_layer_tree_host.h"
+#include "cc/test/fake_proxy.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace cc {
+namespace {
+
+class DelegatedRendererLayerTest : public testing::Test {
+ public:
+ DelegatedRendererLayerTest() : proxy_() {
+ LayerTreeSettings settings;
+ settings.minimum_occlusion_tracking_size = gfx::Size();
+
+ host_impl_ = FakeLayerTreeHost::Create(settings);
+ host_impl_->SetViewportSize(gfx::Size(10, 10));
+ }
+
+ protected:
+ FakeProxy proxy_;
+ TestSharedBitmapManager shared_bitmap_manager_;
+ scoped_ptr<LayerTreeHost> host_impl_;
+};
+
+class DelegatedRendererLayerTestSimple : public DelegatedRendererLayerTest {
+ public:
+ DelegatedRendererLayerTestSimple() : DelegatedRendererLayerTest() {
+ scoped_ptr<RenderPass> root_pass(RenderPass::Create());
+ root_pass->SetNew(RenderPass::Id(1, 1),
+ gfx::Rect(1, 1),
+ gfx::Rect(1, 1),
+ gfx::Transform());
+ scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
+ frame_data->render_pass_list.push_back(root_pass.Pass());
+ resources_ = new DelegatedFrameResourceCollection;
+ provider_ = new DelegatedFrameProvider(resources_, frame_data.Pass());
+ root_layer_ = SolidColorLayer::Create();
+ layer_before_ = SolidColorLayer::Create();
+ delegated_renderer_layer_ = FakeDelegatedRendererLayer::Create(provider_);
+ }
+
+ protected:
+ scoped_refptr<Layer> root_layer_;
+ scoped_refptr<Layer> layer_before_;
+ scoped_refptr<DelegatedRendererLayer> delegated_renderer_layer_;
+ scoped_refptr<DelegatedFrameResourceCollection> resources_;
+ scoped_refptr<DelegatedFrameProvider> provider_;
+};
+
+TEST_F(DelegatedRendererLayerTestSimple, DelegatedManyDescendants) {
+ EXPECT_EQ(0, root_layer_->NumDescendantsThatDrawContent());
+ root_layer_->AddChild(layer_before_);
+ EXPECT_EQ(0, root_layer_->NumDescendantsThatDrawContent());
+ layer_before_->SetIsDrawable(true);
+ EXPECT_EQ(1, root_layer_->NumDescendantsThatDrawContent());
+ EXPECT_EQ(0, layer_before_->NumDescendantsThatDrawContent());
+ layer_before_->AddChild(delegated_renderer_layer_);
+ EXPECT_EQ(0, layer_before_->NumDescendantsThatDrawContent());
+ EXPECT_EQ(0, delegated_renderer_layer_->NumDescendantsThatDrawContent());
+ EXPECT_EQ(1, root_layer_->NumDescendantsThatDrawContent());
+ delegated_renderer_layer_->SetIsDrawable(true);
+ EXPECT_EQ(1000, delegated_renderer_layer_->NumDescendantsThatDrawContent());
+ EXPECT_EQ(1001, layer_before_->NumDescendantsThatDrawContent());
+ EXPECT_EQ(1002, root_layer_->NumDescendantsThatDrawContent());
+}
+
+} // namespace
+} // namespace cc
diff --git a/cc/layers/draw_properties.h b/cc/layers/draw_properties.h
index a0bfc2a..4bbce72 100644
--- a/cc/layers/draw_properties.h
+++ b/cc/layers/draw_properties.h
@@ -26,7 +26,6 @@ struct CC_EXPORT DrawProperties {
render_target(NULL),
contents_scale_x(1.f),
contents_scale_y(1.f),
- num_descendants_that_draw_content(0),
num_unclipped_descendants(0),
layer_or_descendant_has_copy_request(false),
layer_or_descendant_has_input_handler(false),
@@ -96,9 +95,6 @@ struct CC_EXPORT DrawProperties {
float contents_scale_y;
gfx::Size content_bounds;
- // Does not include this layer itself, only its children and descendants.
- int num_descendants_that_draw_content;
-
// Number of descendants with a clip parent that is our ancestor. NB - this
// does not include our clip children because they are clipped by us.
int num_unclipped_descendants;
diff --git a/cc/layers/heads_up_display_layer.cc b/cc/layers/heads_up_display_layer.cc
index ca63471..6adf8d0 100644
--- a/cc/layers/heads_up_display_layer.cc
+++ b/cc/layers/heads_up_display_layer.cc
@@ -16,7 +16,10 @@ scoped_refptr<HeadsUpDisplayLayer> HeadsUpDisplayLayer::Create() {
return make_scoped_refptr(new HeadsUpDisplayLayer());
}
-HeadsUpDisplayLayer::HeadsUpDisplayLayer() {}
+HeadsUpDisplayLayer::HeadsUpDisplayLayer() {
+ SetIsDrawable(true);
+ UpdateDrawsContent(HasDrawableContent());
+}
HeadsUpDisplayLayer::~HeadsUpDisplayLayer() {}
@@ -47,7 +50,9 @@ void HeadsUpDisplayLayer::PrepareForCalculateDrawProperties(
SetTransform(matrix);
}
-bool HeadsUpDisplayLayer::DrawsContent() const { return true; }
+bool HeadsUpDisplayLayer::HasDrawableContent() const {
+ return true;
+}
scoped_ptr<LayerImpl> HeadsUpDisplayLayer::CreateLayerImpl(
LayerTreeImpl* tree_impl) {
diff --git a/cc/layers/heads_up_display_layer.h b/cc/layers/heads_up_display_layer.h
index 4750faf..12d6aef 100644
--- a/cc/layers/heads_up_display_layer.h
+++ b/cc/layers/heads_up_display_layer.h
@@ -20,13 +20,13 @@ class CC_EXPORT HeadsUpDisplayLayer : public ContentsScalingLayer {
void PrepareForCalculateDrawProperties(
const gfx::Size& device_viewport, float device_scale_factor);
- virtual bool DrawsContent() const OVERRIDE;
virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl)
OVERRIDE;
protected:
HeadsUpDisplayLayer();
+ virtual bool HasDrawableContent() const OVERRIDE;
private:
virtual ~HeadsUpDisplayLayer();
diff --git a/cc/layers/image_layer.cc b/cc/layers/image_layer.cc
index edcf1dc..67e620c 100644
--- a/cc/layers/image_layer.cc
+++ b/cc/layers/image_layer.cc
@@ -30,9 +30,14 @@ void ImageLayer::SetBitmap(const SkBitmap& bitmap) {
return;
bitmap_ = bitmap;
+ UpdateDrawsContent(HasDrawableContent());
SetNeedsDisplay();
}
+bool ImageLayer::HasDrawableContent() const {
+ return !bitmap_.isNull() && TiledLayer::HasDrawableContent();
+}
+
void ImageLayer::SetTexturePriorities(const PriorityCalculator& priority_calc) {
// Update the tile data before creating all the layer's tiles.
UpdateTileSizeAndTilingOption();
@@ -73,10 +78,6 @@ void ImageLayer::CalculateContentsScale(float ideal_contents_scale,
*content_bounds = gfx::Size(bitmap_.width(), bitmap_.height());
}
-bool ImageLayer::DrawsContent() const {
- return !bitmap_.isNull() && TiledLayer::DrawsContent();
-}
-
void ImageLayer::OnOutputSurfaceCreated() {
SetTextureFormat(
layer_tree_host()->GetRendererCapabilities().best_texture_format);
diff --git a/cc/layers/image_layer.h b/cc/layers/image_layer.h
index a3cee58..63d467a 100644
--- a/cc/layers/image_layer.h
+++ b/cc/layers/image_layer.h
@@ -19,7 +19,6 @@ class CC_EXPORT ImageLayer : public TiledLayer {
static scoped_refptr<ImageLayer> Create();
// Layer implementation.
- virtual bool DrawsContent() const OVERRIDE;
virtual void SetTexturePriorities(const PriorityCalculator& priority_calc)
OVERRIDE;
virtual bool Update(ResourceUpdateQueue* queue,
@@ -32,6 +31,9 @@ class CC_EXPORT ImageLayer : public TiledLayer {
void SetBitmap(const SkBitmap& image);
+ protected:
+ virtual bool HasDrawableContent() const OVERRIDE;
+
private:
ImageLayer();
virtual ~ImageLayer();
diff --git a/cc/layers/io_surface_layer.cc b/cc/layers/io_surface_layer.cc
index 98d3dfe..0682aee 100644
--- a/cc/layers/io_surface_layer.cc
+++ b/cc/layers/io_surface_layer.cc
@@ -20,6 +20,7 @@ void IOSurfaceLayer::SetIOSurfaceProperties(uint32_t io_surface_id,
const gfx::Size& size) {
io_surface_id_ = io_surface_id;
io_surface_size_ = size;
+ UpdateDrawsContent(HasDrawableContent());
SetNeedsCommit();
}
@@ -28,8 +29,8 @@ scoped_ptr<LayerImpl> IOSurfaceLayer::CreateLayerImpl(
return IOSurfaceLayerImpl::Create(tree_impl, layer_id_).PassAs<LayerImpl>();
}
-bool IOSurfaceLayer::DrawsContent() const {
- return io_surface_id_ && Layer::DrawsContent();
+bool IOSurfaceLayer::HasDrawableContent() const {
+ return io_surface_id_ && Layer::HasDrawableContent();
}
void IOSurfaceLayer::PushPropertiesTo(LayerImpl* layer) {
diff --git a/cc/layers/io_surface_layer.h b/cc/layers/io_surface_layer.h
index 80e5b69..ad06e7f 100644
--- a/cc/layers/io_surface_layer.h
+++ b/cc/layers/io_surface_layer.h
@@ -18,12 +18,12 @@ class CC_EXPORT IOSurfaceLayer : public Layer {
virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl)
OVERRIDE;
- virtual bool DrawsContent() const OVERRIDE;
virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE;
virtual bool Update(ResourceUpdateQueue* queue,
const OcclusionTracker<Layer>* occlusion) OVERRIDE;
protected:
+ virtual bool HasDrawableContent() const OVERRIDE;
IOSurfaceLayer();
private:
diff --git a/cc/layers/layer.cc b/cc/layers/layer.cc
index 2367e52..737a261 100644
--- a/cc/layers/layer.cc
+++ b/cc/layers/layer.cc
@@ -47,6 +47,7 @@ Layer::Layer()
parent_(NULL),
layer_tree_host_(NULL),
scroll_clip_layer_id_(INVALID_ID),
+ num_descendants_that_draw_content_(0),
should_scroll_on_main_thread_(false),
have_wheel_event_handlers_(false),
have_scroll_event_handlers_(false),
@@ -55,6 +56,7 @@ Layer::Layer()
is_root_for_isolated_group_(false),
is_container_for_fixed_position_layers_(false),
is_drawable_(false),
+ draws_content_(false),
hide_layer_and_subtree_(false),
masks_to_bounds_(false),
contents_opaque_(false),
@@ -250,6 +252,8 @@ void Layer::InsertChild(scoped_refptr<Layer> child, size_t index) {
index = std::min(index, children_.size());
children_.insert(children_.begin() + index, child);
+ AddDrawableDescendants(child->NumDescendantsThatDrawContent() +
+ (child->DrawsContent() ? 1 : 0));
SetNeedsFullTreeSync();
}
@@ -280,6 +284,8 @@ void Layer::RemoveChildOrDependent(Layer* child) {
continue;
child->SetParent(NULL);
+ AddDrawableDescendants(-child->NumDescendantsThatDrawContent() -
+ (child->DrawsContent() ? 1 : 0));
children_.erase(iter);
SetNeedsFullTreeSync();
return;
@@ -775,7 +781,7 @@ void Layer::SetIsDrawable(bool is_drawable) {
return;
is_drawable_ = is_drawable;
- SetNeedsCommit();
+ UpdateDrawsContent(HasDrawableContent());
}
void Layer::SetHideLayerAndSubtree(bool hide) {
@@ -898,6 +904,7 @@ void Layer::PushPropertiesTo(LayerImpl* layer) {
layer->SetTransformAndInvertibility(transform_, transform_is_invertible_);
DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly()));
layer->Set3dSortingContextId(sorting_context_id_);
+ layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_);
layer->SetScrollClipLayer(scroll_clip_layer_id_);
layer->set_user_scrollable_horizontal(user_scrollable_horizontal_);
@@ -1004,9 +1011,38 @@ scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
}
bool Layer::DrawsContent() const {
+ return draws_content_;
+}
+
+bool Layer::HasDrawableContent() const {
return is_drawable_;
}
+void Layer::UpdateDrawsContent(bool has_drawable_content) {
+ bool draws_content = has_drawable_content;
+ DCHECK(is_drawable_ || !has_drawable_content);
+ if (draws_content == draws_content_)
+ return;
+
+ if (HasDelegatedContent()) {
+ // Layers with delegated content need to be treated as if they have as
+ // many children as the number of layers they own delegated quads for.
+ // Since we don't know this number right now, we choose one that acts like
+ // infinity for our purposes.
+ AddDrawableDescendants(draws_content ? 1000 : -1000);
+ }
+
+ if (parent())
+ parent()->AddDrawableDescendants(draws_content ? 1 : -1);
+
+ draws_content_ = draws_content;
+ SetNeedsCommit();
+}
+
+int Layer::NumDescendantsThatDrawContent() const {
+ return num_descendants_that_draw_content_;
+}
+
void Layer::SavePaintProperties() {
DCHECK(layer_tree_host_);
@@ -1187,7 +1223,23 @@ void Layer::RemoveFromClipTree() {
clip_parent_ = NULL;
}
+void Layer::AddDrawableDescendants(int num) {
+ DCHECK_GE(num_descendants_that_draw_content_, 0);
+ DCHECK_GE(num_descendants_that_draw_content_ + num, 0);
+ if (num == 0)
+ return;
+ num_descendants_that_draw_content_ += num;
+ SetNeedsCommit();
+ if (parent())
+ parent()->AddDrawableDescendants(num);
+}
+
void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) {
benchmark->RunOnLayer(this);
}
+
+bool Layer::HasDelegatedContent() const {
+ return false;
+}
+
} // namespace cc
diff --git a/cc/layers/layer.h b/cc/layers/layer.h
index 822b16d..dfbbdf7b 100644
--- a/cc/layers/layer.h
+++ b/cc/layers/layer.h
@@ -331,7 +331,7 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>,
virtual void SetLayerTreeHost(LayerTreeHost* host);
- bool HasDelegatedContent() const { return false; }
+ virtual bool HasDelegatedContent() const;
bool HasContributingDelegatedRenderPasses() const { return false; }
void SetIsDrawable(bool is_drawable);
@@ -350,8 +350,13 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>,
(mask_layer_.get() || replica_layer_->mask_layer_.get());
}
- // These methods typically need to be overwritten by derived classes.
+ int NumDescendantsThatDrawContent() const;
+
+ // This is only virtual for tests.
+ // TODO(awoloszyn): Remove this once we no longer need it for tests
virtual bool DrawsContent() const;
+
+ // This methods typically need to be overwritten by derived classes.
virtual void SavePaintProperties();
// Returns true iff any resources were updated that need to be committed.
virtual bool Update(ResourceUpdateQueue* queue,
@@ -482,6 +487,14 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>,
// unused resources on the impl thread are returned before commit completes.
void SetNextCommitWaitsForActivation();
+ // Will recalculate whether the layer draws content and set draws_content_
+ // appropriately.
+ void UpdateDrawsContent(bool has_drawable_content);
+ virtual bool HasDrawableContent() const;
+
+ // Called when the layer's number of drawable descendants changes.
+ void AddDrawableDescendants(int num);
+
void AddDependentNeedsPushProperties();
void RemoveDependentNeedsPushProperties();
bool parent_should_know_need_push_properties() const {
@@ -575,6 +588,7 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>,
// transformed relative to this layer, defines the maximum scroll offset for
// this layer.
int scroll_clip_layer_id_;
+ int num_descendants_that_draw_content_;
bool should_scroll_on_main_thread_ : 1;
bool have_wheel_event_handlers_ : 1;
bool have_scroll_event_handlers_ : 1;
@@ -583,6 +597,7 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>,
bool is_root_for_isolated_group_ : 1;
bool is_container_for_fixed_position_layers_ : 1;
bool is_drawable_ : 1;
+ bool draws_content_ : 1;
bool hide_layer_and_subtree_ : 1;
bool masks_to_bounds_ : 1;
bool contents_opaque_ : 1;
diff --git a/cc/layers/layer_impl.cc b/cc/layers/layer_impl.cc
index bd9a2d7..e6e60f5 100644
--- a/cc/layers/layer_impl.cc
+++ b/cc/layers/layer_impl.cc
@@ -64,6 +64,7 @@ LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, int id)
background_color_(0),
opacity_(1.0),
blend_mode_(SkXfermode::kSrcOver_Mode),
+ num_descendants_that_draw_content_(0),
draw_depth_(0.f),
needs_push_properties_(false),
num_dependents_need_push_properties_(0),
@@ -176,6 +177,13 @@ void LayerImpl::SetScrollChildren(std::set<LayerImpl*>* children) {
SetNeedsPushProperties();
}
+void LayerImpl::SetNumDescendantsThatDrawContent(int num_descendants) {
+ if (num_descendants_that_draw_content_ == num_descendants)
+ return;
+ num_descendants_that_draw_content_ = num_descendants;
+ SetNeedsPushProperties();
+}
+
void LayerImpl::SetClipParent(LayerImpl* ancestor) {
if (clip_parent_ == ancestor)
return;
@@ -532,6 +540,7 @@ void LayerImpl::PushPropertiesTo(LayerImpl* layer) {
scroll_offset_, layer->ScrollDelta() - layer->sent_scroll_delta());
layer->SetSentScrollDelta(gfx::Vector2d());
layer->Set3dSortingContextId(sorting_context_id_);
+ layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_);
LayerImpl* scroll_parent = NULL;
if (scroll_parent_) {
@@ -1521,6 +1530,10 @@ void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) {
benchmark->RunOnLayer(this);
}
+int LayerImpl::NumDescendantsThatDrawContent() const {
+ return num_descendants_that_draw_content_;
+}
+
void LayerImpl::NotifyAnimationFinished(
base::TimeTicks monotonic_time,
Animation::TargetProperty target_property) {
diff --git a/cc/layers/layer_impl.h b/cc/layers/layer_impl.h
index c1ce9df..b09cb3f 100644
--- a/cc/layers/layer_impl.h
+++ b/cc/layers/layer_impl.h
@@ -140,6 +140,7 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver,
return scroll_children_.get();
}
+ void SetNumDescendantsThatDrawContent(int num_descendants);
void SetClipParent(LayerImpl* ancestor);
LayerImpl* clip_parent() {
@@ -211,6 +212,7 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver,
void SetDrawsContent(bool draws_content);
bool DrawsContent() const { return draws_content_; }
+ int NumDescendantsThatDrawContent() const;
void SetHideLayerAndSubtree(bool hide);
bool hide_layer_and_subtree() const { return hide_layer_and_subtree_; }
@@ -650,6 +652,8 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver,
gfx::Vector2d sent_scroll_delta_;
gfx::Vector2dF last_scroll_offset_;
+ int num_descendants_that_draw_content_;
+
// The global depth value of the center of the layer. This value is used
// to sort layers from back to front.
float draw_depth_;
diff --git a/cc/layers/layer_impl_unittest.cc b/cc/layers/layer_impl_unittest.cc
index 39469c1..c5cac8d 100644
--- a/cc/layers/layer_impl_unittest.cc
+++ b/cc/layers/layer_impl_unittest.cc
@@ -200,6 +200,8 @@ TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) {
root->SetClipParent(clip_parent.get()));
EXECUTE_AND_VERIFY_NEEDS_PUSH_PROPERTIES_AND_SUBTREE_DID_NOT_CHANGE(
root->SetClipChildren(clip_children));
+ EXECUTE_AND_VERIFY_NEEDS_PUSH_PROPERTIES_AND_SUBTREE_DID_NOT_CHANGE(
+ root->SetNumDescendantsThatDrawContent(10));
// After setting all these properties already, setting to the exact same
// values again should not cause any change.
diff --git a/cc/layers/picture_image_layer.cc b/cc/layers/picture_image_layer.cc
index a65ac8c..8f24aaf 100644
--- a/cc/layers/picture_image_layer.cc
+++ b/cc/layers/picture_image_layer.cc
@@ -24,8 +24,8 @@ scoped_ptr<LayerImpl> PictureImageLayer::CreateLayerImpl(
return PictureImageLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
}
-bool PictureImageLayer::DrawsContent() const {
- return !bitmap_.isNull() && PictureLayer::DrawsContent();
+bool PictureImageLayer::HasDrawableContent() const {
+ return !bitmap_.isNull() && PictureLayer::HasDrawableContent();
}
void PictureImageLayer::SetBitmap(const SkBitmap& bitmap) {
@@ -37,6 +37,7 @@ void PictureImageLayer::SetBitmap(const SkBitmap& bitmap) {
return;
bitmap_ = bitmap;
+ UpdateDrawsContent(HasDrawableContent());
SetNeedsDisplay();
}
diff --git a/cc/layers/picture_image_layer.h b/cc/layers/picture_image_layer.h
index 69b89d1..0b3e32c 100644
--- a/cc/layers/picture_image_layer.h
+++ b/cc/layers/picture_image_layer.h
@@ -22,7 +22,6 @@ class CC_EXPORT PictureImageLayer : public PictureLayer, ContentLayerClient {
// Layer implementation.
virtual scoped_ptr<LayerImpl> CreateLayerImpl(
LayerTreeImpl* tree_impl) OVERRIDE;
- virtual bool DrawsContent() const OVERRIDE;
// ContentLayerClient implementation.
virtual void PaintContents(
@@ -33,6 +32,9 @@ class CC_EXPORT PictureImageLayer : public PictureLayer, ContentLayerClient {
virtual void DidChangeLayerCanUseLCDText() OVERRIDE {}
virtual bool FillsBoundsCompletely() const OVERRIDE;
+ protected:
+ virtual bool HasDrawableContent() const OVERRIDE;
+
private:
PictureImageLayer();
virtual ~PictureImageLayer();
diff --git a/cc/layers/picture_layer.cc b/cc/layers/picture_layer.cc
index b9f265a..d2e29b6 100644
--- a/cc/layers/picture_layer.cc
+++ b/cc/layers/picture_layer.cc
@@ -28,10 +28,6 @@ PictureLayer::PictureLayer(ContentLayerClient* client)
PictureLayer::~PictureLayer() {
}
-bool PictureLayer::DrawsContent() const {
- return Layer::DrawsContent() && client_;
-}
-
scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
}
@@ -200,6 +196,15 @@ bool PictureLayer::IsSuitableForGpuRasterization() const {
return pile_->is_suitable_for_gpu_rasterization();
}
+void PictureLayer::ClearClient() {
+ client_ = NULL;
+ UpdateDrawsContent(HasDrawableContent());
+}
+
+bool PictureLayer::HasDrawableContent() const {
+ return client_ && Layer::HasDrawableContent();
+}
+
void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) {
benchmark->RunOnLayer(this);
}
diff --git a/cc/layers/picture_layer.h b/cc/layers/picture_layer.h
index 406ffad..80bb4d8 100644
--- a/cc/layers/picture_layer.h
+++ b/cc/layers/picture_layer.h
@@ -21,10 +21,9 @@ class CC_EXPORT PictureLayer : public Layer {
public:
static scoped_refptr<PictureLayer> Create(ContentLayerClient* client);
- void ClearClient() { client_ = NULL; }
+ void ClearClient();
// Layer interface.
- virtual bool DrawsContent() const OVERRIDE;
virtual scoped_ptr<LayerImpl> CreateLayerImpl(
LayerTreeImpl* tree_impl) OVERRIDE;
virtual void SetLayerTreeHost(LayerTreeHost* host) OVERRIDE;
@@ -49,6 +48,7 @@ class CC_EXPORT PictureLayer : public Layer {
explicit PictureLayer(ContentLayerClient* client);
virtual ~PictureLayer();
+ virtual bool HasDrawableContent() const OVERRIDE;
void UpdateCanUseLCDText();
private:
diff --git a/cc/layers/surface_layer.cc b/cc/layers/surface_layer.cc
index f345b74..3ca179f 100644
--- a/cc/layers/surface_layer.cc
+++ b/cc/layers/surface_layer.cc
@@ -19,6 +19,7 @@ SurfaceLayer::~SurfaceLayer() {}
void SurfaceLayer::SetSurfaceId(SurfaceId surface_id) {
surface_id_ = surface_id;
+ UpdateDrawsContent(HasDrawableContent());
SetNeedsPushProperties();
}
@@ -26,8 +27,8 @@ scoped_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
return SurfaceLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
}
-bool SurfaceLayer::DrawsContent() const {
- return !surface_id_.is_null() && Layer::DrawsContent();
+bool SurfaceLayer::HasDrawableContent() const {
+ return !surface_id_.is_null() && Layer::HasDrawableContent();
}
void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) {
diff --git a/cc/layers/surface_layer.h b/cc/layers/surface_layer.h
index cf150ab..d58d47d 100644
--- a/cc/layers/surface_layer.h
+++ b/cc/layers/surface_layer.h
@@ -22,11 +22,11 @@ class CC_EXPORT SurfaceLayer : public Layer {
// Layer overrides.
virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl)
OVERRIDE;
- virtual bool DrawsContent() const OVERRIDE;
virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE;
protected:
SurfaceLayer();
+ virtual bool HasDrawableContent() const OVERRIDE;
private:
virtual ~SurfaceLayer();
diff --git a/cc/layers/texture_layer.cc b/cc/layers/texture_layer.cc
index 05391fe..5d386ca 100644
--- a/cc/layers/texture_layer.cc
+++ b/cc/layers/texture_layer.cc
@@ -45,6 +45,7 @@ void TextureLayer::ClearClient() {
layer_tree_host()->StopRateLimiter();
client_ = NULL;
ClearTexture();
+ UpdateDrawsContent(HasDrawableContent());
}
void TextureLayer::ClearTexture() {
@@ -136,6 +137,7 @@ void TextureLayer::SetTextureMailboxInternal(
else
SetNeedsPushProperties();
+ UpdateDrawsContent(HasDrawableContent());
// The active frame needs to be replaced and the mailbox returned before the
// commit is called complete.
SetNextCommitWaitsForActivation();
@@ -198,8 +200,8 @@ void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) {
Layer::SetLayerTreeHost(host);
}
-bool TextureLayer::DrawsContent() const {
- return (client_ || holder_ref_) && Layer::DrawsContent();
+bool TextureLayer::HasDrawableContent() const {
+ return (client_ || holder_ref_) && Layer::HasDrawableContent();
}
bool TextureLayer::Update(ResourceUpdateQueue* queue,
diff --git a/cc/layers/texture_layer.h b/cc/layers/texture_layer.h
index aa2ed56..fb25da6 100644
--- a/cc/layers/texture_layer.h
+++ b/cc/layers/texture_layer.h
@@ -134,7 +134,6 @@ class CC_EXPORT TextureLayer : public Layer {
virtual void SetNeedsDisplayRect(const gfx::RectF& dirty_rect) OVERRIDE;
virtual void SetLayerTreeHost(LayerTreeHost* layer_tree_host) OVERRIDE;
- virtual bool DrawsContent() const OVERRIDE;
virtual bool Update(ResourceUpdateQueue* queue,
const OcclusionTracker<Layer>* occlusion) OVERRIDE;
virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE;
@@ -143,6 +142,7 @@ class CC_EXPORT TextureLayer : public Layer {
protected:
explicit TextureLayer(TextureLayerClient* client);
virtual ~TextureLayer();
+ virtual bool HasDrawableContent() const OVERRIDE;
private:
void SetTextureMailboxInternal(
diff --git a/cc/layers/tiled_layer.cc b/cc/layers/tiled_layer.cc
index 6656405..c1937e4 100644
--- a/cc/layers/tiled_layer.cc
+++ b/cc/layers/tiled_layer.cc
@@ -154,27 +154,26 @@ void TiledLayer::UpdateBounds() {
for (Region::Iterator new_rects(new_region); new_rects.has_rect();
new_rects.next())
InvalidateContentRect(new_rects.rect());
+ UpdateDrawsContent(HasDrawableContent());
}
void TiledLayer::SetTileSize(const gfx::Size& size) {
tiler_->SetTileSize(size);
+ UpdateDrawsContent(HasDrawableContent());
}
void TiledLayer::SetBorderTexelOption(
LayerTilingData::BorderTexelOption border_texel_option) {
tiler_->SetBorderTexelOption(border_texel_option);
+ UpdateDrawsContent(HasDrawableContent());
}
-bool TiledLayer::DrawsContent() const {
- if (!ContentsScalingLayer::DrawsContent())
- return false;
-
+bool TiledLayer::HasDrawableContent() const {
bool has_more_than_one_tile =
- tiler_->num_tiles_x() > 1 || tiler_->num_tiles_y() > 1;
- if (tiling_option_ == NEVER_TILE && has_more_than_one_tile)
- return false;
+ (tiler_->num_tiles_x() > 1) || (tiler_->num_tiles_y() > 1);
- return true;
+ return !(tiling_option_ == NEVER_TILE && has_more_than_one_tile) &&
+ ContentsScalingLayer::HasDrawableContent();
}
void TiledLayer::ReduceMemoryUsage() {
diff --git a/cc/layers/tiled_layer.h b/cc/layers/tiled_layer.h
index e272497..4a83e45 100644
--- a/cc/layers/tiled_layer.h
+++ b/cc/layers/tiled_layer.h
@@ -27,7 +27,6 @@ class CC_EXPORT TiledLayer : public ContentsScalingLayer {
// Layer implementation.
virtual void SetIsMask(bool is_mask) OVERRIDE;
virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE;
- virtual bool DrawsContent() const OVERRIDE;
virtual void ReduceMemoryUsage() OVERRIDE;
virtual void SetNeedsDisplayRect(const gfx::RectF& dirty_rect) OVERRIDE;
virtual void SetLayerTreeHost(LayerTreeHost* layer_tree_host) OVERRIDE;
@@ -68,6 +67,8 @@ class CC_EXPORT TiledLayer : public ContentsScalingLayer {
bool SkipsDraw() const { return skips_draw_; }
+ virtual bool HasDrawableContent() const OVERRIDE;
+
// Virtual for testing
virtual PrioritizedResourceManager* ResourceManager();
const LayerTilingData* TilerForTesting() const { return tiler_.get(); }
diff --git a/cc/layers/ui_resource_layer.cc b/cc/layers/ui_resource_layer.cc
index b26ebaa..59fbe83 100644
--- a/cc/layers/ui_resource_layer.cc
+++ b/cc/layers/ui_resource_layer.cc
@@ -113,11 +113,11 @@ void UIResourceLayer::SetLayerTreeHost(LayerTreeHost* host) {
void UIResourceLayer::RecreateUIResourceHolder() {
ui_resource_holder_.reset();
- if (!layer_tree_host() || bitmap_.empty())
- return;
-
- ui_resource_holder_ =
- ScopedUIResourceHolder::Create(layer_tree_host(), bitmap_);
+ if (layer_tree_host() && !bitmap_.empty()) {
+ ui_resource_holder_ =
+ ScopedUIResourceHolder::Create(layer_tree_host(), bitmap_);
+ }
+ UpdateDrawsContent(HasDrawableContent());
}
void UIResourceLayer::SetBitmap(const SkBitmap& skbitmap) {
@@ -137,12 +137,13 @@ void UIResourceLayer::SetUIResourceId(UIResourceId resource_id) {
ui_resource_holder_.reset();
}
+ UpdateDrawsContent(HasDrawableContent());
SetNeedsCommit();
}
-bool UIResourceLayer::DrawsContent() const {
+bool UIResourceLayer::HasDrawableContent() const {
return ui_resource_holder_ && ui_resource_holder_->id() &&
- Layer::DrawsContent();
+ Layer::HasDrawableContent();
}
void UIResourceLayer::PushPropertiesTo(LayerImpl* layer) {
diff --git a/cc/layers/ui_resource_layer.h b/cc/layers/ui_resource_layer.h
index d99c073..8e278a9 100644
--- a/cc/layers/ui_resource_layer.h
+++ b/cc/layers/ui_resource_layer.h
@@ -20,8 +20,6 @@ class CC_EXPORT UIResourceLayer : public Layer {
public:
static scoped_refptr<UIResourceLayer> Create();
- virtual bool DrawsContent() const OVERRIDE;
-
virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE;
virtual void SetLayerTreeHost(LayerTreeHost* host) OVERRIDE;
@@ -51,6 +49,8 @@ class CC_EXPORT UIResourceLayer : public Layer {
UIResourceLayer();
virtual ~UIResourceLayer();
+ virtual bool HasDrawableContent() const OVERRIDE;
+
scoped_ptr<UIResourceHolder> ui_resource_holder_;
SkBitmap bitmap_;