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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/auto_reset.h"
6 #include "cc/animation/animation_host.h"
7 #include "cc/layers/layer.h"
8 #include "cc/proto/layer_tree.pb.h"
9 #include "cc/trees/layer_tree.h"
10
11 namespace cc {
12
13 LayerTree::LayerTree(std::unique_ptr<AnimationHost> animation_host)
14 : in_paint_layer_contents_(false),
15 animation_host_(std::move(animation_host)) {
16 DCHECK(animation_host_);
17 }
18
19 LayerTree::~LayerTree() {}
20
21 void LayerTree::RegisterLayer(Layer* layer) {
22 DCHECK(!LayerById(layer->id()));
23 DCHECK(!in_paint_layer_contents_);
24 layer_id_map_[layer->id()] = layer;
25 if (layer->element_id()) {
26 animation_host_->RegisterElement(layer->element_id(),
27 ElementListType::ACTIVE);
28 }
29 }
30
31 void LayerTree::UnregisterLayer(Layer* layer) {
32 DCHECK(LayerById(layer->id()));
33 DCHECK(!in_paint_layer_contents_);
34 if (layer->element_id()) {
35 animation_host_->UnregisterElement(layer->element_id(),
36 ElementListType::ACTIVE);
37 }
38 RemoveLayerShouldPushProperties(layer);
39 layer_id_map_.erase(layer->id());
40 }
41
42 Layer* LayerTree::LayerById(int id) const {
43 LayerIdMap::const_iterator iter = layer_id_map_.find(id);
44 return iter != layer_id_map_.end() ? iter->second : nullptr;
45 }
46
47 bool LayerTree::UpdateLayers(const LayerList& update_layer_list,
48 bool* content_is_suitable_for_gpu) {
49 base::AutoReset<bool> painting(&in_paint_layer_contents_, true);
50 bool did_paint_content = false;
51 for (const auto& layer : update_layer_list) {
52 did_paint_content |= layer->Update();
53 *content_is_suitable_for_gpu &= layer->IsSuitableForGpuRasterization();
54 }
55 return did_paint_content;
56 }
57
58 void LayerTree::AddLayerShouldPushProperties(Layer* layer) {
59 layers_that_should_push_properties_.insert(layer);
60 }
61
62 void LayerTree::RemoveLayerShouldPushProperties(Layer* layer) {
63 layers_that_should_push_properties_.erase(layer);
64 }
65
66 std::unordered_set<Layer*>& LayerTree::LayersThatShouldPushProperties() {
67 return layers_that_should_push_properties_;
68 }
69
70 bool LayerTree::LayerNeedsPushPropertiesForTesting(Layer* layer) const {
71 return layers_that_should_push_properties_.find(layer) !=
72 layers_that_should_push_properties_.end();
73 }
74
75 void LayerTree::ToProtobuf(proto::LayerTree* proto) {
76 for (auto* layer : layers_that_should_push_properties_) {
77 proto->add_layers_that_should_push_properties(layer->id());
78 }
79 proto->set_in_paint_layer_contents(in_paint_layer_contents());
80 }
81
82 void LayerTree::FromProtobuf(const proto::LayerTree& proto) {
83 for (auto layer_id : proto.layers_that_should_push_properties()) {
84 AddLayerShouldPushProperties(layer_id_map_[layer_id]);
85 }
86 in_paint_layer_contents_ = proto.in_paint_layer_contents();
87 }
88
89 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698