forked from AuroraMiddleware/gtk
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 <ebassi@gnome.org>
This commit is contained in:
parent
5563841603
commit
318e19f570
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user