2016-11-07 18:10:49 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2016 Benjamin Otte <otte@gnome.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtksnapshot.h"
|
|
|
|
#include "gtksnapshotprivate.h"
|
|
|
|
|
2020-01-10 12:02:33 +00:00
|
|
|
#include "gtkcsscolorvalueprivate.h"
|
2020-01-14 13:34:15 +00:00
|
|
|
#include "gtkcssshadowvalueprivate.h"
|
2018-04-24 02:02:55 +00:00
|
|
|
#include "gtkdebug.h"
|
2016-11-13 15:16:39 +00:00
|
|
|
#include "gtkrenderbackgroundprivate.h"
|
|
|
|
#include "gtkrenderborderprivate.h"
|
2016-11-15 05:19:16 +00:00
|
|
|
#include "gtkrendericonprivate.h"
|
2018-03-26 02:37:01 +00:00
|
|
|
#include "gtkrendernodepaintableprivate.h"
|
2016-11-13 15:16:39 +00:00
|
|
|
#include "gtkstylecontextprivate.h"
|
2019-02-28 08:52:49 +00:00
|
|
|
#include "gsktransformprivate.h"
|
2016-11-13 15:16:39 +00:00
|
|
|
|
2021-07-15 17:14:13 +00:00
|
|
|
#include "gdk/gdkrgbaprivate.h"
|
|
|
|
|
2016-11-11 23:37:54 +00:00
|
|
|
#include "gsk/gskrendernodeprivate.h"
|
2021-03-07 19:35:44 +00:00
|
|
|
#include "gsk/gskroundedrectprivate.h"
|
2016-11-11 23:37:54 +00:00
|
|
|
|
2017-08-30 15:14:48 +00:00
|
|
|
#include "gtk/gskpango.h"
|
|
|
|
|
2020-07-02 21:32:04 +00:00
|
|
|
#define GDK_ARRAY_NAME gtk_snapshot_nodes
|
|
|
|
#define GDK_ARRAY_TYPE_NAME GtkSnapshotNodes
|
|
|
|
#define GDK_ARRAY_ELEMENT_TYPE GskRenderNode *
|
|
|
|
#define GDK_ARRAY_FREE_FUNC gsk_render_node_unref
|
|
|
|
#include "gdk/gdkarrayimpl.c"
|
2016-11-18 11:53:57 +00:00
|
|
|
|
|
|
|
/**
|
2021-03-02 03:53:00 +00:00
|
|
|
* GtkSnapshot:
|
2016-11-18 11:53:57 +00:00
|
|
|
*
|
2022-01-05 11:36:55 +00:00
|
|
|
* `GtkSnapshot` assists in creating [class@Gsk.RenderNode]s for widgets.
|
2021-03-02 03:53:00 +00:00
|
|
|
*
|
|
|
|
* It functions in a similar way to a cairo context, and maintains a stack
|
|
|
|
* of render nodes and their associated transformations.
|
2016-11-18 11:53:57 +00:00
|
|
|
*
|
2022-01-05 11:36:55 +00:00
|
|
|
* The node at the top of the stack is the one that `gtk_snapshot_append_…()`
|
|
|
|
* functions operate on. Use the `gtk_snapshot_push_…()` functions and
|
|
|
|
* [method@Snapshot.pop] to change the current node.
|
2016-11-18 11:53:57 +00:00
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* The typical way to obtain a `GtkSnapshot` object is as an argument to
|
2021-05-18 21:05:26 +00:00
|
|
|
* the [vfunc@Gtk.Widget.snapshot] vfunc. If you need to create your own
|
2021-03-02 03:53:00 +00:00
|
|
|
* `GtkSnapshot`, use [ctor@Gtk.Snapshot.new].
|
2016-11-18 11:53:57 +00:00
|
|
|
*/
|
|
|
|
|
2020-07-02 20:59:40 +00:00
|
|
|
typedef struct _GtkSnapshotState GtkSnapshotState;
|
|
|
|
|
|
|
|
typedef GskRenderNode * (* GtkSnapshotCollectFunc) (GtkSnapshot *snapshot,
|
|
|
|
GtkSnapshotState *state,
|
|
|
|
GskRenderNode **nodes,
|
|
|
|
guint n_nodes);
|
2020-11-11 00:34:37 +00:00
|
|
|
typedef void (* GtkSnapshotClearFunc) (GtkSnapshotState *state);
|
2020-07-02 20:59:40 +00:00
|
|
|
|
|
|
|
struct _GtkSnapshotState {
|
|
|
|
guint start_node_index;
|
|
|
|
guint n_nodes;
|
|
|
|
|
|
|
|
GskTransform * transform;
|
|
|
|
|
|
|
|
GtkSnapshotCollectFunc collect_func;
|
2020-11-11 00:34:37 +00:00
|
|
|
GtkSnapshotClearFunc clear_func;
|
2020-07-02 20:59:40 +00:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
double opacity;
|
|
|
|
} opacity;
|
|
|
|
struct {
|
|
|
|
double radius;
|
|
|
|
} blur;
|
|
|
|
struct {
|
|
|
|
graphene_matrix_t matrix;
|
|
|
|
graphene_vec4_t offset;
|
|
|
|
} color_matrix;
|
|
|
|
struct {
|
|
|
|
graphene_rect_t bounds;
|
|
|
|
graphene_rect_t child_bounds;
|
|
|
|
} repeat;
|
|
|
|
struct {
|
|
|
|
graphene_rect_t bounds;
|
|
|
|
} clip;
|
2020-09-18 15:56:02 +00:00
|
|
|
struct {
|
|
|
|
GskGLShader *shader;
|
|
|
|
GBytes *args;
|
|
|
|
graphene_rect_t bounds;
|
|
|
|
GskRenderNode **nodes;
|
|
|
|
GskRenderNode *internal_nodes[4];
|
|
|
|
} glshader;
|
|
|
|
struct {
|
|
|
|
graphene_rect_t bounds;
|
|
|
|
int node_idx;
|
|
|
|
int n_children;
|
|
|
|
} glshader_texture;
|
2020-07-02 20:59:40 +00:00
|
|
|
struct {
|
|
|
|
GskRoundedRect bounds;
|
|
|
|
} rounded_clip;
|
|
|
|
struct {
|
|
|
|
gsize n_shadows;
|
|
|
|
GskShadow *shadows;
|
|
|
|
GskShadow a_shadow; /* Used if n_shadows == 1 */
|
|
|
|
} shadow;
|
|
|
|
struct {
|
|
|
|
GskBlendMode blend_mode;
|
|
|
|
GskRenderNode *bottom_node;
|
|
|
|
} blend;
|
|
|
|
struct {
|
|
|
|
double progress;
|
|
|
|
GskRenderNode *start_node;
|
|
|
|
} cross_fade;
|
|
|
|
struct {
|
|
|
|
char *message;
|
|
|
|
} debug;
|
|
|
|
} data;
|
|
|
|
};
|
|
|
|
|
2020-07-03 02:53:50 +00:00
|
|
|
static void gtk_snapshot_state_clear (GtkSnapshotState *state);
|
|
|
|
|
|
|
|
#define GDK_ARRAY_NAME gtk_snapshot_states
|
|
|
|
#define GDK_ARRAY_TYPE_NAME GtkSnapshotStates
|
|
|
|
#define GDK_ARRAY_ELEMENT_TYPE GtkSnapshotState
|
|
|
|
#define GDK_ARRAY_FREE_FUNC gtk_snapshot_state_clear
|
|
|
|
#define GDK_ARRAY_BY_VALUE 1
|
2020-09-29 14:03:06 +00:00
|
|
|
#define GDK_ARRAY_PREALLOC 16
|
|
|
|
#define GDK_ARRAY_NO_MEMSET 1
|
2020-07-03 02:53:50 +00:00
|
|
|
#include "gdk/gdkarrayimpl.c"
|
|
|
|
|
2020-07-02 20:59:40 +00:00
|
|
|
/* This is a nasty little hack. We typedef GtkSnapshot to the fake object GdkSnapshot
|
|
|
|
* so that we don't need to typecast between them.
|
|
|
|
* After all, the GdkSnapshot only exist so poor language bindings don't trip. Hardcore
|
|
|
|
* C code can just blatantly ignore such layering violations with a typedef.
|
|
|
|
*/
|
|
|
|
struct _GdkSnapshot {
|
|
|
|
GObject parent_instance; /* it's really GdkSnapshot, but don't tell anyone! */
|
|
|
|
|
2020-07-03 02:53:50 +00:00
|
|
|
GtkSnapshotStates state_stack;
|
2020-07-02 21:32:04 +00:00
|
|
|
GtkSnapshotNodes nodes;
|
2020-07-02 20:59:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkSnapshotClass {
|
|
|
|
GObjectClass parent_class; /* it's really GdkSnapshotClass, but don't tell anyone! */
|
|
|
|
};
|
|
|
|
|
2018-03-18 18:21:33 +00:00
|
|
|
G_DEFINE_TYPE (GtkSnapshot, gtk_snapshot, GDK_TYPE_SNAPSHOT)
|
2018-03-11 01:52:06 +00:00
|
|
|
|
2018-03-18 18:21:33 +00:00
|
|
|
static void
|
|
|
|
gtk_snapshot_dispose (GObject *object)
|
2018-03-11 01:52:06 +00:00
|
|
|
{
|
2018-03-18 18:21:33 +00:00
|
|
|
GtkSnapshot *snapshot = GTK_SNAPSHOT (object);
|
2018-03-11 01:52:06 +00:00
|
|
|
|
2020-07-03 02:53:50 +00:00
|
|
|
if (!gtk_snapshot_states_is_empty (&snapshot->state_stack))
|
2018-03-11 01:52:06 +00:00
|
|
|
gsk_render_node_unref (gtk_snapshot_to_node (snapshot));
|
|
|
|
|
2020-07-03 02:53:50 +00:00
|
|
|
g_assert (gtk_snapshot_states_is_empty (&snapshot->state_stack));
|
2020-07-02 21:32:04 +00:00
|
|
|
g_assert (gtk_snapshot_nodes_is_empty (&snapshot->nodes));
|
2018-03-11 01:52:06 +00:00
|
|
|
|
2018-03-18 18:21:33 +00:00
|
|
|
G_OBJECT_CLASS (gtk_snapshot_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_snapshot_class_init (GtkSnapshotClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->dispose = gtk_snapshot_dispose;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_snapshot_init (GtkSnapshot *self)
|
|
|
|
{
|
2018-03-11 01:52:06 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 08:40:24 +00:00
|
|
|
static GskRenderNode *
|
2018-03-20 17:55:33 +00:00
|
|
|
gtk_snapshot_collect_default (GtkSnapshot *snapshot,
|
|
|
|
GtkSnapshotState *state,
|
|
|
|
GskRenderNode **nodes,
|
2018-04-24 01:17:23 +00:00
|
|
|
guint n_nodes)
|
2016-12-13 08:40:24 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
|
|
|
|
|
|
|
if (n_nodes == 0)
|
|
|
|
{
|
|
|
|
node = NULL;
|
|
|
|
}
|
|
|
|
else if (n_nodes == 1)
|
|
|
|
{
|
|
|
|
node = gsk_render_node_ref (nodes[0]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
node = gsk_container_node_new (nodes, n_nodes);
|
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2016-11-17 00:55:26 +00:00
|
|
|
static GtkSnapshotState *
|
2017-10-01 11:49:01 +00:00
|
|
|
gtk_snapshot_push_state (GtkSnapshot *snapshot,
|
2019-02-28 08:52:49 +00:00
|
|
|
GskTransform *transform,
|
2020-11-11 00:34:37 +00:00
|
|
|
GtkSnapshotCollectFunc collect_func,
|
|
|
|
GtkSnapshotClearFunc clear_func)
|
2016-11-17 00:55:26 +00:00
|
|
|
{
|
2020-07-03 02:53:50 +00:00
|
|
|
const gsize n_states = gtk_snapshot_states_get_size (&snapshot->state_stack);
|
2019-01-11 09:05:44 +00:00
|
|
|
GtkSnapshotState *state;
|
2016-11-17 00:55:26 +00:00
|
|
|
|
2020-07-03 02:53:50 +00:00
|
|
|
gtk_snapshot_states_set_size (&snapshot->state_stack, n_states + 1);
|
|
|
|
state = gtk_snapshot_states_get (&snapshot->state_stack, n_states);
|
2018-04-05 16:18:55 +00:00
|
|
|
|
2019-02-28 08:52:49 +00:00
|
|
|
state->transform = gsk_transform_ref (transform);
|
2019-01-11 09:05:44 +00:00
|
|
|
state->collect_func = collect_func;
|
2020-11-11 00:34:37 +00:00
|
|
|
state->clear_func = clear_func;
|
2020-07-02 21:32:04 +00:00
|
|
|
state->start_node_index = gtk_snapshot_nodes_get_size (&snapshot->nodes);
|
2019-01-11 09:05:44 +00:00
|
|
|
state->n_nodes = 0;
|
2018-04-05 16:18:55 +00:00
|
|
|
|
2019-01-11 09:05:44 +00:00
|
|
|
return state;
|
2016-11-17 00:55:26 +00:00
|
|
|
}
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
static GtkSnapshotState *
|
|
|
|
gtk_snapshot_get_current_state (const GtkSnapshot *snapshot)
|
2017-01-11 10:41:46 +00:00
|
|
|
{
|
2020-07-03 02:53:50 +00:00
|
|
|
gsize size = gtk_snapshot_states_get_size (&snapshot->state_stack);
|
2017-10-01 11:49:01 +00:00
|
|
|
|
2020-07-03 02:53:50 +00:00
|
|
|
g_assert (size > 0);
|
|
|
|
|
|
|
|
return gtk_snapshot_states_get (&snapshot->state_stack, size - 1);
|
2017-10-01 11:49:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkSnapshotState *
|
|
|
|
gtk_snapshot_get_previous_state (const GtkSnapshot *snapshot)
|
|
|
|
{
|
2020-07-03 02:53:50 +00:00
|
|
|
gsize size = gtk_snapshot_states_get_size (&snapshot->state_stack);
|
|
|
|
|
|
|
|
g_assert (size > 1);
|
2017-10-01 11:49:01 +00:00
|
|
|
|
2020-07-03 02:53:50 +00:00
|
|
|
return gtk_snapshot_states_get (&snapshot->state_stack, size - 2);
|
2017-01-11 10:41:46 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 15:56:02 +00:00
|
|
|
/* n == 0 => current, n == 1, previous, etc */
|
|
|
|
static GtkSnapshotState *
|
|
|
|
gtk_snapshot_get_nth_previous_state (const GtkSnapshot *snapshot,
|
|
|
|
int n)
|
|
|
|
{
|
|
|
|
gsize size = gtk_snapshot_states_get_size (&snapshot->state_stack);
|
|
|
|
|
|
|
|
g_assert (size > n);
|
|
|
|
|
|
|
|
return gtk_snapshot_states_get (&snapshot->state_stack, size - (1 + n));
|
|
|
|
}
|
|
|
|
|
2016-11-17 00:55:26 +00:00
|
|
|
static void
|
2017-10-01 11:49:01 +00:00
|
|
|
gtk_snapshot_state_clear (GtkSnapshotState *state)
|
2016-11-17 00:55:26 +00:00
|
|
|
{
|
2020-11-11 00:34:37 +00:00
|
|
|
if (state->clear_func)
|
|
|
|
state->clear_func (state);
|
|
|
|
|
2019-02-28 08:52:49 +00:00
|
|
|
gsk_transform_unref (state->transform);
|
2018-03-20 17:55:33 +00:00
|
|
|
}
|
|
|
|
|
2018-03-11 02:29:46 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_new:
|
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* Creates a new `GtkSnapshot`.
|
2018-03-11 02:29:46 +00:00
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* Returns: a newly-allocated `GtkSnapshot`
|
2018-03-11 02:29:46 +00:00
|
|
|
*/
|
2018-03-11 01:52:06 +00:00
|
|
|
GtkSnapshot *
|
2018-04-24 01:17:23 +00:00
|
|
|
gtk_snapshot_new (void)
|
2018-03-20 17:55:33 +00:00
|
|
|
{
|
|
|
|
GtkSnapshot *snapshot;
|
2018-03-11 02:20:25 +00:00
|
|
|
|
2018-04-24 01:17:23 +00:00
|
|
|
snapshot = g_object_new (GTK_TYPE_SNAPSHOT, NULL);
|
2018-03-20 17:55:33 +00:00
|
|
|
|
2020-07-03 02:53:50 +00:00
|
|
|
gtk_snapshot_states_init (&snapshot->state_stack);
|
2020-07-02 21:32:04 +00:00
|
|
|
gtk_snapshot_nodes_init (&snapshot->nodes);
|
2018-03-20 17:55:33 +00:00
|
|
|
|
2018-04-24 01:17:23 +00:00
|
|
|
gtk_snapshot_push_state (snapshot,
|
2019-02-21 00:54:01 +00:00
|
|
|
NULL,
|
2020-11-11 00:34:37 +00:00
|
|
|
gtk_snapshot_collect_default,
|
|
|
|
NULL);
|
2018-03-20 17:55:33 +00:00
|
|
|
|
2018-03-11 01:52:06 +00:00
|
|
|
return snapshot;
|
|
|
|
}
|
|
|
|
|
2018-03-11 02:29:46 +00:00
|
|
|
/**
|
2018-03-18 18:21:33 +00:00
|
|
|
* gtk_snapshot_free_to_node: (skip)
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: (transfer full): a `GtkSnapshot`
|
2018-03-11 02:29:46 +00:00
|
|
|
*
|
|
|
|
* Returns the node that was constructed by @snapshot
|
|
|
|
* and frees @snapshot.
|
|
|
|
*
|
2022-01-23 22:11:07 +00:00
|
|
|
* Returns: (transfer full) (nullable): a newly-created [class@Gsk.RenderNode]
|
2018-03-11 02:29:46 +00:00
|
|
|
*/
|
2018-03-11 01:52:06 +00:00
|
|
|
GskRenderNode *
|
|
|
|
gtk_snapshot_free_to_node (GtkSnapshot *snapshot)
|
|
|
|
{
|
|
|
|
GskRenderNode *result;
|
|
|
|
|
|
|
|
result = gtk_snapshot_to_node (snapshot);
|
2018-03-18 18:21:33 +00:00
|
|
|
g_object_unref (snapshot);
|
2018-03-11 01:52:06 +00:00
|
|
|
|
|
|
|
return result;
|
2016-11-07 18:10:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-26 02:37:01 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_free_to_paintable: (skip)
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: (transfer full): a `GtkSnapshot`
|
2021-05-19 11:24:34 +00:00
|
|
|
* @size: (nullable): The size of the resulting paintable
|
2021-05-18 21:05:26 +00:00
|
|
|
* or %NULL to use the bounds of the snapshot
|
2018-03-26 02:37:01 +00:00
|
|
|
*
|
|
|
|
* Returns a paintable for the node that was
|
|
|
|
* constructed by @snapshot and frees @snapshot.
|
|
|
|
*
|
2022-01-23 22:11:07 +00:00
|
|
|
* Returns: (transfer full) (nullable): a newly-created [iface@Gdk.Paintable]
|
2018-03-26 02:37:01 +00:00
|
|
|
*/
|
|
|
|
GdkPaintable *
|
2018-04-02 04:15:50 +00:00
|
|
|
gtk_snapshot_free_to_paintable (GtkSnapshot *snapshot,
|
|
|
|
const graphene_size_t *size)
|
2018-03-26 02:37:01 +00:00
|
|
|
{
|
|
|
|
GdkPaintable *result;
|
|
|
|
|
2018-04-02 04:15:50 +00:00
|
|
|
result = gtk_snapshot_to_paintable (snapshot, size);
|
2018-03-26 02:37:01 +00:00
|
|
|
g_object_unref (snapshot);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-02-21 00:54:01 +00:00
|
|
|
static GskRenderNode *
|
|
|
|
gtk_snapshot_collect_autopush_transform (GtkSnapshot *snapshot,
|
|
|
|
GtkSnapshotState *state,
|
|
|
|
GskRenderNode **nodes,
|
|
|
|
guint n_nodes)
|
|
|
|
{
|
|
|
|
GskRenderNode *node, *transform_node;
|
2019-03-01 05:35:55 +00:00
|
|
|
GtkSnapshotState *previous_state;
|
|
|
|
|
|
|
|
previous_state = gtk_snapshot_get_previous_state (snapshot);
|
2019-02-21 00:54:01 +00:00
|
|
|
|
|
|
|
node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes);
|
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2019-03-01 05:35:55 +00:00
|
|
|
transform_node = gsk_transform_node_new (node, previous_state->transform);
|
2019-02-21 00:54:01 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
|
|
|
|
return transform_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_snapshot_autopush_transform (GtkSnapshot *snapshot)
|
|
|
|
{
|
2019-03-01 05:35:55 +00:00
|
|
|
gtk_snapshot_push_state (snapshot,
|
|
|
|
NULL,
|
2020-11-11 00:34:37 +00:00
|
|
|
gtk_snapshot_collect_autopush_transform,
|
|
|
|
NULL);
|
2019-02-21 00:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_snapshot_state_should_autopop (const GtkSnapshotState *state)
|
|
|
|
{
|
2019-02-21 03:24:24 +00:00
|
|
|
return state->collect_func == gtk_snapshot_collect_autopush_transform;
|
2019-02-21 00:54:01 +00:00
|
|
|
}
|
|
|
|
|
2018-04-24 01:17:23 +00:00
|
|
|
static GskRenderNode *
|
|
|
|
gtk_snapshot_collect_debug (GtkSnapshot *snapshot,
|
|
|
|
GtkSnapshotState *state,
|
|
|
|
GskRenderNode **nodes,
|
|
|
|
guint n_nodes)
|
|
|
|
{
|
|
|
|
GskRenderNode *node, *debug_node;
|
|
|
|
|
|
|
|
node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes);
|
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
debug_node = gsk_debug_node_new (node, state->data.debug.message);
|
2020-11-11 00:34:37 +00:00
|
|
|
state->data.debug.message = NULL;
|
2018-04-24 01:17:23 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
|
|
|
|
return debug_node;
|
|
|
|
}
|
|
|
|
|
2020-11-11 00:34:37 +00:00
|
|
|
static void
|
|
|
|
gtk_snapshot_clear_debug (GtkSnapshotState *state)
|
|
|
|
{
|
|
|
|
g_clear_pointer (&state->data.debug.message, g_free);
|
|
|
|
}
|
|
|
|
|
2019-02-24 20:29:08 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_push_debug:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2019-02-24 20:29:08 +00:00
|
|
|
* @message: a printf-style format string
|
|
|
|
* @...: arguments for @message
|
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* Inserts a debug node with a message.
|
|
|
|
*
|
|
|
|
* Debug nodes don't affect the rendering at all, but can be
|
|
|
|
* helpful in identifying parts of a render node tree dump,
|
|
|
|
* for example in the GTK inspector.
|
2019-02-24 20:29:08 +00:00
|
|
|
*/
|
2016-11-13 15:16:39 +00:00
|
|
|
void
|
2018-04-24 01:17:23 +00:00
|
|
|
gtk_snapshot_push_debug (GtkSnapshot *snapshot,
|
|
|
|
const char *message,
|
|
|
|
...)
|
2016-11-13 15:16:39 +00:00
|
|
|
{
|
2018-04-24 01:17:23 +00:00
|
|
|
GtkSnapshotState *current_state = gtk_snapshot_get_current_state (snapshot);
|
|
|
|
|
2018-04-24 02:02:55 +00:00
|
|
|
if (GTK_DEBUG_CHECK (SNAPSHOT))
|
2016-11-13 15:16:39 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
2020-07-12 09:33:34 +00:00
|
|
|
GtkSnapshotState *state;
|
|
|
|
|
|
|
|
state = gtk_snapshot_push_state (snapshot,
|
|
|
|
current_state->transform,
|
2020-11-11 00:34:37 +00:00
|
|
|
gtk_snapshot_collect_debug,
|
|
|
|
gtk_snapshot_clear_debug);
|
2020-07-12 09:33:34 +00:00
|
|
|
|
|
|
|
|
2016-11-13 15:16:39 +00:00
|
|
|
|
2018-04-24 01:17:23 +00:00
|
|
|
va_start (args, message);
|
|
|
|
state->data.debug.message = g_strdup_vprintf (message, args);
|
2016-11-13 15:16:39 +00:00
|
|
|
va_end (args);
|
|
|
|
}
|
2016-12-13 01:33:15 +00:00
|
|
|
else
|
|
|
|
{
|
2020-07-12 09:33:34 +00:00
|
|
|
gtk_snapshot_push_state (snapshot,
|
|
|
|
current_state->transform,
|
2020-11-11 00:34:37 +00:00
|
|
|
gtk_snapshot_collect_default,
|
|
|
|
NULL);
|
2016-12-13 08:40:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-17 07:06:59 +00:00
|
|
|
static GskRenderNode *
|
2017-10-01 11:49:01 +00:00
|
|
|
gtk_snapshot_collect_opacity (GtkSnapshot *snapshot,
|
|
|
|
GtkSnapshotState *state,
|
2018-04-24 01:17:23 +00:00
|
|
|
GskRenderNode **nodes,
|
|
|
|
guint n_nodes)
|
2016-12-17 07:06:59 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node, *opacity_node;
|
|
|
|
|
2018-04-24 01:17:23 +00:00
|
|
|
node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes);
|
2016-12-17 07:06:59 +00:00
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2017-10-19 10:01:02 +00:00
|
|
|
if (state->data.opacity.opacity == 1.0)
|
|
|
|
{
|
|
|
|
opacity_node = node;
|
|
|
|
}
|
|
|
|
else if (state->data.opacity.opacity == 0.0)
|
|
|
|
{
|
2021-07-15 17:14:13 +00:00
|
|
|
GdkRGBA color = GDK_RGBA ("00000000");
|
|
|
|
graphene_rect_t bounds;
|
|
|
|
|
|
|
|
gsk_render_node_get_bounds (node, &bounds);
|
|
|
|
opacity_node = gsk_color_node_new (&color, &bounds);
|
2017-10-19 10:01:02 +00:00
|
|
|
gsk_render_node_unref (node);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
opacity_node = gsk_opacity_node_new (node, state->data.opacity.opacity);
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
}
|
2016-12-17 07:06:59 +00:00
|
|
|
|
|
|
|
return opacity_node;
|
|
|
|
}
|
|
|
|
|
2019-02-24 20:29:08 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_push_opacity:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2019-02-24 20:29:08 +00:00
|
|
|
* @opacity: the opacity to use
|
|
|
|
*
|
|
|
|
* Modifies the opacity of an image.
|
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* The image is recorded until the next call to [method@Gtk.Snapshot.pop].
|
2019-02-24 20:29:08 +00:00
|
|
|
*/
|
2016-12-17 07:06:59 +00:00
|
|
|
void
|
|
|
|
gtk_snapshot_push_opacity (GtkSnapshot *snapshot,
|
2018-04-24 01:17:23 +00:00
|
|
|
double opacity)
|
2016-12-17 07:06:59 +00:00
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
GtkSnapshotState *current_state = gtk_snapshot_get_current_state (snapshot);
|
2017-01-11 10:21:27 +00:00
|
|
|
GtkSnapshotState *state;
|
2016-12-17 07:06:59 +00:00
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
state = gtk_snapshot_push_state (snapshot,
|
2019-02-21 00:54:01 +00:00
|
|
|
current_state->transform,
|
2020-11-11 00:34:37 +00:00
|
|
|
gtk_snapshot_collect_opacity,
|
|
|
|
NULL);
|
2017-10-19 10:01:02 +00:00
|
|
|
state->data.opacity.opacity = CLAMP (opacity, 0.0, 1.0);
|
2016-12-17 07:06:59 +00:00
|
|
|
}
|
|
|
|
|
2017-09-03 03:50:39 +00:00
|
|
|
static GskRenderNode *
|
2017-10-01 11:49:01 +00:00
|
|
|
gtk_snapshot_collect_blur (GtkSnapshot *snapshot,
|
|
|
|
GtkSnapshotState *state,
|
2018-04-24 01:17:23 +00:00
|
|
|
GskRenderNode **nodes,
|
|
|
|
guint n_nodes)
|
2017-09-03 03:50:39 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node, *blur_node;
|
2017-12-08 15:58:06 +00:00
|
|
|
double radius;
|
2017-09-03 03:50:39 +00:00
|
|
|
|
2018-04-24 01:17:23 +00:00
|
|
|
node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes);
|
2017-09-03 03:50:39 +00:00
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2017-12-08 15:58:06 +00:00
|
|
|
radius = state->data.blur.radius;
|
|
|
|
|
|
|
|
if (radius == 0.0)
|
|
|
|
return node;
|
|
|
|
|
2021-10-17 10:15:34 +00:00
|
|
|
if (radius < 0)
|
|
|
|
return node;
|
|
|
|
|
2017-12-08 15:58:06 +00:00
|
|
|
blur_node = gsk_blur_node_new (node, radius);
|
2017-09-03 03:50:39 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
|
|
|
|
return blur_node;
|
|
|
|
}
|
|
|
|
|
2019-02-24 20:29:08 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_push_blur:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2021-10-17 10:15:34 +00:00
|
|
|
* @radius: the blur radius to use. Must be positive
|
2019-02-24 20:29:08 +00:00
|
|
|
*
|
|
|
|
* Blurs an image.
|
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* The image is recorded until the next call to [method@Gtk.Snapshot.pop].
|
2019-02-24 20:29:08 +00:00
|
|
|
*/
|
2017-09-03 03:50:39 +00:00
|
|
|
void
|
|
|
|
gtk_snapshot_push_blur (GtkSnapshot *snapshot,
|
2018-04-24 01:17:23 +00:00
|
|
|
double radius)
|
2017-09-03 03:50:39 +00:00
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
const GtkSnapshotState *current_state = gtk_snapshot_get_current_state (snapshot);
|
2017-09-03 03:50:39 +00:00
|
|
|
GtkSnapshotState *state;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
state = gtk_snapshot_push_state (snapshot,
|
2019-02-21 00:54:01 +00:00
|
|
|
current_state->transform,
|
2020-11-11 00:34:37 +00:00
|
|
|
gtk_snapshot_collect_blur,
|
|
|
|
NULL);
|
2017-09-03 03:50:39 +00:00
|
|
|
state->data.blur.radius = radius;
|
|
|
|
}
|
|
|
|
|
2019-11-29 08:13:27 +00:00
|
|
|
static GskRenderNode *
|
|
|
|
merge_color_matrix_nodes (const graphene_matrix_t *matrix2,
|
|
|
|
const graphene_vec4_t *offset2,
|
|
|
|
GskRenderNode *child)
|
|
|
|
{
|
2020-11-16 23:59:36 +00:00
|
|
|
const graphene_matrix_t *mat1 = gsk_color_matrix_node_get_color_matrix (child);
|
|
|
|
const graphene_vec4_t *offset1 = gsk_color_matrix_node_get_color_offset (child);
|
2019-11-29 08:13:27 +00:00
|
|
|
graphene_matrix_t mat2 = *matrix2;
|
|
|
|
graphene_vec4_t off2 = *offset2;
|
|
|
|
GskRenderNode *result;
|
|
|
|
|
|
|
|
g_assert (gsk_render_node_get_node_type (child) == GSK_COLOR_MATRIX_NODE);
|
|
|
|
|
|
|
|
/* color matrix node: color = mat * p + offset; for a pixel p.
|
|
|
|
* color = mat1 * (mat2 * p + offset2) + offset1;
|
|
|
|
* = mat1 * mat2 * p + offset2 * mat1 + offset1
|
|
|
|
* = (mat1 * mat2) * p + (offset2 * mat1 + offset1)
|
|
|
|
* Which this code does.
|
|
|
|
* mat1 and offset1 come from @child.
|
|
|
|
*/
|
|
|
|
|
|
|
|
graphene_matrix_transform_vec4 (mat1, offset2, &off2);
|
|
|
|
graphene_vec4_add (&off2, offset1, &off2);
|
|
|
|
|
|
|
|
graphene_matrix_multiply (mat1, &mat2, &mat2);
|
|
|
|
|
2019-11-29 08:14:55 +00:00
|
|
|
result = gsk_color_matrix_node_new (gsk_color_matrix_node_get_child (child),
|
|
|
|
&mat2, &off2);
|
2019-11-29 08:13:27 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-12-31 00:14:59 +00:00
|
|
|
static GskRenderNode *
|
2017-10-01 11:49:01 +00:00
|
|
|
gtk_snapshot_collect_color_matrix (GtkSnapshot *snapshot,
|
|
|
|
GtkSnapshotState *state,
|
2017-01-11 10:21:27 +00:00
|
|
|
GskRenderNode **nodes,
|
2018-04-24 01:17:23 +00:00
|
|
|
guint n_nodes)
|
2016-12-31 00:14:59 +00:00
|
|
|
{
|
2019-11-29 08:13:27 +00:00
|
|
|
GskRenderNode *node, *result;
|
2016-12-31 00:14:59 +00:00
|
|
|
|
2018-04-24 01:17:23 +00:00
|
|
|
node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes);
|
2016-12-31 00:14:59 +00:00
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2017-12-06 14:53:15 +00:00
|
|
|
if (gsk_render_node_get_node_type (node) == GSK_COLOR_MATRIX_NODE)
|
|
|
|
{
|
2019-11-29 08:13:27 +00:00
|
|
|
result = merge_color_matrix_nodes (&state->data.color_matrix.matrix,
|
|
|
|
&state->data.color_matrix.offset,
|
|
|
|
node);
|
2019-11-29 08:14:55 +00:00
|
|
|
gsk_render_node_unref (node);
|
|
|
|
}
|
|
|
|
else if (gsk_render_node_get_node_type (node) == GSK_TRANSFORM_NODE)
|
|
|
|
{
|
|
|
|
GskRenderNode *transform_child = gsk_transform_node_get_child (node);
|
|
|
|
GskRenderNode *color_matrix;
|
|
|
|
|
|
|
|
if (gsk_render_node_get_node_type (transform_child) == GSK_COLOR_MATRIX_NODE)
|
|
|
|
{
|
|
|
|
color_matrix = merge_color_matrix_nodes (&state->data.color_matrix.matrix,
|
|
|
|
&state->data.color_matrix.offset,
|
|
|
|
transform_child);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
color_matrix = gsk_color_matrix_node_new (transform_child,
|
|
|
|
&state->data.color_matrix.matrix,
|
|
|
|
&state->data.color_matrix.offset);
|
|
|
|
}
|
|
|
|
result = gsk_transform_node_new (color_matrix,
|
|
|
|
gsk_transform_node_get_transform (node));
|
|
|
|
gsk_render_node_unref (color_matrix);
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
node = NULL;
|
2017-12-06 14:53:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-29 08:13:27 +00:00
|
|
|
result = gsk_color_matrix_node_new (node,
|
|
|
|
&state->data.color_matrix.matrix,
|
|
|
|
&state->data.color_matrix.offset);
|
2017-12-06 14:53:15 +00:00
|
|
|
gsk_render_node_unref (node);
|
|
|
|
}
|
|
|
|
|
2019-11-29 08:13:27 +00:00
|
|
|
return result;
|
2016-12-31 00:14:59 +00:00
|
|
|
}
|
|
|
|
|
2019-02-24 20:29:08 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_push_color_matrix:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2019-02-24 20:29:08 +00:00
|
|
|
* @color_matrix: the color matrix to use
|
|
|
|
* @color_offset: the color offset to use
|
|
|
|
*
|
|
|
|
* Modifies the colors of an image by applying an affine transformation
|
|
|
|
* in RGB space.
|
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* The image is recorded until the next call to [method@Gtk.Snapshot.pop].
|
2019-02-24 20:29:08 +00:00
|
|
|
*/
|
2016-12-31 00:14:59 +00:00
|
|
|
void
|
|
|
|
gtk_snapshot_push_color_matrix (GtkSnapshot *snapshot,
|
|
|
|
const graphene_matrix_t *color_matrix,
|
2018-04-24 01:17:23 +00:00
|
|
|
const graphene_vec4_t *color_offset)
|
2016-12-31 00:14:59 +00:00
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
const GtkSnapshotState *current_state = gtk_snapshot_get_current_state (snapshot);
|
2017-01-11 10:21:27 +00:00
|
|
|
GtkSnapshotState *state;
|
2016-12-31 00:14:59 +00:00
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
state = gtk_snapshot_push_state (snapshot,
|
2019-02-21 00:54:01 +00:00
|
|
|
current_state->transform,
|
2020-11-11 00:34:37 +00:00
|
|
|
gtk_snapshot_collect_color_matrix,
|
|
|
|
NULL);
|
2016-12-31 00:14:59 +00:00
|
|
|
|
2017-01-11 10:21:27 +00:00
|
|
|
graphene_matrix_init_from_matrix (&state->data.color_matrix.matrix, color_matrix);
|
|
|
|
graphene_vec4_init_from_vec4 (&state->data.color_matrix.offset, color_offset);
|
2016-12-31 00:14:59 +00:00
|
|
|
}
|
|
|
|
|
2017-01-01 18:52:18 +00:00
|
|
|
static GskRenderNode *
|
2017-10-01 11:49:01 +00:00
|
|
|
gtk_snapshot_collect_repeat (GtkSnapshot *snapshot,
|
|
|
|
GtkSnapshotState *state,
|
2017-01-11 10:21:27 +00:00
|
|
|
GskRenderNode **nodes,
|
2018-04-24 01:17:23 +00:00
|
|
|
guint n_nodes)
|
2017-01-01 18:52:18 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node, *repeat_node;
|
2019-12-19 08:15:13 +00:00
|
|
|
const graphene_rect_t *bounds = &state->data.repeat.bounds;
|
|
|
|
const graphene_rect_t *child_bounds = &state->data.repeat.child_bounds;
|
2017-01-01 18:52:18 +00:00
|
|
|
|
2018-04-24 01:17:23 +00:00
|
|
|
node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes);
|
2017-01-01 18:52:18 +00:00
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2019-12-19 08:15:13 +00:00
|
|
|
if (gsk_render_node_get_node_type (node) == GSK_COLOR_NODE &&
|
|
|
|
graphene_rect_equal (child_bounds, &node->bounds))
|
|
|
|
{
|
|
|
|
/* Repeating a color node entirely is pretty easy by just increasing
|
|
|
|
* the size of the color node. */
|
2020-11-16 23:59:36 +00:00
|
|
|
GskRenderNode *color_node = gsk_color_node_new (gsk_color_node_get_color (node), bounds);
|
2019-12-19 08:15:13 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
|
|
|
|
return color_node;
|
|
|
|
}
|
|
|
|
|
2017-01-11 10:21:27 +00:00
|
|
|
repeat_node = gsk_repeat_node_new (bounds,
|
2017-01-01 18:52:18 +00:00
|
|
|
node,
|
2017-01-11 10:21:27 +00:00
|
|
|
child_bounds->size.width > 0 ? child_bounds : NULL);
|
2017-01-01 18:52:18 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
|
|
|
|
return repeat_node;
|
|
|
|
}
|
|
|
|
|
2019-02-21 00:54:01 +00:00
|
|
|
static void
|
|
|
|
gtk_graphene_rect_scale_affine (const graphene_rect_t *rect,
|
|
|
|
float scale_x,
|
|
|
|
float scale_y,
|
|
|
|
float dx,
|
|
|
|
float dy,
|
|
|
|
graphene_rect_t *res)
|
|
|
|
{
|
|
|
|
res->origin.x = scale_x * rect->origin.x + dx;
|
|
|
|
res->origin.y = scale_y * rect->origin.y + dy;
|
|
|
|
res->size.width = scale_x * rect->size.width;
|
|
|
|
res->size.height = scale_y * rect->size.height;
|
2019-12-31 07:54:42 +00:00
|
|
|
|
|
|
|
if (scale_x < 0 || scale_y < 0)
|
|
|
|
graphene_rect_normalize (res);
|
2019-02-21 00:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_snapshot_ensure_affine (GtkSnapshot *snapshot,
|
|
|
|
float *scale_x,
|
|
|
|
float *scale_y,
|
|
|
|
float *dx,
|
|
|
|
float *dy)
|
|
|
|
{
|
2019-03-04 18:33:04 +00:00
|
|
|
const GtkSnapshotState *state = gtk_snapshot_get_current_state (snapshot);
|
2019-02-21 00:54:01 +00:00
|
|
|
|
2019-03-04 18:33:04 +00:00
|
|
|
if (gsk_transform_get_category (state->transform) < GSK_TRANSFORM_CATEGORY_2D_AFFINE)
|
|
|
|
{
|
|
|
|
gtk_snapshot_autopush_transform (snapshot);
|
|
|
|
state = gtk_snapshot_get_current_state (snapshot);
|
2020-09-28 14:09:06 +00:00
|
|
|
gsk_transform_to_affine (state->transform, scale_x, scale_y, dx, dy);
|
|
|
|
}
|
|
|
|
else if (gsk_transform_get_category (state->transform) == GSK_TRANSFORM_CATEGORY_2D_AFFINE)
|
|
|
|
{
|
|
|
|
gsk_transform_to_affine (state->transform, scale_x, scale_y, dx, dy);
|
|
|
|
if (*scale_x < 0.0 || *scale_y < 0.0)
|
|
|
|
{
|
|
|
|
gtk_snapshot_autopush_transform (snapshot);
|
|
|
|
state = gtk_snapshot_get_current_state (snapshot);
|
|
|
|
gsk_transform_to_affine (state->transform, scale_x, scale_y, dx, dy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gsk_transform_to_affine (state->transform, scale_x, scale_y, dx, dy);
|
2019-03-04 18:33:04 +00:00
|
|
|
}
|
2019-02-21 00:54:01 +00:00
|
|
|
}
|
|
|
|
|
2019-02-21 02:07:14 +00:00
|
|
|
static void
|
|
|
|
gtk_snapshot_ensure_translate (GtkSnapshot *snapshot,
|
|
|
|
float *dx,
|
|
|
|
float *dy)
|
|
|
|
{
|
2019-03-04 18:33:04 +00:00
|
|
|
const GtkSnapshotState *state = gtk_snapshot_get_current_state (snapshot);
|
2019-02-21 02:07:14 +00:00
|
|
|
|
2019-03-04 18:33:04 +00:00
|
|
|
if (gsk_transform_get_category (state->transform) < GSK_TRANSFORM_CATEGORY_2D_TRANSLATE)
|
|
|
|
{
|
|
|
|
gtk_snapshot_autopush_transform (snapshot);
|
|
|
|
state = gtk_snapshot_get_current_state (snapshot);
|
|
|
|
}
|
|
|
|
|
|
|
|
gsk_transform_to_translate (state->transform, dx, dy);
|
2019-02-21 02:07:14 +00:00
|
|
|
}
|
|
|
|
|
2019-02-21 00:54:01 +00:00
|
|
|
static void
|
|
|
|
gtk_snapshot_ensure_identity (GtkSnapshot *snapshot)
|
|
|
|
{
|
|
|
|
const GtkSnapshotState *state = gtk_snapshot_get_current_state (snapshot);
|
|
|
|
|
2019-03-04 18:33:04 +00:00
|
|
|
if (gsk_transform_get_category (state->transform) < GSK_TRANSFORM_CATEGORY_IDENTITY)
|
|
|
|
gtk_snapshot_autopush_transform (snapshot);
|
2019-02-21 00:54:01 +00:00
|
|
|
}
|
|
|
|
|
2019-05-02 02:57:49 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_push_repeat:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2019-05-02 02:57:49 +00:00
|
|
|
* @bounds: the bounds within which to repeat
|
2019-08-10 06:43:44 +00:00
|
|
|
* @child_bounds: (nullable): the bounds of the child or %NULL
|
|
|
|
* to use the full size of the collected child node
|
2019-05-02 02:57:49 +00:00
|
|
|
*
|
|
|
|
* Creates a node that repeats the child node.
|
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* The child is recorded until the next call to [method@Gtk.Snapshot.pop].
|
2019-05-02 02:57:49 +00:00
|
|
|
*/
|
2017-01-01 18:52:18 +00:00
|
|
|
void
|
|
|
|
gtk_snapshot_push_repeat (GtkSnapshot *snapshot,
|
|
|
|
const graphene_rect_t *bounds,
|
2018-04-24 01:17:23 +00:00
|
|
|
const graphene_rect_t *child_bounds)
|
2017-01-01 18:52:18 +00:00
|
|
|
{
|
2017-01-11 10:21:27 +00:00
|
|
|
GtkSnapshotState *state;
|
|
|
|
graphene_rect_t real_child_bounds = { { 0 } };
|
2019-02-21 00:54:01 +00:00
|
|
|
float scale_x, scale_y, dx, dy;
|
|
|
|
|
|
|
|
gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &dx, &dy);
|
2017-01-01 18:52:18 +00:00
|
|
|
|
|
|
|
if (child_bounds)
|
2019-02-21 00:54:01 +00:00
|
|
|
gtk_graphene_rect_scale_affine (child_bounds, scale_x, scale_y, dx, dy, &real_child_bounds);
|
2017-01-01 18:52:18 +00:00
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
state = gtk_snapshot_push_state (snapshot,
|
2019-02-21 00:54:01 +00:00
|
|
|
gtk_snapshot_get_current_state (snapshot)->transform,
|
2020-11-11 00:34:37 +00:00
|
|
|
gtk_snapshot_collect_repeat,
|
|
|
|
NULL);
|
2017-10-01 11:49:01 +00:00
|
|
|
|
2019-02-21 00:54:01 +00:00
|
|
|
gtk_graphene_rect_scale_affine (bounds, scale_x, scale_y, dx, dy, &state->data.repeat.bounds);
|
2017-01-11 10:21:27 +00:00
|
|
|
state->data.repeat.child_bounds = real_child_bounds;
|
2017-01-01 18:52:18 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 08:40:24 +00:00
|
|
|
static GskRenderNode *
|
2017-10-01 11:49:01 +00:00
|
|
|
gtk_snapshot_collect_clip (GtkSnapshot *snapshot,
|
|
|
|
GtkSnapshotState *state,
|
2017-01-11 10:21:27 +00:00
|
|
|
GskRenderNode **nodes,
|
2018-04-24 01:17:23 +00:00
|
|
|
guint n_nodes)
|
2016-12-13 08:40:24 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node, *clip_node;
|
|
|
|
|
2018-04-24 01:17:23 +00:00
|
|
|
node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes);
|
2016-12-13 08:40:24 +00:00
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2017-12-01 06:38:43 +00:00
|
|
|
/* Check if the child node will even be clipped */
|
|
|
|
if (graphene_rect_contains_rect (&state->data.clip.bounds, &node->bounds))
|
|
|
|
return node;
|
|
|
|
|
2017-12-28 09:52:57 +00:00
|
|
|
if (state->data.clip.bounds.size.width == 0 ||
|
|
|
|
state->data.clip.bounds.size.height == 0)
|
|
|
|
return NULL;
|
|
|
|
|
2017-12-01 08:08:57 +00:00
|
|
|
clip_node = gsk_clip_node_new (node, &state->data.clip.bounds);
|
2016-12-13 08:40:24 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
|
|
|
|
return clip_node;
|
|
|
|
}
|
|
|
|
|
2019-02-24 20:29:08 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_push_clip:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2019-02-24 20:29:08 +00:00
|
|
|
* @bounds: the rectangle to clip to
|
|
|
|
*
|
|
|
|
* Clips an image to a rectangle.
|
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* The image is recorded until the next call to [method@Gtk.Snapshot.pop].
|
2019-02-24 20:29:08 +00:00
|
|
|
*/
|
2016-12-13 08:40:24 +00:00
|
|
|
void
|
|
|
|
gtk_snapshot_push_clip (GtkSnapshot *snapshot,
|
2018-04-24 01:17:23 +00:00
|
|
|
const graphene_rect_t *bounds)
|
2016-12-13 08:40:24 +00:00
|
|
|
{
|
2017-01-11 10:21:27 +00:00
|
|
|
GtkSnapshotState *state;
|
2019-02-21 00:54:01 +00:00
|
|
|
float scale_x, scale_y, dx, dy;
|
|
|
|
|
|
|
|
gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &dx, &dy);
|
2016-12-13 08:40:24 +00:00
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
state = gtk_snapshot_push_state (snapshot,
|
2019-02-21 00:54:01 +00:00
|
|
|
gtk_snapshot_get_current_state (snapshot)->transform,
|
2020-11-11 00:34:37 +00:00
|
|
|
gtk_snapshot_collect_clip,
|
|
|
|
NULL);
|
2017-01-11 10:21:27 +00:00
|
|
|
|
2019-02-21 00:54:01 +00:00
|
|
|
gtk_graphene_rect_scale_affine (bounds, scale_x, scale_y, dx, dy, &state->data.clip.bounds);
|
2016-11-13 15:16:39 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 15:56:02 +00:00
|
|
|
static GskRenderNode *
|
|
|
|
gtk_snapshot_collect_gl_shader (GtkSnapshot *snapshot,
|
|
|
|
GtkSnapshotState *state,
|
|
|
|
GskRenderNode **collected_nodes,
|
|
|
|
guint n_collected_nodes)
|
|
|
|
{
|
|
|
|
GskRenderNode *shader_node = NULL;
|
|
|
|
GskRenderNode **nodes;
|
|
|
|
int n_children;
|
|
|
|
|
|
|
|
n_children = gsk_gl_shader_get_n_textures (state->data.glshader.shader);
|
|
|
|
shader_node = NULL;
|
|
|
|
|
|
|
|
if (n_collected_nodes != 0)
|
|
|
|
g_warning ("Unexpected children when poping gl shader.");
|
|
|
|
|
|
|
|
if (state->data.glshader.nodes)
|
|
|
|
nodes = state->data.glshader.nodes;
|
|
|
|
else
|
|
|
|
nodes = &state->data.glshader.internal_nodes[0];
|
|
|
|
|
|
|
|
if (state->data.glshader.bounds.size.width != 0 &&
|
|
|
|
state->data.glshader.bounds.size.height != 0)
|
|
|
|
shader_node = gsk_gl_shader_node_new (state->data.glshader.shader,
|
|
|
|
&state->data.glshader.bounds,
|
|
|
|
state->data.glshader.args,
|
|
|
|
nodes, n_children);
|
|
|
|
|
2020-11-11 00:34:37 +00:00
|
|
|
return shader_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_snapshot_clear_gl_shader (GtkSnapshotState *state)
|
|
|
|
{
|
|
|
|
GskRenderNode **nodes;
|
|
|
|
guint i, n_children;
|
|
|
|
|
|
|
|
n_children = gsk_gl_shader_get_n_textures (state->data.glshader.shader);
|
|
|
|
|
|
|
|
if (state->data.glshader.nodes)
|
|
|
|
nodes = state->data.glshader.nodes;
|
|
|
|
else
|
|
|
|
nodes = &state->data.glshader.internal_nodes[0];
|
|
|
|
|
2020-09-18 15:56:02 +00:00
|
|
|
g_object_unref (state->data.glshader.shader);
|
|
|
|
g_bytes_unref (state->data.glshader.args);
|
|
|
|
|
2020-11-11 00:34:37 +00:00
|
|
|
for (i = 0; i < n_children; i++)
|
2020-09-18 15:56:02 +00:00
|
|
|
gsk_render_node_unref (nodes[i]);
|
|
|
|
|
|
|
|
g_free (state->data.glshader.nodes);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static GskRenderNode *
|
|
|
|
gtk_snapshot_collect_gl_shader_texture (GtkSnapshot *snapshot,
|
|
|
|
GtkSnapshotState *state,
|
|
|
|
GskRenderNode **nodes,
|
|
|
|
guint n_nodes)
|
|
|
|
{
|
|
|
|
GskRenderNode *child_node;
|
|
|
|
GdkRGBA transparent = { 0, 0, 0, 0 };
|
|
|
|
int n_children, node_idx;
|
|
|
|
GtkSnapshotState *glshader_state;
|
|
|
|
GskRenderNode **out_nodes;
|
|
|
|
|
|
|
|
child_node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes);
|
|
|
|
|
|
|
|
if (child_node == NULL)
|
|
|
|
child_node = gsk_color_node_new (&transparent, &state->data.glshader_texture.bounds);
|
|
|
|
|
|
|
|
n_children = state->data.glshader_texture.n_children;
|
|
|
|
node_idx = state->data.glshader_texture.node_idx;
|
|
|
|
|
|
|
|
glshader_state = gtk_snapshot_get_nth_previous_state (snapshot, n_children - node_idx);
|
|
|
|
g_assert (glshader_state->collect_func == gtk_snapshot_collect_gl_shader);
|
|
|
|
|
|
|
|
if (glshader_state->data.glshader.nodes)
|
|
|
|
out_nodes = glshader_state->data.glshader.nodes;
|
|
|
|
else
|
|
|
|
out_nodes = &glshader_state->data.glshader.internal_nodes[0];
|
|
|
|
|
|
|
|
out_nodes[node_idx] = child_node;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_snapshot_push_gl_shader:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2020-09-18 15:56:02 +00:00
|
|
|
* @shader: The code to run
|
|
|
|
* @bounds: the rectangle to render into
|
|
|
|
* @take_args: (transfer full): Data block with arguments for the shader.
|
|
|
|
*
|
2022-01-05 11:36:55 +00:00
|
|
|
* Push a [class@Gsk.GLShaderNode].
|
2021-03-02 03:53:00 +00:00
|
|
|
*
|
|
|
|
* The node uses the given [class@Gsk.GLShader] and uniform values
|
|
|
|
* Additionally this takes a list of @n_children other nodes
|
2022-01-05 11:36:55 +00:00
|
|
|
* which will be passed to the [class@Gsk.GLShaderNode].
|
2020-09-18 15:56:02 +00:00
|
|
|
*
|
|
|
|
* The @take_args argument is a block of data to use for uniform
|
2021-03-02 03:53:00 +00:00
|
|
|
* arguments, 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:56:02 +00:00
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* The snapshotter takes ownership of @take_args, so the caller should
|
|
|
|
* not free it after this.
|
2020-09-18 15:56:02 +00:00
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* 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 [method@Gsk.GLShader.compile] to ensure the @shader
|
|
|
|
* will work for the renderer before using it.
|
2020-09-18 15:56:02 +00:00
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* If the shader requires textures (see [method@Gsk.GLShader.get_n_textures]),
|
|
|
|
* then it is expected that you call [method@Gtk.Snapshot.gl_shader_pop_texture]
|
|
|
|
* the number of times that are required. Each of these calls will generate
|
|
|
|
* a node that is added as a child to the `GskGLShaderNode`, which in turn
|
|
|
|
* will render these offscreen and pass as a texture to the shader.
|
2020-09-18 15:56:02 +00:00
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* Once all textures (if any) are pop:ed, you must call the regular
|
|
|
|
* [method@Gtk.Snapshot.pop].
|
2020-09-18 15:56:02 +00:00
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* If you want to use pre-existing textures as input to the shader rather
|
|
|
|
* than rendering new ones, use [method@Gtk.Snapshot.append_texture] to
|
|
|
|
* push a texture node. These will be used directly rather than being
|
|
|
|
* re-rendered.
|
|
|
|
*
|
|
|
|
* For details on how to write shaders, see [class@Gsk.GLShader].
|
2020-09-18 15:56:02 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_snapshot_push_gl_shader (GtkSnapshot *snapshot,
|
|
|
|
GskGLShader *shader,
|
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
GBytes *take_args)
|
|
|
|
{
|
|
|
|
GtkSnapshotState *state;
|
|
|
|
float scale_x, scale_y, dx, dy;
|
|
|
|
graphene_rect_t transformed_bounds;
|
|
|
|
int n_children = gsk_gl_shader_get_n_textures (shader);
|
|
|
|
|
|
|
|
gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &dx, &dy);
|
|
|
|
|
|
|
|
state = gtk_snapshot_push_state (snapshot,
|
|
|
|
gtk_snapshot_get_current_state (snapshot)->transform,
|
2020-11-11 00:34:37 +00:00
|
|
|
gtk_snapshot_collect_gl_shader,
|
|
|
|
gtk_snapshot_clear_gl_shader);
|
2020-09-18 15:56:02 +00:00
|
|
|
gtk_graphene_rect_scale_affine (bounds, scale_x, scale_y, dx, dy, &transformed_bounds);
|
|
|
|
state->data.glshader.bounds = transformed_bounds;
|
|
|
|
state->data.glshader.shader = g_object_ref (shader);
|
|
|
|
state->data.glshader.args = take_args; /* Takes ownership */
|
|
|
|
if (n_children <= G_N_ELEMENTS (state->data.glshader.internal_nodes))
|
|
|
|
state->data.glshader.nodes = NULL;
|
|
|
|
else
|
|
|
|
state->data.glshader.nodes = g_new (GskRenderNode *, n_children);
|
|
|
|
|
|
|
|
for (int i = 0; i < n_children; i++)
|
|
|
|
{
|
|
|
|
state = gtk_snapshot_push_state (snapshot,
|
|
|
|
gtk_snapshot_get_current_state (snapshot)->transform,
|
2020-11-11 00:34:37 +00:00
|
|
|
gtk_snapshot_collect_gl_shader_texture,
|
|
|
|
NULL);
|
2020-09-18 15:56:02 +00:00
|
|
|
state->data.glshader_texture.bounds = transformed_bounds;
|
|
|
|
state->data.glshader_texture.node_idx = n_children - 1 - i;/* We pop in reverse order */
|
|
|
|
state->data.glshader_texture.n_children = n_children;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 20:59:28 +00:00
|
|
|
static GskRenderNode *
|
2017-10-01 11:49:01 +00:00
|
|
|
gtk_snapshot_collect_rounded_clip (GtkSnapshot *snapshot,
|
|
|
|
GtkSnapshotState *state,
|
2017-01-11 10:21:27 +00:00
|
|
|
GskRenderNode **nodes,
|
2018-04-24 01:17:23 +00:00
|
|
|
guint n_nodes)
|
2016-12-13 20:59:28 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node, *clip_node;
|
|
|
|
|
2018-04-24 01:17:23 +00:00
|
|
|
node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes);
|
2016-12-13 20:59:28 +00:00
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2017-12-01 07:04:31 +00:00
|
|
|
/* If the given radius is 0 in all corners, we can just create a normal clip node */
|
|
|
|
if (gsk_rounded_rect_is_rectilinear (&state->data.rounded_clip.bounds))
|
|
|
|
{
|
|
|
|
/* ... and do the same optimization */
|
|
|
|
if (graphene_rect_contains_rect (&state->data.rounded_clip.bounds.bounds, &node->bounds))
|
|
|
|
return node;
|
|
|
|
|
|
|
|
clip_node = gsk_clip_node_new (node, &state->data.rounded_clip.bounds.bounds);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (gsk_rounded_rect_contains_rect (&state->data.rounded_clip.bounds, &node->bounds))
|
|
|
|
return node;
|
|
|
|
|
|
|
|
clip_node = gsk_rounded_clip_node_new (node, &state->data.rounded_clip.bounds);
|
|
|
|
}
|
|
|
|
|
2018-03-14 09:51:55 +00:00
|
|
|
if (clip_node->bounds.size.width == 0 ||
|
|
|
|
clip_node->bounds.size.height == 0)
|
2018-03-31 09:41:13 +00:00
|
|
|
{
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
gsk_render_node_unref (clip_node);
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-03-14 09:51:55 +00:00
|
|
|
|
2016-12-13 20:59:28 +00:00
|
|
|
gsk_render_node_unref (node);
|
|
|
|
|
|
|
|
return clip_node;
|
|
|
|
}
|
|
|
|
|
2019-02-24 20:29:08 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_push_rounded_clip:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2019-02-24 20:29:08 +00:00
|
|
|
* @bounds: the rounded rectangle to clip to
|
|
|
|
*
|
|
|
|
* Clips an image to a rounded rectangle.
|
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* The image is recorded until the next call to [method@Gtk.Snapshot.pop].
|
2019-02-24 20:29:08 +00:00
|
|
|
*/
|
2016-12-13 20:59:28 +00:00
|
|
|
void
|
|
|
|
gtk_snapshot_push_rounded_clip (GtkSnapshot *snapshot,
|
2018-04-24 01:17:23 +00:00
|
|
|
const GskRoundedRect *bounds)
|
2016-12-13 20:59:28 +00:00
|
|
|
{
|
2017-01-11 10:21:27 +00:00
|
|
|
GtkSnapshotState *state;
|
2019-02-21 00:54:01 +00:00
|
|
|
float scale_x, scale_y, dx, dy;
|
2016-12-13 20:59:28 +00:00
|
|
|
|
2019-02-21 00:54:01 +00:00
|
|
|
gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &dx, &dy);
|
2016-12-13 20:59:28 +00:00
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
state = gtk_snapshot_push_state (snapshot,
|
2019-02-21 00:54:01 +00:00
|
|
|
gtk_snapshot_get_current_state (snapshot)->transform,
|
2020-11-11 00:34:37 +00:00
|
|
|
gtk_snapshot_collect_rounded_clip,
|
|
|
|
NULL);
|
2017-01-11 10:21:27 +00:00
|
|
|
|
2021-03-07 19:35:44 +00:00
|
|
|
gsk_rounded_rect_scale_affine (&state->data.rounded_clip.bounds, bounds, scale_x, scale_y, dx, dy);
|
2016-12-13 20:59:28 +00:00
|
|
|
}
|
|
|
|
|
2016-12-18 23:45:35 +00:00
|
|
|
static GskRenderNode *
|
2017-10-01 11:49:01 +00:00
|
|
|
gtk_snapshot_collect_shadow (GtkSnapshot *snapshot,
|
|
|
|
GtkSnapshotState *state,
|
2017-01-11 10:21:27 +00:00
|
|
|
GskRenderNode **nodes,
|
2018-04-24 01:17:23 +00:00
|
|
|
guint n_nodes)
|
2016-12-18 23:45:35 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node, *shadow_node;
|
|
|
|
|
2018-04-24 01:17:23 +00:00
|
|
|
node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes);
|
2016-12-18 23:45:35 +00:00
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
shadow_node = gsk_shadow_node_new (node,
|
|
|
|
state->data.shadow.shadows != NULL ?
|
|
|
|
state->data.shadow.shadows :
|
|
|
|
&state->data.shadow.a_shadow,
|
|
|
|
state->data.shadow.n_shadows);
|
2016-12-18 23:45:35 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
|
|
|
|
return shadow_node;
|
|
|
|
}
|
|
|
|
|
2020-11-11 00:34:37 +00:00
|
|
|
static void
|
|
|
|
gtk_snapshot_clear_shadow (GtkSnapshotState *state)
|
|
|
|
{
|
|
|
|
g_free (state->data.shadow.shadows);
|
|
|
|
}
|
|
|
|
|
2019-02-24 20:29:08 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_push_shadow:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2021-10-12 09:00:03 +00:00
|
|
|
* @shadow: (array length=n_shadows): the first shadow specification
|
2019-02-24 20:29:08 +00:00
|
|
|
* @n_shadows: number of shadow specifications
|
|
|
|
*
|
|
|
|
* Applies a shadow to an image.
|
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* The image is recorded until the next call to [method@Gtk.Snapshot.pop].
|
2019-02-24 20:29:08 +00:00
|
|
|
*/
|
2016-12-18 23:45:35 +00:00
|
|
|
void
|
2018-04-24 01:17:23 +00:00
|
|
|
gtk_snapshot_push_shadow (GtkSnapshot *snapshot,
|
|
|
|
const GskShadow *shadow,
|
|
|
|
gsize n_shadows)
|
2016-12-18 23:45:35 +00:00
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
const GtkSnapshotState *current_state = gtk_snapshot_get_current_state (snapshot);
|
2017-01-11 10:21:27 +00:00
|
|
|
GtkSnapshotState *state;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
state = gtk_snapshot_push_state (snapshot,
|
2019-02-21 00:54:01 +00:00
|
|
|
current_state->transform,
|
2020-11-11 00:34:37 +00:00
|
|
|
gtk_snapshot_collect_shadow,
|
|
|
|
gtk_snapshot_clear_shadow);
|
2017-01-11 10:21:27 +00:00
|
|
|
|
|
|
|
state->data.shadow.n_shadows = n_shadows;
|
|
|
|
if (n_shadows == 1)
|
2017-10-01 11:49:01 +00:00
|
|
|
{
|
|
|
|
state->data.shadow.shadows = NULL;
|
|
|
|
memcpy (&state->data.shadow.a_shadow, shadow, sizeof (GskShadow));
|
|
|
|
}
|
2017-01-11 10:21:27 +00:00
|
|
|
else
|
2017-10-01 11:49:01 +00:00
|
|
|
{
|
|
|
|
state->data.shadow.shadows = g_malloc (sizeof (GskShadow) * n_shadows);
|
|
|
|
memcpy (state->data.shadow.shadows, shadow, sizeof (GskShadow) * n_shadows);
|
|
|
|
}
|
2017-01-11 10:21:27 +00:00
|
|
|
|
2016-12-18 23:45:35 +00:00
|
|
|
}
|
|
|
|
|
2017-01-12 22:20:31 +00:00
|
|
|
static GskRenderNode *
|
2017-10-01 11:49:01 +00:00
|
|
|
gtk_snapshot_collect_blend_top (GtkSnapshot *snapshot,
|
|
|
|
GtkSnapshotState *state,
|
2017-01-12 22:20:31 +00:00
|
|
|
GskRenderNode **nodes,
|
2018-04-24 01:17:23 +00:00
|
|
|
guint n_nodes)
|
2017-01-12 22:20:31 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *bottom_node, *top_node, *blend_node;
|
2017-10-09 02:19:22 +00:00
|
|
|
GdkRGBA transparent = { 0, 0, 0, 0 };
|
2017-01-12 22:20:31 +00:00
|
|
|
|
2018-04-24 01:17:23 +00:00
|
|
|
top_node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes);
|
2020-11-26 00:21:11 +00:00
|
|
|
bottom_node = state->data.blend.bottom_node != NULL
|
|
|
|
? gsk_render_node_ref (state->data.blend.bottom_node)
|
|
|
|
: NULL;
|
2017-01-12 22:20:31 +00:00
|
|
|
|
2017-10-09 02:19:22 +00:00
|
|
|
g_assert (top_node != NULL || bottom_node != NULL);
|
|
|
|
|
2017-01-12 22:20:31 +00:00
|
|
|
/* XXX: Is this necessary? Do we need a NULL node? */
|
|
|
|
if (top_node == NULL)
|
2017-10-09 02:19:22 +00:00
|
|
|
top_node = gsk_color_node_new (&transparent, &bottom_node->bounds);
|
2017-01-12 22:20:31 +00:00
|
|
|
if (bottom_node == NULL)
|
2017-10-09 02:19:22 +00:00
|
|
|
bottom_node = gsk_color_node_new (&transparent, &top_node->bounds);
|
2017-01-12 22:20:31 +00:00
|
|
|
|
|
|
|
blend_node = gsk_blend_node_new (bottom_node, top_node, state->data.blend.blend_mode);
|
|
|
|
|
|
|
|
gsk_render_node_unref (top_node);
|
|
|
|
gsk_render_node_unref (bottom_node);
|
|
|
|
|
|
|
|
return blend_node;
|
|
|
|
}
|
|
|
|
|
2020-11-11 00:34:37 +00:00
|
|
|
static void
|
|
|
|
gtk_snapshot_clear_blend_top (GtkSnapshotState *state)
|
|
|
|
{
|
2020-11-26 00:21:11 +00:00
|
|
|
g_clear_pointer (&(state->data.blend.bottom_node), gsk_render_node_unref);
|
2020-11-11 00:34:37 +00:00
|
|
|
}
|
|
|
|
|
2017-01-12 22:20:31 +00:00
|
|
|
static GskRenderNode *
|
2017-10-01 11:49:01 +00:00
|
|
|
gtk_snapshot_collect_blend_bottom (GtkSnapshot *snapshot,
|
|
|
|
GtkSnapshotState *state,
|
2017-01-12 22:20:31 +00:00
|
|
|
GskRenderNode **nodes,
|
2018-04-24 01:17:23 +00:00
|
|
|
guint n_nodes)
|
2017-01-12 22:20:31 +00:00
|
|
|
{
|
2017-10-08 03:31:47 +00:00
|
|
|
GtkSnapshotState *prev_state = gtk_snapshot_get_previous_state (snapshot);
|
2017-10-01 11:49:01 +00:00
|
|
|
|
|
|
|
g_assert (prev_state->collect_func == gtk_snapshot_collect_blend_top);
|
|
|
|
|
2018-04-24 01:17:23 +00:00
|
|
|
prev_state->data.blend.bottom_node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes);
|
2017-10-01 11:49:01 +00:00
|
|
|
|
2017-01-12 22:20:31 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_snapshot_push_blend:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2017-01-12 22:20:31 +00:00
|
|
|
* @blend_mode: blend mode to use
|
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* Blends together two images with the given blend mode.
|
2017-01-12 22:20:31 +00:00
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* Until the first call to [method@Gtk.Snapshot.pop], the
|
|
|
|
* bottom image for the blend operation will be recorded.
|
|
|
|
* After that call, the top image to be blended will be
|
|
|
|
* recorded until the second call to [method@Gtk.Snapshot.pop].
|
2017-01-12 22:20:31 +00:00
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* Calling this function requires two subsequent calls
|
|
|
|
* to [method@Gtk.Snapshot.pop].
|
|
|
|
*/
|
2017-01-12 22:20:31 +00:00
|
|
|
void
|
|
|
|
gtk_snapshot_push_blend (GtkSnapshot *snapshot,
|
2018-04-24 01:17:23 +00:00
|
|
|
GskBlendMode blend_mode)
|
2017-01-12 22:20:31 +00:00
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
GtkSnapshotState *current_state = gtk_snapshot_get_current_state (snapshot);
|
|
|
|
GtkSnapshotState *top_state;
|
2017-01-12 22:20:31 +00:00
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
top_state = gtk_snapshot_push_state (snapshot,
|
2019-02-21 00:54:01 +00:00
|
|
|
current_state->transform,
|
2020-11-11 00:34:37 +00:00
|
|
|
gtk_snapshot_collect_blend_top,
|
|
|
|
gtk_snapshot_clear_blend_top);
|
2017-10-08 06:28:35 +00:00
|
|
|
top_state->data.blend.blend_mode = blend_mode;
|
2017-10-08 03:31:47 +00:00
|
|
|
|
|
|
|
gtk_snapshot_push_state (snapshot,
|
2019-02-21 00:54:01 +00:00
|
|
|
top_state->transform,
|
2020-11-11 00:34:37 +00:00
|
|
|
gtk_snapshot_collect_blend_bottom,
|
|
|
|
NULL);
|
2017-01-12 22:20:31 +00:00
|
|
|
}
|
|
|
|
|
2017-01-12 21:00:38 +00:00
|
|
|
static GskRenderNode *
|
2017-10-01 11:49:01 +00:00
|
|
|
gtk_snapshot_collect_cross_fade_end (GtkSnapshot *snapshot,
|
|
|
|
GtkSnapshotState *state,
|
2017-01-12 21:00:38 +00:00
|
|
|
GskRenderNode **nodes,
|
2018-04-24 01:17:23 +00:00
|
|
|
guint n_nodes)
|
2017-01-12 21:00:38 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *start_node, *end_node, *node;
|
|
|
|
|
2018-04-24 01:17:23 +00:00
|
|
|
end_node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes);
|
2017-01-12 21:00:38 +00:00
|
|
|
start_node = state->data.cross_fade.start_node;
|
2020-11-11 00:34:37 +00:00
|
|
|
state->data.cross_fade.start_node = NULL;
|
2017-01-12 21:00:38 +00:00
|
|
|
|
|
|
|
if (state->data.cross_fade.progress <= 0.0)
|
|
|
|
{
|
|
|
|
node = start_node;
|
|
|
|
|
|
|
|
if (end_node)
|
|
|
|
gsk_render_node_unref (end_node);
|
|
|
|
}
|
|
|
|
else if (state->data.cross_fade.progress >= 1.0)
|
|
|
|
{
|
|
|
|
node = end_node;
|
|
|
|
|
|
|
|
if (start_node)
|
|
|
|
gsk_render_node_unref (start_node);
|
|
|
|
}
|
|
|
|
else if (start_node && end_node)
|
|
|
|
{
|
|
|
|
node = gsk_cross_fade_node_new (start_node, end_node, state->data.cross_fade.progress);
|
|
|
|
|
|
|
|
gsk_render_node_unref (start_node);
|
|
|
|
gsk_render_node_unref (end_node);
|
|
|
|
}
|
|
|
|
else if (start_node)
|
|
|
|
{
|
|
|
|
node = gsk_opacity_node_new (start_node, 1.0 - state->data.cross_fade.progress);
|
|
|
|
|
|
|
|
gsk_render_node_unref (start_node);
|
|
|
|
}
|
|
|
|
else if (end_node)
|
|
|
|
{
|
|
|
|
node = gsk_opacity_node_new (end_node, state->data.cross_fade.progress);
|
|
|
|
|
|
|
|
gsk_render_node_unref (end_node);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
node = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2020-11-11 00:34:37 +00:00
|
|
|
static void
|
|
|
|
gtk_snapshot_clear_cross_fade_end (GtkSnapshotState *state)
|
|
|
|
{
|
|
|
|
g_clear_pointer (&state->data.cross_fade.start_node, gsk_render_node_unref);
|
|
|
|
}
|
|
|
|
|
2017-01-12 21:00:38 +00:00
|
|
|
static GskRenderNode *
|
2017-10-01 11:49:01 +00:00
|
|
|
gtk_snapshot_collect_cross_fade_start (GtkSnapshot *snapshot,
|
|
|
|
GtkSnapshotState *state,
|
2017-01-12 21:00:38 +00:00
|
|
|
GskRenderNode **nodes,
|
2018-04-24 01:17:23 +00:00
|
|
|
guint n_nodes)
|
2017-01-12 21:00:38 +00:00
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
GtkSnapshotState *prev_state = gtk_snapshot_get_previous_state (snapshot);
|
|
|
|
|
|
|
|
g_assert (prev_state->collect_func == gtk_snapshot_collect_cross_fade_end);
|
|
|
|
|
2018-04-24 01:17:23 +00:00
|
|
|
prev_state->data.cross_fade.start_node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes);
|
2017-10-01 11:49:01 +00:00
|
|
|
|
2017-01-12 21:00:38 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_snapshot_push_cross_fade:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2017-01-12 21:00:38 +00:00
|
|
|
* @progress: progress between 0.0 and 1.0
|
|
|
|
*
|
|
|
|
* Snapshots a cross-fade operation between two images with the
|
|
|
|
* given @progress.
|
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* Until the first call to [method@Gtk.Snapshot.pop], the start image
|
2017-01-12 21:00:38 +00:00
|
|
|
* will be snapshot. After that call, the end image will be recorded
|
2021-03-02 03:53:00 +00:00
|
|
|
* until the second call to [method@Gtk.Snapshot.pop].
|
2017-01-12 21:00:38 +00:00
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* Calling this function requires two subsequent calls
|
|
|
|
* to [method@Gtk.Snapshot.pop].
|
|
|
|
*/
|
2017-01-12 21:00:38 +00:00
|
|
|
void
|
|
|
|
gtk_snapshot_push_cross_fade (GtkSnapshot *snapshot,
|
2018-04-24 01:17:23 +00:00
|
|
|
double progress)
|
2017-01-12 21:00:38 +00:00
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
const GtkSnapshotState *current_state = gtk_snapshot_get_current_state (snapshot);
|
|
|
|
GtkSnapshotState *end_state;
|
2017-01-12 21:00:38 +00:00
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
end_state = gtk_snapshot_push_state (snapshot,
|
2019-02-21 00:54:01 +00:00
|
|
|
current_state->transform,
|
2020-11-11 00:34:37 +00:00
|
|
|
gtk_snapshot_collect_cross_fade_end,
|
|
|
|
gtk_snapshot_clear_cross_fade_end);
|
2017-10-01 11:49:01 +00:00
|
|
|
end_state->data.cross_fade.progress = progress;
|
2017-10-02 13:25:44 +00:00
|
|
|
|
|
|
|
gtk_snapshot_push_state (snapshot,
|
2019-02-21 00:54:01 +00:00
|
|
|
end_state->transform,
|
2020-11-11 00:34:37 +00:00
|
|
|
gtk_snapshot_collect_cross_fade_start,
|
|
|
|
NULL);
|
2017-01-12 21:00:38 +00:00
|
|
|
}
|
|
|
|
|
2017-01-12 23:39:59 +00:00
|
|
|
static GskRenderNode *
|
2019-02-21 00:54:01 +00:00
|
|
|
gtk_snapshot_pop_one (GtkSnapshot *snapshot)
|
2016-11-07 18:10:49 +00:00
|
|
|
{
|
2016-11-17 00:55:26 +00:00
|
|
|
GtkSnapshotState *state;
|
2017-10-01 11:49:01 +00:00
|
|
|
guint state_index;
|
2016-12-13 01:33:15 +00:00
|
|
|
GskRenderNode *node;
|
2016-11-17 00:55:26 +00:00
|
|
|
|
2020-07-03 02:53:50 +00:00
|
|
|
if (gtk_snapshot_states_is_empty (&snapshot->state_stack))
|
2016-11-11 23:37:54 +00:00
|
|
|
{
|
|
|
|
g_warning ("Too many gtk_snapshot_pop() calls.");
|
2016-12-13 01:33:15 +00:00
|
|
|
return NULL;
|
2016-11-11 23:37:54 +00:00
|
|
|
}
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
state = gtk_snapshot_get_current_state (snapshot);
|
2020-07-03 02:53:50 +00:00
|
|
|
state_index = gtk_snapshot_states_get_size (&snapshot->state_stack) - 1;
|
2016-11-11 23:37:54 +00:00
|
|
|
|
2019-02-21 00:54:01 +00:00
|
|
|
if (state->collect_func)
|
|
|
|
{
|
|
|
|
node = state->collect_func (snapshot,
|
|
|
|
state,
|
2020-07-02 21:32:04 +00:00
|
|
|
(GskRenderNode **) gtk_snapshot_nodes_index (&snapshot->nodes, state->start_node_index),
|
2019-02-21 00:54:01 +00:00
|
|
|
state->n_nodes);
|
|
|
|
|
|
|
|
/* The collect func may not modify the state stack... */
|
2020-07-03 02:53:50 +00:00
|
|
|
g_assert (state_index == gtk_snapshot_states_get_size (&snapshot->state_stack) - 1);
|
2019-02-21 00:54:01 +00:00
|
|
|
|
|
|
|
/* Remove all the state's nodes from the list of nodes */
|
2020-07-02 21:32:04 +00:00
|
|
|
g_assert (state->start_node_index + state->n_nodes == gtk_snapshot_nodes_get_size (&snapshot->nodes));
|
2020-12-23 19:04:29 +00:00
|
|
|
gtk_snapshot_nodes_splice (&snapshot->nodes, state->start_node_index, state->n_nodes, FALSE, NULL, 0);
|
2019-02-21 00:54:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkSnapshotState *previous_state;
|
2016-12-13 01:33:15 +00:00
|
|
|
|
2019-02-21 00:54:01 +00:00
|
|
|
node = NULL;
|
2017-10-01 12:28:11 +00:00
|
|
|
|
2019-02-21 00:54:01 +00:00
|
|
|
/* move the nodes to the parent */
|
|
|
|
previous_state = gtk_snapshot_get_previous_state (snapshot);
|
|
|
|
previous_state->n_nodes += state->n_nodes;
|
2020-07-02 21:32:04 +00:00
|
|
|
g_assert (previous_state->start_node_index + previous_state->n_nodes == gtk_snapshot_nodes_get_size (&snapshot->nodes));
|
2019-02-21 00:54:01 +00:00
|
|
|
}
|
2017-10-01 12:28:11 +00:00
|
|
|
|
2020-12-23 19:04:29 +00:00
|
|
|
gtk_snapshot_states_splice (&snapshot->state_stack, state_index, 1, FALSE, NULL, 0);
|
2016-12-13 01:33:15 +00:00
|
|
|
|
|
|
|
return node;
|
2016-11-07 18:10:49 +00:00
|
|
|
}
|
|
|
|
|
2019-08-16 05:17:41 +00:00
|
|
|
static void
|
|
|
|
gtk_snapshot_append_node_internal (GtkSnapshot *snapshot,
|
|
|
|
GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GtkSnapshotState *current_state;
|
|
|
|
|
|
|
|
current_state = gtk_snapshot_get_current_state (snapshot);
|
|
|
|
|
|
|
|
if (current_state)
|
|
|
|
{
|
2020-07-02 21:32:04 +00:00
|
|
|
gtk_snapshot_nodes_append (&snapshot->nodes, node);
|
2019-08-16 05:17:41 +00:00
|
|
|
current_state->n_nodes ++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_critical ("Tried appending a node to an already finished snapshot.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-21 00:54:01 +00:00
|
|
|
static GskRenderNode *
|
2021-04-01 14:37:47 +00:00
|
|
|
gtk_snapshot_pop_internal (GtkSnapshot *snapshot,
|
|
|
|
gboolean is_texture_pop)
|
2019-02-21 00:54:01 +00:00
|
|
|
{
|
|
|
|
GtkSnapshotState *state;
|
|
|
|
GskRenderNode *node;
|
2019-02-21 03:24:24 +00:00
|
|
|
guint forgotten_restores = 0;
|
2019-02-21 00:54:01 +00:00
|
|
|
|
|
|
|
for (state = gtk_snapshot_get_current_state (snapshot);
|
2019-02-21 03:24:24 +00:00
|
|
|
gtk_snapshot_state_should_autopop (state) ||
|
|
|
|
state->collect_func == NULL;
|
2019-02-21 00:54:01 +00:00
|
|
|
state = gtk_snapshot_get_current_state (snapshot))
|
|
|
|
{
|
2019-02-21 03:24:24 +00:00
|
|
|
if (state->collect_func == NULL)
|
|
|
|
forgotten_restores++;
|
|
|
|
|
2019-02-21 00:54:01 +00:00
|
|
|
node = gtk_snapshot_pop_one (snapshot);
|
|
|
|
if (node)
|
2019-06-04 14:14:30 +00:00
|
|
|
gtk_snapshot_append_node_internal (snapshot, node);
|
2019-02-21 00:54:01 +00:00
|
|
|
}
|
|
|
|
|
2019-02-21 03:24:24 +00:00
|
|
|
if (forgotten_restores)
|
|
|
|
{
|
|
|
|
g_warning ("Too many gtk_snapshot_save() calls. %u saves remaining.", forgotten_restores);
|
|
|
|
}
|
|
|
|
|
2021-04-01 14:37:47 +00:00
|
|
|
if (is_texture_pop && (state->collect_func != gtk_snapshot_collect_gl_shader_texture))
|
|
|
|
{
|
|
|
|
g_critical ("Unexpected call to gtk_snapshot_gl_shader_pop_texture().");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else if (!is_texture_pop && (state->collect_func == gtk_snapshot_collect_gl_shader_texture))
|
|
|
|
{
|
|
|
|
g_critical ("Expected a call to gtk_snapshot_gl_shader_pop_texture().");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-02-21 00:54:01 +00:00
|
|
|
return gtk_snapshot_pop_one (snapshot);
|
|
|
|
}
|
|
|
|
|
2020-01-31 07:05:34 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_push_collect:
|
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* Private.
|
2020-01-31 07:05:34 +00:00
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* Pushes state so a later pop_collect call can collect all nodes
|
2020-01-31 07:05:34 +00:00
|
|
|
* appended until that point.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_snapshot_push_collect (GtkSnapshot *snapshot)
|
|
|
|
{
|
|
|
|
gtk_snapshot_push_state (snapshot,
|
|
|
|
NULL,
|
2020-11-11 00:34:37 +00:00
|
|
|
gtk_snapshot_collect_default,
|
|
|
|
NULL);
|
2020-01-31 07:05:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GskRenderNode *
|
|
|
|
gtk_snapshot_pop_collect (GtkSnapshot *snapshot)
|
|
|
|
{
|
2021-04-01 14:37:47 +00:00
|
|
|
GskRenderNode *result = gtk_snapshot_pop_internal (snapshot, FALSE);
|
2020-01-31 07:05:34 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-03-11 02:29:46 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_to_node:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2018-03-11 02:29:46 +00:00
|
|
|
*
|
|
|
|
* Returns the render node that was constructed
|
2021-03-02 03:53:00 +00:00
|
|
|
* by @snapshot.
|
2018-03-11 02:29:46 +00:00
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* After calling this function, it is no longer possible to
|
|
|
|
* add more nodes to @snapshot. The only function that should
|
2022-01-05 11:36:55 +00:00
|
|
|
* be called after this is [method@GObject.Object.unref].
|
2021-03-02 03:53:00 +00:00
|
|
|
*
|
2022-01-23 22:11:07 +00:00
|
|
|
* Returns: (transfer full) (nullable): the constructed `GskRenderNode`
|
2018-03-11 02:29:46 +00:00
|
|
|
*/
|
2017-01-12 23:39:59 +00:00
|
|
|
GskRenderNode *
|
2018-03-11 01:52:06 +00:00
|
|
|
gtk_snapshot_to_node (GtkSnapshot *snapshot)
|
2017-01-12 23:39:59 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *result;
|
|
|
|
|
2021-04-01 14:37:47 +00:00
|
|
|
result = gtk_snapshot_pop_internal (snapshot, FALSE);
|
2019-02-21 00:54:01 +00:00
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
/* We should have exactly our initial state */
|
2020-07-03 02:53:50 +00:00
|
|
|
if (!gtk_snapshot_states_is_empty (&snapshot->state_stack))
|
2017-01-12 23:39:59 +00:00
|
|
|
{
|
2020-07-03 02:53:50 +00:00
|
|
|
g_warning ("Too many gtk_snapshot_push() calls. %zu states remaining.",
|
|
|
|
gtk_snapshot_states_get_size (&snapshot->state_stack));
|
2017-01-12 23:39:59 +00:00
|
|
|
}
|
2019-01-16 07:30:42 +00:00
|
|
|
|
2020-07-03 02:53:50 +00:00
|
|
|
gtk_snapshot_states_clear (&snapshot->state_stack);
|
2020-07-02 21:32:04 +00:00
|
|
|
gtk_snapshot_nodes_clear (&snapshot->nodes);
|
2018-03-11 01:52:06 +00:00
|
|
|
|
2017-01-12 23:39:59 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-03-26 02:37:01 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_to_paintable:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2021-05-19 11:24:34 +00:00
|
|
|
* @size: (nullable): The size of the resulting paintable
|
2021-05-18 21:05:26 +00:00
|
|
|
* or %NULL to use the bounds of the snapshot
|
2018-03-26 02:37:01 +00:00
|
|
|
*
|
|
|
|
* Returns a paintable encapsulating the render node
|
2021-03-02 03:53:00 +00:00
|
|
|
* that was constructed by @snapshot.
|
|
|
|
*
|
|
|
|
* After calling this function, it is no longer possible to
|
|
|
|
* add more nodes to @snapshot. The only function that should
|
2022-01-05 11:36:55 +00:00
|
|
|
* be called after this is [method@GObject.Object.unref].
|
2018-03-26 02:37:01 +00:00
|
|
|
*
|
2022-01-23 22:11:07 +00:00
|
|
|
* Returns: (transfer full) (nullable): a new `GdkPaintable`
|
2018-03-26 02:37:01 +00:00
|
|
|
*/
|
|
|
|
GdkPaintable *
|
2018-04-02 04:15:50 +00:00
|
|
|
gtk_snapshot_to_paintable (GtkSnapshot *snapshot,
|
|
|
|
const graphene_size_t *size)
|
2018-03-26 02:37:01 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
|
|
|
GdkPaintable *paintable;
|
2018-04-02 04:15:50 +00:00
|
|
|
graphene_rect_t bounds;
|
2018-03-26 02:37:01 +00:00
|
|
|
|
|
|
|
node = gtk_snapshot_to_node (snapshot);
|
2018-06-19 17:40:37 +00:00
|
|
|
if (size)
|
|
|
|
{
|
|
|
|
graphene_size_init_from_size (&bounds.size, size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gsk_render_node_get_bounds (node, &bounds);
|
|
|
|
bounds.size.width += bounds.origin.x;
|
|
|
|
bounds.size.height += bounds.origin.y;
|
|
|
|
}
|
2018-04-02 04:15:50 +00:00
|
|
|
bounds.origin.x = 0;
|
|
|
|
bounds.origin.y = 0;
|
2018-06-19 17:40:37 +00:00
|
|
|
|
2018-04-02 04:15:50 +00:00
|
|
|
paintable = gtk_render_node_paintable_new (node, &bounds);
|
2018-03-26 02:37:01 +00:00
|
|
|
gsk_render_node_unref (node);
|
|
|
|
|
|
|
|
return paintable;
|
|
|
|
}
|
|
|
|
|
2016-12-13 08:40:24 +00:00
|
|
|
/**
|
2017-01-12 23:39:59 +00:00
|
|
|
* gtk_snapshot_pop:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2016-12-13 08:40:24 +00:00
|
|
|
*
|
|
|
|
* Removes the top element from the stack of render nodes,
|
|
|
|
* and appends it to the node underneath it.
|
|
|
|
*/
|
|
|
|
void
|
2017-01-12 23:39:59 +00:00
|
|
|
gtk_snapshot_pop (GtkSnapshot *snapshot)
|
2016-12-13 08:40:24 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
|
|
|
|
2021-04-01 14:37:47 +00:00
|
|
|
node = gtk_snapshot_pop_internal (snapshot, FALSE);
|
2019-06-04 14:14:30 +00:00
|
|
|
|
2016-12-17 07:03:43 +00:00
|
|
|
if (node)
|
2019-06-04 14:14:30 +00:00
|
|
|
gtk_snapshot_append_node_internal (snapshot, node);
|
2016-12-13 08:40:24 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 15:56:02 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_gl_shader_pop_texture:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2020-09-18 15:56:02 +00:00
|
|
|
*
|
|
|
|
* Removes the top element from the stack of render nodes and
|
2022-01-05 11:36:55 +00:00
|
|
|
* adds it to the nearest [class@Gsk.GLShaderNode] below it.
|
2021-03-02 03:53:00 +00:00
|
|
|
*
|
|
|
|
* This must be called the same number of times as the number
|
|
|
|
* of textures is needed for the shader in
|
|
|
|
* [method@Gtk.Snapshot.push_gl_shader].
|
2020-09-18 15:56:02 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_snapshot_gl_shader_pop_texture (GtkSnapshot *snapshot)
|
|
|
|
{
|
2021-02-11 00:03:50 +00:00
|
|
|
G_GNUC_UNUSED GskRenderNode *node;
|
2020-09-18 15:56:02 +00:00
|
|
|
|
2021-04-01 14:37:47 +00:00
|
|
|
node = gtk_snapshot_pop_internal (snapshot, TRUE);
|
2020-09-18 15:56:02 +00:00
|
|
|
g_assert (node == NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-21 03:24:24 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_save:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2019-02-21 03:24:24 +00:00
|
|
|
*
|
|
|
|
* Makes a copy of the current state of @snapshot and saves it
|
2021-03-02 03:53:00 +00:00
|
|
|
* on an internal stack.
|
|
|
|
*
|
|
|
|
* When [method@Gtk.Snapshot.restore] is called, @snapshot will
|
|
|
|
* be restored to the saved state. Multiple calls to
|
2022-01-05 11:36:55 +00:00
|
|
|
* [method@Snapshot.save] and [class@Snapshot.restore] can be nested;
|
|
|
|
* each call to `gtk_snapshot_restore()` restores the state from
|
|
|
|
* the matching paired `gtk_snapshot_save()`.
|
2021-03-02 03:53:00 +00:00
|
|
|
*
|
|
|
|
* It is necessary to clear all saved states with corresponding
|
2022-01-05 11:36:55 +00:00
|
|
|
* calls to `gtk_snapshot_restore()`.
|
2021-03-02 03:53:00 +00:00
|
|
|
*/
|
2019-02-21 03:24:24 +00:00
|
|
|
void
|
|
|
|
gtk_snapshot_save (GtkSnapshot *snapshot)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_SNAPSHOT (snapshot));
|
|
|
|
|
|
|
|
gtk_snapshot_push_state (snapshot,
|
|
|
|
gtk_snapshot_get_current_state (snapshot)->transform,
|
2020-11-11 00:34:37 +00:00
|
|
|
NULL,
|
2019-02-21 03:24:24 +00:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_snapshot_restore:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2019-02-21 03:24:24 +00:00
|
|
|
*
|
|
|
|
* Restores @snapshot to the state saved by a preceding call to
|
2022-01-05 11:36:55 +00:00
|
|
|
* [method@Snapshot.save] and removes that state from the stack of
|
2019-02-21 03:24:24 +00:00
|
|
|
* saved states.
|
2021-03-02 03:53:00 +00:00
|
|
|
*/
|
2019-02-21 03:24:24 +00:00
|
|
|
void
|
|
|
|
gtk_snapshot_restore (GtkSnapshot *snapshot)
|
|
|
|
{
|
|
|
|
GtkSnapshotState *state;
|
|
|
|
GskRenderNode *node;
|
|
|
|
|
|
|
|
for (state = gtk_snapshot_get_current_state (snapshot);
|
|
|
|
gtk_snapshot_state_should_autopop (state);
|
|
|
|
state = gtk_snapshot_get_current_state (snapshot))
|
|
|
|
{
|
|
|
|
node = gtk_snapshot_pop_one (snapshot);
|
|
|
|
if (node)
|
2019-06-04 14:14:30 +00:00
|
|
|
gtk_snapshot_append_node_internal (snapshot, node);
|
2019-02-21 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (state->collect_func != NULL)
|
|
|
|
{
|
|
|
|
g_warning ("Too many gtk_snapshot_restore() calls.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
node = gtk_snapshot_pop_one (snapshot);
|
|
|
|
g_assert (node == NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_snapshot_transform:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2021-05-19 11:24:34 +00:00
|
|
|
* @transform: (nullable): the transform to apply
|
2019-02-21 03:24:24 +00:00
|
|
|
*
|
|
|
|
* Transforms @snapshot's coordinate system with the given @transform.
|
2021-03-02 03:53:00 +00:00
|
|
|
*/
|
2019-02-21 03:24:24 +00:00
|
|
|
void
|
|
|
|
gtk_snapshot_transform (GtkSnapshot *snapshot,
|
2019-02-28 08:52:49 +00:00
|
|
|
GskTransform *transform)
|
2019-02-21 03:24:24 +00:00
|
|
|
{
|
|
|
|
GtkSnapshotState *state;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_SNAPSHOT (snapshot));
|
|
|
|
|
|
|
|
state = gtk_snapshot_get_current_state (snapshot);
|
2019-02-28 08:52:49 +00:00
|
|
|
state->transform = gsk_transform_transform (state->transform, transform);
|
2019-02-21 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_snapshot_transform_matrix:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2019-02-21 03:24:24 +00:00
|
|
|
* @matrix: the matrix to multiply the transform with
|
|
|
|
*
|
|
|
|
* Transforms @snapshot's coordinate system with the given @matrix.
|
2021-03-02 03:53:00 +00:00
|
|
|
*/
|
2019-02-21 03:24:24 +00:00
|
|
|
void
|
|
|
|
gtk_snapshot_transform_matrix (GtkSnapshot *snapshot,
|
|
|
|
const graphene_matrix_t *matrix)
|
|
|
|
{
|
|
|
|
GtkSnapshotState *state;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_SNAPSHOT (snapshot));
|
|
|
|
g_return_if_fail (matrix != NULL);
|
|
|
|
|
|
|
|
state = gtk_snapshot_get_current_state (snapshot);
|
2019-02-28 08:52:49 +00:00
|
|
|
state->transform = gsk_transform_matrix (state->transform, matrix);
|
2019-02-21 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-24 20:29:08 +00:00
|
|
|
* gtk_snapshot_translate:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2019-02-21 03:24:24 +00:00
|
|
|
* @point: the point to translate the snapshot by
|
|
|
|
*
|
|
|
|
* Translates @snapshot's coordinate system by @point in 2-dimensional space.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_snapshot_translate (GtkSnapshot *snapshot,
|
|
|
|
const graphene_point_t *point)
|
|
|
|
{
|
|
|
|
GtkSnapshotState *state;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_SNAPSHOT (snapshot));
|
|
|
|
g_return_if_fail (point != NULL);
|
|
|
|
|
|
|
|
state = gtk_snapshot_get_current_state (snapshot);
|
2019-02-28 08:52:49 +00:00
|
|
|
state->transform = gsk_transform_translate (state->transform, point);
|
2019-02-21 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-24 20:29:08 +00:00
|
|
|
* gtk_snapshot_translate_3d:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2019-02-21 03:24:24 +00:00
|
|
|
* @point: the point to translate the snapshot by
|
|
|
|
*
|
|
|
|
* Translates @snapshot's coordinate system by @point.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_snapshot_translate_3d (GtkSnapshot *snapshot,
|
|
|
|
const graphene_point3d_t *point)
|
|
|
|
{
|
|
|
|
GtkSnapshotState *state;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_SNAPSHOT (snapshot));
|
|
|
|
g_return_if_fail (point != NULL);
|
|
|
|
|
|
|
|
state = gtk_snapshot_get_current_state (snapshot);
|
2019-02-28 08:52:49 +00:00
|
|
|
state->transform = gsk_transform_translate_3d (state->transform, point);
|
2019-02-21 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-24 20:29:08 +00:00
|
|
|
* gtk_snapshot_rotate:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2019-02-21 03:24:24 +00:00
|
|
|
* @angle: the rotation angle, in degrees (clockwise)
|
|
|
|
*
|
|
|
|
* Rotates @@snapshot's coordinate system by @angle degrees in 2D space -
|
2021-03-02 03:53:00 +00:00
|
|
|
* or in 3D speak, rotates around the Z axis.
|
|
|
|
*
|
|
|
|
* To rotate around other axes, use [method@Gsk.Transform.rotate_3d].
|
2019-02-21 03:24:24 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_snapshot_rotate (GtkSnapshot *snapshot,
|
|
|
|
float angle)
|
|
|
|
{
|
|
|
|
GtkSnapshotState *state;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_SNAPSHOT (snapshot));
|
|
|
|
|
|
|
|
state = gtk_snapshot_get_current_state (snapshot);
|
2019-02-28 08:52:49 +00:00
|
|
|
state->transform = gsk_transform_rotate (state->transform, angle);
|
2019-02-21 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-24 20:29:08 +00:00
|
|
|
* gtk_snapshot_rotate_3d:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2019-02-21 03:24:24 +00:00
|
|
|
* @angle: the rotation angle, in degrees (clockwise)
|
|
|
|
* @axis: The rotation axis
|
|
|
|
*
|
|
|
|
* Rotates @snapshot's coordinate system by @angle degrees around @axis.
|
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* For a rotation in 2D space, use [method@Gsk.Transform.rotate].
|
2019-02-21 03:24:24 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_snapshot_rotate_3d (GtkSnapshot *snapshot,
|
|
|
|
float angle,
|
|
|
|
const graphene_vec3_t *axis)
|
|
|
|
{
|
|
|
|
GtkSnapshotState *state;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_SNAPSHOT (snapshot));
|
|
|
|
g_return_if_fail (axis != NULL);
|
|
|
|
|
|
|
|
state = gtk_snapshot_get_current_state (snapshot);
|
2019-02-28 08:52:49 +00:00
|
|
|
state->transform = gsk_transform_rotate_3d (state->transform, angle, axis);
|
2019-02-21 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_snapshot_scale:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2019-02-21 03:24:24 +00:00
|
|
|
* @factor_x: scaling factor on the X axis
|
|
|
|
* @factor_y: scaling factor on the Y axis
|
|
|
|
*
|
2019-03-05 08:27:30 +00:00
|
|
|
* Scales @snapshot's coordinate system in 2-dimensional space by
|
2019-02-21 03:24:24 +00:00
|
|
|
* the given factors.
|
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* Use [method@Gtk.Snapshot.scale_3d] to scale in all 3 dimensions.
|
|
|
|
*/
|
2019-02-21 03:24:24 +00:00
|
|
|
void
|
|
|
|
gtk_snapshot_scale (GtkSnapshot *snapshot,
|
|
|
|
float factor_x,
|
|
|
|
float factor_y)
|
|
|
|
{
|
|
|
|
GtkSnapshotState *state;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_SNAPSHOT (snapshot));
|
|
|
|
|
|
|
|
state = gtk_snapshot_get_current_state (snapshot);
|
2019-02-28 08:52:49 +00:00
|
|
|
state->transform = gsk_transform_scale (state->transform, factor_x, factor_y);
|
2019-02-21 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_snapshot_scale_3d:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2019-02-21 03:24:24 +00:00
|
|
|
* @factor_x: scaling factor on the X axis
|
|
|
|
* @factor_y: scaling factor on the Y axis
|
|
|
|
* @factor_z: scaling factor on the Z axis
|
|
|
|
*
|
2019-03-05 08:27:30 +00:00
|
|
|
* Scales @snapshot's coordinate system by the given factors.
|
2019-02-21 03:24:24 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_snapshot_scale_3d (GtkSnapshot *snapshot,
|
|
|
|
float factor_x,
|
|
|
|
float factor_y,
|
|
|
|
float factor_z)
|
|
|
|
{
|
|
|
|
GtkSnapshotState *state;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_SNAPSHOT (snapshot));
|
|
|
|
|
|
|
|
state = gtk_snapshot_get_current_state (snapshot);
|
2019-02-28 08:52:49 +00:00
|
|
|
state->transform = gsk_transform_scale_3d (state->transform, factor_x, factor_y, factor_z);
|
2019-02-21 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-05 08:27:30 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_perspective:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2019-03-05 08:27:30 +00:00
|
|
|
* @depth: distance of the z=0 plane
|
|
|
|
*
|
|
|
|
* Applies a perspective projection transform.
|
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* See [method@Gsk.Transform.perspective] for a discussion on the details.
|
2019-03-05 08:27:30 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_snapshot_perspective (GtkSnapshot *snapshot,
|
|
|
|
float depth)
|
|
|
|
{
|
|
|
|
GtkSnapshotState *state;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_SNAPSHOT (snapshot));
|
|
|
|
|
|
|
|
state = gtk_snapshot_get_current_state (snapshot);
|
|
|
|
state->transform = gsk_transform_perspective (state->transform, depth);
|
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_append_node:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2021-05-20 13:17:04 +00:00
|
|
|
* @node: a `GskRenderNode`
|
2016-11-18 11:53:57 +00:00
|
|
|
*
|
|
|
|
* Appends @node to the current render node of @snapshot,
|
2021-03-02 03:53:00 +00:00
|
|
|
* without changing the current node.
|
|
|
|
*
|
|
|
|
* If @snapshot does not have a current node yet, @node
|
|
|
|
* will become the initial node.
|
2016-11-18 11:53:57 +00:00
|
|
|
*/
|
2016-11-11 23:37:54 +00:00
|
|
|
void
|
2016-11-17 00:55:26 +00:00
|
|
|
gtk_snapshot_append_node (GtkSnapshot *snapshot,
|
2016-11-11 23:37:54 +00:00
|
|
|
GskRenderNode *node)
|
|
|
|
{
|
2016-11-17 00:55:26 +00:00
|
|
|
g_return_if_fail (snapshot != NULL);
|
2016-11-11 23:37:54 +00:00
|
|
|
g_return_if_fail (GSK_IS_RENDER_NODE (node));
|
|
|
|
|
2019-02-21 00:54:01 +00:00
|
|
|
gtk_snapshot_ensure_identity (snapshot);
|
|
|
|
|
2019-06-04 14:14:30 +00:00
|
|
|
gtk_snapshot_append_node_internal (snapshot, gsk_render_node_ref (node));
|
2016-11-11 23:37:54 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
2017-01-13 03:46:09 +00:00
|
|
|
* gtk_snapshot_append_cairo:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2016-11-18 11:53:57 +00:00
|
|
|
* @bounds: the bounds for the new node
|
|
|
|
*
|
2022-01-05 11:36:55 +00:00
|
|
|
* Creates a new [class@Gsk.CairoNode] and appends it to the current
|
2021-03-02 03:53:00 +00:00
|
|
|
* render node of @snapshot, without changing the current node.
|
2016-11-18 11:53:57 +00:00
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* Returns: a `cairo_t` suitable for drawing the contents of
|
|
|
|
* the newly created render node
|
2016-11-18 11:53:57 +00:00
|
|
|
*/
|
2016-11-11 23:37:54 +00:00
|
|
|
cairo_t *
|
2017-01-13 03:46:09 +00:00
|
|
|
gtk_snapshot_append_cairo (GtkSnapshot *snapshot,
|
2018-04-24 01:17:23 +00:00
|
|
|
const graphene_rect_t *bounds)
|
2016-11-11 23:37:54 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
2016-12-12 23:11:06 +00:00
|
|
|
graphene_rect_t real_bounds;
|
2019-02-21 00:54:01 +00:00
|
|
|
float scale_x, scale_y, dx, dy;
|
2016-12-12 23:11:06 +00:00
|
|
|
cairo_t *cr;
|
2016-11-11 23:37:54 +00:00
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
g_return_val_if_fail (snapshot != NULL, NULL);
|
2016-11-11 23:37:54 +00:00
|
|
|
g_return_val_if_fail (bounds != NULL, NULL);
|
|
|
|
|
2019-02-21 00:54:01 +00:00
|
|
|
gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &dx, &dy);
|
|
|
|
gtk_graphene_rect_scale_affine (bounds, scale_x, scale_y, dx, dy, &real_bounds);
|
2018-03-19 17:52:12 +00:00
|
|
|
|
2016-12-12 23:11:06 +00:00
|
|
|
node = gsk_cairo_node_new (&real_bounds);
|
2016-11-11 23:37:54 +00:00
|
|
|
|
2018-03-20 03:33:58 +00:00
|
|
|
gtk_snapshot_append_node_internal (snapshot, node);
|
2016-11-11 23:37:54 +00:00
|
|
|
|
2018-03-24 20:33:08 +00:00
|
|
|
cr = gsk_cairo_node_get_draw_context (node);
|
2016-12-12 23:11:06 +00:00
|
|
|
|
2019-02-21 00:54:01 +00:00
|
|
|
cairo_scale (cr, scale_x, scale_y);
|
|
|
|
cairo_translate (cr, dx, dy);
|
2016-12-12 23:11:06 +00:00
|
|
|
|
|
|
|
return cr;
|
2016-11-11 23:37:54 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 03:22:13 +00:00
|
|
|
/**
|
2017-01-13 03:46:09 +00:00
|
|
|
* gtk_snapshot_append_texture:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2022-01-05 11:36:55 +00:00
|
|
|
* @texture: the texture to render
|
2016-12-13 03:22:13 +00:00
|
|
|
* @bounds: the bounds for the new node
|
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* Creates a new render node drawing the @texture
|
|
|
|
* into the given @bounds and appends it to the
|
|
|
|
* current render node of @snapshot.
|
|
|
|
*/
|
2016-12-13 03:22:13 +00:00
|
|
|
void
|
2018-04-24 01:17:23 +00:00
|
|
|
gtk_snapshot_append_texture (GtkSnapshot *snapshot,
|
|
|
|
GdkTexture *texture,
|
|
|
|
const graphene_rect_t *bounds)
|
2016-12-13 03:22:13 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
|
|
|
graphene_rect_t real_bounds;
|
2019-02-21 00:54:01 +00:00
|
|
|
float scale_x, scale_y, dx, dy;
|
2016-12-13 03:22:13 +00:00
|
|
|
|
|
|
|
g_return_if_fail (snapshot != NULL);
|
2017-11-02 20:39:00 +00:00
|
|
|
g_return_if_fail (GDK_IS_TEXTURE (texture));
|
2016-12-13 03:22:13 +00:00
|
|
|
g_return_if_fail (bounds != NULL);
|
|
|
|
|
2019-02-21 00:54:01 +00:00
|
|
|
gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &dx, &dy);
|
|
|
|
gtk_graphene_rect_scale_affine (bounds, scale_x, scale_y, dx, dy, &real_bounds);
|
2017-11-04 15:03:03 +00:00
|
|
|
node = gsk_texture_node_new (texture, &real_bounds);
|
2016-12-13 03:22:13 +00:00
|
|
|
|
2018-03-20 03:33:58 +00:00
|
|
|
gtk_snapshot_append_node_internal (snapshot, node);
|
2016-12-13 03:22:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 03:46:09 +00:00
|
|
|
* gtk_snapshot_append_color:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2022-01-05 11:36:55 +00:00
|
|
|
* @color: the color to draw
|
2016-12-13 03:22:13 +00:00
|
|
|
* @bounds: the bounds for the new node
|
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* Creates a new render node drawing the @color into the
|
|
|
|
* given @bounds and appends it to the current render node
|
|
|
|
* of @snapshot.
|
2016-12-13 03:22:13 +00:00
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* You should try to avoid calling this function if
|
|
|
|
* @color is transparent.
|
|
|
|
*/
|
2016-12-13 03:22:13 +00:00
|
|
|
void
|
2017-01-13 03:46:09 +00:00
|
|
|
gtk_snapshot_append_color (GtkSnapshot *snapshot,
|
|
|
|
const GdkRGBA *color,
|
2018-04-24 01:17:23 +00:00
|
|
|
const graphene_rect_t *bounds)
|
2016-12-13 03:22:13 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
|
|
|
graphene_rect_t real_bounds;
|
2019-02-21 00:54:01 +00:00
|
|
|
float scale_x, scale_y, dx, dy;
|
2016-12-13 03:22:13 +00:00
|
|
|
|
|
|
|
g_return_if_fail (snapshot != NULL);
|
|
|
|
g_return_if_fail (color != NULL);
|
|
|
|
g_return_if_fail (bounds != NULL);
|
|
|
|
|
2019-02-21 00:54:01 +00:00
|
|
|
gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &dx, &dy);
|
|
|
|
gtk_graphene_rect_scale_affine (bounds, scale_x, scale_y, dx, dy, &real_bounds);
|
2017-12-12 19:33:53 +00:00
|
|
|
|
2016-12-13 03:22:13 +00:00
|
|
|
node = gsk_color_node_new (color, &real_bounds);
|
|
|
|
|
2018-03-20 03:33:58 +00:00
|
|
|
gtk_snapshot_append_node_internal (snapshot, node);
|
2016-12-13 03:22:13 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_render_background:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2022-01-05 11:36:55 +00:00
|
|
|
* @context: the style context that defines the background
|
2016-11-18 11:53:57 +00:00
|
|
|
* @x: X origin of the rectangle
|
|
|
|
* @y: Y origin of the rectangle
|
|
|
|
* @width: rectangle width
|
|
|
|
* @height: rectangle height
|
|
|
|
*
|
|
|
|
* Creates a render node for the CSS background according to @context,
|
|
|
|
* and appends it to the current node of @snapshot, without changing
|
|
|
|
* the current node.
|
|
|
|
*/
|
2016-11-13 15:16:39 +00:00
|
|
|
void
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_render_background (GtkSnapshot *snapshot,
|
2016-11-13 15:16:39 +00:00
|
|
|
GtkStyleContext *context,
|
2020-07-24 20:32:16 +00:00
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
double width,
|
|
|
|
double height)
|
2016-11-13 15:16:39 +00:00
|
|
|
{
|
2019-02-15 05:15:50 +00:00
|
|
|
GtkCssBoxes boxes;
|
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
g_return_if_fail (snapshot != NULL);
|
2016-11-13 15:16:39 +00:00
|
|
|
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
|
|
|
|
|
2019-02-15 05:15:50 +00:00
|
|
|
gtk_css_boxes_init_border_box (&boxes,
|
|
|
|
gtk_style_context_lookup_style (context),
|
|
|
|
x, y, width, height);
|
|
|
|
gtk_css_style_snapshot_background (&boxes, snapshot);
|
2016-11-13 15:16:39 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_render_frame:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2022-01-05 11:36:55 +00:00
|
|
|
* @context: the style context that defines the frame
|
2016-11-18 12:57:10 +00:00
|
|
|
* @x: X origin of the rectangle
|
|
|
|
* @y: Y origin of the rectangle
|
|
|
|
* @width: rectangle width
|
|
|
|
* @height: rectangle height
|
|
|
|
*
|
|
|
|
* Creates a render node for the CSS border according to @context,
|
|
|
|
* and appends it to the current node of @snapshot, without changing
|
|
|
|
* the current node.
|
|
|
|
*/
|
2016-11-13 15:16:39 +00:00
|
|
|
void
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_render_frame (GtkSnapshot *snapshot,
|
2016-11-13 15:16:39 +00:00
|
|
|
GtkStyleContext *context,
|
2020-07-24 20:32:16 +00:00
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
double width,
|
|
|
|
double height)
|
2016-11-13 15:16:39 +00:00
|
|
|
{
|
2019-02-15 05:15:50 +00:00
|
|
|
GtkCssBoxes boxes;
|
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
g_return_if_fail (snapshot != NULL);
|
2016-11-13 15:16:39 +00:00
|
|
|
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
|
|
|
|
|
2019-02-15 05:15:50 +00:00
|
|
|
gtk_css_boxes_init_border_box (&boxes,
|
|
|
|
gtk_style_context_lookup_style (context),
|
|
|
|
x, y, width, height);
|
|
|
|
gtk_css_style_snapshot_border (&boxes, snapshot);
|
2016-11-13 15:16:39 +00:00
|
|
|
}
|
2016-11-13 22:54:30 +00:00
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_render_focus:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2022-01-05 11:36:55 +00:00
|
|
|
* @context: the style context that defines the focus ring
|
2016-11-18 11:53:57 +00:00
|
|
|
* @x: X origin of the rectangle
|
|
|
|
* @y: Y origin of the rectangle
|
|
|
|
* @width: rectangle width
|
|
|
|
* @height: rectangle height
|
|
|
|
*
|
|
|
|
* Creates a render node for the focus outline according to @context,
|
|
|
|
* and appends it to the current node of @snapshot, without changing
|
|
|
|
* the current node.
|
|
|
|
*/
|
2016-11-14 21:58:58 +00:00
|
|
|
void
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_render_focus (GtkSnapshot *snapshot,
|
2016-11-14 21:58:58 +00:00
|
|
|
GtkStyleContext *context,
|
2020-07-24 20:32:16 +00:00
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
double width,
|
|
|
|
double height)
|
2016-11-14 21:58:58 +00:00
|
|
|
{
|
2019-02-15 05:15:50 +00:00
|
|
|
GtkCssBoxes boxes;
|
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
g_return_if_fail (snapshot != NULL);
|
2016-11-14 21:58:58 +00:00
|
|
|
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
|
|
|
|
|
2019-02-15 05:15:50 +00:00
|
|
|
gtk_css_boxes_init_border_box (&boxes,
|
|
|
|
gtk_style_context_lookup_style (context),
|
|
|
|
x, y, width, height);
|
|
|
|
gtk_css_style_snapshot_outline (&boxes, snapshot);
|
2016-11-14 21:58:58 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_render_layout:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2022-01-05 11:36:55 +00:00
|
|
|
* @context: the style context that defines the text
|
2016-11-18 11:53:57 +00:00
|
|
|
* @x: X origin of the rectangle
|
|
|
|
* @y: Y origin of the rectangle
|
2021-05-20 13:17:04 +00:00
|
|
|
* @layout: the `PangoLayout` to render
|
2016-11-18 11:53:57 +00:00
|
|
|
*
|
|
|
|
* Creates a render node for rendering @layout according to the style
|
|
|
|
* information in @context, and appends it to the current node of @snapshot,
|
|
|
|
* without changing the current node.
|
|
|
|
*/
|
2016-11-13 22:54:30 +00:00
|
|
|
void
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_render_layout (GtkSnapshot *snapshot,
|
2016-11-13 22:54:30 +00:00
|
|
|
GtkStyleContext *context,
|
2020-07-24 20:32:16 +00:00
|
|
|
double x,
|
|
|
|
double y,
|
2016-11-13 22:54:30 +00:00
|
|
|
PangoLayout *layout)
|
|
|
|
{
|
2020-04-17 06:14:34 +00:00
|
|
|
const bool needs_translate = (x != 0 || y != 0);
|
2016-11-13 22:54:30 +00:00
|
|
|
const GdkRGBA *fg_color;
|
2017-09-01 19:33:27 +00:00
|
|
|
GtkCssValue *shadows_value;
|
2017-10-28 20:10:46 +00:00
|
|
|
gboolean has_shadow;
|
2016-11-13 22:54:30 +00:00
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
g_return_if_fail (snapshot != NULL);
|
2016-11-13 22:54:30 +00:00
|
|
|
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
|
|
|
|
g_return_if_fail (PANGO_IS_LAYOUT (layout));
|
|
|
|
|
2020-04-17 06:14:34 +00:00
|
|
|
if (needs_translate)
|
|
|
|
{
|
|
|
|
gtk_snapshot_save (snapshot);
|
|
|
|
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x, y));
|
|
|
|
}
|
2017-08-30 15:14:48 +00:00
|
|
|
|
2020-01-10 12:02:33 +00:00
|
|
|
fg_color = gtk_css_color_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR));
|
2017-08-30 15:14:48 +00:00
|
|
|
|
2017-09-01 19:33:27 +00:00
|
|
|
shadows_value = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_TEXT_SHADOW);
|
2020-07-12 09:33:34 +00:00
|
|
|
has_shadow = gtk_css_shadow_value_push_snapshot (shadows_value, snapshot);
|
2016-11-13 22:54:30 +00:00
|
|
|
|
2018-04-24 01:17:23 +00:00
|
|
|
gtk_snapshot_append_layout (snapshot, layout, fg_color);
|
2017-09-30 11:11:51 +00:00
|
|
|
|
2017-10-28 20:10:46 +00:00
|
|
|
if (has_shadow)
|
2017-09-30 11:11:51 +00:00
|
|
|
gtk_snapshot_pop (snapshot);
|
|
|
|
|
2020-04-17 06:14:34 +00:00
|
|
|
if (needs_translate)
|
|
|
|
gtk_snapshot_restore (snapshot);
|
2016-11-13 22:54:30 +00:00
|
|
|
}
|
2017-12-13 08:05:49 +00:00
|
|
|
|
2019-02-21 02:07:14 +00:00
|
|
|
void
|
2021-09-04 18:51:41 +00:00
|
|
|
gtk_snapshot_append_text (GtkSnapshot *snapshot,
|
|
|
|
PangoFont *font,
|
|
|
|
PangoGlyphString *glyphs,
|
|
|
|
const GdkRGBA *color,
|
|
|
|
float x,
|
|
|
|
float y)
|
2019-02-21 02:07:14 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
|
|
|
float dx, dy;
|
|
|
|
|
|
|
|
gtk_snapshot_ensure_translate (snapshot, &dx, &dy);
|
|
|
|
|
2021-09-04 18:51:41 +00:00
|
|
|
node = gsk_text_node_new (font,
|
|
|
|
glyphs,
|
|
|
|
color,
|
|
|
|
&GRAPHENE_POINT_INIT (x + dx, y + dy));
|
2019-02-21 02:07:14 +00:00
|
|
|
if (node == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_snapshot_append_node_internal (snapshot, node);
|
|
|
|
}
|
|
|
|
|
2018-05-01 10:35:32 +00:00
|
|
|
/**
|
2017-12-13 08:05:49 +00:00
|
|
|
* gtk_snapshot_append_linear_gradient:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2017-12-13 08:05:49 +00:00
|
|
|
* @bounds: the rectangle to render the linear gradient into
|
2018-05-01 10:35:32 +00:00
|
|
|
* @start_point: the point at which the linear gradient will begin
|
|
|
|
* @end_point: the point at which the linear gradient will finish
|
2022-01-05 11:36:55 +00:00
|
|
|
* @stops: (array length=n_stops): the color stops defining the gradient
|
2018-04-20 18:35:00 +00:00
|
|
|
* @n_stops: the number of elements in @stops
|
2017-12-13 08:05:49 +00:00
|
|
|
*
|
|
|
|
* Appends a linear gradient node with the given stops to @snapshot.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_snapshot_append_linear_gradient (GtkSnapshot *snapshot,
|
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
const graphene_point_t *start_point,
|
|
|
|
const graphene_point_t *end_point,
|
|
|
|
const GskColorStop *stops,
|
2018-04-24 01:17:23 +00:00
|
|
|
gsize n_stops)
|
2017-12-13 08:05:49 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
|
|
|
graphene_rect_t real_bounds;
|
2019-02-21 00:54:01 +00:00
|
|
|
float scale_x, scale_y, dx, dy;
|
2019-09-25 15:07:45 +00:00
|
|
|
const GdkRGBA *first_color;
|
|
|
|
gboolean need_gradient = FALSE;
|
2017-12-13 08:05:49 +00:00
|
|
|
|
|
|
|
g_return_if_fail (snapshot != NULL);
|
|
|
|
g_return_if_fail (start_point != NULL);
|
|
|
|
g_return_if_fail (end_point != NULL);
|
|
|
|
g_return_if_fail (stops != NULL);
|
|
|
|
g_return_if_fail (n_stops > 1);
|
|
|
|
|
2019-02-21 00:54:01 +00:00
|
|
|
gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &dx, &dy);
|
|
|
|
gtk_graphene_rect_scale_affine (bounds, scale_x, scale_y, dx, dy, &real_bounds);
|
2017-12-13 08:05:49 +00:00
|
|
|
|
2019-09-25 15:07:45 +00:00
|
|
|
first_color = &stops[0].color;
|
2021-07-15 14:52:38 +00:00
|
|
|
for (gsize i = 0; i < n_stops; i ++)
|
2019-09-25 15:07:45 +00:00
|
|
|
{
|
|
|
|
if (!gdk_rgba_equal (first_color, &stops[i].color))
|
|
|
|
{
|
|
|
|
need_gradient = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_gradient)
|
2021-07-15 14:52:38 +00:00
|
|
|
{
|
|
|
|
graphene_point_t real_start_point, real_end_point;
|
|
|
|
|
|
|
|
real_start_point.x = scale_x * start_point->x + dx;
|
|
|
|
real_start_point.y = scale_y * start_point->y + dy;
|
|
|
|
real_end_point.x = scale_x * end_point->x + dx;
|
|
|
|
real_end_point.y = scale_y * end_point->y + dy;
|
|
|
|
|
|
|
|
node = gsk_linear_gradient_node_new (&real_bounds,
|
|
|
|
&real_start_point,
|
|
|
|
&real_end_point,
|
|
|
|
stops,
|
|
|
|
n_stops);
|
|
|
|
}
|
2019-09-25 15:07:45 +00:00
|
|
|
else
|
2021-07-15 14:52:38 +00:00
|
|
|
{
|
|
|
|
node = gsk_color_node_new (first_color, &real_bounds);
|
|
|
|
}
|
2017-12-13 08:05:49 +00:00
|
|
|
|
2018-03-20 03:33:58 +00:00
|
|
|
gtk_snapshot_append_node_internal (snapshot, node);
|
2017-12-13 08:05:49 +00:00
|
|
|
}
|
|
|
|
|
2018-05-01 10:35:32 +00:00
|
|
|
/**
|
2017-12-13 08:05:49 +00:00
|
|
|
* gtk_snapshot_append_repeating_linear_gradient:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2017-12-13 08:05:49 +00:00
|
|
|
* @bounds: the rectangle to render the linear gradient into
|
2018-05-01 10:35:32 +00:00
|
|
|
* @start_point: the point at which the linear gradient will begin
|
|
|
|
* @end_point: the point at which the linear gradient will finish
|
2022-01-05 11:36:55 +00:00
|
|
|
* @stops: (array length=n_stops): the color stops defining the gradient
|
2018-04-20 18:35:00 +00:00
|
|
|
* @n_stops: the number of elements in @stops
|
2017-12-13 08:05:49 +00:00
|
|
|
*
|
|
|
|
* Appends a repeating linear gradient node with the given stops to @snapshot.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_snapshot_append_repeating_linear_gradient (GtkSnapshot *snapshot,
|
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
const graphene_point_t *start_point,
|
|
|
|
const graphene_point_t *end_point,
|
|
|
|
const GskColorStop *stops,
|
2018-04-24 01:17:23 +00:00
|
|
|
gsize n_stops)
|
2017-12-13 08:05:49 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
|
|
|
graphene_rect_t real_bounds;
|
2019-02-21 00:54:01 +00:00
|
|
|
float scale_x, scale_y, dx, dy;
|
2021-07-15 14:50:32 +00:00
|
|
|
gboolean need_gradient = FALSE;
|
|
|
|
const GdkRGBA *first_color;
|
2017-12-13 08:05:49 +00:00
|
|
|
|
|
|
|
g_return_if_fail (snapshot != NULL);
|
|
|
|
g_return_if_fail (start_point != NULL);
|
|
|
|
g_return_if_fail (end_point != NULL);
|
|
|
|
g_return_if_fail (stops != NULL);
|
|
|
|
g_return_if_fail (n_stops > 1);
|
|
|
|
|
2019-02-21 00:54:01 +00:00
|
|
|
gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &dx, &dy);
|
|
|
|
gtk_graphene_rect_scale_affine (bounds, scale_x, scale_y, dx, dy, &real_bounds);
|
2017-12-13 08:05:49 +00:00
|
|
|
|
2021-07-15 14:50:32 +00:00
|
|
|
first_color = &stops[0].color;
|
|
|
|
for (gsize i = 0; i < n_stops; i ++)
|
|
|
|
{
|
|
|
|
if (!gdk_rgba_equal (first_color, &stops[i].color))
|
|
|
|
{
|
|
|
|
need_gradient = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_gradient)
|
|
|
|
{
|
|
|
|
graphene_point_t real_start_point, real_end_point;
|
|
|
|
|
|
|
|
real_start_point.x = scale_x * start_point->x + dx;
|
|
|
|
real_start_point.y = scale_y * start_point->y + dy;
|
|
|
|
real_end_point.x = scale_x * end_point->x + dx;
|
|
|
|
real_end_point.y = scale_y * end_point->y + dy;
|
|
|
|
|
|
|
|
node = gsk_repeating_linear_gradient_node_new (&real_bounds,
|
|
|
|
&real_start_point,
|
|
|
|
&real_end_point,
|
|
|
|
stops,
|
|
|
|
n_stops);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
node = gsk_color_node_new (first_color, &real_bounds);
|
|
|
|
}
|
2017-12-13 08:05:49 +00:00
|
|
|
|
2018-03-20 03:33:58 +00:00
|
|
|
gtk_snapshot_append_node_internal (snapshot, node);
|
2017-12-13 08:05:49 +00:00
|
|
|
}
|
2019-02-21 01:11:13 +00:00
|
|
|
|
2020-12-03 00:15:53 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_append_conic_gradient:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2020-12-03 00:15:53 +00:00
|
|
|
* @bounds: the rectangle to render the gradient into
|
|
|
|
* @center: the center point of the conic gradient
|
2021-03-02 03:53:00 +00:00
|
|
|
* @rotation: the clockwise rotation in degrees of the starting angle.
|
|
|
|
* 0 means the starting angle is the top.
|
2022-01-05 11:36:55 +00:00
|
|
|
* @stops: (array length=n_stops): the color stops defining the gradient
|
2020-12-03 00:15:53 +00:00
|
|
|
* @n_stops: the number of elements in @stops
|
|
|
|
*
|
|
|
|
* Appends a conic gradient node with the given stops to @snapshot.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_snapshot_append_conic_gradient (GtkSnapshot *snapshot,
|
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
const graphene_point_t *center,
|
|
|
|
float rotation,
|
|
|
|
const GskColorStop *stops,
|
|
|
|
gsize n_stops)
|
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
|
|
|
graphene_rect_t real_bounds;
|
|
|
|
float dx, dy;
|
|
|
|
const GdkRGBA *first_color;
|
|
|
|
gboolean need_gradient = FALSE;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
g_return_if_fail (snapshot != NULL);
|
|
|
|
g_return_if_fail (center != NULL);
|
|
|
|
g_return_if_fail (stops != NULL);
|
|
|
|
g_return_if_fail (n_stops > 1);
|
|
|
|
|
|
|
|
gtk_snapshot_ensure_translate (snapshot, &dx, &dy);
|
|
|
|
graphene_rect_offset_r (bounds, dx, dy, &real_bounds);
|
|
|
|
|
|
|
|
first_color = &stops[0].color;
|
|
|
|
for (i = 0; i < n_stops; i ++)
|
|
|
|
{
|
|
|
|
if (!gdk_rgba_equal (first_color, &stops[i].color))
|
|
|
|
{
|
|
|
|
need_gradient = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_gradient)
|
|
|
|
node = gsk_conic_gradient_node_new (&real_bounds,
|
|
|
|
&GRAPHENE_POINT_INIT(
|
|
|
|
center->x + dx,
|
|
|
|
center->y + dy
|
|
|
|
),
|
|
|
|
rotation,
|
|
|
|
stops,
|
|
|
|
n_stops);
|
|
|
|
else
|
|
|
|
node = gsk_color_node_new (first_color, &real_bounds);
|
|
|
|
|
|
|
|
gtk_snapshot_append_node_internal (snapshot, node);
|
|
|
|
}
|
|
|
|
|
2020-09-29 02:43:27 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_append_radial_gradient:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2020-09-29 02:43:27 +00:00
|
|
|
* @bounds: the rectangle to render the readial gradient into
|
|
|
|
* @center: the center point for the radial gradient
|
|
|
|
* @hradius: the horizontal radius
|
|
|
|
* @vradius: the vertical radius
|
|
|
|
* @start: the start position (on the horizontal axis)
|
|
|
|
* @end: the end position (on the horizontal axis)
|
2022-01-05 11:36:55 +00:00
|
|
|
* @stops: (array length=n_stops): the color stops defining the gradient
|
2020-09-29 02:43:27 +00:00
|
|
|
* @n_stops: the number of elements in @stops
|
|
|
|
*
|
|
|
|
* Appends a radial gradient node with the given stops to @snapshot.
|
|
|
|
*/
|
2020-09-12 03:50:25 +00:00
|
|
|
void
|
|
|
|
gtk_snapshot_append_radial_gradient (GtkSnapshot *snapshot,
|
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
const graphene_point_t *center,
|
2020-09-12 13:17:02 +00:00
|
|
|
float hradius,
|
|
|
|
float vradius,
|
2020-09-12 03:50:25 +00:00
|
|
|
float start,
|
|
|
|
float end,
|
|
|
|
const GskColorStop *stops,
|
|
|
|
gsize n_stops)
|
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
|
|
|
graphene_rect_t real_bounds;
|
|
|
|
float scale_x, scale_y, dx, dy;
|
2021-07-15 14:50:32 +00:00
|
|
|
gboolean need_gradient = FALSE;
|
|
|
|
const GdkRGBA *first_color;
|
2020-09-12 03:50:25 +00:00
|
|
|
|
|
|
|
g_return_if_fail (snapshot != NULL);
|
|
|
|
g_return_if_fail (center != NULL);
|
|
|
|
g_return_if_fail (stops != NULL);
|
|
|
|
g_return_if_fail (n_stops > 1);
|
|
|
|
|
|
|
|
gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &dx, &dy);
|
|
|
|
gtk_graphene_rect_scale_affine (bounds, scale_x, scale_y, dx, dy, &real_bounds);
|
2021-07-15 14:50:32 +00:00
|
|
|
|
|
|
|
first_color = &stops[0].color;
|
|
|
|
for (gsize i = 0; i < n_stops; i ++)
|
|
|
|
{
|
|
|
|
if (!gdk_rgba_equal (first_color, &stops[i].color))
|
|
|
|
{
|
|
|
|
need_gradient = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_gradient)
|
|
|
|
{
|
|
|
|
graphene_point_t real_center;
|
|
|
|
|
|
|
|
real_center.x = scale_x * center->x + dx;
|
|
|
|
real_center.y = scale_y * center->y + dy;
|
|
|
|
|
|
|
|
node = gsk_radial_gradient_node_new (&real_bounds,
|
|
|
|
&real_center,
|
|
|
|
hradius * scale_x,
|
|
|
|
vradius * scale_y,
|
|
|
|
start,
|
|
|
|
end,
|
|
|
|
stops,
|
|
|
|
n_stops);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
node = gsk_color_node_new (first_color, &real_bounds);
|
|
|
|
}
|
2020-09-12 03:50:25 +00:00
|
|
|
|
|
|
|
gtk_snapshot_append_node_internal (snapshot, node);
|
|
|
|
}
|
|
|
|
|
2020-09-29 02:43:27 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_append_repeating_radial_gradient:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2020-09-29 02:43:27 +00:00
|
|
|
* @bounds: the rectangle to render the readial gradient into
|
|
|
|
* @center: the center point for the radial gradient
|
|
|
|
* @hradius: the horizontal radius
|
|
|
|
* @vradius: the vertical radius
|
|
|
|
* @start: the start position (on the horizontal axis)
|
|
|
|
* @end: the end position (on the horizontal axis)
|
2022-01-05 11:36:55 +00:00
|
|
|
* @stops: (array length=n_stops): the color stops defining the gradient
|
2020-09-29 02:43:27 +00:00
|
|
|
* @n_stops: the number of elements in @stops
|
|
|
|
*
|
|
|
|
* Appends a repeating radial gradient node with the given stops to @snapshot.
|
|
|
|
*/
|
2020-09-12 03:50:25 +00:00
|
|
|
void
|
|
|
|
gtk_snapshot_append_repeating_radial_gradient (GtkSnapshot *snapshot,
|
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
const graphene_point_t *center,
|
2020-09-12 13:17:02 +00:00
|
|
|
float hradius,
|
|
|
|
float vradius,
|
2020-09-12 03:50:25 +00:00
|
|
|
float start,
|
|
|
|
float end,
|
|
|
|
const GskColorStop *stops,
|
|
|
|
gsize n_stops)
|
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
|
|
|
graphene_rect_t real_bounds;
|
|
|
|
float scale_x, scale_y, dx, dy;
|
2021-07-15 14:50:32 +00:00
|
|
|
gboolean need_gradient = FALSE;
|
|
|
|
const GdkRGBA *first_color;
|
2020-09-12 03:50:25 +00:00
|
|
|
|
|
|
|
g_return_if_fail (snapshot != NULL);
|
|
|
|
g_return_if_fail (center != NULL);
|
|
|
|
g_return_if_fail (stops != NULL);
|
|
|
|
g_return_if_fail (n_stops > 1);
|
|
|
|
|
|
|
|
gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &dx, &dy);
|
|
|
|
gtk_graphene_rect_scale_affine (bounds, scale_x, scale_y, dx, dy, &real_bounds);
|
2021-07-15 14:50:32 +00:00
|
|
|
|
|
|
|
first_color = &stops[0].color;
|
|
|
|
for (gsize i = 0; i < n_stops; i ++)
|
|
|
|
{
|
|
|
|
if (!gdk_rgba_equal (first_color, &stops[i].color))
|
|
|
|
{
|
|
|
|
need_gradient = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_gradient)
|
|
|
|
{
|
|
|
|
graphene_point_t real_center;
|
|
|
|
|
|
|
|
real_center.x = scale_x * center->x + dx;
|
|
|
|
real_center.y = scale_y * center->y + dy;
|
|
|
|
node = gsk_repeating_radial_gradient_node_new (&real_bounds,
|
|
|
|
&real_center,
|
|
|
|
hradius * scale_x,
|
|
|
|
vradius * scale_y,
|
|
|
|
start,
|
|
|
|
end,
|
|
|
|
stops,
|
|
|
|
n_stops);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
node = gsk_color_node_new (first_color, &real_bounds);
|
|
|
|
}
|
2020-09-12 03:50:25 +00:00
|
|
|
|
|
|
|
gtk_snapshot_append_node_internal (snapshot, node);
|
|
|
|
}
|
|
|
|
|
2019-02-21 01:11:13 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_append_border:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2022-01-05 11:36:55 +00:00
|
|
|
* @outline: 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
|
2021-05-18 21:05:26 +00:00
|
|
|
* the top, right, bottom and left side respectively.
|
2019-02-21 01:11:13 +00:00
|
|
|
* @border_color: (array fixed-size=4): the color used on the top, right,
|
2021-05-18 21:05:26 +00:00
|
|
|
* bottom and left side.
|
2019-02-21 01:11:13 +00:00
|
|
|
*
|
2021-03-02 03:53:00 +00:00
|
|
|
* Appends a stroked border rectangle inside the given @outline.
|
|
|
|
*
|
|
|
|
* The four sides of the border can have different widths and colors.
|
|
|
|
*/
|
2019-02-21 01:11:13 +00:00
|
|
|
void
|
|
|
|
gtk_snapshot_append_border (GtkSnapshot *snapshot,
|
|
|
|
const GskRoundedRect *outline,
|
|
|
|
const float border_width[4],
|
|
|
|
const GdkRGBA border_color[4])
|
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
|
|
|
GskRoundedRect real_outline;
|
|
|
|
float scale_x, scale_y, dx, dy;
|
|
|
|
|
|
|
|
g_return_if_fail (snapshot != NULL);
|
|
|
|
g_return_if_fail (outline != NULL);
|
|
|
|
g_return_if_fail (border_width != NULL);
|
|
|
|
g_return_if_fail (border_color != NULL);
|
|
|
|
|
|
|
|
gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &dx, &dy);
|
2021-03-07 19:35:44 +00:00
|
|
|
gsk_rounded_rect_scale_affine (&real_outline, outline, scale_x, scale_y, dx, dy);
|
2019-02-21 01:11:13 +00:00
|
|
|
|
2021-04-01 14:20:32 +00:00
|
|
|
node = gsk_border_node_new (&real_outline,
|
|
|
|
(float[4]) {
|
|
|
|
border_width[0] * scale_y,
|
|
|
|
border_width[1] * scale_x,
|
|
|
|
border_width[2] * scale_y,
|
|
|
|
border_width[3] * scale_x,
|
|
|
|
},
|
|
|
|
border_color);
|
2019-02-21 01:11:13 +00:00
|
|
|
|
|
|
|
gtk_snapshot_append_node_internal (snapshot, node);
|
|
|
|
}
|
2019-02-21 02:26:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_snapshot_append_inset_shadow:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2019-02-21 02:26:03 +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
|
|
|
|
*
|
|
|
|
* Appends an inset shadow into the box given by @outline.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_snapshot_append_inset_shadow (GtkSnapshot *snapshot,
|
|
|
|
const GskRoundedRect *outline,
|
|
|
|
const GdkRGBA *color,
|
|
|
|
float dx,
|
|
|
|
float dy,
|
|
|
|
float spread,
|
|
|
|
float blur_radius)
|
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
|
|
|
GskRoundedRect real_outline;
|
|
|
|
float scale_x, scale_y, x, y;
|
|
|
|
|
|
|
|
g_return_if_fail (snapshot != NULL);
|
|
|
|
g_return_if_fail (outline != NULL);
|
|
|
|
g_return_if_fail (color != NULL);
|
|
|
|
|
|
|
|
gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &x, &y);
|
2021-03-07 19:35:44 +00:00
|
|
|
gsk_rounded_rect_scale_affine (&real_outline, outline, scale_x, scale_y, x, y);
|
2019-02-21 02:26:03 +00:00
|
|
|
|
|
|
|
node = gsk_inset_shadow_node_new (&real_outline,
|
|
|
|
color,
|
2019-10-11 11:47:40 +00:00
|
|
|
scale_x * dx,
|
|
|
|
scale_y * dy,
|
2019-02-21 02:26:03 +00:00
|
|
|
spread,
|
|
|
|
blur_radius);
|
|
|
|
|
|
|
|
gtk_snapshot_append_node_internal (snapshot, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_snapshot_append_outset_shadow:
|
2021-03-02 03:53:00 +00:00
|
|
|
* @snapshot: a `GtkSnapshot`
|
2019-02-21 02:26:03 +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 outside
|
|
|
|
* @blur_radius: how much blur to apply to the shadow
|
|
|
|
*
|
|
|
|
* Appends an outset shadow node around the box given by @outline.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_snapshot_append_outset_shadow (GtkSnapshot *snapshot,
|
|
|
|
const GskRoundedRect *outline,
|
|
|
|
const GdkRGBA *color,
|
|
|
|
float dx,
|
|
|
|
float dy,
|
|
|
|
float spread,
|
|
|
|
float blur_radius)
|
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
|
|
|
GskRoundedRect real_outline;
|
|
|
|
float scale_x, scale_y, x, y;
|
|
|
|
|
|
|
|
g_return_if_fail (snapshot != NULL);
|
|
|
|
g_return_if_fail (outline != NULL);
|
|
|
|
g_return_if_fail (color != NULL);
|
|
|
|
|
|
|
|
gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &x, &y);
|
2021-03-07 19:35:44 +00:00
|
|
|
gsk_rounded_rect_scale_affine (&real_outline, outline, scale_x, scale_y, x, y);
|
2019-02-21 02:26:03 +00:00
|
|
|
|
|
|
|
node = gsk_outset_shadow_node_new (&real_outline,
|
|
|
|
color,
|
2019-10-11 11:47:40 +00:00
|
|
|
scale_x * dx,
|
|
|
|
scale_y * dy,
|
2019-02-21 02:26:03 +00:00
|
|
|
spread,
|
|
|
|
blur_radius);
|
|
|
|
|
|
|
|
|
|
|
|
gtk_snapshot_append_node_internal (snapshot, node);
|
|
|
|
}
|