Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
choreographer.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/impeller/toolkit/android/choreographer.h"
6
7#include "flutter/fml/message_loop.h"
8
10
12 static thread_local Choreographer tChoreographer;
13 return tChoreographer;
14}
15
16Choreographer::Choreographer() {
17 if (!IsAvailableOnPlatform()) {
18 return;
19 }
20
21 // We need a message loop on the current thread for the choreographer to
22 // schedule callbacks for us on.
24 instance_ = GetProcTable().AChoreographer_getInstance();
25}
26
28
30 return !!instance_;
31}
32
34 int64_t p_nanos) {
35 return Choreographer::FrameTimePoint{std::chrono::nanoseconds(p_nanos)};
36}
37
39 if (!callback || !IsValid()) {
40 return false;
41 }
42
43 struct InFlightData {
45 };
46
47 auto data = std::make_unique<InFlightData>();
48 data->callback = std::move(callback);
49
50 const auto& table = GetProcTable();
51 if (table.AChoreographer_postFrameCallback64) {
52 table.AChoreographer_postFrameCallback64(
53 const_cast<AChoreographer*>(instance_),
54 [](int64_t nanos, void* p_data) {
55 auto data = reinterpret_cast<InFlightData*>(p_data);
56 data->callback(ClockMonotonicNanosToFrameTimePoint(nanos));
57 delete data;
58 },
59 data.release());
60 return true;
61 } else if (table.AChoreographer_postFrameCallback) {
62 table.AChoreographer_postFrameCallback(
63 const_cast<AChoreographer*>(instance_),
64 [](long /*NOLINT*/ nanos, void* p_data) {
65 auto data = reinterpret_cast<InFlightData*>(p_data);
66 data->callback(ClockMonotonicNanosToFrameTimePoint(nanos));
67 delete data;
68 },
69 data.release());
70 return true;
71 }
72
73 // The validity check should have tripped by now.
75 return false;
76}
77
79 return GetProcTable().AChoreographer_getInstance &&
80 (GetProcTable().AChoreographer_postFrameCallback64 ||
81 GetProcTable().AChoreographer_postFrameCallback);
82}
83
84} // namespace impeller::android
SI F table(const skcms_Curve *curve, F v)
static void EnsureInitializedForCurrentThread()
This class describes access to the choreographer instance for the current thread. Choreographers are ...
std::chrono::time_point< FrameClock > FrameTimePoint
std::function< void(FrameTimePoint)> FrameCallback
bool PostFrameCallback(FrameCallback callback) const
Posts a frame callback. The time that the frame is being rendered will be available in the callback a...
static Choreographer & GetInstance()
Create or get the thread local instance of a choreographer. A message loop will be setup on the calli...
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_UNREACHABLE()
Definition logging.h:109
const ProcTable & GetProcTable()
Definition proc_table.cc:12
static Choreographer::FrameTimePoint ClockMonotonicNanosToFrameTimePoint(int64_t p_nanos)