embedder.h 86.9 KB
Newer Older
M
Michael Goderbauer 已提交
1
// Copyright 2013 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8 9 10 11
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_EMBEDDER_H_
#define FLUTTER_EMBEDDER_H_

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
// This file defines an Application Binary Interface (ABI), which requires more
// stability than regular code to remain functional for exchanging messages
// between different versions of the embedding and the engine, to allow for both
// forward and backward compatibility.
//
// Specifically,
// - The order, type, and size of the struct members below must remain the same,
//   and members should not be removed.
// - New structures that are part of the ABI must be defined with "size_t
//   struct_size;" as their first member, which should be initialized using
//   "sizeof(Type)".
// - Enum values must not change or be removed.
// - Enum members without explicit values must not be reordered.
// - Function signatures (names, argument counts, argument order, and argument
//   type) cannot change.
// - The core behavior of existing functions cannot change.
//
// These changes are allowed:
// - Adding new struct members at the end of a structure.
// - Adding new enum members with a new value.
// - Renaming a struct member as long as its type, size, and intent remain the
//   same.
// - Renaming an enum member as long as its value and intent remains the same.
//
// It is expected that struct members and implicitly-valued enums will not
// always be declared in an order that is optimal for the reader, since members
// will be added over time, and they can't be reordered.
//
// Existing functions should continue to appear from the caller's point of view
// to operate as they did when they were first introduced, so introduce a new
// function instead of modifying the core behavior of a function (and continue
// to support the existing function with the previous behavior).

