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