| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/CompositorMutableStateProvider.h" | 5 #include "platform/graphics/CompositorMutableStateProvider.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include "cc/layers/layer_impl.h" | 8 #include "cc/layers/layer_impl.h" |
| 9 #include "cc/trees/layer_tree_impl.h" | 9 #include "cc/trees/layer_tree_impl.h" |
| 10 #include "platform/graphics/CompositorElementId.h" | |
| 11 #include "platform/graphics/CompositorMutableProperties.h" | 10 #include "platform/graphics/CompositorMutableProperties.h" |
| 12 #include "platform/graphics/CompositorMutableState.h" | 11 #include "platform/graphics/CompositorMutableState.h" |
| 13 #include "platform/graphics/CompositorMutation.h" | 12 #include "platform/graphics/CompositorMutation.h" |
| 14 #include "platform/wtf/PtrUtil.h" | 13 #include "platform/wtf/PtrUtil.h" |
| 15 | 14 |
| 16 namespace blink { | 15 namespace blink { |
| 17 | 16 |
| 18 CompositorMutableStateProvider::CompositorMutableStateProvider( | 17 CompositorMutableStateProvider::CompositorMutableStateProvider( |
| 19 cc::LayerTreeImpl* tree_impl, | 18 cc::LayerTreeImpl* tree_impl, |
| 20 CompositorMutations* mutations) | 19 CompositorMutations* mutations) |
| 21 : tree_(tree_impl), mutations_(mutations) {} | 20 : tree_(tree_impl), mutations_(mutations) {} |
| 22 | 21 |
| 23 CompositorMutableStateProvider::~CompositorMutableStateProvider() {} | 22 CompositorMutableStateProvider::~CompositorMutableStateProvider() {} |
| 24 | 23 |
| 25 std::unique_ptr<CompositorMutableState> | 24 std::unique_ptr<CompositorMutableState> |
| 26 CompositorMutableStateProvider::GetMutableStateFor(uint64_t element_id) { | 25 CompositorMutableStateProvider::GetMutableStateFor(DOMNodeId dom_node_id) { |
| 27 cc::LayerImpl* main_layer = | 26 cc::LayerImpl* main_layer = |
| 28 tree_->LayerByElementId(CompositorElementIdFromDOMNodeId( | 27 tree_->LayerByElementId(CompositorElementIdFromDOMNodeId( |
| 29 element_id, CompositorElementIdNamespace::kPrimary)); | 28 dom_node_id, CompositorElementIdNamespace::kPrimaryCompositorProxy)); |
| 30 cc::LayerImpl* scroll_layer = | 29 cc::LayerImpl* scroll_layer = |
| 31 tree_->LayerByElementId(CompositorElementIdFromDOMNodeId( | 30 tree_->LayerByElementId(CompositorElementIdFromDOMNodeId( |
| 32 element_id, CompositorElementIdNamespace::kScroll)); | 31 dom_node_id, CompositorElementIdNamespace::kScrollCompositorProxy)); |
| 33 | 32 |
| 34 if (!main_layer && !scroll_layer) | 33 if (!main_layer && !scroll_layer) |
| 35 return nullptr; | 34 return nullptr; |
| 36 | 35 |
| 37 // Ensure that we have an entry in the map for |elementId| but do as few | 36 // Ensure that we have an entry in the map for |elementId| but do as few |
| 38 // allocations and queries as possible. This will update the map only if we | 37 // allocations and queries as possible. This will update the map only if we |
| 39 // have not added a value for |elementId|. | 38 // have not added a value for |elementId|. |
| 40 auto result = mutations_->map.insert(element_id, nullptr); | 39 auto result = mutations_->map.insert(dom_node_id, nullptr); |
| 41 | 40 |
| 42 // Only if this is a new entry do we want to allocate a new mutation. | 41 // Only if this is a new entry do we want to allocate a new mutation. |
| 43 if (result.is_new_entry) | 42 if (result.is_new_entry) |
| 44 result.stored_value->value = WTF::WrapUnique(new CompositorMutation); | 43 result.stored_value->value = WTF::WrapUnique(new CompositorMutation); |
| 45 | 44 |
| 46 return WTF::WrapUnique(new CompositorMutableState( | 45 return WTF::WrapUnique(new CompositorMutableState( |
| 47 result.stored_value->value.get(), main_layer, scroll_layer)); | 46 result.stored_value->value.get(), main_layer, scroll_layer)); |
| 48 } | 47 } |
| 49 | 48 |
| 50 } // namespace blink | 49 } // namespace blink |
| OLD | NEW |