From 318e19f570369a1beaabc76b7ca3b018e985f13d Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Tue, 29 Nov 2016 04:51:07 +0100 Subject: [PATCH] gskrenderer: Add GError argument to gsk_renderer_realize() This way, we don't spam criticals when GL is not available. Instead, we print a useful debug message to stderr and continue with the Cairo renderer. Signed-off-by: Emmanuele Bassi --- gsk/gskcairorenderer.c | 5 ++-- gsk/gskglrenderer.c | 52 +++++++++++++++++----------------------- gsk/gskrenderer.c | 25 ++++++++++++------- gsk/gskrenderer.h | 3 ++- gsk/gskrendererprivate.h | 3 ++- 5 files changed, 45 insertions(+), 43 deletions(-) diff --git a/gsk/gskcairorenderer.c b/gsk/gskcairorenderer.c index 9c9929c7b2..4c9dfef803 100644 --- a/gsk/gskcairorenderer.c +++ b/gsk/gskcairorenderer.c @@ -34,8 +34,9 @@ struct _GskCairoRendererClass G_DEFINE_TYPE (GskCairoRenderer, gsk_cairo_renderer, GSK_TYPE_RENDERER) static gboolean -gsk_cairo_renderer_realize (GskRenderer *renderer, - GdkWindow *window) +gsk_cairo_renderer_realize (GskRenderer *renderer, + GdkWindow *window, + GError **error) { return TRUE; } diff --git a/gsk/gskglrenderer.c b/gsk/gskglrenderer.c index 1df501a19f..853f690149 100644 --- a/gsk/gskglrenderer.c +++ b/gsk/gskglrenderer.c @@ -187,10 +187,11 @@ gsk_gl_renderer_destroy_buffers (GskGLRenderer *self) } static gboolean -gsk_gl_renderer_create_programs (GskGLRenderer *self) +gsk_gl_renderer_create_programs (GskGLRenderer *self, + GError **error) { GskShaderBuilder *builder; - GError *error = NULL; + GError *shader_error = NULL; gboolean res = FALSE; builder = gsk_shader_builder_new (); @@ -241,21 +242,23 @@ gsk_gl_renderer_create_programs (GskGLRenderer *self) #endif self->blend_program_id = - gsk_shader_builder_create_program (builder, "blend.vs.glsl", "blend.fs.glsl", &error); - if (error != NULL) + gsk_shader_builder_create_program (builder, "blend.vs.glsl", "blend.fs.glsl", &shader_error); + if (shader_error != NULL) { - g_critical ("Unable to create 'blend' program: %s", error->message); - g_error_free (error); + g_propagate_prefixed_error (error, + shader_error, + "Unable to create 'blend' program: "); g_object_unref (builder); goto out; } self->blit_program_id = - gsk_shader_builder_create_program (builder, "blit.vs.glsl", "blit.fs.glsl", &error); - if (error != NULL) + gsk_shader_builder_create_program (builder, "blit.vs.glsl", "blit.fs.glsl", &shader_error); + if (shader_error != NULL) { - g_critical ("Unable to create 'blit' program: %s", error->message); - g_error_free (error); + g_propagate_prefixed_error (error, + shader_error, + "Unable to create 'blit' program: "); g_object_unref (builder); goto out; } @@ -278,35 +281,24 @@ gsk_gl_renderer_destroy_programs (GskGLRenderer *self) } static gboolean -gsk_gl_renderer_realize (GskRenderer *renderer, - GdkWindow *window) +gsk_gl_renderer_realize (GskRenderer *renderer, + GdkWindow *window, + GError **error) { GskGLRenderer *self = GSK_GL_RENDERER (renderer); - GError *error = NULL; /* If we didn't get a GdkGLContext before realization, try creating * one now, for our exclusive use. */ if (self->gl_context == NULL) { - self->gl_context = gdk_window_create_gl_context (window, &error); - if (error != NULL) - { - g_critical ("Unable to create GL context for renderer: %s", - error->message); - g_error_free (error); - - return FALSE; - } + self->gl_context = gdk_window_create_gl_context (window, error); + if (self->gl_context == NULL) + return FALSE; } - gdk_gl_context_realize (self->gl_context, &error); - if (error != NULL) - { - g_critical ("Unable to realize GL renderer: %s", error->message); - g_error_free (error); - return FALSE; - } + if (!gdk_gl_context_realize (self->gl_context, error)) + return FALSE; gdk_gl_context_make_current (self->gl_context); @@ -315,7 +307,7 @@ gsk_gl_renderer_realize (GskRenderer *renderer, self->gl_profiler = gsk_gl_profiler_new (self->gl_context); GSK_NOTE (OPENGL, g_print ("Creating buffers and programs\n")); - if (!gsk_gl_renderer_create_programs (self)) + if (!gsk_gl_renderer_create_programs (self, error)) return FALSE; return TRUE; diff --git a/gsk/gskrenderer.c b/gsk/gskrenderer.c index 629551cacf..86e262ca3d 100644 --- a/gsk/gskrenderer.c +++ b/gsk/gskrenderer.c @@ -97,8 +97,9 @@ 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, - GdkWindow *window) +gsk_renderer_real_realize (GskRenderer *self, + GdkWindow *window, + GError **error) { GSK_RENDERER_WARN_NOT_IMPLEMENTED_METHOD (self, realize); return FALSE; @@ -528,6 +529,7 @@ gsk_renderer_is_realized (GskRenderer *renderer) * gsk_renderer_realize: * @renderer: a #GskRenderer * @window: the #GdkWindow renderer will be used on + * @error: return location for an error * * Creates the resources needed by the @renderer to render the scene * graph. @@ -535,18 +537,20 @@ gsk_renderer_is_realized (GskRenderer *renderer) * Since: 3.90 */ gboolean -gsk_renderer_realize (GskRenderer *renderer, - GdkWindow *window) +gsk_renderer_realize (GskRenderer *renderer, + GdkWindow *window, + GError **error) { 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); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); priv->window = g_object_ref (window); - if (!GSK_RENDERER_GET_CLASS (renderer)->realize (renderer, window)) + if (!GSK_RENDERER_GET_CLASS (renderer)->realize (renderer, window, error)) { g_clear_object (&priv->window); return FALSE; @@ -750,6 +754,7 @@ gsk_renderer_new_for_window (GdkWindow *window) { GType renderer_type; GskRenderer *renderer; + GError *error = NULL; guint i; g_return_val_if_fail (GDK_IS_WINDOW (window), NULL); @@ -764,7 +769,7 @@ gsk_renderer_new_for_window (GdkWindow *window) "display", gdk_window_get_display (window), NULL); - if (gsk_renderer_realize (renderer, window)) + if (gsk_renderer_realize (renderer, window, &error)) { GSK_NOTE (RENDERER, g_print ("Using renderer of type '%s' for display '%s'\n", G_OBJECT_TYPE_NAME (renderer), @@ -772,10 +777,12 @@ gsk_renderer_new_for_window (GdkWindow *window) return renderer; } - GSK_NOTE (RENDERER, g_print ("Failed to realize renderer of type '%s' for window '%s'\n", + GSK_NOTE (RENDERER, g_print ("Failed to realize renderer of type '%s' for window '%s': %s\n", G_OBJECT_TYPE_NAME (renderer), - G_OBJECT_TYPE_NAME (window))); + G_OBJECT_TYPE_NAME (window), + error->message)); g_object_unref (renderer); + g_clear_error (&error); } g_assert_not_reached (); @@ -850,7 +857,7 @@ gsk_renderer_create_fallback (GskRenderer *renderer, NULL); gsk_renderer_set_cairo_context (res, cr); - gsk_renderer_realize (res, priv->window); + gsk_renderer_realize (res, priv->window, NULL); return res; } diff --git a/gsk/gskrenderer.h b/gsk/gskrenderer.h index 646ba6dedd..722259f4b9 100644 --- a/gsk/gskrenderer.h +++ b/gsk/gskrenderer.h @@ -63,7 +63,8 @@ GdkDisplay * gsk_renderer_get_display (GskRenderer GDK_AVAILABLE_IN_3_90 gboolean gsk_renderer_realize (GskRenderer *renderer, - GdkWindow *window); + GdkWindow *window, + GError **error); GDK_AVAILABLE_IN_3_90 void gsk_renderer_unrealize (GskRenderer *renderer); diff --git a/gsk/gskrendererprivate.h b/gsk/gskrendererprivate.h index 41064fb6ca..eae8412445 100644 --- a/gsk/gskrendererprivate.h +++ b/gsk/gskrendererprivate.h @@ -38,7 +38,8 @@ struct _GskRendererClass GObjectClass parent_class; gboolean (* realize) (GskRenderer *renderer, - GdkWindow *window); + GdkWindow *window, + GError **error); void (* unrealize) (GskRenderer *renderer); void (* render) (GskRenderer *renderer,