Chromium Code Reviews| Index: ash/laser/laser_pointer_controller.cc |
| diff --git a/ash/laser/laser_pointer_controller.cc b/ash/laser/laser_pointer_controller.cc |
| index ac8de4ebc5d5032e9334efa4a98ec40f26bda418..0aaac213fd6a5098fbfc274dfad6bab1d4acf8de 100644 |
| --- a/ash/laser/laser_pointer_controller.cc |
| +++ b/ash/laser/laser_pointer_controller.cc |
| @@ -4,9 +4,12 @@ |
| #include "ash/laser/laser_pointer_controller.h" |
| +#include "ash/common/ash_switches.h" |
| #include "ash/common/system/chromeos/palette/palette_utils.h" |
| #include "ash/laser/laser_pointer_view.h" |
| #include "ash/shell.h" |
| +#include "base/command_line.h" |
| +#include "base/strings/string_number_conversions.h" |
| #include "ui/display/screen.h" |
| #include "ui/views/widget/widget.h" |
| @@ -26,6 +29,11 @@ const int kPointLifeDurationMs = 200; |
| // TODO(reveman): Use real VSYNC interval instead of a hard-coded delay. |
| const int kAddStationaryPointsDelayMs = 16; |
| +// The default amount of time used to estimate time from VSYNC event to when |
| +// visible light can be noticed by the user. This is used when a device |
| +// specific estimate was not provided using --estimated-presentation-delay. |
| +const int kDefaultPresentationDelayMs = 18; |
| + |
| } // namespace |
| LaserPointerController::LaserPointerController() |
| @@ -34,8 +42,24 @@ LaserPointerController::LaserPointerController() |
| base::TimeDelta::FromMilliseconds(kAddStationaryPointsDelayMs), |
| base::Bind(&LaserPointerController::AddStationaryPoint, |
| base::Unretained(this)), |
| - true /* is_repeating */)) { |
| + true /* is_repeating */)), |
| + presentation_delay_( |
| + base::TimeDelta::FromMilliseconds(kDefaultPresentationDelayMs)) { |
| Shell::GetInstance()->AddPreTargetHandler(this); |
| + |
| + // Use device specific presentation delay if specified. |
| + const base::CommandLine* command_line = |
| + base::CommandLine::ForCurrentProcess(); |
| + if (command_line->HasSwitch(switches::kAshEstimatedPresentationDelay)) { |
|
Daniele Castagna
2017/03/15 19:07:28
nit: you can get rid of this line and the code sho
reveman
2017/03/16 12:57:28
Done.
|
| + std::string presentation_delay_string = command_line->GetSwitchValueASCII( |
| + switches::kAshEstimatedPresentationDelay); |
| + int64_t presentation_delay_time_ms; |
| + if (base::StringToInt64(presentation_delay_string, |
| + &presentation_delay_time_ms)) { |
| + presentation_delay_ = |
| + base::TimeDelta::FromMilliseconds(presentation_delay_time_ms); |
| + } |
| + } |
| } |
| LaserPointerController::~LaserPointerController() { |
| @@ -106,7 +130,8 @@ void LaserPointerController::SwitchTargetRootWindowIfNeeded( |
| if (!laser_pointer_view_ && enabled_) { |
| laser_pointer_view_.reset(new LaserPointerView( |
| - base::TimeDelta::FromMilliseconds(kPointLifeDurationMs), root_window)); |
| + base::TimeDelta::FromMilliseconds(kPointLifeDurationMs), |
| + presentation_delay_, root_window)); |
| } |
| } |
| @@ -116,7 +141,8 @@ void LaserPointerController::UpdateLaserPointerView( |
| ui::Event* event) { |
| SwitchTargetRootWindowIfNeeded(current_window); |
| current_stylus_location_ = event_location; |
| - laser_pointer_view_->AddNewPoint(current_stylus_location_); |
| + laser_pointer_view_->AddNewPoint(current_stylus_location_, |
| + event->time_stamp()); |
| event->StopPropagation(); |
| } |
| @@ -136,10 +162,12 @@ void LaserPointerController::RestartTimer() { |
| } |
| void LaserPointerController::AddStationaryPoint() { |
| - if (is_fading_away_) |
| + if (is_fading_away_) { |
| laser_pointer_view_->UpdateTime(); |
| - else |
| - laser_pointer_view_->AddNewPoint(current_stylus_location_); |
| + } else { |
| + laser_pointer_view_->AddNewPoint(current_stylus_location_, |
| + base::TimeTicks::Now()); |
| + } |
| // We can stop repeating the timer once the stylus has been stationary for |
| // longer than the life of a point. |