| 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/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
| 10 #include "core/loader/DocumentLoader.h" | 10 #include "core/loader/DocumentLoader.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 TRACE_EVENT_MARK_WITH_TIMESTAMP1( | 65 TRACE_EVENT_MARK_WITH_TIMESTAMP1( |
| 66 "blink.user_timing,rail", "firstImagePaint", | 66 "blink.user_timing,rail", "firstImagePaint", |
| 67 TraceEvent::toTraceTimestamp(m_firstImagePaint), "frame", frame()); | 67 TraceEvent::toTraceTimestamp(m_firstImagePaint), "frame", frame()); |
| 68 notifyPaintTimingChanged(); | 68 notifyPaintTimingChanged(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void PaintTiming::markFirstMeaningfulPaintCandidate() { | 71 void PaintTiming::markFirstMeaningfulPaintCandidate() { |
| 72 if (m_firstMeaningfulPaintCandidate) | 72 if (m_firstMeaningfulPaintCandidate) |
| 73 return; | 73 return; |
| 74 m_firstMeaningfulPaintCandidate = monotonicallyIncreasingTime(); | 74 m_firstMeaningfulPaintCandidate = monotonicallyIncreasingTime(); |
| 75 if (m_document->frame() && m_document->frame()->view() && | 75 if (frame() && frame()->view() && !frame()->view()->parent()) { |
| 76 !m_document->frame()->view()->parent()) { | 76 frame()->frameScheduler()->onFirstMeaningfulPaint(); |
| 77 m_document->frame()->frameScheduler()->onFirstMeaningfulPaint(); | |
| 78 } | 77 } |
| 79 } | 78 } |
| 80 | 79 |
| 81 void PaintTiming::setFirstMeaningfulPaint(double stamp) { | 80 void PaintTiming::setFirstMeaningfulPaint(double stamp) { |
| 82 DCHECK_EQ(m_firstMeaningfulPaint, 0.0); | 81 DCHECK_EQ(m_firstMeaningfulPaint, 0.0); |
| 83 m_firstMeaningfulPaint = stamp; | 82 m_firstMeaningfulPaint = stamp; |
| 84 TRACE_EVENT_MARK_WITH_TIMESTAMP1( | 83 TRACE_EVENT_MARK_WITH_TIMESTAMP1( |
| 85 "blink.user_timing", "firstMeaningfulPaint", | 84 "blink.user_timing", "firstMeaningfulPaint", |
| 86 TraceEvent::toTraceTimestamp(m_firstMeaningfulPaint), "frame", frame()); | 85 TraceEvent::toTraceTimestamp(m_firstMeaningfulPaint), "frame", frame()); |
| 87 notifyPaintTimingChanged(); | 86 notifyPaintTimingChanged(); |
| 88 } | 87 } |
| 89 | 88 |
| 90 void PaintTiming::notifyPaint(bool isFirstPaint, | 89 void PaintTiming::notifyPaint(bool isFirstPaint, |
| 91 bool textPainted, | 90 bool textPainted, |
| 92 bool imagePainted) { | 91 bool imagePainted) { |
| 93 if (isFirstPaint) | 92 if (isFirstPaint) |
| 94 markFirstPaint(); | 93 markFirstPaint(); |
| 95 if (textPainted) | 94 if (textPainted) |
| 96 markFirstTextPaint(); | 95 markFirstTextPaint(); |
| 97 if (imagePainted) | 96 if (imagePainted) |
| 98 markFirstImagePaint(); | 97 markFirstImagePaint(); |
| 99 m_fmpDetector->notifyPaint(); | 98 m_fmpDetector->notifyPaint(); |
| 100 } | 99 } |
| 101 | 100 |
| 102 DEFINE_TRACE(PaintTiming) { | 101 DEFINE_TRACE(PaintTiming) { |
| 103 visitor->trace(m_document); | |
| 104 visitor->trace(m_fmpDetector); | 102 visitor->trace(m_fmpDetector); |
| 105 Supplement<Document>::trace(visitor); | 103 Supplement<Document>::trace(visitor); |
| 106 } | 104 } |
| 107 | 105 |
| 108 PaintTiming::PaintTiming(Document& document) | 106 PaintTiming::PaintTiming(Document& document) |
| 109 : m_document(document), | 107 : Supplement<Document>(document), |
| 110 m_fmpDetector(new FirstMeaningfulPaintDetector(this)) {} | 108 m_fmpDetector(new FirstMeaningfulPaintDetector(this)) {} |
| 111 | 109 |
| 112 LocalFrame* PaintTiming::frame() const { | 110 LocalFrame* PaintTiming::frame() const { |
| 113 return m_document ? m_document->frame() : nullptr; | 111 return host()->frame(); |
| 114 } | 112 } |
| 115 | 113 |
| 116 void PaintTiming::notifyPaintTimingChanged() { | 114 void PaintTiming::notifyPaintTimingChanged() { |
| 117 if (m_document && m_document->loader()) | 115 if (host()->loader()) |
| 118 m_document->loader()->didChangePerformanceTiming(); | 116 host()->loader()->didChangePerformanceTiming(); |
| 119 } | 117 } |
| 120 | 118 |
| 121 void PaintTiming::setFirstPaint(double stamp) { | 119 void PaintTiming::setFirstPaint(double stamp) { |
| 122 if (m_firstPaint != 0.0) | 120 if (m_firstPaint != 0.0) |
| 123 return; | 121 return; |
| 124 m_firstPaint = stamp; | 122 m_firstPaint = stamp; |
| 125 TRACE_EVENT_INSTANT1("blink.user_timing,rail", "firstPaint", | 123 TRACE_EVENT_INSTANT1("blink.user_timing,rail", "firstPaint", |
| 126 TRACE_EVENT_SCOPE_PROCESS, "frame", frame()); | 124 TRACE_EVENT_SCOPE_PROCESS, "frame", frame()); |
| 127 } | 125 } |
| 128 | 126 |
| 129 void PaintTiming::setFirstContentfulPaint(double stamp) { | 127 void PaintTiming::setFirstContentfulPaint(double stamp) { |
| 130 if (m_firstContentfulPaint != 0.0) | 128 if (m_firstContentfulPaint != 0.0) |
| 131 return; | 129 return; |
| 132 setFirstPaint(stamp); | 130 setFirstPaint(stamp); |
| 133 m_firstContentfulPaint = stamp; | 131 m_firstContentfulPaint = stamp; |
| 134 TRACE_EVENT_INSTANT1("blink.user_timing,rail", "firstContentfulPaint", | 132 TRACE_EVENT_INSTANT1("blink.user_timing,rail", "firstContentfulPaint", |
| 135 TRACE_EVENT_SCOPE_PROCESS, "frame", frame()); | 133 TRACE_EVENT_SCOPE_PROCESS, "frame", frame()); |
| 136 } | 134 } |
| 137 | 135 |
| 138 } // namespace blink | 136 } // namespace blink |
| OLD | NEW |