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

Side by Side Diff: third_party/WebKit/Source/core/paint/FramePainter.cpp

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

Powered by Google App Engine
This is Rietveld 408576698