Move tbm acquiring part 56/245556/14
authorDaekwang Ryu <dkdk.ryu@samsung.com>
Thu, 21 Jan 2021 10:03:31 +0000 (19:03 +0900)
committerDaekwang Ryu <dkdk.ryu@samsung.com>
Wed, 12 May 2021 06:22:59 +0000 (06:22 +0000)
TBM acquiring part is moved to EvasPlugin and OffscreenWindow.
PostRenderSignal is removed and SetPostRenderCallback is added in
OffscreenWindow.

Change-Id: I4adfd699930a4dcc5e1298da9a0f1e199feadf54

dali/devel-api/adaptor-framework/offscreen-window.cpp
dali/devel-api/adaptor-framework/offscreen-window.h
dali/integration-api/adaptor-framework/native-render-surface.h
dali/internal/offscreen/common/offscreen-window-impl.cpp
dali/internal/offscreen/common/offscreen-window-impl.h
dali/internal/window-system/tizen-wayland/native-render-surface-ecore-wl.cpp
dali/internal/window-system/tizen-wayland/native-render-surface-ecore-wl.h

index 020eca4..42cc8eb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -103,9 +103,9 @@ Uint16Pair OffscreenWindow::GetDpi() const
   return Internal::GetImplementation(*this).GetDpi();
 }
 
-OffscreenWindow::PostRenderSignalType& OffscreenWindow::PostRenderSignal()
+void OffscreenWindow::SetPostRenderCallback(CallbackBase* callback)
 {
-  return Internal::GetImplementation(*this).PostRenderSignal();
+  Internal::GetImplementation(*this).SetPostRenderCallback(callback);
 }
 
 OffscreenWindow::OffscreenWindow(Internal::OffscreenWindow* window)
index 5e2b502..1c2e144 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_OFFSCREEN_WINDOW_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -22,7 +22,6 @@
 #include <dali/public-api/actors/actor.h>
 #include <dali/public-api/math/uint-16-pair.h>
 #include <dali/public-api/object/any.h>
-#include <dali/public-api/signals/dali-signal.h>
 
 // INTERNAL INCLUDES
 #include <dali/public-api/dali-adaptor-common.h>
@@ -44,8 +43,7 @@ class OffscreenWindow;
 class DALI_ADAPTOR_API OffscreenWindow : public Dali::BaseHandle
 {
 public:
-  using WindowSize           = Uint16Pair;
-  using PostRenderSignalType = Signal<void(OffscreenWindow, Any)>;
+  using WindowSize = Uint16Pair;
 
 public:
   /**
@@ -176,13 +174,18 @@ public:
    */
   Uint16Pair GetDpi() const;
 
-public: // Signals
   /**
-   * @brief This signal is emitted when the OffscreenWindow is rendered.
+   * @brief Sets the PostRenderCallback of the OffscreenWindow.
+   *
+   * @param[in] callback The PostRenderCallback function
+   * @code
+   *   void MyFunction( OffscreenWindow window, Any nativeSurface );
+   * @endcode
+   *
+   * @note Ownership of the callback is passed onto this class.
    *
-   * @return The signal
    */
-  PostRenderSignalType& PostRenderSignal();
+  void SetPostRenderCallback(CallbackBase* callback);
 
 public: // Not intended for application developers
   /**
index c15f139..c55be78 100644 (file)
@@ -44,12 +44,6 @@ public:
 
 public: // API
   /**
-   * @brief Get the render surface the adaptor is using to render to.
-   * @return reference to current render surface
-   */
-  virtual Any GetDrawable() = 0;
-
-  /**
    * @brief Sets the render notification trigger to call when render thread is completed a frame
    * @param renderNotification to use
    */
@@ -67,11 +61,6 @@ private: // from NativeRenderSurface
    */
   virtual void CreateNativeRenderable() = 0;
 
-  /**
-   * @brief Release a drawable
-   */
-  virtual void ReleaseDrawable() = 0;
-
 protected:
   // Undefined
   NativeRenderSurface(const NativeRenderSurface&) = delete;
index ed34e15..d85bdd3 100644 (file)
@@ -26,6 +26,7 @@
 #include <dali/integration-api/adaptor-framework/native-render-surface-factory.h>
 #include <dali/integration-api/adaptor-framework/native-render-surface.h>
 #include <dali/integration-api/adaptor-framework/trigger-event-factory.h>
+#include <dali/integration-api/debug.h>
 #include <dali/internal/offscreen/common/offscreen-application-impl.h>
 
 namespace Dali
@@ -49,31 +50,11 @@ void OffscreenWindow::Initialize(bool isDefaultWindow)
 {
   if(isDefaultWindow)
   {
-    Initialize();
     return;
   }
 
   Dali::Integration::SceneHolder sceneHolderHandler = Dali::Integration::SceneHolder(this);
   Dali::Adaptor::Get().AddWindow(sceneHolderHandler);
-
-  Initialize();
-}
-
-void OffscreenWindow::Initialize()
-{
-  // Connect callback to be notified when the surface is rendered
-  TriggerEventFactory triggerEventFactory;
-
-  mRenderNotification = std::unique_ptr<TriggerEventInterface>(triggerEventFactory.CreateTriggerEvent(MakeCallback(this, &OffscreenWindow::OnPostRender), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER));
-
-  NativeRenderSurface* surface = GetNativeRenderSurface();
-
-  if(!surface)
-  {
-    return;
-  }
-
-  surface->SetRenderNotification(mRenderNotification.get());
 }
 
 OffscreenWindow::~OffscreenWindow()
@@ -112,6 +93,28 @@ Dali::Any OffscreenWindow::GetNativeHandle() const
   return surface->GetNativeRenderable();
 }
 
