From 5486913c6367d4703648ce687a9a50d608b2cebb Mon Sep 17 00:00:00 2001 From: h00415081 Date: Tue, 27 Feb 2024 17:33:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EonFirstScreenImagePaint,=20on?= =?UTF-8?q?FirstScreenImageText=E6=8E=A5=E5=8F=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I41ab61e52b5a4cf10dfa8e6a482b973e7b7b909c Signed-off-by: h00415081 --- .../web_performance_metrics_for_reporting.h | 6 + .../web_performance_metrics_for_reporting.cc | 11 + .../timing/image_paint_timing_detector.cc | 60 +++++- .../timing/image_paint_timing_detector.h | 25 +++ .../core/paint/timing/paint_timing.cc | 33 +++ .../renderer/core/paint/timing/paint_timing.h | 15 ++ .../paint/timing/paint_timing_detector.cc | 189 +++++++++++++++++- .../core/paint/timing/paint_timing_detector.h | 25 +++ .../timing/text_paint_timing_detector.cc | 26 ++- .../paint/timing/text_paint_timing_detector.h | 21 +- .../performance_timing_for_reporting.cc | 25 +++ .../timing/performance_timing_for_reporting.h | 6 + 12 files changed, 437 insertions(+), 5 deletions(-) diff --git a/blink/public/web/web_performance_metrics_for_reporting.h b/blink/public/web/web_performance_metrics_for_reporting.h index 72e20494a..7a143e2b6 100644 --- a/blink/public/web/web_performance_metrics_for_reporting.h +++ b/blink/public/web/web_performance_metrics_for_reporting.h @@ -117,6 +117,12 @@ class BLINK_EXPORT WebPerformanceMetricsForReporting { WebPerformanceMetricsForReporting& operator=(WindowPerformance*); #endif +#ifdef OHOS_PAGE_LOAD_METRICS +double FirstScreenImagePaint() const; +double FirstScreenImageLoad() const; +double FirstScreenTextPaint() const; +#endif // OHOS_PAGE_LOAD_METRICS + private: WebPrivatePtr private_; }; diff --git a/blink/renderer/core/exported/web_performance_metrics_for_reporting.cc b/blink/renderer/core/exported/web_performance_metrics_for_reporting.cc index ffbb851b1..14c6d7bb8 100644 --- a/blink/renderer/core/exported/web_performance_metrics_for_reporting.cc +++ b/blink/renderer/core/exported/web_performance_metrics_for_reporting.cc @@ -329,4 +329,15 @@ WebPerformanceMetricsForReporting& WebPerformanceMetricsForReporting::operator=( return *this; } +#ifdef OHOS_PAGE_LOAD_METRICS +double WebPerformanceMetricsForReporting::FirstScreenImagePaint() const { + return MillisecondsToSeconds(private_->timingForReporting()->FirstScreenImagePaint()); +} +double WebPerformanceMetricsForReporting::FirstScreenImageLoad() const { + return MillisecondsToSeconds(private_->timingForReporting()->FirstScreenImageLoad()); +} +double WebPerformanceMetricsForReporting::FirstScreenTextPaint() const { + return MillisecondsToSeconds(private_->timingForReporting()->FirstScreenTextPaint()); +} +#endif // OHOS_PAGE_LOAD_METRICS } // namespace blink diff --git a/blink/renderer/core/paint/timing/image_paint_timing_detector.cc b/blink/renderer/core/paint/timing/image_paint_timing_detector.cc index b4ed09ccd..26a6659e8 100644 --- a/blink/renderer/core/paint/timing/image_paint_timing_detector.cc +++ b/blink/renderer/core/paint/timing/image_paint_timing_detector.cc @@ -24,6 +24,11 @@ #include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h" #include "third_party/blink/renderer/platform/instrumentation/tracing/traced_value.h" +#ifdef OHOS_PAGE_LOAD_METRICS +#include "base/command_line.h" +#include "content/public/common/content_switches.h" +#endif + namespace blink { namespace { @@ -96,7 +101,14 @@ ImagePaintTimingDetector::ImagePaintTimingDetector( base::FeatureList::IsEnabled(features::kUsePageViewportInLCP)), records_manager_(frame_view), frame_view_(frame_view), - callback_manager_(callback_manager) {} + callback_manager_(callback_manager) { +#ifdef OHOS_PAGE_LOAD_METRICS + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kForBrowser )) { + is_for_browser_ = true; + } +#endif +} ImageRecord* ImageRecordsManager::LargestImage() const { DCHECK_EQ(pending_images_.size(), size_ordered_set_.size()); @@ -297,6 +309,16 @@ void ImageRecordsManager::AssignPaintTimeToRegisteredQueuedRecords( largest_painted_image_->recorded_size < record->recorded_size) { largest_painted_image_ = std::move(it->value); } + +#ifdef OHOS_PAGE_LOAD_METRICS + if (is_for_browser_) { + LOG(INFO) << "AssignPaintTimeToRegisteredQueuedRecords timestamp:" << timestamp + << ", image load_time:" << record->load_time; + frame_view_->GetPaintTimingDetector().NotifyImagePaint( + record->root_visual_rect_, timestamp, record->load_time); + } +#endif // OHOS_PAGE_LOAD_METRICS + pending_images_.erase(it); } } @@ -381,6 +403,15 @@ bool ImagePaintTimingDetector::RecordImage( bool added_pending = records_manager_.RecordFirstPaintAndReturnIsPending( record_id, rect_size, image_border, mapped_visual_rect, bpp, is_loaded_after_mouseover); + +#ifdef OHOS_PAGE_LOAD_METRICS + if (is_for_browser_ && !added_pending) { + added_pending = records_manager_.RecordFirstPaintForAllImage(record_id, + rect_size, image_border, mapped_visual_rect, + is_loaded_after_mouseover); + } +#endif // OHOS_PAGE_LOAD_METRICS + if (!added_pending) return false; @@ -455,7 +486,14 @@ void ImagePaintTimingDetector::ReportLargestIgnoredImage() { } ImageRecordsManager::ImageRecordsManager(LocalFrameView* frame_view) - : size_ordered_set_(&LargeImageFirst), frame_view_(frame_view) {} + : size_ordered_set_(&LargeImageFirst), frame_view_(frame_view) { +#ifdef OHOS_PAGE_LOAD_METRICS + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kForBrowser)) { + is_for_browser_ = true; + } +#endif +} bool ImageRecordsManager::OnFirstAnimatedFramePainted( const RecordId& record_id, @@ -634,4 +672,22 @@ void ImagePaintTimingDetector::Trace(Visitor* visitor) const { visitor->Trace(frame_view_); visitor->Trace(callback_manager_); } + +#ifdef OHOS_PAGE_LOAD_METRICS +bool ImageRecordsManager::RecordFirstPaintForAllImage( + const RecordId& record_id, const uint64_t& visual_size, + const gfx::Rect& frame_visual_rect, const gfx::RectF& root_visual_rect, + const bool is_loaded_after_mouseover) { + if (visual_size == 0u) { + return false; + } + std::unique_ptr record = CreateImageRecord(*record_id.first, + record_id.second, visual_size, frame_visual_rect, root_visual_rect, + is_loaded_after_mouseover); + size_ordered_set_.insert(record->AsWeakPtr()); + pending_images_.insert(record_id, std::move(record)); + return true; +} +#endif // OHOS_PAGE_LOAD_METRICS + } // namespace blink diff --git a/blink/renderer/core/paint/timing/image_paint_timing_detector.h b/blink/renderer/core/paint/timing/image_paint_timing_detector.h index 413176e99..951469b4a 100644 --- a/blink/renderer/core/paint/timing/image_paint_timing_detector.h +++ b/blink/renderer/core/paint/timing/image_paint_timing_detector.h @@ -45,6 +45,10 @@ class ImageRecord : public base::SupportsWeakPtr { : node_id(new_node_id), media_timing(new_media_timing), recorded_size(new_recorded_size), +#ifdef OHOS_PAGE_LOAD_METRICS + frame_visual_rect_(frame_visual_rect), + root_visual_rect_(root_visual_rect), +#endif // OHOS_PAGE_LOAD_METRICS is_loaded_after_mouseover(is_loaded_after_mouseover_input) { static unsigned next_insertion_index_ = 1; insertion_index = next_insertion_index_++; @@ -87,6 +91,11 @@ class ImageRecord : public base::SupportsWeakPtr { // what they report. bool origin_clean = true; +#ifdef OHOS_PAGE_LOAD_METRICS + gfx::RectF frame_visual_rect_; + gfx::RectF root_visual_rect_; +#endif // OHOS_PAGE_LOAD_METRICS + bool is_loaded_after_mouseover = false; }; @@ -178,6 +187,14 @@ class CORE_EXPORT ImageRecordsManager { void Trace(Visitor* visitor) const; +#ifdef OHOS_PAGE_LOAD_METRICS + bool RecordFirstPaintForAllImage(const RecordId& record_id, + const uint64_t& visual_size, + const gfx::Rect& frame_visual_rect, + const gfx::RectF& root_visual_rect, + const bool is_loaded_after_mouseover); +#endif // OHOS_PAGE_LOAD_METRICS + private: std::unique_ptr CreateImageRecord( const LayoutObject& object, @@ -235,6 +252,10 @@ class CORE_EXPORT ImageRecordsManager { // consider this an LCP candidate when the documentElement's opacity changes // from zero to nonzero. std::unique_ptr largest_ignored_image_; + +#ifdef OHOS_PAGE_LOAD_METRICS +bool is_for_browser_ = false; +#endif // OHOS_PAGE_LOAD_METRICS }; // ImagePaintTimingDetector contains Largest Image Paint. @@ -355,6 +376,10 @@ class CORE_EXPORT ImagePaintTimingDetector final ImageRecordsManager records_manager_; Member frame_view_; Member callback_manager_; + +#ifdef OHOS_PAGE_LOAD_METRICS +bool is_for_browser_ = false; +#endif // OHOS_PAGE_LOAD_METRICS }; } // namespace blink diff --git a/blink/renderer/core/paint/timing/paint_timing.cc b/blink/renderer/core/paint/timing/paint_timing.cc index 9180013d1..57153b36a 100644 --- a/blink/renderer/core/paint/timing/paint_timing.cc +++ b/blink/renderer/core/paint/timing/paint_timing.cc @@ -179,6 +179,14 @@ void PaintTiming::SetFirstMeaningfulPaint( "frame", GetFrameIdForTracing(GetFrame()), "afterUserInput", had_input); +#ifdef OHOS_PAGE_LOAD_METRICS + // FirstScreenPaint uses FMP as a fallback. // TODO: + if (first_screen_image_paint_.is_null()) { + first_screen_image_paint_ = presentation_time; + NotifyPaintTimingChanged(); + } +#endif // OHOS_PAGE_LOAD_METRICS + // Notify FMP for UMA only if there's no user input before FMP, so that layout // changes caused by user interactions wouldn't be considered as FMP. if (had_input == FirstMeaningfulPaintDetector::kNoUserInput) { @@ -492,4 +500,29 @@ void PaintTiming::SetLCPMouseoverDispatched() { lcp_mouse_over_dispatch_time_ = clock_->NowTicks(); } +#ifdef OHOS_PAGE_LOAD_METRICS +void PaintTiming::SetFirstScreenImagePaint(base::TimeTicks presentation_time, + base::TimeTicks load_time) { + first_screen_image_paint_ = presentation_time; + first_screen_image_load_ = load_time; + NotifyPaintTimingChanged(); +} + +base::TimeTicks PaintTiming::FirstScreenImagePaint() const { + return first_screen_image_paint_; +} + +base::TimeTicks PaintTiming::FirstScreenImageLoad() const { + return first_screen_image_load_; +} + +void PaintTiming::SetFirstScreenTextPaint(base::TimeTicks presentation_time) { + first_screen_text_paint_ = presentation_time; + NotifyPaintTimingChanged(); +} + +base::TimeTicks PaintTiming::FirstScreenTextPaint() const { + return first_screen_text_paint_; +} +#endif // OHOS_PAGE_LOAD_METRICS } // namespace blink diff --git a/blink/renderer/core/paint/timing/paint_timing.h b/blink/renderer/core/paint/timing/paint_timing.h index 7b3405c31..d80f70905 100644 --- a/blink/renderer/core/paint/timing/paint_timing.h +++ b/blink/renderer/core/paint/timing/paint_timing.h @@ -185,6 +185,15 @@ class CORE_EXPORT PaintTiming final : public GarbageCollected, void Trace(Visitor*) const override; +#ifdef OHOS_PAGE_LOAD_METRICS +void SetFirstScreenImagePaint(base::TimeTicks presentation_time, + base::TimeTicks load_time); +base::TimeTicks FirstScreenImagePaint() const; +base::TimeTicks FirstScreenImageLoad() const; +void SetFirstScreenTextPaint(base::TimeTicks presentation_time); +base::TimeTicks FirstScreenTextPaint() const; +#endif // OHOS_PAGE_LOAD_METRICS + private: friend class RecodingTimeAfterBackForwardCacheRestoreFrameCallback; @@ -263,6 +272,12 @@ class CORE_EXPORT PaintTiming final : public GarbageCollected, const base::TickClock* clock_; +#ifdef OHOS_PAGE_LOAD_METRICS +base::TimeTicks first_screen_image_paint_; +base::TimeTicks first_screen_image_load_; +base::TimeTicks first_screen_text_paint_; +#endif // OHOS_PAGE_LOAD_METRICS + FRIEND_TEST_ALL_PREFIXES(FirstMeaningfulPaintDetectorTest, TwoLayoutsSignificantFirst); }; diff --git a/blink/renderer/core/paint/timing/paint_timing_detector.cc b/blink/renderer/core/paint/timing/paint_timing_detector.cc index 247f88009..250b03ed6 100644 --- a/blink/renderer/core/paint/timing/paint_timing_detector.cc +++ b/blink/renderer/core/paint/timing/paint_timing_detector.cc @@ -45,10 +45,19 @@ #include "third_party/blink/renderer/platform/wtf/std_lib_extras.h" #include "ui/gfx/geometry/rect.h" +#ifdef OHOS_PAGE_LOAD_METRICS +#include "third_party/blink/renderer/core/frame/visual_viewport.h" +#include "third_party/blink/renderer/core/paint/timing/paint_timing.h" +#endif // OHOS_PAGE_LOAD_METRICS + namespace blink { namespace { +#ifdef OHOS_PAGE_LOAD_METRICS +constexpr base::TimeDelta kContentNoChangeTimeout = base::Seconds(1); +#endif // OHOS_PAGE_LOAD_METRICS + // In the context of FCP++, we define contentful background image as one that // satisfies all of the following conditions: // * has image reources attached to style of the object, i.e., @@ -148,6 +157,53 @@ void ReportImagePixelInaccuracy(HTMLImageElement* image_element) { } } +#ifdef OHOS_PAGE_LOAD_METRICS +template +bool ContentReachesContainerBottom(const T& container_rect, + const U& content_rect) { + const float factor = 3.f / 4; + float shrink_top = container_rect.height() * factor; + gfx::RectF container_bottom_rect = container_rect; + container_bottom_rect.Inset(gfx::InsetsF().set_top(shrink_top)); + gfx::RectF content_rect_f = content_rect; + return container_bottom_rect.Intersects(content_rect_f); +} + +bool MaybeFirstScreenTextPaintAlmostFinished(float container_size, + float text_content_size, bool content_reaches_bottom) { + const float expected_text_content_ratio = 1.f / 3; + const float expected_text_content_ratio_with_content_in_bottom = 1.f / 10; + float text_content_ratio = text_content_size / container_size; + if (content_reaches_bottom) { + if (text_content_ratio >= + expected_text_content_ratio_with_content_in_bottom) { + return true; + } + } + if (text_content_ratio >= expected_text_content_ratio) { + return true; + } + return false; +} + +bool MaybeFirstScreenImagePaintAlmostFinished(float container_size, + float image_content_size, + bool content_reaches_bottom) { + const float expected_image_content_ratio = 1.f / 2; + const float expected_image_content_ratio_with_content_in_bottom = 1.f / 4; + float image_content_ratio = image_content_size / container_size; + if (content_reaches_bottom) { + if (image_content_ratio >= + expected_image_content_ratio_with_content_in_bottom) { + return true; + } + } + if (image_content_ratio >= expected_image_content_ratio) { + return true; + } + return false; +} +#endif // OHOS_PAGE_LOAD_METRICS } // namespace PaintTimingDetector::PaintTimingDetector(LocalFrameView* frame_view) @@ -161,7 +217,15 @@ PaintTimingDetector::PaintTimingDetector(LocalFrameView* frame_view) frame_view, nullptr /*set later*/)), callback_manager_( - MakeGarbageCollected(frame_view)) { + MakeGarbageCollected(frame_view)) +#ifdef OHOS_PAGE_LOAD_METRICS + , content_no_change_timer_( + frame_view_->GetFrame().GetTaskRunner( + TaskType::kPerformanceTimeline), + this, + &PaintTimingDetector::ContentNoChangeTimerFired) +#endif // OHOS_PAGE_LOAD_METRICS +{ if (PaintTimingVisualizer::IsTracingEnabled()) visualizer_.emplace(); text_paint_timing_detector_->ResetCallbackManager(callback_manager_.Get()); @@ -624,6 +688,129 @@ void PaintTimingDetector::Trace(Visitor* visitor) const { visitor->Trace(callback_manager_); } +#ifdef OHOS_PAGE_LOAD_METRICS +void PaintTimingDetector::NotifyTextPaint(const gfx::RectF& content_rect, + const base::TimeTicks& timestamp) { + if (!frame_view_->GetFrame().IsMainFrame()) { + const LocalFrame& local_frame_root = + frame_view_->GetFrame().LocalFrameRoot(); + if (local_frame_root.View()) { + local_frame_root.View()->GetPaintTimingDetector().NotifyTextPaint( + content_rect, timestamp); + } + return; + } + if (!frame_view_->GetPage()) { + return; + } + if (did_first_screen_text_paint_) { + return; + } + + gfx::RectF visual_viewport_rect = BlinkSpaceToDIPs( + frame_view_->GetPage()->GetVisualViewport().VisibleRect()); + gfx::RectF content_visual_rect = content_rect; + content_visual_rect.Intersect(visual_viewport_rect); + painted_text_size_ += content_visual_rect.size().GetArea(); + if (!content_reaches_bottom_) { + content_reaches_bottom_ = ContentReachesContainerBottom( + visual_viewport_rect, content_visual_rect); + } + if (MaybeFirstScreenTextPaintAlmostFinished( + visual_viewport_rect.size().GetArea(), + painted_text_size_, + content_reaches_bottom_)) { + NotifyFirstScreenTextPaint(timestamp); + return; + } + + last_first_screen_paint_timestamp_ = timestamp; + if (content_no_change_timer_.IsActive()) { + content_no_change_timer_.Stop(); + } + + content_no_change_timer_.StartOneShot(kContentNoChangeTimeout, FROM_HERE); +} + +void PaintTimingDetector::NotifyImagePaint(const gfx::RectF& content_rect, + const base::TimeTicks& timestamp, const base::TimeTicks& load_time) { + if (!frame_view_->GetFrame().IsMainFrame()) { + const LocalFrame& local_frame_root = + frame_view_->GetFrame().LocalFrameRoot(); + if (local_frame_root.View()) { + local_frame_root.View()->GetPaintTimingDetector().NotifyImagePaint( + content_rect, timestamp, load_time); + } + return; + } + if (!frame_view_->GetPage()) { + return; + } + if (did_first_screen_image_paint_) { + return; + } + + gfx::RectF visual_viewport_rect = BlinkSpaceToDIPs( + frame_view_->GetPage()->GetVisualViewport().VisibleRect()); + gfx::RectF content_visual_rect = content_rect; + content_visual_rect.Intersect(visual_viewport_rect); + painted_image_size_ += content_visual_rect.size().GetArea(); + if (!content_reaches_bottom_) { + content_reaches_bottom_ = ContentReachesContainerBottom( + visual_viewport_rect, content_visual_rect); + } + if (MaybeFirstScreenImagePaintAlmostFinished( + visual_viewport_rect.size().GetArea(), + painted_image_size_, + content_reaches_bottom_)) { + NotifyFirstScreenImagePaint(timestamp, load_time); + return; + } + + last_first_screen_paint_timestamp_ = timestamp; + if (content_no_change_timer_.IsActive()) { + content_no_change_timer_.Stop(); + } + + content_no_change_timer_.StartOneShot(kContentNoChangeTimeout, FROM_HERE); +} + +void PaintTimingDetector::NotifyFirstScreenImagePaint( + const base::TimeTicks& timestamp, const base::TimeTicks& load_time) { + if (did_first_screen_image_paint_) { + return; + } + did_first_screen_image_paint_ = true; + Document* document = frame_view_->GetFrame().GetDocument(); + if (document) { + PaintTiming::From(*document).SetFirstScreenImagePaint(timestamp, + load_time); + } + if (content_no_change_timer_.IsActive()) { + content_no_change_timer_.Stop(); + } +} + +void PaintTimingDetector::NotifyFirstScreenTextPaint( + const base::TimeTicks& timestamp) { + if (did_first_screen_text_paint_) { + return; + } + did_first_screen_text_paint_ = true; + Document* document = frame_view_->GetFrame().GetDocument(); + if (document) { + PaintTiming::From(*document).SetFirstScreenTextPaint(timestamp); + } + if (content_no_change_timer_.IsActive()) { + content_no_change_timer_.Stop(); + } +} + +void PaintTimingDetector::ContentNoChangeTimerFired(TimerBase*) { + +} +#endif // OHOS_PAGE_LOAD_METRICS + void PaintTimingCallbackManagerImpl:: RegisterPaintTimeCallbackForCombinedCallbacks() { DCHECK(!frame_callbacks_->empty()); diff --git a/blink/renderer/core/paint/timing/paint_timing_detector.h b/blink/renderer/core/paint/timing/paint_timing_detector.h index 322bfee2a..af90c63e5 100644 --- a/blink/renderer/core/paint/timing/paint_timing_detector.h +++ b/blink/renderer/core/paint/timing/paint_timing_detector.h @@ -22,6 +22,10 @@ #include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h" #include "ui/gfx/geometry/rect.h" +#ifdef OHOS_PAGE_LOAD_METRICS +#include "third_party/blink/renderer/platform/timer.h" +#endif // OHOS_PAGE_LOAD_METRICS + namespace blink { class Image; @@ -256,6 +260,17 @@ class CORE_EXPORT PaintTimingDetector absl::optional& Visualizer() { return visualizer_; } void Trace(Visitor* visitor) const; +#ifdef OHOS_PAGE_LOAD_METRICS +void NotifyTextPaint(const gfx::RectF& content_rect, + const base::TimeTicks& timestamp); +void NotifyImagePaint(const gfx::RectF& content_rect, + const base::TimeTicks& timestamp, const base::TimeTicks& load_time); +void NotifyFirstScreenImagePaint( + const base::TimeTicks& timestamp, const base::TimeTicks& load_time); +void NotifyFirstScreenTextPaint(const base::TimeTicks& timestamp); +void ContentNoChangeTimerFired(TimerBase*); +#endif // OHOS_PAGE_LOAD_METRICS + private: FRIEND_TEST_ALL_PREFIXES(ImagePaintTimingDetectorTest, LargestImagePaint_Detached_Frame); @@ -288,6 +303,16 @@ class CORE_EXPORT PaintTimingDetector LargestContentfulPaintDetails lcp_details_for_ukm_; bool record_lcp_to_ukm_ = true; bool lcp_was_restarted_ = false; + +#ifdef OHOS_PAGE_LOAD_METRICS + float painted_text_size_ = 0; + float painted_image_size_ = 0; + bool did_first_screen_image_paint_ = false; + bool did_first_screen_text_paint_ = false; + bool content_reaches_bottom_ = false; + base::TimeTicks last_first_screen_paint_timestamp_; + HeapTaskRunnerTimer content_no_change_timer_; +#endif // OHOS_PAGE_LOAD_METRICS }; // Largest Text Paint and Text Element Timing aggregate text nodes by these diff --git a/blink/renderer/core/paint/timing/text_paint_timing_detector.cc b/blink/renderer/core/paint/timing/text_paint_timing_detector.cc index 4007abf89..230b90a4d 100644 --- a/blink/renderer/core/paint/timing/text_paint_timing_detector.cc +++ b/blink/renderer/core/paint/timing/text_paint_timing_detector.cc @@ -17,6 +17,11 @@ #include "third_party/blink/renderer/platform/instrumentation/tracing/traced_value.h" #include "third_party/blink/renderer/platform/runtime_enabled_features.h" +#ifdef OHOS_PAGE_LOAD_METRICS +#include "base/command_line.h" +#include "content/public/common/content_switches.h" +#endif + namespace blink { void TextRecord::Trace(Visitor* visitor) const { @@ -31,7 +36,14 @@ TextPaintTimingDetector::TextPaintTimingDetector( frame_view_(frame_view), ltp_manager_(MakeGarbageCollected( frame_view, - paint_timing_detector)) {} + paint_timing_detector)) { +#ifdef OHOS_PAGE_LOAD_METRICS + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kForBrowser)) { + is_for_browser_ = true; + } +#endif +} void LargestTextPaintManager::PopulateTraceValue( TracedValue& value, @@ -283,6 +295,12 @@ void TextPaintTimingDetector::AssignPaintTimeToQueuedRecords( ltp_manager_->MaybeUpdateLargestText(record); } keys_to_be_removed.push_back(it.key); + +#ifdef OHOS_PAGE_LOAD_METRICS + if (is_for_browser_ && ltp_manager_) { + ltp_manager_->NotifyTextPaint(record->root_visual_rect_, timestamp); + } +#endif // OHOS_PAGE_LOAD_METRICS } texts_queued_for_paint_time_.RemoveAll(keys_to_be_removed); } @@ -315,4 +333,10 @@ void TextPaintTimingDetector::MaybeRecordTextRecord( QueueToMeasurePaintTime(object, record); } +#ifdef OHOS_PAGE_LOAD_METRICS +void LargestTextPaintManager::NotifyTextPaint(const gfx::RectF& visual_rect, + const base::TimeTicks& timestamp) { + paint_timing_detector_->NotifyTextPaint(visual_rect, timestamp); +} +#endif // OHOS_PAGE_LOAD_METRICS } // namespace blink diff --git a/blink/renderer/core/paint/timing/text_paint_timing_detector.h b/blink/renderer/core/paint/timing/text_paint_timing_detector.h index e0d9dfa0e..188e63707 100644 --- a/blink/renderer/core/paint/timing/text_paint_timing_detector.h +++ b/blink/renderer/core/paint/timing/text_paint_timing_detector.h @@ -33,7 +33,12 @@ class TextRecord final : public GarbageCollected { : node_(&node), recorded_size(new_recorded_size), frame_index_(frame_index), - element_timing_rect_(element_timing_rect) { + element_timing_rect_(element_timing_rect) +#ifdef OHOS_PAGE_LOAD_METRICS + , frame_visual_rect_(frame_visual_rect) + , root_visual_rect_(root_visual_rect) +#endif // OHOS_PAGE_LOAD_METRICS + { if (PaintTimingVisualizer::IsTracingEnabled()) { lcp_rect_info_ = std::make_unique( frame_visual_rect, gfx::ToRoundedRect(root_visual_rect)); @@ -51,6 +56,11 @@ class TextRecord final : public GarbageCollected { std::unique_ptr lcp_rect_info_; // The time of the first paint after fully loaded. base::TimeTicks paint_time = base::TimeTicks(); + +#ifdef OHOS_PAGE_LOAD_METRICS + gfx::RectF frame_visual_rect_; + gfx::RectF root_visual_rect_; +#endif // OHOS_PAGE_LOAD_METRICS }; class CORE_EXPORT LargestTextPaintManager final @@ -86,6 +96,11 @@ class CORE_EXPORT LargestTextPaintManager final void Trace(Visitor*) const; +#ifdef OHOS_PAGE_LOAD_METRICS +void NotifyTextPaint(const gfx::RectF& visual_rect, + const base::TimeTicks& timestamp); +#endif // OHOS_PAGE_LOAD_METRICS + private: friend class LargestContentfulPaintCalculatorTest; friend class TextPaintTimingDetectorTest; @@ -191,6 +206,10 @@ class CORE_EXPORT TextPaintTimingDetector final // Used to decide which frame a record belongs to, monotonically increasing. uint32_t frame_index_ = 1; bool added_entry_in_latest_frame_ = false; + +#ifdef OHOS_PAGE_LOAD_METRICS + bool is_for_browser_ = false; +#endif // OHOS_PAGE_LOAD_METRICS }; } // namespace blink diff --git a/blink/renderer/core/timing/performance_timing_for_reporting.cc b/blink/renderer/core/timing/performance_timing_for_reporting.cc index 49cdd9b7b..70b477753 100644 --- a/blink/renderer/core/timing/performance_timing_for_reporting.cc +++ b/blink/renderer/core/timing/performance_timing_for_reporting.cc @@ -580,4 +580,29 @@ void PerformanceTimingForReporting::Trace(Visitor* visitor) const { ExecutionContextClient::Trace(visitor); } +#ifdef OHOS_PAGE_LOAD_METRICS +uint64_t PerformanceTimingForReporting::FirstScreenImagePaint() const { + const PaintTiming* timing = GetPaintTiming(); + if (!timing) { + return 0; + } + return MonotonicTimeToIntegerMilliseconds(timing->FirstScreenImagePaint()); +} + +uint64_t PerformanceTimingForReporting::FirstScreenImageLoad() const { + const PaintTiming* timing = GetPaintTiming(); + if (!timing) { + return 0; + } + return MonotonicTimeToIntegerMilliseconds(timing->FirstScreenImageLoad()); +} + +uint64_t PerformanceTimingForReporting::FirstScreenTextPaint() const { + const PaintTiming* timing = GetPaintTiming(); + if (!timing) { + return 0; + } + return MonotonicTimeToIntegerMilliseconds(timing->FirstScreenTextPaint()); +} +#endif // OHOS_PAGE_LOAD_METRICS } // namespace blink diff --git a/blink/renderer/core/timing/performance_timing_for_reporting.h b/blink/renderer/core/timing/performance_timing_for_reporting.h index b7592497d..3070bfce5 100644 --- a/blink/renderer/core/timing/performance_timing_for_reporting.h +++ b/blink/renderer/core/timing/performance_timing_for_reporting.h @@ -198,6 +198,12 @@ class CORE_EXPORT PerformanceTimingForReporting final std::unique_ptr GetNavigationTracingData(); +#ifdef OHOS_PAGE_LOAD_METRICS +uint64_t FirstScreenImagePaint() const; +uint64_t FirstScreenImageLoad() const; +uint64_t FirstScreenTextPaint() const; +#endif + private: const DocumentTiming* GetDocumentTiming() const; const DocumentParserTiming* GetDocumentParserTiming() const; -- Gitee