Added memory pool logging
[platform/core/uifw/dali-core.git] / dali / internal / common / core-impl.h
index 49d62ea..5c21a44 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_CORE_H
 
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 
 // INTERNAL INCLUDES
-#include <dali/public-api/common/dali-vector.h>
-#include <dali/public-api/object/ref-object.h>
+#include <dali/devel-api/common/owner-container.h>
 #include <dali/integration-api/context-notifier.h>
 #include <dali/integration-api/core-enumerations.h>
+#include <dali/integration-api/resource-policies.h>
 #include <dali/internal/common/owner-pointer.h>
 #include <dali/internal/event/animation/animation-playlist-declarations.h>
+#include <dali/internal/event/common/object-registry-impl.h>
+#include <dali/internal/event/common/scene-impl.h>
 #include <dali/internal/event/common/stage-def.h>
-#include <dali/public-api/common/view-mode.h>
-#include <dali/integration-api/resource-policies.h>
+#include <dali/public-api/common/dali-vector.h>
+#include <dali/public-api/object/ref-object.h>
 
 namespace Dali
 {
+namespace Graphics
+{
+class Controller;
+}
 
 namespace Integration
 {
 class Processor;
 class RenderController;
-class PlatformAbstraction;
-class GestureManager;
 class GlAbstraction;
-class GlSyncAbstraction;
-class SystemOverlay;
+class PlatformAbstraction;
 class UpdateStatus;
 class RenderStatus;
 struct Event;
-struct TouchData;
-}
+struct TouchEvent;
+} // namespace Integration
 
 namespace Internal
 {
-
 class NotificationManager;
 class AnimationPlaylist;
 class PropertyNotificationManager;
@@ -58,6 +60,7 @@ class GestureEventProcessor;
 class ShaderFactory;
 class TouchResampler;
 class RelayoutController;
+class EventThreadServices;
 
 namespace SceneGraph
 {
@@ -65,32 +68,34 @@ class UpdateManager;
 class RenderManager;
 class DiscardQueue;
 class RenderTaskProcessor;
-}
+} // namespace SceneGraph
 
 /**
  * Internal class for Dali::Integration::Core
  */
-class Core
+class Core : public EventThreadServices
 {
 public:
-
   /**
    * Create and initialise a new Core instance
    */
-  Core( Integration::RenderController& renderController,
-        Integration::PlatformAbstraction& platform,
-        Integration::GlAbstraction& glAbstraction,
-        Integration::GlSyncAbstraction& glSyncAbstraction,
-        Integration::GestureManager& gestureManager,
-        ResourcePolicy::DataRetention dataRetentionPolicy,
-        Integration::RenderToFrameBuffer renderToFboEnabled,
-        Integration::DepthBufferAvailable depthBufferAvailable,
-        Integration::StencilBufferAvailable stencilBufferAvailable );
+  Core(Integration::RenderController&      renderController,
+       Integration::PlatformAbstraction&   platform,
+       Graphics::Controller&               graphicsController,
+       Integration::RenderToFrameBuffer    renderToFboEnabled,
+       Integration::DepthBufferAvailable   depthBufferAvailable,
+       Integration::StencilBufferAvailable stencilBufferAvailable,
+       Integration::PartialUpdateAvailable partialUpdateAvailable);
 
   /**
    * Destructor
    */
-  ~Core();
+  ~Core() override;
+
+  /**
+   * @copydoc Dali::Integration::Core::Initialize()
+   */
+  void Initialize();
 
   /**
    * @copydoc Dali::Integration::Core::GetContextNotifier()
@@ -113,34 +118,39 @@ public:
   void RecoverFromContextLoss();
 
   /**
-   * @copydoc Dali::Integration::Core::SurfaceResized(uint32_t, uint32_t)
+   * @copydoc Dali::Integration::Core::SetMinimumFrameTimeInterval(uint32_t)
+   */
+  void SetMinimumFrameTimeInterval(uint32_t interval);
+
+  /**
+   * @copydoc Dali::Integration::Core::Update()
    */
-  void SurfaceResized(uint32_t width, uint32_t height);
+  void Update(float elapsedSeconds, uint32_t lastVSyncTimeMilliseconds, uint32_t nextVSyncTimeMilliseconds, Integration::UpdateStatus& status, bool renderToFboEnabled, bool isRenderingToFbo, bool uploadOnly);
 
   /**
-   * @copydoc Dali::Integration::Core::SetTopMargin( uint32_t margin )
+   * @copydoc Dali::Integration::Core::PreRender()
    */
-  void SetTopMargin( uint32_t margin );
+  void PreRender(Integration::RenderStatus& status, bool forceClear);
 
   /**
-   * @copydoc Dali::Integration::Core::SetDpi(uint32_t, uint32_t)
+   * @copydoc Dali::Integration::Core::PreRender()
    */
-  void SetDpi(uint32_t dpiHorizontal, uint32_t dpiVertical);
+  void PreRender(Integration::Scene& scene, std::vector<Rect<int>>& damagedRects);
 
   /**
-   * @copydoc Dali::Integration::Core::SetMinimumFrameTimeInterval(uint32_t)
+   * @copydoc Dali::Integration::Core::RenderScene()
    */
-  void SetMinimumFrameTimeInterval(uint32_t interval);
+  void RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo);
 
   /**
-   * @copydoc Dali::Integration::Core::Update()
+   * @copydoc Dali::Integration::Core::RenderScene()
    */
