| Flutter Linux Embedder |

Classes | Functions
fl_renderer_gl.cc File Reference
`#include "flutter/shell/platform/linux/fl_renderer_gl.h"`
`#include "flutter/shell/platform/linux/fl_backing_store_provider.h"`
`#include "flutter/shell/platform/linux/fl_view_private.h"`

Go to the source code of this file.

## Classes
struct | _FlRendererGL

## Functions
static gboolean | fl_renderer_gl_create_contexts (FlRenderer *renderer, GtkWidget *widget, GdkGLContext **visible, GdkGLContext **resource, GError **error)
static gboolean | fl_renderer_gl_create_backing_store (FlRenderer *renderer, const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
static gboolean | fl_renderer_gl_collect_backing_store (FlRenderer *renderer, const FlutterBackingStore *backing_store)
static gboolean | fl_renderer_gl_present_layers (FlRenderer *renderer, const FlutterLayer **layers, size_t layers_count)
static void | fl_renderer_gl_class_init (FlRendererGLClass *klass)
static void | fl_renderer_gl_init (FlRendererGL *self)
FlRendererGL * | fl_renderer_gl_new ()

## Function Documentation

## ◆ fl_renderer_gl_class_init()

static void fl_renderer_gl_class_init | ( | FlRendererGLClass * | klass | ) |
| static

Definition at line 123 of file fl_renderer_gl.cc.

123 {
124 FL_RENDERER_CLASS(klass)->create_contexts = fl_renderer_gl_create_contexts;
125 FL_RENDERER_CLASS(klass)->create_backing_store =
126 fl_renderer_gl_create_backing_store;
127 FL_RENDERER_CLASS(klass)->collect_backing_store =
128 fl_renderer_gl_collect_backing_store;
129 FL_RENDERER_CLASS(klass)->present_layers = fl_renderer_gl_present_layers;
130 }

References fl_renderer_gl_collect_backing_store(), fl_renderer_gl_create_backing_store(), fl_renderer_gl_create_contexts(), and fl_renderer_gl_present_layers().

## ◆ fl_renderer_gl_collect_backing_store()

static gboolean fl_renderer_gl_collect_backing_store | ( | FlRenderer * | renderer,
|  | const FlutterBackingStore * | backing_store
| ) |  |
| static

Definition at line 75 of file fl_renderer_gl.cc.

77 {
78 g_autoptr(GError) error = nullptr;
79 gboolean result = fl_renderer_make_current(renderer, &error);
80 if (!result) {
81 g_warning(
82 "Failed to make renderer current when collecting backing store: %s",
83 error->message);
84 return FALSE;
85 }
86
87 // OpenGL context is required when destroying #FlBackingStoreProvider.
88 g_object_unref(backing_store->open_gl.framebuffer.user_data);
89 return TRUE;
90 }

References error, fl_renderer_make_current(), result, and TRUE.

Referenced by fl_renderer_gl_class_init().

## ◆ fl_renderer_gl_create_backing_store()

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

Definition at line 39 of file fl_renderer_gl.cc.

42 {
43 g_autoptr(GError) error = nullptr;
44 gboolean result = fl_renderer_make_current(renderer, &error);
45 if (!result) {
46 g_warning("Failed to make renderer current when creating backing store: %s",
47 error->message);
48 return FALSE;
49 }
50
51 FlBackingStoreProvider* provider =
52 fl_backing_store_provider_new(config->size.width, config->size.height);
53 if (!provider) {
54 g_warning("Failed to create backing store");
55 return FALSE;
56 }
57
58 uint32_t name = fl_backing_store_provider_get_gl_framebuffer_id(provider);
59 uint32_t format = fl_backing_store_provider_get_gl_format(provider);
60
61 backing_store_out->type = kFlutterBackingStoreTypeOpenGL;
62 backing_store_out->open_gl.type = kFlutterOpenGLTargetTypeFramebuffer;
63 backing_store_out->open_gl.framebuffer.user_data = provider;
64 backing_store_out->open_gl.framebuffer.name = name;
65 backing_store_out->open_gl.framebuffer.target = format;
66 backing_store_out->open_gl.framebuffer.destruction_callback = [](void* p) {
67 // Backing store destroyed in fl_renderer_gl_collect_backing_store(), set
68 // on FlutterCompositor.collect_backing_store_callback during engine start.
69 };
70
71 return TRUE;
72 }

References error, fl_backing_store_provider_get_gl_format(), fl_backing_store_provider_get_gl_framebuffer_id(), fl_backing_store_provider_new(), fl_renderer_make_current(), format, result, and TRUE.

Referenced by fl_renderer_gl_class_init().

## ◆ fl_renderer_gl_create_contexts()

static gboolean fl_renderer_gl_create_contexts | ( | FlRenderer * | renderer,
|  | GtkWidget * | widget,
|  | GdkGLContext ** | visible,
|  | GdkGLContext ** | resource,
|  | GError ** | error
| ) |  |
| static

Definition at line 17 of file fl_renderer_gl.cc.

21 {
22 GdkWindow* window = gtk_widget_get_parent_window(widget);
23
24 *visible = gdk_window_create_gl_context(window, error);
25
26 if (*error != nullptr) {
27 return FALSE;
28 }
29
30 *resource = gdk_window_create_gl_context(window, error);
31
32 if (*error != nullptr) {
33 return FALSE;
34 }
35 return TRUE;
36 }

References error, and TRUE.

Referenced by fl_renderer_gl_class_init().

## ◆ fl_renderer_gl_init()

static void fl_renderer_gl_init | ( | FlRendererGL * | self | ) |
| static

Definition at line 132 of file fl_renderer_gl.cc.

132 {}

## ◆ fl_renderer_gl_new()

FlRendererGL* fl_renderer_gl_new | ( |  | ) |

FlRendererGL:

#FlRendererGL is an implementation of #FlRenderer that renders by OpenGL ES. fl_renderer_gl_new:

Creates an object that allows Flutter to render by OpenGL ES.

Returns: a new #FlRendererGL.

Definition at line 134 of file fl_renderer_gl.cc.

134 {
135 return FL_RENDERER_GL(g_object_new(fl_renderer_gl_get_type(), nullptr));
136 }

Referenced by fl_view_constructed().

## ◆ fl_renderer_gl_present_layers()

static gboolean fl_renderer_gl_present_layers | ( | FlRenderer * | renderer,
|  | const FlutterLayer ** | layers,
|  | size_t | layers_count
| ) |  |
| static

Definition at line 93 of file fl_renderer_gl.cc.

95 {
96 FlView* view = fl_renderer_get_view(renderer);
97 GdkGLContext* context = fl_renderer_get_context(renderer);
98 if (!view || !context) {
99 return FALSE;
100 }
101
102 g_autoptr(GPtrArray) textures = g_ptr_array_new();
103 for (size_t i = 0; i < layers_count; ++i) {
104 const FlutterLayer* layer = layers[i];
105 switch (layer->type) {
106 case kFlutterLayerContentTypeBackingStore: {
107 const FlutterBackingStore* backing_store = layer->backing_store;
108 auto framebuffer = &backing_store->open_gl.framebuffer;
109 g_ptr_array_add(textures, reinterpret_cast<FlBackingStoreProvider*>(
110 framebuffer->user_data));
111 } break;
112 case kFlutterLayerContentTypePlatformView: {
113 // Currently unsupported.
114 } break;
115 }
116 }
117
118 fl_view_set_textures(view, context, textures);
119
120 return TRUE;
121 }

References fl_renderer_get_context(), fl_renderer_get_view(), fl_view_set_textures(), and TRUE.

Referenced by fl_renderer_gl_class_init().

fl_renderer_get_view
FlView * fl_renderer_get_view(FlRenderer *self)
Definition: fl_renderer.cc:79
fl_backing_store_provider_get_gl_format
uint32_t fl_backing_store_provider_get_gl_format(FlBackingStoreProvider *self)
Definition: fl_backing_store_provider.cc:80
fl_backing_store_provider_new
FlBackingStoreProvider * fl_backing_store_provider_new(int width, int height)
Definition: fl_backing_store_provider.cc:35
fl_renderer_gl_create_contexts
static gboolean fl_renderer_gl_create_contexts(FlRenderer *renderer, GtkWidget *widget, GdkGLContext **visible, GdkGLContext **resource, GError **error)
Definition: fl_renderer_gl.cc:17
fl_renderer_gl_create_backing_store
static gboolean fl_renderer_gl_create_backing_store(FlRenderer *renderer, const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
Definition: fl_renderer_gl.cc:39
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
fl_renderer_gl_present_layers
static gboolean fl_renderer_gl_present_layers(FlRenderer *renderer, const FlutterLayer **layers, size_t layers_count)
Definition: fl_renderer_gl.cc:93
result
GAsyncResult * result
Definition: fl_text_input_plugin.cc:106
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
fl_renderer_gl_collect_backing_store
static gboolean fl_renderer_gl_collect_backing_store(FlRenderer *renderer, const FlutterBackingStore *backing_store)
Definition: fl_renderer_gl.cc:75
fl_view_set_textures
void fl_view_set_textures(FlView *self, GdkGLContext *context, GPtrArray *textures)
Definition: fl_view.cc:775
fl_renderer_make_current
gboolean fl_renderer_make_current(FlRenderer *self, GError **error)
Definition: fl_renderer.cc:95
format
uint32_t uint32_t * format
Definition: fl_texture_registrar_test.cc:41
fl_renderer_get_context
GdkGLContext * fl_renderer_get_context(FlRenderer *self)
Definition: fl_renderer.cc:85
fl_backing_store_provider_get_gl_framebuffer_id
uint32_t fl_backing_store_provider_get_gl_framebuffer_id(FlBackingStoreProvider *self)
Definition: fl_backing_store_provider.cc:66