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
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 * Used by the EventProcessor to emit key event signals.
236 * @param[in] event The key event.
238 void EmitKeyEventSignal(const Dali::KeyEvent& event);
241 * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
242 * @param[in] event The key event.
243 * @return The return is true if KeyEvent is consumed, otherwise false.
245 bool EmitKeyEventGeneratedSignal(const Dali::KeyEvent& event);
248 * Emits the event processing finished signal.
250 * @see Dali::Scene::SignalEventProcessingFinished()
252 void EmitEventProcessingFinishedSignal();
255 * Emits the touched signal.
256 * @param[in] touch The touch event details.
258 void EmitTouchedSignal( const Dali::TouchEvent& touch );
261 * Used by the EventProcessor to emit wheel event signals.
262 * @param[in] event The wheel event.
264 void EmitWheelEventSignal( const Dali::WheelEvent& event );
267 * @copydoc Dali::Integration::Scene::AddFrameRenderedCallback
269 void AddFrameRenderedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
272 * @copydoc Dali::Integration::Scene::AddFramePresentedCallback
274 void AddFramePresentedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
277 * @copydoc Dali::Integration::Scene::GetFrameRenderedCallback
279 void GetFrameRenderedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
282 * @copydoc Dali::Integration::Scene::GetFramePresentedCallback
284 void GetFramePresentedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
287 * @copydoc Integration::Scene::KeyEventSignal()
289 Integration::Scene::KeyEventSignalType& KeyEventSignal();
292 * @copydoc Integration::Scene::KeyEventGeneratedSignal()
294 Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
297 * @copydoc Integration::Scene::SignalEventProcessingFinished()
299 Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
302 * @copydoc Integration::Scene::TouchedSignal()
304 Integration::Scene::TouchEventSignalType& TouchedSignal();
307 * @copydoc Integration::Scene::sWheelEventSignal()
309 Integration::Scene::WheelEventSignalType& WheelEventSignal();
312 * @brief Get ItemsDirtyRects
314 * @return the ItemsDirtyRects
316 std::vector<Dali::Internal::SceneGraph::DirtyRect>& GetItemsDirtyRects();
321 * From RenderTaskDefaults; retrieve the default root actor.
322 * @return The default root actor.
324 Actor& GetDefaultRootActor() override;
327 * From RenderTaskDefaults; retrieve the default camera actor.
328 * @return The default camera actor.
330 CameraActor& GetDefaultCameraActor() override;
338 * Second-phase constructor.
340 * @param[in] size The size of the set surface
342 void Initialize( Size size );
345 Scene(const Scene&) = delete;
348 Scene& operator=(const Scene& rhs) = delete;
351 Internal::SceneGraph::Scene* mSceneObject;
357 Vector4 mBackgroundColor;
361 // Ordered list of currently on-stage layers
362 OwnerPointer<LayerList> mLayerList;
364 IntrusivePtr<CameraActor> mDefaultCamera;
366 // The list of render-tasks
367 IntrusivePtr<RenderTaskList> mRenderTaskList;
369 bool mDepthTreeDirty:1; ///< True if the depth tree needs recalculating
371 EventProcessor mEventProcessor;
373 // The key event signal
374 Integration::Scene::KeyEventSignalType mKeyEventSignal;
375 Integration::Scene::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
377 // The event processing finished signal
378 Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
381 Integration::Scene::TouchEventSignalType mTouchedSignal;
383 // The wheel event signal
384 Integration::Scene::WheelEventSignalType mWheelEventSignal;
386 std::vector<Dali::Internal::SceneGraph::DirtyRect> mItemsDirtyRects;
391 // Get impl of handle
392 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
394 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
395 Dali::RefObject& object = scene.GetBaseObject();
396 return static_cast<Internal::Scene&>(object);
399 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
401 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
402 const Dali::RefObject& object = scene.GetBaseObject();
403 return static_cast<const Internal::Scene&>(object);
408 #endif // DALI_INTERNAL_SCENE_H