1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147
|
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Copyright (C) 2011 Intel Corporation.
*
* 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/>.
*
* Author:
* Emmanuele Bassi <ebassi@linux.intel.com>
*/
/**
* SECTION:clutter-paint-node
* @Title: ClutterPaintNode
* @Short_Description: Paint objects
*
* #ClutterPaintNode is an element in the render graph.
*
* The render graph contains all the elements that need to be painted by
* Clutter when submitting a frame to the graphics system.
*
* The render graph is distinct from the scene graph: the scene graph is
* composed by actors, which can be visible or invisible; the scene graph
* elements also respond to events. The render graph, instead, is only
* composed by nodes that will be painted.
*
* Each #ClutterActor can submit multiple #ClutterPaintNode<!-- -->s to
* the render graph.
*/
/**
* ClutterPaintNode: (ref-func clutter_paint_node_ref) (unref-func clutter_paint_node_unref) (set-value-func clutter_value_set_paint_node) (get-value-func clutter_value_get_paint_node)
*
* The `ClutterPaintNode` structure contains only private data
* and it should be accessed using the provided API.
*
* Since: 1.10
*/
/**
* ClutterPaintNodeClass:
*
* The `ClutterPaintNodeClass` structure contains only private data.
*
* Since: 1.10
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define CLUTTER_ENABLE_EXPERIMENTAL_API
#include <pango/pango.h>
#include <cogl/cogl.h>
#include <json-glib/json-glib.h>
#include "clutter-paint-node-private.h"
#include "clutter-debug.h"
#include "clutter-private.h"
#include <gobject/gvaluecollector.h>
static inline void clutter_paint_operation_clear (ClutterPaintOperation *op);
static void
value_paint_node_init (GValue *value)
{
value->data[0].v_pointer = NULL;
}
static void
value_paint_node_free_value (GValue *value)
{
if (value->data[0].v_pointer != NULL)
clutter_paint_node_unref (value->data[0].v_pointer);
}
static void
value_paint_node_copy_value (const GValue *src,
GValue *dst)
{
if (src->data[0].v_pointer != NULL)
dst->data[0].v_pointer = clutter_paint_node_ref (src->data[0].v_pointer);
else
dst->data[0].v_pointer = NULL;
}
static gpointer
value_paint_node_peek_pointer (const GValue *value)
{
return value->data[0].v_pointer;
}
static gchar *
value_paint_node_collect_value (GValue *value,
guint n_collect_values,
GTypeCValue *collect_values,
guint collect_flags)
{
ClutterPaintNode *node;
node = collect_values[0].v_pointer;
if (node == NULL)
{
value->data[0].v_pointer = NULL;
return NULL;
}
if (node->parent_instance.g_class == NULL)
return g_strconcat ("invalid unclassed ClutterPaintNode pointer for "
"value type '",
G_VALUE_TYPE_NAME (value),
"'",
NULL);
value->data[0].v_pointer = clutter_paint_node_ref (node);
return NULL;
}
static gchar *
value_paint_node_lcopy_value (const GValue *value,
guint n_collect_values,
GTypeCValue *collect_values,
guint collect_flags)
{
ClutterPaintNode **node_p = collect_values[0].v_pointer;
if (node_p == NULL)
return g_strconcat ("value location for '",
G_VALUE_TYPE_NAME (value),
"' passed as NULL",
NULL);
if (value->data[0].v_pointer == NULL)
*node_p = NULL;
else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
*node_p = value->data[0].v_pointer;
else
*node_p = clutter_paint_node_ref (value->data[0].v_pointer);
return NULL;
}
static void
clutter_paint_node_class_base_init (ClutterPaintNodeClass *klass)
{
}
static void
clutter_paint_node_class_base_finalize (ClutterPaintNodeClass *klass)
{
}
static void
clutter_paint_node_real_finalize (ClutterPaintNode *node)
{
ClutterPaintNode *iter;
g_free (node->name);
if (node->operations != NULL)
{
guint i;
for (i = 0; i < node->operations->len; i++)
{
ClutterPaintOperation *op;
op = &g_array_index (node->operations, ClutterPaintOperation, i);
clutter_paint_operation_clear (op);
}
g_array_unref (node->operations);
}
iter = node->first_child;
while (iter != NULL)
{
ClutterPaintNode *next = iter->next_sibling;
clutter_paint_node_remove_child (node, iter);
iter = next;
}
g_type_free_instance ((GTypeInstance *) node);
}
static gboolean
clutter_paint_node_real_pre_draw (ClutterPaintNode *node)
{
return FALSE;
}
static void
clutter_paint_node_real_draw (ClutterPaintNode *node)
{
}
static void
clutter_paint_node_real_post_draw (ClutterPaintNode *node)
{
}
static void
clutter_paint_node_class_init (ClutterPaintNodeClass *klass)
{
klass->pre_draw = clutter_paint_node_real_pre_draw;
klass->draw = clutter_paint_node_real_draw;
klass->post_draw = clutter_paint_node_real_post_draw;
klass->finalize = clutter_paint_node_real_finalize;
}
static void
clutter_paint_node_init (ClutterPaintNode *self)
{
self->ref_count = 1;
}
GType
clutter_paint_node_get_type (void)
{
static volatile gsize paint_node_type_id__volatile = 0;
if (g_once_init_enter (&paint_node_type_id__volatile))
{
static const GTypeFundamentalInfo finfo = {
(G_TYPE_FLAG_CLASSED |
G_TYPE_FLAG_INSTANTIATABLE |
G_TYPE_FLAG_DERIVABLE |
G_TYPE_FLAG_DEEP_DERIVABLE),
};
static const GTypeValueTable value_table = {
value_paint_node_init,
value_paint_node_free_value,
value_paint_node_copy_value,
value_paint_node_peek_pointer,
"p",
value_paint_node_collect_value,
"p",
value_paint_node_lcopy_value,
};
const GTypeInfo node_info = {
sizeof (ClutterPaintNodeClass),
(GBaseInitFunc) clutter_paint_node_class_base_init,
(GBaseFinalizeFunc) clutter_paint_node_class_base_finalize,
(GClassInitFunc) clutter_paint_node_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (ClutterPaintNode),
0,
(GInstanceInitFunc) clutter_paint_node_init,
&value_table,
};
GType paint_node_type_id =
g_type_register_fundamental (g_type_fundamental_next (),
I_("ClutterPaintNode"),
&node_info, &finfo,
G_TYPE_FLAG_ABSTRACT);
g_once_init_leave (&paint_node_type_id__volatile, paint_node_type_id);
}
return paint_node_type_id__volatile;
}
/**
* clutter_paint_node_set_name:
* @node: a #ClutterPaintNode
* @name: a string annotating the @node
*
* Sets a user-readable @name for @node.
*
* The @name will be used for debugging purposes.
*
* The @node will copy the passed string.
*
* Since: 1.10
*/
void
clutter_paint_node_set_name (ClutterPaintNode *node,
const char *name)
{
g_return_if_fail (CLUTTER_IS_PAINT_NODE (node));
g_free (node->name);
node->name = g_strdup (name);
}
/**
* clutter_paint_node_ref:
* @node: a #ClutterPaintNode
*
* Acquires a reference on @node.
*
* Return value: (transfer full): the #ClutterPaintNode
*
* Since: 1.10
*/
ClutterPaintNode *
clutter_paint_node_ref (ClutterPaintNode *node)
{
g_return_val_if_fail (CLUTTER_IS_PAINT_NODE (node), NULL);
g_atomic_int_inc (&node->ref_count);
return node;
}
/**
* clutter_paint_node_unref:
* @node: a #ClutterPaintNode
*
* Releases a reference on @node.
*
* Since: 1.10
*/
void
clutter_paint_node_unref (ClutterPaintNode *node)
{
g_return_if_fail (CLUTTER_IS_PAINT_NODE (node));
if (g_atomic_int_dec_and_test (&node->ref_count))
{
ClutterPaintNodeClass *klass = CLUTTER_PAINT_NODE_GET_CLASS (node);
klass->finalize (node);
}
}
/**
* clutter_paint_node_add_child:
* @node: a #ClutterPaintNode
* @child: the child #ClutterPaintNode to add
*
* Adds @child to the list of children of @node.
*
* This function will acquire a reference on @child.
*
* Since: 1.10
*/
void
clutter_paint_node_add_child (ClutterPaintNode *node,
ClutterPaintNode *child)
{
g_return_if_fail (CLUTTER_IS_PAINT_NODE (node));
g_return_if_fail (CLUTTER_IS_PAINT_NODE (child));
g_return_if_fail (node != child);
g_return_if_fail (child->parent == NULL);
child->parent = node;
clutter_paint_node_ref (child);
node->n_children += 1;
child->prev_sibling = node->last_child;
if (node->last_child != NULL)
{
ClutterPaintNode *tmp = node->last_child;
tmp->next_sibling = child;
}
if (child->prev_sibling == NULL)
node->first_child = child;
if (child->next_sibling == NULL)
node->last_child = child;
}
/**
* clutter_paint_node_remove_child:
* @node: a #ClutterPaintNode
* @child: the #ClutterPaintNode to remove
*
* Removes @child from the list of children of @node.
*
* This function will release the reference on @child acquired by
* using clutter_paint_node_add_child().
*
* Since: 1.10
*/
void
clutter_paint_node_remove_child (ClutterPaintNode *node,
ClutterPaintNode *child)
{
ClutterPaintNode *prev, *next;
g_return_if_fail (CLUTTER_IS_PAINT_NODE (node));
g_return_if_fail (CLUTTER_IS_PAINT_NODE (child));
g_return_if_fail (node != child);
g_return_if_fail (child->parent == node);
node->n_children -= 1;
prev = child->prev_sibling;
next = child->next_sibling;
if (prev != NULL)
prev->next_sibling = next;
if (next != NULL)
next->prev_sibling = prev;
if (node->first_child == child)
node->first_child = next;
if (node->last_child == child)
node->last_child = prev;
child->prev_sibling = NULL;
child->next_sibling = NULL;
child->parent = NULL;
clutter_paint_node_unref (child);
}
/**
* clutter_paint_node_replace_child:
* @node: a #ClutterPaintNode
* @old_child: the child replaced by @new_child
* @new_child: the child that replaces @old_child
*
* Atomically replaces @old_child with @new_child in the list of
* children of @node.
*
* This function will release the reference on @old_child acquired
* by @node, and will acquire a new reference on @new_child.
*
* Since: 1.10
*/
void
clutter_paint_node_replace_child (ClutterPaintNode *node,
ClutterPaintNode *old_child,
ClutterPaintNode *new_child)
{
ClutterPaintNode *prev, *next;
g_return_if_fail (CLUTTER_IS_PAINT_NODE (node));
g_return_if_fail (CLUTTER_IS_PAINT_NODE (old_child));
g_return_if_fail (old_child->parent == node);
g_return_if_fail (CLUTTER_IS_PAINT_NODE (new_child));
g_return_if_fail (new_child->parent == NULL);
prev = old_child->prev_sibling;
next = old_child->next_sibling;
new_child->parent = node;
new_child->prev_sibling = prev;
new_child->next_sibling = next;
clutter_paint_node_ref (new_child);
if (prev != NULL)
prev->next_sibling = new_child;
if (next != NULL)
next->prev_sibling = new_child;
if (node->first_child == old_child)
node->first_child = new_child;
if (node->last_child == old_child)
node->last_child = new_child;
old_child->prev_sibling = NULL;
old_child->next_sibling = NULL;
old_child->parent = NULL;
clutter_paint_node_unref (old_child);
}
/**
* clutter_paint_node_remove_all:
* @node: a #ClutterPaintNode
*
* Removes all children of @node.
*
* This function releases the reference acquired by @node on its
* children.
*
* Since: 1.10
*/
void
clutter_paint_node_remove_all (ClutterPaintNode *node)
{
ClutterPaintNode *iter;
g_return_if_fail (CLUTTER_IS_PAINT_NODE (node));
iter = node->first_child;
while (iter != NULL)
{
ClutterPaintNode *next = iter->next_sibling;
clutter_paint_node_remove_child (node, iter);
iter = next;
}
}
/**
* clutter_paint_node_get_first_child:
* @node: a #ClutterPaintNode
*
* Retrieves the first child of the @node.
*
* Return value: (transfer none): a pointer to the first child of
* the #ClutterPaintNode.
*
* Since: 1.10
*/
ClutterPaintNode *
clutter_paint_node_get_first_child (ClutterPaintNode *node)
{
g_return_val_if_fail (CLUTTER_IS_PAINT_NODE (node), NULL);
return node->first_child;
}
/**
* clutter_paint_node_get_previous_sibling:
* @node: a #ClutterPaintNode
*
* Retrieves the previous sibling of @node.
*
* Return value: (transfer none): a pointer to the previous sibling
* of the #ClutterPaintNode.
*
* Since: 1.10
*/
ClutterPaintNode *
clutter_paint_node_get_previous_sibling (ClutterPaintNode *node)
{
g_return_val_if_fail (CLUTTER_IS_PAINT_NODE (node), NULL);
return node->prev_sibling;
}
/**
* clutter_paint_node_get_next_sibling:
* @node: a #ClutterPaintNode
*
* Retrieves the next sibling of @node.
*
* Return value: (transfer none): a pointer to the next sibling
* of a #ClutterPaintNode
*
* Since: 1.10
*/
ClutterPaintNode *
clutter_paint_node_get_next_sibling (ClutterPaintNode *node)
{
g_return_val_if_fail (CLUTTER_IS_PAINT_NODE (node), NULL);
return node->next_sibling;
}
/**
* clutter_paint_node_get_last_child:
* @node: a #ClutterPaintNode
*
* Retrieves the last child of @node.
*
* Return value: (transfer none): a pointer to the last child
* of a #ClutterPaintNode
*
* Since: 1.10
*/
ClutterPaintNode *
clutter_paint_node_get_last_child (ClutterPaintNode *node)
{
g_return_val_if_fail (CLUTTER_IS_PAINT_NODE (node), NULL);
return node->last_child;
}
/**
* clutter_paint_node_get_parent:
* @node: a #ClutterPaintNode
*
* Retrieves the parent of @node.
*
* Return value: (transfer none): a pointer to the parent of
* a #ClutterPaintNode
*
* Since: 1.10
*/
ClutterPaintNode *
clutter_paint_node_get_parent (ClutterPaintNode *node)
{
g_return_val_if_fail (CLUTTER_IS_PAINT_NODE (node), NULL);
return node->parent;
}
/**
* clutter_paint_node_get_n_children:
* @node: a #ClutterPaintNode
*
* Retrieves the number of children of @node.
*
* Return value: the number of children of a #ClutterPaintNode
*
* Since: 1.10
*/
guint
clutter_paint_node_get_n_children (ClutterPaintNode *node)
{
g_return_val_if_fail (CLUTTER_IS_PAINT_NODE (node), 0);
return node->n_children;
}
/**
* clutter_value_set_paint_node:
* @value: a #GValue initialized with %CLUTTER_TYPE_PAINT_NODE
* @node: (type Clutter.PaintNode) (allow-none): a #ClutterPaintNode, or %NULL
*
* Sets the contents of a #GValue initialized with %CLUTTER_TYPE_PAINT_NODE.
*
* This function increased the reference count of @node; if you do not wish
* to increase the reference count, use clutter_value_take_paint_node()
* instead. The reference count will be released by g_value_unset().
*
* Since: 1.10
*/
void
clutter_value_set_paint_node (GValue *value,
gpointer node)
{
ClutterPaintNode *old_node;
g_return_if_fail (CLUTTER_VALUE_HOLDS_PAINT_NODE (value));
old_node = value->data[0].v_pointer;
if (node != NULL)
{
g_return_if_fail (CLUTTER_IS_PAINT_NODE (node));
value->data[0].v_pointer = clutter_paint_node_ref (node);
}
else
value->data[0].v_pointer = NULL;
if (old_node != NULL)
clutter_paint_node_unref (old_node);
}
/**
* clutter_value_take_paint_node:
* @value: a #GValue, initialized with %CLUTTER_TYPE_PAINT_NODE
* @node: (type Clutter.PaintNode) (allow-none): a #ClutterPaintNode, or %NULL
*
* Sets the contents of a #GValue initialized with %CLUTTER_TYPE_PAINT_NODE.
*
* Unlike clutter_value_set_paint_node(), this function will not take a
* reference on the passed @node: instead, it will take ownership of the
* current reference count.
*
* Since: 1.10
*/
void
clutter_value_take_paint_node (GValue *value,
gpointer node)
{
ClutterPaintNode *old_node;
g_return_if_fail (CLUTTER_VALUE_HOLDS_PAINT_NODE (value));
old_node = value->data[0].v_pointer;
if (node != NULL)
{
g_return_if_fail (CLUTTER_IS_PAINT_NODE (node));
/* take over ownership */
value->data[0].v_pointer = node;
}
else
value->data[0].v_pointer = NULL;
if (old_node != NULL)
clutter_paint_node_unref (old_node);
}
/**
* clutter_value_get_paint_node:
* @value: a #GValue initialized with %CLUTTER_TYPE_PAINT_NODE
*
* Retrieves a pointer to the #ClutterPaintNode contained inside
* the passed #GValue.
*
* Return value: (transfer none) (type Clutter.PaintNode): a pointer to
* a #ClutterPaintNode, or %NULL
*
* Since: 1.10
*/
gpointer
clutter_value_get_paint_node (const GValue *value)
{
g_return_val_if_fail (CLUTTER_VALUE_HOLDS_PAINT_NODE (value), NULL);
return value->data[0].v_pointer;
}
/**
* clutter_value_dup_paint_node:
* @value: a #GValue initialized with %CLUTTER_TYPE_PAINT_NODE
*
* Retrieves a pointer to the #ClutterPaintNode contained inside
* the passed #GValue, and if not %NULL it will increase the
* reference count.
*
* Return value: (transfer full) (type Clutter.PaintNode): a pointer
* to the #ClutterPaintNode, with its reference count increased,
* or %NULL
*
* Since: 1.10
*/
gpointer
clutter_value_dup_paint_node (const GValue *value)
{
g_return_val_if_fail (CLUTTER_VALUE_HOLDS_PAINT_NODE (value), NULL);
if (value->data[0].v_pointer != NULL)
return clutter_paint_node_ref (value->data[0].v_pointer);
return NULL;
}
static inline void
clutter_paint_operation_clear (ClutterPaintOperation *op)
{
switch (op->opcode)
{
case PAINT_OP_INVALID:
break;
case PAINT_OP_TEX_RECT:
break;
case PAINT_OP_PATH:
if (op->op.path != NULL)
cogl_object_unref (op->op.path);
break;
case PAINT_OP_PRIMITIVE:
if (op->op.primitive != NULL)
cogl_object_unref (op->op.primitive);
break;
}
}
static inline void
clutter_paint_op_init_tex_rect (ClutterPaintOperation *op,
const ClutterActorBox *rect,
float x_1,
float y_1,
float x_2,
float y_2)
{
clutter_paint_operation_clear (op);
op->opcode = PAINT_OP_TEX_RECT;
op->op.texrect[0] = rect->x1;
op->op.texrect[1] = rect->y1;
op->op.texrect[2] = rect->x2;
op->op.texrect[3] = rect->y2;
op->op.texrect[4] = x_1;
op->op.texrect[5] = y_1;
op->op.texrect[6] = x_2;
op->op.texrect[7] = y_2;
}
static inline void
clutter_paint_op_init_path (ClutterPaintOperation *op,
CoglPath *path)
{
clutter_paint_operation_clear (op);
op->opcode = PAINT_OP_PATH;
op->op.path = cogl_object_ref (path);
}
static inline void
clutter_paint_op_init_primitive (ClutterPaintOperation *op,
CoglPrimitive *primitive)
{
clutter_paint_operation_clear (op);
op->opcode = PAINT_OP_PRIMITIVE;
op->op.primitive = cogl_object_ref (primitive);
}
static inline void
clutter_paint_node_maybe_init_operations (ClutterPaintNode *node)
{
if (node->operations != NULL)
return;
node->operations =
g_array_new (FALSE, FALSE, sizeof (ClutterPaintOperation));
}
/**
* clutter_paint_node_add_rectangle:
* @node: a #ClutterPaintNode
* @rect: a #ClutterActorBox
*
* Adds a rectangle region to the @node, as described by the
* passed @rect.
*
* Since: 1.10
*/
void
clutter_paint_node_add_rectangle (ClutterPaintNode *node,
const ClutterActorBox *rect)
{
ClutterPaintOperation operation = PAINT_OP_INIT;
g_return_if_fail (CLUTTER_IS_PAINT_NODE (node));
g_return_if_fail (rect != NULL);
clutter_paint_node_maybe_init_operations (node);
clutter_paint_op_init_tex_rect (&operation, rect, 0.0, 0.0, 1.0, 1.0);
g_array_append_val (node->operations, operation);
}
/**
* clutter_paint_node_add_texture_rectangle:
* @node: a #ClutterPaintNode
* @rect: a #ClutterActorBox
* @x_1: the left X coordinate of the texture
* @y_1: the top Y coordinate of the texture
* @x_2: the right X coordinate of the texture
* @y_2: the bottom Y coordinate of the texture
*
* Adds a rectangle region to the @node, with texture coordinates.
*
* Since: 1.10
*/
void
clutter_paint_node_add_texture_rectangle (ClutterPaintNode *node,
const ClutterActorBox *rect,
float x_1,
float y_1,
float x_2,
float y_2)
{
ClutterPaintOperation operation = PAINT_OP_INIT;
g_return_if_fail (CLUTTER_IS_PAINT_NODE (node));
g_return_if_fail (rect != NULL);
clutter_paint_node_maybe_init_operations (node);
clutter_paint_op_init_tex_rect (&operation, rect, x_1, y_1, x_2, y_2);
g_array_append_val (node->operations, operation);
}
/**
* clutter_paint_node_add_path:
* @node: a #ClutterPaintNode
* @path: a Cogl path
*
* Adds a region described as a path to the @node.
*
* This function acquires a reference on the passed @path, so it
* is safe to call cogl_object_unref() when it returns.
*
* Since: 1.10
* Stability: unstable
*/
void
clutter_paint_node_add_path (ClutterPaintNode *node,
CoglPath *path)
{
ClutterPaintOperation operation = PAINT_OP_INIT;
g_return_if_fail (CLUTTER_IS_PAINT_NODE (node));
g_return_if_fail (cogl_is_path (path));
clutter_paint_node_maybe_init_operations (node);
clutter_paint_op_init_path (&operation, path);
g_array_append_val (node->operations, operation);
}
/**
* clutter_paint_node_add_primitive:
* @node: a #ClutterPaintNode
* @primitive: a Cogl primitive
*
* Adds a region described by a Cogl primitive to the @node.
*
* This function acquires a reference on @primitive, so it is safe
* to call cogl_object_unref() when it returns.
*
* Since: 1.10
*/
void
clutter_paint_node_add_primitive (ClutterPaintNode *node,
CoglPrimitive *primitive)
{
ClutterPaintOperation operation = PAINT_OP_INIT;
g_return_if_fail (CLUTTER_IS_PAINT_NODE (node));
g_return_if_fail (cogl_is_primitive (primitive));
clutter_paint_node_maybe_init_operations (node);
clutter_paint_op_init_primitive (&operation, primitive);
g_array_append_val (node->operations, operation);
}
/*< private >
* _clutter_paint_node_paint:
* @node: a #ClutterPaintNode
*
* Paints the @node using the class implementation, traversing
* its children, if any.
*/
void
_clutter_paint_node_paint (ClutterPaintNode *node)
{
ClutterPaintNodeClass *klass = CLUTTER_PAINT_NODE_GET_CLASS (node);
ClutterPaintNode *iter;
gboolean res;
res = klass->pre_draw (node);
if (res)
{
klass->draw (node);
}
for (iter = node->first_child;
iter != NULL;
iter = iter->next_sibling)
{
_clutter_paint_node_paint (iter);
}
if (res)
{
klass->post_draw (node);
}
}
#ifdef CLUTTER_ENABLE_DEBUG
static JsonNode *
clutter_paint_node_serialize (ClutterPaintNode *node)
{
ClutterPaintNodeClass *klass = CLUTTER_PAINT_NODE_GET_CLASS (node);
if (klass->serialize != NULL)
return klass->serialize (node);
return json_node_new (JSON_NODE_NULL);
}
static JsonNode *
clutter_paint_node_to_json (ClutterPaintNode *node)
{
JsonBuilder *builder;
JsonNode *res;
builder = json_builder_new ();
json_builder_begin_object (builder);
json_builder_set_member_name (builder, "type");
json_builder_add_string_value (builder, g_type_name (G_TYPE_FROM_INSTANCE (node)));
json_builder_set_member_name (builder, "name");
json_builder_add_string_value (builder, node->name);
json_builder_set_member_name (builder, "node-data");
json_builder_add_value (builder, clutter_paint_node_serialize (node));
json_builder_set_member_name (builder, "operations");
json_builder_begin_array (builder);
if (node->operations != NULL)
{
guint i;
for (i = 0; i < node->operations->len; i++)
{
const ClutterPaintOperation *op;
op = &g_array_index (node->operations, ClutterPaintOperation, i);
json_builder_begin_object (builder);
switch (op->opcode)
{
case PAINT_OP_TEX_RECT:
json_builder_set_member_name (builder, "texrect");
json_builder_begin_array (builder);
json_builder_add_double_value (builder, op->op.texrect[0]);
json_builder_add_double_value (builder, op->op.texrect[1]);
json_builder_add_double_value (builder, op->op.texrect[2]);
json_builder_add_double_value (builder, op->op.texrect[3]);
json_builder_add_double_value (builder, op->op.texrect[4]);
json_builder_add_double_value (builder, op->op.texrect[5]);
json_builder_add_double_value (builder, op->op.texrect[6]);
json_builder_add_double_value (builder, op->op.texrect[7]);
json_builder_end_array (builder);
break;
case PAINT_OP_PATH:
json_builder_set_member_name (builder, "path");
json_builder_add_int_value (builder, (gint64) op->op.path);
break;
case PAINT_OP_PRIMITIVE:
json_builder_set_member_name (builder, "primitive");
json_builder_add_int_value (builder, (gint64) op->op.primitive);
break;
case PAINT_OP_INVALID:
break;
}
json_builder_end_object (builder);
}
}
json_builder_end_array (builder);
json_builder_set_member_name (builder, "children");
json_builder_begin_array (builder);
if (node->first_child != NULL)
{
ClutterPaintNode *child;
for (child = node->first_child;
child != NULL;
child = child->next_sibling)
{
JsonNode *n = clutter_paint_node_to_json (child);
json_builder_add_value (builder, n);
}
}
json_builder_end_array (builder);
json_builder_end_object (builder);
res = json_builder_get_root (builder);
g_object_unref (builder);
return res;
}
#endif /* CLUTTER_ENABLE_DEBUG */
void
_clutter_paint_node_dump_tree (ClutterPaintNode *node)
{
#ifdef CLUTTER_ENABLE_DEBUG
JsonGenerator *gen = json_generator_new ();
char *str;
gsize len;
json_generator_set_root (gen, clutter_paint_node_to_json (node));
str = json_generator_to_data (gen, &len);
g_print ("Render tree starting from %p:\n%s\n", node, str);
g_free (str);
#endif /* CLUTTER_ENABLE_DEBUG */
}
/*< private >
* _clutter_paint_node_create:
* @gtype: a #ClutterPaintNode type
*
* Creates a new #ClutterPaintNode instance using @gtype
*
* Return value: (transfer full): the newly created #ClutterPaintNode
* sub-class instance; use clutter_paint_node_unref() when done
*/
gpointer
_clutter_paint_node_create (GType gtype)
{
g_return_val_if_fail (g_type_is_a (gtype, CLUTTER_TYPE_PAINT_NODE), NULL);
_clutter_paint_node_init_types ();
return (gpointer) g_type_create_instance (gtype);
}
static ClutterPaintNode *
clutter_paint_node_get_root (ClutterPaintNode *node)
{
ClutterPaintNode *iter;
iter = node;
while (iter != NULL && iter->parent != NULL)
iter = iter->parent;
return iter;
}
CoglFramebuffer *
clutter_paint_node_get_framebuffer (ClutterPaintNode *node)
{
ClutterPaintNode *root = clutter_paint_node_get_root (node);
ClutterPaintNodeClass *klass;
if (root == NULL)
return NULL;
klass = CLUTTER_PAINT_NODE_GET_CLASS (root);
if (klass->get_framebuffer != NULL)
return klass->get_framebuffer (root);
return cogl_get_draw_framebuffer ();
}
|