Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: cc/trees/layer_tree_host.cc

Issue 2216203002: Refactor MutatorHostClient from LayerTreeHost to LayerTree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix call site in cc_perftest. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/trees/layer_tree_host.cc
diff --git a/cc/trees/layer_tree_host.cc b/cc/trees/layer_tree_host.cc
index 2ec46969f214e11d317dcb599b3eb20323d7c971..4427185f14d9b219e5567ceece9e76f1f3e8acbf 100644
--- a/cc/trees/layer_tree_host.cc
+++ b/cc/trees/layer_tree_host.cc
@@ -248,11 +248,10 @@ LayerTreeHost::LayerTreeHost(InitParams* params, CompositorMode mode)
image_serialization_processor_(params->image_serialization_processor),
surface_client_id_(0u),
next_surface_sequence_(1u),
- layer_tree_(std::move(params->animation_host)) {
+ layer_tree_(base::WrapUnique(
+ new LayerTree(std::move(params->animation_host), this))) {
DCHECK(task_graph_runner_);
- layer_tree_.animation_host()->SetMutatorHostClient(this);
-
rendering_stats_instrumentation_->set_record_rendering_stats(
debug_state_.RecordRenderingStats());
}
@@ -362,15 +361,13 @@ void LayerTreeHost::InitializeProxy(
proxy_ = std::move(proxy);
proxy_->Start(std::move(external_begin_frame_source));
- layer_tree_.animation_host()->SetSupportsScrollAnimations(
+ layer_tree_->animation_host()->SetSupportsScrollAnimations(
proxy_->SupportsImplScrolling());
}
LayerTreeHost::~LayerTreeHost() {
TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost");
- layer_tree_.animation_host()->SetMutatorHostClient(nullptr);
-
if (root_layer_.get())
root_layer_->SetLayerTreeHost(NULL);
@@ -438,7 +435,7 @@ void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) {
frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() &&
root_layer()) {
LayerTreeHostCommon::CallFunctionForEveryLayer(
- this, [](Layer* layer) { layer->DidBeginTracing(); });
+ layer_tree_.get(), [](Layer* layer) { layer->DidBeginTracing(); });
}
LayerTreeImpl* sync_tree = host_impl->sync_tree();
@@ -547,7 +544,7 @@ void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) {
{
TRACE_EVENT0("cc", "LayerTreeHost::PushProperties");
- TreeSynchronizer::PushLayerProperties(&layer_tree_, sync_tree);
+ TreeSynchronizer::PushLayerProperties(layer_tree_.get(), sync_tree);
// This must happen after synchronizing property trees and after push
// properties, which updates property tree indices, but before animation
@@ -558,7 +555,8 @@ void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) {
TRACE_EVENT0("cc", "LayerTreeHost::AnimationHost::PushProperties");
DCHECK(host_impl->animation_host());
- layer_tree_.animation_host()->PushPropertiesTo(host_impl->animation_host());
+ layer_tree_->animation_host()->PushPropertiesTo(
+ host_impl->animation_host());
}
// This must happen after synchronizing property trees and after pushing
@@ -645,7 +643,8 @@ std::unique_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl(
const bool supports_impl_scrolling = task_runner_provider_->HasImplThread();
std::unique_ptr<AnimationHost> animation_host_impl =
- layer_tree_.animation_host()->CreateImplInstance(supports_impl_scrolling);
+ layer_tree_->animation_host()->CreateImplInstance(
+ supports_impl_scrolling);
std::unique_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create(
settings_, client, task_runner_provider_.get(),
@@ -682,7 +681,7 @@ void LayerTreeHost::SetDeferCommits(bool defer_commits) {
}
void LayerTreeHost::SetNeedsDisplayOnAllLayers() {
Khushal 2016/08/15 17:46:39 This method can move to the LayerTree as well.
xingliu 2016/08/15 21:29:13 Done.
- for (auto* layer : *this)
+ for (auto* layer : *layer_tree_)
layer->SetNeedsDisplay();
}
@@ -750,7 +749,7 @@ void LayerTreeHost::SetNextCommitForcesRedraw() {
void LayerTreeHost::SetAnimationEvents(
std::unique_ptr<AnimationEvents> events) {
DCHECK(task_runner_provider_->IsMainThread());
- layer_tree_.animation_host()->SetAnimationEvents(std::move(events));
+ layer_tree_->animation_host()->SetAnimationEvents(std::move(events));
}
void LayerTreeHost::SetRootLayer(scoped_refptr<Layer> root_layer) {
@@ -920,22 +919,6 @@ bool LayerTreeHost::UpdateLayers() {
return result || next_commit_forces_redraw_;
}
-LayerListIterator<Layer> LayerTreeHost::begin() const {
- return LayerListIterator<Layer>(root_layer_.get());
-}
-
-LayerListIterator<Layer> LayerTreeHost::end() const {
- return LayerListIterator<Layer>(nullptr);
-}
-
-LayerListReverseIterator<Layer> LayerTreeHost::rbegin() {
- return LayerListReverseIterator<Layer>(root_layer_.get());
-}
-
-LayerListReverseIterator<Layer> LayerTreeHost::rend() {
- return LayerListReverseIterator<Layer>(nullptr);
-}
-
void LayerTreeHost::DidCompletePageScaleAnimation() {
did_complete_scale_animation_ = true;
}
@@ -982,7 +965,8 @@ static void SetElementIdForTesting(Layer* layer) {
}
void LayerTreeHost::SetElementIdsForTesting() {
Khushal 2016/08/15 17:46:39 Can move this to the LayerTree.
xingliu 2016/08/15 21:29:13 Done.
- LayerTreeHostCommon::CallFunctionForEveryLayer(this, SetElementIdForTesting);
+ LayerTreeHostCommon::CallFunctionForEveryLayer(layer_tree_.get(),
+ SetElementIdForTesting);
}
bool LayerTreeHost::UsingSharedMemoryResources() {
@@ -1046,8 +1030,8 @@ bool LayerTreeHost::DoUpdateLayers(Layer* root_layer) {
layer->SavePaintProperties();
bool content_is_suitable_for_gpu = true;
- bool did_paint_content =
- layer_tree_.UpdateLayers(update_layer_list, &content_is_suitable_for_gpu);
+ bool did_paint_content = layer_tree_->UpdateLayers(
+ update_layer_list, &content_is_suitable_for_gpu);
if (content_is_suitable_for_gpu) {
++num_consecutive_frames_suitable_for_gpu_;
@@ -1104,7 +1088,7 @@ void LayerTreeHost::ApplyScrollAndScale(ScrollAndScaleSet* info) {
if (root_layer_.get()) {
for (size_t i = 0; i < info->scrolls.size(); ++i) {
- Layer* layer = LayerById(info->scrolls[i].layer_id);
+ Layer* layer = layer_tree_->LayerById(info->scrolls[i].layer_id);
if (!layer)
continue;
layer->SetScrollOffsetFromImplSide(gfx::ScrollOffsetWithDelta(
@@ -1146,7 +1130,7 @@ void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints,
}
void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) {
- AnimationHost* animation_host = layer_tree_.animation_host();
+ AnimationHost* animation_host = layer_tree_->animation_host();
std::unique_ptr<AnimationEvents> events = animation_host->CreateEvents();
if (animation_host->AnimateLayers(monotonic_time))
@@ -1308,149 +1292,6 @@ void LayerTreeHost::SetLayerTreeMutator(
proxy_->SetMutator(std::move(mutator));
}
-Layer* LayerTreeHost::LayerById(int id) const {
- return layer_tree_.LayerById(id);
-}
-
-Layer* LayerTreeHost::LayerByElementId(ElementId element_id) const {
- ElementLayersMap::const_iterator iter = element_layers_map_.find(element_id);
- return iter != element_layers_map_.end() ? iter->second : nullptr;
-}
-
-void LayerTreeHost::AddToElementMap(Layer* layer) {
- if (!layer->element_id())
- return;
-
- element_layers_map_[layer->element_id()] = layer;
-}
-
-void LayerTreeHost::RemoveFromElementMap(Layer* layer) {
- if (!layer->element_id())
- return;
-
- element_layers_map_.erase(layer->element_id());
-}
-
-bool LayerTreeHost::IsElementInList(ElementId element_id,
- ElementListType list_type) const {
- return list_type == ElementListType::ACTIVE && LayerByElementId(element_id);
-}
-
-void LayerTreeHost::SetMutatorsNeedCommit() {
- SetNeedsCommit();
-}
-
-void LayerTreeHost::SetMutatorsNeedRebuildPropertyTrees() {
- property_trees_.needs_rebuild = true;
-}
-
-void LayerTreeHost::SetElementFilterMutated(ElementId element_id,
- ElementListType list_type,
- const FilterOperations& filters) {
- Layer* layer = LayerByElementId(element_id);
- DCHECK(layer);
- layer->OnFilterAnimated(filters);
-}
-
-void LayerTreeHost::SetElementOpacityMutated(ElementId element_id,
- ElementListType list_type,
- float opacity) {
- Layer* layer = LayerByElementId(element_id);
- DCHECK(layer);
- layer->OnOpacityAnimated(opacity);
-}
-
-void LayerTreeHost::SetElementTransformMutated(
- ElementId element_id,
- ElementListType list_type,
- const gfx::Transform& transform) {
- Layer* layer = LayerByElementId(element_id);
- DCHECK(layer);
- layer->OnTransformAnimated(transform);
-}
-
-void LayerTreeHost::SetElementScrollOffsetMutated(
- ElementId element_id,
- ElementListType list_type,
- const gfx::ScrollOffset& scroll_offset) {
- Layer* layer = LayerByElementId(element_id);
- DCHECK(layer);
- layer->OnScrollOffsetAnimated(scroll_offset);
-}
-
-void LayerTreeHost::ElementTransformIsAnimatingChanged(
- ElementId element_id,
- ElementListType list_type,
- AnimationChangeType change_type,
- bool is_animating) {
- Layer* layer = LayerByElementId(element_id);
- if (layer) {
- switch (change_type) {
- case AnimationChangeType::POTENTIAL:
- layer->OnTransformIsPotentiallyAnimatingChanged(is_animating);
- break;
- case AnimationChangeType::RUNNING:
- layer->OnTransformIsCurrentlyAnimatingChanged(is_animating);
- break;
- case AnimationChangeType::BOTH:
- layer->OnTransformIsPotentiallyAnimatingChanged(is_animating);
- layer->OnTransformIsCurrentlyAnimatingChanged(is_animating);
- break;
- }
- }
-}
-
-void LayerTreeHost::ElementOpacityIsAnimatingChanged(
- ElementId element_id,
- ElementListType list_type,
- AnimationChangeType change_type,
- bool is_animating) {
- Layer* layer = LayerByElementId(element_id);
- if (layer) {
- switch (change_type) {
- case AnimationChangeType::POTENTIAL:
- layer->OnOpacityIsPotentiallyAnimatingChanged(is_animating);
- break;
- case AnimationChangeType::RUNNING:
- layer->OnOpacityIsCurrentlyAnimatingChanged(is_animating);
- break;
- case AnimationChangeType::BOTH:
- layer->OnOpacityIsPotentiallyAnimatingChanged(is_animating);
- layer->OnOpacityIsCurrentlyAnimatingChanged(is_animating);
- break;
- }
- }
-}
-
-void LayerTreeHost::ElementFilterIsAnimatingChanged(
- ElementId element_id,
- ElementListType list_type,
- AnimationChangeType change_type,
- bool is_animating) {
- Layer* layer = LayerByElementId(element_id);
- if (layer) {
- switch (change_type) {
- case AnimationChangeType::POTENTIAL:
- layer->OnFilterIsPotentiallyAnimatingChanged(is_animating);
- break;
- case AnimationChangeType::RUNNING:
- layer->OnFilterIsCurrentlyAnimatingChanged(is_animating);
- break;
- case AnimationChangeType::BOTH:
- layer->OnFilterIsPotentiallyAnimatingChanged(is_animating);
- layer->OnFilterIsCurrentlyAnimatingChanged(is_animating);
- break;
- }
- }
-}
-
-gfx::ScrollOffset LayerTreeHost::GetScrollOffsetForAnimation(
- ElementId element_id) const {
- Layer* layer = LayerByElementId(element_id);
- DCHECK(layer);
- return layer->ScrollOffsetForAnimation();
-}
-
bool LayerTreeHost::IsSingleThreaded() const {
DCHECK(compositor_mode_ != CompositorMode::SINGLE_THREADED ||
!task_runner_provider_->HasImplThread());
@@ -1512,7 +1353,7 @@ void LayerTreeHost::ToProtobufForCommit(
// Serialize the LayerTree before serializing the properties. During layer
// property serialization, we clear the list |layer_that_should_properties_|
// from the LayerTree.
- layer_tree_.ToProtobuf(proto->mutable_layer_tree());
+ layer_tree_->ToProtobuf(proto->mutable_layer_tree());
LayerProtoConverter::SerializeLayerProperties(this,
proto->mutable_layer_updates());
@@ -1590,7 +1431,7 @@ void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) {
root_layer_ = new_root_layer;
}
- layer_tree_.FromProtobuf(proto.layer_tree());
+ layer_tree_->FromProtobuf(proto.layer_tree());
// Ensure ClientPictureCache contains all the necessary SkPictures before
// deserializing the properties.
@@ -1637,19 +1478,19 @@ void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) {
id_ = proto.id();
next_commit_forces_redraw_ = proto.next_commit_forces_redraw();
- hud_layer_ = static_cast<HeadsUpDisplayLayer*>(
- UpdateAndGetLayer(hud_layer_.get(), proto.hud_layer_id(), &layer_tree_));
- overscroll_elasticity_layer_ =
- UpdateAndGetLayer(overscroll_elasticity_layer_.get(),
- proto.overscroll_elasticity_layer_id(), &layer_tree_);
+ hud_layer_ = static_cast<HeadsUpDisplayLayer*>(UpdateAndGetLayer(
+ hud_layer_.get(), proto.hud_layer_id(), layer_tree_.get()));
+ overscroll_elasticity_layer_ = UpdateAndGetLayer(
+ overscroll_elasticity_layer_.get(),
+ proto.overscroll_elasticity_layer_id(), layer_tree_.get());
page_scale_layer_ = UpdateAndGetLayer(
- page_scale_layer_.get(), proto.page_scale_layer_id(), &layer_tree_);
- inner_viewport_scroll_layer_ =
- UpdateAndGetLayer(inner_viewport_scroll_layer_.get(),
- proto.inner_viewport_scroll_layer_id(), &layer_tree_);
- outer_viewport_scroll_layer_ =
- UpdateAndGetLayer(outer_viewport_scroll_layer_.get(),
- proto.outer_viewport_scroll_layer_id(), &layer_tree_);
+ page_scale_layer_.get(), proto.page_scale_layer_id(), layer_tree_.get());
+ inner_viewport_scroll_layer_ = UpdateAndGetLayer(
+ inner_viewport_scroll_layer_.get(),
+ proto.inner_viewport_scroll_layer_id(), layer_tree_.get());
+ outer_viewport_scroll_layer_ = UpdateAndGetLayer(
+ outer_viewport_scroll_layer_.get(),
+ proto.outer_viewport_scroll_layer_id(), layer_tree_.get());
LayerSelectionFromProtobuf(&selection_, proto.selection());
@@ -1663,16 +1504,12 @@ 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);
- });
+ LayerTreeHostCommon::CallFunctionForEveryLayer(
+ layer_tree_.get(), [seq_num](Layer* layer) {
+ layer->set_property_tree_sequence_number(seq_num);
+ });
surface_client_id_ = proto.surface_client_id();
next_surface_sequence_ = proto.next_surface_sequence();
}
-
-AnimationHost* LayerTreeHost::animation_host() const {
- return layer_tree_.animation_host();
-}
-
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698