Chromium Code Reviews

Side by Side Diff: third_party/WebKit/Source/platform/graphics/paint/DisplayItemClient.h

Issue 1508223005: Client side display item cache flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ScrollbarTheme
Patch Set: Fix unit tests Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
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 // A paint controller sets its cache generation to DisplayItemCacheGeneration::n ext()
16 // at the end of each commitNewDisplayItems, and updates the cache generation of each
17 // client with cached drawings by calling DisplayItemClient::setDisplayItemsCach ed().
18 // A display item is treated as validly cached in a paint controller if its cach e generation
19 // matches the paint controller's cache generation.
20 class PLATFORM_EXPORT DisplayItemCacheGeneration {
21 DISALLOW_NEW();
22 public:
23 DisplayItemCacheGeneration() : m_value(kInvalidGeneration) { }
24
25 void invalidate() { m_value = kInvalidGeneration; }
26 static DisplayItemCacheGeneration next() { return DisplayItemCacheGeneration (s_nextGeneration++); }
27 bool matches(const DisplayItemCacheGeneration& other)
28 {
29 return m_value != kInvalidGeneration && other.m_value != kInvalidGenerat ion && m_value == other.m_value;
30 }
31
32 private:
33 typedef uint32_t Generation;
34 DisplayItemCacheGeneration(Generation value) : m_value(value) { }
35
36 static const Generation kInvalidGeneration = 0;
37 static Generation s_nextGeneration;
38 Generation m_value;
39 };
40
14 // The interface for objects that can be associated with display items. 41 // 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 42 // A DisplayItemClient object should live at least longer than the document cycl e
16 // in which its display items are created during painting. 43 // in which its display items are created during painting.
17 // After the document cycle, a pointer/reference to DisplayItemClient should be 44 // 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. 45 // no longer dereferenced unless we can make sure the client is still valid.
19 class PLATFORM_EXPORT DisplayItemClient { 46 class PLATFORM_EXPORT DisplayItemClient {
20 public: 47 public:
21 #if ENABLE(ASSERT) 48 #if ENABLE(ASSERT)
22 DisplayItemClient(); 49 DisplayItemClient();
23 virtual ~DisplayItemClient(); 50 virtual ~DisplayItemClient();
24 #else 51 #else
25 virtual ~DisplayItemClient() { } 52 virtual ~DisplayItemClient() { }
26 #endif 53 #endif
27 54
28 virtual String debugName() const = 0; 55 virtual String debugName() const = 0;
29 56
30 // The visual rect of this DisplayItemClient, in object space of the object that owns the GraphicsLayer, i.e. 57 // The visual rect of this DisplayItemClient, in object space of the object that owns the GraphicsLayer, i.e.
31 // offset by offsetFromLayoutObjectWithSubpixelAccumulation(). 58 // offset by offsetFromLayoutObjectWithSubpixelAccumulation().
32 virtual LayoutRect visualRect() const = 0; 59 virtual LayoutRect visualRect() const = 0;
33 60
61 virtual bool displayItemsAreCached(DisplayItemCacheGeneration) const = 0;
62 virtual void setDisplayItemsCached(DisplayItemCacheGeneration) const = 0;
63 virtual void setDisplayItemsUncached() const = 0;
64
34 #if ENABLE(ASSERT) 65 #if ENABLE(ASSERT)
35 // Tests if a DisplayItemClient object has been created and has not been del eted yet. 66 // Tests if a DisplayItemClient object has been created and has not been del eted yet.
36 static bool isAlive(const DisplayItemClient&); 67 static bool isAlive(const DisplayItemClient&);
37 #endif 68 #endif
69
70 protected:
38 }; 71 };
39 72
73 #define DISPLAY_ITEM_CACHE_STATUS_IMPLEMENTATION \
74 bool displayItemsAreCached(DisplayItemCacheGeneration cacheGeneration) const final { return m_cacheGeneration.matches(cacheGeneration); } \
75 void setDisplayItemsCached(DisplayItemCacheGeneration cacheGeneration) const final { m_cacheGeneration = cacheGeneration; } \
76 void setDisplayItemsUncached() const final { m_cacheGeneration.invalidate(); } \
77 mutable DisplayItemCacheGeneration m_cacheGeneration;
78
79 #define DISPLAY_ITEM_CACHE_STATUS_UNCACHEABLE_IMPLEMENTATION \
80 bool displayItemsAreCached(DisplayItemCacheGeneration) const final { return false; } \
81 void setDisplayItemsCached(DisplayItemCacheGeneration) const final { } \
82 void setDisplayItemsUncached() const final { }
83
40 inline bool operator==(const DisplayItemClient& client1, const DisplayItemClient & client2) { return &client1 == &client2; } 84 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; } 85 inline bool operator!=(const DisplayItemClient& client1, const DisplayItemClient & client2) { return &client1 != &client2; }
42 86
43 } // namespace blink 87 } // namespace blink
44 88
45 #endif // DisplayItemClient_h 89 #endif // DisplayItemClient_h
OLDNEW

Powered by Google App Engine