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"
|
|
|
|
|
2016-11-13 22:54:30 +00:00
|
|
|
#include "gtkcssrgbavalueprivate.h"
|
|
|
|
#include "gtkcssshadowsvalueprivate.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"
|
2016-11-13 15:16:39 +00:00
|
|
|
#include "gtkstylecontextprivate.h"
|
|
|
|
|
2016-11-11 23:37:54 +00:00
|
|
|
#include "gsk/gskrendernodeprivate.h"
|
|
|
|
|
2017-08-30 15:14:48 +00:00
|
|
|
#include "gtk/gskpango.h"
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gtksnapshot
|
|
|
|
* @Short_description: Auxiliary object for snapshots
|
|
|
|
* @Title: GtkSnapshot
|
|
|
|
*
|
|
|
|
* GtkSnapshot is an auxiliary object that assists in creating #GskRenderNodes
|
|
|
|
* in the #GtkWidget::snapshot vfunc. It functions in a similar way to
|
|
|
|
* a cairo context, and maintains a stack of render nodes and their associated
|
|
|
|
* transformations.
|
|
|
|
*
|
2017-01-13 03:46:09 +00:00
|
|
|
* The node at the top of the stack is the the one that gtk_snapshot_append()
|
2016-12-12 23:11:06 +00:00
|
|
|
* operates on. Use the gtk_snapshot_push() and gtk_snapshot_pop() functions to
|
2016-11-18 11:53:57 +00:00
|
|
|
* change the current node.
|
|
|
|
*
|
|
|
|
* The only way to obtain a #GtkSnapshot object is as an argument to
|
|
|
|
* the #GtkWidget::snapshot vfunc.
|
|
|
|
*/
|
|
|
|
|
2016-12-13 08:40:24 +00:00
|
|
|
static GskRenderNode *
|
2017-10-01 11:49:01 +00:00
|
|
|
gtk_snapshot_collect_default (GtkSnapshot *snapshot,
|
|
|
|
GtkSnapshotState *state,
|
2017-01-11 10:21:27 +00:00
|
|
|
GskRenderNode **nodes,
|
2016-12-13 08:40:24 +00:00
|
|
|
guint n_nodes,
|
2017-01-11 10:21:27 +00:00
|
|
|
const char *name)
|
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);
|
2017-01-11 09:08:58 +00:00
|
|
|
if (name)
|
|
|
|
gsk_render_node_set_name (node, name);
|
2016-12-13 08:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
char *name,
|
|
|
|
cairo_region_t *clip,
|
|
|
|
int translate_x,
|
|
|
|
int translate_y,
|
|
|
|
GtkSnapshotCollectFunc collect_func)
|
2016-11-17 00:55:26 +00:00
|
|
|
{
|
|
|
|
GtkSnapshotState *state;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
g_array_set_size (snapshot->state_stack, snapshot->state_stack->len + 1);
|
|
|
|
state = &g_array_index (snapshot->state_stack, GtkSnapshotState, snapshot->state_stack->len - 1);
|
|
|
|
|
2016-12-13 01:33:15 +00:00
|
|
|
state->name = name;
|
2016-12-13 00:44:52 +00:00
|
|
|
if (clip)
|
|
|
|
state->clip_region = cairo_region_reference (clip);
|
2016-12-13 08:40:24 +00:00
|
|
|
state->translate_x = translate_x;
|
|
|
|
state->translate_y = translate_y;
|
|
|
|
state->collect_func = collect_func;
|
2017-10-01 12:28:11 +00:00
|
|
|
state->start_node_index = snapshot->nodes->len;
|
|
|
|
state->n_nodes = 0;
|
2016-11-17 00:55:26 +00:00
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
g_assert (snapshot->state_stack->len > 0);
|
|
|
|
|
|
|
|
return &g_array_index (snapshot->state_stack, GtkSnapshotState, snapshot->state_stack->len - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkSnapshotState *
|
|
|
|
gtk_snapshot_get_previous_state (const GtkSnapshot *snapshot)
|
|
|
|
{
|
|
|
|
g_assert (snapshot->state_stack->len > 1);
|
|
|
|
|
|
|
|
return &g_array_index (snapshot->state_stack, GtkSnapshotState, snapshot->state_stack->len - 2);
|
2017-01-11 10:41:46 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
g_clear_pointer (&state->clip_region, cairo_region_destroy);
|
|
|
|
g_clear_pointer (&state->name, g_free);
|
2016-11-17 00:55:26 +00:00
|
|
|
}
|
|
|
|
|
2016-11-07 18:10:49 +00:00
|
|
|
void
|
2016-11-17 01:14:10 +00:00
|
|
|
gtk_snapshot_init (GtkSnapshot *snapshot,
|
|
|
|
GskRenderer *renderer,
|
2017-01-11 09:08:58 +00:00
|
|
|
gboolean record_names,
|
2016-12-09 20:33:38 +00:00
|
|
|
const cairo_region_t *clip,
|
|
|
|
const char *name,
|
|
|
|
...)
|
2016-11-07 18:10:49 +00:00
|
|
|
{
|
2016-12-13 01:33:15 +00:00
|
|
|
char *str;
|
2016-12-09 20:33:38 +00:00
|
|
|
|
2017-01-11 09:08:58 +00:00
|
|
|
snapshot->record_names = record_names;
|
2016-11-17 01:14:10 +00:00
|
|
|
snapshot->renderer = renderer;
|
2017-10-01 11:49:01 +00:00
|
|
|
snapshot->state_stack = g_array_new (FALSE, TRUE, sizeof (GtkSnapshotState));
|
|
|
|
g_array_set_clear_func (snapshot->state_stack, (GDestroyNotify)gtk_snapshot_state_clear);
|
2017-10-01 12:28:11 +00:00
|
|
|
snapshot->nodes = g_ptr_array_new_with_free_func ((GDestroyNotify)gsk_render_node_unref);
|
2016-12-09 20:33:38 +00:00
|
|
|
|
2017-01-11 09:08:58 +00:00
|
|
|
if (name && record_names)
|
2016-12-09 20:33:38 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, name);
|
|
|
|
str = g_strdup_vprintf (name, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
2016-12-13 01:33:15 +00:00
|
|
|
else
|
|
|
|
str = NULL;
|
2016-12-09 20:33:38 +00:00
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
gtk_snapshot_push_state (snapshot,
|
|
|
|
str,
|
|
|
|
(cairo_region_t *) clip,
|
|
|
|
0, 0,
|
|
|
|
gtk_snapshot_collect_default);
|
2016-11-07 18:10:49 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_push:
|
|
|
|
* @snapshot: a #GtkSnapshot
|
2016-12-13 01:33:15 +00:00
|
|
|
* @keep_coordinates: If %TRUE, the current offset and clip will be kept.
|
|
|
|
* Otherwise, the clip will be unset and the offset will be reset to
|
|
|
|
* (0, 0).
|
2016-12-01 09:19:24 +00:00
|
|
|
* @name: (transfer none): a printf() style format string for the name for the new node
|
2016-11-18 11:53:57 +00:00
|
|
|
* @...: arguments to insert into the format string
|
|
|
|
*
|
|
|
|
* Creates a new render node, appends it to the current render
|
|
|
|
* node of @snapshot, and makes it the new current render node.
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
2016-11-13 15:16:39 +00:00
|
|
|
void
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_push (GtkSnapshot *snapshot,
|
2016-12-13 01:33:15 +00:00
|
|
|
gboolean keep_coordinates,
|
2016-11-13 15:16:39 +00:00
|
|
|
const char *name,
|
|
|
|
...)
|
|
|
|
{
|
2016-12-13 01:33:15 +00:00
|
|
|
char *str;
|
2016-11-13 15:16:39 +00:00
|
|
|
|
2017-01-11 09:08:58 +00:00
|
|
|
if (name && snapshot->record_names)
|
2016-11-13 15:16:39 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, name);
|
|
|
|
str = g_strdup_vprintf (name, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
2016-12-13 01:33:15 +00:00
|
|
|
else
|
|
|
|
str = NULL;
|
2016-11-13 15:16:39 +00:00
|
|
|
|
2016-12-13 01:33:15 +00:00
|
|
|
if (keep_coordinates)
|
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
GtkSnapshotState *state = gtk_snapshot_get_current_state (snapshot);
|
|
|
|
|
|
|
|
gtk_snapshot_push_state (snapshot,
|
|
|
|
g_strdup (str),
|
|
|
|
state->clip_region,
|
|
|
|
state->translate_x,
|
|
|
|
state->translate_y,
|
|
|
|
gtk_snapshot_collect_default);
|
|
|
|
|
2016-12-13 01:33:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
gtk_snapshot_push_state (snapshot,
|
|
|
|
g_strdup (str),
|
|
|
|
NULL, 0, 0,
|
|
|
|
gtk_snapshot_collect_default);
|
2016-12-13 08:40:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GskRenderNode *
|
2017-10-01 11:49:01 +00:00
|
|
|
gtk_snapshot_collect_transform (GtkSnapshot *snapshot,
|
|
|
|
GtkSnapshotState *state,
|
2017-01-11 10:21:27 +00:00
|
|
|
GskRenderNode **nodes,
|
2016-12-13 08:40:24 +00:00
|
|
|
guint n_nodes,
|
2017-01-11 10:21:27 +00:00
|
|
|
const char *name)
|
2016-12-13 08:40:24 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node, *transform_node;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes, name);
|
2016-12-13 08:40:24 +00:00
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2017-01-11 10:21:27 +00:00
|
|
|
transform_node = gsk_transform_node_new (node, &state->data.transform.transform);
|
2017-01-11 09:08:58 +00:00
|
|
|
if (name)
|
|
|
|
gsk_render_node_set_name (transform_node, name);
|
2016-12-13 08:40:24 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
|
|
|
|
return transform_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_snapshot_push_transform (GtkSnapshot *snapshot,
|
|
|
|
const graphene_matrix_t *transform,
|
|
|
|
const char *name,
|
|
|
|
...)
|
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
GtkSnapshotState *previous_state;
|
2017-01-11 10:21:27 +00:00
|
|
|
GtkSnapshotState *state;
|
2016-12-13 08:40:24 +00:00
|
|
|
graphene_matrix_t offset;
|
|
|
|
char *str;
|
|
|
|
|
2017-01-11 09:08:58 +00:00
|
|
|
if (name && snapshot->record_names)
|
2016-12-13 08:40:24 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, name);
|
|
|
|
str = g_strdup_vprintf (name, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
str = NULL;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
state = gtk_snapshot_push_state (snapshot,
|
|
|
|
str,
|
|
|
|
NULL,
|
|
|
|
0, 0,
|
|
|
|
gtk_snapshot_collect_transform);
|
|
|
|
|
|
|
|
previous_state = gtk_snapshot_get_previous_state (snapshot);
|
2017-01-11 10:21:27 +00:00
|
|
|
|
|
|
|
graphene_matrix_init_translate (&offset,
|
|
|
|
&GRAPHENE_POINT3D_INIT(
|
2017-10-01 11:49:01 +00:00
|
|
|
previous_state->translate_x,
|
|
|
|
previous_state->translate_y,
|
2017-01-11 10:21:27 +00:00
|
|
|
0
|
|
|
|
));
|
|
|
|
|
|
|
|
graphene_matrix_multiply (transform, &offset, &state->data.transform.transform);
|
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,
|
2017-01-11 10:21:27 +00:00
|
|
|
GskRenderNode **nodes,
|
2016-12-17 07:06:59 +00:00
|
|
|
guint n_nodes,
|
2017-01-11 10:21:27 +00:00
|
|
|
const char *name)
|
2016-12-17 07:06:59 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node, *opacity_node;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes, name);
|
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)
|
|
|
|
{
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
opacity_node = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
opacity_node = gsk_opacity_node_new (node, state->data.opacity.opacity);
|
|
|
|
if (name)
|
|
|
|
gsk_render_node_set_name (opacity_node, name);
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
}
|
2016-12-17 07:06:59 +00:00
|
|
|
|
|
|
|
return opacity_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_snapshot_push_opacity (GtkSnapshot *snapshot,
|
|
|
|
double opacity,
|
|
|
|
const char *name,
|
|
|
|
...)
|
|
|
|
{
|
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
|
|
|
char *str;
|
|
|
|
|
2017-01-11 09:08:58 +00:00
|
|
|
if (name && snapshot->record_names)
|
2016-12-17 07:06:59 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, name);
|
|
|
|
str = g_strdup_vprintf (name, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
str = NULL;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
state = gtk_snapshot_push_state (snapshot,
|
|
|
|
str,
|
|
|
|
current_state->clip_region,
|
|
|
|
current_state->translate_x,
|
|
|
|
current_state->translate_y,
|
|
|
|
gtk_snapshot_collect_opacity);
|
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,
|
2017-09-03 03:50:39 +00:00
|
|
|
GskRenderNode **nodes,
|
|
|
|
guint n_nodes,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
GskRenderNode *node, *blur_node;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes, name);
|
2017-09-03 03:50:39 +00:00
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
blur_node = gsk_blur_node_new (node, state->data.blur.radius);
|
|
|
|
if (name)
|
|
|
|
gsk_render_node_set_name (blur_node, name);
|
|
|
|
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
|
|
|
|
return blur_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_snapshot_push_blur (GtkSnapshot *snapshot,
|
|
|
|
double radius,
|
|
|
|
const char *name,
|
|
|
|
...)
|
|
|
|
{
|
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;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
if (name && snapshot->record_names)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, name);
|
|
|
|
str = g_strdup_vprintf (name, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
str = NULL;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
state = gtk_snapshot_push_state (snapshot,
|
|
|
|
str,
|
|
|
|
current_state->clip_region,
|
|
|
|
current_state->translate_x,
|
|
|
|
current_state->translate_y,
|
|
|
|
gtk_snapshot_collect_blur);
|
2017-09-03 03:50:39 +00:00
|
|
|
state->data.blur.radius = radius;
|
2017-10-01 11:49:01 +00:00
|
|
|
current_state = state;
|
2017-09-03 03:50:39 +00:00
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
guint n_nodes,
|
|
|
|
const char *name)
|
2016-12-31 00:14:59 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node, *color_matrix_node;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes, name);
|
2016-12-31 00:14:59 +00:00
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
color_matrix_node = gsk_color_matrix_node_new (node,
|
2017-01-11 10:21:27 +00:00
|
|
|
&state->data.color_matrix.matrix,
|
|
|
|
&state->data.color_matrix.offset);
|
2017-01-11 09:08:58 +00:00
|
|
|
if (name)
|
|
|
|
gsk_render_node_set_name (color_matrix_node, name);
|
2016-12-31 00:14:59 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
|
|
|
|
return color_matrix_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_snapshot_push_color_matrix (GtkSnapshot *snapshot,
|
|
|
|
const graphene_matrix_t *color_matrix,
|
|
|
|
const graphene_vec4_t *color_offset,
|
|
|
|
const char *name,
|
|
|
|
...)
|
|
|
|
{
|
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
|
|
|
char *str;
|
|
|
|
|
2017-01-11 09:08:58 +00:00
|
|
|
if (name && snapshot->record_names)
|
2016-12-31 00:14:59 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, name);
|
|
|
|
str = g_strdup_vprintf (name, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
str = NULL;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
state = gtk_snapshot_push_state (snapshot,
|
2017-01-11 10:21:27 +00:00
|
|
|
str,
|
2017-10-01 11:49:01 +00:00
|
|
|
current_state->clip_region,
|
|
|
|
current_state->translate_x,
|
|
|
|
current_state->translate_y,
|
2017-01-11 10:21:27 +00:00
|
|
|
gtk_snapshot_collect_color_matrix);
|
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);
|
2017-10-01 11:49:01 +00:00
|
|
|
current_state = state;
|
2016-12-31 00:14:59 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 08:40:24 +00:00
|
|
|
static void
|
|
|
|
rectangle_init_from_graphene (cairo_rectangle_int_t *cairo,
|
|
|
|
const graphene_rect_t *graphene)
|
|
|
|
{
|
|
|
|
cairo->x = floorf (graphene->origin.x);
|
|
|
|
cairo->y = floorf (graphene->origin.y);
|
|
|
|
cairo->width = ceilf (graphene->origin.x + graphene->size.width) - cairo->x;
|
|
|
|
cairo->height = ceilf (graphene->origin.y + graphene->size.height) - cairo->y;
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
guint n_nodes,
|
|
|
|
const char *name)
|
2017-01-01 18:52:18 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node, *repeat_node;
|
2017-01-11 10:21:27 +00:00
|
|
|
graphene_rect_t *bounds = &state->data.repeat.bounds;
|
|
|
|
graphene_rect_t *child_bounds = &state->data.repeat.child_bounds;
|
2017-01-01 18:52:18 +00:00
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes, name);
|
2017-01-01 18:52:18 +00:00
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
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-11 09:08:58 +00:00
|
|
|
if (name)
|
|
|
|
gsk_render_node_set_name (repeat_node, name);
|
2017-01-01 18:52:18 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
|
|
|
|
return repeat_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_snapshot_push_repeat (GtkSnapshot *snapshot,
|
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
const graphene_rect_t *child_bounds,
|
|
|
|
const char *name,
|
|
|
|
...)
|
|
|
|
{
|
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;
|
|
|
|
cairo_region_t *clip = NULL;
|
|
|
|
graphene_rect_t real_child_bounds = { { 0 } };
|
2017-01-01 18:52:18 +00:00
|
|
|
char *str;
|
|
|
|
|
2017-01-11 09:08:58 +00:00
|
|
|
if (name && snapshot->record_names)
|
2017-01-01 18:52:18 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, name);
|
|
|
|
str = g_strdup_vprintf (name, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
str = NULL;
|
|
|
|
|
|
|
|
if (child_bounds)
|
|
|
|
{
|
|
|
|
cairo_rectangle_int_t rect;
|
2017-10-01 11:49:01 +00:00
|
|
|
graphene_rect_offset_r (child_bounds, current_state->translate_x, current_state->translate_y, &real_child_bounds);
|
2017-01-11 10:21:27 +00:00
|
|
|
rectangle_init_from_graphene (&rect, &real_child_bounds);
|
2017-01-01 18:52:18 +00:00
|
|
|
clip = cairo_region_create_rectangle (&rect);
|
|
|
|
}
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
state = gtk_snapshot_push_state (snapshot,
|
|
|
|
str,
|
|
|
|
clip,
|
|
|
|
current_state->translate_x,
|
|
|
|
current_state->translate_y,
|
|
|
|
gtk_snapshot_collect_repeat);
|
|
|
|
|
|
|
|
current_state = gtk_snapshot_get_previous_state (snapshot);
|
2017-01-11 10:21:27 +00:00
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
graphene_rect_offset_r (bounds, current_state->translate_x, current_state->translate_y, &state->data.repeat.bounds);
|
2017-01-11 10:21:27 +00:00
|
|
|
state->data.repeat.child_bounds = real_child_bounds;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
current_state = state;
|
2017-01-01 18:52:18 +00:00
|
|
|
|
|
|
|
if (clip)
|
|
|
|
cairo_region_destroy (clip);
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
guint n_nodes,
|
|
|
|
const char *name)
|
2016-12-13 08:40:24 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node, *clip_node;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes, name);
|
2016-12-13 08:40:24 +00:00
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2017-01-11 10:21:27 +00:00
|
|
|
clip_node = gsk_clip_node_new (node, &state->data.clip.bounds);
|
2017-01-11 09:08:58 +00:00
|
|
|
if (name)
|
|
|
|
gsk_render_node_set_name (clip_node, name);
|
2016-12-13 08:40:24 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
|
|
|
|
return clip_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_snapshot_push_clip (GtkSnapshot *snapshot,
|
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
const char *name,
|
|
|
|
...)
|
|
|
|
{
|
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;
|
|
|
|
graphene_rect_t real_bounds;
|
2016-12-13 08:40:24 +00:00
|
|
|
cairo_region_t *clip;
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
char *str;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
graphene_rect_offset_r (bounds, current_state->translate_x, current_state->translate_y, &real_bounds);
|
2016-12-13 08:40:24 +00:00
|
|
|
|
2017-01-11 09:08:58 +00:00
|
|
|
if (name && snapshot->record_names)
|
2016-12-13 08:40:24 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, name);
|
|
|
|
str = g_strdup_vprintf (name, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
str = NULL;
|
2017-01-11 10:21:27 +00:00
|
|
|
|
|
|
|
rectangle_init_from_graphene (&rect, &real_bounds);
|
2017-10-01 11:49:01 +00:00
|
|
|
if (current_state->clip_region)
|
2016-12-13 08:40:24 +00:00
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
clip = cairo_region_copy (current_state->clip_region);
|
2016-12-13 08:40:24 +00:00
|
|
|
cairo_region_intersect_rectangle (clip, &rect);
|
2016-12-13 01:33:15 +00:00
|
|
|
}
|
2016-12-13 08:40:24 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
clip = cairo_region_create_rectangle (&rect);
|
|
|
|
}
|
2017-10-01 11:49:01 +00:00
|
|
|
state = gtk_snapshot_push_state (snapshot,
|
2017-01-11 10:21:27 +00:00
|
|
|
str,
|
|
|
|
clip,
|
2017-10-01 11:49:01 +00:00
|
|
|
current_state->translate_x,
|
|
|
|
current_state->translate_y,
|
2017-01-11 10:21:27 +00:00
|
|
|
gtk_snapshot_collect_clip);
|
|
|
|
|
|
|
|
state->data.clip.bounds = real_bounds;
|
|
|
|
|
2016-12-13 08:40:24 +00:00
|
|
|
cairo_region_destroy (clip);
|
2016-11-13 15:16:39 +00:00
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
guint n_nodes,
|
|
|
|
const char *name)
|
2016-12-13 20:59:28 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node, *clip_node;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes, name);
|
2016-12-13 20:59:28 +00:00
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2017-01-11 10:21:27 +00:00
|
|
|
clip_node = gsk_rounded_clip_node_new (node, &state->data.rounded_clip.bounds);
|
2017-01-11 09:08:58 +00:00
|
|
|
if (name)
|
|
|
|
gsk_render_node_set_name (clip_node, name);
|
2016-12-13 20:59:28 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
|
|
|
|
return clip_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_snapshot_push_rounded_clip (GtkSnapshot *snapshot,
|
|
|
|
const GskRoundedRect *bounds,
|
|
|
|
const char *name,
|
|
|
|
...)
|
|
|
|
{
|
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;
|
|
|
|
GskRoundedRect real_bounds;
|
2016-12-13 20:59:28 +00:00
|
|
|
cairo_region_t *clip;
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
char *str;
|
|
|
|
|
2017-01-11 10:21:27 +00:00
|
|
|
gsk_rounded_rect_init_copy (&real_bounds, bounds);
|
2017-10-01 11:49:01 +00:00
|
|
|
gsk_rounded_rect_offset (&real_bounds, current_state->translate_x, current_state->translate_y);
|
2016-12-13 20:59:28 +00:00
|
|
|
|
2017-01-11 09:08:58 +00:00
|
|
|
if (name && snapshot->record_names)
|
2016-12-13 20:59:28 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, name);
|
|
|
|
str = g_strdup_vprintf (name, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
str = NULL;
|
2017-01-11 10:21:27 +00:00
|
|
|
|
|
|
|
rectangle_init_from_graphene (&rect, &real_bounds.bounds);
|
2017-10-01 11:49:01 +00:00
|
|
|
if (current_state->clip_region)
|
2016-12-13 20:59:28 +00:00
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
clip = cairo_region_copy (current_state->clip_region);
|
2016-12-13 20:59:28 +00:00
|
|
|
cairo_region_intersect_rectangle (clip, &rect);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clip = cairo_region_create_rectangle (&rect);
|
|
|
|
}
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
state = gtk_snapshot_push_state (snapshot,
|
2017-01-11 10:21:27 +00:00
|
|
|
str,
|
|
|
|
clip,
|
2017-10-01 11:49:01 +00:00
|
|
|
current_state->translate_x,
|
|
|
|
current_state->translate_y,
|
2017-01-11 10:21:27 +00:00
|
|
|
gtk_snapshot_collect_rounded_clip);
|
|
|
|
|
|
|
|
|
|
|
|
state->data.rounded_clip.bounds = real_bounds;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
current_state = state;
|
2016-12-13 20:59:28 +00:00
|
|
|
cairo_region_destroy (clip);
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
guint n_nodes,
|
|
|
|
const char *name)
|
2016-12-18 23:45:35 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node, *shadow_node;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes, name);
|
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);
|
2017-01-11 09:08:58 +00:00
|
|
|
if (name)
|
|
|
|
gsk_render_node_set_name (shadow_node, name);
|
2016-12-18 23:45:35 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (node);
|
2017-10-01 11:49:01 +00:00
|
|
|
g_free (state->data.shadow.shadows);
|
2016-12-18 23:45:35 +00:00
|
|
|
|
|
|
|
return shadow_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_snapshot_push_shadow (GtkSnapshot *snapshot,
|
|
|
|
const GskShadow *shadow,
|
|
|
|
gsize n_shadows,
|
|
|
|
const char *name,
|
|
|
|
...)
|
|
|
|
{
|
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-18 23:45:35 +00:00
|
|
|
char *str;
|
|
|
|
|
2017-01-11 09:08:58 +00:00
|
|
|
if (name && snapshot->record_names)
|
2016-12-18 23:45:35 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, name);
|
|
|
|
str = g_strdup_vprintf (name, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
str = NULL;
|
2017-01-11 10:21:27 +00:00
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
state = gtk_snapshot_push_state (snapshot,
|
|
|
|
str,
|
|
|
|
current_state->clip_region,
|
|
|
|
current_state->translate_x,
|
|
|
|
current_state->translate_y,
|
|
|
|
gtk_snapshot_collect_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,
|
|
|
|
guint n_nodes,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
top_node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes, name);
|
2017-01-12 22:20:31 +00:00
|
|
|
bottom_node = state->data.blend.bottom_node;
|
|
|
|
|
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_set_name (blend_node, name);
|
|
|
|
|
|
|
|
gsk_render_node_unref (top_node);
|
|
|
|
gsk_render_node_unref (bottom_node);
|
|
|
|
|
|
|
|
return blend_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
guint n_nodes,
|
|
|
|
const char *name)
|
|
|
|
{
|
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);
|
|
|
|
|
|
|
|
prev_state->data.blend.bottom_node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes, name);
|
|
|
|
|
2017-01-12 22:20:31 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_snapshot_push_blend:
|
|
|
|
* @snapshot: a #GtkSnapshot
|
|
|
|
* @blend_mode: blend mode to use
|
|
|
|
* @name: printf format string for name of the pushed node
|
|
|
|
* @...: printf-style arguments for the @name string
|
|
|
|
*
|
|
|
|
* Blends together 2 images with the given blend mode.
|
|
|
|
*
|
|
|
|
* Until the first call to 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 gtk_snapshot_pop().
|
|
|
|
*
|
|
|
|
* Calling this function requires 2 subsequent calls to gtk_snapshot_pop().
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_snapshot_push_blend (GtkSnapshot *snapshot,
|
|
|
|
GskBlendMode blend_mode,
|
|
|
|
const char *name,
|
|
|
|
...)
|
|
|
|
{
|
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
|
|
|
char *str;
|
|
|
|
|
|
|
|
if (name && snapshot->record_names)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, name);
|
|
|
|
str = g_strdup_vprintf (name, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
str = NULL;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
top_state = gtk_snapshot_push_state (snapshot,
|
2017-10-08 03:31:47 +00:00
|
|
|
str,
|
|
|
|
current_state->clip_region,
|
|
|
|
current_state->translate_x,
|
|
|
|
current_state->translate_y,
|
|
|
|
gtk_snapshot_collect_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,
|
|
|
|
g_strdup (str),
|
|
|
|
top_state->clip_region,
|
|
|
|
top_state->translate_x,
|
|
|
|
top_state->translate_y,
|
|
|
|
gtk_snapshot_collect_blend_bottom);
|
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,
|
|
|
|
guint n_nodes,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
GskRenderNode *start_node, *end_node, *node;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
end_node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes, name);
|
2017-01-12 21:00:38 +00:00
|
|
|
start_node = state->data.cross_fade.start_node;
|
|
|
|
|
|
|
|
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_set_name (node, name);
|
|
|
|
|
|
|
|
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_set_name (node, name);
|
|
|
|
|
|
|
|
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_set_name (node, name);
|
|
|
|
|
|
|
|
gsk_render_node_unref (end_node);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
node = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
guint n_nodes,
|
|
|
|
const char *name)
|
|
|
|
{
|
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);
|
|
|
|
|
|
|
|
prev_state->data.cross_fade.start_node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes, name);
|
|
|
|
|
2017-01-12 21:00:38 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_snapshot_push_cross_fade:
|
|
|
|
* @snapshot: a #GtkSnapshot
|
|
|
|
* @progress: progress between 0.0 and 1.0
|
|
|
|
* @name: printf format string for name of the pushed node
|
|
|
|
* @...: printf-style arguments for the @name string
|
|
|
|
*
|
|
|
|
* Snapshots a cross-fade operation between two images with the
|
|
|
|
* given @progress.
|
|
|
|
*
|
|
|
|
* Until the first call to gtk_snapshot_pop(), the start image
|
|
|
|
* will be snapshot. After that call, the end image will be recorded
|
|
|
|
* until the second call to gtk_snapshot_pop().
|
|
|
|
*
|
|
|
|
* Calling this function requires 2 calls to gtk_snapshot_pop().
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_snapshot_push_cross_fade (GtkSnapshot *snapshot,
|
|
|
|
double progress,
|
|
|
|
const char *name,
|
|
|
|
...)
|
|
|
|
{
|
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
|
|
|
char *str;
|
|
|
|
|
|
|
|
if (name && snapshot->record_names)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, name);
|
|
|
|
str = g_strdup_vprintf (name, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
str = NULL;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
end_state = gtk_snapshot_push_state (snapshot,
|
2017-10-02 13:25:44 +00:00
|
|
|
str,
|
|
|
|
current_state->clip_region,
|
|
|
|
current_state->translate_x,
|
|
|
|
current_state->translate_y,
|
|
|
|
gtk_snapshot_collect_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,
|
|
|
|
g_strdup (str),
|
|
|
|
end_state->clip_region,
|
|
|
|
end_state->translate_x,
|
|
|
|
end_state->translate_y,
|
|
|
|
gtk_snapshot_collect_cross_fade_start);
|
2017-01-12 21:00:38 +00:00
|
|
|
}
|
|
|
|
|
2017-01-12 23:39:59 +00:00
|
|
|
static GskRenderNode *
|
|
|
|
gtk_snapshot_pop_internal (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
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
if (snapshot->state_stack->len == 0)
|
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);
|
|
|
|
state_index = snapshot->state_stack->len - 1;
|
2016-11-11 23:37:54 +00:00
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
node = state->collect_func (snapshot,
|
|
|
|
state,
|
2017-10-01 12:28:11 +00:00
|
|
|
(GskRenderNode **) snapshot->nodes->pdata + state->start_node_index,
|
|
|
|
state->n_nodes,
|
2017-01-11 10:21:27 +00:00
|
|
|
state->name);
|
2016-12-13 01:33:15 +00:00
|
|
|
|
2017-10-01 12:28:11 +00:00
|
|
|
/* The collect func may not modify the state stack... */
|
|
|
|
g_assert (state_index == snapshot->state_stack->len - 1);
|
|
|
|
|
|
|
|
/* Remove all the state's nodes from the list of nodes */
|
|
|
|
g_assert (state->start_node_index + state->n_nodes == snapshot->nodes->len);
|
|
|
|
g_ptr_array_remove_range (snapshot->nodes,
|
|
|
|
snapshot->nodes->len - state->n_nodes,
|
|
|
|
state->n_nodes);
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
g_array_remove_index (snapshot->state_stack, state_index);
|
2016-12-13 01:33:15 +00:00
|
|
|
|
|
|
|
return node;
|
2016-11-07 18:10:49 +00:00
|
|
|
}
|
|
|
|
|
2017-01-12 23:39:59 +00:00
|
|
|
GskRenderNode *
|
|
|
|
gtk_snapshot_finish (GtkSnapshot *snapshot)
|
|
|
|
{
|
|
|
|
GskRenderNode *result;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
/* We should have exactly our initial state */
|
|
|
|
if (snapshot->state_stack->len > 1)
|
2017-01-12 23:39:59 +00:00
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_warning ("Too many gtk_snapshot_push() calls. Still there:");
|
|
|
|
for (i = snapshot->state_stack->len - 1; i >= 0; i --)
|
|
|
|
{
|
|
|
|
const GtkSnapshotState *s = &g_array_index (snapshot->state_stack, GtkSnapshotState, i);
|
|
|
|
|
|
|
|
g_warning ("%s", s->name);
|
|
|
|
}
|
2017-01-12 23:39:59 +00:00
|
|
|
}
|
2017-10-01 11:49:01 +00:00
|
|
|
|
|
|
|
result = gtk_snapshot_pop_internal (snapshot);
|
2017-01-12 23:39:59 +00:00
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
g_array_free (snapshot->state_stack, TRUE);
|
2017-10-01 12:28:11 +00:00
|
|
|
g_ptr_array_free (snapshot->nodes, TRUE);
|
2017-01-12 23:39:59 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-12-13 08:40:24 +00:00
|
|
|
/**
|
2017-01-12 23:39:59 +00:00
|
|
|
* gtk_snapshot_pop:
|
2016-12-13 08:40:24 +00:00
|
|
|
* @snapshot: a #GtkSnapshot
|
|
|
|
*
|
|
|
|
* Removes the top element from the stack of render nodes,
|
|
|
|
* and appends it to the node underneath it.
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
|
|
|
void
|
2017-01-12 23:39:59 +00:00
|
|
|
gtk_snapshot_pop (GtkSnapshot *snapshot)
|
2016-12-13 08:40:24 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
|
|
|
|
2017-01-12 23:39:59 +00:00
|
|
|
node = gtk_snapshot_pop_internal (snapshot);
|
2016-12-17 07:03:43 +00:00
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
gtk_snapshot_append_node (snapshot, node);
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
}
|
2016-12-13 08:40:24 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_get_renderer:
|
|
|
|
* @snapshot: a #GtkSnapshot
|
|
|
|
*
|
|
|
|
* Obtains the #GskRenderer that this snapshot will be
|
|
|
|
* rendered with.
|
|
|
|
*
|
2016-12-01 09:19:24 +00:00
|
|
|
* Returns: (transfer none): the #GskRenderer
|
2016-11-18 11:53:57 +00:00
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
2016-11-07 18:10:49 +00:00
|
|
|
GskRenderer *
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_get_renderer (const GtkSnapshot *snapshot)
|
2016-11-07 18:10:49 +00:00
|
|
|
{
|
2016-11-18 12:57:10 +00:00
|
|
|
return snapshot->renderer;
|
2016-11-07 18:10:49 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
2017-01-13 13:36:56 +00:00
|
|
|
* gtk_snapshot_offset:
|
2016-12-12 23:11:06 +00:00
|
|
|
* @snapshot: a $GtkSnapshot
|
|
|
|
* @x: horizontal translation
|
|
|
|
* @y: vertical translation
|
2016-11-18 11:53:57 +00:00
|
|
|
*
|
2016-12-12 23:11:06 +00:00
|
|
|
* Appends a translation by (@x, @y) to the current transformation.
|
2016-11-18 11:53:57 +00:00
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
2016-11-11 23:37:54 +00:00
|
|
|
void
|
2017-01-13 13:36:56 +00:00
|
|
|
gtk_snapshot_offset (GtkSnapshot *snapshot,
|
|
|
|
int x,
|
|
|
|
int y)
|
2016-11-11 23:37:54 +00:00
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
GtkSnapshotState *current_state = gtk_snapshot_get_current_state (snapshot);
|
|
|
|
|
|
|
|
current_state->translate_x += x;
|
|
|
|
current_state->translate_y += y;
|
2016-11-11 23:37:54 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
2016-12-12 23:11:06 +00:00
|
|
|
* gtk_snapshot_get_offset:
|
2016-11-18 11:53:57 +00:00
|
|
|
* @snapshot: a #GtkSnapshot
|
2016-12-21 17:16:34 +00:00
|
|
|
* @x: (out) (optional): return location for x offset
|
|
|
|
* @y: (out) (optional): return location for y offset
|
2016-11-18 11:53:57 +00:00
|
|
|
*
|
2016-12-12 23:11:06 +00:00
|
|
|
* Queries the offset managed by @snapshot. This offset is the
|
2017-01-13 13:36:56 +00:00
|
|
|
* accumulated sum of calls to gtk_snapshot_offset().
|
2016-11-18 11:53:57 +00:00
|
|
|
*
|
2016-12-12 23:11:06 +00:00
|
|
|
* Use this offset to determine how to offset nodes that you
|
|
|
|
* manually add to the snapshot using
|
2017-01-13 03:46:09 +00:00
|
|
|
* gtk_snapshot_append().
|
2016-11-18 11:53:57 +00:00
|
|
|
*
|
2016-12-12 23:11:06 +00:00
|
|
|
* Note that other functions that add nodes for you, such as
|
2017-01-13 03:46:09 +00:00
|
|
|
* gtk_snapshot_append_cairo() will add this offset for
|
2016-12-12 23:11:06 +00:00
|
|
|
* you.
|
|
|
|
**/
|
2016-11-11 23:37:54 +00:00
|
|
|
void
|
2016-12-12 23:11:06 +00:00
|
|
|
gtk_snapshot_get_offset (GtkSnapshot *snapshot,
|
2017-01-11 15:14:03 +00:00
|
|
|
int *x,
|
|
|
|
int *y)
|
2016-11-11 23:37:54 +00:00
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
const GtkSnapshotState *current_state = gtk_snapshot_get_current_state (snapshot);
|
|
|
|
|
2016-12-12 23:11:06 +00:00
|
|
|
if (x)
|
2017-10-01 11:49:01 +00:00
|
|
|
*x = current_state->translate_x;
|
2016-11-11 23:37:54 +00:00
|
|
|
|
2016-12-12 23:11:06 +00:00
|
|
|
if (y)
|
2017-10-01 11:49:01 +00:00
|
|
|
*y = current_state->translate_y;
|
2016-11-11 23:37:54 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_append_node:
|
|
|
|
* @snapshot: a #GtkSnapshot
|
|
|
|
* @node: a #GskRenderNode
|
|
|
|
*
|
|
|
|
* Appends @node to the current render node of @snapshot,
|
|
|
|
* without changing the current node. If @snapshot does
|
|
|
|
* not have a current node yet, @node will become the
|
|
|
|
* initial node.
|
|
|
|
*/
|
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)
|
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
GtkSnapshotState *current_state;
|
2017-10-01 12:28:11 +00:00
|
|
|
|
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));
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
current_state = gtk_snapshot_get_current_state (snapshot);
|
|
|
|
|
|
|
|
if (current_state)
|
2016-11-17 00:55:26 +00:00
|
|
|
{
|
2017-10-01 12:28:11 +00:00
|
|
|
g_ptr_array_add (snapshot->nodes, gsk_render_node_ref (node));
|
|
|
|
current_state->n_nodes ++;
|
2016-11-17 00:55:26 +00:00
|
|
|
}
|
2016-11-11 23:37:54 +00:00
|
|
|
else
|
|
|
|
{
|
2016-11-15 21:39:05 +00:00
|
|
|
g_critical ("Tried appending a node to an already finished snapshot.");
|
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:
|
2016-11-18 12:57:10 +00:00
|
|
|
* @snapshot: a #GtkSnapshot
|
2016-11-18 11:53:57 +00:00
|
|
|
* @bounds: the bounds for the new node
|
2016-12-01 09:19:24 +00:00
|
|
|
* @name: (transfer none): a printf() style format string for the name for the new node
|
2016-11-18 11:53:57 +00:00
|
|
|
* @...: arguments to insert into the format string
|
|
|
|
*
|
|
|
|
* Creates a new render node and appends it to the current render
|
|
|
|
* node of @snapshot, without changing the current node.
|
|
|
|
*
|
|
|
|
* Returns: a cairo_t suitable for drawing the contents of the newly
|
|
|
|
* created render node
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
2016-11-11 23:37:54 +00:00
|
|
|
cairo_t *
|
2017-01-13 03:46:09 +00:00
|
|
|
gtk_snapshot_append_cairo (GtkSnapshot *snapshot,
|
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
const char *name,
|
|
|
|
...)
|
2016-11-11 23:37:54 +00:00
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
const GtkSnapshotState *current_state = gtk_snapshot_get_current_state (snapshot);
|
2016-11-11 23:37:54 +00:00
|
|
|
GskRenderNode *node;
|
2016-12-12 23:11:06 +00:00
|
|
|
graphene_rect_t real_bounds;
|
|
|
|
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);
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
graphene_rect_offset_r (bounds, current_state->translate_x, current_state->translate_y, &real_bounds);
|
2016-12-12 23:11:06 +00:00
|
|
|
node = gsk_cairo_node_new (&real_bounds);
|
2016-11-11 23:37:54 +00:00
|
|
|
|
2017-01-11 09:08:58 +00:00
|
|
|
if (name && snapshot->record_names)
|
2016-11-11 23:37:54 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
va_start (args, name);
|
|
|
|
str = g_strdup_vprintf (name, args);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
gsk_render_node_set_name (node, str);
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_append_node (snapshot, node);
|
2016-11-11 23:37:54 +00:00
|
|
|
gsk_render_node_unref (node);
|
|
|
|
|
2016-12-12 23:11:06 +00:00
|
|
|
cr = gsk_cairo_node_get_draw_context (node, snapshot->renderer);
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
cairo_translate (cr, current_state->translate_x, current_state->translate_y);
|
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:
|
2016-12-13 03:22:13 +00:00
|
|
|
* @snapshot: a #GtkSnapshot
|
2017-11-02 20:39:00 +00:00
|
|
|
* @texture: the #GdkTexture to render
|
2016-12-13 03:22:13 +00:00
|
|
|
* @bounds: the bounds for the new node
|
|
|
|
* @name: (transfer none): a printf() style format string for the name for the new node
|
|
|
|
* @...: arguments to insert into the format string
|
|
|
|
*
|
|
|
|
* Creates a new render node drawing the @texture into the given @bounds and appends it
|
|
|
|
* to the current render node of @snapshot.
|
|
|
|
**/
|
|
|
|
void
|
2017-01-13 03:46:09 +00:00
|
|
|
gtk_snapshot_append_texture (GtkSnapshot *snapshot,
|
2017-11-02 20:39:00 +00:00
|
|
|
GdkTexture *texture,
|
2017-01-13 03:46:09 +00:00
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
const char *name,
|
|
|
|
...)
|
2016-12-13 03:22:13 +00:00
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
GtkSnapshotState *current_state = gtk_snapshot_get_current_state (snapshot);
|
2016-12-13 03:22:13 +00:00
|
|
|
GskRenderNode *node;
|
|
|
|
graphene_rect_t real_bounds;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
graphene_rect_offset_r (bounds, current_state->translate_x, current_state->translate_y, &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
|
|
|
|
2017-01-11 09:08:58 +00:00
|
|
|
if (name && snapshot->record_names)
|
2016-12-13 03:22:13 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
va_start (args, name);
|
|
|
|
str = g_strdup_vprintf (name, args);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
gsk_render_node_set_name (node, str);
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_snapshot_append_node (snapshot, node);
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 03:46:09 +00:00
|
|
|
* gtk_snapshot_append_color:
|
2016-12-13 03:22:13 +00:00
|
|
|
* @snapshot: a #GtkSnapshot
|
|
|
|
* @color: the #GdkRGBA to draw
|
|
|
|
* @bounds: the bounds for the new node
|
|
|
|
* @name: (transfer none): a printf() style format string for the name for the new node
|
|
|
|
* @...: arguments to insert into the format string
|
|
|
|
*
|
|
|
|
* Creates a new render node drawing the @color into the given @bounds and appends it
|
|
|
|
* to the current render node of @snapshot.
|
|
|
|
*
|
|
|
|
* You should try to avoid calling this function if @color is transparent.
|
|
|
|
**/
|
|
|
|
void
|
2017-01-13 03:46:09 +00:00
|
|
|
gtk_snapshot_append_color (GtkSnapshot *snapshot,
|
|
|
|
const GdkRGBA *color,
|
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
const char *name,
|
|
|
|
...)
|
2016-12-13 03:22:13 +00:00
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
const GtkSnapshotState *current_state = gtk_snapshot_get_current_state (snapshot);
|
2016-12-13 03:22:13 +00:00
|
|
|
GskRenderNode *node;
|
|
|
|
graphene_rect_t real_bounds;
|
|
|
|
|
|
|
|
g_return_if_fail (snapshot != NULL);
|
|
|
|
g_return_if_fail (color != NULL);
|
|
|
|
g_return_if_fail (bounds != NULL);
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
graphene_rect_offset_r (bounds, current_state->translate_x, current_state->translate_y, &real_bounds);
|
2016-12-13 03:22:13 +00:00
|
|
|
node = gsk_color_node_new (color, &real_bounds);
|
|
|
|
|
2017-01-11 09:08:58 +00:00
|
|
|
if (name && snapshot->record_names)
|
2016-12-13 03:22:13 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
va_start (args, name);
|
|
|
|
str = g_strdup_vprintf (name, args);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
gsk_render_node_set_name (node, str);
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_snapshot_append_node (snapshot, node);
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_clips_rect:
|
|
|
|
* @snapshot: a #GtkSnapshot
|
|
|
|
* @bounds: a rectangle
|
|
|
|
*
|
|
|
|
* Tests whether the rectangle is entirely outside the clip region of @snapshot.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE is @bounds is entirely outside the clip region
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
2016-11-13 19:47:34 +00:00
|
|
|
gboolean
|
2017-01-13 03:46:09 +00:00
|
|
|
gtk_snapshot_clips_rect (GtkSnapshot *snapshot,
|
2017-01-11 15:14:03 +00:00
|
|
|
const cairo_rectangle_int_t *rect)
|
2016-11-13 19:47:34 +00:00
|
|
|
{
|
2017-10-01 11:49:01 +00:00
|
|
|
const GtkSnapshotState *current_state = gtk_snapshot_get_current_state (snapshot);
|
2017-01-11 15:14:03 +00:00
|
|
|
cairo_rectangle_int_t offset_rect;
|
2016-11-17 02:31:15 +00:00
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
if (current_state->clip_region == NULL)
|
2016-12-13 00:44:52 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
offset_rect.x = rect->x + current_state->translate_x;
|
|
|
|
offset_rect.y = rect->y + current_state->translate_y;
|
2017-01-11 15:14:03 +00:00
|
|
|
offset_rect.width = rect->width;
|
|
|
|
offset_rect.height = rect->height;
|
2016-11-17 02:31:15 +00:00
|
|
|
|
2017-10-01 11:49:01 +00:00
|
|
|
return cairo_region_contains_rectangle (current_state->clip_region, &offset_rect) == CAIRO_REGION_OVERLAP_OUT;
|
2016-11-13 19:47:34 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_render_background:
|
2016-11-18 12:57:10 +00:00
|
|
|
* @snapshot: a #GtkSnapshot
|
2016-11-18 11:53:57 +00:00
|
|
|
* @context: the #GtkStyleContext to use
|
|
|
|
* @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.
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
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,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble width,
|
|
|
|
gdouble height)
|
|
|
|
{
|
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));
|
|
|
|
|
2017-01-13 13:36:56 +00:00
|
|
|
gtk_snapshot_offset (snapshot, x, y);
|
2016-11-13 15:16:39 +00:00
|
|
|
gtk_css_style_snapshot_background (gtk_style_context_lookup_style (context),
|
2016-11-18 12:57:10 +00:00
|
|
|
snapshot,
|
2016-12-19 17:46:24 +00:00
|
|
|
width, height);
|
2017-01-13 13:36:56 +00:00
|
|
|
gtk_snapshot_offset (snapshot, -x, -y);
|
2016-11-13 15:16:39 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_render_frame:
|
|
|
|
* @snapshot: a #GtkSnapshot
|
|
|
|
* @context: the #GtkStyleContext to use
|
|
|
|
* @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.
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
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,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble width,
|
|
|
|
gdouble height)
|
|
|
|
{
|
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));
|
|
|
|
|
2017-01-13 13:36:56 +00:00
|
|
|
gtk_snapshot_offset (snapshot, x, y);
|
2016-11-13 15:16:39 +00:00
|
|
|
gtk_css_style_snapshot_border (gtk_style_context_lookup_style (context),
|
2016-11-18 12:57:10 +00:00
|
|
|
snapshot,
|
2016-12-19 17:46:24 +00:00
|
|
|
width, height);
|
2017-01-13 13:36:56 +00:00
|
|
|
gtk_snapshot_offset (snapshot, -x, -y);
|
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:
|
2016-11-18 12:57:10 +00:00
|
|
|
* @snapshot: a #GtkSnapshot
|
2016-11-18 11:53:57 +00:00
|
|
|
* @context: the #GtkStyleContext to use
|
|
|
|
* @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.
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
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,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble width,
|
|
|
|
gdouble height)
|
|
|
|
{
|
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));
|
|
|
|
|
2017-01-13 13:36:56 +00:00
|
|
|
gtk_snapshot_offset (snapshot, x, y);
|
2016-11-14 21:58:58 +00:00
|
|
|
gtk_css_style_snapshot_outline (gtk_style_context_lookup_style (context),
|
2016-11-18 12:57:10 +00:00
|
|
|
snapshot,
|
2016-11-14 21:58:58 +00:00
|
|
|
width, height);
|
2017-01-13 13:36:56 +00:00
|
|
|
gtk_snapshot_offset (snapshot, -x, -y);
|
2016-11-14 21:58:58 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_render_layout:
|
2016-11-18 12:57:10 +00:00
|
|
|
* @snapshot: a #GtkSnapshot
|
2016-11-18 11:53:57 +00:00
|
|
|
* @context: the #GtkStyleContext to use
|
|
|
|
* @x: X origin of the rectangle
|
|
|
|
* @y: Y origin of the rectangle
|
|
|
|
* @layout: the #PangoLayout to render
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
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,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
PangoLayout *layout)
|
|
|
|
{
|
|
|
|
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));
|
|
|
|
|
2017-08-30 15:14:48 +00:00
|
|
|
gtk_snapshot_offset (snapshot, x, y);
|
|
|
|
|
2016-11-13 22:54:30 +00:00
|
|
|
fg_color = _gtk_css_rgba_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);
|
2017-10-28 20:10:46 +00:00
|
|
|
has_shadow = gtk_css_shadows_value_push_snapshot (shadows_value, snapshot);
|
2016-11-13 22:54:30 +00:00
|
|
|
|
2017-09-30 11:11:51 +00:00
|
|
|
gsk_pango_show_layout (snapshot, fg_color, layout);
|
|
|
|
|
2017-10-28 20:10:46 +00:00
|
|
|
if (has_shadow)
|
2017-09-30 11:11:51 +00:00
|
|
|
gtk_snapshot_pop (snapshot);
|
|
|
|
|
2017-01-13 13:36:56 +00:00
|
|
|
gtk_snapshot_offset (snapshot, -x, -y);
|
2016-11-13 22:54:30 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_render_icon:
|
|
|
|
* @snapshot: a #GtkSnapshot
|
|
|
|
* @context: the #GtkStyleContext to use
|
|
|
|
* @pixbuf: the #GdkPixbuf to render
|
|
|
|
* @x: X origin of the rectangle
|
|
|
|
* @y: Y origin of the rectangle
|
|
|
|
*
|
|
|
|
* Creates a render node for rendering @pixbuf according to the style
|
|
|
|
* information in @context, and appends it to the current node of @snapshot,
|
|
|
|
* without changing the current node.
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
2016-11-15 05:19:16 +00:00
|
|
|
void
|
|
|
|
gtk_snapshot_render_icon (GtkSnapshot *snapshot,
|
|
|
|
GtkStyleContext *context,
|
|
|
|
GdkPixbuf *pixbuf,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
|
|
|
{
|
2017-11-02 20:39:00 +00:00
|
|
|
GdkTexture *texture;
|
2016-11-15 05:19:16 +00:00
|
|
|
|
2017-11-02 20:39:00 +00:00
|
|
|
texture = gdk_texture_new_for_pixbuf (pixbuf);
|
2017-01-13 13:36:56 +00:00
|
|
|
gtk_snapshot_offset (snapshot, x, y);
|
2016-11-16 19:51:53 +00:00
|
|
|
gtk_css_style_snapshot_icon_texture (gtk_style_context_lookup_style (context),
|
|
|
|
snapshot,
|
2016-11-26 10:51:30 +00:00
|
|
|
texture,
|
2017-10-23 09:42:23 +00:00
|
|
|
1,
|
2017-11-09 03:21:42 +00:00
|
|
|
FALSE);
|
2017-01-13 13:36:56 +00:00
|
|
|
gtk_snapshot_offset (snapshot, -x, -y);
|
2017-01-01 12:40:13 +00:00
|
|
|
g_object_unref (texture);
|
2016-11-15 05:19:16 +00:00
|
|
|
}
|
|
|
|
|