[Tizen] Add screen and client rotation itself function
[platform/core/uifw/dali-adaptor.git] / dali / integration-api / adaptor-framework / scene-holder-impl.h
1 #ifndef DALI_INTEGRATION_INTERNAL_SCENEHOLDER_H
2 #define DALI_INTEGRATION_INTERNAL_SCENEHOLDER_H
3
4 /*
5  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <memory>
23 #include <vector>
24 #include <dali/public-api/object/base-object.h>
25 #include <dali/public-api/common/intrusive-ptr.h>
26 #include <dali/integration-api/scene.h>
27 #include <dali/integration-api/events/key-event-integ.h>
28 #include <dali/integration-api/events/point.h>
29 #include <dali/integration-api/events/touch-event-combiner.h>
30
31 // INTERNAL INCLUDES
32 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
33 #include <dali/integration-api/adaptor-framework/scene-holder.h>
34
35 namespace Dali
36 {
37
38 class Any;
39 class Adaptor;
40 class Actor;
41 class Layer;
42 struct TouchPoint;
43 struct WheelEvent;
44 struct KeyEvent;
45
46 namespace Integration
47 {
48
49 class Scene;
50 struct Point;
51 struct KeyEvent;
52 struct WheelEvent;
53
54 }
55
56 namespace Internal
57 {
58
59 namespace Adaptor
60 {
61
62 class Adaptor;
63 class SceneHolder;
64 using SceneHolderPtr = IntrusivePtr< SceneHolder >;
65
66 /**
67  * @brief SceneHolder creates a Scene for rendering.
68  */
69 class DALI_ADAPTOR_API SceneHolder : public BaseObject
70 {
71
72 public:
73
74   /**
75    * @copydoc Dali::Integration::SceneHolder::Add
76    */
77   void Add( Dali::Actor actor );
78
79   /**
80    * @copydoc Dali::Integration::SceneHolder::Remove
81    */
82   void Remove( Dali::Actor actor );
83
84   /**
85    * @copydoc Dali::Integration::SceneHolder::GetRootLayer
86    */
87   Dali::Layer GetRootLayer() const;
88
89   /**
90    * @brief Gets the window name.
91    * @return The name of the window
92    */
93   std::string GetName() const;
94
95   /**
96    * @brief Retrieve the unique ID of the window.
97    * @return The ID
98    */
99   uint32_t GetId() const;
100
101   /**
102    * @brief Retrieve the Scene.
103    * @return The Scene
104    */
105   Dali::Integration::Scene GetScene();
106
107   /**
108    * @brief Set the render surface
109    * @param[in] surface The render surface
110    */
111   void SetSurface( Dali::RenderSurfaceInterface* surface );
112
113   /**
114    * @brief Called when the surface is resized.
115    * @param[in] forceUpdate The flag to update force
116    */
117   void SurfaceResized( bool forceUpdate );
118
119   /**
120    * @brief Get the render surface
121    * @return The render surface
122    */
123   Dali::RenderSurfaceInterface* GetSurface() const;
124
125   /**
126    * @brief Set the adaptor to the scene holder
127    * @param[in] adaptor An initialized adaptor
128    */
129   void SetAdaptor( Dali::Adaptor& adaptor );
130
131   /**
132    * @copydoc Dali::Integration::SceneHolder::SetBackgroundColor
133    */
134   void SetBackgroundColor( const Dali::Vector4& color );
135
136   /**
137    * @copydoc Dali::Integration::SceneHolder::GetBackgroundColor
138    */
139   Vector4 GetBackgroundColor() const;
140
141   /**
142    * @brief Pause the rendering of the scene holder.
143    */
144   void Pause();
145
146   /**
147    * @brief Resume the rendering of the scene holder (from pause).
148    */
149   void Resume();
150
151   /**
152    * @copydoc Dali::Integration::SceneHolder::FeedTouchPoint
153    */
154   void FeedTouchPoint( Dali::Integration::Point& point, int timeStamp );
155
156   /**
157    * @copydoc Dali::Integration::SceneHolder::FeedWheelEvent
158    */
159   void FeedWheelEvent( Dali::Integration::WheelEvent& wheelEvent );
160
161   /**
162    * @copydoc Dali::Integration::SceneHolder::FeedKeyEvent
163    */
164   void FeedKeyEvent( Dali::Integration::KeyEvent& keyEvent );
165
166   /**
167    * @copydoc Dali::Integration::SceneHolder::Get()
168    */
169   static Dali::Integration::SceneHolder Get( Dali::Actor actor );
170
171   /**
172    * @copydoc Dali::Integration::SceneHolder::KeyEventSignal()
173    */
174   Dali::Integration::SceneHolder::KeyEventSignalType& KeyEventSignal() { return mScene.KeyEventSignal(); }
175
176   /**
177    * @copydoc Dali::Integration::SceneHolder::KeyEventGeneratedSignal()
178    */
179   Dali::Integration::SceneHolder::KeyEventGeneratedSignalType& KeyEventGeneratedSignal() { return mScene.KeyEventGeneratedSignal(); }
180
181   /**
182    * @copydoc Dali::Integration::SceneHolder::TouchSignal()
183    */
184   Dali::Integration::SceneHolder::TouchSignalType& TouchSignal() { return mScene.TouchSignal(); }
185
186   /**
187    * @copydoc Dali::Integration::SceneHolder::WheelEventSignal()
188    */
189   Dali::Integration::SceneHolder::WheelEventSignalType& WheelEventSignal() { return mScene.WheelEventSignal(); }
190
191 public: // The following methods can be overridden if required
192
193   /**
194    * @brief Returns whether the Scene is visible or not.
195    * @return True if the Scene is visible, false otherwise.
196    */
197   virtual bool IsVisible() const;
198
199 public: // The following methods must be overridden
200
201   /**
202    * @copydoc Dali::Integration::SceneHolder::GetNativeHandle
203    */
204   virtual Dali::Any GetNativeHandle() const = 0;
205
206 protected:
207
208   // Constructor
209   SceneHolder();
210
211   // Undefined
212   SceneHolder(const SceneHolder&) = delete;
213
214   // Undefined
215   SceneHolder& operator=(const SceneHolder& rhs) = delete;
216
217   /**
218    * virtual destructor
219    */
220   virtual ~SceneHolder();
221
222 private: // The following methods can be overridden if required
223
224   /**
225    * @brief Called by the base class to inform deriving classes that the adaptor has been set.
226    * @param[in] adaptor The adaptor
227    */
228   virtual void OnAdaptorSet( Dali::Adaptor& adaptor ) {};
229
230   /**
231    * @brief Called by the base class to inform deriving classes that a new surface has been set.
232    * @param[in] surface The new render surface
233    */
234   virtual void OnSurfaceSet( Dali::RenderSurfaceInterface* surface ) {};
235
236   /**
237    * @brief Called by the base class to inform deriving classes that we are being paused.
238    */
239   virtual void OnPause() {};
240
241   /**
242    * @brief Called by the base class to inform deriving classes that we are resuming from a paused state.
243    */
244   virtual void OnResume() {};
245
246   /**
247    * Recalculate the touch position if required
248    * @param[in,out] point The touch point
249    */
250   virtual void RecalculateTouchPosition( Integration::Point& point ) {};
251
252 private:
253
254   /**
255    * Resets the event handling.
256    */
257   void Reset();
258
259 private:
260
261   static uint32_t                                 mSceneHolderCounter; ///< A counter to track the SceneHolder creation
262
263   class SceneHolderLifeCycleObserver;
264   std::unique_ptr< SceneHolderLifeCycleObserver > mLifeCycleObserver;  ///< The adaptor life cycle observer
265
266 protected:
267
268   uint32_t                                        mId;                 ///< A unique ID to identify the SceneHolder starting from 0
269   Dali::Integration::Scene                        mScene;              ///< The Scene
270   std::string                                     mName;               ///< The name of the SceneHolder
271
272   std::unique_ptr< Dali::RenderSurfaceInterface > mSurface;            ///< The window rendering surface
273   Adaptor*                                        mAdaptor;            ///< The adaptor
274
275   Dali::Integration::TouchEventCombiner           mCombiner;           ///< Combines multi-touch events.
276
277   bool                                            mAdaptorStarted:1;   ///< Whether the adaptor has started or not
278   bool                                            mVisible:1;          ///< Whether the scene is visible or not
279 };
280
281 } // Adaptor
282
283 } // Internal
284
285 // Get impl of handle
286 inline Internal::Adaptor::SceneHolder& GetImplementation( Dali::Integration::SceneHolder& sceneHolder )
287 {
288   DALI_ASSERT_ALWAYS( sceneHolder && "SceneHolder handle is empty" );
289   Dali::RefObject& object = sceneHolder.GetBaseObject();
290   return static_cast<Internal::Adaptor::SceneHolder&>( object );
291 }
292
293 inline const Internal::Adaptor::SceneHolder& GetImplementation( const Dali::Integration::SceneHolder& sceneHolder )
294 {
295   DALI_ASSERT_ALWAYS( sceneHolder && "SceneHolder handle is empty" );
296   const Dali::RefObject& object = sceneHolder.GetBaseObject();
297   return static_cast<const Internal::Adaptor::SceneHolder&>( object );
298 }
299
300 } // Dali
301
302 #endif // DALI_INTEGRATION_INTERNAL_SCENEHOLDER_H