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