remove dead code from shadow view (OnStageConnection & OnStageDisconnection)
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / effects-view / effects-view-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_EFFECTS_VIEW_H__
2 #define __DALI_TOOLKIT_INTERNAL_EFFECTS_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 <dali/public-api/actors/camera-actor.h>
23 #include <dali/public-api/actors/image-actor.h>
24 #include <dali/public-api/common/dali-vector.h>
25 #include <dali/public-api/render-tasks/render-task.h>
26 #include <dali/public-api/shader-effects/shader-effect.h>
27
28 // INTERNAL INCLUDES
29 #include <dali-toolkit/public-api/controls/control-impl.h>
30 #include <dali-toolkit/devel-api/controls/effects-view/effects-view.h>
31 #include <dali-toolkit/public-api/controls/gaussian-blur-view/gaussian-blur-view.h>
32
33 namespace Dali
34 {
35
36 namespace Toolkit
37 {
38
39 namespace Internal
40 {
41
42 class GaussianBlurView;
43 class ImageFilter;
44
45 /**
46  * EffectsView implementation class
47  * @copydoc Dali::Toolkit::EffectsView
48  */
49 class EffectsView : public Control
50 {
51 public:
52   /// @copydoc Dali::Toolkit::EffectsView New()
53   static Toolkit::EffectsView New();
54
55   /**
56    * Construct a new EffectsView.
57    * @copydoc Toolkit::EffectsView New()
58    */
59   EffectsView();
60
61   /**
62    * Constructor.
63    * @copydoc Toolkit::EffectsView New(const unsigned int,const float,const Pixel::Format,const float,const float)
64    */
65   EffectsView(const unsigned int numSamples, const float blurBellCurveWidth, const int spread,
66               const Pixel::Format pixelFormat,
67               const float downsampleWidthScale, const float downsampleHeightScale,
68               FrameBufferImage image);
69
70   /**
71    * A reference counted object may only be deleted by calling Unreference()
72    */
73   virtual ~EffectsView();
74
75 public:
76
77   /// @copydoc Dali::Toolkit::EffectsView::SetType
78   void SetType( Toolkit::EffectsView::EffectType type );
79
80   /// @copydoc Dali::Toolkit::EffectsView::GetType
81   Toolkit::EffectsView::EffectType GetType() const;
82
83   /// @copydoc Dali::Toolkit::EffectsView::Enable
84   void Enable();
85
86   /// @copydoc Dali::Toolkit::EffectsView::Disable
87   void Disable();
88
89   /// @copydoc Dali::Toolkit::EffectsView::Refresh
90   void Refresh();
91
92   /// @copydoc Dali::Toolkit::EffectsView::SetRefreshOnDemand
93   void SetRefreshOnDemand( bool onDemand );
94
95   /// @copydoc Dali::Toolkit::EffectsView::SetPixelFormat
96   void SetPixelFormat( Pixel::Format pixelFormat );
97
98   /// @copydoc Dali::Toolkit::EffectsView::SetOutputImage
99   void SetOutputImage( FrameBufferImage image );
100
101   /// @copydoc Dali::Toolkit::EffectsView::GetOutputImage
102   FrameBufferImage GetOutputImage();
103
104   /// @copydoc Dali::Toolkit::EffectsView::GetEffectSizePropertyIndex
105   Property::Index GetEffectSizePropertyIndex() const;
106
107   /// @copydoc Dali::Toolkit::EffectsView::GetEffectStrengthPropertyIndex
108   Property::Index GetEffectStrengthPropertyIndex() const;
109
110   /// @copydoc Dali::Toolkit::EffectsView::GetEffectOffsetPropertyIndex
111   Property::Index GetEffectOffsetPropertyIndex() const;
112
113   /// @copydoc Dali::Toolkit::EffectsView::GetEffectColorPropertyIndex
114   Property::Index GetEffectColorPropertyIndex() const;
115
116   /// @copydoc Dali::Toolkit::EffectsView::SetBackgroundColor(const Vector4&)
117   void SetBackgroundColor( const Vector4& color );
118
119   /// @copydoc Dali::Toolkit::GaussianBlurView::GetBackgroundColor
120   Vector4 GetBackgroundColor() const;
121
122 private:
123   /**
124    * Register and setup indices for EffectsView properties
125    */
126   void SetupProperties();
127
128 private: // From Control
129
130   /**
131    * @copydoc Toolkit::Control::OnInitialize()
132    */
133   virtual void OnInitialize();
134
135   /**
136    * @copydoc CustomActorImpl::OnSizeSet( const Vector3& targetSize )
137    */
138   virtual void OnSizeSet( const Vector3& targetSize );
139
140 private:
141
142   /**
143    * Callback received when the control is disconnected from the stage.
144    */
145   void OnStageDisconnection();
146
147   /**
148    * Setup image filters
149    */
150   void SetupFilters();
151
152   /**
153    * Allocate resources
154    */
155   void AllocateResources();
156
157   /**
158    * Setup cameras
159    */
160   void SetupCameras();
161
162   /**
163    * Create render tasks for internal jobs
164    */
165   void CreateRenderTasks();
166
167   /**
168    * Remove render tasks
169    */
170   void RemoveRenderTasks();
171
172   /**
173    * Refresh render tasks
174    */
175   void RefreshRenderTasks();
176
177   /**
178    * Remove ImageFilters
179    */
180   void RemoveFilters();
181
182 private:
183
184   // Undefined
185   EffectsView( const EffectsView& );
186
187   // Undefined
188   EffectsView& operator = ( const EffectsView& );
189
190 private: // attributes/properties
191   Toolkit::EffectsView::EffectType mEffectType;
192
193   /////////////////////////////////////////////////////////////
194   // for rendering all user added children to offscreen target
195   FrameBufferImage mImageForChildren;
196   ImageActor mActorForChildren;
197   RenderTask mRenderTaskForChildren;
198   CameraActor mCameraForChildren;
199
200   /////////////////////////////////////////////////////////////
201   Pixel::Format mPixelFormat;     ///< pixel format used by render targets
202
203   /////////////////////////////////////////////////////////////
204   // downsampling is used for the separated blur passes to get increased blur with the same number of samples and also to make rendering quicker
205   float mSpread;
206
207   /////////////////////////////////////////////////////////////
208   // background fill color
209   Vector4 mBackgroundColor;
210
211   /////////////////////////////////////////////////////////////
212   // for checking if we need to reallocate render targets
213   Vector2 mTargetSize;
214   Vector2 mLastSize;
215
216   bool mRefreshOnDemand;
217
218   /////////////////////////////////////////////////////////////
219   // horizontal spread objects
220   FrameBufferImage mImageForHorzSpread;
221   ImageActor mActorForHorzSpread;
222   RenderTask mRenderTaskForHorzSpread;
223
224   /////////////////////////////////////////////////////////////
225   // vertical spread objects
226   FrameBufferImage mImageForVertSpread;
227   ImageActor mActorForVertSpread;
228   RenderTask mRenderTaskForVertSpread;
229
230   CameraActor mCameraForSpread;
231
232   /////////////////////////////////////////////////////////////
233   // post blur image
234   FrameBufferImage mImagePostFilter;
235   ImageActor mActorPostFilter;
236
237   /////////////////////////////////////////////////////////////
238   // final image
239   FrameBufferImage mImageForResult;
240   Actor mActorForResult;
241   RenderTask mRenderTaskForResult;
242
243   Property::Index mEffectSizePropertyIndex;
244   Property::Index mEffectStrengthPropertyIndex;
245   Property::Index mEffectOffsetPropertyIndex;
246   Property::Index mEffectColorPropertyIndex;
247
248   std::vector<ImageFilter*> mFilters;
249 }; // class EffectsView
250
251 } // namespace Internal
252
253
254 // Helpers for public-api forwarding methods
255
256 inline Toolkit::Internal::EffectsView& GetImpl( Toolkit::EffectsView& effectsView )
257 {
258   DALI_ASSERT_ALWAYS( effectsView );
259
260   Dali::RefObject& handle = effectsView.GetImplementation();
261
262   return static_cast<Toolkit::Internal::EffectsView&>( handle );
263 }
264
265 inline const Toolkit::Internal::EffectsView& GetImpl( const Toolkit::EffectsView& effectsView )
266 {
267   DALI_ASSERT_ALWAYS( effectsView );
268
269   const Dali::RefObject& handle = effectsView.GetImplementation();
270
271   return static_cast<const Toolkit::Internal::EffectsView&>( handle );
272 }
273
274 } // namespace Toolkit
275
276 } // namespace Dali
277
278 #endif // __DALI_TOOLKIT_INTERNAL_EFFECTS_VIEW_H__
279