Skip to content

Commit

Permalink
cc: Add mask and replica layer ids to the effect tree
Browse files Browse the repository at this point in the history
This adds mask, replica, and replica mask layer ids to effect nodes,
removes mask_layer and replica_layer from LayerImpl, and adds
mask_layer and replica_layer to LayerImplTestProperties. With this
change, render surfaces can determine if they have a mask or replica
using their effect node rather than using their owning layer.

CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel
BUG=612220

Review-Url: https://codereview.chromium.org/2035863003
Cr-Commit-Position: refs/heads/master@{#399690}
  • Loading branch information
alijuma authored and Commit bot committed Jun 14, 2016
1 parent 1ae80b2 commit 1d4026a
Show file tree
Hide file tree
Showing 32 changed files with 469 additions and 472 deletions.
2 changes: 1 addition & 1 deletion cc/debug/debug_rect_history.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void DebugRectHistory::SaveScreenSpaceRects(
render_surface->screen_space_transform(),
render_surface->content_rect())));

if (render_surface_layer->replica_layer()) {
if (render_surface->HasReplica()) {
debug_rects_.push_back(
DebugRect(REPLICA_SCREEN_SPACE_RECT_TYPE,
MathUtil::MapEnclosingClippedRect(
Expand Down
96 changes: 1 addition & 95 deletions cc/layers/layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@
namespace cc {
LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, int id)
: parent_(nullptr),
mask_layer_id_(-1),
mask_layer_(nullptr),
replica_layer_id_(-1),
replica_layer_(nullptr),
layer_id_(id),
layer_tree_impl_(tree_impl),
test_properties_(nullptr),
Expand Down Expand Up @@ -103,12 +99,6 @@ LayerImpl::~LayerImpl() {

TRACE_EVENT_OBJECT_DELETED_WITH_ID(
TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerImpl", this);

// The mask and replica layers should have been removed already.
if (mask_layer_)
DCHECK(!layer_tree_impl_->RemoveLayer(mask_layer_id_));
if (replica_layer_)
DCHECK(!layer_tree_impl_->RemoveLayer(replica_layer_id_));
}

void LayerImpl::AddChild(std::unique_ptr<LayerImpl> child) {
Expand All @@ -131,11 +121,6 @@ void LayerImpl::SetParent(LayerImpl* parent) {
parent_ = parent;
}

void LayerImpl::ClearLinksToOtherLayers() {
mask_layer_ = nullptr;
replica_layer_ = nullptr;
}

void LayerImpl::SetHasWillChangeTransformHint(bool has_will_change) {
if (has_will_change_transform_hint_ == has_will_change)
return;
Expand Down Expand Up @@ -525,14 +510,6 @@ void LayerImpl::ResetChangeTracking() {

if (render_surface_)
render_surface_->ResetPropertyChangedFlag();

if (mask_layer_)
mask_layer_->ResetChangeTracking();

if (replica_layer_) {
// This also resets the replica mask, if it exists.
replica_layer_->ResetChangeTracking();
}
}

int LayerImpl::num_copy_requests_in_target_subtree() {
Expand Down Expand Up @@ -793,65 +770,6 @@ void LayerImpl::SetBoundsDelta(const gfx::Vector2dF& bounds_delta) {
}
}

void LayerImpl::SetMaskLayer(std::unique_ptr<LayerImpl> mask_layer) {
int new_layer_id = mask_layer ? mask_layer->id() : -1;

if (mask_layer) {
DCHECK_EQ(layer_tree_impl(), mask_layer->layer_tree_impl());
DCHECK_NE(new_layer_id, mask_layer_id_);
} else if (new_layer_id == mask_layer_id_) {
return;
}

if (mask_layer_)
layer_tree_impl_->RemoveLayer(mask_layer_->id());
mask_layer_ = mask_layer.get();
if (mask_layer_)
layer_tree_impl_->AddLayer(std::move(mask_layer));

mask_layer_id_ = new_layer_id;
}

std::unique_ptr<LayerImpl> LayerImpl::TakeMaskLayer() {
mask_layer_id_ = -1;
std::unique_ptr<LayerImpl> ret;
if (mask_layer_)
ret = layer_tree_impl_->RemoveLayer(mask_layer_->id());
mask_layer_ = nullptr;
return ret;
}

void LayerImpl::SetReplicaLayer(std::unique_ptr<LayerImpl> replica_layer) {
int new_layer_id = replica_layer ? replica_layer->id() : -1;

if (replica_layer) {
DCHECK_EQ(layer_tree_impl(), replica_layer->layer_tree_impl());
DCHECK_NE(new_layer_id, replica_layer_id_);
} else if (new_layer_id == replica_layer_id_) {
return;
}

if (replica_layer_)
layer_tree_impl_->RemoveLayer(replica_layer_->id());
replica_layer_ = replica_layer.get();
if (replica_layer_)
layer_tree_impl_->AddLayer(std::move(replica_layer));

replica_layer_id_ = new_layer_id;
}

std::unique_ptr<LayerImpl> LayerImpl::TakeReplicaLayerForTesting() {
replica_layer_id_ = -1;
std::unique_ptr<LayerImpl> ret;
if (replica_layer_) {
if (replica_layer_->mask_layer())
replica_layer_->SetMaskLayer(nullptr);
ret = layer_tree_impl_->RemoveLayer(replica_layer_->id());
}
replica_layer_ = nullptr;
return ret;
}

ScrollbarLayerImplBase* LayerImpl::ToScrollbarLayer() {
return nullptr;
}
Expand Down Expand Up @@ -1169,16 +1087,6 @@ void LayerImpl::AsValueInto(base::trace_event::TracedValue* state) const {
non_fast_scrollable_region_.AsValueInto(state);
state->EndArray();
}
if (mask_layer_) {
state->BeginDictionary("mask_layer");
mask_layer_->AsValueInto(state);
state->EndDictionary();
}
if (replica_layer_) {
state->BeginDictionary("replica_layer");
replica_layer_->AsValueInto(state);
state->EndDictionary();
}

state->SetBoolean("can_use_lcd_text", CanUseLCDText());
state->SetBoolean("contents_opaque", contents_opaque());
Expand Down Expand Up @@ -1334,9 +1242,7 @@ bool LayerImpl::InsideReplica() const {
EffectNode* node = effect_tree.Node(effect_tree_index_);

while (node->id > 0) {
LayerImpl* target_layer = layer_tree_impl()->LayerById(node->owner_id);
DCHECK(target_layer);
if (target_layer->has_replica())
if (node->data.replica_layer_id != -1)
return true;
node = effect_tree.Node(node->data.target_id);
}
Expand Down
26 changes: 1 addition & 25 deletions cc/layers/layer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,6 @@ class CC_EXPORT LayerImpl {
// For compatibility with Layer.
bool has_render_surface() const { return !!render_surface(); }

void SetMaskLayer(std::unique_ptr<LayerImpl> mask_layer);
LayerImpl* mask_layer() { return mask_layer_; }
const LayerImpl* mask_layer() const { return mask_layer_; }
std::unique_ptr<LayerImpl> TakeMaskLayer();

void SetReplicaLayer(std::unique_ptr<LayerImpl> replica_layer);
LayerImpl* replica_layer() { return replica_layer_; }
const LayerImpl* replica_layer() const { return replica_layer_; }
std::unique_ptr<LayerImpl> TakeReplicaLayerForTesting();

bool has_mask() const { return !!mask_layer_; }
bool has_replica() const { return !!replica_layer_; }
bool replica_has_mask() const {
return replica_layer_ && (mask_layer_ || replica_layer_->mask_layer_);
}

LayerTreeImpl* layer_tree_impl() const { return layer_tree_impl_; }

void PopulateSharedQuadState(SharedQuadState* state) const;
Expand Down Expand Up @@ -202,7 +186,7 @@ class CC_EXPORT LayerImpl {

LayerImplTestProperties* test_properties() {
if (!test_properties_)
test_properties_.reset(new LayerImplTestProperties());
test_properties_.reset(new LayerImplTestProperties(this));
return test_properties_.get();
}

Expand Down Expand Up @@ -500,8 +484,6 @@ class CC_EXPORT LayerImpl {

void NoteLayerPropertyChanged();

void ClearLinksToOtherLayers();

void SetHasWillChangeTransformHint(bool has_will_change);
bool has_will_change_transform_hint() const {
return has_will_change_transform_hint_;
Expand Down Expand Up @@ -537,12 +519,6 @@ class CC_EXPORT LayerImpl {
// Properties internal to LayerImpl
LayerImpl* parent_;

// mask_layer_ can be temporarily stolen during tree sync, we need this ID to
// confirm newly assigned layer is still the previous one
int mask_layer_id_;
LayerImpl* mask_layer_;
int replica_layer_id_; // ditto
LayerImpl* replica_layer_;
int layer_id_;
LayerTreeImpl* layer_tree_impl_;

Expand Down
32 changes: 29 additions & 3 deletions cc/layers/layer_impl_test_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

#include "cc/layers/layer_impl_test_properties.h"

#include "cc/layers/layer_impl.h"
#include "cc/output/copy_output_request.h"
#include "cc/trees/layer_tree_impl.h"

namespace cc {

LayerImplTestProperties::LayerImplTestProperties()
: double_sided(true),
LayerImplTestProperties::LayerImplTestProperties(LayerImpl* owning_layer)
: owning_layer(owning_layer),
double_sided(true),
force_render_surface(false),
is_container_for_fixed_position_layers(false),
should_flatten_transform(true),
Expand All @@ -19,8 +22,31 @@ LayerImplTestProperties::LayerImplTestProperties()
num_unclipped_descendants(0),
opacity(1.f),
scroll_parent(nullptr),
clip_parent(nullptr) {}
clip_parent(nullptr),
mask_layer(nullptr),
replica_layer(nullptr) {}

LayerImplTestProperties::~LayerImplTestProperties() {}

void LayerImplTestProperties::SetMaskLayer(std::unique_ptr<LayerImpl> mask) {
if (mask_layer)
owning_layer->layer_tree_impl()->RemoveLayer(mask_layer->id());
mask_layer = mask.get();
if (mask)
owning_layer->layer_tree_impl()->AddLayer(std::move(mask));
}

void LayerImplTestProperties::SetReplicaLayer(
std::unique_ptr<LayerImpl> replica) {
if (replica_layer) {
replica_layer->test_properties()->SetMaskLayer(nullptr);
owning_layer->layer_tree_impl()->RemoveLayer(replica_layer->id());
}
replica_layer = replica.get();
if (replica) {
replica->SetParent(owning_layer);
owning_layer->layer_tree_impl()->AddLayer(std::move(replica));
}
}

} // namespace cc
8 changes: 7 additions & 1 deletion cc/layers/layer_impl_test_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ class CopyOutputRequest;
class LayerImpl;

struct CC_EXPORT LayerImplTestProperties {
LayerImplTestProperties();
explicit LayerImplTestProperties(LayerImpl* owning_layer);
~LayerImplTestProperties();

void SetMaskLayer(std::unique_ptr<LayerImpl> mask);
void SetReplicaLayer(std::unique_ptr<LayerImpl> replica);

LayerImpl* owning_layer;
bool double_sided;
bool force_render_surface;
bool is_container_for_fixed_position_layers;
Expand All @@ -39,6 +43,8 @@ struct CC_EXPORT LayerImplTestProperties {
std::unique_ptr<std::set<LayerImpl*>> clip_children;
std::vector<std::unique_ptr<CopyOutputRequest>> copy_requests;
LayerImplList children;
LayerImpl* mask_layer;
LayerImpl* replica_layer;
};

} // namespace cc
Expand Down
6 changes: 0 additions & 6 deletions cc/layers/layer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,17 +300,11 @@ TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) {
gfx::ScrollOffset(arbitrary_vector2d.x(), arbitrary_vector2d.y())));

// Unrelated functions, always set to new values, always set needs update.
VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 4));
layer->NoteLayerPropertyChanged());
host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();
VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetMasksToBounds(true);
layer->NoteLayerPropertyChanged());
VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetContentsOpaque(true);
layer->NoteLayerPropertyChanged());
VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
layer->SetReplicaLayer(LayerImpl::Create(host_impl.active_tree(), 5));
layer->NoteLayerPropertyChanged());
VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer2->SetPosition(arbitrary_point_f);
layer->NoteLayerPropertyChanged());
VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->Set3dSortingContextId(1);
Expand Down
26 changes: 13 additions & 13 deletions cc/layers/picture_layer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1144,13 +1144,13 @@ TEST_F(PictureLayerImplTest, DontAddLowResForSmallLayers) {
host_impl()->pending_tree(), 3, pending_raster_source);
mask->SetBounds(layer_bounds);
mask->SetDrawsContent(true);
pending_layer()->SetMaskLayer(std::move(mask));
pending_layer()->test_properties()->SetMaskLayer(std::move(mask));
pending_layer()->SetHasRenderSurface(true);
RebuildPropertyTreesOnPendingTree();
host_impl()->pending_tree()->UpdateDrawProperties(false);

FakePictureLayerImpl* mask_raw =
static_cast<FakePictureLayerImpl*>(pending_layer()->mask_layer());
FakePictureLayerImpl* mask_raw = static_cast<FakePictureLayerImpl*>(
pending_layer()->test_properties()->mask_layer);
// We did an UpdateDrawProperties above, which will set a contents scale on
// the mask layer, so allow us to reset the contents scale.
mask_raw->ReleaseResources();
Expand All @@ -1177,16 +1177,16 @@ TEST_F(PictureLayerImplTest, HugeMasksGetScaledDown) {
host_impl()->pending_tree(), 3, valid_raster_source);
mask_ptr->SetBounds(layer_bounds);
mask_ptr->SetDrawsContent(true);
pending_layer()->SetMaskLayer(std::move(mask_ptr));
pending_layer()->test_properties()->SetMaskLayer(std::move(mask_ptr));
pending_layer()->test_properties()->force_render_surface = true;

RebuildPropertyTreesOnPendingTree();
host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
bool update_lcd_text = false;
host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text);

FakePictureLayerImpl* pending_mask =
static_cast<FakePictureLayerImpl*>(pending_layer()->mask_layer());
FakePictureLayerImpl* pending_mask = static_cast<FakePictureLayerImpl*>(
pending_layer()->test_properties()->mask_layer);

EXPECT_EQ(1.f, pending_mask->HighResTiling()->contents_scale());
EXPECT_EQ(1u, pending_mask->num_tilings());
Expand All @@ -1196,8 +1196,8 @@ TEST_F(PictureLayerImplTest, HugeMasksGetScaledDown) {

ActivateTree();

FakePictureLayerImpl* active_mask =
static_cast<FakePictureLayerImpl*>(active_layer()->mask_layer());
FakePictureLayerImpl* active_mask = static_cast<FakePictureLayerImpl*>(
host_impl()->active_tree()->LayerById(pending_mask->id()));

// Mask layers have a tiling with a single tile in it.
EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
Expand Down Expand Up @@ -1307,16 +1307,16 @@ TEST_F(PictureLayerImplTest, ScaledMaskLayer) {
host_impl()->pending_tree(), 3, valid_raster_source);
mask_ptr->SetBounds(layer_bounds);
mask_ptr->SetDrawsContent(true);
pending_layer()->SetMaskLayer(std::move(mask_ptr));
pending_layer()->test_properties()->SetMaskLayer(std::move(mask_ptr));
pending_layer()->test_properties()->force_render_surface = true;

RebuildPropertyTreesOnPendingTree();
host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
bool update_lcd_text = false;
host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text);

FakePictureLayerImpl* pending_mask =
static_cast<FakePictureLayerImpl*>(pending_layer()->mask_layer());
FakePictureLayerImpl* pending_mask = static_cast<FakePictureLayerImpl*>(
pending_layer()->test_properties()->mask_layer);

// Masks are scaled, and do not have a low res tiling.
EXPECT_EQ(1.3f, pending_mask->HighResTiling()->contents_scale());
Expand All @@ -1327,8 +1327,8 @@ TEST_F(PictureLayerImplTest, ScaledMaskLayer) {

ActivateTree();

FakePictureLayerImpl* active_mask =
static_cast<FakePictureLayerImpl*>(active_layer()->mask_layer());
FakePictureLayerImpl* active_mask = static_cast<FakePictureLayerImpl*>(
host_impl()->active_tree()->LayerById(pending_mask->id()));

// Mask layers have a tiling with a single tile in it.
EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
Expand Down
Loading

0 comments on commit 1d4026a

Please sign in to comment.