(Properties) Added ability to add non-animatable event-thread only properties via...
[platform/core/uifw/dali-core.git] / dali / internal / event / actor-attachments / renderable-attachment-impl.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // CLASS HEADER
18 #include <dali/internal/event/actor-attachments/renderable-attachment-impl.h>
19
20 // INTERNAL INCLUDES
21 #include <dali/internal/event/common/stage-impl.h>
22 #include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
23 #include <dali/internal/render/renderers/scene-graph-renderer.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 RenderableAttachment::RenderableAttachment( Stage& stage )
32 : ActorAttachment( stage ),
33   mSortModifier( 0.0f ),
34   mCullFaceMode( CullNone ),
35   mBlendingMode( BlendingMode::AUTO )
36 {
37 }
38
39 RenderableAttachment::~RenderableAttachment()
40 {
41 }
42
43 void RenderableAttachment::SetSortModifier(float modifier)
44 {
45   // Cache for actor-side getters
46   mSortModifier = modifier;
47
48   // attachment is being used in a separate thread; queue a message to set the value & base value
49   SetSortModifierMessage( mStage->GetUpdateInterface(), GetSceneObject(), modifier );
50 }
51
52 float RenderableAttachment::GetSortModifier() const
53 {
54   // mSortModifier is not animatable; this is the most up-to-date value.
55   return mSortModifier;
56 }
57
58 void RenderableAttachment::SetCullFace( CullFaceMode mode )
59 {
60   // Cache for actor-side getters
61   mCullFaceMode = mode;
62
63   // attachment is being used in a separate thread; queue a message to set the value
64   SetCullFaceMessage( mStage->GetUpdateInterface(), GetSceneObject(), mode );
65 }
66
67 CullFaceMode RenderableAttachment::GetCullFace() const
68 {
69   // mCullFaceMode is not animatable; this is the most up-to-date value.
70   return mCullFaceMode;
71 }
72
73 void RenderableAttachment::SetBlendMode( BlendingMode::Type mode )
74 {
75   mBlendingMode = mode;
76
77   // attachment is being used in a separate thread; queue a message to set the value
78   SetBlendingModeMessage( mStage->GetUpdateInterface(), GetSceneObject(), mode );
79 }
80
81 BlendingMode::Type RenderableAttachment::GetBlendMode() const
82 {
83   return mBlendingMode;
84 }
85
86 void RenderableAttachment::SetBlendFunc( BlendingFactor::Type srcFactorRgb,   BlendingFactor::Type destFactorRgb,
87                                          BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha )
88 {
89   // Cache for actor-side getters
90   mBlendingOptions.SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
91
92   // attachment is being used in a separate thread; queue a message to set the value
93   SetBlendingOptionsMessage( mStage->GetUpdateInterface(), GetSceneObject(), mBlendingOptions.GetBitmask() );
94 }
95
96 void RenderableAttachment::GetBlendFunc( BlendingFactor::Type& srcFactorRgb,   BlendingFactor::Type& destFactorRgb,
97                                          BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const
98 {
99   // These are not animatable, the cached values are up-to-date.
100   srcFactorRgb    = mBlendingOptions.GetBlendSrcFactorRgb();
101   destFactorRgb   = mBlendingOptions.GetBlendDestFactorRgb();
102   srcFactorAlpha  = mBlendingOptions.GetBlendSrcFactorAlpha();
103   destFactorAlpha = mBlendingOptions.GetBlendDestFactorAlpha();
104 }
105
106 void RenderableAttachment::SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha )
107 {
108   mBlendingOptions.SetBlendEquation( equationRgb, equationAlpha );
109
110   // attachment is being used in a separate thread; queue a message to set the value
111   SetBlendingOptionsMessage( mStage->GetUpdateInterface(), GetSceneObject(), mBlendingOptions.GetBitmask() );
112 }
113
114 void RenderableAttachment::GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const
115 {
116   // These are not animatable, the cached values are up-to-date.
117   equationRgb   = mBlendingOptions.GetBlendEquationRgb();
118   equationAlpha = mBlendingOptions.GetBlendEquationAlpha();
119 }
120
121 void RenderableAttachment::SetBlendColor( const Vector4& color )
122 {
123   if( mBlendingOptions.SetBlendColor( color ) )
124   {
125     // attachment is being used in a separate thread; queue a message to set the value
126     SetBlendColorMessage( mStage->GetUpdateInterface(), GetSceneObject(), color );
127   }
128 }
129
130 const Vector4& RenderableAttachment::GetBlendColor() const
131 {
132   const Vector4* optionalColor = mBlendingOptions.GetBlendColor();
133   if( optionalColor )
134   {
135     return *optionalColor;
136   }
137
138   return Vector4::ZERO;
139 }
140
141 void RenderableAttachment::OnStageConnection()
142 {
143   // For derived classes
144   OnStageConnection2();
145 }
146
147 void RenderableAttachment::OnStageDisconnection()
148 {
149   // For derived classes
150   OnStageDisconnection2();
151 }
152
153 } // namespace Internal
154
155 } // namespace Dali