| Flutter Linux Embedder |

Classes | Enumerations | Functions
fl_renderer.h File Reference
`#include <gtk/gtk.h>`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_dart_project.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_view.h"`
`#include "flutter/shell/platform/embedder/embedder.h"`

Go to the source code of this file.

## Classes
struct | _FlRendererClass

## Enumerations
enum | FlRendererError { FL_RENDERER_ERROR_FAILED }

## Functions
GQuark | fl_renderer_error_quark (void) G_GNUC_CONST
void | fl_renderer_set_engine (FlRenderer *renderer, FlEngine *engine)
void | fl_renderer_add_view (FlRenderer *renderer, FlutterViewId view_id, FlView *view)
void | fl_renderer_remove_view (FlRenderer *renderer, FlutterViewId view_id)
: a function name.
fl_renderer_get_proc_address: @renderer: an #FlRenderer. Gets the rendering API function that matches the given name. Returns: a function pointer.
void * | fl_renderer_get_proc_address (FlRenderer *renderer, const char *name)
void | fl_renderer_make_current (FlRenderer *renderer)
void | fl_renderer_make_resource_current (FlRenderer *renderer)
void | fl_renderer_clear_current (FlRenderer *renderer)
guint32 | fl_renderer_get_fbo (FlRenderer *renderer)
gboolean | fl_renderer_create_backing_store (FlRenderer *renderer, const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
gboolean | fl_renderer_collect_backing_store (FlRenderer *renderer, const FlutterBackingStore *backing_store)
gboolean | fl_renderer_present_layers (FlRenderer *renderer, FlutterViewId view_id, const FlutterLayer **layers, size_t layers_count)
void | fl_renderer_wait_for_frame (FlRenderer *renderer, int target_width, int target_height)
void | fl_renderer_setup (FlRenderer *renderer)
void | fl_renderer_render (FlRenderer *renderer, FlutterViewId view_id, int width, int height, const GdkRGBA *background_color)
void | fl_renderer_cleanup (FlRenderer *renderer)
gdouble | fl_renderer_get_refresh_rate (FlRenderer *renderer)

## Enumeration Type Documentation

## ◆ FlRendererError

enum FlRendererError

FlRendererError: Errors for #FlRenderer objects to set on failures.

Enumerator
FL_RENDERER_ERROR_FAILED |

Definition at line 22 of file fl_renderer.h.

22 {
23 // NOLINTBEGIN(readability-identifier-naming)
24 FL_RENDERER_ERROR_FAILED,
25 // NOLINTEND(readability-identifier-naming)
26 } FlRendererError;

## Function Documentation

## ◆ fl_renderer_add_view()

void fl_renderer_add_view | ( | FlRenderer * | renderer,
|  | FlutterViewId | view_id,
|  | FlView * | view
| ) |  |

fl_renderer_add_view: @renderer: an #FlRenderer. @view_id: the ID of the view. @view: the view Flutter is renderering to.

Add a view to render on.

Definition at line 314 of file fl_renderer.cc.

316 {
317 FlRendererPrivate* priv = reinterpret_cast<FlRendererPrivate*>(
318 fl_renderer_get_instance_private(self));
319
320 g_return_if_fail(FL_IS_RENDERER(self));
321
322 g_hash_table_insert(priv->views, GINT_TO_POINTER(view_id), view);
323 }

References priv, and view.

Referenced by fl_view_new_for_engine(), realize_cb(), and TEST().

## ◆ fl_renderer_cleanup()

void fl_renderer_cleanup | ( | FlRenderer * | renderer | ) |

fl_renderer_cleanup:

Removes OpenGL resources used for rendering. Requires an active OpenGL context.

Definition at line 528 of file fl_renderer.cc.

528 {
529 FlRendererPrivate* priv = reinterpret_cast<FlRendererPrivate*>(
530 fl_renderer_get_instance_private(self));
531
532 g_return_if_fail(FL_IS_RENDERER(self));
533
534 if (priv->program != 0) {
535 glDeleteProgram(priv->program);
536 }
537 }

References priv.

Referenced by unrealize_cb().

## ◆ fl_renderer_clear_current()

void fl_renderer_clear_current | ( | FlRenderer * | renderer | ) |

fl_renderer_clear_current: @renderer: an #FlRenderer.

Clears the current rendering context.

Definition at line 350 of file fl_renderer.cc.

350 {
351 g_return_if_fail(FL_IS_RENDERER(self));
352 FL_RENDERER_GET_CLASS(self)->clear_current(self);
353 }

Referenced by fl_engine_gl_clear_current().

## ◆ fl_renderer_collect_backing_store()

gboolean fl_renderer_collect_backing_store | ( | FlRenderer * | renderer,
|  | const FlutterBackingStore * | backing_store
| ) |  |

fl_renderer_collect_backing_store: @renderer: an #FlRenderer. @backing_store: backing store to be released.

A callback invoked by the engine to release the backing store. The embedder may collect any resources associated with the backing store.

Returns TRUE if successful.

Definition at line 399 of file fl_renderer.cc.

401 {
402 fl_renderer_make_current(self);
403
404 // OpenGL context is required when destroying #FlFramebuffer.
405 g_object_unref(backing_store->open_gl.framebuffer.user_data);
406 return TRUE;
407 }

References fl_renderer_make_current(), and TRUE.

Referenced by compositor_collect_backing_store_callback().

## ◆ fl_renderer_create_backing_store()

gboolean fl_renderer_create_backing_store | ( | FlRenderer * | renderer,
|  | const FlutterBackingStoreConfig * | config,
|  | FlutterBackingStore * | backing_store_out
| ) |  |

fl_renderer_create_backing_store: @renderer: an #FlRenderer. @config: backing store config. @backing_store_out: saves created backing store.

Obtain a backing store for a specific #FlutterLayer.

Returns TRUE if successful.

Definition at line 367 of file fl_renderer.cc.

370 {
371 FlRendererPrivate* priv = reinterpret_cast<FlRendererPrivate*>(
372 fl_renderer_get_instance_private(self));
373
374 fl_renderer_make_current(self);
375
376 initialize(self);
377
378 FlFramebuffer* framebuffer = fl_framebuffer_new(
379 priv->general_format, config->size.width, config->size.height);
380 if (!framebuffer) {
381 g_warning("Failed to create backing store");
382 return FALSE;
383 }
384
385 backing_store_out->type = kFlutterBackingStoreTypeOpenGL;
386 backing_store_out->open_gl.type = kFlutterOpenGLTargetTypeFramebuffer;
387 backing_store_out->open_gl.framebuffer.user_data = framebuffer;
388 backing_store_out->open_gl.framebuffer.name =
389 fl_framebuffer_get_id(framebuffer);
390 backing_store_out->open_gl.framebuffer.target = priv->sized_format;
391 backing_store_out->open_gl.framebuffer.destruction_callback = [](void* p) {
392 // Backing store destroyed in fl_renderer_collect_backing_store(), set
393 // on FlutterCompositor.collect_backing_store_callback during engine start.
394 };
395
396 return TRUE;
397 }

References fl_framebuffer_get_id(), fl_framebuffer_new(), fl_renderer_make_current(), initialize(), priv, and TRUE.

Referenced by compositor_create_backing_store_callback(), and TEST().

## ◆ fl_renderer_error_quark()

GQuark fl_renderer_error_quark | ( | void |  | ) |

## ◆ fl_renderer_get_fbo()

guint32 fl_renderer_get_fbo | ( | FlRenderer * | renderer | ) |

fl_renderer_get_fbo: @renderer: an #FlRenderer.

Gets the frame buffer object to render to.

Returns: a frame buffer object index.

Definition at line 360 of file fl_renderer.cc.

360 {
361 g_return_val_if_fail(FL_IS_RENDERER(self), 0);
362
363 // There is only one frame buffer object - always return that.
364 return 0;
365 }

Referenced by fl_engine_gl_get_fbo().

## ◆ fl_renderer_get_proc_address()

void* fl_renderer_get_proc_address | ( | FlRenderer * | renderer,
|  | const char * | name
| ) |  |

Definition at line 334 of file fl_renderer.cc.

334 {
335 g_return_val_if_fail(FL_IS_RENDERER(self), NULL);
336
337 return reinterpret_cast<void*>(eglGetProcAddress(name));
338 }

Referenced by fl_engine_gl_proc_resolver().

## ◆ fl_renderer_get_refresh_rate()

gdouble fl_renderer_get_refresh_rate | ( | FlRenderer * | renderer | ) |

fl_renderer_get_refresh_rate: @renderer: an #FlRenderer.

Returns: The refresh rate of the display in Hz. If the refresh rate is not available, returns -1.0.

Definition at line 355 of file fl_renderer.cc.

355 {
356 g_return_val_if_fail(FL_IS_RENDERER(self), -1.0);
357 return FL_RENDERER_GET_CLASS(self)->get_refresh_rate(self);
358 }

Referenced by fl_engine_start(), and TEST().

## ◆ fl_renderer_make_current()

void fl_renderer_make_current | ( | FlRenderer * | renderer | ) |

fl_renderer_make_current: @renderer: an #FlRenderer.

Makes the rendering context current.

Definition at line 340 of file fl_renderer.cc.

340 {
341 g_return_if_fail(FL_IS_RENDERER(self));
342 FL_RENDERER_GET_CLASS(self)->make_current(self);
343 }

Referenced by fl_engine_gl_make_current(), fl_renderer_collect_backing_store(), fl_renderer_create_backing_store(), realize_cb(), and unrealize_cb().

## ◆ fl_renderer_make_resource_current()

void fl_renderer_make_resource_current | ( | FlRenderer * | renderer | ) |

fl_renderer_make_resource_current: @renderer: an #FlRenderer.

Makes the resource rendering context current.

Definition at line 345 of file fl_renderer.cc.

345 {
346 g_return_if_fail(FL_IS_RENDERER(self));
347 FL_RENDERER_GET_CLASS(self)->make_resource_current(self);
348 }

Referenced by fl_engine_gl_make_resource_current().

## ◆ fl_renderer_present_layers()

gboolean fl_renderer_present_layers | ( | FlRenderer * | renderer,
|  | FlutterViewId | view_id,
|  | const FlutterLayer ** | layers,
|  | size_t | layers_count
| ) |  |

fl_renderer_present_layers: @renderer: an #FlRenderer. @view_id: view to present. @layers: layers to be composited. @layers_count: number of layers.

Callback invoked by the engine to composite the contents of each layer onto the screen.

Returns TRUE if successful.

Definition at line 429 of file fl_renderer.cc.

432 {
433 FlRendererPrivate* priv = reinterpret_cast<FlRendererPrivate*>(
434 fl_renderer_get_instance_private(self));
435
436 g_return_val_if_fail(FL_IS_RENDERER(self), FALSE);
437
438 // ignore incoming frame with wrong dimensions in trivial case with just one
439 // layer
440 if (priv->blocking_main_thread && layers_count == 1 &&
441 layers[0]->offset.x == 0 && layers[0]->offset.y == 0 &&
442 (layers[0]->size.width != priv->target_width ||
443 layers[0]->size.height != priv->target_height)) {
444 return TRUE;
445 }
446
447 priv->had_first_frame = true;
448
449 fl_renderer_unblock_main_thread(self);
450
451 GPtrArray* framebuffers = reinterpret_cast<GPtrArray*>((g_hash_table_lookup(
452 priv->framebuffers_by_view_id, GINT_TO_POINTER(view_id))));
453 if (framebuffers == nullptr) {
454 framebuffers = g_ptr_array_new_with_free_func(g_object_unref);
455 g_hash_table_insert(priv->framebuffers_by_view_id, GINT_TO_POINTER(view_id),
456 framebuffers);
457 }
458 g_ptr_array_set_size(framebuffers, 0);
459 for (size_t i = 0; i < layers_count; ++i) {
460 const FlutterLayer* layer = layers[i];
461 switch (layer->type) {
462 case kFlutterLayerContentTypeBackingStore: {
463 const FlutterBackingStore* backing_store = layer->backing_store;
464 FlFramebuffer* framebuffer =
465 FL_FRAMEBUFFER(backing_store->open_gl.framebuffer.user_data);
466 g_ptr_array_add(framebuffers, g_object_ref(framebuffer));
467 } break;
468 case kFlutterLayerContentTypePlatformView: {
469 // TODO(robert-ancell) Not implemented -
470 // https://github.com/flutter/flutter/issues/41724
471 } break;
472 }
473 }
474
475 FlView* view =
476 FL_VIEW(g_hash_table_lookup(priv->views, GINT_TO_POINTER(view_id)));
477 if (view != nullptr) {
478 fl_view_redraw(view);
479 }
480
481 return TRUE;
482 }

References fl_renderer_unblock_main_thread(), fl_view_redraw(), i, priv, TRUE, and view.

Referenced by compositor_present_view_callback(), and TEST().

## ◆ fl_renderer_remove_view()

void fl_renderer_remove_view | ( | FlRenderer * | renderer,
|  | FlutterViewId | view_id
| ) |  |

fl_renderer_remove_view: @renderer: an #FlRenderer. @view_id: the ID of the view.

Remove a view from the renderer.

Definition at line 325 of file fl_renderer.cc.

325 {
326 FlRendererPrivate* priv = reinterpret_cast<FlRendererPrivate*>(
327 fl_renderer_get_instance_private(self));
328
329 g_return_if_fail(FL_IS_RENDERER(self));
330
331 g_hash_table_remove(priv->views, GINT_TO_POINTER(view_id));
332 }

References priv.

Referenced by fl_view_dispose().

## ◆ fl_renderer_render()

void fl_renderer_render | ( | FlRenderer * | renderer,
|  | FlutterViewId | view_id,
|  | int | width,
|  | int | height,
|  | const GdkRGBA * | background_color
| ) |  |

fl_renderer_render: @renderer: an #FlRenderer. @view_id: view to render. @width: width of the window in pixels. @height: height of the window in pixels. @background_color: color to use for background.

Performs OpenGL commands to render current Flutter view.

Definition at line 501 of file fl_renderer.cc.

505 {
506 FlRendererPrivate* priv = reinterpret_cast<FlRendererPrivate*>(
507 fl_renderer_get_instance_private(self));
508
509 g_return_if_fail(FL_IS_RENDERER(self));
510
511 glClearColor(background_color->red, background_color->green,
512 background_color->blue, background_color->alpha);
513 glClear(GL_COLOR_BUFFER_BIT);
514
515 GPtrArray* framebuffers = reinterpret_cast<GPtrArray*>((g_hash_table_lookup(
516 priv->framebuffers_by_view_id, GINT_TO_POINTER(view_id))));
517 if (framebuffers != nullptr) {
518 if (priv->has_gl_framebuffer_blit) {
519 render_with_blit(self, framebuffers);
520 } else {
521 render_with_textures(self, framebuffers, width, height);
522 }
523 }
524
525 glFlush();
526 }

References height, priv, render_with_blit(), render_with_textures(), and width.

Referenced by render_cb(), and TEST().

## ◆ fl_renderer_set_engine()

void fl_renderer_set_engine | ( | FlRenderer * | renderer,
|  | FlEngine * | engine
| ) |  |

fl_renderer_set_engine: @renderer: an #FlRenderer. @engine: an #FlEngine.

Called when the renderer is connected to an engine.

Definition at line 305 of file fl_renderer.cc.

305 {
306 FlRendererPrivate* priv = reinterpret_cast<FlRendererPrivate*>(
307 fl_renderer_get_instance_private(self));
308
309 g_return_if_fail(FL_IS_RENDERER(self));
310
311 g_weak_ref_init(&priv->engine, engine);
312 }

References priv.

Referenced by fl_engine_new_with_renderer().

## ◆ fl_renderer_setup()

void fl_renderer_setup | ( | FlRenderer * | renderer | ) |

fl_renderer_setup: @renderer: an #FlRenderer.

Creates OpenGL resources required before rendering. Requires an active OpenGL context.

Definition at line 484 of file fl_renderer.cc.

484 {
485 FlRendererPrivate* priv = reinterpret_cast<FlRendererPrivate*>(
486 fl_renderer_get_instance_private(self));
487
488 g_return_if_fail(FL_IS_RENDERER(self));
489
490 // Note: NVIDIA is temporarily disabled due to
491 // https://github.com/flutter/flutter/issues/152099
492 priv->has_gl_framebuffer_blit =
493 !is_nvidia() && (epoxy_gl_version() >= 30 ||
494 epoxy_has_gl_extension("GL_EXT_framebuffer_blit"));
495
496 if (!priv->has_gl_framebuffer_blit) {
497 setup_shader(self);
498 }
499 }

References is_nvidia(), priv, and setup_shader().

Referenced by realize_cb(), and TEST().

## ◆ fl_renderer_wait_for_frame()

void fl_renderer_wait_for_frame | ( | FlRenderer * | renderer,
|  | int | target_width,
|  | int | target_height
| ) |  |

fl_renderer_wait_for_frame: @renderer: an #FlRenderer. @target_width: width of frame being waited for @target_height: height of frame being waited for

Holds the thread until frame with requested dimensions is presented. While waiting for frame Flutter platform and raster tasks are being processed.

Definition at line 409 of file fl_renderer.cc.

411 {
412 FlRendererPrivate* priv = reinterpret_cast<FlRendererPrivate*>(
413 fl_renderer_get_instance_private(self));
414
415 g_return_if_fail(FL_IS_RENDERER(self));
416
417 priv->target_width = target_width;
418 priv->target_height = target_height;
419
420 if (priv->had_first_frame && !priv->blocking_main_thread) {
421 priv->blocking_main_thread = true;
422 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&priv->engine));
423 if (engine != nullptr) {
424 fl_task_runner_block_main_thread(fl_engine_get_task_runner(engine));
425 }
426 }
427 }