+void OffscreenWindow::SetPostRenderCallback(CallbackBase* callback)
+{
+  // Connect callback to be notified when the surface is rendered
+  mPostRenderCallback = std::unique_ptr<CallbackBase>(callback);
+  TriggerEventFactory triggerEventFactory;
+
+  if(!mRenderNotification)
+  {
+    mRenderNotification = std::unique_ptr<TriggerEventInterface>(triggerEventFactory.CreateTriggerEvent(MakeCallback(this, &OffscreenWindow::OnPostRender), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER));
+  }
+
+  NativeRenderSurface* surface = GetNativeRenderSurface();
+
+  if(!surface)
+  {
+    DALI_LOG_ERROR("NativeRenderSurface is null.");
+    return;
+  }
+
+  surface->SetRenderNotification(mRenderNotification.get());
+}
+
 NativeRenderSurface* OffscreenWindow::GetNativeRenderSurface() const
 {
   return dynamic_cast<NativeRenderSurface*>(mSurface.get());
@@ -119,13 +122,18 @@ NativeRenderSurface* OffscreenWindow::GetNativeRenderSurface() const
 
 void OffscreenWindow::OnPostRender()
 {
+  NativeRenderSurface* surface = GetNativeRenderSurface();
+
+  if(!surface)
+  {
+    DALI_LOG_ERROR("NativeRenderSurface is null.");
+    return;
+  }
+
   Dali::OffscreenWindow handle(this);
-  mPostRenderSignal.Emit(handle, GetNativeHandle());
-}
+  CallbackBase::Execute(*mPostRenderCallback, handle, surface->GetNativeRenderable());
 
-OffscreenWindow::PostRenderSignalType& OffscreenWindow::PostRenderSignal()
-{
-  return mPostRenderSignal;
+  surface->ReleaseLock();
 }
 
 } // namespace Internal
index ee564e9..e45cf49 100644 (file)
@@ -20,7 +20,6 @@
 
 // EXTERNAL INCLUDES
 #include <dali/public-api/common/intrusive-ptr.h>
-#include <dali/public-api/signals/connection-tracker.h>
 #include <memory>
 
 // INTERNAL INCLUDES
@@ -39,12 +38,10 @@ namespace Internal
 /**
  * Implementation of the OffscreenWindow class.
  */
-class OffscreenWindow : public Dali::Internal::Adaptor::SceneHolder,
-                        public ConnectionTracker
+class OffscreenWindow : public Dali::Internal::Adaptor::SceneHolder
 {
 public:
-  using WindowSize           = Dali::OffscreenWindow::WindowSize;
-  using PostRenderSignalType = Dali::OffscreenWindow::PostRenderSignalType;
+  using WindowSize = Dali::OffscreenWindow::WindowSize;
 
   /**
    * @brief Create a new OffscreenWindow
@@ -84,18 +81,17 @@ public:
    */
   Any GetNativeHandle() const override;
 
+  /**
+   * @copydoc Dali::OffscreenWindow::SetPostRenderCallback
+   */
+  void SetPostRenderCallback(CallbackBase* callback);
+
   /*
    * @brief Initialize the OffscreenWindow
    * @param[in] isDefaultWindow Whether the OffscreenWindow is a default one or not
    */
   void Initialize(bool isDefaultWindow);
 
-public: // Signals
-  /**
-   * @copydoc Dali::OffscreenWindow::PostRenderSignal
-   */
-  PostRenderSignalType& PostRenderSignal();
-
 private:
   /**
    * This function is called after drawing by dali.
@@ -123,14 +119,9 @@ private:
   OffscreenWindow(const OffscreenWindow&);
   OffscreenWindow& operator=(OffscreenWindow&);
 
-  /*
-   * @brief Initialize the OffscreenWindow (for internal use)
-   */
-  void Initialize();
-
 private:
   std::unique_ptr<TriggerEventInterface> mRenderNotification;
-  PostRenderSignalType                   mPostRenderSignal;
+  std::unique_ptr<CallbackBase>          mPostRenderCallback;
 };
 
 inline OffscreenWindow& GetImplementation(Dali::OffscreenWindow& offscreenWindow)
