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

Side by Side Diff: content/common/input/web_input_event_queue.h

Issue 2162143002: Don't use PostTask queueing between compositor and main thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't ack mouse move right away send them unthrottled 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 unified diff | Download patch
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 #ifndef CONTENT_COMMON_INPUT_WEB_INPUT_EVENT_QUEUE_H_ 5 #ifndef CONTENT_COMMON_INPUT_WEB_INPUT_EVENT_QUEUE_H_
6 #define CONTENT_COMMON_INPUT_WEB_INPUT_EVENT_QUEUE_H_ 6 #define CONTENT_COMMON_INPUT_WEB_INPUT_EVENT_QUEUE_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <memory> 9 #include <memory>
10 10
11 namespace content { 11 namespace content {
12 12
13 enum class WebInputEventQueueState { ITEM_PENDING, ITEM_NOT_PENDING }; 13 // WebInputEventQueue is a coalescing queue.
tdresser 2016/07/20 20:52:27 Could the changes in this file be made separately
dtapuska 2016/07/27 05:29:00 Done.
14
15 // WebInputEventQueue is a coalescing queue with the addition of a state
16 // variable that represents whether an item is pending to be processed.
17 // The desired usage sending with this queue is: 14 // The desired usage sending with this queue is:
18 // if (queue.state() == WebInputEventQueueState::ITEM_PENDING) { 15 // bool send_notification = queue.empty();
19 // queue.Queue(T); 16 // queue.Queue(T);
20 // } else { 17 // send notification
tdresser 2016/07/20 20:52:27 This is a somewhat odd pseudo-pseudo-code. I'd pr
dtapuska 2016/07/27 05:29:00 Done.
21 // send T
22 // queue.set_state(WebInputEventQueueState::ITEM_PENDING);
23 // }
24 // 18 //
25 // Processing the event response: 19 // Processing the event response:
26 // if (!queue.empty()) { 20 // if (!queue.empty()) {
27 // T = queue.Pop(); 21 // T = queue.Pop();
28 // send T now 22 // send T now
29 // } else { 23 // } else {
30 // queue.set_state(WebInputEventQueueState::ITEM_NOT_PENDING); 24 // queue.set_state(WebInputEventQueueState::ITEM_NOT_PENDING);
tdresser 2016/07/20 20:52:27 Update comment.
31 // } 25 // }
32 // 26 //
33 template <typename T> 27 template <typename T>
34 class WebInputEventQueue { 28 class WebInputEventQueue {
35 public: 29 public:
36 WebInputEventQueue() : state_(WebInputEventQueueState::ITEM_NOT_PENDING) {} 30 WebInputEventQueue() {}
37 31
38 // Adds an event to the queue. The event may be coalesced with previously 32 // Adds an event to the queue. The event may be coalesced with previously
39 // queued events. 33 // queued events.
40 void Queue(const T& event) { 34 void Queue(std::unique_ptr<T>&& event) {
41 if (!queue_.empty()) { 35 for (auto last_event_iter = queue_.rbegin();
42 std::unique_ptr<T>& last_event = queue_.back(); 36 last_event_iter != queue_.rend(); ++last_event_iter) {
tdresser 2016/07/20 20:52:27 Range based for?
dtapuska 2016/07/27 05:29:00 It's a reverse iteration; so you can't do a revers
43 if (last_event->CanCoalesceWith(event)) { 37 if (!(*last_event_iter)->event().isSameEventClass(event->event())) {
44 last_event->CoalesceWith(event); 38 continue;
39 }
40
41 if ((*last_event_iter)->CanCoalesceWith(*event.get())) {
tdresser 2016/07/20 20:52:27 Could we get weird out of order coalescing happeni
dtapuska 2016/07/27 05:29:00 No because it should stop at the most recent gestu
42 (*last_event_iter)->CoalesceWith(*event.get());
45 return; 43 return;
46 } 44 }
45 break;
47 } 46 }
48 queue_.emplace_back(std::unique_ptr<T>(new T(event))); 47 queue_.emplace_back(std::move(event));
49 } 48 }
50 49
51 std::unique_ptr<T> Pop() { 50 std::unique_ptr<T> Pop() {
52 std::unique_ptr<T> result; 51 std::unique_ptr<T> result;
53 if (!queue_.empty()) { 52 if (!queue_.empty()) {
54 result.reset(queue_.front().release()); 53 result.reset(queue_.front().release());
55 queue_.pop_front(); 54 queue_.pop_front();
56 } 55 }
57 return result; 56 return result;
58 } 57 }
59 58
60 bool empty() const { return queue_.empty(); } 59 bool empty() const { return queue_.empty(); }
61 60
62 size_t size() const { return queue_.size(); } 61 size_t size() const { return queue_.size(); }
63 62
64 void set_state(WebInputEventQueueState state) { state_ = state; }
65
66 WebInputEventQueueState state() const WARN_UNUSED_RESULT { return state_; }
67
68 private: 63 private:
69 typedef std::deque<std::unique_ptr<T>> EventQueue; 64 typedef std::deque<std::unique_ptr<T>> EventQueue;
70 EventQueue queue_; 65 EventQueue queue_;
71 WebInputEventQueueState state_;
72 66
73 DISALLOW_COPY_AND_ASSIGN(WebInputEventQueue); 67 DISALLOW_COPY_AND_ASSIGN(WebInputEventQueue);
74 }; 68 };
75 69
76 } // namespace content 70 } // namespace content
77 71
78 #endif // CONTENT_COMMON_INPUT_WEB_INPUT_EVENT_QUEUE_H_ 72 #endif // CONTENT_COMMON_INPUT_WEB_INPUT_EVENT_QUEUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698