| 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 "cc/layers/layer_impl.h" | 7 #include "cc/layers/layer_impl.h" |
| 8 #include "cc/trees/layer_tree_impl.h" | 8 #include "cc/trees/layer_tree_impl.h" |
| 9 #include "platform/graphics/CompositorElementId.h" | 9 #include "platform/graphics/CompositorElementId.h" |
| 10 #include "platform/graphics/CompositorMutableProperties.h" | 10 #include "platform/graphics/CompositorMutableProperties.h" |
| 11 #include "platform/graphics/CompositorMutableState.h" | 11 #include "platform/graphics/CompositorMutableState.h" |
| 12 #include "platform/graphics/CompositorMutation.h" | 12 #include "platform/graphics/CompositorMutation.h" |
| 13 #include "wtf/PassOwnPtr.h" | 13 #include "wtf/PassOwnPtr.h" |
| 14 #include "wtf/PtrUtil.h" |
| 14 | 15 |
| 15 namespace blink { | 16 namespace blink { |
| 16 | 17 |
| 17 CompositorMutableStateProvider::CompositorMutableStateProvider(cc::LayerTreeImpl
* state, CompositorMutations* mutations) | 18 CompositorMutableStateProvider::CompositorMutableStateProvider(cc::LayerTreeImpl
* state, CompositorMutations* mutations) |
| 18 : m_state(state) | 19 : m_state(state) |
| 19 , m_mutations(mutations) | 20 , m_mutations(mutations) |
| 20 { | 21 { |
| 21 } | 22 } |
| 22 | 23 |
| 23 CompositorMutableStateProvider::~CompositorMutableStateProvider() {} | 24 CompositorMutableStateProvider::~CompositorMutableStateProvider() {} |
| 24 | 25 |
| 25 PassOwnPtr<CompositorMutableState> | 26 std::unique_ptr<CompositorMutableState> |
| 26 CompositorMutableStateProvider::getMutableStateFor(uint64_t element_id) | 27 CompositorMutableStateProvider::getMutableStateFor(uint64_t element_id) |
| 27 { | 28 { |
| 28 cc::LayerImpl* mainLayer = m_state->LayerByElementId(createCompositorElement
Id(element_id, CompositorSubElementId::Primary)); | 29 cc::LayerImpl* mainLayer = m_state->LayerByElementId(createCompositorElement
Id(element_id, CompositorSubElementId::Primary)); |
| 29 cc::LayerImpl* scrollLayer = m_state->LayerByElementId(createCompositorEleme
ntId(element_id, CompositorSubElementId::Scroll)); | 30 cc::LayerImpl* scrollLayer = m_state->LayerByElementId(createCompositorEleme
ntId(element_id, CompositorSubElementId::Scroll)); |
| 30 | 31 |
| 31 if (!mainLayer && !scrollLayer) | 32 if (!mainLayer && !scrollLayer) |
| 32 return nullptr; | 33 return nullptr; |
| 33 | 34 |
| 34 // Ensure that we have an entry in the map for |element_id| but do as few | 35 // Ensure that we have an entry in the map for |element_id| but do as few |
| 35 // allocations and queries as possible. This will update the map only if we | 36 // allocations and queries as possible. This will update the map only if we |
| 36 // have not added a value for |element_id|. | 37 // have not added a value for |element_id|. |
| 37 auto result = m_mutations->map.add(element_id, nullptr); | 38 auto result = m_mutations->map.add(element_id, nullptr); |
| 38 | 39 |
| 39 // Only if this is a new entry do we want to allocate a new mutation. | 40 // Only if this is a new entry do we want to allocate a new mutation. |
| 40 if (result.isNewEntry) | 41 if (result.isNewEntry) |
| 41 result.storedValue->value = adoptPtr(new CompositorMutation); | 42 result.storedValue->value = adoptPtr(new CompositorMutation); |
| 42 | 43 |
| 43 return adoptPtr(new CompositorMutableState(result.storedValue->value.get(),
mainLayer, scrollLayer)); | 44 return wrapUnique(new CompositorMutableState(result.storedValue->value.get()
, mainLayer, scrollLayer)); |
| 44 } | 45 } |
| 45 | 46 |
| 46 } // namespace blink | 47 } // namespace blink |
| OLD | NEW |