index ce439ba..ecdc4e2 100644 (file)
@@ -59,7 +59,6 @@ NativeRenderSurfaceEcoreWl::NativeRenderSurfaceEcoreWl(SurfaceSize surfaceSize,
   mEGLContext(nullptr),
   mOwnSurface(false),
   mTbmQueue(NULL),
-  mConsumeSurface(NULL),
   mThreadSynchronization(NULL)
 {
   Dali::Internal::Adaptor::WindowSystem::Initialize();
@@ -95,8 +94,6 @@ NativeRenderSurfaceEcoreWl::~NativeRenderSurfaceEcoreWl()
   // release the surface if we own one
   if(mOwnSurface)
   {
-    ReleaseDrawable();
-
     if(mTbmQueue)
     {
       tbm_surface_queue_destroy(mTbmQueue);
@@ -108,11 +105,6 @@ NativeRenderSurfaceEcoreWl::~NativeRenderSurfaceEcoreWl()
   Dali::Internal::Adaptor::WindowSystem::Shutdown();
 }
 
-Any NativeRenderSurfaceEcoreWl::GetDrawable()
-{
-  return mConsumeSurface;
-}
-
 void NativeRenderSurfaceEcoreWl::SetRenderNotification(TriggerEventInterface* renderNotification)
 {
   mRenderNotification = renderNotification;
@@ -242,54 +234,21 @@ void NativeRenderSurfaceEcoreWl::PostRender(bool renderToFbo, bool replacingSurf
     eglImpl.SwapBuffers(mEGLSurface, damagedRects);
   }
 
-  //TODO: Move calling tbm_surface_queue_acruie to OffscreenWindow and Scene in EvasPlugin
-  if(mOwnSurface)
+  if(mRenderNotification)
   {
     if(mThreadSynchronization)
     {
       mThreadSynchronization->PostRenderStarted();
     }
 
-    if(tbm_surface_queue_can_acquire(mTbmQueue, 1))
-    {
-      if(tbm_surface_queue_acquire(mTbmQueue, &mConsumeSurface) != TBM_SURFACE_QUEUE_ERROR_NONE)
-      {
-        DALI_LOG_ERROR("Failed to acquire a tbm_surface\n");
-        return;
-      }
-    }
-
-    if(mConsumeSurface)
-    {
-      tbm_surface_internal_ref(mConsumeSurface);
-    }
-
-    // create damage for client applications which wish to know the update timing
-    if(mRenderNotification)
-    {
-      // use notification trigger
-      // Tell the event-thread to render the tbm_surface
-      mRenderNotification->Trigger();
-    }
+    // Tell the event-thread to render the tbm_surface
+    mRenderNotification->Trigger();
 
     if(mThreadSynchronization)
     {
       // wait until the event-thread completed to use the tbm_surface
       mThreadSynchronization->PostRenderWaitForCompletion();
     }
-
-    // release the consumed surface after post render was completed
-    ReleaseDrawable();
-  }
-  else
-  {
-    // create damage for client applications which wish to know the update timing
-    if(mRenderNotification)
-    {
-      // use notification trigger
-      // Tell the event-thread to render the tbm_surface
-      mRenderNotification->Trigger();
-    }
   }
 }
 
@@ -354,18 +313,4 @@ void NativeRenderSurfaceEcoreWl::CreateNativeRenderable()
   }
 }
 
-void NativeRenderSurfaceEcoreWl::ReleaseDrawable()
-{
-  if(mConsumeSurface)
-  {
-    tbm_surface_internal_unref(mConsumeSurface);
-
-    if(tbm_surface_internal_is_valid(mConsumeSurface))
-    {
-      tbm_surface_queue_release(mTbmQueue, mConsumeSurface);
-    }
-    mConsumeSurface = NULL;
-  }
-}
-
 } // namespace Dali
index 9561801..da93899 100644 (file)
@@ -55,11 +55,6 @@ public:
 
 public: // from WindowRenderSurface
   /**
-   * @copydoc Dali::NativeRenderSurface::GetSurface()
-   */
-  Any GetDrawable() override;
-
-  /**
    * @copydoc Dali::NativeRenderSurface::SetRenderNotification()
    */
   void SetRenderNotification(TriggerEventInterface* renderNotification) override;
@@ -166,11 +161,6 @@ private:
    */
   void CreateNativeRenderable() override;
 
-  /**
-   * @copydoc Dali::NativeRenderSurface::ReleaseDrawable()
-   */
-  void ReleaseDrawable() override;
-
 private: // Data
   SurfaceSize                           mSurfaceSize;
   TriggerEventInterface*                mRenderNotification;
@@ -183,7 +173,6 @@ private: // Data
   bool                                  mOwnSurface;
 
   tbm_surface_queue_h             mTbmQueue;
-  tbm_surface_h                   mConsumeSurface;
   ThreadSynchronizationInterface* mThreadSynchronization; ///< A pointer to the thread-synchronization
 };