Remove 20k of unnecessary binary bloat by removing dummy constant property values
[platform/core/uifw/dali-core.git] / dali / internal / update / common / inherited-property.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_INHERITED_PROPERTY_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_INHERITED_PROPERTY_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
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
21 // INTERNAL INCLUDES
22 #include <dali/internal/event/common/property-input-impl.h>
23 #include <dali/internal/update/common/double-buffered.h>
24 #include <dali/internal/update/common/property-base.h>
25 #include <dali/internal/update/common/scene-graph-buffers.h>
26 #include <dali/public-api/common/dali-common.h>
27 #include <dali/public-api/object/property.h>
28 #include <dali/public-api/object/property-input.h>
29 #include <dali/public-api/object/property-types.h>
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 namespace SceneGraph
38 {
39
40 /**
41  * An inherited Vector3 property.
42  */
43 class InheritedVector3 : public PropertyInputImpl
44 {
45 public:
46
47   /**
48    * Create an inherited Vector3.
49    */
50   InheritedVector3()
51   : mValue(),
52     mInheritedFlag( false ),
53     mReinheritedFlag( true )
54   {
55   }
56
57   /**
58    * Create an inherited Vector3.
59    * @param [in] initialValue The initial value of the property.
60    */
61   InheritedVector3( const Vector3& initialValue )
62   : mValue( initialValue ),
63     mInheritedFlag( false ),
64     mReinheritedFlag( true )
65   {
66   }
67   /**
68    * Virtual destructor.
69    */
70   virtual ~InheritedVector3()
71   {
72   }
73
74   /**
75    * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
76    */
77   virtual Dali::Property::Type GetType() const
78   {
79     return Dali::PropertyTypes::Get<Vector3>();
80   }
81
82   /**
83    * Called once per Update (only) if the property did not need to be re-inherited.
84    * @param[in] updateBufferIndex The current update buffer index.
85    */
86   void CopyPrevious( BufferIndex updateBufferIndex )
87   {
88     if ( mReinheritedFlag )
89     {
90       mValue[updateBufferIndex] = mValue[updateBufferIndex ? 0 : 1];
91
92       mReinheritedFlag = false;
93     }
94   }
95
96   /**
97    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
98    */
99   virtual bool IsClean() const
100   {
101     return ( false == mReinheritedFlag );
102   }
103
104   /**
105    * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
106    */
107   virtual bool InputInitialized() const
108   {
109     // A constraint cannot use the property until it has been inherited (at least once).
110     return mInheritedFlag;
111   }
112
113   /**
114    * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
115    * @note A constraint can only receive the inherited property from the previous frame.
116    */
117   virtual bool InputChanged() const
118   {
119     return !IsClean();
120   }
121
122   /**
123    * @copydoc Dali::PropertyInput::GetVector3()
124    */
125   virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
126   {
127     return mValue[ bufferIndex ];
128   }
129
130   /**
131    * @copydoc Dali::PropertyInput::GetConstraintInputVector3()
132    */
133   virtual const Vector3& GetConstraintInputVector3( BufferIndex bufferIndex ) const
134   {
135     // For inherited properties, constraints work with the value from the previous frame.
136     // This is because constraints are applied to position etc, before world-position is calculated.
137     BufferIndex eventBufferIndex = bufferIndex ? 0u : 1u;
138
139     return mValue[ eventBufferIndex ];
140   }
141
142   /**
143    * Set the property value. This will only persist for the current frame; the property
144    * will be reset with the base value, at the beginning of the next frame.
145    * @param[in] bufferIndex The buffer to write.
146    * @param[in] value The new property value.
147    */
148   void Set(BufferIndex bufferIndex, const Vector3& value)
149   {
150     mValue[bufferIndex] = value;
151
152     // The value has been inherited for the first time
153     mInheritedFlag = true;
154
155     mReinheritedFlag = true;
156   }
157
158   /**
159    * @copydoc Dali::SceneGraph::PropertyInterface::Get()
160    */
161   Vector3& Get(size_t bufferIndex)
162   {
163     return mValue[bufferIndex];
164   }
165
166   /**
167    * @copydoc Dali::SceneGraph::PropertyInterface::Get()
168    */
169   const Vector3& Get(size_t bufferIndex) const
170   {
171     return mValue[bufferIndex];
172   }
173
174   /**
175    * Retrieve the property value.
176    * @param[in] bufferIndex The buffer to read.
177    * @return The property value.
178    */
179   const Vector3& operator[](size_t bufferIndex) const
180   {
181     return mValue[bufferIndex];
182   }
183
184 private:
185
186   // Undefined
187   InheritedVector3(const InheritedVector3& property);
188
189   // Undefined
190   InheritedVector3& operator=(const InheritedVector3& rhs);
191
192 private:
193
194   DoubleBuffered<Vector3> mValue; ///< The double-buffered property value
195
196   bool mInheritedFlag   :1; ///< Flag whether the value has ever been inherited
197   bool mReinheritedFlag :1; ///< Flag whether value was re-inherited in previous frame
198 };
199
200 /**
201  * An inherited Color property.
202  */
203 class InheritedColor : public PropertyInputImpl
204 {
205 public:
206
207   /**
208    * Create an inherited property.
209    * @param [in] initialValue The initial value of the property.
210    */
211   InheritedColor( const Vector4& initialValue )
212   : mValue( initialValue ),
213     mInheritedFlag( false ),
214     mReinheritedFlag( true )
215   {
216   }
217
218   /**
219    * Virtual destructor.
220    */
221   virtual ~InheritedColor()
222   {
223   }
224
225   /**
226    * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
227    */
228   virtual Dali::Property::Type GetType() const
229   {
230     return Dali::PropertyTypes::Get<Vector4>();
231   }
232
233   /**
234    * Called once per Update (only) if the property did not need to be re-inherited.
235    * @param[in] updateBufferIndex The current update buffer index.
236    */
237   void CopyPrevious( BufferIndex updateBufferIndex )
238   {
239     if ( mReinheritedFlag )
240     {
241       mValue[updateBufferIndex] = mValue[updateBufferIndex ? 0 : 1];
242
243       mReinheritedFlag = false;
244     }
245   }
246
247   /**
248    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
249    */
250   virtual bool IsClean() const
251   {
252     return ( false == mReinheritedFlag );
253   }
254
255   /**
256    * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
257    */
258   virtual bool InputInitialized() const
259   {
260     // A constraint cannot use the property until it has been inherited (at least once).
261     return mInheritedFlag;
262   }
263
264   /**
265    * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
266    * @note A constraint can only receive the inherited property from the previous frame.
267    */
268   virtual bool InputChanged() const
269   {
270     return !IsClean();
271   }
272
273   /**
274    * @copydoc Dali::PropertyInput::GetVector4()
275    */
276   virtual const Vector4& GetVector4( BufferIndex bufferIndex ) const
277   {
278     return mValue[ bufferIndex ];
279   }
280
281   /**
282    * @copydoc Dali::PropertyInput::GetConstraintInputVector4()
283    */
284   virtual const Vector4& GetConstraintInputVector4( BufferIndex bufferIndex ) const
285   {
286     // For inherited properties, constraints work with the value from the previous frame.
287     // This is because constraints are applied to position etc, before world-position is calculated.
288     BufferIndex eventBufferIndex = bufferIndex ? 0u : 1u;
289
290     return mValue[ eventBufferIndex ];
291   }
292
293   /**
294    * Set the property value. This will only persist for the current frame; the property
295    * will be reset with the base value, at the beginning of the next frame.
296    * @param[in] bufferIndex The buffer to write.
297    * @param[in] value The new property value.
298    */
299   void Set(BufferIndex bufferIndex, const Vector4& value)
300   {
301     mValue[bufferIndex] = Clamp( value, 0.0f, 1.0f ); // color values are clamped between 0 and 1
302
303     // The value has been inherited for the first time
304     mInheritedFlag = true;
305     mReinheritedFlag = true;
306   }
307
308   /**
309    * Set the property value. This will only persist for the current frame; the property
310    * will be reset with the base value, at the beginning of the next frame.
311    * @param[in] bufferIndex The buffer to write.
312    * @param[in] r The new red value.
313    * @param[in] g The new green value.
314    * @param[in] b The new blue value.
315    * @param[in] a The new alpha value.
316    */
317   void Set(BufferIndex bufferIndex, float r, float g, float b, float a )
318   {
319     mValue[bufferIndex].r = Clamp( r, 0.0f, 1.0f ); // color values are clamped between 0 and 1
320     mValue[bufferIndex].g = Clamp( g, 0.0f, 1.0f ); // color values are clamped between 0 and 1
321     mValue[bufferIndex].b = Clamp( b, 0.0f, 1.0f ); // color values are clamped between 0 and 1
322     mValue[bufferIndex].a = Clamp( a, 0.0f, 1.0f ); // color values are clamped between 0 and 1
323
324     // The value has been inherited for the first time
325     mInheritedFlag = true;
326     mReinheritedFlag = true;
327   }
328
329   /**
330    * @copydoc Dali::SceneGraph::PropertyInterface::Get()
331    */
332   Vector4& Get(size_t bufferIndex)
333   {
334     return mValue[bufferIndex];
335   }
336
337   /**
338    * @copydoc Dali::SceneGraph::PropertyInterface::Get()
339    */
340   const Vector4& Get(size_t bufferIndex) const
341   {
342     return mValue[bufferIndex];
343   }
344
345   /**
346    * Retrieve the property value.
347    * @param[in] bufferIndex The buffer to read.
348    * @return The property value.
349    */
350   const Vector4& operator[](size_t bufferIndex) const
351   {
352     return mValue[bufferIndex];
353   }
354
355 private:
356
357   // Undefined
358   InheritedColor(const InheritedColor& property);
359   // Undefined
360   InheritedColor& operator=(const InheritedColor& rhs);
361
362 private:
363
364   DoubleBuffered<Vector4> mValue; ///< The double-buffered property value
365
366   bool mInheritedFlag   :1; ///< Flag whether the value has ever been inherited
367   bool mReinheritedFlag :1; ///< Flag whether value was re-inherited in previous frame
368 };
369
370 /**
371  * An inherited Quaternion property.
372  */
373 class InheritedQuaternion : public PropertyInputImpl
374 {
375 public:
376
377   /**
378    * Create an inherited property.
379    */
380   InheritedQuaternion()
381   : mValue(),
382     mInheritedFlag( false ),
383     mReinheritedFlag( true )
384   {
385   }
386
387   /**
388    * Virtual destructor.
389    */
390   virtual ~InheritedQuaternion()
391   {
392   }
393
394   /**
395    * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
396    */
397   virtual Dali::Property::Type GetType() const
398   {
399     return Dali::PropertyTypes::Get<Quaternion>();
400   }
401
402   /**
403    * Called once per Update (only) if the property did not need to be re-inherited.
404    * @param[in] updateBufferIndex The current update buffer index.
405    */
406   void CopyPrevious( BufferIndex updateBufferIndex )
407   {
408     if ( mReinheritedFlag )
409     {
410       mValue[updateBufferIndex] = mValue[updateBufferIndex ? 0 : 1];
411
412       mReinheritedFlag = false;
413     }
414   }
415
416   /**
417    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
418    */
419   virtual bool IsClean() const
420   {
421     return ( false == mReinheritedFlag );
422   }
423
424   /**
425    * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
426    */
427   virtual bool InputInitialized() const
428   {
429     // A constraint cannot use the property until it has been inherited (at least once).
430     return mInheritedFlag;
431   }
432
433   /**
434    * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
435    * @note A constraint can only receive the inherited property from the previous frame.
436    */
437   virtual bool InputChanged() const
438   {
439     return !IsClean();
440   }
441
442   /**
443    * @copydoc Dali::PropertyInput::GetQuaternion()
444    */
445   virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
446   {
447     return mValue[ bufferIndex ];
448   }
449
450   /**
451    * @copydoc Dali::PropertyInput::GetConstraintInputQuaternion()
452    */
453   virtual const Quaternion& GetConstraintInputQuaternion( BufferIndex bufferIndex ) const
454   {
455     // For inherited properties, constraints work with the value from the previous frame.
456     // This is because constraints are applied to position etc, before world-position is calculated.
457     BufferIndex eventBufferIndex = bufferIndex ? 0u : 1u;
458
459     return mValue[ eventBufferIndex ];
460   }
461
462   /**
463    * Set the property value. This will only persist for the current frame; the property
464    * will be reset with the base value, at the beginning of the next frame.
465    * @param[in] bufferIndex The buffer to write.
466    * @param[in] value The new property value.
467    */
468   void Set(BufferIndex bufferIndex, const Quaternion& value)
469   {
470     mValue[bufferIndex] = value;
471
472     // The value has been inherited for the first time
473     mInheritedFlag = true;
474
475     mReinheritedFlag = true;
476   }
477
478   /**
479    * @copydoc Dali::SceneGraph::PropertyInterface::Get()
480    */
481   Quaternion& Get(size_t bufferIndex)
482   {
483     return mValue[bufferIndex];
484   }
485
486   /**
487    * @copydoc Dali::SceneGraph::PropertyInterface::Get()
488    */
489   const Quaternion& Get(size_t bufferIndex) const
490   {
491     return mValue[bufferIndex];
492   }
493
494   /**
495    * Retrieve the property value.
496    * @param[in] bufferIndex The buffer to read.
497    * @return The property value.
498    */
499   const Quaternion& operator[](size_t bufferIndex) const
500   {
501     return mValue[bufferIndex];
502   }
503
504 private:
505
506   // Undefined
507   InheritedQuaternion(const InheritedQuaternion& property);
508
509   // Undefined
510   InheritedQuaternion& operator=(const InheritedQuaternion& rhs);
511
512 private:
513
514   DoubleBuffered<Quaternion> mValue; ///< The double-buffered property value
515
516   bool mInheritedFlag   :1;   ///< Flag whether the value has ever been inherited
517   bool mReinheritedFlag :1;   ///< Flag whether value was re-inherited in previous frame
518 };
519
520 /**
521  * An inherited Matrix property.
522  */
523 class InheritedMatrix : public PropertyInputImpl
524 {
525 public:
526
527   /**
528    * Create an inherited property.
529    */
530   InheritedMatrix()
531   : mValue(),
532     mInheritedFlag( false ),
533     mReinheritedFlag( true )
534   {
535   }
536
537   /**
538    * Virtual destructor.
539    */
540   virtual ~InheritedMatrix()
541   {
542   }
543
544   /**
545    * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
546    */
547   virtual Dali::Property::Type GetType() const
548   {
549     return Dali::PropertyTypes::Get<Matrix>();
550   }
551
552   /**
553    * Called once per Update (only) if the property did not need to be re-inherited.
554    * @param[in] updateBufferIndex The current update buffer index.
555    */
556   void CopyPrevious( BufferIndex updateBufferIndex )
557   {
558     if ( mReinheritedFlag )
559     {
560       mValue[updateBufferIndex] = mValue[updateBufferIndex ? 0 : 1];
561
562       mReinheritedFlag = false;
563     }
564   }
565
566   /**
567    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
568    */
569   virtual bool IsClean() const
570   {
571     return ( false == mReinheritedFlag );
572   }
573
574   /**
575    * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
576    */
577   virtual bool InputInitialized() const
578   {
579     // A constraint cannot use the property until it has been inherited (at least once).
580     return mInheritedFlag;
581   }
582
583   /**
584    * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
585    * @note A constraint can only receive the inherited property from the previous frame.
586    */
587   virtual bool InputChanged() const
588   {
589     return !IsClean();
590   }
591
592   /**
593    * @copydoc Dali::Internal::PropertyInputImpl::GetMatrix()
594    */
595   virtual const Matrix& GetMatrix( BufferIndex bufferIndex ) const
596   {
597     return mValue[ bufferIndex ];
598   }
599
600   /**
601    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix()
602    */
603   virtual const Matrix& GetConstraintInputMatrix( BufferIndex bufferIndex ) const
604   {
605     // For inherited properties, constraints work with the value from the previous frame.
606     // This is because constraints are applied to position etc, before world-position is calculated.
607     BufferIndex eventBufferIndex = bufferIndex ? 0u : 1u;
608
609     return mValue[ eventBufferIndex ];
610   }
611
612   /**
613    * Set the property value. This will only persist for the current frame; the property
614    * will be reset with the base value, at the beginning of the next frame.
615    * @param[in] bufferIndex The buffer to write.
616    * @param[in] value The new property value.
617    */
618   void Set(BufferIndex bufferIndex, const Matrix& value)
619   {
620     mValue[bufferIndex] = value;
621
622     // The value has been inherited for the first time
623     mInheritedFlag = true;
624
625     mReinheritedFlag = true;
626   }
627
628   /**
629    * @copydoc Dali::SceneGraph::PropertyInterface::Get()
630    */
631   Matrix& Get(size_t bufferIndex)
632   {
633     return mValue[bufferIndex];
634   }
635
636   /**
637    * @copydoc Dali::SceneGraph::PropertyInterface::Get()
638    */
639   const Matrix& Get(size_t bufferIndex) const
640   {
641     return mValue[bufferIndex];
642   }
643
644   /**
645    * Retrieve the property value.
646    * @param[in] bufferIndex The buffer to read.
647    * @return The property value.
648    */
649   const Matrix& operator[](size_t bufferIndex) const
650   {
651     return mValue[bufferIndex];
652   }
653
654   void SetDirty(size_t bufferIndex)
655   {
656     mReinheritedFlag = true;
657
658     // The value has been inherited for the first time
659     mInheritedFlag = true;
660   }
661
662 private:
663
664   // Undefined
665   InheritedMatrix(const InheritedMatrix& property);
666
667   // Undefined
668   InheritedMatrix& operator=(const InheritedMatrix& rhs);
669
670 private:
671
672   DoubleBuffered<Matrix> mValue; ///< The double-buffered property value
673
674   bool mInheritedFlag   :1;   ///< Flag whether the value has ever been inherited
675   bool mReinheritedFlag :1;   ///< Flag whether value was re-inherited in previous frame
676
677 };
678
679 } // namespace SceneGraph
680
681 } // namespace Internal
682
683 } // namespace Dali
684
685 #endif // __DALI_INTERNAL_SCENE_GRAPH_INHERITED_PROPERTY_H__