From: Benjamin Otte Date: Sun, 4 Jul 2021 00:43:49 +0000 (+0200) Subject: gdk: Allow GdkDrawContext with a %NULL surface X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2~3^2~9^2~23 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=01e9fa9adb8184a778ed70e41f2dbfe9049b83d5;p=gtk4.git gdk: Allow GdkDrawContext with a %NULL surface This is not used yet, but it allows surfaceless GL contexts. For that purpose, we need to make the display a construct-only property, so that it can be set when the surface isn't. This adds a bunch of very picky checks in the constructor so nothing bad can happen. --- diff --git a/gdk/gdkdrawcontext.c b/gdk/gdkdrawcontext.c index d377c227a2..d1c5cd0960 100644 --- a/gdk/gdkdrawcontext.c +++ b/gdk/gdkdrawcontext.c @@ -43,6 +43,7 @@ typedef struct _GdkDrawContextPrivate GdkDrawContextPrivate; struct _GdkDrawContextPrivate { + GdkDisplay *display; GdkSurface *surface; cairo_region_t *frame_region; @@ -77,6 +78,7 @@ gdk_draw_context_dispose (GObject *gobject) priv->surface->draw_contexts = g_slist_remove (priv->surface->draw_contexts, context); g_clear_object (&priv->surface); } + g_clear_object (&priv->display); G_OBJECT_CLASS (gdk_draw_context_parent_class)->dispose (gobject); } @@ -92,10 +94,31 @@ gdk_draw_context_set_property (GObject *gobject, switch (prop_id) { + case PROP_DISPLAY: + if (priv->display != NULL) + { + g_assert (g_value_get_object (value) == NULL); + } + else + { + priv->display = g_value_dup_object (value); + } + break; + case PROP_SURFACE: priv->surface = g_value_dup_object (value); - g_assert (priv->surface != NULL); - priv->surface->draw_contexts = g_slist_prepend (priv->surface->draw_contexts, context); + if (priv->surface) + { + priv->surface->draw_contexts = g_slist_prepend (priv->surface->draw_contexts, context); + if (priv->display) + { + g_assert (priv->display == gdk_surface_get_display (priv->surface)); + } + else + { + priv->display = g_object_ref (gdk_surface_get_display (priv->surface)); + } + } break; default: @@ -148,7 +171,8 @@ gdk_draw_context_class_init (GdkDrawContextClass *klass) P_("Display"), P_("The GDK display used to create the context"), GDK_TYPE_DISPLAY, - G_PARAM_READABLE | + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); /** @@ -228,7 +252,7 @@ gdk_draw_context_get_display (GdkDrawContext *context) g_return_val_if_fail (GDK_IS_DRAW_CONTEXT (context), NULL); - return priv->surface ? gdk_surface_get_display (priv->surface) : NULL; + return priv->display; } /**