2016-12-11 01:59:47 +00:00
|
|
|
/* GSK - The GTK Scene Kit
|
|
|
|
*
|
|
|
|
* Copyright 2016 Endless
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gskrendernodeprivate.h"
|
|
|
|
|
|
|
|
#include "gskdebugprivate.h"
|
|
|
|
#include "gskrendererprivate.h"
|
|
|
|
#include "gsktexture.h"
|
|
|
|
|
|
|
|
/*** GSK_TEXTURE_NODE ***/
|
|
|
|
|
2016-12-11 03:28:21 +00:00
|
|
|
typedef struct _GskTextureNode GskTextureNode;
|
|
|
|
|
|
|
|
struct _GskTextureNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GskTexture *texture;
|
2016-12-12 05:29:04 +00:00
|
|
|
graphene_rect_t bounds;
|
2016-12-11 03:28:21 +00:00
|
|
|
};
|
|
|
|
|
2016-12-11 03:18:25 +00:00
|
|
|
static void
|
|
|
|
gsk_texture_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
2016-12-11 03:28:21 +00:00
|
|
|
GskTextureNode *self = (GskTextureNode *) node;
|
|
|
|
|
|
|
|
gsk_texture_unref (self->texture);
|
2016-12-11 03:18:25 +00:00
|
|
|
}
|
|
|
|
|
2016-12-11 10:53:17 +00:00
|
|
|
static void
|
|
|
|
gsk_texture_node_make_immutable (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-12-12 05:29:04 +00:00
|
|
|
static void
|
|
|
|
gsk_texture_node_get_bounds (GskRenderNode *node,
|
|
|
|
graphene_rect_t *bounds)
|
|
|
|
{
|
|
|
|
GskTextureNode *self = (GskTextureNode *) node;
|
|
|
|
|
|
|
|
graphene_rect_init_from_rect (bounds, &self->bounds);
|
|
|
|
}
|
|
|
|
|
2016-12-11 02:57:42 +00:00
|
|
|
static const GskRenderNodeClass GSK_TEXTURE_NODE_CLASS = {
|
|
|
|
GSK_TEXTURE_NODE,
|
2016-12-11 03:28:21 +00:00
|
|
|
sizeof (GskTextureNode),
|
2016-12-11 03:18:25 +00:00
|
|
|
"GskTextureNode",
|
2016-12-11 10:53:17 +00:00
|
|
|
gsk_texture_node_finalize,
|
2016-12-12 05:29:04 +00:00
|
|
|
gsk_texture_node_make_immutable,
|
|
|
|
gsk_texture_node_get_bounds
|
2016-12-11 02:57:42 +00:00
|
|
|
};
|
|
|
|
|
2016-12-11 01:59:47 +00:00
|
|
|
GskTexture *
|
|
|
|
gsk_texture_node_get_texture (GskRenderNode *node)
|
|
|
|
{
|
2016-12-11 03:28:21 +00:00
|
|
|
GskTextureNode *self = (GskTextureNode *) node;
|
|
|
|
|
2016-12-11 02:57:42 +00:00
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_TEXTURE_NODE), 0);
|
2016-12-11 01:59:47 +00:00
|
|
|
|
2016-12-11 03:28:21 +00:00
|
|
|
return self->texture;
|
2016-12-11 01:59:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_texture_node_new:
|
|
|
|
* @texture: the #GskTexture
|
|
|
|
* @bounds: the rectangle to render the texture into
|
|
|
|
*
|
|
|
|
* Creates a #GskRenderNode that will render the given
|
|
|
|
* @texture into the area given by @bounds.
|
|
|
|
*
|
|
|
|
* Returns: A new #GskRenderNode
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_texture_node_new (GskTexture *texture,
|
|
|
|
const graphene_rect_t *bounds)
|
|
|
|
{
|
2016-12-11 03:28:21 +00:00
|
|
|
GskTextureNode *self;
|
2016-12-11 01:59:47 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_TEXTURE (texture), NULL);
|
|
|
|
g_return_val_if_fail (bounds != NULL, NULL);
|
|
|
|
|
2016-12-12 05:29:04 +00:00
|
|
|
self = (GskTextureNode *) gsk_render_node_new (&GSK_TEXTURE_NODE_CLASS);
|
2016-12-11 01:59:47 +00:00
|
|
|
|
2016-12-11 03:28:21 +00:00
|
|
|
self->texture = gsk_texture_ref (texture);
|
2016-12-12 05:29:04 +00:00
|
|
|
graphene_rect_init_from_rect (&self->bounds, bounds);
|
2016-12-11 01:59:47 +00:00
|
|
|
|
2016-12-12 05:29:04 +00:00
|
|
|
return &self->render_node;
|
2016-12-11 01:59:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** GSK_CAIRO_NODE ***/
|
|
|
|
|
2016-12-11 03:28:21 +00:00
|
|
|
typedef struct _GskCairoNode GskCairoNode;
|
|
|
|
|
|
|
|
struct _GskCairoNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
cairo_surface_t *surface;
|
2016-12-12 05:29:04 +00:00
|
|
|
graphene_rect_t bounds;
|
2016-12-11 03:28:21 +00:00
|
|
|
};
|
|
|
|
|
2016-12-11 03:18:25 +00:00
|
|
|
static void
|
|
|
|
gsk_cairo_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
2016-12-11 03:28:21 +00:00
|
|
|
GskCairoNode *self = (GskCairoNode *) node;
|
|
|
|
|
|
|
|
if (self->surface)
|
|
|
|
cairo_surface_destroy (self->surface);
|
2016-12-11 03:18:25 +00:00
|
|
|
}
|
|
|
|
|
2016-12-11 10:53:17 +00:00
|
|
|
static void
|
|
|
|
gsk_cairo_node_make_immutable (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-12-12 05:29:04 +00:00
|
|
|
static void
|
|
|
|
gsk_cairo_node_get_bounds (GskRenderNode *node,
|
|
|
|
graphene_rect_t *bounds)
|
|
|
|
{
|
|
|
|
GskCairoNode *self = (GskCairoNode *) node;
|
|
|
|
|
|
|
|
graphene_rect_init_from_rect (bounds, &self->bounds);
|
|
|
|
}
|
|
|
|
|
2016-12-11 02:57:42 +00:00
|
|
|
static const GskRenderNodeClass GSK_CAIRO_NODE_CLASS = {
|
|
|
|
GSK_CAIRO_NODE,
|
2016-12-11 03:28:21 +00:00
|
|
|
sizeof (GskCairoNode),
|
2016-12-11 03:18:25 +00:00
|
|
|
"GskCairoNode",
|
2016-12-11 10:53:17 +00:00
|
|
|
gsk_cairo_node_finalize,
|
2016-12-12 05:29:04 +00:00
|
|
|
gsk_cairo_node_make_immutable,
|
|
|
|
gsk_cairo_node_get_bounds
|
2016-12-11 02:57:42 +00:00
|
|
|
};
|
|
|
|
|
2016-12-11 01:59:47 +00:00
|
|
|
/*< private >
|
|
|
|
* gsk_cairo_node_get_surface:
|
|
|
|
* @node: a #GskRenderNode
|
|
|
|
*
|
|
|
|
* Retrieves the surface set using gsk_render_node_set_surface().
|
|
|
|
*
|
|
|
|
* Returns: (transfer none) (nullable): a Cairo surface
|
|
|
|
*/
|
|
|
|
cairo_surface_t *
|
|
|
|
gsk_cairo_node_get_surface (GskRenderNode *node)
|
|
|
|
{
|
2016-12-11 03:28:21 +00:00
|
|
|
GskCairoNode *self = (GskCairoNode *) node;
|
|
|
|
|
2016-12-11 02:57:42 +00:00
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_CAIRO_NODE), NULL);
|
2016-12-11 01:59:47 +00:00
|
|
|
|
2016-12-11 03:28:21 +00:00
|
|
|
return self->surface;
|
2016-12-11 01:59:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_cairo_node_new:
|
|
|
|
* @bounds: the rectangle to render the to
|
|
|
|
*
|
|
|
|
* Creates a #GskRenderNode that will render a cairo surface
|
|
|
|
* into the area given by @bounds. You can draw to the cairo
|
|
|
|
* surface using gsk_cairo_node_get_draw_context()
|
|
|
|
*
|
|
|
|
* Returns: A new #GskRenderNode
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_cairo_node_new (const graphene_rect_t *bounds)
|
|
|
|
{
|
2016-12-12 05:29:04 +00:00
|
|
|
GskCairoNode *self;
|
2016-12-11 01:59:47 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (bounds != NULL, NULL);
|
|
|
|
|
2016-12-12 05:29:04 +00:00
|
|
|
self = (GskCairoNode *) gsk_render_node_new (&GSK_CAIRO_NODE_CLASS);
|
2016-12-11 01:59:47 +00:00
|
|
|
|
2016-12-12 05:29:04 +00:00
|
|
|
graphene_rect_init_from_rect (&self->bounds, bounds);
|
2016-12-11 01:59:47 +00:00
|
|
|
|
2016-12-12 05:29:04 +00:00
|
|
|
return &self->render_node;
|
2016-12-11 01:59:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_cairo_node_get_draw_context:
|
|
|
|
* @node: a cairo #GskRenderNode
|
|
|
|
* @renderer: (nullable): Renderer to optimize for or %NULL for any
|
|
|
|
*
|
|
|
|
* Creates a Cairo context for drawing using the surface associated
|
|
|
|
* to the render node.
|
|
|
|
* If no surface exists yet, a surface will be created optimized for
|
|
|
|
* rendering to @renderer.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a Cairo context used for drawing; use
|
|
|
|
* cairo_destroy() when done drawing
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
|
|
|
cairo_t *
|
|
|
|
gsk_cairo_node_get_draw_context (GskRenderNode *node,
|
|
|
|
GskRenderer *renderer)
|
|
|
|
{
|
2016-12-11 03:28:21 +00:00
|
|
|
GskCairoNode *self = (GskCairoNode *) node;
|
2016-12-11 01:59:47 +00:00
|
|
|
int width, height;
|
|
|
|
cairo_t *res;
|
|
|
|
|
2016-12-11 02:57:42 +00:00
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_CAIRO_NODE), NULL);
|
2016-12-11 01:59:47 +00:00
|
|
|
g_return_val_if_fail (node->is_mutable, NULL);
|
|
|
|
g_return_val_if_fail (renderer == NULL || GSK_IS_RENDERER (renderer), NULL);
|
|
|
|
|
2016-12-12 05:29:04 +00:00
|
|
|
width = ceilf (self->bounds.size.width);
|
|
|
|
height = ceilf (self->bounds.size.height);
|
2016-12-11 01:59:47 +00:00
|
|
|
|
|
|
|
if (width <= 0 || height <= 0)
|
|
|
|
{
|
|
|
|
cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 0, 0);
|
|
|
|
res = cairo_create (surface);
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
}
|
2016-12-11 03:28:21 +00:00
|
|
|
else if (self->surface == NULL)
|
2016-12-11 01:59:47 +00:00
|
|
|
{
|
|
|
|
if (renderer)
|
|
|
|
{
|
2016-12-11 03:28:21 +00:00
|
|
|
self->surface = gsk_renderer_create_cairo_surface (renderer,
|
2016-12-11 10:48:32 +00:00
|
|
|
CAIRO_FORMAT_ARGB32,
|
2016-12-12 05:29:04 +00:00
|
|
|
ceilf (self->bounds.size.width),
|
|
|
|
ceilf (self->bounds.size.height));
|
2016-12-11 01:59:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-11 10:48:32 +00:00
|
|
|
self->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
|
2016-12-12 05:29:04 +00:00
|
|
|
ceilf (self->bounds.size.width),
|
|
|
|
ceilf (self->bounds.size.height));
|
2016-12-11 01:59:47 +00:00
|
|
|
}
|
2016-12-11 03:28:21 +00:00
|
|
|
res = cairo_create (self->surface);
|
2016-12-11 01:59:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-11 03:28:21 +00:00
|
|
|
res = cairo_create (self->surface);
|
2016-12-11 01:59:47 +00:00
|
|
|
}
|
|
|
|
|
2016-12-12 05:29:04 +00:00
|
|
|
cairo_translate (res, -self->bounds.origin.x, -self->bounds.origin.y);
|
2016-12-11 01:59:47 +00:00
|
|
|
|
|
|
|
cairo_rectangle (res,
|
2016-12-12 05:29:04 +00:00
|
|
|
self->bounds.origin.x, self->bounds.origin.y,
|
|
|
|
self->bounds.size.width, self->bounds.size.height);
|
2016-12-11 01:59:47 +00:00
|
|
|
cairo_clip (res);
|
|
|
|
|
|
|
|
if (GSK_DEBUG_CHECK (SURFACE))
|
|
|
|
{
|
|
|
|
const char *prefix;
|
|
|
|
prefix = g_getenv ("GSK_DEBUG_PREFIX");
|
|
|
|
if (!prefix || g_str_has_prefix (node->name, prefix))
|
|
|
|
{
|
|
|
|
cairo_save (res);
|
|
|
|
cairo_rectangle (res,
|
2016-12-12 05:29:04 +00:00
|
|
|
self->bounds.origin.x + 1, self->bounds.origin.y + 1,
|
|
|
|
self->bounds.size.width - 2, self->bounds.size.height - 2);
|
2016-12-11 01:59:47 +00:00
|
|
|
cairo_set_line_width (res, 2);
|
|
|
|
cairo_set_source_rgb (res, 1, 0, 0);
|
|
|
|
cairo_stroke (res);
|
|
|
|
cairo_restore (res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2016-12-11 03:14:04 +00:00
|
|
|
/**** GSK_CONTAINER_NODE ***/
|
|
|
|
|
2016-12-12 18:30:41 +00:00
|
|
|
typedef struct _GskContainerNode GskContainerNode;
|
|
|
|
|
|
|
|
struct _GskContainerNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
2016-12-13 01:33:15 +00:00
|
|
|
GskRenderNode **children;
|
|
|
|
guint n_children;
|
2016-12-12 18:30:41 +00:00
|
|
|
};
|
|
|
|
|
2016-12-11 03:18:25 +00:00
|
|
|
static void
|
|
|
|
gsk_container_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
2016-12-12 18:30:41 +00:00
|
|
|
GskContainerNode *container = (GskContainerNode *) node;
|
2016-12-13 01:33:15 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < container->n_children; i++)
|
|
|
|
gsk_render_node_unref (container->children[i]);
|
2016-12-12 18:30:41 +00:00
|
|
|
|
2016-12-13 01:33:15 +00:00
|
|
|
g_free (container->children);
|
2016-12-11 03:18:25 +00:00
|
|
|
}
|
|
|
|
|
2016-12-11 10:53:17 +00:00
|
|
|
static void
|
|
|
|
gsk_container_node_make_immutable (GskRenderNode *node)
|
|
|
|
{
|
2016-12-12 18:30:41 +00:00
|
|
|
GskContainerNode *container = (GskContainerNode *) node;
|
|
|
|
guint i;
|
2016-12-11 10:53:17 +00:00
|
|
|
|
2016-12-13 01:33:15 +00:00
|
|
|
for (i = 1; i < container->n_children; i++)
|
2016-12-11 10:53:17 +00:00
|
|
|
{
|
2016-12-13 01:33:15 +00:00
|
|
|
gsk_render_node_make_immutable (container->children[i]);
|
2016-12-11 10:53:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-12 05:29:04 +00:00
|
|
|
static void
|
|
|
|
gsk_container_node_get_bounds (GskRenderNode *node,
|
|
|
|
graphene_rect_t *bounds)
|
|
|
|
{
|
2016-12-12 18:30:41 +00:00
|
|
|
GskContainerNode *container = (GskContainerNode *) node;
|
|
|
|
guint i;
|
2016-12-12 05:29:04 +00:00
|
|
|
|
2016-12-12 18:30:41 +00:00
|
|
|
if (container->n_children == 0)
|
2016-12-12 05:29:04 +00:00
|
|
|
{
|
|
|
|
graphene_rect_init_from_rect (bounds, graphene_rect_zero());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-12 18:30:41 +00:00
|
|
|
gsk_render_node_get_bounds (container->children[0], bounds);
|
2016-12-12 05:29:04 +00:00
|
|
|
|
2016-12-12 18:30:41 +00:00
|
|
|
for (i = 1; i < container->n_children; i++)
|
2016-12-12 05:29:04 +00:00
|
|
|
{
|
2016-12-12 18:30:41 +00:00
|
|
|
graphene_rect_t child_bounds;
|
2016-12-12 05:29:04 +00:00
|
|
|
|
2016-12-12 18:30:41 +00:00
|
|
|
gsk_render_node_get_bounds (container->children[i], &child_bounds);
|
|
|
|
graphene_rect_union (bounds, &child_bounds, bounds);
|
2016-12-12 05:29:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-11 03:14:04 +00:00
|
|
|
static const GskRenderNodeClass GSK_CONTAINER_NODE_CLASS = {
|
|
|
|
GSK_CONTAINER_NODE,
|
2016-12-12 18:30:41 +00:00
|
|
|
sizeof (GskContainerNode),
|
2016-12-11 03:18:25 +00:00
|
|
|
"GskContainerNode",
|
2016-12-11 10:53:17 +00:00
|
|
|
gsk_container_node_finalize,
|
2016-12-12 05:29:04 +00:00
|
|
|
gsk_container_node_make_immutable,
|
|
|
|
gsk_container_node_get_bounds
|
2016-12-11 03:14:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_container_node_new:
|
2016-12-13 01:33:15 +00:00
|
|
|
* @children: (array length=n_children) (transfer none): The children of the node
|
|
|
|
* @n_children: Number of children in the @children array
|
2016-12-11 03:14:04 +00:00
|
|
|
*
|
2016-12-13 01:33:15 +00:00
|
|
|
* Creates a new #GskRenderNode instance for holding the given @children.
|
|
|
|
* The new node will acquire a reference to each of the children.
|
2016-12-11 03:14:04 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer full): the new #GskRenderNode
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
|
|
|
GskRenderNode *
|
2016-12-13 01:33:15 +00:00
|
|
|
gsk_container_node_new (GskRenderNode **children,
|
|
|
|
guint n_children)
|
2016-12-11 03:14:04 +00:00
|
|
|
{
|
2016-12-12 18:30:41 +00:00
|
|
|
GskContainerNode *container;
|
2016-12-13 01:33:15 +00:00
|
|
|
guint i;
|
2016-12-12 18:30:41 +00:00
|
|
|
|
|
|
|
container = (GskContainerNode *) gsk_render_node_new (&GSK_CONTAINER_NODE_CLASS);
|
|
|
|
|
2016-12-13 01:33:15 +00:00
|
|
|
container->children = g_memdup (children, sizeof (GskRenderNode *) * n_children);
|
|
|
|
container->n_children = n_children;
|
2016-12-12 18:30:41 +00:00
|
|
|
|
2016-12-13 01:33:15 +00:00
|
|
|
for (i = 0; i < container->n_children; i++)
|
|
|
|
gsk_render_node_ref (container->children[i]);
|
2016-12-12 18:30:41 +00:00
|
|
|
|
2016-12-13 01:33:15 +00:00
|
|
|
return &container->render_node;
|
2016-12-12 18:30:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_container_node_get_n_children:
|
|
|
|
* @node: a container #GskRenderNode
|
|
|
|
*
|
|
|
|
* Retrieves the number of direct children of @node.
|
|
|
|
*
|
|
|
|
* Returns: the number of children of the #GskRenderNode
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
gsk_container_node_get_n_children (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskContainerNode *container = (GskContainerNode *) node;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_CONTAINER_NODE), 0);
|
|
|
|
|
2016-12-13 01:33:15 +00:00
|
|
|
return container->n_children;
|
2016-12-12 18:30:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_container_node_get_child (GskRenderNode *node,
|
|
|
|
guint idx)
|
|
|
|
{
|
|
|
|
GskContainerNode *container = (GskContainerNode *) node;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_CONTAINER_NODE), NULL);
|
2016-12-13 01:33:15 +00:00
|
|
|
g_return_val_if_fail (idx < container->n_children, 0);
|
2016-12-12 18:30:41 +00:00
|
|
|
|
2016-12-13 01:33:15 +00:00
|
|
|
return container->children[idx];
|
2016-12-11 03:14:04 +00:00
|
|
|
}
|
|
|
|
|
2016-12-12 23:11:06 +00:00
|
|
|
/*** GSK_TRANSFORM_NODE ***/
|
|
|
|
|
|
|
|
typedef struct _GskTransformNode GskTransformNode;
|
|
|
|
|
|
|
|
struct _GskTransformNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GskRenderNode *child;
|
|
|
|
graphene_matrix_t transform;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_transform_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskTransformNode *self = (GskTransformNode *) node;
|
|
|
|
|
|
|
|
gsk_render_node_unref (self->child);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_transform_node_make_immutable (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskTransformNode *self = (GskTransformNode *) node;
|
|
|
|
|
|
|
|
gsk_render_node_make_immutable (self->child);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_transform_node_get_bounds (GskRenderNode *node,
|
|
|
|
graphene_rect_t *bounds)
|
|
|
|
{
|
|
|
|
GskTransformNode *self = (GskTransformNode *) node;
|
|
|
|
graphene_rect_t child_bounds;
|
|
|
|
|
|
|
|
gsk_render_node_get_bounds (self->child, &child_bounds);
|
|
|
|
|
|
|
|
graphene_matrix_transform_bounds (&self->transform,
|
|
|
|
&child_bounds,
|
|
|
|
bounds);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const GskRenderNodeClass GSK_TRANSFORM_NODE_CLASS = {
|
|
|
|
GSK_TRANSFORM_NODE,
|
|
|
|
sizeof (GskTransformNode),
|
|
|
|
"GskTransformNode",
|
|
|
|
gsk_transform_node_finalize,
|
|
|
|
gsk_transform_node_make_immutable,
|
|
|
|
gsk_transform_node_get_bounds
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_transform_node_new:
|
|
|
|
* @child: The node to transform
|
|
|
|
* @transform: The transform to apply
|
|
|
|
*
|
|
|
|
* Creates a #GskRenderNode that will transform the given @child
|
|
|
|
* with the given @transform.
|
|
|
|
*
|
|
|
|
* Returns: A new #GskRenderNode
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_transform_node_new (GskRenderNode *child,
|
|
|
|
const graphene_matrix_t *transform)
|
|
|
|
{
|
|
|
|
GskTransformNode *self;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL);
|
|
|
|
g_return_val_if_fail (transform != NULL, NULL);
|
|
|
|
|
|
|
|
self = (GskTransformNode *) gsk_render_node_new (&GSK_TRANSFORM_NODE_CLASS);
|
|
|
|
|
|
|
|
self->child = gsk_render_node_ref (child);
|
|
|
|
graphene_matrix_init_from_matrix (&self->transform, transform);
|
|
|
|
|
|
|
|
return &self->render_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_transform_node_get_child:
|
|
|
|
* @node: a transform @GskRenderNode
|
|
|
|
*
|
|
|
|
* Gets the child node that is getting transformed by the given @node.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): The child that is getting transformed
|
|
|
|
**/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_transform_node_get_child (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskTransformNode *self = (GskTransformNode *) node;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_TRANSFORM_NODE), NULL);
|
|
|
|
|
|
|
|
return self->child;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gsk_transform_node_get_transform (GskRenderNode *node,
|
|
|
|
graphene_matrix_t *transform)
|
|
|
|
{
|
|
|
|
GskTransformNode *self = (GskTransformNode *) node;
|
|
|
|
|
|
|
|
g_return_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_TRANSFORM_NODE));
|
|
|
|
|
|
|
|
graphene_matrix_init_from_matrix (transform, &self->transform);
|
|
|
|
}
|
|
|
|
|