1 #ifndef DALI_INTERNAL_SCENE_H
2 #define DALI_INTERNAL_SCENE_H
5 * Copyright (c) 2019 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/integration-api/render-surface.h>
27 #include <dali/internal/common/owner-pointer.h>
28 #include <dali/internal/event/actors/layer-impl.h>
29 #include <dali/internal/event/events/event-processor.h>
30 #include <dali/internal/event/render-tasks/render-task-defaults.h>
52 using FrameBufferPtr = IntrusivePtr<FrameBuffer>;
53 using ScenePtr = IntrusivePtr<Scene>;
56 * @brief Scene creates a "world" that can be bound to a surface for rendering.
58 class Scene : public BaseObject, public RenderTaskDefaults
63 * @copydoc Dali::Integration::Scene::New
65 static ScenePtr New( const Size& size );
73 * @copydoc Dali::Integration::Scene::Add
75 void Add(Actor& actor);
78 * @copydoc Dali::Integration::Scene::Remove
80 void Remove(Actor& actor);
83 * @copydoc Dali::Integration::Scene::GetSize
88 * @copydoc Dali::Integration::Scene::SetDpi
90 void SetDpi( Vector2 dpi );
93 * @copydoc Dali::Integration::Scene::GetDpi
95 Vector2 GetDpi() const;
98 * @copydoc Dali::Integration::Scene::GetRenderTaskList
100 RenderTaskList& GetRenderTaskList() const;
103 * @copydoc Dali::Integration::Scene::GetRootLayer
105 Dali::Layer GetRootLayer() const;
108 * @copydoc Dali::Integration::Scene::GetLayerCount
110 uint32_t GetLayerCount() const;
113 * @copydoc Dali::Integration::Scene::GetLayer
115 Dali::Layer GetLayer(uint32_t depth) const;
118 * @copydoc Dali::Integration::Scene::SetSurface
120 void SetSurface( Integration::RenderSurface& surface );
123 * Notify the surface has been resized.
125 void SurfaceResized();
128 * Notify the surface has been deleted.
130 void SurfaceDeleted();
133 * @copydoc Dali::Integration::Scene::Discard
138 * Retrieve the render surface the scene is binded to.
139 * @return The render surface.
141 Integration::RenderSurface* GetSurface() const;
144 * Retrieve the ordered list of on-scene layers.
145 * @return The layer-list.
147 LayerList& GetLayerList() const;
150 * Request that the depth tree is rebuilt
152 void RequestRebuildDepthTree();
155 * This function is called when an event is queued.
156 * @param[in] event A event to queue.
158 void QueueEvent( const Integration::Event& event );
161 * This function is called by Core when events are processed.
163 void ProcessEvents();
166 * Rebuilds the depth tree at the end of the event frame if
167 * it was requested this frame.
169 void RebuildDepthTree();
172 * @brief Sets the background color of the render surface.
173 * @param[in] color The new background color
175 void SetBackgroundColor( const Vector4& color );
178 * @brief Gets the background color of the render surface.
179 * @return The background color
181 Vector4 GetBackgroundColor() const;
184 * Used by the EventProcessor to emit key event signals.
185 * @param[in] event The key event.
187 void EmitKeyEventSignal(const KeyEvent& event);
190 * Emits the event processing finished signal.
192 * @see Dali::Scene::SignalEventProcessingFinished()
194 void EmitEventProcessingFinishedSignal();
197 * Emits the touched signal.
198 * @param[in] touchEvent The touch event details (Old API).
199 * @param[in] touch The touch event details.
201 void EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch );
204 * Used by the EventProcessor to emit wheel event signals.
205 * @param[in] event The wheel event.
207 void EmitWheelEventSignal( const WheelEvent& event );
210 * @copydoc Integration::Scene::KeyEventSignal()
212 Integration::Scene::KeyEventSignalType& KeyEventSignal();
215 * @copydoc Integration::Scene::SignalEventProcessingFinished()
217 Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
219 // The touched signal, to support Stage touched signal, will be removed when deprecated in public Stage API
220 using TouchedSignalType = Signal< void (const TouchEvent&) >;
223 * Touched signal to support deprecated stage touched signal.
225 TouchedSignalType& TouchedSignal();
228 * @copydoc Integration::Scene::TouchSignal()
230 Integration::Scene::TouchSignalType& TouchSignal();
233 * @copydoc Integration::Scene::sWheelEventSignal()
235 Integration::Scene::WheelEventSignalType& WheelEventSignal();
240 * From RenderTaskDefaults; retrieve the default root actor.
241 * @return The default root actor.
243 virtual Actor& GetDefaultRootActor();
246 * From RenderTaskDefaults; retrieve the default camera actor.
247 * @return The default camera actor.
249 virtual CameraActor& GetDefaultCameraActor();
254 Scene( const Size& size );
257 * Second-phase constructor.
262 Scene(const Scene&) = delete;
265 Scene& operator=(const Scene& rhs) = delete;
268 Integration::RenderSurface* mSurface;
270 // The scene-size may be different with the surface-size
276 Vector4 mBackgroundColor;
280 // Ordered list of currently on-stage layers
281 OwnerPointer<LayerList> mLayerList;
283 IntrusivePtr<CameraActor> mDefaultCamera;
285 // The list of render-tasks
286 IntrusivePtr<RenderTaskList> mRenderTaskList;
289 FrameBufferPtr mFrameBuffer;
291 bool mDepthTreeDirty:1; ///< True if the depth tree needs recalculating
293 EventProcessor mEventProcessor;
295 // The key event signal
296 Integration::Scene::KeyEventSignalType mKeyEventSignal;
298 // The event processing finished signal
299 Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
302 Integration::Scene::TouchSignalType mTouchSignal;
304 // The touched signal
305 TouchedSignalType mTouchedSignal;
307 // The wheel event signal
308 Integration::Scene::WheelEventSignalType mWheelEventSignal;
313 // Get impl of handle
314 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
316 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
317 Dali::RefObject& object = scene.GetBaseObject();
318 return static_cast<Internal::Scene&>(object);
321 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
323 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
324 const Dali::RefObject& object = scene.GetBaseObject();
325 return static_cast<const Internal::Scene&>(object);
330 #endif // DALI_INTERNAL_SCENE_H