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
179 * @param[in] orientation The orientation of the surface
180 * @param[in] forceUpdate The flag to update force
182 void SurfaceResized( float width, float height, int orientation, bool forceUpdate );
185 * @copydoc Dali::Integration::Scene::SurfaceReplaced
187 void SurfaceReplaced();
190 * @copydoc Dali::Integration::Scene::Discard
195 * Retrieve the ordered list of on-scene layers.
196 * @return The layer-list.
198 LayerList& GetLayerList() const;
201 * Request that the depth tree is rebuilt
203 void RequestRebuildDepthTree();
206 * This function is called when an event is queued.
207 * @param[in] event A event to queue.
209 void QueueEvent( const Integration::Event& event );
212 * This function is called by Core when events are processed.
214 void ProcessEvents();
217 * Rebuilds the depth tree at the end of the event frame if
218 * it was requested this frame.
220 void RebuildDepthTree();
223 * @brief Sets the background color of the render surface.
224 * @param[in] color The new background color
226 void SetBackgroundColor( const Vector4& color );
229 * @brief Gets the background color of the render surface.
230 * @return The background color
232 Vector4 GetBackgroundColor() const;
235 * @brief Get the Scene scene graph object
237 * @return the Scene scene graph object
239 SceneGraph::Scene* GetSceneObject() const;
242 * Used by the EventProcessor to emit key event signals.
243 * @param[in] event The key event.
245 void EmitKeyEventSignal(const Dali::KeyEvent& event);
248 * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
249 * @param[in] event The key event.
250 * @return The return is true if KeyEvent is consumed, otherwise false.
252 bool EmitKeyEventGeneratedSignal(const Dali::KeyEvent& event);
255 * Emits the event processing finished signal.
257 * @see Dali::Scene::SignalEventProcessingFinished()
259 void EmitEventProcessingFinishedSignal();
262 * Emits the touched signal.
263 * @param[in] touch The touch event details.
265 void EmitTouchedSignal( const Dali::TouchEvent& touch );
268 * Used by the EventProcessor to emit wheel event signals.
269 * @param[in] event The wheel event.
271 void EmitWheelEventSignal( const Dali::WheelEvent& event );
274 * @copydoc Dali::Integration::Scene::AddFrameRenderedCallback
276 void AddFrameRenderedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
279 * @copydoc Dali::Integration::Scene::AddFramePresentedCallback
281 void AddFramePresentedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
284 * @copydoc Dali::Integration::Scene::GetFrameRenderedCallback
286 void GetFrameRenderedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
289 * @copydoc Dali::Integration::Scene::GetFramePresentedCallback
291 void GetFramePresentedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
294 * @copydoc Integration::Scene::KeyEventSignal()
296 Integration::Scene::KeyEventSignalType& KeyEventSignal();
299 * @copydoc Integration::Scene::KeyEventGeneratedSignal()
301 Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
304 * @copydoc Integration::Scene::SignalEventProcessingFinished()
306 Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
309 * @copydoc Integration::Scene::TouchedSignal()
311 Integration::Scene::TouchEventSignalType& TouchedSignal();
314 * @copydoc Integration::Scene::sWheelEventSignal()
316 Integration::Scene::WheelEventSignalType& WheelEventSignal();
319 * @brief Get ItemsDirtyRects
321 * @return the ItemsDirtyRects
323 std::vector<Dali::Internal::SceneGraph::DirtyRect>& GetItemsDirtyRects();
328 * From RenderTaskDefaults; retrieve the default root actor.
329 * @return The default root actor.
331 virtual Actor& GetDefaultRootActor();
334 * From RenderTaskDefaults; retrieve the default camera actor.
335 * @return The default camera actor.
337 virtual CameraActor& GetDefaultCameraActor();
345 * Second-phase constructor.
347 * @param[in] size The size of the set surface
348 * @param[in] orientation The orientation of the set surface for this scene
350 void Initialize( Size size, int orientation );
353 Scene(const Scene&) = delete;
356 Scene& operator=(const Scene& rhs) = delete;
359 Internal::SceneGraph::Scene* mSceneObject;
365 Vector4 mBackgroundColor;
367 // The SurfaceOrientation
368 int mSurfaceOrientation;
372 // Ordered list of currently on-stage layers
373 OwnerPointer<LayerList> mLayerList;
375 IntrusivePtr<CameraActor> mDefaultCamera;
377 // The list of render-tasks
378 IntrusivePtr<RenderTaskList> mRenderTaskList;
380 bool mDepthTreeDirty:1; ///< True if the depth tree needs recalculating
382 EventProcessor mEventProcessor;
384 // The key event signal
385 Integration::Scene::KeyEventSignalType mKeyEventSignal;
386 Integration::Scene::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
388 // The event processing finished signal
389 Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
392 Integration::Scene::TouchEventSignalType mTouchedSignal;
394 // The wheel event signal
395 Integration::Scene::WheelEventSignalType mWheelEventSignal;
397 std::vector<Dali::Internal::SceneGraph::DirtyRect> mItemsDirtyRects;
402 // Get impl of handle
403 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
405 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
406 Dali::RefObject& object = scene.GetBaseObject();
407 return static_cast<Internal::Scene&>(object);
410 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
412 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
413 const Dali::RefObject& object = scene.GetBaseObject();
414 return static_cast<const Internal::Scene&>(object);
419 #endif // DALI_INTERNAL_SCENE_H