diff options
author | Benjamin Otte <otte@redhat.com> | 2016-12-21 20:23:46 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2016-12-23 08:11:01 +0100 |
commit | 373e08d6d4ea35dbc937a012ef864fd36bb6e42d (patch) | |
tree | 9bca39da5924d122a3bac7fa50a1c754ce5fecd5 /gsk/gskrenderer.c | |
parent | 98086014d85ea60862c3cb0598e7b6c8cf7fb072 (diff) | |
download | gtk+-373e08d6d4ea35dbc937a012ef864fd36bb6e42d.tar.gz |
gsk: Add gsk_renderer_render_texture()
... and implement it for the Cairo renderer.
It's an API that instructs a renderer to render to a texture.
So far this is mostly meant to be used for testing, but I could imagine
it being useful for rendering DND icons.
Diffstat (limited to 'gsk/gskrenderer.c')
-rw-r--r-- | gsk/gskrenderer.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/gsk/gskrenderer.c b/gsk/gskrenderer.c index b50ebd7f56..87a4074735 100644 --- a/gsk/gskrenderer.c +++ b/gsk/gskrenderer.c @@ -113,6 +113,15 @@ gsk_renderer_real_unrealize (GskRenderer *self) GSK_RENDERER_WARN_NOT_IMPLEMENTED_METHOD (self, unrealize); } +static GskTexture * +gsk_renderer_real_render_texture (GskRenderer *self, + GskRenderNode *root, + const graphene_rect_t *viewport) +{ + GSK_RENDERER_WARN_NOT_IMPLEMENTED_METHOD (self, render_texture); + return NULL; +} + static GdkDrawingContext * gsk_renderer_real_begin_draw_frame (GskRenderer *self, const cairo_region_t *region) @@ -259,6 +268,7 @@ gsk_renderer_class_init (GskRendererClass *klass) klass->begin_draw_frame = gsk_renderer_real_begin_draw_frame; klass->end_draw_frame = gsk_renderer_real_end_draw_frame; klass->render = gsk_renderer_real_render; + klass->render_texture = gsk_renderer_real_render_texture; klass->create_cairo_surface = gsk_renderer_real_create_cairo_surface; gobject_class->constructed = gsk_renderer_constructed; @@ -607,6 +617,76 @@ gsk_renderer_unrealize (GskRenderer *renderer) } /** + * gsk_renderer_render_texture: + * @renderer: a realized #GdkRenderer + * @root: a #GskRenderNode + * @viewport: (allow-none): the section to draw or %NULL to use @root's bounds + * + * Renders the scene graph, described by a tree of #GskRenderNode instances, + * to a #GskTexture. + * + * The @renderer will acquire a reference on the #GskRenderNode tree while + * the rendering is in progress, and will make the tree immutable. + * + * If you want to apply any transformations to @root, you should put it into a + * transform node and pass that node instead. + * + * Returns: (transfer full): a #GskTexture with the rendered contents of @root. + * + * Since: 3.90 + */ +GskTexture * +gsk_renderer_render_texture (GskRenderer *renderer, + GskRenderNode *root, + const graphene_rect_t *viewport) +{ + GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer); + graphene_rect_t real_viewport; + GskTexture *texture; + + g_return_val_if_fail (GSK_IS_RENDERER (renderer), NULL); + g_return_val_if_fail (priv->is_realized, NULL); + g_return_val_if_fail (GSK_IS_RENDER_NODE (root), NULL); + g_return_val_if_fail (priv->root_node == NULL, NULL); + + priv->root_node = gsk_render_node_ref (root); + gsk_render_node_make_immutable (priv->root_node); + + if (viewport == NULL) + { + gsk_render_node_get_bounds (root, &real_viewport); + viewport = &real_viewport; + } + +#ifdef G_ENABLE_DEBUG + gsk_profiler_reset (priv->profiler); +#endif + + texture = GSK_RENDERER_GET_CLASS (renderer)->render_texture (renderer, root, viewport); + +#ifdef G_ENABLE_DEBUG + if (GSK_DEBUG_CHECK (RENDERER)) + { + GString *buf = g_string_new ("*** Texture stats ***\n\n"); + + gsk_profiler_append_counters (priv->profiler, buf); + g_string_append_c (buf, '\n'); + + gsk_profiler_append_timers (priv->profiler, buf); + g_string_append_c (buf, '\n'); + + g_print ("%s\n***\n\n", buf->str); + + g_string_free (buf, TRUE); + } +#endif + + g_clear_pointer (&priv->root_node, gsk_render_node_unref); + + return texture; +} + +/** * gsk_renderer_render: * @renderer: a #GskRenderer * @root: a #GskRenderNode |