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 | |
14 // The interface for objects that can be associated with display items. | 48 // The interface for objects that can be associated with display items. |
15 // A DisplayItemClient object should live at least longer than the document cycl e | 49 // A DisplayItemClient object should live at least longer than the document cycl e |
16 // in which its display items are created during painting. | 50 // in which its display items are created during painting. |
17 // After the document cycle, a pointer/reference to DisplayItemClient should be | 51 // After the document cycle, a pointer/reference to DisplayItemClient should be |
18 // no longer dereferenced unless we can make sure the client is still valid. | 52 // no longer dereferenced unless we can make sure the client is still valid. |
19 class PLATFORM_EXPORT DisplayItemClient { | 53 class PLATFORM_EXPORT DisplayItemClient { |
20 public: | 54 public: |
21 #if ENABLE(ASSERT) | 55 #if ENABLE(ASSERT) |
22 DisplayItemClient(); | 56 DisplayItemClient(); |
23 virtual ~DisplayItemClient(); | 57 virtual ~DisplayItemClient(); |
24 #else | 58 #else |
25 virtual ~DisplayItemClient() { } | 59 virtual ~DisplayItemClient() { } |
26 #endif | 60 #endif |
27 | 61 |
28 virtual String debugName() const = 0; | 62 virtual String debugName() const = 0; |
29 | 63 |
30 // The visual rect of this DisplayItemClient, in object space of the object that owns the GraphicsLayer, i.e. | 64 // The visual rect of this DisplayItemClient, in object space of the object that owns the GraphicsLayer, i.e. |
31 // offset by offsetFromLayoutObjectWithSubpixelAccumulation(). | 65 // offset by offsetFromLayoutObjectWithSubpixelAccumulation(). |
32 virtual LayoutRect visualRect() const = 0; | 66 virtual LayoutRect visualRect() const = 0; |
33 | 67 |
68 // The default implementation is uncacheable. | |
69 // Use DISPLAY_ITEM_CACHE_STATUS_IMPLEMENTATION for cacheable implementation . | |
chrishtr
2016/04/29 15:55:17
I think it would be better to do the opposite, so
Xianzhu
2016/04/29 16:37:11
Agreed. Done.
| |
70 virtual bool displayItemsAreCached(DisplayItemCacheGeneration) const { retur n false; } | |
71 virtual void setDisplayItemsCached(DisplayItemCacheGeneration) const { } | |
72 virtual void setDisplayItemsUncached() const { } | |
73 | |
34 #if ENABLE(ASSERT) | 74 #if ENABLE(ASSERT) |
35 // Tests if a DisplayItemClient object has been created and has not been del eted yet. | 75 // Tests if a DisplayItemClient object has been created and has not been del eted yet. |
36 static bool isAlive(const DisplayItemClient&); | 76 static bool isAlive(const DisplayItemClient&); |
37 #endif | 77 #endif |
78 | |
79 protected: | |
38 }; | 80 }; |
39 | 81 |
82 #define DISPLAY_ITEM_CACHE_STATUS_IMPLEMENTATION \ | |
83 bool displayItemsAreCached(DisplayItemCacheGeneration cacheGeneration) const final { return m_cacheGeneration.matches(cacheGeneration); } \ | |
84 void setDisplayItemsCached(DisplayItemCacheGeneration cacheGeneration) const final { m_cacheGeneration = cacheGeneration; } \ | |
85 void setDisplayItemsUncached() const final { m_cacheGeneration.invalidate(); } \ | |
86 mutable DisplayItemCacheGeneration m_cacheGeneration; | |
87 | |
40 inline bool operator==(const DisplayItemClient& client1, const DisplayItemClient & client2) { return &client1 == &client2; } | 88 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; } | 89 inline bool operator!=(const DisplayItemClient& client1, const DisplayItemClient & client2) { return &client1 != &client2; } |
42 | 90 |
43 } // namespace blink | 91 } // namespace blink |
44 | 92 |
45 #endif // DisplayItemClient_h | 93 #endif // DisplayItemClient_h |
OLD | NEW |