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/geometry/LayoutRect.h" | 9 #include "platform/geometry/LayoutRect.h" |
10 #include "wtf/text/WTFString.h" | 10 #include "wtf/text/WTFString.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 // Holds a unique cache generation id of display items and paint controllers. | |
15 // | |
16 // A paint controller sets its cache generation to DisplayItemCacheGeneration::n
ext() | |
17 // at the end of each commitNewDisplayItems, and updates the cache generation of
each | |
18 // client with cached drawings by calling DisplayItemClient::setDisplayItemsCach
ed(). | |
19 // A display item is treated as validly cached in a paint controller if its cach
e generation | |
20 // matches the paint controller's cache generation. | |
21 // | |
22 // SPv1 only: If a display item is painted on multiple paint controllers, becaus
e cache | |
23 // generations are unique, the client's cache generation matches the last paint
controller | |
24 // only. The client will be treated as invalid on other paint controllers regard
less if | |
25 // it's validly cached by these paint controllers. The situation is very rare (a
bout 0.07% | |
26 // clients were painted on multiple paint controllers) so the performance penalt
y is trivial. | |
27 class PLATFORM_EXPORT DisplayItemCacheGeneration { | |
28 DISALLOW_NEW(); | |
29 public: | |
30 DisplayItemCacheGeneration() : m_value(kInvalidGeneration) { } | |
31 | |
32 void invalidate() { m_value = kInvalidGeneration; } | |
33 static DisplayItemCacheGeneration next() { return DisplayItemCacheGeneration
(s_nextGeneration++); } | |
34 bool matches(const DisplayItemCacheGeneration& other) | |
35 { | |
36 return m_value != kInvalidGeneration && other.m_value != kInvalidGenerat
ion && m_value == other.m_value; | |
37 } | |
38 | |
39 private: | |
40 typedef uint32_t Generation; | |
41 DisplayItemCacheGeneration(Generation value) : m_value(value) { } | |
42 | |
43 static const Generation kInvalidGeneration = 0; | |
44 static Generation s_nextGeneration; | |
45 Generation m_value; | |
46 }; | |
47 | |
48 // The interface for objects that can be associated with display items. | 14 // The interface for objects that can be associated with display items. |
49 // A DisplayItemClient object should live at least longer than the document cycl
e | 15 // A DisplayItemClient object should live at least longer than the document cycl
e |
50 // in which its display items are created during painting. | 16 // in which its display items are created during painting. |
51 // After the document cycle, a pointer/reference to DisplayItemClient should be | 17 // After the document cycle, a pointer/reference to DisplayItemClient should be |
52 // no longer dereferenced unless we can make sure the client is still valid. | 18 // no longer dereferenced unless we can make sure the client is still valid. |
53 class PLATFORM_EXPORT DisplayItemClient { | 19 class PLATFORM_EXPORT DisplayItemClient { |
54 public: | 20 public: |
55 #if ENABLE(ASSERT) | 21 #if ENABLE(ASSERT) |
56 DisplayItemClient(); | 22 DisplayItemClient(); |
57 virtual ~DisplayItemClient(); | 23 virtual ~DisplayItemClient(); |
58 #else | 24 #else |
59 virtual ~DisplayItemClient() { } | 25 virtual ~DisplayItemClient() { } |
60 #endif | 26 #endif |
61 | 27 |
62 virtual String debugName() const = 0; | 28 virtual String debugName() const = 0; |
63 | 29 |
64 // The visual rect of this DisplayItemClient, in object space of the object
that owns the GraphicsLayer, i.e. | 30 // The visual rect of this DisplayItemClient, in object space of the object
that owns the GraphicsLayer, i.e. |
65 // offset by offsetFromLayoutObjectWithSubpixelAccumulation(). | 31 // offset by offsetFromLayoutObjectWithSubpixelAccumulation(). |
66 virtual LayoutRect visualRect() const = 0; | 32 virtual LayoutRect visualRect() const = 0; |
67 | 33 |
68 virtual bool displayItemsAreCached(DisplayItemCacheGeneration) const = 0; | |
69 virtual void setDisplayItemsCached(DisplayItemCacheGeneration) const = 0; | |
70 virtual void setDisplayItemsUncached() const = 0; | |
71 | |
72 #if ENABLE(ASSERT) | 34 #if ENABLE(ASSERT) |
73 // Tests if a DisplayItemClient object has been created and has not been del
eted yet. | 35 // Tests if a DisplayItemClient object has been created and has not been del
eted yet. |
74 static bool isAlive(const DisplayItemClient&); | 36 static bool isAlive(const DisplayItemClient&); |
75 #endif | 37 #endif |
76 | |
77 protected: | |
78 }; | 38 }; |
79 | 39 |
80 #define DISPLAY_ITEM_CACHE_STATUS_IMPLEMENTATION \ | |
81 bool displayItemsAreCached(DisplayItemCacheGeneration cacheGeneration) const
final { return m_cacheGeneration.matches(cacheGeneration); } \ | |
82 void setDisplayItemsCached(DisplayItemCacheGeneration cacheGeneration) const
final { m_cacheGeneration = cacheGeneration; } \ | |
83 void setDisplayItemsUncached() const final { m_cacheGeneration.invalidate();
} \ | |
84 mutable DisplayItemCacheGeneration m_cacheGeneration; | |
85 | |
86 #define DISPLAY_ITEM_CACHE_STATUS_UNCACHEABLE_IMPLEMENTATION \ | |
87 bool displayItemsAreCached(DisplayItemCacheGeneration) const final { return
false; } \ | |
88 void setDisplayItemsCached(DisplayItemCacheGeneration) const final { } \ | |
89 void setDisplayItemsUncached() const final { } | |
90 | |
91 inline bool operator==(const DisplayItemClient& client1, const DisplayItemClient
& client2) { return &client1 == &client2; } | 40 inline bool operator==(const DisplayItemClient& client1, const DisplayItemClient
& client2) { return &client1 == &client2; } |
92 inline bool operator!=(const DisplayItemClient& client1, const DisplayItemClient
& client2) { return &client1 != &client2; } | 41 inline bool operator!=(const DisplayItemClient& client1, const DisplayItemClient
& client2) { return &client1 != &client2; } |
93 | 42 |
94 } // namespace blink | 43 } // namespace blink |
95 | 44 |
96 #endif // DisplayItemClient_h | 45 #endif // DisplayItemClient_h |
OLD | NEW |