embedder.h 62.7 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 12 13 14 15 16 17 18 19
// 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>

#if defined(__cplusplus)
extern "C" {
#endif

#ifndef FLUTTER_EXPORT
#define FLUTTER_EXPORT
#endif  // FLUTTER_EXPORT

20 21 22 23 24 25 26 27 28 29
#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

30 31 32 33 34 35
#define FLUTTER_ENGINE_VERSION 1

typedef enum {
  kSuccess = 0,
  kInvalidLibraryVersion,
  kInvalidArguments,
36
  kInternalInconsistency,
37
} FlutterEngineResult;
38 39 40

typedef enum {
  kOpenGL,
41
  kSoftware,
42 43
} FlutterRendererType;

44 45
/// Additional accessibility features that may be enabled by the platform.
/// Must match the `AccessibilityFeatures` enum in window.dart.
46
typedef enum {
47 48
  /// Indicate there is a running accessibility service which is changing the
  /// interaction model of the device.
49
  kFlutterAccessibilityFeatureAccessibleNavigation = 1 << 0,
50
  /// Indicate the platform is inverting the colors of the application.
51
  kFlutterAccessibilityFeatureInvertColors = 1 << 1,
52
  /// Request that animations be disabled or simplified.
53
  kFlutterAccessibilityFeatureDisableAnimations = 1 << 2,
54
  /// Request that text be rendered at a bold font weight.
55
  kFlutterAccessibilityFeatureBoldText = 1 << 3,
56
  /// Request that certain animations be simplified and parallax effects
57 58 59 60
  // removed.
  kFlutterAccessibilityFeatureReduceMotion = 1 << 4,
} FlutterAccessibilityFeature;

61 62 63
/// The set of possible actions that can be conveyed to a semantics node.
///
/// Must match the `SemanticsAction` enum in semantics.dart.
64
typedef enum {
65
  /// The equivalent of a user briefly tapping the screen with the finger
66
  /// without moving it.
67
  kFlutterSemanticsActionTap = 1 << 0,
68 69
  /// The equivalent of a user pressing and holding the screen with the finger
  /// for a few seconds without moving it.
70
  kFlutterSemanticsActionLongPress = 1 << 1,
71 72
  /// The equivalent of a user moving their finger across the screen from right
  /// to left.
73
  kFlutterSemanticsActionScrollLeft = 1 << 2,
74 75 76
  /// The equivalent of a user moving their finger across the screen from left
  /// to
  /// right.
77
  kFlutterSemanticsActionScrollRight = 1 << 3,
78 79
  /// The equivalent of a user moving their finger across the screen from bottom
  /// to top.
80
  kFlutterSemanticsActionScrollUp = 1 << 4,
81 82
  /// The equivalent of a user moving their finger across the screen from top to
  /// bottom.
83
  kFlutterSemanticsActionScrollDown = 1 << 5,
84
  /// Increase the value represented by the semantics node.
85
  kFlutterSemanticsActionIncrease = 1 << 6,
86
  /// Decrease the value represented by the semantics node.
87
  kFlutterSemanticsActionDecrease = 1 << 7,
88
  /// A request to fully show the semantics node on screen.
89
  kFlutterSemanticsActionShowOnScreen = 1 << 8,
90
  /// Move the cursor forward by one character.
91
  kFlutterSemanticsActionMoveCursorForwardByCharacter = 1 << 9,
92
  /// Move the cursor backward by one character.
93
  kFlutterSemanticsActionMoveCursorBackwardByCharacter = 1 << 10,
94
  /// Set the text selection to the given range.
95
  kFlutterSemanticsActionSetSelection = 1 << 11,
96
  /// Copy the current selection to the clipboard.
97
  kFlutterSemanticsActionCopy = 1 << 12,
98
  /// Cut the current selection and place it in the clipboard.
99
  kFlutterSemanticsActionCut = 1 << 13,
100
  /// Paste the current content of the clipboard.
101
  kFlutterSemanticsActionPaste = 1 << 14,
102
  /// Indicate that the node has gained accessibility focus.
103
  kFlutterSemanticsActionDidGainAccessibilityFocus = 1 << 15,
104
  /// Indicate that the node has lost accessibility focus.
105
  kFlutterSemanticsActionDidLoseAccessibilityFocus = 1 << 16,
106
  /// Indicate that the user has invoked a custom accessibility action.
107
  kFlutterSemanticsActionCustomAction = 1 << 17,
108
  /// A request that the node should be dismissed.
109
  kFlutterSemanticsActionDismiss = 1 << 18,
110
  /// Move the cursor forward by one word.
111
  kFlutterSemanticsActionMoveCursorForwardByWord = 1 << 19,
112
  /// Move the cursor backward by one word.
113
  kFlutterSemanticsActionMoveCursorBackwardByWord = 1 << 20,
114 115
} FlutterSemanticsAction;

116 117 118
/// The set of properties that may be associated with a semantics node.
///
/// Must match the `SemanticsFlag` enum in semantics.dart.
119
typedef enum {
120 121
  /// The semantics node has the quality of either being "checked" or
  /// "unchecked".
122
  kFlutterSemanticsFlagHasCheckedState = 1 << 0,
123
  /// Whether a semantics node is checked.
124
  kFlutterSemanticsFlagIsChecked = 1 << 1,
125
  /// Whether a semantics node is selected.
126
  kFlutterSemanticsFlagIsSelected = 1 << 2,
127
  /// Whether the semantic node represents a button.
128
  kFlutterSemanticsFlagIsButton = 1 << 3,
129
  /// Whether the semantic node represents a text field.
130
  kFlutterSemanticsFlagIsTextField = 1 << 4,
131
  /// Whether the semantic node currently holds the user's focus.
132
  kFlutterSemanticsFlagIsFocused = 1 << 5,
133 134
  /// The semantics node has the quality of either being "enabled" or
  /// "disabled".
135
  kFlutterSemanticsFlagHasEnabledState = 1 << 6,
136
  /// Whether a semantic node that hasEnabledState is currently enabled.
137
  kFlutterSemanticsFlagIsEnabled = 1 << 7,
138
  /// Whether a semantic node is in a mutually exclusive group.
139
  kFlutterSemanticsFlagIsInMutuallyExclusiveGroup = 1 << 8,
140
  /// Whether a semantic node is a header that divides content into sections.
141
  kFlutterSemanticsFlagIsHeader = 1 << 9,
142
  /// Whether the value of the semantics node is obscured.
143
  kFlutterSemanticsFlagIsObscured = 1 << 10,
144 145
  /// Whether the semantics node is the root of a subtree for which a route name
  /// should be announced.
146
  kFlutterSemanticsFlagScopesRoute = 1 << 11,
147
  /// Whether the semantics node label is the name of a visually distinct route.
148
  kFlutterSemanticsFlagNamesRoute = 1 << 12,
149
  /// Whether the semantics node is considered hidden.
150
  kFlutterSemanticsFlagIsHidden = 1 << 13,
151
  /// Whether the semantics node represents an image.
152
  kFlutterSemanticsFlagIsImage = 1 << 14,
153
  /// Whether the semantics node is a live region.
154
  kFlutterSemanticsFlagIsLiveRegion = 1 << 15,
155
  /// The semantics node has the quality of either being "on" or "off".
156
  kFlutterSemanticsFlagHasToggledState = 1 << 16,
157 158
  /// If true, the semantics node is "on". If false, the semantics node is
  /// "off".
159
  kFlutterSemanticsFlagIsToggled = 1 << 17,
160 161 162 163 164 165 166
  /// 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.
167
  kFlutterSemanticsFlagHasImplicitScrolling = 1 << 18,
168 169 170
  /// Whether the semantic node is read only.
  ///
  /// Only applicable when kFlutterSemanticsFlagIsTextField flag is on.
171
  kFlutterSemanticsFlagIsReadOnly = 1 << 20,
172 173
  /// Whether the semantic node can hold the user's focus.
  kFlutterSemanticsFlagIsFocusable = 1 << 21,
174 175
  /// Whether the semantics node represents a link.
  kFlutterSemanticsFlagIsLink = 1 << 22,
176 177 178
} FlutterSemanticsFlag;

typedef enum {
179
  /// Text has unknown text direction.
180
  kFlutterTextDirectionUnknown = 0,
181
  /// Text is read from right to left.
182
  kFlutterTextDirectionRTL = 1,
183
  /// Text is read from left to right.
184 185 186
  kFlutterTextDirectionLTR = 2,
} FlutterTextDirection;

187
typedef struct _FlutterEngine* FLUTTER_API_SYMBOL(FlutterEngine);
188

189
typedef struct {
190
  /// horizontal scale factor
191
  double scaleX;
192
  /// horizontal skew factor
193
  double skewX;
194
  /// horizontal translation
195
  double transX;
196
  /// vertical skew factor
197
  double skewY;
198
  /// vertical scale factor
199
  double scaleY;
200
  /// vertical translation
201
  double transY;
202
  /// input x-axis perspective factor
203
  double pers0;
204
  /// input y-axis perspective factor
205
  double pers1;
206
  /// perspective scale factor
207 208 209
  double pers2;
} FlutterTransformation;

210 211
typedef void (*VoidCallback)(void* /* user data */);

212
typedef enum {
213 214
  /// Specifies an OpenGL texture target type. Textures are specified using
  /// the FlutterOpenGLTexture struct.
215
  kFlutterOpenGLTargetTypeTexture,
216 217
  /// Specifies an OpenGL frame-buffer target type. Framebuffers are specified
  /// using the FlutterOpenGLFramebuffer struct.
218 219 220
  kFlutterOpenGLTargetTypeFramebuffer,
} FlutterOpenGLTargetType;

221
typedef struct {
222 223
  /// Target texture of the active texture unit (example GL_TEXTURE_2D or
  /// GL_TEXTURE_RECTANGLE).
224
  uint32_t target;
225
  /// The name of the texture.
226
  uint32_t name;
227
  /// The texture format (example GL_RGBA8).
228
  uint32_t format;
229
  /// User data to be returned on the invocation of the destruction callback.
230
  void* user_data;
231 232
  /// Callback invoked (on an engine managed thread) that asks the embedder to
  /// collect the texture.
233
  VoidCallback destruction_callback;
234 235 236 237 238 239 240 241
  /// 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;
242 243
} FlutterOpenGLTexture;

244
typedef struct {
245 246 247
  /// 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.
248 249
  uint32_t target;

250
  /// The name of the framebuffer.
251 252
  uint32_t name;

253
  /// User data to be returned on the invocation of the destruction callback.
254 255
  void* user_data;

256 257
  /// Callback invoked (on an engine managed thread) that asks the embedder to
  /// collect the framebuffer.
258 259 260
  VoidCallback destruction_callback;
} FlutterOpenGLFramebuffer;

261
typedef bool (*BoolCallback)(void* /* user data */);
262
typedef FlutterTransformation (*TransformationCallback)(void* /* user data */);
263
typedef uint32_t (*UIntCallback)(void* /* user data */);
264 265 266 267
typedef bool (*SoftwareSurfacePresentCallback)(void* /* user data */,
                                               const void* /* allocation */,
                                               size_t /* row bytes */,
                                               size_t /* height */);
268
typedef void* (*ProcResolver)(void* /* user data */, const char* /* name */);
269 270 271 272 273
typedef bool (*TextureFrameCallback)(void* /* user data */,
                                     int64_t /* texture identifier */,
                                     size_t /* width */,
                                     size_t /* height */,
                                     FlutterOpenGLTexture* /* texture out */);
274
typedef void (*VsyncCallback)(void* /* user data */, intptr_t /* baton */);
275 276

typedef struct {
277
  /// The size of this struct. Must be sizeof(FlutterOpenGLRendererConfig).
278 279 280 281 282
  size_t struct_size;
  BoolCallback make_current;
  BoolCallback clear_current;
  BoolCallback present;
  UIntCallback fbo_callback;
283 284 285 286 287 288
  /// 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.
289
  BoolCallback make_resource_current;
290 291 292 293
  /// 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.
294
  bool fbo_reset_after_present;
295 296
  /// The transformation to apply to the render target before any rendering
  /// operations. This callback is optional.
297 298 299 300 301 302 303 304
  /// @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).
305
  TransformationCallback surface_transformation;
306
  ProcResolver gl_proc_resolver;
307 308 309 310
  /// 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.
311
  TextureFrameCallback gl_external_texture_frame_callback;
312 313
} FlutterOpenGLRendererConfig;

314
typedef struct {
315
  /// The size of this struct. Must be sizeof(FlutterSoftwareRendererConfig).
316
  size_t struct_size;
317 318 319 320
  /// 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.
321 322 323
  SoftwareSurfacePresentCallback surface_present_callback;
} FlutterSoftwareRendererConfig;

324 325 326 327
typedef struct {
  FlutterRendererType type;
  union {
    FlutterOpenGLRendererConfig open_gl;
328
    FlutterSoftwareRendererConfig software;
329 330 331 332
  };
} FlutterRendererConfig;

typedef struct {
333
  /// The size of this struct. Must be sizeof(FlutterWindowMetricsEvent).
334
  size_t struct_size;
335
  /// Physical width of the window.
336
  size_t width;
337
  /// Physical height of the window.
338
  size_t height;
339
  /// Scale factor for the physical screen.
340 341 342
  double pixel_ratio;
} FlutterWindowMetricsEvent;

343
/// The phase of the pointer event.
344 345
typedef enum {
  kCancel,
346 347 348 349 350 351
  /// 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.
352
  kUp,
353 354 355 356 357 358
  /// 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.
359
  kDown,
360 361 362 363
  /// 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.
364
  kMove,
365 366 367 368
  /// 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.
369
  kAdd,
370 371 372 373
  /// 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.
374
  kRemove,
375
  /// The pointer moved while up.
376
  kHover,
377 378
} FlutterPointerPhase;

379
/// The device type that created a pointer event.
380 381 382 383 384
typedef enum {
  kFlutterPointerDeviceKindMouse = 1,
  kFlutterPointerDeviceKindTouch,
} FlutterPointerDeviceKind;

385 386
/// Flags for the `buttons` field of `FlutterPointerEvent` when `device_kind`
/// is `kFlutterPointerDeviceKindMouse`.
387 388 389 390 391 392
typedef enum {
  kFlutterPointerButtonMousePrimary = 1 << 0,
  kFlutterPointerButtonMouseSecondary = 1 << 1,
  kFlutterPointerButtonMouseMiddle = 1 << 2,
  kFlutterPointerButtonMouseBack = 1 << 3,
  kFlutterPointerButtonMouseForward = 1 << 4,
393 394
  /// If a mouse has more than five buttons, send higher bit shifted values
  /// corresponding to the button number: 1 << 5 for the 6th, etc.
395 396
} FlutterPointerMouseButtons;

397
/// The type of a pointer signal.
398 399 400 401 402
typedef enum {
  kFlutterPointerSignalKindNone,
  kFlutterPointerSignalKindScroll,
} FlutterPointerSignalKind;

403
typedef struct {
404
  /// The size of this struct. Must be sizeof(FlutterPointerEvent).
405 406
  size_t struct_size;
  FlutterPointerPhase phase;
407 408
  /// @attention     The timestamp must be specified in microseconds.
  size_t timestamp;
409 410
  double x;
  double y;
411 412
  /// An optional device identifier. If this is not specified, it is assumed
  /// that the embedder has no multi-touch capability.
413
  int32_t device;
414 415 416
  FlutterPointerSignalKind signal_kind;
  double scroll_delta_x;
  double scroll_delta_y;
417 418 419 420 421
  /// 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.
422
  FlutterPointerDeviceKind device_kind;
423
  /// The buttons currently pressed, if any.
424
  int64_t buttons;
425 426
} FlutterPointerEvent;

427 428 429 430
struct _FlutterPlatformMessageResponseHandle;
typedef struct _FlutterPlatformMessageResponseHandle
    FlutterPlatformMessageResponseHandle;

431
typedef struct {
432
  /// The size of this struct. Must be sizeof(FlutterPlatformMessage).
433 434 435
  size_t struct_size;
  const char* channel;
  const uint8_t* message;
436
  size_t message_size;
437 438 439 440 441 442
  /// 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.
443
  const FlutterPlatformMessageResponseHandle* response_handle;
444 445
} FlutterPlatformMessage;

446 447 448 449
typedef void (*FlutterPlatformMessageCallback)(
    const FlutterPlatformMessage* /* message*/,
    void* /* user data */);

450 451 452 453
typedef void (*FlutterDataCallback)(const uint8_t* /* data */,
                                    size_t /* size */,
                                    void* /* user data */);

454 455 456 457 458 459 460
typedef struct {
  double left;
  double top;
  double right;
  double bottom;
} FlutterRect;

461 462
/// `FlutterSemanticsNode` ID used as a sentinel to signal the end of a batch of
/// semantics node updates.
463
FLUTTER_EXPORT
464
extern const int32_t kFlutterSemanticsNodeIdBatchEnd;
465

466 467 468 469 470 471
/// 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`.
472
typedef struct {
473
  /// The size of this struct. Must be sizeof(FlutterSemanticsNode).
474
  size_t struct_size;
475
  /// The unique identifier for this node.
476
  int32_t id;
477
  /// The set of semantics flags associated with this node.
478
  FlutterSemanticsFlag flags;
479
  /// The set of semantics actions applicable to this node.
480
  FlutterSemanticsAction actions;
481
  /// The position at which the text selection originates.
482
  int32_t text_selection_base;
483
  /// The position at which the text selection terminates.
484
  int32_t text_selection_extent;
485
  /// The total number of scrollable children that contribute to semantics.
486
  int32_t scroll_child_count;
487
  /// The index of the first visible semantic child of a scroll node.
488
  int32_t scroll_index;
489 490
  /// The current scrolling position in logical pixels if the node is
  /// scrollable.
491
  double scroll_position;
492
  /// The maximum in-range value for `scrollPosition` if the node is scrollable.
493
  double scroll_extent_max;
494
  /// The minimum in-range value for `scrollPosition` if the node is scrollable.
495
  double scroll_extent_min;
496 497
  /// The elevation along the z-axis at which the rect of this semantics node is
  /// located above its parent.
498
  double elevation;
499
  /// Describes how much space the semantics node takes up along the z-axis.
500
  double thickness;
501
  /// A textual description of the node.
502
  const char* label;
503
  /// A brief description of the result of performing an action on the node.
504
  const char* hint;
505
  /// A textual description of the current value of the node.
506
  const char* value;
507 508
  /// A value that `value` will have after a kFlutterSemanticsActionIncrease`
  /// action has been performed.
509
  const char* increased_value;
510 511
  /// A value that `value` will have after a kFlutterSemanticsActionDecrease`
  /// action has been performed.
512
  const char* decreased_value;
513 514
  /// The reading direction for `label`, `value`, `hint`, `increasedValue`, and
  /// `decreasedValue`.
515
  FlutterTextDirection text_direction;
516
  /// The bounding box for this node in its coordinate system.
517
  FlutterRect rect;
518 519
  /// The transform from this node's coordinate system to its parent's
  /// coordinate system.
520
  FlutterTransformation transform;
521
  /// The number of children this node has.
522
  size_t child_count;
523
  /// Array of child node IDs in traversal order. Has length `child_count`.
524
  const int32_t* children_in_traversal_order;
525
  /// Array of child node IDs in hit test order. Has length `child_count`.
526
  const int32_t* children_in_hit_test_order;
527
  /// The number of custom accessibility action associated with this node.
528
  size_t custom_accessibility_actions_count;
529 530
  /// Array of `FlutterSemanticsCustomAction` IDs associated with this node.
  /// Has length `custom_accessibility_actions_count`.
531 532 533
  const int32_t* custom_accessibility_actions;
} FlutterSemanticsNode;

534 535
/// `FlutterSemanticsCustomAction` ID used as a sentinel to signal the end of a
/// batch of semantics custom action updates.
536
FLUTTER_EXPORT
537
extern const int32_t kFlutterSemanticsCustomActionIdBatchEnd;
538

539 540 541 542 543 544 545 546 547
/// 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.
548
typedef struct {
549
  /// The size of the struct. Must be sizeof(FlutterSemanticsCustomAction).
550
  size_t struct_size;
551
  /// The unique custom action or action override ID.
552
  int32_t id;
553 554
  /// For overridden standard actions, corresponds to the
  /// `FlutterSemanticsAction` to override.
555
  FlutterSemanticsAction override_action;
556
  /// The user-readable name of this custom semantics action.
557
  const char* label;
558
  /// The hint description of this custom semantics action.
559 560 561 562 563 564 565 566 567 568 569
  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 */);

570 571 572 573 574 575 576 577 578 579 580 581
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 */);

