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

Side by Side Diff: ui/events/blink/compositor_thread_event_queue.cc

Issue 2552853002: [Compositor event queue] Coalesce gesture scroll&pinch of the same sequence (Closed)
Patch Set: sadrul's comments, fix dependency Created 4 years 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 | « ui/events/blink/blink_event_util.cc ('k') | ui/events/blink/event_with_callback.h » ('j') | 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 "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(ToWebGestureEvent(new_event->event()),
18 queue_.back()->CoalesceWith(event.get(), timestamp_now); 22 ToWebGestureEvent(queue_.back()->event()))) {
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 // Extract the last event in queue.
33 std::unique_ptr<EventWithCallback> last_event = std::move(queue_.back());
34 queue_.pop_back();
35 DCHECK_LE(last_event->latency_info().trace_id(),
36 new_event->latency_info().trace_id());
37 LatencyInfo oldest_latency = last_event->latency_info();
38 oldest_latency.set_coalesced();
39 base::TimeTicks oldest_creation_timestamp = last_event->creation_timestamp();
40 auto combined_original_events =
41 base::MakeUnique<EventWithCallback::OriginalEventList>();
42 combined_original_events->splice(combined_original_events->end(),
43 last_event->original_events());
44 combined_original_events->splice(combined_original_events->end(),
45 new_event->original_events());
46
47 // Extract the second last event in queue.
48 std::unique_ptr<EventWithCallback> second_last_event = nullptr;
49 if (!queue_.empty() &&
50 IsCompatibleScrollorPinch(ToWebGestureEvent(new_event->event()),
51 ToWebGestureEvent(queue_.back()->event()))) {
52 second_last_event = std::move(queue_.back());
53 queue_.pop_back();
54 DCHECK_LE(second_last_event->latency_info().trace_id(),
55 oldest_latency.trace_id());
56 oldest_latency = second_last_event->latency_info();
57 oldest_latency.set_coalesced();
58 oldest_creation_timestamp = second_last_event->creation_timestamp();
59 combined_original_events->splice(combined_original_events->begin(),
60 second_last_event->original_events());
61 }
62
63 std::pair<blink::WebGestureEvent, blink::WebGestureEvent> coalesced_events =
64 CoalesceScrollAndPinch(
65 second_last_event ? &ToWebGestureEvent(second_last_event->event())
66 : nullptr,
67 ToWebGestureEvent(last_event->event()),
68 ToWebGestureEvent(new_event->event()));
69
70 std::unique_ptr<EventWithCallback> scroll_event =
71 base::MakeUnique<EventWithCallback>(
72 WebInputEventTraits::Clone(coalesced_events.first), oldest_latency,
73 oldest_creation_timestamp, timestamp_now, nullptr);
74
75 std::unique_ptr<EventWithCallback> pinch_event =
76 base::MakeUnique<EventWithCallback>(
77 WebInputEventTraits::Clone(coalesced_events.second), oldest_latency,
78 oldest_creation_timestamp, timestamp_now,
79 std::move(combined_original_events));
80
81 queue_.emplace_back(std::move(scroll_event));
82 queue_.emplace_back(std::move(pinch_event));
23 } 83 }
24 84
25 std::unique_ptr<EventWithCallback> CompositorThreadEventQueue::Pop() { 85 std::unique_ptr<EventWithCallback> CompositorThreadEventQueue::Pop() {
26 std::unique_ptr<EventWithCallback> result; 86 std::unique_ptr<EventWithCallback> result;
27 if (!queue_.empty()) { 87 if (!queue_.empty()) {
28 result.reset(queue_.front().release()); 88 result.reset(queue_.front().release());
29 queue_.pop_front(); 89 queue_.pop_front();
30 } 90 }
31 return result; 91 return result;
32 } 92 }
33 93
34 } // namespace ui 94 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/blink/blink_event_util.cc ('k') | ui/events/blink/event_with_callback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698