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

Side by Side Diff: content/renderer/input/main_thread_event_queue.h

Issue 1780953003: Change the non-blocking event queue to the main thread event queue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master_wheel_regression_5
Patch Set: Fix android Created 4 years, 9 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_
6 #define CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_
7
8 #include <deque>
9 #include "content/common/content_export.h"
10 #include "content/common/input/event_with_latency_info.h"
11 #include "content/common/input/input_event_ack_state.h"
12 #include "content/common/input/input_event_dispatch_type.h"
13 #include "content/common/input/web_input_event_queue.h"
14 #include "third_party/WebKit/public/web/WebInputEvent.h"
15 #include "ui/events/latency_info.h"
16
17 namespace content {
18
19 template <typename BaseClass, typename BaseType>
20 class EventWithDispatchType : public BaseClass {
21 public:
22 EventWithDispatchType(const BaseType& e,
23 const ui::LatencyInfo& l,
24 InputEventDispatchType t)
25 : BaseClass(e, l), type(t) {}
26
27 InputEventDispatchType type;
28
29 bool CanCoalesceWith(const EventWithDispatchType& other) const
30 WARN_UNUSED_RESULT {
31 return other.type == type && BaseClass::CanCoalesceWith(other);
32 }
33
34 void CoalesceWith(const EventWithDispatchType& other) {
35 BaseClass::CoalesceWith(other);
36 }
37 };
38
39 using PendingMouseWheelEvent =
40 EventWithDispatchType<MouseWheelEventWithLatencyInfo,
41 blink::WebMouseWheelEvent>;
42
43 using PendingTouchEvent =
44 EventWithDispatchType<TouchEventWithLatencyInfo, blink::WebTouchEvent>;
45
46 class CONTENT_EXPORT MainThreadEventQueueClient {
47 public:
48 // Send an |event| that was previously queued (possibly
49 // coalesced with another event) to the |routing_id|'s
50 // channel. Implementors must implement this callback.
51 virtual void SendEventToMainThread(int routing_id,
52 const blink::WebInputEvent* event,
53 const ui::LatencyInfo& latency,
54 InputEventDispatchType dispatch_type) = 0;
55 };
56
57 // MainThreadEventQueue implements a series of queues (one touch
58 // and one mouse wheel) for events that need to be queued between
59 // the compositor and main threads. When an event is sent
60 // from the compositor to main it can either be sent directly if no
61 // outstanding events of that type are in flight; or it needs to
62 // wait in a queue until the main thread has finished processing
63 // the in-flight event. This class tracks the state and queues
64 // for the event types. Methods on this class should only be called
65 // from the compositor thread.
66 //
67 // Below some example flows are how the code behaves.
68 // Legend: B=Browser, C=Compositor, M=Main Thread, NB=Non-blocking
69 // BL=Blocking, PT=Post Task, ACK=Acknowledgement
70 //
71 // Normal blocking event sent to main thread.
72 // B C M
73 // ---(BL)-->
74 // ---(PT)-->
75 // <-------(ACK)------
76 //
77 // Non-blocking event sent to main thread.
78 // B C M
79 // ---(NB)-->
80 // ---(PT)-->
81 // <--(PT)---
82 //
83 // Non-blocking followed by blocking event sent to main thread.
84 // B C M
85 // ---(NB)-->
86 // ---(PT)-->
87 // ---(BL)-->
88 // <--(PT)--- // Notify from NB event.
89 // ---(PT)--> // Release blocking event.
90 // <--(PT)--- // Notify from BL event.
91 // <-------(ACK)------
92 //
93 class CONTENT_EXPORT MainThreadEventQueue {
94 public:
95 MainThreadEventQueue(int routing_id, MainThreadEventQueueClient* client);
96 ~MainThreadEventQueue();
97
98 // Called once the compositor has handled |event| and indicated that it is
99 // a non-blocking event to be queued to the main thread.
100 bool HandleEvent(const blink::WebInputEvent* event,
101 const ui::LatencyInfo& latency,
102 InputEventDispatchType dispatch_type,
103 InputEventAckState ack_result);
104
105 // Call once the main thread has handled an outstanding |type| event
106 // in flight.
107 void EventHandled(blink::WebInputEvent::Type type);
108
109 private:
110 friend class MainThreadEventQueueTest;
111 int routing_id_;
112 MainThreadEventQueueClient* client_;
113 WebInputEventQueue<PendingMouseWheelEvent> wheel_events_;
114 WebInputEventQueue<PendingTouchEvent> touch_events_;
115
116 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue);
117 };
118
119 } // namespace content
120
121 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_
OLDNEW
« no previous file with comments | « content/renderer/input/input_handler_manager_client.h ('k') | content/renderer/input/main_thread_event_queue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698