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