1 #ifndef DALI_INTERNAL_SCENE_H
2 #define DALI_INTERNAL_SCENE_H
5 * Copyright (c) 2022 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/internal/common/owner-pointer.h>
24 #include <dali/internal/event/actors/layer-impl.h>
25 #include <dali/internal/event/events/event-processor.h>
26 #include <dali/internal/event/render-tasks/render-task-defaults.h>
27 #include <dali/public-api/actors/layer.h>
28 #include <dali/public-api/math/vector2.h>
29 #include <dali/public-api/render-tasks/render-task-list.h>
44 } // namespace SceneGraph
53 using FrameBufferPtr = IntrusivePtr<FrameBuffer>;
54 using ScenePtr = IntrusivePtr<Scene>;
57 * @brief Scene creates a "world" that can be bound to a surface for rendering.
59 class Scene : public BaseObject, public RenderTaskDefaults
63 * @copydoc Dali::Integration::Scene::New
65 static ScenePtr New(Size size, int32_t orientation = 0);
73 * @copydoc Dali::Integration::Scene::Add
75 void Add(Actor& actor);
78 * @copydoc Dali::Integration::Scene::Remove
80 void Remove(Actor& actor);
83 * @copydoc Dali::Integration::Scene::GetSize
88 * @copydoc Dali::Integration::Scene::SetDpi
90 void SetDpi(Vector2 dpi);
93 * @copydoc Dali::Integration::Scene::GetDpi
95 Vector2 GetDpi() const;
98 * @copydoc Dali::Integration::Scene::GetRenderTaskList
100 RenderTaskList& GetRenderTaskList() const;
103 * @copydoc Dali::Integration::Scene::GetRootLayer
105 Dali::Layer GetRootLayer() const;
108 * @copydoc Dali::Integration::Scene::GetLayerCount
110 uint32_t GetLayerCount() const;
113 * @copydoc Dali::Integration::Scene::GetLayer
115 Dali::Layer GetLayer(uint32_t depth) const;
118 * Notify the surface has been resized.
120 * @param[in] width The new width of the set surface
121 * @param[in] height The new height of the set surface
123 void SurfaceResized(float width, float height);
126 * @copydoc Dali::Integration::Scene::SurfaceReplaced
128 void SurfaceReplaced();
131 * @copydoc Dali::Integration::Scene::Discard
136 * Retrieve the ordered list of on-scene layers.
137 * @return The layer-list.
139 LayerList& GetLayerList() const;
142 * Request that the depth tree is rebuilt
144 void RequestRebuildDepthTree();
147 * This function is called when an event is queued.
148 * @param[in] event A event to queue.
150 void QueueEvent(const Integration::Event& event);
153 * This function is called by Core when events are processed.
155 void ProcessEvents();
158 * Rebuilds the depth tree at the end of the event frame if
159 * it was requested this frame.
161 void RebuildDepthTree();
164 * @brief Sets the background color of the render surface.
165 * @param[in] color The new background color
167 void SetBackgroundColor(const Vector4& color);
170 * @brief Gets the background color of the render surface.
171 * @return The background color
173 Vector4 GetBackgroundColor() const;
176 * @brief Get the Scene scene graph object
178 * @return the Scene scene graph object
180 SceneGraph::Scene* GetSceneObject() const;
183 * Notify the surface has been rotated.
184 * When the device is rotated or the rotation event is received by display manager,
185 * this function will be called by window implementation.
187 * @param[in] width The width of rotated surface
188 * @param[in] height The height of rotated surface
189 * @param[in] orientation The orientation of rotated surface
191 void SurfaceRotated(float width, float height, int32_t orientation);
194 * @copydoc Dali::Integration::Scene::SetRotationCompletedAcknowledgement
196 void SetRotationCompletedAcknowledgement();
199 * @copydoc Dali::Integration::Scene::IsRotationCompletedAcknowledgementSet
201 bool IsRotationCompletedAcknowledgementSet() const;
204 * @copydoc Dali::Integration::Scene::GetCurrentSurfaceOrientation
206 int32_t GetCurrentSurfaceOrientation() const;
209 * @copydoc Dali::Integration::Scene::GetCurrentSurfaceRect
211 const Rect<int32_t>& GetCurrentSurfaceRect() const;
214 * @copydoc Dali::Integration::Scene::IsSurfaceRectChanged
216 bool IsSurfaceRectChanged() const;
219 * @copydoc Dali::Integration::Scene::SetSurfaceRenderTarget
221 void SetSurfaceRenderTarget(Graphics::RenderTarget* renderTarget);
224 * Used by the EventProcessor to emit key event signals.
225 * @param[in] event The key event.
227 void EmitKeyEventSignal(const Dali::KeyEvent& event);
230 * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
231 * @param[in] event The key event.
232 * @return The return is true if KeyEvent is consumed, otherwise false.
234 bool EmitKeyEventGeneratedSignal(const Dali::KeyEvent& event);
237 * Used by the KeyEventProcessor to emit InterceptKeyEventSignal signals.
238 * @param[in] event The key event.
239 * @return The return is true if KeyEvent is consumed, otherwise false.
241 bool EmitInterceptKeyEventSignal(const Dali::KeyEvent& event);
244 * Emits the event processing finished signal.
246 * @see Dali::Scene::SignalEventProcessingFinished()
248 void EmitEventProcessingFinishedSignal();
251 * Emits the touched signal.
252 * @param[in] touch The touch event details.
254 void EmitTouchedSignal(const Dali::TouchEvent& touch);
257 * Used by the EventProcessor to emit wheel event signals.
258 * @param[in] event The wheel event.
260 void EmitWheelEventSignal(const Dali::WheelEvent& event);
263 * Used by the WheelEventProcessor to emit WheelEventGenerated signals.
264 * @param[in] event The wheel event.
265 * @return The return is true if WheelEvent is consumed, otherwise false.
267 bool EmitWheelEventGeneratedSignal(const Dali::WheelEvent& event);
270 * @copydoc Dali::Integration::Scene::AddFrameRenderedCallback
272 void AddFrameRenderedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
275 * @copydoc Dali::Integration::Scene::AddFramePresentedCallback
277 void AddFramePresentedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
280 * @copydoc Dali::Integration::Scene::GetFrameRenderedCallback
282 void GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
285 * @copydoc Dali::Integration::Scene::GetFramePresentedCallback
287 void GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
290 * @copydoc Integration::Scene::KeyEventSignal()
292 Integration::Scene::KeyEventSignalType& KeyEventSignal();
295 * @copydoc Integration::Scene::KeyEventGeneratedSignal()
297 Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
300 * @copydoc Integration::Scene::InterceptKeyEventSignal()
302 Integration::Scene::KeyEventGeneratedSignalType& InterceptKeyEventSignal();
305 * @copydoc Integration::Scene::SignalEventProcessingFinished()
307 Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
310 * @copydoc Integration::Scene::TouchedSignal()
312 Integration::Scene::TouchEventSignalType& TouchedSignal();
315 * @copydoc Integration::Scene::sWheelEventSignal()
317 Integration::Scene::WheelEventSignalType& WheelEventSignal();
320 * @copydoc Integration::Scene::WheelEventGeneratedSignal()
322 Integration::Scene::WheelEventGeneratedSignalType& WheelEventGeneratedSignal();
326 * From RenderTaskDefaults; retrieve the default root actor.
327 * @return The default root actor.
329 Actor& GetDefaultRootActor() override;
332 * From RenderTaskDefaults; retrieve the default camera actor.
333 * @return The default camera actor.
335 CameraActor& GetDefaultCameraActor() const override;
342 * Second-phase constructor.
344 * @param[in] size The size of the set surface
345 * @param[in] orientation The orientation of the set surface for this scene
347 void Initialize(Size size, int32_t orientation);
350 Scene(const Scene&) = delete;
353 Scene& operator=(const Scene& rhs) = delete;
356 * Informs the scene that the set surface has been resized or rotated.
358 * @param[in] width The width of rotated surface
359 * @param[in] height The height of rotated surface
360 * @param[in] orientation The orientation of rotated surface
362 void ChangedSurface(float width, float height, int32_t orientation);
365 Internal::SceneGraph::Scene* mSceneObject;
371 Vector4 mBackgroundColor;
375 // Ordered list of currently on-stage layers
376 OwnerPointer<LayerList> mLayerList;
378 IntrusivePtr<CameraActor> mDefaultCamera;
380 // The list of render-tasks
381 IntrusivePtr<RenderTaskList> mRenderTaskList;
383 bool mDepthTreeDirty : 1; ///< True if the depth tree needs recalculating
385 EventProcessor mEventProcessor;
387 // The Surface's orientation
388 int32_t mSurfaceOrientation;
390 // The key event signal
391 Integration::Scene::KeyEventSignalType mKeyEventSignal;
392 Integration::Scene::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
393 Integration::Scene::KeyEventGeneratedSignalType mInterceptKeyEventSignal;
395 // The event processing finished signal
396 Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
399 Integration::Scene::TouchEventSignalType mTouchedSignal;
401 // The wheel event signal
402 Integration::Scene::WheelEventSignalType mWheelEventSignal;
403 Integration::Scene::WheelEventGeneratedSignalType mWheelEventGeneratedSignal;
406 } // namespace Internal
408 // Get impl of handle
409 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
411 DALI_ASSERT_ALWAYS(scene && "Scene handle is empty");
412 Dali::RefObject& object = scene.GetBaseObject();
413 return static_cast<Internal::Scene&>(object);
416 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
418 DALI_ASSERT_ALWAYS(scene && "Scene handle is empty");
419 const Dali::RefObject& object = scene.GetBaseObject();
420 return static_cast<const Internal::Scene&>(object);
425 #endif // DALI_INTERNAL_SCENE_H