1 #ifndef DALI_INTERNAL_SCENE_H
2 #define DALI_INTERNAL_SCENE_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/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>
41 //@todo Break this dependence somehow.
53 DirtyRect(Node* node, Render::Renderer* renderer, int32_t frame, Rect<int>& rect)
71 bool operator<(const DirtyRect& rhs) const
75 if(renderer == rhs.renderer)
77 return frame > rhs.frame; // Most recent rects come first
81 return renderer < rhs.renderer;
86 return node < rhs.node;
91 Render::Renderer* renderer;
98 } // namespace SceneGraph
100 class EventProcessor;
104 class RenderTaskList;
107 using FrameBufferPtr = IntrusivePtr<FrameBuffer>;
108 using ScenePtr = IntrusivePtr<Scene>;
111 * @brief Scene creates a "world" that can be bound to a surface for rendering.
113 class Scene : public BaseObject, public RenderTaskDefaults
117 * @copydoc Dali::Integration::Scene::New
119 static ScenePtr New(Size size, int32_t orientation = 0);
127 * @copydoc Dali::Integration::Scene::Add
129 void Add(Actor& actor);
132 * @copydoc Dali::Integration::Scene::Remove
134 void Remove(Actor& actor);
137 * @copydoc Dali::Integration::Scene::GetSize
139 Size GetSize() const;
142 * @copydoc Dali::Integration::Scene::SetDpi
144 void SetDpi(Vector2 dpi);
147 * @copydoc Dali::Integration::Scene::GetDpi
149 Vector2 GetDpi() const;
152 * @copydoc Dali::Integration::Scene::GetRenderTaskList
154 RenderTaskList& GetRenderTaskList() const;
157 * @copydoc Dali::Integration::Scene::GetRootLayer
159 Dali::Layer GetRootLayer() const;
162 * @copydoc Dali::Integration::Scene::GetLayerCount
164 uint32_t GetLayerCount() const;
167 * @copydoc Dali::Integration::Scene::GetLayer
169 Dali::Layer GetLayer(uint32_t depth) const;
172 * Notify the surface has been resized.
174 * @param[in] width The new width of the set surface
175 * @param[in] height The new height of the set surface
177 void SurfaceResized(float width, float height);
180 * @copydoc Dali::Integration::Scene::SurfaceReplaced
182 void SurfaceReplaced();
185 * @copydoc Dali::Integration::Scene::Discard
190 * Retrieve the ordered list of on-scene layers.
191 * @return The layer-list.
193 LayerList& GetLayerList() const;
196 * Request that the depth tree is rebuilt
198 void RequestRebuildDepthTree();
201 * This function is called when an event is queued.
202 * @param[in] event A event to queue.
204 void QueueEvent(const Integration::Event& event);
207 * This function is called by Core when events are processed.
209 void ProcessEvents();
212 * Rebuilds the depth tree at the end of the event frame if
213 * it was requested this frame.
215 void RebuildDepthTree();
218 * @brief Sets the background color of the render surface.
219 * @param[in] color The new background color
221 void SetBackgroundColor(const Vector4& color);
224 * @brief Gets the background color of the render surface.
225 * @return The background color
227 Vector4 GetBackgroundColor() const;
230 * @brief Get the Scene scene graph object
232 * @return the Scene scene graph object
234 SceneGraph::Scene* GetSceneObject() const;
237 * Notify the surface has been rotated.
238 * When the device is rotated or the rotation event is received by display manager,
239 * this function will be called by window implementation.
241 * @param[in] width The width of rotated surface
242 * @param[in] height The height of rotated surface
243 * @param[in] orientation The orientation of rotated surface
245 void SurfaceRotated(float width, float height, int32_t orientation);
248 * @copydoc Dali::Integration::Scene::SetRotationCompletedAcknowledgement
250 void SetRotationCompletedAcknowledgement();
253 * @copydoc Dali::Integration::Scene::IsRotationCompletedAcknowledgementSet
255 bool IsRotationCompletedAcknowledgementSet() const;
258 * @copydoc Dali::Integration::Scene::GetCurrentSurfaceOrientation
260 int32_t GetCurrentSurfaceOrientation() const;
263 * @copydoc Dali::Integration::Scene::GetCurrentSurfaceRect
265 const Rect<int32_t>& GetCurrentSurfaceRect() const;
268 * @copydoc Dali::Integration::Scene::IsSurfaceRectChanged
270 bool IsSurfaceRectChanged() const;
273 * @copydoc Dali::Integration::Scene::SetSurfaceRenderTarget
275 void SetSurfaceRenderTarget(Graphics::RenderTarget* renderTarget);
278 * Used by the EventProcessor to emit key event signals.
279 * @param[in] event The key event.
281 void EmitKeyEventSignal(const Dali::KeyEvent& event);
284 * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
285 * @param[in] event The key event.
286 * @return The return is true if KeyEvent is consumed, otherwise false.
288 bool EmitKeyEventGeneratedSignal(const Dali::KeyEvent& event);
291 * Emits the event processing finished signal.
293 * @see Dali::Scene::SignalEventProcessingFinished()
295 void EmitEventProcessingFinishedSignal();
298 * Emits the touched signal.
299 * @param[in] touch The touch event details.
301 void EmitTouchedSignal(const Dali::TouchEvent& touch);
304 * Used by the EventProcessor to emit wheel event signals.
305 * @param[in] event The wheel event.
307 void EmitWheelEventSignal(const Dali::WheelEvent& event);
310 * @copydoc Dali::Integration::Scene::AddFrameRenderedCallback
312 void AddFrameRenderedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
315 * @copydoc Dali::Integration::Scene::AddFramePresentedCallback
317 void AddFramePresentedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
320 * @copydoc Dali::Integration::Scene::GetFrameRenderedCallback
322 void GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
325 * @copydoc Dali::Integration::Scene::GetFramePresentedCallback
327 void GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
330 * @copydoc Integration::Scene::KeyEventSignal()
332 Integration::Scene::KeyEventSignalType& KeyEventSignal();
335 * @copydoc Integration::Scene::KeyEventGeneratedSignal()
337 Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
340 * @copydoc Integration::Scene::SignalEventProcessingFinished()
342 Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
345 * @copydoc Integration::Scene::TouchedSignal()
347 Integration::Scene::TouchEventSignalType& TouchedSignal();
350 * @copydoc Integration::Scene::sWheelEventSignal()
352 Integration::Scene::WheelEventSignalType& WheelEventSignal();
355 * @brief Get ItemsDirtyRects
357 * @return the ItemsDirtyRects
359 std::vector<Dali::Internal::SceneGraph::DirtyRect>& GetItemsDirtyRects();
363 * From RenderTaskDefaults; retrieve the default root actor.
364 * @return The default root actor.
366 Actor& GetDefaultRootActor() override;
369 * From RenderTaskDefaults; retrieve the default camera actor.
370 * @return The default camera actor.
372 CameraActor& GetDefaultCameraActor() const override;
379 * Second-phase constructor.
381 * @param[in] size The size of the set surface
382 * @param[in] orientation The orientation of the set surface for this scene
384 void Initialize(Size size, int32_t orientation);
387 Scene(const Scene&) = delete;
390 Scene& operator=(const Scene& rhs) = delete;
393 * Informs the scene that the set surface has been resized or rotated.
395 * @param[in] width The width of rotated surface
396 * @param[in] height The height of rotated surface
397 * @param[in] orientation The orientation of rotated surface
399 void ChangedSurface(float width, float height, int32_t orientation);
402 Internal::SceneGraph::Scene* mSceneObject;
408 Vector4 mBackgroundColor;
412 // Ordered list of currently on-stage layers
413 OwnerPointer<LayerList> mLayerList;
415 IntrusivePtr<CameraActor> mDefaultCamera;
417 // The list of render-tasks
418 IntrusivePtr<RenderTaskList> mRenderTaskList;
420 bool mDepthTreeDirty : 1; ///< True if the depth tree needs recalculating
422 EventProcessor mEventProcessor;
424 // The Surface's orientation
425 int32_t mSurfaceOrientation;
427 // The key event signal
428 Integration::Scene::KeyEventSignalType mKeyEventSignal;
429 Integration::Scene::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
431 // The event processing finished signal
432 Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
435 Integration::Scene::TouchEventSignalType mTouchedSignal;
437 // The wheel event signal
438 Integration::Scene::WheelEventSignalType mWheelEventSignal;
440 std::vector<Dali::Internal::SceneGraph::DirtyRect> mItemsDirtyRects;
443 } // namespace Internal
445 // Get impl of handle
446 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
448 DALI_ASSERT_ALWAYS(scene && "Scene handle is empty");
449 Dali::RefObject& object = scene.GetBaseObject();
450 return static_cast<Internal::Scene&>(object);
453 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
455 DALI_ASSERT_ALWAYS(scene && "Scene handle is empty");
456 const Dali::RefObject& object = scene.GetBaseObject();
457 return static_cast<const Internal::Scene&>(object);
462 #endif // DALI_INTERNAL_SCENE_H