1 #ifndef __DALI_TOOLKIT_INTERNAL_EFFECTS_VIEW_H__
2 #define __DALI_TOOLKIT_INTERNAL_EFFECTS_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.
22 #include <dali/public-api/actors/camera-actor.h>
23 #include <dali/public-api/actors/image-actor.h>
24 #include <dali/public-api/common/dali-vector.h>
25 #include <dali/public-api/render-tasks/render-task.h>
26 #include <dali/public-api/shader-effects/shader-effect.h>
29 #include <dali-toolkit/public-api/controls/control-impl.h>
30 #include <dali-toolkit/public-api/controls/effects-view/effects-view.h>
31 #include <dali-toolkit/public-api/controls/gaussian-blur-view/gaussian-blur-view.h>
42 class GaussianBlurView;
46 * EffectsView implementation class
47 * @copydoc Dali::Toolkit::EffectsView
49 class EffectsView : public Control
52 /// @copydoc Dali::Toolkit::EffectsView New()
53 static Toolkit::EffectsView New();
56 * Construct a new EffectsView.
57 * @copydoc Toolkit::EffectsView New()
63 * @copydoc Toolkit::EffectsView New(const unsigned int,const float,const Pixel::Format,const float,const float)
65 EffectsView(const unsigned int numSamples, const float blurBellCurveWidth, const int spread,
66 const Pixel::Format pixelFormat,
67 const float downsampleWidthScale, const float downsampleHeightScale,
68 FrameBufferImage image);
71 * A reference counted object may only be deleted by calling Unreference()
73 virtual ~EffectsView();
77 /// @copydoc Dali::Toolkit::EffectsView::SetType
78 void SetType( Toolkit::EffectsView::EffectType type );
80 /// @copydoc Dali::Toolkit::EffectsView::GetType
81 Toolkit::EffectsView::EffectType GetType() const;
83 /// @copydoc Dali::Toolkit::EffectsView::Enable
86 /// @copydoc Dali::Toolkit::EffectsView::Disable
89 /// @copydoc Dali::Toolkit::EffectsView::Refresh
92 /// @copydoc Dali::Toolkit::EffectsView::SetRefreshOnDemand
93 void SetRefreshOnDemand( bool onDemand );
95 /// @copydoc Dali::Toolkit::EffectsView::SetPixelFormat
96 void SetPixelFormat( Pixel::Format pixelFormat );
98 /// @copydoc Dali::Toolkit::EffectsView::SetOutputImage
99 void SetOutputImage( FrameBufferImage image );
101 /// @copydoc Dali::Toolkit::EffectsView::GetOutputImage
102 FrameBufferImage GetOutputImage();
104 /// @copydoc Dali::Toolkit::EffectsView::GetEffectSizePropertyIndex
105 Property::Index GetEffectSizePropertyIndex() const;
107 /// @copydoc Dali::Toolkit::EffectsView::GetEffectStrengthPropertyIndex
108 Property::Index GetEffectStrengthPropertyIndex() const;
110 /// @copydoc Dali::Toolkit::EffectsView::GetEffectOffsetPropertyIndex
111 Property::Index GetEffectOffsetPropertyIndex() const;
113 /// @copydoc Dali::Toolkit::EffectsView::GetEffectColorPropertyIndex
114 Property::Index GetEffectColorPropertyIndex() const;
116 /// @copydoc Dali::Toolkit::EffectsView::SetBackgroundColor(const Vector4&)
117 void SetBackgroundColor( const Vector4& color );
119 /// @copydoc Dali::Toolkit::GaussianBlurView::GetBackgroundColor
120 Vector4 GetBackgroundColor() const;
124 * Register and setup indices for EffectsView properties
126 void SetupProperties();
128 private: // From Control
131 * @copydoc Toolkit::Control::OnInitialize()
133 virtual void OnInitialize();
136 * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& targetSize )
138 virtual void OnControlSizeSet( const Vector3& targetSize );
143 * Callback received when the control is disconnected from the stage.
145 void OnStageDisconnection();
148 * Setup image filters
155 void AllocateResources();
163 * Create render tasks for internal jobs
165 void CreateRenderTasks();
168 * Remove render tasks
170 void RemoveRenderTasks();
173 * Refresh render tasks
175 void RefreshRenderTasks();
178 * Remove ImageFilters
180 void RemoveFilters();
185 EffectsView( const EffectsView& );
188 EffectsView& operator = ( const EffectsView& );
190 private: // attributes/properties
191 Toolkit::EffectsView::EffectType mEffectType;
193 /////////////////////////////////////////////////////////////
194 // for rendering all user added children to offscreen target
195 FrameBufferImage mImageForChildren;
196 ImageActor mActorForChildren;
197 RenderTask mRenderTaskForChildren;
198 CameraActor mCameraForChildren;
200 /////////////////////////////////////////////////////////////
201 Pixel::Format mPixelFormat; ///< pixel format used by render targets
203 /////////////////////////////////////////////////////////////
204 // downsampling is used for the separated blur passes to get increased blur with the same number of samples and also to make rendering quicker
207 /////////////////////////////////////////////////////////////
208 // background fill color
209 Vector4 mBackgroundColor;
211 /////////////////////////////////////////////////////////////
212 // for checking if we need to reallocate render targets
216 bool mRefreshOnDemand;
218 /////////////////////////////////////////////////////////////
219 // horizontal spread objects
220 FrameBufferImage mImageForHorzSpread;
221 ImageActor mActorForHorzSpread;
222 RenderTask mRenderTaskForHorzSpread;
224 /////////////////////////////////////////////////////////////
225 // vertical spread objects
226 FrameBufferImage mImageForVertSpread;
227 ImageActor mActorForVertSpread;
228 RenderTask mRenderTaskForVertSpread;
230 CameraActor mCameraForSpread;
232 /////////////////////////////////////////////////////////////
234 FrameBufferImage mImagePostFilter;
235 ImageActor mActorPostFilter;
237 /////////////////////////////////////////////////////////////
239 FrameBufferImage mImageForResult;
240 Actor mActorForResult;
241 RenderTask mRenderTaskForResult;
243 Property::Index mEffectSizePropertyIndex;
244 Property::Index mEffectStrengthPropertyIndex;
245 Property::Index mEffectOffsetPropertyIndex;
246 Property::Index mEffectColorPropertyIndex;
248 std::vector<ImageFilter*> mFilters;
249 }; // class EffectsView
251 } // namespace Internal
254 // Helpers for public-api forwarding methods
256 inline Toolkit::Internal::EffectsView& GetImpl( Toolkit::EffectsView& effectsView )
258 DALI_ASSERT_ALWAYS( effectsView );
260 Dali::RefObject& handle = effectsView.GetImplementation();
262 return static_cast<Toolkit::Internal::EffectsView&>( handle );
265 inline const Toolkit::Internal::EffectsView& GetImpl( const Toolkit::EffectsView& effectsView )
267 DALI_ASSERT_ALWAYS( effectsView );
269 const Dali::RefObject& handle = effectsView.GetImplementation();
271 return static_cast<const Toolkit::Internal::EffectsView&>( handle );
274 } // namespace Toolkit
278 #endif // __DALI_TOOLKIT_INTERNAL_EFFECTS_VIEW_H__