OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "platform/graphics/compositing/PropertyTreeManager.h" | 5 #include "platform/graphics/compositing/PropertyTreeManager.h" |
6 | 6 |
7 #include "cc/layers/layer.h" | 7 #include "cc/layers/layer.h" |
8 #include "cc/trees/clip_node.h" | 8 #include "cc/trees/clip_node.h" |
9 #include "cc/trees/effect_node.h" | 9 #include "cc/trees/effect_node.h" |
10 #include "cc/trees/layer_tree_host.h" | 10 #include "cc/trees/layer_tree_host.h" |
11 #include "cc/trees/property_tree.h" | 11 #include "cc/trees/property_tree.h" |
12 #include "cc/trees/scroll_node.h" | 12 #include "cc/trees/scroll_node.h" |
13 #include "cc/trees/transform_node.h" | 13 #include "cc/trees/transform_node.h" |
14 #include "platform/graphics/paint/ClipPaintPropertyNode.h" | 14 #include "platform/graphics/paint/ClipPaintPropertyNode.h" |
15 #include "platform/graphics/paint/EffectPaintPropertyNode.h" | 15 #include "platform/graphics/paint/EffectPaintPropertyNode.h" |
16 #include "platform/graphics/paint/GeometryMapper.h" | 16 #include "platform/graphics/paint/GeometryMapper.h" |
17 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" | 17 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" |
18 #include "platform/graphics/paint/TransformPaintPropertyNode.h" | 18 #include "platform/graphics/paint/TransformPaintPropertyNode.h" |
19 #include "public/platform/WebLayerScrollClient.h" | |
19 | 20 |
20 namespace blink { | 21 namespace blink { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 static constexpr int kInvalidNodeId = -1; | 25 static constexpr int kInvalidNodeId = -1; |
25 // cc's property trees use 0 for the root node (always non-null). | 26 // cc's property trees use 0 for the root node (always non-null). |
26 static constexpr int kRealRootNodeId = 0; | 27 static constexpr int kRealRootNodeId = 0; |
27 // cc allocates special nodes for root effects such as the device scale. | 28 // cc allocates special nodes for root effects such as the device scale. |
28 static constexpr int kSecondaryRootNodeId = 1; | 29 static constexpr int kSecondaryRootNodeId = 1; |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 return kSecondaryRootNodeId; | 258 return kSecondaryRootNodeId; |
258 | 259 |
259 auto it = m_scrollNodeMap.find(scrollNode); | 260 auto it = m_scrollNodeMap.find(scrollNode); |
260 if (it != m_scrollNodeMap.end()) | 261 if (it != m_scrollNodeMap.end()) |
261 return it->value; | 262 return it->value; |
262 | 263 |
263 int parentId = ensureCompositorScrollNode(scrollNode->parent()); | 264 int parentId = ensureCompositorScrollNode(scrollNode->parent()); |
264 int id = scrollTree().Insert(cc::ScrollNode(), parentId); | 265 int id = scrollTree().Insert(cc::ScrollNode(), parentId); |
265 | 266 |
266 cc::ScrollNode& compositorNode = *scrollTree().Node(id); | 267 cc::ScrollNode& compositorNode = *scrollTree().Node(id); |
267 // TODO(wkorman): Fix owning layer id to reference a layer id rather than a | |
268 // scroll node index. | |
269 compositorNode.owning_layer_id = parentId; | |
270 m_propertyTrees | |
271 .layer_id_to_scroll_node_index[compositorNode.owning_layer_id] = id; | |
272 | |
273 compositorNode.scrollable = true; | 268 compositorNode.scrollable = true; |
274 | 269 |
275 compositorNode.scroll_clip_layer_bounds.SetSize(scrollNode->clip().width(), | 270 compositorNode.scroll_clip_layer_bounds.SetSize(scrollNode->clip().width(), |
276 scrollNode->clip().height()); | 271 scrollNode->clip().height()); |
277 compositorNode.bounds.SetSize(scrollNode->bounds().width(), | 272 compositorNode.bounds.SetSize(scrollNode->bounds().width(), |
278 scrollNode->bounds().height()); | 273 scrollNode->bounds().height()); |
279 compositorNode.user_scrollable_horizontal = | 274 compositorNode.user_scrollable_horizontal = |
280 scrollNode->userScrollableHorizontal(); | 275 scrollNode->userScrollableHorizontal(); |
281 compositorNode.user_scrollable_vertical = | 276 compositorNode.user_scrollable_vertical = |
282 scrollNode->userScrollableVertical(); | 277 scrollNode->userScrollableVertical(); |
(...skipping 29 matching lines...) Expand all Loading... | |
312 // cc's transform node to remove the 2d scroll translation and instead set the | 307 // cc's transform node to remove the 2d scroll translation and instead set the |
313 // scroll_offset field. | 308 // scroll_offset field. |
314 auto scrollOffsetSize = scrollOffsetNode->matrix().to2DTranslation(); | 309 auto scrollOffsetSize = scrollOffsetNode->matrix().to2DTranslation(); |
315 auto scrollOffset = | 310 auto scrollOffset = |
316 gfx::ScrollOffset(-scrollOffsetSize.width(), -scrollOffsetSize.height()); | 311 gfx::ScrollOffset(-scrollOffsetSize.width(), -scrollOffsetSize.height()); |
317 DCHECK(compositorTransformNode.local.IsIdentityOr2DTranslation()); | 312 DCHECK(compositorTransformNode.local.IsIdentityOr2DTranslation()); |
318 compositorTransformNode.scroll_offset = scrollOffset; | 313 compositorTransformNode.scroll_offset = scrollOffset; |
319 compositorTransformNode.local.MakeIdentity(); | 314 compositorTransformNode.local.MakeIdentity(); |
320 compositorTransformNode.scrolls = true; | 315 compositorTransformNode.scrolls = true; |
321 transformTree().set_needs_update(true); | 316 transformTree().set_needs_update(true); |
322 // TODO(pdr): The scroll tree's scroll offset will need to be set here. | 317 // TODO(pdr): Because of a layer dependancy, the scroll tree scroll offset is |
318 // set in updateLayerScrollMapping but that should occur here. | |
319 } | |
320 | |
321 void PropertyTreeManager::updateLayerScrollMapping( | |
322 cc::Layer* layer, | |
323 const TransformPaintPropertyNode* transform) { | |
324 auto* enclosingScrollNode = transform->findEnclosingScrollNode(); | |
325 int scrollNodeId = ensureCompositorScrollNode(enclosingScrollNode); | |
326 layer->SetScrollTreeIndex(scrollNodeId); | |
327 int layerId = layer->id(); | |
328 m_propertyTrees.layer_id_to_scroll_node_index[layerId] = scrollNodeId; | |
329 | |
330 if (transform->isScrollTranslation()) { | |
wkorman
2017/02/16 22:36:22
Could return here if false, to early-out and save
pdr.
2017/02/16 23:08:27
Done
| |
331 auto& compositorScrollNode = *scrollTree().Node(scrollNodeId); | |
332 auto& compositorTransformNode = | |
333 *transformTree().Node(compositorScrollNode.transform_id); | |
334 | |
335 // TODO(pdr): Remove the scroll node's owning_layer_id. | |
336 if (compositorScrollNode.owning_layer_id == cc::Layer::INVALID_ID) { | |
wkorman
2017/02/16 22:36:22
So if it ever got an owning_layer_id previously we
pdr.
2017/02/16 23:08:27
Good question, I should have called this out in mo
ajuma
2017/02/17 00:06:18
Might be worth adding a comment about this.
| |
337 compositorScrollNode.owning_layer_id = layerId; | |
338 // TODO(pdr): Set this in updateScrollAndScrollTranslationNodes once the | |
339 // layer id is no longer needed. | |
340 scrollTree().SetScrollOffset(layerId, | |
341 compositorTransformNode.scroll_offset); | |
342 if (auto* scrollClient = enclosingScrollNode->scrollClient()) { | |
343 layer->set_did_scroll_callback( | |
344 base::Bind(&blink::WebLayerScrollClient::didScroll, | |
345 base::Unretained(scrollClient))); | |
346 } | |
347 } | |
348 } | |
323 } | 349 } |
324 | 350 |
325 int PropertyTreeManager::switchToEffectNode( | 351 int PropertyTreeManager::switchToEffectNode( |
326 const EffectPaintPropertyNode& nextEffect) { | 352 const EffectPaintPropertyNode& nextEffect) { |
327 const EffectPaintPropertyNode* ancestor = | 353 const EffectPaintPropertyNode* ancestor = |
328 GeometryMapper::lowestCommonAncestor(currentEffectNode(), &nextEffect); | 354 GeometryMapper::lowestCommonAncestor(currentEffectNode(), &nextEffect); |
329 DCHECK(ancestor) << "Malformed effect tree. All nodes must be descendant of " | 355 DCHECK(ancestor) << "Malformed effect tree. All nodes must be descendant of " |
330 "EffectPaintPropertyNode::root()."; | 356 "EffectPaintPropertyNode::root()."; |
331 while (currentEffectNode() != ancestor) | 357 while (currentEffectNode() != ancestor) |
332 m_effectStack.pop_back(); | 358 m_effectStack.pop_back(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 m_effectStack.push_back(BlinkEffectAndCcIdPair{nextEffect, effectNode.id}); | 438 m_effectStack.push_back(BlinkEffectAndCcIdPair{nextEffect, effectNode.id}); |
413 | 439 |
414 dummyLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); | 440 dummyLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); |
415 dummyLayer->SetTransformTreeIndex(kSecondaryRootNodeId); | 441 dummyLayer->SetTransformTreeIndex(kSecondaryRootNodeId); |
416 dummyLayer->SetClipTreeIndex(outputClipId); | 442 dummyLayer->SetClipTreeIndex(outputClipId); |
417 dummyLayer->SetEffectTreeIndex(effectNode.id); | 443 dummyLayer->SetEffectTreeIndex(effectNode.id); |
418 dummyLayer->SetScrollTreeIndex(kRealRootNodeId); | 444 dummyLayer->SetScrollTreeIndex(kRealRootNodeId); |
419 } | 445 } |
420 | 446 |
421 } // namespace blink | 447 } // namespace blink |
OLD | NEW |