| Flutter Impeller |

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
Choreographer & | operator= (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 Choreographer & | GetInstance ()
| 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

using impeller::android::Choreographer::FrameCallback = std::function<void(FrameTimePoint)>

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

using impeller::android::Choreographer::FrameTimePoint = std::chrono::time_point<FrameClock>

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 }
impeller::android::Choreographer::Choreographer
Choreographer(const Choreographer &)=delete

Referenced by impeller::android::testing::TEST().

## ◆ 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 }
impeller::android::GetProcTable
const ProcTable & GetProcTable()
Definition: proc_table.cc:12

References impeller::android::GetProcTable().

Referenced by impeller::android::testing::TEST().

## ◆ IsValid()

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

Definition at line 29 of file choreographer.cc.

29 {
30 return !!instance_;
31 }

Referenced by PostFrameCallback().

## ◆ 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] | callback | The 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 {
44 FrameCallback callback;
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.
74 FML_UNREACHABLE();
75 return false;
76 }
impeller::android::Choreographer::FrameCallback
std::function< void(FrameTimePoint)> FrameCallback
Definition: choreographer.h:60
impeller::android::Choreographer::IsValid
bool IsValid() const
Definition: choreographer.cc:29
impeller::android::ClockMonotonicNanosToFrameTimePoint
static Choreographer::FrameTimePoint ClockMonotonicNanosToFrameTimePoint(int64_t p_nanos)
Definition: choreographer.cc:33
data
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:64

References impeller::android::ClockMonotonicNanosToFrameTimePoint(), data, impeller::android::GetProcTable(), and IsValid().

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

- impeller/toolkit/android/choreographer.h
- impeller/toolkit/android/choreographer.cc