Revert "Remove EGL surface in the update thread"
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / common / combined-update-render-controller.h
index a8cb5f2..ca22517 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_COMBINED_UPDATE_RENDER_CONTROLLER_H
 
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
  */
 
 // EXTERNAL INCLUDES
+#include <pthread.h>
 #include <semaphore.h>
+#include <atomic>
 #include <stdint.h>
-#include <dali/integration-api/core.h>
 #include <dali/devel-api/threading/conditional-wait.h>
+#include <dali/integration-api/core.h>
 
 // INTERNAL INCLUDES
-#include <dali/integration-api/thread-synchronization-interface.h>
-#include <dali/internal/system/common/performance-interface.h>
-#include <dali/internal/system/common/fps-tracker.h>
+#include <dali/integration-api/adaptor-framework/thread-synchronization-interface.h>
 #include <dali/internal/adaptor/common/thread-controller-interface.h>
+#include <dali/internal/system/common/fps-tracker.h>
+#include <dali/internal/system/common/performance-interface.h>
 #include <dali/internal/system/common/update-status-logger.h>
 #include <dali/internal/window-system/common/display-connection.h>
 
-
 namespace Dali
 {
 
@@ -119,7 +120,7 @@ public:
   /**
    * @copydoc ThreadControllerInterface::RequestUpdateOnce()
    */
-  virtual void RequestUpdateOnce();
+  virtual void RequestUpdateOnce( UpdateMode updateMode );
 
   /**
    * @copydoc ThreadControllerInterface::ReplaceSurface()
@@ -132,6 +133,11 @@ public:
   virtual void ResizeSurface();
 
   /**
+   * @copydoc ThreadControllerInterface::WaitForGraphicsInitialization()
+   */
+  virtual void WaitForGraphicsInitialization();
+
+  /**
    * @copydoc ThreadControllerInterface::SetRenderRefreshRate()
    */
   virtual void SetRenderRefreshRate( unsigned int numberOfFramesPerRender );
@@ -141,6 +147,16 @@ public:
    */
   void SetPreRenderCallback( CallbackBase* callback ) override;
 
+  /**
+   * @copydoc ThreadControllerInterface::AddSurface()
+   */
+  virtual void AddSurface( Dali::RenderSurfaceInterface* surface );
+
+  /**
+   * @copydoc ThreadControllerInterface::IsRenderingWindows()
+   */
+  bool IsRenderingWindows() const override { return mIsRenderingWindows; }
+
 private:
 
   // Undefined copy constructor.
@@ -153,14 +169,21 @@ private:
   // EventThread
   /////////////////////////////////////////////////////////////////////////////////////////////////
 
+  enum AnimationProgression
+  {
+    USE_ELAPSED_TIME,          ///< Animation progression using elapsed time
+    NONE                       ///< No animation progression
+  };
+
   /**
    * Runs the Update/Render Thread.
    * This will lock the mutex in mUpdateRenderThreadWaitCondition.
    *
    * @param[in]  numberOfCycles           The number of times the update/render cycle should run. If -1, then it will run continuously.
-   * @param[in]  useElapsedTimeAfterWait  If true, then the elapsed time during wait is used for animations, otherwise no animation progression is made.
+   * @param[in]  animationProgression     Whether to progress animation using time elapsed since the last frame.
+   * @param[in]  updateMode               The update mode (i.e. either update & render or skip rendering)
    */
-  inline void RunUpdateRenderThread( int numberOfCycles, bool useElapsedTimeAfterWait );
+  inline void RunUpdateRenderThread( int numberOfCycles, AnimationProgression animationProgression, UpdateMode updateMode );
 
   /**
    * Pauses the Update/Render Thread.
@@ -217,7 +240,7 @@ private:
    *
    * @return Pointer to the new surface, NULL otherwise
    */
-  Integration::RenderSurface* ShouldSurfaceBeReplaced();
+  Dali::RenderSurfaceInterface* ShouldSurfaceBeReplaced();
 
   /**
    * Called by the Update/Render thread after a surface has been replaced.
@@ -263,6 +286,11 @@ private:
   void NotifyThreadInitialised();
 
   /**
+   * Called by the update-render thread when graphics has been initialised.
+   */
+  void NotifyGraphicsInitialised();
+
+  /**
    * Helper to add a performance marker to the performance server (if it's active)
    * @param[in]  type  performance marker type
    */
@@ -301,6 +329,7 @@ private:
   UpdateStatusLogger                mUpdateStatusLogger;               ///< Object that logs the update-status as required.
 
   sem_t                             mEventThreadSemaphore;             ///< Used by the event thread to ensure all threads have been initialised, and when replacing the surface.
+  sem_t                             mGraphicsInitializeSemaphore;      ///< Used by the render thread to ensure the graphics has been initialised.
 
   ConditionalWait                   mUpdateRenderThreadWaitCondition;  ///< The wait condition for the update-render-thread.
 
@@ -335,11 +364,17 @@ private:
 
   volatile unsigned int             mUseElapsedTimeAfterWait;          ///< Whether we should use the elapsed time after waiting (set by the event-thread, read by the update-render-thread).
 
-  Integration::RenderSurface* volatile mNewSurface;                    ///< Will be set to the new-surface if requested (set by the event-thread, read & cleared by the update-render thread).
+  Dali::RenderSurfaceInterface* volatile mNewSurface;                  ///< Will be set to the new-surface if requested (set by the event-thread, read & cleared by the update-render thread).
 
   volatile unsigned int             mPostRendering;                    ///< Whether post-rendering is taking place (set by the event & render threads, read by the render-thread).
   volatile unsigned int             mSurfaceResized;                   ///< Will be set to resize the surface (set by the event-thread, read & cleared by the update-render thread).
   volatile unsigned int             mForceClear;                       ///< Will be set to clear forcibly
+
+  volatile unsigned int             mUploadWithoutRendering;           ///< Will be set to upload the resource only (with no rendering)
+
+  volatile unsigned int             mFirstFrameAfterResume;            ///< Will be set to check the first frame after resume (for log)
+
+  std::atomic<bool>                 mIsRenderingWindows;               ///< This is set only from the render thread and read only from the event thread
 };
 
 } // namespace Adaptor