| OLD | NEW |
| 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/LocalDOMWindow.h" | 8 #include "core/frame/LocalDOMWindow.h" |
| 9 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
| 10 #include "core/frame/LocalFrameView.h" | 10 #include "core/frame/LocalFrameView.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 134 |
| 135 void PaintTiming::NotifyPaintTimingChanged() { | 135 void PaintTiming::NotifyPaintTimingChanged() { |
| 136 if (GetSupplementable()->Loader()) | 136 if (GetSupplementable()->Loader()) |
| 137 GetSupplementable()->Loader()->DidChangePerformanceTiming(); | 137 GetSupplementable()->Loader()->DidChangePerformanceTiming(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void PaintTiming::SetFirstPaint(double stamp) { | 140 void PaintTiming::SetFirstPaint(double stamp) { |
| 141 if (first_paint_ != 0.0) | 141 if (first_paint_ != 0.0) |
| 142 return; | 142 return; |
| 143 first_paint_ = stamp; | 143 first_paint_ = stamp; |
| 144 Performance* performance = GetPerformanceInstance(GetFrame()); | |
| 145 if (performance) | |
| 146 performance->AddFirstPaintTiming(first_paint_); | |
| 147 | |
| 148 TRACE_EVENT_INSTANT1("loading,rail,devtools.timeline", "firstPaint", | 144 TRACE_EVENT_INSTANT1("loading,rail,devtools.timeline", "firstPaint", |
| 149 TRACE_EVENT_SCOPE_PROCESS, "frame", GetFrame()); | 145 TRACE_EVENT_SCOPE_PROCESS, "frame", GetFrame()); |
| 150 RegisterNotifySwapTime(PaintEvent::kFirstPaint); | 146 RegisterNotifySwapTime(PaintEvent::kFirstPaint); |
| 151 } | 147 } |
| 152 | 148 |
| 153 void PaintTiming::SetFirstContentfulPaint(double stamp) { | 149 void PaintTiming::SetFirstContentfulPaint(double stamp) { |
| 154 if (first_contentful_paint_ != 0.0) | 150 if (first_contentful_paint_ != 0.0) |
| 155 return; | 151 return; |
| 156 SetFirstPaint(stamp); | 152 SetFirstPaint(stamp); |
| 157 first_contentful_paint_ = stamp; | 153 first_contentful_paint_ = stamp; |
| 158 Performance* performance = GetPerformanceInstance(GetFrame()); | |
| 159 if (performance) | |
| 160 performance->AddFirstContentfulPaintTiming(first_contentful_paint_); | |
| 161 | |
| 162 TRACE_EVENT_INSTANT1("loading,rail,devtools.timeline", "firstContentfulPaint", | 154 TRACE_EVENT_INSTANT1("loading,rail,devtools.timeline", "firstContentfulPaint", |
| 163 TRACE_EVENT_SCOPE_PROCESS, "frame", GetFrame()); | 155 TRACE_EVENT_SCOPE_PROCESS, "frame", GetFrame()); |
| 164 RegisterNotifySwapTime(PaintEvent::kFirstContentfulPaint); | 156 RegisterNotifySwapTime(PaintEvent::kFirstContentfulPaint); |
| 165 GetFrame()->Loader().Progress().DidFirstContentfulPaint(); | 157 GetFrame()->Loader().Progress().DidFirstContentfulPaint(); |
| 166 } | 158 } |
| 167 | 159 |
| 168 void PaintTiming::RegisterNotifySwapTime(PaintEvent event) { | 160 void PaintTiming::RegisterNotifySwapTime(PaintEvent event) { |
| 169 // ReportSwapTime on layerTreeView will queue a swap-promise, the callback is | 161 // ReportSwapTime on layerTreeView will queue a swap-promise, the callback is |
| 170 // called when the swap for current render frame completes or fails to happen. | 162 // called when the swap for current render frame completes or fails to happen. |
| 171 if (!GetFrame() || !GetFrame()->GetPage()) | 163 if (!GetFrame() || !GetFrame()->GetPage()) |
| 172 return; | 164 return; |
| 173 if (WebLayerTreeView* layerTreeView = | 165 if (WebLayerTreeView* layerTreeView = |
| 174 GetFrame()->GetPage()->GetChromeClient().GetWebLayerTreeView( | 166 GetFrame()->GetPage()->GetChromeClient().GetWebLayerTreeView( |
| 175 GetFrame())) { | 167 GetFrame())) { |
| 176 layerTreeView->NotifySwapTime(ConvertToBaseCallback( | 168 layerTreeView->NotifySwapTime(ConvertToBaseCallback( |
| 177 WTF::Bind(&PaintTiming::ReportSwapTime, | 169 WTF::Bind(&PaintTiming::ReportSwapTime, |
| 178 WrapCrossThreadWeakPersistent(this), event))); | 170 WrapCrossThreadWeakPersistent(this), event))); |
| 179 } | 171 } |
| 180 } | 172 } |
| 181 | 173 |
| 182 void PaintTiming::ReportSwapTime(PaintEvent event, | 174 void PaintTiming::ReportSwapTime(PaintEvent event, |
| 183 bool did_swap, | 175 bool did_swap, |
| 184 double timestamp) { | 176 double timestamp) { |
| 185 if (!did_swap) | 177 if (!did_swap) |
| 186 return; | 178 return; |
| 179 Performance* performance = GetPerformanceInstance(GetFrame()); |
| 187 switch (event) { | 180 switch (event) { |
| 188 case PaintEvent::kFirstPaint: | 181 case PaintEvent::kFirstPaint: |
| 189 first_paint_swap_ = timestamp; | 182 first_paint_swap_ = timestamp; |
| 183 if (performance) |
| 184 performance->AddFirstPaintTiming(first_paint_); |
| 190 return; | 185 return; |
| 191 case PaintEvent::kFirstContentfulPaint: | 186 case PaintEvent::kFirstContentfulPaint: |
| 192 first_contentful_paint_swap_ = timestamp; | 187 first_contentful_paint_swap_ = timestamp; |
| 188 if (performance) |
| 189 performance->AddFirstContentfulPaintTiming(first_contentful_paint_); |
| 193 return; | 190 return; |
| 194 case PaintEvent::kFirstMeaningfulPaint: | 191 case PaintEvent::kFirstMeaningfulPaint: |
| 195 first_meaningful_paint_swap_ = timestamp; | 192 first_meaningful_paint_swap_ = timestamp; |
| 196 return; | 193 return; |
| 197 } | 194 } |
| 198 NOTREACHED(); | 195 NOTREACHED(); |
| 199 } | 196 } |
| 200 | 197 |
| 201 } // namespace blink | 198 } // namespace blink |
| OLD | NEW |