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