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 );
120 * @copydoc Dali::Integration::Scene::New
122 static ScenePtr New( Size size, int orientation );
130 * @copydoc Dali::Integration::Scene::Add
132 void Add(Actor& actor);
135 * @copydoc Dali::Integration::Scene::Remove
137 void Remove(Actor& actor);
140 * @copydoc Dali::Integration::Scene::GetSize
142 Size GetSize() const;
145 * @copydoc Dali::Integration::Scene::SetDpi
147 void SetDpi( Vector2 dpi );
150 * @copydoc Dali::Integration::Scene::GetDpi
152 Vector2 GetDpi() const;
155 * @copydoc Dali::Integration::Scene::GetRenderTaskList
157 RenderTaskList& GetRenderTaskList() const;
160 * @copydoc Dali::Integration::Scene::GetRootLayer
162 Dali::Layer GetRootLayer() const;
165 * @copydoc Dali::Integration::Scene::GetLayerCount
167 uint32_t GetLayerCount() const;
170 * @copydoc Dali::Integration::Scene::GetLayer
172 Dali::Layer GetLayer(uint32_t depth) const;
175 * Notify the surface has been resized.
177 * @param[in] width The new width of the set surface
178 * @param[in] height The new height of the set surface
180 void SurfaceResized( float width, float height );
183 * @copydoc Dali::Integration::Scene::SurfaceReplaced
185 void SurfaceReplaced();
188 * @copydoc Dali::Integration::Scene::Discard
193 * Retrieve the ordered list of on-scene layers.
194 * @return The layer-list.
196 LayerList& GetLayerList() const;
199 * Request that the depth tree is rebuilt
201 void RequestRebuildDepthTree();
204 * This function is called when an event is queued.
205 * @param[in] event A event to queue.
207 void QueueEvent( const Integration::Event& event );
210 * This function is called by Core when events are processed.
212 void ProcessEvents();
215 * Rebuilds the depth tree at the end of the event frame if
216 * it was requested this frame.
218 void RebuildDepthTree();
221 * @brief Sets the background color of the render surface.
222 * @param[in] color The new background color
224 void SetBackgroundColor( const Vector4& color );
227 * @brief Gets the background color of the render surface.
228 * @return The background color
230 Vector4 GetBackgroundColor() const;
233 * @brief Get the Scene scene graph object
235 * @return the Scene scene graph object
237 SceneGraph::Scene* GetSceneObject() const;
240 * Used by the EventProcessor to emit key event signals.
241 * @param[in] event The key event.
243 void EmitKeyEventSignal(const Dali::KeyEvent& event);
246 * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
247 * @param[in] event The key event.
248 * @return The return is true if KeyEvent is consumed, otherwise false.
250 bool EmitKeyEventGeneratedSignal(const Dali::KeyEvent& event);
253 * Emits the event processing finished signal.
255 * @see Dali::Scene::SignalEventProcessingFinished()
257 void EmitEventProcessingFinishedSignal();
260 * Emits the touched signal.
261 * @param[in] touch The touch event details.
263 void EmitTouchedSignal( const Dali::TouchEvent& touch );
266 * Used by the EventProcessor to emit wheel event signals.
267 * @param[in] event The wheel event.
269 void EmitWheelEventSignal( const Dali::WheelEvent& event );
272 * @copydoc Dali::Integration::Scene::AddFrameRenderedCallback
274 void AddFrameRenderedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
277 * @copydoc Dali::Integration::Scene::AddFramePresentedCallback
279 void AddFramePresentedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
282 * @copydoc Dali::Integration::Scene::GetFrameRenderedCallback
284 void GetFrameRenderedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
287 * @copydoc Dali::Integration::Scene::GetFramePresentedCallback
289 void GetFramePresentedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
292 * @copydoc Integration::Scene::KeyEventSignal()
294 Integration::Scene::KeyEventSignalType& KeyEventSignal();
297 * @copydoc Integration::Scene::KeyEventGeneratedSignal()
299 Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
302 * @copydoc Integration::Scene::SignalEventProcessingFinished()
304 Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
307 * @copydoc Integration::Scene::TouchedSignal()
309 Integration::Scene::TouchEventSignalType& TouchedSignal();
312 * @copydoc Integration::Scene::sWheelEventSignal()
314 Integration::Scene::WheelEventSignalType& WheelEventSignal();
317 * @brief Get ItemsDirtyRects
319 * @return the ItemsDirtyRects
321 std::vector<Dali::Internal::SceneGraph::DirtyRect>& GetItemsDirtyRects();
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() override;
343 * Second-phase constructor.
345 * @param[in] size The size of the set surface
346 * @param[in] orientation The orientation of the set surface for this scene
348 void Initialize( Size size, int orientation );
351 Scene(const Scene&) = delete;
354 Scene& operator=(const Scene& rhs) = delete;
357 Internal::SceneGraph::Scene* mSceneObject;
363 Vector4 mBackgroundColor;
367 // Ordered list of currently on-stage layers
368 OwnerPointer<LayerList> mLayerList;
370 IntrusivePtr<CameraActor> mDefaultCamera;
372 // The list of render-tasks
373 IntrusivePtr<RenderTaskList> mRenderTaskList;
375 bool mDepthTreeDirty:1; ///< True if the depth tree needs recalculating
377 EventProcessor mEventProcessor;
379 // The key event signal
380 Integration::Scene::KeyEventSignalType mKeyEventSignal;
381 Integration::Scene::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
383 // The event processing finished signal
384 Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
387 Integration::Scene::TouchEventSignalType mTouchedSignal;
389 // The wheel event signal
390 Integration::Scene::WheelEventSignalType mWheelEventSignal;
392 std::vector<Dali::Internal::SceneGraph::DirtyRect> mItemsDirtyRects;
397 // Get impl of handle
398 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
400 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
401 Dali::RefObject& object = scene.GetBaseObject();
402 return static_cast<Internal::Scene&>(object);
405 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
407 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
408 const Dali::RefObject& object = scene.GetBaseObject();
409 return static_cast<const Internal::Scene&>(object);
414 #endif // DALI_INTERNAL_SCENE_H