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

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

Issue 2835763002: Use swap-promise to improve first* paint times (Closed)
Patch Set: remove printfs 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/PaintTiming.h" 5 #include "core/paint/PaintTiming.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/frame/FrameView.h" 8 #include "core/frame/FrameView.h"
9 #include "core/frame/LocalDOMWindow.h" 9 #include "core/frame/LocalDOMWindow.h"
10 #include "core/frame/LocalFrame.h" 10 #include "core/frame/LocalFrame.h"
11 #include "core/loader/DocumentLoader.h" 11 #include "core/loader/DocumentLoader.h"
12 #include "core/page/ChromeClient.h"
13 #include "core/page/Page.h"
12 #include "core/timing/DOMWindowPerformance.h" 14 #include "core/timing/DOMWindowPerformance.h"
13 #include "core/timing/Performance.h" 15 #include "core/timing/Performance.h"
14 #include "platform/WebFrameScheduler.h" 16 #include "platform/WebFrameScheduler.h"
15 #include "platform/instrumentation/tracing/TraceEvent.h" 17 #include "platform/instrumentation/tracing/TraceEvent.h"
18 #include "public/platform/WebLayerTreeView.h"
16 19
17 namespace blink { 20 namespace blink {
18 21
19 namespace { 22 namespace {
20 23
21 Performance* GetPerformanceInstance(LocalFrame* frame) { 24 Performance* GetPerformanceInstance(LocalFrame* frame) {
22 Performance* performance = nullptr; 25 Performance* performance = nullptr;
23 if (frame && frame->DomWindow()) { 26 if (frame && frame->DomWindow()) {
24 performance = DOMWindowPerformance::performance(*frame->DomWindow()); 27 performance = DOMWindowPerformance::performance(*frame->DomWindow());
25 } 28 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 96 }
94 97
95 void PaintTiming::SetFirstMeaningfulPaint(double stamp) { 98 void PaintTiming::SetFirstMeaningfulPaint(double stamp) {
96 DCHECK_EQ(first_meaningful_paint_, 0.0); 99 DCHECK_EQ(first_meaningful_paint_, 0.0);
97 first_meaningful_paint_ = stamp; 100 first_meaningful_paint_ = stamp;
98 TRACE_EVENT_MARK_WITH_TIMESTAMP1( 101 TRACE_EVENT_MARK_WITH_TIMESTAMP1(
99 "loading,rail,devtools.timeline", "firstMeaningfulPaint", 102 "loading,rail,devtools.timeline", "firstMeaningfulPaint",
100 TraceEvent::ToTraceTimestamp(first_meaningful_paint_), "frame", 103 TraceEvent::ToTraceTimestamp(first_meaningful_paint_), "frame",
101 GetFrame()); 104 GetFrame());
102 NotifyPaintTimingChanged(); 105 NotifyPaintTimingChanged();
106 RegisterNotifySwapTime(PaintEvent::kFirstMeaningfulPaint);
103 } 107 }
104 108
105 void PaintTiming::NotifyPaint(bool is_first_paint, 109 void PaintTiming::NotifyPaint(bool is_first_paint,
106 bool text_painted, 110 bool text_painted,
107 bool image_painted) { 111 bool image_painted) {
108 if (is_first_paint) 112 if (is_first_paint)
109 MarkFirstPaint(); 113 MarkFirstPaint();
110 if (text_painted) 114 if (text_painted)
111 MarkFirstTextPaint(); 115 MarkFirstTextPaint();
112 if (image_painted) 116 if (image_painted)
(...skipping 22 matching lines...) Expand all
135 void PaintTiming::SetFirstPaint(double stamp) { 139 void PaintTiming::SetFirstPaint(double stamp) {
136 if (first_paint_ != 0.0) 140 if (first_paint_ != 0.0)
137 return; 141 return;
138 first_paint_ = stamp; 142 first_paint_ = stamp;
139 Performance* performance = GetPerformanceInstance(GetFrame()); 143 Performance* performance = GetPerformanceInstance(GetFrame());
140 if (performance) 144 if (performance)
141 performance->AddFirstPaintTiming(first_paint_); 145 performance->AddFirstPaintTiming(first_paint_);
142 146
143 TRACE_EVENT_INSTANT1("loading,rail,devtools.timeline", "firstPaint", 147 TRACE_EVENT_INSTANT1("loading,rail,devtools.timeline", "firstPaint",
144 TRACE_EVENT_SCOPE_PROCESS, "frame", GetFrame()); 148 TRACE_EVENT_SCOPE_PROCESS, "frame", GetFrame());
149 RegisterNotifySwapTime(PaintEvent::kFirstPaint);
145 } 150 }
146 151
147 void PaintTiming::SetFirstContentfulPaint(double stamp) { 152 void PaintTiming::SetFirstContentfulPaint(double stamp) {
148 if (first_contentful_paint_ != 0.0) 153 if (first_contentful_paint_ != 0.0)
149 return; 154 return;
150 SetFirstPaint(stamp); 155 SetFirstPaint(stamp);
151 first_contentful_paint_ = stamp; 156 first_contentful_paint_ = stamp;
152 Performance* performance = GetPerformanceInstance(GetFrame()); 157 Performance* performance = GetPerformanceInstance(GetFrame());
153 if (performance) 158 if (performance)
154 performance->AddFirstContentfulPaintTiming(first_contentful_paint_); 159 performance->AddFirstContentfulPaintTiming(first_contentful_paint_);
160
155 TRACE_EVENT_INSTANT1("loading,rail,devtools.timeline", "firstContentfulPaint", 161 TRACE_EVENT_INSTANT1("loading,rail,devtools.timeline", "firstContentfulPaint",
156 TRACE_EVENT_SCOPE_PROCESS, "frame", GetFrame()); 162 TRACE_EVENT_SCOPE_PROCESS, "frame", GetFrame());
163 RegisterNotifySwapTime(PaintEvent::kFirstContentfulPaint);
164 }
165
166 void PaintTiming::RegisterNotifySwapTime(PaintEvent event) {
167 // ReportSwapTime on layerTreeView will queue a swap-promise, the callback is
168 // called when the swap for current render frame completes or fails to happen.
169 if (GetFrame()->GetPage() &&
enne (OOO) 2017/05/01 21:58:11 style nit: could rewrite this as "if (!GetPage) re
panicker 2017/05/02 00:57:04 Done.
170 GetFrame()->GetPage()->GetChromeClient().GetWebLayerTreeView(
171 GetFrame())) {
172 WebLayerTreeView* layerTreeView =
173 GetFrame()->GetPage()->GetChromeClient().GetWebLayerTreeView(
174 GetFrame());
175 layerTreeView->NotifySwapTime(ConvertToBaseCallback(WTF::Bind(
176 &PaintTiming::ReportSwapTime, WrapWeakPersistent(this), event)));
177 }
178 }
179
180 void PaintTiming::ReportSwapTime(PaintEvent event,
181 bool did_swap,
182 double timestamp) {
183 if (did_swap) {
enne (OOO) 2017/05/01 21:58:11 style nit: could early out here instead of indenti
panicker 2017/05/02 00:57:04 Done.
184 switch (event) {
185 case PaintEvent::kFirstPaint:
186 first_paint_swap_ = timestamp;
187 break;
188 case PaintEvent::kFirstContentfulPaint:
189 first_contentful_paint_swap_ = timestamp;
190 break;
191 case PaintEvent::kFirstMeaningfulPaint:
192 first_meaningful_paint_swap_ = timestamp;
193 break;
194 }
195 }
157 } 196 }
158 197
159 } // namespace blink 198 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698