1 #ifndef DALI_INTERNAL_SCENE_H
2 #define DALI_INTERNAL_SCENE_H
5 * Copyright (c) 2020 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/integration-api/scene.h>
23 #include <dali/public-api/math/vector2.h>
24 #include <dali/public-api/actors/layer.h>
25 #include <dali/public-api/render-tasks/render-task-list.h>
26 #include <dali/internal/common/owner-pointer.h>
27 #include <dali/internal/event/actors/layer-impl.h>
28 #include <dali/internal/event/events/event-processor.h>
29 #include <dali/internal/event/render-tasks/render-task-defaults.h>
56 using FrameBufferPtr = IntrusivePtr<FrameBuffer>;
57 using ScenePtr = IntrusivePtr<Scene>;
60 * @brief Scene creates a "world" that can be bound to a surface for rendering.
62 class Scene : public BaseObject, public RenderTaskDefaults
67 * @copydoc Dali::Integration::Scene::New
69 static ScenePtr New( Size size );
77 * @copydoc Dali::Integration::Scene::Add
79 void Add(Actor& actor);
82 * @copydoc Dali::Integration::Scene::Remove
84 void Remove(Actor& actor);
87 * @copydoc Dali::Integration::Scene::GetSize
92 * @copydoc Dali::Integration::Scene::SetDpi
94 void SetDpi( Vector2 dpi );
97 * @copydoc Dali::Integration::Scene::GetDpi
99 Vector2 GetDpi() const;
102 * @copydoc Dali::Integration::Scene::GetRenderTaskList
104 RenderTaskList& GetRenderTaskList() const;
107 * @copydoc Dali::Integration::Scene::GetRootLayer
109 Dali::Layer GetRootLayer() const;
112 * @copydoc Dali::Integration::Scene::GetLayerCount
114 uint32_t GetLayerCount() const;
117 * @copydoc Dali::Integration::Scene::GetLayer
119 Dali::Layer GetLayer(uint32_t depth) const;
122 * Notify the surface has been resized.
124 * @param[in] width The new width of the set surface
125 * @param[in] height The new height of the set surface
126 * @param[in] orientation The orientation of the surface
127 * @param[in] forceUpdate The flag to update force
129 void SurfaceResized( float width, float height, int orientation, bool forceUpdate );
132 * @copydoc Dali::Integration::Scene::SurfaceReplaced
134 void SurfaceReplaced();
137 * @copydoc Dali::Integration::Scene::Discard
142 * Retrieve the ordered list of on-scene layers.
143 * @return The layer-list.
145 LayerList& GetLayerList() const;
148 * Request that the depth tree is rebuilt
150 void RequestRebuildDepthTree();
153 * This function is called when an event is queued.
154 * @param[in] event A event to queue.
156 void QueueEvent( const Integration::Event& event );
159 * This function is called by Core when events are processed.
161 void ProcessEvents();
164 * Rebuilds the depth tree at the end of the event frame if
165 * it was requested this frame.
167 void RebuildDepthTree();
170 * @brief Sets the background color of the render surface.
171 * @param[in] color The new background color
173 void SetBackgroundColor( const Vector4& color );
176 * @brief Gets the background color of the render surface.
177 * @return The background color
179 Vector4 GetBackgroundColor() const;
182 * @brief Get the Scene scene graph object
184 * @return the Scene scene graph object
186 SceneGraph::Scene* GetSceneObject() const;
189 * Used by the EventProcessor to emit key event signals.
190 * @param[in] event The key event.
192 void EmitKeyEventSignal(const Dali::KeyEvent& event);
195 * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
196 * @param[in] event The key event.
197 * @return The return is true if KeyEvent is consumed, otherwise false.
199 bool EmitKeyEventGeneratedSignal(const Dali::KeyEvent& event);
202 * Emits the event processing finished signal.
204 * @see Dali::Scene::SignalEventProcessingFinished()
206 void EmitEventProcessingFinishedSignal();
209 * Emits the touched signal.
210 * @param[in] touch The touch event details.
212 void EmitTouchedSignal( const Dali::TouchEvent& touch );
215 * Used by the EventProcessor to emit wheel event signals.
216 * @param[in] event The wheel event.
218 void EmitWheelEventSignal( const Dali::WheelEvent& event );
221 * @copydoc Dali::Integration::Scene::AddFrameRenderedCallback
223 void AddFrameRenderedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
226 * @copydoc Dali::Integration::Scene::AddFramePresentedCallback
228 void AddFramePresentedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
231 * @copydoc Dali::Integration::Scene::GetFrameRenderedCallback
233 void GetFrameRenderedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
236 * @copydoc Dali::Integration::Scene::GetFramePresentedCallback
238 void GetFramePresentedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
241 * @copydoc Integration::Scene::KeyEventSignal()
243 Integration::Scene::KeyEventSignalType& KeyEventSignal();
246 * @copydoc Integration::Scene::KeyEventGeneratedSignal()
248 Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
251 * @copydoc Integration::Scene::SignalEventProcessingFinished()
253 Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
256 * @copydoc Integration::Scene::TouchedSignal()
258 Integration::Scene::TouchEventSignalType& TouchedSignal();
261 * @copydoc Integration::Scene::sWheelEventSignal()
263 Integration::Scene::WheelEventSignalType& WheelEventSignal();
268 * From RenderTaskDefaults; retrieve the default root actor.
269 * @return The default root actor.
271 Actor& GetDefaultRootActor() override;
274 * From RenderTaskDefaults; retrieve the default camera actor.
275 * @return The default camera actor.
277 CameraActor& GetDefaultCameraActor() override;
285 * Second-phase constructor.
287 * @param[in] size The size of the set surface
289 void Initialize( Size size );
292 Scene(const Scene&) = delete;
295 Scene& operator=(const Scene& rhs) = delete;
298 Internal::SceneGraph::Scene* mSceneObject;
304 Vector4 mBackgroundColor;
306 // The SurfaceOrientation
307 int mSurfaceOrientation;
311 // Ordered list of currently on-stage layers
312 OwnerPointer<LayerList> mLayerList;
314 IntrusivePtr<CameraActor> mDefaultCamera;
316 // The list of render-tasks
317 IntrusivePtr<RenderTaskList> mRenderTaskList;
319 bool mDepthTreeDirty:1; ///< True if the depth tree needs recalculating
321 EventProcessor mEventProcessor;
323 // The key event signal
324 Integration::Scene::KeyEventSignalType mKeyEventSignal;
325 Integration::Scene::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
327 // The event processing finished signal
328 Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
331 Integration::Scene::TouchEventSignalType mTouchedSignal;
333 // The wheel event signal
334 Integration::Scene::WheelEventSignalType mWheelEventSignal;
339 // Get impl of handle
340 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
342 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
343 Dali::RefObject& object = scene.GetBaseObject();
344 return static_cast<Internal::Scene&>(object);
347 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
349 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
350 const Dali::RefObject& object = scene.GetBaseObject();
351 return static_cast<const Internal::Scene&>(object);
356 #endif // DALI_INTERNAL_SCENE_H