| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/laser/laser_pointer_view.h" | 5 #include "ash/laser/laser_pointer_view.h" |
| 6 | 6 |
| 7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
| 8 #include <GLES2/gl2ext.h> | 8 #include <GLES2/gl2ext.h> |
| 9 #include <GLES2/gl2extchromium.h> | 9 #include <GLES2/gl2extchromium.h> |
| 10 | 10 |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 gfx::Vector2dF scale(1.0f / screen_size.width(), 1.0f / screen_size.height()); | 287 gfx::Vector2dF scale(1.0f / screen_size.width(), 1.0f / screen_size.height()); |
| 288 | 288 |
| 289 // TODO(reveman): Determine interval based on history when event time stamps | 289 // TODO(reveman): Determine interval based on history when event time stamps |
| 290 // are accurate. b/36137953 | 290 // are accurate. b/36137953 |
| 291 const float kPredictionIntervalMs = 5.0f; | 291 const float kPredictionIntervalMs = 5.0f; |
| 292 const float kMaxPointIntervalMs = 10.0f; | 292 const float kMaxPointIntervalMs = 10.0f; |
| 293 base::TimeDelta prediction_interval = | 293 base::TimeDelta prediction_interval = |
| 294 base::TimeDelta::FromMilliseconds(kPredictionIntervalMs); | 294 base::TimeDelta::FromMilliseconds(kPredictionIntervalMs); |
| 295 base::TimeDelta max_point_interval = | 295 base::TimeDelta max_point_interval = |
| 296 base::TimeDelta::FromMilliseconds(kMaxPointIntervalMs); | 296 base::TimeDelta::FromMilliseconds(kMaxPointIntervalMs); |
| 297 base::TimeTicks last_point_time = current_time; | 297 base::TimeTicks last_point_time = new_time; |
| 298 gfx::PointF last_point_location = |
| 299 gfx::ScalePoint(new_point, scale.x(), scale.y()); |
| 298 | 300 |
| 299 // Use the last four points for prediction. | 301 // Use the last four points for prediction. |
| 300 using PositionArray = std::array<gfx::PointF, 4>; | 302 using PositionArray = std::array<gfx::PointF, 4>; |
| 301 PositionArray position; | 303 PositionArray position; |
| 302 PositionArray::iterator it = position.begin(); | 304 PositionArray::iterator it = position.begin(); |
| 303 for (const auto& point : base::Reversed(laser_points_.laser_points())) { | 305 for (const auto& point : base::Reversed(laser_points_.laser_points())) { |
| 304 // Stop adding positions if interval between points is too large to provide | 306 // Stop adding positions if interval between points is too large to provide |
| 305 // an accurate history for prediction. | 307 // an accurate history for prediction. |
| 306 if ((last_point_time - point.time) > max_point_interval) | 308 if ((last_point_time - point.time) > max_point_interval) |
| 307 break; | 309 break; |
| 308 | 310 |
| 309 *it++ = gfx::ScalePoint(point.location, scale.x(), scale.y()); | |
| 310 last_point_time = point.time; | 311 last_point_time = point.time; |
| 312 last_point_location = gfx::ScalePoint(point.location, scale.x(), scale.y()); |
| 313 *it++ = last_point_location; |
| 311 | 314 |
| 312 // Stop when no more positions are needed. | 315 // Stop when no more positions are needed. |
| 313 if (it == position.end()) | 316 if (it == position.end()) |
| 314 break; | 317 break; |
| 315 } | 318 } |
| 316 // Pad with last point if needed. | 319 // Pad with last point if needed. |
| 317 std::fill(it, position.end(), *(it - 1)); | 320 std::fill(it, position.end(), last_point_location); |
| 318 | 321 |
| 319 // Note: Currently there's no need to divide by the time delta between | 322 // Note: Currently there's no need to divide by the time delta between |
| 320 // points as we assume a constant delta between points that matches the | 323 // points as we assume a constant delta between points that matches the |
| 321 // prediction point interval. | 324 // prediction point interval. |
| 322 gfx::Vector2dF velocity[3]; | 325 gfx::Vector2dF velocity[3]; |
| 323 for (size_t i = 0; i < arraysize(velocity); ++i) | 326 for (size_t i = 0; i < arraysize(velocity); ++i) |
| 324 velocity[i] = position[i] - position[i + 1]; | 327 velocity[i] = position[i] - position[i + 1]; |
| 325 | 328 |
| 326 gfx::Vector2dF acceleration[2]; | 329 gfx::Vector2dF acceleration[2]; |
| 327 for (size_t i = 0; i < arraysize(acceleration); ++i) | 330 for (size_t i = 0; i < arraysize(acceleration); ++i) |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 pending_draw_surface_ = true; | 715 pending_draw_surface_ = true; |
| 713 } | 716 } |
| 714 | 717 |
| 715 void LaserPointerView::OnDidDrawSurface() { | 718 void LaserPointerView::OnDidDrawSurface() { |
| 716 pending_draw_surface_ = false; | 719 pending_draw_surface_ = false; |
| 717 if (needs_update_surface_) | 720 if (needs_update_surface_) |
| 718 UpdateSurface(); | 721 UpdateSurface(); |
| 719 } | 722 } |
| 720 | 723 |
| 721 } // namespace ash | 724 } // namespace ash |
| OLD | NEW |