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/hover-event-integ.h>
24 #include <dali/integration-api/events/key-event-integ.h>
25 #include <dali/integration-api/events/point.h>
26 #include <dali/integration-api/events/touch-event-combiner.h>
27 #include <dali/integration-api/scene.h>
28 #include <dali/public-api/common/intrusive-ptr.h>
29 #include <dali/public-api/events/hover-event.h>
30 #include <dali/public-api/events/touch-event.h>
31 #include <dali/public-api/math/uint-16-pair.h>
32 #include <dali/public-api/object/base-object.h>
38 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
39 #include <dali/integration-api/adaptor-framework/scene-holder.h>
58 } // namespace Integration
66 using SceneHolderPtr = IntrusivePtr<SceneHolder>;
69 * @brief SceneHolder creates a Scene for rendering.
71 class DALI_ADAPTOR_API SceneHolder : public BaseObject
75 * @copydoc Dali::Integration::SceneHolder::Add
77 void Add(Dali::Actor actor);
80 * @copydoc Dali::Integration::SceneHolder::Remove
82 void Remove(Dali::Actor actor);
85 * @copydoc Dali::Integration::SceneHolder::GetRootLayer
87 Dali::Layer GetRootLayer() const;
90 * @copydoc Dali::Integration::SceneHolder::GetOverlayLayer
92 Dali::Layer GetOverlayLayer();
95 * @brief Gets the window name.
96 * @return The name of the window
98 std::string GetName() const;
101 * @brief Retrieve the unique ID of the window.
104 uint32_t GetId() const;
107 * @brief Retrieve the Scene.
110 Dali::Integration::Scene GetScene();
113 * @brief Retrieves the DPI of this sceneholder.
116 Uint16Pair GetDpi() const;
119 * @brief Set the render surface
120 * @param[in] surface The render surface
122 void SetSurface(Dali::RenderSurfaceInterface* surface);
125 * @brief Called when the surface set is resized.
126 * @param[in] width the resized window's width
127 * @param[in] height the resized window's height
129 void SurfaceResized(float width, float height);
132 * @brief Get the render surface
133 * @return The render surface
135 Dali::RenderSurfaceInterface* GetSurface() const;
138 * @brief Set the adaptor to the scene holder
139 * @param[in] adaptor An initialized adaptor
141 void SetAdaptor(Dali::Adaptor& adaptor);
144 * @copydoc Dali::Integration::SceneHolder::SetBackgroundColor
146 void SetBackgroundColor(const Dali::Vector4& color);
149 * @copydoc Dali::Integration::SceneHolder::GetBackgroundColor
151 Vector4 GetBackgroundColor() const;
154 * @brief Pause the rendering of the scene holder.
159 * @brief Resume the rendering of the scene holder (from pause).
164 * @brief Informs the scene that the set surface has been rotated.
166 * @param[in] width The width of rotated surface
167 * @param[in] height The height of rotated surface
168 * @param[in] windowOrientation the current window orientation
169 * @param[in] screenOrientation the current screen orientation
171 void SurfaceRotated(float width, float height, int32_t windowOrientation, int32_t screenOrientation);
174 * @brief Send message to acknowledge window rotation with current window orientation.
175 * It is to send message to render thread for completing window rotation by user.
177 void SetRotationCompletedAcknowledgement();
180 * @copydoc Dali::Integration::SceneHolder::FeedTouchPoint
182 void FeedTouchPoint(Dali::Integration::Point& point, int timeStamp);
185 * @brief Get the Last Touch Event
187 * @return Dali::TouchEvent
189 const Dali::TouchEvent& GetLastTouchEvent() const;
192 * @brief Get the Last Hover Event
194 * @return Dali::HoverEvent
196 const Dali::HoverEvent& GetLastHoverEvent() const;
199 * @copydoc Dali::Integration::SceneHolder::FeedWheelEvent
201 void FeedWheelEvent(Dali::Integration::WheelEvent& wheelEvent);
204 * @copydoc Dali::Integration::SceneHolder::FeedKeyEvent
206 void FeedKeyEvent(Dali::Integration::KeyEvent& keyEvent);
209 * @copydoc Dali::Integration::SceneHolder::FeedHoverEvent
211 void FeedHoverEvent(Dali::Integration::Point& point);
214 * @copydoc Dali::Integration::SceneHolder::SetGeometryHittestEnabled
216 void SetGeometryHittestEnabled(bool enabled);
219 * @copydoc Dali::Integration::SceneHolder::IsGeometryHittestEnabled
221 bool IsGeometryHittestEnabled();
224 * @copydoc Dali::Integration::SceneHolder::GetNativeId
226 int32_t GetNativeId() const;
229 * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
231 * @param[in] callback The function to call
232 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
234 * @note A callback of the following type may be used:
236 * void MyFunction( int frameId );
238 * This callback will be deleted once it is called.
240 * @note Ownership of the callback is passed onto this class.
242 void AddFrameRenderedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
245 * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
247 * @param[in] callback The function to call
248 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
250 * @note A callback of the following type may be used:
252 * void MyFunction( int frameId );
254 * This callback will be deleted once it is called.
256 * @note Ownership of the callback is passed onto this class.
258 void AddFramePresentedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
261 * @brief Creates the render target for the surface when the surface is created/resized/replaced.
263 void CreateRenderTarget();
266 * @copydoc Dali::Integration::SceneHolder::GetRenderTaskList()
268 Dali::RenderTaskList GetRenderTaskList() const;
271 * @copydoc Dali::Integration::SceneHolder::Get()
273 static Dali::Integration::SceneHolder Get(Dali::Actor actor);
276 * @copydoc Dali::Integration::SceneHolder::KeyEventSignal()
278 Dali::Integration::SceneHolder::KeyEventSignalType& KeyEventSignal()
280 return mScene.KeyEventSignal();
284 * @copydoc Dali::Integration::SceneHolder::KeyEventGeneratedSignal()
286 Dali::Integration::SceneHolder::KeyEventGeneratedSignalType& KeyEventGeneratedSignal()
288 return mScene.KeyEventGeneratedSignal();
292 * @copydoc Dali::Integration::SceneHolder::InterceptKeyEventSignal()
294 Dali::Integration::SceneHolder::KeyEventGeneratedSignalType& InterceptKeyEventSignal()
296 return mScene.InterceptKeyEventSignal();
300 * @copydoc Dali::Integration::SceneHolder::TouchedSignal()
302 Dali::Integration::SceneHolder::TouchEventSignalType& TouchedSignal()
304 return mScene.TouchedSignal();
308 * @copydoc Dali::Integration::SceneHolder::WheelEventSignal()
310 Dali::Integration::SceneHolder::WheelEventSignalType& WheelEventSignal()
312 return mScene.WheelEventSignal();
316 * @copydoc Dali::Integration::SceneHolder::WheelEventGeneratedSignal()
318 Dali::Integration::SceneHolder::WheelEventGeneratedSignalType& WheelEventGeneratedSignal()
320 return mScene.WheelEventGeneratedSignal();
323 public: // The following methods can be overridden if required
325 * @brief Returns whether the Scene is visible or not.
326 * @return True if the Scene is visible, false otherwise.
328 virtual bool IsVisible() const;
330 public: // The following methods must be overridden
332 * @copydoc Dali::Integration::SceneHolder::GetNativeHandle
334 virtual Dali::Any GetNativeHandle() const = 0;
341 SceneHolder(const SceneHolder&) = delete;
344 SceneHolder& operator=(const SceneHolder& rhs) = delete;
349 ~SceneHolder() override;
351 private: // The following methods can be overridden if required
353 * @brief Called by the base class to inform deriving classes that the adaptor has been set.
354 * @param[in] adaptor The adaptor
356 virtual void OnAdaptorSet(Dali::Adaptor& adaptor){};
359 * @brief Called by the base class to inform deriving classes that a new surface has been set.
360 * @param[in] surface The new render surface
362 virtual void OnSurfaceSet(Dali::RenderSurfaceInterface* surface){};
365 * @brief Called by the base class to inform deriving classes that we are being paused.
367 virtual void OnPause(){};
370 * @brief Called by the base class to inform deriving classes that we are resuming from a paused state.
372 virtual void OnResume(){};
375 * Recalculate the position if required
376 * @param[in] position The screen position
377 * @return converted position by oriention
379 virtual Vector2 RecalculatePosition(const Vector2& position)
386 * Resets the event handling.
391 * Initializes the DPI for this object.
393 void InitializeDpi();
396 static uint32_t mSceneHolderCounter; ///< A counter to track the SceneHolder creation
398 class SceneHolderLifeCycleObserver;
399 std::unique_ptr<SceneHolderLifeCycleObserver> mLifeCycleObserver; ///< The adaptor life cycle observer
400 Dali::TouchEvent mLastTouchEvent;
401 Dali::HoverEvent mLastHoverEvent;
404 uint32_t mId; ///< A unique ID to identify the SceneHolder starting from 0
405 Dali::Integration::Scene mScene; ///< The Scene
406 std::string mName; ///< The name of the SceneHolder
408 std::unique_ptr<Dali::RenderSurfaceInterface> mSurface; ///< The window rendering surface
409 Adaptor* mAdaptor; ///< The adaptor
411 Dali::Integration::TouchEventCombiner mCombiner; ///< Combines multi-touch events.
413 Uint16Pair mDpi; ///< The DPI for this SceneHolder.
415 bool mAdaptorStarted; ///< Whether the adaptor has started or not
416 bool mVisible : 1; ///< Whether the scene is visible or not
419 } // namespace Adaptor
421 } // namespace Internal
423 // Get impl of handle
424 inline Internal::Adaptor::SceneHolder& GetImplementation(Dali::Integration::SceneHolder& sceneHolder)
426 DALI_ASSERT_ALWAYS(sceneHolder && "SceneHolder handle is empty");
427 Dali::RefObject& object = sceneHolder.GetBaseObject();
428 return static_cast<Internal::Adaptor::SceneHolder&>(object);
431 inline const Internal::Adaptor::SceneHolder& GetImplementation(const Dali::Integration::SceneHolder& sceneHolder)
433 DALI_ASSERT_ALWAYS(sceneHolder && "SceneHolder handle is empty");
434 const Dali::RefObject& object = sceneHolder.GetBaseObject();
435 return static_cast<const Internal::Adaptor::SceneHolder&>(object);
440 #endif // DALI_INTEGRATION_INTERNAL_SCENEHOLDER_H