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