gsk: Add fallback code to renderers

This code makes renderers fall back to Cairo rendering if they don't
know how to handle a render node's type.

This allows adding new render nodes with impunity.
This commit is contained in:
Benjamin Otte 2016-12-13 04:20:04 +01:00
parent 6129daf29b
commit ee9aca882d
2 changed files with 39 additions and 3 deletions

View File

@ -760,8 +760,40 @@ gsk_gl_renderer_add_render_item (GskGLRenderer *self,
return;
case GSK_NOT_A_RENDER_NODE:
default:
g_assert_not_reached ();
return;
default:
{
graphene_rect_t bounds;
cairo_surface_t *surface;
cairo_t *cr;
gsk_render_node_get_bounds (node, &bounds);
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
ceil (bounds.size.width),
ceil (bounds.size.height));
cr = cairo_create (surface);
cairo_translate (cr, -bounds.origin.x, -bounds.origin.y);
gsk_render_node_draw (node, cr);
cairo_destroy (cr);
/* Upload the Cairo surface to a GL texture */
item.render_data.texture_id = gsk_gl_driver_create_texture (self->gl_driver,
item.size.width,
item.size.height);
gsk_gl_driver_bind_source_texture (self->gl_driver, item.render_data.texture_id);
gsk_gl_driver_init_texture_with_surface (self->gl_driver,
item.render_data.texture_id,
surface,
GL_NEAREST, GL_NEAREST);
cairo_surface_destroy (surface);
}
break;
}
/* Create the vertex buffers holding the geometry of the quad */

View File

@ -72,10 +72,14 @@ gsk_vulkan_render_pass_add_node (GskVulkanRenderPass *self,
switch (gsk_render_node_get_node_type (node))
{
case GSK_NOT_A_RENDER_NODE:
default:
g_assert_not_reached ();
break;
default:
op.type = GSK_VULKAN_OP_FALLBACK;
g_array_append_val (self->render_ops, op);
break;
case GSK_CAIRO_NODE:
op.type = GSK_VULKAN_OP_SURFACE;
g_array_append_val (self->render_ops, op);
@ -150,7 +154,7 @@ gsk_vulkan_render_pass_upload_fallback (GskVulkanRenderPass *self,
ceil (bounds.size.width),
ceil (bounds.size.height));
cr = cairo_create (surface);
cairo_translate (cr, bounds.origin.x, bounds.origin.y);
cairo_translate (cr, -bounds.origin.x, -bounds.origin.y);
gsk_render_node_draw (op->node, cr);