1 /*
2 * Copyright © 2021 Red Hat, Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors: Matthias Clasen
18 */
19
20 #include <gtk/gtk.h>
21 #include "gsk/gskrendernodeprivate.h"
22
23 static void
test_can_diff_basic(void)24 test_can_diff_basic (void)
25 {
26 GskRenderNode *container1, *container2;
27 GskRenderNode *color1, *color2;
28
29 color1 = gsk_color_node_new (&(GdkRGBA){0, 1, 0, 1 }, &GRAPHENE_RECT_INIT (0, 0, 10, 10));
30 color2 = gsk_color_node_new (&(GdkRGBA){1, 1, 0, 1 }, &GRAPHENE_RECT_INIT (0, 0, 10, 10));
31
32 container1 = gsk_container_node_new (&color1, 1);
33 container2 = gsk_container_node_new (&color2, 1);
34
35 /* We can diff two color nodes */
36 g_assert_true (gsk_render_node_can_diff (color1, color2));
37 /* We can diff two container nodes */
38 g_assert_true (gsk_render_node_can_diff (container1, container2));
39 /* We can diff container nodes against anything else */
40 g_assert_true (gsk_render_node_can_diff (container1, color2));
41 g_assert_true (gsk_render_node_can_diff (color1, container2));
42
43 gsk_render_node_unref (color1);
44 gsk_render_node_unref (color2);
45
46 gsk_render_node_unref (container1);
47 gsk_render_node_unref (container2);
48 }
49
50 static void
test_can_diff_transform(void)51 test_can_diff_transform (void)
52 {
53 GskRenderNode *color1, *color2;
54 GskRenderNode *opacity;
55 GskRenderNode *transform1, *transform2, *transform3, *transform4;
56 GskTransform *t1, *t2;
57
58 color1 = gsk_color_node_new (&(GdkRGBA){0, 1, 0, 1 }, &GRAPHENE_RECT_INIT (0, 0, 10, 10));
59 color2 = gsk_color_node_new (&(GdkRGBA){1, 1, 0, 1 }, &GRAPHENE_RECT_INIT (0, 0, 10, 10));
60 opacity = gsk_opacity_node_new (color2, 0.5);
61
62 t1 = gsk_transform_translate (NULL, &GRAPHENE_POINT_INIT (10, 10));
63 t2 = gsk_transform_scale (NULL, 2, 1);
64
65 transform1 = gsk_transform_node_new (color1, t1);
66 transform2 = gsk_transform_node_new (color2, t1);
67 transform3 = gsk_transform_node_new (color2, t2);
68 transform4 = gsk_transform_node_new (opacity, t1);
69
70 /* The case we can handle */
71 g_assert_true (gsk_render_node_can_diff (transform1, transform2));
72
73 /* These, we can't */
74 g_assert_false (gsk_render_node_can_diff (transform1, transform3));
75 g_assert_false (gsk_render_node_can_diff (transform1, transform4));
76
77 gsk_render_node_unref (color1);
78 gsk_render_node_unref (color2);
79 gsk_render_node_unref (opacity);
80 gsk_render_node_unref (transform1);
81 gsk_render_node_unref (transform2);
82 gsk_render_node_unref (transform3);
83 gsk_render_node_unref (transform4);
84
85 gsk_transform_unref (t1);
86 gsk_transform_unref (t2);
87 }
88
89 int
main(int argc,char * argv[])90 main (int argc,
91 char *argv[])
92 {
93 gtk_test_init (&argc, &argv, NULL);
94
95 g_test_add_func ("/node/can-diff/basic", test_can_diff_basic);
96 g_test_add_func ("/node/can-diff/transform", test_can_diff_transform);
97
98 return g_test_run ();
99 }
100