Conversion to Apache 2.0 license
[platform/core/uifw/dali-toolkit.git] / optional / dali-toolkit / internal / controls / super-blur-view / super-blur-view-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_SUPER_BLUR_VIEW_H__
2 #define __DALI_TOOLKIT_INTERNAL_SUPER_BLUR_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 // INTERNAL INCLUDES
22 #include <dali/dali.h>
23 #include <dali-toolkit/public-api/controls/control-impl.h>
24 #include <dali-toolkit/public-api/controls/super-blur-view/super-blur-view.h>
25 #include <dali-toolkit/public-api/controls/gaussian-blur-view/gaussian-blur-view.h>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 class SuperBlurView;
34
35 namespace Internal
36 {
37
38 /**
39  * SuperBlurView implementation class
40  */
41 class SuperBlurView : public Control
42 {
43 public:
44
45   // Properties
46   enum
47   {
48     SUPER_BLUR_VIEW_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
49     SUPER_BLUR_VIEW_PROPERTY_END_INDEX = SUPER_BLUR_VIEW_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
50   };
51
52 public:
53
54   /**
55    * @copydoc Dali::Toolkit::SuperBlurView::New
56    */
57   static Toolkit::SuperBlurView New( unsigned int blurLevels );
58
59   /**
60    * @copydoc Dali::Toolkit::SuperBlurView::SetImage
61    */
62   void SetImage(Image inputImage);
63
64   /**
65    * @copydoc Dali::Toolkit::SuperBlurView::GetBlurStrengthPropertyIndex
66    */
67   Property::Index GetBlurStrengthPropertyIndex() const;
68
69   /**
70    * @copydoc Dali::Toolkit::SuperBlurView::SetBlurStrength
71    */
72   void SetBlurStrength( float blurStrength );
73
74   /**
75    * @copydoc Dali::Toolkit::SuperBlurView::GetCurrentBlurStrength
76    */
77   float GetCurrentBlurStrength() const;
78
79   /**
80    * @copydoc Dali::Toolkit::SuperBlurView::BlurFinishedSignal
81    */
82   Dali::Toolkit::SuperBlurView::SuperBlurViewSignal& BlurFinishedSignal();
83
84   /**
85    * @copydoc Dali::Toolkit::SuperBlurView::GetBlurredImage
86    */
87   Image GetBlurredImage( unsigned int level );
88
89   // Properties
90
91   /**
92    * Called when a property of an object of this type is set.
93    * @param[in] object The object whose property is set.
94    * @param[in] index The property index.
95    * @param[in] value The new property value.
96    */
97   static void SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value );
98
99   /**
100    * Called to retrieve a property of an object of this type.
101    * @param[in] object The object whose property is to be retrieved.
102    * @param[in] index The property index.
103    * @return The current value of the property.
104    */
105   static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
106
107 protected:
108
109   /**
110    * Constructor. It initializes the SuperBlurView members
111    */
112   SuperBlurView( unsigned int blurLevels );
113
114   /**
115    * A reference counted object may only be deleted by calling Unreference()
116    */
117   virtual ~SuperBlurView();
118
119 private: // from Control
120
121   /**
122    * @copydoc Toolkit::Control::OnInitialize
123    */
124   virtual void OnInitialize();
125
126   /**
127    * @copydoc Toolkit::Control::OnControlSizeSet
128    */
129   virtual void OnControlSizeSet(const Vector3& targetSize);
130
131   /**
132    * @copydoc Control::OnRelaidOut()
133    */
134   virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
135
136 private:
137
138   /**
139    * Carry out the idx-th pass of blurring
140    * @param[in] idx The blur pass index
141    * @param[in] image The input image for the current blurring, it is either the original image or the blurred image from the previous pass
142    */
143   void BlurImage( unsigned int idx, Image image );
144
145   /**
146    * Signal handler to tell when the last blur view completes
147    * @param[in] blurView The blur view that just completed
148    */
149   void OnBlurViewFinished( Toolkit::GaussianBlurView blurView );
150
151   /**
152    * Clear the resources used to create the blurred image
153    */
154   void ClearBlurResource();
155
156 private:
157
158   unsigned int                           mBlurLevels;
159
160   Property::Index                        mBlurStrengthPropertyIndex;
161
162   std::vector<Toolkit::GaussianBlurView> mGaussianBlurView;
163   std::vector<FrameBufferImage>          mBlurredImage;
164   std::vector<ImageActor>                mImageActors;
165   bool                                   mResourcesCleared;
166
167   Vector2                                mTargetSize;
168   Toolkit::SuperBlurView::SuperBlurViewSignal mBlurFinishedSignal; ///< Signal emitted when blur has completed.
169 };
170
171 }
172
173 // Helpers for public-api forwarding methods
174 inline Toolkit::Internal::SuperBlurView& GetImpl( Toolkit::SuperBlurView& obj )
175 {
176   DALI_ASSERT_ALWAYS(obj);
177   Dali::RefObject& handle = obj.GetImplementation();
178   return static_cast<Toolkit::Internal::SuperBlurView&>(handle);
179 }
180
181 inline const Toolkit::Internal::SuperBlurView& GetImpl( const Toolkit::SuperBlurView& obj )
182 {
183   DALI_ASSERT_ALWAYS(obj);
184   const Dali::RefObject& handle = obj.GetImplementation();
185   return static_cast<const Toolkit::Internal::SuperBlurView&>(handle);
186 }
187
188 }
189
190 }
191
192 #endif /* __DALI_TOOLKIT_INTERNALSUPER_BLUR_VIEW_H__ */