| Flutter Linux Embedder |

fl_renderer.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_RENDERER_H_
6 #define FLUTTER_SHELL_PLATFORM_LINUX_FL_RENDERER_H_
7
8 #include <gtk/gtk.h>
9
10 #include "flutter/shell/platform/linux/public/flutter_linux/fl_dart_project.h"
11 #include "flutter/shell/platform/linux/public/flutter_linux/fl_view.h"
12
13 #include "flutter/shell/platform/embedder/embedder.h"
14
15 G_BEGIN_DECLS
16
17 /**
18 * FlRendererError:
19 * Errors for #FlRenderer objects to set on failures.
20 */
21
22 typedef enum {
23 // NOLINTBEGIN(readability-identifier-naming)
24 FL_RENDERER_ERROR_FAILED,
25 // NOLINTEND(readability-identifier-naming)
26 } FlRendererError;
27
28 GQuark fl_renderer_error_quark(void) G_GNUC_CONST;
29
30 G_DECLARE_DERIVABLE_TYPE(FlRenderer, fl_renderer, FL, RENDERER, GObject)
31
32 /**
33 * FlRenderer:
34 *
35 * #FlRenderer is an abstract class that allows Flutter to draw pixels.
36 */
37
38 struct _FlRendererClass {
39 GObjectClass parent_class;
40
41 /**
42 * Virtual method called when Flutter needs to make the OpenGL context
43 * current.
44 * @renderer: an #FlRenderer.
45 */
46 void (*make_current)(FlRenderer* renderer);
47
48 /**
49 * Virtual method called when Flutter needs to make the OpenGL resource
50 * context current.
51 * @renderer: an #FlRenderer.
52 */
53 void (*make_resource_current)(FlRenderer* renderer);
54
55 /**
56 * Virtual method called when Flutter needs to clear the OpenGL context.
57 * @renderer: an #FlRenderer.
58 */
59 void (*clear_current)(FlRenderer* renderer);
60
61 /**
62 * Virtual method called when Flutter wants to get the refresh rate of the
63 * renderer.
64 * @renderer: an #FlRenderer.
65 *
66 * Returns: The refresh rate of the display in Hz. If the refresh rate is
67 * not available, returns -1.0.
68 */
69 gdouble (*get_refresh_rate)(FlRenderer* renderer);
70 };
71
72 /**
73 * fl_renderer_set_engine:
74 * @renderer: an #FlRenderer.
75 * @engine: an #FlEngine.
76 *
77 * Called when the renderer is connected to an engine.
78 */
79 void fl_renderer_set_engine(FlRenderer* renderer, FlEngine* engine);
80
81 /**
82 * fl_renderer_add_view:
83 * @renderer: an #FlRenderer.
84 * @view_id: the ID of the view.
85 * @view: the view Flutter is renderering to.
86 *
87 * Add a view to render on.
88 */
89 void fl_renderer_add_view(FlRenderer* renderer,
90 FlutterViewId view_id,
91 FlView* view);
92
93 /**
94 * fl_renderer_remove_view:
95 * @renderer: an #FlRenderer.
96 * @view_id: the ID of the view.
97 *
98 * Remove a view from the renderer.
99 */
100 void fl_renderer_remove_view(FlRenderer* renderer, FlutterViewId view_id);
101
102 /**
103 * fl_renderer_get_proc_address:
104 * @renderer: an #FlRenderer.
105 * @name: a function name.
106 *
107 * Gets the rendering API function that matches the given name.
108 *
109 * Returns: a function pointer.
110 */
111 void* fl_renderer_get_proc_address(FlRenderer* renderer, const char* name);
112
113 /**
114 * fl_renderer_make_current:
115 * @renderer: an #FlRenderer.
116 *
117 * Makes the rendering context current.
118 */
119 void fl_renderer_make_current(FlRenderer* renderer);
120
121 /**
122 * fl_renderer_make_resource_current:
123 * @renderer: an #FlRenderer.
124 *
125 * Makes the resource rendering context current.
126 */
127 void fl_renderer_make_resource_current(FlRenderer* renderer);
128
129 /**
130 * fl_renderer_clear_current:
131 * @renderer: an #FlRenderer.
132 *
133 * Clears the current rendering context.
134 */
135 void fl_renderer_clear_current(FlRenderer* renderer);
136
137 /**
138 * fl_renderer_get_fbo:
139 * @renderer: an #FlRenderer.
140 *
141 * Gets the frame buffer object to render to.
142 *
143 * Returns: a frame buffer object index.
144 */
145 guint32 fl_renderer_get_fbo(FlRenderer* renderer);
146
147 /**
148 * fl_renderer_create_backing_store:
149 * @renderer: an #FlRenderer.
150 * @config: backing store config.
151 * @backing_store_out: saves created backing store.
152 *
153 * Obtain a backing store for a specific #FlutterLayer.
154 *
155 * Returns %TRUE if successful.
156 */
157 gboolean fl_renderer_create_backing_store(
158 FlRenderer* renderer,
159 const FlutterBackingStoreConfig* config,
160 FlutterBackingStore* backing_store_out);
161
162 /**
163 * fl_renderer_collect_backing_store:
164 * @renderer: an #FlRenderer.
165 * @backing_store: backing store to be released.
166 *
167 * A callback invoked by the engine to release the backing store. The
168 * embedder may collect any resources associated with the backing store.
169 *
170 * Returns %TRUE if successful.
171 */
172 gboolean fl_renderer_collect_backing_store(
173 FlRenderer* renderer,
174 const FlutterBackingStore* backing_store);
175
176 /**
177 * fl_renderer_present_layers:
178 * @renderer: an #FlRenderer.
179 * @view_id: view to present.
180 * @layers: layers to be composited.
181 * @layers_count: number of layers.
182 *
183 * Callback invoked by the engine to composite the contents of each layer
184 * onto the screen.
185 *
186 * Returns %TRUE if successful.
187 */
188 gboolean fl_renderer_present_layers(FlRenderer* renderer,
189 FlutterViewId view_id,
190 const FlutterLayer** layers,
191 size_t layers_count);
192
193 /**
194 * fl_renderer_wait_for_frame:
195 * @renderer: an #FlRenderer.
196 * @target_width: width of frame being waited for
197 * @target_height: height of frame being waited for
198 *
199 * Holds the thread until frame with requested dimensions is presented.
200 * While waiting for frame Flutter platform and raster tasks are being
201 * processed.
202 */
203 void fl_renderer_wait_for_frame(FlRenderer* renderer,
204 int target_width,
205 int target_height);
206
207 /**
208 * fl_renderer_setup:
209 * @renderer: an #FlRenderer.
210 *
211 * Creates OpenGL resources required before rendering. Requires an active OpenGL
212 * context.
213 */
214 void fl_renderer_setup(FlRenderer* renderer);
215
216 /**
217 * fl_renderer_render:
218 * @renderer: an #FlRenderer.
219 * @view_id: view to render.
220 * @width: width of the window in pixels.
221 * @height: height of the window in pixels.
222 * @background_color: color to use for background.
223 *
224 * Performs OpenGL commands to render current Flutter view.
225 */
226 void fl_renderer_render(FlRenderer* renderer,
227 FlutterViewId view_id,
228 int width,
229 int height,
230 const GdkRGBA* background_color);
231
232 /**
233 * fl_renderer_cleanup:
234 *
235 * Removes OpenGL resources used for rendering. Requires an active OpenGL
236 * context.
237 */
238 void fl_renderer_cleanup(FlRenderer* renderer);
239
240 /**
241 * fl_renderer_get_refresh_rate:
242 * @renderer: an #FlRenderer.
243 *
244 * Returns: The refresh rate of the display in Hz. If the refresh rate is
245 * not available, returns -1.0.
246 */
247 gdouble fl_renderer_get_refresh_rate(FlRenderer* renderer);
248
249 G_END_DECLS
250
251 #endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_RENDERER_H_
G_DECLARE_DERIVABLE_TYPE
G_DECLARE_DERIVABLE_TYPE(FlAccessibleNode, fl_accessible_node, FL, ACCESSIBLE_NODE, AtkObject)
FL_RENDERER_ERROR_FAILED
@ FL_RENDERER_ERROR_FAILED
Definition: fl_renderer.h:24
fl_renderer_error_quark
GQuark fl_renderer_error_quark(void) G_GNUC_CONST
fl_renderer_get_fbo
guint32 fl_renderer_get_fbo(FlRenderer *renderer)
Definition: fl_renderer.cc:360
fl_renderer_remove_view
void fl_renderer_remove_view(FlRenderer *renderer, FlutterViewId view_id)
Definition: fl_renderer.cc:325
fl_renderer_add_view
void fl_renderer_add_view(FlRenderer *renderer, FlutterViewId view_id, FlView *view)
Definition: fl_renderer.cc:314
fl_renderer_create_backing_store
gboolean fl_renderer_create_backing_store(FlRenderer *renderer, const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
Definition: fl_renderer.cc:367
fl_renderer_cleanup
void fl_renderer_cleanup(FlRenderer *renderer)
Definition: fl_renderer.cc:528
fl_dart_project.h
fl_renderer_wait_for_frame
void fl_renderer_wait_for_frame(FlRenderer *renderer, int target_width, int target_height)
Definition: fl_renderer.cc:409
_FlRendererClass
Definition: fl_renderer.h:38
fl_renderer_set_engine
void fl_renderer_set_engine(FlRenderer *renderer, FlEngine *engine)
Definition: fl_renderer.cc:305
FL
FL
Definition: fl_binary_messenger.cc:27
fl_renderer_render
void fl_renderer_render(FlRenderer *renderer, FlutterViewId view_id, int width, int height, const GdkRGBA *background_color)
Definition: fl_renderer.cc:501
_FlRendererClass::parent_class
GObjectClass parent_class
Definition: fl_renderer.h:39
fl_renderer_clear_current
void fl_renderer_clear_current(FlRenderer *renderer)
Definition: fl_renderer.cc:350
fl_view.h
fl_renderer_setup
void fl_renderer_setup(FlRenderer *renderer)
Definition: fl_renderer.cc:484
height
const uint8_t uint32_t uint32_t * height
Definition: fl_pixel_buffer_texture_test.cc:39
fl_renderer_present_layers
gboolean fl_renderer_present_layers(FlRenderer *renderer, FlutterViewId view_id, const FlutterLayer **layers, size_t layers_count)
Definition: fl_renderer.cc:429
view
FlView * view
Definition: fl_application.cc:35
FlRendererError
FlRendererError
Definition: fl_renderer.h:22
fl_renderer_make_resource_current
void fl_renderer_make_resource_current(FlRenderer *renderer)
Definition: fl_renderer.cc:345
fl_renderer_get_refresh_rate
gdouble fl_renderer_get_refresh_rate(FlRenderer *renderer)
Definition: fl_renderer.cc:355
width
const uint8_t uint32_t * width
Definition: fl_pixel_buffer_texture_test.cc:38
fl_renderer_collect_backing_store
gboolean fl_renderer_collect_backing_store(FlRenderer *renderer, const FlutterBackingStore *backing_store)
Definition: fl_renderer.cc:399
fl_renderer_get_proc_address
void * fl_renderer_get_proc_address(FlRenderer *renderer, const char *name)
Definition: fl_renderer.cc:334
fl_renderer_make_current
void fl_renderer_make_current(FlRenderer *renderer)
Definition: fl_renderer.cc:340