OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/events/gesture_detection/motion_event_buffer.h" | 5 #include "ui/events/gesture_detection/motion_event_buffer.h" |
6 | 6 |
7 #include "base/trace_event/trace_event.h" | 7 #include "base/trace_event/trace_event.h" |
8 #include "ui/events/gesture_detection/motion_event_generic.h" | 8 #include "ui/events/gesture_detection/motion_event_generic.h" |
9 | 9 |
10 namespace ui { | 10 namespace ui { |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 // artificially synthesized. | 254 // artificially synthesized. |
255 if (!last_extrapolated_event_time_.is_null()) { | 255 if (!last_extrapolated_event_time_.is_null()) { |
256 DCHECK(buffered_events_.empty()); | 256 DCHECK(buffered_events_.empty()); |
257 if (event.GetEventTime() < last_extrapolated_event_time_) | 257 if (event.GetEventTime() < last_extrapolated_event_time_) |
258 return; | 258 return; |
259 last_extrapolated_event_time_ = base::TimeTicks(); | 259 last_extrapolated_event_time_ = base::TimeTicks(); |
260 } | 260 } |
261 | 261 |
262 scoped_ptr<MotionEventGeneric> clone = MotionEventGeneric::CloneEvent(event); | 262 scoped_ptr<MotionEventGeneric> clone = MotionEventGeneric::CloneEvent(event); |
263 if (buffered_events_.empty()) { | 263 if (buffered_events_.empty()) { |
264 buffered_events_.push_back(clone.release()); | 264 buffered_events_.push_back(clone.Pass()); |
265 client_->SetNeedsFlush(); | 265 client_->SetNeedsFlush(); |
266 return; | 266 return; |
267 } | 267 } |
268 | 268 |
269 if (CanAddSample(*buffered_events_.front(), *clone)) { | 269 if (CanAddSample(*buffered_events_.front(), *clone)) { |
270 DCHECK(buffered_events_.back()->GetEventTime() <= clone->GetEventTime()); | 270 DCHECK(buffered_events_.back()->GetEventTime() <= clone->GetEventTime()); |
271 } else { | 271 } else { |
272 FlushWithoutResampling(buffered_events_.Pass()); | 272 FlushWithoutResampling(buffered_events_.Pass()); |
273 } | 273 } |
274 | 274 |
275 buffered_events_.push_back(clone.release()); | 275 buffered_events_.push_back(clone.Pass()); |
276 // No need to request another flush as the first event will have requested it. | 276 // No need to request another flush as the first event will have requested it. |
277 } | 277 } |
278 | 278 |
279 void MotionEventBuffer::Flush(base::TimeTicks frame_time) { | 279 void MotionEventBuffer::Flush(base::TimeTicks frame_time) { |
280 if (buffered_events_.empty()) | 280 if (buffered_events_.empty()) |
281 return; | 281 return; |
282 | 282 |
283 // Shifting the sample time back slightly minimizes the potential for | 283 // Shifting the sample time back slightly minimizes the potential for |
284 // misprediction when extrapolating events. | 284 // misprediction when extrapolating events. |
285 if (resample_) | 285 if (resample_) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 331 |
332 void MotionEventBuffer::FlushWithoutResampling(MotionEventVector events) { | 332 void MotionEventBuffer::FlushWithoutResampling(MotionEventVector events) { |
333 last_extrapolated_event_time_ = base::TimeTicks(); | 333 last_extrapolated_event_time_ = base::TimeTicks(); |
334 if (events.empty()) | 334 if (events.empty()) |
335 return; | 335 return; |
336 | 336 |
337 client_->ForwardMotionEvent(*ConsumeSamples(events.Pass())); | 337 client_->ForwardMotionEvent(*ConsumeSamples(events.Pass())); |
338 } | 338 } |
339 | 339 |
340 } // namespace ui | 340 } // namespace ui |
OLD | NEW |