Merge branch 'devel/master' into tizen
[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) 2021 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);
129
130   /**
131    * @copydoc Dali::Integration::Core::PreRender()
132    */
133   void PreRender(Integration::RenderStatus& status, bool forceClear, bool uploadOnly);
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(bool uploadOnly);
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(Dali::Integration::Processor& processor);
179
180   /**
181    * @copydoc Dali::Integration::Core::UnregisterProcessor
182    */
183   void UnregisterProcessor(Dali::Integration::Processor& processor);
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 public: // Implementation of EventThreadServices
202   /**
203    * @copydoc EventThreadServices::RegisterObject
204    */
205   void RegisterObject(BaseObject* object) override;
206
207   /**
208    * @copydoc EventThreadServices::UnregisterObject
209    */
210   void UnregisterObject(BaseObject* object) override;
211
212   /**
213    * @copydoc EventThreadServices::GetUpdateManager
214    */
215   SceneGraph::UpdateManager& GetUpdateManager() override;
216
217   /**
218    * @copydoc EventThreadServices::GetRenderController
219    */
220   Integration::RenderController& GetRenderController() override;
221
222   /**
223    * @copydoc EventThreadServices::ReserveMessageSlot
224    */
225   uint32_t* ReserveMessageSlot(uint32_t size, bool updateScene) override;
226
227   /**
228    * @copydoc EventThreadServices::GetEventBufferIndex
229    */
230   BufferIndex GetEventBufferIndex() const override;
231
232   /**
233    * @copydoc EventThreadServices::ForceNextUpdate
234    */
235   void ForceNextUpdate() override;
236
237   /**
238    * @copydoc EventThreadServices::IsNextUpdateForced
239    */
240   bool IsNextUpdateForced() override;
241
242 private:
243   /**
244    * Run each registered processor
245    */
246   void RunProcessors();
247
248   // for use by ThreadLocalStorage
249
250   /**
251    * Returns the current stage.
252    * @return A smart-pointer to the current stage.
253    */
254   StagePtr GetCurrentStage();
255
256   /**
257    * Returns the platform abstraction.
258    * @return A reference to the platform abstraction.
259    */
260   Integration::PlatformAbstraction& GetPlatform();
261
262   /**
263    * Returns the render manager.
264    * @return A reference to the render manager.
265    */
266   SceneGraph::RenderManager& GetRenderManager();
267
268   /**
269    * Returns the notification manager.
270    * @return A reference to the Notification Manager.
271    */
272   NotificationManager& GetNotificationManager();
273
274   /**
275    * Returns the Shader factory
276    * @return A reference to the Shader binary factory.
277    */
278   ShaderFactory& GetShaderFactory();
279
280   /**
281    * Returns the gesture event processor.
282    * @return A reference to the gesture event processor.
283    */
284   GestureEventProcessor& GetGestureEventProcessor();
285
286   /**
287    * Return the relayout controller
288    * @Return Return a reference to the relayout controller
289    */
290   RelayoutController& GetRelayoutController();
291
292   /**
293    * @brief Gets the event thread services.
294    * @return A reference to the event thread services
295    */
296   EventThreadServices& GetEventThreadServices();
297
298   /**
299    * @brief Gets the property notification manager.
300    * @return A reference to the property notification manager
301    */
302   PropertyNotificationManager& GetPropertyNotificationManager() const;
303
304   /**
305    * @brief Gets the animation play list.
306    * @return A reference to the animation play list
307    */
308   AnimationPlaylist& GetAnimationPlaylist() const;
309
310   /**
311    * @brief Returns GlAbstraction.
312    * @note Use only for the capability. Do not use this for bypass context
313    * @return GlAbstraction
314    */
315   Integration::GlAbstraction& GetGlAbstraction() const;
316
317 private:
318   /**
319    * Undefined copy and assignment operators
320    */
321   Core(const Core& core) = delete;            // No definition
322   Core& operator=(const Core& core) = delete; // No definition
323
324   /**
325    * Create Thread local storage
326    */
327   void CreateThreadLocalStorage();
328
329 private:
330   Integration::RenderController&    mRenderController; ///< Reference to Render controller to tell it to keep rendering
331   Integration::PlatformAbstraction& mPlatform;         ///< The interface providing platform specific services.
332
333   IntrusivePtr<Stage>                       mStage;                       ///< The current stage
334   AnimationPlaylistOwner                    mAnimationPlaylist;           ///< For 'Fire and forget' animation support
335   OwnerPointer<PropertyNotificationManager> mPropertyNotificationManager; ///< For safe signal emmision of property changed notifications
336   IntrusivePtr<RelayoutController>          mRelayoutController;          ///< Size negotiation relayout controller
337
338   OwnerPointer<SceneGraph::RenderTaskProcessor> mRenderTaskProcessor;   ///< Handles the processing of render tasks
339   OwnerPointer<SceneGraph::RenderManager>       mRenderManager;         ///< Render manager
340   OwnerPointer<SceneGraph::UpdateManager>       mUpdateManager;         ///< Update manager
341   OwnerPointer<SceneGraph::DiscardQueue>        mDiscardQueue;          ///< Used to cleanup nodes & resources when no longer in use.
342   OwnerPointer<ShaderFactory>                   mShaderFactory;         ///< Shader resource factory
343   OwnerPointer<NotificationManager>             mNotificationManager;   ///< Notification manager
344   OwnerPointer<GestureEventProcessor>           mGestureEventProcessor; ///< The gesture event processor
345   Dali::Vector<Integration::Processor*>         mProcessors;            ///< Registered processors (not owned)
346
347   using SceneContainer = std::vector<ScenePtr>;
348   SceneContainer mScenes; ///< A container of scenes that bound to a surface for rendering, owned by Core
349
350   // The object registry
351   ObjectRegistryPtr mObjectRegistry;
352
353   Graphics::Controller& mGraphicsController;
354
355   bool mProcessingEvent : 1; ///< True during ProcessEvents()
356   bool mForceNextUpdate : 1; ///< True if the next rendering is really required.
357
358   friend class ThreadLocalStorage;
359 };
360
361 } // namespace Internal
362
363 } // namespace Dali
364
365 #endif // DALI_INTERNAL_CORE_H