| 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/loader/DocumentLoader.h" | 8 #include "core/loader/DocumentLoader.h" |
| 9 #include "platform/TraceEvent.h" | 9 #include "platform/TraceEvent.h" |
| 10 #include "wtf/RawPtr.h" | 10 #include "wtf/RawPtr.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 static const char kSupplementName[] = "PaintTiming"; | 14 static const char kSupplementName[] = "PaintTiming"; |
| 15 | 15 |
| 16 PaintTiming& PaintTiming::from(Document& document) | 16 PaintTiming& PaintTiming::from(Document& document) |
| 17 { | 17 { |
| 18 PaintTiming* timing = static_cast<PaintTiming*>(WillBeHeapSupplement<Documen
t>::from(document, kSupplementName)); | 18 PaintTiming* timing = static_cast<PaintTiming*>(WillBeHeapSupplement<Documen
t>::from(document, kSupplementName)); |
| 19 if (!timing) { | 19 if (!timing) { |
| 20 timing = new PaintTiming(document); | 20 timing = new PaintTiming(document); |
| 21 WillBeHeapSupplement<Document>::provideTo(document, kSupplementName, ado
ptPtrWillBeNoop(timing)); | 21 WillBeHeapSupplement<Document>::provideTo(document, kSupplementName, ado
ptPtrWillBeNoop(timing)); |
| 22 } | 22 } |
| 23 return *timing; | 23 return *timing; |
| 24 } | 24 } |
| 25 | 25 |
| 26 PaintTiming::PaintTiming(Document& document) | |
| 27 : m_document(document) | |
| 28 { | |
| 29 } | |
| 30 | |
| 31 DEFINE_TRACE(PaintTiming) | |
| 32 { | |
| 33 visitor->trace(m_document); | |
| 34 } | |
| 35 | |
| 36 LocalFrame* PaintTiming::frame() const | |
| 37 { | |
| 38 return m_document ? m_document->frame() : nullptr; | |
| 39 } | |
| 40 | |
| 41 void PaintTiming::notifyPaintTimingChanged() | |
| 42 { | |
| 43 if (m_document && m_document->loader()) | |
| 44 m_document->loader()->didChangePerformanceTiming(); | |
| 45 } | |
| 46 | |
| 47 void PaintTiming::markFirstPaint() | 26 void PaintTiming::markFirstPaint() |
| 48 { | 27 { |
| 28 // Test that m_firstPaint is non-zero here, as well as in setFirstPaint, so |
| 29 // we avoid invoking monotonicallyIncreasingTime() on every call to |
| 30 // markFirstPaint(). |
| 49 if (m_firstPaint != 0.0) | 31 if (m_firstPaint != 0.0) |
| 50 return; | 32 return; |
| 51 m_firstPaint = monotonicallyIncreasingTime(); | 33 setFirstPaint(monotonicallyIncreasingTime()); |
| 52 TRACE_EVENT_INSTANT1("blink.user_timing", "firstPaint", TRACE_EVENT_SCOPE_PR
OCESS, "frame", frame()); | |
| 53 notifyPaintTimingChanged(); | 34 notifyPaintTimingChanged(); |
| 54 } | 35 } |
| 55 | 36 |
| 37 void PaintTiming::markFirstContentfulPaint() |
| 38 { |
| 39 // Test that m_firstContentfulPaint is non-zero here, as well as in |
| 40 // setFirstContentfulPaint, so we avoid invoking |
| 41 // monotonicallyIncreasingTime() on every call to |
| 42 // markFirstContentfulPaint(). |
| 43 if (m_firstContentfulPaint != 0.0) |
| 44 return; |
| 45 setFirstContentfulPaint(monotonicallyIncreasingTime()); |
| 46 notifyPaintTimingChanged(); |
| 47 } |
| 48 |
| 56 void PaintTiming::markFirstTextPaint() | 49 void PaintTiming::markFirstTextPaint() |
| 57 { | 50 { |
| 58 if (m_firstTextPaint != 0.0) | 51 if (m_firstTextPaint != 0.0) |
| 59 return; | 52 return; |
| 60 m_firstTextPaint = monotonicallyIncreasingTime(); | 53 m_firstTextPaint = monotonicallyIncreasingTime(); |
| 54 setFirstContentfulPaint(m_firstTextPaint); |
| 61 TRACE_EVENT_MARK_WITH_TIMESTAMP1("blink.user_timing", "firstTextPaint", m_fi
rstTextPaint, "frame", frame()); | 55 TRACE_EVENT_MARK_WITH_TIMESTAMP1("blink.user_timing", "firstTextPaint", m_fi
rstTextPaint, "frame", frame()); |
| 62 | 56 notifyPaintTimingChanged(); |
| 63 if (firstContentfulPaint() == 0.0) | |
| 64 markFirstContentfulPaint(); | |
| 65 else | |
| 66 notifyPaintTimingChanged(); | |
| 67 } | 57 } |
| 68 | 58 |
| 69 void PaintTiming::markFirstImagePaint() | 59 void PaintTiming::markFirstImagePaint() |
| 70 { | 60 { |
| 71 if (m_firstImagePaint != 0.0) | 61 if (m_firstImagePaint != 0.0) |
| 72 return; | 62 return; |
| 73 m_firstImagePaint = monotonicallyIncreasingTime(); | 63 m_firstImagePaint = monotonicallyIncreasingTime(); |
| 64 setFirstContentfulPaint(m_firstImagePaint); |
| 74 TRACE_EVENT_MARK_WITH_TIMESTAMP1("blink.user_timing", "firstImagePaint", m_f
irstImagePaint, "frame", frame()); | 65 TRACE_EVENT_MARK_WITH_TIMESTAMP1("blink.user_timing", "firstImagePaint", m_f
irstImagePaint, "frame", frame()); |
| 75 | 66 notifyPaintTimingChanged(); |
| 76 if (firstContentfulPaint() == 0.0) | |
| 77 markFirstContentfulPaint(); | |
| 78 else | |
| 79 notifyPaintTimingChanged(); | |
| 80 } | 67 } |
| 81 | 68 |
| 82 void PaintTiming::markFirstContentfulPaint() | 69 DEFINE_TRACE(PaintTiming) |
| 70 { |
| 71 visitor->trace(m_document); |
| 72 } |
| 73 |
| 74 PaintTiming::PaintTiming(Document& document) |
| 75 : m_document(document) |
| 76 { |
| 77 } |
| 78 |
| 79 LocalFrame* PaintTiming::frame() const |
| 80 { |
| 81 return m_document ? m_document->frame() : nullptr; |
| 82 } |
| 83 |
| 84 void PaintTiming::notifyPaintTimingChanged() |
| 85 { |
| 86 if (m_document && m_document->loader()) |
| 87 m_document->loader()->didChangePerformanceTiming(); |
| 88 } |
| 89 |
| 90 void PaintTiming::setFirstPaint(double stamp) |
| 91 { |
| 92 if (m_firstPaint != 0.0) |
| 93 return; |
| 94 m_firstPaint = stamp; |
| 95 TRACE_EVENT_INSTANT1("blink.user_timing", "firstPaint", TRACE_EVENT_SCOPE_PR
OCESS, "frame", frame()); |
| 96 } |
| 97 |
| 98 void PaintTiming::setFirstContentfulPaint(double stamp) |
| 83 { | 99 { |
| 84 if (m_firstContentfulPaint != 0.0) | 100 if (m_firstContentfulPaint != 0.0) |
| 85 return; | 101 return; |
| 86 m_firstContentfulPaint = monotonicallyIncreasingTime(); | 102 setFirstPaint(stamp); |
| 103 m_firstContentfulPaint = stamp; |
| 87 TRACE_EVENT_INSTANT1("blink.user_timing", "firstContentfulPaint", TRACE_EVEN
T_SCOPE_PROCESS, "frame", frame()); | 104 TRACE_EVENT_INSTANT1("blink.user_timing", "firstContentfulPaint", TRACE_EVEN
T_SCOPE_PROCESS, "frame", frame()); |
| 88 notifyPaintTimingChanged(); | |
| 89 } | 105 } |
| 90 | 106 |
| 91 } // namespace blink | 107 } // namespace blink |
| OLD | NEW |