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