[gtk/wip/otte/gleanup] gdk: Add gdk_gl_context_is_compatible()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/gleanup] gdk: Add gdk_gl_context_is_compatible()
- Date: Wed, 30 Jun 2021 03:17:58 +0000 (UTC)
commit 9ebed2d6ec3c1e3fc1463b5eac892c4aaba2e8a9
Author: Benjamin Otte <otte redhat com>
Date: Wed Jun 30 04:52:35 2021 +0200
gdk: Add gdk_gl_context_is_compatible()
... and use it in the GL renderers.
gdk/gdkglcontext.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++
gdk/gdkglcontext.h | 3 +++
gdk/gdkglcontextprivate.h | 9 ++++++---
gsk/gl/gskgldriver.c | 8 +++-----
gsk/ngl/gskngldriver.c | 10 +++-------
5 files changed, 64 insertions(+), 15 deletions(-)
---
diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c
index a82c7e3bc4..11211287c0 100644
--- a/gdk/gdkglcontext.c
+++ b/gdk/gdkglcontext.c
@@ -333,6 +333,18 @@ gdk_gl_context_real_get_damage (GdkGLContext *context)
});
}
+static gboolean
+gdk_gl_context_real_is_compatible (GdkGLContext *self,
+ GdkGLContext *other)
+{
+ if (gdk_draw_context_get_display (GDK_DRAW_CONTEXT (self)) != gdk_draw_context_get_display
(GDK_DRAW_CONTEXT (other)))
+ return FALSE;
+
+ /* XXX: Should we check es or legacy here? */
+
+ return TRUE;
+}
+
static void
gdk_gl_context_real_begin_frame (GdkDrawContext *draw_context,
cairo_region_t *region)
@@ -406,6 +418,7 @@ gdk_gl_context_class_init (GdkGLContextClass *klass)
klass->realize = gdk_gl_context_real_realize;
klass->get_damage = gdk_gl_context_real_get_damage;
+ klass->is_compatible = gdk_gl_context_real_is_compatible;
draw_context_class->begin_frame = gdk_gl_context_real_begin_frame;
draw_context_class->end_frame = gdk_gl_context_real_end_frame;
@@ -812,6 +825,42 @@ gdk_gl_context_set_is_legacy (GdkGLContext *context,
priv->is_legacy = !!is_legacy;
}
+/**
+ * gdk_gl_context_is_compatible:
+ * @self: a `GdkGLContext`
+ * @other: the `GdkGLContext` that should be compatible with @self
+ *
+ * Checks if the two GL contexts are compatible.
+ *
+ * When they are, the texture IDs from @other can be used in @self. This
+ * is particularly useful when passing `GdkGLTexture` objects between
+ * different contexts.
+ *
+ * Contexts created for the same display with the same properties will
+ * always be compatible, even if they are created for different surfaces.
+ * For other contexts it depends on the GL backend.
+ *
+ * Both contexts must be realized for this check to succeed. If either one
+ * is not, this function will return %FALSE.
+ *
+ * Returns: %TRUE if the two GL contexts are compatible.
+ */
+gboolean
+gdk_gl_context_is_compatible (GdkGLContext *self,
+ GdkGLContext *other)
+{
+ GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (self);
+ GdkGLContextPrivate *priv_other = gdk_gl_context_get_instance_private (other);
+
+ g_return_val_if_fail (GDK_IS_GL_CONTEXT (self), FALSE);
+ g_return_val_if_fail (GDK_IS_GL_CONTEXT (other), FALSE);
+
+ if (!priv->realized || !priv_other->realized)
+ return FALSE;
+
+ return GDK_GL_CONTEXT_GET_CLASS (self)->is_compatible (self, other);
+}
+
/**
* gdk_gl_context_set_use_es:
* @context: a `GdkGLContext`
diff --git a/gdk/gdkglcontext.h b/gdk/gdkglcontext.h
index 10bac82e9b..8f9308928d 100644
--- a/gdk/gdkglcontext.h
+++ b/gdk/gdkglcontext.h
@@ -54,6 +54,9 @@ void gdk_gl_context_get_version (GdkGLContext *
int *minor);
GDK_AVAILABLE_IN_ALL
gboolean gdk_gl_context_is_legacy (GdkGLContext *context);
+GDK_AVAILABLE_IN_4_4
+gboolean gdk_gl_context_is_compatible (GdkGLContext *self,
+ GdkGLContext *other);
GDK_AVAILABLE_IN_ALL
void gdk_gl_context_set_required_version (GdkGLContext *context,
diff --git a/gdk/gdkglcontextprivate.h b/gdk/gdkglcontextprivate.h
index 07310eebfa..0c520bc735 100644
--- a/gdk/gdkglcontextprivate.h
+++ b/gdk/gdkglcontextprivate.h
@@ -45,10 +45,13 @@ struct _GdkGLContextClass
{
GdkDrawContextClass parent_class;
- gboolean (* realize) (GdkGLContext *context,
- GError **error);
+ gboolean (* realize) (GdkGLContext *context,
+ GError **error);
- cairo_region_t * (* get_damage) (GdkGLContext *context);
+ cairo_region_t * (* get_damage) (GdkGLContext *context);
+
+ gboolean (* is_compatible) (GdkGLContext *self,
+ GdkGLContext *other);
};
typedef struct {
diff --git a/gsk/gl/gskgldriver.c b/gsk/gl/gskgldriver.c
index 621c25825c..bd6530c601 100644
--- a/gsk/gl/gskgldriver.c
+++ b/gsk/gl/gskgldriver.c
@@ -518,14 +518,12 @@ gsk_gl_driver_get_texture_for_texture (GskGLDriver *self,
if (GDK_IS_GL_TEXTURE (texture))
{
- GdkGLContext *texture_context = gdk_gl_texture_get_context ((GdkGLTexture *)texture);
- GdkGLContext *shared_context = gdk_gl_context_get_shared_context (self->gl_context);
+ GdkGLContext *texture_context = gdk_gl_texture_get_context (GDK_GL_TEXTURE (texture));
- if (texture_context == self->gl_context ||
- (gdk_gl_context_get_shared_context (texture_context) == shared_context && shared_context != NULL))
+ if (gdk_gl_context_is_compatible (self->gl_context, texture_context))
{
/* A GL texture from the same GL context is a simple task... */
- return gdk_gl_texture_get_id ((GdkGLTexture *)texture);
+ return gdk_gl_texture_get_id (GDK_GL_TEXTURE (texture));
}
else
{
diff --git a/gsk/ngl/gskngldriver.c b/gsk/ngl/gskngldriver.c
index ec7cdf7bb7..c9b61ee6af 100644
--- a/gsk/ngl/gskngldriver.c
+++ b/gsk/ngl/gskngldriver.c
@@ -736,16 +736,12 @@ gsk_ngl_driver_load_texture (GskNglDriver *self,
if (GDK_IS_GL_TEXTURE (texture))
{
- GdkGLContext *texture_context = gdk_gl_texture_get_context ((GdkGLTexture *)texture);
- GdkGLContext *shared_context = gdk_gl_context_get_shared_context (context);
-
- if (texture_context == context ||
- (shared_context != NULL &&
- shared_context == gdk_gl_context_get_shared_context (texture_context)))
+ GdkGLContext *texture_context = gdk_gl_texture_get_context (GDK_GL_TEXTURE (texture));
+ if (gdk_gl_context_is_compatible (context, texture_context))
{
/* A GL texture from the same GL context is a simple task... */
- return gdk_gl_texture_get_id ((GdkGLTexture *)texture);
+ return gdk_gl_texture_get_id (GDK_GL_TEXTURE (texture));
}
else
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]