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 "ui/events/blink/compositor_thread_event_queue.h" | 5 #include "ui/events/blink/compositor_thread_event_queue.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | |
8 #include "ui/events/blink/blink_event_util.h" | |
9 #include "ui/events/blink/web_input_event_traits.h" | |
10 | |
7 namespace ui { | 11 namespace ui { |
8 | 12 |
9 CompositorThreadEventQueue::CompositorThreadEventQueue() {} | 13 CompositorThreadEventQueue::CompositorThreadEventQueue() {} |
10 | 14 |
11 CompositorThreadEventQueue::~CompositorThreadEventQueue() {} | 15 CompositorThreadEventQueue::~CompositorThreadEventQueue() {} |
12 | 16 |
13 // TODO(chongz): Support coalescing events across interleaved boundaries. | 17 void CompositorThreadEventQueue::Queue( |
14 // https://crbug.com/661601 | 18 std::unique_ptr<EventWithCallback> new_event, |
15 void CompositorThreadEventQueue::Queue(std::unique_ptr<EventWithCallback> event, | 19 base::TimeTicks timestamp_now) { |
16 base::TimeTicks timestamp_now) { | 20 if (queue_.empty() || !IsContinuousGestureEvent(new_event->event().type) || |
17 if (!queue_.empty() && queue_.back()->CanCoalesceWith(*event)) { | 21 !IsCompatibleScrollorPinch(new_event->ToWebGestureEvent(), |
18 queue_.back()->CoalesceWith(event.get(), timestamp_now); | 22 queue_.back()->ToWebGestureEvent())) { |
23 queue_.emplace_back(std::move(new_event)); | |
19 return; | 24 return; |
20 } | 25 } |
21 | 26 |
22 queue_.emplace_back(std::move(event)); | 27 if (queue_.back()->CanCoalesceWith(*new_event)) { |
28 queue_.back()->CoalesceWith(new_event.get(), timestamp_now); | |
29 return; | |
30 } | |
31 | |
32 // Coalesce |GestureScrollUpdate| and |GesturePinchUpdate| in one sequence. | |
33 EventWithCallback* last_event = queue_.back().get(); | |
34 EventWithCallback* second_last_event = nullptr; | |
35 if (queue_.size() > 1 && | |
36 IsCompatibleScrollorPinch( | |
37 new_event->ToWebGestureEvent(), | |
38 queue_[queue_.size() - 2]->ToWebGestureEvent())) { | |
39 second_last_event = queue_[queue_.size() - 2].get(); | |
40 } | |
41 | |
42 std::pair<blink::WebGestureEvent, blink::WebGestureEvent> coalesced_events = | |
dtapuska
2016/12/08 15:18:37
Isn't this complicated logic if second_last_event
chongz
2016/12/09 20:52:25
As discussed we have to go through the matrix as 2
| |
43 CoalesceScrollAndPinch( | |
44 second_last_event ? &second_last_event->ToWebGestureEvent() : nullptr, | |
45 last_event->ToWebGestureEvent(), new_event->ToWebGestureEvent()); | |
46 | |
47 DCHECK_LE(last_event->latency_info().trace_id(), | |
48 new_event->latency_info().trace_id()); | |
49 if (second_last_event) { | |
50 DCHECK_LE(second_last_event->latency_info().trace_id(), | |
51 last_event->latency_info().trace_id()); | |
52 } | |
53 LatencyInfo oldest_latency = second_last_event | |
54 ? second_last_event->latency_info() | |
55 : last_event->latency_info(); | |
56 oldest_latency.set_coalesced(); | |
57 const base::TimeTicks oldest_creation_timestamp = | |
58 second_last_event ? second_last_event->creation_timestamp() | |
59 : last_event->creation_timestamp(); | |
60 | |
61 // Creating 2 events, but store original events in the last one. | |
62 auto combined_original_events = | |
63 base::MakeUnique<EventWithCallback::OriginalEventList>(); | |
64 if (second_last_event) { | |
65 combined_original_events->splice(combined_original_events->end(), | |
66 second_last_event->original_events()); | |
67 } | |
68 combined_original_events->splice(combined_original_events->end(), | |
69 last_event->original_events()); | |
70 combined_original_events->splice(combined_original_events->end(), | |
71 new_event->original_events()); | |
72 | |
73 std::unique_ptr<EventWithCallback> scroll_event = | |
74 base::MakeUnique<EventWithCallback>( | |
75 WebInputEventTraits::Clone(coalesced_events.first), oldest_latency, | |
76 oldest_creation_timestamp, timestamp_now, nullptr); | |
77 | |
78 std::unique_ptr<EventWithCallback> pinch_event = | |
79 base::MakeUnique<EventWithCallback>( | |
80 WebInputEventTraits::Clone(coalesced_events.second), oldest_latency, | |
81 oldest_creation_timestamp, timestamp_now, | |
82 std::move(combined_original_events)); | |
83 | |
84 // Pop |last_event| and |second_last_event| first. | |
85 queue_.pop_back(); | |
86 if (second_last_event) | |
87 queue_.pop_back(); | |
88 queue_.emplace_back(std::move(scroll_event)); | |
89 queue_.emplace_back(std::move(pinch_event)); | |
23 } | 90 } |
24 | 91 |
25 std::unique_ptr<EventWithCallback> CompositorThreadEventQueue::Pop() { | 92 std::unique_ptr<EventWithCallback> CompositorThreadEventQueue::Pop() { |
26 std::unique_ptr<EventWithCallback> result; | 93 std::unique_ptr<EventWithCallback> result; |
27 if (!queue_.empty()) { | 94 if (!queue_.empty()) { |
28 result.reset(queue_.front().release()); | 95 result.reset(queue_.front().release()); |
29 queue_.pop_front(); | 96 queue_.pop_front(); |
30 } | 97 } |
31 return result; | 98 return result; |
32 } | 99 } |
33 | 100 |
34 } // namespace ui | 101 } // namespace ui |
OLD | NEW |