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