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

Side by Side Diff: ash/laser/laser_pointer_controller.cc

Issue 2723653003: ash: Avoid unnecessary laser pointer updates. (Closed)
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_controller.h" 5 #include "ash/laser/laser_pointer_controller.h"
6 6
7 #include "ash/common/system/chromeos/palette/palette_utils.h" 7 #include "ash/common/system/chromeos/palette/palette_utils.h"
8 #include "ash/laser/laser_pointer_view.h" 8 #include "ash/laser/laser_pointer_view.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ui/display/screen.h" 10 #include "ui/display/screen.h"
11 #include "ui/views/widget/widget.h" 11 #include "ui/views/widget/widget.h"
12 12
13 namespace ash { 13 namespace ash {
14 namespace { 14 namespace {
15 15
16 // A point gets removed from the collection if it is older than 16 // A point gets removed from the collection if it is older than
17 // |kPointLifeDurationMs|. 17 // |kPointLifeDurationMs|.
18 const int kPointLifeDurationMs = 200; 18 const int kPointLifeDurationMs = 200;
19 19
20 // When no move events are being received we add a new point every 20 // When no move events are being received we add a new point every
21 // |kAddStationaryPointsDelayMs| so that points older than 21 // |kAddStationaryPointsDelayMs| so that points older than
22 // |kPointLifeDurationMs| can get removed. 22 // |kPointLifeDurationMs| can get removed.
23 const int kAddStationaryPointsDelayMs = 5; 23 const int kAddStationaryPointsDelayMs = 16;
jdufault 2017/02/28 20:25:08 Please document why 16ms is the minimum.
reveman 2017/03/02 14:42:39 Done. Also added a TODO about using the real VSYNC
24 24
25 } // namespace 25 } // namespace
26 26
27 LaserPointerController::LaserPointerController() 27 LaserPointerController::LaserPointerController()
28 : stationary_timer_(new base::Timer( 28 : stationary_timer_(new base::Timer(
29 FROM_HERE, 29 FROM_HERE,
30 base::TimeDelta::FromMilliseconds(kAddStationaryPointsDelayMs), 30 base::TimeDelta::FromMilliseconds(kAddStationaryPointsDelayMs),
31 base::Bind(&LaserPointerController::AddStationaryPoint, 31 base::Bind(&LaserPointerController::AddStationaryPoint,
32 base::Unretained(this)), 32 base::Unretained(this)),
33 true /* is_repeating */)) { 33 true /* is_repeating */)) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // add points when |laser_pointer_view_| is null. 121 // add points when |laser_pointer_view_| is null.
122 stationary_timer_->Stop(); 122 stationary_timer_->Stop();
123 if (laser_pointer_view_) { 123 if (laser_pointer_view_) {
124 is_fading_away_ = false; 124 is_fading_away_ = false;
125 laser_pointer_view_.reset(); 125 laser_pointer_view_.reset();
126 } 126 }
127 } 127 }
128 128
129 void LaserPointerController::RestartTimer() { 129 void LaserPointerController::RestartTimer() {
130 stationary_timer_repeat_count_ = 0; 130 stationary_timer_repeat_count_ = 0;
131 if (!stationary_timer_->IsRunning()) 131 stationary_timer_->Reset();
132 stationary_timer_->Reset();
133 } 132 }
134 133
135 void LaserPointerController::AddStationaryPoint() { 134 void LaserPointerController::AddStationaryPoint() {
136 if (is_fading_away_) 135 if (is_fading_away_)
137 laser_pointer_view_->UpdateTime(); 136 laser_pointer_view_->UpdateTime();
138 else 137 else
139 laser_pointer_view_->AddNewPoint(current_stylus_location_); 138 laser_pointer_view_->AddNewPoint(current_stylus_location_);
140 139
141 // We can stop repeating the timer once the stylus has been stationary for 140 // We can stop repeating the timer once the stylus has been stationary for
142 // longer than the life of a point. 141 // longer than the life of a point.
143 if (stationary_timer_repeat_count_ * kAddStationaryPointsDelayMs >= 142 if (stationary_timer_repeat_count_ * kAddStationaryPointsDelayMs >=
144 kPointLifeDurationMs) { 143 kPointLifeDurationMs) {
145 stationary_timer_->Stop(); 144 stationary_timer_->Stop();
146 // Reset the view if the timer expires and the view was in process of fading 145 // Reset the view if the timer expires and the view was in process of fading
147 // away. 146 // away.
148 if (is_fading_away_) 147 if (is_fading_away_)
149 DestroyLaserPointerView(); 148 DestroyLaserPointerView();
150 } 149 }
151 stationary_timer_repeat_count_++; 150 stationary_timer_repeat_count_++;
152 } 151 }
153 } // namespace ash 152 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698