Text: Quality improvement
[platform/core/uifw/dali-core.git] / dali / internal / update / node-attachments / node-attachment.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_NODE_ATTACHMENT_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_NODE_ATTACHMENT_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //     http://floralicense.org/license/
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19
20 // INTERNAL INCLUDES
21 #include <dali/internal/common/message.h>
22
23 namespace Dali
24 {
25
26 namespace Internal
27 {
28
29 namespace SceneGraph
30 {
31
32 class Node;
33 class RenderableAttachment;
34 class SceneController;
35
36 /**
37  * NodeAttachment is a base class for objects attached to Nodes in the scene graph.
38  * The position of the object is provided by its parent node.
39  * NodeAttachment data is double-buffered. This allows an update thread to modify node data, without interferring
40  * with another thread reading the values from the previous update traversal.
41  */
42 class NodeAttachment
43 {
44 public:
45
46   /**
47    * Virtual destructor
48    */
49   virtual ~NodeAttachment();
50
51   /**
52    * Second-phase construction.
53    * This is called by the UpdateManager, when the attachment is attached to the scene-graph.
54    * @param[in] sceneController Allows attachments to get light/camera controllers.
55    * @param[in] updateBufferIndex The current update buffer index.
56    */
57   virtual void ConnectToSceneGraph( SceneController& sceneController, BufferIndex updateBufferIndex ) = 0;
58
59   /**
60    * Called shortly before destruction.
61    * After this method has been called, the SceneController cannot be safely accessed.
62    */
63   virtual void OnDestroy() = 0;
64
65   /**
66    * Set the parent of a NodeAttachment.
67    * @param[in] parent the new parent.
68    */
69   void SetParent( Node& parent );
70
71   /**
72    * Retrieve the parent node of a NodeAttachment.
73    * @return The parent node, or NULL if the NodeAttachment has not been added to the scene-graph.
74    */
75   Node& GetParent()
76   {
77     DALI_ASSERT_DEBUG( mParent != NULL );
78     return *mParent;
79   }
80
81   /**
82    * Retrieve the parent node of a NodeAttachment.
83    * @return The parent node, or NULL if the NodeAttachment has not been added to the scene-graph.
84    */
85   Node& GetParent() const
86   {
87     DALI_ASSERT_DEBUG( mParent != NULL );
88     return *mParent;
89   }
90
91   // RenderableAttachment interface
92
93   /**
94    * Query whether the attachment is renderable i.e. implements the SceneGraph::RenderableAttachment interface.
95    * @return True if the attachment is renderable.
96    */
97   bool IsRenderable()
98   {
99     return (GetRenderable() != NULL);
100   }
101
102   /**
103    * Convert an attachment to a renderable attachment.
104    * @return A pointer to the renderable attachment, or NULL.
105    */
106   virtual RenderableAttachment* GetRenderable() = 0;
107
108   // Update methods
109
110   /**
111    * Called when the attachment or it's owning node is flagged as dirty during scene graph updates.
112    * Allows derived classes to perform extra processing
113    * @param[in] updateBufferIndex The current update buffer index.
114    * @param[in] owningNode The attachment's owning node
115    * @param[in] nodeDirtyFlags of the owning node
116    */
117   virtual void Update( BufferIndex updateBufferIndex, const Node& owningNode, int nodeDirtyFlags ) {}
118
119 protected:
120
121   /**
122    * Derived versions of NodeAttachment should be constructed.
123    */
124   NodeAttachment();
125
126 private:
127
128   // Undefined
129   NodeAttachment( const NodeAttachment& );
130
131   // Undefined
132   NodeAttachment& operator=( const NodeAttachment& rhs );
133
134 protected:
135
136   Node* mParent; ///< Pointer to parent node which owns the attachment.
137 };
138
139 } // namespace SceneGraph
140
141 } // namespace Internal
142
143 } // namespace Dali
144
145 #endif // __DALI_INTERNAL_SCENE_GRAPH_NODE_ATTACHMENT_H__