Revert "[Tizen] Implement partial update"
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / update-proxy-property-modifier.h
1 #ifndef DALI_INTERNAL_UPDATE_PROXY_PROPERTY_MODIFIER_H
2 #define DALI_INTERNAL_UPDATE_PROXY_PROPERTY_MODIFIER_H
3
4 /*
5  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
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
21 // INTERNAL INCLUDES
22 #include <dali/internal/common/owner-pointer.h>
23 #include <dali/internal/update/common/property-resetter.h>
24 #include <dali/internal/update/manager/update-manager.h>
25 #include <dali/internal/update/manager/update-proxy-impl.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace SceneGraph
34 {
35 class Node;
36 class PropertyBase;
37 }
38
39 /**
40  * Keeps track of any non-transform manager properties that are modified by the UpdateProxy.
41  *
42  * This is required so the Update Manager can then reset the value to the base at the start of every frame.
43  */
44 class UpdateProxy::PropertyModifier final
45 {
46 public:
47
48   using Resetter = SceneGraph::Resetter< PropertyModifier >;
49
50   /**
51    * Observer to determine when the animator is no longer present
52    */
53   class LifecycleObserver
54   {
55   public:
56
57     /**
58      * Called shortly before the animator is destroyed.
59      */
60     virtual void ObjectDestroyed() = 0;
61
62   protected:
63
64     /**
65      * Virtual destructor, no deletion through this interface
66      */
67     virtual ~LifecycleObserver() = default;
68   };
69
70   /**
71    * Default Constructor.
72    * @param[in]  updateManager  A reference to the update-manager
73    */
74   PropertyModifier( SceneGraph::UpdateManager& updateManager )
75   : mProperties(),
76     mLifecycleObservers(),
77     mUpdateManager( &updateManager )
78   {
79   }
80
81   /**
82    * Non-virtual destructor.
83    */
84   ~PropertyModifier()
85   {
86     for( auto& observer : mLifecycleObservers )
87     {
88       observer->ObjectDestroyed();
89     }
90   }
91
92   // Movable but not copyable
93
94   PropertyModifier( const PropertyModifier& )            = delete;  ///< Deleted copy constructor.
95   PropertyModifier& operator=( const PropertyModifier& ) = delete;  ///< Deleted assignment operator.
96
97   /**
98    * Move constructor.
99    */
100   PropertyModifier( PropertyModifier&& other )
101   : mProperties( std::move( other.mProperties ) ),
102     mLifecycleObservers( std::move( other.mLifecycleObservers ) ),
103     mUpdateManager( std::move( other.mUpdateManager ) )
104   {
105     // Clear other so that it does not remove any resetters unintentionally
106     other.mLifecycleObservers.clear();
107   }
108
109   /**
110    * Move assignment operator.
111    */
112   PropertyModifier& operator=( PropertyModifier&& other )
113   {
114     if( this != &other )
115     {
116       mProperties = std::move( other.mProperties );
117       mLifecycleObservers = std::move( other.mLifecycleObservers );
118       mUpdateManager = std::move( other.mUpdateManager );
119
120       // Clear other so that it does not remove any resetters unintentionally
121       other.mLifecycleObservers.clear();
122     }
123     return *this;
124   }
125
126   /**
127    * Allows Resetter to track the life-cycle of this object.
128    * @param[in]  observer  The observer to add.
129    */
130   void AddLifecycleObserver( LifecycleObserver& observer )
131   {
132     mLifecycleObservers.push_back( &observer );
133   }
134
135   /**
136    * The Resetter no longer needs to track the life-cycle of this object.
137    * @param[in]  observer  The observer that to remove.
138    */
139   void RemoveLifecycleObserver( LifecycleObserver& observer )
140   {
141     std::remove( mLifecycleObservers.begin(), mLifecycleObservers.end(), &observer );
142   }
143
144   /**
145    * Adds a resetter to the given node and property if it hasn't already been added previously.
146    * @param[in]  node          The associated Node
147    * @param[in]  propertyBase  The associated PropertyBase
148    */
149   void AddResetter( SceneGraph::Node& node, SceneGraph::PropertyBase& propertyBase )
150   {
151     // Check if we've already added a resetter for this node and property to the update-manager
152     NodePropertyPair pair{ &node, &propertyBase };
153     if( mUpdateManager &&
154         ( mProperties.end() == std::find( mProperties.begin(), mProperties.end(), pair ) ) )
155     {
156       // We haven't, add the pair to our container to ensure we don't add it again
157       // Then create a Resetter which will observe the life of this object
158       // Finally, add the resetter to the Update-Manager
159       // When this object is destroyed, the resetter will be informed and will automatically be removed
160
161       mProperties.emplace_back( std::move( pair ) );
162       OwnerPointer< SceneGraph::PropertyResetterBase > resetter( Resetter::New( node, propertyBase, *this ) );
163       mUpdateManager->AddPropertyResetter( resetter );
164     }
165   }
166
167 public:
168
169   /**
170    * Structure to store the Node & property-base pair
171    */
172   struct NodePropertyPair
173   {
174     SceneGraph::Node* node;
175     SceneGraph::PropertyBase* propertyBase;
176
177     NodePropertyPair( const NodePropertyPair& )            = delete;  ///< Deleted copy constructor.
178     NodePropertyPair( NodePropertyPair&& )                 = default; ///< Default move constructor.
179     NodePropertyPair& operator=( const NodePropertyPair& ) = delete;  ///< Deleted assignment operator.
180     NodePropertyPair& operator=( NodePropertyPair&& )      = default; ///< Default move assignment operator.
181
182     /**
183      * Comparison operator
184      */
185     bool operator==( const NodePropertyPair& other )
186     {
187       return ( other.node == node ) &&
188              ( other.propertyBase == propertyBase );
189     }
190   };
191
192   std::vector< NodePropertyPair > mProperties;
193   std::vector< LifecycleObserver* > mLifecycleObservers;
194   SceneGraph::UpdateManager* mUpdateManager;
195 };
196
197 } // namespace Internal
198
199 } // namespace Dali
200
201 #endif // DALI_INTERNAL_UPDATE_PROXY_PROPERTY_MODIFIER_H