1 #ifndef DALI_INTEGRATION_INTERNAL_SCENEHOLDER_H
2 #define DALI_INTEGRATION_INTERNAL_SCENEHOLDER_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.
25 #include <dali/public-api/object/base-object.h>
26 #include <dali/public-api/common/intrusive-ptr.h>
27 #include <dali/integration-api/scene.h>
28 #include <dali/integration-api/events/key-event-integ.h>
29 #include <dali/integration-api/events/point.h>
30 #include <dali/integration-api/events/touch-event-combiner.h>
33 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
34 #include <dali/integration-api/adaptor-framework/scene-holder.h>
65 using SceneHolderPtr = IntrusivePtr< SceneHolder >;
68 * @brief SceneHolder creates a Scene for rendering.
70 class DALI_ADAPTOR_API SceneHolder : public BaseObject
76 * @copydoc Dali::Integration::SceneHolder::Add
78 void Add( Dali::Actor actor );
81 * @copydoc Dali::Integration::SceneHolder::Remove
83 void Remove( Dali::Actor actor );
86 * @copydoc Dali::Integration::SceneHolder::GetRootLayer
88 Dali::Layer GetRootLayer() const;
91 * @brief Gets the window name.
92 * @return The name of the window
94 std::string GetName() const;
97 * @brief Retrieve the unique ID of the window.
100 uint32_t GetId() const;
103 * @brief Retrieve the Scene.
106 Dali::Integration::Scene GetScene();
109 * @brief Set the render surface
110 * @param[in] surface The render surface
112 void SetSurface( Dali::RenderSurfaceInterface* surface );
115 * @brief Called when the surface set is resized.
117 void SurfaceResized();
120 * @brief Get the render surface
121 * @return The render surface
123 Dali::RenderSurfaceInterface* GetSurface() const;
126 * @brief Set the adaptor to the scene holder
127 * @param[in] adaptor An initialized adaptor
129 void SetAdaptor( Dali::Adaptor& adaptor );
132 * @copydoc Dali::Integration::SceneHolder::SetBackgroundColor
134 void SetBackgroundColor( const Dali::Vector4& color );
137 * @copydoc Dali::Integration::SceneHolder::GetBackgroundColor
139 Vector4 GetBackgroundColor() const;
142 * @brief Pause the rendering of the scene holder.
147 * @brief Resume the rendering of the scene holder (from pause).
152 * @brief Checks whether this scene holder is being deleted in the event thread.
154 * @return true if this scene holder is being deleted in the event thread, or false if not.
156 bool IsBeingDeleted() const { return mIsBeingDeleted; }
159 * @copydoc Dali::Integration::SceneHolder::FeedTouchPoint
161 void FeedTouchPoint( Dali::Integration::Point& point, int timeStamp );
164 * @copydoc Dali::Integration::SceneHolder::FeedWheelEvent
166 void FeedWheelEvent( Dali::Integration::WheelEvent& wheelEvent );
169 * @copydoc Dali::Integration::SceneHolder::FeedKeyEvent
171 void FeedKeyEvent( Dali::Integration::KeyEvent& keyEvent );
174 * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
176 * @param[in] callback The function to call
177 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
179 * @note A callback of the following type may be used:
181 * void MyFunction( int frameId );
183 * This callback will be deleted once it is called.
185 * @note Ownership of the callback is passed onto this class.
187 void AddFrameRenderedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
190 * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
192 * @param[in] callback The function to call
193 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
195 * @note A callback of the following type may be used:
197 * void MyFunction( int frameId );
199 * This callback will be deleted once it is called.
201 * @note Ownership of the callback is passed onto this class.
203 void AddFramePresentedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
206 * @copydoc Dali::Integration::SceneHolder::Get()
208 static Dali::Integration::SceneHolder Get( Dali::Actor actor );
211 * @copydoc Dali::Integration::SceneHolder::KeyEventSignal()
213 Dali::Integration::SceneHolder::KeyEventSignalType& KeyEventSignal() { return mScene.KeyEventSignal(); }
216 * @copydoc Dali::Integration::SceneHolder::KeyEventGeneratedSignal()
218 Dali::Integration::SceneHolder::KeyEventGeneratedSignalType& KeyEventGeneratedSignal() { return mScene.KeyEventGeneratedSignal(); }
221 * @copydoc Dali::Integration::SceneHolder::TouchSignal()
223 Dali::Integration::SceneHolder::TouchSignalType& TouchSignal() { return mScene.TouchSignal(); }
226 * @copydoc Dali::Integration::SceneHolder::WheelEventSignal()
228 Dali::Integration::SceneHolder::WheelEventSignalType& WheelEventSignal() { return mScene.WheelEventSignal(); }
230 public: // The following methods can be overridden if required
233 * @brief Returns whether the Scene is visible or not.
234 * @return True if the Scene is visible, false otherwise.
236 virtual bool IsVisible() const;
238 public: // The following methods must be overridden
241 * @copydoc Dali::Integration::SceneHolder::GetNativeHandle
243 virtual Dali::Any GetNativeHandle() const = 0;
251 SceneHolder(const SceneHolder&) = delete;
254 SceneHolder& operator=(const SceneHolder& rhs) = delete;
259 virtual ~SceneHolder();
261 private: // The following methods can be overridden if required
264 * @brief Called by the base class to inform deriving classes that the adaptor has been set.
265 * @param[in] adaptor The adaptor
267 virtual void OnAdaptorSet( Dali::Adaptor& adaptor ) {};
270 * @brief Called by the base class to inform deriving classes that a new surface has been set.
271 * @param[in] surface The new render surface
273 virtual void OnSurfaceSet( Dali::RenderSurfaceInterface* surface ) {};
276 * @brief Called by the base class to inform deriving classes that we are being paused.
278 virtual void OnPause() {};
281 * @brief Called by the base class to inform deriving classes that we are resuming from a paused state.
283 virtual void OnResume() {};
286 * Recalculate the touch position if required
287 * @param[in,out] point The touch point
289 virtual void RecalculateTouchPosition( Integration::Point& point ) {};
294 * Resets the event handling.
300 static uint32_t mSceneHolderCounter; ///< A counter to track the SceneHolder creation
302 class SceneHolderLifeCycleObserver;
303 std::unique_ptr< SceneHolderLifeCycleObserver > mLifeCycleObserver; ///< The adaptor life cycle observer
307 uint32_t mId; ///< A unique ID to identify the SceneHolder starting from 0
308 Dali::Integration::Scene mScene; ///< The Scene
309 std::string mName; ///< The name of the SceneHolder
311 std::unique_ptr< Dali::RenderSurfaceInterface > mSurface; ///< The window rendering surface
312 Adaptor* mAdaptor; ///< The adaptor
314 Dali::Integration::TouchEventCombiner mCombiner; ///< Combines multi-touch events.
316 std::atomic<bool> mIsBeingDeleted; ///< This is set only from the event thread and read only from the render thread
318 bool mAdaptorStarted:1; ///< Whether the adaptor has started or not
319 bool mVisible:1; ///< Whether the scene is visible or not
326 // Get impl of handle
327 inline Internal::Adaptor::SceneHolder& GetImplementation( Dali::Integration::SceneHolder& sceneHolder )
329 DALI_ASSERT_ALWAYS( sceneHolder && "SceneHolder handle is empty" );
330 Dali::RefObject& object = sceneHolder.GetBaseObject();
331 return static_cast<Internal::Adaptor::SceneHolder&>( object );
334 inline const Internal::Adaptor::SceneHolder& GetImplementation( const Dali::Integration::SceneHolder& sceneHolder )
336 DALI_ASSERT_ALWAYS( sceneHolder && "SceneHolder handle is empty" );
337 const Dali::RefObject& object = sceneHolder.GetBaseObject();
338 return static_cast<const Internal::Adaptor::SceneHolder&>( object );
343 #endif // DALI_INTEGRATION_INTERNAL_SCENEHOLDER_H