Revert "[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 <atomic>
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>
31
32 // INTERNAL INCLUDES
33 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
34 #include <dali/integration-api/adaptor-framework/scene-holder.h>
35
36 namespace Dali
37 {
38
39 class Any;
40 class Adaptor;
41 class Actor;
42 class Layer;
43 struct TouchPoint;
44 struct WheelEvent;
45 struct KeyEvent;
46
47 namespace Integration
48 {
49
50 class Scene;
51 struct Point;
52 struct KeyEvent;
53 struct WheelEvent;
54
55 }
56
57 namespace Internal
58 {
59
60 namespace Adaptor
61 {
62
63 class Adaptor;
64 class SceneHolder;
65 using SceneHolderPtr = IntrusivePtr< SceneHolder >;
66
67 /**
68  * @brief SceneHolder creates a Scene for rendering.
69  */
70 class DALI_ADAPTOR_API SceneHolder : public BaseObject
71 {
72
73 public:
74
75   /**
76    * @copydoc Dali::Integration::SceneHolder::Add
77    */
78   void Add( Dali::Actor actor );
79
80   /**
81    * @copydoc Dali::Integration::SceneHolder::Remove
82    */
83   void Remove( Dali::Actor actor );
84
85   /**
86    * @copydoc Dali::Integration::SceneHolder::GetRootLayer
87    */
88   Dali::Layer GetRootLayer() const;
89
90   /**
91    * @brief Gets the window name.
92    * @return The name of the window
93    */
94   std::string GetName() const;
95
96   /**
97    * @brief Retrieve the unique ID of the window.
98    * @return The ID
99    */
100   uint32_t GetId() const;
101
102   /**
103    * @brief Retrieve the Scene.
104    * @return The Scene
105    */
106   Dali::Integration::Scene GetScene();
107
108   /**
109    * @brief Set the render surface
110    * @param[in] surface The render surface
111    */
112   void SetSurface( Dali::RenderSurfaceInterface* surface );
113
114   /**
115    * @brief Called when the surface set is resized.
116    */
117   void SurfaceResized();
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    * @brief Checks whether this scene holder is being deleted in the event thread.
153    *
154    * @return true if this scene holder is being deleted in the event thread, or false if not.
155    */
156   bool IsBeingDeleted() const { return mIsBeingDeleted; }
157
158   /**
159    * @copydoc Dali::Integration::SceneHolder::FeedTouchPoint
160    */
161   void FeedTouchPoint( Dali::Integration::Point& point, int timeStamp );
162
163   /**
164    * @copydoc Dali::Integration::SceneHolder::FeedWheelEvent
165    */
166   void FeedWheelEvent( Dali::Integration::WheelEvent& wheelEvent );
167
168   /**
169    * @copydoc Dali::Integration::SceneHolder::FeedKeyEvent
170    */
171   void FeedKeyEvent( Dali::Integration::KeyEvent& keyEvent );
172
173   /**
174    * @copydoc Dali::Integration::SceneHolder::Get()
175    */
176   static Dali::Integration::SceneHolder Get( Dali::Actor actor );
177
178   /**
179    * @copydoc Dali::Integration::SceneHolder::KeyEventSignal()
180    */
181   Dali::Integration::SceneHolder::KeyEventSignalType& KeyEventSignal() { return mScene.KeyEventSignal(); }
182
183   /**
184    * @copydoc Dali::Integration::SceneHolder::KeyEventGeneratedSignal()
185    */
186   Dali::Integration::SceneHolder::KeyEventGeneratedSignalType& KeyEventGeneratedSignal() { return mScene.KeyEventGeneratedSignal(); }
187
188   /**
189    * @copydoc Dali::Integration::SceneHolder::TouchSignal()
190    */
191   Dali::Integration::SceneHolder::TouchSignalType& TouchSignal() { return mScene.TouchSignal(); }
192
193   /**
194    * @copydoc Dali::Integration::SceneHolder::WheelEventSignal()
195    */
196   Dali::Integration::SceneHolder::WheelEventSignalType& WheelEventSignal() { return mScene.WheelEventSignal(); }
197
198 public: // The following methods can be overridden if required
199
200   /**
201    * @brief Returns whether the Scene is visible or not.
202    * @return True if the Scene is visible, false otherwise.
203    */
204   virtual bool IsVisible() const;
205
206 public: // The following methods must be overridden
207
208   /**
209    * @copydoc Dali::Integration::SceneHolder::GetNativeHandle
210    */
211   virtual Dali::Any GetNativeHandle() const = 0;
212
213 protected:
214
215   // Constructor
216   SceneHolder();
217
218   // Undefined
219   SceneHolder(const SceneHolder&) = delete;
220
221   // Undefined
222   SceneHolder& operator=(const SceneHolder& rhs) = delete;
223
224   /**
225    * virtual destructor
226    */
227   virtual ~SceneHolder();
228
229 private: // The following methods can be overridden if required
230
231   /**
232    * @brief Called by the base class to inform deriving classes that the adaptor has been set.
233    * @param[in] adaptor The adaptor
234    */
235   virtual void OnAdaptorSet( Dali::Adaptor& adaptor ) {};
236
237   /**
238    * @brief Called by the base class to inform deriving classes that a new surface has been set.
239    * @param[in] surface The new render surface
240    */
241   virtual void OnSurfaceSet( Dali::RenderSurfaceInterface* surface ) {};
242
243   /**
244    * @brief Called by the base class to inform deriving classes that we are being paused.
245    */
246   virtual void OnPause() {};
247
248   /**
249    * @brief Called by the base class to inform deriving classes that we are resuming from a paused state.
250    */
251   virtual void OnResume() {};
252
253   /**
254    * Recalculate the touch position if required
255    * @param[in,out] point The touch point
256    */
257   virtual void RecalculateTouchPosition( Integration::Point& point ) {};
258
259 private:
260
261   /**
262    * Resets the event handling.
263    */
264   void Reset();
265
266 private:
267
268   static uint32_t                                 mSceneHolderCounter; ///< A counter to track the SceneHolder creation
269
270   class SceneHolderLifeCycleObserver;
271   std::unique_ptr< SceneHolderLifeCycleObserver > mLifeCycleObserver;  ///< The adaptor life cycle observer
272
273 protected:
274
275   uint32_t                                        mId;                 ///< A unique ID to identify the SceneHolder starting from 0
276   Dali::Integration::Scene                        mScene;              ///< The Scene
277   std::string                                     mName;               ///< The name of the SceneHolder
278
279   std::unique_ptr< Dali::RenderSurfaceInterface > mSurface;            ///< The window rendering surface
280   Adaptor*                                        mAdaptor;            ///< The adaptor
281
282   Dali::Integration::TouchEventCombiner           mCombiner;           ///< Combines multi-touch events.
283
284   std::atomic<bool>                               mIsBeingDeleted;     ///< This is set only from the event thread and read only from the render thread
285
286   bool                                            mAdaptorStarted:1;   ///< Whether the adaptor has started or not
287   bool                                            mVisible:1;          ///< Whether the scene is visible or not
288 };
289
290 } // Adaptor
291
292 } // Internal
293
294 // Get impl of handle
295 inline Internal::Adaptor::SceneHolder& GetImplementation( Dali::Integration::SceneHolder& sceneHolder )
296 {
297   DALI_ASSERT_ALWAYS( sceneHolder && "SceneHolder handle is empty" );
298   Dali::RefObject& object = sceneHolder.GetBaseObject();
299   return static_cast<Internal::Adaptor::SceneHolder&>( object );
300 }
301
302 inline const Internal::Adaptor::SceneHolder& GetImplementation( const Dali::Integration::SceneHolder& sceneHolder )
303 {
304   DALI_ASSERT_ALWAYS( sceneHolder && "SceneHolder handle is empty" );
305   const Dali::RefObject& object = sceneHolder.GetBaseObject();
306   return static_cast<const Internal::Adaptor::SceneHolder&>( object );
307 }
308
309 } // Dali
310
311 #endif // DALI_INTEGRATION_INTERNAL_SCENEHOLDER_H