[gtk+/wip/gl-texture] wip: convert gtkglarea to use snapshots
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/gl-texture] wip: convert gtkglarea to use snapshots
- Date: Wed, 17 Jan 2018 12:26:22 +0000 (UTC)
commit 9abe8ea25c33ffd4a57b41216fd7b67321ad18ac
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Jan 17 07:25:51 2018 -0500
wip: convert gtkglarea to use snapshots
Just append a texture node.
gtk/gtkglarea.c | 42 ++++++++++++++++++++++++++++--------------
1 files changed, 28 insertions(+), 14 deletions(-)
---
diff --git a/gtk/gtkglarea.c b/gtk/gtkglarea.c
index 27157a0..9074a23 100644
--- a/gtk/gtkglarea.c
+++ b/gtk/gtkglarea.c
@@ -27,6 +27,7 @@
#include "gtkmarshalers.h"
#include "gtkprivate.h"
#include "gtkrender.h"
+#include "gtksnapshot.h"
#include <epoxy/gl.h>
@@ -144,6 +145,7 @@
typedef struct {
GdkGLContext *context;
GError *error;
+ GdkTexture *gdk_texture;
gboolean have_buffers;
@@ -381,7 +383,13 @@ gtk_gl_area_ensure_buffers (GtkGLArea *area)
{
/* For alpha we use textures as that is required for blending to work */
if (priv->texture == 0)
- glGenTextures (1, &priv->texture);
+ {
+ glGenTextures (1, &priv->texture);
+ priv->gdk_texture = gdk_texture_new_for_gl (priv->context,
+ priv->texture,
+ gtk_widget_get_width (widget),
+ gtk_widget_get_height (widget));
+ }
/* Delete old render buffer if any */
if (priv->render_buffer != 0)
@@ -399,6 +407,7 @@ gtk_gl_area_ensure_buffers (GtkGLArea *area)
/* Delete old texture if any */
if (priv->texture != 0)
{
+ g_clear_object (&priv->gdk_texture);
glDeleteTextures(1, &priv->texture);
priv->texture = 0;
}
@@ -537,6 +546,7 @@ gtk_gl_area_delete_buffers (GtkGLArea *area)
if (priv->texture != 0)
{
+ g_clear_object (&priv->gdk_texture);
glDeleteTextures(1, &priv->texture);
priv->texture = 0;
}
@@ -618,9 +628,9 @@ gtk_gl_area_draw_error_screen (GtkGLArea *area,
g_object_unref (layout);
}
-static gboolean
-gtk_gl_area_draw (GtkWidget *widget,
- cairo_t *cr)
+static void
+gtk_gl_area_snapshot (GtkWidget *widget,
+ GtkSnapshot *snapshot)
{
GtkGLArea *area = GTK_GL_AREA (widget);
GtkGLAreaPrivate *priv = gtk_gl_area_get_instance_private (area);
@@ -628,6 +638,7 @@ gtk_gl_area_draw (GtkWidget *widget,
int w, h, scale;
GLenum status;
+#if 0
if (priv->error != NULL)
{
gtk_gl_area_draw_error_screen (area,
@@ -636,9 +647,10 @@ gtk_gl_area_draw (GtkWidget *widget,
gtk_widget_get_height (widget));
return FALSE;
}
+#endif
if (priv->context == NULL)
- return FALSE;
+ return;
gtk_gl_area_make_current (area);
@@ -669,19 +681,17 @@ gtk_gl_area_draw (GtkWidget *widget,
priv->needs_render = FALSE;
- gdk_cairo_draw_from_gl (cr,
- gtk_widget_get_window (widget),
- priv->texture ? priv->texture : priv->render_buffer,
- priv->texture ? GL_TEXTURE : GL_RENDERBUFFER,
- scale, 0, 0, w, h);
- gtk_gl_area_make_current (area);
+ gtk_snapshot_append_texture (snapshot,
+ priv->gdk_texture,
+ &GRAPHENE_RECT_INIT (0, 0,
+ gtk_widget_get_width (widget),
+ gtk_widget_get_height (widget)),
+ "GL Area");
}
else
{
g_warning ("fb setup not supported");
}
-
- return TRUE;
}
static gboolean
@@ -708,7 +718,7 @@ gtk_gl_area_class_init (GtkGLAreaClass *klass)
widget_class->realize = gtk_gl_area_realize;
widget_class->unrealize = gtk_gl_area_unrealize;
widget_class->size_allocate = gtk_gl_area_size_allocate;
- widget_class->draw = gtk_gl_area_draw;
+ widget_class->snapshot = gtk_gl_area_snapshot;
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_DRAWING_AREA);
@@ -929,6 +939,8 @@ gtk_gl_area_init (GtkGLArea *area)
priv->auto_render = TRUE;
priv->needs_render = TRUE;
priv->required_gl_version = 0;
+
+ priv->has_alpha = 1;
}
/**
@@ -1138,6 +1150,8 @@ gtk_gl_area_set_has_alpha (GtkGLArea *area,
has_alpha = !!has_alpha;
+ has_alpha = 1;
+
if (priv->has_alpha != has_alpha)
{
priv->has_alpha = has_alpha;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]