45 46 47 48 49 50 51 52
#if defined(__cplusplus)
extern "C" {
#endif

#ifndef FLUTTER_EXPORT
#define FLUTTER_EXPORT
#endif  // FLUTTER_EXPORT

53 54 55 56 57 58 59 60 61 62
#ifdef FLUTTER_API_SYMBOL_PREFIX
#define FLUTTER_EMBEDDING_CONCAT(a, b) a##b
#define FLUTTER_EMBEDDING_ADD_PREFIX(symbol, prefix) \
  FLUTTER_EMBEDDING_CONCAT(prefix, symbol)
#define FLUTTER_API_SYMBOL(symbol) \
  FLUTTER_EMBEDDING_ADD_PREFIX(symbol, FLUTTER_API_SYMBOL_PREFIX)
#else
#define FLUTTER_API_SYMBOL(symbol) symbol
#endif

63 64 65 66 67 68
#define FLUTTER_ENGINE_VERSION 1

typedef enum {
  kSuccess = 0,
  kInvalidLibraryVersion,
  kInvalidArguments,
69
  kInternalInconsistency,
70
} FlutterEngineResult;
71 72 73

typedef enum {
  kOpenGL,
74
  kSoftware,
75 76
} FlutterRendererType;

77 78
/// Additional accessibility features that may be enabled by the platform.
/// Must match the `AccessibilityFeatures` enum in window.dart.
79
typedef enum {
80 81
  /// Indicate there is a running accessibility service which is changing the
  /// interaction model of the device.
82
  kFlutterAccessibilityFeatureAccessibleNavigation = 1 << 0,
83
  /// Indicate the platform is inverting the colors of the application.
84
  kFlutterAccessibilityFeatureInvertColors = 1 << 1,
85
  /// Request that animations be disabled or simplified.
86
  kFlutterAccessibilityFeatureDisableAnimations = 1 << 2,
87
  /// Request that text be rendered at a bold font weight.
88
  kFlutterAccessibilityFeatureBoldText = 1 << 3,
89
  /// Request that certain animations be simplified and parallax effects
90 91 92 93
  // removed.
  kFlutterAccessibilityFeatureReduceMotion = 1 << 4,
} FlutterAccessibilityFeature;

94 95 96
/// The set of possible actions that can be conveyed to a semantics node.
///
/// Must match the `SemanticsAction` enum in semantics.dart.
97
typedef enum {
98
  /// The equivalent of a user briefly tapping the screen with the finger
99
  /// without moving it.
100
  kFlutterSemanticsActionTap = 1 << 0,
101 102
  /// The equivalent of a user pressing and holding the screen with the finger
  /// for a few seconds without moving it.
103
  kFlutterSemanticsActionLongPress = 1 << 1,
104 105
  /// The equivalent of a user moving their finger across the screen from right
  /// to left.
106
  kFlutterSemanticsActionScrollLeft = 1 << 2,
107 108 109
  /// The equivalent of a user moving their finger across the screen from left
  /// to
  /// right.
110
  kFlutterSemanticsActionScrollRight = 1 << 3,
111 112
  /// The equivalent of a user moving their finger across the screen from bottom
  /// to top.
113
  kFlutterSemanticsActionScrollUp = 1 << 4,
114 115
  /// The equivalent of a user moving their finger across the screen from top to
  /// bottom.
116
  kFlutterSemanticsActionScrollDown = 1 << 5,
117
  /// Increase the value represented by the semantics node.
118
  kFlutterSemanticsActionIncrease = 1 << 6,
119
  /// Decrease the value represented by the semantics node.
120
  kFlutterSemanticsActionDecrease = 1 << 7,
121
  /// A request to fully show the semantics node on screen.
122
  kFlutterSemanticsActionShowOnScreen = 1 << 8,
123
  /// Move the cursor forward by one character.
124
  kFlutterSemanticsActionMoveCursorForwardByCharacter = 1 << 9,
125
  /// Move the cursor backward by one character.
126
  kFlutterSemanticsActionMoveCursorBackwardByCharacter = 1 << 10,
127
  /// Set the text selection to the given range.
128
  kFlutterSemanticsActionSetSelection = 1 << 11,
129
  /// Copy the current selection to the clipboard.
130
  kFlutterSemanticsActionCopy = 1 << 12,
131
  /// Cut the current selection and place it in the clipboard.
132
  kFlutterSemanticsActionCut = 1 << 13,
133
  /// Paste the current content of the clipboard.
134
  kFlutterSemanticsActionPaste = 1 << 14,
135
  /// Indicate that the node has gained accessibility focus.
136
  kFlutterSemanticsActionDidGainAccessibilityFocus = 1 << 15,
137
  /// Indicate that the node has lost accessibility focus.
138
  kFlutterSemanticsActionDidLoseAccessibilityFocus = 1 << 16,
139
  /// Indicate that the user has invoked a custom accessibility action.
140
  kFlutterSemanticsActionCustomAction = 1 << 17,
141
  /// A request that the node should be dismissed.
142
  kFlutterSemanticsActionDismiss = 1 << 18,
143
  /// Move the cursor forward by one word.
144
  kFlutterSemanticsActionMoveCursorForwardByWord = 1 << 19,
145
  /// Move the cursor backward by one word.
146
  kFlutterSemanticsActionMoveCursorBackwardByWord = 1 << 20,
147 148
} FlutterSemanticsAction;

149 150 151
/// The set of properties that may be associated with a semantics node.
///
/// Must match the `SemanticsFlag` enum in semantics.dart.
152
typedef enum {
153 154
  /// The semantics node has the quality of either being "checked" or
  /// "unchecked".
155
  kFlutterSemanticsFlagHasCheckedState = 1 << 0,
156
  /// Whether a semantics node is checked.
157
  kFlutterSemanticsFlagIsChecked = 1 << 1,
158
  /// Whether a semantics node is selected.
159
  kFlutterSemanticsFlagIsSelected = 1 << 2,
160
  /// Whether the semantic node represents a button.
161
  kFlutterSemanticsFlagIsButton = 1 << 3,
162
  /// Whether the semantic node represents a text field.
163
  kFlutterSemanticsFlagIsTextField = 1 << 4,
164
  /// Whether the semantic node currently holds the user's focus.
165
  kFlutterSemanticsFlagIsFocused = 1 << 5,
166 167
  /// The semantics node has the quality of either being "enabled" or
  /// "disabled".
168
  kFlutterSemanticsFlagHasEnabledState = 1 << 6,
169
  /// Whether a semantic node that hasEnabledState is currently enabled.
170
  kFlutterSemanticsFlagIsEnabled = 1 << 7,
171
  /// Whether a semantic node is in a mutually exclusive group.
172
  kFlutterSemanticsFlagIsInMutuallyExclusiveGroup = 1 << 8,
173
  /// Whether a semantic node is a header that divides content into sections.
174
  kFlutterSemanticsFlagIsHeader = 1 << 9,
175
  /// Whether the value of the semantics node is obscured.
176
  kFlutterSemanticsFlagIsObscured = 1 << 10,
177 178
  /// Whether the semantics node is the root of a subtree for which a route name
  /// should be announced.
179
  kFlutterSemanticsFlagScopesRoute = 1 << 11,
180
  /// Whether the semantics node label is the name of a visually distinct route.
181
  kFlutterSemanticsFlagNamesRoute = 1 << 12,
182
  /// Whether the semantics node is considered hidden.
183
  kFlutterSemanticsFlagIsHidden = 1 << 13,
184
  /// Whether the semantics node represents an image.
185
  kFlutterSemanticsFlagIsImage = 1 << 14,
186
  /// Whether the semantics node is a live region.
187
  kFlutterSemanticsFlagIsLiveRegion = 1 << 15,
188
  /// The semantics node has the quality of either being "on" or "off".
189
  kFlutterSemanticsFlagHasToggledState = 1 << 16,
190 191
  /// If true, the semantics node is "on". If false, the semantics node is
  /// "off".
192
  kFlutterSemanticsFlagIsToggled = 1 << 17,
193 194 195 196 197 198 199
  /// Whether the platform can scroll the semantics node when the user attempts
  /// to move the accessibility focus to an offscreen child.
  ///
  /// For example, a `ListView` widget has implicit scrolling so that users can
  /// easily move the accessibility focus to the next set of children. A
  /// `PageView` widget does not have implicit scrolling, so that users don't
  /// navigate to the next page when reaching the end of the current one.
200
  kFlutterSemanticsFlagHasImplicitScrolling = 1 << 18,
201 202 203
  /// Whether the semantic node is read only.
  ///
  /// Only applicable when kFlutterSemanticsFlagIsTextField flag is on.
204
  kFlutterSemanticsFlagIsReadOnly = 1 << 20,
205 206
  /// Whether the semantic node can hold the user's focus.
  kFlutterSemanticsFlagIsFocusable = 1 << 21,
207 208
  /// Whether the semantics node represents a link.
  kFlutterSemanticsFlagIsLink = 1 << 22,
209 210 211
} FlutterSemanticsFlag;

typedef enum {
212
  /// Text has unknown text direction.
213
  kFlutterTextDirectionUnknown = 0,
214
  /// Text is read from right to left.
215
  kFlutterTextDirectionRTL = 1,
216
  /// Text is read from left to right.
217 218 219
  kFlutterTextDirectionLTR = 2,
} FlutterTextDirection;

220
typedef struct _FlutterEngine* FLUTTER_API_SYMBOL(FlutterEngine);
221

222
typedef struct {
223
  /// horizontal scale factor
224
  double scaleX;
225
  /// horizontal skew factor
226
  double skewX;
227
  /// horizontal translation
228
  double transX;
229
  /// vertical skew factor
230
  double skewY;
231
  /// vertical scale factor
232
  double scaleY;
233
  /// vertical translation
234
  double transY;
235
  /// input x-axis perspective factor
236
  double pers0;
237
  /// input y-axis perspective factor
238
  double pers1;
239
  /// perspective scale factor
240 241 242
  double pers2;
} FlutterTransformation;

243 244
typedef void (*VoidCallback)(void* /* user data */);

245
typedef enum {
246 247
  /// Specifies an OpenGL texture target type. Textures are specified using
  /// the FlutterOpenGLTexture struct.
248
  kFlutterOpenGLTargetTypeTexture,
249 250
  /// Specifies an OpenGL frame-buffer target type. Framebuffers are specified
  /// using the FlutterOpenGLFramebuffer struct.
251 252 253
  kFlutterOpenGLTargetTypeFramebuffer,
} FlutterOpenGLTargetType;

254
typedef struct {
255 256
  /// Target texture of the active texture unit (example GL_TEXTURE_2D or
  /// GL_TEXTURE_RECTANGLE).
257
  uint32_t target;
258
  /// The name of the texture.
259
  uint32_t name;
260
  /// The texture format (example GL_RGBA8).
261
  uint32_t format;
262
  /// User data to be returned on the invocation of the destruction callback.
263
  void* user_data;
264 265
  /// Callback invoked (on an engine managed thread) that asks the embedder to
  /// collect the texture.
266
  VoidCallback destruction_callback;
267 268 269 270 271 272 273 274
  /// Optional parameters for texture height/width, default is 0, non-zero means
  /// the texture has the specified width/height. Usually, when the texture type
  /// is GL_TEXTURE_RECTANGLE, we need to specify the texture width/height to
  /// tell the embedder to scale when rendering.
  /// Width of the texture.
  size_t width;
  /// Height of the texture.
  size_t height;
275 276
} FlutterOpenGLTexture;

277
typedef struct {
278 279 280
  /// The target of the color attachment of the frame-buffer. For example,
  /// GL_TEXTURE_2D or GL_RENDERBUFFER. In case of ambiguity when dealing with
  /// Window bound frame-buffers, 0 may be used.
281 282
  uint32_t target;

283
  /// The name of the framebuffer.
284 285
  uint32_t name;

286
  /// User data to be returned on the invocation of the destruction callback.
287 288
  void* user_data;

289 290
  /// Callback invoked (on an engine managed thread) that asks the embedder to
  /// collect the framebuffer.
291 292 293
  VoidCallback destruction_callback;
} FlutterOpenGLFramebuffer;

294
typedef bool (*BoolCallback)(void* /* user data */);
295
typedef FlutterTransformation (*TransformationCallback)(void* /* user data */);
296
typedef uint32_t (*UIntCallback)(void* /* user data */);
297 298 299 300
typedef bool (*SoftwareSurfacePresentCallback)(void* /* user data */,
                                               const void* /* allocation */,
                                               size_t /* row bytes */,
                                               size_t /* height */);
301
typedef void* (*ProcResolver)(void* /* user data */, const char* /* name */);
302 303 304 305 306
typedef bool (*TextureFrameCallback)(void* /* user data */,
                                     int64_t /* texture identifier */,
                                     size_t /* width */,
                                     size_t /* height */,
                                     FlutterOpenGLTexture* /* texture out */);
307
typedef void (*VsyncCallback)(void* /* user data */, intptr_t /* baton */);
308

309 310 311 312 313 314 315 316 317 318 319 320 321 322
/// A structure to represent the width and height.
typedef struct {
  double width;
  double height;
} FlutterSize;

/// A structure to represent the width and height.
///
/// See: \ref FlutterSize when the value are not integers.
typedef struct {
  uint32_t width;
  uint32_t height;
} FlutterUIntSize;

323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
/// A structure to represent a rectangle.
typedef struct {
  double left;
  double top;
  double right;
  double bottom;
} FlutterRect;

/// A structure to represent a 2D point.
typedef struct {
  double x;
  double y;
} FlutterPoint;

/// A structure to represent a rounded rectangle.
typedef struct {
  FlutterRect rect;
  FlutterSize upper_left_corner_radius;
  FlutterSize upper_right_corner_radius;
  FlutterSize lower_right_corner_radius;
  FlutterSize lower_left_corner_radius;
} FlutterRoundedRect;

346 347 348
/// This information is passed to the embedder when requesting a frame buffer
/// object.
///
349
/// See: \ref FlutterOpenGLRendererConfig.fbo_with_frame_info_callback.
350 351 352 353 354 355 356
typedef struct {
  /// The size of this struct. Must be sizeof(FlutterFrameInfo).
  size_t struct_size;
  /// The size of the surface that will be backed by the fbo.
  FlutterUIntSize size;
} FlutterFrameInfo;

357
/// Callback for when a frame buffer object is requested.
358 359 360 361
typedef uint32_t (*UIntFrameInfoCallback)(
    void* /* user data */,
    const FlutterFrameInfo* /* frame info */);

362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
/// This information is passed to the embedder when a surface is presented.
///
/// See: \ref FlutterOpenGLRendererConfig.present_with_info.
typedef struct {
  /// The size of this struct. Must be sizeof(FlutterFrameInfo).
  size_t struct_size;
  /// Id of the fbo backing the surface that was presented.
  uint32_t fbo_id;
} FlutterPresentInfo;

/// Callback for when a surface is presented.
typedef bool (*BoolPresentInfoCallback)(
    void* /* user data */,
    const FlutterPresentInfo* /* present info */);

377
typedef struct {
378
  /// The size of this struct. Must be sizeof(FlutterOpenGLRendererConfig).
379 380 381
  size_t struct_size;
  BoolCallback make_current;
  BoolCallback clear_current;
382 383 384
  /// Specifying one (and only one) of `present` or `present_with_info` is
  /// required. Specifying both is an error and engine initialization will be
  /// terminated. The return value indicates success of the present call.
385
  BoolCallback present;
386 387 388 389 390
  /// Specifying one (and only one) of the `fbo_callback` or
  /// `fbo_with_frame_info_callback` is required. Specifying both is an error
  /// and engine intialization will be terminated. The return value indicates
  /// the id of the frame buffer object that flutter will obtain the gl surface
  /// from.
391
  UIntCallback fbo_callback;
392 393 394 395 396 397
  /// This is an optional callback. Flutter will ask the emebdder to create a GL
  /// context current on a background thread. If the embedder is able to do so,
  /// Flutter will assume that this context is in the same sharegroup as the
  /// main rendering context and use this context for asynchronous texture
  /// uploads. Though optional, it is recommended that all embedders set this
  /// callback as it will lead to better performance in texture handling.
398
  BoolCallback make_resource_current;
399 400 401 402
  /// By default, the renderer config assumes that the FBO does not change for
  /// the duration of the engine run. If this argument is true, the
  /// engine will ask the embedder for an updated FBO target (via an
  /// fbo_callback invocation) after a present call.
403
  bool fbo_reset_after_present;
404 405
  /// The transformation to apply to the render target before any rendering
  /// operations. This callback is optional.
406 407 408 409 410 411 412 413
  /// @attention      When using a custom compositor, the layer offset and sizes
  ///                 will be affected by this transformation. It will be
  ///                 embedder responsibility to render contents at the
  ///                 transformed offset and size. This is useful for embedders
  ///                 that want to render transformed contents directly into
  ///                 hardware overlay planes without having to apply extra
  ///                 transformations to layer contents (which may necessitate
  ///                 an expensive off-screen render pass).
414
  TransformationCallback surface_transformation;
415
  ProcResolver gl_proc_resolver;
416 417 418 419
  /// When the embedder specifies that a texture has a frame available, the
  /// engine will call this method (on an internal engine managed thread) so
  /// that external texture details can be supplied to the engine for subsequent
  /// composition.
420
  TextureFrameCallback gl_external_texture_frame_callback;
421 422 423 424 425 426 427 428
  /// Specifying one (and only one) of the `fbo_callback` or
  /// `fbo_with_frame_info_callback` is required. Specifying both is an error
  /// and engine intialization will be terminated. The return value indicates
  /// the id of the frame buffer object (fbo) that flutter will obtain the gl
  /// surface from. When using this variant, the embedder is passed a
  /// `FlutterFrameInfo` struct that indicates the properties of the surface
  /// that flutter will acquire from the returned fbo.
  UIntFrameInfoCallback fbo_with_frame_info_callback;
429 430 431 432 433 434
  /// Specifying one (and only one) of `present` or `present_with_info` is
  /// required. Specifying both is an error and engine initialization will be
  /// terminated. When using this variant, the embedder is passed a
  /// `FlutterPresentInfo` struct that the embedder can use to release any
  /// resources. The return value indicates success of the present call.
  BoolPresentInfoCallback present_with_info;
435 436
} FlutterOpenGLRendererConfig;

437
typedef struct {
438
  /// The size of this struct. Must be sizeof(FlutterSoftwareRendererConfig).
439
  size_t struct_size;
440 441 442 443
  /// The callback presented to the embedder to present a fully populated buffer
  /// to the user. The pixel format of the buffer is the native 32-bit RGBA
  /// format. The buffer is owned by the Flutter engine and must be copied in
  /// this callback if needed.
444 445 446
  SoftwareSurfacePresentCallback surface_present_callback;
} FlutterSoftwareRendererConfig;

447 448 449 450
typedef struct {
  FlutterRendererType type;
  union {
    FlutterOpenGLRendererConfig open_gl;
451
    FlutterSoftwareRendererConfig software;
452 453 454 455
  };
} FlutterRendererConfig;

typedef struct {
456
  /// The size of this struct. Must be sizeof(FlutterWindowMetricsEvent).
457
  size_t struct_size;
458
  /// Physical width of the window.
459
  size_t width;
460
  /// Physical height of the window.
461
  size_t height;
462
  /// Scale factor for the physical screen.
463 464 465
  double pixel_ratio;
} FlutterWindowMetricsEvent;

466
/// The phase of the pointer event.
467 468
typedef enum {
  kCancel,
469 470 471 472 473 474
  /// The pointer, which must have been down (see kDown), is now up.
  ///
  /// For touch, this means that the pointer is no longer in contact with the
  /// screen. For a mouse, it means the last button was released. Note that if
  /// any other buttons are still pressed when one button is released, that
  /// should be sent as a kMove rather than a kUp.
475
  kUp,
476 477 478 479 480 481
  /// The pointer, which must have been been up, is now down.
  ///
  /// For touch, this means that the pointer has come into contact with the
  /// screen. For a mouse, it means a button is now pressed. Note that if any
  /// other buttons are already pressed when a new button is pressed, that
  /// should be sent as a kMove rather than a kDown.
482
  kDown,
483 484 485 486
  /// The pointer moved while down.
  ///
  /// This is also used for changes in button state that don't cause a kDown or
  /// kUp, such as releasing one of two pressed buttons.
487
  kMove,
488 489 490 491
  /// The pointer is now sending input to Flutter. For instance, a mouse has
  /// entered the area where the Flutter content is displayed.
  ///
  /// A pointer should always be added before sending any other events.
492
  kAdd,
493 494 495 496
  /// The pointer is no longer sending input to Flutter. For instance, a mouse
  /// has left the area where the Flutter content is displayed.
  ///
  /// A removed pointer should no longer send events until sending a new kAdd.
497
  kRemove,
498
  /// The pointer moved while up.
499
  kHover,
500 501
} FlutterPointerPhase;

502
/// The device type that created a pointer event.
503 504 505 506 507
typedef enum {
  kFlutterPointerDeviceKindMouse = 1,
  kFlutterPointerDeviceKindTouch,
} FlutterPointerDeviceKind;

508 509
/// Flags for the `buttons` field of `FlutterPointerEvent` when `device_kind`
/// is `kFlutterPointerDeviceKindMouse`.
510 511 512 513 514 515
typedef enum {
  kFlutterPointerButtonMousePrimary = 1 << 0,
  kFlutterPointerButtonMouseSecondary = 1 << 1,
  kFlutterPointerButtonMouseMiddle = 1 << 2,
  kFlutterPointerButtonMouseBack = 1 << 3,
  kFlutterPointerButtonMouseForward = 1 << 4,
516 517
  /// If a mouse has more than five buttons, send higher bit shifted values
  /// corresponding to the button number: 1 << 5 for the 6th, etc.
518 519
} FlutterPointerMouseButtons;

520
/// The type of a pointer signal.
521 522 523 524 525
typedef enum {
  kFlutterPointerSignalKindNone,
  kFlutterPointerSignalKindScroll,
} FlutterPointerSignalKind;

526
typedef struct {
527
  /// The size of this struct. Must be sizeof(FlutterPointerEvent).
528 529
  size_t struct_size;
  FlutterPointerPhase phase;
530 531 532
  /// The timestamp at which the pointer event was generated. The timestamp
  /// should be specified in microseconds and the clock should be the same as
  /// that used by `FlutterEngineGetCurrentTime`.
533
  size_t timestamp;
534
  /// The x coordinate of the pointer event in physical pixels.
535
  double x;
536
  /// The y coordinate of the pointer event in physical pixels.
537
  double y;
538 539
  /// An optional device identifier. If this is not specified, it is assumed
  /// that the embedder has no multi-touch capability.
540
  int32_t device;
541
  FlutterPointerSignalKind signal_kind;
542
  /// The x offset of the scroll in physical pixels.
543
  double scroll_delta_x;
544
  /// The y offset of the scroll in physical pixels.
545
  double scroll_delta_y;
546 547 548 549 550
  /// The type of the device generating this event.
  /// Backwards compatibility note: If this is not set, the device will be
  /// treated as a mouse, with the primary button set for `kDown` and `kMove`.
  /// If set explicitly to `kFlutterPointerDeviceKindMouse`, you must set the
  /// correct buttons.
551
  FlutterPointerDeviceKind device_kind;
552
  /// The buttons currently pressed, if any.
553
  int64_t buttons;
554 555
} FlutterPointerEvent;

556 557 558 559
struct _FlutterPlatformMessageResponseHandle;
typedef struct _FlutterPlatformMessageResponseHandle
    FlutterPlatformMessageResponseHandle;

560
typedef struct {
561
  /// The size of this struct. Must be sizeof(FlutterPlatformMessage).
562 563 564
  size_t struct_size;
  const char* channel;
  const uint8_t* message;
565
  size_t message_size;
566 567 568 569 570 571
  /// The response handle on which to invoke
  /// `FlutterEngineSendPlatformMessageResponse` when the response is ready.
  /// `FlutterEngineSendPlatformMessageResponse` must be called for all messages
  /// received by the embedder. Failure to call
  /// `FlutterEngineSendPlatformMessageResponse` will cause a memory leak. It is
  /// not safe to send multiple responses on a single response object.
572
  const FlutterPlatformMessageResponseHandle* response_handle;
573 574
} FlutterPlatformMessage;

575 576 577 578
typedef void (*FlutterPlatformMessageCallback)(
    const FlutterPlatformMessage* /* message*/,
    void* /* user data */);

579 580 581 582
typedef void (*FlutterDataCallback)(const uint8_t* /* data */,
                                    size_t /* size */,
                                    void* /* user data */);

583 584 585 586 587
/// The identifier of the platform view. This identifier is specified by the
/// application when a platform view is added to the scene via the
/// `SceneBuilder.addPlatformView` call.
typedef int64_t FlutterPlatformViewIdentifier;

588 589
/// `FlutterSemanticsNode` ID used as a sentinel to signal the end of a batch of
/// semantics node updates.
590
FLUTTER_EXPORT
591
extern const int32_t kFlutterSemanticsNodeIdBatchEnd;
592

593 594 595 596 597 598
/// A node that represents some semantic data.
///
/// The semantics tree is maintained during the semantics phase of the pipeline
/// (i.e., during PipelineOwner.flushSemantics), which happens after
/// compositing. Updates are then pushed to embedders via the registered
/// `FlutterUpdateSemanticsNodeCallback`.
599
typedef struct {
600
  /// The size of this struct. Must be sizeof(FlutterSemanticsNode).
601
  size_t struct_size;
602
  /// The unique identifier for this node.
603
  int32_t id;
604
  /// The set of semantics flags associated with this node.
605
  FlutterSemanticsFlag flags;
606
  /// The set of semantics actions applicable to this node.
607
  FlutterSemanticsAction actions;
608
  /// The position at which the text selection originates.
609
  int32_t text_selection_base;
610
  /// The position at which the text selection terminates.
611
  int32_t text_selection_extent;
612
  /// The total number of scrollable children that contribute to semantics.
613
  int32_t scroll_child_count;
614
  /// The index of the first visible semantic child of a scroll node.
615
  int32_t scroll_index;
616 617
  /// The current scrolling position in logical pixels if the node is
  /// scrollable.
618
  double scroll_position;
619
  /// The maximum in-range value for `scrollPosition` if the node is scrollable.
620
  double scroll_extent_max;
621
  /// The minimum in-range value for `scrollPosition` if the node is scrollable.
622
  double scroll_extent_min;
623 624
  /// The elevation along the z-axis at which the rect of this semantics node is
  /// located above its parent.
625
  double elevation;
626
  /// Describes how much space the semantics node takes up along the z-axis.
627
  double thickness;
628
  /// A textual description of the node.
629
  const char* label;
630
  /// A brief description of the result of performing an action on the node.
631
  const char* hint;
632
  /// A textual description of the current value of the node.
633
  const char* value;
634 635
  /// A value that `value` will have after a kFlutterSemanticsActionIncrease`
  /// action has been performed.
636
  const char* increased_value;
637 638
  /// A value that `value` will have after a kFlutterSemanticsActionDecrease`
  /// action has been performed.
639
  const char* decreased_value;
640 641
  /// The reading direction for `label`, `value`, `hint`, `increasedValue`, and
  /// `decreasedValue`.
642
  FlutterTextDirection text_direction;
643
  /// The bounding box for this node in its coordinate system.
644
  FlutterRect rect;
645 646
  /// The transform from this node's coordinate system to its parent's
  /// coordinate system.
647
  FlutterTransformation transform;
648
  /// The number of children this node has.
649
  size_t child_count;
650
  /// Array of child node IDs in traversal order. Has length `child_count`.
651
  const int32_t* children_in_traversal_order;
652
  /// Array of child node IDs in hit test order. Has length `child_count`.
653
  const int32_t* children_in_hit_test_order;
654
  /// The number of custom accessibility action associated with this node.
655
  size_t custom_accessibility_actions_count;
656 657
  /// Array of `FlutterSemanticsCustomAction` IDs associated with this node.
  /// Has length `custom_accessibility_actions_count`.
658
  const int32_t* custom_accessibility_actions;
659
  /// Identifier of the platform view associated with this semantics node, or
660
  /// -1 if none.
661
  FlutterPlatformViewIdentifier platform_view_id;
662 663
} FlutterSemanticsNode;

664 665
/// `FlutterSemanticsCustomAction` ID used as a sentinel to signal the end of a
/// batch of semantics custom action updates.
666
FLUTTER_EXPORT
667
extern const int32_t kFlutterSemanticsCustomActionIdBatchEnd;
668

669 670 671 672 673 674 675 676 677
/// A custom semantics action, or action override.
///
/// Custom actions can be registered by applications in order to provide
/// semantic actions other than the standard actions available through the
/// `FlutterSemanticsAction` enum.
///
/// Action overrides are custom actions that the application developer requests
/// to be used in place of the standard actions in the `FlutterSemanticsAction`
/// enum.
678
typedef struct {
679
  /// The size of the struct. Must be sizeof(FlutterSemanticsCustomAction).
680
  size_t struct_size;
681
  /// The unique custom action or action override ID.
682
  int32_t id;
683 684
  /// For overridden standard actions, corresponds to the
  /// `FlutterSemanticsAction` to override.
685
  FlutterSemanticsAction override_action;
686
  /// The user-readable name of this custom semantics action.
687
  const char* label;
688
  /// The hint description of this custom semantics action.
689 690 691 692 693 694 695 696 697 698 699
  const char* hint;
} FlutterSemanticsCustomAction;

typedef void (*FlutterUpdateSemanticsNodeCallback)(
    const FlutterSemanticsNode* /* semantics node */,
    void* /* user data */);

typedef void (*FlutterUpdateSemanticsCustomActionCallback)(
    const FlutterSemanticsCustomAction* /* semantics custom action */,
    void* /* user data */);

700 701 702 703 704 705 706 707 708 709 710 711
typedef struct _FlutterTaskRunner* FlutterTaskRunner;

typedef struct {
  FlutterTaskRunner runner;
  uint64_t task;
} FlutterTask;

typedef void (*FlutterTaskRunnerPostTaskCallback)(
    FlutterTask /* task */,
    uint64_t /* target time nanos */,
    void* /* user data */);

712 713 714 715
/// An interface used by the Flutter engine to execute tasks at the target time
/// on a specified thread. There should be a 1-1 relationship between a thread
/// and a task runner. It is undefined behavior to run a task on a thread that
/// is not associated with its task runner.
716
typedef struct {
717
  /// The size of this struct. Must be sizeof(FlutterTaskRunnerDescription).
718 719
  size_t struct_size;
  void* user_data;
720 721 722 723
  /// May be called from any thread. Should return true if tasks posted on the
  /// calling thread will be run on that same thread.
  ///
  /// @attention     This field is required.
724
  BoolCallback runs_task_on_current_thread_callback;
725 726 727 728 729 730 731 732 733 734
  /// May be called from any thread. The given task should be executed by the
  /// embedder on the thread associated with that task runner by calling
  /// `FlutterEngineRunTask` at the given target time. The system monotonic
  /// clock should be used for the target time. The target time is the absolute
  /// time from epoch (NOT a delta) at which the task must be returned back to
  /// the engine on the correct thread. If the embedder needs to calculate a
  /// delta, `FlutterEngineGetCurrentTime` may be called and the difference used
  /// as the delta.
  ///
  /// @attention     This field is required.
735
  FlutterTaskRunnerPostTaskCallback post_task_callback;
736 737 738
  /// A unique identifier for the task runner. If multiple task runners service
  /// tasks on the same thread, their identifiers must match.
  size_t identifier;
739 740 741
} FlutterTaskRunnerDescription;

typedef struct {
742
  /// The size of this struct. Must be sizeof(FlutterCustomTaskRunners).
743
  size_t struct_size;
744
  /// Specify the task runner for the thread on which the `FlutterEngineRun`
745 746 747
  /// call is made. The same task runner description can be specified for both
  /// the render and platform task runners. This makes the Flutter engine use
  /// the same thread for both task runners.
748
  const FlutterTaskRunnerDescription* platform_task_runner;
749 750 751 752 753
  /// Specify the task runner for the thread on which the render tasks will be
  /// run. The same task runner description can be specified for both the render
  /// and platform task runners. This makes the Flutter engine use the same
  /// thread for both task runners.
  const FlutterTaskRunnerDescription* render_task_runner;
754 755
} FlutterCustomTaskRunners;

756
typedef struct {
757 758
  /// The type of the OpenGL backing store. Currently, it can either be a
  /// texture or a framebuffer.
759 760
  FlutterOpenGLTargetType type;
  union {
761
    /// A texture for Flutter to render into.
762
    FlutterOpenGLTexture texture;
763 764
    /// A framebuffer for Flutter to render into. The embedder must ensure that
    /// the framebuffer is complete.
765 766 767 768 769
    FlutterOpenGLFramebuffer framebuffer;
  };
} FlutterOpenGLBackingStore;

typedef struct {
770 771
  /// A pointer to the raw bytes of the allocation described by this software
  /// backing store.
772
  const void* allocation;
773
  /// The number of bytes in a single row of the allocation.
774
  size_t row_bytes;
775
  /// The number of rows in the allocation.
776
  size_t height;
777 778 779
  /// A baton that is not interpreted by the engine in any way. It will be given
  /// back to the embedder in the destruction callback below. Embedder resources
  /// may be associated with this baton.
780
  void* user_data;
781 782
  /// The callback invoked by the engine when it no longer needs this backing
  /// store.
783 784 785
  VoidCallback destruction_callback;
} FlutterSoftwareBackingStore;

786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811
typedef enum {
  /// Indicates that the Flutter application requested that an opacity be
  /// applied to the platform view.
  kFlutterPlatformViewMutationTypeOpacity,
  /// Indicates that the Flutter application requested that the platform view be
  /// clipped using a rectangle.
  kFlutterPlatformViewMutationTypeClipRect,
  /// Indicates that the Flutter application requested that the platform view be
  /// clipped using a rounded rectangle.
  kFlutterPlatformViewMutationTypeClipRoundedRect,
  /// Indicates that the Flutter application requested that the platform view be
  /// transformed before composition.
  kFlutterPlatformViewMutationTypeTransformation,
} FlutterPlatformViewMutationType;

typedef struct {
  /// The type of the mutation described by the subsequent union.
  FlutterPlatformViewMutationType type;
  union {
    double opacity;
    FlutterRect clip_rect;
    FlutterRoundedRect clip_rounded_rect;
    FlutterTransformation transformation;
  };
} FlutterPlatformViewMutation;

812
typedef struct {
813
  /// The size of this struct. Must be sizeof(FlutterPlatformView).
814
  size_t struct_size;
815 816 817
  /// The identifier of this platform view. This identifier is specified by the
  /// application when a platform view is added to the scene via the
  /// `SceneBuilder.addPlatformView` call.
818
  FlutterPlatformViewIdentifier identifier;
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
  /// The number of mutations to be applied to the platform view by the embedder
  /// before on-screen composition.
  size_t mutations_count;
  /// The mutations to be applied by this platform view before it is composited
  /// on-screen. The Flutter application may transform the platform view but
  /// these transformations cannot be affected by the Flutter compositor because
  /// it does not render platform views. Since the embedder is responsible for
  /// composition of these views, it is also the embedder's responsibility to
  /// affect the appropriate transformation.
  ///
  /// The mutations must be applied in order. The mutations done in the
  /// collection don't take into account the device pixel ratio or the root
  /// surface transformation. If these exist, the first mutation in the list
  /// will be a transformation mutation to make sure subsequent mutations are in
  /// the correct coordinate space.
  const FlutterPlatformViewMutation** mutations;
835 836 837
} FlutterPlatformView;

typedef enum {
838 839
  /// Specifies an OpenGL backing store. Can either be an OpenGL texture or
  /// framebuffer.
840
  kFlutterBackingStoreTypeOpenGL,
841
  /// Specified an software allocation for Flutter to render into using the CPU.
842 843 844 845
  kFlutterBackingStoreTypeSoftware,
} FlutterBackingStoreType;

typedef struct {
846
  /// The size of this struct. Must be sizeof(FlutterBackingStore).
847
  size_t struct_size;
848 849 850
  /// A baton that is not interpreted by the engine in any way. The embedder may
  /// use this to associate resources that are tied to the lifecycle of the
  /// `FlutterBackingStore`.
851
  void* user_data;
852
  /// Specifies the type of backing store.
853
  FlutterBackingStoreType type;
854 855
  /// Indicates if this backing store was updated since the last time it was
  /// associated with a presented layer.
856 857
  bool did_update;
  union {
858
    /// The description of the OpenGL backing store.
859
    FlutterOpenGLBackingStore open_gl;
860
    /// The description of the software backing store.
861 862 863 864 865
    FlutterSoftwareBackingStore software;
  };
} FlutterBackingStore;

typedef struct {
866
  /// The size of this struct. Must be sizeof(FlutterBackingStoreConfig).
867
  size_t struct_size;
868
  /// The size of the render target the engine expects to render into.
869 870 871 872
  FlutterSize size;
} FlutterBackingStoreConfig;

typedef enum {
873 874
  /// Indicates that the contents of this layer are rendered by Flutter into a
  /// backing store.
875
  kFlutterLayerContentTypeBackingStore,
876
  /// Indicates that the contents of this layer are determined by the embedder.
877 878 879 880
  kFlutterLayerContentTypePlatformView,
} FlutterLayerContentType;

typedef struct {
881
  /// This size of this struct. Must be sizeof(FlutterLayer).
882
  size_t struct_size;
883 884
  /// Each layer displays contents in one way or another. The type indicates
  /// whether those contents are specified by Flutter or the embedder.
885 886
  FlutterLayerContentType type;
  union {
887 888
    /// Indicates that the contents of this layer are rendered by Flutter into a
    /// backing store.
889
    const FlutterBackingStore* backing_store;
890 891
    /// Indicates that the contents of this layer are determined by the
    /// embedder.
892 893
    const FlutterPlatformView* platform_view;
  };
894 895
  /// The offset of this layer (in physical pixels) relative to the top left of
  /// the root surface used by the engine.
896
  FlutterPoint offset;
897
  /// The size of the layer (in physical pixels).
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914
  FlutterSize size;
} FlutterLayer;

typedef bool (*FlutterBackingStoreCreateCallback)(
    const FlutterBackingStoreConfig* config,
    FlutterBackingStore* backing_store_out,
    void* user_data);

typedef bool (*FlutterBackingStoreCollectCallback)(
    const FlutterBackingStore* renderer,
    void* user_data);

typedef bool (*FlutterLayersPresentCallback)(const FlutterLayer** layers,
                                             size_t layers_count,
                                             void* user_data);

typedef struct {
915
  /// This size of this struct. Must be sizeof(FlutterCompositor).
916
  size_t struct_size;
917 918 919 920
  /// A baton that in not interpreted by the engine in any way. If it passed
  /// back to the embedder in `FlutterCompositor.create_backing_store_callback`,
  /// `FlutterCompositor.collect_backing_store_callback` and
  /// `FlutterCompositor.present_layers_callback`
921
  void* user_data;
922 923 924 925 926 927 928
  /// A callback invoked by the engine to obtain a backing store for a specific
  /// `FlutterLayer`.
  ///
  /// On ABI stability: Callers must take care to restrict access within
  /// `FlutterBackingStore::struct_size` when specifying a new backing store to
  /// the engine. This only matters if the embedder expects to be used with
  /// engines older than the version whose headers it used during compilation.
929
  FlutterBackingStoreCreateCallback create_backing_store_callback;
930 931
  /// A callback invoked by the engine to release the backing store. The
  /// embedder may collect any resources associated with the backing store.
932
  FlutterBackingStoreCollectCallback collect_backing_store_callback;
933 934
  /// Callback invoked by the engine to composite the contents of each layer
  /// onto the screen.
935 936 937
  FlutterLayersPresentCallback present_layers_callback;
} FlutterCompositor;

938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961
typedef struct {
  /// This size of this struct. Must be sizeof(FlutterLocale).
  size_t struct_size;
  /// The language code of the locale. For example, "en". This is a required
  /// field. The string must be null terminated. It may be collected after the
  /// call to `FlutterEngineUpdateLocales`.
  const char* language_code;
  /// The country code of the locale. For example, "US". This is a an optional
  /// field. The string must be null terminated if present. It may be collected
  /// after the call to `FlutterEngineUpdateLocales`. If not present, a
  /// `nullptr` may be specified.
  const char* country_code;
  /// The script code of the locale. This is a an optional field. The string
  /// must be null terminated if present. It may be collected after the call to
  /// `FlutterEngineUpdateLocales`. If not present, a `nullptr` may be
  /// specified.
  const char* script_code;
  /// The variant code of the locale. This is a an optional field. The string
  /// must be null terminated if present. It may be collected after the call to
  /// `FlutterEngineUpdateLocales`. If not present, a `nullptr` may be
  /// specified.
  const char* variant_code;
} FlutterLocale;

962 963 964 965
typedef const FlutterLocale* (*FlutterComputePlatformResolvedLocaleCallback)(
    const FlutterLocale** /* supported_locales*/,
    size_t /* Number of locales*/);

966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
/// Display refers to a graphics hardware system consisting of a framebuffer,
/// typically a monitor or a screen. This ID is unique per display and is
/// stable until the Flutter application restarts.
typedef uint64_t FlutterEngineDisplayId;

typedef struct {
  /// This size of this struct. Must be sizeof(FlutterDisplay).
  size_t struct_size;

  FlutterEngineDisplayId display_id;

  /// This is set to true if the embedder only has one display. In cases where
  /// this is set to true, the value of display_id is ignored. In cases where
  /// this is not set to true, it is expected that a valid display_id be
  /// provided.
  bool single_display;

  /// This represents the refresh period in frames per second. This value may be
  /// zero if the device is not running or unavaliable or unknown.
  double refresh_rate;
} FlutterEngineDisplay;

/// The update type parameter that is passed to
/// `FlutterEngineNotifyDisplayUpdate`.
typedef enum {
  /// `FlutterEngineDisplay`s that were active during start-up. A display is
  /// considered active if:
  ///    1. The frame buffer hardware is connected.
  ///    2. The display is drawable, e.g. it isn't being mirrored from another
  ///    connected display or sleeping.
  kFlutterEngineDisplaysUpdateTypeStartup,
  kFlutterEngineDisplaysUpdateTypeCount,
} FlutterEngineDisplaysUpdateType;

//------------------------------------------------------------------------------
/// @brief    Posts updates corresponding to display changes to a running engine
///           instance.
///
/// @param[in] update_type      The type of update pushed to the engine.
/// @param[in] displays         The displays affected by this update.
/// @param[in] display_count    Size of the displays array, must be at least 1.
///
/// @return the result of the call made to the engine.
///
FlutterEngineResult FlutterEngineNotifyDisplayUpdate(
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
    FlutterEngineDisplaysUpdateType update_type,
    const FlutterEngineDisplay* displays,
    size_t display_count);

1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
typedef int64_t FlutterEngineDartPort;

typedef enum {
  kFlutterEngineDartObjectTypeNull,
  kFlutterEngineDartObjectTypeBool,
  kFlutterEngineDartObjectTypeInt32,
  kFlutterEngineDartObjectTypeInt64,
  kFlutterEngineDartObjectTypeDouble,
  kFlutterEngineDartObjectTypeString,
  /// The object will be made available to Dart code as an instance of
  /// Uint8List.
  kFlutterEngineDartObjectTypeBuffer,
} FlutterEngineDartObjectType;

typedef struct {
  /// The size of this struct. Must be sizeof(FlutterEngineDartBuffer).
  size_t struct_size;
  /// An opaque baton passed back to the embedder when the
  /// buffer_collect_callback is invoked. The engine does not interpret this
  /// field in any way.
  void* user_data;
  /// This is an optional field.
  ///
  /// When specified, the engine will assume that the buffer is owned by the
  /// embedder. When the data is no longer needed by any isolate, this callback
  /// will be made on an internal engine managed thread. The embedder is free to
  /// collect the buffer here. When this field is specified, it is the embedders
  /// responsibility to keep the buffer alive and not modify it till this
  /// callback is invoked by the engine. The user data specified in the callback
  /// is the value of `user_data` field in this struct.
  ///
  /// When NOT specified, the VM creates an internal copy of the buffer. The
  /// caller is free to modify the buffer as necessary or collect it immediately
  /// after the call to `FlutterEnginePostDartObject`.
  ///
  /// @attention      The buffer_collect_callback is will only be invoked by the
  ///                 engine when the `FlutterEnginePostDartObject` method
  ///                 returns kSuccess. In case of non-successful calls to this
  ///                 method, it is the embedders responsibility to collect the
  ///                 buffer.
  VoidCallback buffer_collect_callback;
  /// A pointer to the bytes of the buffer. When the buffer is owned by the
  /// embedder (by specifying the `buffer_collect_callback`), Dart code may
  /// modify that embedder owned buffer. For this reason, it is important that
  /// this buffer not have page protections that restrict writing to this
  /// buffer.
  uint8_t* buffer;
  /// The size of the buffer.
  size_t buffer_size;
} FlutterEngineDartBuffer;

/// This struct specifies the native representation of a Dart object that can be
/// sent via a send port to any isolate in the VM that has the corresponding
/// receive port.
///
/// All fields in this struct are copied out in the call to
/// `FlutterEnginePostDartObject` and the caller is free to reuse or collect
/// this struct after that call.
typedef struct {
  FlutterEngineDartObjectType type;
  union {
    bool bool_value;
    int32_t int32_value;
    int64_t int64_value;
    double double_value;
    /// A null terminated string. This string will be copied by the VM in the
    /// call to `FlutterEnginePostDartObject` and must be collected by the
    /// embedder after that call is made.
    const char* string_value;
    const FlutterEngineDartBuffer* buffer_value;
  };
} FlutterEngineDartObject;

1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113
/// This enum allows embedders to determine the type of the engine thread in the
/// FlutterNativeThreadCallback. Based on the thread type, the embedder may be
/// able to tweak the thread priorities for optimum performance.
typedef enum {
  /// The Flutter Engine considers the thread on which the FlutterEngineRun call
  /// is made to be the platform thread. There is only one such thread per
  /// engine instance.
  kFlutterNativeThreadTypePlatform,
  /// This is the thread the Flutter Engine uses to execute rendering commands
  /// based on the selected client rendering API. There is only one such thread
  /// per engine instance.
  kFlutterNativeThreadTypeRender,
  /// This is a dedicated thread on which the root Dart isolate is serviced.
  /// There is only one such thread per engine instance.
  kFlutterNativeThreadTypeUI,
  /// Multiple threads are used by the Flutter engine to perform long running
  /// background tasks.
  kFlutterNativeThreadTypeWorker,
} FlutterNativeThreadType;

/// A callback made by the engine in response to
/// `FlutterEnginePostCallbackOnAllNativeThreads` on all internal thread.
typedef void (*FlutterNativeThreadCallback)(FlutterNativeThreadType type,
                                            void* user_data);

1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164
/// AOT data source type.
typedef enum {
  kFlutterEngineAOTDataSourceTypeElfPath
} FlutterEngineAOTDataSourceType;

/// This struct specifies one of the various locations the engine can look for
/// AOT data sources.
typedef struct {
  FlutterEngineAOTDataSourceType type;
  union {
    /// Absolute path to an ELF library file.
    const char* elf_path;
  };
} FlutterEngineAOTDataSource;

/// An opaque object that describes the AOT data that can be used to launch a
/// FlutterEngine instance in AOT mode.
typedef struct _FlutterEngineAOTData* FlutterEngineAOTData;

//------------------------------------------------------------------------------
/// @brief      Creates the necessary data structures to launch a Flutter Dart
///             application in AOT mode. The data may only be collected after
///             all FlutterEngine instances launched using this data have been
///             terminated.
///
/// @param[in]  source    The source of the AOT data.
/// @param[out] data_out  The AOT data on success. Unchanged on failure.
///
/// @return     Returns if the AOT data could be successfully resolved.
///
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineCreateAOTData(
    const FlutterEngineAOTDataSource* source,
    FlutterEngineAOTData* data_out);

//------------------------------------------------------------------------------
/// @brief      Collects the AOT data.
///
/// @warning    The embedder must ensure that this call is made only after all
///             FlutterEngine instances launched using this data have been
///             terminated, and that all of those instances were launched with
///             the FlutterProjectArgs::shutdown_dart_vm_when_done flag set to
///             true.
///
/// @param[in]  data   The data to collect.
///
/// @return     Returns if the AOT data was successfully collected.
///
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineCollectAOTData(FlutterEngineAOTData data);

1165
typedef struct {
1166
  /// The size of this struct. Must be sizeof(FlutterProjectArgs).
1167
  size_t struct_size;
1168 1169 1170
  /// The path to the Flutter assets directory containing project assets. The
  /// string can be collected after the call to `FlutterEngineRun` returns. The
  /// string must be NULL terminated.
1171
  const char* assets_path;
1172 1173 1174 1175 1176 1177 1178 1179 1180
  /// The path to the Dart file containing the `main` entry point.
  /// The string can be collected after the call to `FlutterEngineRun` returns.
  /// The string must be NULL terminated.
  ///
  /// @deprecated     As of Dart 2, running from Dart source is no longer
  ///                 supported. Dart code should now be compiled to kernel form
  ///                 and will be loaded by from `kernel_blob.bin` in the assets
  ///                 directory. This struct member is retained for ABI
  ///                 stability.
1181
  const char* main_path__unused__;
1182 1183 1184 1185 1186 1187 1188 1189 1190
  /// The path to the `.packages` file for the project. The string can be
  /// collected after the call to `FlutterEngineRun` returns. The string must be
  /// NULL terminated.
  ///
  /// @deprecated    As of Dart 2, running from Dart source is no longer
  ///                supported. Dart code should now be compiled to kernel form
  ///                and will be loaded by from `kernel_blob.bin` in the assets
  ///                directory. This struct member is retained for ABI
  ///                stability.
1191
  const char* packages_path__unused__;
1192 1193 1194
  /// The path to the `icudtl.dat` file for the project. The string can be
  /// collected after the call to `FlutterEngineRun` returns. The string must
  /// be NULL terminated.
1195
  const char* icu_data_path;
1196
  /// The command line argument count used to initialize the project.
1197
  int command_line_argc;
1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212
  /// The command line arguments used to initialize the project. The strings can
  /// be collected after the call to `FlutterEngineRun` returns. The strings
  /// must be `NULL` terminated.
  ///
  /// @attention     The first item in the command line (if specified at all) is
  ///                interpreted as the executable name. So if an engine flag
  ///                needs to be passed into the same, it needs to not be the
  ///                very first item in the list.
  ///
  /// The set of engine flags are only meant to control
  /// unstable features in the engine. Deployed applications should not pass any
  /// command line arguments at all as they may affect engine stability at
  /// runtime in the presence of un-sanitized input. The list of currently
  /// recognized engine flags and their descriptions can be retrieved from the
  /// `switches.h` engine source file.
1213
  const char* const* command_line_argv;
1214 1215 1216 1217
  /// The callback invoked by the engine in order to give the embedder the
  /// chance to respond to platform messages from the Dart application. The
  /// callback will be invoked on the thread on which the `FlutterEngineRun`
  /// call is made.
1218
  FlutterPlatformMessageCallback platform_message_callback;
1219 1220 1221 1222
  /// The VM snapshot data buffer used in AOT operation. This buffer must be
  /// mapped in as read-only. For more information refer to the documentation on
  /// the Wiki at
  /// https://github.com/flutter/flutter/wiki/Flutter-engine-operation-in-AOT-Mode
1223
  const uint8_t* vm_snapshot_data;
1224 1225
  /// The size of the VM snapshot data buffer.  If vm_snapshot_data is a symbol
  /// reference, 0 may be passed here.
1226
  size_t vm_snapshot_data_size;
1227 1228 1229 1230
  /// The VM snapshot instructions buffer used in AOT operation. This buffer
  /// must be mapped in as read-execute. For more information refer to the
  /// documentation on the Wiki at
  /// https://github.com/flutter/flutter/wiki/Flutter-engine-operation-in-AOT-Mode
1231
  const uint8_t* vm_snapshot_instructions;
1232 1233
  /// The size of the VM snapshot instructions buffer. If
  /// vm_snapshot_instructions is a symbol reference, 0 may be passed here.
1234
  size_t vm_snapshot_instructions_size;
1235 1236 1237 1238
  /// The isolate snapshot data buffer used in AOT operation. This buffer must
  /// be mapped in as read-only. For more information refer to the documentation
  /// on the Wiki at
  /// https://github.com/flutter/flutter/wiki/Flutter-engine-operation-in-AOT-Mode
1239
  const uint8_t* isolate_snapshot_data;
1240 1241
  /// The size of the isolate snapshot data buffer.  If isolate_snapshot_data is
  /// a symbol reference, 0 may be passed here.
1242
  size_t isolate_snapshot_data_size;
1243 1244 1245 1246
  /// The isolate snapshot instructions buffer used in AOT operation. This
  /// buffer must be mapped in as read-execute. For more information refer to
  /// the documentation on the Wiki at
  /// https://github.com/flutter/flutter/wiki/Flutter-engine-operation-in-AOT-Mode
1247
  const uint8_t* isolate_snapshot_instructions;
1248 1249
  /// The size of the isolate snapshot instructions buffer. If
  /// isolate_snapshot_instructions is a symbol reference, 0 may be passed here.
1250
  size_t isolate_snapshot_instructions_size;
1251 1252
  /// The callback invoked by the engine in root isolate scope. Called
  /// immediately after the root isolate has been created and marked runnable.
1253
  VoidCallback root_isolate_create_callback;
1254 1255 1256 1257 1258 1259 1260 1261
  /// The callback invoked by the engine in order to give the embedder the
  /// chance to respond to semantics node updates from the Dart application.
  /// Semantics node updates are sent in batches terminated by a 'batch end'
  /// callback that is passed a sentinel `FlutterSemanticsNode` whose `id` field
  /// has the value `kFlutterSemanticsNodeIdBatchEnd`.
  ///
  /// The callback will be invoked on the thread on which the `FlutterEngineRun`
  /// call is made.
1262
  FlutterUpdateSemanticsNodeCallback update_semantics_node_callback;
1263 1264 1265 1266 1267 1268 1269 1270 1271
  /// The callback invoked by the engine in order to give the embedder the
  /// chance to respond to updates to semantics custom actions from the Dart
  /// application.  Custom action updates are sent in batches terminated by a
  /// 'batch end' callback that is passed a sentinel
  /// `FlutterSemanticsCustomAction` whose `id` field has the value
  /// `kFlutterSemanticsCustomActionIdBatchEnd`.
  ///
  /// The callback will be invoked on the thread on which the `FlutterEngineRun`
  /// call is made.
1272 1273
  FlutterUpdateSemanticsCustomActionCallback
      update_semantics_custom_action_callback;
1274 1275 1276 1277
  /// Path to a directory used to store data that is cached across runs of a
  /// Flutter application (such as compiled shader programs used by Skia).
  /// This is optional.  The string must be NULL terminated.
  ///
1278
  // This is different from the cache-path-dir argument defined in switches.h,
1279
  // which is used in `flutter::Settings` as `temp_directory_path`.
1280
  const char* persistent_cache_path;
1281

L
liyuqian 已提交
1282 1283
  /// If true, the engine would only read the existing cache, but not write new
  /// ones.
1284 1285
  bool is_persistent_cache_read_only;

1286 1287 1288 1289 1290 1291 1292 1293 1294
  /// A callback that gets invoked by the engine when it attempts to wait for a
  /// platform vsync event. The engine will give the platform a baton that needs
  /// to be returned back to the engine via `FlutterEngineOnVsync`. All batons
  /// must be retured to the engine before initializing a
  /// `FlutterEngineShutdown`. Not doing the same will result in a memory leak.
  /// While the call to `FlutterEngineOnVsync` must occur on the thread that
  /// made the call to `FlutterEngineRun`, the engine will make this callback on
  /// an internal engine-managed thread. If the components accessed on the
  /// embedder are not thread safe, the appropriate re-threading must be done.
1295
  VsyncCallback vsync_callback;
1296

1297 1298 1299 1300 1301 1302 1303
  /// The name of a custom Dart entrypoint. This is optional and specifying a
  /// null or empty entrypoint makes the engine look for a method named "main"
  /// in the root library of the application.
  ///
  /// Care must be taken to ensure that the custom entrypoint is not tree-shaken
  /// away. Usually, this is done using the `@pragma('vm:entry-point')`
  /// decoration.
1304
  const char* custom_dart_entrypoint;
1305

1306 1307 1308
  /// Typically the Flutter engine create and manages its internal threads. This
  /// optional argument allows for the specification of task runner interfaces
  /// to event loops managed by the embedder on threads it creates.
1309
  const FlutterCustomTaskRunners* custom_task_runners;
1310

1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
  /// All `FlutterEngine` instances in the process share the same Dart VM. When
  /// the first engine is launched, it starts the Dart VM as well. It used to be
  /// the case that it was not possible to shutdown the Dart VM cleanly and
  /// start it back up in the process in a safe manner. This issue has since
  /// been patched. Unfortunately, applications already began to make use of the
  /// fact that shutting down the Flutter engine instance left a running VM in
  /// the process. Since a Flutter engine could be launched on any thread,
  /// applications would "warm up" the VM on another thread by launching
  /// an engine with no isolates and then shutting it down immediately. The main
  /// Flutter application could then be started on the main thread without
  /// having to incur the Dart VM startup costs at that time. With the new
  /// behavior, this "optimization" immediately becomes massive performance
  /// pessimization as the VM would be started up in the "warm up" phase, shut
  /// down there and then started again on the main thread. Changing this
  /// behavior was deemed to be an unacceptable breaking change. Embedders that
  /// wish to shutdown the Dart VM when the last engine is terminated in the
  /// process should opt into this behavior by setting this flag to true.
1328
  bool shutdown_dart_vm_when_done;
1329

1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343
  /// Typically, Flutter renders the layer hierarchy into a single root surface.
  /// However, when embedders need to interleave their own contents within the
  /// Flutter layer hierarchy, their applications can push platform views within
  /// the Flutter scene. This is done using the `SceneBuilder.addPlatformView`
  /// call. When this happens, the Flutter rasterizer divides the effective view
  /// hierarchy into multiple layers. Each layer gets its own backing store and
  /// Flutter renders into the same. Once the layers contents have been
  /// fulfilled, the embedder is asked to composite these layers on-screen. At
  /// this point, it can interleave its own contents within the effective
  /// hierarchy. The interface for the specification of these layer backing
  /// stores and the hooks to listen for the composition of layers on-screen can
  /// be controlled using this field. This field is completely optional. In its
  /// absence, platforms views in the scene are ignored and Flutter renders to
  /// the root surface as normal.
1344
  const FlutterCompositor* compositor;
1345 1346 1347 1348 1349 1350 1351

  /// Max size of the old gen heap for the Dart VM in MB, or 0 for unlimited, -1
  /// for default value.
  ///
  /// See also:
  /// https://github.com/dart-lang/sdk/blob/ca64509108b3e7219c50d6c52877c85ab6a35ff2/runtime/vm/flag_list.h#L150
  int64_t dart_old_gen_heap_size;
1352 1353 1354 1355 1356 1357 1358 1359

  /// The AOT data to be used in AOT operation.
  ///
  /// Embedders should instantiate and destroy this object via the
  /// FlutterEngineCreateAOTData and FlutterEngineCollectAOTData methods.
  ///
  /// Embedders can provide either snapshot buffers or aot_data, but not both.
  FlutterEngineAOTData aot_data;
1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370

  /// A callback that computes the locale the platform would natively resolve
  /// to.
  ///
  /// The input parameter is an array of FlutterLocales which represent the
  /// locales supported by the app. One of the input supported locales should
  /// be selected and returned to best match with the user/device's preferred
  /// locale. The implementation should produce a result that as closely
  /// matches what the platform would natively resolve to as possible.
  FlutterComputePlatformResolvedLocaleCallback
      compute_platform_resolved_locale_callback;
1371 1372
} FlutterProjectArgs;

1373 1374
//------------------------------------------------------------------------------
/// @brief      Initialize and run a Flutter engine instance and return a handle
D
Dan Field 已提交
1375
///             to it. This is a convenience method for the pair of calls to
1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398
///             `FlutterEngineInitialize` and `FlutterEngineRunInitialized`.
///
/// @note       This method of running a Flutter engine works well except in
///             cases where the embedder specifies custom task runners via
///             `FlutterProjectArgs::custom_task_runners`. In such cases, the
///             engine may need the embedder to post tasks back to it before
///             `FlutterEngineRun` has returned. Embedders can only post tasks
///             to the engine if they have a handle to the engine. In such
///             cases, embedders are advised to get the engine handle via the
///             `FlutterInitializeCall`. Then they can call
///             `FlutterEngineRunInitialized` knowing that they will be able to
///             service custom tasks on other threads with the engine handle.
///
/// @param[in]  version    The Flutter embedder API version. Must be
///                        FLUTTER_ENGINE_VERSION.
/// @param[in]  config     The renderer configuration.
/// @param[in]  args       The Flutter project arguments.
/// @param      user_data  A user data baton passed back to embedders in
///                        callbacks.
/// @param[out] engine_out The engine handle on successful engine creation.
///
/// @return     The result of the call to run the Flutter engine.
///
1399
FLUTTER_EXPORT
1400 1401 1402 1403
FlutterEngineResult FlutterEngineRun(size_t version,
                                     const FlutterRendererConfig* config,
                                     const FlutterProjectArgs* args,
                                     void* user_data,
1404 1405
                                     FLUTTER_API_SYMBOL(FlutterEngine) *
                                         engine_out);
1406

1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418
//------------------------------------------------------------------------------
/// @brief      Shuts down a Flutter engine instance. The engine handle is no
///             longer valid for any calls in the embedder API after this point.
///             Making additional calls with this handle is undefined behavior.
///
/// @note       This de-initializes the Flutter engine instance (via an implicit
///             call to `FlutterEngineDeinitialize`) if necessary.
///
/// @param[in]  engine  The Flutter engine instance to collect.
///
/// @return     The result of the call to shutdown the Flutter engine instance.
///
1419
FLUTTER_EXPORT
1420 1421
FlutterEngineResult FlutterEngineShutdown(FLUTTER_API_SYMBOL(FlutterEngine)
                                              engine);
1422

1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481
//------------------------------------------------------------------------------
/// @brief      Initialize a Flutter engine instance. This does not run the
///             Flutter application code till the `FlutterEngineRunInitialized`
///             call is made. Besides Flutter application code, no tasks are
///             scheduled on embedder managed task runners either. This allows
///             embedders providing custom task runners to the Flutter engine to
///             obtain a handle to the Flutter engine before the engine can post
///             tasks on these task runners.
///
/// @param[in]  version    The Flutter embedder API version. Must be
///                        FLUTTER_ENGINE_VERSION.
/// @param[in]  config     The renderer configuration.
/// @param[in]  args       The Flutter project arguments.
/// @param      user_data  A user data baton passed back to embedders in
///                        callbacks.
/// @param[out] engine_out The engine handle on successful engine creation.
///
/// @return     The result of the call to initialize the Flutter engine.
///
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineInitialize(size_t version,
                                            const FlutterRendererConfig* config,
                                            const FlutterProjectArgs* args,
                                            void* user_data,
                                            FLUTTER_API_SYMBOL(FlutterEngine) *
                                                engine_out);

//------------------------------------------------------------------------------
/// @brief      Stops running the Flutter engine instance. After this call, the
///             embedder is also guaranteed that no more calls to post tasks
///             onto custom task runners specified by the embedder are made. The
///             Flutter engine handle still needs to be collected via a call to
///             `FlutterEngineShutdown`.
///
/// @param[in]  engine    The running engine instance to de-initialize.
///
/// @return     The result of the call to de-initialize the Flutter engine.
///
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineDeinitialize(FLUTTER_API_SYMBOL(FlutterEngine)
                                                  engine);

//------------------------------------------------------------------------------
/// @brief      Runs an initialized engine instance. An engine can be
///             initialized via `FlutterEngineInitialize`. An initialized
///             instance can only be run once. During and after this call,
///             custom task runners supplied by the embedder are expected to
///             start servicing tasks.
///
/// @param[in]  engine  An initialized engine instance that has not previously
///                     been run.
///
/// @return     The result of the call to run the initialized Flutter
///             engine instance.
///
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineRunInitialized(
    FLUTTER_API_SYMBOL(FlutterEngine) engine);

1482
FLUTTER_EXPORT
1483
FlutterEngineResult FlutterEngineSendWindowMetricsEvent(
1484
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1485 1486 1487
    const FlutterWindowMetricsEvent* event);

FLUTTER_EXPORT
1488
FlutterEngineResult FlutterEngineSendPointerEvent(
1489
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1490 1491
    const FlutterPointerEvent* events,
    size_t events_count);
1492

1493
FLUTTER_EXPORT
1494
FlutterEngineResult FlutterEngineSendPlatformMessage(
1495
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1496 1497
    const FlutterPlatformMessage* message);

1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526
//------------------------------------------------------------------------------
/// @brief     Creates a platform message response handle that allows the
///            embedder to set a native callback for a response to a message.
///            This handle may be set on the `response_handle` field of any
///            `FlutterPlatformMessage` sent to the engine.
///
///            The handle must be collected via a call to
///            `FlutterPlatformMessageReleaseResponseHandle`. This may be done
///            immediately after a call to `FlutterEngineSendPlatformMessage`
///            with a platform message whose response handle contains the handle
///            created using this call. In case a handle is created but never
///            sent in a message, the release call must still be made. Not
///            calling release on the handle results in a small memory leak.
///
///            The user data baton passed to the data callback is the one
///            specified in this call as the third argument.
///
/// @see       FlutterPlatformMessageReleaseResponseHandle()
///
/// @param[in]  engine         A running engine instance.
/// @param[in]  data_callback  The callback invoked by the engine when the
///                            Flutter application send a response on the
///                            handle.
/// @param[in]  user_data      The user data associated with the data callback.
/// @param[out] response_out   The response handle created when this call is
///                            successful.
///
/// @return     The result of the call.
///
1527 1528
FLUTTER_EXPORT
FlutterEngineResult FlutterPlatformMessageCreateResponseHandle(
1529
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1530 1531 1532 1533
    FlutterDataCallback data_callback,
    void* user_data,
    FlutterPlatformMessageResponseHandle** response_out);

1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546
//------------------------------------------------------------------------------
/// @brief      Collects the handle created using
///             `FlutterPlatformMessageCreateResponseHandle`.
///
/// @see        FlutterPlatformMessageCreateResponseHandle()
///
/// @param[in]  engine     A running engine instance.
/// @param[in]  response   The platform message response handle to collect.
///                        These handles are created using
///                        `FlutterPlatformMessageCreateResponseHandle()`.
///
/// @return     The result of the call.
///
1547 1548
FLUTTER_EXPORT
FlutterEngineResult FlutterPlatformMessageReleaseResponseHandle(
1549
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1550 1551
    FlutterPlatformMessageResponseHandle* response);

1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563
//------------------------------------------------------------------------------
/// @brief      Send a response from the native side to a platform message from
///             the Dart Flutter application.
///
/// @param[in]  engine       The running engine instance.
/// @param[in]  handle       The platform message response handle.
/// @param[in]  data         The data to associate with the platform message
///                          response.
/// @param[in]  data_length  The length of the platform message response data.
///
/// @return     The result of the call.
///
1564
FLUTTER_EXPORT
1565
FlutterEngineResult FlutterEngineSendPlatformMessageResponse(
1566
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1567 1568 1569 1570
    const FlutterPlatformMessageResponseHandle* handle,
    const uint8_t* data,
    size_t data_length);

1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583
//------------------------------------------------------------------------------
/// @brief      This API is only meant to be used by platforms that need to
///             flush tasks on a message loop not controlled by the Flutter
///             engine.
///
/// @deprecated This API will be deprecated and is not part of the stable API.
///             Please use the custom task runners API by setting an
///             appropriate `FlutterProjectArgs::custom_task_runners`
///             interface. This will yield better performance and the
///             interface is stable.
///
/// @return     The result of the call.
///
1584
FLUTTER_EXPORT
1585
FlutterEngineResult __FlutterEngineFlushPendingTasksNow();
1586

1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605
//------------------------------------------------------------------------------
/// @brief      Register an external texture with a unique (per engine)
///             identifier. Only rendering backends that support external
///             textures accept external texture registrations. After the
///             external texture is registered, the application can mark that a
///             frame is available by calling
///             `FlutterEngineMarkExternalTextureFrameAvailable`.
///
/// @see        FlutterEngineUnregisterExternalTexture()
/// @see        FlutterEngineMarkExternalTextureFrameAvailable()
///
/// @param[in]  engine              A running engine instance.
/// @param[in]  texture_identifier  The identifier of the texture to register
///                                 with the engine. The embedder may supply new
///                                 frames to this texture using the same
///                                 identifier.
///
/// @return     The result of the call.
///
1606
FLUTTER_EXPORT
1607
FlutterEngineResult FlutterEngineRegisterExternalTexture(
1608
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1609
    int64_t texture_identifier);
1610

1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622
//------------------------------------------------------------------------------
/// @brief      Unregister a previous texture registration.
///
/// @see        FlutterEngineRegisterExternalTexture()
/// @see        FlutterEngineMarkExternalTextureFrameAvailable()
///
/// @param[in]  engine              A running engine instance.
/// @param[in]  texture_identifier  The identifier of the texture for which new
///                                 frame will not be available.
///
/// @return     The result of the call.
///
1623
FLUTTER_EXPORT
1624
FlutterEngineResult FlutterEngineUnregisterExternalTexture(
1625
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1626 1627
    int64_t texture_identifier);

1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640
//------------------------------------------------------------------------------
/// @brief      Mark that a new texture frame is available for a given texture
///             identifier.
///
/// @see        FlutterEngineRegisterExternalTexture()
/// @see        FlutterEngineUnregisterExternalTexture()
///
/// @param[in]  engine              A running engine instance.
/// @param[in]  texture_identifier  The identifier of the texture whose frame
///                                 has been updated.
///
/// @return     The result of the call.
///
1641
FLUTTER_EXPORT
1642
FlutterEngineResult FlutterEngineMarkExternalTextureFrameAvailable(
1643
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1644 1645
    int64_t texture_identifier);

1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657
//------------------------------------------------------------------------------
/// @brief      Enable or disable accessibility semantics.
///
/// @param[in]  engine     A running engine instance.
/// @param[in]  enabled    When enabled, changes to the semantic contents of the
///                        window are sent via the
///                        `FlutterUpdateSemanticsNodeCallback` registered to
///                        `update_semantics_node_callback` in
///                        `FlutterProjectArgs`.
///
/// @return     The result of the call.
///
1658
FLUTTER_EXPORT
1659 1660 1661
FlutterEngineResult FlutterEngineUpdateSemanticsEnabled(
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
    bool enabled);
1662

1663 1664 1665 1666 1667 1668 1669 1670
//------------------------------------------------------------------------------
/// @brief      Sets additional accessibility features.
///
/// @param[in]  engine     A running engine instance
/// @param[in]  features   The accessibility features to set.
///
/// @return     The result of the call.
///
1671 1672
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineUpdateAccessibilityFeatures(
1673
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1674 1675
    FlutterAccessibilityFeature features);

1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686
//------------------------------------------------------------------------------
/// @brief      Dispatch a semantics action to the specified semantics node.
///
/// @param[in]  engine       A running engine instance.
/// @param[in]  identifier   The semantics action identifier.
/// @param[in]  action       The semantics action.
/// @param[in]  data         Data associated with the action.
/// @param[in]  data_length  The data length.
///
/// @return     The result of the call.
///
1687 1688
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineDispatchSemanticsAction(
1689
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1690 1691 1692 1693 1694
    uint64_t id,
    FlutterSemanticsAction action,
    const uint8_t* data,
    size_t data_length);

1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725
//------------------------------------------------------------------------------
/// @brief      Notify the engine that a vsync event occurred. A baton passed to
///             the platform via the vsync callback must be returned. This call
///             must be made on the thread on which the call to
///             `FlutterEngineRun` was made.
///
/// @see        FlutterEngineGetCurrentTime()
///
/// @attention  That frame timepoints are in nanoseconds.
///
/// @attention  The system monotonic clock is used as the timebase.
///
/// @param[in]  engine.                  A running engine instance.
/// @param[in]  baton                    The baton supplied by the engine.
/// @param[in]  frame_start_time_nanos   The point at which the vsync event
///                                      occurred or will occur. If the time
///                                      point is in the future, the engine will
///                                      wait till that point to begin its frame
///                                      workload.
/// @param[in]  frame_target_time_nanos  The point at which the embedder
///                                      anticipates the next vsync to occur.
///                                      This is a hint the engine uses to
///                                      schedule Dart VM garbage collection in
///                                      periods in which the various threads
///                                      are most likely to be idle. For
///                                      example, for a 60Hz display, embedders
///                                      should add 16.6 * 1e6 to the frame time
///                                      field.
///
/// @return     The result of the call.
///
1726
FLUTTER_EXPORT
1727 1728
FlutterEngineResult FlutterEngineOnVsync(FLUTTER_API_SYMBOL(FlutterEngine)
                                             engine,
1729 1730 1731 1732
                                         intptr_t baton,
                                         uint64_t frame_start_time_nanos,
                                         uint64_t frame_target_time_nanos);

1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743
//------------------------------------------------------------------------------
/// @brief      Reloads the system fonts in engine.
///
/// @param[in]  engine.                  A running engine instance.
///
/// @return     The result of the call.
///
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineReloadSystemFonts(
    FLUTTER_API_SYMBOL(FlutterEngine) engine);

1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754
//------------------------------------------------------------------------------
/// @brief      A profiling utility. Logs a trace duration begin event to the
///             timeline. If the timeline is unavailable or disabled, this has
///             no effect. Must be balanced with an duration end event (via
///             `FlutterEngineTraceEventDurationEnd`) with the same name on the
///             same thread. Can be called on any thread. Strings passed into
///             the function will NOT be copied when added to the timeline. Only
///             string literals may be passed in.
///
/// @param[in]  name  The name of the trace event.
///
1755 1756 1757
FLUTTER_EXPORT
void FlutterEngineTraceEventDurationBegin(const char* name);

1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768
//-----------------------------------------------------------------------------
/// @brief      A profiling utility. Logs a trace duration end event to the
///             timeline. If the timeline is unavailable or disabled, this has
///             no effect. This call must be preceded by a trace duration begin
///             call (via `FlutterEngineTraceEventDurationBegin`) with the same
///             name on the same thread. Can be called on any thread. Strings
///             passed into the function will NOT be copied when added to the
///             timeline. Only string literals may be passed in.
///
/// @param[in]  name  The name of the trace event.
///
1769 1770 1771
FLUTTER_EXPORT
void FlutterEngineTraceEventDurationEnd(const char* name);

1772 1773 1774 1775 1776 1777 1778 1779 1780
//-----------------------------------------------------------------------------
/// @brief      A profiling utility. Logs a trace duration instant event to the
///             timeline. If the timeline is unavailable or disabled, this has
///             no effect. Can be called on any thread. Strings passed into the
///             function will NOT be copied when added to the timeline. Only
///             string literals may be passed in.
///
/// @param[in]  name  The name of the trace event.
///
1781 1782 1783
FLUTTER_EXPORT
void FlutterEngineTraceEventInstant(const char* name);

1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794
//------------------------------------------------------------------------------
/// @brief      Posts a task onto the Flutter render thread. Typically, this may
///             be called from any thread as long as a `FlutterEngineShutdown`
///             on the specific engine has not already been initiated.
///
/// @param[in]  engine         A running engine instance.
/// @param[in]  callback       The callback to execute on the render thread.
/// @param      callback_data  The callback context.
///
/// @return     The result of the call.
///
1795
FLUTTER_EXPORT
1796 1797 1798 1799
FlutterEngineResult FlutterEnginePostRenderThreadTask(
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
    VoidCallback callback,
    void* callback_data);
1800

1801 1802 1803 1804 1805 1806
//------------------------------------------------------------------------------
/// @brief      Get the current time in nanoseconds from the clock used by the
///             flutter engine. This is the system monotonic clock.
///
/// @return     The current time in nanoseconds.
///
1807 1808 1809
FLUTTER_EXPORT
uint64_t FlutterEngineGetCurrentTime();

1810 1811 1812 1813 1814 1815 1816
//------------------------------------------------------------------------------
/// @brief      Inform the engine to run the specified task. This task has been
///             given to the engine via the
///             `FlutterTaskRunnerDescription.post_task_callback`. This call
///             must only be made at the target time specified in that callback.
///             Running the task before that time is undefined behavior.
///
1817
/// @param[in]  engine     A running engine instance.
1818 1819 1820 1821
/// @param[in]  task       the task handle.
///
/// @return     The result of the call.
///
1822
FLUTTER_EXPORT
1823 1824
FlutterEngineResult FlutterEngineRunTask(FLUTTER_API_SYMBOL(FlutterEngine)
                                             engine,
1825 1826
                                         const FlutterTask* task);

1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844
//------------------------------------------------------------------------------
/// @brief      Notify a running engine instance that the locale has been
///             updated. The preferred locale must be the first item in the list
///             of locales supplied. The other entries will be used as a
///             fallback.
///
/// @param[in]  engine         A running engine instance.
/// @param[in]  locales        The updated locales in the order of preference.
/// @param[in]  locales_count  The count of locales supplied.
///
/// @return     Whether the locale updates were applied.
///
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineUpdateLocales(FLUTTER_API_SYMBOL(FlutterEngine)
                                                   engine,
                                               const FlutterLocale** locales,
                                               size_t locales_count);

1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864
//------------------------------------------------------------------------------
/// @brief      Returns if the Flutter engine instance will run AOT compiled
///             Dart code. This call has no threading restrictions.
///
///             For embedder code that is configured for both AOT and JIT mode
///             Dart execution based on the Flutter engine being linked to, this
///             runtime check may be used to appropriately configure the
///             `FlutterProjectArgs`. In JIT mode execution, the kernel
///             snapshots must be present in the Flutter assets directory
///             specified in the `FlutterProjectArgs`. For AOT execution, the
///             fields `vm_snapshot_data`, `vm_snapshot_instructions`,
///             `isolate_snapshot_data` and `isolate_snapshot_instructions`
///             (along with their size fields) must be specified in
///             `FlutterProjectArgs`.
///
/// @return     True, if AOT Dart code is run. JIT otherwise.
///
FLUTTER_EXPORT
bool FlutterEngineRunsAOTCompiledDartCode(void);

1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882
//------------------------------------------------------------------------------
/// @brief      Posts a Dart object to specified send port. The corresponding
///             receive port for send port can be in any isolate running in the
///             VM. This isolate can also be the root isolate for an
///             unrelated engine. The engine parameter is necessary only to
///             ensure the call is not made when no engine (and hence no VM) is
///             running.
///
///             Unlike the platform messages mechanism, there are no threading
///             restrictions when using this API. Message can be posted on any
///             thread and they will be made available to isolate on which the
///             corresponding send port is listening.
///
///             However, it is the embedders responsibility to ensure that the
///             call is not made during an ongoing call the
///             `FlutterEngineDeinitialize` or `FlutterEngineShutdown` on
///             another thread.
///
1883
/// @param[in]  engine     A running engine instance.
1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895
/// @param[in]  port       The send port to send the object to.
/// @param[in]  object     The object to send to the isolate with the
///                        corresponding receive port.
///
/// @return     If the message was posted to the send port.
///
FLUTTER_EXPORT
FlutterEngineResult FlutterEnginePostDartObject(
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
    FlutterEngineDartPort port,
    const FlutterEngineDartObject* object);

1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916
//------------------------------------------------------------------------------
/// @brief      Posts a low memory notification to a running engine instance.
///             The engine will do its best to release non-critical resources in
///             response. It is not guaranteed that the resource would have been
///             collected by the time this call returns however. The
///             notification is posted to engine subsystems that may be
///             operating on other threads.
///
///             Flutter applications can respond to these notifications by
///             setting `WidgetsBindingObserver.didHaveMemoryPressure`
///             observers.
///
/// @param[in]  engine     A running engine instance.
///
/// @return     If the low memory notification was sent to the running engine
///             instance.
///
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineNotifyLowMemoryWarning(
    FLUTTER_API_SYMBOL(FlutterEngine) engine);

1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955
//------------------------------------------------------------------------------
/// @brief      Schedule a callback to be run on all engine managed threads.
///             The engine will attempt to service this callback the next time
///             the message loop for each managed thread is idle. Since the
///             engine manages the entire lifecycle of multiple threads, there
///             is no opportunity for the embedders to finely tune the
///             priorities of threads directly, or, perform other thread
///             specific configuration (for example, setting thread names for
///             tracing). This callback gives embedders a chance to affect such
///             tuning.
///
/// @attention  This call is expensive and must be made as few times as
///             possible. The callback must also return immediately as not doing
///             so may risk performance issues (especially for callbacks of type
///             kFlutterNativeThreadTypeUI and kFlutterNativeThreadTypeRender).
///
/// @attention  Some callbacks (especially the ones of type
///             kFlutterNativeThreadTypeWorker) may be called after the
///             FlutterEngine instance has shut down. Embedders must be careful
///             in handling the lifecycle of objects associated with the user
///             data baton.
///
/// @attention  In case there are multiple running Flutter engine instances,
///             their workers are shared.
///
/// @param[in]  engine     A running engine instance.
/// @param[in]  callback   The callback that will get called multiple times on
///                        each engine managed thread.
/// @param[in]  user_data  A baton passed by the engine to the callback. This
///                        baton is not interpreted by the engine in any way.
///
/// @return     Returns if the callback was successfully posted to all threads.
///
FLUTTER_EXPORT
FlutterEngineResult FlutterEnginePostCallbackOnAllNativeThreads(
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
    FlutterNativeThreadCallback callback,
    void* user_data);

1956 1957 1958 1959 1960
#if defined(__cplusplus)
}  // extern "C"
#endif

#endif  // FLUTTER_EMBEDDER_H_