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 "wtf/HashFunctions.h" |
| 11 #include "wtf/HashTraits.h" |
10 | 12 |
11 namespace blink { | 13 namespace blink { |
12 | 14 |
13 enum class CompositorSubElementId { Primary, Scroll, Viewport, LinkHighlight }; | 15 enum class CompositorSubElementId { Primary, Scroll, Viewport, LinkHighlight }; |
14 | 16 |
15 using CompositorElementId = cc::ElementId; | 17 using CompositorElementId = cc::ElementId; |
16 | 18 |
17 CompositorElementId PLATFORM_EXPORT | 19 CompositorElementId PLATFORM_EXPORT |
18 createCompositorElementId(int domNodeId, CompositorSubElementId); | 20 createCompositorElementId(int domNodeId, CompositorSubElementId); |
19 | 21 |
| 22 // Note cc::ElementId has a hash function already implemented via |
| 23 // ElementIdHash::operator(). However for consistency's sake we choose to use |
| 24 // Blink's hash functions with Blink specific data structures. |
| 25 struct CompositorElementIdHash { |
| 26 static unsigned hash(const CompositorElementId& p) { |
| 27 return WTF::hashInts(p.primaryId, p.secondaryId); |
| 28 } |
| 29 static bool equal(const CompositorElementId& a, |
| 30 const CompositorElementId& b) { |
| 31 return a.primaryId == b.primaryId && a.secondaryId == b.secondaryId; |
| 32 } |
| 33 static const bool safeToCompareToEmptyOrDeleted = true; |
| 34 }; |
| 35 |
| 36 struct CompositorElementIdHashTraits |
| 37 : WTF::GenericHashTraits<CompositorElementId> { |
| 38 static CompositorElementId emptyValue() { return CompositorElementId(); } |
| 39 // TODO(wkorman): Should we optimize below to keep a single static |
| 40 // pre-constructed CompositorElementId() rather than constructing each |
| 41 // function call? |
| 42 static void constructDeletedValue(CompositorElementId& slot, bool) { |
| 43 slot = CompositorElementId(); |
| 44 } |
| 45 static bool isDeletedValue(CompositorElementId value) { |
| 46 return value == CompositorElementId(); |
| 47 } |
| 48 }; |
| 49 |
20 } // namespace blink | 50 } // namespace blink |
21 | 51 |
22 #endif // CompositorElementId_h | 52 #endif // CompositorElementId_h |
OLD | NEW |