Chromium Code Reviews| 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 #ifndef CompositorElementId_h | 5 #ifndef CompositorElementId_h |
| 6 #define CompositorElementId_h | 6 #define CompositorElementId_h |
| 7 | 7 |
| 8 #include "cc/trees/element_id.h" | 8 #include "cc/trees/element_id.h" |
| 9 #include "platform/PlatformExport.h" | 9 #include "platform/PlatformExport.h" |
| 10 #include "platform/wtf/HashFunctions.h" | 10 #include "platform/wtf/HashFunctions.h" |
| 11 #include "platform/wtf/HashSet.h" | 11 #include "platform/wtf/HashSet.h" |
| 12 #include "platform/wtf/HashTraits.h" | 12 #include "platform/wtf/HashTraits.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 enum class CompositorSubElementId { | 16 enum class CompositorElementIdNamespace { |
| 17 kPrimary, | 17 kPrimary, |
| 18 kScroll, | 18 kScroll, |
| 19 kViewport, | 19 kViewport, |
| 20 kLinkHighlight, | 20 kLinkHighlight, |
| 21 kScrollbar, | |
| 21 // A sentinel to indicate how many enum values there are. | 22 // A sentinel to indicate how many enum values there are. |
| 22 kNumSubElementTypes | 23 kMaxRepresentableNamespaceId = 8 |
|
wkorman
2017/05/12 22:29:39
Could define kNamespaceBits = 3 above/somewhere, a
chrishtr
2017/05/12 23:44:16
Great idea! Done. Xianzhu++, it was his idea from
| |
| 23 }; | 24 }; |
| 24 | 25 |
| 25 using CompositorElementId = cc::ElementId; | 26 using CompositorElementId = cc::ElementId; |
| 26 using DOMNodeId = uint64_t; | |
| 27 | 27 |
| 28 CompositorElementId PLATFORM_EXPORT | 28 CompositorElementId PLATFORM_EXPORT |
| 29 CreateCompositorElementId(DOMNodeId, CompositorSubElementId); | 29 CreateCompositorElementId(uint64_t id, CompositorElementIdNamespace); |
|
wkorman
2017/05/12 22:29:39
Is conflict between scrollbar id and dom node id n
chrishtr
2017/05/12 23:44:16
Done.
| |
| 30 | 30 |
| 31 // Note cc::ElementId has a hash function already implemented via | 31 // Note cc::ElementId has a hash function already implemented via |
| 32 // ElementIdHash::operator(). However for consistency's sake we choose to use | 32 // ElementIdHash::operator(). However for consistency's sake we choose to use |
| 33 // Blink's hash functions with Blink specific data structures. | 33 // Blink's hash functions with Blink specific data structures. |
| 34 struct CompositorElementIdHash { | 34 struct CompositorElementIdHash { |
| 35 static unsigned GetHash(const CompositorElementId& key) { | 35 static unsigned GetHash(const CompositorElementId& key) { |
| 36 return WTF::HashInt(static_cast<cc::ElementIdType>(key.id_)); | 36 return WTF::HashInt(static_cast<cc::ElementIdType>(key.id_)); |
| 37 } | 37 } |
| 38 static bool Equal(const CompositorElementId& a, | 38 static bool Equal(const CompositorElementId& a, |
| 39 const CompositorElementId& b) { | 39 const CompositorElementId& b) { |
| 40 return a.id_ == b.id_; | 40 return a.id_ == b.id_; |
| 41 } | 41 } |
| 42 static const bool safe_to_compare_to_empty_or_deleted = true; | 42 static const bool safe_to_compare_to_empty_or_deleted = true; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 DOMNodeId PLATFORM_EXPORT DomNodeIdFromCompositorElementId(CompositorElementId); | 45 uint64_t PLATFORM_EXPORT IdFromCompositorElementId(CompositorElementId); |
| 46 CompositorSubElementId PLATFORM_EXPORT | 46 CompositorElementIdNamespace PLATFORM_EXPORT |
| 47 SubElementIdFromCompositorElementId(CompositorElementId); | 47 NamespaceFromCompositorElementId(CompositorElementId); |
| 48 | 48 |
| 49 struct CompositorElementIdHashTraits | 49 struct CompositorElementIdHashTraits |
| 50 : WTF::GenericHashTraits<CompositorElementId> { | 50 : WTF::GenericHashTraits<CompositorElementId> { |
| 51 static CompositorElementId EmptyValue() { return CompositorElementId(1); } | 51 static CompositorElementId EmptyValue() { return CompositorElementId(1); } |
| 52 static void ConstructDeletedValue(CompositorElementId& slot, bool) { | 52 static void ConstructDeletedValue(CompositorElementId& slot, bool) { |
| 53 slot = CompositorElementId(); | 53 slot = CompositorElementId(); |
| 54 } | 54 } |
| 55 static bool IsDeletedValue(CompositorElementId value) { | 55 static bool IsDeletedValue(CompositorElementId value) { |
| 56 return value == CompositorElementId(); | 56 return value == CompositorElementId(); |
| 57 } | 57 } |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 using CompositorElementIdSet = HashSet<CompositorElementId, | 60 using CompositorElementIdSet = HashSet<CompositorElementId, |
| 61 CompositorElementIdHash, | 61 CompositorElementIdHash, |
| 62 CompositorElementIdHashTraits>; | 62 CompositorElementIdHashTraits>; |
| 63 | 63 |
| 64 } // namespace blink | 64 } // namespace blink |
| 65 | 65 |
| 66 #endif // CompositorElementId_h | 66 #endif // CompositorElementId_h |
| OLD | NEW |