[dali_2.3.25] Merge branch '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) 2024 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/common/object-registry-impl.h>
28 #include <dali/internal/event/common/scene-impl.h>
29 #include <dali/internal/event/common/stage-def.h>
30 #include <dali/public-api/common/dali-vector.h>
31 #include <dali/public-api/object/ref-object.h>
32
33 namespace Dali
34 {
35 namespace Graphics
36 {
37 class Controller;
38 }
39
40 namespace Integration
41 {
42 class Processor;
43 class RenderController;
44 class PlatformAbstraction;
45 class UpdateStatus;
46 class RenderStatus;
47 struct Event;
48 struct TouchEvent;
49 } // namespace Integration
50
51 namespace Internal
52 {
53 class NotificationManager;
54 class AnimationPlaylist;
55 class PropertyNotificationManager;
56 class EventProcessor;
57 class GestureEventProcessor;
58 class ShaderFactory;
59 class TouchResampler;
60 class RelayoutController;
61 class EventThreadServices;
62
63 namespace SceneGraph
64 {
65 class UpdateManager;
66 class RenderManager;
67 class RenderTaskProcessor;
68 } // namespace SceneGraph
69
70 /**
71  * Internal class for Dali::Integration::Core
72  */
73 class Core : public EventThreadServices
74 {
75 public:
76   /**
77    * Create and initialise a new Core instance
78    */
79   Core(Integration::RenderController&    renderController,
80        Integration::PlatformAbstraction& platform,
81        Graphics::Controller&             graphicsController,
82        Integration::CorePolicyFlags      corePolicy);
83
84   /**
85    * Destructor
86    */
87   ~Core() override;
88
89   /**
90    * @copydoc Dali::Integration::Core::Initialize()
91    */
92   void Initialize();
93
94   /**
95    * @copydoc Dali::Integration::Core::GetContextNotifier()
96    */
97   Integration::ContextNotifierInterface* GetContextNotifier();
98
99   /**
100    * @copydoc Dali::Integration::Core::ContextCreated()
101    */
102   void ContextCreated();
103
104   /**
105    * @copydoc Dali::Integration::Core::ContextDestroyed()
106    */
107   void ContextDestroyed();
108
109   /**
110    * @copydoc Dali::Integration::Core::RecoverFromContextLoss()
111    */
112   void RecoverFromContextLoss();
113
114   /**
115    * @copydoc Dali::Integration::Core::SetMinimumFrameTimeInterval(uint32_t)
116    */
117   void SetMinimumFrameTimeInterval(uint32_t interval);
118
119   /**
120    * @copydoc Dali::Integration::Core::Update()
121    */
122   void Update(float elapsedSeconds, uint32_t lastVSyncTimeMilliseconds, uint32_t nextVSyncTimeMilliseconds, Integration::UpdateStatus& status, bool renderToFboEnabled, bool isRenderingToFbo, bool uploadOnly);
123
124   /**
125    * @copydoc Dali::Integration::Core::PreRender()
126    */
127   void PreRender(Integration::RenderStatus& status, bool forceClear);
128
129   /**
130    * @copydoc Dali::Integration::Core::PreRender()
131    */
132   void PreRender(Integration::Scene& scene, std::vector<Rect<int>>& damagedRects);
133
134   /**
135    * @copydoc Dali::Integration::Core::RenderScene()
136    */
137   void RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo);
138
139   /**
140    * @copydoc Dali::Integration::Core::RenderScene()
141    */
142   void RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo, Rect<int>& clippingRect);
143
144   /**
145    * @copydoc Dali::Integration::Core::Render()
146    */
147   void PostRender();
148
149   /**
150    * @copydoc Dali::Integration::Core::SceneCreated()
151    */
152   void SceneCreated();
153
154   /**
155    * @copydoc Dali::Integration::Core::QueueEvent(const Integration::Event&)
156    */
157   void QueueEvent(const Integration::Event& event);
158
159   /**
160    * @copydoc Dali::Integration::Core::ForceRelayout()
161    */
162   void ForceRelayout();
163
164   /**
165    * @copydoc Dali::Integration::Core::ProcessEvents()
166    */
167   void ProcessEvents();
168
169   /**
170    * @copydoc Dali::Integration::Core::GetMaximumUpdateCount()
171    */
172   uint32_t GetMaximumUpdateCount() const;
173
174   /**
175    * @copydoc Dali::Integration::Core::RegisterProcessor
176    */
177   void RegisterProcessor(Integration::Processor& processor, bool postProcessor = false);
178
179   /**
180    * @copydoc Dali::Integration::Core::UnregisterProcessor
181    */
182   void UnregisterProcessor(Dali::Integration::Processor& processor, bool postProcessor = false);
183
184   /**
185    * @copydoc Dali::Integration::Core::UnregisterProcessors
186    */
187   void UnregisterProcessors();
188
189   /**
190    * @copydoc Dali::Internal::ThreadLocalStorage::AddScene()
191    */
192   void AddScene(Scene* scene);
193
194   /**
195    * @copydoc Dali::Internal::ThreadLocalStorage::RemoveScene()
196    */
197   void RemoveScene(Scene* scene);
198
199   /**
200    * @brief Gets the Object registry.
201    * @return A reference to the object registry
202    */
203   ObjectRegistry& GetObjectRegistry() const;
204
205   /**
206    * Log the capacity of DALi memory pools
207    */
208   void LogMemoryPools() const;
209
210 public: // Implementation of EventThreadServices
211   /**
212    * @copydoc EventThreadServices::RegisterObject
213    */
214   void RegisterObject(BaseObject* object) override;
215
216   /**
217    * @copydoc EventThreadServices::UnregisterObject
218    */
219   void UnregisterObject(BaseObject* object) override;
220
221   /**
222    * @copydoc EventThreadServices::GetUpdateManager
223    */
224   SceneGraph::UpdateManager& GetUpdateManager() override;
225
226   /**
227    * @copydoc EventThreadServices::GetRenderController
228    */
229   Integration::RenderController& GetRenderController() override;
230
231   /**
232    * @copydoc EventThreadServices::ReserveMessageSlot
233    */
234   uint32_t* ReserveMessageSlot(uint32_t size, bool updateScene) override;
235
236   /**
237    * @copydoc EventThreadServices::GetEventBufferIndex
238    */
239   BufferIndex GetEventBufferIndex() const override;
240
241 private:
242   using SceneContainer = std::vector<ScenePtr>;
243
244   /**
245    * Run each registered processor
246    */
247   void RunProcessors();
248
249   /**
250    * Run each registered postprocessor
251    */
252   void RunPostProcessors();
253
254   /**
255    * Run registered processors, and relayout, and flush messages
256    */
257   void RelayoutAndFlush(SceneContainer& scenes);
258
259   // for use by ThreadLocalStorage
260
261   /**
262    * Returns the current stage.
263    * @return A smart-pointer to the current stage.
264    */
265   StagePtr GetCurrentStage();
266
267   /**
268    * Returns the platform abstraction.
269    * @return A reference to the platform abstraction.
270    */
271   Integration::PlatformAbstraction& GetPlatform();
272
273   /**
274    * Returns the render manager.
275    * @return A reference to the render manager.
276    */
277   SceneGraph::RenderManager& GetRenderManager();
278
279   /**
280    * Returns the notification manager.
281    * @return A reference to the Notification Manager.
282    */
283   NotificationManager& GetNotificationManager();
284
285   /**
286    * Returns the Shader factory
287    * @return A reference to the Shader binary factory.
288    */
289   ShaderFactory& GetShaderFactory();
290
291   /**
292    * Returns the gesture event processor.
293    * @return A reference to the gesture event processor.
294    */
295   GestureEventProcessor& GetGestureEventProcessor();
296
297   /**
298    * Return the relayout controller
299    * @Return Return a reference to the relayout controller
300    */
301   RelayoutController& GetRelayoutController();
302
303   /**
304    * @brief Gets the event thread services.
305    * @return A reference to the event thread services
306    */
307   EventThreadServices& GetEventThreadServices();
308
309   /**
310    * @brief Gets the property notification manager.
311    * @return A reference to the property notification manager
312    */
313   PropertyNotificationManager& GetPropertyNotificationManager() const;
314
315   /**
316    * @brief Gets the animation play list.
317    * @return A reference to the animation play list
318    */
319   AnimationPlaylist& GetAnimationPlaylist() const;
320
321   /**
322    * @brief Returns GraphicsConfig
323    * @return A reference to the GraphicsConfig struct.
324    */
325   Integration::GraphicsConfig& GetGraphicsConfig() 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   OwnerPointer<AnimationPlaylist>           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<ShaderFactory>                   mShaderFactory;         ///< Shader resource factory
352   OwnerPointer<NotificationManager>             mNotificationManager;   ///< Notification manager
353   OwnerPointer<GestureEventProcessor>           mGestureEventProcessor; ///< The gesture event processor
354   Dali::Vector<Integration::Processor*>         mProcessors;            ///< Registered processors (not owned)
355   Dali::Vector<Integration::Processor*>         mPostProcessors;        ///< Registered post processors those will called after relayout(not owned)
356
357   SceneContainer mScenes; ///< A container of scenes that bound to a surface for rendering, owned by Core
358
359   // The object registry
360   ObjectRegistryPtr mObjectRegistry;
361
362   Graphics::Controller& mGraphicsController;
363
364   bool mProcessingEvent : 1;           ///< True during ProcessEvents()
365   bool mProcessorUnregistered : 1;     ///< True if the processor is unregistered during RunProcessors()
366   bool mPostProcessorUnregistered : 1; ///< True if the post-processor is unregistered during RunPostProcessors()
367   bool mRelayoutFlush : 1;             ///< True during RelayoutAndFlush()
368
369   friend class ThreadLocalStorage;
370 };
371
372 } // namespace Internal
373
374 } // namespace Dali
375
376 #endif // DALI_INTERNAL_CORE_H