Skip to content

Commit

Permalink
cc: Make CallFunctionForEveryLayer use LayerListIterator
Browse files Browse the repository at this point in the history
Now that we have a main thread and impl thread layer list iterator. We
should use the iterator to perform those methods on every layer. The old
traversal way should be abandoned.

CallFunctionForEveryLayer is expected to call function for all mask_layers
and replica_layers.

BUG=603181
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel

Review URL: https://codereview.chromium.org/1907053004

Cr-Commit-Position: refs/heads/master@{#389487}
  • Loading branch information
sunxd authored and Commit bot committed Apr 25, 2016
1 parent 71705d9 commit 8591041
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 120 deletions.
9 changes: 3 additions & 6 deletions cc/debug/debug_rect_history.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ void DebugRectHistory::SaveScreenSpaceRects(
void DebugRectHistory::SaveTouchEventHandlerRects(LayerTreeImpl* tree_impl) {
LayerTreeHostCommon::CallFunctionForEveryLayer(
tree_impl,
[this](LayerImpl* layer) { SaveTouchEventHandlerRectsCallback(layer); },
CallFunctionLayerType::ALL_LAYERS);
[this](LayerImpl* layer) { SaveTouchEventHandlerRectsCallback(layer); });
}

void DebugRectHistory::SaveTouchEventHandlerRectsCallback(LayerImpl* layer) {
Expand Down Expand Up @@ -200,8 +199,7 @@ void DebugRectHistory::SaveWheelEventHandlerRects(LayerImpl* root_layer) {
void DebugRectHistory::SaveScrollEventHandlerRects(LayerTreeImpl* tree_impl) {
LayerTreeHostCommon::CallFunctionForEveryLayer(
tree_impl,
[this](LayerImpl* layer) { SaveScrollEventHandlerRectsCallback(layer); },
CallFunctionLayerType::ALL_LAYERS);
[this](LayerImpl* layer) { SaveScrollEventHandlerRectsCallback(layer); });
}

void DebugRectHistory::SaveScrollEventHandlerRectsCallback(LayerImpl* layer) {
Expand All @@ -217,8 +215,7 @@ void DebugRectHistory::SaveScrollEventHandlerRectsCallback(LayerImpl* layer) {
void DebugRectHistory::SaveNonFastScrollableRects(LayerTreeImpl* tree_impl) {
LayerTreeHostCommon::CallFunctionForEveryLayer(
tree_impl,
[this](LayerImpl* layer) { SaveNonFastScrollableRectsCallback(layer); },
CallFunctionLayerType::ALL_LAYERS);
[this](LayerImpl* layer) { SaveNonFastScrollableRectsCallback(layer); });
}

void DebugRectHistory::SaveNonFastScrollableRectsCallback(LayerImpl* layer) {
Expand Down
3 changes: 1 addition & 2 deletions cc/debug/invalidation_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ InvalidationBenchmark::~InvalidationBenchmark() {

void InvalidationBenchmark::DidUpdateLayers(LayerTreeHost* host) {
LayerTreeHostCommon::CallFunctionForEveryLayer(
host, [this](Layer* layer) { layer->RunMicroBenchmark(this); },
CallFunctionLayerType::ALL_LAYERS);
host, [this](Layer* layer) { layer->RunMicroBenchmark(this); });
}

void InvalidationBenchmark::RunOnLayer(PictureLayer* layer) {
Expand Down
3 changes: 1 addition & 2 deletions cc/debug/rasterize_and_record_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ RasterizeAndRecordBenchmark::~RasterizeAndRecordBenchmark() {
void RasterizeAndRecordBenchmark::DidUpdateLayers(LayerTreeHost* host) {
host_ = host;
LayerTreeHostCommon::CallFunctionForEveryLayer(
host, [this](Layer* layer) { layer->RunMicroBenchmark(this); },
CallFunctionLayerType::ALL_LAYERS);
host, [this](Layer* layer) { layer->RunMicroBenchmark(this); });

DCHECK(!results_.get());
results_ = base::WrapUnique(new base::DictionaryValue);
Expand Down
6 changes: 2 additions & 4 deletions cc/debug/rasterize_and_record_benchmark_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,10 @@ RasterizeAndRecordBenchmarkImpl::~RasterizeAndRecordBenchmarkImpl() {}
void RasterizeAndRecordBenchmarkImpl::DidCompleteCommit(
LayerTreeHostImpl* host) {
LayerTreeHostCommon::CallFunctionForEveryLayer(
host->active_tree(),
[this](LayerImpl* layer) {
host->active_tree(), [this](LayerImpl* layer) {
rasterize_results_.total_layers++;
layer->RunMicroBenchmark(this);
},
CallFunctionLayerType::ALL_LAYERS);
});

std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue());
result->SetDouble("rasterize_time_ms",
Expand Down
3 changes: 1 addition & 2 deletions cc/layers/layer_proto_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ void LayerProtoConverter::RecursivelyFindAllLayers(Layer* root_layer,
LayerIdMap* layer_id_map) {
LayerTreeHostCommon::CallFunctionForEveryLayer(
root_layer->layer_tree_host(),
[layer_id_map](Layer* layer) { (*layer_id_map)[layer->id()] = layer; },
CallFunctionLayerType::ALL_LAYERS);
[layer_id_map](Layer* layer) { (*layer_id_map)[layer->id()] = layer; });
}

// static
Expand Down
47 changes: 22 additions & 25 deletions cc/trees/draw_property_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -426,32 +426,29 @@ void FindLayersThatNeedUpdates(LayerTreeHost* layer_tree_host,
const TransformTree& transform_tree,
const EffectTree& effect_tree,
LayerList* update_layer_list) {
LayerTreeHostCommon::CallFunctionForEveryLayer(
layer_tree_host,
[&](Layer* layer) {
bool layer_is_drawn =
effect_tree.Node(layer->effect_tree_index())->data.is_drawn;

if (!IsRootLayer(layer) &&
LayerShouldBeSkipped(layer, layer_is_drawn, transform_tree,
effect_tree))
return;

if (LayerNeedsUpdate(layer, layer_is_drawn, transform_tree)) {
update_layer_list->push_back(layer);
}
for (auto* layer : *layer_tree_host) {
bool layer_is_drawn =
effect_tree.Node(layer->effect_tree_index())->data.is_drawn;

// Append mask layers to the update layer list. They don't have valid
// visible rects, so need to get added after the above calculation.
// Replica layers don't need to be updated.
if (Layer* mask_layer = layer->mask_layer())
update_layer_list->push_back(mask_layer);
if (Layer* replica_layer = layer->replica_layer()) {
if (Layer* mask_layer = replica_layer->mask_layer())
update_layer_list->push_back(mask_layer);
}
},
CallFunctionLayerType::BASIC_LAYER);
if (!IsRootLayer(layer) &&
LayerShouldBeSkipped(layer, layer_is_drawn, transform_tree,
effect_tree))
continue;

if (LayerNeedsUpdate(layer, layer_is_drawn, transform_tree)) {
update_layer_list->push_back(layer);
}

// Append mask layers to the update layer list. They don't have valid
// visible rects, so need to get added after the above calculation.
// Replica layers don't need to be updated.
if (Layer* mask_layer = layer->mask_layer())
update_layer_list->push_back(mask_layer);
if (Layer* replica_layer = layer->replica_layer()) {
if (Layer* mask_layer = replica_layer->mask_layer())
update_layer_list->push_back(mask_layer);
}
}
}

static void ResetIfHasNanCoordinate(gfx::RectF* rect) {
Expand Down
12 changes: 4 additions & 8 deletions cc/trees/layer_tree_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,7 @@ void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) {
frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() &&
root_layer()) {
LayerTreeHostCommon::CallFunctionForEveryLayer(
this, [](Layer* layer) { layer->DidBeginTracing(); },
CallFunctionLayerType::ALL_LAYERS);
this, [](Layer* layer) { layer->DidBeginTracing(); });
}

LayerTreeImpl* sync_tree = host_impl->sync_tree();
Expand Down Expand Up @@ -1650,12 +1649,9 @@ void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) {
// updated for other reasons. All layers that at this point are part of the
// layer tree are valid, so it is OK that they have a valid sequence number.
int seq_num = property_trees_.sequence_number;
LayerTreeHostCommon::CallFunctionForEveryLayer(
this,
[seq_num](Layer* layer) {
layer->set_property_tree_sequence_number(seq_num);
},
CallFunctionLayerType::ALL_LAYERS);
LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) {
layer->set_property_tree_sequence_number(seq_num);
});

surface_id_namespace_ = proto.surface_id_namespace();
next_surface_sequence_ = proto.next_surface_sequence();
Expand Down
56 changes: 13 additions & 43 deletions cc/trees/layer_tree_host_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ class Layer;
class SwapPromise;
class PropertyTrees;

enum CallFunctionLayerType : uint32_t {
BASIC_LAYER = 0,
MASK_LAYER = 1,
REPLICA_LAYER = 2,
ALL_LAYERS = MASK_LAYER | REPLICA_LAYER
};

class CC_EXPORT LayerTreeHostCommon {
public:
struct CC_EXPORT CalcDrawPropsMainInputsForTesting {
Expand Down Expand Up @@ -138,13 +131,11 @@ class CC_EXPORT LayerTreeHostCommon {

template <typename Function>
static void CallFunctionForEveryLayer(LayerTreeHost* layer,
const Function& function,
const CallFunctionLayerType& type);
const Function& function);

template <typename Function>
static void CallFunctionForEveryLayer(LayerTreeImpl* layer,
const Function& function,
const CallFunctionLayerType& type);
const Function& function);

struct CC_EXPORT ScrollUpdateInfo {
int layer_id;
Expand Down Expand Up @@ -178,51 +169,30 @@ struct CC_EXPORT ScrollAndScaleSet {
};

template <typename LayerType, typename Function>
static void CallFunctionForLayer(LayerType* layer,
const Function& function,
const CallFunctionLayerType& type) {
static void CallFunctionForLayer(LayerType* layer, const Function& function) {
function(layer);

LayerType* mask_layer = layer->mask_layer();
if ((type & CallFunctionLayerType::MASK_LAYER) && mask_layer)
if (LayerType* mask_layer = layer->mask_layer())
function(mask_layer);
LayerType* replica_layer = layer->replica_layer();
if ((type & CallFunctionLayerType::REPLICA_LAYER) && replica_layer) {
if (LayerType* replica_layer = layer->replica_layer()) {
function(replica_layer);
mask_layer = replica_layer->mask_layer();
if ((type & CallFunctionLayerType::MASK_LAYER) && mask_layer)
if (LayerType* mask_layer = replica_layer->mask_layer())
function(mask_layer);
}
}

template <typename Function>
static void CallFunctionForEveryLayerInternal(
Layer* layer,
const Function& function,
const CallFunctionLayerType& type) {
CallFunctionForLayer(layer, function, type);

for (size_t i = 0; i < layer->children().size(); ++i) {
CallFunctionForEveryLayerInternal(layer->children()[i].get(), function,
type);
}
}

template <typename Function>
void LayerTreeHostCommon::CallFunctionForEveryLayer(
LayerTreeHost* host,
const Function& function,
const CallFunctionLayerType& type) {
CallFunctionForEveryLayerInternal(host->root_layer(), function, type);
void LayerTreeHostCommon::CallFunctionForEveryLayer(LayerTreeHost* host,
const Function& function) {
for (auto* layer : *host)
CallFunctionForLayer(layer, function);
}

template <typename Function>
void LayerTreeHostCommon::CallFunctionForEveryLayer(
LayerTreeImpl* host_impl,
const Function& function,
const CallFunctionLayerType& type) {
void LayerTreeHostCommon::CallFunctionForEveryLayer(LayerTreeImpl* host_impl,
const Function& function) {
for (auto* layer : *host_impl)
CallFunctionForLayer(layer, function, type);
CallFunctionForLayer(layer, function);
}

CC_EXPORT PropertyTrees* GetPropertyTrees(Layer* layer);
Expand Down
6 changes: 2 additions & 4 deletions cc/trees/layer_tree_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1628,12 +1628,10 @@ void LayerTreeHostImpl::DrawLayers(FrameData* frame) {
if (is_new_trace) {
if (pending_tree_) {
LayerTreeHostCommon::CallFunctionForEveryLayer(
pending_tree(), [](LayerImpl* layer) { layer->DidBeginTracing(); },
CallFunctionLayerType::ALL_LAYERS);
pending_tree(), [](LayerImpl* layer) { layer->DidBeginTracing(); });
}
LayerTreeHostCommon::CallFunctionForEveryLayer(
active_tree(), [](LayerImpl* layer) { layer->DidBeginTracing(); },
CallFunctionLayerType::ALL_LAYERS);
active_tree(), [](LayerImpl* layer) { layer->DidBeginTracing(); });
}

{
Expand Down
6 changes: 2 additions & 4 deletions cc/trees/layer_tree_host_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6226,16 +6226,14 @@ class LayerTreeTestPageScaleFlags : public LayerTreeTest {

void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
LayerTreeHostCommon::CallFunctionForEveryLayer(
host_impl->sync_tree(),
[this](LayerImpl* layer) {
host_impl->sync_tree(), [this](LayerImpl* layer) {
const std::vector<int>& list =
layer->IsAffectedByPageScale()
? this->affected_by_page_scale_
: this->not_affected_by_page_scale_;
EXPECT_TRUE(std::find(list.begin(), list.end(), layer->id()) !=
list.end());
},
CallFunctionLayerType::ALL_LAYERS);
});

EndTest();
}
Expand Down
12 changes: 4 additions & 8 deletions cc/trees/layer_tree_host_unittest_serialization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ class LayerTreeHostSerializationTest : public testing::Test {

void VerifyHostHasAllExpectedLayersInTree(Layer* root_layer) {
LayerTreeHostCommon::CallFunctionForEveryLayer(
root_layer->layer_tree_host(),
[root_layer](Layer* layer) {
root_layer->layer_tree_host(), [root_layer](Layer* layer) {
DCHECK(layer->layer_tree_host());
EXPECT_EQ(layer, layer->layer_tree_host()->LayerById(layer->id()));
},
CallFunctionLayerType::ALL_LAYERS);
});
}

void VerifySerializationAndDeserialization() {
Expand Down Expand Up @@ -174,11 +172,9 @@ class LayerTreeHostSerializationTest : public testing::Test {
if (layer_tree_host_dst_->property_trees_.sequence_number) {
int seq_num = layer_tree_host_dst_->property_trees_.sequence_number;
LayerTreeHostCommon::CallFunctionForEveryLayer(
layer_tree_host_dst_.get(),
[seq_num](Layer* layer) {
layer_tree_host_dst_.get(), [seq_num](Layer* layer) {
EXPECT_EQ(seq_num, layer->property_tree_sequence_number());
},
CallFunctionLayerType::ALL_LAYERS);
});
}
}

Expand Down
18 changes: 6 additions & 12 deletions cc/trees/layer_tree_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,14 @@ void LayerTreeImpl::Shutdown() {
void LayerTreeImpl::ReleaseResources() {
if (root_layer_) {
LayerTreeHostCommon::CallFunctionForEveryLayer(
this, [](LayerImpl* layer) { layer->ReleaseResources(); },
CallFunctionLayerType::ALL_LAYERS);
this, [](LayerImpl* layer) { layer->ReleaseResources(); });
}
}

void LayerTreeImpl::RecreateResources() {
if (root_layer_) {
LayerTreeHostCommon::CallFunctionForEveryLayer(
this, [](LayerImpl* layer) { layer->RecreateResources(); },
CallFunctionLayerType::ALL_LAYERS);
this, [](LayerImpl* layer) { layer->RecreateResources(); });
}
}

Expand Down Expand Up @@ -555,12 +553,9 @@ void LayerTreeImpl::UpdatePropertyTreeScrollingAndAnimationFromMainThread() {
// frame to a newly-committed property tree.
if (!root_layer())
return;
LayerTreeHostCommon::CallFunctionForEveryLayer(
this,
[](LayerImpl* layer) {
layer->UpdatePropertyTreeForScrollingAndAnimationIfNeeded();
},
CallFunctionLayerType::ALL_LAYERS);
LayerTreeHostCommon::CallFunctionForEveryLayer(this, [](LayerImpl* layer) {
layer->UpdatePropertyTreeForScrollingAndAnimationIfNeeded();
});
}

void LayerTreeImpl::SetPageScaleOnActiveTree(float active_page_scale) {
Expand Down Expand Up @@ -1073,8 +1068,7 @@ void LayerTreeImpl::DidBecomeActive() {

if (root_layer()) {
LayerTreeHostCommon::CallFunctionForEveryLayer(
this, [](LayerImpl* layer) { layer->DidBecomeActive(); },
CallFunctionLayerType::ALL_LAYERS);
this, [](LayerImpl* layer) { layer->DidBecomeActive(); });
}

for (const auto& swap_promise : swap_promise_list_)
Expand Down

0 comments on commit 8591041

Please sign in to comment.