1 #ifndef DALI_INTERNAL_SCENE_GRAPH_DOUBLE_BUFFERED_H
2 #define DALI_INTERNAL_SCENE_GRAPH_DOUBLE_BUFFERED_H
5 * Copyright (c) 2021 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>
28 // The number of buffers per scene-graph property
29 static const unsigned int NUM_SCENE_GRAPH_BUFFERS = 2;
34 * Templated class for a double-buffered value.
46 DoubleBuffered(const T& val)
52 inline T& operator[](const BufferIndex i)
54 DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS);
56 return *(&mValue1 + i);
59 inline const T& operator[](const BufferIndex i) const
61 DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS);
63 return *(&mValue1 + i);
68 DoubleBuffered<T>(const DoubleBuffered<T>&);
71 DoubleBuffered<T>& operator=(const DoubleBuffered<T>& rhs);
79 * @brief Specialization for owner-pointer
81 * This class takes ownership of the pointers and releases the memory when the pointer
82 * is no longer used by either buffer
85 class DoubleBuffered<OwnerPointer<T> >
89 * Class that deals with setting a value
95 * @brief Assignment operator to that a value that will later
96 * be set in the correct buffer index of the object referenced by the setter.
98 Setter& operator=(T* value)
106 mObject.Set(mIndex, mValue);
110 Setter(DoubleBuffered& object,
119 Setter(const Setter& rhs)
120 : mObject(rhs.mObject),
126 DoubleBuffered& mObject; ///< Double-buffered object that will be changed
127 const BufferIndex mIndex; ///< Buffer index that will be changed
128 T* mValue; ///< Value of the pointer
130 friend class DoubleBuffered;
139 DoubleBuffered(T* val)
147 if(mValue2 != mValue1)
154 void Set(BufferIndex i, T* value)
156 T*& current = *(&mValue1 + i);
157 T*& previous = *(&mValue1 + 1u - i);
159 if(current != value && current != previous)
166 Setter operator[](BufferIndex i)
168 return Setter(*this, i, *(&mValue1 + i));
171 const T* operator[](BufferIndex i) const
173 DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS);
175 return *(&mValue1 + i);
179 * Auto-age the property: if it was set the previous frame,
180 * then copy the value into the current frame's buffer.
182 void CopyPrevious(BufferIndex i)
184 DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS);
186 T*& current = *(&mValue1 + i);
187 T*& previous = *(&mValue1 + 1u - i);
189 if(current != previous)
199 DoubleBuffered(const DoubleBuffered&);
202 DoubleBuffered& operator=(const DoubleBuffered& rhs);
209 } // namespace SceneGraph
211 } // namespace Internal
215 #endif // DALI_INTERNAL_SCENE_GRAPH_DOUBLE_BUFFERED_H