References fl_engine_get_task_runner(), fl_task_runner_block_main_thread(), and priv.

Referenced by handle_geometry_changed(), and TEST().

FL_RENDERER_ERROR_FAILED
@ FL_RENDERER_ERROR_FAILED
Definition: fl_renderer.h:24
i
int i
Definition: fl_socket_accessible.cc:18
priv
FlPixelBufferTexturePrivate * priv
Definition: fl_pixel_buffer_texture.cc:30
setup_shader
static void setup_shader(FlRenderer *self)
Definition: fl_renderer.cc:149
fl_framebuffer_new
FlFramebuffer * fl_framebuffer_new(GLint format, size_t width, size_t height)
Definition: fl_framebuffer.cc:42
initialize
static void initialize(FlRenderer *self)
Definition: fl_renderer.cc:118
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
fl_view_redraw
void fl_view_redraw(FlView *self)
Definition: fl_view.cc:892
fl_renderer_unblock_main_thread
static void fl_renderer_unblock_main_thread(FlRenderer *self)
Definition: fl_renderer.cc:136
height
const uint8_t uint32_t uint32_t * height
Definition: fl_pixel_buffer_texture_test.cc:39
view
FlView * view
Definition: fl_application.cc:35
fl_engine_get_task_runner
FlTaskRunner * fl_engine_get_task_runner(FlEngine *self)
Definition: fl_engine.cc:1001
fl_renderer_make_current
void fl_renderer_make_current(FlRenderer *self)
Definition: fl_renderer.cc:340
FlRendererError
FlRendererError
Definition: fl_renderer.h:22
render_with_textures
static void render_with_textures(FlRenderer *self, GPtrArray *framebuffers, int width, int height)
Definition: fl_renderer.cc:209
render_with_blit
static void render_with_blit(FlRenderer *self, GPtrArray *framebuffers)
Definition: fl_renderer.cc:189
is_nvidia
static gboolean is_nvidia()
Definition: fl_renderer.cc:81
width
const uint8_t uint32_t * width
Definition: fl_pixel_buffer_texture_test.cc:38
FlRendererPrivate
Definition: fl_renderer.cc:41
fl_task_runner_block_main_thread
void fl_task_runner_block_main_thread(FlTaskRunner *self)
Definition: fl_task_runner.cc:176
fl_framebuffer_get_id
GLuint fl_framebuffer_get_id(FlFramebuffer *self)
Definition: fl_framebuffer.cc:69