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