Flutter Engine
pointer_data_dispatcher.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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 "flutter/shell/common/pointer_data_dispatcher.h"
6 
7 #include "flutter/fml/trace_event.h"
8 
9 namespace flutter {
10 
13 
15  : DefaultPointerDataDispatcher(delegate), weak_factory_(this) {}
17 
19  std::unique_ptr<PointerDataPacket> packet,
20  uint64_t trace_flow_id) {
21  TRACE_EVENT0("flutter", "DefaultPointerDataDispatcher::DispatchPacket");
22  TRACE_FLOW_STEP("flutter", "PointerEvent", trace_flow_id);
23  delegate_.DoDispatchPacket(std::move(packet), trace_flow_id);
24 }
25 
27  std::unique_ptr<PointerDataPacket> packet,
28  uint64_t trace_flow_id) {
29  TRACE_EVENT0("flutter", "SmoothPointerDataDispatcher::DispatchPacket");
30  TRACE_FLOW_STEP("flutter", "PointerEvent", trace_flow_id);
31 
32  if (is_pointer_data_in_progress_) {
33  if (pending_packet_ != nullptr) {
34  DispatchPendingPacket();
35  }
36  pending_packet_ = std::move(packet);
37  pending_trace_flow_id_ = trace_flow_id;
38  } else {
39  FML_DCHECK(pending_packet_ == nullptr);
41  trace_flow_id);
42  }
43  is_pointer_data_in_progress_ = true;
44  ScheduleSecondaryVsyncCallback();
45 }
46 
47 void SmoothPointerDataDispatcher::ScheduleSecondaryVsyncCallback() {
49  reinterpret_cast<uintptr_t>(this),
50  [dispatcher = weak_factory_.GetWeakPtr()]() {
51  if (dispatcher && dispatcher->is_pointer_data_in_progress_) {
52  if (dispatcher->pending_packet_ != nullptr) {
53  dispatcher->DispatchPendingPacket();
54  } else {
55  dispatcher->is_pointer_data_in_progress_ = false;
56  }
57  }
58  });
59 }
60 
61 void SmoothPointerDataDispatcher::DispatchPendingPacket() {
62  FML_DCHECK(pending_packet_ != nullptr);
63  FML_DCHECK(is_pointer_data_in_progress_);
64  DefaultPointerDataDispatcher::DispatchPacket(std::move(pending_packet_),
65  pending_trace_flow_id_);
66  pending_packet_ = nullptr;
67  pending_trace_flow_id_ = -1;
68  ScheduleSecondaryVsyncCallback();
69 }
70 
71 } // namespace flutter
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:90
#define TRACE_FLOW_STEP(category, name, id)
Definition: trace_event.h:133
#define FML_DCHECK(condition)
Definition: logging.h:86
void DispatchPacket(std::unique_ptr< PointerDataPacket > packet, uint64_t trace_flow_id) override
Signal that PlatformView has a packet to be dispatched.
The interface for Engine to implement.
void DispatchPacket(std::unique_ptr< PointerDataPacket > packet, uint64_t trace_flow_id) override
Signal that PlatformView has a packet to be dispatched.
virtual ~PointerDataDispatcher()
Default destructor.
virtual void ScheduleSecondaryVsyncCallback(uintptr_t id, const fml::closure &callback)=0
Schedule a secondary callback to be executed right after the main VsyncWaiter::AsyncWaitForVsync call...
virtual void DoDispatchPacket(std::unique_ptr< PointerDataPacket > packet, uint64_t trace_flow_id)=0