1 #ifndef DALI_INTEGRATION_INTERNAL_SCENEHOLDER_H
2 #define DALI_INTEGRATION_INTERNAL_SCENEHOLDER_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/events/key-event-integ.h>
23 #include <dali/integration-api/events/point.h>
24 #include <dali/integration-api/events/touch-event-combiner.h>
25 #include <dali/integration-api/scene.h>
26 #include <dali/public-api/common/intrusive-ptr.h>
27 #include <dali/public-api/math/uint-16-pair.h>
28 #include <dali/public-api/object/base-object.h>
34 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
35 #include <dali/integration-api/adaptor-framework/scene-holder.h>
54 } // namespace Integration
62 using SceneHolderPtr = IntrusivePtr<SceneHolder>;
65 * @brief SceneHolder creates a Scene for rendering.
67 class DALI_ADAPTOR_API SceneHolder : public BaseObject
71 * @copydoc Dali::Integration::SceneHolder::Add
73 void Add(Dali::Actor actor);
76 * @copydoc Dali::Integration::SceneHolder::Remove
78 void Remove(Dali::Actor actor);
81 * @copydoc Dali::Integration::SceneHolder::GetRootLayer
83 Dali::Layer GetRootLayer() const;
86 * @brief Gets the window name.
87 * @return The name of the window
89 std::string GetName() const;
92 * @brief Retrieve the unique ID of the window.
95 uint32_t GetId() const;
98 * @brief Retrieve the Scene.
101 Dali::Integration::Scene GetScene();
104 * @brief Retrieves the DPI of this sceneholder.
107 Uint16Pair GetDpi() const;
110 * @brief Set the render surface
111 * @param[in] surface The render surface
113 void SetSurface(Dali::RenderSurfaceInterface* surface);
116 * @brief Called when the surface set is resized.
118 void SurfaceResized();
121 * @brief Get the render surface
122 * @return The render surface
124 Dali::RenderSurfaceInterface* GetSurface() const;
127 * @brief Set the adaptor to the scene holder
128 * @param[in] adaptor An initialized adaptor
130 void SetAdaptor(Dali::Adaptor& adaptor);
133 * @copydoc Dali::Integration::SceneHolder::SetBackgroundColor
135 void SetBackgroundColor(const Dali::Vector4& color);
138 * @copydoc Dali::Integration::SceneHolder::GetBackgroundColor
140 Vector4 GetBackgroundColor() const;
143 * @brief Pause the rendering of the scene holder.
148 * @brief Resume the rendering of the scene holder (from pause).
153 * @brief Checks whether this scene holder is being deleted in the event thread.
155 * @return true if this scene holder is being deleted in the event thread, or false if not.
157 bool IsBeingDeleted() const
159 return mIsBeingDeleted;
163 * @copydoc Dali::Integration::SceneHolder::FeedTouchPoint
165 void FeedTouchPoint(Dali::Integration::Point& point, int timeStamp);
168 * @copydoc Dali::Integration::SceneHolder::FeedWheelEvent
170 void FeedWheelEvent(Dali::Integration::WheelEvent& wheelEvent);
173 * @copydoc Dali::Integration::SceneHolder::FeedKeyEvent
175 void FeedKeyEvent(Dali::Integration::KeyEvent& keyEvent);
178 * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
180 * @param[in] callback The function to call
181 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
183 * @note A callback of the following type may be used:
185 * void MyFunction( int frameId );
187 * This callback will be deleted once it is called.
189 * @note Ownership of the callback is passed onto this class.
191 void AddFrameRenderedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
194 * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
196 * @param[in] callback The function to call
197 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
199 * @note A callback of the following type may be used:
201 * void MyFunction( int frameId );
203 * This callback will be deleted once it is called.
205 * @note Ownership of the callback is passed onto this class.
207 void AddFramePresentedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
210 * @copydoc Dali::Integration::SceneHolder::Get()
212 static Dali::Integration::SceneHolder Get(Dali::Actor actor);
215 * @copydoc Dali::Integration::SceneHolder::KeyEventSignal()
217 Dali::Integration::SceneHolder::KeyEventSignalType& KeyEventSignal()
219 return mScene.KeyEventSignal();
223 * @copydoc Dali::Integration::SceneHolder::KeyEventGeneratedSignal()
225 Dali::Integration::SceneHolder::KeyEventGeneratedSignalType& KeyEventGeneratedSignal()
227 return mScene.KeyEventGeneratedSignal();
231 * @copydoc Dali::Integration::SceneHolder::TouchedSignal()
233 Dali::Integration::SceneHolder::TouchEventSignalType& TouchedSignal()
235 return mScene.TouchedSignal();
239 * @copydoc Dali::Integration::SceneHolder::WheelEventSignal()
241 Dali::Integration::SceneHolder::WheelEventSignalType& WheelEventSignal()
243 return mScene.WheelEventSignal();
246 public: // The following methods can be overridden if required
248 * @brief Returns whether the Scene is visible or not.
249 * @return True if the Scene is visible, false otherwise.
251 virtual bool IsVisible() const;
253 public: // The following methods must be overridden
255 * @copydoc Dali::Integration::SceneHolder::GetNativeHandle
257 virtual Dali::Any GetNativeHandle() const = 0;
264 SceneHolder(const SceneHolder&) = delete;
267 SceneHolder& operator=(const SceneHolder& rhs) = delete;
272 ~SceneHolder() override;
274 private: // The following methods can be overridden if required
276 * @brief Called by the base class to inform deriving classes that the adaptor has been set.
277 * @param[in] adaptor The adaptor
279 virtual void OnAdaptorSet(Dali::Adaptor& adaptor){};
282 * @brief Called by the base class to inform deriving classes that a new surface has been set.
283 * @param[in] surface The new render surface
285 virtual void OnSurfaceSet(Dali::RenderSurfaceInterface* surface){};
288 * @brief Called by the base class to inform deriving classes that we are being paused.
290 virtual void OnPause(){};
293 * @brief Called by the base class to inform deriving classes that we are resuming from a paused state.
295 virtual void OnResume(){};
298 * Recalculate the touch position if required
299 * @param[in,out] point The touch point
301 virtual void RecalculateTouchPosition(Integration::Point& point){};
305 * Resets the event handling.
310 * Initializes the DPI for this object.
312 void InitializeDpi();
315 static uint32_t mSceneHolderCounter; ///< A counter to track the SceneHolder creation
317 class SceneHolderLifeCycleObserver;
318 std::unique_ptr<SceneHolderLifeCycleObserver> mLifeCycleObserver; ///< The adaptor life cycle observer
321 uint32_t mId; ///< A unique ID to identify the SceneHolder starting from 0
322 Dali::Integration::Scene mScene; ///< The Scene
323 std::string mName; ///< The name of the SceneHolder
325 std::unique_ptr<Dali::RenderSurfaceInterface> mSurface; ///< The window rendering surface
326 Adaptor* mAdaptor; ///< The adaptor
328 Dali::Integration::TouchEventCombiner mCombiner; ///< Combines multi-touch events.
330 Uint16Pair mDpi; ///< The DPI for this SceneHolder.
332 std::atomic<bool> mIsBeingDeleted; ///< This is set only from the event thread and read only from the render thread
334 bool mAdaptorStarted : 1; ///< Whether the adaptor has started or not
335 bool mVisible : 1; ///< Whether the scene is visible or not
338 } // namespace Adaptor
340 } // namespace Internal
342 // Get impl of handle
343 inline Internal::Adaptor::SceneHolder& GetImplementation(Dali::Integration::SceneHolder& sceneHolder)
345 DALI_ASSERT_ALWAYS(sceneHolder && "SceneHolder handle is empty");
346 Dali::RefObject& object = sceneHolder.GetBaseObject();
347 return static_cast<Internal::Adaptor::SceneHolder&>(object);
350 inline const Internal::Adaptor::SceneHolder& GetImplementation(const Dali::Integration::SceneHolder& sceneHolder)
352 DALI_ASSERT_ALWAYS(sceneHolder && "SceneHolder handle is empty");
353 const Dali::RefObject& object = sceneHolder.GetBaseObject();
354 return static_cast<const Internal::Adaptor::SceneHolder&>(object);
359 #endif // DALI_INTEGRATION_INTERNAL_SCENEHOLDER_H