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

Side by Side Diff: cc/layers/layer.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: add proto to gyp file and modify inproper comment. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2010 The Chromium Authors. All rights reserved. 1 // Copyright 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/layers/layer.h" 5 #include "cc/layers/layer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } 122 }
123 } 123 }
124 124
125 void Layer::SetLayerTreeHost(LayerTreeHost* host) { 125 void Layer::SetLayerTreeHost(LayerTreeHost* host) {
126 if (layer_tree_host_ == host) 126 if (layer_tree_host_ == host)
127 return; 127 return;
128 128
129 if (layer_tree_host_) { 129 if (layer_tree_host_) {
130 layer_tree_host_->property_trees()->RemoveIdFromIdToIndexMaps(id()); 130 layer_tree_host_->property_trees()->RemoveIdFromIdToIndexMaps(id());
131 layer_tree_host_->property_trees()->needs_rebuild = true; 131 layer_tree_host_->property_trees()->needs_rebuild = true;
132 layer_tree_host_->UnregisterLayer(this); 132 GetLayerTree()->UnregisterLayer(this);
133 if (inputs_.element_id) { 133 if (inputs_.element_id) {
134 layer_tree_host_->animation_host()->UnregisterElement( 134 layer_tree_host_->animation_host()->UnregisterElement(
135 inputs_.element_id, ElementListType::ACTIVE); 135 inputs_.element_id, ElementListType::ACTIVE);
136 layer_tree_host_->RemoveFromElementMap(this); 136 layer_tree_host_->RemoveFromElementMap(this);
137 } 137 }
138 } 138 }
139 if (host) { 139 if (host) {
140 host->property_trees()->needs_rebuild = true; 140 host->property_trees()->needs_rebuild = true;
141 host->RegisterLayer(this); 141 host->GetLayerTree()->RegisterLayer(this);
142 if (inputs_.element_id) { 142 if (inputs_.element_id) {
143 host->AddToElementMap(this); 143 host->AddToElementMap(this);
144 host->animation_host()->RegisterElement(inputs_.element_id, 144 host->animation_host()->RegisterElement(inputs_.element_id,
145 ElementListType::ACTIVE); 145 ElementListType::ACTIVE);
146 } 146 }
147 } 147 }
148 148
149 layer_tree_host_ = host; 149 layer_tree_host_ = host;
150 InvalidatePropertyTreesIndices(); 150 InvalidatePropertyTreesIndices();
151 151
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 207 }
208 208
209 void Layer::SetNextCommitWaitsForActivation() { 209 void Layer::SetNextCommitWaitsForActivation() {
210 if (!layer_tree_host_) 210 if (!layer_tree_host_)
211 return; 211 return;
212 212
213 layer_tree_host_->SetNextCommitWaitsForActivation(); 213 layer_tree_host_->SetNextCommitWaitsForActivation();
214 } 214 }
215 215
216 void Layer::SetNeedsPushProperties() { 216 void Layer::SetNeedsPushProperties() {
217 if (layer_tree_host_) 217 if (layer_tree_host_)
vmpstr 2016/07/27 18:05:30 if (GetLayerTree()) here and throughout
218 layer_tree_host_->AddLayerShouldPushProperties(this); 218 GetLayerTree()->AddLayerShouldPushProperties(this);
219 } 219 }
220 220
221 void Layer::ResetNeedsPushPropertiesForTesting() { 221 void Layer::ResetNeedsPushPropertiesForTesting() {
222 layer_tree_host_->RemoveLayerShouldPushProperties(this); 222 GetLayerTree()->RemoveLayerShouldPushProperties(this);
223 } 223 }
224 224
225 bool Layer::IsPropertyChangeAllowed() const { 225 bool Layer::IsPropertyChangeAllowed() const {
226 if (!layer_tree_host_) 226 if (!layer_tree_host_)
227 return true; 227 return true;
228 228
229 return !layer_tree_host_->in_paint_layer_contents(); 229 return !GetLayerTree()->in_paint_layer_contents();
230 } 230 }
231 231
232 sk_sp<SkPicture> Layer::GetPicture() const { 232 sk_sp<SkPicture> Layer::GetPicture() const {
233 return nullptr; 233 return nullptr;
234 } 234 }
235 235
236 void Layer::SetParent(Layer* layer) { 236 void Layer::SetParent(Layer* layer) {
237 DCHECK(!layer || !layer->HasAncestor(this)); 237 DCHECK(!layer || !layer->HasAncestor(this));
238 238
239 parent_ = layer; 239 parent_ = layer;
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 layer->SetUpdateRect(inputs_.update_rect); 1188 layer->SetUpdateRect(inputs_.update_rect);
1189 1189
1190 layer->SetHasWillChangeTransformHint(has_will_change_transform_hint()); 1190 layer->SetHasWillChangeTransformHint(has_will_change_transform_hint());
1191 layer->SetNeedsPushProperties(); 1191 layer->SetNeedsPushProperties();
1192 1192
1193 // Reset any state that should be cleared for the next update. 1193 // Reset any state that should be cleared for the next update.
1194 subtree_property_changed_ = false; 1194 subtree_property_changed_ = false;
1195 layer_property_changed_ = false; 1195 layer_property_changed_ = false;
1196 inputs_.update_rect = gfx::Rect(); 1196 inputs_.update_rect = gfx::Rect();
1197 1197
1198 layer_tree_host()->RemoveLayerShouldPushProperties(this); 1198 GetLayerTree()->RemoveLayerShouldPushProperties(this);
1199 } 1199 }
1200 1200
1201 void Layer::TakeCopyRequests( 1201 void Layer::TakeCopyRequests(
1202 std::vector<std::unique_ptr<CopyOutputRequest>>* requests) { 1202 std::vector<std::unique_ptr<CopyOutputRequest>>* requests) {
1203 for (auto& it : inputs_.copy_requests) { 1203 for (auto& it : inputs_.copy_requests) {
1204 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner = 1204 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner =
1205 layer_tree_host()->task_runner_provider()->MainThreadTaskRunner(); 1205 layer_tree_host()->task_runner_provider()->MainThreadTaskRunner();
1206 std::unique_ptr<CopyOutputRequest> original_request = std::move(it); 1206 std::unique_ptr<CopyOutputRequest> original_request = std::move(it);
1207 const CopyOutputRequest& original_request_ref = *original_request; 1207 const CopyOutputRequest& original_request_ref = *original_request;
1208 std::unique_ptr<CopyOutputRequest> main_thread_request = 1208 std::unique_ptr<CopyOutputRequest> main_thread_request =
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 inputs_.mask_layer->ToLayerNodeProto(proto->mutable_mask_layer()); 1240 inputs_.mask_layer->ToLayerNodeProto(proto->mutable_mask_layer());
1241 if (inputs_.replica_layer) 1241 if (inputs_.replica_layer)
1242 inputs_.replica_layer->ToLayerNodeProto(proto->mutable_replica_layer()); 1242 inputs_.replica_layer->ToLayerNodeProto(proto->mutable_replica_layer());
1243 } 1243 }
1244 1244
1245 void Layer::ClearLayerTreePropertiesForDeserializationAndAddToMap( 1245 void Layer::ClearLayerTreePropertiesForDeserializationAndAddToMap(
1246 LayerIdMap* layer_map) { 1246 LayerIdMap* layer_map) {
1247 (*layer_map)[inputs_.layer_id] = this; 1247 (*layer_map)[inputs_.layer_id] = this;
1248 1248
1249 if (layer_tree_host_) 1249 if (layer_tree_host_)
1250 layer_tree_host_->UnregisterLayer(this); 1250 GetLayerTree()->UnregisterLayer(this);
1251 1251
1252 layer_tree_host_ = nullptr; 1252 layer_tree_host_ = nullptr;
1253 parent_ = nullptr; 1253 parent_ = nullptr;
1254 1254
1255 // Clear these properties for all the children and add them to the map. 1255 // Clear these properties for all the children and add them to the map.
1256 for (auto& child : inputs_.children) { 1256 for (auto& child : inputs_.children) {
1257 child->ClearLayerTreePropertiesForDeserializationAndAddToMap(layer_map); 1257 child->ClearLayerTreePropertiesForDeserializationAndAddToMap(layer_map);
1258 } 1258 }
1259 1259
1260 inputs_.children.clear(); 1260 inputs_.children.clear();
(...skipping 17 matching lines...) Expand all
1278 DCHECK(!layer_tree_host_); 1278 DCHECK(!layer_tree_host_);
1279 DCHECK(inputs_.children.empty()); 1279 DCHECK(inputs_.children.empty());
1280 DCHECK(!inputs_.mask_layer); 1280 DCHECK(!inputs_.mask_layer);
1281 DCHECK(!inputs_.replica_layer); 1281 DCHECK(!inputs_.replica_layer);
1282 DCHECK(layer_tree_host); 1282 DCHECK(layer_tree_host);
1283 DCHECK(proto.has_id()); 1283 DCHECK(proto.has_id());
1284 1284
1285 inputs_.layer_id = proto.id(); 1285 inputs_.layer_id = proto.id();
1286 1286
1287 layer_tree_host_ = layer_tree_host; 1287 layer_tree_host_ = layer_tree_host;
1288 layer_tree_host_->RegisterLayer(this); 1288 GetLayerTree()->RegisterLayer(this);
1289 1289
1290 for (int i = 0; i < proto.children_size(); ++i) { 1290 for (int i = 0; i < proto.children_size(); ++i) {
1291 const proto::LayerNode& child_proto = proto.children(i); 1291 const proto::LayerNode& child_proto = proto.children(i);
1292 DCHECK(child_proto.has_type()); 1292 DCHECK(child_proto.has_type());
1293 scoped_refptr<Layer> child = 1293 scoped_refptr<Layer> child =
1294 LayerProtoConverter::FindOrAllocateAndConstruct(child_proto, layer_map); 1294 LayerProtoConverter::FindOrAllocateAndConstruct(child_proto, layer_map);
1295 // The child must now refer to this layer as its parent, and must also have 1295 // The child must now refer to this layer as its parent, and must also have
1296 // the same LayerTreeHost. This must be done before deserializing children. 1296 // the same LayerTreeHost. This must be done before deserializing children.
1297 DCHECK(!child->parent_); 1297 DCHECK(!child->parent_);
1298 child->parent_ = this; 1298 child->parent_ = this;
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1740 } 1740 }
1741 1741
1742 void Layer::SetHasWillChangeTransformHint(bool has_will_change) { 1742 void Layer::SetHasWillChangeTransformHint(bool has_will_change) {
1743 if (inputs_.has_will_change_transform_hint == has_will_change) 1743 if (inputs_.has_will_change_transform_hint == has_will_change)
1744 return; 1744 return;
1745 inputs_.has_will_change_transform_hint = has_will_change; 1745 inputs_.has_will_change_transform_hint = has_will_change;
1746 SetNeedsCommit(); 1746 SetNeedsCommit();
1747 } 1747 }
1748 1748
1749 AnimationHost* Layer::GetAnimationHost() const { 1749 AnimationHost* Layer::GetAnimationHost() const {
1750 return layer_tree_host_ ? layer_tree_host_->animation_host() : nullptr; 1750 LayerTree* layer_tree = GetLayerTree();
1751 return layer_tree ? layer_tree->animation_host() : nullptr;
1751 } 1752 }
1752 1753
1753 ElementListType Layer::GetElementTypeForAnimation() const { 1754 ElementListType Layer::GetElementTypeForAnimation() const {
1754 return ElementListType::ACTIVE; 1755 return ElementListType::ACTIVE;
1755 } 1756 }
1756 1757
1757 ScrollbarLayerInterface* Layer::ToScrollbarLayer() { 1758 ScrollbarLayerInterface* Layer::ToScrollbarLayer() {
1758 return nullptr; 1759 return nullptr;
1759 } 1760 }
1760 1761
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1842 ->effect_tree.Node(effect_tree_index()) 1843 ->effect_tree.Node(effect_tree_index())
1843 ->num_copy_requests_in_subtree; 1844 ->num_copy_requests_in_subtree;
1844 } 1845 }
1845 1846
1846 gfx::Transform Layer::screen_space_transform() const { 1847 gfx::Transform Layer::screen_space_transform() const {
1847 DCHECK_NE(transform_tree_index_, -1); 1848 DCHECK_NE(transform_tree_index_, -1);
1848 return draw_property_utils::ScreenSpaceTransform( 1849 return draw_property_utils::ScreenSpaceTransform(
1849 this, layer_tree_host_->property_trees()->transform_tree); 1850 this, layer_tree_host_->property_trees()->transform_tree);
1850 } 1851 }
1851 1852
1853 LayerTree* Layer::GetLayerTree() const {
1854 return layer_tree_host_ ? layer_tree_host_->GetLayerTree() : nullptr;
vmpstr 2016/07/25 20:45:46 If we're mimicking impl side of things, then layer
xingliu 2016/07/25 23:40:25 @Khushal Khushal probably can answer this questio
Khushal 2016/07/26 18:10:41 Not sure. Blink uses the WebCompositorSupportImpl
1855 }
1856
1852 } // namespace cc 1857 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698