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