Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-core.git] / dali / internal / update / common / double-buffered.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_DOUBLE_BUFFERED_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_DOUBLE_BUFFERED_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali/public-api/math/matrix.h>
22 #include <dali/public-api/math/quaternion.h>
23 #include <dali/public-api/math/vector3.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 // The number of buffers per scene-graph property
32 static const unsigned int NUM_SCENE_GRAPH_BUFFERS = 2;
33
34 // Buffer index used when reading off-stage values
35 static const unsigned int ARBITRARY_OFF_STAGE_BUFFER = 0;
36
37 namespace SceneGraph
38 {
39
40 /**
41  * Templated class for a double-buffered value.
42  * This simplifies init code, and forces explicit initialization.
43  */
44 template <typename T>
45 class DoubleBuffered
46 {
47 public:
48
49   DoubleBuffered(const T& val)
50   : mValue1(val),
51     mValue2(val)
52   {
53   }
54
55   inline T& operator[](const size_t i)
56   {
57     DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS);
58
59     return *(&mValue1+i);
60   }
61
62   inline const T& operator[](const size_t i) const
63   {
64     DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS);
65
66     return *(&mValue1+i);
67   }
68
69 private:
70
71   // Undefined
72   DoubleBuffered<T>(const DoubleBuffered<T>&);
73
74   // Undefined
75   DoubleBuffered<T>& operator=(const DoubleBuffered<T>& rhs);
76
77 private:
78
79   T mValue1;
80   T mValue2;
81 };
82
83 /**
84  * Templated class for a double-buffered value, initialized with 3 value parameters.
85  * This simplifies init code, and forces explicit initialization.
86  */
87 template <typename T, typename P>
88 class DoubleBuffered3
89 {
90 public:
91
92   DoubleBuffered3(const T& val)
93   : mValue1(val),
94     mValue2(val)
95   {
96   }
97
98   DoubleBuffered3(P val1, P val2, P val3)
99   : mValue1(val1, val2, val3),
100     mValue2(val1, val2, val3)
101   {
102   }
103
104   inline T& operator[](const size_t i)
105   {
106     DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS);
107
108     return *(&mValue1+i);
109   }
110
111   inline const T& operator[](const size_t i) const
112   {
113     DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS);
114
115     return *(&mValue1+i);
116   }
117
118 private:
119
120   // Undefined
121   DoubleBuffered3<T,P>(const DoubleBuffered3<T,P>&);
122
123   // Undefined
124   DoubleBuffered3<T,P>& operator=(const DoubleBuffered3<T,P>& rhs);
125
126 private:
127
128   T mValue1;
129   T mValue2;
130 };
131
132 /**
133  * Templated class for a double-buffered value, initialized with 4 value parameters.
134  * This simplifies init code, and forces explicit initialization.
135  */
136 template <typename T, typename P>
137 class DoubleBuffered4
138 {
139 public:
140
141   DoubleBuffered4(const T& val)
142   : mValue1(val),
143     mValue2(val)
144   {
145   }
146
147   DoubleBuffered4(P val1, P val2, P val3, P val4)
148   : mValue1(val1, val2, val3, val4),
149     mValue2(val1, val2, val3, val4)
150   {
151   }
152
153   inline T& operator[](const size_t i)
154   {
155     DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS);
156
157     return *(&mValue1+i);
158   }
159
160   inline const T& operator[](const size_t i) const
161   {
162     DALI_ASSERT_DEBUG(i < NUM_SCENE_GRAPH_BUFFERS);
163
164     return *(&mValue1+i);
165   }
166
167 private:
168
169   // Undefined
170   DoubleBuffered4<T,P>(const DoubleBuffered4<T,P>&);
171
172   // Undefined
173   DoubleBuffered4<T,P>& operator=(const DoubleBuffered4<T,P>& rhs);
174
175 private:
176
177   T mValue1;
178   T mValue2;
179 };
180
181 typedef DoubleBuffered<int>   DoubleBufferedInt;
182 typedef DoubleBuffered<float> DoubleBufferedFloat;
183 typedef DoubleBuffered<bool>  DoubleBufferedBool;
184
185 typedef DoubleBuffered3<Vector3,float>      DoubleBufferedVector3;
186 typedef DoubleBuffered4<Vector4,float>      DoubleBufferedVector4;
187
188 typedef DoubleBuffered4<Quaternion, float>  DoubleBufferedQuaternion;
189
190 typedef DoubleBuffered<Matrix> DoubleBufferedMatrix;
191
192 } // namespace SceneGraph
193
194 } // namespace Internal
195
196 } // namespace Dali
197
198 #endif // __DALI_INTERNAL_SCENE_GRAPH_DOUBLE_BUFFERED_H__