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>
56 using FrameBufferPtr = IntrusivePtr<FrameBuffer>;
57 using ScenePtr = IntrusivePtr<Scene>;
60 * @brief Scene creates a "world" that can be bound to a surface for rendering.
62 class Scene : public BaseObject, public RenderTaskDefaults
67 * @copydoc Dali::Integration::Scene::New
69 static ScenePtr New( Size size );
77 * @copydoc Dali::Integration::Scene::Add
79 void Add(Actor& actor);
82 * @copydoc Dali::Integration::Scene::Remove
84 void Remove(Actor& actor);
87 * @copydoc Dali::Integration::Scene::GetSize
92 * @copydoc Dali::Integration::Scene::SetDpi
94 void SetDpi( Vector2 dpi );
97 * @copydoc Dali::Integration::Scene::GetDpi
99 Vector2 GetDpi() const;
102 * @copydoc Dali::Integration::Scene::GetRenderTaskList
104 RenderTaskList& GetRenderTaskList() const;
107 * @copydoc Dali::Integration::Scene::GetRootLayer
109 Dali::Layer GetRootLayer() const;
112 * @copydoc Dali::Integration::Scene::GetLayerCount
114 uint32_t GetLayerCount() const;
117 * @copydoc Dali::Integration::Scene::GetLayer
119 Dali::Layer GetLayer(uint32_t depth) const;
122 * Notify the surface has been resized.
124 * @param[in] width The new width of the set surface
125 * @param[in] height The new height of the set surface
127 void SurfaceResized( float width, float height );
130 * @copydoc Dali::Integration::Scene::SurfaceReplaced
132 void SurfaceReplaced();
135 * @copydoc Dali::Integration::Scene::Discard
140 * Retrieve the ordered list of on-scene layers.
141 * @return The layer-list.
143 LayerList& GetLayerList() const;
146 * Request that the depth tree is rebuilt
148 void RequestRebuildDepthTree();
151 * This function is called when an event is queued.
152 * @param[in] event A event to queue.
154 void QueueEvent( const Integration::Event& event );
157 * This function is called by Core when events are processed.
159 void ProcessEvents();
162 * Rebuilds the depth tree at the end of the event frame if
163 * it was requested this frame.
165 void RebuildDepthTree();
168 * @brief Sets the background color of the render surface.
169 * @param[in] color The new background color
171 void SetBackgroundColor( const Vector4& color );
174 * @brief Gets the background color of the render surface.
175 * @return The background color
177 Vector4 GetBackgroundColor() const;
180 * @brief Get the Scene scene graph object
182 * @return the Scene scene graph object
184 SceneGraph::Scene* GetSceneObject() const;
187 * Used by the EventProcessor to emit key event signals.
188 * @param[in] event The key event.
190 void EmitKeyEventSignal(const Dali::KeyEvent& event);
193 * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
194 * @param[in] event The key event.
195 * @return The return is true if KeyEvent is consumed, otherwise false.
197 bool EmitKeyEventGeneratedSignal(const Dali::KeyEvent& event);
200 * Emits the event processing finished signal.
202 * @see Dali::Scene::SignalEventProcessingFinished()
204 void EmitEventProcessingFinishedSignal();
207 * Emits the touched signal.
208 * @param[in] touch The touch event details.
210 void EmitTouchedSignal( const Dali::TouchEvent& touch );
213 * Used by the EventProcessor to emit wheel event signals.
214 * @param[in] event The wheel event.
216 void EmitWheelEventSignal( const Dali::WheelEvent& event );
219 * @copydoc Dali::Integration::Scene::AddFrameRenderedCallback
221 void AddFrameRenderedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
224 * @copydoc Dali::Integration::Scene::AddFramePresentedCallback
226 void AddFramePresentedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
229 * @copydoc Dali::Integration::Scene::GetFrameRenderedCallback
231 void GetFrameRenderedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
234 * @copydoc Dali::Integration::Scene::GetFramePresentedCallback
236 void GetFramePresentedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
239 * @copydoc Integration::Scene::KeyEventSignal()
241 Integration::Scene::KeyEventSignalType& KeyEventSignal();
244 * @copydoc Integration::Scene::KeyEventGeneratedSignal()
246 Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
249 * @copydoc Integration::Scene::SignalEventProcessingFinished()
251 Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
254 * @copydoc Integration::Scene::TouchedSignal()
256 Integration::Scene::TouchEventSignalType& TouchedSignal();
259 * @copydoc Integration::Scene::sWheelEventSignal()
261 Integration::Scene::WheelEventSignalType& WheelEventSignal();
266 * From RenderTaskDefaults; retrieve the default root actor.
267 * @return The default root actor.
269 Actor& GetDefaultRootActor() override;
272 * From RenderTaskDefaults; retrieve the default camera actor.
273 * @return The default camera actor.
275 CameraActor& GetDefaultCameraActor() override;
283 * Second-phase constructor.
285 * @param[in] size The size of the set surface
287 void Initialize( Size size );
290 Scene(const Scene&) = delete;
293 Scene& operator=(const Scene& rhs) = delete;
296 Internal::SceneGraph::Scene* mSceneObject;
302 Vector4 mBackgroundColor;
306 // Ordered list of currently on-stage layers
307 OwnerPointer<LayerList> mLayerList;
309 IntrusivePtr<CameraActor> mDefaultCamera;
311 // The list of render-tasks
312 IntrusivePtr<RenderTaskList> mRenderTaskList;
314 bool mDepthTreeDirty:1; ///< True if the depth tree needs recalculating
316 EventProcessor mEventProcessor;
318 // The key event signal
319 Integration::Scene::KeyEventSignalType mKeyEventSignal;
320 Integration::Scene::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
322 // The event processing finished signal
323 Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
326 Integration::Scene::TouchEventSignalType mTouchedSignal;
328 // The wheel event signal
329 Integration::Scene::WheelEventSignalType mWheelEventSignal;
334 // Get impl of handle
335 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
337 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
338 Dali::RefObject& object = scene.GetBaseObject();
339 return static_cast<Internal::Scene&>(object);
342 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
344 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
345 const Dali::RefObject& object = scene.GetBaseObject();
346 return static_cast<const Internal::Scene&>(object);
351 #endif // DALI_INTERNAL_SCENE_H