Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

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

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

Powered by Google App Engine
This is Rietveld 408576698