1 #ifndef DALI_INTERNAL_SCENE_GRAPH_DOUBLE_BUFFERED_H
2 #define DALI_INTERNAL_SCENE_GRAPH_DOUBLE_BUFFERED_H
5 * Copyright (c) 2020 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.
22 #include <dali/internal/common/owner-pointer.h>
30 // The number of buffers per scene-graph property
31 static const unsigned int NUM_SCENE_GRAPH_BUFFERS = 2;
37 * Templated class for a double-buffered value.
50 DoubleBuffered(const T& val)
56 inline T& operator[](const BufferIndex i)
58 DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS);
63 inline const T& operator[](const BufferIndex i) const
65 DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS);
73 DoubleBuffered<T>(const DoubleBuffered<T>&);
76 DoubleBuffered<T>& operator=(const DoubleBuffered<T>& rhs);
85 * @brief Specialization for owner-pointer
87 * This class takes ownership of the pointers and releases the memory when the pointer
88 * is no longer used by either buffer
91 class DoubleBuffered< OwnerPointer< T > >
96 * Class that deals with setting a value
102 * @brief Assignment operator to that a value that will later
103 * be set in the correct buffer index of the object referenced by the setter.
105 Setter& operator=( T* value )
113 mObject.Set( mIndex, mValue );
117 Setter( DoubleBuffered& object,
126 Setter( const Setter& rhs )
127 : mObject( rhs.mObject ),
128 mIndex( rhs.mIndex ),
133 DoubleBuffered& mObject; ///< Double-buffered object that will be changed
134 const BufferIndex mIndex; ///< Buffer index that will be changed
135 T* mValue; ///< Value of the pointer
137 friend class DoubleBuffered;
146 DoubleBuffered(T* val)
154 if( mValue2 != mValue1 )
161 void Set( BufferIndex i, T* value )
163 T*& current = *(&mValue1 + i);
164 T*& previous = *(&mValue1 + 1u-i);
166 if( current != value && current != previous )
173 Setter operator[]( BufferIndex i )
175 return Setter( *this, i, *(&mValue1+i) );
178 const T* operator[]( BufferIndex i ) const
180 DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS);
182 return *(&mValue1+i);
186 * Auto-age the property: if it was set the previous frame,
187 * then copy the value into the current frame's buffer.
189 void CopyPrevious( BufferIndex i )
191 DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS);
193 T*& current = *(&mValue1 + i);
194 T*& previous = *(&mValue1 + 1u-i);
196 if( current != previous )
207 DoubleBuffered(const DoubleBuffered&);
210 DoubleBuffered& operator=(const DoubleBuffered& rhs);
220 } // namespace SceneGraph
222 } // namespace Internal
226 #endif // DALI_INTERNAL_SCENE_GRAPH_DOUBLE_BUFFERED_H