Dali 3D User Interface Engine
blending-options.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 // CLASS HEADER
20 
21 namespace // unnamed namespace
22 {
23 
24 using namespace Dali;
25 
26 const int MASK_SRC_FACTOR_RGB = 0x0000000F;
27 const int MASK_SRC_FACTOR_ALPHA = 0x000000F0;
28 const int MASK_DEST_FACTOR_RGB = 0x00000F00;
29 const int MASK_DEST_FACTOR_ALPHA = 0x0000F000;
30 const int MASK_EQUATION_RGB = 0x000F0000;
31 const int MASK_EQUATION_ALPHA = 0x00F00000;
32 
37 const int SHIFT_TO_EQUATION_RGB = 16;
38 const int SHIFT_TO_EQUATION_ALPHA = 20;
39 
40 static unsigned int CLEAR_BLEND_FUNC_MASK = 0xFFFF0000; // Bottom 16 bits cleared
41 static unsigned int CLEAR_BLEND_EQUATION_MASK = 0xFF00FFFF; // 8 bits cleared
42 
49 void StoreBlendingFactor( unsigned int& options, BlendingFactor::Type factor, int bitShift )
50 {
51  switch ( factor )
52  {
54  options |= ( 0u << bitShift );
55  break;
56 
58  options |= ( 1u << bitShift );
59  break;
60 
62  options |= ( 2u << bitShift );
63  break;
64 
66  options |= ( 3u << bitShift );
67  break;
68 
70  options |= ( 4u << bitShift );
71  break;
72 
74  options |= ( 5u << bitShift );
75  break;
76 
78  options |= ( 6u << bitShift );
79  break;
80 
82  options |= ( 7u << bitShift );
83  break;
84 
86  options |= ( 8u << bitShift );
87  break;
88 
90  options |= ( 9u << bitShift );
91  break;
92 
94  options |= ( 10u << bitShift );
95  break;
96 
98  options |= ( 11u << bitShift );
99  break;
100 
102  options |= ( 12u << bitShift );
103  break;
104 
106  options |= ( 13u << bitShift );
107  break;
108 
110  options |= ( 14u << bitShift );
111  break;
112  }
113 }
114 
121 void StoreBlendingEquation( unsigned int& options, BlendingEquation::Type factor, int bitShift )
122 {
123  switch ( factor )
124  {
126  options |= ( 0u << bitShift );
127  break;
128 
130  options |= ( 1u << bitShift );
131  break;
132 
134  options |= ( 2u << bitShift );
135  break;
136  }
137 }
138 
139 const unsigned int BLENDING_FACTOR_COUNT = 15;
140 const unsigned int BLENDING_EQUATION_COUNT = 3;
141 
158 
163 
171 BlendingFactor::Type RetrieveBlendingFactor( unsigned int options, int mask, int bitShift )
172 {
173  unsigned int index = options & mask;
174  index = index >> bitShift;
175 
177 
178  return BLENDING_FACTORS[ index ];
179 }
180 
188 BlendingEquation::Type RetrieveBlendingEquation( unsigned int options, int mask, int bitShift )
189 {
190  unsigned int index = options & mask;
191  index = index >> bitShift;
192 
194 
195  return BLENDING_EQUATIONS[ index ];
196 }
197 
198 } // unnamed namespace
199 
200 namespace Dali
201 {
202 
203 namespace Internal
204 {
205 
207 : mBitmask( 0u ),
208  mBlendColor( NULL )
209 {
212 
214 }
215 
217 {
218  delete mBlendColor;
219 }
220 
221 void BlendingOptions::SetBitmask( unsigned int bitmask )
222 {
223  mBitmask = bitmask;
224 }
225 
226 unsigned int BlendingOptions::GetBitmask() const
227 {
228  return mBitmask;
229 }
230 
232  BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha )
233 {
234  mBitmask &= CLEAR_BLEND_FUNC_MASK; // Clear the BlendFunc values
235 
240 }
241 
243 {
245 }
246 
248 {
250 }
251 
253 {
255 }
256 
258 {
260 }
261 
263 {
264  mBitmask &= CLEAR_BLEND_EQUATION_MASK; // Clear the BlendEquation values
265 
268 }
269 
271 {
273 }
274 
276 {
278 }
279 
281 {
282  if( Vector4::ZERO == color )
283  {
284  if( mBlendColor )
285  {
286  // Discard unnecessary vector
287  delete mBlendColor;
288  mBlendColor = NULL;
289  }
290  return;
291  }
292 
293  if( mBlendColor )
294  {
295  *mBlendColor = color;
296  }
297  else
298  {
299  // Lazy allocation when non-default is set
300  mBlendColor = new Vector4( color );
301  }
302 }
303 
305 {
306  return mBlendColor;
307 }
308 
309 } // namespace Internal
310 
311 } // namespace Dali
Dali Docs Home
Read more about Dali