1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_DOUBLE_BUFFERED_PROPERTY_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_DOUBLE_BUFFERED_PROPERTY_H__
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.
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/object/property.h>
27 #include <dali/public-api/object/property-input.h>
28 #include <dali/public-api/object/property-types.h>
29 #include <dali/internal/common/message.h>
30 #include <dali/internal/common/type-abstraction.h>
31 #include <dali/internal/event/common/event-thread-services.h>
32 #include <dali/internal/event/common/property-input-impl.h>
33 #include <dali/internal/update/common/double-buffered.h>
34 #include <dali/internal/update/common/scene-graph-buffers.h>
45 namespace DoubleBufferedPropertyFlags
48 * Dirty flags record whether a doubleBuffered property has changed.
49 * In the frame following a change, the property is copied from the most recent
50 * buffer to the old buffer.
52 static const unsigned int CLEAN_FLAG = 0x00; ///< Indicates that the value did not change in this, or the previous frame
53 static const unsigned int COPIED_FLAG = 0x01; ///< Indicates that the value was copied during the previous frame
54 static const unsigned int SET_FLAG = 0x02; ///< Indicates that the value was Set during the previous frame
58 * Base class to reduce code size from the templates.
60 class DoubleBufferedPropertyBase : public PropertyInputImpl
65 * Constructor, initialize the dirty flag
67 DoubleBufferedPropertyBase()
68 : PropertyInputImpl(),
69 mDirtyFlags( DoubleBufferedPropertyFlags::COPIED_FLAG )
75 virtual ~DoubleBufferedPropertyBase()
79 * Auto-age the property: if it was set the previous frame,
80 * then copy the value into the current frame's buffer.
82 virtual void CopyPrevious( BufferIndex updateBufferIndex ) = 0;
85 protected: // for derived classes
87 * Flag that the property has been Set during the current frame.
91 mDirtyFlags = DoubleBufferedPropertyFlags::SET_FLAG;
94 public: // From PropertyBase
97 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
99 virtual bool InputChanged() const
101 return ( DoubleBufferedPropertyFlags::CLEAN_FLAG != mDirtyFlags );
105 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
107 virtual bool InputInitialized() const
109 return true; // DoubleBuffered properties are always valid
112 protected: // so that ResetToBaseValue can set it directly
114 unsigned int mDirtyFlags; ///< Flag whether value changed during previous 2 frames
119 * A doubleBuffered property of a scene-graph object.
122 class DoubleBufferedPropertyImpl : public DoubleBufferedPropertyBase
126 * Create an doubleBuffered property.
127 * @param [in] initialValue The initial value of the property.
129 DoubleBufferedPropertyImpl( typename ParameterType<T>::PassingType initialValue )
130 : mValue( initialValue )
135 * Virtual destructor.
137 virtual ~DoubleBufferedPropertyImpl()
142 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
144 virtual Dali::Property::Type GetType() const
146 return Dali::PropertyTypes::Get<T>();
150 * @copydoc Dali::Internal::SceneGraph::DoubleBufferedPropertyBase::CopyPrevious()
152 virtual void CopyPrevious( BufferIndex updateBufferIndex )
154 if( DoubleBufferedPropertyFlags::SET_FLAG == mDirtyFlags)
156 mValue[ updateBufferIndex ] = mValue[ 1-updateBufferIndex ];
157 mDirtyFlags = ( mDirtyFlags >> 1 );
162 * Set the property value. This will persist for the current frame, and will
163 * be copied to the other buffer next frame (unless it is set again)
164 * @param[in] bufferIndex The buffer to write.
165 * @param[in] value The new property value.
167 void Set(BufferIndex bufferIndex, typename ParameterType<T>::PassingType value )
169 // check if the value actually changed to avoid dirtying nodes unnecessarily
170 if( mValue[bufferIndex] != value )
172 mValue[bufferIndex] = value;
179 * @copydoc Dali::SceneGraph::DoubleBufferedProperty::Get()
181 const T& Get(size_t bufferIndex) const
183 return mValue[bufferIndex];
187 * Retrieve the property value.
188 * @param[in] bufferIndex The buffer to read.
189 * @return The property value.
191 const T& operator[](size_t bufferIndex) const
193 return mValue[bufferIndex];
197 DoubleBuffered<T> mValue; ///< The double-buffered property value
199 private: // Undefined
200 DoubleBufferedPropertyImpl(const DoubleBufferedPropertyImpl& property);
201 DoubleBufferedPropertyImpl& operator=(const DoubleBufferedPropertyImpl& rhs);
206 class DoubleBufferedProperty;
209 class DoubleBufferedProperty<bool> : public DoubleBufferedPropertyImpl<bool>
215 DoubleBufferedProperty( bool value ) : DoubleBufferedPropertyImpl( value ) {};
218 * copydoc PropertyInputImpl::GetBoolean
220 virtual const bool& GetBoolean( BufferIndex bufferIndex ) const
222 return mValue[bufferIndex];
227 class DoubleBufferedProperty<int> : public DoubleBufferedPropertyImpl<int>
233 DoubleBufferedProperty( int value ) : DoubleBufferedPropertyImpl( value ) {};
236 * copydoc PropertyInputImpl::GetInteger
238 virtual const int& GetInteger( BufferIndex bufferIndex ) const
240 return mValue[bufferIndex];
245 class DoubleBufferedProperty<float> : public DoubleBufferedPropertyImpl<float>
251 DoubleBufferedProperty( float value ) : DoubleBufferedPropertyImpl( value ) {};
254 * copydoc PropertyInputImpl::GetFloat
256 virtual const float& GetFloat( BufferIndex bufferIndex ) const
258 return mValue[bufferIndex];
263 class DoubleBufferedProperty<Vector2> : public DoubleBufferedPropertyImpl<Vector2>
269 DoubleBufferedProperty( const Vector2& value ) : DoubleBufferedPropertyImpl( value ) {};
272 * copydoc PropertyInputImpl::GetVector2
274 virtual const Vector2& GetVector2( BufferIndex bufferIndex ) const
276 return mValue[bufferIndex];
281 class DoubleBufferedProperty<Vector3> : public DoubleBufferedPropertyImpl<Vector3>
287 DoubleBufferedProperty( const Vector3& value ) : DoubleBufferedPropertyImpl( value ) {};
290 * copydoc PropertyInputImpl::GetVector3
292 virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
294 return mValue[bufferIndex];
299 class DoubleBufferedProperty<Vector4> : public DoubleBufferedPropertyImpl<Vector4>
305 DoubleBufferedProperty( const Vector4& value ) : DoubleBufferedPropertyImpl( value ) {};
308 * copydoc PropertyInputImpl::GetVector4
310 virtual const Vector4& GetVector4( BufferIndex bufferIndex ) const
312 return mValue[bufferIndex];
317 class DoubleBufferedProperty<Quaternion> : public DoubleBufferedPropertyImpl<Quaternion>
323 DoubleBufferedProperty( const Quaternion& value ) : DoubleBufferedPropertyImpl( value ) {};
326 * copydoc PropertyInputImpl::GetQuaternion
328 virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
330 return mValue[bufferIndex];
335 class DoubleBufferedProperty<Matrix3> : public DoubleBufferedPropertyImpl<Matrix3>
341 DoubleBufferedProperty( const Matrix3& value ) : DoubleBufferedPropertyImpl( value ) {};
344 * copydoc PropertyInputImpl::GetMatrix3
346 virtual const Matrix3& GetMatrix3( BufferIndex bufferIndex ) const
348 return mValue[bufferIndex];
353 class DoubleBufferedProperty<Matrix> : public DoubleBufferedPropertyImpl<Matrix>
359 DoubleBufferedProperty( const Matrix& value ) : DoubleBufferedPropertyImpl( value ) {};
362 * copydoc PropertyInputImpl::GetMatrix
364 virtual const Matrix& GetMatrix( BufferIndex bufferIndex ) const
366 return mValue[bufferIndex];
370 } // namespace SceneGraph
372 } // namespace Internal
376 #endif // __DALI_INTERNAL_SCENE_GRAPH_DOUBLE_BUFFERED_PROPERTY_H__