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