| 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" | |
| 10 #include "wtf/text/WTFString.h" | 9 #include "wtf/text/WTFString.h" |
| 11 | 10 |
| 12 namespace blink { | 11 namespace blink { |
| 13 | 12 |
| 14 class DisplayItemClientInternalVoid; | 13 // The interface for objects that can be associated with display items. |
| 15 using DisplayItemClient = const DisplayItemClientInternalVoid*; | 14 class PLATFORM_EXPORT DisplayItemClient { |
| 15 public: |
| 16 virtual ~DisplayItemClient() { } |
| 16 | 17 |
| 17 inline DisplayItemClient toDisplayItemClient(const void* object) { return static
_cast<DisplayItemClient>(object); } | 18 virtual String debugName() const = 0; |
| 19 }; |
| 18 | 20 |
| 19 // Used to pass DisplayItemClient and debugName() (called only when needed) from | 21 inline bool operator==(const DisplayItemClient& client1, const DisplayItemClient
& client2) { return &client1 == &client2; } |
| 20 // core/layout module etc. to platform/paint module. | 22 inline bool operator!=(const DisplayItemClient& client1, const DisplayItemClient
& client2) { return &client1 != &client2; } |
| 21 // The instance must not out-live the object. Long-time reference to a client mu
st | |
| 22 // use DisplayItemClient. | |
| 23 class PLATFORM_EXPORT DisplayItemClientWrapper final { | |
| 24 DISALLOW_NEW(); // Allow allocated in stack or in another object only. | |
| 25 public: | |
| 26 template <typename T> | |
| 27 DisplayItemClientWrapper(const T& object) | |
| 28 : m_displayItemClient(object.displayItemClient()) | |
| 29 , m_object(reinterpret_cast<const GenericClass&>(object)) | |
| 30 , m_debugNameInvoker(&invokeDebugName<T>) | |
| 31 { } | |
| 32 | |
| 33 DisplayItemClientWrapper(const DisplayItemClientWrapper& other) | |
| 34 : m_displayItemClient(other.m_displayItemClient) | |
| 35 , m_object(other.m_object) | |
| 36 , m_debugNameInvoker(other.m_debugNameInvoker) | |
| 37 { } | |
| 38 | |
| 39 DisplayItemClient displayItemClient() const { return m_displayItemClient; } | |
| 40 String debugName() const { return m_debugNameInvoker(m_object); } | |
| 41 | |
| 42 private: | |
| 43 DisplayItemClientWrapper& operator=(const DisplayItemClientWrapper&) = delet
e; | |
| 44 | |
| 45 class GenericClass; | |
| 46 template <typename T> | |
| 47 static String invokeDebugName(const GenericClass& object) { return reinterpr
et_cast<const T&>(object).debugName(); } | |
| 48 | |
| 49 DisplayItemClient m_displayItemClient; | |
| 50 const GenericClass& m_object; | |
| 51 using DebugNameInvoker = String(*)(const GenericClass&); | |
| 52 DebugNameInvoker m_debugNameInvoker; | |
| 53 }; | |
| 54 | 23 |
| 55 } | 24 } |
| 56 | 25 |
| 57 #endif // DisplayItemClient_h | 26 #endif // DisplayItemClient_h |
| OLD | NEW |