Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | Static Public Member Functions | List of all members
impeller::android::Choreographer Class Reference

This class describes access to the choreographer instance for the current thread. Choreographers are only available on API levels above 24. On levels below 24, an invalid choreographer will be returned. More...

#include <choreographer.h>

Public Types

using FrameClock = std::chrono::steady_clock
 
using FrameTimePoint = std::chrono::time_point< FrameClock >
 
using FrameCallback = std::function< void(FrameTimePoint)>
 

Public Member Functions

 ~Choreographer ()
 
 Choreographer (const Choreographer &)=delete
 
Choreographeroperator= (const Choreographer &)=delete
 
bool IsValid () const
 
bool PostFrameCallback (FrameCallback callback) const
 Posts a frame callback. The time that the frame is being rendered will be available in the callback as an argument. Multiple frame callbacks within the same frame interval will receive the same argument. More...
 

Static Public Member Functions

static bool IsAvailableOnPlatform ()
 
static ChoreographerGetInstance ()
 Create or get the thread local instance of a choreographer. A message loop will be setup on the calling thread if none exists. More...
 

Detailed Description

This class describes access to the choreographer instance for the current thread. Choreographers are only available on API levels above 24. On levels below 24, an invalid choreographer will be returned.

Since choreographer need an event loop on the current thread, one will be setup if it doesn't already exist.

Definition at line 24 of file choreographer.h.

Member Typedef Documentation

◆ FrameCallback

Definition at line 60 of file choreographer.h.

◆ FrameClock

using impeller::android::Choreographer::FrameClock = std::chrono::steady_clock

A monotonic system clock.

Definition at line 54 of file choreographer.h.

◆ FrameTimePoint

A timepoint on a monotonic system clock.

Definition at line 59 of file choreographer.h.

Constructor & Destructor Documentation

◆ ~Choreographer()

impeller::android::Choreographer::~Choreographer ( )
default

◆ Choreographer()

impeller::android::Choreographer::Choreographer ( const Choreographer )
delete

Member Function Documentation

◆ GetInstance()

Choreographer & impeller::android::Choreographer::GetInstance ( )
static

Create or get the thread local instance of a choreographer. A message loop will be setup on the calling thread if none exists.

Warning
Choreographers are only available on API levels 24 and above. Below this level, this will return an invalid instance. Availability can also be checked via the IsAvailableOnPlatform call.
Returns
The thread local choreographer instance. If none can be setup, an invalid object reference will be returned. See IsValid.

Definition at line 11 of file choreographer.cc.

11 {
12 static thread_local Choreographer tChoreographer;
13 return tChoreographer;
14}
Choreographer(const Choreographer &)=delete

◆ IsAvailableOnPlatform()

bool impeller::android::Choreographer::IsAvailableOnPlatform ( )
static

Definition at line 78 of file choreographer.cc.

78 {
79 return GetProcTable().AChoreographer_getInstance &&
80 (GetProcTable().AChoreographer_postFrameCallback64 ||
81 GetProcTable().AChoreographer_postFrameCallback);
82}
const ProcTable & GetProcTable()
Definition: proc_table.cc:12

◆ IsValid()

bool impeller::android::Choreographer::IsValid ( ) const

Definition at line 29 of file choreographer.cc.

29 {
30 return !!instance_;
31}

◆ operator=()

Choreographer & impeller::android::Choreographer::operator= ( const Choreographer )
delete

◆ PostFrameCallback()

bool impeller::android::Choreographer::PostFrameCallback ( FrameCallback  callback) const

Posts a frame callback. The time that the frame is being rendered will be available in the callback as an argument. Multiple frame callbacks within the same frame interval will receive the same argument.

Parameters
[in]callbackThe callback
Returns
true if the frame callback could be posted. This may return false if choreographers are not available on the platform. See IsAvailableOnPlatform.

Definition at line 38 of file choreographer.cc.

38 {
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);
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);
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}
SI F table(const skcms_Curve *curve, F v)
std::function< void(FrameTimePoint)> FrameCallback
Definition: choreographer.h:60
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_UNREACHABLE()
Definition: logging.h:109
static Choreographer::FrameTimePoint ClockMonotonicNanosToFrameTimePoint(int64_t p_nanos)
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

The documentation for this class was generated from the following files: