summaryrefslogtreecommitdiffstats
path: root/chromium/cc/layers/layer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/cc/layers/layer.cc')
-rw-r--r--chromium/cc/layers/layer.cc257
1 files changed, 96 insertions, 161 deletions
diff --git a/chromium/cc/layers/layer.cc b/chromium/cc/layers/layer.cc
index f622b2e9537..063e39f34f7 100644
--- a/chromium/cc/layers/layer.cc
+++ b/chromium/cc/layers/layer.cc
@@ -18,7 +18,6 @@
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "cc/base/simple_enclosed_region.h"
-#include "cc/input/main_thread_scrolling_reason.h"
#include "cc/layers/layer_client.h"
#include "cc/layers/layer_impl.h"
#include "cc/layers/picture_layer.h"
@@ -39,35 +38,77 @@
namespace cc {
+struct SameSizeAsLayer : public base::RefCounted<SameSizeAsLayer> {
+ private:
+ SameSizeAsLayer();
+ virtual ~SameSizeAsLayer();
+
+ void* pointers[2];
+ struct {
+ LayerList children;
+ gfx::Rect update_rect;
+ gfx::Size bounds;
+ gfx::Rect clip_rect;
+ scoped_refptr<PictureLayer> mask_layer;
+ int layer_id;
+ float opacity;
+ SkBlendMode blend_mode;
+ unsigned bitfields;
+ gfx::PointF position;
+ gfx::Transform transform;
+ gfx::Point3F transform_origin;
+ SkColor background_color;
+ FilterOperations filters[2];
+ base::Optional<gfx::RRectF> backdrop_filter_bounds;
+ gfx::PointF filters_origin;
+ float backdrop_filter_quality;
+ gfx::RoundedCornersF corner_radii;
+ gfx::ScrollOffset scroll_offset;
+ gfx::Size scroll_container_bounds;
+ int mirror_count;
+ Region non_fast_scrollable_region;
+ TouchActionRegion touch_action_region;
+ ElementId element_id;
+ base::WeakPtr<LayerClient> client;
+ std::unique_ptr<base::trace_event::TracedValue> debug_info;
+ base::RepeatingCallback<void()> did_scroll_callback;
+ std::vector<std::unique_ptr<viz::CopyOutputRequest>> copy_requests;
+ } inputs;
+ int int_fields[7];
+ gfx::Vector2dF offset;
+ unsigned bitfields;
+ SkColor safe_opaque_background_color;
+ int owner_node_id;
+ uint64_t compositing_reasons;
+};
+
+static_assert(sizeof(Layer) == sizeof(SameSizeAsLayer),
+ "Layer should stay small");
+
base::AtomicSequenceNumber g_next_layer_id;
Layer::Inputs::Inputs(int layer_id)
- : layer_id(layer_id),
- masks_to_bounds(false),
- mask_layer(nullptr),
+ : mask_layer(nullptr),
+ layer_id(layer_id),
opacity(1.f),
blend_mode(SkBlendMode::kSrcOver),
- is_root_for_isolated_group(false),
+ masks_to_bounds(false),
hit_testable(false),
contents_opaque(false),
is_drawable(false),
double_sided(true),
- should_flatten_transform(true),
- sorting_context_id(0),
use_parent_backface_visibility(false),
- background_color(0),
- backdrop_filter_quality(1.0f),
- corner_radii({0, 0, 0, 0}),
is_fast_rounded_corner(false),
scrollable(false),
is_scrollbar(false),
user_scrollable_horizontal(true),
user_scrollable_vertical(true),
- main_thread_scrolling_reasons(
- MainThreadScrollingReason::kNotScrollingOnMain),
has_will_change_transform_hint(false),
trilinear_filtering(false),
hide_layer_and_subtree(false),
+ background_color(0),
+ backdrop_filter_quality(1.0f),
+ corner_radii({0, 0, 0, 0}),
mirror_count(0) {}
Layer::Inputs::~Inputs() = default;
@@ -77,19 +118,18 @@ scoped_refptr<Layer> Layer::Create() {
}
Layer::Layer()
- : ignore_set_needs_commit_(false),
- paint_count_(0),
- parent_(nullptr),
+ : parent_(nullptr),
layer_tree_host_(nullptr),
// Layer IDs start from 1.
inputs_(g_next_layer_id.GetNext() + 1),
+ paint_count_(0),
num_descendants_that_draw_content_(0),
transform_tree_index_(TransformTree::kInvalidNodeId),
effect_tree_index_(EffectTree::kInvalidNodeId),
clip_tree_index_(ClipTree::kInvalidNodeId),
scroll_tree_index_(ScrollTree::kInvalidNodeId),
property_tree_sequence_number_(-1),
- should_flatten_screen_space_transform_from_property_tree_(false),
+ ignore_set_needs_commit_(false),
draws_content_(false),
should_check_backface_visibility_(false),
cache_render_surface_(false),
@@ -101,8 +141,8 @@ Layer::Layer()
has_clip_node_(false),
subtree_has_copy_request_(false),
safe_opaque_background_color_(0),
- compositing_reasons_(0),
- owner_node_id_(0) {}
+ owner_node_id_(0),
+ compositing_reasons_(0) {}
Layer::~Layer() {
// Our parent should be holding a reference to us so there should be no
@@ -114,10 +154,6 @@ Layer::~Layer() {
// Remove the parent reference from all children and dependents.
RemoveAllChildren();
- if (inputs_.mask_layer.get()) {
- DCHECK_EQ(this, inputs_.mask_layer->parent());
- inputs_.mask_layer->RemoveFromParent();
- }
}
void Layer::SetLayerTreeHost(LayerTreeHost* host) {
@@ -162,9 +198,6 @@ void Layer::SetLayerTreeHost(LayerTreeHost* host) {
for (size_t i = 0; i < inputs_.children.size(); ++i)
inputs_.children[i]->SetLayerTreeHost(host);
- if (inputs_.mask_layer.get())
- inputs_.mask_layer->SetLayerTreeHost(host);
-
if (host && !host->IsUsingLayerLists() &&
host->mutator_host()->IsElementAnimating(element_id())) {
host->SetNeedsCommit();
@@ -238,6 +271,11 @@ void Layer::InsertChild(scoped_refptr<Layer> child, size_t index) {
child->SetSubtreePropertyChanged();
index = std::min(index, inputs_.children.size());
+ if (inputs_.mask_layer && index && index == inputs_.children.size()) {
+ // Ensure that the mask layer is always the last child.
+ DCHECK_EQ(inputs_.mask_layer, inputs_.children.back().get());
+ index--;
+ }
inputs_.children.insert(inputs_.children.begin() + index, child);
SetNeedsFullTreeSync();
}
@@ -245,16 +283,12 @@ void Layer::InsertChild(scoped_refptr<Layer> child, size_t index) {
void Layer::RemoveFromParent() {
DCHECK(IsPropertyChangeAllowed());
if (parent_)
- parent_->RemoveChildOrDependent(this);
+ parent_->RemoveChild(this);
}
-void Layer::RemoveChildOrDependent(Layer* child) {
- if (inputs_.mask_layer.get() == child) {
- inputs_.mask_layer->SetParent(nullptr);
+void Layer::RemoveChild(Layer* child) {
+ if (child == inputs_.mask_layer)
inputs_.mask_layer = nullptr;
- SetNeedsFullTreeSync();
- return;
- }
for (auto iter = inputs_.children.begin(); iter != inputs_.children.end();
++iter) {
@@ -327,7 +361,7 @@ void Layer::SetBounds(const gfx::Size& size) {
// Rounded corner clipping, bounds clipping and mask clipping can result in
// new areas of subtrees being exposed on a bounds change. Ensure the damaged
// areas are updated.
- if (masks_to_bounds() || inputs_.mask_layer.get() || HasRoundedCorner()) {
+ if (masks_to_bounds() || IsMaskedByChild() || HasRoundedCorner()) {
SetSubtreePropertyChanged();
SetPropertyTreesNeedRebuild();
}
@@ -343,25 +377,6 @@ void Layer::SetBounds(const gfx::Size& size) {
SetNeedsCommit();
}
-void Layer::SetSnapContainerData(base::Optional<SnapContainerData> data) {
- DCHECK(IsPropertyChangeAllowed());
- if (snap_container_data() == data)
- return;
- inputs_.snap_container_data = std::move(data);
- if (!layer_tree_host_)
- return;
-
- if (scrollable() && !layer_tree_host_->IsUsingLayerLists()) {
- auto& scroll_tree = layer_tree_host_->property_trees()->scroll_tree;
- if (auto* scroll_node = scroll_tree.Node(scroll_tree_index_))
- scroll_node->snap_container_data = inputs_.snap_container_data;
- else
- SetPropertyTreesNeedRebuild();
- }
-
- SetNeedsCommit();
-}
-
Layer* Layer::RootLayer() {
Layer* layer = this;
while (layer->parent())
@@ -557,7 +572,8 @@ gfx::RectF Layer::EffectiveClipRect() {
// Layer needs to clip to its bounds as well apply a clip rect. Intersect the
// two to get the effective clip.
- if (masks_to_bounds() || mask_layer() || filters().HasFilterThatMovesPixels())
+ if (masks_to_bounds() || IsMaskedByChild() ||
+ filters().HasFilterThatMovesPixels())
return gfx::IntersectRects(layer_bounds, clip_rect_f);
// Clip rect is the only clip effecting the layer.
@@ -566,26 +582,27 @@ gfx::RectF Layer::EffectiveClipRect() {
void Layer::SetMaskLayer(scoped_refptr<PictureLayer> mask_layer) {
DCHECK(IsPropertyChangeAllowed());
- if (inputs_.mask_layer.get() == mask_layer)
- return;
DCHECK(!layer_tree_host_ || !layer_tree_host_->IsUsingLayerLists());
- if (inputs_.mask_layer.get()) {
+ if (inputs_.mask_layer == mask_layer)
+ return;
+ if (inputs_.mask_layer) {
DCHECK_EQ(this, inputs_.mask_layer->parent());
inputs_.mask_layer->RemoveFromParent();
}
- inputs_.mask_layer = mask_layer;
- if (inputs_.mask_layer.get()) {
+ // Clear mask_layer first and set it later because InsertChild() checks it to
+ // ensure the mask layer is the last child.
+ inputs_.mask_layer = nullptr;
+ if (mask_layer) {
// The mask layer should not have any children.
- DCHECK(inputs_.mask_layer->children().empty());
+ DCHECK(mask_layer->children().empty());
- inputs_.mask_layer->RemoveFromParent();
- DCHECK(!inputs_.mask_layer->parent());
- inputs_.mask_layer->SetParent(this);
- inputs_.mask_layer->SetLayerMaskType(
- Layer::LayerMaskType::SINGLE_TEXTURE_MASK);
+ mask_layer->inputs_.position = gfx::PointF();
+ mask_layer->SetIsDrawable(true);
+ mask_layer->SetBlendMode(SkBlendMode::kDstIn);
+ AddChild(mask_layer);
}
+ inputs_.mask_layer = mask_layer.get();
SetSubtreePropertyChanged();
- SetNeedsFullTreeSync();
}
void Layer::SetFilters(const FilterOperations& filters) {
@@ -759,15 +776,6 @@ void Layer::SetBlendMode(SkBlendMode blend_mode) {
SetPropertyTreesNeedRebuild();
}
-void Layer::SetIsRootForIsolatedGroup(bool root) {
- DCHECK(IsPropertyChangeAllowed());
- if (inputs_.is_root_for_isolated_group == root)
- return;
- inputs_.is_root_for_isolated_group = root;
- SetPropertyTreesNeedRebuild();
- SetNeedsCommit();
-}
-
void Layer::SetHitTestable(bool should_hit_test) {
DCHECK(IsPropertyChangeAllowed());
if (inputs_.hit_testable == should_hit_test)
@@ -792,6 +800,14 @@ void Layer::SetContentsOpaque(bool opaque) {
}
void Layer::SetPosition(const gfx::PointF& position) {
+ // The mask layer should always be at the same location as the masked layer
+ // which is its parent, so its position should be always zero.
+ if (parent() && parent()->inputs_.mask_layer == this) {
+ DCHECK(!layer_tree_host_ || !layer_tree_host_->IsUsingLayerLists());
+ DCHECK(inputs_.position.IsOrigin());
+ return;
+ }
+
DCHECK(IsPropertyChangeAllowed());
if (inputs_.position == position)
return;
@@ -1043,54 +1059,6 @@ bool Layer::GetUserScrollableVertical() const {
return inputs_.user_scrollable_vertical;
}
-uint32_t Layer::GetMainThreadScrollingReasons() const {
- // When using layer lists, main thread scrolling reasons are stored in scroll
- // nodes.
- if (layer_tree_host() && layer_tree_host()->IsUsingLayerLists()) {
- auto& scroll_tree = layer_tree_host()->property_trees()->scroll_tree;
- if (auto* scroll_node = scroll_tree.Node(scroll_tree_index_))
- return scroll_node->main_thread_scrolling_reasons;
- return MainThreadScrollingReason::kNotScrollingOnMain;
- }
- return inputs_.main_thread_scrolling_reasons;
-}
-
-void Layer::AddMainThreadScrollingReasons(
- uint32_t main_thread_scrolling_reasons) {
- DCHECK(IsPropertyChangeAllowed());
- DCHECK(main_thread_scrolling_reasons);
-
- // When layer lists are used, the main thread scrolling reasons should be set
- // on property tree nodes directly.
- // TODO(pdr): Uncomment this check when https://crbug.com/919969 is fixed.
- // DCHECK(!layer_tree_host() || !layer_tree_host()->IsUsingLayerLists());
-
- // Layer should only see non-transient scrolling reasons. Transient scrolling
- // reasons are computed per hit test.
- DCHECK(MainThreadScrollingReason::MainThreadCanSetScrollReasons(
- main_thread_scrolling_reasons));
- uint32_t new_reasons =
- inputs_.main_thread_scrolling_reasons | main_thread_scrolling_reasons;
- if (inputs_.main_thread_scrolling_reasons == new_reasons)
- return;
- inputs_.main_thread_scrolling_reasons = new_reasons;
- SetPropertyTreesNeedRebuild();
- SetNeedsCommit();
-}
-
-void Layer::ClearMainThreadScrollingReasons(
- uint32_t main_thread_scrolling_reasons_to_clear) {
- DCHECK(IsPropertyChangeAllowed());
- DCHECK(main_thread_scrolling_reasons_to_clear);
- uint32_t new_reasons = ~main_thread_scrolling_reasons_to_clear &
- inputs_.main_thread_scrolling_reasons;
- if (new_reasons == inputs_.main_thread_scrolling_reasons)
- return;
- inputs_.main_thread_scrolling_reasons = new_reasons;
- SetPropertyTreesNeedRebuild();
- SetNeedsCommit();
-}
-
void Layer::SetNonFastScrollableRegion(const Region& region) {
DCHECK(IsPropertyChangeAllowed());
if (inputs_.non_fast_scrollable_region == region)
@@ -1155,16 +1123,6 @@ void Layer::SetDoubleSided(bool double_sided) {
SetSubtreePropertyChanged();
}
-void Layer::Set3dSortingContextId(int id) {
- DCHECK(IsPropertyChangeAllowed());
- if (id == inputs_.sorting_context_id)
- return;
- inputs_.sorting_context_id = id;
- SetNeedsCommit();
- SetPropertyTreesNeedRebuild();
- SetSubtreePropertyChanged();
-}
-
void Layer::SetTransformTreeIndex(int index) {
DCHECK(IsPropertyChangeAllowed());
if (transform_tree_index_ == index)
@@ -1255,23 +1213,9 @@ void Layer::SetPropertyTreesNeedRebuild() {
layer_tree_host_->property_trees()->needs_rebuild = true;
}
-void Layer::SetShouldFlattenTransform(bool should_flatten) {
- DCHECK(IsPropertyChangeAllowed());
- if (inputs_.should_flatten_transform == should_flatten)
- return;
- inputs_.should_flatten_transform = should_flatten;
- SetNeedsCommit();
- SetPropertyTreesNeedRebuild();
- SetSubtreePropertyChanged();
-}
-
#if DCHECK_IS_ON()
std::string Layer::DebugName() const {
- if (inputs_.client) {
- if (auto debug_info = inputs_.client->TakeDebugInfo(this))
- return debug_info->ToBaseValue()->FindKey("layer_name")->GetString();
- }
- return "";
+ return inputs_.client ? inputs_.client->LayerDebugName(this) : "";
}
#endif
@@ -1361,6 +1305,11 @@ void Layer::PushPropertiesTo(LayerImpl* layer) {
"Layer::PushPropertiesTo");
DCHECK(layer_tree_host_);
+ if (inputs_.mask_layer) {
+ DCHECK_EQ(bounds(), inputs_.mask_layer->bounds());
+ DCHECK(inputs_.mask_layer->position().IsOrigin());
+ }
+
// The element id should be set first because other setters may
// depend on it. Referencing element id on a layer is
// deprecated. http://crbug.com/709137
@@ -1398,8 +1347,6 @@ void Layer::PushPropertiesTo(LayerImpl* layer) {
layer->SetWheelEventHandlerRegion(Region());
}
layer->SetContentsOpaque(inputs_.contents_opaque);
- layer->SetShouldFlattenScreenSpaceTransformFromPropertyTree(
- should_flatten_screen_space_transform_from_property_tree_);
layer->SetUseParentBackfaceVisibility(inputs_.use_parent_backface_visibility);
layer->SetShouldCheckBackfaceVisibility(should_check_backface_visibility_);
@@ -1439,9 +1386,6 @@ void Layer::PushPropertiesTo(LayerImpl* layer) {
needs_show_scrollbars_ = false;
subtree_property_changed_ = false;
inputs_.update_rect = gfx::Rect();
-
- if (mask_layer())
- DCHECK_EQ(bounds().ToString(), mask_layer()->bounds().ToString());
}
void Layer::TakeCopyRequests(
@@ -1519,15 +1463,6 @@ void Layer::SetSubtreePropertyChanged() {
SetNeedsPushProperties();
}
-void Layer::SetShouldFlattenScreenSpaceTransformFromPropertyTree(
- bool should_flatten) {
- if (should_flatten_screen_space_transform_from_property_tree_ ==
- should_flatten)
- return;
- should_flatten_screen_space_transform_from_property_tree_ = should_flatten;
- SetNeedsPushProperties();
-}
-
void Layer::SetMayContainVideo(bool yes) {
if (may_contain_video_ == yes)
return;