| Flutter Impeller |

choreographer.h
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 #ifndef FLUTTER_IMPELLER_TOOLKIT_ANDROID_CHOREOGRAPHER_H_
6 #define FLUTTER_IMPELLER_TOOLKIT_ANDROID_CHOREOGRAPHER_H_
7
8 #include "impeller/toolkit/android/proc_table.h"
9
10 #include <chrono>
11 #include <memory>
12
13 namespace impeller::android {
14
15 //------------------------------------------------------------------------------
16 /// @brief This class describes access to the choreographer instance for
17 /// the current thread. Choreographers are only available on API
18 /// levels above 24. On levels below 24, an invalid choreographer
19 /// will be returned.
20 ///
21 /// Since choreographer need an event loop on the current thread,
22 /// one will be setup if it doesn't already exist.
23 ///
24 class Choreographer {
25 public:
26 static bool IsAvailableOnPlatform();
27
28 //----------------------------------------------------------------------------
29 /// @brief Create or get the thread local instance of a choreographer. A
30 /// message loop will be setup on the calling thread if none
31 /// exists.
32 ///
33 /// @warning Choreographers are only available on API levels 24 and above.
34 /// Below this level, this will return an invalid instance.
35 /// Availability can also be checked via the
36 /// `IsAvailableOnPlatform` call.
37 ///
38 /// @return The thread local choreographer instance. If none can be setup,
39 /// an invalid object reference will be returned. See `IsValid`.
40 ///
41 static Choreographer& GetInstance();
42
43 ~Choreographer();
44
45 Choreographer(const Choreographer&) = delete;
46
47 Choreographer& operator=(const Choreographer&) = delete;
48
49 bool IsValid() const;
50
51 //----------------------------------------------------------------------------
52 /// A monotonic system clock.
53 ///
54 using FrameClock = std::chrono::steady_clock;
55
56 //----------------------------------------------------------------------------
57 /// A timepoint on a monotonic system clock.
58 ///
59 using FrameTimePoint = std::chrono::time_point<FrameClock>;
60 using FrameCallback = std::function<void(FrameTimePoint)>;
61
62 //----------------------------------------------------------------------------
63 /// @brief Posts a frame callback. The time that the frame is being
64 /// rendered will be available in the callback as an argument.
65 /// Multiple frame callbacks within the same frame interval will
66 /// receive the same argument.
67 ///
68 /// @param[in] callback The callback
69 ///
70 /// @return `true` if the frame callback could be posted. This may return
71 /// `false` if choreographers are not available on the platform.
72 /// See `IsAvailableOnPlatform`.
73 ///
74 bool PostFrameCallback(FrameCallback callback) const;
75
76 private:
77 AChoreographer* instance_ = nullptr;
78
79 explicit Choreographer();
80 };
81
82 } // namespace impeller::android
83
84 #endif // FLUTTER_IMPELLER_TOOLKIT_ANDROID_CHOREOGRAPHER_H_
proc_table.h
impeller::android::Choreographer
This class describes access to the choreographer instance for the current thread. Choreographers are ...
Definition: choreographer.h:24
impeller::android::Choreographer::FrameTimePoint
std::chrono::time_point< FrameClock > FrameTimePoint
Definition: choreographer.h:59
impeller::android::Choreographer::FrameCallback
std::function< void(FrameTimePoint)> FrameCallback
Definition: choreographer.h:60
impeller::android::Choreographer::PostFrameCallback
bool PostFrameCallback(FrameCallback callback) const
Posts a frame callback. The time that the frame is being rendered will be available in the callback a...
Definition: choreographer.cc:38
impeller::android::Choreographer::FrameClock
std::chrono::steady_clock FrameClock
Definition: choreographer.h:54
impeller::android::Choreographer::Choreographer
Choreographer(const Choreographer &)=delete
impeller::android::Choreographer::IsAvailableOnPlatform
static bool IsAvailableOnPlatform()
Definition: choreographer.cc:78
impeller::android::Choreographer::operator=
Choreographer & operator=(const Choreographer &)=delete
impeller::android::Choreographer::~Choreographer
~Choreographer()
impeller::android::Choreographer::IsValid
bool IsValid() const
Definition: choreographer.cc:29
impeller::android::Choreographer::GetInstance
static Choreographer & GetInstance()
Create or get the thread local instance of a choreographer. A message loop will be setup on the calli...
Definition: choreographer.cc:11
impeller::android
Definition: ahb_texture_source_vk_unittests.cc:16