1 #ifndef DALI_INTERNAL_SCENE_GRAPH_OBJECT_OWNER_CONTAINER
2 #define DALI_INTERNAL_SCENE_GRAPH_OBJECT_OWNER_CONTAINER
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 #include <dali/devel-api/common/owner-container.h>
25 #include <dali/internal/update/common/discard-queue.h>
26 #include <dali/internal/update/controllers/scene-controller.h>
37 * ObjectOwnerContainer is an object which owns SceneGraph Objects.
38 * It is responsible for ensuring they are placed on a discard queue
39 * when removed from the container.
41 template< class Type >
42 class ObjectOwnerContainer
45 typedef typename Dali::OwnerContainer< Type* > ObjectContainer;
46 typedef typename Dali::OwnerContainer< Type* >::Iterator Iterator;
49 * @brief Constructor - create a new object container
51 * Object container own update side objects
53 * @param[in] sceneGraphBuffers Helper to get the correct buffer index
54 * @param[in] discardQueue Queue to discard objects that might still be in use in the render thread.
56 ObjectOwnerContainer( SceneGraphBuffers& sceneGraphBuffers, DiscardQueue& discardQueue )
57 : mSceneController( NULL ),
58 mSceneGraphBuffers( sceneGraphBuffers ),
59 mDiscardQueue( discardQueue )
64 * @brief Set the SceneController on this owner
66 * @param[in] sceneController The SceneController
68 void SetSceneController( SceneController& sceneController )
70 mSceneController = &sceneController;
74 * @brief Add an object to the owner
76 * @param[in] object Pointer to the object that will be owned
78 void Add( Type* pointer )
80 DALI_ASSERT_DEBUG( pointer && "Pointer should not be null" );
82 mObjectContainer.PushBack( pointer );
84 pointer->ConnectToSceneGraph(*mSceneController, mSceneGraphBuffers.GetUpdateBufferIndex() );
88 * @brief Remove an object from the owner.
90 * The object is put on the discard queue.
92 * @param[in] object Pointer to the object to be removed
94 void Remove( Type* pointer )
96 DALI_ASSERT_DEBUG( pointer && "Pointer should not be null" );
99 Iterator match = std::find( mObjectContainer.Begin(), mObjectContainer.End(), pointer );
100 DALI_ASSERT_DEBUG( match != mObjectContainer.End() && "Should always find a match" );
102 mDiscardQueue.Add( mSceneGraphBuffers.GetUpdateBufferIndex(), mObjectContainer.Release( match ) );
103 pointer->DisconnectFromSceneGraph(*mSceneController, mSceneGraphBuffers.GetUpdateBufferIndex() );
107 * @brief Method to call ResetToBaseValues on all the objects owned.
109 * @param[in] bufferIndex Buffer index for double buffered values.
111 void ResetToBaseValues( BufferIndex bufferIndex )
113 for ( Iterator iter = mObjectContainer.Begin(); iter != mObjectContainer.End(); ++iter)
115 Type* object = (*iter);
116 object->ResetToBaseValues( bufferIndex );
121 * @brief Method to call ConstrainObjects on all the objects owned.
123 * @param[in] bufferIndex Buffer index for double buffered values.
125 void ConstrainObjects( BufferIndex bufferIndex )
127 for ( Iterator iter = mObjectContainer.Begin(); iter != mObjectContainer.End(); ++iter)
129 Type* object = (*iter);
130 ConstrainPropertyOwner( *object, bufferIndex );
134 const ObjectContainer& GetObjectContainer()
136 return mObjectContainer;
140 SceneController* mSceneController; ///< SceneController used to send messages
141 ObjectContainer mObjectContainer; ///< Container for the objects owned
142 SceneGraphBuffers& mSceneGraphBuffers; ///< Reference to a SceneGraphBuffers to get the indexBuffer
143 DiscardQueue& mDiscardQueue; ///< Discard queue used for removed objects
146 } // namespace SceneGraph
147 } // namespace Internal
151 #endif // DALI_INTERNAL_SCENE_GRAPH_OBJECT_OWNER_CONTAINER