Moving visuals into new folder with same level as controls
[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/common/dali-vector.h>
24 #include <dali/public-api/render-tasks/render-task.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/devel-api/controls/effects-view/effects-view.h>
28 #include <dali-toolkit/public-api/controls/control-impl.h>
29 #include <dali-toolkit/public-api/controls/gaussian-blur-view/gaussian-blur-view.h>
30 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
31
32 namespace Dali
33 {
34
35 namespace Toolkit
36 {
37
38 namespace Internal
39 {
40
41 class GaussianBlurView;
42 class ImageFilter;
43
44 /**
45  * EffectsView implementation class
46  * @copydoc Dali::Toolkit::EffectsView
47  */
48 class EffectsView : public Control
49 {
50 public:
51   /// @copydoc Dali::Toolkit::EffectsView New()
52   static Toolkit::EffectsView New();
53
54   /**
55    * Construct a new EffectsView.
56    * @copydoc Toolkit::EffectsView New()
57    */
58   EffectsView();
59
60   /**
61    * Constructor.
62    * @copydoc Toolkit::EffectsView New(const unsigned int,const float,const Pixel::Format,const float,const float)
63    */
64   EffectsView(const unsigned int numSamples, const float blurBellCurveWidth, const int spread,
65               const Pixel::Format pixelFormat,
66               const float downsampleWidthScale, const float downsampleHeightScale,
67               FrameBufferImage image);
68
69   /**
70    * A reference counted object may only be deleted by calling Unreference()
71    */
72   virtual ~EffectsView();
73
74 public:
75
76   /// @copydoc Dali::Toolkit::EffectsView::SetType
77   void SetType( Toolkit::EffectsView::EffectType type );
78
79   /// @copydoc Dali::Toolkit::EffectsView::GetType
80   Toolkit::EffectsView::EffectType GetType() const;
81
82   /// @copydoc Dali::Toolkit::EffectsView::Refresh
83   void Refresh();
84
85   /// @copydoc Dali::Toolkit::EffectsView::SetRefreshOnDemand
86   void SetRefreshOnDemand( bool onDemand );
87
88   /// @copydoc Dali::Toolkit::EffectsView::SetPixelFormat
89   void SetPixelFormat( Pixel::Format pixelFormat );
90
91   /// @copydoc Dali::Toolkit::EffectsView::SetBackgroundColor(const Vector4&)
92   void SetBackgroundColor( const Vector4& color );
93
94   /// @copydoc Dali::Toolkit::GaussianBlurView::GetBackgroundColor
95   Vector4 GetBackgroundColor() const;
96
97   /**
98    * Set the effect size which decides the size of filter kernel.
99    * @param[in] effectSize The effect size.
100    */
101   void SetEffectSize( int effectSize );
102
103   /**
104    * Get the effect size.
105    * @return The effect size.
106    */
107   int GetEffectSize();
108
109   // Properties
110   /**
111    * Called when a property of an object of this type is set.
112    * @param[in] object The object whose property is set.
113    * @param[in] index The property index.
114    * @param[in] value The new property value.
115    */
116   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
117
118
119   /**
120    * Called to retrieve a property of an object of this type.
121    * @param[in] object The object whose property is to be retrieved.
122    * @param[in] index The property index.
123    * @return The current value of the property.
124    */
125   static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
126
127 private: // From Control
128
129   /**
130    * @copydoc Toolkit::Internal::Control::OnInitialize()
131    */
132   virtual void OnInitialize();
133
134   /**
135    * @copydoc CustomActorImpl::OnSizeSet( const Vector3& targetSize )
136    */
137   virtual void OnSizeSet( const Vector3& targetSize );
138
139   /**
140    * @copydoc Toolkit::Internal::Control::OnStageConnection
141    */
142   virtual void OnStageConnection( int depth );
143
144   /**
145    * @copydoc Toolkit::Internal::Control::OnStageDisconnection
146    */
147   virtual void OnStageDisconnection();
148
149   /**
150    * @copydoc Toolkit::Internal::Control::OnChildAdd
151    */
152   virtual void OnChildAdd( Actor& child );
153
154   /**
155    * @copydoc Toolkit::Internal::Control::OnChildRemove
156    */
157   virtual void OnChildRemove( Actor& child );
158
159 private:
160
161   /**
162    * Enable the effect when the control is set on stage
163    */
164   void Enable();
165
166   /**
167    * Disable the effect when the control is set off stage
168    */
169   void Disable();
170
171   /**
172    * Setup image filters
173    */
174   void SetupFilters();
175
176   /**
177    * Allocate resources
178    */
179   void AllocateResources();
180
181   /**
182    * Setup cameras
183    */
184   void SetupCameras();
185
186   /**
187    * Create render tasks for internal jobs
188    */
189   void CreateRenderTasks();
190
191   /**
192    * Remove render tasks
193    */
194   void RemoveRenderTasks();
195
196   /**
197    * Refresh render tasks
198    */
199   void RefreshRenderTasks();
200
201   /**
202    * Remove ImageFilters
203    */
204   void RemoveFilters();
205
206 private:
207
208   // Undefined
209   EffectsView( const EffectsView& );
210
211   // Undefined
212   EffectsView& operator = ( const EffectsView& );
213
214 private: // attributes/properties
215
216   /////////////////////////////////////////////////////////////
217   // for rendering all user added children to offscreen target
218   FrameBufferImage mImageForChildren;
219   Toolkit::Visual mRendererForChildren;
220   RenderTask mRenderTaskForChildren;
221   CameraActor mCameraForChildren;
222   Actor mChildrenRoot; // for creating a subtree for all user added child actors
223
224   /////////////////////////////////////////////////////////////
225   // background fill color
226   Vector4 mBackgroundColor;
227
228   /////////////////////////////////////////////////////////////
229   // for checking if we need to reallocate render targets
230   Vector2 mTargetSize;
231   Vector2 mLastSize;
232   /////////////////////////////////////////////////////////////
233   // post blur image
234   FrameBufferImage mImagePostFilter;
235   Toolkit::Visual mRendererPostFilter;
236
237   Vector<ImageFilter*> mFilters;
238
239   /////////////////////////////////////////////////////////////
240   // downsampling is used for the separated blur passes to get increased blur with the same number of samples and also to make rendering quicker
241   int mEffectSize;
242
243   /////////////////////////////////////////////////////////////
244   Toolkit::EffectsView::EffectType mEffectType;
245   Pixel::Format mPixelFormat;     ///< pixel format used by render targets
246
247   bool mEnabled:1;
248   bool mRefreshOnDemand:1;
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