4 * An object oriented GL/GLES Abstraction/Utility Layer
6 * Copyright (C) 2008,2009,2010 Intel Corporation.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library. If not, see
20 * <http://www.gnu.org/licenses/>.
25 * Robert Bragg <robert@linux.intel.com>
32 #include "cogl-util.h"
33 #include "cogl-node-private.h"
36 _cogl_pipeline_node_init (CoglNode *node)
39 COGL_LIST_INIT (&node->children);
43 _cogl_pipeline_node_set_parent_real (CoglNode *node,
45 CoglNodeUnparentVFunc unparent,
46 gboolean take_strong_reference)
48 /* NB: the old parent may indirectly be keeping the new parent alive
49 * so we have to ref the new parent before unrefing the old.
51 * Note: we take a reference here regardless of
52 * take_strong_reference because weak children may need special
53 * handling when the parent disposes itself which relies on a
54 * consistent link to all weak nodes. Once the node is linked to its
55 * parent then we remove the reference at the end if
56 * take_strong_reference == FALSE. */
57 cogl_object_ref (parent);
62 COGL_LIST_INSERT_HEAD (&parent->children, node, list_node);
64 node->parent = parent;
65 node->has_parent_reference = take_strong_reference;
67 /* Now that there is a consistent parent->child link we can remove
68 * the parent reference if no reference was requested. If it turns
69 * out that the new parent was only being kept alive by the old
70 * parent then it will be disposed of here. */
71 if (!take_strong_reference)
72 cogl_object_unref (parent);
76 _cogl_pipeline_node_unparent_real (CoglNode *node)
78 CoglNode *parent = node->parent;
83 _COGL_RETURN_IF_FAIL (!COGL_LIST_EMPTY (&parent->children));
85 COGL_LIST_REMOVE (node, list_node);
87 if (node->has_parent_reference)
88 cogl_object_unref (parent);
94 _cogl_pipeline_node_foreach_child (CoglNode *node,
95 CoglNodeChildCallback callback,
98 CoglNode *child, *next;
100 COGL_LIST_FOREACH_SAFE (child, &node->children, list_node, next)
101 callback (child, user_data);