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 is resized.
116 * @param[in] forceUpdate The flag to update force
118 void SurfaceResized( bool forceUpdate );
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 { return mIsBeingDeleted; }
160 * @copydoc Dali::Integration::SceneHolder::FeedTouchPoint
162 void FeedTouchPoint( Dali::Integration::Point& point, int timeStamp );
165 * @copydoc Dali::Integration::SceneHolder::FeedWheelEvent
167 void FeedWheelEvent( Dali::Integration::WheelEvent& wheelEvent );
170 * @copydoc Dali::Integration::SceneHolder::FeedKeyEvent
172 void FeedKeyEvent( Dali::Integration::KeyEvent& keyEvent );
175 * @copydoc Dali::Integration::SceneHolder::Get()
177 static Dali::Integration::SceneHolder Get( Dali::Actor actor );
180 * @copydoc Dali::Integration::SceneHolder::KeyEventSignal()
182 Dali::Integration::SceneHolder::KeyEventSignalType& KeyEventSignal() { return mScene.KeyEventSignal(); }
185 * @copydoc Dali::Integration::SceneHolder::KeyEventGeneratedSignal()
187 Dali::Integration::SceneHolder::KeyEventGeneratedSignalType& KeyEventGeneratedSignal() { return mScene.KeyEventGeneratedSignal(); }
190 * @copydoc Dali::Integration::SceneHolder::TouchSignal()
192 Dali::Integration::SceneHolder::TouchSignalType& TouchSignal() { return mScene.TouchSignal(); }
195 * @copydoc Dali::Integration::SceneHolder::WheelEventSignal()
197 Dali::Integration::SceneHolder::WheelEventSignalType& WheelEventSignal() { return mScene.WheelEventSignal(); }
199 public: // The following methods can be overridden if required
202 * @brief Returns whether the Scene is visible or not.
203 * @return True if the Scene is visible, false otherwise.
205 virtual bool IsVisible() const;
207 public: // The following methods must be overridden
210 * @copydoc Dali::Integration::SceneHolder::GetNativeHandle
212 virtual Dali::Any GetNativeHandle() const = 0;
220 SceneHolder(const SceneHolder&) = delete;
223 SceneHolder& operator=(const SceneHolder& rhs) = delete;
228 virtual ~SceneHolder();
230 private: // The following methods can be overridden if required
233 * @brief Called by the base class to inform deriving classes that the adaptor has been set.
234 * @param[in] adaptor The adaptor
236 virtual void OnAdaptorSet( Dali::Adaptor& adaptor ) {};
239 * @brief Called by the base class to inform deriving classes that a new surface has been set.
240 * @param[in] surface The new render surface
242 virtual void OnSurfaceSet( Dali::RenderSurfaceInterface* surface ) {};
245 * @brief Called by the base class to inform deriving classes that we are being paused.
247 virtual void OnPause() {};
250 * @brief Called by the base class to inform deriving classes that we are resuming from a paused state.
252 virtual void OnResume() {};
255 * Recalculate the touch position if required
256 * @param[in,out] point The touch point
258 virtual void RecalculateTouchPosition( Integration::Point& point ) {};
263 * Resets the event handling.
269 static uint32_t mSceneHolderCounter; ///< A counter to track the SceneHolder creation
271 class SceneHolderLifeCycleObserver;
272 std::unique_ptr< SceneHolderLifeCycleObserver > mLifeCycleObserver; ///< The adaptor life cycle observer
276 uint32_t mId; ///< A unique ID to identify the SceneHolder starting from 0
277 Dali::Integration::Scene mScene; ///< The Scene
278 std::string mName; ///< The name of the SceneHolder
280 std::unique_ptr< Dali::RenderSurfaceInterface > mSurface; ///< The window rendering surface
281 Adaptor* mAdaptor; ///< The adaptor
283 Dali::Integration::TouchEventCombiner mCombiner; ///< Combines multi-touch events.
285 std::atomic<bool> mIsBeingDeleted; ///< This is set only from the event thread and read only from the render thread
287 bool mAdaptorStarted:1; ///< Whether the adaptor has started or not
288 bool mVisible:1; ///< Whether the scene is visible or not
295 // Get impl of handle
296 inline Internal::Adaptor::SceneHolder& GetImplementation( Dali::Integration::SceneHolder& sceneHolder )
298 DALI_ASSERT_ALWAYS( sceneHolder && "SceneHolder handle is empty" );
299 Dali::RefObject& object = sceneHolder.GetBaseObject();
300 return static_cast<Internal::Adaptor::SceneHolder&>( object );
303 inline const Internal::Adaptor::SceneHolder& GetImplementation( const Dali::Integration::SceneHolder& sceneHolder )
305 DALI_ASSERT_ALWAYS( sceneHolder && "SceneHolder handle is empty" );
306 const Dali::RefObject& object = sceneHolder.GetBaseObject();
307 return static_cast<const Internal::Adaptor::SceneHolder&>( object );
312 #endif // DALI_INTEGRATION_INTERNAL_SCENEHOLDER_H