1 #ifndef DALI_INTERNAL_SCENE_GRAPH_DOUBLE_BUFFERED_H
2 #define DALI_INTERNAL_SCENE_GRAPH_DOUBLE_BUFFERED_H
5 * Copyright (c) 2023 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/buffer-index.h>
23 #include <dali/internal/common/owner-pointer.h>
29 // The number of buffers per scene-graph property
30 static const unsigned int NUM_SCENE_GRAPH_BUFFERS = 2;
35 * Templated class for a double-buffered value.
47 DoubleBuffered(const T& val)
53 inline T& operator[](const BufferIndex i)
55 DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS);
57 return *(&mValue1 + i);
60 inline const T& operator[](const BufferIndex i) const
62 DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS);
64 return *(&mValue1 + i);
69 DoubleBuffered(const DoubleBuffered&);
72 DoubleBuffered& operator=(const DoubleBuffered& rhs);
80 * @brief Specialization for owner-pointer
82 * This class takes ownership of the pointers and releases the memory when the pointer
83 * is no longer used by either buffer
86 class DoubleBuffered<OwnerPointer<T> >
90 * Class that deals with setting a value
96 * @brief Assignment operator to that a value that will later
97 * be set in the correct buffer index of the object referenced by the setter.
99 Setter& operator=(T* value)
107 mObject.Set(mIndex, mValue);
111 Setter(DoubleBuffered& object,
120 Setter(const Setter& rhs)
121 : mObject(rhs.mObject),
127 DoubleBuffered& mObject; ///< Double-buffered object that will be changed
128 const BufferIndex mIndex; ///< Buffer index that will be changed
129 T* mValue; ///< Value of the pointer
131 friend class DoubleBuffered;
140 DoubleBuffered(T* val)
148 if(mValue2 != mValue1)
155 void Set(BufferIndex i, T* value)
157 T*& current = *(&mValue1 + i);
158 T*& previous = *(&mValue1 + 1u - i);
160 if(current != value && current != previous)
167 Setter operator[](BufferIndex i)
169 return Setter(*this, i, *(&mValue1 + i));
172 const T* operator[](BufferIndex i) const
174 DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS);
176 return *(&mValue1 + i);
180 * Auto-age the property: if it was set the previous frame,
181 * then copy the value into the current frame's buffer.
183 void CopyPrevious(BufferIndex i)
185 DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS);
187 T*& current = *(&mValue1 + i);
188 T*& previous = *(&mValue1 + 1u - i);
190 if(current != previous)
200 DoubleBuffered(const DoubleBuffered&);
203 DoubleBuffered& operator=(const DoubleBuffered& rhs);
210 } // namespace SceneGraph
212 } // namespace Internal
216 #endif // DALI_INTERNAL_SCENE_GRAPH_DOUBLE_BUFFERED_H