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 namespace flutter {
8 
11 
13  : DefaultPointerDataDispatcher(delegate), weak_factory_(this) {}
15 
17  std::unique_ptr<PointerDataPacket> packet,
18  uint64_t trace_flow_id) {
19  delegate_.DoDispatchPacket(std::move(packet), trace_flow_id);
20 }
21 
23  std::unique_ptr<PointerDataPacket> packet,
24  uint64_t trace_flow_id) {
25  if (is_pointer_data_in_progress_) {
26  if (pending_packet_ != nullptr) {
27  DispatchPendingPacket();
28  }
29  pending_packet_ = std::move(packet);
30  pending_trace_flow_id_ = trace_flow_id;
31  } else {
32  FML_DCHECK(pending_packet_ == nullptr);
34  trace_flow_id);
35  }
36  is_pointer_data_in_progress_ = true;
37  ScheduleSecondaryVsyncCallback();
38 }
39 
40 void SmoothPointerDataDispatcher::ScheduleSecondaryVsyncCallback() {
42  [dispatcher = weak_factory_.GetWeakPtr()]() {
43  if (dispatcher && dispatcher->is_pointer_data_in_progress_) {
44  if (dispatcher->pending_packet_ != nullptr) {
45  dispatcher->DispatchPendingPacket();
46  } else {
47  dispatcher->is_pointer_data_in_progress_ = false;
48  }
49  }
50  });
51 }
52 
53 void SmoothPointerDataDispatcher::DispatchPendingPacket() {
54  FML_DCHECK(pending_packet_ != nullptr);
55  FML_DCHECK(is_pointer_data_in_progress_);
56  DefaultPointerDataDispatcher::DispatchPacket(std::move(pending_packet_),
57  pending_trace_flow_id_);
58  pending_packet_ = nullptr;
59  pending_trace_flow_id_ = -1;
60  ScheduleSecondaryVsyncCallback();
61 }
62 
63 } // namespace flutter
#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 DoDispatchPacket(std::unique_ptr< PointerDataPacket > packet, uint64_t trace_flow_id)=0
virtual void ScheduleSecondaryVsyncCallback(const fml::closure &callback)=0
Schedule a secondary callback to be executed right after the main VsyncWaiter::AsyncWaitForVsync call...