Flutter Linux Embedder
fl_gl_area.cc File Reference
#include "flutter/shell/platform/linux/fl_gl_area.h"
#include <epoxy/gl.h>

Go to the source code of this file.

Classes

struct  _FlGLArea
 

Functions

static void fl_gl_area_dispose (GObject *gobject)
 
static void fl_gl_area_realize (GtkWidget *widget)
 
static void fl_gl_area_unrealize (GtkWidget *widget)
 
static void fl_gl_area_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
 
static gboolean fl_gl_area_draw (GtkWidget *widget, cairo_t *cr)
 
static void fl_gl_area_class_init (FlGLAreaClass *klass)
 
static void fl_gl_area_init (FlGLArea *self)
 
GtkWidget * fl_gl_area_new (GdkGLContext *context)
 
void fl_gl_area_queue_render (FlGLArea *self, GPtrArray *textures)
 

Function Documentation

◆ fl_gl_area_class_init()

static void fl_gl_area_class_init ( FlGLAreaClass *  klass)
static

Definition at line 104 of file fl_gl_area.cc.

104  {
105  GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
106  gobject_class->dispose = fl_gl_area_dispose;
107 
108  GtkWidgetClass* widget_class = GTK_WIDGET_CLASS(klass);
109  widget_class->realize = fl_gl_area_realize;
110  widget_class->unrealize = fl_gl_area_unrealize;
111  widget_class->size_allocate = fl_gl_area_size_allocate;
112  widget_class->draw = fl_gl_area_draw;
113 
114  gtk_widget_class_set_accessible_role(widget_class, ATK_ROLE_DRAWING_AREA);
115 }

References fl_gl_area_dispose(), fl_gl_area_draw(), fl_gl_area_realize(), fl_gl_area_size_allocate(), and fl_gl_area_unrealize().

◆ fl_gl_area_dispose()

static void fl_gl_area_dispose ( GObject *  gobject)
static

Definition at line 19 of file fl_gl_area.cc.

19  {
20  FlGLArea* self = FL_GL_AREA(gobject);
21 
22  g_clear_object(&self->context);
23  g_clear_pointer(&self->textures, g_ptr_array_unref);
24 
25  G_OBJECT_CLASS(fl_gl_area_parent_class)->dispose(gobject);
26 }

References self.

Referenced by fl_gl_area_class_init().

◆ fl_gl_area_draw()

static gboolean fl_gl_area_draw ( GtkWidget *  widget,
cairo_t *  cr 
)
static

Definition at line 80 of file fl_gl_area.cc.

80  {
81  FlGLArea* self = FL_GL_AREA(widget);
82 
83  gdk_gl_context_make_current(self->context);
84 
85  gint scale = gtk_widget_get_scale_factor(widget);
86 
87  if (self->textures == nullptr) {
88  return TRUE;
89  }
90 
91  for (guint i = 0; i < self->textures->len; i++) {
92  FlBackingStoreProvider* texture =
93  FL_BACKING_STORE_PROVIDER(g_ptr_array_index(self->textures, i));
95  GdkRectangle geometry = fl_backing_store_provider_get_geometry(texture);
96  gdk_cairo_draw_from_gl(cr, gtk_widget_get_window(widget), texture_id,
97  GL_TEXTURE, scale, geometry.x, geometry.y,
98  geometry.width, geometry.height);
99  }
100 
101  return TRUE;
102 }

References fl_backing_store_provider_get_geometry(), fl_backing_store_provider_get_gl_texture_id(), self, texture_id, and TRUE.

Referenced by fl_gl_area_class_init().

◆ fl_gl_area_init()

static void fl_gl_area_init ( FlGLArea *  self)
static

Definition at line 117 of file fl_gl_area.cc.

117  {
118  gtk_widget_set_app_paintable(GTK_WIDGET(self), TRUE);
119 }

References TRUE.

◆ fl_gl_area_new()

GtkWidget* fl_gl_area_new ( GdkGLContext *  context)

FlGLArea:

#FlGLArea is a OpenGL drawing area that shows Flutter backing store Layer. fl_gl_area_new: @context: an #GdkGLContext.

Creates a new #FlGLArea widget.

Returns: the newly created #FlGLArea widget.

Definition at line 121 of file fl_gl_area.cc.

121  {
122  g_return_val_if_fail(GDK_IS_GL_CONTEXT(context), nullptr);
123  FlGLArea* area =
124  reinterpret_cast<FlGLArea*>(g_object_new(fl_gl_area_get_type(), nullptr));
125  area->context = GDK_GL_CONTEXT(g_object_ref(context));
126  return GTK_WIDGET(area);
127 }

Referenced by fl_view_set_textures().

◆ fl_gl_area_queue_render()

void fl_gl_area_queue_render ( FlGLArea *  area,
GPtrArray *  textures 
)

fl_gl_area_queue_render: @area: an #FlGLArea. @textures: (transfer none) (element-type FlBackingStoreProvider): a list of #FlBackingStoreProvider.

Queues textures to be drawn later.

Definition at line 129 of file fl_gl_area.cc.

129  {
130  g_return_if_fail(FL_IS_GL_AREA(self));
131 
132  g_clear_pointer(&self->textures, g_ptr_array_unref);
133  self->textures = g_ptr_array_ref(textures);
134 
135  gtk_widget_queue_draw(GTK_WIDGET(self));
136 }

References self.

Referenced by fl_view_set_textures().

◆ fl_gl_area_realize()

static void fl_gl_area_realize ( GtkWidget *  widget)
static

Definition at line 29 of file fl_gl_area.cc.

29  {
30  GtkAllocation allocation;
31  gtk_widget_get_allocation(widget, &allocation);
32 
33  gtk_widget_set_realized(widget, TRUE);
34 
35  GdkWindowAttr attributes;
36  attributes.window_type = GDK_WINDOW_CHILD;
37  attributes.x = allocation.x;
38  attributes.y = allocation.y;
39  attributes.width = allocation.width;
40  attributes.height = allocation.height;
41  attributes.wclass = GDK_INPUT_OUTPUT;
42  attributes.visual = gtk_widget_get_visual(widget);
43  attributes.event_mask = gtk_widget_get_events(widget);
44  gint attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
45  GdkWindow* window = gdk_window_new(gtk_widget_get_parent_window(widget),
46  &attributes, attributes_mask);
47  gtk_widget_set_window(widget, window);
48  gtk_widget_register_window(widget, window);
49 }

References TRUE.

Referenced by fl_gl_area_class_init().

◆ fl_gl_area_size_allocate()

static void fl_gl_area_size_allocate ( GtkWidget *  widget,
GtkAllocation *  allocation 
)
static

Definition at line 66 of file fl_gl_area.cc.

67  {
68  gtk_widget_set_allocation(widget, allocation);
69 
70  if (gtk_widget_get_has_window(widget)) {
71  if (gtk_widget_get_realized(widget)) {
72  gdk_window_move_resize(gtk_widget_get_window(widget), allocation->x,
73  allocation->y, allocation->width,
74  allocation->height);
75  }
76  }
77 }

Referenced by fl_gl_area_class_init().

◆ fl_gl_area_unrealize()

static void fl_gl_area_unrealize ( GtkWidget *  widget)
static

Definition at line 52 of file fl_gl_area.cc.

52  {
53  FlGLArea* self = FL_GL_AREA(widget);
54  gdk_gl_context_make_current(self->context);
55  g_clear_pointer(&self->textures, g_ptr_array_unref);
56 
57  /* Make sure to unset the context if current */
58  if (self->context == gdk_gl_context_get_current()) {
59  gdk_gl_context_clear_current();
60  }
61 
62  GTK_WIDGET_CLASS(fl_gl_area_parent_class)->unrealize(widget);
63 }

References self.

Referenced by fl_gl_area_class_init().

fl_gl_area_unrealize
static void fl_gl_area_unrealize(GtkWidget *widget)
Definition: fl_gl_area.cc:52
fl_gl_area_draw
static gboolean fl_gl_area_draw(GtkWidget *widget, cairo_t *cr)
Definition: fl_gl_area.cc:80
fl_backing_store_provider_get_gl_texture_id
uint32_t fl_backing_store_provider_get_gl_texture_id(FlBackingStoreProvider *self)
Definition: fl_backing_store_provider.cc:71
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
self
GdkEvent FlView * self
Definition: fl_view.cc:100
fl_backing_store_provider_get_geometry
GdkRectangle fl_backing_store_provider_get_geometry(FlBackingStoreProvider *self)
Definition: fl_backing_store_provider.cc:104
fl_gl_area_realize
static void fl_gl_area_realize(GtkWidget *widget)
Definition: fl_gl_area.cc:29
fl_gl_area_dispose
static void fl_gl_area_dispose(GObject *gobject)
Definition: fl_gl_area.cc:19
texture_id
int64_t texture_id
Definition: texture_registrar_unittests.cc:24
fl_gl_area_size_allocate
static void fl_gl_area_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
Definition: fl_gl_area.cc:66