Flutter Engine
fl_renderer.cc File Reference
#include "fl_renderer.h"
#include <epoxy/egl.h>
#include <epoxy/gl.h>
#include "flutter/shell/platform/embedder/embedder.h"
#include "flutter/shell/platform/linux/fl_backing_store_provider.h"
#include "flutter/shell/platform/linux/fl_engine_private.h"

Go to the source code of this file.

Classes

struct  FlRendererPrivate
 

Functions

static void fl_renderer_unblock_main_thread (FlRenderer *self)
 
static void fl_renderer_dispose (GObject *self)
 
static void fl_renderer_class_init (FlRendererClass *klass)
 
static void fl_renderer_init (FlRenderer *self)
 
gboolean fl_renderer_start (FlRenderer *self, FlView *view, GError **error)
 
FlView * fl_renderer_get_view (FlRenderer *self)
 
GdkGLContext * fl_renderer_get_context (FlRenderer *self)
 
void * fl_renderer_get_proc_address (FlRenderer *self, const char *name)
 
gboolean fl_renderer_make_current (FlRenderer *self, GError **error)
 
gboolean fl_renderer_make_resource_current (FlRenderer *self, GError **error)
 
gboolean fl_renderer_clear_current (FlRenderer *self, GError **error)
 
guint32 fl_renderer_get_fbo (FlRenderer *self)
 
gboolean fl_renderer_present (FlRenderer *self, GError **error)
 
