blob: a77491aa0c591c66d516486c3ecd4c15672ba8fe [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include "base/component_export.h"
#include "base/macros.h"
#include "base/time/time.h"
#include "ui/gfx/geometry/point_f.h"
namespace ui {
// This class expects a sequence of inputs with their coordinates and timestamps
// and models the input path. It then can predict the coordinates at any given
// time.
virtual ~InputPredictor() = default;
struct InputData {
gfx::PointF pos;
base::TimeTicks time_stamp;
InputData() {
pos = gfx::PointF();
time_stamp = base::TimeTicks();
InputData(const gfx::PointF& event_pos, const base::TimeTicks& event_time) {
pos = event_pos;
time_stamp = event_time;
// Returns the name of the predictor.
virtual const char* GetName() const = 0;
// Reset should be called each time when a new line start.
virtual void Reset() = 0;
// Update the predictor with new input points.
virtual void Update(const InputData& new_input) = 0;
// Return true if the predictor is able to predict points.
virtual bool HasPrediction() const = 0;
// Generate the prediction based on current points.
// It can use a latency based on the vsync refresh rate: `frame_interval`.
// TODO( Remove the `frame_interval` arg if the expriment
// concludes that a frame-dependent latency isn't better.
virtual std::unique_ptr<InputData> GeneratePrediction(
base::TimeTicks predict_time,
base::TimeDelta frame_interval = base::TimeDelta::FromSeconds(0)) = 0;
// Returns the maximum of prediction available for resampling
// before having side effects (jitter, wrong orientation, etc..)
const base::TimeDelta MaxResampleTime() const { return kMaxResampleTime; }
// Returns the maximum prediction time available for the predictor
// before having side effects (jitter, wrong orientation, etc..)
const base::TimeDelta MaxPredictionTime() const { return kMaxPredictionTime; }
// Return the time interval based on current points.
virtual base::TimeDelta TimeInterval() const = 0;
static constexpr base::TimeDelta kMaxTimeDelta =
// Default time interval between events.
static constexpr base::TimeDelta kTimeInterval =
// Minimum time interval between events.
static constexpr base::TimeDelta kMinTimeInterval =
// Maximum amount of prediction when resampling.
static constexpr base::TimeDelta kMaxResampleTime =
// Maximum time delta for prediction.
static constexpr base::TimeDelta kMaxPredictionTime =
} // namespace ui