582 583 584 585
/// 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.
586
typedef struct {
587
  /// The size of this struct. Must be sizeof(FlutterTaskRunnerDescription).
588 589
  size_t struct_size;
  void* user_data;
590 591 592 593
  /// 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.
594
  BoolCallback runs_task_on_current_thread_callback;
595 596 597 598 599 600 601 602 603 604
  /// 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.
605
  FlutterTaskRunnerPostTaskCallback post_task_callback;
606 607 608
  /// A unique identifier for the task runner. If multiple task runners service
  /// tasks on the same thread, their identifiers must match.
  size_t identifier;
609 610 611
} FlutterTaskRunnerDescription;

typedef struct {
612
  /// The size of this struct. Must be sizeof(FlutterCustomTaskRunners).
613
  size_t struct_size;
614
  /// Specify the task runner for the thread on which the `FlutterEngineRun`
615 616 617
  /// 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.
618
  const FlutterTaskRunnerDescription* platform_task_runner;
619 620 621 622 623
  /// 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;
624 625
} FlutterCustomTaskRunners;

626
typedef struct {
627 628
  /// The type of the OpenGL backing store. Currently, it can either be a
  /// texture or a framebuffer.
629 630
  FlutterOpenGLTargetType type;
  union {
631
    /// A texture for Flutter to render into.
632
    FlutterOpenGLTexture texture;
633 634
    /// A framebuffer for Flutter to render into. The embedder must ensure that
    /// the framebuffer is complete.
635 636 637 638 639
    FlutterOpenGLFramebuffer framebuffer;
  };
} FlutterOpenGLBackingStore;

