Skip to content

Commit

Permalink
Refactor cc::Layer bit flags, and make them ProtectedSequenceReadable
Browse files Browse the repository at this point in the history
Aside from using ProtectedSequenceReadable, this is a mechanical
patch that applies uniform naming and getter/setter style to the
bit fields.

Bug: chromium:1255972
Change-Id: Ibb687622d03a53c2a36b801ec253265718a543ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3403095
Reviewed-by: Vladimir Levin <vmpstr@chromium.org>
Reviewed-by: Robert Flack <flackr@chromium.org>
Reviewed-by: Matthew Jones <mdjones@chromium.org>
Commit-Queue: Stefan Zager <szager@chromium.org>
Cr-Commit-Position: refs/heads/main@{#964128}
  • Loading branch information
szager-chromium authored and Chromium LUCI CQ committed Jan 27, 2022
1 parent 568be10 commit 2cec268
Show file tree
Hide file tree
Showing 31 changed files with 178 additions and 180 deletions.
2 changes: 1 addition & 1 deletion cc/benchmarks/rasterize_and_record_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ RasterizeAndRecordBenchmark::CreateBenchmarkImpl(
void RasterizeAndRecordBenchmark::RunOnLayer(PictureLayer* layer) {
DCHECK(layer_tree_host_);

if (!layer->DrawsContent())
if (!layer->draws_content())
return;

ContentLayerClient* painter = layer->client();
Expand Down
2 changes: 1 addition & 1 deletion cc/layers/heads_up_display_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ HeadsUpDisplayLayer::HeadsUpDisplayLayer()
}
DCHECK(typeface_.get());
SetIsDrawable(true);
UpdateDrawsContent(HasDrawableContent());
SetDrawsContent(HasDrawableContent());
}

HeadsUpDisplayLayer::~HeadsUpDisplayLayer() = default;
Expand Down
126 changes: 43 additions & 83 deletions cc/layers/layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,7 @@ Layer::Layer()
// Layer IDs start from 1.
layer_id_(g_next_layer_id.GetNext() + 1),
ignore_set_needs_commit_(false),
draws_content_(false),
should_check_backface_visibility_(false),
cache_render_surface_(false),
force_render_surface_for_testing_(false),
may_contain_video_(false),
has_transform_node_(false),
has_clip_node_(false),
subtree_has_copy_request_(false),
bitflags_(0u),
subtree_property_changed_(false) {}

Layer::~Layer() {
Expand Down Expand Up @@ -265,7 +258,7 @@ void Layer::InsertChild(scoped_refptr<Layer> child, size_t index) {
DCHECK(IsPropertyChangeAllowed());
child->RemoveFromParent();
AddDrawableDescendants(child->NumDescendantsThatDrawContent() +
(child->DrawsContent() ? 1 : 0));
(child->draws_content() ? 1 : 0));
child->SetParent(this);
child->SetSubtreePropertyChanged();

Expand Down Expand Up @@ -301,13 +294,36 @@ void Layer::RemoveChild(Layer* child) {

child->SetParent(nullptr);
AddDrawableDescendants(-child->NumDescendantsThatDrawContent() -
(child->DrawsContent() ? 1 : 0));
(child->draws_content() ? 1 : 0));
inputs.children.erase(iter);
SetNeedsFullTreeSync();
return;
}
}

bool Layer::GetBitFlag(uint8_t mask) const {
return bitflags_.Read(*this) & mask;
}

bool Layer::SetBitFlag(bool new_value,
uint8_t mask,
bool invalidate,
bool needs_push) {
if (GetBitFlag(mask) == new_value)
return false;
if (new_value)
bitflags_.Write(*this) |= mask;
else
bitflags_.Write(*this) &= ~mask;
if (invalidate) {
SetPropertyTreesNeedRebuild();
SetNeedsCommit();
}
if (needs_push)
SetNeedsPushProperties();
return true;
}

void Layer::ReorderChildren(LayerList* new_children_order) {
auto& inputs = inputs_.Write(*this);
#if DCHECK_IS_ON()
Expand Down Expand Up @@ -425,7 +441,7 @@ void Layer::SetChildLayerList(LayerList new_children) {
for (auto* child : children_to_remove) {
child->SetParent(nullptr);
AddDrawableDescendants(-child->NumDescendantsThatDrawContent() -
(child->DrawsContent() ? 1 : 0));
(child->draws_content() ? 1 : 0));
}
}

