1 #ifndef __DALI_TOOLKIT_INTERNAL_EFFECTS_VIEW_H__
2 #define __DALI_TOOLKIT_INTERNAL_EFFECTS_VIEW_H__
5 * Copyright (c) 2016 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/devel-api/visual-factory/visual-factory.h>
40 class GaussianBlurView;
44 * EffectsView implementation class
45 * @copydoc Dali::Toolkit::EffectsView
47 class EffectsView : public Control
50 /// @copydoc Dali::Toolkit::EffectsView New()
51 static Toolkit::EffectsView New();
54 * Construct a new EffectsView.
55 * @copydoc Toolkit::EffectsView New()
61 * @copydoc Toolkit::EffectsView New(const unsigned int,const float,const Pixel::Format,const float,const float)
63 EffectsView(const unsigned int numSamples, const float blurBellCurveWidth, const int spread,
64 const Pixel::Format pixelFormat,
65 const float downsampleWidthScale, const float downsampleHeightScale,
66 FrameBufferImage image);
69 * A reference counted object may only be deleted by calling Unreference()
71 virtual ~EffectsView();
75 /// @copydoc Dali::Toolkit::EffectsView::SetType
76 void SetType( Toolkit::EffectsView::EffectType type );
78 /// @copydoc Dali::Toolkit::EffectsView::GetType
79 Toolkit::EffectsView::EffectType GetType() const;
81 /// @copydoc Dali::Toolkit::EffectsView::Refresh
84 /// @copydoc Dali::Toolkit::EffectsView::SetRefreshOnDemand
85 void SetRefreshOnDemand( bool onDemand );
87 /// @copydoc Dali::Toolkit::EffectsView::SetPixelFormat
88 void SetPixelFormat( Pixel::Format pixelFormat );
90 /// @copydoc Dali::Toolkit::EffectsView::SetBackgroundColor(const Vector4&)
91 void SetBackgroundColor( const Vector4& color );
93 /// @copydoc Dali::Toolkit::GaussianBlurView::GetBackgroundColor
94 Vector4 GetBackgroundColor() const;
97 * Set the effect size which decides the size of filter kernel.
98 * @param[in] effectSize The effect size.
100 void SetEffectSize( int effectSize );
103 * Get the effect size.
104 * @return The effect size.
110 * Called when a property of an object of this type is set.
111 * @param[in] object The object whose property is set.
112 * @param[in] index The property index.
113 * @param[in] value The new property value.
115 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
119 * Called to retrieve a property of an object of this type.
120 * @param[in] object The object whose property is to be retrieved.
121 * @param[in] index The property index.
122 * @return The current value of the property.
124 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
126 private: // From Control
129 * @copydoc Toolkit::Internal::Control::OnInitialize()
131 virtual void OnInitialize();
134 * @copydoc CustomActorImpl::OnSizeSet( const Vector3& targetSize )
136 virtual void OnSizeSet( const Vector3& targetSize );
139 * @copydoc Toolkit::Internal::Control::OnStageConnection
141 virtual void OnStageConnection( int depth );
144 * @copydoc Toolkit::Internal::Control::OnStageDisconnection
146 virtual void OnStageDisconnection();
149 * @copydoc Toolkit::Internal::Control::OnChildAdd
151 virtual void OnChildAdd( Actor& child );
154 * @copydoc Toolkit::Internal::Control::OnChildRemove
156 virtual void OnChildRemove( Actor& child );
161 * Enable the effect when the control is set on stage
166 * Disable the effect when the control is set off stage
171 * Setup image filters
178 void AllocateResources();
186 * Create render tasks for internal jobs
188 void CreateRenderTasks();
191 * Remove render tasks
193 void RemoveRenderTasks();
196 * Refresh render tasks
198 void RefreshRenderTasks();
201 * Remove ImageFilters
203 void RemoveFilters();
208 EffectsView( const EffectsView& );
211 EffectsView& operator = ( const EffectsView& );
213 private: // attributes/properties
215 /////////////////////////////////////////////////////////////
216 // for rendering all user added children to offscreen target
217 FrameBufferImage mImageForChildren;
218 Toolkit::Visual::Base mVisualForChildren;
219 RenderTask mRenderTaskForChildren;
220 CameraActor mCameraForChildren;
221 Actor mChildrenRoot; // for creating a subtree for all user added child actors
223 /////////////////////////////////////////////////////////////
224 // background fill color
225 Vector4 mBackgroundColor;
227 /////////////////////////////////////////////////////////////
228 // for checking if we need to reallocate render targets
231 /////////////////////////////////////////////////////////////
233 FrameBufferImage mImagePostFilter;
234 Toolkit::Visual::Base mVisualPostFilter;
236 Vector<ImageFilter*> mFilters;
238 /////////////////////////////////////////////////////////////
239 // downsampling is used for the separated blur passes to get increased blur with the same number of samples and also to make rendering quicker
242 /////////////////////////////////////////////////////////////
243 Toolkit::EffectsView::EffectType mEffectType;
244 Pixel::Format mPixelFormat; ///< pixel format used by render targets
247 bool mRefreshOnDemand:1;
248 }; // class EffectsView
250 } // namespace Internal
253 // Helpers for public-api forwarding methods
255 inline Toolkit::Internal::EffectsView& GetImpl( Toolkit::EffectsView& effectsView )
257 DALI_ASSERT_ALWAYS( effectsView );
259 Dali::RefObject& handle = effectsView.GetImplementation();
261 return static_cast<Toolkit::Internal::EffectsView&>( handle );
264 inline const Toolkit::Internal::EffectsView& GetImpl( const Toolkit::EffectsView& effectsView )
266 DALI_ASSERT_ALWAYS( effectsView );
268 const Dali::RefObject& handle = effectsView.GetImplementation();
270 return static_cast<const Toolkit::Internal::EffectsView&>( handle );
273 } // namespace Toolkit
277 #endif // __DALI_TOOLKIT_INTERNAL_EFFECTS_VIEW_H__