mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-25 21:21:21 +00:00
gsk: Change gsk_renderer_realize()
Instead of having a gsk_renderer_set_window() call, pass the window to realize(). This way, the realization can fail with the wrong window. Signed-off-by: Emmanuele Bassi <ebassi@gnome.org>
This commit is contained in:
parent
efd04b47aa
commit
ce98df881f
@ -5,7 +5,6 @@ gsk_renderer_set_viewport
|
||||
gsk_renderer_get_viewport
|
||||
gsk_renderer_set_scale_factor
|
||||
gsk_renderer_get_scale_factor
|
||||
gsk_renderer_set_window
|
||||
gsk_renderer_get_window
|
||||
gsk_renderer_get_display
|
||||
gsk_renderer_realize
|
||||
|
@ -34,7 +34,8 @@ struct _GskCairoRendererClass
|
||||
G_DEFINE_TYPE (GskCairoRenderer, gsk_cairo_renderer, GSK_TYPE_RENDERER)
|
||||
|
||||
static gboolean
|
||||
gsk_cairo_renderer_realize (GskRenderer *renderer)
|
||||
gsk_cairo_renderer_realize (GskRenderer *renderer,
|
||||
GdkWindow *window)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -278,7 +278,8 @@ gsk_gl_renderer_destroy_programs (GskGLRenderer *self)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gsk_gl_renderer_realize (GskRenderer *renderer)
|
||||
gsk_gl_renderer_realize (GskRenderer *renderer,
|
||||
GdkWindow *window)
|
||||
{
|
||||
GskGLRenderer *self = GSK_GL_RENDERER (renderer);
|
||||
GError *error = NULL;
|
||||
@ -288,11 +289,6 @@ gsk_gl_renderer_realize (GskRenderer *renderer)
|
||||
*/
|
||||
if (self->gl_context == NULL)
|
||||
{
|
||||
GdkWindow *window = gsk_renderer_get_window (renderer);
|
||||
|
||||
if (window == NULL)
|
||||
return FALSE;
|
||||
|
||||
self->gl_context = gdk_window_create_gl_context (window, &error);
|
||||
if (error != NULL)
|
||||
{
|
||||
|
@ -97,7 +97,8 @@ static GParamSpec *gsk_renderer_properties[N_PROPS];
|
||||
g_critical ("Renderer of type '%s' does not implement GskRenderer::" # method, G_OBJECT_TYPE_NAME (obj))
|
||||
|
||||
static gboolean
|
||||
gsk_renderer_real_realize (GskRenderer *self)
|
||||
gsk_renderer_real_realize (GskRenderer *self,
|
||||
GdkWindow *window)
|
||||
{
|
||||
GSK_RENDERER_WARN_NOT_IMPLEMENTED_METHOD (self, realize);
|
||||
return FALSE;
|
||||
@ -145,7 +146,6 @@ gsk_renderer_dispose (GObject *gobject)
|
||||
g_clear_pointer (&priv->cairo_context, cairo_destroy);
|
||||
|
||||
g_clear_object (&priv->profiler);
|
||||
g_clear_object (&priv->window);
|
||||
g_clear_object (&priv->display);
|
||||
|
||||
G_OBJECT_CLASS (gsk_renderer_parent_class)->dispose (gobject);
|
||||
@ -170,10 +170,6 @@ gsk_renderer_set_property (GObject *gobject,
|
||||
gsk_renderer_set_scale_factor (self, g_value_get_int (value));
|
||||
break;
|
||||
|
||||
case PROP_WINDOW:
|
||||
gsk_renderer_set_window (self, g_value_get_object (value));
|
||||
break;
|
||||
|
||||
case PROP_DISPLAY:
|
||||
/* Construct-only */
|
||||
priv->display = g_value_dup_object (value);
|
||||
@ -431,34 +427,12 @@ gsk_renderer_get_scale_factor (GskRenderer *renderer)
|
||||
return priv->scale_factor;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_renderer_set_window:
|
||||
* @renderer: a #GskRenderer
|
||||
* @window: the window to set
|
||||
*
|
||||
* Sets the window on which the @renderer is rendering.
|
||||
*
|
||||
* Since: 3.90
|
||||
*/
|
||||
void
|
||||
gsk_renderer_set_window (GskRenderer *renderer,
|
||||
GdkWindow *window)
|
||||
{
|
||||
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
|
||||
|
||||
g_return_if_fail (GSK_IS_RENDERER (renderer));
|
||||
g_return_if_fail (!priv->is_realized);
|
||||
g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
|
||||
|
||||
if (g_set_object (&priv->window, window))
|
||||
g_object_notify_by_pspec (G_OBJECT (renderer), gsk_renderer_properties[PROP_WINDOW]);
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_renderer_get_window:
|
||||
* @renderer: a #GskRenderer
|
||||
*
|
||||
* Retrieves the #GdkWindow set using gsk_renderer_set_window().
|
||||
* Retrieves the #GdkWindow set using gsk_renderer_realize(). If the renderer
|
||||
* has not been realized yet, %NULL will be returned.
|
||||
*
|
||||
* Returns: (transfer none) (nullable): a #GdkWindow
|
||||
*
|
||||
@ -553,6 +527,7 @@ gsk_renderer_is_realized (GskRenderer *renderer)
|
||||
/**
|
||||
* gsk_renderer_realize:
|
||||
* @renderer: a #GskRenderer
|
||||
* @window: the #GdkWindow renderer will be used on
|
||||
*
|
||||
* Creates the resources needed by the @renderer to render the scene
|
||||
* graph.
|
||||
@ -560,18 +535,25 @@ gsk_renderer_is_realized (GskRenderer *renderer)
|
||||
* Since: 3.90
|
||||
*/
|
||||
gboolean
|
||||
gsk_renderer_realize (GskRenderer *renderer)
|
||||
gsk_renderer_realize (GskRenderer *renderer,
|
||||
GdkWindow *window)
|
||||
{
|
||||
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
|
||||
|
||||
g_return_val_if_fail (GSK_IS_RENDERER (renderer), FALSE);
|
||||
g_return_val_if_fail (!gsk_renderer_is_realized (renderer), FALSE);
|
||||
g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
|
||||
|
||||
if (priv->is_realized)
|
||||
return TRUE;
|
||||
priv->window = g_object_ref (window);
|
||||
|
||||
priv->is_realized = GSK_RENDERER_GET_CLASS (renderer)->realize (renderer);
|
||||
if (!GSK_RENDERER_GET_CLASS (renderer)->realize (renderer, window))
|
||||
{
|
||||
g_clear_object (&priv->window);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return priv->is_realized;
|
||||
priv->is_realized = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -815,13 +797,12 @@ gsk_renderer_create_fallback (GskRenderer *renderer,
|
||||
|
||||
res = g_object_new (GSK_TYPE_CAIRO_RENDERER,
|
||||
"display", priv->display,
|
||||
"window", priv->window,
|
||||
"scale-factor", priv->scale_factor,
|
||||
"viewport", viewport,
|
||||
NULL);
|
||||
|
||||
gsk_renderer_set_cairo_context (res, cr);
|
||||
gsk_renderer_realize (res);
|
||||
gsk_renderer_realize (res, priv->window);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -62,7 +62,8 @@ GDK_AVAILABLE_IN_3_90
|
||||
GdkDisplay * gsk_renderer_get_display (GskRenderer *renderer);
|
||||
|
||||
GDK_AVAILABLE_IN_3_90
|
||||
gboolean gsk_renderer_realize (GskRenderer *renderer);
|
||||
gboolean gsk_renderer_realize (GskRenderer *renderer,
|
||||
GdkWindow *window);
|
||||
GDK_AVAILABLE_IN_3_90
|
||||
void gsk_renderer_unrealize (GskRenderer *renderer);
|
||||
|
||||
|
@ -37,7 +37,8 @@ struct _GskRendererClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
|
||||
gboolean (* realize) (GskRenderer *renderer);
|
||||
gboolean (* realize) (GskRenderer *renderer,
|
||||
GdkWindow *window);
|
||||
void (* unrealize) (GskRenderer *renderer);
|
||||
|
||||
void (* render) (GskRenderer *renderer,
|
||||
|
@ -6910,8 +6910,7 @@ gtk_window_realize (GtkWidget *widget)
|
||||
popover_realize (popover->widget, popover, window);
|
||||
}
|
||||
|
||||
gsk_renderer_set_window (priv->renderer, gdk_window);
|
||||
gsk_renderer_realize (priv->renderer);
|
||||
gsk_renderer_realize (priv->renderer, gdk_window);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -7109,8 +7108,7 @@ gtk_window_realize (GtkWidget *widget)
|
||||
check_scale_changed (window);
|
||||
|
||||
/* Renderer */
|
||||
gsk_renderer_set_window (priv->renderer, gdk_window);
|
||||
gsk_renderer_realize (priv->renderer);
|
||||
gsk_renderer_realize (priv->renderer, gdk_window);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user