~elementary-os/elementaryos/os-patch-mutter-bionic

« back to all changes in this revision

Viewing changes to cogl/cogl/cogl-node.c

  • Committer: RabbitBot
  • Date: 2018-04-11 14:49:36 UTC
  • Revision ID: rabbitbot@elementary.io-20180411144936-hgymqa9d8d1xfpbh
Initial import, version 3.28.0-2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Cogl
 
3
 *
 
4
 * A Low Level GPU Graphics and Utilities API
 
5
 *
 
6
 * Copyright (C) 2008,2009,2010 Intel Corporation.
 
7
 *
 
8
 * Permission is hereby granted, free of charge, to any person
 
9
 * obtaining a copy of this software and associated documentation
 
10
 * files (the "Software"), to deal in the Software without
 
11
 * restriction, including without limitation the rights to use, copy,
 
12
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 
13
 * of the Software, and to permit persons to whom the Software is
 
14
 * furnished to do so, subject to the following conditions:
 
15
 *
 
16
 * The above copyright notice and this permission notice shall be
 
17
 * included in all copies or substantial portions of the Software.
 
18
 *
 
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
20
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
21
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
22
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 
23
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 
24
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
25
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
26
 * SOFTWARE.
 
27
 *
 
28
 *
 
29
 *
 
30
 * Authors:
 
31
 *   Robert Bragg <robert@linux.intel.com>
 
32
 */
 
33
 
 
34
#ifdef HAVE_CONFIG_H
 
35
#include "cogl-config.h"
 
36
#endif
 
37
 
 
38
#include "cogl-util.h"
 
39
#include "cogl-node-private.h"
 
40
 
 
41
void
 
42
_cogl_pipeline_node_init (CoglNode *node)
 
43
{
 
44
  node->parent = NULL;
 
45
  _cogl_list_init (&node->children);
 
46
}
 
47
 
 
48
void
 
49
_cogl_pipeline_node_set_parent_real (CoglNode *node,
 
50
                                     CoglNode *parent,
 
51
                                     CoglNodeUnparentVFunc unparent,
 
52
                                     CoglBool take_strong_reference)
 
53
{
 
54
  /* NB: the old parent may indirectly be keeping the new parent alive
 
55
   * so we have to ref the new parent before unrefing the old.
 
56
   *
 
57
   * Note: we take a reference here regardless of
 
58
   * take_strong_reference because weak children may need special
 
59
   * handling when the parent disposes itself which relies on a
 
60
   * consistent link to all weak nodes. Once the node is linked to its
 
61
   * parent then we remove the reference at the end if
 
62
   * take_strong_reference == FALSE. */
 
63
  cogl_object_ref (parent);
 
64
 
 
65
  if (node->parent)
 
66
    unparent (node);
 
67
 
 
68
  _cogl_list_insert (&parent->children, &node->link);
 
69
 
 
70
  node->parent = parent;
 
71
  node->has_parent_reference = take_strong_reference;
 
72
 
 
73
  /* Now that there is a consistent parent->child link we can remove
 
74
   * the parent reference if no reference was requested. If it turns
 
75
   * out that the new parent was only being kept alive by the old
 
76
   * parent then it will be disposed of here. */
 
77
  if (!take_strong_reference)
 
78
    cogl_object_unref (parent);
 
79
}
 
80
 
 
81
void
 
82
_cogl_pipeline_node_unparent_real (CoglNode *node)
 
83
{
 
84
  CoglNode *parent = node->parent;
 
85
 
 
86
  if (parent == NULL)
 
87
    return;
 
88
 
 
89
  _COGL_RETURN_IF_FAIL (!_cogl_list_empty (&parent->children));
 
90
 
 
91
  _cogl_list_remove (&node->link);
 
92
 
 
93
  if (node->has_parent_reference)
 
94
    cogl_object_unref (parent);
 
95
 
 
96
  node->parent = NULL;
 
97
}
 
98
 
 
99
void
 
100
_cogl_pipeline_node_foreach_child (CoglNode *node,
 
101
                                   CoglNodeChildCallback callback,
 
102
                                   void *user_data)
 
103
{
 
104
  CoglNode *child, *next;
 
105
 
 
106
  _cogl_list_for_each_safe (child, next, &node->children, link)
 
107
    callback (child, user_data);
 
108
}
 
109
 
 
110