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

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

Issue 2429953002: Implement compositor thread VSync aligned event queue (Closed)
Patch Set: tdresser's review: Move CanCoalesce/Coalesce; Test queueing time Created 4 years, 1 month 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 #include "ui/events/blink/event_with_callback.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "ui/events/blink/blink_event_util.h"
9 #include "ui/events/blink/did_overscroll_params.h"
10 #include "ui/events/blink/web_input_event_traits.h"
11
12 using blink::WebInputEvent;
13 using blink::WebGestureEvent;
14
15 namespace ui {
16
17 std::unique_ptr<base::TimeTicks> EventWithCallback::testing_timestamp_now_ =
18 nullptr;
19
20 EventWithCallback::EventWithCallback(
21 ScopedWebInputEvent event,
22 const LatencyInfo& latency,
23 const InputHandlerProxy::EventDispositionCallback& callback)
24 : event_(WebInputEventTraits::Clone(*event)),
25 latency_(latency),
26 creation_timestamp_(testing_timestamp_now_ ? *testing_timestamp_now_
27 : base::TimeTicks::Now()),
28 last_coalesced_timestamp_(creation_timestamp_) {
29 original_events_.emplace_back(std::move(event), callback);
30 }
31
32 EventWithCallback::~EventWithCallback() {}
33
34 bool EventWithCallback::CanCoalesceWith(const EventWithCallback& other) const {
35 return CanCoalesce(other.event(), event());
36 }
37
38 void EventWithCallback::CoalesceWith(EventWithCallback* other) {
39 // |other| should be a newer event than |this|.
40 if (other->latency_.trace_id() >= 0 && latency_.trace_id() >= 0)
41 DCHECK_GT(other->latency_.trace_id(), latency_.trace_id());
42
43 // New events get coalesced into older events, and the newer timestamp
44 // should always be preserved.
45 const double time_stamp_seconds = other->event().timeStampSeconds;
46 Coalesce(other->event(), event_.get());
47 event_->timeStampSeconds = time_stamp_seconds;
48
49 // When coalescing two input events, we keep the oldest LatencyInfo
50 // since it will represent the longest latency.
51 other->latency_ = latency_;
52 other->latency_.set_coalesced();
53
54 // Move original events.
55 original_events_.splice(original_events_.end(), other->original_events_);
56 last_coalesced_timestamp_ =
57 testing_timestamp_now_ ? *testing_timestamp_now_ : base::TimeTicks::Now();
58 }
59
60 void EventWithCallback::RunCallbacks(
61 InputHandlerProxy::EventDisposition disposition,
62 const LatencyInfo& latency,
63 std::unique_ptr<DidOverscrollParams> did_overscroll_params) {
64 for (auto& original_event : original_events_) {
65 std::unique_ptr<DidOverscrollParams> did_overscroll_params_copy;
66 if (did_overscroll_params) {
67 did_overscroll_params_copy =
68 base::MakeUnique<DidOverscrollParams>(*did_overscroll_params);
69 }
70 original_event.callback_.Run(disposition, std::move(original_event.event_),
71 latency, std::move(did_overscroll_params));
72 }
73 }
74
75 EventWithCallback::OriginalEventWithCallback::OriginalEventWithCallback(
76 ScopedWebInputEvent event,
77 const InputHandlerProxy::EventDispositionCallback& callback)
78 : event_(std::move(event)), callback_(callback) {}
79
80 EventWithCallback::OriginalEventWithCallback::~OriginalEventWithCallback() {}
81
82 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698