Remove non-touch related deprecated APIs
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / gaussian-blur-view / gaussian-blur-view-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_GAUSSIAN_BLUR_EFFECT_H
2 #define DALI_TOOLKIT_INTERNAL_GAUSSIAN_BLUR_EFFECT_H
3
4 /*
5  * Copyright (c) 2020 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 <sstream>
23 #include <cmath>
24 #include <dali/public-api/object/property-map.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/devel-api/controls/gaussian-blur-view/gaussian-blur-view.h>
29 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
30
31 namespace Dali
32 {
33
34 namespace Toolkit
35 {
36
37 class GaussianBlurView;
38
39 namespace Internal
40 {
41
42 /**
43  * GaussianBlurView implementation class
44  */
45 class GaussianBlurView : public Control
46 {
47 public:
48
49   /**
50    * @copydoc Dali::Toolkit::GaussianBlurView::GaussianBlurView
51    */
52   GaussianBlurView();
53
54   /**
55    * @copydoc Dali::Toolkit::GaussianBlurView::GaussianBlurView
56    */
57   GaussianBlurView(const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat,
58                    const float downsampleWidthScale, const float downsampleHeightScale,
59                    bool blurUserImage);
60
61   /**
62    * @copydoc Dali::Toolkit::GaussianBlurView::~GaussianBlurView
63    */
64   virtual ~GaussianBlurView();
65
66   /**
67    * @copydoc Dali::Toolkit::GaussianBlurView::New
68    */
69   static Dali::Toolkit::GaussianBlurView New();
70   static Dali::Toolkit::GaussianBlurView New( const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat,
71                                               const float downsampleWidthScale, const float downsampleHeightScale,
72                                               bool blurUserImage);
73
74   void Activate();
75   void ActivateOnce();
76   void Deactivate();
77
78   void SetUserImageAndOutputRenderTarget(Texture inputImage, FrameBuffer outputRenderTarget);
79
80   Property::Index GetBlurStrengthPropertyIndex() const {return mBlurStrengthPropertyIndex;}
81   FrameBuffer GetBlurredRenderTarget() const;
82
83   /// @copydoc Dali::Toolkit::GaussianBlurView::SetBackgroundColor(const Vector4&)
84   void SetBackgroundColor( const Vector4& color );
85
86   /// @copydoc Dali::Toolkit::GaussianBlurView::GetBackgroundColor
87   Vector4 GetBackgroundColor() const;
88
89   void AllocateResources();
90   void CreateRenderTasks();
91   void RemoveRenderTasks();
92   Dali::Toolkit::GaussianBlurView::GaussianBlurViewSignal& FinishedSignal();
93
94 private:
95
96   virtual void OnInitialize();
97   virtual void OnSizeSet(const Vector3& targetSize);
98
99   /**
100    * @copydoc Control::OnChildAdd()
101    */
102   virtual void OnChildAdd( Actor& child );
103
104   /**
105    * @copydoc Control::OnChildRemove()
106    */
107   virtual void OnChildRemove( Actor& child );
108
109   void SetBlurBellCurveWidth(float blurBellCurveWidth);
110   float CalcGaussianWeight(float x);
111   void SetShaderConstants();
112   std::string GetSampleOffsetsPropertyName( unsigned int index ) const;
113   std::string GetSampleWeightsPropertyName( unsigned int index ) const;
114
115   void OnRenderTaskFinished(Dali::RenderTask& renderTask);
116
117   /////////////////////////////////////////////////////////////
118   unsigned int mNumSamples;       // number of blur samples in each of horiz/vert directions
119   float mBlurBellCurveWidth;      // constant used when calculating the gaussian weights
120   Pixel::Format mPixelFormat;     // pixel format used by render targets
121
122   /////////////////////////////////////////////////////////////
123   // downsampling is used for the separated blur passes to get increased blur with the same number of samples and also to make rendering quicker
124   float mDownsampleWidthScale;
125   float mDownsampleHeightScale;
126   float mDownsampledWidth;
127   float mDownsampledHeight;
128
129   /////////////////////////////////////////////////////////////
130   // if this is set to true, we blur a user supplied image rather than rendering and blurring children
131   bool mBlurUserImage:1;
132
133   /////////////////////////////////////////////////////////////
134   // if this is set to true, set the render tasks to refresh once
135   bool mRenderOnce:1;
136
137   /////////////////////////////////////////////////////////////
138   // background fill color
139   Vector4 mBackgroundColor;
140
141   /////////////////////////////////////////////////////////////
142   // for checking if we need to reallocate render targets
143   Vector2 mTargetSize;
144   Vector2 mLastSize;
145
146   /////////////////////////////////////////////////////////////
147   // for creating a subtree for all user added child actors, so that we can have them exclusive to the mRenderChildrenTask and our other actors exclusive to our other tasks
148   Actor mChildrenRoot;
149   // for creating a subtree for the internal actors
150   Actor mInternalRoot;
151
152   /////////////////////////////////////////////////////////////
153   // for mapping offscreen renders to render target sizes
154   CameraActor mRenderFullSizeCamera;
155   CameraActor mRenderDownsampledCamera;
156
157   /////////////////////////////////////////////////////////////
158   // for rendering all user added children to offscreen target
159   FrameBuffer mRenderTargetForRenderingChildren;
160   RenderTask mRenderChildrenTask;
161
162   /////////////////////////////////////////////////////////////
163   // for rendering separated blur passes to offscreen targets
164   FrameBuffer mRenderTarget1;
165   FrameBuffer mRenderTarget2;
166
167   Actor mHorizBlurActor;
168   Actor mVertBlurActor;
169
170   RenderTask mHorizBlurTask;
171   RenderTask mVertBlurTask;
172
173   /////////////////////////////////////////////////////////////
174   // for compositing blur and children renders to offscreen target
175   Actor mCompositingActor;
176   RenderTask mCompositeTask;
177
178   /////////////////////////////////////////////////////////////
179   // for holding blurred result
180   Actor mTargetActor;
181
182   /////////////////////////////////////////////////////////////
183   // for animating fade in / out of blur, hiding internal implementation but allowing user to set via GaussianBlurView interface
184   Property::Index mBlurStrengthPropertyIndex;
185
186   /////////////////////////////////////////////////////////////
187   // User can specify image to blur and output target, so we can use GaussianBlurView for arbitrary blur processes
188   Texture mUserInputImage;
189   FrameBuffer mUserOutputRenderTarget;
190
191   Dali::Toolkit::GaussianBlurView::GaussianBlurViewSignal mFinishedSignal; ///< Signal emitted when blur has completed.
192
193   bool mActivated:1;
194 private:
195
196   // Undefined copy constructor.
197   GaussianBlurView( const GaussianBlurView& );
198
199   // Undefined assignment operator.
200   GaussianBlurView& operator=( const GaussianBlurView& );
201 };
202
203 } // namespace Internal
204
205
206 // Helpers for public-api forwarding methods
207 inline Toolkit::Internal::GaussianBlurView& GetImpl( Toolkit::GaussianBlurView& obj )
208 {
209   DALI_ASSERT_ALWAYS(obj);
210   Dali::RefObject& handle = obj.GetImplementation();
211   return static_cast<Toolkit::Internal::GaussianBlurView&>(handle);
212 }
213
214 inline const Toolkit::Internal::GaussianBlurView& GetImpl( const Toolkit::GaussianBlurView& obj )
215 {
216   DALI_ASSERT_ALWAYS(obj);
217   const Dali::RefObject& handle = obj.GetImplementation();
218   return static_cast<const Toolkit::Internal::GaussianBlurView&>(handle);
219 }
220
221
222 } // namespace Toolkit
223
224 } // namespace Dali
225
226 #endif // DALI_TOOLKIT_INTERNAL_GAUSSIAN_BLUR_EFFECT_H