[gtk/wip/otte/for-master: 2/2] snapshot: Move sanity checks to a better place
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/for-master: 2/2] snapshot: Move sanity checks to a better place
- Date: Thu, 1 Apr 2021 14:53:56 +0000 (UTC)
commit ef455f5c8574ee1e0fc8ba8218ffa0b824e68658
Author: Benjamin Otte <otte redhat com>
Date: Thu Apr 1 16:37:47 2021 +0200
snapshot: Move sanity checks to a better place
Fixes cases where the sanity checks would reject valid code, like when
using GL shaders on a scaled transform.
Fixes #3819
gtk/gtksnapshot.c | 35 +++++++++++++++++------------------
1 file changed, 17 insertions(+), 18 deletions(-)
---
diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c
index 577565d21a..304abbde79 100644
--- a/gtk/gtksnapshot.c
+++ b/gtk/gtksnapshot.c
@@ -1413,7 +1413,8 @@ gtk_snapshot_append_node_internal (GtkSnapshot *snapshot,
}
static GskRenderNode *
-gtk_snapshot_pop_internal (GtkSnapshot *snapshot)
+gtk_snapshot_pop_internal (GtkSnapshot *snapshot,
+ gboolean is_texture_pop)
{
GtkSnapshotState *state;
GskRenderNode *node;
@@ -1437,6 +1438,17 @@ gtk_snapshot_pop_internal (GtkSnapshot *snapshot)
g_warning ("Too many gtk_snapshot_save() calls. %u saves remaining.", forgotten_restores);
}
+ 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;
+ }
+
return gtk_snapshot_pop_one (snapshot);
}
@@ -1460,7 +1472,7 @@ gtk_snapshot_push_collect (GtkSnapshot *snapshot)
GskRenderNode *
gtk_snapshot_pop_collect (GtkSnapshot *snapshot)
{
- GskRenderNode *result = gtk_snapshot_pop_internal (snapshot);
+ GskRenderNode *result = gtk_snapshot_pop_internal (snapshot, FALSE);
return result;
}
@@ -1483,7 +1495,7 @@ gtk_snapshot_to_node (GtkSnapshot *snapshot)
{
GskRenderNode *result;
- result = gtk_snapshot_pop_internal (snapshot);
+ result = gtk_snapshot_pop_internal (snapshot, FALSE);
/* We should have exactly our initial state */
if (!gtk_snapshot_states_is_empty (&snapshot->state_stack))
@@ -1551,13 +1563,9 @@ gtk_snapshot_to_paintable (GtkSnapshot *snapshot,
void
gtk_snapshot_pop (GtkSnapshot *snapshot)
{
- GtkSnapshotState *state = gtk_snapshot_get_current_state (snapshot);
GskRenderNode *node;
- if (state->collect_func == gtk_snapshot_collect_gl_shader_texture)
- g_warning ("Not enough calls to gtk_snapshot_gl_shader_pop_texture().");
-
- node = gtk_snapshot_pop_internal (snapshot);
+ node = gtk_snapshot_pop_internal (snapshot, FALSE);
if (node)
gtk_snapshot_append_node_internal (snapshot, node);
@@ -1577,18 +1585,9 @@ gtk_snapshot_pop (GtkSnapshot *snapshot)
void
gtk_snapshot_gl_shader_pop_texture (GtkSnapshot *snapshot)
{
- GtkSnapshotState *state = gtk_snapshot_get_current_state (snapshot);
G_GNUC_UNUSED GskRenderNode *node;
- if (state->collect_func != gtk_snapshot_collect_gl_shader_texture)
- {
- g_warning ("Too many calls to gtk_snapshot_gl_shader_pop_texture().");
- return;
- }
-
- g_assert (state->collect_func == gtk_snapshot_collect_gl_shader_texture);
-
- node = gtk_snapshot_pop_internal (snapshot);
+ node = gtk_snapshot_pop_internal (snapshot, TRUE);
g_assert (node == NULL);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]