Flutter Engine
fl_engine_private.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_SHELL_PLATFORM_LINUX_FL_ENGINE_PRIVATE_H_
6 #define FLUTTER_SHELL_PLATFORM_LINUX_FL_ENGINE_PRIVATE_H_
7 
8 #include <glib-object.h>
9 
10 #include "flutter/shell/platform/embedder/embedder.h"
11 #include "flutter/shell/platform/linux/fl_renderer.h"
12 #include "flutter/shell/platform/linux/public/flutter_linux/fl_dart_project.h"
13 #include "flutter/shell/platform/linux/public/flutter_linux/fl_engine.h"
14 
15 G_BEGIN_DECLS
16 
17 /**
18  * FlEngineError:
19  * Errors for #FlEngine objects to set on failures.
20  */
21 
22 typedef enum {
25 
26 GQuark fl_engine_error_quark(void) G_GNUC_CONST;
27 
28 /**
29  * FlEnginePlatformMessageHandler:
30  * @engine: an #FlEngine.
31  * @channel: channel message received on.
32  * @message: message content received from Dart.
33  * @response_handle: a handle to respond to the message with.
34  * @user_data: (closure): data provided when registering this handler.
35  *
36  * Function called when platform messages are received.
37  *
38  * Returns: %TRUE if message has been accepted.
39  */
40 typedef gboolean (*FlEnginePlatformMessageHandler)(
41  FlEngine* engine,
42  const gchar* channel,
43  GBytes* message,
44  const FlutterPlatformMessageResponseHandle* response_handle,
45  gpointer user_data);
46 
47 /**
48  * fl_engine_new:
49  * @project: an #FlDartProject.
50  * @renderer: an #FlRenderer.
51  *
52  * Creates new Flutter engine.
53  *
54  * Returns: a new #FlEngine.
55  */
56 FlEngine* fl_engine_new(FlDartProject* project, FlRenderer* renderer);
57 
58 /**
59  * fl_engine_set_platform_message_handler:
60  * @engine: an #FlEngine.
61  * @handler: function to call when a platform message is received.
62  * @user_data: (closure): user data to pass to @handler.
63  * @destroy_notify: (allow-none): a function which gets called to free
64  * @user_data, or %NULL.
65  *
66  * Registers the function called when a platform message is reveived. Call
67  * fl_engine_send_platform_message_response() with the response to this message.
68  * Ownership of #FlutterPlatformMessageResponseHandle is
69  * transferred to the caller, and the message must be responded to to avoid
70  * memory leaks.
71  */
73  FlEngine* engine,
75  gpointer user_data,
76  GDestroyNotify destroy_notify);
77 
78 /**
79  * fl_engine_start:
80  * @engine: an #FlEngine.
81  * @error: (allow-none): #GError location to store the error occurring, or %NULL
82  * to ignore.
83  *
84  * Starts the Flutter engine.
85  *
86  * Returns: %TRUE on success.
87  */
88 gboolean fl_engine_start(FlEngine* engine, GError** error);
89 
90 /**
91  * fl_engine_send_window_metrics_event:
92  * @engine: an #FlEngine.
93  * @width: width of the window in pixels.
94  * @height: height of the window in pixels.
95  * @pixel_ratio: scale factor for window.
96  *
97  * Sends a window metrics event to the engine.
98  */
100  size_t width,
101  size_t height,
102  double pixel_ratio);
103 
104 /**
105  * fl_engine_send_mouse_pointer_event:
106  * @engine: an #FlEngine.
107  * @phase: mouse phase.
108  * @timestamp: time when event occurred in microseconds.
109  * @x: x location of mouse cursor.
110  * @y: y location of mouse cursor.
111  * @scroll_delta_x: x offset of scroll.
112  * @scroll_delta_y: y offset of scroll.
113  * @buttons: buttons that are pressed.
114  *
115  * Sends a mouse pointer event to the engine.
116  */
119  size_t timestamp,
120  double x,
121  double y,
122  double scroll_delta_x,
123  double scroll_delta_y,
124  int64_t buttons);
125 
126 /**
127  * fl_engine_send_platform_message_response:
128  * @engine: an #FlEngine.
129  * @handle: handle that was provided in #FlEnginePlatformMessageHandler.
130  * @response: (allow-none): response to send or %NULL for an empty response.
131  * @error: (allow-none): #GError location to store the error occurring, or %NULL
132  * to ignore.
133  *
134  * Responds to a platform message.
135  *
136  * Returns: %TRUE on success.
137  */
139  FlEngine* engine,
141  GBytes* response,
142  GError** error);
143 
144 /**
145  * fl_engine_send_platform_message:
146  * @engine: an #FlEngine.
147  * @channel: channel to send to.
148  * @message: (allow-none): message buffer to send or %NULL for an empty message
149  * @cancellable: (allow-none): a #GCancellable or %NULL.
150  * @callback: (scope async): a #GAsyncReadyCallback to call when the request is
151  * satisfied.
152  * @user_data: (closure): user data to pass to @callback.
153  *
154  * Asynchronously sends a platform message.
155  */
157  const gchar* channel,
158  GBytes* message,
159  GCancellable* cancellable,
160  GAsyncReadyCallback callback,
161  gpointer user_data);
162 
163 /**
164  * fl_engine_send_platform_message_finish:
165  * @engine: an #FlEngine.
166  * @result: a #GAsyncResult.
167  * @error: (allow-none): #GError location to store the error occurring, or %NULL
168  * to ignore.
169  *
170  * Completes request started with fl_engine_send_platform_message().
171  *
172  * Returns: message response on success or %NULL on error.
173  */
175  GAsyncResult* result,
176  GError** error);
177 
178 G_END_DECLS
179 
180 #endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_ENGINE_PRIVATE_H_
GBytes * fl_engine_send_platform_message_finish(FlEngine *engine, GAsyncResult *result, GError **error)
Definition: fl_engine.cc:540
gboolean(* FlEnginePlatformMessageHandler)(FlEngine *engine, const gchar *channel, GBytes *message, const FlutterPlatformMessageResponseHandle *response_handle, gpointer user_data)
void fl_engine_send_window_metrics_event(FlEngine *engine, size_t width, size_t height, double pixel_ratio)
Definition: fl_engine.cc:549
void fl_engine_send_platform_message(FlEngine *engine, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_engine.cc:483
gboolean fl_engine_start(FlEngine *engine, GError **error)
Definition: fl_engine.cc:352
FlMethodResponse GError ** error
FlutterPointerPhase
The phase of the pointer event.
Definition: embedder.h:471
gboolean fl_engine_send_platform_message_response(FlEngine *engine, const FlutterPlatformMessageResponseHandle *handle, GBytes *response, GError **error)
Definition: fl_engine.cc:451
G_BEGIN_DECLS FlValue gpointer user_data
FlutterPointerPhase phase
Definition: fl_view.cc:78
int32_t height
int32_t width
void fl_engine_set_platform_message_handler(FlEngine *engine, FlEnginePlatformMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
Definition: fl_engine.cc:433
FlEngineError
FlEngine * fl_engine_new(FlDartProject *project, FlRenderer *renderer)
Definition: fl_engine.cc:337
void fl_engine_send_mouse_pointer_event(FlEngine *engine, FlutterPointerPhase phase, size_t timestamp, double x, double y, double scroll_delta_x, double scroll_delta_y, int64_t buttons)
Definition: fl_engine.cc:567
GQuark fl_engine_error_quark(void) G_GNUC_CONST