-  void Update( float elapsedSeconds, uint32_t lastVSyncTimeMilliseconds, uint32_t nextVSyncTimeMilliseconds, Integration::UpdateStatus& status, bool renderToFboEnabled, bool isRenderingToFbo );
+  void RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo, Rect<int>& clippingRect);
 
   /**
    * @copydoc Dali::Integration::Core::Render()
    */
-  void Render( Integration::RenderStatus& status, bool forceClear );
+  void PostRender();
 
   /**
    * @copydoc Dali::Integration::Core::SceneCreated()
@@ -150,7 +160,7 @@ public:
   /**
    * @copydoc Dali::Integration::Core::QueueEvent(const Integration::Event&)
    */
-  void QueueEvent( const Integration::Event& event );
+  void QueueEvent(const Integration::Event& event);
 
   /**
    * @copydoc Dali::Integration::Core::ProcessEvents()
@@ -163,42 +173,76 @@ public:
   uint32_t GetMaximumUpdateCount() const;
 
   /**
-   * @copydoc Dali::Integration::Core::GetSystemOverlay()
+   * @copydoc Dali::Integration::Core::RegisterProcessor
    */
-  Integration::SystemOverlay& GetSystemOverlay();
+  void RegisterProcessor(Integration::Processor& processor, bool postProcessor = false);
 
-  // Stereoscopy
+  /**
+   * @copydoc Dali::Integration::Core::UnregisterProcessor
+   */
+  void UnregisterProcessor(Dali::Integration::Processor& processor, bool postProcessor = false);
 
   /**
-   * @copydoc Dali::Integration::Core::SetViewMode()
+   * @copydoc Dali::Internal::ThreadLocalStorage::AddScene()
    */
-  void SetViewMode( ViewMode viewMode );
+  void AddScene(Scene* scene);
 
   /**
-   * @copydoc Dali::Integration::Core::GetViewMode()
+   * @copydoc Dali::Internal::ThreadLocalStorage::RemoveScene()
    */
-  ViewMode GetViewMode() const;
+  void RemoveScene(Scene* scene);
 
   /**
-   * @copydoc Dali::Integration::Core::SetStereoBase()
+   * @brief Gets the Object registry.
+   * @return A reference to the object registry
    */
-  void SetStereoBase( float stereoBase );
+  ObjectRegistry& GetObjectRegistry() const;
 
   /**
-   * @copydoc Dali::Integration::Core::GetStereoBase()
+   * Log the capacity of DALi memory pools
    */
-  float GetStereoBase() const;
+  void LogMemoryPools() const;
 
+public: // Implementation of EventThreadServices
+  /**
+   * @copydoc EventThreadServices::RegisterObject
+   */
+  void RegisterObject(BaseObject* object) override;
 
   /**
-   * @copydoc Dali::Integration::Core::RegisterProcessor
+   * @copydoc EventThreadServices::UnregisterObject
    */
-  void RegisterProcessor( Dali::Integration::Processor& processor );
+  void UnregisterObject(BaseObject* object) override;
 
   /**
-   * @copydoc Dali::Integration::Core::UnregisterProcessor
+   * @copydoc EventThreadServices::GetUpdateManager
    */
-  void UnregisterProcessor( Dali::Integration::Processor& processor );
+  SceneGraph::UpdateManager& GetUpdateManager() override;
+
+  /**
+   * @copydoc EventThreadServices::GetRenderController
+   */
+  Integration::RenderController& GetRenderController() override;
+
+  /**
+   * @copydoc EventThreadServices::ReserveMessageSlot
+   */
+  uint32_t* ReserveMessageSlot(uint32_t size, bool updateScene) override;
+
+  /**
+   * @copydoc EventThreadServices::GetEventBufferIndex
+   */
+  BufferIndex GetEventBufferIndex() const override;
+
+  /**
+   * @copydoc EventThreadServices::ForceNextUpdate
+   */
+  void ForceNextUpdate() override;
+
+  /**
+   * @copydoc EventThreadServices::IsNextUpdateForced
+   */
+  bool IsNextUpdateForced() override;
 
 private:
   /**
@@ -206,6 +250,11 @@ private:
    */
   void RunProcessors();
 
+  /**
+   * Run each registered postprocessor
+   */
+  void RunPostProcessors();
+
   // for use by ThreadLocalStorage
 
   /**
@@ -221,12 +270,6 @@ private:
   Integration::PlatformAbstraction& GetPlatform();
 
   /**
-   * Returns the update manager.
-   * @return A reference to the update manager.
-   */
-  SceneGraph::UpdateManager& GetUpdateManager();
-
-  /**
    * Returns the render manager.
    * @return A reference to the render manager.
    */
@@ -256,13 +299,37 @@ private:
    */
   RelayoutController& GetRelayoutController();
 
