| 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 #ifndef PaintTiming_h | 5 #ifndef PaintTiming_h |
| 6 #define PaintTiming_h | 6 #define PaintTiming_h |
| 7 | 7 |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/paint/FirstMeaningfulPaintDetector.h" |
| 9 #include "platform/Supplementable.h" | 10 #include "platform/Supplementable.h" |
| 10 #include "platform/heap/Handle.h" | 11 #include "platform/heap/Handle.h" |
| 11 #include "wtf/Noncopyable.h" | 12 #include "wtf/Noncopyable.h" |
| 12 | 13 |
| 13 namespace blink { | 14 namespace blink { |
| 14 | 15 |
| 15 class LocalFrame; | 16 class LocalFrame; |
| 16 | 17 |
| 17 // PaintTiming is responsible for tracking paint-related timings for a given | 18 // PaintTiming is responsible for tracking paint-related timings for a given |
| 18 // document. | 19 // document. |
| 19 class PaintTiming final : public GarbageCollectedFinalized<PaintTiming>, public
Supplement<Document> { | 20 class CORE_EXPORT PaintTiming final : public GarbageCollectedFinalized<PaintTimi
ng>, public Supplement<Document> { |
| 20 WTF_MAKE_NONCOPYABLE(PaintTiming); | 21 WTF_MAKE_NONCOPYABLE(PaintTiming); |
| 21 USING_GARBAGE_COLLECTED_MIXIN(PaintTiming); | 22 USING_GARBAGE_COLLECTED_MIXIN(PaintTiming); |
| 22 public: | 23 public: |
| 23 virtual ~PaintTiming() { } | 24 virtual ~PaintTiming() { } |
| 24 | 25 |
| 25 static PaintTiming& from(Document&); | 26 static PaintTiming& from(Document&); |
| 26 | 27 |
| 27 // mark*() methods record the time for the given paint event, record a trace | 28 // mark*() methods record the time for the given paint event, record a trace |
| 28 // event, and notify that paint timing has changed. These methods do nothing | 29 // event, and notify that paint timing has changed. These methods do nothing |
| 29 // (early return) if a time has already been recorded for the given paint | 30 // (early return) if a time has already been recorded for the given paint |
| 30 // event. | 31 // event. |
| 31 void markFirstPaint(); | 32 void markFirstPaint(); |
| 32 | 33 |
| 33 // markFirstTextPaint, markFirstImagePaint, and markFirstContentfulPaint | 34 // markFirstTextPaint, markFirstImagePaint, and markFirstContentfulPaint |
| 34 // will also record first paint if first paint hasn't been recorded yet. | 35 // will also record first paint if first paint hasn't been recorded yet. |
| 35 void markFirstContentfulPaint(); | 36 void markFirstContentfulPaint(); |
| 36 | 37 |
| 37 // markFirstTextPaint and markFirstImagePaint will also record first | 38 // markFirstTextPaint and markFirstImagePaint will also record first |
| 38 // contentful paint if first contentful paint hasn't been recorded yet. | 39 // contentful paint if first contentful paint hasn't been recorded yet. |
| 39 void markFirstTextPaint(); | 40 void markFirstTextPaint(); |
| 40 void markFirstImagePaint(); | 41 void markFirstImagePaint(); |
| 41 | 42 |
| 43 void setFirstMeaningfulPaint(double stamp); |
| 44 void notifyPaint(bool isFirstPaint, bool textPainted, bool imagePainted); |
| 45 |
| 42 // The getters below return monotonically-increasing seconds, or zero if the | 46 // The getters below return monotonically-increasing seconds, or zero if the |
| 43 // given paint event has not yet occurred. See the comments for | 47 // given paint event has not yet occurred. See the comments for |
| 44 // monotonicallyIncreasingTime in wtf/CurrentTime.h for additional details. | 48 // monotonicallyIncreasingTime in wtf/CurrentTime.h for additional details. |
| 45 | 49 |
| 46 // firstPaint returns the first time that anything was painted for the | 50 // firstPaint returns the first time that anything was painted for the |
| 47 // current document. | 51 // current document. |
| 48 double firstPaint() const { return m_firstPaint; } | 52 double firstPaint() const { return m_firstPaint; } |
| 49 | 53 |
| 50 // firstContentfulPaint returns the first time that 'contentful' content was | 54 // firstContentfulPaint returns the first time that 'contentful' content was |
| 51 // painted. For instance, the first time that text or image content was | 55 // painted. For instance, the first time that text or image content was |
| 52 // painted. | 56 // painted. |
| 53 double firstContentfulPaint() const { return m_firstContentfulPaint; } | 57 double firstContentfulPaint() const { return m_firstContentfulPaint; } |
| 54 | 58 |
| 55 // firstTextPaint returns the first time that text content was painted. | 59 // firstTextPaint returns the first time that text content was painted. |
| 56 double firstTextPaint() const { return m_firstTextPaint; } | 60 double firstTextPaint() const { return m_firstTextPaint; } |
| 57 | 61 |
| 58 // firstImagePaint returns the first time that image content was painted. | 62 // firstImagePaint returns the first time that image content was painted. |
| 59 double firstImagePaint() const { return m_firstImagePaint; } | 63 double firstImagePaint() const { return m_firstImagePaint; } |
| 60 | 64 |
| 65 // firstMeaningfulPaint returns the first time that page's primary content |
| 66 // was painted. |
| 67 double firstMeaningfulPaint() const { return m_firstMeaningfulPaint; } |
| 68 |
| 69 Document* document() { return m_document.get(); } |
| 70 FirstMeaningfulPaintDetector& firstMeaningfulPaintDetector() { return *m_fmp
Detector; } |
| 71 |
| 61 DECLARE_VIRTUAL_TRACE(); | 72 DECLARE_VIRTUAL_TRACE(); |
| 62 | 73 |
| 63 private: | 74 private: |
| 64 explicit PaintTiming(Document&); | 75 explicit PaintTiming(Document&); |
| 65 LocalFrame* frame() const; | 76 LocalFrame* frame() const; |
| 66 void notifyPaintTimingChanged(); | 77 void notifyPaintTimingChanged(); |
| 67 | 78 |
| 68 // set*() set the timing for the given paint event to the given timestamp | 79 // set*() set the timing for the given paint event to the given timestamp |
| 69 // and record a trace event if the value is currently zero, but do not | 80 // and record a trace event if the value is currently zero, but do not |
| 70 // notify that paint timing changed. These methods can be invoked from other | 81 // notify that paint timing changed. These methods can be invoked from other |
| 71 // mark*() or set*() methods to make sure that first paint is marked as part | 82 // mark*() or set*() methods to make sure that first paint is marked as part |
| 72 // of marking first contentful paint, or that first contentful paint is | 83 // of marking first contentful paint, or that first contentful paint is |
| 73 // marked as part of marking first text/image paint, for example. | 84 // marked as part of marking first text/image paint, for example. |
| 74 void setFirstPaint(double stamp); | 85 void setFirstPaint(double stamp); |
| 75 | 86 |
| 76 // setFirstContentfulPaint will also set first paint time if first paint | 87 // setFirstContentfulPaint will also set first paint time if first paint |
| 77 // time has not yet been recorded. | 88 // time has not yet been recorded. |
| 78 void setFirstContentfulPaint(double stamp); | 89 void setFirstContentfulPaint(double stamp); |
| 79 | 90 |
| 80 double m_firstPaint = 0.0; | 91 double m_firstPaint = 0.0; |
| 81 double m_firstTextPaint = 0.0; | 92 double m_firstTextPaint = 0.0; |
| 82 double m_firstImagePaint = 0.0; | 93 double m_firstImagePaint = 0.0; |
| 83 double m_firstContentfulPaint = 0.0; | 94 double m_firstContentfulPaint = 0.0; |
| 95 double m_firstMeaningfulPaint = 0.0; |
| 84 | 96 |
| 85 Member<Document> m_document; | 97 Member<Document> m_document; |
| 98 Member<FirstMeaningfulPaintDetector> m_fmpDetector; |
| 86 }; | 99 }; |
| 87 | 100 |
| 88 } // namespace blink | 101 } // namespace blink |
| 89 | 102 |
| 90 #endif | 103 #endif |
| OLD | NEW |