summaryrefslogtreecommitdiff
path: root/chromium/ui/base/prediction
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2021-10-26 13:57:00 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2021-11-02 11:31:01 +0000
commit1943b3c2a1dcee36c233724fc4ee7613d71b9cf6 (patch)
tree8c1b5f12357025c197da5427ae02cfdc2f3570d6 /chromium/ui/base/prediction
parent21ba0c5d4bf8fba15dddd97cd693bad2358b77fd (diff)
downloadqtwebengine-chromium-1943b3c2a1dcee36c233724fc4ee7613d71b9cf6.tar.gz
BASELINE: Update Chromium to 94.0.4606.111
Change-Id: I924781584def20fc800bedf6ff41fdb96c438193 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/ui/base/prediction')
-rw-r--r--chromium/ui/base/prediction/OWNERS2
-rw-r--r--chromium/ui/base/prediction/README.md17
-rw-r--r--chromium/ui/base/prediction/linear_resampling.cc15
-rw-r--r--chromium/ui/base/prediction/prediction_metrics_handler.cc29
-rw-r--r--chromium/ui/base/prediction/prediction_metrics_handler.h10
-rw-r--r--chromium/ui/base/prediction/prediction_metrics_handler_unittest.cc45
6 files changed, 99 insertions, 19 deletions
diff --git a/chromium/ui/base/prediction/OWNERS b/chromium/ui/base/prediction/OWNERS
new file mode 100644
index 00000000000..e1fbf38f49a
--- /dev/null
+++ b/chromium/ui/base/prediction/OWNERS
@@ -0,0 +1,2 @@
+flackr@chromium.org
+sadrul@chromium.org \ No newline at end of file
diff --git a/chromium/ui/base/prediction/README.md b/chromium/ui/base/prediction/README.md
new file mode 100644
index 00000000000..3790a8e769b
--- /dev/null
+++ b/chromium/ui/base/prediction/README.md
@@ -0,0 +1,17 @@
+#ui/base/prediction
+This directory implements general purpose predictors.
+
+Examples of usage in scrolling can be found at third_party/blink/renderer/
+platform/widget/input/scroll_predictor.cc.
+
+# PredictionMetricsHandler
+
+Metrics from all predictors are logged by PredictorMetricsHandler.
+
+This is an example of the points used by
+PredictionMetricsHandler::ComputeFrameOverUnderPredictionMetric.
+
+The analogous is valid for ComputeOverUnderPredictionMetric, using
+`interpolated_` instead of `frame_interpolated_`
+
+![ComputeOverUnderPredictionMetric Overview](/docs/ui/base/prediction/images/frame_prediction_score.png)
diff --git a/chromium/ui/base/prediction/linear_resampling.cc b/chromium/ui/base/prediction/linear_resampling.cc
index b0dabac18ec..740f5fcd61f 100644
--- a/chromium/ui/base/prediction/linear_resampling.cc
+++ b/chromium/ui/base/prediction/linear_resampling.cc
@@ -89,11 +89,16 @@ std::unique_ptr<InputPredictor::InputData> LinearResampling::GeneratePrediction(
latency_calculator_.GetResampleLatency(frame_interval);
base::TimeTicks sample_time = frame_time + resample_latency;
- base::TimeDelta max_prediction =
- std::min(kResampleMaxPrediction, events_dt_ / 2.0);
-
- sample_time =
- std::min(sample_time, events_queue_[0].time_stamp + max_prediction);
+ // Clamping shouldn't affect prediction experiment, as we're predicting
+ // further in the future.
+ if (!base::FeatureList::IsEnabled(
+ ::features::kResamplingScrollEventsExperimentalPrediction)) {
+ base::TimeDelta max_prediction =
+ std::min(kResampleMaxPrediction, events_dt_ / 2.0);
+
+ sample_time =
+ std::min(sample_time, events_queue_[0].time_stamp + max_prediction);
+ }
return std::make_unique<InputData>(
lerp(events_queue_[0], events_queue_[1], sample_time), sample_time);
diff --git a/chromium/ui/base/prediction/prediction_metrics_handler.cc b/chromium/ui/base/prediction/prediction_metrics_handler.cc
index f8d4354d38c..d5b1e869953 100644
--- a/chromium/ui/base/prediction/prediction_metrics_handler.cc
+++ b/chromium/ui/base/prediction/prediction_metrics_handler.cc
@@ -141,6 +141,8 @@ void PredictionMetricsHandler::ComputeMetrics() {
predicted_events_queue_.front().frame_time, &frame_interpolated_);
next_real_ = events_queue_[low_idx_interpolated + 1].pos;
+ next_real_point_after_frame_ =
+ events_queue_[low_idx_frame_interpolated + 1].pos;
int first_needed_event =
std::min(low_idx_interpolated, low_idx_frame_interpolated);
@@ -159,6 +161,20 @@ void PredictionMetricsHandler::ComputeMetrics() {
base::UmaHistogramCounts1000(
base::StrCat({histogram_name_, ".UnderPrediction"}), -score);
}
+ base::UmaHistogramCounts1000(
+ base::StrCat({histogram_name_, ".PredictionScore"}), std::abs(score));
+
+ double frame_score = ComputeFrameOverUnderPredictionMetric();
+ if (frame_score >= 0) {
+ base::UmaHistogramCounts1000(
+ base::StrCat({histogram_name_, ".FrameOverPrediction"}), frame_score);
+ } else {
+ base::UmaHistogramCounts1000(
+ base::StrCat({histogram_name_, ".FrameUnderPrediction"}), -frame_score);
+ }
+ base::UmaHistogramCounts1000(
+ base::StrCat({histogram_name_, ".FramePredictionScore"}),
+ std::abs(frame_score));
// Need |last_predicted_| to compute WrongDirection and Jitter metrics.
if (!last_predicted_.has_value())
@@ -173,7 +189,7 @@ void PredictionMetricsHandler::ComputeMetrics() {
ComputeVisualJitterMetric());
}
-double PredictionMetricsHandler::ComputeOverUnderPredictionMetric() {
+double PredictionMetricsHandler::ComputeOverUnderPredictionMetric() const {
gfx::Vector2dF real_direction = next_real_ - interpolated_;
gfx::Vector2dF relative_direction =
predicted_events_queue_.front().pos - interpolated_;
@@ -183,6 +199,17 @@ double PredictionMetricsHandler::ComputeOverUnderPredictionMetric() {
return -relative_direction.Length();
}
+double PredictionMetricsHandler::ComputeFrameOverUnderPredictionMetric() const {
+ gfx::Vector2dF real_direction =
+ next_real_point_after_frame_ - frame_interpolated_;
+ gfx::Vector2dF relative_direction =
+ predicted_events_queue_.front().pos - frame_interpolated_;
+ if (gfx::DotProduct(real_direction, relative_direction) >= 0)
+ return relative_direction.Length();
+ else
+ return -relative_direction.Length();
+}
+
bool PredictionMetricsHandler::ComputeWrongDirectionMetric() {
gfx::Vector2dF real_direction = next_real_ - interpolated_;
gfx::Vector2dF predicted_direction =
diff --git a/chromium/ui/base/prediction/prediction_metrics_handler.h b/chromium/ui/base/prediction/prediction_metrics_handler.h
index 55dd4a33ebe..b0ca353d672 100644
--- a/chromium/ui/base/prediction/prediction_metrics_handler.h
+++ b/chromium/ui/base/prediction/prediction_metrics_handler.h
@@ -65,7 +65,12 @@ class COMPONENT_EXPORT(UI_BASE_PREDICTION) PredictionMetricsHandler {
// The score is the amount of pixels the predicted point is ahead of
// the real point. If the score is positive, the prediction is OverPredicting,
// otherwise UnderPredicting.
- double ComputeOverUnderPredictionMetric();
+ double ComputeOverUnderPredictionMetric() const;
+
+ // The score is the amount of pixels the predicted point is ahead/behind of
+ // the real input curve. The curve point being an interpolation of the real
+ // input points at the `frame_time` from the current predicted point.
+ double ComputeFrameOverUnderPredictionMetric() const;
// Compute the PredictionJitterMetric score.
// The score is the euclidean distance between 2 successive variation of
@@ -104,6 +109,9 @@ class COMPONENT_EXPORT(UI_BASE_PREDICTION) PredictionMetricsHandler {
// The first real event position which time is later than the predicted time.
gfx::PointF next_real_;
+ // The first real event position which time is later than the frame time.
+ gfx::PointF next_real_point_after_frame_;
+
// Beginning of the full histogram name. It will have the various metrics'
// names (.OverPrediction, .UnderPrediction, .WrongDirection,
// .PredictionJitter, .VisualJitter) appended to it when counting the metric
diff --git a/chromium/ui/base/prediction/prediction_metrics_handler_unittest.cc b/chromium/ui/base/prediction/prediction_metrics_handler_unittest.cc
index 8ed0f380ab2..47c08628efb 100644
--- a/chromium/ui/base/prediction/prediction_metrics_handler_unittest.cc
+++ b/chromium/ui/base/prediction/prediction_metrics_handler_unittest.cc
@@ -162,30 +162,35 @@ void AddEvents(PredictionMetricsHandler* metrics_handler) {
MillisecondsToTestTimeTicks(48),
MillisecondsToTestTimeTicks(54)); // R5
- // P0 | Interpolation from R0-R1 is (1.5,1.5)
+ // P0 | Interpolation from R0-R1 is (1.25,1.25)
+ // P0 | Frame Interpolation from R0-R1 is (1.5,1.5)
// UnderPrediction
metrics_handler->AddPredictedEvent(gfx::PointF(1, 1),
- MillisecondsToTestTimeTicks(12),
+ MillisecondsToTestTimeTicks(10),
MillisecondsToTestTimeTicks(12));
- // P1 | Interpolation from R1-R2 is (3,3)
+ // P1 | Interpolation from R1-R2 is (2.5,2.5)
+ // P1 | Frame Interpolation from R1-R2 is (3,3)
// OverPrediction | RightDirection
metrics_handler->AddPredictedEvent(gfx::PointF(3.5, 3.5),
- MillisecondsToTestTimeTicks(20),
+ MillisecondsToTestTimeTicks(18),
MillisecondsToTestTimeTicks(20));
- // P2 | Interpolation from R2-R3 is (5.5,5.5)
+ // P2 | Interpolation from R2-R3 is (4.75,4.75)
+ // P2 | Frame Interpolation from R2-R3 is (5.5,5.5)
// UnderPrediction | RightDirection
metrics_handler->AddPredictedEvent(gfx::PointF(5, 5),
- MillisecondsToTestTimeTicks(28),
+ MillisecondsToTestTimeTicks(26),
MillisecondsToTestTimeTicks(28));
- // P3 | Interpolation from R3-R4 is (6,6)
+ // P3 | Interpolation from R3-R4 is (6.5,6.5)
+ // P3 | Frame Interpolation from R3-R4 is (6,6)
// UnderPrediction | WrongDirection
metrics_handler->AddPredictedEvent(gfx::PointF(7, 7),
- MillisecondsToTestTimeTicks(36),
+ MillisecondsToTestTimeTicks(34),
MillisecondsToTestTimeTicks(36));
- // P4 | Interpolation from R4-R5 is (4,4)
+ // P4 | Interpolation from R4-R5 is (4.5,4.5)
+ // P4 | Frame Interpolation from R4-R5 is (4,4)
// OverPrediction | RightDirection
metrics_handler->AddPredictedEvent(gfx::PointF(3, 3),
- MillisecondsToTestTimeTicks(44),
+ MillisecondsToTestTimeTicks(42),
MillisecondsToTestTimeTicks(44));
}
@@ -195,19 +200,35 @@ TEST_F(PredictionMetricsHandlerTest, PredictionMetricTest) {
EXPECT_THAT(histogram_tester().GetAllSamples(
"Event.InputEventPrediction.Scroll.OverPrediction"),
- ElementsAre(Bucket(0, 1), Bucket(1, 1)));
+ ElementsAre(Bucket(0, 1), Bucket(1, 1), Bucket(2, 1)));
EXPECT_THAT(histogram_tester().GetAllSamples(
"Event.InputEventPrediction.Scroll.UnderPrediction"),
+ ElementsAre(Bucket(0, 2)));
+
+ EXPECT_THAT(histogram_tester().GetAllSamples(
+ "Event.InputEventPrediction.Scroll.PredictionScore"),
+ ElementsAre(Bucket(0, 3), Bucket(1, 1), Bucket(2, 1)));
+
+ EXPECT_THAT(histogram_tester().GetAllSamples(
+ "Event.InputEventPrediction.Scroll.FrameOverPrediction"),
+ ElementsAre(Bucket(0, 1), Bucket(1, 1)));
+
+ EXPECT_THAT(histogram_tester().GetAllSamples(
+ "Event.InputEventPrediction.Scroll.FrameUnderPrediction"),
ElementsAre(Bucket(0, 2), Bucket(1, 1)));
EXPECT_THAT(histogram_tester().GetAllSamples(
+ "Event.InputEventPrediction.Scroll.FramePredictionScore"),
+ ElementsAre(Bucket(0, 3), Bucket(1, 2)));
+
+ EXPECT_THAT(histogram_tester().GetAllSamples(
"Event.InputEventPrediction.Scroll.WrongDirection"),
ElementsAre(Bucket(0, 3), Bucket(1, 1)));
EXPECT_THAT(histogram_tester().GetAllSamples(
"Event.InputEventPrediction.Scroll.PredictionJitter"),
- ElementsAre(Bucket(1, 2), Bucket(2, 2)));
+ ElementsAre(Bucket(0, 1), Bucket(1, 2), Bucket(2, 1)));
EXPECT_THAT(histogram_tester().GetAllSamples(
"Event.InputEventPrediction.Scroll.VisualJitter"),