Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(407)

Unified Diff: ash/laser/laser_pointer_points.cc

Issue 2745953002: ash: Add basic prediction code to the laser pointer. (Closed)
Patch Set: more tests and nits Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/laser/laser_pointer_points.h ('k') | ash/laser/laser_pointer_points_test_api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/laser/laser_pointer_points.cc
diff --git a/ash/laser/laser_pointer_points.cc b/ash/laser/laser_pointer_points.cc
index 2bd23cebd7ea83e4dfa5aafde61e27873ad9c824..1e597636b826d2542ea31e7d478c7f1415833323 100644
--- a/ash/laser/laser_pointer_points.cc
+++ b/ash/laser/laser_pointer_points.cc
@@ -16,15 +16,24 @@ LaserPointerPoints::LaserPointerPoints(base::TimeDelta life_duration)
LaserPointerPoints::~LaserPointerPoints() {}
-void LaserPointerPoints::AddPoint(const gfx::PointF& point) {
- MoveForwardToTime(base::Time::Now());
+void LaserPointerPoints::AddPoint(const gfx::PointF& point,
+ const base::TimeTicks& time) {
+ // Move forward in time if needed.
+ if (time > collection_latest_time_)
+ MoveForwardToTime(time);
LaserPoint new_point;
new_point.location = point;
+ new_point.time = time;
+ new_point.age = std::min((collection_latest_time_ - time).InMillisecondsF() /
+ life_duration_.InMillisecondsF(),
+ 1.0);
points_.push_back(new_point);
}
-void LaserPointerPoints::MoveForwardToTime(const base::Time& latest_time) {
+void LaserPointerPoints::MoveForwardToTime(const base::TimeTicks& latest_time) {
+ DCHECK_GE(latest_time, collection_latest_time_);
+
if (!points_.empty()) {
DCHECK(!collection_latest_time_.is_null());
@@ -80,7 +89,7 @@ int LaserPointerPoints::GetNumberOfPoints() const {
}
const std::deque<LaserPointerPoints::LaserPoint>&
-LaserPointerPoints::laser_points() {
+LaserPointerPoints::laser_points() const {
return points_;
}
} // namespace ash
« no previous file with comments | « ash/laser/laser_pointer_points.h ('k') | ash/laser/laser_pointer_points_test_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698