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