Add 'ExclusiveArch: armv7l' limit build to arm architecture
[platform/core/uifw/dali-toolkit.git] / optional / dali-toolkit / internal / controls / bloom-view / bloom-view-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_BLOOM_VIEW_H__
2 #define __DALI_TOOLKIT_INTERNAL_BLOOM_VIEW_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // EXTERNAL INCLUDES
21 #include <sstream>
22 #include <cmath>
23
24 // INTERNAL INCLUDES
25 #include <dali/dali.h>
26 #include <dali-toolkit/public-api/controls/control-impl.h>
27 #include <dali-toolkit/public-api/controls/gaussian-blur-view/gaussian-blur-view.h>
28 #include <dali-toolkit/public-api/controls/bloom-view/bloom-view.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 class BloomView;
37
38 namespace Internal
39 {
40
41 /**
42  * BloomEffect implementation class
43  */
44 class BloomView : public ControlImpl
45 {
46 public:
47   /**
48    * @copydoc Dali::Toolkit::BloomView::BloomView
49    */
50   BloomView();
51
52   /**
53    * @copydoc Dali::Toolkit::BloomView::BloomView
54    */
55   BloomView(const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat,
56                    const float downsampleWidthScale, const float downsampleHeightScale);
57
58   /**
59    * @copydoc Dali::Toolkit::BloomView::~BloomView
60    */
61   virtual ~BloomView();
62
63   /**
64    * @copydoc Dali::Toolkit::BloomView::New
65    */
66   static Dali::Toolkit::BloomView New();
67   static Dali::Toolkit::BloomView New( const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat,
68                                               const float downsampleWidthScale, const float downsampleHeightScale);
69
70   void Add(Actor child);
71   void Remove(Actor child);
72
73   void Activate();
74   void Deactivate();
75
76   Property::Index GetBloomThresholdPropertyIndex() const {return mBloomThresholdPropertyIndex;}
77   Property::Index GetBlurStrengthPropertyIndex() const {return mBlurStrengthPropertyIndex;}
78   Property::Index GetBloomIntensityPropertyIndex() const {return mBloomIntensityPropertyIndex;}
79   Property::Index GetBloomSaturationPropertyIndex() const {return mBloomSaturationPropertyIndex;}
80   Property::Index GetImageIntensityPropertyIndex() const {return mImageIntensityPropertyIndex;}
81   Property::Index GetImageSaturationPropertyIndex() const {return mImageSaturationPropertyIndex;}
82
83 private:
84
85   virtual void OnInitialize();
86   virtual void OnControlSizeSet(const Vector3& targetSize);
87   virtual void OnStageDisconnection();
88
89   virtual void OnControlStageConnection();
90
91   void AllocateResources();
92   void CreateRenderTasks();
93   void RemoveRenderTasks();
94
95   void SetupProperties();
96
97
98   /////////////////////////////////////////////////////////////
99   unsigned int mBlurNumSamples;   // number of blur samples in each of horiz/vert directions
100   float mBlurBellCurveWidth;      // constant used when calculating the gaussian weights
101   Pixel::Format mPixelFormat;     // pixel format used by render targets
102
103   /////////////////////////////////////////////////////////////
104   // downsampling is used for the separated blur passes to get increased blur with the same number of samples and also to make rendering quicker
105   float mDownsampleWidthScale;
106   float mDownsampleHeightScale;
107   float mDownsampledWidth;
108   float mDownsampledHeight;
109
110
111   /////////////////////////////////////////////////////////////
112   // for checking if we need to reallocate render targets
113   Vector2 mTargetSize;
114   Vector2 mLastSize;
115
116   /////////////////////////////////////////////////////////////
117   // 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
118   Actor mChildrenRoot;
119
120   /////////////////////////////////////////////////////////////
121   // for mapping offscreen renders to render target sizes
122   CameraActor mRenderFullSizeCamera;
123   CameraActor mRenderDownsampledCamera;
124
125   /////////////////////////////////////////////////////////////
126   // for rendering all user added children to offscreen target
127   FrameBufferImage mRenderTargetForRenderingChildren;
128   RenderTask mRenderChildrenTask;
129
130   /////////////////////////////////////////////////////////////
131   // for extracting bright parts of image to an offscreen target
132   FrameBufferImage mBloomExtractTarget; // for rendering bright parts of image into separate texture, also used as target for gaussian blur
133   RenderTask mBloomExtractTask;
134   ShaderEffect mBloomExtractShader;
135   ImageActor mBloomExtractImageActor;
136
137   /////////////////////////////////////////////////////////////
138   // for blurring extracted bloom
139   Dali::Toolkit::GaussianBlurView mGaussianBlurView;
140
141   /////////////////////////////////////////////////////////////
142   // for compositing bloom and children renders to offscreen target
143   RenderTask mCompositeTask;
144   ShaderEffect mCompositeShader;
145   ImageActor mCompositeImageActor;
146
147   /////////////////////////////////////////////////////////////
148   // for holding blurred result
149   FrameBufferImage mOutputRenderTarget;
150   ImageActor mTargetImageActor;
151
152   /////////////////////////////////////////////////////////////
153   // Properties for setting by user, e.g. by animations
154   Property::Index mBloomThresholdPropertyIndex;
155   Property::Index mBlurStrengthPropertyIndex;
156   Property::Index mBloomIntensityPropertyIndex;
157   Property::Index mBloomSaturationPropertyIndex;
158   Property::Index mImageIntensityPropertyIndex;
159   Property::Index mImageSaturationPropertyIndex;
160
161 private:
162
163   // Undefined copy constructor.
164   BloomView( const BloomView& );
165
166   // Undefined assignment operator.
167   BloomView& operator=( const BloomView& );
168 };
169
170 } // namespace Internal
171
172 // Helpers for public-api forwarding methods
173 inline Toolkit::Internal::BloomView& GetImpl( Toolkit::BloomView& obj )
174 {
175   DALI_ASSERT_ALWAYS(obj);
176   Dali::RefObject& handle = obj.GetImplementation();
177   return static_cast<Toolkit::Internal::BloomView&>(handle);
178 }
179
180 inline const Toolkit::Internal::BloomView& GetImpl( const Toolkit::BloomView& obj )
181 {
182   DALI_ASSERT_ALWAYS(obj);
183   const Dali::RefObject& handle = obj.GetImplementation();
184   return static_cast<const Toolkit::Internal::BloomView&>(handle);
185 }
186
187 } // namespace Toolkit
188
189 } // namespace Dali
190
191 #endif // __DALI_TOOLKIT_INTERNAL_BLOOM_VIEW_H__