Fix header inclusion in an integration api header
[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 <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
28 // INTERNAL INCLUDES
29
30 #ifdef DALI_ADAPTOR_COMPILATION
31 #include <dali/integration-api/render-surface-interface.h>
32 #include <dali/integration-api/scene-holder.h>
33 #else
34 #include <dali/integration-api/adaptors/render-surface-interface.h>
35 #include <dali/integration-api/adaptors/scene-holder.h>
36 #endif
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 Adaptor;
63 class SceneHolder;
64 using SceneHolderPtr = IntrusivePtr< SceneHolder >;
65
66 /**
67  * @brief SceneHolder creates a Scene for rendering.
68  */
69 class 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 Get the render surface
115    * @return The render surface
116    */
117   Dali::RenderSurfaceInterface* GetSurface() const;
118
119   /**
120    * @brief Set the adaptor to the scene holder
121    * @param[in] adaptor An initialized adaptor
122    */
123   void SetAdaptor( Dali::Adaptor& adaptor );
124
125   /**
126    * @copydoc Dali::Integration::SceneHolder::SetBackgroundColor
127    */
128   void SetBackgroundColor( const Dali::Vector4& color );
129
130   /**
131    * @copydoc Dali::Integration::SceneHolder::GetBackgroundColor
132    */
133   Vector4 GetBackgroundColor() const;
134
135   /**
136    * @brief Pause the rendering of the scene holder.
137    */
138   void Pause();
139
140   /**
141    * @brief Resume the rendering of the scene holder (from pause).
142    */
143   void Resume();
144
145 public: // The following methods can be overridden if required
146
147   /**
148    * @brief Returns whether the Scene is visible or not.
149    * @return True if the Scene is visible, false otherwise.
150    */
151   virtual bool IsVisible() const;
152
153 public: // The following methods must be overridden
154
155   /**
156    * @copydoc Dali::Integration::SceneHolder::GetNativeHandle
157    */
158   virtual Dali::Any GetNativeHandle() const = 0;
159
160   /**
161    * @copydoc Dali::Integration::SceneHolder::FeedTouchPoint
162    */
163   virtual void FeedTouchPoint( Dali::TouchPoint& point, int timeStamp ) = 0;
164
165   /**
166    * @copydoc Dali::Integration::SceneHolder::FeedWheelEvent
167    */
168   virtual void FeedWheelEvent( Dali::WheelEvent& wheelEvent ) = 0;
169
170   /**
171    * @copydoc Dali::Integration::SceneHolder::FeedKeyEvent
172    */
173   virtual void FeedKeyEvent( Dali::KeyEvent& keyEvent ) = 0;
174
175 protected:
176
177   // Constructor
178   SceneHolder();
179
180   // Undefined
181   SceneHolder(const SceneHolder&) = delete;
182
183   // Undefined
184   SceneHolder& operator=(const SceneHolder& rhs) = delete;
185
186   /**
187    * virtual destructor
188    */
189   virtual ~SceneHolder();
190
191 private: // The following methods can be overridden if required
192
193   /**
194    * @brief Called by the base class to inform deriving classes that the adaptor has been set.
195    * @param[in] adaptor The adaptor
196    */
197   virtual void OnAdaptorSet( Dali::Adaptor& adaptor ) {};
198
199   /**
200    * @brief Called by the base class to inform deriving classes that a new surface has been set.
201    * @param[in] surface The new render surface
202    */
203   virtual void OnSurfaceSet( Dali::RenderSurfaceInterface* surface ) {};
204
205   /**
206    * @brief Called by the base class to inform deriving classes that we are being paused.
207    */
208   virtual void OnPause() {};
209
210   /**
211    * @brief Called by the base class to inform deriving classes that we are resuming from a paused state.
212    */
213   virtual void OnResume() {};
214
215 private:
216
217   static uint32_t                                 mSceneHolderCounter; ///< A counter to track the SceneHolder creation
218
219   class SceneHolderLifeCycleObserver;
220   std::unique_ptr< SceneHolderLifeCycleObserver > mLifeCycleObserver;  ///< The adaptor life cycle observer
221
222 protected:
223
224   uint32_t                                        mId;                 ///< A unique ID to identify the SceneHolder starting from 0
225   Dali::Integration::Scene                        mScene;              ///< The Scene
226   std::string                                     mName;               ///< The name of the SceneHolder
227
228   std::unique_ptr< Dali::RenderSurfaceInterface > mSurface;            ///< The window rendering surface
229   Adaptor*                                        mAdaptor;            ///< The adaptor
230
231   bool                                            mAdaptorStarted:1;   ///< Whether the adaptor has started or not
232   bool                                            mVisible:1;          ///< Whether the scene is visible or not
233 };
234
235 } // Adaptor
236
237 } // Internal
238
239 // Get impl of handle
240 inline Internal::Adaptor::SceneHolder& GetImplementation( Dali::Integration::SceneHolder& sceneHolder )
241 {
242   DALI_ASSERT_ALWAYS( sceneHolder && "SceneHolder handle is empty" );
243   Dali::RefObject& object = sceneHolder.GetBaseObject();
244   return static_cast<Internal::Adaptor::SceneHolder&>( object );
245 }
246
247 inline const Internal::Adaptor::SceneHolder& GetImplementation( const Dali::Integration::SceneHolder& sceneHolder )
248 {
249   DALI_ASSERT_ALWAYS( sceneHolder && "SceneHolder handle is empty" );
250   const Dali::RefObject& object = sceneHolder.GetBaseObject();
251   return static_cast<const Internal::Adaptor::SceneHolder&>( object );
252 }
253
254 } // Dali
255
256 #endif // DALI_INTEGRATION_INTERNAL_SCENEHOLDER_H