2016-03-17 13:48:19 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-08-19 21:36:16 +00:00
|
|
|
* GskRenderNode: (ref-func gsk_render_node_ref) (unref-func gsk_render_node_unref) (set-value-func gsk_value_set_render_node) (get-value-func gsk_value_get_render_node)
|
2016-03-17 13:48:19 +00:00
|
|
|
*
|
2021-02-25 11:59:57 +00:00
|
|
|
* `GskRenderNode` is the basic block in a scene graph to be
|
|
|
|
* rendered using `GskRenderer`.
|
2016-07-03 23:23:19 +00:00
|
|
|
*
|
|
|
|
* Each node has a parent, except the top-level node; each node may have
|
|
|
|
* children nodes.
|
|
|
|
*
|
|
|
|
* Each node has an associated drawing surface, which has the size of
|
2021-02-25 11:59:57 +00:00
|
|
|
* the rectangle set when creating it.
|
2016-07-03 23:23:19 +00:00
|
|
|
*
|
|
|
|
* Render nodes are meant to be transient; once they have been associated
|
2021-02-25 11:59:57 +00:00
|
|
|
* to a [class@Gsk.Renderer] it's safe to release any reference you have on
|
|
|
|
* them. All [class@Gsk.RenderNode]s are immutable, you can only specify their
|
|
|
|
* properties during construction.
|
2016-03-17 13:48:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gskrendernodeprivate.h"
|
|
|
|
|
|
|
|
#include "gskdebugprivate.h"
|
2016-10-31 16:28:09 +00:00
|
|
|
#include "gskrendererprivate.h"
|
2019-03-02 15:55:17 +00:00
|
|
|
#include "gskrendernodeparserprivate.h"
|
2016-03-17 13:48:19 +00:00
|
|
|
|
|
|
|
#include <graphene-gobject.h>
|
|
|
|
|
2016-11-01 02:40:01 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2016-06-29 18:05:33 +00:00
|
|
|
#include <gobject/gvaluecollector.h>
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
G_DEFINE_QUARK (gsk-serialization-error-quark, gsk_serialization_error)
|
|
|
|
|
|
|
|
#define GSK_RENDER_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GSK_TYPE_RENDER_NODE, GskRenderNodeClass))
|
|
|
|
|
2016-07-04 13:07:24 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
static void
|
|
|
|
value_render_node_init (GValue *value)
|
|
|
|
{
|
|
|
|
value->data[0].v_pointer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
value_render_node_free_value (GValue *value)
|
|
|
|
{
|
|
|
|
if (value->data[0].v_pointer != NULL)
|
|
|
|
gsk_render_node_unref (value->data[0].v_pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
value_render_node_copy_value (const GValue *src,
|
|
|
|
GValue *dst)
|
|
|
|
{
|
|
|
|
if (src->data[0].v_pointer != NULL)
|
|
|
|
dst->data[0].v_pointer = gsk_render_node_ref (src->data[0].v_pointer);
|
|
|
|
else
|
|
|
|
dst->data[0].v_pointer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
value_render_node_peek_pointer (const GValue *value)
|
|
|
|
{
|
|
|
|
return value->data[0].v_pointer;
|
|
|
|
}
|
2016-06-29 18:05:33 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
static char *
|
|
|
|
value_render_node_collect_value (GValue *value,
|
|
|
|
guint n_collect_values,
|
|
|
|
GTypeCValue *collect_values,
|
|
|
|
guint collect_flags)
|
|
|
|
{
|
|
|
|
GskRenderNode *node = collect_values[0].v_pointer;
|
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
value->data[0].v_pointer = NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node->parent_instance.g_class == NULL)
|
|
|
|
return g_strconcat ("invalid unclassed GskRenderNode pointer for "
|
|
|
|
"value type '",
|
|
|
|
G_VALUE_TYPE_NAME (value),
|
|
|
|
"'",
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
value->data[0].v_pointer = gsk_render_node_ref (node);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
static char *
|
2020-04-07 22:33:54 +00:00
|
|
|
value_render_node_lcopy_value (const GValue *value,
|
|
|
|
guint n_collect_values,
|
|
|
|
GTypeCValue *collect_values,
|
|
|
|
guint collect_flags)
|
|
|
|
{
|
|
|
|
GskRenderNode **node_p = collect_values[0].v_pointer;
|
|
|
|
|
|
|
|
if (node_p == NULL)
|
|
|
|
return g_strconcat ("value location for '",
|
|
|
|
G_VALUE_TYPE_NAME (value),
|
|
|
|
"' passed as NULL",
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (value->data[0].v_pointer == NULL)
|
|
|
|
*node_p = NULL;
|
|
|
|
else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
|
|
|
|
*node_p = value->data[0].v_pointer;
|
|
|
|
else
|
|
|
|
*node_p = gsk_render_node_ref (value->data[0].v_pointer);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-12-23 07:03:36 +00:00
|
|
|
|
2016-06-29 18:05:33 +00:00
|
|
|
static void
|
|
|
|
gsk_render_node_finalize (GskRenderNode *self)
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
2020-04-07 22:33:54 +00:00
|
|
|
g_type_free_instance ((GTypeInstance *) self);
|
|
|
|
}
|
2016-12-11 03:18:25 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
static void
|
|
|
|
gsk_render_node_real_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
2016-06-29 18:05:33 +00:00
|
|
|
}
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
static gboolean
|
|
|
|
gsk_render_node_real_can_diff (const GskRenderNode *node1,
|
|
|
|
const GskRenderNode *node2)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_render_node_real_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
|
|
|
cairo_region_t *region)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_render_node_class_init (GskRenderNodeClass *klass)
|
|
|
|
{
|
|
|
|
klass->node_type = GSK_NOT_A_RENDER_NODE;
|
|
|
|
klass->finalize = gsk_render_node_finalize;
|
|
|
|
klass->draw = gsk_render_node_real_draw;
|
|
|
|
klass->can_diff = gsk_render_node_real_can_diff;
|
|
|
|
klass->diff = gsk_render_node_real_diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_render_node_init (GskRenderNode *self)
|
|
|
|
{
|
|
|
|
g_atomic_ref_count_init (&self->ref_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
GType
|
|
|
|
gsk_render_node_get_type (void)
|
|
|
|
{
|
2020-11-19 03:58:09 +00:00
|
|
|
static gsize render_node_type__volatile;
|
2020-04-07 22:33:54 +00:00
|
|
|
|
|
|
|
if (g_once_init_enter (&render_node_type__volatile))
|
|
|
|
{
|
|
|
|
static const GTypeFundamentalInfo finfo = {
|
|
|
|
(G_TYPE_FLAG_CLASSED |
|
|
|
|
G_TYPE_FLAG_INSTANTIATABLE |
|
|
|
|
G_TYPE_FLAG_DERIVABLE |
|
|
|
|
G_TYPE_FLAG_DEEP_DERIVABLE),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const GTypeValueTable value_table = {
|
|
|
|
value_render_node_init,
|
|
|
|
value_render_node_free_value,
|
|
|
|
value_render_node_copy_value,
|
|
|
|
value_render_node_peek_pointer,
|
|
|
|
"p",
|
|
|
|
value_render_node_collect_value,
|
|
|
|
"p",
|
|
|
|
value_render_node_lcopy_value,
|
|
|
|
};
|
|
|
|
|
|
|
|
const GTypeInfo node_info = {
|
|
|
|
/* Class */
|
|
|
|
sizeof (GskRenderNodeClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gsk_render_node_class_init,
|
|
|
|
(GClassFinalizeFunc) NULL,
|
|
|
|
NULL,
|
|
|
|
|
|
|
|
/* Instance */
|
|
|
|
sizeof (GskRenderNode),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gsk_render_node_init,
|
|
|
|
|
|
|
|
/* GValue */
|
|
|
|
&value_table,
|
|
|
|
};
|
|
|
|
|
|
|
|
GType render_node_type =
|
|
|
|
g_type_register_fundamental (g_type_fundamental_next (),
|
|
|
|
g_intern_static_string ("GskRenderNode"),
|
|
|
|
&node_info, &finfo,
|
|
|
|
G_TYPE_FLAG_ABSTRACT);
|
|
|
|
|
|
|
|
g_once_init_leave (&render_node_type__volatile, render_node_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return render_node_type__volatile;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GskRenderNodeType node_type;
|
|
|
|
|
|
|
|
void (* finalize) (GskRenderNode *node);
|
|
|
|
void (* draw) (GskRenderNode *node,
|
|
|
|
cairo_t *cr);
|
|
|
|
gboolean (* can_diff) (const GskRenderNode *node1,
|
|
|
|
const GskRenderNode *node2);
|
|
|
|
void (* diff) (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
|
|
|
cairo_region_t *region);
|
|
|
|
} RenderNodeClassData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_render_node_generic_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
2016-06-29 18:05:33 +00:00
|
|
|
{
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
RenderNodeClassData *node_data = class_data;
|
|
|
|
|
|
|
|
/* Mandatory */
|
|
|
|
node_class->node_type = node_data->node_type;
|
2016-12-21 11:20:56 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/* Optional */
|
|
|
|
if (node_data->finalize != NULL)
|
|
|
|
node_class->finalize = node_data->finalize;
|
|
|
|
if (node_data->can_diff != NULL)
|
|
|
|
node_class->can_diff = node_data->can_diff;
|
2016-12-10 20:42:01 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/* Mandatory */
|
|
|
|
node_class->draw = node_data->draw;
|
|
|
|
node_class->diff = node_data->diff;
|
2016-12-10 20:42:01 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
g_free (node_data);
|
|
|
|
}
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
static gboolean
|
|
|
|
gsk_render_node_can_diff_true (const GskRenderNode *node1,
|
|
|
|
const GskRenderNode *node2)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
2016-06-29 18:05:33 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/*< private >
|
|
|
|
* gsk_render_node_type_register_static:
|
|
|
|
* @node_name: the name of the node
|
|
|
|
* @node_info: type information of the node
|
|
|
|
*
|
2021-02-25 11:59:57 +00:00
|
|
|
* Registers a new `GskRenderNode` type for the given @node_name using
|
2020-04-07 22:33:54 +00:00
|
|
|
* the type information in @node_info.
|
|
|
|
*
|
|
|
|
* Returns: the newly registered GType
|
|
|
|
*/
|
|
|
|
GType
|
|
|
|
gsk_render_node_type_register_static (const char *node_name,
|
|
|
|
const GskRenderNodeTypeInfo *node_info)
|
|
|
|
{
|
|
|
|
GTypeInfo info;
|
|
|
|
|
|
|
|
info.class_size = sizeof (GskRenderNodeClass);
|
|
|
|
info.base_init = NULL;
|
|
|
|
info.base_finalize = NULL;
|
|
|
|
info.class_init = gsk_render_node_generic_class_init;
|
|
|
|
info.class_finalize = NULL;
|
|
|
|
|
|
|
|
/* Avoid having a class_init() and a class struct for every GskRenderNode,
|
|
|
|
* by passing the various virtual functions and class data when initializing
|
|
|
|
* the base class
|
|
|
|
*/
|
|
|
|
info.class_data = g_new (RenderNodeClassData, 1);
|
|
|
|
((RenderNodeClassData *) info.class_data)->node_type = node_info->node_type;
|
|
|
|
((RenderNodeClassData *) info.class_data)->finalize = node_info->finalize;
|
|
|
|
((RenderNodeClassData *) info.class_data)->draw = node_info->draw;
|
|
|
|
((RenderNodeClassData *) info.class_data)->can_diff = node_info->can_diff != NULL
|
|
|
|
? node_info->can_diff
|
|
|
|
: gsk_render_node_can_diff_true;
|
|
|
|
((RenderNodeClassData *) info.class_data)->diff = node_info->diff != NULL
|
|
|
|
? node_info->diff
|
|
|
|
: gsk_render_node_diff_impossible;
|
|
|
|
|
|
|
|
info.instance_size = node_info->instance_size;
|
|
|
|
info.n_preallocs = 0;
|
|
|
|
info.instance_init = (GInstanceInitFunc) node_info->instance_init;
|
|
|
|
info.value_table = NULL;
|
|
|
|
|
|
|
|
return g_type_register_static (GSK_TYPE_RENDER_NODE, node_name, &info, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*< private >
|
|
|
|
* gsk_render_node_alloc:
|
2021-02-25 11:59:57 +00:00
|
|
|
* @node_type: the `GskRenderNode`Type to instantiate
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
2021-02-25 11:59:57 +00:00
|
|
|
* Instantiates a new `GskRenderNode` for the given @node_type.
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
2021-02-25 11:59:57 +00:00
|
|
|
* Returns: (transfer full) (type GskRenderNode): the newly created `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*/
|
|
|
|
gpointer
|
|
|
|
gsk_render_node_alloc (GskRenderNodeType node_type)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (node_type > GSK_NOT_A_RENDER_NODE, NULL);
|
|
|
|
g_return_val_if_fail (node_type < GSK_RENDER_NODE_TYPE_N_TYPES, NULL);
|
|
|
|
|
|
|
|
g_assert (gsk_render_node_types[node_type] != G_TYPE_INVALID);
|
|
|
|
return g_type_create_instance (gsk_render_node_types[node_type]);
|
2016-06-29 18:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_render_node_ref:
|
2021-02-25 11:59:57 +00:00
|
|
|
* @node: a `GskRenderNode`
|
2016-06-29 18:05:33 +00:00
|
|
|
*
|
2021-02-25 11:59:57 +00:00
|
|
|
* Acquires a reference on the given `GskRenderNode`.
|
2016-06-29 18:05:33 +00:00
|
|
|
*
|
2021-02-25 11:59:57 +00:00
|
|
|
* Returns: (transfer full): the `GskRenderNode` with an additional reference
|
2016-06-29 18:05:33 +00:00
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_render_node_ref (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (node), NULL);
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
g_atomic_ref_count_inc (&node->ref_count);
|
2016-06-29 18:05:33 +00:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_render_node_unref:
|
2021-02-25 11:59:57 +00:00
|
|
|
* @node: (transfer full): a `GskRenderNode`
|
2016-06-29 18:05:33 +00:00
|
|
|
*
|
2021-02-25 11:59:57 +00:00
|
|
|
* Releases a reference on the given `GskRenderNode`.
|
2016-06-29 18:05:33 +00:00
|
|
|
*
|
|
|
|
* If the reference was the last, the resources associated to the @node are
|
|
|
|
* freed.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gsk_render_node_unref (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GSK_IS_RENDER_NODE (node));
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
if (g_atomic_ref_count_dec (&node->ref_count))
|
|
|
|
GSK_RENDER_NODE_GET_CLASS (node)->finalize (node);
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
|
2016-12-10 20:42:01 +00:00
|
|
|
/**
|
|
|
|
* gsk_render_node_get_node_type:
|
2021-02-25 11:59:57 +00:00
|
|
|
* @node: a `GskRenderNode`
|
2016-12-10 20:42:01 +00:00
|
|
|
*
|
|
|
|
* Returns the type of the @node.
|
|
|
|
*
|
2021-02-25 11:59:57 +00:00
|
|
|
* Returns: the type of the `GskRenderNode`
|
2016-12-10 20:42:01 +00:00
|
|
|
*/
|
|
|
|
GskRenderNodeType
|
2021-02-04 04:53:23 +00:00
|
|
|
gsk_render_node_get_node_type (const GskRenderNode *node)
|
2016-12-10 20:42:01 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (node), GSK_NOT_A_RENDER_NODE);
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return GSK_RENDER_NODE_GET_CLASS (node)->node_type;
|
2016-12-10 20:42:01 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 12:17:09 +00:00
|
|
|
G_GNUC_PURE static inline
|
2019-06-01 21:25:55 +00:00
|
|
|
GskRenderNodeType
|
2020-01-24 12:17:09 +00:00
|
|
|
_gsk_render_node_get_node_type (const GskRenderNode *node)
|
2019-06-01 21:25:55 +00:00
|
|
|
{
|
2020-04-07 22:33:54 +00:00
|
|
|
return GSK_RENDER_NODE_GET_CLASS (node)->node_type;
|
2019-06-01 21:25:55 +00:00
|
|
|
}
|
|
|
|
|
2016-03-17 13:48:19 +00:00
|
|
|
/**
|
|
|
|
* gsk_render_node_get_bounds:
|
2021-02-25 11:59:57 +00:00
|
|
|
* @node: a `GskRenderNode`
|
2016-03-17 13:48:19 +00:00
|
|
|
* @bounds: (out caller-allocates): return location for the boundaries
|
|
|
|
*
|
2021-02-25 11:59:57 +00:00
|
|
|
* Retrieves the boundaries of the @node.
|
|
|
|
*
|
|
|
|
* The node will not draw outside of its boundaries.
|
2016-03-17 13:48:19 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gsk_render_node_get_bounds (GskRenderNode *node,
|
|
|
|
graphene_rect_t *bounds)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GSK_IS_RENDER_NODE (node));
|
|
|
|
g_return_if_fail (bounds != NULL);
|
|
|
|
|
2016-12-21 10:21:38 +00:00
|
|
|
graphene_rect_init_from_rect (bounds, &node->bounds);
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 02:05:15 +00:00
|
|
|
/**
|
|
|
|
* gsk_render_node_draw:
|
2021-02-25 11:59:57 +00:00
|
|
|
* @node: a `GskRenderNode`
|
2016-12-13 02:05:15 +00:00
|
|
|
* @cr: cairo context to draw to
|
|
|
|
*
|
|
|
|
* Draw the contents of @node to the given cairo context.
|
|
|
|
*
|
|
|
|
* Typically, you'll use this function to implement fallback rendering
|
2021-02-25 11:59:57 +00:00
|
|
|
* of `GskRenderNode`s on an intermediate Cairo context, instead of using
|
|
|
|
* the drawing context associated to a `GdkSurface`'s rendering buffer.
|
2016-12-13 02:05:15 +00:00
|
|
|
*
|
|
|
|
* For advanced nodes that cannot be supported using Cairo, in particular
|
|
|
|
* for nodes doing 3D operations, this function may fail.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gsk_render_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GSK_IS_RENDER_NODE (node));
|
|
|
|
g_return_if_fail (cr != NULL);
|
2016-12-23 04:56:17 +00:00
|
|
|
g_return_if_fail (cairo_status (cr) == CAIRO_STATUS_SUCCESS);
|
2016-12-13 02:05:15 +00:00
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
|
2018-01-14 14:52:52 +00:00
|
|
|
GSK_NOTE (CAIRO, g_message ("Rendering node %s[%p]",
|
2020-04-07 22:33:54 +00:00
|
|
|
g_type_name_from_instance ((GTypeInstance *) node),
|
|
|
|
node));
|
2016-12-13 02:05:15 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
GSK_RENDER_NODE_GET_CLASS (node)->draw (node, cr);
|
2016-12-13 02:05:15 +00:00
|
|
|
|
2018-01-14 20:11:33 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
if (GSK_DEBUG_CHECK (GEOMETRY))
|
2016-12-13 02:05:15 +00:00
|
|
|
{
|
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
|
2016-12-21 10:21:38 +00:00
|
|
|
cairo_rectangle (cr, node->bounds.origin.x - 1, node->bounds.origin.y - 1,
|
|
|
|
node->bounds.size.width + 2, node->bounds.size.height + 2);
|
2016-12-13 02:05:15 +00:00
|
|
|
cairo_set_line_width (cr, 2);
|
|
|
|
cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
2018-01-14 20:11:33 +00:00
|
|
|
#endif
|
2016-12-13 02:05:15 +00:00
|
|
|
|
|
|
|
cairo_restore (cr);
|
2016-12-23 04:56:17 +00:00
|
|
|
|
|
|
|
if (cairo_status (cr))
|
|
|
|
{
|
2018-04-24 01:46:44 +00:00
|
|
|
g_warning ("drawing failure for render node %s: %s",
|
2020-04-07 22:33:54 +00:00
|
|
|
g_type_name_from_instance ((GTypeInstance *) node),
|
2016-12-23 04:56:17 +00:00
|
|
|
cairo_status_to_string (cairo_status (cr)));
|
|
|
|
}
|
2016-12-13 02:05:15 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 00:37:05 +00:00
|
|
|
/*
|
|
|
|
* gsk_render_node_can_diff:
|
2021-02-25 11:59:57 +00:00
|
|
|
* @node1: a `GskRenderNode`
|
|
|
|
* @node2: the `GskRenderNode` to compare with
|
2018-03-20 00:37:05 +00:00
|
|
|
*
|
2019-05-25 21:52:15 +00:00
|
|
|
* Checks if two render nodes can be expected to be compared via
|
2021-02-25 11:59:57 +00:00
|
|
|
* gsk_render_node_diff().
|
|
|
|
*
|
|
|
|
* The node diffing algorithm uses this function to match up similar
|
|
|
|
* nodes to compare when trying to minimize the resulting region.
|
2018-03-20 00:37:05 +00:00
|
|
|
*
|
|
|
|
* Nodes of different type always return %FALSE here.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @node1 and @node2 can be expected to be compared
|
|
|
|
**/
|
|
|
|
gboolean
|
2020-01-24 12:17:09 +00:00
|
|
|
gsk_render_node_can_diff (const GskRenderNode *node1,
|
|
|
|
const GskRenderNode *node2)
|
2018-03-20 00:37:05 +00:00
|
|
|
{
|
|
|
|
if (node1 == node2)
|
|
|
|
return TRUE;
|
|
|
|
|
2021-03-28 14:18:23 +00:00
|
|
|
if (_gsk_render_node_get_node_type (node1) == _gsk_render_node_get_node_type (node2))
|
|
|
|
return GSK_RENDER_NODE_GET_CLASS (node1)->can_diff (node1, node2);
|
2018-03-20 00:37:05 +00:00
|
|
|
|
2021-03-28 14:18:23 +00:00
|
|
|
if (_gsk_render_node_get_node_type (node1) == GSK_CONTAINER_NODE ||
|
|
|
|
_gsk_render_node_get_node_type (node2) == GSK_CONTAINER_NODE)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
2018-03-20 00:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rectangle_init_from_graphene (cairo_rectangle_int_t *cairo,
|
|
|
|
const graphene_rect_t *graphene)
|
|
|
|
{
|
|
|
|
cairo->x = floorf (graphene->origin.x);
|
|
|
|
cairo->y = floorf (graphene->origin.y);
|
|
|
|
cairo->width = ceilf (graphene->origin.x + graphene->size.width) - cairo->x;
|
|
|
|
cairo->height = ceilf (graphene->origin.y + graphene->size.height) - cairo->y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gsk_render_node_diff_impossible (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
|
|
|
cairo_region_t *region)
|
|
|
|
{
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
|
|
|
|
rectangle_init_from_graphene (&rect, &node1->bounds);
|
|
|
|
cairo_region_union_rectangle (region, &rect);
|
|
|
|
rectangle_init_from_graphene (&rect, &node2->bounds);
|
|
|
|
cairo_region_union_rectangle (region, &rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_render_node_diff:
|
2021-02-25 11:59:57 +00:00
|
|
|
* @node1: a `GskRenderNode`
|
|
|
|
* @node2: the `GskRenderNode` to compare with
|
|
|
|
* @region: a `cairo_region_t` to add the differences to
|
2018-03-20 00:37:05 +00:00
|
|
|
*
|
|
|
|
* Compares @node1 and @node2 trying to compute the minimal region of changes.
|
2021-02-25 11:59:57 +00:00
|
|
|
*
|
2018-03-20 00:37:05 +00:00
|
|
|
* In the worst case, this is the union of the bounds of @node1 and @node2.
|
|
|
|
*
|
|
|
|
* This function is used to compute the area that needs to be redrawn when
|
|
|
|
* the previous contents were drawn by @node1 and the new contents should
|
|
|
|
* correspond to @node2. As such, it is important that this comparison is
|
|
|
|
* faster than the time it takes to actually do the redraw.
|
|
|
|
*
|
|
|
|
* Note that the passed in @region may already contain previous results from
|
|
|
|
* previous node comparisons, so this function call will only add to it.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gsk_render_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
|
|
|
cairo_region_t *region)
|
|
|
|
{
|
|
|
|
if (node1 == node2)
|
|
|
|
return;
|
|
|
|
|
2021-03-28 14:18:23 +00:00
|
|
|
if (_gsk_render_node_get_node_type (node1) == _gsk_render_node_get_node_type (node2))
|
2021-04-16 03:33:00 +00:00
|
|
|
GSK_RENDER_NODE_GET_CLASS (node1)->diff (node1, node2, region);
|
2021-03-28 14:18:23 +00:00
|
|
|
|
2021-04-16 03:33:00 +00:00
|
|
|
else if (_gsk_render_node_get_node_type (node1) == GSK_CONTAINER_NODE)
|
|
|
|
gsk_container_node_diff_with (node1, node2, region);
|
|
|
|
else if (_gsk_render_node_get_node_type (node2) == GSK_CONTAINER_NODE)
|
|
|
|
gsk_container_node_diff_with (node2, node1, region);
|
|
|
|
else
|
|
|
|
gsk_render_node_diff_impossible (node1, node2, region);
|
2018-03-20 00:37:05 +00:00
|
|
|
}
|
|
|
|
|
2016-12-23 04:58:07 +00:00
|
|
|
/**
|
|
|
|
* gsk_render_node_write_to_file:
|
2021-02-25 11:59:57 +00:00
|
|
|
* @node: a `GskRenderNode`
|
2021-06-12 15:12:06 +00:00
|
|
|
* @filename: (type filename): the file to save it to.
|
2016-12-23 04:58:07 +00:00
|
|
|
* @error: Return location for a potential error
|
|
|
|
*
|
|
|
|
* This function is equivalent to calling gsk_render_node_serialize()
|
2021-02-25 11:59:57 +00:00
|
|
|
* followed by g_file_set_contents().
|
|
|
|
*
|
|
|
|
* See those two functions for details on the arguments.
|
2016-12-23 04:58:07 +00:00
|
|
|
*
|
|
|
|
* It is mostly intended for use inside a debugger to quickly dump a render
|
|
|
|
* node to a file for later inspection.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if saving was successful
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gsk_render_node_write_to_file (GskRenderNode *node,
|
|
|
|
const char *filename,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GBytes *bytes;
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (node), FALSE);
|
|
|
|
g_return_val_if_fail (filename != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
bytes = gsk_render_node_serialize (node);
|
|
|
|
result = g_file_set_contents (filename,
|
|
|
|
g_bytes_get_data (bytes, NULL),
|
|
|
|
g_bytes_get_size (bytes),
|
|
|
|
error);
|
2016-12-23 12:08:43 +00:00
|
|
|
g_bytes_unref (bytes);
|
2016-12-23 04:58:07 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-12-23 07:03:36 +00:00
|
|
|
/**
|
|
|
|
* gsk_render_node_deserialize:
|
|
|
|
* @bytes: the bytes containing the data
|
2021-05-21 00:45:06 +00:00
|
|
|
* @error_func: (nullable) (scope call): Callback on parsing errors
|
2019-05-30 15:05:02 +00:00
|
|
|
* @user_data: (closure error_func): user_data for @error_func
|
2016-12-23 07:03:36 +00:00
|
|
|
*
|
2021-02-25 11:59:57 +00:00
|
|
|
* Loads data previously created via gsk_render_node_serialize().
|
2016-12-23 07:03:36 +00:00
|
|
|
*
|
2021-02-25 11:59:57 +00:00
|
|
|
* For a discussion of the supported format, see that function.
|
|
|
|
*
|
2021-05-18 21:05:26 +00:00
|
|
|
* Returns: (nullable) (transfer full): a new `GskRenderNode`
|
2021-02-25 11:59:57 +00:00
|
|
|
*/
|
2016-12-21 04:43:14 +00:00
|
|
|
GskRenderNode *
|
2019-04-24 16:30:46 +00:00
|
|
|
gsk_render_node_deserialize (GBytes *bytes,
|
|
|
|
GskParseErrorFunc error_func,
|
|
|
|
gpointer user_data)
|
2016-12-21 04:43:14 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node = NULL;
|
|
|
|
|
2019-04-24 16:30:46 +00:00
|
|
|
node = gsk_render_node_deserialize_from_bytes (bytes, error_func, user_data);
|
2016-12-21 04:43:14 +00:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
2021-08-19 21:36:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_value_set_render_node:
|
|
|
|
* @value: a `GValue` initialized with type `GSK_TYPE_RENDER_NODE`
|
|
|
|
* @node: a `GskRenderNode`
|
|
|
|
*
|
|
|
|
* Stores the given `GskRenderNode` inside `value`.
|
|
|
|
*
|
|
|
|
* The `GValue` will acquire a reference to the `node`.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gsk_value_set_render_node (GValue *value,
|
|
|
|
GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskRenderNode *old_node;
|
|
|
|
|
|
|
|
g_return_if_fail (G_VALUE_HOLDS (value, GSK_TYPE_RENDER_NODE));
|
|
|
|
|
|
|
|
old_node = value->data[0].v_pointer;
|
|
|
|
|
|
|
|
if (node != NULL)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GSK_IS_RENDER_NODE (node));
|
|
|
|
|
|
|
|
value->data[0].v_pointer = gsk_render_node_ref (node);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value->data[0].v_pointer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_node != NULL)
|
|
|
|
gsk_render_node_unref (old_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_value_take_render_node:
|
|
|
|
* @value: a `GValue` initialized with type `GSK_TYPE_RENDER_NODE`
|
|
|
|
* @node: (transfer full) (nullable): a `GskRenderNode`
|
|
|
|
*
|
|
|
|
* Stores the given `GskRenderNode` inside `value`.
|
|
|
|
*
|
|
|
|
* This function transfers the ownership of the `node` to the `GValue`.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gsk_value_take_render_node (GValue *value,
|
|
|
|
GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskRenderNode *old_node;
|
|
|
|
|
|
|
|
g_return_if_fail (G_VALUE_HOLDS (value, GSK_TYPE_RENDER_NODE));
|
|
|
|
|
|
|
|
old_node = value->data[0].v_pointer;
|
|
|
|
|
|
|
|
if (node != NULL)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GSK_IS_RENDER_NODE (node));
|
|
|
|
|
|
|
|
value->data[0].v_pointer = node;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value->data[0].v_pointer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_node != NULL)
|
|
|
|
gsk_render_node_unref (old_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_value_get_render_node:
|
|
|
|
* @value: a `GValue` initialized with type `GSK_TYPE_RENDER_NODE`
|
|
|
|
*
|
|
|
|
* Retrieves the `GskRenderNode` stored inside the given `value`.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none) (nullable): a `GskRenderNode`
|
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_value_get_render_node (const GValue *value)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_VALUE_HOLDS (value, GSK_TYPE_RENDER_NODE), NULL);
|
|
|
|
|
|
|
|
return value->data[0].v_pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_value_dup_render_node:
|
|
|
|
* @value: a `GValue` initialized with type `GSK_TYPE_RENDER_NODE`
|
|
|
|
*
|
|
|
|
* Retrieves the `GskRenderNode` stored inside the given `value`, and acquires
|
|
|
|
* a reference to it.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full) (nullable): a `GskRenderNode`
|
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_value_dup_render_node (const GValue *value)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_VALUE_HOLDS (value, GSK_TYPE_RENDER_NODE), NULL);
|
|
|
|
|
|
|
|
if (value->data[0].v_pointer == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return gsk_render_node_ref (value->data[0].v_pointer);
|
|
|
|
}
|
|
|
|
|