Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
9namespace flutter {
10
13
17
19 std::unique_ptr<PointerDataPacket> packet,
20 uint64_t trace_flow_id) {
22 "DefaultPointerDataDispatcher::DispatchPacket",
23 /*flow_id_count=*/1, &trace_flow_id);
24 TRACE_FLOW_STEP("flutter", "PointerEvent", trace_flow_id);
25 delegate_.DoDispatchPacket(std::move(packet), trace_flow_id);
26}
27
29 std::unique_ptr<PointerDataPacket> packet,
30 uint64_t trace_flow_id) {
32 "SmoothPointerDataDispatcher::DispatchPacket",
33 /*flow_id_count=*/1, &trace_flow_id);
34 TRACE_FLOW_STEP("flutter", "PointerEvent", trace_flow_id);
35
36 if (is_pointer_data_in_progress_) {
37 if (pending_packet_ != nullptr) {
38 DispatchPendingPacket();
39 }
40 pending_packet_ = std::move(packet);
41 pending_trace_flow_id_ = trace_flow_id;
42 } else {
43 FML_DCHECK(pending_packet_ == nullptr);
45 trace_flow_id);
46 }
47 is_pointer_data_in_progress_ = true;
48 ScheduleSecondaryVsyncCallback();
49}
50
51void SmoothPointerDataDispatcher::ScheduleSecondaryVsyncCallback() {
53 reinterpret_cast<uintptr_t>(this),
54 [dispatcher = weak_factory_.GetWeakPtr()]() {
55 if (dispatcher && dispatcher->is_pointer_data_in_progress_) {
56 if (dispatcher->pending_packet_ != nullptr) {
57 dispatcher->DispatchPendingPacket();
58 } else {
59 dispatcher->is_pointer_data_in_progress_ = false;
60 }
61 }
62 });
63}
64
65void SmoothPointerDataDispatcher::DispatchPendingPacket() {
66 FML_DCHECK(pending_packet_ != nullptr);
67 FML_DCHECK(is_pointer_data_in_progress_);
68 DefaultPointerDataDispatcher::DispatchPacket(std::move(pending_packet_),
69 pending_trace_flow_id_);
70 pending_packet_ = nullptr;
71 pending_trace_flow_id_ = -1;
72 ScheduleSecondaryVsyncCallback();
73}
74
75} // namespace flutter
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.
virtual void DoDispatchPacket(std::unique_ptr< PointerDataPacket > packet, uint64_t trace_flow_id)=0
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 ~PointerDataDispatcher()
Default destructor.
void DispatchPacket(std::unique_ptr< PointerDataPacket > packet, uint64_t trace_flow_id) override
Signal that PlatformView has a packet to be dispatched.
#define FML_DCHECK(condition)
Definition logging.h:103
#define TRACE_FLOW_STEP(category, name, id)
#define TRACE_EVENT0_WITH_FLOW_IDS(category_group, name, flow_id_count, flow_ids)