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