1 // Copyright 2020 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/metrics/lcd_text_metrics_reporter.h"
7 #include "base/lazy_instance.h"
8 #include "base/memory/ptr_util.h"
9 #include "base/metrics/histogram_macros.h"
10 #include "cc/base/histograms.h"
11 #include "cc/layers/picture_layer_impl.h"
12 #include "cc/paint/display_item_list.h"
13 #include "cc/trees/layer_tree_host_impl.h"
14 #include "cc/trees/layer_tree_impl.h"
20 constexpr auto kMinimumTimeInterval = base::Minutes(1);
21 constexpr unsigned kMinimumFrameInterval = 500;
23 // This must be the same as that used in DeviceScaleEnsuresTextQuality() in
24 // content/renderer/render_widget.cc.
25 constexpr float kHighDPIDeviceScaleFactorThreshold = 1.5f;
26 constexpr char kMetricNameLCDTextKPixelsHighDPI[] =
27 "Compositing.Renderer.LCDTextDisallowedReasonKPixels.HighDPI";
28 constexpr char kMetricNameLCDTextKPixelsLowDPI[] =
29 "Compositing.Renderer.LCDTextDisallowedReasonKPixels.LowDPI";
30 constexpr char kMetricNameLCDTextLayersHighDPI[] =
31 "Compositing.Renderer.LCDTextDisallowedReasonLayers.HighDPI";
32 constexpr char kMetricNameLCDTextLayersLowDPI[] =
33 "Compositing.Renderer.LCDTextDisallowedReasonLayers.LowDPI";
35 } // anonymous namespace
37 std::unique_ptr<LCDTextMetricsReporter> LCDTextMetricsReporter::CreateIfNeeded(
38 const LayerTreeHostImpl* layer_tree_host_impl) {
39 const char* client_name = GetClientNameForMetrics();
40 // The metrics are for the renderer only.
41 if (!client_name || strcmp(client_name, "Renderer") != 0)
43 return base::WrapUnique(new LCDTextMetricsReporter(layer_tree_host_impl));
46 LCDTextMetricsReporter::LCDTextMetricsReporter(
47 const LayerTreeHostImpl* layer_tree_host_impl)
48 : layer_tree_host_impl_(layer_tree_host_impl) {}
50 LCDTextMetricsReporter::~LCDTextMetricsReporter() = default;
52 void LCDTextMetricsReporter::NotifySubmitFrame(
53 const viz::BeginFrameArgs& args) {
54 current_frame_time_ = args.frame_time;
55 frame_count_since_last_report_++;
56 if (last_report_frame_time_.is_null())
57 last_report_frame_time_ = current_frame_time_;
60 void LCDTextMetricsReporter::NotifyPauseFrameProduction() {
61 if (current_frame_time_.is_null() ||
62 current_frame_time_ - last_report_frame_time_ < kMinimumTimeInterval ||
63 frame_count_since_last_report_ < kMinimumFrameInterval) {
67 last_report_frame_time_ = current_frame_time_;
68 frame_count_since_last_report_ = 0;
70 float device_scale_factor =
71 layer_tree_host_impl_->settings().use_painted_device_scale_factor
72 ? layer_tree_host_impl_->active_tree()->painted_device_scale_factor()
73 : layer_tree_host_impl_->active_tree()->device_scale_factor();
74 bool is_high_dpi = device_scale_factor >= kHighDPIDeviceScaleFactorThreshold;
76 for (const auto* layer :
77 layer_tree_host_impl_->active_tree()->picture_layers()) {
78 if (!layer->draws_content() || !layer->GetRasterSource())
80 const scoped_refptr<DisplayItemList>& display_item_list =
81 layer->GetRasterSource()->GetDisplayItemList();
82 if (!display_item_list)
85 int text_pixels = static_cast<int>(
86 display_item_list->AreaOfDrawText(layer->visible_layer_rect()));
90 auto reason = layer->lcd_text_disallowed_reason();
92 UMA_HISTOGRAM_SCALED_ENUMERATION(kMetricNameLCDTextKPixelsHighDPI, reason,
94 UMA_HISTOGRAM_ENUMERATION(kMetricNameLCDTextLayersHighDPI, reason);
96 UMA_HISTOGRAM_SCALED_ENUMERATION(kMetricNameLCDTextKPixelsLowDPI, reason,
98 UMA_HISTOGRAM_ENUMERATION(kMetricNameLCDTextLayersLowDPI, reason);