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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/blink/compositor_thread_event_queue.cc
diff --git a/ui/events/blink/compositor_thread_event_queue.cc b/ui/events/blink/compositor_thread_event_queue.cc
index 58290fd98b2e01e27b0da3a6c4806be98293a0a5..6c67c33497c0c36a39c2af1203bcdb28f7773624 100644
--- a/ui/events/blink/compositor_thread_event_queue.cc
+++ b/ui/events/blink/compositor_thread_event_queue.cc
@@ -4,22 +4,82 @@
#include "ui/events/blink/compositor_thread_event_queue.h"
+#include "base/memory/ptr_util.h"
+#include "ui/events/blink/blink_event_util.h"
+#include "ui/events/blink/web_input_event_traits.h"
+
namespace ui {
CompositorThreadEventQueue::CompositorThreadEventQueue() {}
CompositorThreadEventQueue::~CompositorThreadEventQueue() {}
-// TODO(chongz): Support coalescing events across interleaved boundaries.
-// https://crbug.com/661601
-void CompositorThreadEventQueue::Queue(std::unique_ptr<EventWithCallback> event,
- base::TimeTicks timestamp_now) {
- if (!queue_.empty() && queue_.back()->CanCoalesceWith(*event)) {
- queue_.back()->CoalesceWith(event.get(), timestamp_now);
+void CompositorThreadEventQueue::Queue(
+ std::unique_ptr<EventWithCallback> new_event,
+ base::TimeTicks timestamp_now) {
+ if (queue_.empty() || !IsContinuousGestureEvent(new_event->event().type) ||
+ !IsCompatibleScrollorPinch(ToWebGestureEvent(new_event->event()),
+ ToWebGestureEvent(queue_.back()->event()))) {
+ queue_.emplace_back(std::move(new_event));
return;
}
- queue_.emplace_back(std::move(event));
+ if (queue_.back()->CanCoalesceWith(*new_event)) {
+ queue_.back()->CoalesceWith(new_event.get(), timestamp_now);
+ return;
+ }
+
+ // Extract the last event in queue.
+ std::unique_ptr<EventWithCallback> last_event = std::move(queue_.back());
+ queue_.pop_back();
+ DCHECK_LE(last_event->latency_info().trace_id(),
+ new_event->latency_info().trace_id());
+ LatencyInfo oldest_latency = last_event->latency_info();
+ oldest_latency.set_coalesced();
+ base::TimeTicks oldest_creation_timestamp = last_event->creation_timestamp();
+ auto combined_original_events =
+ base::MakeUnique<EventWithCallback::OriginalEventList>();
+ combined_original_events->splice(combined_original_events->end(),
+ last_event->original_events());
+ combined_original_events->splice(combined_original_events->end(),
+ new_event->original_events());
+
+ // Extract the second last event in queue.
+ std::unique_ptr<EventWithCallback> second_last_event = nullptr;
+ if (!queue_.empty() &&
+ IsCompatibleScrollorPinch(ToWebGestureEvent(new_event->event()),
+ ToWebGestureEvent(queue_.back()->event()))) {
+ second_last_event = std::move(queue_.back());
+ queue_.pop_back();
+ DCHECK_LE(second_last_event->latency_info().trace_id(),
+ oldest_latency.trace_id());
+ oldest_latency = second_last_event->latency_info();
+ oldest_latency.set_coalesced();
+ oldest_creation_timestamp = second_last_event->creation_timestamp();
+ combined_original_events->splice(combined_original_events->begin(),
+ second_last_event->original_events());
+ }
+
+ std::pair<blink::WebGestureEvent, blink::WebGestureEvent> coalesced_events =
+ CoalesceScrollAndPinch(
+ second_last_event ? &ToWebGestureEvent(second_last_event->event())
+ : nullptr,
+ ToWebGestureEvent(last_event->event()),
+ ToWebGestureEvent(new_event->event()));
+
+ std::unique_ptr<EventWithCallback> scroll_event =
+ base::MakeUnique<EventWithCallback>(
+ WebInputEventTraits::Clone(coalesced_events.first), oldest_latency,
+ oldest_creation_timestamp, timestamp_now, nullptr);
+
+ std::unique_ptr<EventWithCallback> pinch_event =
+ base::MakeUnique<EventWithCallback>(
+ WebInputEventTraits::Clone(coalesced_events.second), oldest_latency,
+ oldest_creation_timestamp, timestamp_now,
+ std::move(combined_original_events));
+
+ queue_.emplace_back(std::move(scroll_event));
+ queue_.emplace_back(std::move(pinch_event));
}
std::unique_ptr<EventWithCallback> CompositorThreadEventQueue::Pop() {
« 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