Initial refactoring of graphics interface
[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 PlatformAbstraction;
46 class UpdateStatus;
47 class RenderStatus;
48 struct Event;
49 struct TouchEvent;
50 } // namespace Integration
51
52 namespace Internal
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 } // namespace SceneGraph
71
72 /**
73  * Internal class for Dali::Integration::Core
74  */
75 class Core : public EventThreadServices
76 {
77 public:
78   /**
79    * Create and initialise a new Core instance
80    */
81   Core(Integration::RenderController&      renderController,
82        Integration::PlatformAbstraction&   platform,
83        Graphics::Controller&               graphicsController,
84        Integration::RenderToFrameBuffer    renderToFboEnabled,
85        Integration::DepthBufferAvailable   depthBufferAvailable,
86        Integration::StencilBufferAvailable stencilBufferAvailable,
87        Integration::PartialUpdateAvailable partialUpdateAvailable);
88
89   /**
90    * Destructor
91    */
92   ~Core() override;
93
94   /**
95    * @copydoc Dali::Integration::Core::Initialize()
96    */
97   void Initialize();
98
99   /**
100    * @copydoc Dali::Integration::Core::GetContextNotifier()
101    */
102   Integration::ContextNotifierInterface* GetContextNotifier();
103
104   /**
105    * @copydoc Dali::Integration::Core::ContextCreated()
106    */
107   void ContextCreated();
108
109   /**
110    * @copydoc Dali::Integration::Core::ContextDestroyed()
111    */
112   void ContextDestroyed();
113
114   /**
115    * @copydoc Dali::Integration::Core::RecoverFromContextLoss()
116    */
117   void RecoverFromContextLoss();
118
119   /**
120    * @copydoc Dali::Integration::Core::SetMinimumFrameTimeInterval(uint32_t)
121    */
122   void SetMinimumFrameTimeInterval(uint32_t interval);
123
124   /**
125    * @copydoc Dali::Integration::Core::Update()
126    */
127   void Update(float elapsedSeconds, uint32_t lastVSyncTimeMilliseconds, uint32_t nextVSyncTimeMilliseconds, Integration::UpdateStatus& status, bool renderToFboEnabled, bool isRenderingToFbo);
128
129   /**
130    * @copydoc Dali::Integration::Core::PreRender()
131    */
132   void PreRender(Integration::RenderStatus& status, bool forceClear, bool uploadOnly);
133
134   /**
135    * @copydoc Dali::Integration::Core::PreRender()
136    */
137   void PreRender(Integration::Scene& scene, std::vector<Rect<int>>& damagedRects);
138
139   /**
140    * @copydoc Dali::Integration::Core::RenderScene()
141    */
142   void RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo);
143
144   /**
145    * @copydoc Dali::Integration::Core::RenderScene()
146    */
147   void RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo, Rect<int>& clippingRect);
148
149   /**
150    * @copydoc Dali::Integration::Core::Render()
151    */
152   void PostRender(bool uploadOnly);
153
154   /**
155    * @copydoc Dali::Integration::Core::SceneCreated()
156    */
157   void SceneCreated();
158
159   /**
160    * @copydoc Dali::Integration::Core::QueueEvent(const Integration::Event&)
161    */
162   void QueueEvent(const Integration::Event& event);
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(Dali::Integration::Processor& processor);
178
179   /**
180    * @copydoc Dali::Integration::Core::UnregisterProcessor
181    */
182   void UnregisterProcessor(Dali::Integration::Processor& processor);
183
184   /**
185    * @copydoc Dali::Internal::ThreadLocalStorage::AddScene()
186    */
187   void AddScene(Scene* scene);
188
189   /**
190    * @copydoc Dali::Internal::ThreadLocalStorage::RemoveScene()
191    */
192   void RemoveScene(Scene* scene);
193
194   /**
195    * @brief Gets the Object registry.
196    * @return A reference to the object registry
197    */
198   ObjectRegistry& GetObjectRegistry() const;
199
200 public: // Implementation of EventThreadServices
201   /**
202    * @copydoc EventThreadServices::RegisterObject
203    */
204   void RegisterObject(BaseObject* object) override;
205
206   /**
207    * @copydoc EventThreadServices::UnregisterObject
208    */
209   void UnregisterObject(BaseObject* object) override;
210
211   /**
212    * @copydoc EventThreadServices::GetUpdateManager
213    */
214   SceneGraph::UpdateManager& GetUpdateManager() override;
215
216   /**
217    * @copydoc EventThreadServices::GetRenderController
218    */
219   Integration::RenderController& GetRenderController() override;
220
221   /**
222    * @copydoc EventThreadServices::ReserveMessageSlot
223    */
224   uint32_t* ReserveMessageSlot(uint32_t size, bool updateScene) override;
225
226   /**
227    * @copydoc EventThreadServices::GetEventBufferIndex
228    */
229   BufferIndex GetEventBufferIndex() const override;
230
231   /**
232    * @copydoc EventThreadServices::ForceNextUpdate
233    */
234   void ForceNextUpdate() override;
235
236   /**
237    * @copydoc EventThreadServices::IsNextUpdateForced
238    */
239   bool IsNextUpdateForced() override;
240
241 private:
242   /**
243    * Run each registered processor
244    */
245   void RunProcessors();
246
247   // for use by ThreadLocalStorage
248
249   /**
250    * Returns the current stage.
251    * @return A smart-pointer to the current stage.
252    */
253   StagePtr GetCurrentStage();
254
255   /**
256    * Returns the platform abstraction.
257    * @return A reference to the platform abstraction.
258    */
259   Integration::PlatformAbstraction& GetPlatform();
260
261   /**
262    * Returns the render manager.
263    * @return A reference to the render manager.
264    */
265   SceneGraph::RenderManager& GetRenderManager();
266
267   /**
268    * Returns the notification manager.
269    * @return A reference to the Notification Manager.
270    */
271   NotificationManager& GetNotificationManager();
272
273   /**
274    * Returns the Shader factory
275    * @return A reference to the Shader binary factory.
276    */
277   ShaderFactory& GetShaderFactory();
278
279   /**
280    * Returns the gesture event processor.
281    * @return A reference to the gesture event processor.
282    */
283   GestureEventProcessor& GetGestureEventProcessor();
284
285   /**
286    * Return the relayout controller
287    * @Return Return a reference to the relayout controller
288    */
289   RelayoutController& GetRelayoutController();
290
291   /**
292    * @brief Gets the event thread services.
293    * @return A reference to the event thread services
294    */
295   EventThreadServices& GetEventThreadServices();
296
297   /**
298    * @brief Gets the property notification manager.
299    * @return A reference to the property notification manager
300    */
301   PropertyNotificationManager& GetPropertyNotificationManager() const;
302
303   /**
304    * @brief Gets the animation play list.
305    * @return A reference to the animation play list
306    */
307   AnimationPlaylist& GetAnimationPlaylist() const;
308
309   /**
310    * @brief Returns GlAbstraction.
311    * @note Use only for the capability. Do not use this for bypass context
312    * @return GlAbstraction
313    */
314   Integration::GlAbstraction& GetGlAbstraction() const;
315
316 private:
317   /**
318    * Undefined copy and assignment operators
319    */
320   Core(const Core& core) = delete;            // No definition
321   Core& operator=(const Core& core) = delete; // No definition
322
323   /**
324    * Create Thread local storage
325    */
326   void CreateThreadLocalStorage();
327
328 private:
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   Graphics::Controller& mGraphicsController;
353
354   bool mProcessingEvent : 1; ///< True during ProcessEvents()
355   bool mForceNextUpdate : 1; ///< True if the next rendering is really required.
356
357   friend class ThreadLocalStorage;
358 };
359
360 } // namespace Internal
361
362 } // namespace Dali
363
364 #endif // DALI_INTERNAL_CORE_H