OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 LayoutObjectDrawingRecorder_h | 5 #ifndef LayoutObjectDrawingRecorder_h |
6 #define LayoutObjectDrawingRecorder_h | 6 #define LayoutObjectDrawingRecorder_h |
7 | 7 |
8 #include "core/layout/LayoutObject.h" | 8 #include "core/layout/LayoutObject.h" |
9 #include "core/layout/line/InlineBox.h" | 9 #include "core/layout/line/InlineBox.h" |
10 #include "core/paint/PaintPhase.h" | 10 #include "core/paint/PaintPhase.h" |
11 #include "platform/geometry/LayoutPoint.h" | 11 #include "platform/geometry/LayoutPoint.h" |
12 #include "platform/geometry/LayoutRect.h" | 12 #include "platform/geometry/LayoutRect.h" |
13 #include "platform/graphics/paint/DisplayItemCacheSkipper.h" | 13 #include "platform/graphics/paint/DisplayItemCacheSkipper.h" |
14 #include "platform/graphics/paint/DrawingRecorder.h" | 14 #include "platform/graphics/paint/DrawingRecorder.h" |
15 #include "wtf/Allocator.h" | 15 #include "wtf/Allocator.h" |
16 #include "wtf/Optional.h" | 16 #include "wtf/Optional.h" |
17 | 17 |
18 namespace blink { | 18 namespace blink { |
19 | 19 |
20 class GraphicsContext; | 20 class GraphicsContext; |
21 | 21 |
22 // Convenience wrapper of DrawingRecorder for LayoutObject painters. | 22 // Convenience wrapper of DrawingRecorder for LayoutObject painters. |
23 class LayoutObjectDrawingRecorder final { | 23 class LayoutObjectDrawingRecorder final { |
24 ALLOW_ONLY_INLINE_ALLOCATION(); | 24 ALLOW_ONLY_INLINE_ALLOCATION(); |
25 public: | 25 public: |
26 static bool useCachedDrawingIfPossible(GraphicsContext& context, const Layou
tObject& layoutObject, DisplayItem::Type displayItemType, const LayoutPoint& pai
ntOffset) | 26 static bool useCachedDrawingIfPossible(GraphicsContext& context, const Layou
tObject& layoutObject, DisplayItem::Type displayItemType, const LayoutPoint& pai
ntOffset) |
27 { | 27 { |
28 // TODO(pdr): The paint offset cache should be stored on LayoutObject bu
t is temporarily on the DisplayItemList. | 28 if (RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled() && layou
tObject.previousPaintOffset() != paintOffset) |
29 if (RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled() && !cont
ext.displayItemList()->paintOffsetIsUnchanged(layoutObject.displayItemClient(),
paintOffset)) | |
30 return false; | 29 return false; |
31 if (layoutObject.fullPaintInvalidationReason() == PaintInvalidationDelay
edFull) | 30 if (layoutObject.fullPaintInvalidationReason() == PaintInvalidationDelay
edFull) |
32 return false; | 31 return false; |
33 return DrawingRecorder::useCachedDrawingIfPossible(context, layoutObject
, displayItemType); | 32 return DrawingRecorder::useCachedDrawingIfPossible(context, layoutObject
, displayItemType); |
34 } | 33 } |
35 | 34 |
36 static bool useCachedDrawingIfPossible(GraphicsContext& context, const Layou
tObject& layoutObject, PaintPhase phase, const LayoutPoint& paintOffset) | 35 static bool useCachedDrawingIfPossible(GraphicsContext& context, const Layou
tObject& layoutObject, PaintPhase phase, const LayoutPoint& paintOffset) |
37 { | 36 { |
38 return useCachedDrawingIfPossible(context, layoutObject, DisplayItem::pa
intPhaseToDrawingType(phase), paintOffset); | 37 return useCachedDrawingIfPossible(context, layoutObject, DisplayItem::pa
intPhaseToDrawingType(phase), paintOffset); |
39 } | 38 } |
40 | 39 |
41 static bool useCachedDrawingIfPossible(GraphicsContext& context, const Inlin
eBox& inlineBox, DisplayItem::Type displayItemType, const LayoutPoint& paintOffs
et) | 40 static bool useCachedDrawingIfPossible(GraphicsContext& context, const Inlin
eBox& inlineBox, DisplayItem::Type displayItemType, const LayoutPoint& paintOffs
et) |
42 { | 41 { |
43 // TODO(pdr): The paint offset cache should be stored on LayoutObject bu
t is temporarily on the DisplayItemList. | 42 if (RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled() && inlin
eBox.layoutObject().previousPaintOffset() != paintOffset) |
44 if (RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled() && !cont
ext.displayItemList()->paintOffsetIsUnchanged(inlineBox.displayItemClient(), pai
ntOffset)) | |
45 return false; | 43 return false; |
46 return DrawingRecorder::useCachedDrawingIfPossible(context, inlineBox, d
isplayItemType); | 44 return DrawingRecorder::useCachedDrawingIfPossible(context, inlineBox, d
isplayItemType); |
47 } | 45 } |
48 | 46 |
49 static bool useCachedDrawingIfPossible(GraphicsContext& context, const Inlin
eBox& inlineBox, PaintPhase phase, const LayoutPoint& paintOffset) | 47 static bool useCachedDrawingIfPossible(GraphicsContext& context, const Inlin
eBox& inlineBox, PaintPhase phase, const LayoutPoint& paintOffset) |
50 { | 48 { |
51 return useCachedDrawingIfPossible(context, inlineBox, DisplayItem::paint
PhaseToDrawingType(phase), paintOffset); | 49 return useCachedDrawingIfPossible(context, inlineBox, DisplayItem::paint
PhaseToDrawingType(phase), paintOffset); |
52 } | 50 } |
53 | 51 |
54 LayoutObjectDrawingRecorder(GraphicsContext& context, const LayoutObject& la
youtObject, DisplayItem::Type displayItemType, const FloatRect& clip, const Layo
utPoint& paintOffset) | 52 LayoutObjectDrawingRecorder(GraphicsContext& context, const LayoutObject& la
youtObject, DisplayItem::Type displayItemType, const FloatRect& clip, const Layo
utPoint& paintOffset) |
55 { | 53 { |
56 updatePaintOffsetIfNeeded(context.displayItemList(), layoutObject, paint
Offset); | 54 updatePaintOffsetIfNeeded(context.displayItemList(), layoutObject, layou
tObject, paintOffset); |
57 // We may paint a delayed-invalidation object before it's actually inval
idated. | 55 // We may paint a delayed-invalidation object before it's actually inval
idated. |
58 if (layoutObject.fullPaintInvalidationReason() == PaintInvalidationDelay
edFull) | 56 if (layoutObject.fullPaintInvalidationReason() == PaintInvalidationDelay
edFull) |
59 m_cacheSkipper.emplace(context); | 57 m_cacheSkipper.emplace(context); |
60 m_drawingRecorder.emplace(context, layoutObject, displayItemType, clip); | 58 m_drawingRecorder.emplace(context, layoutObject, displayItemType, clip); |
61 } | 59 } |
62 | 60 |
63 LayoutObjectDrawingRecorder(GraphicsContext& context, const LayoutObject& la
youtObject, DisplayItem::Type displayItemType, const LayoutRect& clip, const Lay
outPoint& paintOffset) | 61 LayoutObjectDrawingRecorder(GraphicsContext& context, const LayoutObject& la
youtObject, DisplayItem::Type displayItemType, const LayoutRect& clip, const Lay
outPoint& paintOffset) |
64 : LayoutObjectDrawingRecorder(context, layoutObject, displayItemType, Fl
oatRect(clip), paintOffset) { } | 62 : LayoutObjectDrawingRecorder(context, layoutObject, displayItemType, Fl
oatRect(clip), paintOffset) { } |
65 | 63 |
66 LayoutObjectDrawingRecorder(GraphicsContext& context, const LayoutObject& la
youtObject, PaintPhase phase, const FloatRect& clip, const LayoutPoint& paintOff
set) | 64 LayoutObjectDrawingRecorder(GraphicsContext& context, const LayoutObject& la
youtObject, PaintPhase phase, const FloatRect& clip, const LayoutPoint& paintOff
set) |
67 : LayoutObjectDrawingRecorder(context, layoutObject, DisplayItem::paintP
haseToDrawingType(phase), clip, paintOffset) { } | 65 : LayoutObjectDrawingRecorder(context, layoutObject, DisplayItem::paintP
haseToDrawingType(phase), clip, paintOffset) { } |
68 | 66 |
69 LayoutObjectDrawingRecorder(GraphicsContext& context, const LayoutObject& la
youtObject, PaintPhase phase, const LayoutRect& clip, const LayoutPoint& paintOf
fset) | 67 LayoutObjectDrawingRecorder(GraphicsContext& context, const LayoutObject& la
youtObject, PaintPhase phase, const LayoutRect& clip, const LayoutPoint& paintOf
fset) |
70 : LayoutObjectDrawingRecorder(context, layoutObject, DisplayItem::paintP
haseToDrawingType(phase), FloatRect(clip), paintOffset) { } | 68 : LayoutObjectDrawingRecorder(context, layoutObject, DisplayItem::paintP
haseToDrawingType(phase), FloatRect(clip), paintOffset) { } |
71 | 69 |
72 LayoutObjectDrawingRecorder(GraphicsContext& context, const LayoutObject& la
youtObject, PaintPhase phase, const IntRect& clip, const LayoutPoint& paintOffse
t) | 70 LayoutObjectDrawingRecorder(GraphicsContext& context, const LayoutObject& la
youtObject, PaintPhase phase, const IntRect& clip, const LayoutPoint& paintOffse
t) |
73 : LayoutObjectDrawingRecorder(context, layoutObject, DisplayItem::paintP
haseToDrawingType(phase), FloatRect(clip), paintOffset) { } | 71 : LayoutObjectDrawingRecorder(context, layoutObject, DisplayItem::paintP
haseToDrawingType(phase), FloatRect(clip), paintOffset) { } |
74 | 72 |
75 LayoutObjectDrawingRecorder(GraphicsContext& context, const InlineBox& inlin
eBox, DisplayItem::Type displayItemType, const FloatRect& clip, const LayoutPoin
t& paintOffset) | 73 LayoutObjectDrawingRecorder(GraphicsContext& context, const InlineBox& inlin
eBox, DisplayItem::Type displayItemType, const FloatRect& clip, const LayoutPoin
t& paintOffset) |
76 { | 74 { |
77 updatePaintOffsetIfNeeded(context.displayItemList(), inlineBox, paintOff
set); | 75 updatePaintOffsetIfNeeded(context.displayItemList(), inlineBox.layoutObj
ect(), inlineBox, paintOffset); |
78 m_drawingRecorder.emplace(context, inlineBox, displayItemType, clip); | 76 m_drawingRecorder.emplace(context, inlineBox, displayItemType, clip); |
79 } | 77 } |
80 | 78 |
81 LayoutObjectDrawingRecorder(GraphicsContext& context, const InlineBox& inlin
eBox, DisplayItem::Type displayItemType, const LayoutRect& clip, const LayoutPoi
nt& paintOffset) | 79 LayoutObjectDrawingRecorder(GraphicsContext& context, const InlineBox& inlin
eBox, DisplayItem::Type displayItemType, const LayoutRect& clip, const LayoutPoi
nt& paintOffset) |
82 : LayoutObjectDrawingRecorder(context, inlineBox, displayItemType, Float
Rect(clip), paintOffset) { } | 80 : LayoutObjectDrawingRecorder(context, inlineBox, displayItemType, Float
Rect(clip), paintOffset) { } |
83 | 81 |
84 LayoutObjectDrawingRecorder(GraphicsContext& context, const InlineBox& inlin
eBox, PaintPhase phase, const LayoutRect& clip, const LayoutPoint& paintOffset) | 82 LayoutObjectDrawingRecorder(GraphicsContext& context, const InlineBox& inlin
eBox, PaintPhase phase, const LayoutRect& clip, const LayoutPoint& paintOffset) |
85 : LayoutObjectDrawingRecorder(context, inlineBox, DisplayItem::paintPhas
eToDrawingType(phase), FloatRect(clip), paintOffset) { } | 83 : LayoutObjectDrawingRecorder(context, inlineBox, DisplayItem::paintPhas
eToDrawingType(phase), FloatRect(clip), paintOffset) { } |
86 | 84 |
87 LayoutObjectDrawingRecorder(GraphicsContext& context, const InlineBox& inlin
eBox, PaintPhase phase, const IntRect& clip, const LayoutPoint& paintOffset) | 85 LayoutObjectDrawingRecorder(GraphicsContext& context, const InlineBox& inlin
eBox, PaintPhase phase, const IntRect& clip, const LayoutPoint& paintOffset) |
88 : LayoutObjectDrawingRecorder(context, inlineBox, DisplayItem::paintPhas
eToDrawingType(phase), FloatRect(clip), paintOffset) { } | 86 : LayoutObjectDrawingRecorder(context, inlineBox, DisplayItem::paintPhas
eToDrawingType(phase), FloatRect(clip), paintOffset) { } |
89 | 87 |
90 #if ENABLE(ASSERT) | 88 #if ENABLE(ASSERT) |
91 void setUnderInvalidationCheckingMode(DrawingDisplayItem::UnderInvalidationC
heckingMode mode) { m_drawingRecorder->setUnderInvalidationCheckingMode(mode); } | 89 void setUnderInvalidationCheckingMode(DrawingDisplayItem::UnderInvalidationC
heckingMode mode) { m_drawingRecorder->setUnderInvalidationCheckingMode(mode); } |
92 #endif | 90 #endif |
93 | 91 |
94 private: | 92 private: |
95 static void updatePaintOffsetIfNeeded(DisplayItemList* displayItemList, cons
t DisplayItemClientWrapper& client, const LayoutPoint& paintOffset) | 93 static void updatePaintOffsetIfNeeded(DisplayItemList* displayItemList, cons
t LayoutObject& layoutObject, const DisplayItemClientWrapper& client, const Layo
utPoint& paintOffset) |
96 { | 94 { |
97 if (!RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled()) | 95 if (!RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled()) |
98 return; | 96 return; |
99 | 97 |
100 // TODO(pdr): The paint offset cache should be stored on LayoutObject bu
t is temporarily on the DisplayItemList. | 98 if (layoutObject.previousPaintOffset() != paintOffset) { |
101 if (!displayItemList->paintOffsetIsUnchanged(client.displayItemClient(),
paintOffset)) { | 99 layoutObject.setPreviousPaintOffset(paintOffset); |
102 displayItemList->recordPaintOffset(client.displayItemClient(), paint
Offset); | |
103 displayItemList->invalidatePaintOffset(client); | 100 displayItemList->invalidatePaintOffset(client); |
104 } else { | 101 } else { |
105 ASSERT(!displayItemList->paintOffsetWasInvalidated(client.displayIte
mClient()) || !displayItemList->clientCacheIsValid(client.displayItemClient())); | 102 ASSERT(!displayItemList->paintOffsetWasInvalidated(client.displayIte
mClient()) || !displayItemList->clientCacheIsValid(client.displayItemClient())); |
106 } | 103 } |
107 } | 104 } |
108 | 105 |
109 Optional<DisplayItemCacheSkipper> m_cacheSkipper; | 106 Optional<DisplayItemCacheSkipper> m_cacheSkipper; |
110 Optional<DrawingRecorder> m_drawingRecorder; | 107 Optional<DrawingRecorder> m_drawingRecorder; |
111 }; | 108 }; |
112 | 109 |
113 } // namespace blink | 110 } // namespace blink |
114 | 111 |
115 #endif // LayoutObjectDrawingRecorder_h | 112 #endif // LayoutObjectDrawingRecorder_h |
OLD | NEW |