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

Unified Diff: content/renderer/input/main_thread_event_queue.cc

Issue 2166703003: Implement Main Thread RAF Aligned Input (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master_main_thread_queue
Patch Set: Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/input/main_thread_event_queue.cc
diff --git a/content/renderer/input/main_thread_event_queue.cc b/content/renderer/input/main_thread_event_queue.cc
index 57d001b1f59861deec2751f76c36e25fb3643c19..de137918a8f1aa01e4b88a834389d2108f6aa59e 100644
--- a/content/renderer/input/main_thread_event_queue.cc
+++ b/content/renderer/input/main_thread_event_queue.cc
@@ -8,6 +8,20 @@
namespace content {
+namespace {
+const size_t kMaxEventsPerVSyncEvent = 10;
tdresser 2016/07/20 21:43:09 Add a comment about this constant - why do we need
+bool isVSyncAlignedEvent(const std::unique_ptr<EventWithDispatchType>& event) {
tdresser 2016/07/20 21:43:09 I'd name this something like eventCanBeRafAligned.
+ switch (event->event().type) {
+ case blink::WebInputEvent::MouseMove:
+ case blink::WebInputEvent::TouchMove:
+ case blink::WebInputEvent::MouseWheel:
+ return true;
+ default:
+ return false;
+ }
+}
+} // namespace
+
EventWithDispatchType::EventWithDispatchType(
const blink::WebInputEvent& event,
const ui::LatencyInfo& latency,
@@ -42,6 +56,7 @@ MainThreadEventQueue::MainThreadEventQueue(
: routing_id_(routing_id),
client_(client),
is_flinging_(false),
+ notification_sent_to_main_(false),
main_task_runner_(main_task_runner) {}
MainThreadEventQueue::~MainThreadEventQueue() {}
@@ -83,13 +98,7 @@ bool MainThreadEventQueue::HandleEvent(
return non_blocking;
}
-void MainThreadEventQueue::PopEventOnMainThread() {
- {
- base::AutoLock lock(event_queue_mutex_);
- if (!events_.empty())
- in_flight_event_ = events_.Pop();
- }
-
+void MainThreadEventQueue::DispatchInFlightEvent() {
if (in_flight_event_) {
InputEventDispatchType dispatch_type = in_flight_event_->dispatchType();
if (!in_flight_event_->eventsToAck().empty() &&
@@ -102,11 +111,23 @@ void MainThreadEventQueue::PopEventOnMainThread() {
}
in_flight_event_.reset();
+}
+
+void MainThreadEventQueue::PopEventOnMainThread() {
+ {
+ base::AutoLock lock(event_queue_mutex_);
+ if (!events_.empty())
+ in_flight_event_ = events_.Pop();
+ }
+
+ DispatchInFlightEvent();
+
{
base::AutoLock lock(event_queue_mutex_);
- if (!events_.empty()) {
+ if (!events_.empty())
SendEventNotificationToMainThread();
- }
+ else
+ notification_sent_to_main_ = false;
}
}
@@ -120,6 +141,22 @@ void MainThreadEventQueue::EventHandled(blink::WebInputEvent::Type type,
}
}
+void MainThreadEventQueue::DispatchVSyncAlignedInput() {
+ size_t i = 0;
+ for (; i < kMaxEventsPerVSyncEvent; ++i) {
+ {
+ base::AutoLock lock(event_queue_mutex_);
+ if (events_.empty())
+ break;
+ if (!isVSyncAlignedEvent(events_.Top()))
+ break;
+ in_flight_event_ = events_.Pop();
+ }
+ DispatchInFlightEvent();
+ }
+ LOG(ERROR) << "Processed " << i << " events in RAF";
tdresser 2016/07/20 21:43:08 Remember to remove this before landing (and make t
+}
+
void MainThreadEventQueue::SendEventNotificationToMainThread() {
main_task_runner_->PostTask(
FROM_HERE, base::Bind(&MainThreadEventQueue::PopEventOnMainThread,
@@ -128,13 +165,17 @@ void MainThreadEventQueue::SendEventNotificationToMainThread() {
void MainThreadEventQueue::QueueEvent(
std::unique_ptr<EventWithDispatchType>&& event) {
- size_t pending;
+ bool isVsynced = isVSyncAlignedEvent(event);
tdresser 2016/07/20 21:43:08 Inconsistent casing here.
+ bool send_notification = false;
{
base::AutoLock lock(event_queue_mutex_);
- pending = events_.size();
events_.Queue(std::move(event));
+ if (!isVsynced && !notification_sent_to_main_) {
+ send_notification = true;
+ notification_sent_to_main_ = true;
+ }
}
- if (pending == 0)
+ if (send_notification)
SendEventNotificationToMainThread();
}

Powered by Google App Engine
This is Rietveld 408576698