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 #include "core/paint/FramePainter.h" | 5 #include "core/paint/FramePainter.h" |
6 | 6 |
7 #include "core/editing/markers/DocumentMarkerController.h" | 7 #include "core/editing/markers/DocumentMarkerController.h" |
8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
9 #include "core/inspector/InspectorTraceEvents.h" | 9 #include "core/inspector/InspectorTraceEvents.h" |
10 #include "core/layout/LayoutView.h" | 10 #include "core/layout/LayoutView.h" |
11 #include "core/page/Page.h" | 11 #include "core/page/Page.h" |
12 #include "core/paint/LayoutObjectDrawingRecorder.h" | 12 #include "core/paint/LayoutObjectDrawingRecorder.h" |
13 #include "core/paint/PaintInfo.h" | 13 #include "core/paint/PaintInfo.h" |
14 #include "core/paint/PaintLayer.h" | 14 #include "core/paint/PaintLayer.h" |
15 #include "core/paint/PaintLayerPainter.h" | 15 #include "core/paint/PaintLayerPainter.h" |
| 16 #include "core/paint/PaintTiming.h" |
16 #include "core/paint/ScrollbarPainter.h" | 17 #include "core/paint/ScrollbarPainter.h" |
17 #include "core/paint/TransformRecorder.h" | 18 #include "core/paint/TransformRecorder.h" |
18 #include "core/probe/CoreProbes.h" | 19 #include "core/probe/CoreProbes.h" |
19 #include "platform/fonts/FontCache.h" | 20 #include "platform/fonts/FontCache.h" |
20 #include "platform/graphics/GraphicsContext.h" | 21 #include "platform/graphics/GraphicsContext.h" |
21 #include "platform/graphics/paint/ClipRecorder.h" | 22 #include "platform/graphics/paint/ClipRecorder.h" |
| 23 #include "platform/graphics/paint/PaintController.h" |
22 #include "platform/graphics/paint/ScopedPaintChunkProperties.h" | 24 #include "platform/graphics/paint/ScopedPaintChunkProperties.h" |
23 #include "platform/loader/fetch/MemoryCache.h" | 25 #include "platform/loader/fetch/MemoryCache.h" |
24 #include "platform/scroll/ScrollbarTheme.h" | 26 #include "platform/scroll/ScrollbarTheme.h" |
25 | 27 |
26 namespace blink { | 28 namespace blink { |
27 | 29 |
28 bool FramePainter::in_paint_contents_ = false; | 30 bool FramePainter::in_paint_contents_ = false; |
29 | 31 |
30 void FramePainter::Paint(GraphicsContext& context, | 32 FramePainter::FramePainter(GraphicsContext& context, |
31 const GlobalPaintFlags global_paint_flags, | 33 const FrameView& frame_view) |
| 34 : context_(context), frame_view_(&frame_view) { |
| 35 context_.GetPaintController().BeginFrame(&GetFrameView().GetFrame()); |
| 36 } |
| 37 |
| 38 FramePainter::~FramePainter() { |
| 39 FrameFirstPaint result = |
| 40 context_.GetPaintController().EndFrame(&GetFrameView().GetFrame()); |
| 41 NotifyPaint(result); |
| 42 } |
| 43 |
| 44 void FramePainter::Paint(const GlobalPaintFlags global_paint_flags, |
32 const CullRect& rect) { | 45 const CullRect& rect) { |
33 GetFrameView().NotifyPageThatContentAreaWillPaint(); | 46 GetFrameView().NotifyPageThatContentAreaWillPaint(); |
34 | 47 |
35 IntRect document_dirty_rect = rect.rect_; | 48 IntRect document_dirty_rect = rect.rect_; |
36 IntRect visible_area_without_scrollbars( | 49 IntRect visible_area_without_scrollbars( |
37 GetFrameView().Location(), GetFrameView().VisibleContentRect().Size()); | 50 GetFrameView().Location(), GetFrameView().VisibleContentRect().Size()); |
38 document_dirty_rect.Intersect(visible_area_without_scrollbars); | 51 document_dirty_rect.Intersect(visible_area_without_scrollbars); |
39 document_dirty_rect.MoveBy(-GetFrameView().Location() + | 52 document_dirty_rect.MoveBy(-GetFrameView().Location() + |
40 GetFrameView().ScrollOffsetInt()); | 53 GetFrameView().ScrollOffsetInt()); |
41 | 54 |
42 bool should_paint_contents = !document_dirty_rect.IsEmpty(); | 55 bool should_paint_contents = !document_dirty_rect.IsEmpty(); |
43 bool should_paint_scrollbars = !GetFrameView().ScrollbarsSuppressed() && | 56 bool should_paint_scrollbars = !GetFrameView().ScrollbarsSuppressed() && |
44 (GetFrameView().HorizontalScrollbar() || | 57 (GetFrameView().HorizontalScrollbar() || |
45 GetFrameView().VerticalScrollbar()); | 58 GetFrameView().VerticalScrollbar()); |
46 if (!should_paint_contents && !should_paint_scrollbars) | 59 if (!should_paint_contents && !should_paint_scrollbars) |
47 return; | 60 return; |
48 | 61 |
49 if (should_paint_contents) { | 62 if (should_paint_contents) { |
50 // TODO(pdr): Creating frame paint properties here will not be needed once | 63 // TODO(pdr): Creating frame paint properties here will not be needed once |
51 // settings()->rootLayerScrolls() is enabled. | 64 // settings()->rootLayerScrolls() is enabled. |
52 // TODO(pdr): Make this conditional on the rootLayerScrolls setting. | 65 // TODO(pdr): Make this conditional on the rootLayerScrolls setting. |
53 Optional<ScopedPaintChunkProperties> scoped_paint_chunk_properties; | 66 Optional<ScopedPaintChunkProperties> scoped_paint_chunk_properties; |
54 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && | 67 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && |
55 !RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { | 68 !RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { |
56 if (const PropertyTreeState* contents_state = | 69 if (const PropertyTreeState* contents_state = |
57 frame_view_->TotalPropertyTreeStateForContents()) { | 70 frame_view_->TotalPropertyTreeStateForContents()) { |
58 PaintChunkProperties properties( | 71 PaintChunkProperties properties( |
59 context.GetPaintController().CurrentPaintChunkProperties()); | 72 context_.GetPaintController().CurrentPaintChunkProperties()); |
60 properties.property_tree_state = *contents_state; | 73 properties.property_tree_state = *contents_state; |
61 scoped_paint_chunk_properties.emplace(context.GetPaintController(), | 74 scoped_paint_chunk_properties.emplace(context_.GetPaintController(), |
62 *GetFrameView().GetLayoutView(), | 75 *GetFrameView().GetLayoutView(), |
63 properties); | 76 properties); |
64 } | 77 } |
65 } | 78 } |
66 | 79 |
67 TransformRecorder transform_recorder( | 80 TransformRecorder transform_recorder( |
68 context, *GetFrameView().GetLayoutView(), | 81 context_, *GetFrameView().GetLayoutView(), |
69 AffineTransform::Translation( | 82 AffineTransform::Translation( |
70 GetFrameView().X() - GetFrameView().ScrollX(), | 83 GetFrameView().X() - GetFrameView().ScrollX(), |
71 GetFrameView().Y() - GetFrameView().ScrollY())); | 84 GetFrameView().Y() - GetFrameView().ScrollY())); |
72 | 85 |
73 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { | 86 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { |
74 PaintContents(context, global_paint_flags, document_dirty_rect); | 87 PaintContents(global_paint_flags, document_dirty_rect); |
75 } else { | 88 } else { |
76 ClipRecorder clip_recorder(context, *GetFrameView().GetLayoutView(), | 89 ClipRecorder clip_recorder(context_, *GetFrameView().GetLayoutView(), |
77 DisplayItem::kClipFrameToVisibleContentRect, | 90 DisplayItem::kClipFrameToVisibleContentRect, |
78 GetFrameView().VisibleContentRect()); | 91 GetFrameView().VisibleContentRect()); |
79 | 92 |
80 PaintContents(context, global_paint_flags, document_dirty_rect); | 93 PaintContents(global_paint_flags, document_dirty_rect); |
81 } | 94 } |
82 } | 95 } |
83 | 96 |
84 if (should_paint_scrollbars) { | 97 if (should_paint_scrollbars) { |
85 DCHECK(!RuntimeEnabledFeatures::rootLayerScrollingEnabled()); | 98 DCHECK(!RuntimeEnabledFeatures::rootLayerScrollingEnabled()); |
86 IntRect scroll_view_dirty_rect = rect.rect_; | 99 IntRect scroll_view_dirty_rect = rect.rect_; |
87 IntRect visible_area_with_scrollbars( | 100 IntRect visible_area_with_scrollbars( |
88 GetFrameView().Location(), | 101 GetFrameView().Location(), |
89 GetFrameView().VisibleContentRect(kIncludeScrollbars).Size()); | 102 GetFrameView().VisibleContentRect(kIncludeScrollbars).Size()); |
90 scroll_view_dirty_rect.Intersect(visible_area_with_scrollbars); | 103 scroll_view_dirty_rect.Intersect(visible_area_with_scrollbars); |
91 scroll_view_dirty_rect.MoveBy(-GetFrameView().Location()); | 104 scroll_view_dirty_rect.MoveBy(-GetFrameView().Location()); |
92 | 105 |
93 Optional<ScopedPaintChunkProperties> scoped_paint_chunk_properties; | 106 Optional<ScopedPaintChunkProperties> scoped_paint_chunk_properties; |
94 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) { | 107 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) { |
95 if (const PropertyTreeState* contents_state = | 108 if (const PropertyTreeState* contents_state = |
96 frame_view_->TotalPropertyTreeStateForContents()) { | 109 frame_view_->TotalPropertyTreeStateForContents()) { |
97 // The scrollbar's property nodes are similar to the frame view's | 110 // The scrollbar's property nodes are similar to the frame view's |
98 // contents state but we want to exclude the content-specific | 111 // contents state but we want to exclude the content-specific |
99 // properties. This prevents the scrollbars from scrolling, for example. | 112 // properties. This prevents the scrollbars from scrolling, for example. |
100 PaintChunkProperties properties( | 113 PaintChunkProperties properties( |
101 context.GetPaintController().CurrentPaintChunkProperties()); | 114 context_.GetPaintController().CurrentPaintChunkProperties()); |
102 properties.property_tree_state.SetTransform( | 115 properties.property_tree_state.SetTransform( |
103 frame_view_->PreTranslation()); | 116 frame_view_->PreTranslation()); |
104 properties.property_tree_state.SetClip( | 117 properties.property_tree_state.SetClip( |
105 frame_view_->ContentClip()->Parent()); | 118 frame_view_->ContentClip()->Parent()); |
106 properties.property_tree_state.SetEffect(contents_state->Effect()); | 119 properties.property_tree_state.SetEffect(contents_state->Effect()); |
107 scoped_paint_chunk_properties.emplace(context.GetPaintController(), | 120 scoped_paint_chunk_properties.emplace(context_.GetPaintController(), |
108 *GetFrameView().GetLayoutView(), | 121 *GetFrameView().GetLayoutView(), |
109 properties); | 122 properties); |
110 } | 123 } |
111 } | 124 } |
112 | 125 |
113 TransformRecorder transform_recorder( | 126 TransformRecorder transform_recorder( |
114 context, *GetFrameView().GetLayoutView(), | 127 context_, *GetFrameView().GetLayoutView(), |
115 AffineTransform::Translation(GetFrameView().X(), GetFrameView().Y())); | 128 AffineTransform::Translation(GetFrameView().X(), GetFrameView().Y())); |
116 | 129 |
117 ClipRecorder recorder( | 130 ClipRecorder recorder( |
118 context, *GetFrameView().GetLayoutView(), | 131 context_, *GetFrameView().GetLayoutView(), |
119 DisplayItem::kClipFrameScrollbars, | 132 DisplayItem::kClipFrameScrollbars, |
120 IntRect(IntPoint(), visible_area_with_scrollbars.Size())); | 133 IntRect(IntPoint(), visible_area_with_scrollbars.Size())); |
121 | 134 |
122 PaintScrollbars(context, scroll_view_dirty_rect); | 135 PaintScrollbars(scroll_view_dirty_rect); |
123 } | 136 } |
124 } | 137 } |
125 | 138 |
126 void FramePainter::PaintContents(GraphicsContext& context, | 139 void FramePainter::PaintContents(const GlobalPaintFlags global_paint_flags, |
127 const GlobalPaintFlags global_paint_flags, | |
128 const IntRect& rect) { | 140 const IntRect& rect) { |
129 Document* document = GetFrameView().GetFrame().GetDocument(); | 141 Document* document = GetFrameView().GetFrame().GetDocument(); |
130 | 142 |
131 if (GetFrameView().ShouldThrottleRendering() || !document->IsActive()) | 143 if (GetFrameView().ShouldThrottleRendering() || !document->IsActive()) |
132 return; | 144 return; |
133 | 145 |
134 LayoutView* layout_view = GetFrameView().GetLayoutView(); | 146 LayoutView* layout_view = GetFrameView().GetLayoutView(); |
135 if (!layout_view) { | 147 if (!layout_view) { |
136 DLOG(ERROR) << "called FramePainter::paint with nil layoutObject"; | 148 DLOG(ERROR) << "called FramePainter::paint with nil layoutObject"; |
137 return; | 149 return; |
(...skipping 29 matching lines...) Expand all Loading... |
167 #if DCHECK_IS_ON() | 179 #if DCHECK_IS_ON() |
168 layout_view->AssertSubtreeIsLaidOut(); | 180 layout_view->AssertSubtreeIsLaidOut(); |
169 LayoutObject::SetLayoutNeededForbiddenScope forbid_set_needs_layout( | 181 LayoutObject::SetLayoutNeededForbiddenScope forbid_set_needs_layout( |
170 root_layer->GetLayoutObject()); | 182 root_layer->GetLayoutObject()); |
171 #endif | 183 #endif |
172 | 184 |
173 PaintLayerPainter layer_painter(*root_layer); | 185 PaintLayerPainter layer_painter(*root_layer); |
174 | 186 |
175 float device_scale_factor = blink::DeviceScaleFactorDeprecated( | 187 float device_scale_factor = blink::DeviceScaleFactorDeprecated( |
176 root_layer->GetLayoutObject().GetFrame()); | 188 root_layer->GetLayoutObject().GetFrame()); |
177 context.SetDeviceScaleFactor(device_scale_factor); | 189 context_.SetDeviceScaleFactor(device_scale_factor); |
178 | 190 |
179 layer_painter.Paint(context, LayoutRect(rect), local_paint_flags); | 191 layer_painter.Paint(context_, LayoutRect(rect), local_paint_flags); |
180 | 192 |
181 if (root_layer->ContainsDirtyOverlayScrollbars()) | 193 if (root_layer->ContainsDirtyOverlayScrollbars()) |
182 layer_painter.PaintOverlayScrollbars(context, LayoutRect(rect), | 194 layer_painter.PaintOverlayScrollbars(context_, LayoutRect(rect), |
183 local_paint_flags); | 195 local_paint_flags); |
184 | 196 |
185 // Regions may have changed as a result of the visibility/z-index of element | 197 // Regions may have changed as a result of the visibility/z-index of element |
186 // changing. | 198 // changing. |
187 if (document->AnnotatedRegionsDirty()) | 199 if (document->AnnotatedRegionsDirty()) |
188 GetFrameView().UpdateDocumentAnnotatedRegions(); | 200 GetFrameView().UpdateDocumentAnnotatedRegions(); |
189 | 201 |
190 if (is_top_level_painter) { | 202 if (is_top_level_painter) { |
191 // Everything that happens after paintContents completions is considered | 203 // Everything that happens after paintContents completions is considered |
192 // to be part of the next frame. | 204 // to be part of the next frame. |
193 GetMemoryCache()->UpdateFramePaintTimestamp(); | 205 GetMemoryCache()->UpdateFramePaintTimestamp(); |
194 in_paint_contents_ = false; | 206 in_paint_contents_ = false; |
195 } | 207 } |
196 | 208 |
197 probe::didPaint(layout_view->GetFrame(), 0, context, LayoutRect(rect)); | 209 probe::didPaint(layout_view->GetFrame(), 0, context_, LayoutRect(rect)); |
198 } | 210 } |
199 | 211 |
200 void FramePainter::PaintScrollbars(GraphicsContext& context, | 212 void FramePainter::PaintScrollbars(const IntRect& rect) { |
201 const IntRect& rect) { | |
202 if (GetFrameView().HorizontalScrollbar() && | 213 if (GetFrameView().HorizontalScrollbar() && |
203 !GetFrameView().LayerForHorizontalScrollbar()) | 214 !GetFrameView().LayerForHorizontalScrollbar()) |
204 PaintScrollbar(context, *GetFrameView().HorizontalScrollbar(), rect); | 215 PaintScrollbar(*GetFrameView().HorizontalScrollbar(), rect); |
205 if (GetFrameView().VerticalScrollbar() && | 216 if (GetFrameView().VerticalScrollbar() && |
206 !GetFrameView().LayerForVerticalScrollbar()) | 217 !GetFrameView().LayerForVerticalScrollbar()) |
207 PaintScrollbar(context, *GetFrameView().VerticalScrollbar(), rect); | 218 PaintScrollbar(*GetFrameView().VerticalScrollbar(), rect); |
208 | 219 |
209 if (GetFrameView().LayerForScrollCorner() || | 220 if (GetFrameView().LayerForScrollCorner() || |
210 !GetFrameView().IsScrollCornerVisible()) { | 221 !GetFrameView().IsScrollCornerVisible()) { |
211 return; | 222 return; |
212 } | 223 } |
213 | 224 |
214 PaintScrollCorner(context, GetFrameView().ScrollCornerRect()); | 225 PaintScrollCorner(GetFrameView().ScrollCornerRect()); |
215 } | 226 } |
216 | 227 |
217 void FramePainter::PaintScrollCorner(GraphicsContext& context, | 228 void FramePainter::PaintScrollCorner(const IntRect& corner_rect) { |
218 const IntRect& corner_rect) { | |
219 if (GetFrameView().ScrollCorner()) { | 229 if (GetFrameView().ScrollCorner()) { |
220 bool needs_background = GetFrameView().GetFrame().IsMainFrame(); | 230 bool needs_background = GetFrameView().GetFrame().IsMainFrame(); |
221 if (needs_background && | 231 if (needs_background && |
222 !LayoutObjectDrawingRecorder::UseCachedDrawingIfPossible( | 232 !LayoutObjectDrawingRecorder::UseCachedDrawingIfPossible( |
223 context, *GetFrameView().GetLayoutView(), | 233 context_, *GetFrameView().GetLayoutView(), |
224 DisplayItem::kScrollbarCorner)) { | 234 DisplayItem::kScrollbarCorner)) { |
225 LayoutObjectDrawingRecorder drawing_recorder( | 235 LayoutObjectDrawingRecorder drawing_recorder( |
226 context, *GetFrameView().GetLayoutView(), | 236 context_, *GetFrameView().GetLayoutView(), |
227 DisplayItem::kScrollbarCorner, FloatRect(corner_rect)); | 237 DisplayItem::kScrollbarCorner, FloatRect(corner_rect)); |
228 context.FillRect(corner_rect, GetFrameView().BaseBackgroundColor()); | 238 context_.FillRect(corner_rect, GetFrameView().BaseBackgroundColor()); |
229 } | 239 } |
230 ScrollbarPainter::PaintIntoRect(*GetFrameView().ScrollCorner(), context, | 240 ScrollbarPainter::PaintIntoRect(*GetFrameView().ScrollCorner(), context_, |
231 corner_rect.Location(), | 241 corner_rect.Location(), |
232 LayoutRect(corner_rect)); | 242 LayoutRect(corner_rect)); |
233 return; | 243 return; |
234 } | 244 } |
235 | 245 |
236 ScrollbarTheme* theme = nullptr; | 246 ScrollbarTheme* theme = nullptr; |
237 | 247 |
238 if (GetFrameView().HorizontalScrollbar()) { | 248 if (GetFrameView().HorizontalScrollbar()) { |
239 theme = &GetFrameView().HorizontalScrollbar()->GetTheme(); | 249 theme = &GetFrameView().HorizontalScrollbar()->GetTheme(); |
240 } else if (GetFrameView().VerticalScrollbar()) { | 250 } else if (GetFrameView().VerticalScrollbar()) { |
241 theme = &GetFrameView().VerticalScrollbar()->GetTheme(); | 251 theme = &GetFrameView().VerticalScrollbar()->GetTheme(); |
242 } else { | 252 } else { |
243 NOTREACHED(); | 253 NOTREACHED(); |
244 } | 254 } |
245 | 255 |
246 theme->PaintScrollCorner(context, *GetFrameView().GetLayoutView(), | 256 theme->PaintScrollCorner(context_, *GetFrameView().GetLayoutView(), |
247 corner_rect); | 257 corner_rect); |
248 } | 258 } |
249 | 259 |
250 void FramePainter::PaintScrollbar(GraphicsContext& context, | 260 void FramePainter::PaintScrollbar(Scrollbar& bar, const IntRect& rect) { |
251 Scrollbar& bar, | |
252 const IntRect& rect) { | |
253 bool needs_background = | 261 bool needs_background = |
254 bar.IsCustomScrollbar() && GetFrameView().GetFrame().IsMainFrame(); | 262 bar.IsCustomScrollbar() && GetFrameView().GetFrame().IsMainFrame(); |
255 if (needs_background) { | 263 if (needs_background) { |
256 IntRect to_fill = bar.FrameRect(); | 264 IntRect to_fill = bar.FrameRect(); |
257 to_fill.Intersect(rect); | 265 to_fill.Intersect(rect); |
258 context.FillRect(to_fill, GetFrameView().BaseBackgroundColor()); | 266 context_.FillRect(to_fill, GetFrameView().BaseBackgroundColor()); |
259 } | 267 } |
260 | 268 |
261 bar.Paint(context, CullRect(rect)); | 269 bar.Paint(context_, CullRect(rect)); |
262 } | 270 } |
263 | 271 |
264 const FrameView& FramePainter::GetFrameView() { | 272 const FrameView& FramePainter::GetFrameView() const { |
265 DCHECK(frame_view_); | 273 DCHECK(frame_view_); |
266 return *frame_view_; | 274 return *frame_view_; |
267 } | 275 } |
268 | 276 |
| 277 void FramePainter::NotifyPaint(const FrameFirstPaint& frame_first_paint) const { |
| 278 const LocalFrame& frame = GetFrameView().GetFrame(); |
| 279 DCHECK(frame.GetDocument()); |
| 280 |
| 281 PaintTiming::From(*frame.GetDocument()) |
| 282 .NotifyPaint(frame_first_paint.first_painted, |
| 283 frame_first_paint.text_painted, |
| 284 frame_first_paint.image_painted); |
| 285 } |
| 286 |
269 } // namespace blink | 287 } // namespace blink |
OLD | NEW |