@@ -934,6 +934,31 @@ typedef struct {
934934 };
935935} FlutterEngineDartObject ;
936936
937+ /// This enum allows embedders to determine the type of the engine thread in the
938+ /// FlutterNativeThreadCallback. Based on the thread type, the embedder may be
939+ /// able to tweak the thread priorities for optimum performance.
940+ typedef enum {
941+ /// The Flutter Engine considers the thread on which the FlutterEngineRun call
942+ /// is made to be the platform thread. There is only one such thread per
943+ /// engine instance.
944+ kFlutterNativeThreadTypePlatform ,
945+ /// This is the thread the Flutter Engine uses to execute rendering commands
946+ /// based on the selected client rendering API. There is only one such thread
947+ /// per engine instance.
948+ kFlutterNativeThreadTypeRender ,
949+ /// This is a dedicated thread on which the root Dart isolate is serviced.
950+ /// There is only one such thread per engine instance.
951+ kFlutterNativeThreadTypeUI ,
952+ /// Multiple threads are used by the Flutter engine to perform long running
953+ /// background tasks.
954+ kFlutterNativeThreadTypeWorker ,
955+ } FlutterNativeThreadType ;
956+
957+ /// A callback made by the engine in response to
958+ /// `FlutterEnginePostCallbackOnAllNativeThreads` on all internal thread.
959+ typedef void (* FlutterNativeThreadCallback )(FlutterNativeThreadType type ,
960+ void * user_data );
961+
937962typedef struct {
938963 /// The size of this struct. Must be sizeof(FlutterProjectArgs).
939964 size_t struct_size ;
@@ -1667,6 +1692,45 @@ FLUTTER_EXPORT
16671692FlutterEngineResult FlutterEngineNotifyLowMemoryWarning (
16681693 FLUTTER_API_SYMBOL (FlutterEngine ) engine );
16691694
1695+ //------------------------------------------------------------------------------
1696+ /// @brief Schedule a callback to be run on all engine managed threads.
1697+ /// The engine will attempt to service this callback the next time
1698+ /// the message loop for each managed thread is idle. Since the
1699+ /// engine manages the entire lifecycle of multiple threads, there
1700+ /// is no opportunity for the embedders to finely tune the
1701+ /// priorities of threads directly, or, perform other thread
1702+ /// specific configuration (for example, setting thread names for
1703+ /// tracing). This callback gives embedders a chance to affect such
1704+ /// tuning.
1705+ ///
1706+ /// @attention This call is expensive and must be made as few times as
1707+ /// possible. The callback must also return immediately as not doing
1708+ /// so may risk performance issues (especially for callbacks of type
1709+ /// kFlutterNativeThreadTypeUI and kFlutterNativeThreadTypeRender).
1710+ ///
1711+ /// @attention Some callbacks (especially the ones of type
1712+ /// kFlutterNativeThreadTypeWorker) may be called after the
1713+ /// FlutterEngine instance has shut down. Embedders must be careful
1714+ /// in handling the lifecycle of objects associated with the user
1715+ /// data baton.
1716+ ///
1717+ /// @attention In case there are multiple running Flutter engine instances,
1718+ /// their workers are shared.
1719+ ///
1720+ /// @param[in] engine A running engine instance.
1721+ /// @param[in] callback The callback that will get called multiple times on
1722+ /// each engine managed thread.
1723+ /// @param[in] user_data A baton passed by the engine to the callback. This
1724+ /// baton is not interpreted by the engine in any way.
1725+ ///
1726+ /// @return Returns if the callback was successfully posted to all threads.
1727+ ///
1728+ FLUTTER_EXPORT
1729+ FlutterEngineResult FlutterEnginePostCallbackOnAllNativeThreads (
1730+ FLUTTER_API_SYMBOL (FlutterEngine ) engine ,
1731+ FlutterNativeThreadCallback callback ,
1732+ void * user_data );
1733+
16701734#if defined(__cplusplus )
16711735 } // extern "C"
16721736#endif
0 commit comments