Expand All @@ -447,7 +463,7 @@ void Layer::SetChildLayerList(LayerList new_children) {
if (child->parent() != this) {
child->RemoveFromParent();
AddDrawableDescendants(child->NumDescendantsThatDrawContent() +
(child->DrawsContent() ? 1 : 0));
(child->draws_content() ? 1 : 0));
child->SetParent(this);
child->SetSubtreePropertyChanged();
}
Expand Down Expand Up @@ -488,18 +504,6 @@ void Layer::RequestCopyOfOutput(
layer_tree_host()->SetHasCopyRequest(true);
}

void Layer::SetSubtreeHasCopyRequest(bool subtree_has_copy_request) {
subtree_has_copy_request_ = subtree_has_copy_request;
}

bool Layer::SubtreeHasCopyRequest() const {
DCHECK(IsAttached());
// When the copy request is pushed to effect tree, we reset layer tree host's
// has_copy_request but do not clear subtree_has_copy_request on individual
// layers.
return layer_tree_host()->has_copy_request() && subtree_has_copy_request_;
}

void Layer::SetBackgroundColor(SkColor background_color) {
DCHECK(IsPropertyChangeAllowed());
auto& inputs = inputs_.Write(*this);
Expand Down Expand Up @@ -575,7 +579,7 @@ void Layer::SetClipRect(const gfx::Rect& clip_rect) {
inputs.clip_rect = clip_rect;

// If the clip bounds have been cleared, the property trees needs a rebuild.
const bool force_rebuild = clip_rect.IsEmpty() || !has_clip_node_;
const bool force_rebuild = clip_rect.IsEmpty() || !has_clip_node();

SetSubtreePropertyChanged();
if (clip_tree_index() != ClipTree::kInvalidNodeId && !force_rebuild) {
Expand Down Expand Up @@ -875,7 +879,7 @@ void Layer::SetPosition(const gfx::PointF& position) {

SetSubtreePropertyChanged();

if (has_transform_node_) {
if (has_transform_node()) {
TransformNode* transform_node =
layer_tree_host()->property_trees()->transform_tree.Node(
transform_tree_index_);
Expand Down Expand Up @@ -916,7 +920,7 @@ void Layer::SetTransform(const gfx::Transform& transform) {

SetSubtreePropertyChanged();
if (IsAttached()) {
if (has_transform_node_) {
if (has_transform_node()) {
TransformNode* transform_node =
layer_tree_host()->property_trees()->transform_tree.Node(
transform_tree_index_);
Expand Down Expand Up @@ -954,7 +958,7 @@ void Layer::SetTransformOrigin(const gfx::Point3F& transform_origin) {

SetSubtreePropertyChanged();

if (has_transform_node_) {
if (has_transform_node()) {
TransformNode* transform_node =
layer_tree_host()->property_trees()->transform_tree.Node(
transform_tree_index_);
Expand Down Expand Up @@ -1158,15 +1162,6 @@ void Layer::SetWheelEventRegion(Region wheel_event_region) {
SetNeedsCommit();
}

void Layer::SetCacheRenderSurface(bool cache) {
DCHECK(IsPropertyChangeAllowed());
if (cache_render_surface_ == cache)
return;
cache_render_surface_ = cache;
SetPropertyTreesNeedRebuild();
SetNeedsCommit();
}

RenderSurfaceReason Layer::GetRenderSurfaceReason() const {
if (!IsAttached())
return RenderSurfaceReason::kNone;
Expand All @@ -1185,21 +1180,11 @@ RenderSurfaceReason Layer::GetRenderSurfaceReason() const {
return effect_node->render_surface_reason;
}

void Layer::SetForceRenderSurfaceForTesting(bool force) {
DCHECK(IsPropertyChangeAllowed());
if (force_render_surface_for_testing_ == force)
return;
force_render_surface_for_testing_ = force;
SetPropertyTreesNeedRebuild();
SetNeedsCommit();
}

void Layer::SetTransformTreeIndex(int index) {
DCHECK(IsPropertyChangeAllowed());
if (transform_tree_index_ == index)
return;
if (index == TransformTree::kInvalidNodeId)
has_transform_node_ = false;
SetHasTransformNode(index != TransformTree::kInvalidNodeId);
transform_tree_index_ = index;
SetNeedsPushProperties();
}
Expand Down Expand Up @@ -1365,21 +1350,13 @@ std::string Layer::ToString() const {
effect_tree_index(), scroll_tree_index(), transform_tree_index());
}

void Layer::SetShouldCheckBackfaceVisibility(
bool should_check_backface_visibility) {
if (should_check_backface_visibility_ == should_check_backface_visibility)
return;
should_check_backface_visibility_ = should_check_backface_visibility;
SetNeedsPushProperties();
}

void Layer::SetIsDrawable(bool is_drawable) {
DCHECK(IsPropertyChangeAllowed());
if (inputs_.Read(*this).is_drawable == is_drawable)
return;

inputs_.Write(*this).is_drawable = is_drawable;
UpdateDrawsContent(HasDrawableContent());
SetDrawsContent(HasDrawableContent());
}

void Layer::SetHideLayerAndSubtree(bool hide) {
Expand All @@ -1401,7 +1378,7 @@ void Layer::SetNeedsDisplayRect(const gfx::Rect& dirty_rect) {
SetNeedsPushProperties();
update_rect_.Write(*this).Union(dirty_rect);

if (DrawsContent() && IsAttached() && !ignore_set_needs_commit_)
if (draws_content() && IsAttached() && !ignore_set_needs_commit_)
layer_tree_host()->SetNeedsUpdateLayers();
}

Expand All @@ -1423,7 +1400,7 @@ void Layer::PushPropertiesTo(LayerImpl* layer,
// deprecated. http://crbug.com/709137
const auto& inputs = inputs_.Read(*this);
layer->SetElementId(inputs.element_id);
layer->SetHasTransformNode(has_transform_node_);
layer->SetHasTransformNode(has_transform_node());
layer->SetBackgroundColor(inputs.background_color);
layer->SetSafeOpaqueBackgroundColor(
SafeOpaqueBackgroundColor(commit_state.background_color));
Expand All @@ -1433,17 +1410,17 @@ void Layer::PushPropertiesTo(LayerImpl* layer,
layer->SetClipTreeIndex(clip_tree_index(property_trees));
layer->SetScrollTreeIndex(scroll_tree_index(property_trees));
layer->SetOffsetToTransformParent(offset_to_transform_parent_);
layer->SetDrawsContent(DrawsContent());
layer->SetDrawsContent(draws_content());
layer->SetHitTestable(HitTestable());
// subtree_property_changed_ is propagated to all descendants while building
// property trees. So, it is enough to check it only for the current layer.
if (subtree_property_changed_.Read(*this))
layer->NoteLayerPropertyChanged();
layer->set_may_contain_video(may_contain_video_);
layer->set_may_contain_video(may_contain_video());
layer->SetTouchActionRegion(inputs.touch_action_region);
layer->SetContentsOpaque(inputs.contents_opaque);
layer->SetContentsOpaqueForText(inputs.contents_opaque_for_text);
layer->SetShouldCheckBackfaceVisibility(should_check_backface_visibility_);
layer->SetShouldCheckBackfaceVisibility(should_check_backface_visibility());

layer->UpdateScrollable();

Expand Down Expand Up @@ -1509,26 +1486,16 @@ std::unique_ptr<LayerImpl> Layer::CreateLayerImpl(
return LayerImpl::Create(tree_impl, id());
}

bool Layer::DrawsContent() const {
return draws_content_;
}

bool Layer::HasDrawableContent() const {
return inputs_.Read(*this).is_drawable;
}

void Layer::UpdateDrawsContent(bool has_drawable_content) {
bool draws_content = has_drawable_content;
DCHECK(inputs_.Read(*this).is_drawable || !has_drawable_content);
if (draws_content == draws_content_)
void Layer::SetDrawsContent(bool value) {
DCHECK(inputs_.Read(*this).is_drawable || !value);
if (!SetBitFlag(value, kDrawsContentFlagMask, /*invalidate=*/true))
return;

if (parent())
mutable_parent()->AddDrawableDescendants(draws_content ? 1 : -1);

draws_content_ = draws_content;
SetPropertyTreesNeedRebuild();
SetNeedsCommit();
mutable_parent()->AddDrawableDescendants(value ? 1 : -1);
}

int Layer::NumDescendantsThatDrawContent() const {
Expand All @@ -1547,13 +1514,6 @@ void Layer::SetSubtreePropertyChanged() {
SetNeedsPushProperties();
}

void Layer::SetMayContainVideo(bool yes) {
if (may_contain_video_ == yes)
return;
may_contain_video_ = yes;
SetNeedsPushProperties();
}

bool Layer::IsOwnerThread() const {
return !IsAttached() || layer_tree_host_->IsOwnerThread();
}
Expand Down
Loading

0 comments on commit 2cec268

Please sign in to comment.