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

Unified Diff: cc/trees/layer_tree.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: Layer GetLayerTree now directly uses LayerTree pointer. 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.cc
diff --git a/cc/trees/layer_tree.cc b/cc/trees/layer_tree.cc
new file mode 100644
index 0000000000000000000000000000000000000000..83537d052e7788d035c974f579a93bf0937ca6b9
--- /dev/null
+++ b/cc/trees/layer_tree.cc
@@ -0,0 +1,89 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/auto_reset.h"
+#include "cc/animation/animation_host.h"
+#include "cc/layers/layer.h"
+#include "cc/proto/layer_tree.pb.h"
+#include "cc/trees/layer_tree.h"
+
+namespace cc {
+
+LayerTree::LayerTree(std::unique_ptr<AnimationHost> animation_host)
+ : in_paint_layer_contents_(false),
+ animation_host_(std::move(animation_host)) {
+ DCHECK(animation_host_);
+}
+
+LayerTree::~LayerTree() {}
+
+void LayerTree::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 LayerTree::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());
+}
+
+Layer* LayerTree::LayerById(int id) const {
+ LayerIdMap::const_iterator iter = layer_id_map_.find(id);
+ return iter != layer_id_map_.end() ? iter->second : nullptr;
+}
+
+bool LayerTree::UpdateLayers(const LayerList& update_layer_list,
+ bool* content_is_suitable_for_gpu) {
+ base::AutoReset<bool> painting(&in_paint_layer_contents_, true);
+ bool did_paint_content = false;
+ for (const auto& layer : update_layer_list) {
+ did_paint_content |= layer->Update();
+ *content_is_suitable_for_gpu &= layer->IsSuitableForGpuRasterization();
+ }
+ return did_paint_content;
+}
+
+void LayerTree::AddLayerShouldPushProperties(Layer* layer) {
+ layers_that_should_push_properties_.insert(layer);
+}
+
+void LayerTree::RemoveLayerShouldPushProperties(Layer* layer) {
+ layers_that_should_push_properties_.erase(layer);
+}
+
+std::unordered_set<Layer*>& LayerTree::LayersThatShouldPushProperties() {
+ return layers_that_should_push_properties_;
+}
+
+bool LayerTree::LayerNeedsPushPropertiesForTesting(Layer* layer) const {
+ return layers_that_should_push_properties_.find(layer) !=
+ layers_that_should_push_properties_.end();
+}
+
+void LayerTree::ToProtobuf(proto::LayerTree* proto) {
+ for (auto* layer : layers_that_should_push_properties_) {
+ proto->add_layers_that_should_push_properties(layer->id());
+ }
+ proto->set_in_paint_layer_contents(in_paint_layer_contents());
+}
+
+void LayerTree::FromProtobuf(const proto::LayerTree& proto) {
+ for (auto layer_id : proto.layers_that_should_push_properties()) {
+ AddLayerShouldPushProperties(layer_id_map_[layer_id]);
+ }
+ in_paint_layer_contents_ = proto.in_paint_layer_contents();
+}
+
+} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698