Commit 67cf612a authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

Reduce size of cc::Layer

This reduces size of cc::Layer from 680 to 552 on LP64 systems.

- Adjust order of fields to reduce gaps;
- Remove snap_container_data.

Change-Id: Id2fa92d5feae2cb819b25c400c8ed678a01558ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1798987
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695839}
parent 03c027f2
...@@ -39,36 +39,86 @@ ...@@ -39,36 +39,86 @@
namespace cc { 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;
int sorting_context_id;
gfx::PointF position;
gfx::Transform transform;
gfx::Point3F transform_origin;
SkColor background_color;
FilterOperations filters[2];
base::Optional<gfx::RRectF> backdrop_filter_bounds;
ElementId backdrop_mask_element_id;
gfx::PointF filters_origin;
float backdrop_filter_quality;
gfx::RoundedCornersF corner_radii;
gfx::ScrollOffset scroll_offset;
gfx::Size scroll_container_bounds;
int mirror_count;
uint32_t main_thread_scrolling_reasons;
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; base::AtomicSequenceNumber g_next_layer_id;
Layer::Inputs::Inputs(int layer_id) Layer::Inputs::Inputs(int layer_id)
: layer_id(layer_id), : mask_layer(nullptr),
masks_to_bounds(false), layer_id(layer_id),
mask_layer(nullptr),
opacity(1.f), opacity(1.f),
blend_mode(SkBlendMode::kSrcOver), blend_mode(SkBlendMode::kSrcOver),
masks_to_bounds(false),
is_root_for_isolated_group(false), is_root_for_isolated_group(false),
hit_testable(false), hit_testable(false),
contents_opaque(false), contents_opaque(false),
is_drawable(false), is_drawable(false),
double_sided(true), double_sided(true),
should_flatten_transform(true), should_flatten_transform(true),
sorting_context_id(0),
use_parent_backface_visibility(false), use_parent_backface_visibility(false),
background_color(0),
backdrop_filter_quality(1.0f),
corner_radii({0, 0, 0, 0}),
is_fast_rounded_corner(false), is_fast_rounded_corner(false),
scrollable(false), scrollable(false),
is_scrollbar(false), is_scrollbar(false),
user_scrollable_horizontal(true), user_scrollable_horizontal(true),
user_scrollable_vertical(true), user_scrollable_vertical(true),
main_thread_scrolling_reasons(
MainThreadScrollingReason::kNotScrollingOnMain),
has_will_change_transform_hint(false), has_will_change_transform_hint(false),
trilinear_filtering(false), trilinear_filtering(false),
hide_layer_and_subtree(false), hide_layer_and_subtree(false),
mirror_count(0) {} sorting_context_id(0),
background_color(0),
backdrop_filter_quality(1.0f),
corner_radii({0, 0, 0, 0}),
mirror_count(0),
main_thread_scrolling_reasons(
MainThreadScrollingReason::kNotScrollingOnMain) {}
Layer::Inputs::~Inputs() = default; Layer::Inputs::~Inputs() = default;
...@@ -77,18 +127,18 @@ scoped_refptr<Layer> Layer::Create() { ...@@ -77,18 +127,18 @@ scoped_refptr<Layer> Layer::Create() {
} }
Layer::Layer() Layer::Layer()
: ignore_set_needs_commit_(false), : parent_(nullptr),
paint_count_(0),
parent_(nullptr),
layer_tree_host_(nullptr), layer_tree_host_(nullptr),
// Layer IDs start from 1. // Layer IDs start from 1.
inputs_(g_next_layer_id.GetNext() + 1), inputs_(g_next_layer_id.GetNext() + 1),
paint_count_(0),
num_descendants_that_draw_content_(0), num_descendants_that_draw_content_(0),
transform_tree_index_(TransformTree::kInvalidNodeId), transform_tree_index_(TransformTree::kInvalidNodeId),
effect_tree_index_(EffectTree::kInvalidNodeId), effect_tree_index_(EffectTree::kInvalidNodeId),
clip_tree_index_(ClipTree::kInvalidNodeId), clip_tree_index_(ClipTree::kInvalidNodeId),
scroll_tree_index_(ScrollTree::kInvalidNodeId), scroll_tree_index_(ScrollTree::kInvalidNodeId),
property_tree_sequence_number_(-1), property_tree_sequence_number_(-1),
ignore_set_needs_commit_(false),
should_flatten_screen_space_transform_from_property_tree_(false), should_flatten_screen_space_transform_from_property_tree_(false),
draws_content_(false), draws_content_(false),
should_check_backface_visibility_(false), should_check_backface_visibility_(false),
...@@ -101,8 +151,8 @@ Layer::Layer() ...@@ -101,8 +151,8 @@ Layer::Layer()
has_clip_node_(false), has_clip_node_(false),
subtree_has_copy_request_(false), subtree_has_copy_request_(false),
safe_opaque_background_color_(0), safe_opaque_background_color_(0),
compositing_reasons_(0), owner_node_id_(0),
owner_node_id_(0) {} compositing_reasons_(0) {}
Layer::~Layer() { Layer::~Layer() {
// Our parent should be holding a reference to us so there should be no // Our parent should be holding a reference to us so there should be no
...@@ -343,25 +393,6 @@ void Layer::SetBounds(const gfx::Size& size) { ...@@ -343,25 +393,6 @@ void Layer::SetBounds(const gfx::Size& size) {
SetNeedsCommit(); 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::RootLayer() {
Layer* layer = this; Layer* layer = this;
while (layer->parent()) while (layer->parent())
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include "base/auto_reset.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/observer_list.h" #include "base/observer_list.h"
...@@ -189,16 +190,6 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { ...@@ -189,16 +190,6 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
void SetBounds(const gfx::Size& bounds); void SetBounds(const gfx::Size& bounds);
const gfx::Size& bounds() const { return inputs_.bounds; } const gfx::Size& bounds() const { return inputs_.bounds; }
// Set and get the snapping behaviour for compositor-thread scrolling of
// this layer. The default value of null means there is no snapping for the
// layer.
// TODO(crbug.com/836884) With blink-gen-property-trees this is stored on the
// ScrollNode and can be removed here.
void SetSnapContainerData(base::Optional<SnapContainerData> data);
const base::Optional<SnapContainerData>& snap_container_data() const {
return inputs_.snap_container_data;
}
// Set or get that this layer clips its subtree to within its bounds. Content // Set or get that this layer clips its subtree to within its bounds. Content
// of children will be intersected with the bounds of this layer when true. // of children will be intersected with the bounds of this layer when true.
void SetMasksToBounds(bool masks_to_bounds); void SetMasksToBounds(bool masks_to_bounds);
...@@ -829,11 +820,11 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { ...@@ -829,11 +820,11 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
// be changed while the frame is being generated for commit. // be changed while the frame is being generated for commit.
bool IsPropertyChangeAllowed() const; bool IsPropertyChangeAllowed() const;
// When true, the layer is about to perform an update. Any commit requests void IncreasePaintCount() { ++paint_count_; }
// will be handled implicitly after the update completes.
bool ignore_set_needs_commit_;
int paint_count_; base::AutoReset<bool> IgnoreSetNeedsCommit() {
return base::AutoReset<bool>(&ignore_set_needs_commit_, true);
}
private: private:
friend class base::RefCounted<Layer>; friend class base::RefCounted<Layer>;
...@@ -875,21 +866,22 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { ...@@ -875,21 +866,22 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
explicit Inputs(int layer_id); explicit Inputs(int layer_id);
~Inputs(); ~Inputs();
int layer_id;
LayerList children; LayerList children;
gfx::Rect update_rect; gfx::Rect update_rect;
gfx::Size bounds; gfx::Size bounds;
bool masks_to_bounds;
gfx::Rect clip_rect; gfx::Rect clip_rect;
scoped_refptr<PictureLayer> mask_layer; scoped_refptr<PictureLayer> mask_layer;
int layer_id;
float opacity; float opacity;
SkBlendMode blend_mode; SkBlendMode blend_mode;
bool masks_to_bounds : 1;
bool is_root_for_isolated_group : 1; bool is_root_for_isolated_group : 1;
// Hit testing depends on this bit. // Hit testing depends on this bit.
...@@ -897,21 +889,42 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { ...@@ -897,21 +889,42 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
bool contents_opaque : 1; bool contents_opaque : 1;
gfx::PointF position;
gfx::Transform transform;
gfx::Point3F transform_origin;
bool is_drawable : 1; bool is_drawable : 1;
bool double_sided : 1; bool double_sided : 1;
bool should_flatten_transform : 1; bool should_flatten_transform : 1;
bool use_parent_backface_visibility : 1;
// If set, disables this layer's rounded corner from triggering a render
// surface on itself if possible.
bool is_fast_rounded_corner : 1;
// Indicates that this layer will need a scroll property node and that this
// layer's bounds correspond to the scroll node's bounds (both |bounds| and
// |scroll_container_bounds|).
bool scrollable : 1;
// Indicates that this layer is a scrollbar.
bool is_scrollbar : 1;
bool user_scrollable_horizontal : 1;
bool user_scrollable_vertical : 1;
bool has_will_change_transform_hint : 1;
bool trilinear_filtering : 1;
bool hide_layer_and_subtree : 1;
// Layers that share a sorting context id will be sorted together in 3d // Layers that share a sorting context id will be sorted together in 3d
// space. 0 is a special value that means this layer will not be sorted // space. 0 is a special value that means this layer will not be sorted
// and will be drawn in paint order. // and will be drawn in paint order.
int sorting_context_id; int sorting_context_id;
bool use_parent_backface_visibility : 1; gfx::PointF position;
gfx::Transform transform;
gfx::Point3F transform_origin;
SkColor background_color; SkColor background_color;
...@@ -926,25 +939,12 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { ...@@ -926,25 +939,12 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
// top left, top right, bottom right, bottom left // top left, top right, bottom right, bottom left
gfx::RoundedCornersF corner_radii; gfx::RoundedCornersF corner_radii;
// If set, disables this layer's rounded corner from triggering a render
// surface on itself if possible.
bool is_fast_rounded_corner : 1;
gfx::ScrollOffset scroll_offset; gfx::ScrollOffset scroll_offset;
// Size of the scroll container that this layer scrolls in. // Size of the scroll container that this layer scrolls in.
gfx::Size scroll_container_bounds; gfx::Size scroll_container_bounds;
// Indicates that this layer will need a scroll property node and that this int mirror_count;
// layer's bounds correspond to the scroll node's bounds (both |bounds| and
// |scroll_container_bounds|).
bool scrollable : 1;
// Indicates that this layer is a scrollbar.
bool is_scrollbar : 1;
bool user_scrollable_horizontal : 1;
bool user_scrollable_vertical : 1;
uint32_t main_thread_scrolling_reasons; uint32_t main_thread_scrolling_reasons;
Region non_fast_scrollable_region; Region non_fast_scrollable_region;
...@@ -953,12 +953,6 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { ...@@ -953,12 +953,6 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
ElementId element_id; ElementId element_id;
bool has_will_change_transform_hint : 1;
bool trilinear_filtering : 1;
bool hide_layer_and_subtree : 1;
// The following elements can not and are not serialized. // The following elements can not and are not serialized.
base::WeakPtr<LayerClient> client; base::WeakPtr<LayerClient> client;
std::unique_ptr<base::trace_event::TracedValue> debug_info; std::unique_ptr<base::trace_event::TracedValue> debug_info;
...@@ -966,10 +960,6 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { ...@@ -966,10 +960,6 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
base::RepeatingCallback<void(const gfx::ScrollOffset&, const ElementId&)> base::RepeatingCallback<void(const gfx::ScrollOffset&, const ElementId&)>
did_scroll_callback; did_scroll_callback;
std::vector<std::unique_ptr<viz::CopyOutputRequest>> copy_requests; std::vector<std::unique_ptr<viz::CopyOutputRequest>> copy_requests;
base::Optional<SnapContainerData> snap_container_data;
int mirror_count;
}; };
Layer* parent_; Layer* parent_;
...@@ -981,6 +971,7 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { ...@@ -981,6 +971,7 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
Inputs inputs_; Inputs inputs_;
int paint_count_;
int num_descendants_that_draw_content_; int num_descendants_that_draw_content_;
int transform_tree_index_; int transform_tree_index_;
int effect_tree_index_; int effect_tree_index_;
...@@ -988,6 +979,12 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { ...@@ -988,6 +979,12 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
int scroll_tree_index_; int scroll_tree_index_;
int property_tree_sequence_number_; int property_tree_sequence_number_;
gfx::Vector2dF offset_to_transform_parent_; gfx::Vector2dF offset_to_transform_parent_;
// When true, the layer is about to perform an update. Any commit requests
// will be handled implicitly after the update completes. Not a bitfield
// because it's used in base::AutoReset.
bool ignore_set_needs_commit_;
bool should_flatten_screen_space_transform_from_property_tree_ : 1; bool should_flatten_screen_space_transform_from_property_tree_ : 1;
bool draws_content_ : 1; bool draws_content_ : 1;
bool should_check_backface_visibility_ : 1; bool should_check_backface_visibility_ : 1;
...@@ -1001,9 +998,10 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { ...@@ -1001,9 +998,10 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
bool has_clip_node_ : 1; bool has_clip_node_ : 1;
// This value is valid only when LayerTreeHost::has_copy_request() is true // This value is valid only when LayerTreeHost::has_copy_request() is true
bool subtree_has_copy_request_ : 1; bool subtree_has_copy_request_ : 1;
SkColor safe_opaque_background_color_; SkColor safe_opaque_background_color_;
uint64_t compositing_reasons_;
int owner_node_id_; int owner_node_id_;
uint64_t compositing_reasons_;
}; };
} // namespace cc } // namespace cc
......
...@@ -1941,5 +1941,9 @@ TEST_F(LayerTestWithLayerLists, SetElementIdUsingLayerLists) { ...@@ -1941,5 +1941,9 @@ TEST_F(LayerTestWithLayerLists, SetElementIdUsingLayerLists) {
EXPECT_EQ(nullptr, layer_tree_host_->LayerByElementId(element_id)); EXPECT_EQ(nullptr, layer_tree_host_->LayerByElementId(element_id));
} }
TEST(A, B) {
LOG(ERROR) << sizeof(Layer);
}
} // namespace } // namespace
} // namespace cc } // namespace cc
...@@ -169,8 +169,7 @@ void PaintedScrollbarLayer::UpdateInternalContentScale() { ...@@ -169,8 +169,7 @@ void PaintedScrollbarLayer::UpdateInternalContentScale() {
bool PaintedScrollbarLayer::Update() { bool PaintedScrollbarLayer::Update() {
{ {
base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, auto ignore_set_needs_commit = IgnoreSetNeedsCommit();
true);
Layer::Update(); Layer::Update();
UpdateInternalContentScale(); UpdateInternalContentScale();
} }
......
...@@ -150,7 +150,7 @@ bool PictureLayer::Update() { ...@@ -150,7 +150,7 @@ bool PictureLayer::Update() {
layer_tree_host()->recording_scale_factor()); layer_tree_host()->recording_scale_factor());
SetNeedsPushProperties(); SetNeedsPushProperties();
paint_count_++; IncreasePaintCount();
} else { } else {
// If this invalidation did not affect the recording source, then it can be // If this invalidation did not affect the recording source, then it can be
// cleared as an optimization. // cleared as an optimization.
......
...@@ -56,10 +56,4 @@ void FakePaintedScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { ...@@ -56,10 +56,4 @@ void FakePaintedScrollbarLayer::PushPropertiesTo(LayerImpl* layer) {
++push_properties_count_; ++push_properties_count_;
} }
std::unique_ptr<base::AutoReset<bool>>
FakePaintedScrollbarLayer::IgnoreSetNeedsCommit() {
return std::make_unique<base::AutoReset<bool>>(&ignore_set_needs_commit_,
true);
}
} // namespace cc } // namespace cc
...@@ -36,7 +36,7 @@ class FakePaintedScrollbarLayer : public PaintedScrollbarLayer { ...@@ -36,7 +36,7 @@ class FakePaintedScrollbarLayer : public PaintedScrollbarLayer {
void PushPropertiesTo(LayerImpl* layer) override; void PushPropertiesTo(LayerImpl* layer) override;
std::unique_ptr<base::AutoReset<bool>> IgnoreSetNeedsCommit(); using PaintedScrollbarLayer::IgnoreSetNeedsCommit;
size_t push_properties_count() const { return push_properties_count_; } size_t push_properties_count() const { return push_properties_count_; }
void reset_push_properties_count() { push_properties_count_ = 0; } void reset_push_properties_count() { push_properties_count_ = 0; }
......
...@@ -4639,8 +4639,7 @@ class LayerTreeHostTestPropertyChangesDuringUpdateArePushed ...@@ -4639,8 +4639,7 @@ class LayerTreeHostTestPropertyChangesDuringUpdateArePushed
// avoid causing a second commit to be scheduled. If a property change // avoid causing a second commit to be scheduled. If a property change
// is made during this, however, it needs to be pushed in the upcoming // is made during this, however, it needs to be pushed in the upcoming
// commit. // commit.
std::unique_ptr<base::AutoReset<bool>> ignore = auto ignore = scrollbar_layer_->IgnoreSetNeedsCommit();
scrollbar_layer_->IgnoreSetNeedsCommit();
scrollbar_layer_->SetBounds(gfx::Size(30, 30)); scrollbar_layer_->SetBounds(gfx::Size(30, 30));
......
...@@ -739,7 +739,6 @@ void PropertyTreeBuilderContext::AddScrollNodeIfNeeded( ...@@ -739,7 +739,6 @@ void PropertyTreeBuilderContext::AddScrollNodeIfNeeded(
node.user_scrollable_vertical = layer->GetUserScrollableVertical(); node.user_scrollable_vertical = layer->GetUserScrollableVertical();
node.element_id = layer->element_id(); node.element_id = layer->element_id();
node.transform_id = data_for_children->transform_tree_parent; node.transform_id = data_for_children->transform_tree_parent;
node.snap_container_data = layer->snap_container_data();
node_id = scroll_tree_.Insert(node, parent_id); node_id = scroll_tree_.Insert(node, parent_id);
data_for_children->scroll_tree_parent = node_id; data_for_children->scroll_tree_parent = node_id;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment