Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 8480820

Browse files
committed
Use a single FlGLArea
1 parent 176e277 commit 8480820

File tree

4 files changed

+66
-284
lines changed

4 files changed

+66
-284
lines changed

shell/platform/linux/fl_gl_area.cc

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct _FlGLArea {
1111

1212
GdkGLContext* context;
1313

14-
FlBackingStoreProvider* texture;
14+
GPtrArray* textures;
1515
};
1616

1717
G_DEFINE_TYPE(FlGLArea, fl_gl_area, GTK_TYPE_WIDGET)
@@ -20,7 +20,7 @@ static void fl_gl_area_dispose(GObject* gobject) {
2020
FlGLArea* self = FL_GL_AREA(gobject);
2121

2222
g_clear_object(&self->context);
23-
g_clear_object(&self->texture);
23+
g_clear_pointer(&self->textures, g_ptr_array_unref);
2424

2525
G_OBJECT_CLASS(fl_gl_area_parent_class)->dispose(gobject);
2626
}
@@ -52,7 +52,7 @@ static void fl_gl_area_realize(GtkWidget* widget) {
5252
static void fl_gl_area_unrealize(GtkWidget* widget) {
5353
FlGLArea* self = FL_GL_AREA(widget);
5454
gdk_gl_context_make_current(self->context);
55-
g_clear_object(&self->texture);
55+
g_clear_pointer(&self->textures, g_ptr_array_unref);
5656

5757
/* Make sure to unset the context if current */
5858
if (self->context == gdk_gl_context_get_current()) {
@@ -84,15 +84,18 @@ static gboolean fl_gl_area_draw(GtkWidget* widget, cairo_t* cr) {
8484

8585
gint scale = gtk_widget_get_scale_factor(widget);
8686

87-
if (self->texture) {
88-
uint32_t texture =
89-
fl_backing_store_provider_get_gl_texture_id(self->texture);
90-
GdkRectangle geometry =
91-
fl_backing_store_provider_get_geometry(self->texture);
92-
gdk_cairo_draw_from_gl(cr, gtk_widget_get_window(widget), texture,
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));
94+
uint32_t texture_id = fl_backing_store_provider_get_gl_texture_id(texture);
95+
GdkRectangle geometry = fl_backing_store_provider_get_geometry(texture);
96+
gdk_cairo_draw_from_gl(cr, gtk_widget_get_window(widget), texture_id,
9397
GL_TEXTURE, scale, geometry.x, geometry.y,
9498
geometry.width, geometry.height);
95-
gdk_gl_context_make_current(self->context);
9699
}
97100

98101
return TRUE;
@@ -112,7 +115,6 @@ static void fl_gl_area_class_init(FlGLAreaClass* klass) {
112115
}
113116

114117
static void fl_gl_area_init(FlGLArea* self) {
115-
gtk_widget_set_can_focus(GTK_WIDGET(self), TRUE);
116118
gtk_widget_set_app_paintable(GTK_WIDGET(self), TRUE);
117119
}
118120

@@ -124,11 +126,11 @@ GtkWidget* fl_gl_area_new(GdkGLContext* context) {
124126
return GTK_WIDGET(area);
125127
}
126128

127-
void fl_gl_area_queue_render(FlGLArea* self, FlBackingStoreProvider* texture) {
129+
void fl_gl_area_queue_render(FlGLArea* self, GPtrArray* textures) {
128130
g_return_if_fail(FL_IS_GL_AREA(self));
129131

130-
g_clear_object(&self->texture);
131-
g_set_object(&self->texture, texture);
132+
g_clear_pointer(&self->textures, g_ptr_array_unref);
133+
self->textures = g_ptr_array_ref(textures);
132134

133135
gtk_widget_queue_draw(GTK_WIDGET(self));
134136
}

shell/platform/linux/fl_gl_area.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ GtkWidget* fl_gl_area_new(GdkGLContext* context);
3232
/**
3333
* fl_gl_area_queue_render:
3434
* @area: an #FlGLArea.
35-
* @texture: queued OpenGL texture.
35+
* @textures: (transfer none) (element-type FlBackingStoreProvider): a list of
36+
* #FlBackingStoreProvider.
3637
*
37-
* Queues a texture to be drawn later.
38+
* Queues textures to be drawn later.
3839
*/
39-
void fl_gl_area_queue_render(FlGLArea* area, FlBackingStoreProvider* texture);
40+
void fl_gl_area_queue_render(FlGLArea* area, GPtrArray* textures);
4041

4142
G_END_DECLS
4243

0 commit comments

Comments
 (0)