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