typedef struct {
640 641
  /// A pointer to the raw bytes of the allocation described by this software
  /// backing store.
642
  const void* allocation;
643
  /// The number of bytes in a single row of the allocation.
644
  size_t row_bytes;
645
  /// The number of rows in the allocation.
646
  size_t height;
647 648 649
  /// 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.
650
  void* user_data;
651 652
  /// The callback invoked by the engine when it no longer needs this backing
  /// store.
653 654 655
  VoidCallback destruction_callback;
} FlutterSoftwareBackingStore;

656 657 658
/// 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.
659 660 661
typedef int64_t FlutterPlatformViewIdentifier;

typedef struct {
662
  /// The size of this struct. Must be sizeof(FlutterPlatformView).
663
  size_t struct_size;
664 665 666
  /// 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.
667 668 669 670
  FlutterPlatformViewIdentifier identifier;
} FlutterPlatformView;

typedef enum {
671 672
  /// Specifies an OpenGL backing store. Can either be an OpenGL texture or
  /// framebuffer.
673
  kFlutterBackingStoreTypeOpenGL,
674
  /// Specified an software allocation for Flutter to render into using the CPU.
675 676 677 678
  kFlutterBackingStoreTypeSoftware,
} FlutterBackingStoreType;

typedef struct {
679
  /// The size of this struct. Must be sizeof(FlutterBackingStore).
680
  size_t struct_size;
681 682 683
  /// 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`.
684
  void* user_data;
685
  /// Specifies the type of backing store.
686
  FlutterBackingStoreType type;
687 688
  /// Indicates if this backing store was updated since the last time it was
  /// associated with a presented layer.
689 690
  bool did_update;
  union {
691
    /// The description of the OpenGL backing store.
692
    FlutterOpenGLBackingStore open_gl;
693
    /// The description of the software backing store.
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
    FlutterSoftwareBackingStore software;
  };
} FlutterBackingStore;

