1 #ifndef DALI_INTEGRATION_INTERNAL_SCENEHOLDER_H
2 #define DALI_INTEGRATION_INTERNAL_SCENEHOLDER_H
5 * Copyright (c) 2023 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/graphics-api/graphics-controller.h>
23 #include <dali/integration-api/events/key-event-integ.h>
24 #include <dali/integration-api/events/point.h>
25 #include <dali/integration-api/events/touch-event-combiner.h>
26 #include <dali/integration-api/scene.h>
27 #include <dali/public-api/common/intrusive-ptr.h>
28 #include <dali/public-api/math/uint-16-pair.h>
29 #include <dali/public-api/object/base-object.h>
35 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
36 #include <dali/integration-api/adaptor-framework/scene-holder.h>
55 } // namespace Integration
63 using SceneHolderPtr = IntrusivePtr<SceneHolder>;
66 * @brief SceneHolder creates a Scene for rendering.
68 class DALI_ADAPTOR_API SceneHolder : public BaseObject
72 * @copydoc Dali::Integration::SceneHolder::Add
74 void Add(Dali::Actor actor);
77 * @copydoc Dali::Integration::SceneHolder::Remove
79 void Remove(Dali::Actor actor);
82 * @copydoc Dali::Integration::SceneHolder::GetRootLayer
84 Dali::Layer GetRootLayer() const;
87 * @copydoc Dali::Integration::SceneHolder::GetOverlayLayer
89 Dali::Layer GetOverlayLayer();
92 * @brief Gets the window name.
93 * @return The name of the window
95 std::string GetName() const;
98 * @brief Retrieve the unique ID of the window.
101 uint32_t GetId() const;
104 * @brief Retrieve the Scene.
107 Dali::Integration::Scene GetScene();
110 * @brief Retrieves the DPI of this sceneholder.
113 Uint16Pair GetDpi() const;
116 * @brief Set the render surface
117 * @param[in] surface The render surface
119 void SetSurface(Dali::RenderSurfaceInterface* surface);
122 * @brief Called when the surface set is resized.
123 * @param[in] width the resized window's width
124 * @param[in] height the resized window's height
126 void SurfaceResized(float width, float height);
129 * @brief Get the render surface
130 * @return The render surface
132 Dali::RenderSurfaceInterface* GetSurface() const;
135 * @brief Set the adaptor to the scene holder
136 * @param[in] adaptor An initialized adaptor
138 void SetAdaptor(Dali::Adaptor& adaptor);
141 * @copydoc Dali::Integration::SceneHolder::SetBackgroundColor
143 void SetBackgroundColor(const Dali::Vector4& color);
146 * @copydoc Dali::Integration::SceneHolder::GetBackgroundColor
148 Vector4 GetBackgroundColor() const;
151 * @brief Pause the rendering of the scene holder.
156 * @brief Resume the rendering of the scene holder (from pause).
161 * @brief Checks whether this scene holder is being deleted in the event thread.
163 * @return true if this scene holder is being deleted in the event thread, or false if not.
165 bool IsBeingDeleted() const
167 return mIsBeingDeleted;
171 * @brief Informs the scene that the set surface has been rotated.
173 * @param[in] width The width of rotated surface
174 * @param[in] height The height of rotated surface
175 * @param[in] windowOrientation the current window orientation
176 * @param[in] screenOrientation the current screen orientation
178 void SurfaceRotated(float width, float height, int32_t windowOrientation, int32_t screenOrientation);
181 * @brief Send message to acknowledge window rotation with current window orientation.
182 * It is to send message to render thread for completing window rotation by user.
184 void SetRotationCompletedAcknowledgement();
187 * @copydoc Dali::Integration::SceneHolder::FeedTouchPoint
189 void FeedTouchPoint(Dali::Integration::Point& point, int timeStamp);
192 * @copydoc Dali::Integration::SceneHolder::FeedWheelEvent
194 void FeedWheelEvent(Dali::Integration::WheelEvent& wheelEvent);
197 * @copydoc Dali::Integration::SceneHolder::FeedKeyEvent
199 void FeedKeyEvent(Dali::Integration::KeyEvent& keyEvent);
202 * @copydoc Dali::Integration::SceneHolder::FeedHoverEvent
204 void FeedHoverEvent(Dali::Integration::Point& point);
207 * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
209 * @param[in] callback The function to call
210 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
212 * @note A callback of the following type may be used:
214 * void MyFunction( int frameId );
216 * This callback will be deleted once it is called.
218 * @note Ownership of the callback is passed onto this class.
220 void AddFrameRenderedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
223 * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
225 * @param[in] callback The function to call
226 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
228 * @note A callback of the following type may be used:
230 * void MyFunction( int frameId );
232 * This callback will be deleted once it is called.
234 * @note Ownership of the callback is passed onto this class.
236 void AddFramePresentedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
239 * @brief Creates the render target for the surface when the surface is created/resized/replaced.
241 void CreateRenderTarget();
244 * @copydoc Dali::Integration::SceneHolder::GetRenderTaskList()
246 Dali::RenderTaskList GetRenderTaskList() const;
249 * @copydoc Dali::Integration::SceneHolder::Get()
251 static Dali::Integration::SceneHolder Get(Dali::Actor actor);
254 * @copydoc Dali::Integration::SceneHolder::KeyEventSignal()
256 Dali::Integration::SceneHolder::KeyEventSignalType& KeyEventSignal()
258 return mScene.KeyEventSignal();
262 * @copydoc Dali::Integration::SceneHolder::KeyEventGeneratedSignal()
264 Dali::Integration::SceneHolder::KeyEventGeneratedSignalType& KeyEventGeneratedSignal()
266 return mScene.KeyEventGeneratedSignal();
270 * @copydoc Dali::Integration::SceneHolder::InterceptKeyEventSignal()
272 Dali::Integration::SceneHolder::KeyEventGeneratedSignalType& InterceptKeyEventSignal()
274 return mScene.InterceptKeyEventSignal();
278 * @copydoc Dali::Integration::SceneHolder::TouchedSignal()
280 Dali::Integration::SceneHolder::TouchEventSignalType& TouchedSignal()
282 return mScene.TouchedSignal();
286 * @copydoc Dali::Integration::SceneHolder::WheelEventSignal()
288 Dali::Integration::SceneHolder::WheelEventSignalType& WheelEventSignal()
290 return mScene.WheelEventSignal();
294 * @copydoc Dali::Integration::SceneHolder::WheelEventGeneratedSignal()
296 Dali::Integration::SceneHolder::WheelEventGeneratedSignalType& WheelEventGeneratedSignal()
298 return mScene.WheelEventGeneratedSignal();
301 public: // The following methods can be overridden if required
303 * @brief Returns whether the Scene is visible or not.
304 * @return True if the Scene is visible, false otherwise.
306 virtual bool IsVisible() const;
308 public: // The following methods must be overridden
310 * @copydoc Dali::Integration::SceneHolder::GetNativeHandle
312 virtual Dali::Any GetNativeHandle() const = 0;
319 SceneHolder(const SceneHolder&) = delete;
322 SceneHolder& operator=(const SceneHolder& rhs) = delete;
327 ~SceneHolder() override;
329 private: // The following methods can be overridden if required
331 * @brief Called by the base class to inform deriving classes that the adaptor has been set.
332 * @param[in] adaptor The adaptor
334 virtual void OnAdaptorSet(Dali::Adaptor& adaptor){};
337 * @brief Called by the base class to inform deriving classes that a new surface has been set.
338 * @param[in] surface The new render surface
340 virtual void OnSurfaceSet(Dali::RenderSurfaceInterface* surface){};
343 * @brief Called by the base class to inform deriving classes that we are being paused.
345 virtual void OnPause(){};
348 * @brief Called by the base class to inform deriving classes that we are resuming from a paused state.
350 virtual void OnResume(){};
353 * Recalculate the position if required
354 * @param[in] position The screen position
355 * @return converted position by oriention
357 virtual Vector2 RecalculatePosition(const Vector2& position)
364 * Resets the event handling.
369 * Initializes the DPI for this object.
371 void InitializeDpi();
374 static uint32_t mSceneHolderCounter; ///< A counter to track the SceneHolder creation
376 class SceneHolderLifeCycleObserver;
377 std::unique_ptr<SceneHolderLifeCycleObserver> mLifeCycleObserver; ///< The adaptor life cycle observer
380 uint32_t mId; ///< A unique ID to identify the SceneHolder starting from 0
381 Dali::Integration::Scene mScene; ///< The Scene
382 std::string mName; ///< The name of the SceneHolder
384 std::unique_ptr<Dali::RenderSurfaceInterface> mSurface; ///< The window rendering surface
385 Adaptor* mAdaptor; ///< The adaptor
387 Dali::Integration::TouchEventCombiner mCombiner; ///< Combines multi-touch events.
389 Uint16Pair mDpi; ///< The DPI for this SceneHolder.
391 std::atomic<bool> mIsBeingDeleted; ///< This is set only from the event thread and read only from the render thread
393 bool mAdaptorStarted : 1; ///< Whether the adaptor has started or not
394 bool mVisible : 1; ///< Whether the scene is visible or not
397 } // namespace Adaptor
399 } // namespace Internal
401 // Get impl of handle
402 inline Internal::Adaptor::SceneHolder& GetImplementation(Dali::Integration::SceneHolder& sceneHolder)
404 DALI_ASSERT_ALWAYS(sceneHolder && "SceneHolder handle is empty");
405 Dali::RefObject& object = sceneHolder.GetBaseObject();
406 return static_cast<Internal::Adaptor::SceneHolder&>(object);
409 inline const Internal::Adaptor::SceneHolder& GetImplementation(const Dali::Integration::SceneHolder& sceneHolder)
411 DALI_ASSERT_ALWAYS(sceneHolder && "SceneHolder handle is empty");
412 const Dali::RefObject& object = sceneHolder.GetBaseObject();
413 return static_cast<const Internal::Adaptor::SceneHolder&>(object);
418 #endif // DALI_INTEGRATION_INTERNAL_SCENEHOLDER_H