| 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 #ifndef DisplayItemClient_h | 5 #ifndef DisplayItemClient_h |
| 6 #define DisplayItemClient_h | 6 #define DisplayItemClient_h |
| 7 | 7 |
| 8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
| 9 #include "platform/heap/Heap.h" | 9 #include "platform/heap/Heap.h" |
| 10 #include "wtf/text/WTFString.h" | 10 #include "wtf/text/WTFString.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 class DisplayItemClientInternalVoid; | 14 class DisplayItemClientInternalVoid; |
| 15 using DisplayItemClient = const DisplayItemClientInternalVoid*; | 15 using DisplayItemClientObject = const DisplayItemClientInternalVoid*; |
| 16 | 16 |
| 17 inline DisplayItemClient toDisplayItemClient(const void* object) { return static
_cast<DisplayItemClient>(object); } | 17 const unsigned kMaxSubDisplayItemClientId = (1 << 6) - 1; |
| 18 |
| 19 struct DisplayItemClient { |
| 20 // subClientId allows multiple display item client per object. |
| 21 // This is useful when we need to cache the display item separately for each
sub clients. |
| 22 DisplayItemClient(const void* inObject, unsigned inSubClientId = 0) |
| 23 : object(static_cast<DisplayItemClientObject>(inObject)) |
| 24 , subClientId(inSubClientId) |
| 25 { |
| 26 ASSERT(inSubClientId <= kMaxSubDisplayItemClientId); |
| 27 } |
| 28 |
| 29 bool operator==(const DisplayItemClient& other) const |
| 30 { |
| 31 return object == other.object && subClientId == other.subClientId; |
| 32 } |
| 33 |
| 34 bool operator!=(const DisplayItemClient& other) const |
| 35 { |
| 36 return !(*this == other); |
| 37 } |
| 38 |
| 39 DisplayItemClientObject object; |
| 40 size_t subClientId; |
| 41 }; |
| 18 | 42 |
| 19 // Used to pass DisplayItemClient and debugName() (called only when needed) from | 43 // Used to pass DisplayItemClient and debugName() (called only when needed) from |
| 20 // core/layout module etc. to platform/paint module. | 44 // core/layout module etc. to platform/paint module. |
| 21 // The instance must not out-live the object. Long-time reference to a client mu
st | 45 // The instance must not out-live the object. Long-time reference to a client mu
st |
| 22 // use DisplayItemClient. | 46 // use DisplayItemClient. |
| 23 class PLATFORM_EXPORT DisplayItemClientWrapper { | 47 class PLATFORM_EXPORT DisplayItemClientWrapper { |
| 24 DISALLOW_NEW(); // Allow allocated in stack or in another object only. | 48 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); // Allow allocated in stack or in anoth
er object only. |
| 25 public: | 49 public: |
| 26 template <typename T> | 50 template <typename T> |
| 27 DisplayItemClientWrapper(const T& object) | 51 DisplayItemClientWrapper(const T& object) |
| 28 : m_displayItemClient(object.displayItemClient()) | 52 : m_displayItemClient(object.displayItemClient()) |
| 29 , m_object(reinterpret_cast<const GenericClass&>(object)) | 53 , m_object(reinterpret_cast<const GenericClass&>(object)) |
| 30 , m_debugNameInvoker(&invokeDebugName<T>) | 54 , m_debugNameInvoker(&invokeDebugName<T>) |
| 31 { } | 55 { } |
| 32 | 56 |
| 57 // Allows one object to create multiple sub display item clients. Use like: |
| 58 // DisplayItemClientWrapper(object, toSubDisplayItemClient<SubClientId>(&obj
ect), functionToGetDebugNameOfSubClient) |
| 59 template <typename T> |
| 60 DisplayItemClientWrapper(const T& object, DisplayItemClient displayItemClien
t, String (*debugNameInvoker)(const T&)) |
| 61 : m_displayItemClient(displayItemClient) |
| 62 , m_object(reinterpret_cast<const GenericClass&>(object)) |
| 63 , m_debugNameInvoker(reinterpret_cast<DebugNameInvoker>(debugNameInvoker
)) |
| 64 { } |
| 65 |
| 33 DisplayItemClientWrapper(const DisplayItemClientWrapper& other) | 66 DisplayItemClientWrapper(const DisplayItemClientWrapper& other) |
| 34 : m_displayItemClient(other.m_displayItemClient) | 67 : m_displayItemClient(other.m_displayItemClient) |
| 35 , m_object(other.m_object) | 68 , m_object(other.m_object) |
| 36 , m_debugNameInvoker(other.m_debugNameInvoker) | 69 , m_debugNameInvoker(other.m_debugNameInvoker) |
| 37 { } | 70 { } |
| 38 | 71 |
| 39 DisplayItemClient displayItemClient() const { return m_displayItemClient; } | 72 DisplayItemClient displayItemClient() const { return m_displayItemClient; } |
| 40 String debugName() const { return m_debugNameInvoker(m_object); } | 73 String debugName() const { return m_debugNameInvoker(m_object); } |
| 41 | 74 |
| 42 private: | 75 private: |
| 43 DisplayItemClientWrapper& operator=(const DisplayItemClientWrapper&) = delet
e; | 76 DisplayItemClientWrapper& operator=(const DisplayItemClientWrapper&) = delet
e; |
| 44 | 77 |
| 45 class GenericClass; | 78 class GenericClass; |
| 46 template <typename T> | 79 template <typename T> |
| 47 static String invokeDebugName(const GenericClass& object) { return reinterpr
et_cast<const T&>(object).debugName(); } | 80 static String invokeDebugName(const GenericClass& object) { return reinterpr
et_cast<const T&>(object).debugName(); } |
| 48 | 81 |
| 82 using DebugNameInvoker = String (*)(const GenericClass&); |
| 49 DisplayItemClient m_displayItemClient; | 83 DisplayItemClient m_displayItemClient; |
| 50 const GenericClass& m_object; | 84 const GenericClass& m_object; |
| 51 using DebugNameInvoker = String(*)(const GenericClass&); | |
| 52 DebugNameInvoker m_debugNameInvoker; | 85 DebugNameInvoker m_debugNameInvoker; |
| 53 }; | 86 }; |
| 54 | 87 |
| 55 } | 88 } |
| 56 | 89 |
| 57 #endif // DisplayItemClient_h | 90 #endif // DisplayItemClient_h |
| OLD | NEW |