typedef struct {
  double x;
  double y;
} FlutterPoint;

typedef struct {
  double width;
  double height;
} FlutterSize;

typedef struct {
709
  /// The size of this struct. Must be sizeof(FlutterBackingStoreConfig).
710
  size_t struct_size;
711
  /// The size of the render target the engine expects to render into.
712 713 714 715
  FlutterSize size;
} FlutterBackingStoreConfig;

typedef enum {
716 717
  /// Indicates that the contents of this layer are rendered by Flutter into a
  /// backing store.
718
  kFlutterLayerContentTypeBackingStore,
719
  /// Indicates that the contents of this layer are determined by the embedder.
720 721 722 723
  kFlutterLayerContentTypePlatformView,
} FlutterLayerContentType;

typedef struct {
724
  /// This size of this struct. Must be sizeof(FlutterLayer).
725
  size_t struct_size;
726 727
  /// Each layer displays contents in one way or another. The type indicates
  /// whether those contents are specified by Flutter or the embedder.
728 729
  FlutterLayerContentType type;
  union {
730 731
    /// Indicates that the contents of this layer are rendered by Flutter into a
    /// backing store.
732
    const FlutterBackingStore* backing_store;
733 734
    /// Indicates that the contents of this layer are determined by the
    /// embedder.
735 736
    const FlutterPlatformView* platform_view;
  };
737 738
  /// The offset of this layer (in physical pixels) relative to the top left of
  /// the root surface used by the engine.
739
  FlutterPoint offset;
740
  /// The size of the layer (in physical pixels).
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757
  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 {
758
  /// This size of this struct. Must be sizeof(FlutterCompositor).
759
  size_t struct_size;
760 761 762 763
  /// 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`
764
  void* user_data;
765 766 767 768 769 770 771
  /// 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.
772
  FlutterBackingStoreCreateCallback create_backing_store_callback;
773 774
  /// A callback invoked by the engine to release the backing store. The
  /// embedder may collect any resources associated with the backing store.
775
  FlutterBackingStoreCollectCallback collect_backing_store_callback;
776 777
  /// Callback invoked by the engine to composite the contents of each layer
  /// onto the screen.
778 779 780
  FlutterLayersPresentCallback present_layers_callback;
} FlutterCompositor;

781
typedef struct {
782
  /// The size of this struct. Must be sizeof(FlutterProjectArgs).
783
  size_t struct_size;
784 785 786
  /// 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.
787
  const char* assets_path;
788 789 790 791 792 793 794 795 796
  /// 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.
797
  const char* main_path__unused__;
798 799 800 801 802 803 804 805 806
  /// 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.
807
  const char* packages_path__unused__;
808 809 810
  /// 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.
811
  const char* icu_data_path;
812
  /// The command line argument count used to initialize the project.
813
  int command_line_argc;
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828
  /// 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.
829
  const char* const* command_line_argv;
830 831 832 833
  /// 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.
834
  FlutterPlatformMessageCallback platform_message_callback;
835 836 837 838
  /// 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
839
  const uint8_t* vm_snapshot_data;
840 841
  /// The size of the VM snapshot data buffer.  If vm_snapshot_data is a symbol
  /// reference, 0 may be passed here.
842
  size_t vm_snapshot_data_size;
843 844 845 846
  /// 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
847
  const uint8_t* vm_snapshot_instructions;
848 849
  /// The size of the VM snapshot instructions buffer. If
  /// vm_snapshot_instructions is a symbol reference, 0 may be passed here.
850
  size_t vm_snapshot_instructions_size;
851 852 853 854
  /// 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
855
  const uint8_t* isolate_snapshot_data;
856 857
  /// The size of the isolate snapshot data buffer.  If isolate_snapshot_data is
  /// a symbol reference, 0 may be passed here.
858
  size_t isolate_snapshot_data_size;
859 860 861 862
  /// 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
863
  const uint8_t* isolate_snapshot_instructions;
864 865
  /// The size of the isolate snapshot instructions buffer. If
  /// isolate_snapshot_instructions is a symbol reference, 0 may be passed here.
866
  size_t isolate_snapshot_instructions_size;
867 868
  /// The callback invoked by the engine in root isolate scope. Called
  /// immediately after the root isolate has been created and marked runnable.
869
  VoidCallback root_isolate_create_callback;
870 871 872 873 874 875 876 877
  /// 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.
878
  FlutterUpdateSemanticsNodeCallback update_semantics_node_callback;
879 880 881 882 883 884 885 886 887
  /// 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.
888 889
  FlutterUpdateSemanticsCustomActionCallback
      update_semantics_custom_action_callback;
890 891 892 893
  /// 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.
  ///
894
  // This is different from the cache-path-dir argument defined in switches.h,
895
  // which is used in `flutter::Settings` as `temp_directory_path`.
896
  const char* persistent_cache_path;
897

L
liyuqian 已提交
898 899
  /// If true, the engine would only read the existing cache, but not write new
  /// ones.
900 901
  bool is_persistent_cache_read_only;

902 903 904 905 906 907 908 909 910
  /// 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.
911
  VsyncCallback vsync_callback;
912

913 914 915 916 917 918 919
  /// 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.
920
  const char* custom_dart_entrypoint;
921

922 923 924
  /// 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.
925
  const FlutterCustomTaskRunners* custom_task_runners;
926

927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943
  /// 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.
944
  bool shutdown_dart_vm_when_done;
945

946 947 948 949 950 951 952 953 954 955 956 957 958 959
  /// 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.
960
  const FlutterCompositor* compositor;
961 962
} FlutterProjectArgs;

963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988
//------------------------------------------------------------------------------
/// @brief      Initialize and run a Flutter engine instance and return a handle
///             to it. This is a convenience method for the the pair of calls to
///             `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.
///
989
FLUTTER_EXPORT
990 991 992 993
FlutterEngineResult FlutterEngineRun(size_t version,
                                     const FlutterRendererConfig* config,
                                     const FlutterProjectArgs* args,
                                     void* user_data,
994 995
                                     FLUTTER_API_SYMBOL(FlutterEngine) *
                                         engine_out);
996

997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008
//------------------------------------------------------------------------------
/// @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.
///
1009
FLUTTER_EXPORT
1010 1011
FlutterEngineResult FlutterEngineShutdown(FLUTTER_API_SYMBOL(FlutterEngine)
                                              engine);
1012

1013 1014 1015 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
//------------------------------------------------------------------------------
/// @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);

1072
FLUTTER_EXPORT
1073
FlutterEngineResult FlutterEngineSendWindowMetricsEvent(
1074
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1075 1076 1077
    const FlutterWindowMetricsEvent* event);

FLUTTER_EXPORT
1078
FlutterEngineResult FlutterEngineSendPointerEvent(
1079
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1080 1081
    const FlutterPointerEvent* events,
    size_t events_count);
1082

1083
FLUTTER_EXPORT
1084
FlutterEngineResult FlutterEngineSendPlatformMessage(
1085
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1086 1087
    const FlutterPlatformMessage* message);

1088 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 1114 1115 1116
//------------------------------------------------------------------------------
/// @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.
///
1117 1118
FLUTTER_EXPORT
FlutterEngineResult FlutterPlatformMessageCreateResponseHandle(
1119
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1120 1121 1122 1123
    FlutterDataCallback data_callback,
    void* user_data,
    FlutterPlatformMessageResponseHandle** response_out);

1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136
//------------------------------------------------------------------------------
/// @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.
///
1137 1138
FLUTTER_EXPORT
FlutterEngineResult FlutterPlatformMessageReleaseResponseHandle(
1139
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1140 1141
    FlutterPlatformMessageResponseHandle* response);

1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
//------------------------------------------------------------------------------
/// @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.
///
1154
FLUTTER_EXPORT
1155
FlutterEngineResult FlutterEngineSendPlatformMessageResponse(
1156
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1157 1158 1159 1160
    const FlutterPlatformMessageResponseHandle* handle,
    const uint8_t* data,
    size_t data_length);

1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173
//------------------------------------------------------------------------------
/// @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.
///
1174
FLUTTER_EXPORT
1175
FlutterEngineResult __FlutterEngineFlushPendingTasksNow();
1176

1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195
//------------------------------------------------------------------------------
/// @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.
///
1196
FLUTTER_EXPORT
1197
FlutterEngineResult FlutterEngineRegisterExternalTexture(
1198
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1199
    int64_t texture_identifier);
1200

1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212
//------------------------------------------------------------------------------
/// @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.
///
1213
FLUTTER_EXPORT
1214
FlutterEngineResult FlutterEngineUnregisterExternalTexture(
1215
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1216 1217
    int64_t texture_identifier);

1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230
//------------------------------------------------------------------------------
/// @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.
///
1231
FLUTTER_EXPORT
1232
FlutterEngineResult FlutterEngineMarkExternalTextureFrameAvailable(
1233
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1234 1235
    int64_t texture_identifier);

1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247
//------------------------------------------------------------------------------
/// @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.
///
1248
FLUTTER_EXPORT
1249 1250 1251
FlutterEngineResult FlutterEngineUpdateSemanticsEnabled(
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
    bool enabled);
1252

1253 1254 1255 1256 1257 1258 1259 1260
//------------------------------------------------------------------------------
/// @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.
///
1261 1262
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineUpdateAccessibilityFeatures(
1263
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1264 1265
    FlutterAccessibilityFeature features);

1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276
//------------------------------------------------------------------------------
/// @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.
///
1277 1278
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineDispatchSemanticsAction(
1279
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
1280 1281 1282 1283 1284
    uint64_t id,
    FlutterSemanticsAction action,
    const uint8_t* data,
    size_t data_length);

1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315
//------------------------------------------------------------------------------
/// @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.
///
1316
FLUTTER_EXPORT
1317 1318
FlutterEngineResult FlutterEngineOnVsync(FLUTTER_API_SYMBOL(FlutterEngine)
                                             engine,
1319 1320 1321 1322
                                         intptr_t baton,
                                         uint64_t frame_start_time_nanos,
                                         uint64_t frame_target_time_nanos);

1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333
//------------------------------------------------------------------------------
/// @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);

1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344
//------------------------------------------------------------------------------
/// @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.
///
1345 1346 1347
FLUTTER_EXPORT
void FlutterEngineTraceEventDurationBegin(const char* name);

1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358
//-----------------------------------------------------------------------------
/// @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.
///
1359 1360 1361
FLUTTER_EXPORT
void FlutterEngineTraceEventDurationEnd(const char* name);

1362 1363 1364 1365 1366 1367 1368 1369 1370
//-----------------------------------------------------------------------------
/// @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.
///
1371 1372 1373
FLUTTER_EXPORT
void FlutterEngineTraceEventInstant(const char* name);

1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384
//------------------------------------------------------------------------------
/// @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.
///
1385
FLUTTER_EXPORT
1386 1387 1388 1389
FlutterEngineResult FlutterEnginePostRenderThreadTask(
    FLUTTER_API_SYMBOL(FlutterEngine) engine,
    VoidCallback callback,
    void* callback_data);
1390

1391 1392 1393 1394 1395 1396
//------------------------------------------------------------------------------
/// @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.
///
1397 1398 1399
FLUTTER_EXPORT
uint64_t FlutterEngineGetCurrentTime();

1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411
//------------------------------------------------------------------------------
/// @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.
///
/// @param[in]  engine     a running instance.
/// @param[in]  task       the task handle.
///
/// @return     The result of the call.
///
1412
FLUTTER_EXPORT
1413 1414
FlutterEngineResult FlutterEngineRunTask(FLUTTER_API_SYMBOL(FlutterEngine)
                                             engine,
1415 1416
                                         const FlutterTask* task);

1417 1418 1419 1420 1421
#if defined(__cplusplus)
}  // extern "C"
#endif

#endif  // FLUTTER_EMBEDDER_H_