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
@ -35,7 +35,8 @@ G_DEFINE_TYPE (GskCairoRenderer, gsk_cairo_renderer, GSK_TYPE_RENDERER)
|
|||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gsk_cairo_renderer_realize (GskRenderer *renderer,
|
gsk_cairo_renderer_realize (GskRenderer *renderer,
|
||||||
GdkWindow *window)
|
GdkWindow *window,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -187,10 +187,11 @@ gsk_gl_renderer_destroy_buffers (GskGLRenderer *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gsk_gl_renderer_create_programs (GskGLRenderer *self)
|
gsk_gl_renderer_create_programs (GskGLRenderer *self,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
GskShaderBuilder *builder;
|
GskShaderBuilder *builder;
|
||||||
GError *error = NULL;
|
GError *shader_error = NULL;
|
||||||
gboolean res = FALSE;
|
gboolean res = FALSE;
|
||||||
|
|
||||||
builder = gsk_shader_builder_new ();
|
builder = gsk_shader_builder_new ();
|
||||||
@ -241,21 +242,23 @@ gsk_gl_renderer_create_programs (GskGLRenderer *self)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
self->blend_program_id =
|
self->blend_program_id =
|
||||||
gsk_shader_builder_create_program (builder, "blend.vs.glsl", "blend.fs.glsl", &error);
|
gsk_shader_builder_create_program (builder, "blend.vs.glsl", "blend.fs.glsl", &shader_error);
|
||||||
if (error != NULL)
|
if (shader_error != NULL)
|
||||||
{
|
{
|
||||||
g_critical ("Unable to create 'blend' program: %s", error->message);
|
g_propagate_prefixed_error (error,
|
||||||
g_error_free (error);
|
shader_error,
|
||||||
|
"Unable to create 'blend' program: ");
|
||||||
g_object_unref (builder);
|
g_object_unref (builder);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
self->blit_program_id =
|
self->blit_program_id =
|
||||||
gsk_shader_builder_create_program (builder, "blit.vs.glsl", "blit.fs.glsl", &error);
|
gsk_shader_builder_create_program (builder, "blit.vs.glsl", "blit.fs.glsl", &shader_error);
|
||||||
if (error != NULL)
|
if (shader_error != NULL)
|
||||||
{
|
{
|
||||||
g_critical ("Unable to create 'blit' program: %s", error->message);
|
g_propagate_prefixed_error (error,
|
||||||
g_error_free (error);
|
shader_error,
|
||||||
|
"Unable to create 'blit' program: ");
|
||||||
g_object_unref (builder);
|
g_object_unref (builder);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -279,34 +282,23 @@ gsk_gl_renderer_destroy_programs (GskGLRenderer *self)
|
|||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gsk_gl_renderer_realize (GskRenderer *renderer,
|
gsk_gl_renderer_realize (GskRenderer *renderer,
|
||||||
GdkWindow *window)
|
GdkWindow *window,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
GskGLRenderer *self = GSK_GL_RENDERER (renderer);
|
GskGLRenderer *self = GSK_GL_RENDERER (renderer);
|
||||||
GError *error = NULL;
|
|
||||||
|
|
||||||
/* If we didn't get a GdkGLContext before realization, try creating
|
/* If we didn't get a GdkGLContext before realization, try creating
|
||||||
* one now, for our exclusive use.
|
* one now, for our exclusive use.
|
||||||
*/
|
*/
|
||||||
if (self->gl_context == NULL)
|
if (self->gl_context == NULL)
|
||||||
{
|
{
|
||||||
self->gl_context = gdk_window_create_gl_context (window, &error);
|
self->gl_context = gdk_window_create_gl_context (window, error);
|
||||||
if (error != NULL)
|
if (self->gl_context == NULL)
|
||||||
{
|
|
||||||
g_critical ("Unable to create GL context for renderer: %s",
|
|
||||||
error->message);
|
|
||||||
g_error_free (error);
|
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
gdk_gl_context_realize (self->gl_context, &error);
|
if (!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;
|
return FALSE;
|
||||||
}
|
|
||||||
|
|
||||||
gdk_gl_context_make_current (self->gl_context);
|
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);
|
self->gl_profiler = gsk_gl_profiler_new (self->gl_context);
|
||||||
|
|
||||||
GSK_NOTE (OPENGL, g_print ("Creating buffers and programs\n"));
|
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 FALSE;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -98,7 +98,8 @@ static GParamSpec *gsk_renderer_properties[N_PROPS];
|
|||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gsk_renderer_real_realize (GskRenderer *self,
|
gsk_renderer_real_realize (GskRenderer *self,
|
||||||
GdkWindow *window)
|
GdkWindow *window,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
GSK_RENDERER_WARN_NOT_IMPLEMENTED_METHOD (self, realize);
|
GSK_RENDERER_WARN_NOT_IMPLEMENTED_METHOD (self, realize);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -528,6 +529,7 @@ gsk_renderer_is_realized (GskRenderer *renderer)
|
|||||||
* gsk_renderer_realize:
|
* gsk_renderer_realize:
|
||||||
* @renderer: a #GskRenderer
|
* @renderer: a #GskRenderer
|
||||||
* @window: the #GdkWindow renderer will be used on
|
* @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
|
* Creates the resources needed by the @renderer to render the scene
|
||||||
* graph.
|
* graph.
|
||||||
@ -536,17 +538,19 @@ gsk_renderer_is_realized (GskRenderer *renderer)
|
|||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
gsk_renderer_realize (GskRenderer *renderer,
|
gsk_renderer_realize (GskRenderer *renderer,
|
||||||
GdkWindow *window)
|
GdkWindow *window,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
|
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
|
||||||
|
|
||||||
g_return_val_if_fail (GSK_IS_RENDERER (renderer), FALSE);
|
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 (!gsk_renderer_is_realized (renderer), FALSE);
|
||||||
g_return_val_if_fail (GDK_IS_WINDOW (window), 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);
|
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);
|
g_clear_object (&priv->window);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -750,6 +754,7 @@ gsk_renderer_new_for_window (GdkWindow *window)
|
|||||||
{
|
{
|
||||||
GType renderer_type;
|
GType renderer_type;
|
||||||
GskRenderer *renderer;
|
GskRenderer *renderer;
|
||||||
|
GError *error = NULL;
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
|
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),
|
"display", gdk_window_get_display (window),
|
||||||
NULL);
|
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",
|
GSK_NOTE (RENDERER, g_print ("Using renderer of type '%s' for display '%s'\n",
|
||||||
G_OBJECT_TYPE_NAME (renderer),
|
G_OBJECT_TYPE_NAME (renderer),
|
||||||
@ -772,10 +777,12 @@ gsk_renderer_new_for_window (GdkWindow *window)
|
|||||||
return renderer;
|
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 (renderer),
|
||||||
G_OBJECT_TYPE_NAME (window)));
|
G_OBJECT_TYPE_NAME (window),
|
||||||
|
error->message));
|
||||||
g_object_unref (renderer);
|
g_object_unref (renderer);
|
||||||
|
g_clear_error (&error);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
@ -850,7 +857,7 @@ gsk_renderer_create_fallback (GskRenderer *renderer,
|
|||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
gsk_renderer_set_cairo_context (res, cr);
|
gsk_renderer_set_cairo_context (res, cr);
|
||||||
gsk_renderer_realize (res, priv->window);
|
gsk_renderer_realize (res, priv->window, NULL);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,8 @@ GdkDisplay * gsk_renderer_get_display (GskRenderer
|
|||||||
|
|
||||||
GDK_AVAILABLE_IN_3_90
|
GDK_AVAILABLE_IN_3_90
|
||||||
gboolean gsk_renderer_realize (GskRenderer *renderer,
|
gboolean gsk_renderer_realize (GskRenderer *renderer,
|
||||||
GdkWindow *window);
|
GdkWindow *window,
|
||||||
|
GError **error);
|
||||||
GDK_AVAILABLE_IN_3_90
|
GDK_AVAILABLE_IN_3_90
|
||||||
void gsk_renderer_unrealize (GskRenderer *renderer);
|
void gsk_renderer_unrealize (GskRenderer *renderer);
|
||||||
|
|
||||||
|
@ -38,7 +38,8 @@ struct _GskRendererClass
|
|||||||
GObjectClass parent_class;
|
GObjectClass parent_class;
|
||||||
|
|
||||||
gboolean (* realize) (GskRenderer *renderer,
|
gboolean (* realize) (GskRenderer *renderer,
|
||||||
GdkWindow *window);
|
GdkWindow *window,
|
||||||
|
GError **error);
|
||||||
void (* unrealize) (GskRenderer *renderer);
|
void (* unrealize) (GskRenderer *renderer);
|
||||||
|
|
||||||
void (* render) (GskRenderer *renderer,
|
void (* render) (GskRenderer *renderer,
|
||||||
|
Loading…
Reference in New Issue
Block a user