Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-toolkit.git] / optional / dali-toolkit / internal / controls / shadow-view / shadow-view-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_SHADOW_VIEW_H__
2 #define __DALI_TOOLKIT_INTERNAL_SHADOW_VIEW_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 // EXTERNAL INCLUDES
21 #include <sstream>
22 #include <cmath>
23
24 // INTERNAL INCLUDES
25 #include <dali/dali.h>
26 #include <dali-toolkit/public-api/controls/shadow-view/shadow-view.h>
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/internal/filters/blur-two-pass-filter.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 class ShadowView;
37
38 namespace Internal
39 {
40
41 /**
42  * ShadowView implementation class
43  */
44 class ShadowView : public ControlImpl
45 {
46 public:
47
48   /**
49    * @copydoc Dali::Toolkit::ShadowView::ShadowView
50    */
51   ShadowView();
52
53   /**
54    * @copydoc Dali::Toolkit::ShadowView::ShadowView
55    */
56   ShadowView(float downsampleWidthScale, float downsampleHeightScale);
57
58   /**
59    * @copydoc Dali::Toolkit::ShadowView::~ShadowView
60    */
61   virtual ~ShadowView();
62
63   /**
64    * @copydoc Dali::Toolkit::ShadowView::New(float downsampleWidthScale, float downsampleHeightScale)
65    */
66   static Dali::Toolkit::ShadowView New(float downsampleWidthScale, float downsampleHeightScale);
67
68   /**
69    * @copydoc Dali::Toolkit::ShadowView::Add(Actor child)
70    */
71   void Add(Actor child);
72
73   /**
74    * @copydoc Dali::Toolkit::ShadowView::Remove(Actor child)
75    */
76   void Remove(Actor child);
77
78   /**
79    * @copydoc Dali::Toolkit::ShadowView::SetShadowPlane(Actor shadowPlane)
80    */
81   void SetShadowPlane(Actor shadowPlane);
82
83   /**
84    * @copydoc Dali::Toolkit::ShadowView::SetPointLight(Actor pointLight)
85    */
86   void SetPointLight(Actor pointLight);
87
88   /**
89    * @copydoc Dali::Toolkit::ShadowView::SetPointLightFieldOfView(float fieldOfView)
90    */
91   void SetPointLightFieldOfView(float fieldOfView);
92
93   /**
94    * @copydoc Dali::Toolkit::ShadowView::SetShadowColor(Vector4 color)
95    */
96   void SetShadowColor(Vector4 color);
97
98   /**
99    * @copydoc Dali::Toolkit::ShadowView::Activate()
100    */
101   void Activate();
102
103   /**
104    * @copydoc Dali::Toolkit::ShadowView::Deactivate()
105    */
106   void Deactivate();
107
108   /**
109    * @copydoc Dali::Toolkit::ShadowView::GetBlurStrengthPropertyIndex()
110    */
111   Property::Index GetBlurStrengthPropertyIndex() const {return mBlurStrengthPropertyIndex;}
112
113   /**
114    * @copydoc Dali::Toolkit::ShadowView::GetShadowColorPropertyIndex()
115    */
116   Property::Index GetShadowColorPropertyIndex() const {return mShadowColorPropertyIndex;}
117
118   void SetShaderConstants();
119
120 private:
121
122   virtual void OnInitialize();
123   virtual void OnSizeSet(const Vector3& targetSize);
124   virtual void OnStageConnection();
125   virtual void OnStageDisconnection();
126
127   /**
128    * Constrain the camera actor to the position of the point light, pointing
129    * at the center of the shadow plane.
130    */
131   void ConstrainCamera();
132
133   void CreateRenderTasks();
134   void RemoveRenderTasks();
135   void CreateBlurFilter();
136
137 private:
138   ImageActor mShadowPlane; // Shadow renders into this actor
139   Actor mShadowPlaneBg; // mShadowPlane renders directly in front of this actor
140   Actor mPointLight;  // Shadow is cast from this point light
141
142   /////////////////////////////////////////////////////////////
143   FrameBufferImage mSceneFromLightRenderTarget;  // for rendering normal scene seen from light to texture instead of the screen
144
145   FrameBufferImage mOutputImage;
146
147   Actor mChildrenRoot; // Subtree for all user added child actors that should be rendered normally
148   Actor mBlurRootActor; // Root actor for blur filter processing
149   ImageActor mShadowPlaneDrawable; // Positioned on top of mShadowPlane for drawing shadow image
150   RenderTask mRenderSceneTask;
151
152   CameraActor mCameraActor; // Constrained to same position as mPointLight and pointing at mShadowPlane
153
154   ShaderEffect mShadowRenderShader;
155   BlurTwoPassFilter mBlurFilter;
156
157   Vector4 mCachedShadowColor;                               ///< Cached Shadow color.
158   Vector4 mCachedBackgroundColor;                           ///< Cached Shadow background color (same as shadow color but with alpha at 0.0)
159
160   /////////////////////////////////////////////////////////////
161   // Properties that can be animated
162   Property::Index mBlurStrengthPropertyIndex;
163   Property::Index mShadowColorPropertyIndex;
164   float mDownsampleWidthScale;
165   float mDownsampleHeightScale;
166
167 private:
168
169   // Undefined copy constructor.
170   ShadowView( const ShadowView& );
171
172   // Undefined assignment operator.
173   ShadowView& operator=( const ShadowView& );
174 };
175
176 } // namespace Internal
177
178
179 // Helpers for public-api forwarding methods
180 inline Toolkit::Internal::ShadowView& GetImpl( Toolkit::ShadowView& obj )
181 {
182   DALI_ASSERT_ALWAYS(obj);
183   Dali::RefObject& handle = obj.GetImplementation();
184   return static_cast<Toolkit::Internal::ShadowView&>(handle);
185 }
186
187 inline const Toolkit::Internal::ShadowView& GetImpl( const Toolkit::ShadowView& obj )
188 {
189   DALI_ASSERT_ALWAYS(obj);
190   const Dali::RefObject& handle = obj.GetImplementation();
191   return static_cast<const Toolkit::Internal::ShadowView&>(handle);
192 }
193
194
195 } // namespace Toolkit
196
197 } // namespace Dali
198
199 #endif // __DALI_TOOLKIT_INTERNAL_SHADOW_VIEW_H__