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>
50 DirtyRect(Node* node, Render::Renderer* renderer, int frame, Rect<int>& rect)
68 bool operator<(const DirtyRect& rhs) const
72 if (renderer == rhs.renderer)
74 return frame > rhs.frame; // Most recent rects come first
78 return renderer < rhs.renderer;
83 return node < rhs.node;
88 Render::Renderer* renderer;
101 class RenderTaskList;
104 using FrameBufferPtr = IntrusivePtr<FrameBuffer>;
105 using ScenePtr = IntrusivePtr<Scene>;
108 * @brief Scene creates a "world" that can be bound to a surface for rendering.
110 class Scene : public BaseObject, public RenderTaskDefaults
115 * @copydoc Dali::Integration::Scene::New
117 static ScenePtr New(Size size, int orientation = 0);
125 * @copydoc Dali::Integration::Scene::Add
127 void Add(Actor& actor);
130 * @copydoc Dali::Integration::Scene::Remove
132 void Remove(Actor& actor);
135 * @copydoc Dali::Integration::Scene::GetSize
137 Size GetSize() const;
140 * @copydoc Dali::Integration::Scene::SetDpi
142 void SetDpi( Vector2 dpi );
145 * @copydoc Dali::Integration::Scene::GetDpi
147 Vector2 GetDpi() const;
150 * @copydoc Dali::Integration::Scene::GetRenderTaskList
152 RenderTaskList& GetRenderTaskList() const;
155 * @copydoc Dali::Integration::Scene::GetRootLayer
157 Dali::Layer GetRootLayer() const;
160 * @copydoc Dali::Integration::Scene::GetLayerCount
162 uint32_t GetLayerCount() const;
165 * @copydoc Dali::Integration::Scene::GetLayer
167 Dali::Layer GetLayer(uint32_t depth) const;
170 * Notify the surface has been resized.
172 * @param[in] width The new width of the set surface
173 * @param[in] height The new height of the set surface
175 void SurfaceResized( float width, float height );
178 * @copydoc Dali::Integration::Scene::SurfaceReplaced
180 void SurfaceReplaced();
183 * @copydoc Dali::Integration::Scene::Discard
188 * Retrieve the ordered list of on-scene layers.
189 * @return The layer-list.
191 LayerList& GetLayerList() const;
194 * Request that the depth tree is rebuilt
196 void RequestRebuildDepthTree();
199 * This function is called when an event is queued.
200 * @param[in] event A event to queue.
202 void QueueEvent( const Integration::Event& event );
205 * This function is called by Core when events are processed.
207 void ProcessEvents();
210 * Rebuilds the depth tree at the end of the event frame if
211 * it was requested this frame.
213 void RebuildDepthTree();
216 * @brief Sets the background color of the render surface.
217 * @param[in] color The new background color
219 void SetBackgroundColor( const Vector4& color );
222 * @brief Gets the background color of the render surface.
223 * @return The background color
225 Vector4 GetBackgroundColor() const;
228 * @brief Get the Scene scene graph object
230 * @return the Scene scene graph object
232 SceneGraph::Scene* GetSceneObject() const;
235 * Notify the surface has been rotated.
236 * When the device is rotated or the rotation event is received by display manager,
237 * this function will be called by window implementation.
239 * @param[in] width The width of rotated surface
240 * @param[in] height The height of rotated surface
241 * @param[in] orientation The orientation of rotated surface
243 void SurfaceRotated(float width, float height, int orientation);
246 * @brief Get surface's current orientation
248 * @return surface orientation
250 int GetSurfaceOrientation();
253 * Used by the EventProcessor to emit key event signals.
254 * @param[in] event The key event.
256 void EmitKeyEventSignal(const Dali::KeyEvent& event);
259 * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
260 * @param[in] event The key event.
261 * @return The return is true if KeyEvent is consumed, otherwise false.
263 bool EmitKeyEventGeneratedSignal(const Dali::KeyEvent& event);
266 * Emits the event processing finished signal.
268 * @see Dali::Scene::SignalEventProcessingFinished()
270 void EmitEventProcessingFinishedSignal();
273 * Emits the touched signal.
274 * @param[in] touch The touch event details.
276 void EmitTouchedSignal( const Dali::TouchEvent& touch );
279 * Used by the EventProcessor to emit wheel event signals.
280 * @param[in] event The wheel event.
282 void EmitWheelEventSignal( const Dali::WheelEvent& event );
285 * @copydoc Dali::Integration::Scene::AddFrameRenderedCallback
287 void AddFrameRenderedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
290 * @copydoc Dali::Integration::Scene::AddFramePresentedCallback
292 void AddFramePresentedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
295 * @copydoc Dali::Integration::Scene::GetFrameRenderedCallback
297 void GetFrameRenderedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
300 * @copydoc Dali::Integration::Scene::GetFramePresentedCallback
302 void GetFramePresentedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
305 * @copydoc Integration::Scene::KeyEventSignal()
307 Integration::Scene::KeyEventSignalType& KeyEventSignal();
310 * @copydoc Integration::Scene::KeyEventGeneratedSignal()
312 Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
315 * @copydoc Integration::Scene::SignalEventProcessingFinished()
317 Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
320 * @copydoc Integration::Scene::TouchedSignal()
322 Integration::Scene::TouchEventSignalType& TouchedSignal();
325 * @copydoc Integration::Scene::sWheelEventSignal()
327 Integration::Scene::WheelEventSignalType& WheelEventSignal();
330 * @brief Get ItemsDirtyRects
332 * @return the ItemsDirtyRects
334 std::vector<Dali::Internal::SceneGraph::DirtyRect>& GetItemsDirtyRects();
339 * From RenderTaskDefaults; retrieve the default root actor.
340 * @return The default root actor.
342 Actor& GetDefaultRootActor() override;
345 * From RenderTaskDefaults; retrieve the default camera actor.
346 * @return The default camera actor.
348 CameraActor& GetDefaultCameraActor() override;
356 * Second-phase constructor.
358 * @param[in] size The size of the set surface
359 * @param[in] orientation The orientation of the set surface for this scene
361 void Initialize(Size size, int orientation);
364 Scene(const Scene&) = delete;
367 Scene& operator=(const Scene& rhs) = delete;
370 * Informs the scene that the set surface has been resized or rotated.
372 * @param[in] width The width of rotated surface
373 * @param[in] height The height of rotated surface
374 * @param[in] orientation The orientation of rotated surface
376 void ChangedSurface(float width, float height, int orientation);
379 Internal::SceneGraph::Scene* mSceneObject;
385 Vector4 mBackgroundColor;
389 // Ordered list of currently on-stage layers
390 OwnerPointer<LayerList> mLayerList;
392 IntrusivePtr<CameraActor> mDefaultCamera;
394 // The list of render-tasks
395 IntrusivePtr<RenderTaskList> mRenderTaskList;
397 bool mDepthTreeDirty:1; ///< True if the depth tree needs recalculating
399 EventProcessor mEventProcessor;
401 // The Surface's orientation
402 int mSurfaceOrientation;
404 // The key event signal
405 Integration::Scene::KeyEventSignalType mKeyEventSignal;
406 Integration::Scene::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
408 // The event processing finished signal
409 Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
412 Integration::Scene::TouchEventSignalType mTouchedSignal;
414 // The wheel event signal
415 Integration::Scene::WheelEventSignalType mWheelEventSignal;
417 std::vector<Dali::Internal::SceneGraph::DirtyRect> mItemsDirtyRects;
422 // Get impl of handle
423 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
425 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
426 Dali::RefObject& object = scene.GetBaseObject();
427 return static_cast<Internal::Scene&>(object);
430 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
432 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
433 const Dali::RefObject& object = scene.GetBaseObject();
434 return static_cast<const Internal::Scene&>(object);
439 #endif // DALI_INTERNAL_SCENE_H