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/common/dali-vector.h>
24 #include <dali/public-api/render-tasks/render-task.h>
27 #include <dali-toolkit/devel-api/controls/effects-view/effects-view.h>
28 #include <dali-toolkit/public-api/controls/control-impl.h>
29 #include <dali-toolkit/public-api/controls/gaussian-blur-view/gaussian-blur-view.h>
30 #include <dali-toolkit/devel-api/controls/renderer-factory/renderer-factory.h>
41 class GaussianBlurView;
45 * EffectsView implementation class
46 * @copydoc Dali::Toolkit::EffectsView
48 class EffectsView : public Control
51 /// @copydoc Dali::Toolkit::EffectsView New()
52 static Toolkit::EffectsView New();
55 * Construct a new EffectsView.
56 * @copydoc Toolkit::EffectsView New()
62 * @copydoc Toolkit::EffectsView New(const unsigned int,const float,const Pixel::Format,const float,const float)
64 EffectsView(const unsigned int numSamples, const float blurBellCurveWidth, const int spread,
65 const Pixel::Format pixelFormat,
66 const float downsampleWidthScale, const float downsampleHeightScale,
67 FrameBufferImage image);
70 * A reference counted object may only be deleted by calling Unreference()
72 virtual ~EffectsView();
76 /// @copydoc Dali::Toolkit::EffectsView::SetType
77 void SetType( Toolkit::EffectsView::EffectType type );
79 /// @copydoc Dali::Toolkit::EffectsView::GetType
80 Toolkit::EffectsView::EffectType GetType() const;
82 /// @copydoc Dali::Toolkit::EffectsView::Refresh
85 /// @copydoc Dali::Toolkit::EffectsView::SetRefreshOnDemand
86 void SetRefreshOnDemand( bool onDemand );
88 /// @copydoc Dali::Toolkit::EffectsView::SetPixelFormat
89 void SetPixelFormat( Pixel::Format pixelFormat );
91 /// @copydoc Dali::Toolkit::EffectsView::SetBackgroundColor(const Vector4&)
92 void SetBackgroundColor( const Vector4& color );
94 /// @copydoc Dali::Toolkit::GaussianBlurView::GetBackgroundColor
95 Vector4 GetBackgroundColor() const;
98 * Set the effect size which decides the size of filter kernel.
99 * @param[in] effectSize The effect size.
101 void SetEffectSize( int effectSize );
104 * Get the effect size.
105 * @return The effect size.
111 * Called when a property of an object of this type is set.
112 * @param[in] object The object whose property is set.
113 * @param[in] index The property index.
114 * @param[in] value The new property value.
116 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
120 * Called to retrieve a property of an object of this type.
121 * @param[in] object The object whose property is to be retrieved.
122 * @param[in] index The property index.
123 * @return The current value of the property.
125 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
127 private: // From Control
130 * @copydoc Toolkit::Internal::Control::OnInitialize()
132 virtual void OnInitialize();
135 * @copydoc CustomActorImpl::OnSizeSet( const Vector3& targetSize )
137 virtual void OnSizeSet( const Vector3& targetSize );
140 * @copydoc Toolkit::Internal::Control::OnStageConnection
142 virtual void OnStageConnection( int depth );
145 * @copydoc Toolkit::Internal::Control::OnStageDisconnection
147 virtual void OnStageDisconnection();
150 * @copydoc Toolkit::Internal::Control::OnChildAdd
152 virtual void OnChildAdd( Actor& child );
155 * @copydoc Toolkit::Internal::Control::OnChildRemove
157 virtual void OnChildRemove( Actor& child );
162 * Enable the effect when the control is set on stage
167 * Disable the effect when the control is set off stage
172 * Setup image filters
179 void AllocateResources();
187 * Create render tasks for internal jobs
189 void CreateRenderTasks();
192 * Remove render tasks
194 void RemoveRenderTasks();
197 * Refresh render tasks
199 void RefreshRenderTasks();
202 * Remove ImageFilters
204 void RemoveFilters();
209 EffectsView( const EffectsView& );
212 EffectsView& operator = ( const EffectsView& );
214 private: // attributes/properties
216 /////////////////////////////////////////////////////////////
217 // for rendering all user added children to offscreen target
218 FrameBufferImage mImageForChildren;
219 Toolkit::ControlRenderer mRendererForChildren;
220 RenderTask mRenderTaskForChildren;
221 CameraActor mCameraForChildren;
222 Actor mChildrenRoot; // for creating a subtree for all user added child actors
224 /////////////////////////////////////////////////////////////
225 // background fill color
226 Vector4 mBackgroundColor;
228 /////////////////////////////////////////////////////////////
229 // for checking if we need to reallocate render targets
232 /////////////////////////////////////////////////////////////
234 FrameBufferImage mImagePostFilter;
235 Toolkit::ControlRenderer mRendererPostFilter;
237 Vector<ImageFilter*> mFilters;
239 /////////////////////////////////////////////////////////////
240 // downsampling is used for the separated blur passes to get increased blur with the same number of samples and also to make rendering quicker
243 /////////////////////////////////////////////////////////////
244 Toolkit::EffectsView::EffectType mEffectType;
245 Pixel::Format mPixelFormat; ///< pixel format used by render targets
248 bool mRefreshOnDemand:1;
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__