1 #ifndef __DALI_TOOLKIT_INTERNAL_BLOOM_VIEW_H__
2 #define __DALI_TOOLKIT_INTERNAL_BLOOM_VIEW_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
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>
46 * BloomEffect implementation class
48 class BloomView : public Control
52 * @copydoc Dali::Toolkit::BloomView::BloomView
57 * @copydoc Dali::Toolkit::BloomView::BloomView
59 BloomView(const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat,
60 const float downsampleWidthScale, const float downsampleHeightScale);
63 * @copydoc Dali::Toolkit::BloomView::~BloomView
68 * @copydoc Dali::Toolkit::BloomView::New
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);
74 void Add(Actor child);
75 void Remove(Actor child);
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;}
89 virtual void OnInitialize();
90 virtual void OnSizeSet(const Vector3& targetSize);
92 void AllocateResources();
93 void CreateRenderTasks();
94 void RemoveRenderTasks();
96 void SetupProperties();
99 /////////////////////////////////////////////////////////////
100 unsigned int mBlurNumSamples; // number of blur samples in each of horiz/vert directions
101 float mBlurBellCurveWidth; // constant used when calculating the gaussian weights
102 Pixel::Format mPixelFormat; // pixel format used by render targets
104 /////////////////////////////////////////////////////////////
105 // downsampling is used for the separated blur passes to get increased blur with the same number of samples and also to make rendering quicker
106 float mDownsampleWidthScale;
107 float mDownsampleHeightScale;
108 float mDownsampledWidth;
109 float mDownsampledHeight;
112 /////////////////////////////////////////////////////////////
113 // for checking if we need to reallocate render targets
117 /////////////////////////////////////////////////////////////
118 // 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
121 /////////////////////////////////////////////////////////////
122 // for mapping offscreen renders to render target sizes
123 CameraActor mRenderFullSizeCamera;
124 CameraActor mRenderDownsampledCamera;
126 /////////////////////////////////////////////////////////////
127 // for rendering all user added children to offscreen target
128 FrameBufferImage mRenderTargetForRenderingChildren;
129 RenderTask mRenderChildrenTask;
131 /////////////////////////////////////////////////////////////
132 // for extracting bright parts of image to an offscreen target
133 FrameBufferImage mBloomExtractTarget; // for rendering bright parts of image into separate texture, also used as target for gaussian blur
134 RenderTask mBloomExtractTask;
135 Toolkit::ImageView mBloomExtractImageActor;
137 /////////////////////////////////////////////////////////////
138 // for blurring extracted bloom
139 Dali::Toolkit::GaussianBlurView mGaussianBlurView;
141 /////////////////////////////////////////////////////////////
142 // for compositing bloom and children renders to offscreen target
143 RenderTask mCompositeTask;
145 Toolkit::ImageView mCompositeImageActor;
147 /////////////////////////////////////////////////////////////
148 // for holding blurred result
149 FrameBufferImage mOutputRenderTarget;
150 Toolkit::ImageView mTargetImageActor;
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;
165 // Undefined copy constructor.
166 BloomView( const BloomView& );
168 // Undefined assignment operator.
169 BloomView& operator=( const BloomView& );
172 } // namespace Internal
174 // Helpers for public-api forwarding methods
175 inline Toolkit::Internal::BloomView& GetImpl( Toolkit::BloomView& obj )
177 DALI_ASSERT_ALWAYS(obj);
178 Dali::RefObject& handle = obj.GetImplementation();
179 return static_cast<Toolkit::Internal::BloomView&>(handle);
182 inline const Toolkit::Internal::BloomView& GetImpl( const Toolkit::BloomView& obj )
184 DALI_ASSERT_ALWAYS(obj);
185 const Dali::RefObject& handle = obj.GetImplementation();
186 return static_cast<const Toolkit::Internal::BloomView&>(handle);
189 } // namespace Toolkit
193 #endif // __DALI_TOOLKIT_INTERNAL_BLOOM_VIEW_H__