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.
25 #include <dali/public-api/object/base-object.h>
26 #include <dali/public-api/common/intrusive-ptr.h>
27 #include <dali/public-api/math/uint-16-pair.h>
28 #include <dali/integration-api/scene.h>
29 #include <dali/integration-api/events/key-event-integ.h>
30 #include <dali/integration-api/events/point.h>
31 #include <dali/integration-api/events/touch-event-combiner.h>
34 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
35 #include <dali/integration-api/adaptor-framework/scene-holder.h>
66 using SceneHolderPtr = IntrusivePtr< SceneHolder >;
69 * @brief SceneHolder creates a Scene for rendering.
71 class DALI_ADAPTOR_API SceneHolder : public BaseObject
77 * @copydoc Dali::Integration::SceneHolder::Add
79 void Add( Dali::Actor actor );
82 * @copydoc Dali::Integration::SceneHolder::Remove
84 void Remove( Dali::Actor actor );
87 * @copydoc Dali::Integration::SceneHolder::GetRootLayer
89 Dali::Layer GetRootLayer() const;
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 is resized.
123 * @param[in] forceUpdate The flag to update force
125 void SurfaceResized( bool forceUpdate );
128 * @brief Get the render surface
129 * @return The render surface
131 Dali::RenderSurfaceInterface* GetSurface() const;
134 * @brief Set the adaptor to the scene holder
135 * @param[in] adaptor An initialized adaptor
137 void SetAdaptor( Dali::Adaptor& adaptor );
140 * @copydoc Dali::Integration::SceneHolder::SetBackgroundColor
142 void SetBackgroundColor( const Dali::Vector4& color );
145 * @copydoc Dali::Integration::SceneHolder::GetBackgroundColor
147 Vector4 GetBackgroundColor() const;
150 * @brief Pause the rendering of the scene holder.
155 * @brief Resume the rendering of the scene holder (from pause).
160 * @brief Checks whether this scene holder is being deleted in the event thread.
162 * @return true if this scene holder is being deleted in the event thread, or false if not.
164 bool IsBeingDeleted() const { return mIsBeingDeleted; }
167 * @copydoc Dali::Integration::SceneHolder::FeedTouchPoint
169 void FeedTouchPoint( Dali::Integration::Point& point, int timeStamp );
172 * @copydoc Dali::Integration::SceneHolder::FeedWheelEvent
174 void FeedWheelEvent( Dali::Integration::WheelEvent& wheelEvent );
177 * @copydoc Dali::Integration::SceneHolder::FeedKeyEvent
179 void FeedKeyEvent( Dali::Integration::KeyEvent& keyEvent );
182 * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
184 * @param[in] callback The function to call
185 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
187 * @note A callback of the following type may be used:
189 * void MyFunction( int frameId );
191 * This callback will be deleted once it is called.
193 * @note Ownership of the callback is passed onto this class.
195 void AddFrameRenderedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
198 * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
200 * @param[in] callback The function to call
201 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
203 * @note A callback of the following type may be used:
205 * void MyFunction( int frameId );
207 * This callback will be deleted once it is called.
209 * @note Ownership of the callback is passed onto this class.
211 void AddFramePresentedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
214 * @copydoc Dali::Integration::SceneHolder::Get()
216 static Dali::Integration::SceneHolder Get( Dali::Actor actor );
219 * @copydoc Dali::Integration::SceneHolder::KeyEventSignal()
221 Dali::Integration::SceneHolder::KeyEventSignalType& KeyEventSignal() { return mScene.KeyEventSignal(); }
224 * @copydoc Dali::Integration::SceneHolder::KeyEventGeneratedSignal()
226 Dali::Integration::SceneHolder::KeyEventGeneratedSignalType& KeyEventGeneratedSignal() { return mScene.KeyEventGeneratedSignal(); }
229 * @copydoc Dali::Integration::SceneHolder::TouchSignal()
231 Dali::Integration::SceneHolder::TouchSignalType& TouchSignal() { return mScene.TouchSignal(); }
234 * @copydoc Dali::Integration::SceneHolder::WheelEventSignal()
236 Dali::Integration::SceneHolder::WheelEventSignalType& WheelEventSignal() { return mScene.WheelEventSignal(); }
238 public: // The following methods can be overridden if required
241 * @brief Returns whether the Scene is visible or not.
242 * @return True if the Scene is visible, false otherwise.
244 virtual bool IsVisible() const;
246 public: // The following methods must be overridden
249 * @copydoc Dali::Integration::SceneHolder::GetNativeHandle
251 virtual Dali::Any GetNativeHandle() const = 0;
259 SceneHolder(const SceneHolder&) = delete;
262 SceneHolder& operator=(const SceneHolder& rhs) = delete;
267 virtual ~SceneHolder();
269 private: // The following methods can be overridden if required
272 * @brief Called by the base class to inform deriving classes that the adaptor has been set.
273 * @param[in] adaptor The adaptor
275 virtual void OnAdaptorSet( Dali::Adaptor& adaptor ) {};
278 * @brief Called by the base class to inform deriving classes that a new surface has been set.
279 * @param[in] surface The new render surface
281 virtual void OnSurfaceSet( Dali::RenderSurfaceInterface* surface ) {};
284 * @brief Called by the base class to inform deriving classes that we are being paused.
286 virtual void OnPause() {};
289 * @brief Called by the base class to inform deriving classes that we are resuming from a paused state.
291 virtual void OnResume() {};
294 * Recalculate the touch position if required
295 * @param[in,out] point The touch point
297 virtual void RecalculateTouchPosition( Integration::Point& point ) {};
302 * Resets the event handling.
307 * Initializes the DPI for this object.
309 void InitializeDpi();
313 static uint32_t mSceneHolderCounter; ///< A counter to track the SceneHolder creation
315 class SceneHolderLifeCycleObserver;
316 std::unique_ptr< SceneHolderLifeCycleObserver > mLifeCycleObserver; ///< The adaptor life cycle observer
320 uint32_t mId; ///< A unique ID to identify the SceneHolder starting from 0
321 Dali::Integration::Scene mScene; ///< The Scene
322 std::string mName; ///< The name of the SceneHolder
324 std::unique_ptr< Dali::RenderSurfaceInterface > mSurface; ///< The window rendering surface
325 Adaptor* mAdaptor; ///< The adaptor
327 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
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