[M108 Migration][VD] Avoid pending frame counter becoming negative
[platform/framework/web/chromium-efl.git] / cc / metrics / lcd_text_metrics_reporter.cc
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.
4
5 #include "cc/metrics/lcd_text_metrics_reporter.h"
6
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"
15
16 namespace cc {
17
18 namespace {
19
20 constexpr auto kMinimumTimeInterval = base::Minutes(1);
21 constexpr unsigned kMinimumFrameInterval = 500;
22
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";
34
35 }  // anonymous namespace
36
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)
42     return nullptr;
43   return base::WrapUnique(new LCDTextMetricsReporter(layer_tree_host_impl));
44 }
45
46 LCDTextMetricsReporter::LCDTextMetricsReporter(
47     const LayerTreeHostImpl* layer_tree_host_impl)
48     : layer_tree_host_impl_(layer_tree_host_impl) {}
49
50 LCDTextMetricsReporter::~LCDTextMetricsReporter() = default;
51
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_;
58 }
59
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) {
64     return;
65   }
66
67   last_report_frame_time_ = current_frame_time_;
68   frame_count_since_last_report_ = 0;
69
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;
75
76   for (const auto* layer :
77        layer_tree_host_impl_->active_tree()->picture_layers()) {
78     if (!layer->draws_content() || !layer->GetRasterSource())
79       continue;
80     const scoped_refptr<DisplayItemList>& display_item_list =
81         layer->GetRasterSource()->GetDisplayItemList();
82     if (!display_item_list)
83       continue;
84
85     int text_pixels = static_cast<int>(
86         display_item_list->AreaOfDrawText(layer->visible_layer_rect()));
87     if (!text_pixels)
88       continue;
89
90     auto reason = layer->lcd_text_disallowed_reason();
91     if (is_high_dpi) {
92       UMA_HISTOGRAM_SCALED_ENUMERATION(kMetricNameLCDTextKPixelsHighDPI, reason,
93                                        text_pixels, 1000);
94       UMA_HISTOGRAM_ENUMERATION(kMetricNameLCDTextLayersHighDPI, reason);
95     } else {
96       UMA_HISTOGRAM_SCALED_ENUMERATION(kMetricNameLCDTextKPixelsLowDPI, reason,
97                                        text_pixels, 1000);
98       UMA_HISTOGRAM_ENUMERATION(kMetricNameLCDTextLayersLowDPI, reason);
99     }
100   }
101 }
102
103 }  // namespace cc