OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 ObjectPaintInvalidator_h | 5 #ifndef ObjectPaintInvalidator_h |
6 #define ObjectPaintInvalidator_h | 6 #define ObjectPaintInvalidator_h |
7 | 7 |
8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
9 #include "platform/graphics/PaintInvalidationReason.h" | 9 #include "platform/graphics/PaintInvalidationReason.h" |
10 #include "wtf/Allocator.h" | 10 #include "wtf/Allocator.h" |
11 #include "wtf/AutoReset.h" | 11 #include "wtf/AutoReset.h" |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 | 14 |
15 class DisplayItemClient; | 15 class DisplayItemClient; |
16 class LayoutBoxModelObject; | 16 class LayoutBoxModelObject; |
17 class LayoutObject; | 17 class LayoutObject; |
18 class LayoutRect; | 18 class LayoutRect; |
19 struct PaintInvalidatorContext; | 19 struct PaintInvalidatorContext; |
20 | 20 |
21 class CORE_EXPORT ObjectPaintInvalidator { | 21 class CORE_EXPORT ObjectPaintInvalidator { |
22 STACK_ALLOCATED(); | 22 STACK_ALLOCATED(); |
23 | 23 |
24 public: | 24 public: |
25 ObjectPaintInvalidator(const LayoutObject& object) : m_object(object) {} | 25 ObjectPaintInvalidator(const LayoutObject& object) : m_object(object) {} |
26 | 26 |
27 static void objectWillBeDestroyed(const LayoutObject&); | 27 static void objectWillBeDestroyed(const LayoutObject&); |
28 | 28 |
29 // This calls paintingLayer() which walks up the tree. | 29 // This calls paintingLayer() which walks up the tree. |
30 // If possible, use the faster PaintInvalidatorContext.paintingLayer.setNeedsR
epaint(). | 30 // If possible, use the faster |
| 31 // PaintInvalidatorContext.paintingLayer.setNeedsRepaint(). |
31 void slowSetPaintingLayerNeedsRepaint(); | 32 void slowSetPaintingLayerNeedsRepaint(); |
32 | 33 |
33 // TODO(wangxianzhu): Change the call sites to use the faster version if possi
ble. | 34 // TODO(wangxianzhu): Change the call sites to use the faster version if |
| 35 // possible. |
34 void slowSetPaintingLayerNeedsRepaintAndInvalidateDisplayItemClient( | 36 void slowSetPaintingLayerNeedsRepaintAndInvalidateDisplayItemClient( |
35 const DisplayItemClient& client, | 37 const DisplayItemClient& client, |
36 PaintInvalidationReason reason) { | 38 PaintInvalidationReason reason) { |
37 slowSetPaintingLayerNeedsRepaint(); | 39 slowSetPaintingLayerNeedsRepaint(); |
38 invalidateDisplayItemClient(client, reason); | 40 invalidateDisplayItemClient(client, reason); |
39 } | 41 } |
40 | 42 |
41 void invalidateDisplayItemClientsIncludingNonCompositingDescendants( | 43 void invalidateDisplayItemClientsIncludingNonCompositingDescendants( |
42 PaintInvalidationReason); | 44 PaintInvalidationReason); |
43 | 45 |
44 void invalidatePaintOfPreviousPaintInvalidationRect( | 46 void invalidatePaintOfPreviousPaintInvalidationRect( |
45 const LayoutBoxModelObject& paintInvalidationContainer, | 47 const LayoutBoxModelObject& paintInvalidationContainer, |
46 PaintInvalidationReason); | 48 PaintInvalidationReason); |
47 | 49 |
48 // The caller should ensure the painting layer has been setNeedsRepaint before
calling this function. | 50 // The caller should ensure the painting layer has been setNeedsRepaint before |
| 51 // calling this function. |
49 void invalidateDisplayItemClient(const DisplayItemClient&, | 52 void invalidateDisplayItemClient(const DisplayItemClient&, |
50 PaintInvalidationReason); | 53 PaintInvalidationReason); |
51 | 54 |
52 // Actually do the paint invalidate of rect r for this object which has been c
omputed in the coordinate space | 55 // Actually do the paint invalidate of rect r for this object which has been |
53 // of the GraphicsLayer backing of |paintInvalidationContainer|. Note that thi
s coordinaten space is not the same | 56 // computed in the coordinate space of the GraphicsLayer backing of |
54 // as the local coordinate space of |paintInvalidationContainer| in the presen
ce of layer squashing. | 57 // |paintInvalidationContainer|. Note that this coordinaten space is not the |
| 58 // same as the local coordinate space of |paintInvalidationContainer| in the |
| 59 // presence of layer squashing. |
55 void invalidatePaintUsingContainer( | 60 void invalidatePaintUsingContainer( |
56 const LayoutBoxModelObject& paintInvalidationContainer, | 61 const LayoutBoxModelObject& paintInvalidationContainer, |
57 const LayoutRect&, | 62 const LayoutRect&, |
58 PaintInvalidationReason); | 63 PaintInvalidationReason); |
59 | 64 |
60 // Invalidate the paint of a specific subrectangle within a given object. The
rect is in the object's coordinate space. | 65 // Invalidate the paint of a specific subrectangle within a given object. The |
61 // If a DisplayItemClient is specified, that client is invalidated rather than
|m_object|. | 66 // rect is in the object's coordinate space. If a DisplayItemClient is |
62 // Returns the visual rect that was invalidated (i.e, invalidation in the spac
e of the GraphicsLayer backing this LayoutObject). | 67 // specified, that client is invalidated rather than |m_object|. |
| 68 // Returns the visual rect that was invalidated (i.e, invalidation in the |
| 69 // space of the GraphicsLayer backing this LayoutObject). |
63 LayoutRect invalidatePaintRectangle(const LayoutRect&, DisplayItemClient*); | 70 LayoutRect invalidatePaintRectangle(const LayoutRect&, DisplayItemClient*); |
64 | 71 |
65 void invalidatePaintIncludingNonCompositingDescendants(); | 72 void invalidatePaintIncludingNonCompositingDescendants(); |
66 void invalidatePaintIncludingNonSelfPaintingLayerDescendants( | 73 void invalidatePaintIncludingNonSelfPaintingLayerDescendants( |
67 const LayoutBoxModelObject& paintInvalidationContainer); | 74 const LayoutBoxModelObject& paintInvalidationContainer); |
68 | 75 |
69 private: | 76 private: |
70 void invalidatePaintIncludingNonSelfPaintingLayerDescendantsInternal( | 77 void invalidatePaintIncludingNonSelfPaintingLayerDescendantsInternal( |
71 const LayoutBoxModelObject& paintInvalidationContainer); | 78 const LayoutBoxModelObject& paintInvalidationContainer); |
72 void setBackingNeedsPaintInvalidationInRect( | 79 void setBackingNeedsPaintInvalidationInRect( |
(...skipping 13 matching lines...) Expand all Loading... |
86 | 93 |
87 PaintInvalidationReason invalidatePaintIfNeeded() { | 94 PaintInvalidationReason invalidatePaintIfNeeded() { |
88 return invalidatePaintIfNeededWithComputedReason( | 95 return invalidatePaintIfNeededWithComputedReason( |
89 computePaintInvalidationReason()); | 96 computePaintInvalidationReason()); |
90 } | 97 } |
91 | 98 |
92 PaintInvalidationReason computePaintInvalidationReason(); | 99 PaintInvalidationReason computePaintInvalidationReason(); |
93 PaintInvalidationReason invalidatePaintIfNeededWithComputedReason( | 100 PaintInvalidationReason invalidatePaintIfNeededWithComputedReason( |
94 PaintInvalidationReason); | 101 PaintInvalidationReason); |
95 | 102 |
96 // This function tries to minimize the amount of invalidation generated by inv
alidating the "difference" between | 103 // This function tries to minimize the amount of invalidation generated by |
97 // |m_context.oldBounds| and |m_context.newBounds|. This means invalidating th
e union of the previous rectangles | 104 // invalidating the "difference" between |m_context.oldBounds| and |
98 // but not their intersection. The use case is when an element only requires a
paint invalidation (which means | 105 // |m_context.newBounds|. This means invalidating the union of the previous |
99 // that its content didn't change) and its bounds changed but its location did
n't. | 106 // rectangles but not their intersection. The use case is when an element only |
100 // If we don't meet the criteria for an incremental paint, the alternative is
a full paint invalidation. | 107 // requires a paint invalidation (which means that its content didn't change) |
101 // Returns true if any paint invalidation is done. | 108 // and its bounds changed but its location didn't. If we don't meet the |
| 109 // criteria for an incremental paint, the alternative is a full paint |
| 110 // invalidation. Returns true if any paint invalidation is done. |
102 bool incrementallyInvalidatePaint(); | 111 bool incrementallyInvalidatePaint(); |
103 | 112 |
104 private: | 113 private: |
105 void invalidateSelectionIfNeeded(PaintInvalidationReason); | 114 void invalidateSelectionIfNeeded(PaintInvalidationReason); |
106 | 115 |
107 // This function generates a full invalidation, which means invalidating both
|oldBounds| and |newBounds|. | 116 // This function generates a full invalidation, which means invalidating both |
108 // This is the default choice when generating an invalidation, as it is always
correct, albeit it may force some extra painting. | 117 // |oldBounds| and |newBounds|. This is the default choice when generating an |
| 118 // invalidation, as it is always correct, albeit it may force some extra |
| 119 // painting. |
109 void fullyInvalidatePaint(PaintInvalidationReason, | 120 void fullyInvalidatePaint(PaintInvalidationReason, |
110 const LayoutRect& oldBounds, | 121 const LayoutRect& oldBounds, |
111 const LayoutRect& newBounds); | 122 const LayoutRect& newBounds); |
112 | 123 |
113 const PaintInvalidatorContext& m_context; | 124 const PaintInvalidatorContext& m_context; |
114 }; | 125 }; |
115 | 126 |
116 // TODO(crbug.com/457415): We should not allow paint invalidation out of paint i
nvalidation state. | 127 // TODO(crbug.com/457415): We should not allow paint invalidation out of paint |
| 128 // invalidation state. |
117 class DisablePaintInvalidationStateAsserts { | 129 class DisablePaintInvalidationStateAsserts { |
118 STACK_ALLOCATED(); | 130 STACK_ALLOCATED(); |
119 WTF_MAKE_NONCOPYABLE(DisablePaintInvalidationStateAsserts); | 131 WTF_MAKE_NONCOPYABLE(DisablePaintInvalidationStateAsserts); |
120 | 132 |
121 public: | 133 public: |
122 DisablePaintInvalidationStateAsserts(); | 134 DisablePaintInvalidationStateAsserts(); |
123 | 135 |
124 private: | 136 private: |
125 AutoReset<bool> m_disabler; | 137 AutoReset<bool> m_disabler; |
126 }; | 138 }; |
127 | 139 |
128 } // namespace blink | 140 } // namespace blink |
129 | 141 |
130 #endif | 142 #endif |
OLD | NEW |