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 );
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
174 * @param[in] orientation The orientation of the surface
175 * @param[in] forceUpdate The flag to update force
177 void SurfaceResized( float width, float height, int orientation, bool forceUpdate );
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 * Used by the EventProcessor to emit key event signals.
238 * @param[in] event The key event.
240 void EmitKeyEventSignal(const KeyEvent& event);
243 * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
244 * @param[in] event The key event.
245 * @return The return is true if KeyEvent is consumed, otherwise false.
247 bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
250 * Emits the event processing finished signal.
252 * @see Dali::Scene::SignalEventProcessingFinished()
254 void EmitEventProcessingFinishedSignal();
257 * Emits the touched signal.
258 * @param[in] touch The touch event details.
260 void EmitTouchedSignal( const Dali::TouchEvent& touch );
263 * Used by the EventProcessor to emit wheel event signals.
264 * @param[in] event The wheel event.
266 void EmitWheelEventSignal( const Dali::WheelEvent& event );
269 * @copydoc Dali::Integration::Scene::AddFrameRenderedCallback
271 void AddFrameRenderedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
274 * @copydoc Dali::Integration::Scene::AddFramePresentedCallback
276 void AddFramePresentedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
279 * @copydoc Dali::Integration::Scene::GetFrameRenderedCallback
281 void GetFrameRenderedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
284 * @copydoc Dali::Integration::Scene::GetFramePresentedCallback
286 void GetFramePresentedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
289 * @copydoc Integration::Scene::KeyEventSignal()
291 Integration::Scene::KeyEventSignalType& KeyEventSignal();
294 * @copydoc Integration::Scene::KeyEventGeneratedSignal()
296 Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
299 * @copydoc Integration::Scene::SignalEventProcessingFinished()
301 Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
304 * @copydoc Integration::Scene::TouchSignal()
306 Integration::Scene::TouchSignalType& TouchSignal();
309 * @copydoc Integration::Scene::sWheelEventSignal()
311 Integration::Scene::WheelEventSignalType& WheelEventSignal();
314 * @brief Get ItemsDirtyRects
316 * @return the ItemsDirtyRects
318 std::vector<Dali::Internal::SceneGraph::DirtyRect>& GetItemsDirtyRects();
323 * From RenderTaskDefaults; retrieve the default root actor.
324 * @return The default root actor.
326 virtual Actor& GetDefaultRootActor();
329 * From RenderTaskDefaults; retrieve the default camera actor.
330 * @return The default camera actor.
332 virtual CameraActor& GetDefaultCameraActor();
340 * Second-phase constructor.
342 * @param[in] size The size of the set surface
344 void Initialize( Size size );
347 Scene(const Scene&) = delete;
350 Scene& operator=(const Scene& rhs) = delete;
353 Internal::SceneGraph::Scene* mSceneObject;
359 Vector4 mBackgroundColor;
361 // The SurfaceOrientation
362 int mSurfaceOrientation;
366 // Ordered list of currently on-stage layers
367 OwnerPointer<LayerList> mLayerList;
369 IntrusivePtr<CameraActor> mDefaultCamera;
371 // The list of render-tasks
372 IntrusivePtr<RenderTaskList> mRenderTaskList;
374 bool mDepthTreeDirty:1; ///< True if the depth tree needs recalculating
376 EventProcessor mEventProcessor;
378 // The key event signal
379 Integration::Scene::KeyEventSignalType mKeyEventSignal;
380 Integration::Scene::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
382 // The event processing finished signal
383 Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
386 Integration::Scene::TouchSignalType mTouchSignal;
388 // The wheel event signal
389 Integration::Scene::WheelEventSignalType mWheelEventSignal;
391 std::vector<Dali::Internal::SceneGraph::DirtyRect> mItemsDirtyRects;
396 // Get impl of handle
397 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
399 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
400 Dali::RefObject& object = scene.GetBaseObject();
401 return static_cast<Internal::Scene&>(object);
404 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
406 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
407 const Dali::RefObject& object = scene.GetBaseObject();
408 return static_cast<const Internal::Scene&>(object);
413 #endif // DALI_INTERNAL_SCENE_H