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