Stop Overriding Actor::Add() & Actor::Remove()
[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) 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
28 // INTERNAL INCLUDES
29 #include <dali-toolkit/public-api/controls/control-impl.h>
30 #include <dali-toolkit/public-api/controls/gaussian-blur-view/gaussian-blur-view.h>
31 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
32 #include <dali-toolkit/devel-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   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 OnSizeSet(const Vector3& targetSize);
87
88   /**
89    * @copydoc Control::OnControlChildAdd()
90    */
91   virtual void OnControlChildAdd( Actor& child );
92
93   /**
94    * @copydoc Control::OnControlChildRemove()
95    */
96   virtual void OnControlChildRemove( Actor& child );
97
98   void AllocateResources();
99   void CreateRenderTasks();
100   void RemoveRenderTasks();
101
102   void SetupProperties();
103
104
105   /////////////////////////////////////////////////////////////
106   unsigned int mBlurNumSamples;   // number of blur samples in each of horiz/vert directions
107   float mBlurBellCurveWidth;      // constant used when calculating the gaussian weights
108   Pixel::Format mPixelFormat;     // pixel format used by render targets
109
110   /////////////////////////////////////////////////////////////
111   // downsampling is used for the separated blur passes to get increased blur with the same number of samples and also to make rendering quicker
112   float mDownsampleWidthScale;
113   float mDownsampleHeightScale;
114   float mDownsampledWidth;
115   float mDownsampledHeight;
116
117
118   /////////////////////////////////////////////////////////////
119   // for checking if we need to reallocate render targets
120   Vector2 mTargetSize;
121   Vector2 mLastSize;
122
123   /////////////////////////////////////////////////////////////
124   // 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
125   Actor mChildrenRoot;
126   // for creating a subtree for the internal actors
127   Actor mInternalRoot;
128
129   /////////////////////////////////////////////////////////////
130   // for mapping offscreen renders to render target sizes
131   CameraActor mRenderFullSizeCamera;
132   CameraActor mRenderDownsampledCamera;
133
134   /////////////////////////////////////////////////////////////
135   // for rendering all user added children to offscreen target
136   FrameBufferImage mRenderTargetForRenderingChildren;
137   RenderTask mRenderChildrenTask;
138
139   /////////////////////////////////////////////////////////////
140   // for extracting bright parts of image to an offscreen target
141   FrameBufferImage mBloomExtractTarget; // for rendering bright parts of image into separate texture, also used as target for gaussian blur
142   RenderTask mBloomExtractTask;
143   Toolkit::ImageView mBloomExtractImageActor;
144
145   /////////////////////////////////////////////////////////////
146   // for blurring extracted bloom
147   Dali::Toolkit::GaussianBlurView mGaussianBlurView;
148
149   /////////////////////////////////////////////////////////////
150   // for compositing bloom and children renders to offscreen target
151   RenderTask mCompositeTask;
152
153   Toolkit::ImageView mCompositeImageActor;
154
155   /////////////////////////////////////////////////////////////
156   // for holding blurred result
157   FrameBufferImage mOutputRenderTarget;
158   Toolkit::ImageView mTargetImageActor;
159
160   /////////////////////////////////////////////////////////////
161   // Properties for setting by user, e.g. by animations
162   Property::Index mBloomThresholdPropertyIndex;
163   Property::Index mBlurStrengthPropertyIndex;
164   Property::Index mBloomIntensityPropertyIndex;
165   Property::Index mBloomSaturationPropertyIndex;
166   Property::Index mImageIntensityPropertyIndex;
167   Property::Index mImageSaturationPropertyIndex;
168
169   bool mActivated:1;
170
171 private:
172
173   // Undefined copy constructor.
174   BloomView( const BloomView& );
175
176   // Undefined assignment operator.
177   BloomView& operator=( const BloomView& );
178 };
179
180 } // namespace Internal
181
182 // Helpers for public-api forwarding methods
183 inline Toolkit::Internal::BloomView& GetImpl( Toolkit::BloomView& obj )
184 {
185   DALI_ASSERT_ALWAYS(obj);
186   Dali::RefObject& handle = obj.GetImplementation();
187   return static_cast<Toolkit::Internal::BloomView&>(handle);
188 }
189
190 inline const Toolkit::Internal::BloomView& GetImpl( const Toolkit::BloomView& obj )
191 {
192   DALI_ASSERT_ALWAYS(obj);
193   const Dali::RefObject& handle = obj.GetImplementation();
194   return static_cast<const Toolkit::Internal::BloomView&>(handle);
195 }
196
197 } // namespace Toolkit
198
199 } // namespace Dali
200
201 #endif // __DALI_TOOLKIT_INTERNAL_BLOOM_VIEW_H__