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/>.
|
|
|
|
*/
|
|
|
|
|
2016-12-23 01:05:54 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2016-12-11 01:59:47 +00:00
|
|
|
#include "gskrendernodeprivate.h"
|
|
|
|
|
2016-12-18 23:45:35 +00:00
|
|
|
#include "gskcairoblurprivate.h"
|
2023-03-10 23:08:20 +00:00
|
|
|
#include "gskcairorenderer.h"
|
2016-12-11 01:59:47 +00:00
|
|
|
#include "gskdebugprivate.h"
|
2018-03-27 22:34:23 +00:00
|
|
|
#include "gskdiffprivate.h"
|
2023-03-10 23:08:20 +00:00
|
|
|
#include "gl/gskglrenderer.h"
|
2020-11-10 23:44:32 +00:00
|
|
|
#include "gskpathprivate.h"
|
2023-07-30 17:59:37 +00:00
|
|
|
#include "gskrectprivate.h"
|
2016-12-11 01:59:47 +00:00
|
|
|
#include "gskrendererprivate.h"
|
2016-12-13 20:59:28 +00:00
|
|
|
#include "gskroundedrectprivate.h"
|
2020-11-11 06:36:04 +00:00
|
|
|
#include "gskstrokeprivate.h"
|
2019-03-01 05:35:55 +00:00
|
|
|
#include "gsktransformprivate.h"
|
2023-10-31 23:07:23 +00:00
|
|
|
#include "gskoffloadprivate.h"
|
2018-03-18 03:38:49 +00:00
|
|
|
|
2017-11-02 20:39:00 +00:00
|
|
|
#include "gdk/gdktextureprivate.h"
|
2021-10-01 20:23:12 +00:00
|
|
|
#include "gdk/gdkmemoryformatprivate.h"
|
2022-09-24 03:23:27 +00:00
|
|
|
#include "gdk/gdkprivate.h"
|
2023-04-28 02:28:23 +00:00
|
|
|
#include "gdk/gdkrectangleprivate.h"
|
2023-10-29 15:48:16 +00:00
|
|
|
#include "gdk/gdksubsurfaceprivate.h"
|
2021-02-04 19:16:39 +00:00
|
|
|
|
2023-03-10 14:30:26 +00:00
|
|
|
#include <cairo.h>
|
|
|
|
#ifdef CAIRO_HAS_SVG_SURFACE
|
|
|
|
#include <cairo-svg.h>
|
|
|
|
#endif
|
2021-07-31 19:22:14 +00:00
|
|
|
#include <hb-ot.h>
|
2016-12-11 01:59:47 +00:00
|
|
|
|
2021-12-20 17:40:02 +00:00
|
|
|
/* maximal number of rectangles we keep in a diff region before we throw
|
|
|
|
* the towel and just use the bounding box of the parent node.
|
|
|
|
* Meant to avoid performance corner cases.
|
|
|
|
*/
|
|
|
|
#define MAX_RECTS_IN_DIFF 30
|
|
|
|
|
2020-02-13 00:48:03 +00:00
|
|
|
static inline void
|
|
|
|
gsk_cairo_rectangle (cairo_t *cr,
|
|
|
|
const graphene_rect_t *rect)
|
|
|
|
{
|
|
|
|
cairo_rectangle (cr,
|
|
|
|
rect->origin.x, rect->origin.y,
|
|
|
|
rect->size.width, rect->size.height);
|
|
|
|
}
|
|
|
|
|
2018-03-27 22:34:23 +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;
|
|
|
|
}
|
|
|
|
|
2023-02-13 00:31:12 +00:00
|
|
|
static void
|
|
|
|
_graphene_rect_init_from_clip_extents (graphene_rect_t *rect,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
double x1c, y1c, x2c, y2c;
|
|
|
|
|
|
|
|
cairo_clip_extents (cr, &x1c, &y1c, &x2c, &y2c);
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init (rect, x1c, y1c, x2c - x1c, y2c - y1c);
|
2023-02-13 00:31:12 +00:00
|
|
|
}
|
|
|
|
|
2023-04-28 02:28:23 +00:00
|
|
|
static void
|
|
|
|
region_union_region_affine (cairo_region_t *region,
|
|
|
|
const cairo_region_t *sub,
|
|
|
|
float scale_x,
|
|
|
|
float scale_y,
|
|
|
|
float offset_x,
|
|
|
|
float offset_y)
|
|
|
|
{
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < cairo_region_num_rectangles (sub); i++)
|
|
|
|
{
|
|
|
|
cairo_region_get_rectangle (sub, i, &rect);
|
|
|
|
gdk_rectangle_transform_affine (&rect, scale_x, scale_y, offset_x, offset_y, &rect);
|
|
|
|
cairo_region_union_rectangle (region, &rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* {{{ GSK_COLOR_NODE */
|
2016-12-13 02:35:56 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskColorNode:
|
|
|
|
*
|
|
|
|
* A render node for a solid color.
|
|
|
|
*/
|
2016-12-13 02:35:56 +00:00
|
|
|
struct _GskColorNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GdkRGBA color;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_color_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskColorNode *self = (GskColorNode *) node;
|
|
|
|
|
|
|
|
gdk_cairo_set_source_rgba (cr, &self->color);
|
|
|
|
|
2020-02-13 00:48:03 +00:00
|
|
|
gsk_cairo_rectangle (cr, &node->bounds);
|
2016-12-13 02:35:56 +00:00
|
|
|
cairo_fill (cr);
|
|
|
|
}
|
|
|
|
|
2018-03-27 22:34:23 +00:00
|
|
|
static void
|
|
|
|
gsk_color_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2018-03-27 22:34:23 +00:00
|
|
|
{
|
|
|
|
GskColorNode *self1 = (GskColorNode *) node1;
|
|
|
|
GskColorNode *self2 = (GskColorNode *) node2;
|
|
|
|
|
2023-11-13 21:12:58 +00:00
|
|
|
if (gsk_rect_equal (&node1->bounds, &node2->bounds) &&
|
2018-03-27 22:34:23 +00:00
|
|
|
gdk_rgba_equal (&self1->color, &self2->color))
|
|
|
|
return;
|
|
|
|
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2018-03-27 22:34:23 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_color_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_COLOR_NODE;
|
|
|
|
|
|
|
|
node_class->draw = gsk_color_node_draw;
|
|
|
|
node_class->diff = gsk_color_node_diff;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_color_node_get_color:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskColorNode): a `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the color of the given @node.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the color of the node
|
|
|
|
*/
|
2016-12-13 02:35:56 +00:00
|
|
|
const GdkRGBA *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_color_node_get_color (const GskRenderNode *node)
|
2016-12-13 02:35:56 +00:00
|
|
|
{
|
|
|
|
GskColorNode *self = (GskColorNode *) node;
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_COLOR_NODE), NULL);
|
|
|
|
|
2016-12-13 02:35:56 +00:00
|
|
|
return &self->color;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-06-27 09:22:54 +00:00
|
|
|
* gsk_color_node_new:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @rgba: a `GdkRGBA` specifying a color
|
2016-12-13 02:35:56 +00:00
|
|
|
* @bounds: the rectangle to render the color into
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that will render the color specified by @rgba into
|
2017-03-27 21:13:32 +00:00
|
|
|
* the area given by @bounds.
|
2016-12-13 02:35:56 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer full) (type GskColorNode): A new `GskRenderNode`
|
2016-12-13 02:35:56 +00:00
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_color_node_new (const GdkRGBA *rgba,
|
|
|
|
const graphene_rect_t *bounds)
|
|
|
|
{
|
|
|
|
GskColorNode *self;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNode *node;
|
2016-12-13 02:35:56 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (rgba != NULL, NULL);
|
|
|
|
g_return_val_if_fail (bounds != NULL, NULL);
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self = gsk_render_node_alloc (GSK_COLOR_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = FALSE;
|
2016-12-13 02:35:56 +00:00
|
|
|
|
|
|
|
self->color = *rgba;
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&node->bounds, bounds);
|
2016-12-13 02:35:56 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return node;
|
2016-12-13 02:35:56 +00:00
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_LINEAR_GRADIENT_NODE */
|
2016-12-15 04:42:31 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskRepeatingLinearGradientNode:
|
|
|
|
*
|
|
|
|
* A render node for a repeating linear gradient.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GskLinearGradientNode:
|
|
|
|
*
|
|
|
|
* A render node for a linear gradient.
|
|
|
|
*/
|
2016-12-15 04:42:31 +00:00
|
|
|
struct _GskLinearGradientNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
graphene_point_t start;
|
|
|
|
graphene_point_t end;
|
|
|
|
|
|
|
|
gsize n_stops;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskColorStop *stops;
|
2016-12-15 04:42:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_linear_gradient_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
2020-04-07 22:33:54 +00:00
|
|
|
GskLinearGradientNode *self = (GskLinearGradientNode *) node;
|
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_LINEAR_GRADIENT_NODE));
|
|
|
|
|
|
|
|
g_free (self->stops);
|
|
|
|
|
|
|
|
parent_class->finalize (node);
|
2016-12-15 04:42:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_linear_gradient_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskLinearGradientNode *self = (GskLinearGradientNode *) node;
|
|
|
|
cairo_pattern_t *pattern;
|
|
|
|
gsize i;
|
|
|
|
|
|
|
|
pattern = cairo_pattern_create_linear (self->start.x, self->start.y,
|
|
|
|
self->end.x, self->end.y);
|
|
|
|
|
|
|
|
if (gsk_render_node_get_node_type (node) == GSK_REPEATING_LINEAR_GRADIENT_NODE)
|
|
|
|
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
|
|
|
|
|
2023-09-07 14:02:09 +00:00
|
|
|
if (self->stops[0].offset > 0.0)
|
|
|
|
cairo_pattern_add_color_stop_rgba (pattern,
|
|
|
|
0.0,
|
|
|
|
self->stops[0].color.red,
|
|
|
|
self->stops[0].color.green,
|
|
|
|
self->stops[0].color.blue,
|
|
|
|
self->stops[0].color.alpha);
|
2016-12-15 04:42:31 +00:00
|
|
|
for (i = 0; i < self->n_stops; i++)
|
|
|
|
{
|
|
|
|
cairo_pattern_add_color_stop_rgba (pattern,
|
|
|
|
self->stops[i].offset,
|
|
|
|
self->stops[i].color.red,
|
|
|
|
self->stops[i].color.green,
|
|
|
|
self->stops[i].color.blue,
|
|
|
|
self->stops[i].color.alpha);
|
|
|
|
}
|
2023-09-07 14:02:09 +00:00
|
|
|
if (self->stops[self->n_stops-1].offset < 1.0)
|
|
|
|
cairo_pattern_add_color_stop_rgba (pattern,
|
|
|
|
1.0,
|
|
|
|
self->stops[self->n_stops-1].color.red,
|
|
|
|
self->stops[self->n_stops-1].color.green,
|
|
|
|
self->stops[self->n_stops-1].color.blue,
|
|
|
|
self->stops[self->n_stops-1].color.alpha);
|
2016-12-15 04:42:31 +00:00
|
|
|
|
|
|
|
cairo_set_source (cr, pattern);
|
|
|
|
cairo_pattern_destroy (pattern);
|
|
|
|
|
2020-02-13 00:48:03 +00:00
|
|
|
gsk_cairo_rectangle (cr, &node->bounds);
|
2016-12-15 04:42:31 +00:00
|
|
|
cairo_fill (cr);
|
|
|
|
}
|
|
|
|
|
2018-03-27 22:34:23 +00:00
|
|
|
static void
|
|
|
|
gsk_linear_gradient_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2018-03-27 22:34:23 +00:00
|
|
|
{
|
|
|
|
GskLinearGradientNode *self1 = (GskLinearGradientNode *) node1;
|
|
|
|
GskLinearGradientNode *self2 = (GskLinearGradientNode *) node2;
|
|
|
|
|
|
|
|
if (graphene_point_equal (&self1->start, &self2->start) &&
|
|
|
|
graphene_point_equal (&self1->end, &self2->end) &&
|
|
|
|
self1->n_stops == self2->n_stops)
|
|
|
|
{
|
|
|
|
gsize i;
|
|
|
|
|
|
|
|
for (i = 0; i < self1->n_stops; i++)
|
|
|
|
{
|
|
|
|
GskColorStop *stop1 = &self1->stops[i];
|
|
|
|
GskColorStop *stop2 = &self2->stops[i];
|
|
|
|
|
|
|
|
if (stop1->offset == stop2->offset &&
|
|
|
|
gdk_rgba_equal (&stop1->color, &stop2->color))
|
|
|
|
continue;
|
|
|
|
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2018-03-27 22:34:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2020-06-27 09:22:54 +00:00
|
|
|
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2018-03-27 22:34:23 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_linear_gradient_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_LINEAR_GRADIENT_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_linear_gradient_node_finalize;
|
|
|
|
node_class->draw = gsk_linear_gradient_node_draw;
|
|
|
|
node_class->diff = gsk_linear_gradient_node_diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_repeating_linear_gradient_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_REPEATING_LINEAR_GRADIENT_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_linear_gradient_node_finalize;
|
|
|
|
node_class->draw = gsk_linear_gradient_node_draw;
|
|
|
|
node_class->diff = gsk_linear_gradient_node_diff;
|
|
|
|
}
|
|
|
|
|
2016-12-15 04:42:31 +00:00
|
|
|
/**
|
|
|
|
* gsk_linear_gradient_node_new:
|
2017-03-27 19:13:15 +00:00
|
|
|
* @bounds: the rectangle to render the linear gradient into
|
|
|
|
* @start: the point at which the linear gradient will begin
|
|
|
|
* @end: the point at which the linear gradient will finish
|
2021-02-20 06:09:55 +00:00
|
|
|
* @color_stops: (array length=n_color_stops): a pointer to an array of
|
|
|
|
* `GskColorStop` defining the gradient. The offsets of all color stops
|
|
|
|
* must be increasing. The first stop's offset must be >= 0 and the last
|
2020-09-18 17:01:10 +00:00
|
|
|
* stop's offset must be <= 1.
|
2017-03-27 19:13:15 +00:00
|
|
|
* @n_color_stops: the number of elements in @color_stops
|
2016-12-15 04:42:31 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that will create a linear gradient from the given
|
2017-03-27 19:13:15 +00:00
|
|
|
* points and color stops, and render that into the area given by @bounds.
|
2016-12-15 04:42:31 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer full) (type GskLinearGradientNode): A new `GskRenderNode`
|
2016-12-15 04:42:31 +00:00
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_linear_gradient_node_new (const graphene_rect_t *bounds,
|
|
|
|
const graphene_point_t *start,
|
|
|
|
const graphene_point_t *end,
|
|
|
|
const GskColorStop *color_stops,
|
|
|
|
gsize n_color_stops)
|
|
|
|
{
|
|
|
|
GskLinearGradientNode *self;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNode *node;
|
2016-12-26 16:04:01 +00:00
|
|
|
gsize i;
|
2016-12-15 04:42:31 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (bounds != NULL, NULL);
|
|
|
|
g_return_val_if_fail (start != NULL, NULL);
|
|
|
|
g_return_val_if_fail (end != NULL, NULL);
|
|
|
|
g_return_val_if_fail (color_stops != NULL, NULL);
|
2016-12-26 16:04:01 +00:00
|
|
|
g_return_val_if_fail (n_color_stops >= 2, NULL);
|
|
|
|
g_return_val_if_fail (color_stops[0].offset >= 0, NULL);
|
|
|
|
for (i = 1; i < n_color_stops; i++)
|
2020-04-07 22:33:54 +00:00
|
|
|
g_return_val_if_fail (color_stops[i].offset >= color_stops[i - 1].offset, NULL);
|
2016-12-26 16:04:01 +00:00
|
|
|
g_return_val_if_fail (color_stops[n_color_stops - 1].offset <= 1, NULL);
|
2016-12-15 04:42:31 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self = gsk_render_node_alloc (GSK_LINEAR_GRADIENT_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = FALSE;
|
2016-12-15 04:42:31 +00:00
|
|
|
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&node->bounds, bounds);
|
2016-12-15 04:42:31 +00:00
|
|
|
graphene_point_init_from_point (&self->start, start);
|
|
|
|
graphene_point_init_from_point (&self->end, end);
|
|
|
|
|
|
|
|
self->n_stops = n_color_stops;
|
2020-04-07 22:33:54 +00:00
|
|
|
self->stops = g_malloc_n (n_color_stops, sizeof (GskColorStop));
|
|
|
|
memcpy (self->stops, color_stops, n_color_stops * sizeof (GskColorStop));
|
2016-12-15 04:42:31 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return node;
|
2016-12-15 04:42:31 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 01:53:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_repeating_linear_gradient_node_new:
|
|
|
|
* @bounds: the rectangle to render the linear gradient into
|
|
|
|
* @start: the point at which the linear gradient will begin
|
|
|
|
* @end: the point at which the linear gradient will finish
|
2021-02-20 06:09:55 +00:00
|
|
|
* @color_stops: (array length=n_color_stops): a pointer to an array of
|
|
|
|
* `GskColorStop` defining the gradient. The offsets of all color stops
|
|
|
|
* must be increasing. The first stop's offset must be >= 0 and the last
|
2020-09-18 17:01:10 +00:00
|
|
|
* stop's offset must be <= 1.
|
2017-09-25 01:53:54 +00:00
|
|
|
* @n_color_stops: the number of elements in @color_stops
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that will create a repeating linear gradient
|
2017-09-25 01:53:54 +00:00
|
|
|
* from the given points and color stops, and render that into the area
|
|
|
|
* given by @bounds.
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer full) (type GskRepeatingLinearGradientNode): A new `GskRenderNode`
|
2017-09-25 01:53:54 +00:00
|
|
|
*/
|
2016-12-15 04:42:31 +00:00
|
|
|
GskRenderNode *
|
|
|
|
gsk_repeating_linear_gradient_node_new (const graphene_rect_t *bounds,
|
|
|
|
const graphene_point_t *start,
|
|
|
|
const graphene_point_t *end,
|
|
|
|
const GskColorStop *color_stops,
|
|
|
|
gsize n_color_stops)
|
|
|
|
{
|
|
|
|
GskLinearGradientNode *self;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNode *node;
|
2016-12-26 16:04:01 +00:00
|
|
|
gsize i;
|
2016-12-15 04:42:31 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (bounds != NULL, NULL);
|
|
|
|
g_return_val_if_fail (start != NULL, NULL);
|
|
|
|
g_return_val_if_fail (end != NULL, NULL);
|
|
|
|
g_return_val_if_fail (color_stops != NULL, NULL);
|
2016-12-26 16:04:01 +00:00
|
|
|
g_return_val_if_fail (n_color_stops >= 2, NULL);
|
|
|
|
g_return_val_if_fail (color_stops[0].offset >= 0, NULL);
|
|
|
|
for (i = 1; i < n_color_stops; i++)
|
2020-04-07 22:33:54 +00:00
|
|
|
g_return_val_if_fail (color_stops[i].offset >= color_stops[i - 1].offset, NULL);
|
2016-12-26 16:04:01 +00:00
|
|
|
g_return_val_if_fail (color_stops[n_color_stops - 1].offset <= 1, NULL);
|
2016-12-15 04:42:31 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self = gsk_render_node_alloc (GSK_REPEATING_LINEAR_GRADIENT_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = FALSE;
|
2016-12-15 04:42:31 +00:00
|
|
|
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&node->bounds, bounds);
|
2016-12-15 04:42:31 +00:00
|
|
|
graphene_point_init_from_point (&self->start, start);
|
|
|
|
graphene_point_init_from_point (&self->end, end);
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self->stops = g_malloc_n (n_color_stops, sizeof (GskColorStop));
|
|
|
|
memcpy (self->stops, color_stops, n_color_stops * sizeof (GskColorStop));
|
2016-12-15 04:42:31 +00:00
|
|
|
self->n_stops = n_color_stops;
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return node;
|
2016-12-15 04:42:31 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_linear_gradient_node_get_start:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskLinearGradientNode): a `GskRenderNode` for a linear gradient
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the initial point of the linear gradient.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the initial point
|
|
|
|
*/
|
2016-12-26 16:11:13 +00:00
|
|
|
const graphene_point_t *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_linear_gradient_node_get_start (const GskRenderNode *node)
|
2016-12-26 16:11:13 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskLinearGradientNode *self = (const GskLinearGradientNode *) node;
|
2016-12-26 16:11:13 +00:00
|
|
|
|
|
|
|
return &self->start;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_linear_gradient_node_get_end:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskLinearGradientNode): a `GskRenderNode` for a linear gradient
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the final point of the linear gradient.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the final point
|
|
|
|
*/
|
2016-12-26 16:11:13 +00:00
|
|
|
const graphene_point_t *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_linear_gradient_node_get_end (const GskRenderNode *node)
|
2016-12-26 16:11:13 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskLinearGradientNode *self = (const GskLinearGradientNode *) node;
|
2016-12-26 16:11:13 +00:00
|
|
|
|
|
|
|
return &self->end;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_linear_gradient_node_get_n_color_stops:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskLinearGradientNode): a `GskRenderNode` for a linear gradient
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the number of color stops in the gradient.
|
|
|
|
*
|
|
|
|
* Returns: the number of color stops
|
|
|
|
*/
|
2017-10-23 14:23:09 +00:00
|
|
|
gsize
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_linear_gradient_node_get_n_color_stops (const GskRenderNode *node)
|
2016-12-26 16:11:13 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskLinearGradientNode *self = (const GskLinearGradientNode *) node;
|
2016-12-26 16:11:13 +00:00
|
|
|
|
|
|
|
return self->n_stops;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_linear_gradient_node_get_color_stops:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskLinearGradientNode): a `GskRenderNode` for a linear gradient
|
2020-04-07 22:33:54 +00:00
|
|
|
* @n_stops: (out) (optional): the number of color stops in the returned array
|
|
|
|
*
|
2020-06-06 00:19:45 +00:00
|
|
|
* Retrieves the color stops in the gradient.
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Returns: (array length=n_stops): the color stops in the gradient
|
|
|
|
*/
|
2016-12-26 16:11:13 +00:00
|
|
|
const GskColorStop *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_linear_gradient_node_get_color_stops (const GskRenderNode *node,
|
|
|
|
gsize *n_stops)
|
2016-12-26 16:11:13 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskLinearGradientNode *self = (const GskLinearGradientNode *) node;
|
2016-12-26 16:11:13 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
if (n_stops != NULL)
|
|
|
|
*n_stops = self->n_stops;
|
|
|
|
|
2016-12-26 16:11:13 +00:00
|
|
|
return self->stops;
|
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_RADIAL_GRADIENT_NODE */
|
2020-09-12 02:55:37 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskRepeatingRadialGradientNode:
|
|
|
|
*
|
|
|
|
* A render node for a repeating radial gradient.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GskRadialGradientNode:
|
|
|
|
*
|
|
|
|
* A render node for a radial gradient.
|
|
|
|
*/
|
2020-09-12 02:55:37 +00:00
|
|
|
struct _GskRadialGradientNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
graphene_point_t center;
|
|
|
|
|
2020-09-12 13:16:17 +00:00
|
|
|
float hradius;
|
|
|
|
float vradius;
|
2020-09-12 02:55:37 +00:00
|
|
|
float start;
|
|
|
|
float end;
|
|
|
|
|
|
|
|
gsize n_stops;
|
|
|
|
GskColorStop *stops;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_radial_gradient_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskRadialGradientNode *self = (GskRadialGradientNode *) node;
|
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_RADIAL_GRADIENT_NODE));
|
|
|
|
|
|
|
|
g_free (self->stops);
|
|
|
|
|
|
|
|
parent_class->finalize (node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_radial_gradient_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskRadialGradientNode *self = (GskRadialGradientNode *) node;
|
|
|
|
cairo_pattern_t *pattern;
|
|
|
|
gsize i;
|
|
|
|
|
2020-09-12 13:16:17 +00:00
|
|
|
pattern = cairo_pattern_create_radial (0, 0, self->hradius * self->start,
|
|
|
|
0, 0, self->hradius * self->end);
|
2020-09-12 02:55:37 +00:00
|
|
|
|
2020-09-12 13:16:17 +00:00
|
|
|
if (self->hradius != self->vradius)
|
2020-09-12 02:55:37 +00:00
|
|
|
{
|
2020-09-18 03:33:16 +00:00
|
|
|
cairo_matrix_t matrix;
|
|
|
|
|
2020-09-12 13:16:17 +00:00
|
|
|
cairo_matrix_init_scale (&matrix, 1.0, self->hradius / self->vradius);
|
2020-09-12 02:55:37 +00:00
|
|
|
cairo_pattern_set_matrix (pattern, &matrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gsk_render_node_get_node_type (node) == GSK_REPEATING_RADIAL_GRADIENT_NODE)
|
|
|
|
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
|
|
|
|
else
|
|
|
|
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD);
|
|
|
|
|
2023-09-07 14:02:09 +00:00
|
|
|
if (self->stops[0].offset > 0.0)
|
|
|
|
cairo_pattern_add_color_stop_rgba (pattern,
|
|
|
|
0.0,
|
|
|
|
self->stops[0].color.red,
|
|
|
|
self->stops[0].color.green,
|
|
|
|
self->stops[0].color.blue,
|
|
|
|
self->stops[0].color.alpha);
|
2020-09-12 02:55:37 +00:00
|
|
|
for (i = 0; i < self->n_stops; i++)
|
2023-09-07 14:02:09 +00:00
|
|
|
{
|
|
|
|
cairo_pattern_add_color_stop_rgba (pattern,
|
|
|
|
self->stops[i].offset,
|
|
|
|
self->stops[i].color.red,
|
|
|
|
self->stops[i].color.green,
|
|
|
|
self->stops[i].color.blue,
|
|
|
|
self->stops[i].color.alpha);
|
|
|
|
}
|
|
|
|
if (self->stops[self->n_stops-1].offset < 1.0)
|
2020-09-12 13:16:17 +00:00
|
|
|
cairo_pattern_add_color_stop_rgba (pattern,
|
2023-09-07 14:02:09 +00:00
|
|
|
1.0,
|
|
|
|
self->stops[self->n_stops-1].color.red,
|
|
|
|
self->stops[self->n_stops-1].color.green,
|
|
|
|
self->stops[self->n_stops-1].color.blue,
|
|
|
|
self->stops[self->n_stops-1].color.alpha);
|
2020-09-12 02:55:37 +00:00
|
|
|
|
|
|
|
gsk_cairo_rectangle (cr, &node->bounds);
|
|
|
|
cairo_translate (cr, self->center.x, self->center.y);
|
|
|
|
cairo_set_source (cr, pattern);
|
|
|
|
cairo_fill (cr);
|
|
|
|
|
|
|
|
cairo_pattern_destroy (pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_radial_gradient_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2020-09-12 02:55:37 +00:00
|
|
|
{
|
|
|
|
GskRadialGradientNode *self1 = (GskRadialGradientNode *) node1;
|
|
|
|
GskRadialGradientNode *self2 = (GskRadialGradientNode *) node2;
|
|
|
|
|
|
|
|
if (graphene_point_equal (&self1->center, &self2->center) &&
|
2020-09-12 13:16:17 +00:00
|
|
|
self1->hradius == self2->hradius &&
|
|
|
|
self1->vradius == self2->vradius &&
|
2020-09-12 02:55:37 +00:00
|
|
|
self1->start == self2->start &&
|
|
|
|
self1->end == self2->end &&
|
|
|
|
self1->n_stops == self2->n_stops)
|
|
|
|
{
|
|
|
|
gsize i;
|
|
|
|
|
|
|
|
for (i = 0; i < self1->n_stops; i++)
|
|
|
|
{
|
|
|
|
GskColorStop *stop1 = &self1->stops[i];
|
|
|
|
GskColorStop *stop2 = &self2->stops[i];
|
|
|
|
|
|
|
|
if (stop1->offset == stop2->offset &&
|
|
|
|
gdk_rgba_equal (&stop1->color, &stop2->color))
|
|
|
|
continue;
|
|
|
|
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2020-09-12 02:55:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2020-09-12 02:55:37 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_radial_gradient_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_RADIAL_GRADIENT_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_radial_gradient_node_finalize;
|
|
|
|
node_class->draw = gsk_radial_gradient_node_draw;
|
|
|
|
node_class->diff = gsk_radial_gradient_node_diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_repeating_radial_gradient_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_REPEATING_RADIAL_GRADIENT_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_radial_gradient_node_finalize;
|
|
|
|
node_class->draw = gsk_radial_gradient_node_draw;
|
|
|
|
node_class->diff = gsk_radial_gradient_node_diff;
|
|
|
|
}
|
|
|
|
|
2020-09-18 16:41:01 +00:00
|
|
|
/**
|
|
|
|
* gsk_radial_gradient_node_new:
|
|
|
|
* @bounds: the bounds of the node
|
|
|
|
* @center: the center of the gradient
|
|
|
|
* @hradius: the horizontal radius
|
|
|
|
* @vradius: the vertical radius
|
|
|
|
* @start: a percentage >= 0 that defines the start of the gradient around @center
|
|
|
|
* @end: a percentage >= 0 that defines the end of the gradient around @center
|
2021-02-20 06:09:55 +00:00
|
|
|
* @color_stops: (array length=n_color_stops): a pointer to an array of
|
|
|
|
* `GskColorStop` defining the gradient. The offsets of all color stops
|
|
|
|
* must be increasing. The first stop's offset must be >= 0 and the last
|
2020-09-18 17:01:10 +00:00
|
|
|
* stop's offset must be <= 1.
|
2020-09-18 16:41:01 +00:00
|
|
|
* @n_color_stops: the number of elements in @color_stops
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that draws a radial gradient.
|
|
|
|
*
|
|
|
|
* The radial gradient
|
2020-09-18 16:41:01 +00:00
|
|
|
* starts around @center. The size of the gradient is dictated by @hradius
|
2022-11-18 03:24:18 +00:00
|
|
|
* in horizontal orientation and by @vradius in vertical orientation.
|
2020-09-18 16:41:01 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer full) (type GskRadialGradientNode): A new `GskRenderNode`
|
2020-09-18 16:41:01 +00:00
|
|
|
*/
|
2020-09-12 02:55:37 +00:00
|
|
|
GskRenderNode *
|
|
|
|
gsk_radial_gradient_node_new (const graphene_rect_t *bounds,
|
|
|
|
const graphene_point_t *center,
|
2020-09-12 13:16:17 +00:00
|
|
|
float hradius,
|
|
|
|
float vradius,
|
2020-09-12 02:55:37 +00:00
|
|
|
float start,
|
|
|
|
float end,
|
|
|
|
const GskColorStop *color_stops,
|
|
|
|
gsize n_color_stops)
|
|
|
|
{
|
|
|
|
GskRadialGradientNode *self;
|
|
|
|
GskRenderNode *node;
|
|
|
|
gsize i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (bounds != NULL, NULL);
|
|
|
|
g_return_val_if_fail (center != NULL, NULL);
|
2020-09-12 13:16:17 +00:00
|
|
|
g_return_val_if_fail (hradius > 0., NULL);
|
|
|
|
g_return_val_if_fail (vradius > 0., NULL);
|
2020-09-16 03:02:07 +00:00
|
|
|
g_return_val_if_fail (start >= 0., NULL);
|
|
|
|
g_return_val_if_fail (end >= 0., NULL);
|
2020-09-18 16:29:08 +00:00
|
|
|
g_return_val_if_fail (end > start, NULL);
|
2020-09-12 02:55:37 +00:00
|
|
|
g_return_val_if_fail (color_stops != NULL, NULL);
|
|
|
|
g_return_val_if_fail (n_color_stops >= 2, NULL);
|
|
|
|
g_return_val_if_fail (color_stops[0].offset >= 0, NULL);
|
|
|
|
for (i = 1; i < n_color_stops; i++)
|
|
|
|
g_return_val_if_fail (color_stops[i].offset >= color_stops[i - 1].offset, NULL);
|
|
|
|
g_return_val_if_fail (color_stops[n_color_stops - 1].offset <= 1, NULL);
|
|
|
|
|
|
|
|
self = gsk_render_node_alloc (GSK_RADIAL_GRADIENT_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = FALSE;
|
2020-09-12 02:55:37 +00:00
|
|
|
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&node->bounds, bounds);
|
2020-09-12 02:55:37 +00:00
|
|
|
graphene_point_init_from_point (&self->center, center);
|
|
|
|
|
2020-09-12 13:16:17 +00:00
|
|
|
self->hradius = hradius;
|
|
|
|
self->vradius = vradius;
|
2020-09-12 02:55:37 +00:00
|
|
|
self->start = start;
|
|
|
|
self->end = end;
|
|
|
|
|
|
|
|
self->n_stops = n_color_stops;
|
|
|
|
self->stops = g_malloc_n (n_color_stops, sizeof (GskColorStop));
|
|
|
|
memcpy (self->stops, color_stops, n_color_stops * sizeof (GskColorStop));
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2020-09-18 16:41:01 +00:00
|
|
|
/**
|
|
|
|
* gsk_repeating_radial_gradient_node_new:
|
|
|
|
* @bounds: the bounds of the node
|
|
|
|
* @center: the center of the gradient
|
|
|
|
* @hradius: the horizontal radius
|
|
|
|
* @vradius: the vertical radius
|
|
|
|
* @start: a percentage >= 0 that defines the start of the gradient around @center
|
|
|
|
* @end: a percentage >= 0 that defines the end of the gradient around @center
|
2021-02-20 06:09:55 +00:00
|
|
|
* @color_stops: (array length=n_color_stops): a pointer to an array of
|
|
|
|
* `GskColorStop` defining the gradient. The offsets of all color stops
|
|
|
|
* must be increasing. The first stop's offset must be >= 0 and the last
|
2020-09-18 17:01:10 +00:00
|
|
|
* stop's offset must be <= 1.
|
2020-09-18 16:41:01 +00:00
|
|
|
* @n_color_stops: the number of elements in @color_stops
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that draws a repeating radial gradient.
|
2020-09-18 16:41:01 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* The radial gradient starts around @center. The size of the gradient
|
|
|
|
* is dictated by @hradius in horizontal orientation and by @vradius
|
2022-11-18 03:24:18 +00:00
|
|
|
* in vertical orientation.
|
2021-02-20 06:09:55 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer full) (type GskRepeatingRadialGradientNode): A new `GskRenderNode`
|
2020-09-18 16:41:01 +00:00
|
|
|
*/
|
2020-09-12 02:55:37 +00:00
|
|
|
GskRenderNode *
|
|
|
|
gsk_repeating_radial_gradient_node_new (const graphene_rect_t *bounds,
|
|
|
|
const graphene_point_t *center,
|
2020-09-12 13:16:17 +00:00
|
|
|
float hradius,
|
|
|
|
float vradius,
|
2020-09-12 02:55:37 +00:00
|
|
|
float start,
|
|
|
|
float end,
|
|
|
|
const GskColorStop *color_stops,
|
|
|
|
gsize n_color_stops)
|
|
|
|
{
|
|
|
|
GskRadialGradientNode *self;
|
|
|
|
GskRenderNode *node;
|
|
|
|
gsize i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (bounds != NULL, NULL);
|
|
|
|
g_return_val_if_fail (center != NULL, NULL);
|
2020-09-12 13:16:17 +00:00
|
|
|
g_return_val_if_fail (hradius > 0., NULL);
|
|
|
|
g_return_val_if_fail (vradius > 0., NULL);
|
2020-09-16 03:02:07 +00:00
|
|
|
g_return_val_if_fail (start >= 0., NULL);
|
|
|
|
g_return_val_if_fail (end >= 0., NULL);
|
2020-09-18 16:29:08 +00:00
|
|
|
g_return_val_if_fail (end > start, NULL);
|
2020-09-12 02:55:37 +00:00
|
|
|
g_return_val_if_fail (color_stops != NULL, NULL);
|
|
|
|
g_return_val_if_fail (n_color_stops >= 2, NULL);
|
|
|
|
g_return_val_if_fail (color_stops[0].offset >= 0, NULL);
|
|
|
|
for (i = 1; i < n_color_stops; i++)
|
|
|
|
g_return_val_if_fail (color_stops[i].offset >= color_stops[i - 1].offset, NULL);
|
|
|
|
g_return_val_if_fail (color_stops[n_color_stops - 1].offset <= 1, NULL);
|
|
|
|
|
|
|
|
self = gsk_render_node_alloc (GSK_REPEATING_RADIAL_GRADIENT_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = FALSE;
|
2020-09-12 02:55:37 +00:00
|
|
|
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&node->bounds, bounds);
|
2020-09-12 02:55:37 +00:00
|
|
|
graphene_point_init_from_point (&self->center, center);
|
|
|
|
|
2020-09-12 13:16:17 +00:00
|
|
|
self->hradius = hradius;
|
|
|
|
self->vradius = vradius;
|
2020-09-12 02:55:37 +00:00
|
|
|
self->start = start;
|
|
|
|
self->end = end;
|
|
|
|
|
|
|
|
self->n_stops = n_color_stops;
|
|
|
|
self->stops = g_malloc_n (n_color_stops, sizeof (GskColorStop));
|
|
|
|
memcpy (self->stops, color_stops, n_color_stops * sizeof (GskColorStop));
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2020-09-29 02:24:59 +00:00
|
|
|
/**
|
|
|
|
* gsk_radial_gradient_node_get_n_color_stops:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskRadialGradientNode): a `GskRenderNode` for a radial gradient
|
2020-09-29 02:24:59 +00:00
|
|
|
*
|
|
|
|
* Retrieves the number of color stops in the gradient.
|
|
|
|
*
|
|
|
|
* Returns: the number of color stops
|
|
|
|
*/
|
2020-09-12 02:55:37 +00:00
|
|
|
gsize
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_radial_gradient_node_get_n_color_stops (const GskRenderNode *node)
|
2020-09-12 02:55:37 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskRadialGradientNode *self = (const GskRadialGradientNode *) node;
|
2020-09-12 02:55:37 +00:00
|
|
|
|
|
|
|
return self->n_stops;
|
|
|
|
}
|
|
|
|
|
2020-09-29 02:24:59 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_radial_gradient_node_get_color_stops:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskRadialGradientNode): a `GskRenderNode` for a radial gradient
|
2020-09-29 02:24:59 +00:00
|
|
|
* @n_stops: (out) (optional): the number of color stops in the returned array
|
|
|
|
*
|
|
|
|
* Retrieves the color stops in the gradient.
|
|
|
|
*
|
|
|
|
* Returns: (array length=n_stops): the color stops in the gradient
|
|
|
|
*/
|
2020-09-12 02:55:37 +00:00
|
|
|
const GskColorStop *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_radial_gradient_node_get_color_stops (const GskRenderNode *node,
|
|
|
|
gsize *n_stops)
|
2020-09-12 02:55:37 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskRadialGradientNode *self = (const GskRadialGradientNode *) node;
|
2020-09-12 02:55:37 +00:00
|
|
|
|
|
|
|
if (n_stops != NULL)
|
|
|
|
*n_stops = self->n_stops;
|
|
|
|
|
|
|
|
return self->stops;
|
|
|
|
}
|
|
|
|
|
2020-09-29 02:24:59 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_radial_gradient_node_get_center:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskRadialGradientNode): a `GskRenderNode` for a radial gradient
|
2020-09-29 02:24:59 +00:00
|
|
|
*
|
|
|
|
* Retrieves the center pointer for the gradient.
|
|
|
|
*
|
|
|
|
* Returns: the center point for the gradient
|
|
|
|
*/
|
2020-09-12 02:55:37 +00:00
|
|
|
const graphene_point_t *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_radial_gradient_node_get_center (const GskRenderNode *node)
|
2020-09-12 02:55:37 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskRadialGradientNode *self = (const GskRadialGradientNode *) node;
|
2020-09-12 02:55:37 +00:00
|
|
|
|
|
|
|
return &self->center;
|
|
|
|
}
|
|
|
|
|
2020-09-29 02:24:59 +00:00
|
|
|
/**
|
|
|
|
* gsk_radial_gradient_node_get_hradius:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskRadialGradientNode): a `GskRenderNode` for a radial gradient
|
2020-09-29 02:24:59 +00:00
|
|
|
*
|
2022-11-18 03:24:18 +00:00
|
|
|
* Retrieves the horizontal radius for the gradient.
|
2020-09-29 02:24:59 +00:00
|
|
|
*
|
|
|
|
* Returns: the horizontal radius for the gradient
|
|
|
|
*/
|
2020-09-12 02:55:37 +00:00
|
|
|
float
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_radial_gradient_node_get_hradius (const GskRenderNode *node)
|
2020-09-12 02:55:37 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskRadialGradientNode *self = (const GskRadialGradientNode *) node;
|
2020-09-12 02:55:37 +00:00
|
|
|
|
2020-09-12 13:16:17 +00:00
|
|
|
return self->hradius;
|
2020-09-12 02:55:37 +00:00
|
|
|
}
|
|
|
|
|
2020-09-29 02:24:59 +00:00
|
|
|
/**
|
|
|
|
* gsk_radial_gradient_node_get_vradius:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskRadialGradientNode): a `GskRenderNode` for a radial gradient
|
2020-09-29 02:24:59 +00:00
|
|
|
*
|
|
|
|
* Retrieves the vertical radius for the gradient.
|
|
|
|
*
|
|
|
|
* Returns: the vertical radius for the gradient
|
|
|
|
*/
|
2020-09-12 02:55:37 +00:00
|
|
|
float
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_radial_gradient_node_get_vradius (const GskRenderNode *node)
|
2020-09-12 02:55:37 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskRadialGradientNode *self = (const GskRadialGradientNode *) node;
|
2020-09-12 02:55:37 +00:00
|
|
|
|
2020-09-12 13:16:17 +00:00
|
|
|
return self->vradius;
|
2020-09-12 02:55:37 +00:00
|
|
|
}
|
|
|
|
|
2020-09-29 02:24:59 +00:00
|
|
|
/**
|
|
|
|
* gsk_radial_gradient_node_get_start:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskRadialGradientNode): a `GskRenderNode` for a radial gradient
|
2020-09-29 02:24:59 +00:00
|
|
|
*
|
|
|
|
* Retrieves the start value for the gradient.
|
|
|
|
*
|
|
|
|
* Returns: the start value for the gradient
|
|
|
|
*/
|
2020-09-12 02:55:37 +00:00
|
|
|
float
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_radial_gradient_node_get_start (const GskRenderNode *node)
|
2020-09-12 02:55:37 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskRadialGradientNode *self = (const GskRadialGradientNode *) node;
|
2020-09-12 02:55:37 +00:00
|
|
|
|
|
|
|
return self->start;
|
|
|
|
}
|
|
|
|
|
2020-09-29 02:24:59 +00:00
|
|
|
/**
|
|
|
|
* gsk_radial_gradient_node_get_end:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskRadialGradientNode): a `GskRenderNode` for a radial gradient
|
2020-09-29 02:24:59 +00:00
|
|
|
*
|
|
|
|
* Retrieves the end value for the gradient.
|
|
|
|
*
|
|
|
|
* Returns: the end value for the gradient
|
|
|
|
*/
|
2020-09-12 02:55:37 +00:00
|
|
|
float
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_radial_gradient_node_get_end (const GskRenderNode *node)
|
2020-09-12 02:55:37 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskRadialGradientNode *self = (const GskRadialGradientNode *) node;
|
2020-09-12 02:55:37 +00:00
|
|
|
|
|
|
|
return self->end;
|
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_CONIC_GRADIENT_NODE */
|
2020-12-02 23:47:54 +00:00
|
|
|
|
2020-12-15 19:18:26 +00:00
|
|
|
/**
|
|
|
|
* GskConicGradientNode:
|
|
|
|
*
|
|
|
|
* A render node for a conic gradient.
|
|
|
|
*/
|
|
|
|
|
2020-12-02 23:47:54 +00:00
|
|
|
struct _GskConicGradientNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
graphene_point_t center;
|
|
|
|
float rotation;
|
2021-01-26 15:15:12 +00:00
|
|
|
float angle;
|
2020-12-02 23:47:54 +00:00
|
|
|
|
|
|
|
gsize n_stops;
|
|
|
|
GskColorStop *stops;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_conic_gradient_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskConicGradientNode *self = (GskConicGradientNode *) node;
|
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_CONIC_GRADIENT_NODE));
|
|
|
|
|
|
|
|
g_free (self->stops);
|
|
|
|
|
|
|
|
parent_class->finalize (node);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEG_TO_RAD(x) ((x) * (G_PI / 180.f))
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cairo_mesh_pattern_set_corner_rgba (cairo_pattern_t *pattern,
|
|
|
|
guint corner_num,
|
|
|
|
const GdkRGBA *rgba)
|
|
|
|
{
|
|
|
|
cairo_mesh_pattern_set_corner_color_rgba (pattern, corner_num, rgba->red, rgba->green, rgba->blue, rgba->alpha);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
project (double angle,
|
|
|
|
double radius,
|
|
|
|
double *x_out,
|
|
|
|
double *y_out)
|
|
|
|
{
|
|
|
|
double x, y;
|
|
|
|
|
2021-11-28 07:00:52 +00:00
|
|
|
#ifdef HAVE_SINCOS
|
|
|
|
sincos (angle, &y, &x);
|
|
|
|
#else
|
|
|
|
x = cos (angle);
|
|
|
|
y = sin (angle);
|
|
|
|
#endif
|
|
|
|
*x_out = radius * x;
|
|
|
|
*y_out = radius * y;
|
2020-12-02 23:47:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_conic_gradient_node_add_patch (cairo_pattern_t *pattern,
|
2020-12-02 23:47:54 +00:00
|
|
|
float radius,
|
|
|
|
float start_angle,
|
|
|
|
const GdkRGBA *start_color,
|
|
|
|
float end_angle,
|
|
|
|
const GdkRGBA *end_color)
|
|
|
|
{
|
|
|
|
double x, y;
|
|
|
|
|
|
|
|
cairo_mesh_pattern_begin_patch (pattern);
|
|
|
|
|
|
|
|
cairo_mesh_pattern_move_to (pattern, 0, 0);
|
|
|
|
project (start_angle, radius, &x, &y);
|
|
|
|
cairo_mesh_pattern_line_to (pattern, x, y);
|
|
|
|
project (end_angle, radius, &x, &y);
|
|
|
|
cairo_mesh_pattern_line_to (pattern, x, y);
|
|
|
|
cairo_mesh_pattern_line_to (pattern, 0, 0);
|
|
|
|
|
|
|
|
_cairo_mesh_pattern_set_corner_rgba (pattern, 0, start_color);
|
|
|
|
_cairo_mesh_pattern_set_corner_rgba (pattern, 1, start_color);
|
|
|
|
_cairo_mesh_pattern_set_corner_rgba (pattern, 2, end_color);
|
|
|
|
_cairo_mesh_pattern_set_corner_rgba (pattern, 3, end_color);
|
|
|
|
|
|
|
|
cairo_mesh_pattern_end_patch (pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_rgba_color_interpolate (GdkRGBA *dest,
|
|
|
|
const GdkRGBA *src1,
|
|
|
|
const GdkRGBA *src2,
|
|
|
|
double progress)
|
|
|
|
{
|
|
|
|
double alpha = src1->alpha * (1.0 - progress) + src2->alpha * progress;
|
|
|
|
|
|
|
|
dest->alpha = alpha;
|
|
|
|
if (alpha == 0)
|
|
|
|
{
|
|
|
|
dest->red = src1->red * (1.0 - progress) + src2->red * progress;
|
|
|
|
dest->green = src1->green * (1.0 - progress) + src2->green * progress;
|
|
|
|
dest->blue = src1->blue * (1.0 - progress) + src2->blue * progress;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dest->red = (src1->red * src1->alpha * (1.0 - progress) + src2->red * src2->alpha * progress) / alpha;
|
|
|
|
dest->green = (src1->green * src1->alpha * (1.0 - progress) + src2->green * src2->alpha * progress) / alpha;
|
|
|
|
dest->blue = (src1->blue * src1->alpha * (1.0 - progress) + src2->blue * src2->alpha * progress) / alpha;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_conic_gradient_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskConicGradientNode *self = (GskConicGradientNode *) node;
|
|
|
|
cairo_pattern_t *pattern;
|
|
|
|
graphene_point_t corner;
|
|
|
|
float radius;
|
|
|
|
gsize i;
|
|
|
|
|
|
|
|
pattern = cairo_pattern_create_mesh ();
|
|
|
|
graphene_rect_get_top_right (&node->bounds, &corner);
|
|
|
|
radius = graphene_point_distance (&self->center, &corner, NULL, NULL);
|
|
|
|
graphene_rect_get_bottom_right (&node->bounds, &corner);
|
|
|
|
radius = MAX (radius, graphene_point_distance (&self->center, &corner, NULL, NULL));
|
|
|
|
graphene_rect_get_bottom_left (&node->bounds, &corner);
|
|
|
|
radius = MAX (radius, graphene_point_distance (&self->center, &corner, NULL, NULL));
|
|
|
|
graphene_rect_get_top_left (&node->bounds, &corner);
|
|
|
|
radius = MAX (radius, graphene_point_distance (&self->center, &corner, NULL, NULL));
|
|
|
|
|
|
|
|
for (i = 0; i <= self->n_stops; i++)
|
|
|
|
{
|
|
|
|
GskColorStop *stop1 = &self->stops[MAX (i, 1) - 1];
|
|
|
|
GskColorStop *stop2 = &self->stops[MIN (i, self->n_stops - 1)];
|
|
|
|
double offset1 = i > 0 ? stop1->offset : 0;
|
|
|
|
double offset2 = i < self->n_stops ? stop2->offset : 1;
|
|
|
|
double start_angle, end_angle;
|
|
|
|
|
|
|
|
offset1 = offset1 * 360 + self->rotation - 90;
|
|
|
|
offset2 = offset2 * 360 + self->rotation - 90;
|
|
|
|
|
|
|
|
for (start_angle = offset1; start_angle < offset2; start_angle = end_angle)
|
|
|
|
{
|
|
|
|
GdkRGBA start_color, end_color;
|
|
|
|
end_angle = (floor (start_angle / 45) + 1) * 45;
|
|
|
|
end_angle = MIN (end_angle, offset2);
|
|
|
|
gdk_rgba_color_interpolate (&start_color,
|
|
|
|
&stop1->color,
|
|
|
|
&stop2->color,
|
|
|
|
(start_angle - offset1) / (offset2 - offset1));
|
|
|
|
gdk_rgba_color_interpolate (&end_color,
|
|
|
|
&stop1->color,
|
|
|
|
&stop2->color,
|
|
|
|
(end_angle - offset1) / (offset2 - offset1));
|
|
|
|
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_conic_gradient_node_add_patch (pattern,
|
2020-12-02 23:47:54 +00:00
|
|
|
radius,
|
|
|
|
DEG_TO_RAD (start_angle),
|
|
|
|
&start_color,
|
|
|
|
DEG_TO_RAD (end_angle),
|
|
|
|
&end_color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD);
|
|
|
|
|
|
|
|
gsk_cairo_rectangle (cr, &node->bounds);
|
|
|
|
cairo_translate (cr, self->center.x, self->center.y);
|
|
|
|
cairo_set_source (cr, pattern);
|
|
|
|
cairo_fill (cr);
|
|
|
|
|
|
|
|
cairo_pattern_destroy (pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_conic_gradient_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2020-12-02 23:47:54 +00:00
|
|
|
{
|
|
|
|
GskConicGradientNode *self1 = (GskConicGradientNode *) node1;
|
|
|
|
GskConicGradientNode *self2 = (GskConicGradientNode *) node2;
|
|
|
|
gsize i;
|
|
|
|
|
|
|
|
if (!graphene_point_equal (&self1->center, &self2->center) ||
|
|
|
|
self1->rotation != self2->rotation ||
|
|
|
|
self1->n_stops != self2->n_stops)
|
|
|
|
{
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2020-12-02 23:47:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < self1->n_stops; i++)
|
|
|
|
{
|
|
|
|
GskColorStop *stop1 = &self1->stops[i];
|
|
|
|
GskColorStop *stop2 = &self2->stops[i];
|
|
|
|
|
|
|
|
if (stop1->offset != stop2->offset ||
|
|
|
|
!gdk_rgba_equal (&stop1->color, &stop2->color))
|
|
|
|
{
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2020-12-02 23:47:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_conic_gradient_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_CONIC_GRADIENT_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_conic_gradient_node_finalize;
|
|
|
|
node_class->draw = gsk_conic_gradient_node_draw;
|
|
|
|
node_class->diff = gsk_conic_gradient_node_diff;
|
|
|
|
}
|
|
|
|
|
2020-12-02 23:47:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_conic_gradient_node_new:
|
|
|
|
* @bounds: the bounds of the node
|
|
|
|
* @center: the center of the gradient
|
|
|
|
* @rotation: the rotation of the gradient in degrees
|
2021-02-20 06:09:55 +00:00
|
|
|
* @color_stops: (array length=n_color_stops): a pointer to an array of
|
|
|
|
* `GskColorStop` defining the gradient. The offsets of all color stops
|
|
|
|
* must be increasing. The first stop's offset must be >= 0 and the last
|
2020-12-02 23:47:54 +00:00
|
|
|
* stop's offset must be <= 1.
|
|
|
|
* @n_color_stops: the number of elements in @color_stops
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that draws a conic gradient.
|
|
|
|
*
|
|
|
|
* The conic gradient
|
2020-12-02 23:47:54 +00:00
|
|
|
* starts around @center in the direction of @rotation. A rotation of 0 means
|
|
|
|
* that the gradient points up. Color stops are then added clockwise.
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer full) (type GskConicGradientNode): A new `GskRenderNode`
|
2020-12-02 23:47:54 +00:00
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_conic_gradient_node_new (const graphene_rect_t *bounds,
|
|
|
|
const graphene_point_t *center,
|
|
|
|
float rotation,
|
|
|
|
const GskColorStop *color_stops,
|
|
|
|
gsize n_color_stops)
|
|
|
|
{
|
|
|
|
GskConicGradientNode *self;
|
|
|
|
GskRenderNode *node;
|
|
|
|
gsize i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (bounds != NULL, NULL);
|
|
|
|
g_return_val_if_fail (center != NULL, NULL);
|
|
|
|
g_return_val_if_fail (color_stops != NULL, NULL);
|
|
|
|
g_return_val_if_fail (n_color_stops >= 2, NULL);
|
|
|
|
g_return_val_if_fail (color_stops[0].offset >= 0, NULL);
|
|
|
|
for (i = 1; i < n_color_stops; i++)
|
|
|
|
g_return_val_if_fail (color_stops[i].offset >= color_stops[i - 1].offset, NULL);
|
|
|
|
g_return_val_if_fail (color_stops[n_color_stops - 1].offset <= 1, NULL);
|
|
|
|
|
|
|
|
self = gsk_render_node_alloc (GSK_CONIC_GRADIENT_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = FALSE;
|
2020-12-02 23:47:54 +00:00
|
|
|
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&node->bounds, bounds);
|
2020-12-02 23:47:54 +00:00
|
|
|
graphene_point_init_from_point (&self->center, center);
|
|
|
|
|
|
|
|
self->rotation = rotation;
|
|
|
|
|
|
|
|
self->n_stops = n_color_stops;
|
|
|
|
self->stops = g_malloc_n (n_color_stops, sizeof (GskColorStop));
|
|
|
|
memcpy (self->stops, color_stops, n_color_stops * sizeof (GskColorStop));
|
|
|
|
|
2021-01-26 15:15:12 +00:00
|
|
|
self->angle = 90.f - self->rotation;
|
|
|
|
self->angle = G_PI * self->angle / 180.f;
|
|
|
|
self->angle = fmodf (self->angle, 2.f * G_PI);
|
|
|
|
if (self->angle < 0.f)
|
|
|
|
self->angle += 2.f * G_PI;
|
|
|
|
|
2020-12-02 23:47:54 +00:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_conic_gradient_node_get_n_color_stops:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskConicGradientNode): a `GskRenderNode` for a conic gradient
|
2020-12-02 23:47:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the number of color stops in the gradient.
|
|
|
|
*
|
|
|
|
* Returns: the number of color stops
|
|
|
|
*/
|
|
|
|
gsize
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_conic_gradient_node_get_n_color_stops (const GskRenderNode *node)
|
2020-12-02 23:47:54 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskConicGradientNode *self = (const GskConicGradientNode *) node;
|
2020-12-02 23:47:54 +00:00
|
|
|
|
|
|
|
return self->n_stops;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_conic_gradient_node_get_color_stops:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskConicGradientNode): a `GskRenderNode` for a conic gradient
|
2020-12-02 23:47:54 +00:00
|
|
|
* @n_stops: (out) (optional): the number of color stops in the returned array
|
|
|
|
*
|
|
|
|
* Retrieves the color stops in the gradient.
|
|
|
|
*
|
|
|
|
* Returns: (array length=n_stops): the color stops in the gradient
|
|
|
|
*/
|
|
|
|
const GskColorStop *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_conic_gradient_node_get_color_stops (const GskRenderNode *node,
|
|
|
|
gsize *n_stops)
|
2020-12-02 23:47:54 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskConicGradientNode *self = (const GskConicGradientNode *) node;
|
2020-12-02 23:47:54 +00:00
|
|
|
|
|
|
|
if (n_stops != NULL)
|
|
|
|
*n_stops = self->n_stops;
|
|
|
|
|
|
|
|
return self->stops;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_conic_gradient_node_get_center:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskConicGradientNode): a `GskRenderNode` for a conic gradient
|
2020-12-02 23:47:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the center pointer for the gradient.
|
|
|
|
*
|
|
|
|
* Returns: the center point for the gradient
|
|
|
|
*/
|
|
|
|
const graphene_point_t *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_conic_gradient_node_get_center (const GskRenderNode *node)
|
2020-12-02 23:47:54 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskConicGradientNode *self = (const GskConicGradientNode *) node;
|
2020-12-02 23:47:54 +00:00
|
|
|
|
|
|
|
return &self->center;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_conic_gradient_node_get_rotation:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskConicGradientNode): a `GskRenderNode` for a conic gradient
|
2020-12-02 23:47:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the rotation for the gradient in degrees.
|
|
|
|
*
|
|
|
|
* Returns: the rotation for the gradient
|
|
|
|
*/
|
|
|
|
float
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_conic_gradient_node_get_rotation (const GskRenderNode *node)
|
2020-12-02 23:47:54 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskConicGradientNode *self = (const GskConicGradientNode *) node;
|
2020-12-02 23:47:54 +00:00
|
|
|
|
|
|
|
return self->rotation;
|
|
|
|
}
|
|
|
|
|
2021-01-26 15:15:12 +00:00
|
|
|
/**
|
|
|
|
* gsk_conic_gradient_node_get_angle:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskConicGradientNode): a `GskRenderNode` for a conic gradient
|
2021-01-26 15:15:12 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Retrieves the angle for the gradient in radians, normalized in [0, 2 * PI].
|
2021-01-26 15:15:12 +00:00
|
|
|
*
|
|
|
|
* The angle is starting at the top and going clockwise, as expressed
|
|
|
|
* in the css specification:
|
2021-02-20 06:09:55 +00:00
|
|
|
*
|
|
|
|
* angle = 90 - gsk_conic_gradient_node_get_rotation()
|
2021-01-26 15:15:12 +00:00
|
|
|
*
|
|
|
|
* Returns: the angle for the gradient
|
2021-03-07 15:51:38 +00:00
|
|
|
*
|
|
|
|
* Since: 4.2
|
2021-01-26 15:15:12 +00:00
|
|
|
*/
|
|
|
|
float
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_conic_gradient_node_get_angle (const GskRenderNode *node)
|
2021-01-26 15:15:12 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskConicGradientNode *self = (const GskConicGradientNode *) node;
|
2021-01-26 15:15:12 +00:00
|
|
|
|
|
|
|
return self->angle;
|
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_BORDER_NODE */
|
2016-12-18 17:14:53 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskBorderNode:
|
|
|
|
*
|
|
|
|
* A render node for a border.
|
|
|
|
*/
|
2016-12-18 17:14:53 +00:00
|
|
|
struct _GskBorderNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
2021-03-09 02:36:41 +00:00
|
|
|
bool uniform_width: 1;
|
|
|
|
bool uniform_color: 1;
|
2016-12-18 17:14:53 +00:00
|
|
|
GskRoundedRect outline;
|
|
|
|
float border_width[4];
|
|
|
|
GdkRGBA border_color[4];
|
|
|
|
};
|
|
|
|
|
2019-04-19 01:37:55 +00:00
|
|
|
static void
|
|
|
|
gsk_border_node_mesh_add_patch (cairo_pattern_t *pattern,
|
|
|
|
const GdkRGBA *color,
|
|
|
|
double x0,
|
|
|
|
double y0,
|
|
|
|
double x1,
|
|
|
|
double y1,
|
|
|
|
double x2,
|
|
|
|
double y2,
|
|
|
|
double x3,
|
|
|
|
double y3)
|
|
|
|
{
|
|
|
|
cairo_mesh_pattern_begin_patch (pattern);
|
|
|
|
cairo_mesh_pattern_move_to (pattern, x0, y0);
|
|
|
|
cairo_mesh_pattern_line_to (pattern, x1, y1);
|
|
|
|
cairo_mesh_pattern_line_to (pattern, x2, y2);
|
|
|
|
cairo_mesh_pattern_line_to (pattern, x3, y3);
|
|
|
|
cairo_mesh_pattern_set_corner_color_rgba (pattern, 0, color->red, color->green, color->blue, color->alpha);
|
|
|
|
cairo_mesh_pattern_set_corner_color_rgba (pattern, 1, color->red, color->green, color->blue, color->alpha);
|
|
|
|
cairo_mesh_pattern_set_corner_color_rgba (pattern, 2, color->red, color->green, color->blue, color->alpha);
|
|
|
|
cairo_mesh_pattern_set_corner_color_rgba (pattern, 3, color->red, color->green, color->blue, color->alpha);
|
|
|
|
cairo_mesh_pattern_end_patch (pattern);
|
|
|
|
}
|
|
|
|
|
2016-12-18 17:14:53 +00:00
|
|
|
static void
|
|
|
|
gsk_border_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskBorderNode *self = (GskBorderNode *) node;
|
|
|
|
GskRoundedRect inside;
|
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
|
|
|
|
gsk_rounded_rect_init_copy (&inside, &self->outline);
|
|
|
|
gsk_rounded_rect_shrink (&inside,
|
|
|
|
self->border_width[0], self->border_width[1],
|
|
|
|
self->border_width[2], self->border_width[3]);
|
|
|
|
|
|
|
|
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
|
|
|
|
gsk_rounded_rect_path (&self->outline, cr);
|
|
|
|
gsk_rounded_rect_path (&inside, cr);
|
|
|
|
|
|
|
|
if (gdk_rgba_equal (&self->border_color[0], &self->border_color[1]) &&
|
|
|
|
gdk_rgba_equal (&self->border_color[0], &self->border_color[2]) &&
|
|
|
|
gdk_rgba_equal (&self->border_color[0], &self->border_color[3]))
|
|
|
|
{
|
|
|
|
gdk_cairo_set_source_rgba (cr, &self->border_color[0]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const graphene_rect_t *bounds = &self->outline.bounds;
|
2019-04-19 01:37:55 +00:00
|
|
|
/* distance to center "line":
|
|
|
|
* +-------------------------+
|
|
|
|
* | |
|
|
|
|
* | |
|
|
|
|
* | ---this-line--- |
|
|
|
|
* | |
|
|
|
|
* | |
|
|
|
|
* +-------------------------+
|
2020-05-28 08:00:03 +00:00
|
|
|
* That line is equidistant from all sides. It's either horizontal
|
2019-04-19 01:37:55 +00:00
|
|
|
* or vertical, depending on if the rect is wider or taller.
|
|
|
|
* We use the 4 sides spanned up by connecting the line to the corner
|
|
|
|
* points to color the regions of the rectangle differently.
|
|
|
|
* Note that the call to cairo_fill() will add the potential final
|
|
|
|
* segment by closing the path, so we don't have to care.
|
|
|
|
*/
|
|
|
|
cairo_pattern_t *mesh;
|
|
|
|
cairo_matrix_t mat;
|
2019-05-02 17:22:43 +00:00
|
|
|
graphene_point_t tl, br;
|
|
|
|
float scale;
|
2019-04-19 01:37:55 +00:00
|
|
|
|
|
|
|
mesh = cairo_pattern_create_mesh ();
|
|
|
|
cairo_matrix_init_translate (&mat, -bounds->origin.x, -bounds->origin.y);
|
|
|
|
cairo_pattern_set_matrix (mesh, &mat);
|
2016-12-18 17:14:53 +00:00
|
|
|
|
2019-05-02 17:22:43 +00:00
|
|
|
scale = MIN (bounds->size.width / (self->border_width[1] + self->border_width[3]),
|
|
|
|
bounds->size.height / (self->border_width[0] + self->border_width[2]));
|
|
|
|
graphene_point_init (&tl,
|
|
|
|
self->border_width[3] * scale,
|
|
|
|
self->border_width[0] * scale);
|
|
|
|
graphene_point_init (&br,
|
|
|
|
bounds->size.width - self->border_width[1] * scale,
|
|
|
|
bounds->size.height - self->border_width[2] * scale);
|
|
|
|
|
2017-08-29 09:48:13 +00:00
|
|
|
/* Top */
|
|
|
|
if (self->border_width[0] > 0)
|
|
|
|
{
|
2019-04-19 01:37:55 +00:00
|
|
|
gsk_border_node_mesh_add_patch (mesh,
|
|
|
|
&self->border_color[0],
|
|
|
|
0, 0,
|
2019-05-02 17:22:43 +00:00
|
|
|
tl.x, tl.y,
|
|
|
|
br.x, tl.y,
|
2019-04-19 01:37:55 +00:00
|
|
|
bounds->size.width, 0);
|
2017-08-29 09:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Right */
|
|
|
|
if (self->border_width[1] > 0)
|
|
|
|
{
|
2019-04-19 01:37:55 +00:00
|
|
|
gsk_border_node_mesh_add_patch (mesh,
|
|
|
|
&self->border_color[1],
|
|
|
|
bounds->size.width, 0,
|
2019-05-02 17:22:43 +00:00
|
|
|
br.x, tl.y,
|
|
|
|
br.x, br.y,
|
2019-04-19 01:37:55 +00:00
|
|
|
bounds->size.width, bounds->size.height);
|
2017-08-29 09:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Bottom */
|
|
|
|
if (self->border_width[2] > 0)
|
|
|
|
{
|
2019-04-19 01:37:55 +00:00
|
|
|
gsk_border_node_mesh_add_patch (mesh,
|
|
|
|
&self->border_color[2],
|
|
|
|
0, bounds->size.height,
|
2019-05-02 17:22:43 +00:00
|
|
|
tl.x, br.y,
|
|
|
|
br.x, br.y,
|
2019-04-19 01:37:55 +00:00
|
|
|
bounds->size.width, bounds->size.height);
|
2017-08-29 09:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Left */
|
|
|
|
if (self->border_width[3] > 0)
|
|
|
|
{
|
2019-04-19 01:37:55 +00:00
|
|
|
gsk_border_node_mesh_add_patch (mesh,
|
|
|
|
&self->border_color[3],
|
|
|
|
0, 0,
|
2019-05-02 17:22:43 +00:00
|
|
|
tl.x, tl.y,
|
|
|
|
tl.x, br.y,
|
2019-04-19 01:37:55 +00:00
|
|
|
0, bounds->size.height);
|
2017-08-29 09:48:13 +00:00
|
|
|
}
|
2019-04-19 01:37:55 +00:00
|
|
|
|
|
|
|
cairo_set_source (cr, mesh);
|
|
|
|
cairo_pattern_destroy (mesh);
|
2016-12-18 17:14:53 +00:00
|
|
|
}
|
|
|
|
|
2019-04-19 01:37:55 +00:00
|
|
|
cairo_fill (cr);
|
2016-12-18 17:14:53 +00:00
|
|
|
cairo_restore (cr);
|
|
|
|
}
|
|
|
|
|
2018-03-27 22:34:23 +00:00
|
|
|
static void
|
|
|
|
gsk_border_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2018-03-27 22:34:23 +00:00
|
|
|
{
|
|
|
|
GskBorderNode *self1 = (GskBorderNode *) node1;
|
|
|
|
GskBorderNode *self2 = (GskBorderNode *) node2;
|
2021-03-09 02:36:41 +00:00
|
|
|
gboolean uniform1 = self1->uniform_width && self1->uniform_color;
|
|
|
|
gboolean uniform2 = self2->uniform_width && self2->uniform_color;
|
2018-03-27 22:34:23 +00:00
|
|
|
|
2021-03-09 02:36:41 +00:00
|
|
|
if (uniform1 &&
|
|
|
|
uniform2 &&
|
2020-08-07 04:54:16 +00:00
|
|
|
self1->border_width[0] == self2->border_width[0] &&
|
|
|
|
gsk_rounded_rect_equal (&self1->outline, &self2->outline) &&
|
|
|
|
gdk_rgba_equal (&self1->border_color[0], &self2->border_color[0]))
|
2020-07-24 17:06:50 +00:00
|
|
|
return;
|
|
|
|
|
2020-12-21 08:56:58 +00:00
|
|
|
/* Different uniformity -> diff impossible */
|
2021-03-17 15:38:01 +00:00
|
|
|
if (uniform1 ^ uniform2)
|
2020-12-21 08:56:58 +00:00
|
|
|
{
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2020-12-21 08:56:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-21 08:56:19 +00:00
|
|
|
if (self1->border_width[0] == self2->border_width[0] &&
|
|
|
|
self1->border_width[1] == self2->border_width[1] &&
|
|
|
|
self1->border_width[2] == self2->border_width[2] &&
|
|
|
|
self1->border_width[3] == self2->border_width[3] &&
|
2018-03-27 22:34:23 +00:00
|
|
|
gdk_rgba_equal (&self1->border_color[0], &self2->border_color[0]) &&
|
|
|
|
gdk_rgba_equal (&self1->border_color[1], &self2->border_color[1]) &&
|
|
|
|
gdk_rgba_equal (&self1->border_color[2], &self2->border_color[2]) &&
|
|
|
|
gdk_rgba_equal (&self1->border_color[3], &self2->border_color[3]) &&
|
2020-12-21 08:56:19 +00:00
|
|
|
gsk_rounded_rect_equal (&self1->outline, &self2->outline))
|
2018-03-27 22:34:23 +00:00
|
|
|
return;
|
|
|
|
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2018-03-27 22:34:23 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_border_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_BORDER_NODE;
|
|
|
|
|
|
|
|
node_class->draw = gsk_border_node_draw;
|
|
|
|
node_class->diff = gsk_border_node_diff;
|
|
|
|
}
|
|
|
|
|
2020-06-06 00:19:45 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_border_node_get_outline:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskBorderNode): a `GskRenderNode` for a border
|
2020-06-06 00:19:45 +00:00
|
|
|
*
|
|
|
|
* Retrieves the outline of the border.
|
|
|
|
*
|
|
|
|
* Returns: the outline of the border
|
|
|
|
*/
|
2016-12-18 17:14:53 +00:00
|
|
|
const GskRoundedRect *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_border_node_get_outline (const GskRenderNode *node)
|
2016-12-18 17:14:53 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskBorderNode *self = (const GskBorderNode *) node;
|
2016-12-18 17:14:53 +00:00
|
|
|
|
|
|
|
return &self->outline;
|
|
|
|
}
|
|
|
|
|
2020-06-06 00:19:45 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_border_node_get_widths:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskBorderNode): a `GskRenderNode` for a border
|
2020-06-06 00:19:45 +00:00
|
|
|
*
|
|
|
|
* Retrieves the stroke widths of the border.
|
|
|
|
*
|
2020-11-17 13:48:07 +00:00
|
|
|
* Returns: (transfer none) (array fixed-size=4): an array of 4 floats
|
|
|
|
* for the top, right, bottom and left stroke width of the border,
|
|
|
|
* respectively
|
2020-06-06 00:19:45 +00:00
|
|
|
*/
|
2017-01-10 13:59:20 +00:00
|
|
|
const float *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_border_node_get_widths (const GskRenderNode *node)
|
2016-12-18 17:14:53 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskBorderNode *self = (const GskBorderNode *) node;
|
2016-12-18 17:14:53 +00:00
|
|
|
|
2017-01-10 13:59:20 +00:00
|
|
|
return self->border_width;
|
2016-12-18 17:14:53 +00:00
|
|
|
}
|
|
|
|
|
2020-06-06 00:19:45 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_border_node_get_colors:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskBorderNode): a `GskRenderNode` for a border
|
2020-06-06 00:19:45 +00:00
|
|
|
*
|
|
|
|
* Retrieves the colors of the border.
|
|
|
|
*
|
2021-05-20 03:40:54 +00:00
|
|
|
* Returns: (transfer none): an array of 4 `GdkRGBA` structs
|
2020-06-06 00:19:45 +00:00
|
|
|
* for the top, right, bottom and left color of the border
|
|
|
|
*/
|
2016-12-18 17:14:53 +00:00
|
|
|
const GdkRGBA *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_border_node_get_colors (const GskRenderNode *node)
|
2016-12-18 17:14:53 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskBorderNode *self = (const GskBorderNode *) node;
|
2016-12-18 17:14:53 +00:00
|
|
|
|
2017-01-10 13:59:20 +00:00
|
|
|
return self->border_color;
|
2016-12-18 17:14:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_border_node_new:
|
2021-05-20 03:40:54 +00:00
|
|
|
* @outline: a `GskRoundedRect` describing the outline of the border
|
2019-02-21 01:11:13 +00:00
|
|
|
* @border_width: (array fixed-size=4): the stroke width of the border on
|
|
|
|
* the top, right, bottom and left side respectively.
|
|
|
|
* @border_color: (array fixed-size=4): the color used on the top, right,
|
|
|
|
* bottom and left side.
|
2016-12-18 17:14:53 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that will stroke a border rectangle inside the
|
|
|
|
* given @outline.
|
2016-12-18 17:14:53 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* The 4 sides of the border can have different widths and colors.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full) (type GskBorderNode): A new `GskRenderNode`
|
2016-12-18 17:14:53 +00:00
|
|
|
*/
|
|
|
|
GskRenderNode *
|
2020-07-24 13:59:45 +00:00
|
|
|
gsk_border_node_new (const GskRoundedRect *outline,
|
|
|
|
const float border_width[4],
|
|
|
|
const GdkRGBA border_color[4])
|
2016-12-18 17:14:53 +00:00
|
|
|
{
|
|
|
|
GskBorderNode *self;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNode *node;
|
2016-12-18 17:14:53 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (outline != NULL, NULL);
|
|
|
|
g_return_val_if_fail (border_width != NULL, NULL);
|
|
|
|
g_return_val_if_fail (border_color != NULL, NULL);
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self = gsk_render_node_alloc (GSK_BORDER_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = FALSE;
|
2016-12-18 17:14:53 +00:00
|
|
|
|
|
|
|
gsk_rounded_rect_init_copy (&self->outline, outline);
|
|
|
|
memcpy (self->border_width, border_width, sizeof (self->border_width));
|
|
|
|
memcpy (self->border_color, border_color, sizeof (self->border_color));
|
|
|
|
|
2020-07-24 13:59:45 +00:00
|
|
|
if (border_width[0] == border_width[1] &&
|
|
|
|
border_width[0] == border_width[2] &&
|
2021-03-09 02:36:41 +00:00
|
|
|
border_width[0] == border_width[3])
|
|
|
|
self->uniform_width = TRUE;
|
|
|
|
else
|
|
|
|
self->uniform_width = FALSE;
|
|
|
|
|
|
|
|
if (gdk_rgba_equal (&border_color[0], &border_color[1]) &&
|
2020-07-24 13:59:45 +00:00
|
|
|
gdk_rgba_equal (&border_color[0], &border_color[2]) &&
|
|
|
|
gdk_rgba_equal (&border_color[0], &border_color[3]))
|
2021-03-09 02:36:41 +00:00
|
|
|
self->uniform_color = TRUE;
|
2020-07-24 13:59:45 +00:00
|
|
|
else
|
2021-03-09 02:36:41 +00:00
|
|
|
self->uniform_color = FALSE;
|
2020-07-24 13:59:45 +00:00
|
|
|
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&node->bounds, &self->outline.bounds);
|
2016-12-21 10:21:38 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return node;
|
2016-12-18 17:14:53 +00:00
|
|
|
}
|
|
|
|
|
2020-07-28 12:33:05 +00:00
|
|
|
/* Private */
|
2020-07-24 13:59:45 +00:00
|
|
|
bool
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_border_node_get_uniform (const GskRenderNode *self)
|
2020-07-24 13:59:45 +00:00
|
|
|
{
|
2021-03-09 02:36:41 +00:00
|
|
|
const GskBorderNode *node = (const GskBorderNode *)self;
|
|
|
|
return node->uniform_width && node->uniform_color;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
gsk_border_node_get_uniform_color (const GskRenderNode *self)
|
|
|
|
{
|
|
|
|
const GskBorderNode *node = (const GskBorderNode *)self;
|
|
|
|
return node->uniform_color;
|
2020-07-24 13:59:45 +00:00
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_TEXTURE_NODE */
|
2016-12-11 01:59:47 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskTextureNode:
|
|
|
|
*
|
2021-05-20 03:40:54 +00:00
|
|
|
* A render node for a `GdkTexture`.
|
2020-12-01 14:16:28 +00:00
|
|
|
*/
|
2017-11-04 15:03:03 +00:00
|
|
|
struct _GskTextureNode
|
2016-12-11 03:28:21 +00:00
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
2017-11-02 20:39:00 +00:00
|
|
|
GdkTexture *texture;
|
2016-12-11 03:28:21 +00:00
|
|
|
};
|
|
|
|
|
2016-12-11 03:18:25 +00:00
|
|
|
static void
|
2017-11-04 15:03:03 +00:00
|
|
|
gsk_texture_node_finalize (GskRenderNode *node)
|
2016-12-11 03:18:25 +00:00
|
|
|
{
|
2017-11-04 15:03:03 +00:00
|
|
|
GskTextureNode *self = (GskTextureNode *) node;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_TEXTURE_NODE));
|
|
|
|
|
|
|
|
g_clear_object (&self->texture);
|
2016-12-11 03:28:21 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
parent_class->finalize (node);
|
2016-12-11 03:18:25 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 02:05:15 +00:00
|
|
|
static void
|
2017-11-04 15:03:03 +00:00
|
|
|
gsk_texture_node_draw (GskRenderNode *node,
|
2016-12-13 02:05:15 +00:00
|
|
|
cairo_t *cr)
|
|
|
|
{
|
2017-11-04 15:03:03 +00:00
|
|
|
GskTextureNode *self = (GskTextureNode *) node;
|
2016-12-13 02:05:15 +00:00
|
|
|
cairo_surface_t *surface;
|
2019-05-10 00:54:24 +00:00
|
|
|
cairo_pattern_t *pattern;
|
2020-02-12 17:44:11 +00:00
|
|
|
cairo_matrix_t matrix;
|
2016-12-13 02:05:15 +00:00
|
|
|
|
2017-11-02 20:39:00 +00:00
|
|
|
surface = gdk_texture_download_surface (self->texture);
|
2019-05-10 00:54:24 +00:00
|
|
|
pattern = cairo_pattern_create_for_surface (surface);
|
|
|
|
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD);
|
2016-12-13 02:05:15 +00:00
|
|
|
|
2020-02-12 17:44:11 +00:00
|
|
|
cairo_matrix_init_scale (&matrix,
|
|
|
|
gdk_texture_get_width (self->texture) / node->bounds.size.width,
|
|
|
|
gdk_texture_get_height (self->texture) / node->bounds.size.height);
|
|
|
|
cairo_matrix_translate (&matrix,
|
|
|
|
-node->bounds.origin.x,
|
|
|
|
-node->bounds.origin.y);
|
|
|
|
cairo_pattern_set_matrix (pattern, &matrix);
|
2016-12-13 02:05:15 +00:00
|
|
|
|
2020-02-12 17:44:11 +00:00
|
|
|
cairo_set_source (cr, pattern);
|
2019-05-10 00:54:24 +00:00
|
|
|
cairo_pattern_destroy (pattern);
|
2016-12-13 02:05:15 +00:00
|
|
|
cairo_surface_destroy (surface);
|
2020-02-12 17:44:11 +00:00
|
|
|
|
2020-02-13 00:48:03 +00:00
|
|
|
gsk_cairo_rectangle (cr, &node->bounds);
|
2020-02-12 17:44:11 +00:00
|
|
|
cairo_fill (cr);
|
2016-12-13 02:05:15 +00:00
|
|
|
}
|
|
|
|
|
2018-03-27 22:34:23 +00:00
|
|
|
static void
|
|
|
|
gsk_texture_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2018-03-27 22:34:23 +00:00
|
|
|
{
|
|
|
|
GskTextureNode *self1 = (GskTextureNode *) node1;
|
|
|
|
GskTextureNode *self2 = (GskTextureNode *) node2;
|
2023-04-27 22:12:49 +00:00
|
|
|
cairo_region_t *sub;
|
2018-03-27 22:34:23 +00:00
|
|
|
|
2023-11-13 21:12:58 +00:00
|
|
|
if (!gsk_rect_equal (&node1->bounds, &node2->bounds) ||
|
2023-04-27 22:12:49 +00:00
|
|
|
gdk_texture_get_width (self1->texture) != gdk_texture_get_width (self2->texture) ||
|
|
|
|
gdk_texture_get_height (self1->texture) != gdk_texture_get_height (self2->texture))
|
|
|
|
{
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2023-04-27 22:12:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self1->texture == self2->texture)
|
2018-03-27 22:34:23 +00:00
|
|
|
return;
|
|
|
|
|
2023-04-27 22:12:49 +00:00
|
|
|
sub = cairo_region_create ();
|
|
|
|
gdk_texture_diff (self1->texture, self2->texture, sub);
|
2023-10-31 23:07:23 +00:00
|
|
|
region_union_region_affine (data->region,
|
2023-04-27 22:12:49 +00:00
|
|
|
sub,
|
|
|
|
node1->bounds.size.width / gdk_texture_get_width (self1->texture),
|
|
|
|
node1->bounds.size.height / gdk_texture_get_height (self1->texture),
|
|
|
|
node1->bounds.origin.x,
|
|
|
|
node1->bounds.origin.y);
|
|
|
|
cairo_region_destroy (sub);
|
2018-03-27 22:34:23 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_texture_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_TEXTURE_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_texture_node_finalize;
|
|
|
|
node_class->draw = gsk_texture_node_draw;
|
|
|
|
node_class->diff = gsk_texture_node_diff;
|
|
|
|
}
|
|
|
|
|
2018-01-03 07:17:23 +00:00
|
|
|
/**
|
|
|
|
* gsk_texture_node_get_texture:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskTextureNode): a `GskRenderNode` of type %GSK_TEXTURE_NODE
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Retrieves the `GdkTexture` used when creating this `GskRenderNode`.
|
2018-01-03 07:17:23 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer none): the `GdkTexture`
|
2018-01-03 07:17:23 +00:00
|
|
|
*/
|
2017-11-02 20:39:00 +00:00
|
|
|
GdkTexture *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_texture_node_get_texture (const GskRenderNode *node)
|
2016-12-11 01:59:47 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskTextureNode *self = (const GskTextureNode *) node;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-11-04 15:03:03 +00:00
|
|
|
* gsk_texture_node_new:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @texture: the `GdkTexture`
|
2016-12-11 01:59:47 +00:00
|
|
|
* @bounds: the rectangle to render the texture into
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that will render the given
|
2016-12-11 01:59:47 +00:00
|
|
|
* @texture into the area given by @bounds.
|
|
|
|
*
|
2023-03-13 07:38:58 +00:00
|
|
|
* Note that GSK applies linear filtering when textures are
|
|
|
|
* scaled and transformed. See [class@Gsk.TextureScaleNode]
|
|
|
|
* for a way to influence filtering.
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer full) (type GskTextureNode): A new `GskRenderNode`
|
2016-12-11 01:59:47 +00:00
|
|
|
*/
|
|
|
|
GskRenderNode *
|
2017-11-04 15:03:03 +00:00
|
|
|
gsk_texture_node_new (GdkTexture *texture,
|
2016-12-11 01:59:47 +00:00
|
|
|
const graphene_rect_t *bounds)
|
|
|
|
{
|
2017-11-04 15:03:03 +00:00
|
|
|
GskTextureNode *self;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNode *node;
|
2016-12-11 01:59:47 +00:00
|
|
|
|
2017-11-02 20:39:00 +00:00
|
|
|
g_return_val_if_fail (GDK_IS_TEXTURE (texture), NULL);
|
2016-12-11 01:59:47 +00:00
|
|
|
g_return_val_if_fail (bounds != NULL, NULL);
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self = gsk_render_node_alloc (GSK_TEXTURE_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = FALSE;
|
2016-12-11 01:59:47 +00:00
|
|
|
|
2017-01-01 12:40:13 +00:00
|
|
|
self->texture = g_object_ref (texture);
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&node->bounds, bounds);
|
2016-12-11 01:59:47 +00:00
|
|
|
|
2023-06-15 18:27:13 +00:00
|
|
|
node->preferred_depth = gdk_memory_format_get_depth (gdk_texture_get_format (texture));
|
2021-10-01 20:23:12 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return node;
|
2016-12-11 01:59:47 +00:00
|
|
|
}
|
|
|
|
|
2023-02-08 03:52:06 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_TEXTURE_SCALE_NODE */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GskTextureScaleNode:
|
|
|
|
*
|
|
|
|
* A render node for a `GdkTexture`.
|
2023-02-19 09:18:15 +00:00
|
|
|
*
|
|
|
|
* Since: 4.10
|
2023-02-08 03:52:06 +00:00
|
|
|
*/
|
|
|
|
struct _GskTextureScaleNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GdkTexture *texture;
|
|
|
|
GskScalingFilter filter;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_texture_scale_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskTextureScaleNode *self = (GskTextureScaleNode *) node;
|
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_TEXTURE_SCALE_NODE));
|
|
|
|
|
|
|
|
g_clear_object (&self->texture);
|
|
|
|
|
|
|
|
parent_class->finalize (node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_texture_scale_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskTextureScaleNode *self = (GskTextureScaleNode *) node;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_pattern_t *pattern;
|
|
|
|
cairo_matrix_t matrix;
|
|
|
|
cairo_filter_t filters[] = {
|
|
|
|
CAIRO_FILTER_BILINEAR,
|
|
|
|
CAIRO_FILTER_NEAREST,
|
|
|
|
CAIRO_FILTER_GOOD,
|
|
|
|
};
|
|
|
|
cairo_t *cr2;
|
|
|
|
cairo_surface_t *surface2;
|
2023-02-13 00:44:48 +00:00
|
|
|
graphene_rect_t clip_rect;
|
|
|
|
|
|
|
|
/* Make sure we draw the minimum region by using the clip */
|
|
|
|
gsk_cairo_rectangle (cr, &node->bounds);
|
|
|
|
cairo_clip (cr);
|
|
|
|
_graphene_rect_init_from_clip_extents (&clip_rect, cr);
|
|
|
|
if (clip_rect.size.width <= 0 || clip_rect.size.height <= 0)
|
|
|
|
return;
|
2023-02-08 03:52:06 +00:00
|
|
|
|
|
|
|
surface2 = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
|
2023-02-13 00:44:48 +00:00
|
|
|
(int) ceilf (clip_rect.size.width),
|
|
|
|
(int) ceilf (clip_rect.size.height));
|
|
|
|
cairo_surface_set_device_offset (surface2, -clip_rect.origin.x, -clip_rect.origin.y);
|
2023-02-08 03:52:06 +00:00
|
|
|
cr2 = cairo_create (surface2);
|
|
|
|
|
|
|
|
surface = gdk_texture_download_surface (self->texture);
|
|
|
|
pattern = cairo_pattern_create_for_surface (surface);
|
|
|
|
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD);
|
|
|
|
|
|
|
|
cairo_matrix_init_scale (&matrix,
|
|
|
|
gdk_texture_get_width (self->texture) / node->bounds.size.width,
|
|
|
|
gdk_texture_get_height (self->texture) / node->bounds.size.height);
|
2023-10-27 18:45:12 +00:00
|
|
|
cairo_matrix_translate (&matrix, -node->bounds.origin.x, -node->bounds.origin.y);
|
2023-02-08 03:52:06 +00:00
|
|
|
cairo_pattern_set_matrix (pattern, &matrix);
|
|
|
|
cairo_pattern_set_filter (pattern, filters[self->filter]);
|
|
|
|
|
|
|
|
cairo_set_source (cr2, pattern);
|
|
|
|
cairo_pattern_destroy (pattern);
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
2023-10-27 18:45:12 +00:00
|
|
|
gsk_cairo_rectangle (cr2, &node->bounds);
|
2023-02-08 03:52:06 +00:00
|
|
|
cairo_fill (cr2);
|
|
|
|
|
|
|
|
cairo_destroy (cr2);
|
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
|
2023-10-27 18:45:12 +00:00
|
|
|
cairo_set_source_surface (cr, surface2, 0, 0);
|
|
|
|
cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_PAD);
|
2023-02-08 03:52:06 +00:00
|
|
|
cairo_surface_destroy (surface2);
|
|
|
|
|
|
|
|
gsk_cairo_rectangle (cr, &node->bounds);
|
|
|
|
cairo_fill (cr);
|
|
|
|
|
|
|
|
cairo_restore (cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_texture_scale_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2023-02-08 03:52:06 +00:00
|
|
|
{
|
|
|
|
GskTextureScaleNode *self1 = (GskTextureScaleNode *) node1;
|
|
|
|
GskTextureScaleNode *self2 = (GskTextureScaleNode *) node2;
|
2023-05-01 20:23:50 +00:00
|
|
|
cairo_region_t *sub;
|
2023-02-08 03:52:06 +00:00
|
|
|
|
2023-11-13 21:12:58 +00:00
|
|
|
if (!gsk_rect_equal (&node1->bounds, &node2->bounds) ||
|
2023-05-01 20:23:50 +00:00
|
|
|
self1->filter != self2->filter ||
|
|
|
|
gdk_texture_get_width (self1->texture) != gdk_texture_get_width (self2->texture) ||
|
|
|
|
gdk_texture_get_height (self1->texture) != gdk_texture_get_height (self2->texture))
|
|
|
|
{
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2023-05-01 20:23:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self1->texture == self2->texture)
|
2023-02-08 03:52:06 +00:00
|
|
|
return;
|
|
|
|
|
2023-05-01 20:23:50 +00:00
|
|
|
sub = cairo_region_create ();
|
|
|
|
gdk_texture_diff (self1->texture, self2->texture, sub);
|
2023-10-31 23:07:23 +00:00
|
|
|
region_union_region_affine (data->region,
|
2023-05-01 20:23:50 +00:00
|
|
|
sub,
|
|
|
|
node1->bounds.size.width / gdk_texture_get_width (self1->texture),
|
|
|
|
node1->bounds.size.height / gdk_texture_get_height (self1->texture),
|
|
|
|
node1->bounds.origin.x,
|
|
|
|
node1->bounds.origin.y);
|
|
|
|
cairo_region_destroy (sub);
|
2023-02-08 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_texture_scale_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_TEXTURE_SCALE_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_texture_scale_node_finalize;
|
|
|
|
node_class->draw = gsk_texture_scale_node_draw;
|
|
|
|
node_class->diff = gsk_texture_scale_node_diff;
|
|
|
|
}
|
|
|
|
|
2023-02-08 03:52:06 +00:00
|
|
|
/**
|
|
|
|
* gsk_texture_scale_node_get_texture:
|
2023-02-19 17:00:34 +00:00
|
|
|
* @node: (type GskTextureScaleNode): a `GskRenderNode` of type %GSK_TEXTURE_SCALE_NODE
|
2023-02-08 03:52:06 +00:00
|
|
|
*
|
|
|
|
* Retrieves the `GdkTexture` used when creating this `GskRenderNode`.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the `GdkTexture`
|
|
|
|
*
|
|
|
|
* Since: 4.10
|
|
|
|
*/
|
|
|
|
GdkTexture *
|
|
|
|
gsk_texture_scale_node_get_texture (const GskRenderNode *node)
|
|
|
|
{
|
|
|
|
const GskTextureScaleNode *self = (const GskTextureScaleNode *) node;
|
|
|
|
|
|
|
|
return self->texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_texture_scale_node_get_filter:
|
2023-02-19 17:00:34 +00:00
|
|
|
* @node: (type GskTextureScaleNode): a `GskRenderNode` of type %GSK_TEXTURE_SCALE_NODE
|
2023-02-08 03:52:06 +00:00
|
|
|
*
|
|
|
|
* Retrieves the `GskScalingFilter` used when creating this `GskRenderNode`.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the `GskScalingFilter`
|
|
|
|
*
|
|
|
|
* Since: 4.10
|
|
|
|
*/
|
|
|
|
GskScalingFilter
|
|
|
|
gsk_texture_scale_node_get_filter (const GskRenderNode *node)
|
|
|
|
{
|
|
|
|
const GskTextureScaleNode *self = (const GskTextureScaleNode *) node;
|
|
|
|
|
|
|
|
return self->filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_texture_scale_node_new:
|
|
|
|
* @texture: the texture to scale
|
|
|
|
* @bounds: the size of the texture to scale to
|
|
|
|
* @filter: how to scale the texture
|
|
|
|
*
|
|
|
|
* Creates a node that scales the texture to the size given by the
|
2023-03-13 07:38:58 +00:00
|
|
|
* bounds using the filter and then places it at the bounds' position.
|
|
|
|
*
|
|
|
|
* Note that further scaling and other transformations which are
|
|
|
|
* applied to the node will apply linear filtering to the resulting
|
|
|
|
* texture, as usual.
|
2023-02-08 03:52:06 +00:00
|
|
|
*
|
|
|
|
* This node is intended for tight control over scaling applied
|
|
|
|
* to a texture, such as in image editors and requires the
|
|
|
|
* application to be aware of the whole render tree as further
|
|
|
|
* transforms may be applied that conflict with the desired effect
|
|
|
|
* of this node.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full) (type GskTextureScaleNode): A new `GskRenderNode`
|
|
|
|
*
|
|
|
|
* Since: 4.10
|
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_texture_scale_node_new (GdkTexture *texture,
|
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
GskScalingFilter filter)
|
|
|
|
{
|
|
|
|
GskTextureScaleNode *self;
|
|
|
|
GskRenderNode *node;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_TEXTURE (texture), NULL);
|
|
|
|
g_return_val_if_fail (bounds != NULL, NULL);
|
|
|
|
|
|
|
|
self = gsk_render_node_alloc (GSK_TEXTURE_SCALE_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
|
|
|
node->offscreen_for_opacity = FALSE;
|
|
|
|
|
|
|
|
self->texture = g_object_ref (texture);
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&node->bounds, bounds);
|
2023-02-08 03:52:06 +00:00
|
|
|
self->filter = filter;
|
|
|
|
|
2023-06-15 18:27:13 +00:00
|
|
|
node->preferred_depth = gdk_memory_format_get_depth (gdk_texture_get_format (texture));
|
2023-02-08 03:52:06 +00:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_INSET_SHADOW_NODE */
|
2016-12-19 04:13:42 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskInsetShadowNode:
|
|
|
|
*
|
|
|
|
* A render node for an inset shadow.
|
|
|
|
*/
|
2016-12-19 04:13:42 +00:00
|
|
|
struct _GskInsetShadowNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GskRoundedRect outline;
|
|
|
|
GdkRGBA color;
|
|
|
|
float dx;
|
|
|
|
float dy;
|
|
|
|
float spread;
|
|
|
|
float blur_radius;
|
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
has_empty_clip (cairo_t *cr)
|
|
|
|
{
|
|
|
|
double x1, y1, x2, y2;
|
|
|
|
|
|
|
|
cairo_clip_extents (cr, &x1, &y1, &x2, &y2);
|
|
|
|
return x1 == x2 && y1 == y2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-08-29 10:03:20 +00:00
|
|
|
draw_shadow (cairo_t *cr,
|
|
|
|
gboolean inset,
|
|
|
|
const GskRoundedRect *box,
|
|
|
|
const GskRoundedRect *clip_box,
|
|
|
|
float radius,
|
|
|
|
const GdkRGBA *color,
|
|
|
|
GskBlurFlags blur_flags)
|
2016-12-19 04:13:42 +00:00
|
|
|
{
|
|
|
|
cairo_t *shadow_cr;
|
|
|
|
|
|
|
|
if (has_empty_clip (cr))
|
|
|
|
return;
|
|
|
|
|
|
|
|
gdk_cairo_set_source_rgba (cr, color);
|
2020-02-12 23:14:29 +00:00
|
|
|
shadow_cr = gsk_cairo_blur_start_drawing (cr, radius, blur_flags);
|
2016-12-19 04:13:42 +00:00
|
|
|
|
|
|
|
cairo_set_fill_rule (shadow_cr, CAIRO_FILL_RULE_EVEN_ODD);
|
|
|
|
gsk_rounded_rect_path (box, shadow_cr);
|
|
|
|
if (inset)
|
2020-02-13 00:48:03 +00:00
|
|
|
gsk_cairo_rectangle (shadow_cr, &clip_box->bounds);
|
2016-12-19 04:13:42 +00:00
|
|
|
|
|
|
|
cairo_fill (shadow_cr);
|
|
|
|
|
2020-02-12 23:14:29 +00:00
|
|
|
gsk_cairo_blur_finish_drawing (shadow_cr, radius, color, blur_flags);
|
2016-12-19 04:13:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
float radius;
|
|
|
|
graphene_size_t corner;
|
|
|
|
} CornerMask;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
TOP,
|
|
|
|
RIGHT,
|
|
|
|
BOTTOM,
|
|
|
|
LEFT
|
|
|
|
} Side;
|
|
|
|
|
|
|
|
static guint
|
|
|
|
corner_mask_hash (CornerMask *mask)
|
|
|
|
{
|
|
|
|
return ((guint)mask->radius << 24) ^
|
|
|
|
((guint)(mask->corner.width*4)) << 12 ^
|
|
|
|
((guint)(mask->corner.height*4)) << 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
corner_mask_equal (CornerMask *mask1,
|
|
|
|
CornerMask *mask2)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
mask1->radius == mask2->radius &&
|
|
|
|
mask1->corner.width == mask2->corner.width &&
|
|
|
|
mask1->corner.height == mask2->corner.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
draw_shadow_corner (cairo_t *cr,
|
|
|
|
gboolean inset,
|
2017-08-28 15:38:57 +00:00
|
|
|
const GskRoundedRect *box,
|
|
|
|
const GskRoundedRect *clip_box,
|
2016-12-19 04:13:42 +00:00
|
|
|
float radius,
|
|
|
|
const GdkRGBA *color,
|
|
|
|
GskCorner corner,
|
|
|
|
cairo_rectangle_int_t *drawn_rect)
|
|
|
|
{
|
|
|
|
float clip_radius;
|
|
|
|
int x1, x2, x3, y1, y2, y3, x, y;
|
|
|
|
GskRoundedRect corner_box;
|
|
|
|
cairo_t *mask_cr;
|
|
|
|
cairo_surface_t *mask;
|
|
|
|
cairo_pattern_t *pattern;
|
|
|
|
cairo_matrix_t matrix;
|
|
|
|
float sx, sy;
|
|
|
|
static GHashTable *corner_mask_cache = NULL;
|
|
|
|
float max_other;
|
|
|
|
CornerMask key;
|
|
|
|
gboolean overlapped;
|
|
|
|
|
|
|
|
clip_radius = gsk_cairo_blur_compute_pixels (radius);
|
|
|
|
|
|
|
|
overlapped = FALSE;
|
|
|
|
if (corner == GSK_CORNER_TOP_LEFT || corner == GSK_CORNER_BOTTOM_LEFT)
|
|
|
|
{
|
|
|
|
x1 = floor (box->bounds.origin.x - clip_radius);
|
|
|
|
x2 = ceil (box->bounds.origin.x + box->corner[corner].width + clip_radius);
|
|
|
|
x = x1;
|
|
|
|
sx = 1;
|
|
|
|
max_other = MAX(box->corner[GSK_CORNER_TOP_RIGHT].width, box->corner[GSK_CORNER_BOTTOM_RIGHT].width);
|
|
|
|
x3 = floor (box->bounds.origin.x + box->bounds.size.width - max_other - clip_radius);
|
|
|
|
if (x2 > x3)
|
|
|
|
overlapped = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x1 = floor (box->bounds.origin.x + box->bounds.size.width - box->corner[corner].width - clip_radius);
|
|
|
|
x2 = ceil (box->bounds.origin.x + box->bounds.size.width + clip_radius);
|
|
|
|
x = x2;
|
|
|
|
sx = -1;
|
|
|
|
max_other = MAX(box->corner[GSK_CORNER_TOP_LEFT].width, box->corner[GSK_CORNER_BOTTOM_LEFT].width);
|
|
|
|
x3 = ceil (box->bounds.origin.x + max_other + clip_radius);
|
|
|
|
if (x3 > x1)
|
|
|
|
overlapped = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (corner == GSK_CORNER_TOP_LEFT || corner == GSK_CORNER_TOP_RIGHT)
|
|
|
|
{
|
|
|
|
y1 = floor (box->bounds.origin.y - clip_radius);
|
|
|
|
y2 = ceil (box->bounds.origin.y + box->corner[corner].height + clip_radius);
|
|
|
|
y = y1;
|
|
|
|
sy = 1;
|
|
|
|
max_other = MAX(box->corner[GSK_CORNER_BOTTOM_LEFT].height, box->corner[GSK_CORNER_BOTTOM_RIGHT].height);
|
|
|
|
y3 = floor (box->bounds.origin.y + box->bounds.size.height - max_other - clip_radius);
|
|
|
|
if (y2 > y3)
|
|
|
|
overlapped = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
y1 = floor (box->bounds.origin.y + box->bounds.size.height - box->corner[corner].height - clip_radius);
|
|
|
|
y2 = ceil (box->bounds.origin.y + box->bounds.size.height + clip_radius);
|
|
|
|
y = y2;
|
|
|
|
sy = -1;
|
|
|
|
max_other = MAX(box->corner[GSK_CORNER_TOP_LEFT].height, box->corner[GSK_CORNER_TOP_RIGHT].height);
|
|
|
|
y3 = ceil (box->bounds.origin.y + max_other + clip_radius);
|
|
|
|
if (y3 > y1)
|
|
|
|
overlapped = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
drawn_rect->x = x1;
|
|
|
|
drawn_rect->y = y1;
|
|
|
|
drawn_rect->width = x2 - x1;
|
|
|
|
drawn_rect->height = y2 - y1;
|
|
|
|
|
|
|
|
cairo_rectangle (cr, x1, y1, x2 - x1, y2 - y1);
|
|
|
|
cairo_clip (cr);
|
|
|
|
|
|
|
|
if (inset || overlapped)
|
|
|
|
{
|
|
|
|
/* Fall back to generic path if inset or if the corner radius
|
|
|
|
runs into each other */
|
|
|
|
draw_shadow (cr, inset, box, clip_box, radius, color, GSK_BLUR_X | GSK_BLUR_Y);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_empty_clip (cr))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* At this point we're drawing a blurred outset corner. The only
|
|
|
|
* things that affect the output of the blurred mask in this case
|
|
|
|
* is:
|
|
|
|
*
|
|
|
|
* What corner this is, which defines the orientation (sx,sy)
|
|
|
|
* and position (x,y)
|
|
|
|
*
|
|
|
|
* The blur radius (which also defines the clip_radius)
|
|
|
|
*
|
2020-05-28 08:00:03 +00:00
|
|
|
* The horizontal and vertical corner radius
|
2016-12-19 04:13:42 +00:00
|
|
|
*
|
|
|
|
* We apply the first position and orientation when drawing the
|
|
|
|
* mask, so we cache rendered masks based on the blur radius and the
|
|
|
|
* corner radius.
|
|
|
|
*/
|
|
|
|
if (corner_mask_cache == NULL)
|
|
|
|
corner_mask_cache = g_hash_table_new_full ((GHashFunc)corner_mask_hash,
|
|
|
|
(GEqualFunc)corner_mask_equal,
|
|
|
|
g_free, (GDestroyNotify)cairo_surface_destroy);
|
|
|
|
|
|
|
|
key.radius = radius;
|
|
|
|
key.corner = box->corner[corner];
|
|
|
|
|
|
|
|
mask = g_hash_table_lookup (corner_mask_cache, &key);
|
|
|
|
if (mask == NULL)
|
|
|
|
{
|
|
|
|
mask = cairo_surface_create_similar_image (cairo_get_target (cr), CAIRO_FORMAT_A8,
|
|
|
|
drawn_rect->width + clip_radius,
|
|
|
|
drawn_rect->height + clip_radius);
|
|
|
|
mask_cr = cairo_create (mask);
|
|
|
|
gsk_rounded_rect_init_from_rect (&corner_box, &GRAPHENE_RECT_INIT (clip_radius, clip_radius, 2*drawn_rect->width, 2*drawn_rect->height), 0);
|
|
|
|
corner_box.corner[0] = box->corner[corner];
|
|
|
|
gsk_rounded_rect_path (&corner_box, mask_cr);
|
|
|
|
cairo_fill (mask_cr);
|
|
|
|
gsk_cairo_blur_surface (mask, radius, GSK_BLUR_X | GSK_BLUR_Y);
|
|
|
|
cairo_destroy (mask_cr);
|
2021-02-04 19:16:39 +00:00
|
|
|
g_hash_table_insert (corner_mask_cache, g_memdup2 (&key, sizeof (key)), mask);
|
2016-12-19 04:13:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gdk_cairo_set_source_rgba (cr, color);
|
|
|
|
pattern = cairo_pattern_create_for_surface (mask);
|
|
|
|
cairo_matrix_init_identity (&matrix);
|
|
|
|
cairo_matrix_scale (&matrix, sx, sy);
|
|
|
|
cairo_matrix_translate (&matrix, -x, -y);
|
|
|
|
cairo_pattern_set_matrix (pattern, &matrix);
|
|
|
|
cairo_mask (cr, pattern);
|
|
|
|
cairo_pattern_destroy (pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
draw_shadow_side (cairo_t *cr,
|
|
|
|
gboolean inset,
|
2017-08-28 15:38:57 +00:00
|
|
|
const GskRoundedRect *box,
|
|
|
|
const GskRoundedRect *clip_box,
|
2016-12-19 04:13:42 +00:00
|
|
|
float radius,
|
|
|
|
const GdkRGBA *color,
|
|
|
|
Side side,
|
|
|
|
cairo_rectangle_int_t *drawn_rect)
|
|
|
|
{
|
|
|
|
GskBlurFlags blur_flags = GSK_BLUR_REPEAT;
|
2020-07-24 20:32:16 +00:00
|
|
|
double clip_radius;
|
2016-12-19 04:13:42 +00:00
|
|
|
int x1, x2, y1, y2;
|
|
|
|
|
|
|
|
clip_radius = gsk_cairo_blur_compute_pixels (radius);
|
|
|
|
|
|
|
|
if (side == TOP || side == BOTTOM)
|
|
|
|
{
|
|
|
|
blur_flags |= GSK_BLUR_Y;
|
|
|
|
x1 = floor (box->bounds.origin.x - clip_radius);
|
|
|
|
x2 = ceil (box->bounds.origin.x + box->bounds.size.width + clip_radius);
|
|
|
|
}
|
|
|
|
else if (side == LEFT)
|
|
|
|
{
|
|
|
|
x1 = floor (box->bounds.origin.x -clip_radius);
|
|
|
|
x2 = ceil (box->bounds.origin.x + clip_radius);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x1 = floor (box->bounds.origin.x + box->bounds.size.width -clip_radius);
|
|
|
|
x2 = ceil (box->bounds.origin.x + box->bounds.size.width + clip_radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (side == LEFT || side == RIGHT)
|
|
|
|
{
|
|
|
|
blur_flags |= GSK_BLUR_X;
|
|
|
|
y1 = floor (box->bounds.origin.y - clip_radius);
|
|
|
|
y2 = ceil (box->bounds.origin.y + box->bounds.size.height + clip_radius);
|
|
|
|
}
|
|
|
|
else if (side == TOP)
|
|
|
|
{
|
|
|
|
y1 = floor (box->bounds.origin.y -clip_radius);
|
|
|
|
y2 = ceil (box->bounds.origin.y + clip_radius);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
y1 = floor (box->bounds.origin.y + box->bounds.size.height -clip_radius);
|
|
|
|
y2 = ceil (box->bounds.origin.y + box->bounds.size.height + clip_radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
drawn_rect->x = x1;
|
|
|
|
drawn_rect->y = y1;
|
|
|
|
drawn_rect->width = x2 - x1;
|
|
|
|
drawn_rect->height = y2 - y1;
|
|
|
|
|
|
|
|
cairo_rectangle (cr, x1, y1, x2 - x1, y2 - y1);
|
|
|
|
cairo_clip (cr);
|
|
|
|
draw_shadow (cr, inset, box, clip_box, radius, color, blur_flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2016-12-19 14:39:43 +00:00
|
|
|
needs_blur (double radius)
|
2016-12-19 04:13:42 +00:00
|
|
|
{
|
|
|
|
/* The code doesn't actually do any blurring for radius 1, as it
|
|
|
|
* ends up with box filter size 1 */
|
2016-12-19 14:39:43 +00:00
|
|
|
if (radius <= 1.0)
|
2016-12-19 04:13:42 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_inset_shadow_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskInsetShadowNode *self = (GskInsetShadowNode *) node;
|
|
|
|
GskRoundedRect box, clip_box;
|
|
|
|
int clip_radius;
|
2023-02-13 00:31:12 +00:00
|
|
|
graphene_rect_t clip_rect;
|
2021-04-08 13:36:51 +00:00
|
|
|
double blur_radius;
|
2016-12-19 04:13:42 +00:00
|
|
|
|
|
|
|
/* We don't need to draw invisible shadows */
|
|
|
|
if (gdk_rgba_is_clear (&self->color))
|
|
|
|
return;
|
|
|
|
|
2023-02-13 00:31:12 +00:00
|
|
|
_graphene_rect_init_from_clip_extents (&clip_rect, cr);
|
|
|
|
if (!gsk_rounded_rect_intersects_rect (&self->outline, &clip_rect))
|
2016-12-19 04:13:42 +00:00
|
|
|
return;
|
|
|
|
|
2021-04-08 13:36:51 +00:00
|
|
|
blur_radius = self->blur_radius / 2;
|
|
|
|
|
|
|
|
clip_radius = gsk_cairo_blur_compute_pixels (blur_radius);
|
2016-12-19 04:13:42 +00:00
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
|
|
|
|
gsk_rounded_rect_path (&self->outline, cr);
|
|
|
|
cairo_clip (cr);
|
|
|
|
|
|
|
|
gsk_rounded_rect_init_copy (&box, &self->outline);
|
|
|
|
gsk_rounded_rect_offset (&box, self->dx, self->dy);
|
|
|
|
gsk_rounded_rect_shrink (&box, self->spread, self->spread, self->spread, self->spread);
|
|
|
|
|
|
|
|
gsk_rounded_rect_init_copy (&clip_box, &self->outline);
|
|
|
|
gsk_rounded_rect_shrink (&clip_box, -clip_radius, -clip_radius, -clip_radius, -clip_radius);
|
|
|
|
|
2021-04-08 13:36:51 +00:00
|
|
|
if (!needs_blur (blur_radius))
|
|
|
|
draw_shadow (cr, TRUE, &box, &clip_box, blur_radius, &self->color, GSK_BLUR_NONE);
|
2016-12-19 04:13:42 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
cairo_region_t *remaining;
|
|
|
|
cairo_rectangle_int_t r;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* For the blurred case we divide the rendering into 9 parts,
|
|
|
|
* 4 of the corners, 4 for the horizonat/vertical lines and
|
|
|
|
* one for the interior. We make the non-interior parts
|
2020-08-21 12:41:13 +00:00
|
|
|
* large enough to fit the full radius of the blur, so that
|
2016-12-19 04:13:42 +00:00
|
|
|
* the interior part can be drawn solidly.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* In the inset case we want to paint the whole clip-box.
|
|
|
|
* We could remove the part of "box" where the blur doesn't
|
|
|
|
* reach, but computing that is a bit tricky since the
|
|
|
|
* rounded corners are on the "inside" of it. */
|
2023-10-30 22:38:21 +00:00
|
|
|
rectangle_init_from_graphene (&r, &clip_box.bounds);
|
2016-12-19 04:13:42 +00:00
|
|
|
remaining = cairo_region_create_rectangle (&r);
|
|
|
|
|
|
|
|
/* First do the corners of box */
|
|
|
|
for (i = 0; i < 4; i++)
|
2020-08-29 10:03:20 +00:00
|
|
|
{
|
|
|
|
cairo_save (cr);
|
2016-12-19 04:13:42 +00:00
|
|
|
/* Always clip with remaining to ensure we never draw any area twice */
|
|
|
|
gdk_cairo_region (cr, remaining);
|
|
|
|
cairo_clip (cr);
|
2021-04-08 13:36:51 +00:00
|
|
|
draw_shadow_corner (cr, TRUE, &box, &clip_box, blur_radius, &self->color, i, &r);
|
2020-08-29 10:03:20 +00:00
|
|
|
cairo_restore (cr);
|
2016-12-19 04:13:42 +00:00
|
|
|
|
2020-08-29 10:03:20 +00:00
|
|
|
/* We drew the region, remove it from remaining */
|
|
|
|
cairo_region_subtract_rectangle (remaining, &r);
|
|
|
|
}
|
2016-12-19 04:13:42 +00:00
|
|
|
|
|
|
|
/* Then the sides */
|
|
|
|
for (i = 0; i < 4; i++)
|
2020-08-29 10:03:20 +00:00
|
|
|
{
|
|
|
|
cairo_save (cr);
|
2016-12-19 04:13:42 +00:00
|
|
|
/* Always clip with remaining to ensure we never draw any area twice */
|
|
|
|
gdk_cairo_region (cr, remaining);
|
|
|
|
cairo_clip (cr);
|
2021-04-08 13:36:51 +00:00
|
|
|
draw_shadow_side (cr, TRUE, &box, &clip_box, blur_radius, &self->color, i, &r);
|
2020-08-29 10:03:20 +00:00
|
|
|
cairo_restore (cr);
|
2016-12-19 04:13:42 +00:00
|
|
|
|
2020-08-29 10:03:20 +00:00
|
|
|
/* We drew the region, remove it from remaining */
|
|
|
|
cairo_region_subtract_rectangle (remaining, &r);
|
|
|
|
}
|
2016-12-19 04:13:42 +00:00
|
|
|
|
|
|
|
/* Then the rest, which needs no blurring */
|
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
gdk_cairo_region (cr, remaining);
|
|
|
|
cairo_clip (cr);
|
2021-04-08 13:36:51 +00:00
|
|
|
draw_shadow (cr, TRUE, &box, &clip_box, blur_radius, &self->color, GSK_BLUR_NONE);
|
2016-12-19 04:13:42 +00:00
|
|
|
cairo_restore (cr);
|
|
|
|
|
|
|
|
cairo_region_destroy (remaining);
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_restore (cr);
|
|
|
|
}
|
|
|
|
|
2018-03-27 22:34:23 +00:00
|
|
|
static void
|
|
|
|
gsk_inset_shadow_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2018-03-27 22:34:23 +00:00
|
|
|
{
|
|
|
|
GskInsetShadowNode *self1 = (GskInsetShadowNode *) node1;
|
|
|
|
GskInsetShadowNode *self2 = (GskInsetShadowNode *) node2;
|
|
|
|
|
|
|
|
if (gsk_rounded_rect_equal (&self1->outline, &self2->outline) &&
|
|
|
|
gdk_rgba_equal (&self1->color, &self2->color) &&
|
|
|
|
self1->dx == self2->dx &&
|
|
|
|
self1->dy == self2->dy &&
|
|
|
|
self1->spread == self2->spread &&
|
|
|
|
self1->blur_radius == self2->blur_radius)
|
|
|
|
return;
|
|
|
|
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2018-03-27 22:34:23 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_inset_shadow_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_INSET_SHADOW_NODE;
|
|
|
|
|
|
|
|
node_class->draw = gsk_inset_shadow_node_draw;
|
|
|
|
node_class->diff = gsk_inset_shadow_node_diff;
|
|
|
|
}
|
|
|
|
|
2016-12-19 04:13:42 +00:00
|
|
|
/**
|
2020-06-27 09:22:54 +00:00
|
|
|
* gsk_inset_shadow_node_new:
|
2016-12-19 04:13:42 +00:00
|
|
|
* @outline: outline of the region containing the shadow
|
|
|
|
* @color: color of the shadow
|
|
|
|
* @dx: horizontal offset of shadow
|
|
|
|
* @dy: vertical offset of shadow
|
|
|
|
* @spread: how far the shadow spreads towards the inside
|
|
|
|
* @blur_radius: how much blur to apply to the shadow
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that will render an inset shadow
|
2016-12-19 04:13:42 +00:00
|
|
|
* into the box given by @outline.
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer full) (type GskInsetShadowNode): A new `GskRenderNode`
|
2016-12-19 04:13:42 +00:00
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_inset_shadow_node_new (const GskRoundedRect *outline,
|
|
|
|
const GdkRGBA *color,
|
|
|
|
float dx,
|
|
|
|
float dy,
|
|
|
|
float spread,
|
|
|
|
float blur_radius)
|
|
|
|
{
|
|
|
|
GskInsetShadowNode *self;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNode *node;
|
2016-12-19 04:13:42 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (outline != NULL, NULL);
|
|
|
|
g_return_val_if_fail (color != NULL, NULL);
|
2023-07-02 04:28:29 +00:00
|
|
|
g_return_val_if_fail (blur_radius >= 0, NULL);
|
2016-12-19 04:13:42 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self = gsk_render_node_alloc (GSK_INSET_SHADOW_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = FALSE;
|
2016-12-19 04:13:42 +00:00
|
|
|
|
|
|
|
gsk_rounded_rect_init_copy (&self->outline, outline);
|
|
|
|
self->color = *color;
|
|
|
|
self->dx = dx;
|
|
|
|
self->dy = dy;
|
|
|
|
self->spread = spread;
|
|
|
|
self->blur_radius = blur_radius;
|
|
|
|
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&node->bounds, &self->outline.bounds);
|
2016-12-21 10:21:38 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return node;
|
2016-12-19 04:13:42 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_inset_shadow_node_get_outline:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskInsetShadowNode): a `GskRenderNode` for an inset shadow
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the outline rectangle of the inset shadow.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): a rounded rectangle
|
|
|
|
*/
|
2017-01-17 23:05:25 +00:00
|
|
|
const GskRoundedRect *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_inset_shadow_node_get_outline (const GskRenderNode *node)
|
2017-01-17 23:05:25 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskInsetShadowNode *self = (const GskInsetShadowNode *) node;
|
2017-01-17 23:05:25 +00:00
|
|
|
|
|
|
|
return &self->outline;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_inset_shadow_node_get_color:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskInsetShadowNode): a `GskRenderNode` for an inset shadow
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the color of the inset shadow.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the color of the shadow
|
|
|
|
*/
|
2017-01-17 23:05:25 +00:00
|
|
|
const GdkRGBA *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_inset_shadow_node_get_color (const GskRenderNode *node)
|
2017-01-17 23:05:25 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskInsetShadowNode *self = (const GskInsetShadowNode *) node;
|
2017-01-17 23:05:25 +00:00
|
|
|
|
|
|
|
return &self->color;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_inset_shadow_node_get_dx:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskInsetShadowNode): a `GskRenderNode` for an inset shadow
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the horizontal offset of the inset shadow.
|
|
|
|
*
|
|
|
|
* Returns: an offset, in pixels
|
|
|
|
*/
|
2017-01-17 23:05:25 +00:00
|
|
|
float
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_inset_shadow_node_get_dx (const GskRenderNode *node)
|
2017-01-17 23:05:25 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskInsetShadowNode *self = (const GskInsetShadowNode *) node;
|
2017-01-17 23:05:25 +00:00
|
|
|
|
|
|
|
return self->dx;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_inset_shadow_node_get_dy:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskInsetShadowNode): a `GskRenderNode` for an inset shadow
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the vertical offset of the inset shadow.
|
|
|
|
*
|
|
|
|
* Returns: an offset, in pixels
|
|
|
|
*/
|
2017-01-17 23:05:25 +00:00
|
|
|
float
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_inset_shadow_node_get_dy (const GskRenderNode *node)
|
2017-01-17 23:05:25 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskInsetShadowNode *self = (const GskInsetShadowNode *) node;
|
2017-01-17 23:05:25 +00:00
|
|
|
|
|
|
|
return self->dy;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_inset_shadow_node_get_spread:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskInsetShadowNode): a `GskRenderNode` for an inset shadow
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves how much the shadow spreads inwards.
|
|
|
|
*
|
|
|
|
* Returns: the size of the shadow, in pixels
|
|
|
|
*/
|
2017-01-17 23:05:25 +00:00
|
|
|
float
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_inset_shadow_node_get_spread (const GskRenderNode *node)
|
2017-01-17 23:05:25 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskInsetShadowNode *self = (const GskInsetShadowNode *) node;
|
2017-01-17 23:05:25 +00:00
|
|
|
|
|
|
|
return self->spread;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_inset_shadow_node_get_blur_radius:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskInsetShadowNode): a `GskRenderNode` for an inset shadow
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the blur radius to apply to the shadow.
|
|
|
|
*
|
|
|
|
* Returns: the blur radius, in pixels
|
|
|
|
*/
|
2017-01-17 23:05:25 +00:00
|
|
|
float
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_inset_shadow_node_get_blur_radius (const GskRenderNode *node)
|
2017-01-17 23:05:25 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskInsetShadowNode *self = (const GskInsetShadowNode *) node;
|
2017-01-17 23:05:25 +00:00
|
|
|
|
|
|
|
return self->blur_radius;
|
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_OUTSET_SHADOW_NODE */
|
2016-12-19 14:39:43 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskOutsetShadowNode:
|
|
|
|
*
|
|
|
|
* A render node for an outset shadow.
|
|
|
|
*/
|
2016-12-19 14:39:43 +00:00
|
|
|
struct _GskOutsetShadowNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GskRoundedRect outline;
|
|
|
|
GdkRGBA color;
|
|
|
|
float dx;
|
|
|
|
float dy;
|
|
|
|
float spread;
|
|
|
|
float blur_radius;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_outset_shadow_get_extents (GskOutsetShadowNode *self,
|
|
|
|
float *top,
|
|
|
|
float *right,
|
|
|
|
float *bottom,
|
|
|
|
float *left)
|
|
|
|
{
|
|
|
|
float clip_radius;
|
|
|
|
|
2022-11-23 17:58:18 +00:00
|
|
|
clip_radius = gsk_cairo_blur_compute_pixels (ceil (self->blur_radius / 2.0));
|
2022-11-23 17:56:45 +00:00
|
|
|
*top = MAX (0, ceil (clip_radius + self->spread - self->dy));
|
2016-12-19 14:39:43 +00:00
|
|
|
*right = MAX (0, ceil (clip_radius + self->spread + self->dx));
|
|
|
|
*bottom = MAX (0, ceil (clip_radius + self->spread + self->dy));
|
|
|
|
*left = MAX (0, ceil (clip_radius + self->spread - self->dx));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_outset_shadow_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskOutsetShadowNode *self = (GskOutsetShadowNode *) node;
|
|
|
|
GskRoundedRect box, clip_box;
|
|
|
|
int clip_radius;
|
2023-02-13 00:31:12 +00:00
|
|
|
graphene_rect_t clip_rect;
|
2016-12-19 14:39:43 +00:00
|
|
|
float top, right, bottom, left;
|
2021-04-08 13:36:51 +00:00
|
|
|
double blur_radius;
|
2016-12-19 14:39:43 +00:00
|
|
|
|
|
|
|
/* We don't need to draw invisible shadows */
|
|
|
|
if (gdk_rgba_is_clear (&self->color))
|
|
|
|
return;
|
|
|
|
|
2023-02-13 00:31:12 +00:00
|
|
|
_graphene_rect_init_from_clip_extents (&clip_rect, cr);
|
|
|
|
if (!gsk_rounded_rect_intersects_rect (&self->outline, &clip_rect))
|
2016-12-19 14:39:43 +00:00
|
|
|
return;
|
|
|
|
|
2021-04-08 13:36:51 +00:00
|
|
|
blur_radius = self->blur_radius / 2;
|
|
|
|
|
|
|
|
clip_radius = gsk_cairo_blur_compute_pixels (blur_radius);
|
2016-12-19 14:39:43 +00:00
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
|
|
|
|
gsk_rounded_rect_init_copy (&clip_box, &self->outline);
|
|
|
|
gsk_outset_shadow_get_extents (self, &top, &right, &bottom, &left);
|
|
|
|
gsk_rounded_rect_shrink (&clip_box, -top, -right, -bottom, -left);
|
|
|
|
|
|
|
|
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
|
|
|
|
gsk_rounded_rect_path (&self->outline, cr);
|
2020-02-13 00:48:03 +00:00
|
|
|
gsk_cairo_rectangle (cr, &clip_box.bounds);
|
2016-12-19 14:39:43 +00:00
|
|
|
|
|
|
|
cairo_clip (cr);
|
|
|
|
|
|
|
|
gsk_rounded_rect_init_copy (&box, &self->outline);
|
|
|
|
gsk_rounded_rect_offset (&box, self->dx, self->dy);
|
|
|
|
gsk_rounded_rect_shrink (&box, -self->spread, -self->spread, -self->spread, -self->spread);
|
|
|
|
|
2021-04-08 13:36:51 +00:00
|
|
|
if (!needs_blur (blur_radius))
|
|
|
|
draw_shadow (cr, FALSE, &box, &clip_box, blur_radius, &self->color, GSK_BLUR_NONE);
|
2016-12-19 14:39:43 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
cairo_region_t *remaining;
|
|
|
|
cairo_rectangle_int_t r;
|
|
|
|
|
|
|
|
/* For the blurred case we divide the rendering into 9 parts,
|
|
|
|
* 4 of the corners, 4 for the horizonat/vertical lines and
|
|
|
|
* one for the interior. We make the non-interior parts
|
2020-08-21 12:41:13 +00:00
|
|
|
* large enough to fit the full radius of the blur, so that
|
2016-12-19 14:39:43 +00:00
|
|
|
* the interior part can be drawn solidly.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* In the outset case we want to paint the entire box, plus as far
|
|
|
|
* as the radius reaches from it */
|
|
|
|
r.x = floor (box.bounds.origin.x - clip_radius);
|
|
|
|
r.y = floor (box.bounds.origin.y - clip_radius);
|
|
|
|
r.width = ceil (box.bounds.origin.x + box.bounds.size.width + clip_radius) - r.x;
|
|
|
|
r.height = ceil (box.bounds.origin.y + box.bounds.size.height + clip_radius) - r.y;
|
|
|
|
|
|
|
|
remaining = cairo_region_create_rectangle (&r);
|
|
|
|
|
|
|
|
/* First do the corners of box */
|
|
|
|
for (i = 0; i < 4; i++)
|
2020-08-29 10:03:20 +00:00
|
|
|
{
|
|
|
|
cairo_save (cr);
|
2016-12-19 14:39:43 +00:00
|
|
|
/* Always clip with remaining to ensure we never draw any area twice */
|
|
|
|
gdk_cairo_region (cr, remaining);
|
|
|
|
cairo_clip (cr);
|
2021-04-08 13:36:51 +00:00
|
|
|
draw_shadow_corner (cr, FALSE, &box, &clip_box, blur_radius, &self->color, i, &r);
|
2020-08-29 10:03:20 +00:00
|
|
|
cairo_restore (cr);
|
2016-12-19 14:39:43 +00:00
|
|
|
|
2020-08-29 10:03:20 +00:00
|
|
|
/* We drew the region, remove it from remaining */
|
|
|
|
cairo_region_subtract_rectangle (remaining, &r);
|
|
|
|
}
|
2016-12-19 14:39:43 +00:00
|
|
|
|
|
|
|
/* Then the sides */
|
|
|
|
for (i = 0; i < 4; i++)
|
2020-08-29 10:03:20 +00:00
|
|
|
{
|
|
|
|
cairo_save (cr);
|
2016-12-19 14:39:43 +00:00
|
|
|
/* Always clip with remaining to ensure we never draw any area twice */
|
|
|
|
gdk_cairo_region (cr, remaining);
|
|
|
|
cairo_clip (cr);
|
2021-04-08 13:36:51 +00:00
|
|
|
draw_shadow_side (cr, FALSE, &box, &clip_box, blur_radius, &self->color, i, &r);
|
2020-08-29 10:03:20 +00:00
|
|
|
cairo_restore (cr);
|
2016-12-19 14:39:43 +00:00
|
|
|
|
2020-08-29 10:03:20 +00:00
|
|
|
/* We drew the region, remove it from remaining */
|
|
|
|
cairo_region_subtract_rectangle (remaining, &r);
|
|
|
|
}
|
2016-12-19 14:39:43 +00:00
|
|
|
|
|
|
|
/* Then the rest, which needs no blurring */
|
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
gdk_cairo_region (cr, remaining);
|
|
|
|
cairo_clip (cr);
|
2021-04-08 13:36:51 +00:00
|
|
|
draw_shadow (cr, FALSE, &box, &clip_box, blur_radius, &self->color, GSK_BLUR_NONE);
|
2016-12-19 14:39:43 +00:00
|
|
|
cairo_restore (cr);
|
|
|
|
|
|
|
|
cairo_region_destroy (remaining);
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_restore (cr);
|
|
|
|
}
|
|
|
|
|
2018-03-27 22:34:23 +00:00
|
|
|
static void
|
|
|
|
gsk_outset_shadow_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2018-03-27 22:34:23 +00:00
|
|
|
{
|
|
|
|
GskOutsetShadowNode *self1 = (GskOutsetShadowNode *) node1;
|
|
|
|
GskOutsetShadowNode *self2 = (GskOutsetShadowNode *) node2;
|
|
|
|
|
|
|
|
if (gsk_rounded_rect_equal (&self1->outline, &self2->outline) &&
|
|
|
|
gdk_rgba_equal (&self1->color, &self2->color) &&
|
|
|
|
self1->dx == self2->dx &&
|
|
|
|
self1->dy == self2->dy &&
|
|
|
|
self1->spread == self2->spread &&
|
|
|
|
self1->blur_radius == self2->blur_radius)
|
|
|
|
return;
|
|
|
|
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2018-03-27 22:34:23 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_outset_shadow_node_class_init (gpointer g_class,
|
2023-07-02 04:28:29 +00:00
|
|
|
gpointer class_data)
|
2023-04-03 14:39:52 +00:00
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_OUTSET_SHADOW_NODE;
|
|
|
|
|
|
|
|
node_class->draw = gsk_outset_shadow_node_draw;
|
|
|
|
node_class->diff = gsk_outset_shadow_node_diff;
|
|
|
|
}
|
|
|
|
|
2016-12-19 14:39:43 +00:00
|
|
|
/**
|
2020-06-27 09:22:54 +00:00
|
|
|
* gsk_outset_shadow_node_new:
|
2016-12-19 14:39:43 +00:00
|
|
|
* @outline: outline of the region surrounded by shadow
|
|
|
|
* @color: color of the shadow
|
|
|
|
* @dx: horizontal offset of shadow
|
|
|
|
* @dy: vertical offset of shadow
|
|
|
|
* @spread: how far the shadow spreads towards the inside
|
|
|
|
* @blur_radius: how much blur to apply to the shadow
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that will render an outset shadow
|
2016-12-19 14:39:43 +00:00
|
|
|
* around the box given by @outline.
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer full) (type GskOutsetShadowNode): A new `GskRenderNode`
|
2016-12-19 14:39:43 +00:00
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_outset_shadow_node_new (const GskRoundedRect *outline,
|
|
|
|
const GdkRGBA *color,
|
|
|
|
float dx,
|
|
|
|
float dy,
|
|
|
|
float spread,
|
|
|
|
float blur_radius)
|
|
|
|
{
|
|
|
|
GskOutsetShadowNode *self;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNode *node;
|
2016-12-21 10:21:38 +00:00
|
|
|
float top, right, bottom, left;
|
2016-12-19 14:39:43 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (outline != NULL, NULL);
|
|
|
|
g_return_val_if_fail (color != NULL, NULL);
|
2023-07-02 04:28:29 +00:00
|
|
|
g_return_val_if_fail (blur_radius >= 0, NULL);
|
2016-12-19 14:39:43 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self = gsk_render_node_alloc (GSK_OUTSET_SHADOW_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = FALSE;
|
2016-12-19 14:39:43 +00:00
|
|
|
|
|
|
|
gsk_rounded_rect_init_copy (&self->outline, outline);
|
|
|
|
self->color = *color;
|
|
|
|
self->dx = dx;
|
|
|
|
self->dy = dy;
|
|
|
|
self->spread = spread;
|
|
|
|
self->blur_radius = blur_radius;
|
|
|
|
|
2016-12-21 10:21:38 +00:00
|
|
|
gsk_outset_shadow_get_extents (self, &top, &right, &bottom, &left);
|
|
|
|
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&node->bounds, &self->outline.bounds);
|
2020-04-07 22:33:54 +00:00
|
|
|
node->bounds.origin.x -= left;
|
|
|
|
node->bounds.origin.y -= top;
|
|
|
|
node->bounds.size.width += left + right;
|
|
|
|
node->bounds.size.height += top + bottom;
|
2016-12-21 10:21:38 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return node;
|
2016-12-19 14:39:43 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_outset_shadow_node_get_outline:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskOutsetShadowNode): a `GskRenderNode` for an outset shadow
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the outline rectangle of the outset shadow.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): a rounded rectangle
|
|
|
|
*/
|
2017-01-17 23:05:25 +00:00
|
|
|
const GskRoundedRect *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_outset_shadow_node_get_outline (const GskRenderNode *node)
|
2017-01-17 23:05:25 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskOutsetShadowNode *self = (const GskOutsetShadowNode *) node;
|
2017-01-17 23:05:25 +00:00
|
|
|
|
|
|
|
return &self->outline;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_outset_shadow_node_get_color:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskOutsetShadowNode): a `GskRenderNode` for an outset shadow
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the color of the outset shadow.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): a color
|
|
|
|
*/
|
2017-01-17 23:05:25 +00:00
|
|
|
const GdkRGBA *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_outset_shadow_node_get_color (const GskRenderNode *node)
|
2017-01-17 23:05:25 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskOutsetShadowNode *self = (const GskOutsetShadowNode *) node;
|
2017-01-17 23:05:25 +00:00
|
|
|
|
|
|
|
return &self->color;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_outset_shadow_node_get_dx:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskOutsetShadowNode): a `GskRenderNode` for an outset shadow
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the horizontal offset of the outset shadow.
|
|
|
|
*
|
|
|
|
* Returns: an offset, in pixels
|
|
|
|
*/
|
2017-01-17 23:05:25 +00:00
|
|
|
float
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_outset_shadow_node_get_dx (const GskRenderNode *node)
|
2017-01-17 23:05:25 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskOutsetShadowNode *self = (const GskOutsetShadowNode *) node;
|
2017-01-17 23:05:25 +00:00
|
|
|
|
|
|
|
return self->dx;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_outset_shadow_node_get_dy:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskOutsetShadowNode): a `GskRenderNode` for an outset shadow
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the vertical offset of the outset shadow.
|
|
|
|
*
|
|
|
|
* Returns: an offset, in pixels
|
|
|
|
*/
|
2017-01-17 23:05:25 +00:00
|
|
|
float
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_outset_shadow_node_get_dy (const GskRenderNode *node)
|
2017-01-17 23:05:25 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskOutsetShadowNode *self = (const GskOutsetShadowNode *) node;
|
2017-01-17 23:05:25 +00:00
|
|
|
|
|
|
|
return self->dy;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_outset_shadow_node_get_spread:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskOutsetShadowNode): a `GskRenderNode` for an outset shadow
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves how much the shadow spreads outwards.
|
|
|
|
*
|
|
|
|
* Returns: the size of the shadow, in pixels
|
|
|
|
*/
|
2017-01-17 23:05:25 +00:00
|
|
|
float
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_outset_shadow_node_get_spread (const GskRenderNode *node)
|
2017-01-17 23:05:25 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskOutsetShadowNode *self = (const GskOutsetShadowNode *) node;
|
2017-01-17 23:05:25 +00:00
|
|
|
|
|
|
|
return self->spread;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_outset_shadow_node_get_blur_radius:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskOutsetShadowNode): a `GskRenderNode` for an outset shadow
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the blur radius of the shadow.
|
|
|
|
*
|
|
|
|
* Returns: the blur radius, in pixels
|
|
|
|
*/
|
2017-01-17 23:05:25 +00:00
|
|
|
float
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_outset_shadow_node_get_blur_radius (const GskRenderNode *node)
|
2017-01-17 23:05:25 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskOutsetShadowNode *self = (const GskOutsetShadowNode *) node;
|
2017-01-17 23:05:25 +00:00
|
|
|
|
|
|
|
return self->blur_radius;
|
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_CAIRO_NODE */
|
2016-12-11 01:59:47 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskCairoNode:
|
|
|
|
*
|
|
|
|
* A render node for a Cairo surface.
|
|
|
|
*/
|
2016-12-11 03:28:21 +00:00
|
|
|
struct _GskCairoNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
};
|
|
|
|
|
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;
|
2020-08-06 22:26:42 +00:00
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_CAIRO_NODE));
|
2016-12-11 03:28:21 +00:00
|
|
|
|
|
|
|
if (self->surface)
|
|
|
|
cairo_surface_destroy (self->surface);
|
2020-08-06 22:26:42 +00:00
|
|
|
|
|
|
|
parent_class->finalize (node);
|
2016-12-11 03:18:25 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 02:05:15 +00:00
|
|
|
static void
|
|
|
|
gsk_cairo_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskCairoNode *self = (GskCairoNode *) node;
|
|
|
|
|
|
|
|
if (self->surface == NULL)
|
|
|
|
return;
|
|
|
|
|
2018-03-24 19:42:42 +00:00
|
|
|
cairo_set_source_surface (cr, self->surface, 0, 0);
|
2016-12-13 02:05:15 +00:00
|
|
|
cairo_paint (cr);
|
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_cairo_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_CAIRO_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_cairo_node_finalize;
|
|
|
|
node_class->draw = gsk_cairo_node_draw;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_cairo_node_get_surface:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskCairoNode): a `GskRenderNode` for a Cairo surface
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the Cairo surface used by the render node.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): a Cairo surface
|
|
|
|
*/
|
2019-05-25 22:50:13 +00:00
|
|
|
cairo_surface_t *
|
2020-11-16 23:59:36 +00:00
|
|
|
gsk_cairo_node_get_surface (GskRenderNode *node)
|
2016-12-11 01:59:47 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-06-27 09:22:54 +00:00
|
|
|
* gsk_cairo_node_new:
|
2017-03-27 21:13:32 +00:00
|
|
|
* @bounds: the rectangle to render to
|
2016-12-11 01:59:47 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that will render a cairo surface
|
|
|
|
* into the area given by @bounds.
|
|
|
|
*
|
|
|
|
* You can draw to the cairo surface using [method@Gsk.CairoNode.get_draw_context].
|
2016-12-11 01:59:47 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer full) (type GskCairoNode): A new `GskRenderNode`
|
2016-12-11 01:59:47 +00:00
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_cairo_node_new (const graphene_rect_t *bounds)
|
|
|
|
{
|
2016-12-12 05:29:04 +00:00
|
|
|
GskCairoNode *self;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNode *node;
|
2016-12-11 01:59:47 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (bounds != NULL, NULL);
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self = gsk_render_node_alloc (GSK_CAIRO_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = FALSE;
|
2016-12-11 01:59:47 +00:00
|
|
|
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&node->bounds, bounds);
|
2016-12-11 01:59:47 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return node;
|
2016-12-11 01:59:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_cairo_node_get_draw_context:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskCairoNode): a `GskRenderNode` for a Cairo surface
|
2016-12-11 01:59:47 +00:00
|
|
|
*
|
|
|
|
* Creates a Cairo context for drawing using the surface associated
|
|
|
|
* to the render node.
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
2016-12-11 01:59:47 +00:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
cairo_t *
|
2018-03-24 20:33:08 +00:00
|
|
|
gsk_cairo_node_get_draw_context (GskRenderNode *node)
|
2016-12-11 01:59:47 +00:00
|
|
|
{
|
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
|
|
|
|
2016-12-21 10:21:38 +00:00
|
|
|
width = ceilf (node->bounds.size.width);
|
|
|
|
height = ceilf (node->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
|
|
|
{
|
2018-03-24 19:42:42 +00:00
|
|
|
self->surface = cairo_recording_surface_create (CAIRO_CONTENT_COLOR_ALPHA,
|
|
|
|
&(cairo_rectangle_t) {
|
|
|
|
node->bounds.origin.x,
|
|
|
|
node->bounds.origin.y,
|
|
|
|
node->bounds.size.width,
|
|
|
|
node->bounds.size.height
|
|
|
|
});
|
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
|
|
|
}
|
|
|
|
|
2020-02-13 00:48:03 +00:00
|
|
|
gsk_cairo_rectangle (res, &node->bounds);
|
2016-12-11 01:59:47 +00:00
|
|
|
cairo_clip (res);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_CONTAINER_NODE */
|
2016-12-11 03:14:04 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskContainerNode:
|
|
|
|
*
|
|
|
|
* A render node that can contain other render nodes.
|
|
|
|
*/
|
2016-12-12 18:30:41 +00:00
|
|
|
struct _GskContainerNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
2022-04-03 23:28:53 +00:00
|
|
|
gboolean disjoint;
|
2016-12-13 01:33:15 +00:00
|
|
|
guint n_children;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNode **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;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_CONTAINER_NODE));
|
2016-12-13 01:33:15 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
for (guint i = 0; i < container->n_children; i++)
|
2016-12-13 01:33:15 +00:00
|
|
|
gsk_render_node_unref (container->children[i]);
|
2020-04-07 22:33:54 +00:00
|
|
|
|
|
|
|
g_free (container->children);
|
|
|
|
|
|
|
|
parent_class->finalize (node);
|
2016-12-11 03:18:25 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 02:05:15 +00:00
|
|
|
static void
|
|
|
|
gsk_container_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskContainerNode *container = (GskContainerNode *) node;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < container->n_children; i++)
|
|
|
|
{
|
|
|
|
gsk_render_node_draw (container->children[i], cr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-27 22:34:23 +00:00
|
|
|
static int
|
|
|
|
gsk_container_node_compare_func (gconstpointer elem1, gconstpointer elem2, gpointer data)
|
|
|
|
{
|
2020-01-24 12:17:09 +00:00
|
|
|
return gsk_render_node_can_diff ((const GskRenderNode *) elem1, (const GskRenderNode *) elem2) ? 0 : 1;
|
2018-03-27 22:34:23 +00:00
|
|
|
}
|
|
|
|
|
2021-12-20 15:50:55 +00:00
|
|
|
static GskDiffResult
|
2018-03-27 22:34:23 +00:00
|
|
|
gsk_container_node_keep_func (gconstpointer elem1, gconstpointer elem2, gpointer data)
|
|
|
|
{
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *gd = data;
|
|
|
|
|
|
|
|
gsk_render_node_data_diff ((GskRenderNode *) elem1, (GskRenderNode *) elem2, gd);
|
|
|
|
if (cairo_region_num_rectangles (gd->region) > MAX_RECTS_IN_DIFF)
|
2021-12-20 17:40:02 +00:00
|
|
|
return GSK_DIFF_ABORTED;
|
2021-12-20 15:50:55 +00:00
|
|
|
|
|
|
|
return GSK_DIFF_OK;
|
2018-03-27 22:34:23 +00:00
|
|
|
}
|
|
|
|
|
2021-12-20 15:50:55 +00:00
|
|
|
static GskDiffResult
|
2018-03-27 22:34:23 +00:00
|
|
|
gsk_container_node_change_func (gconstpointer elem, gsize idx, gpointer data)
|
|
|
|
{
|
2021-12-20 15:50:55 +00:00
|
|
|
const GskRenderNode *node = elem;
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *gd = data;
|
2021-12-20 15:50:55 +00:00
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
|
|
|
|
rectangle_init_from_graphene (&rect, &node->bounds);
|
2023-10-31 23:07:23 +00:00
|
|
|
cairo_region_union_rectangle (gd->region, &rect);
|
|
|
|
if (cairo_region_num_rectangles (gd->region) > MAX_RECTS_IN_DIFF)
|
2021-12-20 17:40:02 +00:00
|
|
|
return GSK_DIFF_ABORTED;
|
2021-12-20 15:50:55 +00:00
|
|
|
|
|
|
|
return GSK_DIFF_OK;
|
2018-03-27 22:34:23 +00:00
|
|
|
}
|
|
|
|
|
2018-03-31 09:02:32 +00:00
|
|
|
static GskDiffSettings *
|
|
|
|
gsk_container_node_get_diff_settings (void)
|
|
|
|
{
|
|
|
|
static GskDiffSettings *settings = NULL;
|
|
|
|
|
|
|
|
if (G_LIKELY (settings))
|
|
|
|
return settings;
|
|
|
|
|
|
|
|
settings = gsk_diff_settings_new (gsk_container_node_compare_func,
|
|
|
|
gsk_container_node_keep_func,
|
|
|
|
gsk_container_node_change_func,
|
|
|
|
gsk_container_node_change_func);
|
2018-03-31 10:52:19 +00:00
|
|
|
gsk_diff_settings_set_allow_abort (settings, TRUE);
|
2018-03-31 09:02:32 +00:00
|
|
|
|
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
|
2021-03-28 14:18:23 +00:00
|
|
|
static gboolean
|
|
|
|
gsk_render_node_diff_multiple (GskRenderNode **nodes1,
|
|
|
|
gsize n_nodes1,
|
|
|
|
GskRenderNode **nodes2,
|
|
|
|
gsize n_nodes2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2021-03-28 14:18:23 +00:00
|
|
|
{
|
|
|
|
return gsk_diff ((gconstpointer *) nodes1, n_nodes1,
|
|
|
|
(gconstpointer *) nodes2, n_nodes2,
|
|
|
|
gsk_container_node_get_diff_settings (),
|
2023-10-31 23:07:23 +00:00
|
|
|
data) == GSK_DIFF_OK;
|
2021-03-28 14:18:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gsk_container_node_diff_with (GskRenderNode *container,
|
|
|
|
GskRenderNode *other,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2021-03-28 14:18:23 +00:00
|
|
|
{
|
|
|
|
GskContainerNode *self = (GskContainerNode *) container;
|
|
|
|
|
|
|
|
if (gsk_render_node_diff_multiple (self->children,
|
|
|
|
self->n_children,
|
|
|
|
&other,
|
|
|
|
1,
|
2023-10-31 23:07:23 +00:00
|
|
|
data))
|
2021-03-28 14:18:23 +00:00
|
|
|
return;
|
|
|
|
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (container, other, data);
|
2021-03-28 14:18:23 +00:00
|
|
|
}
|
|
|
|
|
2018-03-27 22:34:23 +00:00
|
|
|
static void
|
|
|
|
gsk_container_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2018-03-27 22:34:23 +00:00
|
|
|
{
|
|
|
|
GskContainerNode *self1 = (GskContainerNode *) node1;
|
|
|
|
GskContainerNode *self2 = (GskContainerNode *) node2;
|
|
|
|
|
2021-03-28 14:18:23 +00:00
|
|
|
if (gsk_render_node_diff_multiple (self1->children,
|
|
|
|
self1->n_children,
|
|
|
|
self2->children,
|
|
|
|
self2->n_children,
|
2023-10-31 23:07:23 +00:00
|
|
|
data))
|
2018-03-31 10:52:19 +00:00
|
|
|
return;
|
|
|
|
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2018-03-27 22:34:23 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_container_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_CONTAINER_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_container_node_finalize;
|
|
|
|
node_class->draw = gsk_container_node_draw;
|
|
|
|
node_class->diff = gsk_container_node_diff;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a new `GskRenderNode` instance for holding the given @children.
|
|
|
|
*
|
2016-12-13 01:33:15 +00:00
|
|
|
* The new node will acquire a reference to each of the children.
|
2016-12-11 03:14:04 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer full) (type GskContainerNode): the new `GskRenderNode`
|
2016-12-11 03:14:04 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
{
|
2020-04-07 22:33:54 +00:00
|
|
|
GskContainerNode *self;
|
|
|
|
GskRenderNode *node;
|
2016-12-12 18:30:41 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self = gsk_render_node_alloc (GSK_CONTAINER_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2016-12-12 18:30:41 +00:00
|
|
|
|
2022-04-03 23:28:53 +00:00
|
|
|
self->disjoint = TRUE;
|
2020-04-07 22:33:54 +00:00
|
|
|
self->n_children = n_children;
|
2016-12-12 18:30:41 +00:00
|
|
|
|
2019-06-04 14:32:49 +00:00
|
|
|
if (n_children == 0)
|
|
|
|
{
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&node->bounds, graphene_rect_zero ());
|
2019-06-04 14:32:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
graphene_rect_t bounds;
|
2016-12-12 18:30:41 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self->children = g_malloc_n (n_children, sizeof (GskRenderNode *));
|
|
|
|
|
|
|
|
self->children[0] = gsk_render_node_ref (children[0]);
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&bounds, &(children[0]->bounds));
|
2023-06-15 18:27:13 +00:00
|
|
|
node->preferred_depth = gdk_memory_depth_merge (node->preferred_depth,
|
|
|
|
gsk_render_node_get_preferred_depth (children[0]));
|
2020-04-07 22:33:54 +00:00
|
|
|
|
|
|
|
for (guint i = 1; i < n_children; i++)
|
2019-06-04 14:32:49 +00:00
|
|
|
{
|
2020-04-07 22:33:54 +00:00
|
|
|
self->children[i] = gsk_render_node_ref (children[i]);
|
2023-11-24 15:03:53 +00:00
|
|
|
self->disjoint = self->disjoint && !gsk_rect_intersects (&bounds, &(children[i]->bounds));
|
2020-04-07 22:33:54 +00:00
|
|
|
graphene_rect_union (&bounds, &(children[i]->bounds), &bounds);
|
2023-06-15 18:27:13 +00:00
|
|
|
node->preferred_depth = gdk_memory_depth_merge (node->preferred_depth,
|
|
|
|
gsk_render_node_get_preferred_depth (children[i]));
|
2023-04-25 11:30:09 +00:00
|
|
|
node->offscreen_for_opacity = node->offscreen_for_opacity || children[i]->offscreen_for_opacity;
|
2019-06-04 14:32:49 +00:00
|
|
|
}
|
|
|
|
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&node->bounds, &bounds);
|
2023-04-25 11:30:09 +00:00
|
|
|
node->offscreen_for_opacity = node->offscreen_for_opacity || !self->disjoint;
|
2019-06-04 14:32:49 +00:00
|
|
|
}
|
2016-12-21 10:21:38 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return node;
|
2016-12-12 18:30:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_container_node_get_n_children:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskContainerNode): a container `GskRenderNode`
|
2016-12-12 18:30:41 +00:00
|
|
|
*
|
|
|
|
* Retrieves the number of direct children of @node.
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: the number of children of the `GskRenderNode`
|
2016-12-12 18:30:41 +00:00
|
|
|
*/
|
|
|
|
guint
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_container_node_get_n_children (const GskRenderNode *node)
|
2016-12-12 18:30:41 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskContainerNode *self = (const GskContainerNode *) node;
|
2016-12-12 18:30:41 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return self->n_children;
|
2016-12-12 18:30:41 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 01:53:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_container_node_get_child:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskContainerNode): a container `GskRenderNode`
|
2017-09-25 01:53:54 +00:00
|
|
|
* @idx: the position of the child to get
|
|
|
|
*
|
|
|
|
* Gets one of the children of @container.
|
|
|
|
*
|
2020-04-07 22:33:54 +00:00
|
|
|
* Returns: (transfer none): the @idx'th child of @container
|
2017-09-25 01:53:54 +00:00
|
|
|
*/
|
2016-12-12 18:30:41 +00:00
|
|
|
GskRenderNode *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_container_node_get_child (const GskRenderNode *node,
|
|
|
|
guint idx)
|
2016-12-12 18:30:41 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskContainerNode *self = (const GskContainerNode *) node;
|
2016-12-12 18:30:41 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_CONTAINER_NODE), NULL);
|
2021-02-03 22:49:42 +00:00
|
|
|
g_return_val_if_fail (idx < self->n_children, NULL);
|
2016-12-12 18:30:41 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return self->children[idx];
|
2016-12-11 03:14:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-24 13:49:09 +00:00
|
|
|
GskRenderNode **
|
|
|
|
gsk_container_node_get_children (const GskRenderNode *node,
|
|
|
|
guint *n_children)
|
|
|
|
{
|
|
|
|
const GskContainerNode *self = (const GskContainerNode *) node;
|
|
|
|
|
|
|
|
*n_children = self->n_children;
|
|
|
|
|
|
|
|
return self->children;
|
|
|
|
}
|
|
|
|
|
2022-04-03 23:28:53 +00:00
|
|
|
/*< private>
|
|
|
|
* gsk_container_node_is_disjoint:
|
|
|
|
* @node: a container `GskRenderNode`
|
|
|
|
*
|
|
|
|
* Returns `TRUE` if it is known that the child nodes are not
|
|
|
|
* overlapping. There is no guarantee that they do overlap
|
|
|
|
* if this function return FALSE.
|
|
|
|
*
|
|
|
|
* Returns: `TRUE` if children don't overlap
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gsk_container_node_is_disjoint (const GskRenderNode *node)
|
|
|
|
{
|
|
|
|
const GskContainerNode *self = (const GskContainerNode *) node;
|
|
|
|
|
|
|
|
return self->disjoint;
|
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_TRANSFORM_NODE */
|
2016-12-12 23:11:06 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskTransformNode:
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* A render node applying a `GskTransform` to its single child node.
|
2020-12-01 14:16:28 +00:00
|
|
|
*/
|
2016-12-12 23:11:06 +00:00
|
|
|
struct _GskTransformNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GskRenderNode *child;
|
2019-03-01 05:35:55 +00:00
|
|
|
GskTransform *transform;
|
2021-07-24 14:48:20 +00:00
|
|
|
float dx, dy;
|
2016-12-12 23:11:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_transform_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskTransformNode *self = (GskTransformNode *) node;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_TRANSFORM_NODE));
|
2016-12-12 23:11:06 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (self->child);
|
2019-03-01 05:35:55 +00:00
|
|
|
gsk_transform_unref (self->transform);
|
2020-04-07 22:33:54 +00:00
|
|
|
|
|
|
|
parent_class->finalize (node);
|
2016-12-12 23:11:06 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 02:05:15 +00:00
|
|
|
static void
|
|
|
|
gsk_transform_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskTransformNode *self = (GskTransformNode *) node;
|
2019-03-01 05:35:55 +00:00
|
|
|
float xx, yx, xy, yy, dx, dy;
|
2019-03-04 18:33:04 +00:00
|
|
|
cairo_matrix_t ctm;
|
2016-12-13 02:05:15 +00:00
|
|
|
|
2019-03-04 18:33:04 +00:00
|
|
|
if (gsk_transform_get_category (self->transform) < GSK_TRANSFORM_CATEGORY_2D)
|
2016-12-13 02:05:15 +00:00
|
|
|
{
|
|
|
|
cairo_set_source_rgb (cr, 255 / 255., 105 / 255., 180 / 255.);
|
2020-02-13 00:48:03 +00:00
|
|
|
gsk_cairo_rectangle (cr, &node->bounds);
|
2016-12-13 02:05:15 +00:00
|
|
|
cairo_fill (cr);
|
2019-03-04 18:33:04 +00:00
|
|
|
return;
|
2016-12-13 02:05:15 +00:00
|
|
|
}
|
2019-03-04 18:33:04 +00:00
|
|
|
|
|
|
|
gsk_transform_to_2d (self->transform, &xx, &yx, &xy, &yy, &dx, &dy);
|
|
|
|
cairo_matrix_init (&ctm, xx, yx, xy, yy, dx, dy);
|
2022-09-23 01:36:50 +00:00
|
|
|
GSK_DEBUG (CAIRO, "CTM = { .xx = %g, .yx = %g, .xy = %g, .yy = %g, .x0 = %g, .y0 = %g }",
|
|
|
|
ctm.xx, ctm.yx,
|
|
|
|
ctm.xy, ctm.yy,
|
|
|
|
ctm.x0, ctm.y0);
|
2020-12-24 05:32:17 +00:00
|
|
|
if (xx * yy == xy * yx)
|
|
|
|
{
|
|
|
|
/* broken matrix here. This can happen during transitions
|
|
|
|
* (like when flipping an axis at the point where scale == 0)
|
|
|
|
* and just means that nothing should be drawn.
|
2022-11-18 03:24:18 +00:00
|
|
|
* But Cairo throws lots of ugly errors instead of silently
|
2020-12-24 05:32:17 +00:00
|
|
|
* going on. So We silently go on.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
2019-03-04 18:33:04 +00:00
|
|
|
cairo_transform (cr, &ctm);
|
2020-06-27 09:22:54 +00:00
|
|
|
|
2019-03-04 18:33:04 +00:00
|
|
|
gsk_render_node_draw (self->child, cr);
|
2016-12-13 02:05:15 +00:00
|
|
|
}
|
|
|
|
|
2019-03-06 11:39:56 +00:00
|
|
|
static gboolean
|
2020-01-24 12:17:09 +00:00
|
|
|
gsk_transform_node_can_diff (const GskRenderNode *node1,
|
|
|
|
const GskRenderNode *node2)
|
2019-03-06 11:39:56 +00:00
|
|
|
{
|
|
|
|
GskTransformNode *self1 = (GskTransformNode *) node1;
|
|
|
|
GskTransformNode *self2 = (GskTransformNode *) node2;
|
|
|
|
|
|
|
|
if (!gsk_transform_equal (self1->transform, self2->transform))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return gsk_render_node_can_diff (self1->child, self2->child);
|
|
|
|
}
|
|
|
|
|
2019-03-04 21:11:57 +00:00
|
|
|
static void
|
|
|
|
gsk_transform_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2019-03-04 21:11:57 +00:00
|
|
|
{
|
|
|
|
GskTransformNode *self1 = (GskTransformNode *) node1;
|
|
|
|
GskTransformNode *self2 = (GskTransformNode *) node2;
|
|
|
|
|
|
|
|
if (!gsk_transform_equal (self1->transform, self2->transform))
|
|
|
|
{
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2019-03-04 21:11:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self1->child == self2->child)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (gsk_transform_get_category (self1->transform))
|
|
|
|
{
|
|
|
|
case GSK_TRANSFORM_CATEGORY_IDENTITY:
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_data_diff (self1->child, self2->child, data);
|
2019-03-04 21:11:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_TRANSFORM_CATEGORY_2D_TRANSLATE:
|
|
|
|
{
|
|
|
|
cairo_region_t *sub;
|
|
|
|
float dx, dy;
|
|
|
|
gsk_transform_to_translate (self1->transform, &dx, &dy);
|
|
|
|
sub = cairo_region_create ();
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_data_diff (self1->child, self2->child, &(GskDiffData) {sub, data->offload });
|
2021-03-28 13:28:40 +00:00
|
|
|
cairo_region_translate (sub, floorf (dx), floorf (dy));
|
|
|
|
if (floorf (dx) != dx)
|
2019-03-04 21:11:57 +00:00
|
|
|
{
|
|
|
|
cairo_region_t *tmp = cairo_region_copy (sub);
|
|
|
|
cairo_region_translate (tmp, 1, 0);
|
|
|
|
cairo_region_union (sub, tmp);
|
2019-07-21 20:18:58 +00:00
|
|
|
cairo_region_destroy (tmp);
|
2019-03-04 21:11:57 +00:00
|
|
|
}
|
2021-03-28 13:28:40 +00:00
|
|
|
if (floorf (dy) != dy)
|
2019-03-04 21:11:57 +00:00
|
|
|
{
|
|
|
|
cairo_region_t *tmp = cairo_region_copy (sub);
|
|
|
|
cairo_region_translate (tmp, 0, 1);
|
|
|
|
cairo_region_union (sub, tmp);
|
2019-07-21 20:18:58 +00:00
|
|
|
cairo_region_destroy (tmp);
|
2019-03-04 21:11:57 +00:00
|
|
|
}
|
2023-10-31 23:07:23 +00:00
|
|
|
cairo_region_union (data->region, sub);
|
2019-03-04 21:11:57 +00:00
|
|
|
cairo_region_destroy (sub);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-04-28 02:28:23 +00:00
|
|
|
case GSK_TRANSFORM_CATEGORY_2D_AFFINE:
|
|
|
|
{
|
|
|
|
cairo_region_t *sub;
|
|
|
|
float scale_x, scale_y, dx, dy;
|
|
|
|
gsk_transform_to_affine (self1->transform, &scale_x, &scale_y, &dx, &dy);
|
|
|
|
sub = cairo_region_create ();
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_data_diff (self1->child, self2->child, &(GskDiffData) { sub, data->offload });
|
|
|
|
region_union_region_affine (data->region, sub, scale_x, scale_y, dx, dy);
|
2023-04-28 02:28:23 +00:00
|
|
|
cairo_region_destroy (sub);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-03-04 21:11:57 +00:00
|
|
|
case GSK_TRANSFORM_CATEGORY_UNKNOWN:
|
|
|
|
case GSK_TRANSFORM_CATEGORY_ANY:
|
|
|
|
case GSK_TRANSFORM_CATEGORY_3D:
|
|
|
|
case GSK_TRANSFORM_CATEGORY_2D:
|
|
|
|
default:
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2019-03-04 21:11:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_transform_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_TRANSFORM_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_transform_node_finalize;
|
|
|
|
node_class->draw = gsk_transform_node_draw;
|
|
|
|
node_class->can_diff = gsk_transform_node_can_diff;
|
|
|
|
node_class->diff = gsk_transform_node_diff;
|
|
|
|
}
|
|
|
|
|
2016-12-12 23:11:06 +00:00
|
|
|
/**
|
2020-06-27 09:22:54 +00:00
|
|
|
* gsk_transform_node_new:
|
2016-12-12 23:11:06 +00:00
|
|
|
* @child: The node to transform
|
2019-03-01 05:35:55 +00:00
|
|
|
* @transform: (transfer none): The transform to apply
|
2016-12-12 23:11:06 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that will transform the given @child
|
2016-12-12 23:11:06 +00:00
|
|
|
* with the given @transform.
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer full) (type GskTransformNode): A new `GskRenderNode`
|
2016-12-12 23:11:06 +00:00
|
|
|
*/
|
|
|
|
GskRenderNode *
|
2019-03-01 05:35:55 +00:00
|
|
|
gsk_transform_node_new (GskRenderNode *child,
|
|
|
|
GskTransform *transform)
|
2016-12-12 23:11:06 +00:00
|
|
|
{
|
2019-03-01 05:35:55 +00:00
|
|
|
GskTransformNode *self;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNode *node;
|
2019-03-01 05:35:55 +00:00
|
|
|
|
2016-12-12 23:11:06 +00:00
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL);
|
|
|
|
g_return_val_if_fail (transform != NULL, NULL);
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self = gsk_render_node_alloc (GSK_TRANSFORM_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = child->offscreen_for_opacity;
|
2016-12-12 23:11:06 +00:00
|
|
|
|
|
|
|
self->child = gsk_render_node_ref (child);
|
2019-03-01 05:35:55 +00:00
|
|
|
self->transform = gsk_transform_ref (transform);
|
2016-12-12 23:11:06 +00:00
|
|
|
|
2021-07-24 14:48:20 +00:00
|
|
|
if (gsk_transform_get_category (transform) >= GSK_TRANSFORM_CATEGORY_2D_TRANSLATE)
|
|
|
|
gsk_transform_to_translate (transform, &self->dx, &self->dy);
|
|
|
|
else
|
|
|
|
self->dx = self->dy = 0;
|
|
|
|
|
2019-03-01 05:35:55 +00:00
|
|
|
gsk_transform_transform_bounds (self->transform,
|
|
|
|
&child->bounds,
|
2020-04-07 22:33:54 +00:00
|
|
|
&node->bounds);
|
2019-02-26 06:24:18 +00:00
|
|
|
|
2023-06-15 18:27:13 +00:00
|
|
|
node->preferred_depth = gsk_render_node_get_preferred_depth (child);
|
2021-10-01 20:23:12 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return node;
|
2016-12-12 23:11:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_transform_node_get_child:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskTransformNode): a `GskRenderNode` for a transform
|
2016-12-12 23:11:06 +00:00
|
|
|
*
|
|
|
|
* Gets the child node that is getting transformed by the given @node.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): The child that is getting transformed
|
2020-04-07 22:33:54 +00:00
|
|
|
*/
|
2016-12-12 23:11:06 +00:00
|
|
|
GskRenderNode *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_transform_node_get_child (const GskRenderNode *node)
|
2016-12-12 23:11:06 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskTransformNode *self = (const GskTransformNode *) node;
|
2016-12-12 23:11:06 +00:00
|
|
|
|
|
|
|
return self->child;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_transform_node_get_transform:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskTransformNode): a `GskRenderNode` for a transform
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Retrieves the `GskTransform` used by the @node.
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer none): a `GskTransform`
|
2020-04-07 22:33:54 +00:00
|
|
|
*/
|
2019-03-01 05:35:55 +00:00
|
|
|
GskTransform *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_transform_node_get_transform (const GskRenderNode *node)
|
2016-12-12 23:11:06 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskTransformNode *self = (const GskTransformNode *) node;
|
2016-12-12 23:11:06 +00:00
|
|
|
|
2019-03-01 05:35:55 +00:00
|
|
|
return self->transform;
|
2019-02-19 05:52:36 +00:00
|
|
|
}
|
|
|
|
|
2021-07-24 14:48:20 +00:00
|
|
|
void
|
|
|
|
gsk_transform_node_get_translate (const GskRenderNode *node,
|
|
|
|
float *dx,
|
|
|
|
float *dy)
|
|
|
|
{
|
|
|
|
const GskTransformNode *self = (const GskTransformNode *) node;
|
|
|
|
|
|
|
|
*dx = self->dx;
|
|
|
|
*dy = self->dy;
|
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_OPACITY_NODE */
|
2018-04-23 22:41:48 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskOpacityNode:
|
|
|
|
*
|
|
|
|
* A render node controlling the opacity of its single child node.
|
|
|
|
*/
|
2020-04-07 22:33:54 +00:00
|
|
|
struct _GskOpacityNode
|
2018-04-23 22:41:48 +00:00
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GskRenderNode *child;
|
2020-04-07 22:33:54 +00:00
|
|
|
float opacity;
|
2018-04-23 22:41:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-04-07 22:33:54 +00:00
|
|
|
gsk_opacity_node_finalize (GskRenderNode *node)
|
2018-04-23 22:41:48 +00:00
|
|
|
{
|
2020-04-07 22:33:54 +00:00
|
|
|
GskOpacityNode *self = (GskOpacityNode *) node;
|
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_OPACITY_NODE));
|
2018-04-23 22:41:48 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (self->child);
|
2020-04-07 22:33:54 +00:00
|
|
|
|
|
|
|
parent_class->finalize (node);
|
2018-04-23 22:41:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-04-07 22:33:54 +00:00
|
|
|
gsk_opacity_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
2018-04-23 22:41:48 +00:00
|
|
|
{
|
2020-04-07 22:33:54 +00:00
|
|
|
GskOpacityNode *self = (GskOpacityNode *) node;
|
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
|
|
|
|
/* clip so the push_group() creates a smaller surface */
|
|
|
|
gsk_cairo_rectangle (cr, &node->bounds);
|
|
|
|
cairo_clip (cr);
|
|
|
|
|
|
|
|
cairo_push_group (cr);
|
2018-04-23 22:41:48 +00:00
|
|
|
|
|
|
|
gsk_render_node_draw (self->child, cr);
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
cairo_pop_group_to_source (cr);
|
|
|
|
cairo_paint_with_alpha (cr, self->opacity);
|
2018-04-23 22:41:48 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
cairo_restore (cr);
|
2018-04-23 22:41:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-04-07 22:33:54 +00:00
|
|
|
gsk_opacity_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2018-04-23 22:41:48 +00:00
|
|
|
{
|
2020-04-07 22:33:54 +00:00
|
|
|
GskOpacityNode *self1 = (GskOpacityNode *) node1;
|
|
|
|
GskOpacityNode *self2 = (GskOpacityNode *) node2;
|
2018-04-23 22:41:48 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
if (self1->opacity == self2->opacity)
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_data_diff (self1->child, self2->child, data);
|
2020-04-07 22:33:54 +00:00
|
|
|
else
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2018-04-23 22:41:48 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_opacity_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_OPACITY_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_opacity_node_finalize;
|
|
|
|
node_class->draw = gsk_opacity_node_draw;
|
|
|
|
node_class->diff = gsk_opacity_node_diff;
|
|
|
|
}
|
|
|
|
|
2018-04-23 22:41:48 +00:00
|
|
|
/**
|
2020-06-27 09:22:54 +00:00
|
|
|
* gsk_opacity_node_new:
|
2020-04-07 22:33:54 +00:00
|
|
|
* @child: The node to draw
|
|
|
|
* @opacity: The opacity to apply
|
2018-04-23 22:41:48 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that will drawn the @child with reduced
|
2020-04-07 22:33:54 +00:00
|
|
|
* @opacity.
|
2018-04-23 22:41:48 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer full) (type GskOpacityNode): A new `GskRenderNode`
|
2018-04-23 22:41:48 +00:00
|
|
|
*/
|
|
|
|
GskRenderNode *
|
2020-04-07 22:33:54 +00:00
|
|
|
gsk_opacity_node_new (GskRenderNode *child,
|
|
|
|
float opacity)
|
2018-04-23 22:41:48 +00:00
|
|
|
{
|
2020-04-07 22:33:54 +00:00
|
|
|
GskOpacityNode *self;
|
|
|
|
GskRenderNode *node;
|
2018-04-23 22:41:48 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL);
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self = gsk_render_node_alloc (GSK_OPACITY_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = child->offscreen_for_opacity;
|
2018-04-23 22:41:48 +00:00
|
|
|
|
|
|
|
self->child = gsk_render_node_ref (child);
|
2020-04-07 22:33:54 +00:00
|
|
|
self->opacity = CLAMP (opacity, 0.0, 1.0);
|
2018-04-23 22:41:48 +00:00
|
|
|
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&node->bounds, &child->bounds);
|
2018-04-23 22:41:48 +00:00
|
|
|
|
2023-06-15 18:27:13 +00:00
|
|
|
node->preferred_depth = gsk_render_node_get_preferred_depth (child);
|
2021-10-01 20:23:12 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return node;
|
2018-04-23 22:41:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-04-07 22:33:54 +00:00
|
|
|
* gsk_opacity_node_get_child:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskOpacityNode): a `GskRenderNode` for an opacity
|
2018-04-23 22:41:48 +00:00
|
|
|
*
|
2020-04-07 22:33:54 +00:00
|
|
|
* Gets the child node that is getting opacityed by the given @node.
|
2018-04-23 22:41:48 +00:00
|
|
|
*
|
2020-04-07 22:33:54 +00:00
|
|
|
* Returns: (transfer none): The child that is getting opacityed
|
|
|
|
*/
|
2018-04-23 22:41:48 +00:00
|
|
|
GskRenderNode *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_opacity_node_get_child (const GskRenderNode *node)
|
2018-04-23 22:41:48 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskOpacityNode *self = (const GskOpacityNode *) node;
|
2018-04-23 22:41:48 +00:00
|
|
|
|
|
|
|
return self->child;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-04-07 22:33:54 +00:00
|
|
|
* gsk_opacity_node_get_opacity:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskOpacityNode): a `GskRenderNode` for an opacity
|
2018-04-23 22:41:48 +00:00
|
|
|
*
|
2020-04-07 22:33:54 +00:00
|
|
|
* Gets the transparency factor for an opacity node.
|
2018-04-23 22:41:48 +00:00
|
|
|
*
|
2020-04-07 22:33:54 +00:00
|
|
|
* Returns: the opacity factor
|
|
|
|
*/
|
|
|
|
float
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_opacity_node_get_opacity (const GskRenderNode *node)
|
2018-04-23 22:41:48 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskOpacityNode *self = (const GskOpacityNode *) node;
|
2018-04-23 22:41:48 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return self->opacity;
|
2018-04-23 22:41:48 +00:00
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_COLOR_MATRIX_NODE */
|
2016-12-31 00:13:19 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskColorMatrixNode:
|
|
|
|
*
|
|
|
|
* A render node controlling the color matrix of its single child node.
|
|
|
|
*/
|
2016-12-31 00:13:19 +00:00
|
|
|
struct _GskColorMatrixNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GskRenderNode *child;
|
|
|
|
graphene_matrix_t color_matrix;
|
|
|
|
graphene_vec4_t color_offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_color_matrix_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskColorMatrixNode *self = (GskColorMatrixNode *) node;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_COLOR_MATRIX_NODE));
|
2016-12-31 00:13:19 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (self->child);
|
2020-04-07 22:33:54 +00:00
|
|
|
|
|
|
|
parent_class->finalize (node);
|
2016-12-31 00:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-02-14 18:44:39 +00:00
|
|
|
apply_color_matrix_to_pattern (cairo_pattern_t *pattern,
|
|
|
|
const graphene_matrix_t *color_matrix,
|
2023-07-03 18:45:53 +00:00
|
|
|
const graphene_vec4_t *color_offset)
|
2016-12-31 00:13:19 +00:00
|
|
|
{
|
|
|
|
cairo_surface_t *surface, *image_surface;
|
2020-02-01 23:56:39 +00:00
|
|
|
guchar *data;
|
|
|
|
gsize x, y, width, height, stride;
|
2023-02-15 02:46:58 +00:00
|
|
|
float alpha;
|
2023-02-14 18:44:39 +00:00
|
|
|
graphene_vec4_t pixel;
|
|
|
|
guint32* pixel_data;
|
2016-12-31 00:13:19 +00:00
|
|
|
|
|
|
|
cairo_pattern_get_surface (pattern, &surface);
|
|
|
|
image_surface = cairo_surface_map_to_image (surface, NULL);
|
|
|
|
|
2020-02-01 23:56:39 +00:00
|
|
|
data = cairo_image_surface_get_data (image_surface);
|
|
|
|
width = cairo_image_surface_get_width (image_surface);
|
|
|
|
height = cairo_image_surface_get_height (image_surface);
|
|
|
|
stride = cairo_image_surface_get_stride (image_surface);
|
2016-12-31 00:13:19 +00:00
|
|
|
|
2020-02-01 23:56:39 +00:00
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
pixel_data = (guint32 *) data;
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
{
|
2023-02-15 02:46:58 +00:00
|
|
|
alpha = ((pixel_data[x] >> 24) & 0xFF) / 255.0;
|
2020-02-01 23:56:39 +00:00
|
|
|
|
|
|
|
if (alpha == 0)
|
|
|
|
{
|
|
|
|
graphene_vec4_init (&pixel, 0.0, 0.0, 0.0, 0.0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
graphene_vec4_init (&pixel,
|
|
|
|
((pixel_data[x] >> 16) & 0xFF) / (255.0 * alpha),
|
|
|
|
((pixel_data[x] >> 8) & 0xFF) / (255.0 * alpha),
|
|
|
|
( pixel_data[x] & 0xFF) / (255.0 * alpha),
|
|
|
|
alpha);
|
2023-02-14 18:44:39 +00:00
|
|
|
graphene_matrix_transform_vec4 (color_matrix, &pixel, &pixel);
|
2020-02-01 23:56:39 +00:00
|
|
|
}
|
|
|
|
|
2023-02-14 18:44:39 +00:00
|
|
|
graphene_vec4_add (&pixel, color_offset, &pixel);
|
2020-02-01 23:56:39 +00:00
|
|
|
|
|
|
|
alpha = graphene_vec4_get_w (&pixel);
|
2023-02-14 18:44:39 +00:00
|
|
|
|
2020-02-01 23:56:39 +00:00
|
|
|
if (alpha > 0.0)
|
|
|
|
{
|
|
|
|
alpha = MIN (alpha, 1.0);
|
|
|
|
pixel_data[x] = (((guint32) roundf (alpha * 255)) << 24) |
|
|
|
|
(((guint32) roundf (CLAMP (graphene_vec4_get_x (&pixel), 0, 1) * alpha * 255)) << 16) |
|
|
|
|
(((guint32) roundf (CLAMP (graphene_vec4_get_y (&pixel), 0, 1) * alpha * 255)) << 8) |
|
|
|
|
((guint32) roundf (CLAMP (graphene_vec4_get_z (&pixel), 0, 1) * alpha * 255));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pixel_data[x] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data += stride;
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_surface_mark_dirty (image_surface);
|
2016-12-31 00:13:19 +00:00
|
|
|
cairo_surface_unmap_image (surface, image_surface);
|
2023-07-03 05:14:53 +00:00
|
|
|
/* https://gitlab.freedesktop.org/cairo/cairo/-/merge_requests/487 */
|
|
|
|
cairo_surface_mark_dirty (surface);
|
2023-02-14 18:44:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_color_matrix_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskColorMatrixNode *self = (GskColorMatrixNode *) node;
|
|
|
|
cairo_pattern_t *pattern;
|
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
|
|
|
|
/* clip so the push_group() creates a smaller surface */
|
|
|
|
gsk_cairo_rectangle (cr, &node->bounds);
|
|
|
|
cairo_clip (cr);
|
|
|
|
|
|
|
|
cairo_push_group (cr);
|
|
|
|
|
|
|
|
gsk_render_node_draw (self->child, cr);
|
|
|
|
|
|
|
|
pattern = cairo_pop_group (cr);
|
|
|
|
|
2023-07-03 18:45:53 +00:00
|
|
|
apply_color_matrix_to_pattern (pattern, &self->color_matrix, &self->color_offset);
|
2016-12-31 00:13:19 +00:00
|
|
|
|
|
|
|
cairo_set_source (cr, pattern);
|
|
|
|
cairo_paint (cr);
|
|
|
|
|
|
|
|
cairo_restore (cr);
|
2017-08-03 23:18:13 +00:00
|
|
|
cairo_pattern_destroy (pattern);
|
2016-12-31 00:13:19 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 14:26:35 +00:00
|
|
|
static void
|
|
|
|
gsk_color_matrix_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2020-05-13 14:26:35 +00:00
|
|
|
{
|
|
|
|
GskColorMatrixNode *self1 = (GskColorMatrixNode *) node1;
|
|
|
|
GskColorMatrixNode *self2 = (GskColorMatrixNode *) node2;
|
|
|
|
|
|
|
|
if (!graphene_vec4_equal (&self1->color_offset, &self2->color_offset))
|
|
|
|
goto nope;
|
|
|
|
|
|
|
|
if (!graphene_matrix_equal_fast (&self1->color_matrix, &self2->color_matrix))
|
|
|
|
goto nope;
|
|
|
|
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_data_diff (self1->child, self2->child, data);
|
2020-05-13 14:26:35 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
nope:
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2020-05-13 14:26:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_color_matrix_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_COLOR_MATRIX_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_color_matrix_node_finalize;
|
|
|
|
node_class->draw = gsk_color_matrix_node_draw;
|
|
|
|
node_class->diff = gsk_color_matrix_node_diff;
|
|
|
|
}
|
|
|
|
|
2016-12-31 00:13:19 +00:00
|
|
|
/**
|
2020-06-27 09:22:54 +00:00
|
|
|
* gsk_color_matrix_node_new:
|
2016-12-31 00:13:19 +00:00
|
|
|
* @child: The node to draw
|
|
|
|
* @color_matrix: The matrix to apply
|
|
|
|
* @color_offset: Values to add to the color
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that will drawn the @child with
|
2016-12-31 00:13:19 +00:00
|
|
|
* @color_matrix.
|
|
|
|
*
|
2023-08-15 08:28:43 +00:00
|
|
|
* In particular, the node will transform colors by applying
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
2023-08-15 08:28:43 +00:00
|
|
|
* pixel = transpose(color_matrix) * pixel + color_offset
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
2023-08-15 08:28:43 +00:00
|
|
|
* for every pixel. The transformation operates on unpremultiplied
|
|
|
|
* colors, with color components ordered R, G, B, A.
|
2016-12-31 00:13:19 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer full) (type GskColorMatrixNode): A new `GskRenderNode`
|
2016-12-31 00:13:19 +00:00
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_color_matrix_node_new (GskRenderNode *child,
|
|
|
|
const graphene_matrix_t *color_matrix,
|
|
|
|
const graphene_vec4_t *color_offset)
|
|
|
|
{
|
|
|
|
GskColorMatrixNode *self;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNode *node;
|
2016-12-31 00:13:19 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL);
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self = gsk_render_node_alloc (GSK_COLOR_MATRIX_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = child->offscreen_for_opacity;
|
2016-12-31 00:13:19 +00:00
|
|
|
|
|
|
|
self->child = gsk_render_node_ref (child);
|
|
|
|
graphene_matrix_init_from_matrix (&self->color_matrix, color_matrix);
|
|
|
|
graphene_vec4_init_from_vec4 (&self->color_offset, color_offset);
|
|
|
|
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&node->bounds, &child->bounds);
|
2016-12-31 00:13:19 +00:00
|
|
|
|
2023-06-15 18:27:13 +00:00
|
|
|
node->preferred_depth = gsk_render_node_get_preferred_depth (child);
|
2021-10-01 20:23:12 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return node;
|
2016-12-31 00:13:19 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 01:53:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_color_matrix_node_get_child:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskColorMatrixNode): a color matrix `GskRenderNode`
|
2017-09-25 01:53:54 +00:00
|
|
|
*
|
|
|
|
* Gets the child node that is getting its colors modified by the given @node.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): The child that is getting its colors modified
|
|
|
|
**/
|
2016-12-31 00:13:19 +00:00
|
|
|
GskRenderNode *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_color_matrix_node_get_child (const GskRenderNode *node)
|
2016-12-31 00:13:19 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskColorMatrixNode *self = (const GskColorMatrixNode *) node;
|
2016-12-31 00:13:19 +00:00
|
|
|
|
|
|
|
return self->child;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_color_matrix_node_get_color_matrix:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskColorMatrixNode): a color matrix `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the color matrix used by the @node.
|
|
|
|
*
|
|
|
|
* Returns: a 4x4 color matrix
|
|
|
|
*/
|
2016-12-31 00:13:19 +00:00
|
|
|
const graphene_matrix_t *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_color_matrix_node_get_color_matrix (const GskRenderNode *node)
|
2016-12-31 00:13:19 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskColorMatrixNode *self = (const GskColorMatrixNode *) node;
|
2016-12-31 00:13:19 +00:00
|
|
|
|
|
|
|
return &self->color_matrix;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_color_matrix_node_get_color_offset:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskColorMatrixNode): a color matrix `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the color offset used by the @node.
|
|
|
|
*
|
|
|
|
* Returns: a color vector
|
|
|
|
*/
|
2016-12-31 00:13:19 +00:00
|
|
|
const graphene_vec4_t *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_color_matrix_node_get_color_offset (const GskRenderNode *node)
|
2016-12-31 00:13:19 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskColorMatrixNode *self = (const GskColorMatrixNode *) node;
|
2016-12-31 00:13:19 +00:00
|
|
|
|
|
|
|
return &self->color_offset;
|
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_REPEAT_NODE */
|
2017-01-01 18:52:18 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskRepeatNode:
|
|
|
|
*
|
|
|
|
* A render node repeating its single child node.
|
|
|
|
*/
|
2017-01-01 18:52:18 +00:00
|
|
|
struct _GskRepeatNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GskRenderNode *child;
|
|
|
|
graphene_rect_t child_bounds;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_repeat_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskRepeatNode *self = (GskRepeatNode *) node;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_REPEAT_NODE));
|
2017-01-01 18:52:18 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (self->child);
|
2020-04-07 22:33:54 +00:00
|
|
|
|
|
|
|
parent_class->finalize (node);
|
2017-01-01 18:52:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_repeat_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskRepeatNode *self = (GskRepeatNode *) node;
|
|
|
|
cairo_pattern_t *pattern;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *surface_cr;
|
2023-06-05 03:29:41 +00:00
|
|
|
double scale_x, scale_y, width, height;
|
|
|
|
cairo_matrix_t matrix;
|
2017-01-01 18:52:18 +00:00
|
|
|
|
2023-06-05 03:29:41 +00:00
|
|
|
cairo_get_matrix (cr, &matrix);
|
|
|
|
width = ceil (self->child_bounds.size.width * (ABS (matrix.xx) + ABS (matrix.yx)));
|
|
|
|
height = ceil (self->child_bounds.size.height * (ABS (matrix.xy) + ABS (matrix.yy)));
|
2017-01-01 18:52:18 +00:00
|
|
|
surface = cairo_surface_create_similar (cairo_get_target (cr),
|
|
|
|
CAIRO_CONTENT_COLOR_ALPHA,
|
2023-06-05 03:29:41 +00:00
|
|
|
width, height);
|
2023-05-21 03:03:49 +00:00
|
|
|
cairo_surface_get_device_scale (surface, &scale_x, &scale_y);
|
2023-06-05 03:29:41 +00:00
|
|
|
scale_x *= width / self->child_bounds.size.width;
|
|
|
|
scale_y *= height / self->child_bounds.size.height;
|
|
|
|
cairo_surface_set_device_scale (surface, scale_x, scale_y);
|
2023-08-09 18:02:05 +00:00
|
|
|
cairo_surface_set_device_offset (surface,
|
2023-05-21 03:03:49 +00:00
|
|
|
- self->child_bounds.origin.x * scale_x,
|
|
|
|
- self->child_bounds.origin.y * scale_y);
|
|
|
|
|
2017-01-01 18:52:18 +00:00
|
|
|
surface_cr = cairo_create (surface);
|
|
|
|
gsk_render_node_draw (self->child, surface_cr);
|
|
|
|
cairo_destroy (surface_cr);
|
|
|
|
|
|
|
|
pattern = cairo_pattern_create_for_surface (surface);
|
|
|
|
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
|
|
|
|
cairo_set_source (cr, pattern);
|
|
|
|
cairo_pattern_destroy (pattern);
|
|
|
|
cairo_surface_destroy (surface);
|
2020-02-13 00:48:03 +00:00
|
|
|
|
|
|
|
gsk_cairo_rectangle (cr, &node->bounds);
|
|
|
|
cairo_fill (cr);
|
2017-01-01 18:52:18 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_repeat_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_REPEAT_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_repeat_node_finalize;
|
|
|
|
node_class->draw = gsk_repeat_node_draw;
|
|
|
|
}
|
|
|
|
|
2017-01-01 18:52:18 +00:00
|
|
|
/**
|
2020-06-27 09:22:54 +00:00
|
|
|
* gsk_repeat_node_new:
|
2017-01-01 18:52:18 +00:00
|
|
|
* @bounds: The bounds of the area to be painted
|
|
|
|
* @child: The child to repeat
|
2021-05-19 11:24:34 +00:00
|
|
|
* @child_bounds: (nullable): The area of the child to repeat or %NULL to
|
2017-01-01 18:52:18 +00:00
|
|
|
* use the child's bounds
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that will repeat the drawing of @child across
|
2017-01-01 18:52:18 +00:00
|
|
|
* the given @bounds.
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer full) (type GskRepeatNode): A new `GskRenderNode`
|
2017-01-01 18:52:18 +00:00
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_repeat_node_new (const graphene_rect_t *bounds,
|
|
|
|
GskRenderNode *child,
|
|
|
|
const graphene_rect_t *child_bounds)
|
|
|
|
{
|
|
|
|
GskRepeatNode *self;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNode *node;
|
2017-01-01 18:52:18 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (bounds != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL);
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self = gsk_render_node_alloc (GSK_REPEAT_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = TRUE;
|
2020-04-07 22:33:54 +00:00
|
|
|
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&node->bounds, bounds);
|
2017-01-01 18:52:18 +00:00
|
|
|
|
|
|
|
self->child = gsk_render_node_ref (child);
|
2020-04-07 22:33:54 +00:00
|
|
|
|
2017-01-01 18:52:18 +00:00
|
|
|
if (child_bounds)
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&self->child_bounds, child_bounds);
|
2017-01-01 18:52:18 +00:00
|
|
|
else
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&self->child_bounds, &child->bounds);
|
2017-01-01 18:52:18 +00:00
|
|
|
|
2023-06-15 18:27:13 +00:00
|
|
|
node->preferred_depth = gsk_render_node_get_preferred_depth (child);
|
2021-10-01 20:23:12 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return node;
|
2017-01-01 18:52:18 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_repeat_node_get_child:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskRepeatNode): a repeat `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the child of @node.
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer none): a `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*/
|
2017-01-01 18:52:18 +00:00
|
|
|
GskRenderNode *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_repeat_node_get_child (const GskRenderNode *node)
|
2017-01-01 18:52:18 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskRepeatNode *self = (const GskRepeatNode *) node;
|
2017-01-01 18:52:18 +00:00
|
|
|
|
|
|
|
return self->child;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_repeat_node_get_child_bounds:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskRepeatNode): a repeat `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the bounding rectangle of the child of @node.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): a bounding rectangle
|
|
|
|
*/
|
2017-01-01 18:52:18 +00:00
|
|
|
const graphene_rect_t *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_repeat_node_get_child_bounds (const GskRenderNode *node)
|
2017-01-01 18:52:18 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskRepeatNode *self = (const GskRepeatNode *) node;
|
2017-01-01 18:52:18 +00:00
|
|
|
|
|
|
|
return &self->child_bounds;
|
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_CLIP_NODE */
|
2016-12-13 08:37:51 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskClipNode:
|
|
|
|
*
|
|
|
|
* A render node applying a rectangular clip to its single child node.
|
|
|
|
*/
|
2016-12-13 08:37:51 +00:00
|
|
|
struct _GskClipNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GskRenderNode *child;
|
|
|
|
graphene_rect_t clip;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_clip_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskClipNode *self = (GskClipNode *) node;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_CLIP_NODE));
|
2016-12-13 08:37:51 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (self->child);
|
2020-04-07 22:33:54 +00:00
|
|
|
|
|
|
|
parent_class->finalize (node);
|
2016-12-13 08:37:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_clip_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskClipNode *self = (GskClipNode *) node;
|
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
|
2020-02-13 00:48:03 +00:00
|
|
|
gsk_cairo_rectangle (cr, &self->clip);
|
2016-12-13 08:37:51 +00:00
|
|
|
cairo_clip (cr);
|
|
|
|
|
|
|
|
gsk_render_node_draw (self->child, cr);
|
|
|
|
|
|
|
|
cairo_restore (cr);
|
|
|
|
}
|
|
|
|
|
2018-03-27 22:34:23 +00:00
|
|
|
static void
|
|
|
|
gsk_clip_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2018-03-27 22:34:23 +00:00
|
|
|
{
|
|
|
|
GskClipNode *self1 = (GskClipNode *) node1;
|
|
|
|
GskClipNode *self2 = (GskClipNode *) node2;
|
|
|
|
|
2023-11-13 21:12:58 +00:00
|
|
|
if (gsk_rect_equal (&self1->clip, &self2->clip))
|
2018-03-27 22:34:23 +00:00
|
|
|
{
|
|
|
|
cairo_region_t *sub;
|
|
|
|
cairo_rectangle_int_t clip_rect;
|
2018-07-08 10:50:21 +00:00
|
|
|
|
2018-03-27 22:34:23 +00:00
|
|
|
sub = cairo_region_create();
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_data_diff (self1->child, self2->child, &(GskDiffData) {sub, data->offload });
|
2018-03-27 22:34:23 +00:00
|
|
|
rectangle_init_from_graphene (&clip_rect, &self1->clip);
|
|
|
|
cairo_region_intersect_rectangle (sub, &clip_rect);
|
2023-10-31 23:07:23 +00:00
|
|
|
cairo_region_union (data->region, sub);
|
2018-03-27 22:34:23 +00:00
|
|
|
cairo_region_destroy (sub);
|
|
|
|
}
|
2018-07-08 10:50:21 +00:00
|
|
|
else
|
|
|
|
{
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2018-07-08 10:50:21 +00:00
|
|
|
}
|
2018-03-27 22:34:23 +00:00
|
|
|
}
|
2023-08-09 18:02:05 +00:00
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_clip_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_CLIP_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_clip_node_finalize;
|
|
|
|
node_class->draw = gsk_clip_node_draw;
|
|
|
|
node_class->diff = gsk_clip_node_diff;
|
|
|
|
}
|
2018-03-27 22:34:23 +00:00
|
|
|
|
2016-12-13 08:37:51 +00:00
|
|
|
/**
|
2020-06-27 09:22:54 +00:00
|
|
|
* gsk_clip_node_new:
|
2016-12-13 08:37:51 +00:00
|
|
|
* @child: The node to draw
|
|
|
|
* @clip: The clip to apply
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that will clip the @child to the area
|
2016-12-13 08:37:51 +00:00
|
|
|
* given by @clip.
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer full) (type GskClipNode): A new `GskRenderNode`
|
2016-12-13 08:37:51 +00:00
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_clip_node_new (GskRenderNode *child,
|
|
|
|
const graphene_rect_t *clip)
|
|
|
|
{
|
|
|
|
GskClipNode *self;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNode *node;
|
2016-12-13 08:37:51 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL);
|
|
|
|
g_return_val_if_fail (clip != NULL, NULL);
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self = gsk_render_node_alloc (GSK_CLIP_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = child->offscreen_for_opacity;
|
2016-12-13 08:37:51 +00:00
|
|
|
|
|
|
|
self->child = gsk_render_node_ref (child);
|
|
|
|
graphene_rect_normalize_r (clip, &self->clip);
|
|
|
|
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_intersection (&self->clip, &child->bounds, &node->bounds);
|
2016-12-21 10:21:38 +00:00
|
|
|
|
2023-06-15 18:27:13 +00:00
|
|
|
node->preferred_depth = gsk_render_node_get_preferred_depth (child);
|
2021-10-01 20:23:12 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return node;
|
2016-12-13 08:37:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_clip_node_get_child:
|
2020-04-07 22:33:54 +00:00
|
|
|
* @node: (type GskClipNode): a clip @GskRenderNode
|
2016-12-13 08:37:51 +00:00
|
|
|
*
|
|
|
|
* Gets the child node that is getting clipped by the given @node.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): The child that is getting clipped
|
|
|
|
**/
|
|
|
|
GskRenderNode *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_clip_node_get_child (const GskRenderNode *node)
|
2016-12-13 08:37:51 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskClipNode *self = (const GskClipNode *) node;
|
2016-12-13 08:37:51 +00:00
|
|
|
|
|
|
|
return self->child;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_clip_node_get_clip:
|
2021-05-20 03:40:54 +00:00
|
|
|
* @node: (type GskClipNode): a `GskClipNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the clip rectangle for @node.
|
|
|
|
*
|
|
|
|
* Returns: a clip rectangle
|
|
|
|
*/
|
2016-12-13 08:37:51 +00:00
|
|
|
const graphene_rect_t *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_clip_node_get_clip (const GskRenderNode *node)
|
2016-12-13 08:37:51 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskClipNode *self = (const GskClipNode *) node;
|
2016-12-13 08:37:51 +00:00
|
|
|
|
|
|
|
return &self->clip;
|
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_ROUNDED_CLIP_NODE */
|
2016-12-13 20:59:28 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskRoundedClipNode:
|
|
|
|
*
|
|
|
|
* A render node applying a rounded rectangle clip to its single child.
|
|
|
|
*/
|
2016-12-13 20:59:28 +00:00
|
|
|
struct _GskRoundedClipNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GskRenderNode *child;
|
|
|
|
GskRoundedRect clip;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_rounded_clip_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskRoundedClipNode *self = (GskRoundedClipNode *) node;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_ROUNDED_CLIP_NODE));
|
2016-12-13 20:59:28 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (self->child);
|
2020-04-07 22:33:54 +00:00
|
|
|
|
|
|
|
parent_class->finalize (node);
|
2016-12-13 20:59:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_rounded_clip_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskRoundedClipNode *self = (GskRoundedClipNode *) node;
|
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
|
|
|
|
gsk_rounded_rect_path (&self->clip, cr);
|
|
|
|
cairo_clip (cr);
|
|
|
|
|
|
|
|
gsk_render_node_draw (self->child, cr);
|
|
|
|
|
|
|
|
cairo_restore (cr);
|
|
|
|
}
|
|
|
|
|
2018-03-27 22:34:23 +00:00
|
|
|
static void
|
|
|
|
gsk_rounded_clip_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2018-03-27 22:34:23 +00:00
|
|
|
{
|
|
|
|
GskRoundedClipNode *self1 = (GskRoundedClipNode *) node1;
|
|
|
|
GskRoundedClipNode *self2 = (GskRoundedClipNode *) node2;
|
|
|
|
|
|
|
|
if (gsk_rounded_rect_equal (&self1->clip, &self2->clip))
|
|
|
|
{
|
|
|
|
cairo_region_t *sub;
|
|
|
|
cairo_rectangle_int_t clip_rect;
|
2018-07-08 10:50:21 +00:00
|
|
|
|
2018-03-27 22:34:23 +00:00
|
|
|
sub = cairo_region_create();
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_data_diff (self1->child, self2->child, &(GskDiffData) { sub, data->offload });
|
2018-03-27 22:34:23 +00:00
|
|
|
rectangle_init_from_graphene (&clip_rect, &self1->clip.bounds);
|
|
|
|
cairo_region_intersect_rectangle (sub, &clip_rect);
|
2023-10-31 23:07:23 +00:00
|
|
|
cairo_region_union (data->region, sub);
|
2018-03-27 22:34:23 +00:00
|
|
|
cairo_region_destroy (sub);
|
|
|
|
}
|
2018-07-08 10:50:21 +00:00
|
|
|
else
|
|
|
|
{
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2018-07-08 10:50:21 +00:00
|
|
|
}
|
2018-03-27 22:34:23 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_rounded_clip_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_ROUNDED_CLIP_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_rounded_clip_node_finalize;
|
|
|
|
node_class->draw = gsk_rounded_clip_node_draw;
|
|
|
|
node_class->diff = gsk_rounded_clip_node_diff;
|
|
|
|
}
|
|
|
|
|
2016-12-13 20:59:28 +00:00
|
|
|
/**
|
2020-06-27 09:22:54 +00:00
|
|
|
* gsk_rounded_clip_node_new:
|
2016-12-13 20:59:28 +00:00
|
|
|
* @child: The node to draw
|
|
|
|
* @clip: The clip to apply
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that will clip the @child to the area
|
2016-12-13 20:59:28 +00:00
|
|
|
* given by @clip.
|
|
|
|
*
|
2022-08-10 08:07:51 +00:00
|
|
|
* Returns: (transfer full) (type GskRoundedClipNode): A new `GskRenderNode`
|
2016-12-13 20:59:28 +00:00
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_rounded_clip_node_new (GskRenderNode *child,
|
|
|
|
const GskRoundedRect *clip)
|
|
|
|
{
|
|
|
|
GskRoundedClipNode *self;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNode *node;
|
2016-12-13 20:59:28 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL);
|
|
|
|
g_return_val_if_fail (clip != NULL, NULL);
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self = gsk_render_node_alloc (GSK_ROUNDED_CLIP_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = child->offscreen_for_opacity;
|
2016-12-13 20:59:28 +00:00
|
|
|
|
|
|
|
self->child = gsk_render_node_ref (child);
|
|
|
|
gsk_rounded_rect_init_copy (&self->clip, clip);
|
|
|
|
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_intersection (&self->clip.bounds, &child->bounds, &node->bounds);
|
2016-12-21 10:21:38 +00:00
|
|
|
|
2023-06-15 18:27:13 +00:00
|
|
|
node->preferred_depth = gsk_render_node_get_preferred_depth (child);
|
2021-10-01 20:23:12 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return node;
|
2016-12-13 20:59:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_rounded_clip_node_get_child:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskRoundedClipNode): a rounded clip `GskRenderNode`
|
2016-12-13 20:59:28 +00:00
|
|
|
*
|
|
|
|
* Gets the child node that is getting clipped by the given @node.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): The child that is getting clipped
|
|
|
|
**/
|
|
|
|
GskRenderNode *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_rounded_clip_node_get_child (const GskRenderNode *node)
|
2016-12-13 20:59:28 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskRoundedClipNode *self = (const GskRoundedClipNode *) node;
|
2016-12-13 20:59:28 +00:00
|
|
|
|
|
|
|
return self->child;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_rounded_clip_node_get_clip:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskRoundedClipNode): a rounded clip `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Retrieves the rounded rectangle used to clip the contents of the @node.
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer none): a rounded rectangle
|
|
|
|
*/
|
2016-12-13 20:59:28 +00:00
|
|
|
const GskRoundedRect *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_rounded_clip_node_get_clip (const GskRenderNode *node)
|
2016-12-13 20:59:28 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskRoundedClipNode *self = (const GskRoundedClipNode *) node;
|
2016-12-13 20:59:28 +00:00
|
|
|
|
|
|
|
return &self->clip;
|
|
|
|
}
|
|
|
|
|
2020-11-10 23:44:32 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_FILL_NODE */
|
|
|
|
|
2023-08-09 18:02:05 +00:00
|
|
|
/**
|
|
|
|
* GskFillNode:
|
|
|
|
*
|
2023-08-11 13:53:24 +00:00
|
|
|
* A render node filling the area given by [struct@Gsk.Path]
|
|
|
|
* and [enum@Gsk.FillRule] with the child node.
|
2023-08-09 18:02:05 +00:00
|
|
|
*
|
|
|
|
* Since: 4.14
|
|
|
|
*/
|
|
|
|
|
2020-11-10 23:44:32 +00:00
|
|
|
struct _GskFillNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GskRenderNode *child;
|
|
|
|
GskPath *path;
|
|
|
|
GskFillRule fill_rule;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_fill_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskFillNode *self = (GskFillNode *) node;
|
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_FILL_NODE));
|
|
|
|
|
|
|
|
gsk_render_node_unref (self->child);
|
|
|
|
gsk_path_unref (self->path);
|
|
|
|
|
|
|
|
parent_class->finalize (node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_fill_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskFillNode *self = (GskFillNode *) node;
|
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
|
|
|
|
switch (self->fill_rule)
|
|
|
|
{
|
|
|
|
case GSK_FILL_RULE_WINDING:
|
|
|
|
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
|
|
|
|
break;
|
|
|
|
case GSK_FILL_RULE_EVEN_ODD:
|
|
|
|
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gsk_path_to_cairo (self->path, cr);
|
2023-07-30 17:59:37 +00:00
|
|
|
if (gsk_render_node_get_node_type (self->child) == GSK_COLOR_NODE &&
|
|
|
|
gsk_rect_contains_rect (&self->child->bounds, &node->bounds))
|
|
|
|
{
|
|
|
|
gdk_cairo_set_source_rgba (cr, gsk_color_node_get_color (self->child));
|
|
|
|
cairo_fill (cr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cairo_clip (cr);
|
|
|
|
gsk_render_node_draw (self->child, cr);
|
|
|
|
}
|
2020-11-10 23:44:32 +00:00
|
|
|
|
|
|
|
cairo_restore (cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_fill_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2020-11-10 23:44:32 +00:00
|
|
|
{
|
|
|
|
GskFillNode *self1 = (GskFillNode *) node1;
|
|
|
|
GskFillNode *self2 = (GskFillNode *) node2;
|
|
|
|
|
|
|
|
if (self1->path == self2->path)
|
|
|
|
{
|
|
|
|
cairo_region_t *sub;
|
|
|
|
cairo_rectangle_int_t clip_rect;
|
|
|
|
|
|
|
|
sub = cairo_region_create();
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_data_diff (self1->child, self2->child, &(GskDiffData) { sub, data->offload });
|
2020-11-10 23:44:32 +00:00
|
|
|
rectangle_init_from_graphene (&clip_rect, &node1->bounds);
|
|
|
|
cairo_region_intersect_rectangle (sub, &clip_rect);
|
2023-10-31 23:07:23 +00:00
|
|
|
cairo_region_union (data->region, sub);
|
2020-11-10 23:44:32 +00:00
|
|
|
cairo_region_destroy (sub);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2020-11-10 23:44:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_fill_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_FILL_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_fill_node_finalize;
|
|
|
|
node_class->draw = gsk_fill_node_draw;
|
|
|
|
node_class->diff = gsk_fill_node_diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_fill_node_new:
|
|
|
|
* @child: The node to fill the area with
|
|
|
|
* @path: The path describing the area to fill
|
|
|
|
* @fill_rule: The fill rule to use
|
|
|
|
*
|
|
|
|
* Creates a `GskRenderNode` that will fill the @child in the area
|
|
|
|
* given by @path and @fill_rule.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none) (type GskFillNode): A new `GskRenderNode`
|
|
|
|
*
|
|
|
|
* Since: 4.14
|
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_fill_node_new (GskRenderNode *child,
|
|
|
|
GskPath *path,
|
|
|
|
GskFillRule fill_rule)
|
|
|
|
{
|
|
|
|
GskFillNode *self;
|
|
|
|
GskRenderNode *node;
|
|
|
|
graphene_rect_t path_bounds;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL);
|
|
|
|
g_return_val_if_fail (path != NULL, NULL);
|
|
|
|
|
|
|
|
self = gsk_render_node_alloc (GSK_FILL_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
|
|
|
|
|
|
|
self->child = gsk_render_node_ref (child);
|
|
|
|
self->path = gsk_path_ref (path);
|
|
|
|
self->fill_rule = fill_rule;
|
|
|
|
|
|
|
|
if (gsk_path_get_bounds (path, &path_bounds))
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_intersection (&path_bounds, &child->bounds, &node->bounds);
|
2020-11-10 23:44:32 +00:00
|
|
|
else
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init (&node->bounds, 0.f, 0.f, 0.f, 0.f);
|
2020-11-10 23:44:32 +00:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_fill_node_get_child:
|
|
|
|
* @node: (type GskFillNode): a fill `GskRenderNode`
|
|
|
|
*
|
|
|
|
* Gets the child node that is getting drawn by the given @node.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): The child that is getting drawn
|
|
|
|
*
|
|
|
|
* Since: 4.14
|
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_fill_node_get_child (const GskRenderNode *node)
|
|
|
|
{
|
|
|
|
const GskFillNode *self = (const GskFillNode *) node;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_FILL_NODE), NULL);
|
|
|
|
|
|
|
|
return self->child;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_fill_node_get_path:
|
|
|
|
* @node: (type GskFillNode): a fill `GskRenderNode`
|
|
|
|
*
|
|
|
|
* Retrieves the path used to describe the area filled with the contents of
|
|
|
|
* the @node.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): a `GskPath`
|
|
|
|
*
|
|
|
|
* Since: 4.14
|
|
|
|
*/
|
|
|
|
GskPath *
|
|
|
|
gsk_fill_node_get_path (const GskRenderNode *node)
|
|
|
|
{
|
|
|
|
const GskFillNode *self = (const GskFillNode *) node;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_FILL_NODE), NULL);
|
|
|
|
|
|
|
|
return self->path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_fill_node_get_fill_rule:
|
|
|
|
* @node: (type GskFillNode): a fill `GskRenderNode`
|
|
|
|
*
|
|
|
|
* Retrieves the fill rule used to determine how the path is filled.
|
|
|
|
*
|
|
|
|
* Returns: a `GskFillRule`
|
|
|
|
*
|
|
|
|
* Since: 4.14
|
|
|
|
*/
|
|
|
|
GskFillRule
|
|
|
|
gsk_fill_node_get_fill_rule (const GskRenderNode *node)
|
|
|
|
{
|
|
|
|
const GskFillNode *self = (const GskFillNode *) node;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_FILL_NODE), GSK_FILL_RULE_WINDING);
|
|
|
|
|
|
|
|
return self->fill_rule;
|
|
|
|
}
|
|
|
|
|
2020-11-11 06:36:04 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_STROKE_NODE */
|
2023-08-09 18:02:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GskStrokeNode:
|
|
|
|
*
|
2023-08-11 13:53:24 +00:00
|
|
|
* A render node that will fill the area determined by stroking the the given
|
|
|
|
* [struct@Gsk.Path] using the [struct@Gsk.Stroke] attributes.
|
2023-08-09 18:02:05 +00:00
|
|
|
*
|
|
|
|
* Since: 4.14
|
|
|
|
*/
|
2020-11-11 06:36:04 +00:00
|
|
|
|
|
|
|
struct _GskStrokeNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GskRenderNode *child;
|
|
|
|
GskPath *path;
|
|
|
|
GskStroke stroke;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_stroke_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskStrokeNode *self = (GskStrokeNode *) node;
|
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_STROKE_NODE));
|
|
|
|
|
|
|
|
gsk_render_node_unref (self->child);
|
|
|
|
gsk_path_unref (self->path);
|
|
|
|
gsk_stroke_clear (&self->stroke);
|
|
|
|
|
|
|
|
parent_class->finalize (node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_stroke_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskStrokeNode *self = (GskStrokeNode *) node;
|
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
|
|
|
|
if (gsk_render_node_get_node_type (self->child) == GSK_COLOR_NODE &&
|
|
|
|
gsk_rect_contains_rect (&self->child->bounds, &node->bounds))
|
|
|
|
{
|
|
|
|
gdk_cairo_set_source_rgba (cr, gsk_color_node_get_color (self->child));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gsk_cairo_rectangle (cr, &self->child->bounds);
|
|
|
|
cairo_clip (cr);
|
|
|
|
cairo_push_group (cr);
|
|
|
|
gsk_render_node_draw (self->child, cr);
|
|
|
|
cairo_pop_group_to_source (cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
gsk_stroke_to_cairo (&self->stroke, cr);
|
|
|
|
|
|
|
|
gsk_path_to_cairo (self->path, cr);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
|
|
|
|
cairo_restore (cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_stroke_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2020-11-11 06:36:04 +00:00
|
|
|
{
|
|
|
|
GskStrokeNode *self1 = (GskStrokeNode *) node1;
|
|
|
|
GskStrokeNode *self2 = (GskStrokeNode *) node2;
|
|
|
|
|
|
|
|
if (self1->path == self2->path &&
|
|
|
|
gsk_stroke_equal (&self1->stroke, &self2->stroke))
|
|
|
|
{
|
|
|
|
cairo_region_t *sub;
|
|
|
|
cairo_rectangle_int_t clip_rect;
|
|
|
|
|
|
|
|
sub = cairo_region_create();
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_data_diff (self1->child, self2->child, &(GskDiffData) { sub, data->offload });
|
2020-11-11 06:36:04 +00:00
|
|
|
rectangle_init_from_graphene (&clip_rect, &node1->bounds);
|
|
|
|
cairo_region_intersect_rectangle (sub, &clip_rect);
|
2023-10-31 23:07:23 +00:00
|
|
|
cairo_region_union (data->region, sub);
|
2020-11-11 06:36:04 +00:00
|
|
|
cairo_region_destroy (sub);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2020-11-11 06:36:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_stroke_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_STROKE_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_stroke_node_finalize;
|
|
|
|
node_class->draw = gsk_stroke_node_draw;
|
|
|
|
node_class->diff = gsk_stroke_node_diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_stroke_node_new:
|
|
|
|
* @child: The node to stroke the area with
|
|
|
|
* @path: (transfer none): The path describing the area to stroke
|
|
|
|
* @stroke: (transfer none): The stroke attributes to use
|
|
|
|
*
|
2023-08-11 13:53:24 +00:00
|
|
|
* Creates a #GskRenderNode that will fill the outline generated by stroking
|
|
|
|
* the given @path using the attributes defined in @stroke.
|
|
|
|
*
|
|
|
|
* The area is filled with @child.
|
2020-11-11 06:36:04 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer none) (type GskStrokeNode): A new #GskRenderNode
|
|
|
|
*
|
|
|
|
* Since: 4.14
|
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_stroke_node_new (GskRenderNode *child,
|
|
|
|
GskPath *path,
|
|
|
|
const GskStroke *stroke)
|
|
|
|
{
|
|
|
|
GskStrokeNode *self;
|
|
|
|
GskRenderNode *node;
|
|
|
|
graphene_rect_t stroke_bounds;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL);
|
|
|
|
g_return_val_if_fail (path != NULL, NULL);
|
|
|
|
g_return_val_if_fail (stroke != NULL, NULL);
|
|
|
|
|
|
|
|
self = gsk_render_node_alloc (GSK_STROKE_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
|
|
|
|
|
|
|
self->child = gsk_render_node_ref (child);
|
|
|
|
self->path = gsk_path_ref (path);
|
|
|
|
gsk_stroke_init_copy (&self->stroke, stroke);
|
|
|
|
|
|
|
|
if (gsk_path_get_stroke_bounds (self->path, &self->stroke, &stroke_bounds))
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_intersection (&stroke_bounds, &child->bounds, &node->bounds);
|
2020-11-11 06:36:04 +00:00
|
|
|
else
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init (&node->bounds, 0.f, 0.f, 0.f, 0.f);
|
2020-11-11 06:36:04 +00:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_stroke_node_get_child:
|
|
|
|
* @node: (type GskStrokeNode): a stroke #GskRenderNode
|
|
|
|
*
|
|
|
|
* Gets the child node that is getting drawn by the given @node.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): The child that is getting drawn
|
|
|
|
*
|
|
|
|
* Since: 4.14
|
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_stroke_node_get_child (const GskRenderNode *node)
|
|
|
|
{
|
|
|
|
const GskStrokeNode *self = (const GskStrokeNode *) node;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_STROKE_NODE), NULL);
|
|
|
|
|
|
|
|
return self->child;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_stroke_node_get_path:
|
|
|
|
* @node: (type GskStrokeNode): a stroke #GskRenderNode
|
|
|
|
*
|
|
|
|
* Retrieves the path that will be stroked with the contents of
|
|
|
|
* the @node.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): a #GskPath
|
|
|
|
*
|
|
|
|
* Since: 4.14
|
|
|
|
*/
|
|
|
|
GskPath *
|
|
|
|
gsk_stroke_node_get_path (const GskRenderNode *node)
|
|
|
|
{
|
|
|
|
const GskStrokeNode *self = (const GskStrokeNode *) node;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_STROKE_NODE), NULL);
|
|
|
|
|
|
|
|
return self->path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_stroke_node_get_stroke:
|
|
|
|
* @node: (type GskStrokeNode): a stroke #GskRenderNode
|
|
|
|
*
|
|
|
|
* Retrieves the stroke attributes used in this @node.
|
|
|
|
*
|
|
|
|
* Returns: a #GskStroke
|
|
|
|
*
|
|
|
|
* Since: 4.14
|
|
|
|
*/
|
|
|
|
const GskStroke *
|
|
|
|
gsk_stroke_node_get_stroke (const GskRenderNode *node)
|
|
|
|
{
|
|
|
|
const GskStrokeNode *self = (const GskStrokeNode *) node;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_STROKE_NODE), NULL);
|
|
|
|
|
|
|
|
return &self->stroke;
|
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_SHADOW_NODE */
|
2016-12-18 23:45:35 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskShadowNode:
|
|
|
|
*
|
|
|
|
* A render node drawing one or more shadows behind its single child node.
|
|
|
|
*/
|
2016-12-18 23:45:35 +00:00
|
|
|
struct _GskShadowNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GskRenderNode *child;
|
|
|
|
|
|
|
|
gsize n_shadows;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskShadow *shadows;
|
2016-12-18 23:45:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_shadow_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskShadowNode *self = (GskShadowNode *) node;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_SHADOW_NODE));
|
2016-12-18 23:45:35 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (self->child);
|
2020-04-07 22:33:54 +00:00
|
|
|
g_free (self->shadows);
|
|
|
|
|
|
|
|
parent_class->finalize (node);
|
2016-12-18 23:45:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_shadow_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskShadowNode *self = (GskShadowNode *) node;
|
|
|
|
gsize i;
|
|
|
|
|
2023-05-05 02:53:08 +00:00
|
|
|
cairo_save (cr);
|
|
|
|
/* clip so the blur area stays small */
|
|
|
|
gsk_cairo_rectangle (cr, &node->bounds);
|
|
|
|
cairo_clip (cr);
|
|
|
|
|
2016-12-18 23:45:35 +00:00
|
|
|
for (i = 0; i < self->n_shadows; i++)
|
|
|
|
{
|
|
|
|
GskShadow *shadow = &self->shadows[i];
|
2023-09-18 05:48:10 +00:00
|
|
|
cairo_pattern_t *pattern;
|
2016-12-18 23:45:35 +00:00
|
|
|
|
|
|
|
/* We don't need to draw invisible shadows */
|
|
|
|
if (gdk_rgba_is_clear (&shadow->color))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
cr = gsk_cairo_blur_start_drawing (cr, shadow->radius, GSK_BLUR_X | GSK_BLUR_Y);
|
|
|
|
|
2023-09-18 05:48:10 +00:00
|
|
|
cairo_save (cr);
|
2016-12-18 23:45:35 +00:00
|
|
|
cairo_translate (cr, shadow->dx, shadow->dy);
|
2023-09-18 05:48:10 +00:00
|
|
|
cairo_push_group (cr);
|
|
|
|
gsk_render_node_draw (self->child, cr);
|
|
|
|
pattern = cairo_pop_group (cr);
|
|
|
|
gdk_cairo_set_source_rgba (cr, &shadow->color);
|
2016-12-18 23:45:35 +00:00
|
|
|
cairo_mask (cr, pattern);
|
2023-09-18 05:48:10 +00:00
|
|
|
cairo_restore (cr);
|
2016-12-18 23:45:35 +00:00
|
|
|
|
|
|
|
cr = gsk_cairo_blur_finish_drawing (cr, shadow->radius, &shadow->color, GSK_BLUR_X | GSK_BLUR_Y);
|
|
|
|
cairo_restore (cr);
|
|
|
|
}
|
|
|
|
|
2023-09-18 05:48:10 +00:00
|
|
|
gsk_render_node_draw (self->child, cr);
|
2016-12-18 23:45:35 +00:00
|
|
|
|
2023-09-18 05:48:10 +00:00
|
|
|
cairo_restore (cr);
|
2016-12-18 23:45:35 +00:00
|
|
|
}
|
|
|
|
|
2018-03-27 22:34:23 +00:00
|
|
|
static void
|
|
|
|
gsk_shadow_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2018-03-27 22:34:23 +00:00
|
|
|
{
|
|
|
|
GskShadowNode *self1 = (GskShadowNode *) node1;
|
|
|
|
GskShadowNode *self2 = (GskShadowNode *) node2;
|
|
|
|
int top = 0, right = 0, bottom = 0, left = 0;
|
|
|
|
cairo_region_t *sub;
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
gsize i, n;
|
|
|
|
|
|
|
|
if (self1->n_shadows != self2->n_shadows)
|
|
|
|
{
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2018-03-27 22:34:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < self1->n_shadows; i++)
|
|
|
|
{
|
|
|
|
GskShadow *shadow1 = &self1->shadows[i];
|
|
|
|
GskShadow *shadow2 = &self2->shadows[i];
|
|
|
|
float clip_radius;
|
|
|
|
|
|
|
|
if (!gdk_rgba_equal (&shadow1->color, &shadow2->color) ||
|
|
|
|
shadow1->dx != shadow2->dx ||
|
|
|
|
shadow1->dy != shadow2->dy ||
|
|
|
|
shadow1->radius != shadow2->radius)
|
|
|
|
{
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2018-03-27 22:34:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-04 09:24:35 +00:00
|
|
|
clip_radius = gsk_cairo_blur_compute_pixels (shadow1->radius / 2.0);
|
2018-03-27 22:34:23 +00:00
|
|
|
top = MAX (top, ceil (clip_radius - shadow1->dy));
|
|
|
|
right = MAX (right, ceil (clip_radius + shadow1->dx));
|
|
|
|
bottom = MAX (bottom, ceil (clip_radius + shadow1->dy));
|
|
|
|
left = MAX (left, ceil (clip_radius - shadow1->dx));
|
|
|
|
}
|
|
|
|
|
|
|
|
sub = cairo_region_create ();
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_data_diff (self1->child, self2->child, &(GskDiffData) { sub, data->offload });
|
2018-03-27 22:34:23 +00:00
|
|
|
|
|
|
|
n = cairo_region_num_rectangles (sub);
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
cairo_region_get_rectangle (sub, i, &rect);
|
|
|
|
rect.x -= left;
|
|
|
|
rect.y -= top;
|
|
|
|
rect.width += left + right;
|
|
|
|
rect.height += top + bottom;
|
2023-10-31 23:07:23 +00:00
|
|
|
cairo_region_union_rectangle (data->region, &rect);
|
2018-03-27 22:34:23 +00:00
|
|
|
}
|
|
|
|
cairo_region_destroy (sub);
|
|
|
|
}
|
|
|
|
|
2016-12-18 23:45:35 +00:00
|
|
|
static void
|
2016-12-21 10:21:38 +00:00
|
|
|
gsk_shadow_node_get_bounds (GskShadowNode *self,
|
2016-12-18 23:45:35 +00:00
|
|
|
graphene_rect_t *bounds)
|
|
|
|
{
|
|
|
|
float top = 0, right = 0, bottom = 0, left = 0;
|
|
|
|
gsize i;
|
|
|
|
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (bounds, &self->child->bounds);
|
2016-12-18 23:45:35 +00:00
|
|
|
|
|
|
|
for (i = 0; i < self->n_shadows; i++)
|
|
|
|
{
|
2021-08-04 09:24:35 +00:00
|
|
|
float clip_radius = gsk_cairo_blur_compute_pixels (self->shadows[i].radius / 2.0);
|
2016-12-18 23:45:35 +00:00
|
|
|
top = MAX (top, clip_radius - self->shadows[i].dy);
|
|
|
|
right = MAX (right, clip_radius + self->shadows[i].dx);
|
|
|
|
bottom = MAX (bottom, clip_radius + self->shadows[i].dy);
|
|
|
|
left = MAX (left, clip_radius - self->shadows[i].dx);
|
|
|
|
}
|
|
|
|
|
|
|
|
bounds->origin.x -= left;
|
|
|
|
bounds->origin.y -= top;
|
|
|
|
bounds->size.width += left + right;
|
|
|
|
bounds->size.height += top + bottom;
|
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_shadow_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_SHADOW_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_shadow_node_finalize;
|
|
|
|
node_class->draw = gsk_shadow_node_draw;
|
|
|
|
node_class->diff = gsk_shadow_node_diff;
|
|
|
|
}
|
|
|
|
|
2016-12-18 23:45:35 +00:00
|
|
|
/**
|
2020-06-27 09:22:54 +00:00
|
|
|
* gsk_shadow_node_new:
|
2016-12-18 23:45:35 +00:00
|
|
|
* @child: The node to draw
|
|
|
|
* @shadows: (array length=n_shadows): The shadows to apply
|
|
|
|
* @n_shadows: number of entries in the @shadows array
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that will draw a @child with the given
|
2016-12-18 23:45:35 +00:00
|
|
|
* @shadows below it.
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer full) (type GskShadowNode): A new `GskRenderNode`
|
2016-12-18 23:45:35 +00:00
|
|
|
*/
|
|
|
|
GskRenderNode *
|
2020-04-07 22:33:54 +00:00
|
|
|
gsk_shadow_node_new (GskRenderNode *child,
|
|
|
|
const GskShadow *shadows,
|
|
|
|
gsize n_shadows)
|
2016-12-18 23:45:35 +00:00
|
|
|
{
|
|
|
|
GskShadowNode *self;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNode *node;
|
2016-12-18 23:45:35 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL);
|
|
|
|
g_return_val_if_fail (shadows != NULL, NULL);
|
|
|
|
g_return_val_if_fail (n_shadows > 0, NULL);
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self = gsk_render_node_alloc (GSK_SHADOW_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2023-09-07 20:57:57 +00:00
|
|
|
node->offscreen_for_opacity = TRUE;
|
2016-12-18 23:45:35 +00:00
|
|
|
|
|
|
|
self->child = gsk_render_node_ref (child);
|
|
|
|
self->n_shadows = n_shadows;
|
2020-04-07 22:33:54 +00:00
|
|
|
self->shadows = g_malloc_n (n_shadows, sizeof (GskShadow));
|
|
|
|
memcpy (self->shadows, shadows, n_shadows * sizeof (GskShadow));
|
2016-12-18 23:45:35 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
gsk_shadow_node_get_bounds (self, &node->bounds);
|
2016-12-21 10:21:38 +00:00
|
|
|
|
2023-06-15 18:27:13 +00:00
|
|
|
node->preferred_depth = gsk_render_node_get_preferred_depth (child);
|
2021-10-01 20:23:12 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return node;
|
2016-12-18 23:45:35 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_shadow_node_get_child:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskShadowNode): a shadow `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Retrieves the child `GskRenderNode` of the shadow @node.
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer none): the child render node
|
|
|
|
*/
|
2016-12-18 23:45:35 +00:00
|
|
|
GskRenderNode *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_shadow_node_get_child (const GskRenderNode *node)
|
2016-12-18 23:45:35 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskShadowNode *self = (const GskShadowNode *) node;
|
2016-12-18 23:45:35 +00:00
|
|
|
|
|
|
|
return self->child;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_shadow_node_get_shadow:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskShadowNode): a shadow `GskRenderNode`
|
2020-05-11 16:47:20 +00:00
|
|
|
* @i: the given index
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the shadow data at the given index @i.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the shadow data
|
|
|
|
*/
|
2016-12-18 23:45:35 +00:00
|
|
|
const GskShadow *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_shadow_node_get_shadow (const GskRenderNode *node,
|
|
|
|
gsize i)
|
2016-12-18 23:45:35 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskShadowNode *self = (const GskShadowNode *) node;
|
2016-12-18 23:45:35 +00:00
|
|
|
|
|
|
|
return &self->shadows[i];
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_shadow_node_get_n_shadows:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskShadowNode): a shadow `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the number of shadows in the @node.
|
|
|
|
*
|
|
|
|
* Returns: the number of shadows.
|
|
|
|
*/
|
2016-12-18 23:45:35 +00:00
|
|
|
gsize
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_shadow_node_get_n_shadows (const GskRenderNode *node)
|
2016-12-18 23:45:35 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskShadowNode *self = (const GskShadowNode *) node;
|
2016-12-18 23:45:35 +00:00
|
|
|
|
|
|
|
return self->n_shadows;
|
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_BLEND_NODE */
|
2016-12-15 03:24:37 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskBlendNode:
|
|
|
|
*
|
|
|
|
* A render node applying a blending function between its two child nodes.
|
|
|
|
*/
|
2016-12-15 03:24:37 +00:00
|
|
|
struct _GskBlendNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GskRenderNode *bottom;
|
|
|
|
GskRenderNode *top;
|
|
|
|
GskBlendMode blend_mode;
|
|
|
|
};
|
|
|
|
|
|
|
|
static cairo_operator_t
|
|
|
|
gsk_blend_mode_to_cairo_operator (GskBlendMode blend_mode)
|
|
|
|
{
|
|
|
|
switch (blend_mode)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
case GSK_BLEND_MODE_DEFAULT:
|
|
|
|
return CAIRO_OPERATOR_OVER;
|
|
|
|
case GSK_BLEND_MODE_MULTIPLY:
|
|
|
|
return CAIRO_OPERATOR_MULTIPLY;
|
|
|
|
case GSK_BLEND_MODE_SCREEN:
|
|
|
|
return CAIRO_OPERATOR_SCREEN;
|
|
|
|
case GSK_BLEND_MODE_OVERLAY:
|
|
|
|
return CAIRO_OPERATOR_OVERLAY;
|
|
|
|
case GSK_BLEND_MODE_DARKEN:
|
|
|
|
return CAIRO_OPERATOR_DARKEN;
|
|
|
|
case GSK_BLEND_MODE_LIGHTEN:
|
|
|
|
return CAIRO_OPERATOR_LIGHTEN;
|
|
|
|
case GSK_BLEND_MODE_COLOR_DODGE:
|
|
|
|
return CAIRO_OPERATOR_COLOR_DODGE;
|
|
|
|
case GSK_BLEND_MODE_COLOR_BURN:
|
|
|
|
return CAIRO_OPERATOR_COLOR_BURN;
|
|
|
|
case GSK_BLEND_MODE_HARD_LIGHT:
|
|
|
|
return CAIRO_OPERATOR_HARD_LIGHT;
|
|
|
|
case GSK_BLEND_MODE_SOFT_LIGHT:
|
|
|
|
return CAIRO_OPERATOR_SOFT_LIGHT;
|
|
|
|
case GSK_BLEND_MODE_DIFFERENCE:
|
|
|
|
return CAIRO_OPERATOR_DIFFERENCE;
|
|
|
|
case GSK_BLEND_MODE_EXCLUSION:
|
|
|
|
return CAIRO_OPERATOR_EXCLUSION;
|
|
|
|
case GSK_BLEND_MODE_COLOR:
|
|
|
|
return CAIRO_OPERATOR_HSL_COLOR;
|
|
|
|
case GSK_BLEND_MODE_HUE:
|
|
|
|
return CAIRO_OPERATOR_HSL_HUE;
|
|
|
|
case GSK_BLEND_MODE_SATURATION:
|
|
|
|
return CAIRO_OPERATOR_HSL_SATURATION;
|
|
|
|
case GSK_BLEND_MODE_LUMINOSITY:
|
|
|
|
return CAIRO_OPERATOR_HSL_LUMINOSITY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_blend_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskBlendNode *self = (GskBlendNode *) node;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_BLEND_NODE));
|
2016-12-15 03:24:37 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (self->bottom);
|
|
|
|
gsk_render_node_unref (self->top);
|
2020-04-07 22:33:54 +00:00
|
|
|
|
|
|
|
parent_class->finalize (node);
|
2016-12-15 03:24:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_blend_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskBlendNode *self = (GskBlendNode *) node;
|
|
|
|
|
|
|
|
cairo_push_group (cr);
|
|
|
|
gsk_render_node_draw (self->bottom, cr);
|
|
|
|
|
|
|
|
cairo_push_group (cr);
|
|
|
|
gsk_render_node_draw (self->top, cr);
|
|
|
|
|
|
|
|
cairo_pop_group_to_source (cr);
|
|
|
|
cairo_set_operator (cr, gsk_blend_mode_to_cairo_operator (self->blend_mode));
|
|
|
|
cairo_paint (cr);
|
|
|
|
|
|
|
|
cairo_pop_group_to_source (cr); /* resets operator */
|
|
|
|
cairo_paint (cr);
|
|
|
|
}
|
|
|
|
|
2018-03-27 22:34:23 +00:00
|
|
|
static void
|
|
|
|
gsk_blend_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2018-03-27 22:34:23 +00:00
|
|
|
{
|
|
|
|
GskBlendNode *self1 = (GskBlendNode *) node1;
|
|
|
|
GskBlendNode *self2 = (GskBlendNode *) node2;
|
|
|
|
|
|
|
|
if (self1->blend_mode == self2->blend_mode)
|
|
|
|
{
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_data_diff (self1->top, self2->top, data);
|
|
|
|
gsk_render_node_data_diff (self1->bottom, self2->bottom, data);
|
2018-03-27 22:34:23 +00:00
|
|
|
}
|
2018-07-08 10:50:21 +00:00
|
|
|
else
|
|
|
|
{
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2018-07-08 10:50:21 +00:00
|
|
|
}
|
2018-03-27 22:34:23 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_blend_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_BLEND_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_blend_node_finalize;
|
|
|
|
node_class->draw = gsk_blend_node_draw;
|
|
|
|
node_class->diff = gsk_blend_node_diff;
|
|
|
|
}
|
|
|
|
|
2016-12-15 03:24:37 +00:00
|
|
|
/**
|
2020-06-27 09:22:54 +00:00
|
|
|
* gsk_blend_node_new:
|
2016-12-15 03:24:37 +00:00
|
|
|
* @bottom: The bottom node to be drawn
|
|
|
|
* @top: The node to be blended onto the @bottom node
|
|
|
|
* @blend_mode: The blend mode to use
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that will use @blend_mode to blend the @top
|
2016-12-15 03:24:37 +00:00
|
|
|
* node onto the @bottom node.
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer full) (type GskBlendNode): A new `GskRenderNode`
|
2016-12-15 03:24:37 +00:00
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_blend_node_new (GskRenderNode *bottom,
|
|
|
|
GskRenderNode *top,
|
|
|
|
GskBlendMode blend_mode)
|
|
|
|
{
|
|
|
|
GskBlendNode *self;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNode *node;
|
2016-12-15 03:24:37 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (bottom), NULL);
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (top), NULL);
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self = gsk_render_node_alloc (GSK_BLEND_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = TRUE;
|
2016-12-15 03:24:37 +00:00
|
|
|
|
|
|
|
self->bottom = gsk_render_node_ref (bottom);
|
|
|
|
self->top = gsk_render_node_ref (top);
|
|
|
|
self->blend_mode = blend_mode;
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
graphene_rect_union (&bottom->bounds, &top->bounds, &node->bounds);
|
2016-12-21 10:21:38 +00:00
|
|
|
|
2023-06-15 18:27:13 +00:00
|
|
|
node->preferred_depth = gdk_memory_depth_merge (gsk_render_node_get_preferred_depth (bottom),
|
|
|
|
gsk_render_node_get_preferred_depth (top));
|
2021-10-01 20:23:12 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return node;
|
2016-12-15 03:24:37 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_blend_node_get_bottom_child:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskBlendNode): a blending `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Retrieves the bottom `GskRenderNode` child of the @node.
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer none): the bottom child node
|
|
|
|
*/
|
2016-12-15 03:24:37 +00:00
|
|
|
GskRenderNode *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_blend_node_get_bottom_child (const GskRenderNode *node)
|
2016-12-15 03:24:37 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskBlendNode *self = (const GskBlendNode *) node;
|
2016-12-15 03:24:37 +00:00
|
|
|
|
|
|
|
return self->bottom;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_blend_node_get_top_child:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskBlendNode): a blending `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Retrieves the top `GskRenderNode` child of the @node.
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer none): the top child node
|
|
|
|
*/
|
2016-12-15 03:24:37 +00:00
|
|
|
GskRenderNode *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_blend_node_get_top_child (const GskRenderNode *node)
|
2016-12-15 03:24:37 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskBlendNode *self = (const GskBlendNode *) node;
|
2016-12-15 03:24:37 +00:00
|
|
|
|
|
|
|
return self->top;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_blend_node_get_blend_mode:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskBlendNode): a blending `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the blend mode used by @node.
|
|
|
|
*
|
|
|
|
* Returns: the blend mode
|
|
|
|
*/
|
2016-12-15 03:24:37 +00:00
|
|
|
GskBlendMode
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_blend_node_get_blend_mode (const GskRenderNode *node)
|
2016-12-15 03:24:37 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskBlendNode *self = (const GskBlendNode *) node;
|
2016-12-15 03:24:37 +00:00
|
|
|
|
|
|
|
return self->blend_mode;
|
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_CROSS_FADE_NODE */
|
2016-12-17 06:44:10 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskCrossFadeNode:
|
|
|
|
*
|
|
|
|
* A render node cross fading between two child nodes.
|
|
|
|
*/
|
2016-12-17 06:44:10 +00:00
|
|
|
struct _GskCrossFadeNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GskRenderNode *start;
|
|
|
|
GskRenderNode *end;
|
2019-12-18 08:48:25 +00:00
|
|
|
float progress;
|
2016-12-17 06:44:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_cross_fade_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskCrossFadeNode *self = (GskCrossFadeNode *) node;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_CROSS_FADE_NODE));
|
2016-12-17 06:44:10 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (self->start);
|
|
|
|
gsk_render_node_unref (self->end);
|
2020-04-07 22:33:54 +00:00
|
|
|
|
|
|
|
parent_class->finalize (node);
|
2016-12-17 06:44:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_cross_fade_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskCrossFadeNode *self = (GskCrossFadeNode *) node;
|
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA);
|
2016-12-17 06:44:10 +00:00
|
|
|
gsk_render_node_draw (self->start, cr);
|
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA);
|
2016-12-17 06:44:10 +00:00
|
|
|
gsk_render_node_draw (self->end, cr);
|
|
|
|
|
|
|
|
cairo_pop_group_to_source (cr);
|
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
|
|
|
cairo_paint_with_alpha (cr, self->progress);
|
|
|
|
|
|
|
|
cairo_pop_group_to_source (cr); /* resets operator */
|
|
|
|
cairo_paint (cr);
|
|
|
|
}
|
|
|
|
|
2018-03-27 22:34:23 +00:00
|
|
|
static void
|
|
|
|
gsk_cross_fade_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2018-03-27 22:34:23 +00:00
|
|
|
{
|
|
|
|
GskCrossFadeNode *self1 = (GskCrossFadeNode *) node1;
|
|
|
|
GskCrossFadeNode *self2 = (GskCrossFadeNode *) node2;
|
|
|
|
|
|
|
|
if (self1->progress == self2->progress)
|
|
|
|
{
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_data_diff (self1->start, self2->start, data);
|
|
|
|
gsk_render_node_data_diff (self1->end, self2->end, data);
|
2018-04-05 15:32:57 +00:00
|
|
|
return;
|
2018-03-27 22:34:23 +00:00
|
|
|
}
|
|
|
|
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2018-03-27 22:34:23 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_cross_fade_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_CROSS_FADE_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_cross_fade_node_finalize;
|
|
|
|
node_class->draw = gsk_cross_fade_node_draw;
|
|
|
|
node_class->diff = gsk_cross_fade_node_diff;
|
|
|
|
}
|
|
|
|
|
2016-12-17 06:44:10 +00:00
|
|
|
/**
|
2020-06-27 09:22:54 +00:00
|
|
|
* gsk_cross_fade_node_new:
|
2016-12-17 06:44:10 +00:00
|
|
|
* @start: The start node to be drawn
|
|
|
|
* @end: The node to be cross_fadeed onto the @start node
|
|
|
|
* @progress: How far the fade has progressed from start to end. The value will
|
|
|
|
* be clamped to the range [0 ... 1]
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that will do a cross-fade between @start and @end.
|
2016-12-17 06:44:10 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer full) (type GskCrossFadeNode): A new `GskRenderNode`
|
2016-12-17 06:44:10 +00:00
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_cross_fade_node_new (GskRenderNode *start,
|
|
|
|
GskRenderNode *end,
|
2019-12-18 08:48:25 +00:00
|
|
|
float progress)
|
2016-12-17 06:44:10 +00:00
|
|
|
{
|
|
|
|
GskCrossFadeNode *self;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNode *node;
|
2016-12-17 06:44:10 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (start), NULL);
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (end), NULL);
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self = gsk_render_node_alloc (GSK_CROSS_FADE_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = TRUE;
|
2016-12-17 06:44:10 +00:00
|
|
|
|
|
|
|
self->start = gsk_render_node_ref (start);
|
|
|
|
self->end = gsk_render_node_ref (end);
|
|
|
|
self->progress = CLAMP (progress, 0.0, 1.0);
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
graphene_rect_union (&start->bounds, &end->bounds, &node->bounds);
|
2016-12-21 10:21:38 +00:00
|
|
|
|
2023-06-15 18:27:13 +00:00
|
|
|
node->preferred_depth = gdk_memory_depth_merge (gsk_render_node_get_preferred_depth (start),
|
|
|
|
gsk_render_node_get_preferred_depth (end));
|
2021-10-01 20:23:12 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return node;
|
2016-12-17 06:44:10 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_cross_fade_node_get_start_child:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskCrossFadeNode): a cross-fading `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Retrieves the child `GskRenderNode` at the beginning of the cross-fade.
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer none): a `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*/
|
2016-12-17 06:44:10 +00:00
|
|
|
GskRenderNode *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_cross_fade_node_get_start_child (const GskRenderNode *node)
|
2016-12-17 06:44:10 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskCrossFadeNode *self = (const GskCrossFadeNode *) node;
|
2016-12-17 06:44:10 +00:00
|
|
|
|
|
|
|
return self->start;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_cross_fade_node_get_end_child:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskCrossFadeNode): a cross-fading `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Retrieves the child `GskRenderNode` at the end of the cross-fade.
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer none): a `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*/
|
2016-12-17 06:44:10 +00:00
|
|
|
GskRenderNode *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_cross_fade_node_get_end_child (const GskRenderNode *node)
|
2016-12-17 06:44:10 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskCrossFadeNode *self = (const GskCrossFadeNode *) node;
|
2016-12-17 06:44:10 +00:00
|
|
|
|
|
|
|
return self->end;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_cross_fade_node_get_progress:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskCrossFadeNode): a cross-fading `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the progress value of the cross fade.
|
|
|
|
*
|
|
|
|
* Returns: the progress value, between 0 and 1
|
|
|
|
*/
|
2019-12-18 08:48:25 +00:00
|
|
|
float
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_cross_fade_node_get_progress (const GskRenderNode *node)
|
2016-12-17 06:44:10 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskCrossFadeNode *self = (const GskCrossFadeNode *) node;
|
2016-12-17 06:44:10 +00:00
|
|
|
|
|
|
|
return self->progress;
|
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_TEXT_NODE */
|
2017-08-29 21:28:10 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskTextNode:
|
|
|
|
*
|
|
|
|
* A render node drawing a set of glyphs.
|
|
|
|
*/
|
2017-08-29 21:28:10 +00:00
|
|
|
struct _GskTextNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
PangoFont *font;
|
2021-09-04 18:52:15 +00:00
|
|
|
gboolean has_color_glyphs;
|
2017-09-01 20:58:42 +00:00
|
|
|
|
2017-08-29 21:28:10 +00:00
|
|
|
GdkRGBA color;
|
2019-05-19 02:08:29 +00:00
|
|
|
graphene_point_t offset;
|
2017-10-27 21:13:40 +00:00
|
|
|
|
|
|
|
guint num_glyphs;
|
2020-04-07 22:33:54 +00:00
|
|
|
PangoGlyphInfo *glyphs;
|
2017-08-29 21:28:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_text_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskTextNode *self = (GskTextNode *) node;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_TEXT_NODE));
|
2017-08-29 21:28:10 +00:00
|
|
|
|
|
|
|
g_object_unref (self->font);
|
2020-04-07 22:33:54 +00:00
|
|
|
g_free (self->glyphs);
|
|
|
|
|
|
|
|
parent_class->finalize (node);
|
2017-08-29 21:28:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_text_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskTextNode *self = (GskTextNode *) node;
|
2018-01-05 23:55:23 +00:00
|
|
|
PangoGlyphString glyphs;
|
|
|
|
|
|
|
|
glyphs.num_glyphs = self->num_glyphs;
|
|
|
|
glyphs.glyphs = self->glyphs;
|
|
|
|
glyphs.log_clusters = NULL;
|
2017-08-29 21:28:10 +00:00
|
|
|
|
2017-09-01 20:58:42 +00:00
|
|
|
cairo_save (cr);
|
2017-08-29 21:28:10 +00:00
|
|
|
|
|
|
|
gdk_cairo_set_source_rgba (cr, &self->color);
|
2019-05-19 02:08:29 +00:00
|
|
|
cairo_translate (cr, self->offset.x, self->offset.y);
|
2018-01-05 23:55:23 +00:00
|
|
|
pango_cairo_show_glyph_string (cr, self->font, &glyphs);
|
2017-08-29 21:28:10 +00:00
|
|
|
|
|
|
|
cairo_restore (cr);
|
|
|
|
}
|
|
|
|
|
2018-03-27 22:34:23 +00:00
|
|
|
static void
|
|
|
|
gsk_text_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2018-03-27 22:34:23 +00:00
|
|
|
{
|
|
|
|
GskTextNode *self1 = (GskTextNode *) node1;
|
|
|
|
GskTextNode *self2 = (GskTextNode *) node2;
|
|
|
|
|
|
|
|
if (self1->font == self2->font &&
|
|
|
|
gdk_rgba_equal (&self1->color, &self2->color) &&
|
2019-05-19 02:08:29 +00:00
|
|
|
graphene_point_equal (&self1->offset, &self2->offset) &&
|
2018-03-27 22:34:23 +00:00
|
|
|
self1->num_glyphs == self2->num_glyphs)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < self1->num_glyphs; i++)
|
|
|
|
{
|
|
|
|
PangoGlyphInfo *info1 = &self1->glyphs[i];
|
|
|
|
PangoGlyphInfo *info2 = &self2->glyphs[i];
|
|
|
|
|
|
|
|
if (info1->glyph == info2->glyph &&
|
|
|
|
info1->geometry.width == info2->geometry.width &&
|
|
|
|
info1->geometry.x_offset == info2->geometry.x_offset &&
|
|
|
|
info1->geometry.y_offset == info2->geometry.y_offset &&
|
2021-07-31 15:41:08 +00:00
|
|
|
info1->attr.is_cluster_start == info2->attr.is_cluster_start &&
|
2021-09-04 13:39:29 +00:00
|
|
|
info1->attr.is_color == info2->attr.is_color)
|
2018-03-27 22:34:23 +00:00
|
|
|
continue;
|
|
|
|
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2018-03-27 22:34:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2018-03-27 22:34:23 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_text_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_TEXT_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_text_node_finalize;
|
|
|
|
node_class->draw = gsk_text_node_draw;
|
|
|
|
node_class->diff = gsk_text_node_diff;
|
|
|
|
}
|
|
|
|
|
2021-09-04 18:52:15 +00:00
|
|
|
/**
|
|
|
|
* gsk_text_node_new:
|
|
|
|
* @font: the `PangoFont` containing the glyphs
|
|
|
|
* @glyphs: the `PangoGlyphString` to render
|
|
|
|
* @color: the foreground color to render with
|
|
|
|
* @offset: offset of the baseline
|
|
|
|
*
|
|
|
|
* Creates a render node that renders the given glyphs.
|
|
|
|
*
|
|
|
|
* Note that @color may not be used if the font contains
|
|
|
|
* color glyphs.
|
|
|
|
*
|
|
|
|
* Returns: (nullable) (transfer full) (type GskTextNode): a new `GskRenderNode`
|
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_text_node_new (PangoFont *font,
|
|
|
|
PangoGlyphString *glyphs,
|
|
|
|
const GdkRGBA *color,
|
|
|
|
const graphene_point_t *offset)
|
2017-08-29 21:28:10 +00:00
|
|
|
{
|
|
|
|
GskTextNode *self;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNode *node;
|
2017-08-29 21:28:10 +00:00
|
|
|
PangoRectangle ink_rect;
|
2021-07-31 19:22:14 +00:00
|
|
|
PangoGlyphInfo *glyph_infos;
|
|
|
|
int n;
|
2017-08-29 21:28:10 +00:00
|
|
|
|
2017-09-03 23:35:02 +00:00
|
|
|
pango_glyph_string_extents (glyphs, font, &ink_rect, NULL);
|
|
|
|
pango_extents_to_pixels (&ink_rect, NULL);
|
|
|
|
|
|
|
|
/* Don't create nodes with empty bounds */
|
|
|
|
if (ink_rect.width == 0 || ink_rect.height == 0)
|
|
|
|
return NULL;
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self = gsk_render_node_alloc (GSK_TEXT_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = FALSE;
|
2017-08-29 21:28:10 +00:00
|
|
|
|
|
|
|
self->font = g_object_ref (font);
|
|
|
|
self->color = *color;
|
2019-05-19 02:08:29 +00:00
|
|
|
self->offset = *offset;
|
2021-07-31 19:22:14 +00:00
|
|
|
self->has_color_glyphs = FALSE;
|
2021-03-29 00:22:24 +00:00
|
|
|
|
2021-07-31 19:22:14 +00:00
|
|
|
glyph_infos = g_malloc_n (glyphs->num_glyphs, sizeof (PangoGlyphInfo));
|
|
|
|
|
|
|
|
n = 0;
|
2021-03-29 00:22:24 +00:00
|
|
|
for (int i = 0; i < glyphs->num_glyphs; i++)
|
|
|
|
{
|
2021-07-31 19:22:14 +00:00
|
|
|
/* skip empty glyphs */
|
|
|
|
if (glyphs->glyphs[i].glyph == PANGO_GLYPH_EMPTY)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
glyph_infos[n] = glyphs->glyphs[i];
|
|
|
|
|
2021-09-01 05:38:44 +00:00
|
|
|
if (glyphs->glyphs[i].attr.is_color)
|
|
|
|
self->has_color_glyphs = TRUE;
|
2021-07-31 19:22:14 +00:00
|
|
|
|
|
|
|
n++;
|
2021-03-29 00:22:24 +00:00
|
|
|
}
|
2017-08-29 21:28:10 +00:00
|
|
|
|
2021-07-31 19:22:14 +00:00
|
|
|
self->glyphs = glyph_infos;
|
|
|
|
self->num_glyphs = n;
|
2021-07-31 15:41:08 +00:00
|
|
|
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init (&node->bounds,
|
|
|
|
offset->x + ink_rect.x - 1,
|
|
|
|
offset->y + ink_rect.y - 1,
|
|
|
|
ink_rect.width + 2,
|
|
|
|
ink_rect.height + 2);
|
2017-08-29 21:28:10 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return node;
|
2017-08-29 21:28:10 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_text_node_get_color:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskTextNode): a text `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the color used by the text @node.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the text color
|
|
|
|
*/
|
2017-09-01 20:58:42 +00:00
|
|
|
const GdkRGBA *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_text_node_get_color (const GskRenderNode *node)
|
2017-09-01 20:58:42 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskTextNode *self = (const GskTextNode *) node;
|
2017-09-01 20:58:42 +00:00
|
|
|
|
|
|
|
return &self->color;
|
|
|
|
}
|
|
|
|
|
2019-05-30 15:05:02 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_text_node_get_font:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskTextNode): The `GskRenderNode`
|
2019-05-30 15:05:02 +00:00
|
|
|
*
|
2020-04-07 22:33:54 +00:00
|
|
|
* Returns the font used by the text @node.
|
2019-05-30 15:05:02 +00:00
|
|
|
*
|
2020-04-07 22:33:54 +00:00
|
|
|
* Returns: (transfer none): the font
|
2019-05-30 15:05:02 +00:00
|
|
|
*/
|
2019-05-19 18:20:09 +00:00
|
|
|
PangoFont *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_text_node_get_font (const GskRenderNode *node)
|
2017-09-01 20:58:42 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskTextNode *self = (const GskTextNode *) node;
|
2017-09-01 20:58:42 +00:00
|
|
|
|
|
|
|
return self->font;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_text_node_has_color_glyphs:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskTextNode): a text `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Checks whether the text @node has color glyphs.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the text node has color glyphs
|
2021-11-13 16:33:15 +00:00
|
|
|
*
|
|
|
|
* Since: 4.2
|
2020-04-07 22:33:54 +00:00
|
|
|
*/
|
2019-10-10 11:31:08 +00:00
|
|
|
gboolean
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_text_node_has_color_glyphs (const GskRenderNode *node)
|
2019-10-10 11:31:08 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskTextNode *self = (const GskTextNode *) node;
|
2019-10-10 11:31:08 +00:00
|
|
|
|
|
|
|
return self->has_color_glyphs;
|
|
|
|
}
|
|
|
|
|
2020-06-06 00:19:45 +00:00
|
|
|
/**
|
|
|
|
* gsk_text_node_get_num_glyphs:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskTextNode): a text `GskRenderNode`
|
2020-06-06 00:19:45 +00:00
|
|
|
*
|
|
|
|
* Retrieves the number of glyphs in the text node.
|
|
|
|
*
|
|
|
|
* Returns: the number of glyphs
|
|
|
|
*/
|
2017-10-27 21:13:40 +00:00
|
|
|
guint
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_text_node_get_num_glyphs (const GskRenderNode *node)
|
2017-10-27 21:13:40 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskTextNode *self = (const GskTextNode *) node;
|
2017-10-27 21:13:40 +00:00
|
|
|
|
|
|
|
return self->num_glyphs;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
2020-11-16 23:59:36 +00:00
|
|
|
* gsk_text_node_get_glyphs:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskTextNode): a text `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
* @n_glyphs: (out) (optional): the number of glyphs returned
|
|
|
|
*
|
|
|
|
* Retrieves the glyph information in the @node.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none) (array length=n_glyphs): the glyph information
|
|
|
|
*/
|
2017-10-27 21:13:40 +00:00
|
|
|
const PangoGlyphInfo *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_text_node_get_glyphs (const GskRenderNode *node,
|
|
|
|
guint *n_glyphs)
|
2017-09-01 20:58:42 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskTextNode *self = (const GskTextNode *) node;
|
2017-09-01 20:58:42 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
if (n_glyphs != NULL)
|
|
|
|
*n_glyphs = self->num_glyphs;
|
|
|
|
|
2017-09-01 20:58:42 +00:00
|
|
|
return self->glyphs;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_text_node_get_offset:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskTextNode): a text `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the offset applied to the text.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): a point with the horizontal and vertical offsets
|
|
|
|
*/
|
2019-05-19 02:08:29 +00:00
|
|
|
const graphene_point_t *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_text_node_get_offset (const GskRenderNode *node)
|
2017-09-01 20:58:42 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskTextNode *self = (const GskTextNode *) node;
|
2017-09-01 20:58:42 +00:00
|
|
|
|
2019-05-19 02:08:29 +00:00
|
|
|
return &self->offset;
|
2017-09-01 20:58:42 +00:00
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_BLUR_NODE */
|
2017-09-03 03:49:34 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskBlurNode:
|
|
|
|
*
|
|
|
|
* A render node applying a blur effect to its single child.
|
|
|
|
*/
|
2017-09-03 03:49:34 +00:00
|
|
|
struct _GskBlurNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GskRenderNode *child;
|
2019-12-18 08:48:25 +00:00
|
|
|
float radius;
|
2017-09-03 03:49:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_blur_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskBlurNode *self = (GskBlurNode *) node;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_BLUR_NODE));
|
2017-09-03 03:49:34 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (self->child);
|
2020-04-07 22:33:54 +00:00
|
|
|
|
|
|
|
parent_class->finalize (node);
|
2017-09-03 03:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
blur_once (cairo_surface_t *src,
|
|
|
|
cairo_surface_t *dest,
|
|
|
|
int radius,
|
|
|
|
guchar *div_kernel_size)
|
|
|
|
{
|
|
|
|
int width, height, src_rowstride, dest_rowstride, n_channels;
|
|
|
|
guchar *p_src, *p_dest, *c1, *c2;
|
2020-07-24 13:54:49 +00:00
|
|
|
int x, y, i, i1, i2, width_minus_1, height_minus_1, radius_plus_1;
|
|
|
|
int r, g, b, a;
|
2017-09-03 03:49:34 +00:00
|
|
|
guchar *p_dest_row, *p_dest_col;
|
|
|
|
|
|
|
|
width = cairo_image_surface_get_width (src);
|
|
|
|
height = cairo_image_surface_get_height (src);
|
|
|
|
n_channels = 4;
|
|
|
|
radius_plus_1 = radius + 1;
|
|
|
|
|
|
|
|
/* horizontal blur */
|
|
|
|
p_src = cairo_image_surface_get_data (src);
|
|
|
|
p_dest = cairo_image_surface_get_data (dest);
|
|
|
|
src_rowstride = cairo_image_surface_get_stride (src);
|
|
|
|
dest_rowstride = cairo_image_surface_get_stride (dest);
|
|
|
|
|
|
|
|
width_minus_1 = width - 1;
|
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
/* calc the initial sums of the kernel */
|
|
|
|
r = g = b = a = 0;
|
|
|
|
for (i = -radius; i <= radius; i++)
|
|
|
|
{
|
|
|
|
c1 = p_src + (CLAMP (i, 0, width_minus_1) * n_channels);
|
|
|
|
r += c1[0];
|
|
|
|
g += c1[1];
|
|
|
|
b += c1[2];
|
2019-05-20 01:24:24 +00:00
|
|
|
a += c1[3];
|
2017-09-03 03:49:34 +00:00
|
|
|
}
|
|
|
|
p_dest_row = p_dest;
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
/* set as the mean of the kernel */
|
|
|
|
p_dest_row[0] = div_kernel_size[r];
|
|
|
|
p_dest_row[1] = div_kernel_size[g];
|
|
|
|
p_dest_row[2] = div_kernel_size[b];
|
2019-05-20 01:24:24 +00:00
|
|
|
p_dest_row[3] = div_kernel_size[a];
|
2017-09-03 03:49:34 +00:00
|
|
|
p_dest_row += n_channels;
|
|
|
|
|
|
|
|
/* the pixel to add to the kernel */
|
|
|
|
i1 = x + radius_plus_1;
|
|
|
|
if (i1 > width_minus_1)
|
|
|
|
i1 = width_minus_1;
|
|
|
|
c1 = p_src + (i1 * n_channels);
|
|
|
|
|
|
|
|
/* the pixel to remove from the kernel */
|
|
|
|
i2 = x - radius;
|
|
|
|
if (i2 < 0)
|
|
|
|
i2 = 0;
|
|
|
|
c2 = p_src + (i2 * n_channels);
|
|
|
|
|
|
|
|
/* calc the new sums of the kernel */
|
|
|
|
r += c1[0] - c2[0];
|
|
|
|
g += c1[1] - c2[1];
|
|
|
|
b += c1[2] - c2[2];
|
2019-05-20 01:24:24 +00:00
|
|
|
a += c1[3] - c2[3];
|
2017-09-03 03:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p_src += src_rowstride;
|
|
|
|
p_dest += dest_rowstride;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vertical blur */
|
|
|
|
p_src = cairo_image_surface_get_data (dest);
|
|
|
|
p_dest = cairo_image_surface_get_data (src);
|
|
|
|
src_rowstride = cairo_image_surface_get_stride (dest);
|
|
|
|
dest_rowstride = cairo_image_surface_get_stride (src);
|
|
|
|
|
|
|
|
height_minus_1 = height - 1;
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
/* calc the initial sums of the kernel */
|
|
|
|
r = g = b = a = 0;
|
|
|
|
for (i = -radius; i <= radius; i++)
|
|
|
|
{
|
|
|
|
c1 = p_src + (CLAMP (i, 0, height_minus_1) * src_rowstride);
|
|
|
|
r += c1[0];
|
|
|
|
g += c1[1];
|
|
|
|
b += c1[2];
|
2019-05-20 01:24:24 +00:00
|
|
|
a += c1[3];
|
2017-09-03 03:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p_dest_col = p_dest;
|
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
/* set as the mean of the kernel */
|
|
|
|
|
|
|
|
p_dest_col[0] = div_kernel_size[r];
|
|
|
|
p_dest_col[1] = div_kernel_size[g];
|
|
|
|
p_dest_col[2] = div_kernel_size[b];
|
2019-05-20 01:24:24 +00:00
|
|
|
p_dest_col[3] = div_kernel_size[a];
|
2017-09-03 03:49:34 +00:00
|
|
|
p_dest_col += dest_rowstride;
|
|
|
|
|
|
|
|
/* the pixel to add to the kernel */
|
|
|
|
i1 = y + radius_plus_1;
|
|
|
|
if (i1 > height_minus_1)
|
|
|
|
i1 = height_minus_1;
|
|
|
|
c1 = p_src + (i1 * src_rowstride);
|
|
|
|
|
|
|
|
/* the pixel to remove from the kernel */
|
|
|
|
i2 = y - radius;
|
|
|
|
if (i2 < 0)
|
|
|
|
i2 = 0;
|
|
|
|
c2 = p_src + (i2 * src_rowstride);
|
|
|
|
/* calc the new sums of the kernel */
|
|
|
|
r += c1[0] - c2[0];
|
|
|
|
g += c1[1] - c2[1];
|
|
|
|
b += c1[2] - c2[2];
|
2019-05-20 01:24:24 +00:00
|
|
|
a += c1[3] - c2[3];
|
2017-09-03 03:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p_src += n_channels;
|
|
|
|
p_dest += n_channels;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
blur_image_surface (cairo_surface_t *surface, int radius, int iterations)
|
|
|
|
{
|
|
|
|
int kernel_size;
|
|
|
|
int i;
|
|
|
|
guchar *div_kernel_size;
|
|
|
|
cairo_surface_t *tmp;
|
|
|
|
int width, height;
|
|
|
|
|
2022-11-18 05:02:20 +00:00
|
|
|
g_assert (radius >= 0);
|
|
|
|
|
2017-09-03 03:49:34 +00:00
|
|
|
width = cairo_image_surface_get_width (surface);
|
|
|
|
height = cairo_image_surface_get_height (surface);
|
|
|
|
tmp = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
|
|
|
|
|
|
|
|
kernel_size = 2 * radius + 1;
|
|
|
|
div_kernel_size = g_new (guchar, 256 * kernel_size);
|
|
|
|
for (i = 0; i < 256 * kernel_size; i++)
|
|
|
|
div_kernel_size[i] = (guchar) (i / kernel_size);
|
|
|
|
|
|
|
|
while (iterations-- > 0)
|
|
|
|
blur_once (surface, tmp, radius, div_kernel_size);
|
|
|
|
|
|
|
|
g_free (div_kernel_size);
|
|
|
|
cairo_surface_destroy (tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_blur_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskBlurNode *self = (GskBlurNode *) node;
|
|
|
|
cairo_surface_t *surface;
|
2023-12-05 16:07:54 +00:00
|
|
|
cairo_t *cr2;
|
|
|
|
graphene_rect_t blur_bounds;
|
|
|
|
double clip_radius;
|
2017-09-03 03:49:34 +00:00
|
|
|
|
2023-12-05 16:07:54 +00:00
|
|
|
clip_radius = gsk_cairo_blur_compute_pixels (0.5 * self->radius);
|
2017-09-03 03:49:34 +00:00
|
|
|
|
2023-12-05 16:07:54 +00:00
|
|
|
/* We need to extend the clip by the blur radius
|
|
|
|
* so we can blur pixels in that region */
|
|
|
|
_graphene_rect_init_from_clip_extents (&blur_bounds, cr);
|
|
|
|
graphene_rect_inset (&blur_bounds, - clip_radius, - clip_radius);
|
|
|
|
if (!gsk_rect_intersection (&blur_bounds, &node->bounds, &blur_bounds))
|
|
|
|
return;
|
2017-09-03 03:49:34 +00:00
|
|
|
|
2023-12-05 16:07:54 +00:00
|
|
|
surface = cairo_surface_create_similar_image (cairo_get_target (cr),
|
|
|
|
CAIRO_FORMAT_ARGB32,
|
|
|
|
ceil (blur_bounds.size.width),
|
|
|
|
ceil (blur_bounds.size.height));
|
|
|
|
cairo_surface_set_device_offset (surface,
|
|
|
|
- blur_bounds.origin.x,
|
|
|
|
- blur_bounds.origin.y);
|
2017-09-03 03:49:34 +00:00
|
|
|
|
2023-12-05 16:07:54 +00:00
|
|
|
cr2 = cairo_create (surface);
|
|
|
|
gsk_render_node_draw (self->child, cr2);
|
|
|
|
cairo_destroy (cr2);
|
2017-09-03 03:49:34 +00:00
|
|
|
|
2023-12-05 16:07:54 +00:00
|
|
|
blur_image_surface (surface, (int) ceil (0.5 * self->radius), 3);
|
2017-09-03 03:49:34 +00:00
|
|
|
cairo_surface_mark_dirty (surface);
|
|
|
|
|
2023-12-05 16:07:54 +00:00
|
|
|
cairo_set_source_surface (cr, surface, 0, 0);
|
2020-02-12 15:21:38 +00:00
|
|
|
cairo_rectangle (cr,
|
|
|
|
node->bounds.origin.x, node->bounds.origin.y,
|
|
|
|
node->bounds.size.width, node->bounds.size.height);
|
|
|
|
cairo_fill (cr);
|
2017-09-03 03:49:34 +00:00
|
|
|
|
2023-12-05 16:07:54 +00:00
|
|
|
cairo_surface_destroy (surface);
|
2017-09-03 03:49:34 +00:00
|
|
|
}
|
|
|
|
|
2018-03-27 22:34:23 +00:00
|
|
|
static void
|
|
|
|
gsk_blur_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2018-03-27 22:34:23 +00:00
|
|
|
{
|
|
|
|
GskBlurNode *self1 = (GskBlurNode *) node1;
|
|
|
|
GskBlurNode *self2 = (GskBlurNode *) node2;
|
|
|
|
|
|
|
|
if (self1->radius == self2->radius)
|
|
|
|
{
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
cairo_region_t *sub;
|
|
|
|
int i, n, clip_radius;
|
|
|
|
|
2021-08-04 09:24:35 +00:00
|
|
|
clip_radius = ceil (gsk_cairo_blur_compute_pixels (self1->radius / 2.0));
|
2018-03-27 22:34:23 +00:00
|
|
|
sub = cairo_region_create ();
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_data_diff (self1->child, self2->child, &(GskDiffData) {sub, data->offload });
|
2018-03-27 22:34:23 +00:00
|
|
|
|
|
|
|
n = cairo_region_num_rectangles (sub);
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
cairo_region_get_rectangle (sub, i, &rect);
|
|
|
|
rect.x -= clip_radius;
|
|
|
|
rect.y -= clip_radius;
|
|
|
|
rect.width += 2 * clip_radius;
|
|
|
|
rect.height += 2 * clip_radius;
|
2023-10-31 23:07:23 +00:00
|
|
|
cairo_region_union_rectangle (data->region, &rect);
|
2018-03-27 22:34:23 +00:00
|
|
|
}
|
|
|
|
cairo_region_destroy (sub);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2018-03-27 22:34:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_blur_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_BLUR_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_blur_node_finalize;
|
|
|
|
node_class->draw = gsk_blur_node_draw;
|
|
|
|
node_class->diff = gsk_blur_node_diff;
|
|
|
|
}
|
|
|
|
|
2017-09-25 01:53:54 +00:00
|
|
|
/**
|
2020-06-27 09:22:54 +00:00
|
|
|
* gsk_blur_node_new:
|
2017-09-25 01:53:54 +00:00
|
|
|
* @child: the child node to blur
|
2021-10-17 10:15:34 +00:00
|
|
|
* @radius: the blur radius. Must be positive
|
2017-09-25 01:53:54 +00:00
|
|
|
*
|
|
|
|
* Creates a render node that blurs the child.
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer full) (type GskBlurNode): a new `GskRenderNode`
|
2017-09-25 01:53:54 +00:00
|
|
|
*/
|
2017-09-03 03:49:34 +00:00
|
|
|
GskRenderNode *
|
|
|
|
gsk_blur_node_new (GskRenderNode *child,
|
2019-12-18 08:48:25 +00:00
|
|
|
float radius)
|
2017-09-03 03:49:34 +00:00
|
|
|
{
|
|
|
|
GskBlurNode *self;
|
2020-04-07 22:33:54 +00:00
|
|
|
GskRenderNode *node;
|
|
|
|
float clip_radius;
|
2017-09-03 03:49:34 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL);
|
2021-10-17 10:15:34 +00:00
|
|
|
g_return_val_if_fail (radius >= 0, NULL);
|
2017-09-03 03:49:34 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
self = gsk_render_node_alloc (GSK_BLUR_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = child->offscreen_for_opacity;
|
2017-09-03 03:49:34 +00:00
|
|
|
|
|
|
|
self->child = gsk_render_node_ref (child);
|
|
|
|
self->radius = radius;
|
|
|
|
|
2021-08-04 09:24:35 +00:00
|
|
|
clip_radius = gsk_cairo_blur_compute_pixels (radius / 2.0);
|
2020-04-07 22:33:54 +00:00
|
|
|
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&node->bounds, &child->bounds);
|
|
|
|
graphene_rect_inset (&self->render_node.bounds, - clip_radius, - clip_radius);
|
2017-09-03 03:49:34 +00:00
|
|
|
|
2023-06-15 18:27:13 +00:00
|
|
|
node->preferred_depth = gsk_render_node_get_preferred_depth (child);
|
2021-10-01 20:23:12 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return node;
|
2017-09-03 03:49:34 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_blur_node_get_child:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskBlurNode): a blur `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Retrieves the child `GskRenderNode` of the blur @node.
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer none): the blurred child node
|
|
|
|
*/
|
2017-09-03 03:49:34 +00:00
|
|
|
GskRenderNode *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_blur_node_get_child (const GskRenderNode *node)
|
2017-09-03 03:49:34 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskBlurNode *self = (const GskBlurNode *) node;
|
2017-09-03 03:49:34 +00:00
|
|
|
|
|
|
|
return self->child;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
|
|
|
* gsk_blur_node_get_radius:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskBlurNode): a blur `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Retrieves the blur radius of the @node.
|
|
|
|
*
|
|
|
|
* Returns: the blur radius
|
|
|
|
*/
|
2019-12-18 08:48:25 +00:00
|
|
|
float
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_blur_node_get_radius (const GskRenderNode *node)
|
2017-09-03 03:49:34 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskBlurNode *self = (const GskBlurNode *) node;
|
2017-09-03 03:49:34 +00:00
|
|
|
|
|
|
|
return self->radius;
|
|
|
|
}
|
2020-04-07 22:33:54 +00:00
|
|
|
|
2023-02-11 13:59:06 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_MASK_NODE */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GskMaskNode:
|
|
|
|
*
|
|
|
|
* A render node masking one child node with another.
|
|
|
|
*
|
|
|
|
* Since: 4.10
|
|
|
|
*/
|
|
|
|
typedef struct _GskMaskNode GskMaskNode;
|
|
|
|
|
|
|
|
struct _GskMaskNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GskRenderNode *mask;
|
|
|
|
GskRenderNode *source;
|
2023-02-14 18:44:39 +00:00
|
|
|
GskMaskMode mask_mode;
|
2023-02-11 13:59:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_mask_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskMaskNode *self = (GskMaskNode *) node;
|
2023-06-10 02:23:06 +00:00
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_MASK_NODE));
|
2023-02-11 13:59:06 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (self->source);
|
|
|
|
gsk_render_node_unref (self->mask);
|
2023-06-10 02:23:06 +00:00
|
|
|
|
|
|
|
parent_class->finalize (node);
|
2023-02-11 13:59:06 +00:00
|
|
|
}
|
|
|
|
|
2023-07-03 18:45:53 +00:00
|
|
|
static void
|
|
|
|
apply_luminance_to_pattern (cairo_pattern_t *pattern,
|
|
|
|
gboolean invert_luminance)
|
|
|
|
{
|
|
|
|
cairo_surface_t *surface, *image_surface;
|
|
|
|
guchar *data;
|
|
|
|
gsize x, y, width, height, stride;
|
|
|
|
int red, green, blue, alpha, luminance;
|
|
|
|
guint32* pixel_data;
|
|
|
|
|
|
|
|
cairo_pattern_get_surface (pattern, &surface);
|
|
|
|
image_surface = cairo_surface_map_to_image (surface, NULL);
|
|
|
|
|
|
|
|
data = cairo_image_surface_get_data (image_surface);
|
|
|
|
width = cairo_image_surface_get_width (image_surface);
|
|
|
|
height = cairo_image_surface_get_height (image_surface);
|
|
|
|
stride = cairo_image_surface_get_stride (image_surface);
|
|
|
|
|
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
pixel_data = (guint32 *) data;
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
alpha = (pixel_data[x] >> 24) & 0xFF;
|
|
|
|
red = (pixel_data[x] >> 16) & 0xFF;
|
|
|
|
green = (pixel_data[x] >> 8) & 0xFF;
|
|
|
|
blue = (pixel_data[x] >> 0) & 0xFF;
|
|
|
|
|
|
|
|
luminance = 2126 * red + 7152 * green + 722 * blue;
|
|
|
|
if (invert_luminance)
|
|
|
|
luminance = 10000 * alpha - luminance;
|
|
|
|
luminance = (luminance + 5000) / 10000;
|
|
|
|
|
|
|
|
pixel_data[x] = luminance * 0x1010101;
|
|
|
|
}
|
|
|
|
data += stride;
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_surface_mark_dirty (image_surface);
|
|
|
|
cairo_surface_unmap_image (surface, image_surface);
|
|
|
|
/* https://gitlab.freedesktop.org/cairo/cairo/-/merge_requests/487 */
|
|
|
|
cairo_surface_mark_dirty (surface);
|
|
|
|
}
|
|
|
|
|
2023-02-11 13:59:06 +00:00
|
|
|
static void
|
|
|
|
gsk_mask_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskMaskNode *self = (GskMaskNode *) node;
|
|
|
|
cairo_pattern_t *mask_pattern;
|
2023-02-14 18:44:39 +00:00
|
|
|
graphene_matrix_t color_matrix;
|
|
|
|
graphene_vec4_t color_offset;
|
2023-02-11 13:59:06 +00:00
|
|
|
|
|
|
|
cairo_push_group (cr);
|
|
|
|
gsk_render_node_draw (self->source, cr);
|
|
|
|
cairo_pop_group_to_source (cr);
|
|
|
|
|
|
|
|
cairo_push_group (cr);
|
|
|
|
gsk_render_node_draw (self->mask, cr);
|
|
|
|
mask_pattern = cairo_pop_group (cr);
|
|
|
|
|
2023-02-14 18:44:39 +00:00
|
|
|
switch (self->mask_mode)
|
|
|
|
{
|
|
|
|
case GSK_MASK_MODE_ALPHA:
|
|
|
|
break;
|
|
|
|
case GSK_MASK_MODE_INVERTED_ALPHA:
|
2023-07-03 18:45:53 +00:00
|
|
|
graphene_matrix_init_from_float (&color_matrix, (float[]){ 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
-1, -1, -1, -1 });
|
|
|
|
graphene_vec4_init (&color_offset, 1, 1, 1, 1);
|
|
|
|
apply_color_matrix_to_pattern (mask_pattern, &color_matrix, &color_offset);
|
2023-02-14 18:44:39 +00:00
|
|
|
break;
|
|
|
|
case GSK_MASK_MODE_LUMINANCE:
|
2023-07-03 18:45:53 +00:00
|
|
|
apply_luminance_to_pattern (mask_pattern, FALSE);
|
2023-02-14 18:44:39 +00:00
|
|
|
break;
|
|
|
|
case GSK_MASK_MODE_INVERTED_LUMINANCE:
|
2023-07-03 18:45:53 +00:00
|
|
|
apply_luminance_to_pattern (mask_pattern, TRUE);
|
2023-02-14 18:44:39 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
gsk_cairo_rectangle (cr, &node->bounds);
|
|
|
|
cairo_clip (cr);
|
|
|
|
|
2023-02-11 13:59:06 +00:00
|
|
|
cairo_mask (cr, mask_pattern);
|
2023-06-28 01:54:15 +00:00
|
|
|
|
|
|
|
cairo_pattern_destroy (mask_pattern);
|
2023-02-11 13:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_mask_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2023-02-11 13:59:06 +00:00
|
|
|
{
|
|
|
|
GskMaskNode *self1 = (GskMaskNode *) node1;
|
|
|
|
GskMaskNode *self2 = (GskMaskNode *) node2;
|
|
|
|
|
2023-07-03 02:44:25 +00:00
|
|
|
if (self1->mask_mode != self2->mask_mode)
|
|
|
|
{
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2023-07-03 02:44:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_data_diff (self1->source, self2->source, data);
|
|
|
|
gsk_render_node_data_diff (self1->mask, self2->mask, data);
|
2023-02-11 13:59:06 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_mask_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_MASK_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_mask_node_finalize;
|
|
|
|
node_class->draw = gsk_mask_node_draw;
|
|
|
|
node_class->diff = gsk_mask_node_diff;
|
|
|
|
}
|
|
|
|
|
2023-02-11 13:59:06 +00:00
|
|
|
/**
|
|
|
|
* gsk_mask_node_new:
|
2023-02-14 18:44:39 +00:00
|
|
|
* @source: The source node to be drawn
|
|
|
|
* @mask: The node to be used as mask
|
|
|
|
* @mask_mode: The mask mode to use
|
2023-02-11 13:59:06 +00:00
|
|
|
*
|
2023-02-14 18:44:39 +00:00
|
|
|
* Creates a `GskRenderNode` that will mask a given node by another.
|
|
|
|
*
|
|
|
|
* The @mask_mode determines how the 'mask values' are derived from
|
|
|
|
* the colors of the @mask. Applying the mask consists of multiplying
|
|
|
|
* the 'mask value' with the alpha of the source.
|
2023-02-11 13:59:06 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer full) (type GskMaskNode): A new `GskRenderNode`
|
|
|
|
*
|
|
|
|
* Since: 4.10
|
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_mask_node_new (GskRenderNode *source,
|
2023-02-14 18:44:39 +00:00
|
|
|
GskRenderNode *mask,
|
|
|
|
GskMaskMode mask_mode)
|
2023-02-11 13:59:06 +00:00
|
|
|
{
|
|
|
|
GskMaskNode *self;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (source), NULL);
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (mask), NULL);
|
|
|
|
|
|
|
|
self = gsk_render_node_alloc (GSK_MASK_NODE);
|
|
|
|
self->source = gsk_render_node_ref (source);
|
|
|
|
self->mask = gsk_render_node_ref (mask);
|
2023-02-14 18:44:39 +00:00
|
|
|
self->mask_mode = mask_mode;
|
2023-02-11 13:59:06 +00:00
|
|
|
|
2023-02-14 18:44:39 +00:00
|
|
|
self->render_node.bounds = source->bounds;
|
|
|
|
|
2023-06-15 18:27:13 +00:00
|
|
|
self->render_node.preferred_depth = gsk_render_node_get_preferred_depth (source);
|
2023-02-11 13:59:06 +00:00
|
|
|
|
|
|
|
return &self->render_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_mask_node_get_source:
|
2023-02-14 18:44:39 +00:00
|
|
|
* @node: (type GskMaskNode): a mask `GskRenderNode`
|
2023-02-11 13:59:06 +00:00
|
|
|
*
|
|
|
|
* Retrieves the source `GskRenderNode` child of the @node.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the source child node
|
|
|
|
*
|
|
|
|
* Since: 4.10
|
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_mask_node_get_source (const GskRenderNode *node)
|
|
|
|
{
|
|
|
|
const GskMaskNode *self = (const GskMaskNode *) node;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_MASK_NODE), NULL);
|
|
|
|
|
|
|
|
return self->source;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_mask_node_get_mask:
|
2023-02-14 18:44:39 +00:00
|
|
|
* @node: (type GskMaskNode): a mask `GskRenderNode`
|
2023-02-11 13:59:06 +00:00
|
|
|
*
|
|
|
|
* Retrieves the mask `GskRenderNode` child of the @node.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the mask child node
|
|
|
|
*
|
|
|
|
* Since: 4.10
|
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_mask_node_get_mask (const GskRenderNode *node)
|
|
|
|
{
|
|
|
|
const GskMaskNode *self = (const GskMaskNode *) node;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_MASK_NODE), NULL);
|
|
|
|
|
|
|
|
return self->mask;
|
|
|
|
}
|
|
|
|
|
2023-02-14 18:44:39 +00:00
|
|
|
/**
|
|
|
|
* gsk_mask_node_get_mask_mode:
|
|
|
|
* @node: (type GskMaskNode): a blending `GskRenderNode`
|
|
|
|
*
|
|
|
|
* Retrieves the mask mode used by @node.
|
|
|
|
*
|
|
|
|
* Returns: the mask mode
|
|
|
|
*
|
|
|
|
* Since: 4.10
|
|
|
|
*/
|
|
|
|
GskMaskMode
|
|
|
|
gsk_mask_node_get_mask_mode (const GskRenderNode *node)
|
|
|
|
{
|
|
|
|
const GskMaskNode *self = (const GskMaskNode *) node;
|
|
|
|
|
|
|
|
return self->mask_mode;
|
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_DEBUG_NODE */
|
2020-04-07 22:33:54 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskDebugNode:
|
|
|
|
*
|
|
|
|
* A render node that emits a debugging message when drawing its
|
|
|
|
* child node.
|
|
|
|
*/
|
2020-04-07 22:33:54 +00:00
|
|
|
struct _GskDebugNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GskRenderNode *child;
|
|
|
|
char *message;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_debug_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskDebugNode *self = (GskDebugNode *) node;
|
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_DEBUG_NODE));
|
|
|
|
|
|
|
|
gsk_render_node_unref (self->child);
|
|
|
|
g_free (self->message);
|
|
|
|
|
|
|
|
parent_class->finalize (node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_debug_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskDebugNode *self = (GskDebugNode *) node;
|
|
|
|
|
|
|
|
gsk_render_node_draw (self->child, cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gsk_debug_node_can_diff (const GskRenderNode *node1,
|
|
|
|
const GskRenderNode *node2)
|
|
|
|
{
|
|
|
|
GskDebugNode *self1 = (GskDebugNode *) node1;
|
|
|
|
GskDebugNode *self2 = (GskDebugNode *) node2;
|
|
|
|
|
|
|
|
return gsk_render_node_can_diff (self1->child, self2->child);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_debug_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2020-04-07 22:33:54 +00:00
|
|
|
{
|
|
|
|
GskDebugNode *self1 = (GskDebugNode *) node1;
|
|
|
|
GskDebugNode *self2 = (GskDebugNode *) node2;
|
|
|
|
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_data_diff (self1->child, self2->child, data);
|
2020-04-07 22:33:54 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_debug_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_DEBUG_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_debug_node_finalize;
|
|
|
|
node_class->draw = gsk_debug_node_draw;
|
|
|
|
node_class->can_diff = gsk_debug_node_can_diff;
|
|
|
|
node_class->diff = gsk_debug_node_diff;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
/**
|
2020-06-27 09:22:54 +00:00
|
|
|
* gsk_debug_node_new:
|
2020-04-07 22:33:54 +00:00
|
|
|
* @child: The child to add debug info for
|
2020-06-27 09:22:54 +00:00
|
|
|
* @message: (transfer full): The debug message
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that will add debug information about
|
2020-04-07 22:33:54 +00:00
|
|
|
* the given @child.
|
|
|
|
*
|
|
|
|
* Adding this node has no visual effect.
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer full) (type GskDebugNode): A new `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_debug_node_new (GskRenderNode *child,
|
|
|
|
char *message)
|
|
|
|
{
|
|
|
|
GskDebugNode *self;
|
|
|
|
GskRenderNode *node;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL);
|
|
|
|
|
|
|
|
self = gsk_render_node_alloc (GSK_DEBUG_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = child->offscreen_for_opacity;
|
2020-04-07 22:33:54 +00:00
|
|
|
|
|
|
|
self->child = gsk_render_node_ref (child);
|
|
|
|
self->message = message;
|
|
|
|
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&node->bounds, &child->bounds);
|
2020-04-07 22:33:54 +00:00
|
|
|
|
2023-06-15 18:27:13 +00:00
|
|
|
node->preferred_depth = gsk_render_node_get_preferred_depth (child);
|
2021-10-01 20:23:12 +00:00
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_debug_node_get_child:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskDebugNode): a debug `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Gets the child node that is getting drawn by the given @node.
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer none): the child `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
**/
|
|
|
|
GskRenderNode *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_debug_node_get_child (const GskRenderNode *node)
|
2020-04-07 22:33:54 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskDebugNode *self = (const GskDebugNode *) node;
|
2020-04-07 22:33:54 +00:00
|
|
|
|
|
|
|
return self->child;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_debug_node_get_message:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskDebugNode): a debug `GskRenderNode`
|
2020-04-07 22:33:54 +00:00
|
|
|
*
|
|
|
|
* Gets the debug message that was set on this node
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): The debug message
|
|
|
|
**/
|
|
|
|
const char *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_debug_node_get_message (const GskRenderNode *node)
|
2020-04-07 22:33:54 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskDebugNode *self = (const GskDebugNode *) node;
|
2020-04-07 22:33:54 +00:00
|
|
|
|
|
|
|
return self->message;
|
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_GL_SHADER_NODE */
|
2020-09-18 15:46:57 +00:00
|
|
|
|
2020-12-01 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* GskGLShaderNode:
|
|
|
|
*
|
|
|
|
* A render node using a GL shader when drawing its children nodes.
|
|
|
|
*/
|
2020-09-18 15:46:57 +00:00
|
|
|
struct _GskGLShaderNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GskGLShader *shader;
|
|
|
|
GBytes *args;
|
|
|
|
GskRenderNode **children;
|
|
|
|
guint n_children;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_gl_shader_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskGLShaderNode *self = (GskGLShaderNode *) node;
|
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_GL_SHADER_NODE));
|
|
|
|
|
|
|
|
for (guint i = 0; i < self->n_children; i++)
|
|
|
|
gsk_render_node_unref (self->children[i]);
|
|
|
|
g_free (self->children);
|
|
|
|
|
|
|
|
g_bytes_unref (self->args);
|
|
|
|
|
|
|
|
g_object_unref (self->shader);
|
|
|
|
|
|
|
|
parent_class->finalize (node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_gl_shader_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
cairo_set_source_rgb (cr, 255 / 255., 105 / 255., 180 / 255.);
|
|
|
|
gsk_cairo_rectangle (cr, &node->bounds);
|
|
|
|
cairo_fill (cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_gl_shader_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2020-09-18 15:46:57 +00:00
|
|
|
{
|
|
|
|
GskGLShaderNode *self1 = (GskGLShaderNode *) node1;
|
|
|
|
GskGLShaderNode *self2 = (GskGLShaderNode *) node2;
|
|
|
|
|
2023-11-13 21:12:58 +00:00
|
|
|
if (gsk_rect_equal (&node1->bounds, &node2->bounds) &&
|
2020-09-18 15:46:57 +00:00
|
|
|
self1->shader == self2->shader &&
|
|
|
|
g_bytes_compare (self1->args, self2->args) == 0 &&
|
|
|
|
self1->n_children == self2->n_children)
|
|
|
|
{
|
|
|
|
cairo_region_t *child_region = cairo_region_create();
|
|
|
|
for (guint i = 0; i < self1->n_children; i++)
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_data_diff (self1->children[i], self2->children[i], &(GskDiffData) {child_region, data->offload });
|
2020-09-18 15:46:57 +00:00
|
|
|
if (!cairo_region_is_empty (child_region))
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2020-09-18 15:46:57 +00:00
|
|
|
cairo_region_destroy (child_region);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-31 23:07:23 +00:00
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
2020-09-18 15:46:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-03 14:39:52 +00:00
|
|
|
static void
|
|
|
|
gsk_gl_shader_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_GL_SHADER_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_gl_shader_node_finalize;
|
|
|
|
node_class->draw = gsk_gl_shader_node_draw;
|
|
|
|
node_class->diff = gsk_gl_shader_node_diff;
|
|
|
|
}
|
|
|
|
|
2020-09-18 15:46:57 +00:00
|
|
|
/**
|
|
|
|
* gsk_gl_shader_node_new:
|
2021-05-20 03:40:54 +00:00
|
|
|
* @shader: the `GskGLShader`
|
2020-09-18 15:46:57 +00:00
|
|
|
* @bounds: the rectangle to render the shader into
|
|
|
|
* @args: Arguments for the uniforms
|
2022-03-04 05:39:02 +00:00
|
|
|
* @children: (nullable) (array length=n_children): array of child nodes,
|
|
|
|
* these will be rendered to textures and used as input.
|
2022-11-18 03:24:18 +00:00
|
|
|
* @n_children: Length of @children (currently the GL backend supports
|
2022-03-04 05:39:02 +00:00
|
|
|
* up to 4 children)
|
2020-09-18 15:46:57 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Creates a `GskRenderNode` that will render the given @shader into the
|
|
|
|
* area given by @bounds.
|
|
|
|
*
|
|
|
|
* The @args is a block of data to use for uniform input, as per types and
|
|
|
|
* offsets defined by the @shader. Normally this is generated by
|
|
|
|
* [method@Gsk.GLShader.format_args] or [struct@Gsk.ShaderArgsBuilder].
|
2020-09-18 15:46:57 +00:00
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* See [class@Gsk.GLShader] for details about how the shader should be written.
|
2020-09-18 15:46:57 +00:00
|
|
|
*
|
|
|
|
* All the children will be rendered into textures (if they aren't already
|
2021-02-20 06:09:55 +00:00
|
|
|
* `GskTextureNodes`, which will be used directly). These textures will be
|
2020-09-18 15:46:57 +00:00
|
|
|
* sent as input to the shader.
|
|
|
|
*
|
|
|
|
* If the renderer doesn't support GL shaders, or if there is any problem
|
|
|
|
* when compiling the shader, then the node will draw pink. You should use
|
2021-02-20 06:09:55 +00:00
|
|
|
* [method@Gsk.GLShader.compile] to ensure the @shader will work for the
|
2020-09-18 15:46:57 +00:00
|
|
|
* renderer before using it.
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Returns: (transfer full) (type GskGLShaderNode): A new `GskRenderNode`
|
2020-09-18 15:46:57 +00:00
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_gl_shader_node_new (GskGLShader *shader,
|
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
GBytes *args,
|
|
|
|
GskRenderNode **children,
|
|
|
|
guint n_children)
|
|
|
|
{
|
|
|
|
GskGLShaderNode *self;
|
|
|
|
GskRenderNode *node;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_GL_SHADER (shader), NULL);
|
|
|
|
g_return_val_if_fail (bounds != NULL, NULL);
|
2022-03-04 05:39:02 +00:00
|
|
|
g_return_val_if_fail (args != NULL, NULL);
|
|
|
|
g_return_val_if_fail (g_bytes_get_size (args) == gsk_gl_shader_get_args_size (shader), NULL);
|
2020-09-18 15:46:57 +00:00
|
|
|
g_return_val_if_fail ((children == NULL && n_children == 0) ||
|
2022-03-04 05:39:02 +00:00
|
|
|
(n_children == gsk_gl_shader_get_n_textures (shader)), NULL);
|
2020-09-18 15:46:57 +00:00
|
|
|
|
|
|
|
self = gsk_render_node_alloc (GSK_GL_SHADER_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
2022-04-05 18:55:36 +00:00
|
|
|
node->offscreen_for_opacity = TRUE;
|
2020-09-18 15:46:57 +00:00
|
|
|
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&node->bounds, bounds);
|
2020-09-18 15:46:57 +00:00
|
|
|
self->shader = g_object_ref (shader);
|
|
|
|
|
|
|
|
self->args = g_bytes_ref (args);
|
|
|
|
|
|
|
|
self->n_children = n_children;
|
|
|
|
if (n_children > 0)
|
|
|
|
{
|
|
|
|
self->children = g_malloc_n (n_children, sizeof (GskRenderNode *));
|
|
|
|
for (guint i = 0; i < n_children; i++)
|
2021-10-01 20:23:12 +00:00
|
|
|
{
|
|
|
|
self->children[i] = gsk_render_node_ref (children[i]);
|
2023-06-15 18:27:13 +00:00
|
|
|
node->preferred_depth = gdk_memory_depth_merge (node->preferred_depth,
|
|
|
|
gsk_render_node_get_preferred_depth (children[i]));
|
2021-10-01 20:23:12 +00:00
|
|
|
}
|
2020-09-18 15:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_gl_shader_node_get_n_children:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskGLShaderNode): a `GskRenderNode` for a gl shader
|
2020-09-18 15:46:57 +00:00
|
|
|
*
|
|
|
|
* Returns the number of children
|
|
|
|
*
|
|
|
|
* Returns: The number of children
|
|
|
|
*/
|
|
|
|
guint
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_gl_shader_node_get_n_children (const GskRenderNode *node)
|
2020-09-18 15:46:57 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskGLShaderNode *self = (const GskGLShaderNode *) node;
|
2020-09-18 15:46:57 +00:00
|
|
|
|
|
|
|
return self->n_children;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_gl_shader_node_get_child:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskGLShaderNode): a `GskRenderNode` for a gl shader
|
2020-09-18 15:46:57 +00:00
|
|
|
* @idx: the position of the child to get
|
|
|
|
*
|
|
|
|
* Gets one of the children.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the @idx'th child of @node
|
|
|
|
*/
|
|
|
|
GskRenderNode *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_gl_shader_node_get_child (const GskRenderNode *node,
|
|
|
|
guint idx)
|
2020-09-18 15:46:57 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskGLShaderNode *self = (const GskGLShaderNode *) node;
|
2020-09-18 15:46:57 +00:00
|
|
|
|
|
|
|
return self->children[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_gl_shader_node_get_shader:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskGLShaderNode): a `GskRenderNode` for a gl shader
|
2020-09-18 15:46:57 +00:00
|
|
|
*
|
|
|
|
* Gets shader code for the node.
|
|
|
|
*
|
2021-05-20 03:40:54 +00:00
|
|
|
* Returns: (transfer none): the `GskGLShader` shader
|
2020-09-18 15:46:57 +00:00
|
|
|
*/
|
|
|
|
GskGLShader *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_gl_shader_node_get_shader (const GskRenderNode *node)
|
2020-09-18 15:46:57 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskGLShaderNode *self = (const GskGLShaderNode *) node;
|
2020-09-18 15:46:57 +00:00
|
|
|
|
|
|
|
return self->shader;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_gl_shader_node_get_args:
|
2021-02-20 06:09:55 +00:00
|
|
|
* @node: (type GskGLShaderNode): a `GskRenderNode` for a gl shader
|
2020-09-18 15:46:57 +00:00
|
|
|
*
|
|
|
|
* Gets args for the node.
|
|
|
|
*
|
2021-05-20 03:40:54 +00:00
|
|
|
* Returns: (transfer none): A `GBytes` with the uniform arguments
|
2020-09-18 15:46:57 +00:00
|
|
|
*/
|
|
|
|
GBytes *
|
2021-02-03 22:49:42 +00:00
|
|
|
gsk_gl_shader_node_get_args (const GskRenderNode *node)
|
2020-09-18 15:46:57 +00:00
|
|
|
{
|
2021-02-03 22:49:42 +00:00
|
|
|
const GskGLShaderNode *self = (const GskGLShaderNode *) node;
|
2020-09-18 15:46:57 +00:00
|
|
|
|
|
|
|
return self->args;
|
|
|
|
}
|
|
|
|
|
2023-10-29 15:48:16 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ GSK_SUBSURFACE_NODE */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GskSubsurfaceNode:
|
|
|
|
*
|
|
|
|
* A render node that potentially diverts a part of the scene graph to a subsurface.
|
|
|
|
*/
|
|
|
|
struct _GskSubsurfaceNode
|
|
|
|
{
|
|
|
|
GskRenderNode render_node;
|
|
|
|
|
|
|
|
GskRenderNode *child;
|
|
|
|
GdkSubsurface *subsurface;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_subsurface_node_finalize (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GskSubsurfaceNode *self = (GskSubsurfaceNode *) node;
|
|
|
|
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_SUBSURFACE_NODE));
|
|
|
|
|
|
|
|
gsk_render_node_unref (self->child);
|
|
|
|
g_clear_object (&self->subsurface);
|
|
|
|
|
|
|
|
parent_class->finalize (node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_subsurface_node_draw (GskRenderNode *node,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GskSubsurfaceNode *self = (GskSubsurfaceNode *) node;
|
|
|
|
|
|
|
|
gsk_render_node_draw (self->child, cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gsk_subsurface_node_can_diff (const GskRenderNode *node1,
|
|
|
|
const GskRenderNode *node2)
|
|
|
|
{
|
2023-10-31 23:07:23 +00:00
|
|
|
GskSubsurfaceNode *self1 = (GskSubsurfaceNode *) node1;
|
|
|
|
GskSubsurfaceNode *self2 = (GskSubsurfaceNode *) node2;
|
|
|
|
|
|
|
|
return self1->subsurface == self2->subsurface;
|
2023-10-29 15:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_subsurface_node_diff (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2,
|
2023-10-31 23:07:23 +00:00
|
|
|
GskDiffData *data)
|
2023-10-29 15:48:16 +00:00
|
|
|
{
|
|
|
|
GskSubsurfaceNode *self1 = (GskSubsurfaceNode *) node1;
|
|
|
|
GskSubsurfaceNode *self2 = (GskSubsurfaceNode *) node2;
|
2023-11-18 07:16:36 +00:00
|
|
|
GskOffloadInfo *info1, *info2;
|
2023-10-29 15:48:16 +00:00
|
|
|
|
2023-11-18 07:16:36 +00:00
|
|
|
if (!data->offload)
|
2023-10-31 23:07:23 +00:00
|
|
|
{
|
2023-11-18 07:16:36 +00:00
|
|
|
gsk_render_node_data_diff (self1->child, self2->child, data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
info1 = gsk_offload_get_subsurface_info (data->offload, self1->subsurface);
|
|
|
|
info2 = gsk_offload_get_subsurface_info (data->offload, self2->subsurface);
|
|
|
|
|
|
|
|
if (!info1 || !info2)
|
|
|
|
{
|
|
|
|
gsk_render_node_data_diff (self1->child, self2->child, data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info1->is_offloaded != info2->is_offloaded ||
|
|
|
|
info1->is_above != info2->is_above)
|
|
|
|
{
|
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
|
|
|
}
|
|
|
|
else if (info1->is_offloaded && !info1->is_above &&
|
|
|
|
!gsk_rect_equal (&info1->rect, &info2->rect))
|
|
|
|
{
|
|
|
|
gsk_render_node_diff_impossible (node1, node2, data);
|
|
|
|
}
|
|
|
|
else if (!info1->is_offloaded)
|
|
|
|
{
|
|
|
|
gsk_render_node_data_diff (self1->child, self2->child, data);
|
2023-10-31 23:07:23 +00:00
|
|
|
}
|
2023-10-29 15:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_subsurface_node_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GskRenderNodeClass *node_class = g_class;
|
|
|
|
|
|
|
|
node_class->node_type = GSK_SUBSURFACE_NODE;
|
|
|
|
|
|
|
|
node_class->finalize = gsk_subsurface_node_finalize;
|
|
|
|
node_class->draw = gsk_subsurface_node_draw;
|
|
|
|
node_class->can_diff = gsk_subsurface_node_can_diff;
|
|
|
|
node_class->diff = gsk_subsurface_node_diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_subsurface_node_new:
|
|
|
|
* @child: The child to divert to a subsurface
|
|
|
|
* @subsurface: (nullable): the subsurface to use
|
|
|
|
*
|
|
|
|
* Creates a `GskRenderNode` that will possibly divert the child
|
|
|
|
* node to a subsurface.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full) (type GskSubsurfaceNode): A new `GskRenderNode`
|
|
|
|
*
|
|
|
|
* Since: 4.14
|
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_subsurface_node_new (GskRenderNode *child,
|
|
|
|
gpointer subsurface)
|
|
|
|
{
|
|
|
|
GskSubsurfaceNode *self;
|
|
|
|
GskRenderNode *node;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL);
|
|
|
|
|
|
|
|
self = gsk_render_node_alloc (GSK_SUBSURFACE_NODE);
|
|
|
|
node = (GskRenderNode *) self;
|
|
|
|
node->offscreen_for_opacity = child->offscreen_for_opacity;
|
|
|
|
|
|
|
|
self->child = gsk_render_node_ref (child);
|
|
|
|
if (subsurface)
|
|
|
|
self->subsurface = g_object_ref (subsurface);
|
|
|
|
else
|
|
|
|
self->subsurface = NULL;
|
|
|
|
|
2023-11-24 15:03:53 +00:00
|
|
|
gsk_rect_init_from_rect (&node->bounds, &child->bounds);
|
2023-10-29 15:48:16 +00:00
|
|
|
|
|
|
|
node->preferred_depth = gsk_render_node_get_preferred_depth (child);
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_subsurface_node_get_child:
|
|
|
|
* @node: (type GskSubsurfaceNode): a debug `GskRenderNode`
|
|
|
|
*
|
|
|
|
* Gets the child node that is getting drawn by the given @node.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the child `GskRenderNode`
|
|
|
|
*
|
|
|
|
* Since: 4.14
|
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_subsurface_node_get_child (const GskRenderNode *node)
|
|
|
|
{
|
|
|
|
const GskSubsurfaceNode *self = (const GskSubsurfaceNode *) node;
|
|
|
|
|
|
|
|
return self->child;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_subsurface_node_get_subsurface:
|
|
|
|
* @node: (type GskDebugNode): a debug `GskRenderNode`
|
|
|
|
*
|
|
|
|
* Gets the subsurface that was set on this node
|
|
|
|
*
|
|
|
|
* Returns: (transfer none) (nullable): the subsurface
|
|
|
|
*
|
|
|
|
* Since: 4.14
|
|
|
|
*/
|
|
|
|
gpointer
|
|
|
|
gsk_subsurface_node_get_subsurface (const GskRenderNode *node)
|
|
|
|
{
|
|
|
|
const GskSubsurfaceNode *self = (const GskSubsurfaceNode *) node;
|
|
|
|
|
|
|
|
return self->subsurface;
|
|
|
|
}
|
|
|
|
|
2023-02-08 03:33:03 +00:00
|
|
|
/* }}} */
|
|
|
|
|
2020-04-08 14:34:11 +00:00
|
|
|
GType gsk_render_node_types[GSK_RENDER_NODE_TYPE_N_TYPES];
|
|
|
|
|
2020-04-07 22:33:54 +00:00
|
|
|
#ifndef I_
|
|
|
|
# define I_(str) g_intern_static_string ((str))
|
|
|
|
#endif
|
|
|
|
|
2020-04-08 14:34:11 +00:00
|
|
|
#define GSK_DEFINE_RENDER_NODE_TYPE(type_name, TYPE_ENUM_VALUE) \
|
|
|
|
GType \
|
|
|
|
type_name ## _get_type (void) { \
|
|
|
|
gsk_render_node_init_types (); \
|
|
|
|
g_assert (gsk_render_node_types[TYPE_ENUM_VALUE] != G_TYPE_INVALID); \
|
|
|
|
return gsk_render_node_types[TYPE_ENUM_VALUE]; \
|
|
|
|
}
|
|
|
|
|
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_container_node, GSK_CONTAINER_NODE)
|
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_cairo_node, GSK_CAIRO_NODE)
|
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_color_node, GSK_COLOR_NODE)
|
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_linear_gradient_node, GSK_LINEAR_GRADIENT_NODE)
|
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_repeating_linear_gradient_node, GSK_REPEATING_LINEAR_GRADIENT_NODE)
|
2020-09-12 02:55:37 +00:00
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_radial_gradient_node, GSK_RADIAL_GRADIENT_NODE)
|
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_repeating_radial_gradient_node, GSK_REPEATING_RADIAL_GRADIENT_NODE)
|
2020-12-02 23:47:54 +00:00
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_conic_gradient_node, GSK_CONIC_GRADIENT_NODE)
|
2020-04-08 14:34:11 +00:00
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_border_node, GSK_BORDER_NODE)
|
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_texture_node, GSK_TEXTURE_NODE)
|
2023-02-08 03:52:06 +00:00
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_texture_scale_node, GSK_TEXTURE_SCALE_NODE)
|
2020-04-08 14:34:11 +00:00
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_inset_shadow_node, GSK_INSET_SHADOW_NODE)
|
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_outset_shadow_node, GSK_OUTSET_SHADOW_NODE)
|
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_transform_node, GSK_TRANSFORM_NODE)
|
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_opacity_node, GSK_OPACITY_NODE)
|
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_color_matrix_node, GSK_COLOR_MATRIX_NODE)
|
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_repeat_node, GSK_REPEAT_NODE)
|
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_clip_node, GSK_CLIP_NODE)
|
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_rounded_clip_node, GSK_ROUNDED_CLIP_NODE)
|
2020-11-10 23:44:32 +00:00
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_fill_node, GSK_FILL_NODE)
|
2020-11-11 06:36:04 +00:00
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_stroke_node, GSK_STROKE_NODE)
|
2020-04-08 14:34:11 +00:00
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_shadow_node, GSK_SHADOW_NODE)
|
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_blend_node, GSK_BLEND_NODE)
|
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_cross_fade_node, GSK_CROSS_FADE_NODE)
|
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_text_node, GSK_TEXT_NODE)
|
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_blur_node, GSK_BLUR_NODE)
|
2023-02-11 13:59:06 +00:00
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_mask_node, GSK_MASK_NODE)
|
2020-09-18 15:46:57 +00:00
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_gl_shader_node, GSK_GL_SHADER_NODE)
|
2020-04-08 14:34:11 +00:00
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_debug_node, GSK_DEBUG_NODE)
|
2023-10-29 15:48:16 +00:00
|
|
|
GSK_DEFINE_RENDER_NODE_TYPE (gsk_subsurface_node, GSK_SUBSURFACE_NODE)
|
2020-04-08 14:34:11 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_render_node_init_types_once (void)
|
2020-04-07 22:33:54 +00:00
|
|
|
{
|
2023-04-03 14:44:03 +00:00
|
|
|
GType node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskContainerNode"),
|
|
|
|
sizeof (GskContainerNode),
|
|
|
|
gsk_container_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_CONTAINER_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskCairoNode"),
|
|
|
|
sizeof (GskCairoNode),
|
|
|
|
gsk_cairo_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_CAIRO_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskColorNode"),
|
|
|
|
sizeof (GskColorNode),
|
|
|
|
gsk_color_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_COLOR_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskLinearGradientNode"),
|
|
|
|
sizeof (GskLinearGradientNode),
|
|
|
|
gsk_linear_gradient_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_LINEAR_GRADIENT_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskRepeatingLinearGradientNode"),
|
|
|
|
sizeof (GskLinearGradientNode),
|
|
|
|
gsk_repeating_linear_gradient_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_REPEATING_LINEAR_GRADIENT_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskRadialGradientNode"),
|
|
|
|
sizeof (GskRadialGradientNode),
|
|
|
|
gsk_radial_gradient_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_RADIAL_GRADIENT_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskRepeatingRadialGradientNode"),
|
|
|
|
sizeof (GskRadialGradientNode),
|
|
|
|
gsk_repeating_radial_gradient_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_REPEATING_RADIAL_GRADIENT_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskConicGradientNode"),
|
|
|
|
sizeof (GskConicGradientNode),
|
|
|
|
gsk_conic_gradient_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_CONIC_GRADIENT_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskBorderNode"),
|
|
|
|
sizeof (GskBorderNode),
|
|
|
|
gsk_border_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_BORDER_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskTextureNode"),
|
|
|
|
sizeof (GskTextureNode),
|
|
|
|
gsk_texture_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_TEXTURE_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskTextureScaleNode"),
|
|
|
|
sizeof (GskTextureScaleNode),
|
|
|
|
gsk_texture_scale_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_TEXTURE_SCALE_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskInsetShadowNode"),
|
|
|
|
sizeof (GskInsetShadowNode),
|
|
|
|
gsk_inset_shadow_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_INSET_SHADOW_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskOutsetShadowNode"),
|
|
|
|
sizeof (GskOutsetShadowNode),
|
|
|
|
gsk_outset_shadow_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_OUTSET_SHADOW_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskTransformNode"),
|
|
|
|
sizeof (GskTransformNode),
|
|
|
|
gsk_transform_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_TRANSFORM_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskOpacityNode"),
|
|
|
|
sizeof (GskOpacityNode),
|
|
|
|
gsk_opacity_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_OPACITY_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskColorMatrixNode"),
|
|
|
|
sizeof (GskColorMatrixNode),
|
|
|
|
gsk_color_matrix_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_COLOR_MATRIX_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskRepeatNode"),
|
|
|
|
sizeof (GskRepeatNode),
|
|
|
|
gsk_repeat_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_REPEAT_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskClipNode"),
|
|
|
|
sizeof (GskClipNode),
|
|
|
|
gsk_clip_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_CLIP_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskRoundedClipNode"),
|
|
|
|
sizeof (GskRoundedClipNode),
|
|
|
|
gsk_rounded_clip_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_ROUNDED_CLIP_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskShadowNode"),
|
|
|
|
sizeof (GskShadowNode),
|
|
|
|
gsk_shadow_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_SHADOW_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskBlendNode"),
|
|
|
|
sizeof (GskBlendNode),
|
|
|
|
gsk_blend_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_BLEND_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskCrossFadeNode"),
|
|
|
|
sizeof (GskCrossFadeNode),
|
|
|
|
gsk_cross_fade_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_CROSS_FADE_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskTextNode"),
|
|
|
|
sizeof (GskTextNode),
|
|
|
|
gsk_text_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_TEXT_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskBlurNode"),
|
|
|
|
sizeof (GskBlurNode),
|
|
|
|
gsk_blur_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_BLUR_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskMaskNode"),
|
|
|
|
sizeof (GskMaskNode),
|
|
|
|
gsk_mask_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_MASK_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskGLShaderNode"),
|
|
|
|
sizeof (GskGLShaderNode),
|
|
|
|
gsk_gl_shader_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_GL_SHADER_NODE] = node_type;
|
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskDebugNode"),
|
|
|
|
sizeof (GskDebugNode),
|
|
|
|
gsk_debug_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_DEBUG_NODE] = node_type;
|
2020-11-10 23:44:32 +00:00
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskFillNode"),
|
|
|
|
sizeof (GskFillNode),
|
|
|
|
gsk_fill_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_FILL_NODE] = node_type;
|
2020-11-11 06:36:04 +00:00
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskStrokeNode"),
|
|
|
|
sizeof (GskStrokeNode),
|
|
|
|
gsk_stroke_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_STROKE_NODE] = node_type;
|
2023-10-29 15:48:16 +00:00
|
|
|
|
|
|
|
node_type = gsk_render_node_type_register_static (I_("GskSubsurfaceNode"),
|
|
|
|
sizeof (GskSubsurfaceNode),
|
|
|
|
gsk_subsurface_node_class_init);
|
|
|
|
gsk_render_node_types[GSK_SUBSURFACE_NODE] = node_type;
|
2020-04-07 22:33:54 +00:00
|
|
|
}
|
2021-08-19 22:30:04 +00:00
|
|
|
|
|
|
|
static void
|
2023-03-10 14:30:26 +00:00
|
|
|
gsk_render_node_serialize_bytes_finish (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer serializer)
|
2021-08-19 22:30:04 +00:00
|
|
|
{
|
|
|
|
GOutputStream *stream = G_OUTPUT_STREAM (source);
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2021-09-11 04:06:02 +00:00
|
|
|
if (g_output_stream_splice_finish (stream, result, &error) < 0)
|
2021-08-19 22:30:04 +00:00
|
|
|
gdk_content_serializer_return_error (serializer, error);
|
|
|
|
else
|
|
|
|
gdk_content_serializer_return_success (serializer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-03-10 14:30:26 +00:00
|
|
|
gsk_render_node_serialize_bytes (GdkContentSerializer *serializer,
|
|
|
|
GBytes *bytes)
|
2021-08-19 22:30:04 +00:00
|
|
|
{
|
2021-09-11 04:06:02 +00:00
|
|
|
GInputStream *input;
|
2021-08-19 22:30:04 +00:00
|
|
|
|
2021-09-11 04:06:02 +00:00
|
|
|
input = g_memory_input_stream_new_from_bytes (bytes);
|
|
|
|
|
|
|
|
g_output_stream_splice_async (gdk_content_serializer_get_output_stream (serializer),
|
|
|
|
input,
|
|
|
|
G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE,
|
|
|
|
gdk_content_serializer_get_priority (serializer),
|
|
|
|
gdk_content_serializer_get_cancellable (serializer),
|
2023-03-10 14:30:26 +00:00
|
|
|
gsk_render_node_serialize_bytes_finish,
|
2021-09-11 04:06:02 +00:00
|
|
|
serializer);
|
|
|
|
g_object_unref (input);
|
2021-08-19 22:30:04 +00:00
|
|
|
g_bytes_unref (bytes);
|
|
|
|
}
|
|
|
|
|
2023-03-10 14:30:26 +00:00
|
|
|
#ifdef CAIRO_HAS_SVG_SURFACE
|
|
|
|
static cairo_status_t
|
|
|
|
gsk_render_node_cairo_serializer_write (gpointer user_data,
|
|
|
|
const unsigned char *data,
|
|
|
|
unsigned int length)
|
|
|
|
{
|
|
|
|
g_byte_array_append (user_data, data, length);
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_render_node_svg_serializer (GdkContentSerializer *serializer)
|
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *cr;
|
|
|
|
graphene_rect_t bounds;
|
|
|
|
GByteArray *array;
|
|
|
|
|
|
|
|
node = gsk_value_get_render_node (gdk_content_serializer_get_value (serializer));
|
|
|
|
gsk_render_node_get_bounds (node, &bounds);
|
|
|
|
array = g_byte_array_new ();
|
|
|
|
|
|
|
|
surface = cairo_svg_surface_create_for_stream (gsk_render_node_cairo_serializer_write,
|
|
|
|
array,
|
|
|
|
bounds.size.width,
|
|
|
|
bounds.size.height);
|
|
|
|
cairo_svg_surface_set_document_unit (surface, CAIRO_SVG_UNIT_PX);
|
|
|
|
cairo_surface_set_device_offset (surface, -bounds.origin.x, -bounds.origin.y);
|
|
|
|
|
|
|
|
cr = cairo_create (surface);
|
|
|
|
gsk_render_node_draw (node, cr);
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
|
|
cairo_surface_finish (surface);
|
|
|
|
if (cairo_surface_status (surface) == CAIRO_STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
gsk_render_node_serialize_bytes (serializer, g_byte_array_free_to_bytes (array));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GError *error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
|
|
cairo_status_to_string (cairo_surface_status (surface)));
|
|
|
|
gdk_content_serializer_return_error (serializer, error);
|
|
|
|
g_byte_array_unref (array);
|
|
|
|
}
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-03-10 23:08:20 +00:00
|
|
|
static void
|
|
|
|
gsk_render_node_png_serializer (GdkContentSerializer *serializer)
|
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
|
|
|
GdkTexture *texture;
|
|
|
|
GskRenderer *renderer;
|
|
|
|
GBytes *bytes;
|
|
|
|
|
|
|
|
node = gsk_value_get_render_node (gdk_content_serializer_get_value (serializer));
|
|
|
|
|
|
|
|
renderer = gsk_gl_renderer_new ();
|
|
|
|
if (!gsk_renderer_realize (renderer, NULL, NULL))
|
|
|
|
{
|
|
|
|
g_object_unref (renderer);
|
|
|
|
renderer = gsk_cairo_renderer_new ();
|
|
|
|
if (!gsk_renderer_realize (renderer, NULL, NULL))
|
|
|
|
{
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
texture = gsk_renderer_render_texture (renderer, node, NULL);
|
|
|
|
gsk_renderer_unrealize (renderer);
|
|
|
|
g_object_unref (renderer);
|
|
|
|
|
|
|
|
bytes = gdk_texture_save_to_png_bytes (texture);
|
|
|
|
g_object_unref (texture);
|
|
|
|
|
|
|
|
gsk_render_node_serialize_bytes (serializer, bytes);
|
|
|
|
}
|
|
|
|
|
2023-03-10 14:30:26 +00:00
|
|
|
static void
|
|
|
|
gsk_render_node_content_serializer (GdkContentSerializer *serializer)
|
|
|
|
{
|
|
|
|
const GValue *value;
|
|
|
|
GskRenderNode *node;
|
|
|
|
GBytes *bytes;
|
|
|
|
|
|
|
|
value = gdk_content_serializer_get_value (serializer);
|
|
|
|
node = gsk_value_get_render_node (value);
|
|
|
|
bytes = gsk_render_node_serialize (node);
|
|
|
|
|
|
|
|
gsk_render_node_serialize_bytes (serializer, bytes);
|
|
|
|
}
|
|
|
|
|
2021-08-19 22:30:04 +00:00
|
|
|
static void
|
|
|
|
gsk_render_node_content_deserializer_finish (GObject *source,
|
2023-03-10 14:30:26 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer deserializer)
|
2021-08-19 22:30:04 +00:00
|
|
|
{
|
|
|
|
GOutputStream *stream = G_OUTPUT_STREAM (source);
|
|
|
|
GError *error = NULL;
|
|
|
|
gssize written;
|
|
|
|
GValue *value;
|
|
|
|
GskRenderNode *node;
|
|
|
|
GBytes *bytes;
|
|
|
|
|
|
|
|
written = g_output_stream_splice_finish (stream, result, &error);
|
|
|
|
if (written < 0)
|
|
|
|
{
|
|
|
|
gdk_content_deserializer_return_error (deserializer, error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bytes = g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (stream));
|
|
|
|
|
|
|
|
/* For now, we ignore any parsing errors. We might want to revisit that if it turns
|
|
|
|
* out copy/paste leads to too many errors */
|
|
|
|
node = gsk_render_node_deserialize (bytes, NULL, NULL);
|
|
|
|
|
|
|
|
value = gdk_content_deserializer_get_value (deserializer);
|
|
|
|
gsk_value_take_render_node (value, node);
|
|
|
|
|
|
|
|
gdk_content_deserializer_return_success (deserializer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_render_node_content_deserializer (GdkContentDeserializer *deserializer)
|
|
|
|
{
|
|
|
|
GOutputStream *output;
|
|
|
|
|
|
|
|
output = g_memory_output_stream_new_resizable ();
|
|
|
|
|
|
|
|
g_output_stream_splice_async (output,
|
|
|
|
gdk_content_deserializer_get_input_stream (deserializer),
|
|
|
|
G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
|
|
|
|
gdk_content_deserializer_get_priority (deserializer),
|
|
|
|
gdk_content_deserializer_get_cancellable (deserializer),
|
|
|
|
gsk_render_node_content_deserializer_finish,
|
|
|
|
deserializer);
|
|
|
|
g_object_unref (output);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_render_node_init_content_serializers (void)
|
|
|
|
{
|
|
|
|
gdk_content_register_serializer (GSK_TYPE_RENDER_NODE,
|
|
|
|
"application/x-gtk-render-node",
|
|
|
|
gsk_render_node_content_serializer,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
gdk_content_register_serializer (GSK_TYPE_RENDER_NODE,
|
|
|
|
"text/plain;charset=utf-8",
|
|
|
|
gsk_render_node_content_serializer,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
/* The serialization format only outputs ASCII, so we can do this */
|
|
|
|
gdk_content_register_serializer (GSK_TYPE_RENDER_NODE,
|
|
|
|
"text/plain",
|
|
|
|
gsk_render_node_content_serializer,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2023-03-10 14:30:26 +00:00
|
|
|
#ifdef CAIRO_HAS_SVG_SURFACE
|
|
|
|
gdk_content_register_serializer (GSK_TYPE_RENDER_NODE,
|
|
|
|
"image/svg+xml",
|
|
|
|
gsk_render_node_svg_serializer,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
#endif
|
2023-03-10 23:08:20 +00:00
|
|
|
gdk_content_register_serializer (GSK_TYPE_RENDER_NODE,
|
|
|
|
"image/png",
|
|
|
|
gsk_render_node_png_serializer,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2021-08-19 22:30:04 +00:00
|
|
|
|
|
|
|
gdk_content_register_deserializer ("application/x-gtk-render-node",
|
|
|
|
GSK_TYPE_RENDER_NODE,
|
|
|
|
gsk_render_node_content_deserializer,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2020-04-08 14:34:11 +00:00
|
|
|
/*< private >
|
|
|
|
* gsk_render_node_init_types:
|
|
|
|
*
|
2021-02-20 06:09:55 +00:00
|
|
|
* Initialize all the `GskRenderNode` types provided by GSK.
|
2020-04-08 14:34:11 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gsk_render_node_init_types (void)
|
|
|
|
{
|
2020-11-19 03:58:09 +00:00
|
|
|
static gsize register_types__volatile;
|
2020-04-08 14:34:11 +00:00
|
|
|
|
|
|
|
if (g_once_init_enter (®ister_types__volatile))
|
|
|
|
{
|
|
|
|
gboolean initialized = TRUE;
|
|
|
|
gsk_render_node_init_types_once ();
|
2021-08-19 22:30:04 +00:00
|
|
|
gsk_render_node_init_content_serializers ();
|
2020-04-08 14:34:11 +00:00
|
|
|
g_once_init_leave (®ister_types__volatile, initialized);
|
|
|
|
}
|
|
|
|
}
|
2023-02-08 03:33:03 +00:00
|
|
|
|
|
|
|
/* vim:set foldmethod=marker expandtab: */
|