d720f7fa06601bc36f161ac48ee760e8c5f2bef2
[platform/core/uifw/dali-adaptor.git] / dali / integration-api / 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 <dali/public-api/object/base-object.h>
24 #include <dali/public-api/common/intrusive-ptr.h>
25
26 // INTERNAL INCLUDES
27 #include <dali/integration-api/scene-holder.h>
28 #include <dali/integration-api/scene.h>
29
30 #ifdef DALI_ADAPTOR_COMPILATION
31 #include <dali/integration-api/render-surface-interface.h>
32 #else
33 #include <dali/integration-api/adaptors/render-surface-interface.h>
34 #endif
35
36 #include <dali/internal/adaptor/common/adaptor-impl.h>
37
38 namespace Dali
39 {
40
41 class Any;
42 class Adaptor;
43 class Actor;
44 class Layer;
45 struct TouchPoint;
46 struct WheelEvent;
47 struct KeyEvent;
48
49 namespace Integration
50 {
51
52 class Scene;
53
54 }
55
56 namespace Internal
57 {
58
59 namespace Adaptor
60 {
61
62 class SceneHolder;
63 using SceneHolderPtr = IntrusivePtr< SceneHolder >;
64
65 /**
66  * @brief SceneHolder creates a Scene for rendering.
67  */
68 class SceneHolder : public BaseObject
69 {
70
71 public:
72
73   /**
74    * @copydoc Dali::Integration::SceneHolder::Add
75    */
76   void Add( Dali::Actor actor );
77
78   /**
79    * @copydoc Dali::Integration::SceneHolder::Remove
80    */
81   void Remove( Dali::Actor actor );
82
83   /**
84    * @copydoc Dali::Integration::SceneHolder::GetRootLayer
85    */
86   Dali::Layer GetRootLayer() const;
87
88   /**
89    * @brief Gets the window name.
90    * @return The name of the window
91    */
92   std::string GetName() const;
93
94   /**
95    * @brief Retrieve the unique ID of the window.
96    * @return The ID
97    */
98   uint32_t GetId() const;
99
100   /**
101    * @brief Retrieve the Scene.
102    * @return The Scene
103    */
104   Dali::Integration::Scene GetScene();
105
106   /**
107    * @brief Set the render surface
108    * @param[in] surface The render surface
109    */
110   void SetSurface( Dali::RenderSurfaceInterface* surface );
111
112   /**
113    * @brief Get the render surface
114    * @return The render surface
115    */
116   Dali::RenderSurfaceInterface* GetSurface() const;
117
118   /**
119    * @brief Set the adaptor to the scene holder
120    * @param[in] adaptor An initialized adaptor
121    */
122   void SetAdaptor( Dali::Adaptor& adaptor );
123
124   /**
125    * @copydoc Dali::Integration::SceneHolder::SetBackgroundColor
126    */
127   void SetBackgroundColor( Dali::Vector4 color );
128
129   /**
130    * @copydoc Dali::Integration::SceneHolder::GetBackgroundColor
131    */
132   Vector4 GetBackgroundColor() const;
133
134   /**
135    * @brief Pause the rendering of the scene holder.
136    */
137   void Pause();
138
139   /**
140    * @brief Resume the rendering of the scene holder (from pause).
141    */
142   void Resume();
143
144 public: // The following methods can be overridden if required
145
146   /**
147    * @brief Returns whether the Scene is visible or not.
148    * @return True if the Scene is visible, false otherwise.
149    */
150   virtual bool IsVisible() const;
151
152 public: // The following methods must be overridden
153
154   /**
155    * @copydoc Dali::Integration::SceneHolder::GetNativeHandle
156    */
157   virtual Dali::Any GetNativeHandle() const = 0;
158
159   /**
160    * @copydoc Dali::Integration::SceneHolder::FeedTouchPoint
161    */
162   virtual void FeedTouchPoint( Dali::TouchPoint& point, int timeStamp ) = 0;
163
164   /**
165    * @copydoc Dali::Integration::SceneHolder::FeedWheelEvent
166    */
167   virtual void FeedWheelEvent( Dali::WheelEvent& wheelEvent ) = 0;
168
169   /**
170    * @copydoc Dali::Integration::SceneHolder::FeedKeyEvent
171    */
172   virtual void FeedKeyEvent( Dali::KeyEvent& keyEvent ) = 0;
173
174 protected:
175
176   // Constructor
177   SceneHolder();
178
179   // Undefined
180   SceneHolder(const SceneHolder&) = delete;
181
182   // Undefined
183   SceneHolder& operator=(const SceneHolder& rhs) = delete;
184
185   /**
186    * virtual destructor
187    */
188   virtual ~SceneHolder();
189
190 private: // The following methods can be overridden if required
191
192   /**
193    * @brief Called by the base class to inform deriving classes that the adaptor has been set.
194    * @param[in] adaptor The adaptor
195    */
196   virtual void OnAdaptorSet( Dali::Adaptor& adaptor ) {};
197
198   /**
199    * @brief Called by the base class to inform deriving classes that a new surface has been set.
200    * @param[in] surface The new render surface
201    */
202   virtual void OnSurfaceSet( Dali::RenderSurfaceInterface* surface ) {};
203
204   /**
205    * @brief Called by the base class to inform deriving classes that we are being paused.
206    */
207   virtual void OnPause() {};
208
209   /**
210    * @brief Called by the base class to inform deriving classes that we are resuming from a paused state.
211    */
212   virtual void OnResume() {};
213
214 private:
215
216   static uint32_t                                 mSceneHolderCounter; ///< A counter to track the SceneHolder creation
217
218   class SceneHolderLifeCycleObserver;
219   std::unique_ptr< SceneHolderLifeCycleObserver > mLifeCycleObserver;  ///< The adaptor life cycle observer
220
221 protected:
222
223   uint32_t                                        mId;                 ///< A unique ID to identify the SceneHolder starting from 0
224   Dali::Integration::Scene                        mScene;              ///< The Scene
225   std::string                                     mName;               ///< The name of the SceneHolder
226
227   std::unique_ptr< Dali::RenderSurfaceInterface > mSurface;            ///< The window rendering surface
228   Adaptor*                                        mAdaptor;            ///< The adaptor
229
230   bool                                            mAdaptorStarted:1;   ///< Whether the adaptor has started or not
231   bool                                            mVisible:1;          ///< Whether the scene is visible or not
232 };
233
234 } // Adaptor
235
236 } // Internal
237
238 // Get impl of handle
239 inline Internal::Adaptor::SceneHolder& GetImplementation( Dali::Integration::SceneHolder& sceneHolder )
240 {
241   DALI_ASSERT_ALWAYS( sceneHolder && "SceneHolder handle is empty" );
242   Dali::RefObject& object = sceneHolder.GetBaseObject();
243   return static_cast<Internal::Adaptor::SceneHolder&>( object );
244 }
245
246 inline const Internal::Adaptor::SceneHolder& GetImplementation( const Dali::Integration::SceneHolder& sceneHolder )
247 {
248   DALI_ASSERT_ALWAYS( sceneHolder && "SceneHolder handle is empty" );
249   const Dali::RefObject& object = sceneHolder.GetBaseObject();
250   return static_cast<const Internal::Adaptor::SceneHolder&>( object );
251 }
252
253 } // Dali
254
255 #endif // DALI_INTEGRATION_INTERNAL_SCENEHOLDER_H