1 #ifndef DALI_INTERNAL_SCENE_H
2 #define DALI_INTERNAL_SCENE_H
5 * Copyright (c) 2023 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 windowOrientation = 0, int32_t screenOrientation = 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::GetOverlayLayer
110 Dali::Layer GetOverlayLayer();
113 * @copydoc Dali::Integration::Scene::GetLayerCount
115 uint32_t GetLayerCount() const;
118 * @copydoc Dali::Integration::Scene::GetLayer
120 Dali::Layer GetLayer(uint32_t depth) const;
123 * Notify the surface has been resized.
125 * @param[in] width The new width of the set surface
126 * @param[in] height The new height of the set surface
128 void SurfaceResized(float width, float height);
131 * @copydoc Dali::Integration::Scene::SurfaceReplaced
133 void SurfaceReplaced();
136 * @copydoc Dali::Integration::Scene::RemoveSceneObject
138 void RemoveSceneObject();
141 * @copydoc Dali::Integration::Scene::Discard
146 * Retrieve the ordered list of on-scene layers.
147 * @return The layer-list.
149 LayerList& GetLayerList() const;
152 * Request that the depth tree is rebuilt
154 void RequestRebuildDepthTree();
157 * This function is called when an event is queued.
158 * @param[in] event A event to queue.
160 void QueueEvent(const Integration::Event& event);
163 * This function is called by Core when events are processed.
165 void ProcessEvents();
168 * This function is called by Core when sending a interrupted event to a specific actor.
169 * @param[in] actor The actor on which the event should occur.
171 void SendInterruptedEvents(Dali::Internal::Actor* actor);
174 * Rebuilds the depth tree at the end of the event frame if
175 * it was requested this frame.
177 void RebuildDepthTree();
180 * @brief Sets the background color of the render surface.
181 * @param[in] color The new background color
183 void SetBackgroundColor(const Vector4& color);
186 * @brief Gets the background color of the render surface.
187 * @return The background color
189 Vector4 GetBackgroundColor() const;
192 * @brief Get the Scene scene graph object
194 * @return the Scene scene graph object
196 SceneGraph::Scene* GetSceneObject() const;
199 * Notify the surface has been rotated.
200 * When the device is rotated or the rotation event is received by display manager,
201 * this function will be called by window implementation.
203 * @param[in] width The width of rotated surface
204 * @param[in] height The height of rotated surface
205 * @param[in] windowOrientation the current window orientation
206 * @param[in] screenOrientation the current screen orientation
208 void SurfaceRotated(float width, float height, int32_t windowOrientation, int32_t screenOrientation);
211 * @copydoc Dali::Integration::Scene::SetRotationCompletedAcknowledgement
213 void SetRotationCompletedAcknowledgement();
216 * @copydoc Dali::Integration::Scene::IsRotationCompletedAcknowledgementSet
218 bool IsRotationCompletedAcknowledgementSet() const;
221 * @copydoc Dali::Integration::Scene::GetCurrentSurfaceOrientation
223 int32_t GetCurrentSurfaceOrientation() const;
226 * @copydoc Dali::Integration::Scene::GetCurrentScreenOrientation
228 int32_t GetCurrentScreenOrientation() const;
231 * @copydoc Dali::Integration::Scene::GetCurrentSurfaceRect
233 const Rect<int32_t>& GetCurrentSurfaceRect() const;
236 * @copydoc Dali::Integration::Scene::GetSurfaceRectChangedCount
238 uint32_t GetSurfaceRectChangedCount() const;
241 * @copydoc Dali::Integration::Scene::SetSurfaceRenderTarget
243 void SetSurfaceRenderTarget(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo);
246 * @copydoc Dali::Integration::Scene::SetGeometryHittestEnabled
248 void SetGeometryHittestEnabled(bool enabled);
251 * @copydoc Dali::Integration::Scene::IsGeometryHittestEnabled
253 bool IsGeometryHittestEnabled() const;
256 * @copydoc Dali::Integration::Scene::SetNativeId
258 void SetNativeId(int32_t nativeId);
261 * @copydoc Dali::Integration::Scene::GetNativeId
263 int32_t GetNativeId() const;
266 * Used by the EventProcessor to emit key event signals.
267 * @param[in] event The key event.
269 void EmitKeyEventSignal(const Dali::KeyEvent& event);
272 * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
273 * @param[in] event The key event.
274 * @return The return is true if KeyEvent is consumed, otherwise false.
276 bool EmitKeyEventGeneratedSignal(const Dali::KeyEvent& event);
279 * Used by the KeyEventProcessor to emit InterceptKeyEventSignal signals.
280 * @param[in] event The key event.
281 * @return The return is true if KeyEvent is consumed, otherwise false.
283 bool EmitInterceptKeyEventSignal(const Dali::KeyEvent& event);
286 * Emits the event processing finished signal.
288 * @see Dali::Scene::SignalEventProcessingFinished()
290 void EmitEventProcessingFinishedSignal();
293 * Emits the touched signal.
294 * @param[in] touch The touch event details.
296 void EmitTouchedSignal(const Dali::TouchEvent& touch);
299 * Used by the EventProcessor to emit wheel event signals.
300 * @param[in] event The wheel event.
302 void EmitWheelEventSignal(const Dali::WheelEvent& event);
305 * Used by the WheelEventProcessor to emit WheelEventGenerated signals.
306 * @param[in] event The wheel event.
307 * @return The return is true if WheelEvent is consumed, otherwise false.
309 bool EmitWheelEventGeneratedSignal(const Dali::WheelEvent& event);
312 * @copydoc Dali::Integration::Scene::AddFrameRenderedCallback
314 void AddFrameRenderedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
317 * @copydoc Dali::Integration::Scene::AddFramePresentedCallback
319 void AddFramePresentedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
322 * @copydoc Dali::Integration::Scene::GetFrameRenderedCallback
324 void GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
327 * @copydoc Dali::Integration::Scene::GetFramePresentedCallback
329 void GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
332 * @copydoc Dali::Integration::Scene::KeepRendering
334 void KeepRendering(float durationSeconds);
337 * @copydoc Dali::Integration::Scene::SetPartialUpdateEnabled()
339 void SetPartialUpdateEnabled(bool enabled);
342 * @copydoc Dali::Integration::Scene::IsPartialUpdateEnabled()
344 bool IsPartialUpdateEnabled() const;
347 * @copydoc Integration::Scene::KeyEventSignal()
349 Integration::Scene::KeyEventSignalType& KeyEventSignal();
352 * @copydoc Integration::Scene::KeyEventGeneratedSignal()
354 Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
357 * @copydoc Integration::Scene::InterceptKeyEventSignal()
359 Integration::Scene::KeyEventGeneratedSignalType& InterceptKeyEventSignal();
362 * @copydoc Integration::Scene::SignalEventProcessingFinished()
364 Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
367 * @copydoc Integration::Scene::TouchedSignal()
369 Integration::Scene::TouchEventSignalType& TouchedSignal();
372 * @copydoc Integration::Scene::sWheelEventSignal()
374 Integration::Scene::WheelEventSignalType& WheelEventSignal();
377 * @copydoc Integration::Scene::WheelEventGeneratedSignal()
379 Integration::Scene::WheelEventGeneratedSignalType& WheelEventGeneratedSignal();
383 * From RenderTaskDefaults; retrieve the default root actor.
384 * @return The default root actor.
386 Actor& GetDefaultRootActor() override;
389 * From RenderTaskDefaults; retrieve the default camera actor.
390 * @return The default camera actor.
392 CameraActor& GetDefaultCameraActor() const override;
399 * Second-phase constructor.
401 * @param[in] size The size of the set surface
402 * @param[in] windowOrientation The rotated angle of the set surface for this scene
403 * @param[in] screenOrientation The rotated angle of the screen
405 void Initialize(Size size, int32_t windowOrientation, int32_t screenOrientation);
408 Scene(const Scene&) = delete;
411 Scene& operator=(const Scene& rhs) = delete;
414 * Informs the scene that the set surface has been resized or rotated.
416 * @param[in] width The width of rotated surface
417 * @param[in] height The height of rotated surface
418 * @param[in] windowOrientation the current window orientation
419 * @param[in] screenOrientation the current screen orientation
421 void ChangedSurface(float width, float height, int32_t windowOrientation, int32_t screenOrientation);
424 Internal::SceneGraph::Scene* mSceneObject;
430 Vector4 mBackgroundColor;
434 LayerPtr mOverlayLayer;
436 // Ordered list of currently on-stage layers
437 OwnerPointer<LayerList> mLayerList;
439 IntrusivePtr<CameraActor> mDefaultCamera;
441 // The list of render-tasks
442 IntrusivePtr<RenderTaskList> mRenderTaskList;
444 bool mDepthTreeDirty : 1; ///< True if the depth tree needs recalculating
445 bool mPartialUpdateEnabled : 1; ///< True if the partial update is enabled
446 bool mGeometryHittest : 1; ///< True if the geometry hittest is enabled
448 EventProcessor mEventProcessor;
450 // The Surface's orientation
451 int32_t mSurfaceOrientation;
453 // The Screen's orientation
454 int32_t mScreenOrientation;
456 // The native window id
459 // The key event signal
460 Integration::Scene::KeyEventSignalType mKeyEventSignal;
461 Integration::Scene::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
462 Integration::Scene::KeyEventGeneratedSignalType mInterceptKeyEventSignal;
464 // The event processing finished signal
465 Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
468 Integration::Scene::TouchEventSignalType mTouchedSignal;
470 // The wheel event signal
471 Integration::Scene::WheelEventSignalType mWheelEventSignal;
472 Integration::Scene::WheelEventGeneratedSignalType mWheelEventGeneratedSignal;
475 } // namespace Internal
477 // Get impl of handle
478 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
480 DALI_ASSERT_ALWAYS(scene && "Scene handle is empty");
481 Dali::RefObject& object = scene.GetBaseObject();
482 return static_cast<Internal::Scene&>(object);
485 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
487 DALI_ASSERT_ALWAYS(scene && "Scene handle is empty");
488 const Dali::RefObject& object = scene.GetBaseObject();
489 return static_cast<const Internal::Scene&>(object);
494 #endif // DALI_INTERNAL_SCENE_H