Add a thread mode
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / common / combined-update-render-controller.h
index 571485b..965479e 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_COMBINED_UPDATE_RENDER_CONTROLLER_H
 
 /*
- * Copyright (c) 2019 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.
@@ -19,7 +19,9 @@
  */
 
 // EXTERNAL INCLUDES
+#include <pthread.h>
 #include <semaphore.h>
+#include <atomic>
 #include <stdint.h>
 #include <dali/devel-api/threading/conditional-wait.h>
 #include <dali/integration-api/core.h>
@@ -78,7 +80,7 @@ public:
   /**
    * Constructor
    */
-  CombinedUpdateRenderController( AdaptorInternalServices& adaptorInterfaces, const EnvironmentOptions& environmentOptions );
+  CombinedUpdateRenderController( AdaptorInternalServices& adaptorInterfaces, const EnvironmentOptions& environmentOptions, ThreadMode threadMode );
 
   /**
    * Non virtual destructor. Not intended as base class.
@@ -136,6 +138,11 @@ public:
   virtual void ResizeSurface();
 
   /**
+   * @copydoc ThreadControllerInterface::WaitForGraphicsInitialization()
+   */
+  virtual void WaitForGraphicsInitialization();
+
+  /**
    * @copydoc ThreadControllerInterface::SetRenderRefreshRate()
    */
   virtual void SetRenderRefreshRate( unsigned int numberOfFramesPerRender );
@@ -145,6 +152,11 @@ public:
    */
   void SetPreRenderCallback( CallbackBase* callback ) override;
 
+  /**
+   * @copydoc ThreadControllerInterface::AddSurface()
+   */
+  virtual void AddSurface( Dali::RenderSurfaceInterface* surface );
+
 private:
 
   // Undefined copy constructor.
@@ -228,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.
@@ -243,7 +255,7 @@ private:
    *
    * @return Pointer to the deleted surface, nullptr otherwise
    */
-  Integration::RenderSurface* ShouldSurfaceBeDeleted();
+  Dali::RenderSurfaceInterface* ShouldSurfaceBeDeleted();
 
   /**
    * Called by the Update/Render thread after a surface has been deleted.
@@ -289,6 +301,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
    */
@@ -327,6 +344,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.
 
@@ -349,6 +367,8 @@ private:
   unsigned int                      mUpdateRequestCount;               ///< Count of update-requests we have received to ensure we do not go to sleep too early.
   unsigned int                      mRunning;                          ///< Read and set on the event-thread only to state whether we are running.
 
+  ThreadMode                        mThreadMode;                       ///< Whether the thread runs continuously or runs when it is requested.
+
   //
   // NOTE: cannot use booleans as these are used from multiple threads, must use variable with machine word size for atomic read/write
   //
@@ -361,8 +381,8 @@ 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).
-  Integration::RenderSurface* volatile mDeletedSurface;                ///< Will be set to the deleted 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).
+  Dali::RenderSurfaceInterface* volatile mDeletedSurface;              ///< Will be set to the deleted 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).