-private:
+  /**
+   * @brief Gets the event thread services.
+   * @return A reference to the event thread services
+   */
+  EventThreadServices& GetEventThreadServices();
+
+  /**
+   * @brief Gets the property notification manager.
+   * @return A reference to the property notification manager
+   */
+  PropertyNotificationManager& GetPropertyNotificationManager() const;
+
+  /**
+   * @brief Gets the animation play list.
+   * @return A reference to the animation play list
+   */
+  AnimationPlaylist& GetAnimationPlaylist() const;
+
+  /**
+   * @brief Returns GlAbstraction.
+   * @note Use only for the capability. Do not use this for bypass context
+   * @return GlAbstraction
+   */
+  Integration::GlAbstraction& GetGlAbstraction() const;
 
+private:
   /**
    * Undefined copy and assignment operators
    */
-  Core(const Core& core);  // No definition
-  Core& operator=(const Core& core) // No definition
+  Core(const Core& core) = delete;            // No definition
+  Core& operator=(const Core& core) = delete; // No definition
 
   /**
    * Create Thread local storage
@@ -270,28 +337,38 @@ private:
   void CreateThreadLocalStorage();
 
 private:
-
-  Integration::RenderController&            mRenderController;            ///< Reference to Render controller to tell it to keep rendering
-  Integration::PlatformAbstraction&         mPlatform;                    ///< The interface providing platform specific services.
+  Integration::RenderController&    mRenderController; ///< Reference to Render controller to tell it to keep rendering
+  Integration::PlatformAbstraction& mPlatform;         ///< The interface providing platform specific services.
 
   IntrusivePtr<Stage>                       mStage;                       ///< The current stage
   AnimationPlaylistOwner                    mAnimationPlaylist;           ///< For 'Fire and forget' animation support
   OwnerPointer<PropertyNotificationManager> mPropertyNotificationManager; ///< For safe signal emmision of property changed notifications
-  IntrusivePtr< RelayoutController >        mRelayoutController;          ///< Size negotiation relayout controller
-  bool                                      mProcessingEvent  : 1;        ///< True during ProcessEvents()
-
-  OwnerPointer<SceneGraph::RenderTaskProcessor> mRenderTaskProcessor;         ///< Handles the processing of render tasks
-  OwnerPointer<SceneGraph::RenderManager>       mRenderManager;               ///< Render manager
-  OwnerPointer<SceneGraph::UpdateManager>       mUpdateManager;               ///< Update manager
-  OwnerPointer<SceneGraph::DiscardQueue>        mDiscardQueue;                ///< Used to cleanup nodes & resources when no longer in use.
-  OwnerPointer<ShaderFactory>                   mShaderFactory;               ///< Shader resource factory
-  OwnerPointer<NotificationManager>             mNotificationManager;         ///< Notification manager
-  OwnerPointer<GestureEventProcessor>           mGestureEventProcessor;       ///< The gesture event processor
-  OwnerPointer<EventProcessor>                  mEventProcessor;              ///< The event processor
-  Dali::Vector<Integration::Processor*>         mProcessors;                  ///< Registered processors (not owned)
+  IntrusivePtr<RelayoutController>          mRelayoutController;          ///< Size negotiation relayout controller
 
-  friend class ThreadLocalStorage;
+  OwnerPointer<SceneGraph::RenderTaskProcessor> mRenderTaskProcessor;   ///< Handles the processing of render tasks
+  OwnerPointer<SceneGraph::RenderManager>       mRenderManager;         ///< Render manager
+  OwnerPointer<SceneGraph::UpdateManager>       mUpdateManager;         ///< Update manager
+  OwnerPointer<SceneGraph::DiscardQueue>        mDiscardQueue;          ///< Used to cleanup nodes & resources when no longer in use.
+  OwnerPointer<ShaderFactory>                   mShaderFactory;         ///< Shader resource factory
+  OwnerPointer<NotificationManager>             mNotificationManager;   ///< Notification manager
+  OwnerPointer<GestureEventProcessor>           mGestureEventProcessor; ///< The gesture event processor
+  Dali::Vector<Integration::Processor*>         mProcessors;            ///< Registered processors (not owned)
+  Dali::Vector<Integration::Processor*>         mPostProcessors;        ///< Registered post processors those will called after relayout(not owned)
+
+  using SceneContainer = std::vector<ScenePtr>;
+  SceneContainer mScenes; ///< A container of scenes that bound to a surface for rendering, owned by Core
 
+  // The object registry
+  ObjectRegistryPtr mObjectRegistry;
+
+  Graphics::Controller& mGraphicsController;
+
+  bool mProcessingEvent : 1;           ///< True during ProcessEvents()
+  bool mForceNextUpdate : 1;           ///< True if the next rendering is really required.
+  bool mProcessorUnregistered : 1;     ///< True if the processor is unregistered during RunProcessors()
+  bool mPostProcessorUnregistered : 1; ///< True if the post-processor is unregistered during RunPostProcessors()
+
+  friend class ThreadLocalStorage;
 };
 
 } // namespace Internal