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

Unified Diff: cc/trees/layer_tree_host.cc

Issue 2159513003: Setup LayerTree class, refactor 2 functions from LayerTreeHost to it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove external access to layer_id_map_ in LayerTree. Created 4 years, 5 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 cd025356975a3d31838bd9bf74d581cd7f189f1b..6ec3714b72d2978eac89923935fa22a16d50f3ac 100644
--- a/cc/trees/layer_tree_host.cc
+++ b/cc/trees/layer_tree_host.cc
@@ -44,6 +44,7 @@
#include "cc/layers/layer_proto_converter.h"
#include "cc/layers/painted_scrollbar_layer.h"
#include "cc/proto/gfx_conversions.h"
+#include "cc/proto/layer_tree.pb.h"
#include "cc/proto/layer_tree_host.pb.h"
#include "cc/resources/ui_resource_request.h"
#include "cc/scheduler/begin_frame_source.h"
@@ -69,20 +70,19 @@ namespace {
Layer* UpdateAndGetLayer(Layer* current_layer,
int layer_id,
- const std::unordered_map<int, Layer*>& layer_id_map) {
+ LayerTree* layer_tree) {
if (layer_id == Layer::INVALID_ID) {
if (current_layer)
current_layer->SetLayerTreeHost(nullptr);
return nullptr;
}
-
- auto layer_it = layer_id_map.find(layer_id);
- DCHECK(layer_it != layer_id_map.end());
- if (current_layer && current_layer != layer_it->second)
+ Layer* layer = layer_tree->LayerById(layer_id);
+ DCHECK(layer);
+ if (current_layer && current_layer != layer)
current_layer->SetLayerTreeHost(nullptr);
- return layer_it->second;
+ return layer;
}
std::unique_ptr<base::trace_event::TracedValue>
@@ -241,9 +241,7 @@ LayerTreeHost::LayerTreeHost(InitParams* params, CompositorMode mode)
has_transparent_background_(false),
have_scroll_event_handlers_(false),
event_listener_properties_(),
- animation_host_(std::move(params->animation_host)),
did_complete_scale_animation_(false),
- in_paint_layer_contents_(false),
id_(s_layer_tree_host_sequence_number.GetNext() + 1),
next_commit_forces_redraw_(false),
shared_bitmap_manager_(params->shared_bitmap_manager),
@@ -251,11 +249,11 @@ LayerTreeHost::LayerTreeHost(InitParams* params, CompositorMode mode)
task_graph_runner_(params->task_graph_runner),
image_serialization_processor_(params->image_serialization_processor),
surface_client_id_(0u),
- next_surface_sequence_(1u) {
+ next_surface_sequence_(1u),
+ layer_tree_(&(params->animation_host)) {
Khushal 2016/07/20 00:46:51 You don't need to pass a reference to the unique_p
xingliu 2016/07/20 20:33:06 Done, maybe release() and pass raw pointer to Laye
Khushal 2016/07/20 21:29:48 Use unique pointers if you're passing ownership, i
DCHECK(task_graph_runner_);
- DCHECK(animation_host_);
- animation_host_->SetMutatorHostClient(this);
+ layer_tree_.animation_host()->SetMutatorHostClient(this);
rendering_stats_instrumentation_->set_record_rendering_stats(
debug_state_.RecordRenderingStats());
@@ -366,13 +364,14 @@ void LayerTreeHost::InitializeProxy(
proxy_ = std::move(proxy);
proxy_->Start(std::move(external_begin_frame_source));
- animation_host_->SetSupportsScrollAnimations(proxy_->SupportsImplScrolling());
+ GetLayerTree()->animation_host()->SetSupportsScrollAnimations(
+ proxy_->SupportsImplScrolling());
}
LayerTreeHost::~LayerTreeHost() {
TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost");
- animation_host_->SetMutatorHostClient(nullptr);
+ GetLayerTree()->animation_host()->SetMutatorHostClient(nullptr);
if (root_layer_.get())
root_layer_->SetLayerTreeHost(NULL);
@@ -550,7 +549,7 @@ void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) {
{
TRACE_EVENT0("cc", "LayerTreeHost::PushProperties");
- TreeSynchronizer::PushLayerProperties(this, sync_tree);
+ TreeSynchronizer::PushLayerProperties(GetLayerTree(), sync_tree);
// This must happen after synchronizing property trees and after push
// properties, which updates property tree indices, but before animation
@@ -561,7 +560,8 @@ void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) {
TRACE_EVENT0("cc", "LayerTreeHost::AnimationHost::PushProperties");
DCHECK(host_impl->animation_host());
- animation_host_->PushPropertiesTo(host_impl->animation_host());
+ GetLayerTree()->animation_host()->PushPropertiesTo(
+ host_impl->animation_host());
}
// This must happen after synchronizing property trees and after pushing
@@ -648,7 +648,8 @@ std::unique_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl(
const bool supports_impl_scrolling = task_runner_provider_->HasImplThread();
std::unique_ptr<AnimationHost> animation_host_impl =
- animation_host_->CreateImplInstance(supports_impl_scrolling);
+ GetLayerTree()->animation_host()->CreateImplInstance(
+ supports_impl_scrolling);
std::unique_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create(
settings_, client, task_runner_provider_.get(),
@@ -753,7 +754,7 @@ void LayerTreeHost::SetNextCommitForcesRedraw() {
void LayerTreeHost::SetAnimationEvents(
std::unique_ptr<AnimationEvents> events) {
DCHECK(task_runner_provider_->IsMainThread());
- animation_host_->SetAnimationEvents(std::move(events));
+ GetLayerTree()->animation_host()->SetAnimationEvents(std::move(events));
}
void LayerTreeHost::SetRootLayer(scoped_refptr<Layer> root_layer) {
@@ -1047,8 +1048,8 @@ bool LayerTreeHost::DoUpdateLayers(Layer* root_layer) {
for (const auto& layer : update_layer_list)
layer->SavePaintProperties();
-
- base::AutoReset<bool> painting(&in_paint_layer_contents_, true);
+ bool& in_paint_layer_contents = GetLayerTree()->get_in_paint_layer_contents();
Khushal 2016/07/20 00:46:51 I think we can have the iteration through the laye
xingliu 2016/07/20 20:33:06 Done.
+ base::AutoReset<bool> painting(&in_paint_layer_contents, true);
bool did_paint_content = false;
bool content_is_suitable_for_gpu = true;
for (const auto& layer : update_layer_list) {
@@ -1159,10 +1160,11 @@ void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints,
}
void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) {
- std::unique_ptr<AnimationEvents> events = animation_host_->CreateEvents();
+ AnimationHost* animation_host = GetLayerTree()->animation_host();
+ std::unique_ptr<AnimationEvents> events = animation_host->CreateEvents();
- if (animation_host_->AnimateLayers(monotonic_time))
- animation_host_->UpdateAnimationState(true, events.get());
+ if (animation_host->AnimateLayers(monotonic_time))
+ animation_host->UpdateAnimationState(true, events.get());
if (!events->events_.empty())
property_trees_.needs_rebuild = true;
@@ -1321,8 +1323,7 @@ void LayerTreeHost::SetLayerTreeMutator(
}
Layer* LayerTreeHost::LayerById(int id) const {
- LayerIdMap::const_iterator iter = layer_id_map_.find(id);
- return iter != layer_id_map_.end() ? iter->second : nullptr;
+ return GetLayerTree()->LayerById(id);
}
Layer* LayerTreeHost::LayerByElementId(ElementId element_id) const {
@@ -1344,42 +1345,9 @@ void LayerTreeHost::RemoveFromElementMap(Layer* layer) {
element_layers_map_.erase(layer->element_id());
}
-void LayerTreeHost::AddLayerShouldPushProperties(Layer* layer) {
- layers_that_should_push_properties_.insert(layer);
-}
-
-void LayerTreeHost::RemoveLayerShouldPushProperties(Layer* layer) {
- layers_that_should_push_properties_.erase(layer);
-}
-
-std::unordered_set<Layer*>& LayerTreeHost::LayersThatShouldPushProperties() {
- return layers_that_should_push_properties_;
-}
-
bool LayerTreeHost::LayerNeedsPushPropertiesForTesting(Layer* layer) {
Khushal 2016/07/20 00:46:51 Since we are moving all tracking for layers that a
xingliu 2016/07/20 20:33:06 Done.
- return layers_that_should_push_properties_.find(layer) !=
- layers_that_should_push_properties_.end();
-}
-
-void LayerTreeHost::RegisterLayer(Layer* layer) {
- DCHECK(!LayerById(layer->id()));
- DCHECK(!in_paint_layer_contents_);
- layer_id_map_[layer->id()] = layer;
- if (layer->element_id()) {
- animation_host_->RegisterElement(layer->element_id(),
- ElementListType::ACTIVE);
- }
-}
-
-void LayerTreeHost::UnregisterLayer(Layer* layer) {
- DCHECK(LayerById(layer->id()));
- DCHECK(!in_paint_layer_contents_);
- if (layer->element_id()) {
- animation_host_->UnregisterElement(layer->element_id(),
- ElementListType::ACTIVE);
- }
- RemoveLayerShouldPushProperties(layer);
- layer_id_map_.erase(layer->id());
+ const LayerSet& layers = GetLayerTree()->LayersThatShouldPushProperties();
+ return layers.find(layer) != layers.end();
}
bool LayerTreeHost::IsElementInList(ElementId element_id,
@@ -1538,11 +1506,11 @@ void LayerTreeHost::ToProtobufForCommit(
LayerProtoConverter::SerializeLayerHierarchy(root_layer_,
proto->mutable_root_layer());
- // layers_that_should_push_properties_ should be serialized before layer
- // properties because it is cleared during the properties serialization.
- for (auto layer : layers_that_should_push_properties_)
- proto->add_layers_that_should_push_properties(layer->id());
+ // Serialize LayerTree before LayerTree.layers_that_should_push_properties_
+ // is cleared.
+ GetLayerTree()->ToProtobuf(proto->mutable_layer_tree());
+ // This will clear LayerTree.layers_that_should_push_properties_.
LayerProtoConverter::SerializeLayerProperties(this,
proto->mutable_layer_updates());
@@ -1577,7 +1545,6 @@ void LayerTreeHost::ToProtobufForCommit(
proto->set_touch_end_or_cancel_event_listener_properties(
static_cast<uint32_t>(
event_listener_properties(EventListenerClass::kTouchEndOrCancel)));
- proto->set_in_paint_layer_contents(in_paint_layer_contents_);
proto->set_id(id_);
proto->set_next_commit_forces_redraw(next_commit_forces_redraw_);
@@ -1608,7 +1575,7 @@ void LayerTreeHost::ToProtobufForCommit(
void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) {
DCHECK(client_picture_cache_);
-
+ LayerTree* layer_tree = GetLayerTree();
needs_full_tree_sync_ = proto.needs_full_tree_sync();
needs_meta_info_recomputation_ = proto.needs_meta_info_recomputation();
source_frame_number_ = proto.source_frame_number();
@@ -1621,8 +1588,7 @@ void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) {
root_layer_ = new_root_layer;
}
- for (auto layer_id : proto.layers_that_should_push_properties())
- layers_that_should_push_properties_.insert(layer_id_map_[layer_id]);
+ layer_tree->FromProtobuf(proto.layer_tree());
// Ensure ClientPictureCache contains all the necessary SkPictures before
// deserializing the properties.
@@ -1666,23 +1632,22 @@ void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) {
EventListenerClass::kTouchEndOrCancel)] =
static_cast<EventListenerProperties>(
proto.touch_end_or_cancel_event_listener_properties());
- in_paint_layer_contents_ = proto.in_paint_layer_contents();
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_id_map_));
+ UpdateAndGetLayer(hud_layer_.get(), proto.hud_layer_id(), layer_tree));
overscroll_elasticity_layer_ =
UpdateAndGetLayer(overscroll_elasticity_layer_.get(),
- proto.overscroll_elasticity_layer_id(), layer_id_map_);
+ proto.overscroll_elasticity_layer_id(), layer_tree);
page_scale_layer_ = UpdateAndGetLayer(
- page_scale_layer_.get(), proto.page_scale_layer_id(), layer_id_map_);
+ 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_id_map_);
+ 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_id_map_);
+ proto.outer_viewport_scroll_layer_id(), layer_tree);
LayerSelectionFromProtobuf(&selection_, proto.selection());
@@ -1704,4 +1669,8 @@ void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) {
next_surface_sequence_ = proto.next_surface_sequence();
}
+AnimationHost* LayerTreeHost::animation_host() const {
+ return GetLayerTree()->animation_host();
+}
+
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698