gboolean fl_renderer_create_backing_store (FlRenderer *self, const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
 
gboolean fl_renderer_collect_backing_store (FlRenderer *self, const FlutterBackingStore *backing_store)
 
void fl_renderer_wait_for_frame (FlRenderer *self, int target_width, int target_height)
 
gboolean fl_renderer_present_layers (FlRenderer *self, const FlutterLayer **layers, size_t layers_count)
 

Function Documentation

◆ fl_renderer_class_init()

static void fl_renderer_class_init ( FlRendererClass *  klass)
static

Definition at line 53 of file fl_renderer.cc.

References fl_renderer_dispose().

53  {
54  G_OBJECT_CLASS(klass)->dispose = fl_renderer_dispose;
55 }
static void fl_renderer_dispose(GObject *self)
Definition: fl_renderer.cc:48

◆ fl_renderer_clear_current()

gboolean fl_renderer_clear_current ( FlRenderer *  renderer,
GError **  error 
)

fl_renderer_clear_current: : an #FlRenderer. : (allow-none): #GError location to store the error occurring, or NULL to ignore.

Clears the current rendering context.

Returns TRUE if successful.

Definition at line 114 of file fl_renderer.cc.

References TRUE.

Referenced by fl_engine_gl_clear_current().

114  {
115  gdk_gl_context_clear_current();
116  return TRUE;
117 }

◆ fl_renderer_collect_backing_store()

gboolean fl_renderer_collect_backing_store ( FlRenderer *  renderer,
const FlutterBackingStore backing_store 
)

fl_renderer_collect_backing_store: : an #FlRenderer. : 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 136 of file fl_renderer.cc.

Referenced by compositor_collect_backing_store_callback().

138  {
139  return FL_RENDERER_GET_CLASS(self)->collect_backing_store(self,
140  backing_store);
141 }

◆ 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: : an #FlRenderer. : backing store config. : saves created backing store.

Obtain a backing store for a specific FlutterLayer.

Returns TRUE if successful.

Definition at line 128 of file fl_renderer.cc.

Referenced by compositor_create_backing_store_callback().

131  {
132  return FL_RENDERER_GET_CLASS(self)->create_backing_store(self, config,
133  backing_store_out);
134 }

◆ fl_renderer_dispose()

static void fl_renderer_dispose ( GObject *  self)
static

Definition at line 48 of file fl_renderer.cc.

References fl_renderer_unblock_main_thread().

Referenced by fl_renderer_class_init().

48  {
49  fl_renderer_unblock_main_thread(FL_RENDERER(self));
50  G_OBJECT_CLASS(fl_renderer_parent_class)->dispose(self);
51 }
static void fl_renderer_unblock_main_thread(FlRenderer *self)
Definition: fl_renderer.cc:36

◆ fl_renderer_get_context()

GdkGLContext* fl_renderer_get_context ( FlRenderer *  renderer)

fl_renderer_get_context: : an #FlRenderer.

Returns: GL context for GLAreas or NULL if headless.

Definition at line 84 of file fl_renderer.cc.

References FlRendererPrivate::main_context.

Referenced by fl_renderer_gl_present_layers().

84  {
85  FlRendererPrivate* priv = reinterpret_cast<FlRendererPrivate*>(
86  fl_renderer_get_instance_private(self));
87  return priv->main_context;
88 }
GdkGLContext * main_context
Definition: fl_renderer.cc:30

◆ fl_renderer_get_fbo()

guint32 fl_renderer_get_fbo ( FlRenderer *  renderer)

fl_renderer_get_fbo: : an #FlRenderer.

Gets the frame buffer object to render to.

Returns: a frame buffer object index.

Definition at line 119 of file fl_renderer.cc.

Referenced by fl_engine_gl_get_fbo().

119  {
120  // There is only one frame buffer object - always return that.
121  return 0;
122 }

◆ fl_renderer_get_proc_address()

void* fl_renderer_get_proc_address ( FlRenderer *  self,
const char *  name 
)

Definition at line 90 of file fl_renderer.cc.

Referenced by fl_engine_gl_proc_resolver().

90  {
91  return reinterpret_cast<void*>(eglGetProcAddress(name));
92 }
const char * name
Definition: fuchsia.cc:50

◆ fl_renderer_get_view()

FlView* fl_renderer_get_view ( FlRenderer *  renderer)

fl_renderer_get_view: : an #FlRenderer.

Returns: targeted #FlView or NULL if headless.

Definition at line 78 of file fl_renderer.cc.

References FlRendererPrivate::view.

Referenced by fl_renderer_gl_present_layers().

78  {
79  FlRendererPrivate* priv = reinterpret_cast<FlRendererPrivate*>(
80  fl_renderer_get_instance_private(self));
81  return priv->view;
82 }

◆ fl_renderer_init()

static void fl_renderer_init ( FlRenderer *  self)
static

Definition at line 57 of file fl_renderer.cc.

57 {}

◆ fl_renderer_make_current()

gboolean fl_renderer_make_current ( FlRenderer *  renderer,
GError **  error 
)

fl_renderer_make_current: : an #FlRenderer. : (allow-none): #GError location to store the error occurring, or NULL to ignore.

Makes the rendering context current.

Returns TRUE if successful.

Definition at line 94 of file fl_renderer.cc.

References FlRendererPrivate::main_context, and TRUE.

Referenced by fl_engine_gl_make_current(), fl_renderer_gl_collect_backing_store(), and fl_renderer_gl_create_backing_store().

94  {
95  FlRendererPrivate* priv = reinterpret_cast<FlRendererPrivate*>(
96  fl_renderer_get_instance_private(self));
97  if (priv->main_context) {
98  gdk_gl_context_make_current(priv->main_context);
99  }
100 
101  return TRUE;
102 }
GdkGLContext * main_context
Definition: fl_renderer.cc:30

◆ fl_renderer_make_resource_current()

gboolean fl_renderer_make_resource_current ( FlRenderer *  renderer,
GError **  error 
)

fl_renderer_make_resource_current: : an #FlRenderer. : (allow-none): #GError location to store the error occurring, or NULL to ignore.

Makes the resource rendering context current.

Returns TRUE if successful.

Definition at line 104 of file fl_renderer.cc.

References FlRendererPrivate::resource_context, and TRUE.

Referenced by fl_engine_gl_make_resource_current().

104  {
105  FlRendererPrivate* priv = reinterpret_cast<FlRendererPrivate*>(
106  fl_renderer_get_instance_private(self));
107  if (priv->resource_context) {
108  gdk_gl_context_make_current(priv->resource_context);
109  }
110 
111  return TRUE;
112 }
GdkGLContext * resource_context
Definition: fl_renderer.cc:31

◆ fl_renderer_present()

gboolean fl_renderer_present ( FlRenderer *  renderer,
GError **  error 
)

fl_renderer_present: : an #FlRenderer. : (allow-none): #GError location to store the error occurring, or NULL to ignore.

Presents the current frame.

Returns TRUE if successful.

Definition at line 124 of file fl_renderer.cc.

References TRUE.

Referenced by fl_engine_gl_present().

124  {
125  return TRUE;
126 }

◆ fl_renderer_present_layers()

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

fl_renderer_present_layers: : an #FlRenderer. : layers to be composited. : 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 160 of file fl_renderer.cc.

References FlRendererPrivate::blocking_main_thread, fl_renderer_unblock_main_thread(), FlRendererPrivate::had_first_frame, FlutterSize::height, FlutterLayer::offset, FlutterLayer::size, FlRendererPrivate::target_height, FlRendererPrivate::target_width, FlutterSize::width, FlutterPoint::x, and FlutterPoint::y.

Referenced by compositor_present_layers_callback().

162  {
163  FlRendererPrivate* priv = reinterpret_cast<FlRendererPrivate*>(
164  fl_renderer_get_instance_private(self));
165 
166  // ignore incoming frame with wrong dimensions in trivial case with just one
167  // layer
168  if (priv->blocking_main_thread && layers_count == 1 &&
169  layers[0]->offset.x == 0 && layers[0]->offset.y == 0 &&
170  (layers[0]->size.width != priv->target_width ||
171  layers[0]->size.height != priv->target_height)) {
172  return true;
173  }
174 
175  priv->had_first_frame = true;
176 
178 
179  return FL_RENDERER_GET_CLASS(self)->present_layers(self, layers,
180  layers_count);
181 }
double y
Definition: embedder.h:343
FlutterSize size
The size of the layer (in physical pixels).
Definition: embedder.h:1108
FlutterPoint offset
Definition: embedder.h:1106
double x
Definition: embedder.h:342
double width
Definition: embedder.h:320
static void fl_renderer_unblock_main_thread(FlRenderer *self)
Definition: fl_renderer.cc:36
double height
Definition: embedder.h:321

◆ fl_renderer_start()

gboolean fl_renderer_start ( FlRenderer *  renderer,
FlView *  view,
GError **  error 
)

fl_renderer_start: : an #FlRenderer. : the view Flutter is renderering to. : (allow-none): #GError location to store the error occurring, or NULL to ignore.

Start the renderer.

Returns: TRUE if successfully started.

Definition at line 59 of file fl_renderer.cc.

References FALSE, FlRendererPrivate::main_context, FlRendererPrivate::resource_context, result, TRUE, FlRendererPrivate::view, and view.

Referenced by fl_view_realize().

59  {
60  g_return_val_if_fail(FL_IS_RENDERER(self), FALSE);
61  FlRendererPrivate* priv = reinterpret_cast<FlRendererPrivate*>(
62  fl_renderer_get_instance_private(self));
63  priv->view = view;
64  gboolean result = FL_RENDERER_GET_CLASS(self)->create_contexts(
65  self, GTK_WIDGET(view), &priv->main_context, &priv->resource_context,
66  error);
67 
68  if (result) {
69  gdk_gl_context_realize(priv->main_context, error);
70  gdk_gl_context_realize(priv->resource_context, error);
71  }
72 
73  if (*error != nullptr)
74  return FALSE;
75  return TRUE;
76 }
const uint8_t uint32_t uint32_t GError ** error
GAsyncResult * result
FlView * view
return FALSE
GdkGLContext * resource_context
Definition: fl_renderer.cc:31
GdkGLContext * main_context
Definition: fl_renderer.cc:30

◆ fl_renderer_unblock_main_thread()

static void fl_renderer_unblock_main_thread ( FlRenderer *  self)
static

Definition at line 36 of file fl_renderer.cc.

References FlRendererPrivate::blocking_main_thread, fl_engine_get_task_runner(), fl_task_runner_release_main_thread(), fl_view_get_engine(), and FlRendererPrivate::view.

Referenced by fl_renderer_dispose(), and fl_renderer_present_layers().

36  {
37  FlRendererPrivate* priv = reinterpret_cast<FlRendererPrivate*>(
38  fl_renderer_get_instance_private(self));
39  if (priv->blocking_main_thread) {
40  priv->blocking_main_thread = false;
41 
42  FlTaskRunner* runner =
45  }
46 }
G_MODULE_EXPORT FlEngine * fl_view_get_engine(FlView *view)
Definition: fl_view.cc:742
void fl_task_runner_release_main_thread(FlTaskRunner *self)
FlTaskRunner * fl_engine_get_task_runner(FlEngine *self)
Definition: fl_engine.cc:775

◆ fl_renderer_wait_for_frame()

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

fl_renderer_wait_for_frame: : an #FlRenderer. : width of frame being waited for : 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 143 of file fl_renderer.cc.

References FlRendererPrivate::blocking_main_thread, fl_engine_get_task_runner(), fl_task_runner_block_main_thread(), fl_view_get_engine(), FlRendererPrivate::had_first_frame, FlRendererPrivate::target_height, FlRendererPrivate::target_width, and FlRendererPrivate::view.

Referenced by fl_view_geometry_changed().

145  {
146  FlRendererPrivate* priv = reinterpret_cast<FlRendererPrivate*>(
147  fl_renderer_get_instance_private(self));
148 
149  priv->target_width = target_width;
150  priv->target_height = target_height;
151 
152  if (priv->had_first_frame && !priv->blocking_main_thread) {
153  priv->blocking_main_thread = true;
154  FlTaskRunner* runner =
157  }
158 }
G_MODULE_EXPORT FlEngine * fl_view_get_engine(FlView *view)
Definition: fl_view.cc:742
void fl_task_runner_block_main_thread(FlTaskRunner *self)
FlTaskRunner * fl_engine_get_task_runner(FlEngine *self)
Definition: fl_engine.cc:775