6e51b4a1d596858c86dc64775627a79c02f6e382
[platform/core/uifw/dali-core.git] / dali / internal / common / core-impl.h
1 #ifndef DALI_INTERNAL_CORE_H
2 #define DALI_INTERNAL_CORE_H
3
4 /*
5  * Copyright (c) 2018 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 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-vector.h>
23 #include <dali/public-api/object/ref-object.h>
24 #include <dali/integration-api/context-notifier.h>
25 #include <dali/integration-api/core-enumerations.h>
26 #include <dali/internal/common/owner-pointer.h>
27 #include <dali/devel-api/common/owner-container.h>
28 #include <dali/internal/event/animation/animation-playlist-declarations.h>
29 #include <dali/internal/event/common/stage-def.h>
30 #include <dali/integration-api/resource-policies.h>
31 #include <dali/internal/event/common/scene-impl.h>
32 #include <dali/internal/event/common/object-registry-impl.h>
33
34 namespace Dali
35 {
36
37 namespace Integration
38 {
39 class Processor;
40 class RenderController;
41 class PlatformAbstraction;
42 class GestureManager;
43 class GlAbstraction;
44 class GlSyncAbstraction;
45 class UpdateStatus;
46 class RenderStatus;
47 class RenderSurface;
48 struct Event;
49 struct TouchData;
50 }
51
52 namespace Internal
53 {
54
55 class NotificationManager;
56 class AnimationPlaylist;
57 class PropertyNotificationManager;
58 class EventProcessor;
59 class GestureEventProcessor;
60 class ShaderFactory;
61 class TouchResampler;
62 class RelayoutController;
63 class EventThreadServices;
64
65 namespace SceneGraph
66 {
67 class UpdateManager;
68 class RenderManager;
69 class DiscardQueue;
70 class RenderTaskProcessor;
71 }
72
73 /**
74  * Internal class for Dali::Integration::Core
75  */
76 class Core : public EventThreadServices
77 {
78 public:
79
80   /**
81    * Create and initialise a new Core instance
82    */
83   Core( Integration::RenderController& renderController,
84         Integration::PlatformAbstraction& platform,
85         Integration::GlAbstraction& glAbstraction,
86         Integration::GlSyncAbstraction& glSyncAbstraction,
87         Integration::GestureManager& gestureManager,
88         ResourcePolicy::DataRetention dataRetentionPolicy,
89         Integration::RenderToFrameBuffer renderToFboEnabled,
90         Integration::DepthBufferAvailable depthBufferAvailable,
91         Integration::StencilBufferAvailable stencilBufferAvailable );
92
93   /**
94    * Destructor
95    */
96   ~Core();
97
98   /**
99    * @copydoc Dali::Integration::Core::Initialize()
100    */
101   void Initialize();
102
103   /**
104    * @copydoc Dali::Integration::Core::GetContextNotifier()
105    */
106   Integration::ContextNotifierInterface* GetContextNotifier();
107
108   /**
109    * @copydoc Dali::Integration::Core::ContextCreated()
110    */
111   void ContextCreated();
112
113   /**
114    * @copydoc Dali::Integration::Core::ContextDestroyed()
115    */
116   void ContextDestroyed();
117
118   /**
119    * @copydoc Dali::Integration::Core::RecoverFromContextLoss()
120    */
121   void RecoverFromContextLoss();
122
123   /**
124    * @copydoc Dali::Integration::Core::SurfaceResized(Integration::RenderSurface*)
125    */
126   void SurfaceResized( Integration::RenderSurface* surface );
127
128   /**
129    * @copydoc Dali::Integration::Core::SetMinimumFrameTimeInterval(uint32_t)
130    */
131   void SetMinimumFrameTimeInterval(uint32_t interval);
132
133   /**
134    * @copydoc Dali::Integration::Core::Update()
135    */
136   void Update( float elapsedSeconds, uint32_t lastVSyncTimeMilliseconds, uint32_t nextVSyncTimeMilliseconds, Integration::UpdateStatus& status, bool renderToFboEnabled, bool isRenderingToFbo );
137
138   /**
139    * @copydoc Dali::Integration::Core::Render()
140    */
141   void Render( Integration::RenderStatus& status, bool forceClear );
142
143   /**
144    * @copydoc Dali::Integration::Core::SceneCreated()
145    */
146   void SceneCreated();
147
148   /**
149    * @copydoc Dali::Integration::Core::QueueEvent(const Integration::Event&)
150    */
151   void QueueEvent( const Integration::Event& event );
152
153   /**
154    * @copydoc Dali::Integration::Core::ProcessEvents()
155    */
156   void ProcessEvents();
157
158   /**
159    * @copydoc Dali::Integration::Core::GetMaximumUpdateCount()
160    */
161   uint32_t GetMaximumUpdateCount() const;
162
163   /**
164    * @copydoc Dali::Integration::Core::RegisterProcessor
165    */
166   void RegisterProcessor( Dali::Integration::Processor& processor );
167
168   /**
169    * @copydoc Dali::Integration::Core::UnregisterProcessor
170    */
171   void UnregisterProcessor( Dali::Integration::Processor& processor );
172
173   /**
174    * @copydoc Dali::Internal::ThreadLocalStorage::AddScene()
175    */
176   void AddScene( Scene* scene );
177
178   /**
179    * @copydoc Dali::Internal::ThreadLocalStorage::RemoveScene()
180    */
181   void RemoveScene( Scene* scene );
182
183 public: // Implementation of EventThreadServices
184
185   /**
186    * @copydoc EventThreadServices::RegisterObject
187    */
188   void RegisterObject( BaseObject* object) override;
189
190   /**
191    * @copydoc EventThreadServices::UnregisterObject
192    */
193   void UnregisterObject( BaseObject* object) override;
194
195   /**
196    * @copydoc EventThreadServices::GetUpdateManager
197    */
198   SceneGraph::UpdateManager& GetUpdateManager() override;
199
200   /**
201    * @copydoc EventThreadServices::GetRenderController
202    */
203   Integration::RenderController& GetRenderController() override;
204
205   /**
206    * @copydoc EventThreadServices::ReserveMessageSlot
207    */
208   uint32_t* ReserveMessageSlot( uint32_t size, bool updateScene ) override;
209
210   /**
211    * @copydoc EventThreadServices::GetEventBufferIndex
212    */
213   BufferIndex GetEventBufferIndex() const override;
214
215   /**
216    * @copydoc EventThreadServices::ForceNextUpdate
217    */
218   void ForceNextUpdate() override;
219
220   /**
221    * @copydoc EventThreadServices::IsNextUpdateForced
222    */
223   bool IsNextUpdateForced() override;
224
225 private:
226   /**
227    * Run each registered processor
228    */
229   void RunProcessors();
230
231   // for use by ThreadLocalStorage
232
233   /**
234    * Returns the current stage.
235    * @return A smart-pointer to the current stage.
236    */
237   StagePtr GetCurrentStage();
238
239   /**
240    * Returns the platform abstraction.
241    * @return A reference to the platform abstraction.
242    */
243   Integration::PlatformAbstraction& GetPlatform();
244
245   /**
246    * Returns the render manager.
247    * @return A reference to the render manager.
248    */
249   SceneGraph::RenderManager& GetRenderManager();
250
251   /**
252    * Returns the notification manager.
253    * @return A reference to the Notification Manager.
254    */
255   NotificationManager& GetNotificationManager();
256
257   /**
258    * Returns the Shader factory
259    * @return A reference to the Shader binary factory.
260    */
261   ShaderFactory& GetShaderFactory();
262
263   /**
264    * Returns the gesture event processor.
265    * @return A reference to the gesture event processor.
266    */
267   GestureEventProcessor& GetGestureEventProcessor();
268
269   /**
270    * Return the relayout controller
271    * @Return Return a reference to the relayout controller
272    */
273   RelayoutController& GetRelayoutController();
274
275   /**
276    * @brief Gets the Object registry.
277    * @return A reference to the object registry
278    */
279   ObjectRegistry& GetObjectRegistry() const;
280
281   /**
282    * @brief Gets the event thread services.
283    * @return A reference to the event thread services
284    */
285   EventThreadServices& GetEventThreadServices();
286
287   /**
288    * @brief Gets the property notification manager.
289    * @return A reference to the property notification manager
290    */
291   PropertyNotificationManager& GetPropertyNotificationManager() const;
292
293   /**
294    * @brief Gets the animation play list.
295    * @return A reference to the animation play list
296    */
297   AnimationPlaylist& GetAnimationPlaylist() const;
298
299 private:
300
301   /**
302    * Undefined copy and assignment operators
303    */
304   Core(const Core& core) = delete;  // No definition
305   Core& operator=(const Core& core) = delete;  // No definition
306
307   /**
308    * Create Thread local storage
309    */
310   void CreateThreadLocalStorage();
311
312 private:
313
314   Integration::RenderController&            mRenderController;            ///< Reference to Render controller to tell it to keep rendering
315   Integration::PlatformAbstraction&         mPlatform;                    ///< The interface providing platform specific services.
316
317   IntrusivePtr<Stage>                       mStage;                       ///< The current stage
318   AnimationPlaylistOwner                    mAnimationPlaylist;           ///< For 'Fire and forget' animation support
319   OwnerPointer<PropertyNotificationManager> mPropertyNotificationManager; ///< For safe signal emmision of property changed notifications
320   IntrusivePtr< RelayoutController >        mRelayoutController;          ///< Size negotiation relayout controller
321
322   OwnerPointer<SceneGraph::RenderTaskProcessor> mRenderTaskProcessor;         ///< Handles the processing of render tasks
323   OwnerPointer<SceneGraph::RenderManager>       mRenderManager;               ///< Render manager
324   OwnerPointer<SceneGraph::UpdateManager>       mUpdateManager;               ///< Update manager
325   OwnerPointer<SceneGraph::DiscardQueue>        mDiscardQueue;                ///< Used to cleanup nodes & resources when no longer in use.
326   OwnerPointer<ShaderFactory>                   mShaderFactory;               ///< Shader resource factory
327   OwnerPointer<NotificationManager>             mNotificationManager;         ///< Notification manager
328   OwnerPointer<GestureEventProcessor>           mGestureEventProcessor;       ///< The gesture event processor
329   Dali::Vector<Integration::Processor*>         mProcessors;                  ///< Registered processors (not owned)
330
331   std::vector<ScenePtr>                         mScenes;                      ///< A container of scenes that bound to a surface for rendering, owned by Core
332
333   // The object registry
334   ObjectRegistryPtr                             mObjectRegistry;
335
336   bool                                      mProcessingEvent  : 1;        ///< True during ProcessEvents()
337   bool                                      mForceNextUpdate:1;           ///< True if the next rendering is really required.
338
339   friend class ThreadLocalStorage;
340
341 };
342
343 } // namespace Internal
344
345 } // namespace Dali
346
347 #endif // DALI_INTERNAL_CORE_H