1 #ifndef DALI_TOOLKIT_INTERNAL_EFFECTS_VIEW_H
2 #define DALI_TOOLKIT_INTERNAL_EFFECTS_VIEW_H
5 * Copyright (c) 2021 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>
25 #include <dali/public-api/rendering/frame-buffer.h>
26 #include <dali/public-api/rendering/renderer.h>
29 #include <dali-toolkit/devel-api/controls/effects-view/effects-view.h>
30 #include <dali-toolkit/public-api/controls/control-impl.h>
38 class GaussianBlurView;
42 * EffectsView implementation class
43 * @copydoc Dali::Toolkit::EffectsView
45 class EffectsView : public Control
48 /// @copydoc Dali::Toolkit::EffectsView New()
49 static Toolkit::EffectsView New();
52 * Construct a new EffectsView.
53 * @copydoc Toolkit::EffectsView New()
58 * A reference counted object may only be deleted by calling Unreference()
60 virtual ~EffectsView();
63 /// @copydoc Dali::Toolkit::EffectsView::SetType
64 void SetType(Toolkit::EffectsView::EffectType type);
66 /// @copydoc Dali::Toolkit::EffectsView::GetType
67 Toolkit::EffectsView::EffectType GetType() const;
69 /// @copydoc Dali::Toolkit::EffectsView::Refresh
72 /// @copydoc Dali::Toolkit::EffectsView::SetRefreshOnDemand
73 void SetRefreshOnDemand(bool onDemand);
75 /// @copydoc Dali::Toolkit::EffectsView::SetPixelFormat
76 void SetPixelFormat(Pixel::Format pixelFormat);
78 /// @copydoc Dali::Toolkit::EffectsView::SetBackgroundColor(const Vector4&)
79 void SetBackgroundColor(const Vector4& color);
81 /// @copydoc Dali::Toolkit::GaussianBlurView::GetBackgroundColor
82 Vector4 GetBackgroundColor() const;
85 * Set the effect size which decides the size of filter kernel.
86 * @param[in] effectSize The effect size.
88 void SetEffectSize(int effectSize);
91 * Get the effect size.
92 * @return The effect size.
98 * Called when a property of an object of this type is set.
99 * @param[in] object The object whose property is set.
100 * @param[in] index The property index.
101 * @param[in] value The new property value.
103 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
106 * Called to retrieve a property of an object of this type.
107 * @param[in] object The object whose property is to be retrieved.
108 * @param[in] index The property index.
109 * @return The current value of the property.
111 static Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex);
113 private: // From Control
115 * @copydoc Toolkit::Internal::Control::OnInitialize()
117 void OnInitialize() override;
120 * @copydoc CustomActorImpl::OnSizeSet( const Vector3& targetSize )
122 void OnSizeSet(const Vector3& targetSize) override;
125 * @copydoc Toolkit::Internal::Control::OnSceneConnection
127 void OnSceneConnection(int depth) override;
130 * @copydoc Toolkit::Internal::Control::OnSceneDisconnection
132 void OnSceneDisconnection() override;
135 * @copydoc Toolkit::Internal::Control::OnChildAdd
137 void OnChildAdd(Actor& child) override;
140 * @copydoc Toolkit::Internal::Control::OnChildRemove
142 void OnChildRemove(Actor& child) override;
146 * Enable the effect when the control is set on stage
151 * Disable the effect when the control is set off stage
156 * Setup image filters
163 void AllocateResources();
171 * Create render tasks for internal jobs
173 void CreateRenderTasks();
176 * Remove render tasks
178 void RemoveRenderTasks();
181 * Refresh render tasks
183 void RefreshRenderTasks();
186 * Remove ImageFilters
188 void RemoveFilters();
192 EffectsView(const EffectsView&);
195 EffectsView& operator=(const EffectsView&);
197 private: // attributes/properties
198 /////////////////////////////////////////////////////////////
199 // for rendering all user added children to offscreen target
200 FrameBuffer mFrameBufferForChildren;
201 Renderer mRendererForChildren;
202 RenderTask mRenderTaskForChildren;
203 CameraActor mCameraForChildren;
204 Actor mChildrenRoot; // for creating a subtree for all user added child actors
206 /////////////////////////////////////////////////////////////
207 // background fill color
208 Vector4 mBackgroundColor;
210 /////////////////////////////////////////////////////////////
211 // for checking if we need to reallocate render targets
214 /////////////////////////////////////////////////////////////
216 FrameBuffer mFrameBufferPostFilter;
217 Renderer mRendererPostFilter;
219 Vector<ImageFilter*> mFilters;
221 /////////////////////////////////////////////////////////////
222 // downsampling is used for the separated blur passes to get increased blur with the same number of samples and also to make rendering quicker
225 /////////////////////////////////////////////////////////////
226 Toolkit::EffectsView::EffectType mEffectType;
227 Pixel::Format mPixelFormat; ///< pixel format used by render targets
230 bool mRefreshOnDemand : 1;
231 }; // class EffectsView
233 } // namespace Internal
235 // Helpers for public-api forwarding methods
237 inline Toolkit::Internal::EffectsView& GetImpl(Toolkit::EffectsView& effectsView)
239 DALI_ASSERT_ALWAYS(effectsView);
241 Dali::RefObject& handle = effectsView.GetImplementation();
243 return static_cast<Toolkit::Internal::EffectsView&>(handle);
246 inline const Toolkit::Internal::EffectsView& GetImpl(const Toolkit::EffectsView& effectsView)
248 DALI_ASSERT_ALWAYS(effectsView);
250 const Dali::RefObject& handle = effectsView.GetImplementation();
252 return static_cast<const Toolkit::Internal::EffectsView&>(handle);
255 } // namespace Toolkit
259 #endif // DALI_TOOLKIT_INTERNAL_EFFECTS_VIEW_H