20 FlGLArea*
self = FL_GL_AREA(gobject);
22 g_clear_object(&
self->context);
23 g_clear_pointer(&
self->textures, g_ptr_array_unref);
25 G_OBJECT_CLASS(fl_gl_area_parent_class)->dispose(gobject);
30 GtkAllocation allocation;
31 gtk_widget_get_allocation(widget, &allocation);
33 gtk_widget_set_realized(widget,
TRUE);
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);
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);
58 if (
self->context == gdk_gl_context_get_current()) {
59 gdk_gl_context_clear_current();
62 GTK_WIDGET_CLASS(fl_gl_area_parent_class)->unrealize(widget);
67 GtkAllocation* allocation) {
68 gtk_widget_set_allocation(widget, allocation);
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,
81 FlGLArea*
self = FL_GL_AREA(widget);
83 gdk_gl_context_make_current(
self->context);
85 gint scale = gtk_widget_get_scale_factor(widget);
87 if (
self->textures ==
nullptr) {
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));
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);
105 GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
108 GtkWidgetClass* widget_class = GTK_WIDGET_CLASS(klass);
114 gtk_widget_class_set_accessible_role(widget_class, ATK_ROLE_DRAWING_AREA);
118 gtk_widget_set_app_paintable(GTK_WIDGET(
self),
TRUE);
122 g_return_val_if_fail(GDK_IS_GL_CONTEXT(context),
nullptr);
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);
130 g_return_if_fail(FL_IS_GL_AREA(
self));
132 g_clear_pointer(&
self->textures, g_ptr_array_unref);
133 self->textures = g_ptr_array_ref(textures);
135 gtk_widget_queue_draw(GTK_WIDGET(
self));