Add SetFrameRenderedCallback() in OffscreenWindow 32/294332/3
authorDaekwang Ryu <dkdk.ryu@samsung.com>
Fri, 16 Jun 2023 06:22:32 +0000 (15:22 +0900)
committerDaekwang Ryu <dkdk.ryu@samsung.com>
Fri, 16 Jun 2023 07:49:49 +0000 (16:49 +0900)
Change-Id: Idea04d1fa2b71cd66cdbfcb76da2841e111b89e5

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 b6e6876..548d5f7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -112,6 +112,11 @@ void OffscreenWindow::SetPostRenderCallback(CallbackBase* callback)
   Internal::GetImplementation(*this).SetPostRenderCallback(callback);
 }
 
+void OffscreenWindow::SetFrameRenderedCallback(CallbackBase* callback)
+{
+  Internal::GetImplementation(*this).SetFrameRenderedCallback(callback);
+}
+
 OffscreenWindow::OffscreenWindow(Internal::OffscreenWindow* window)
 : BaseHandle(window)
 {
index 2ba8838..3952ff0 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_OFFSCREEN_WINDOW_H
 
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -202,6 +202,20 @@ public:
    */
   void SetPostRenderCallback(CallbackBase* callback);
 
+  /**
+   * @brief Sets a callback that is called when the frame rendering is done by the graphics driver.
+   *
+   * @param[in] callback The function to call
+   *
+   * @note A callback of the following type may be used:
+   * @code
+   *   void MyFunction();
+   * @endcode
+   *
+   * @note Ownership of the callback is passed onto this class.
+   */
+  void SetFrameRenderedCallback(CallbackBase* callback);
+
 public: // Not intended for application developers
   /**
    * @brief Internal constructor
index c55be78..edde560 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_NATIVE_RENDER_SURFACE_H
 
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -55,6 +55,12 @@ public: // API
    */
   virtual Any GetNativeRenderable() = 0;
 
+  /**
+   * @brief Sets a callback that is called when the frame rendering is done by the graphics driver.
+   * @param callback The function to call
+   */
+  virtual void SetFrameRenderedCallback(CallbackBase* callback) = 0;
+
 private: // from NativeRenderSurface
   /**
    * @brief Create a renderable
index d85bdd3..c55fadb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -115,6 +115,19 @@ void OffscreenWindow::SetPostRenderCallback(CallbackBase* callback)
   surface->SetRenderNotification(mRenderNotification.get());
 }
 
+void OffscreenWindow::SetFrameRenderedCallback(CallbackBase* callback)
+{
+  NativeRenderSurface* surface = GetNativeRenderSurface();
+
+  if(!surface)
+  {
+    DALI_LOG_ERROR("NativeRenderSurface is null.");
+    return;
+  }
+
+  surface->SetFrameRenderedCallback(callback);
+}
+
 NativeRenderSurface* OffscreenWindow::GetNativeRenderSurface() const
 {
   return dynamic_cast<NativeRenderSurface*>(mSurface.get());
index e45cf49..e9bc182 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_OFFSCREEN_WINDOW_IMPL_H
 
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -86,6 +86,11 @@ public:
    */
   void SetPostRenderCallback(CallbackBase* callback);
 
+  /**
+   * @copydoc Dali::OffscreenWindow::SetFrameRenderedCallback
+   */
+  void SetFrameRenderedCallback(CallbackBase* callback);
+
   /*
    * @brief Initialize the OffscreenWindow
    * @param[in] isDefaultWindow Whether the OffscreenWindow is a default one or not
index c215b30..18a5a59 100644 (file)
@@ -48,6 +48,16 @@ namespace
 Debug::Filter* gNativeSurfaceLogFilter = Debug::Filter::New(Debug::Verbose, false, "LOG_NATIVE_RENDER_SURFACE");
 #endif
 
+// The callback of tbm_surface_queue_add_acquirable_cb()
+static void TbmAcquirableCallback(tbm_surface_queue_h queue, void* data)
+{
+  NativeRenderSurfaceEcoreWl* surface = static_cast<NativeRenderSurfaceEcoreWl*>(data);
+  if(surface)
+  {
+    surface->TriggerFrameRenderedCallback();
+  }
+}
+
 } // unnamed namespace
 
 NativeRenderSurfaceEcoreWl::NativeRenderSurfaceEcoreWl(SurfaceSize surfaceSize, Any surface, bool isTransparent)
@@ -110,6 +120,25 @@ Any NativeRenderSurfaceEcoreWl::GetNativeRenderable()
   return mTbmQueue;
 }
 
+void NativeRenderSurfaceEcoreWl::TriggerFrameRenderedCallback()
+{
+  if(mFrameRenderedCallback)
+  {
+    mFrameRenderedCallback->Trigger();
+  }
+}
+
+void NativeRenderSurfaceEcoreWl::SetFrameRenderedCallback(CallbackBase* callback)
+{
+  mFrameRenderedCallback = std::unique_ptr<EventThreadCallback>(new EventThreadCallback(callback));
+
+  tbm_surface_queue_error_e result = tbm_surface_queue_add_acquirable_cb(mTbmQueue, TbmAcquirableCallback, this);
+  if(result != TBM_ERROR_NONE)
+  {
+    DALI_LOG_ERROR("Failed calling tbm_surface_queue_add_acquirable_cb(), error : %x", result);
+  }
+}
+
 PositionSize NativeRenderSurfaceEcoreWl::GetPositionSize() const
 {
   return PositionSize(0, 0, static_cast<int>(mSurfaceSize.GetWidth()), static_cast<int>(mSurfaceSize.GetHeight()));
@@ -229,9 +258,9 @@ bool NativeRenderSurfaceEcoreWl::PreRender(bool resizingSurface, const std::vect
     mDamagedRects.clear();
   }
 
-  //TODO: Need to support partial update
-  // This is now done when the render pass for the render surface begins
-  //  MakeContextCurrent();
+  // TODO: Need to support partial update
+  //  This is now done when the render pass for the render surface begins
+  //   MakeContextCurrent();
   return true;
 }
 
index 404a916..3a8968a 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_WINDOWSYSTEM_TIZENWAYLAND_NATIVE_SURFACE_ECORE_WL_H
 
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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,6 +19,7 @@
  */
 
 // EXTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/event-thread-callback.h>
 #include <dali/devel-api/threading/conditional-wait.h>
 #include <tbm_surface.h>
 #include <tbm_surface_queue.h>
@@ -41,11 +42,11 @@ class NativeRenderSurfaceEcoreWl : public Dali::NativeRenderSurface
 {
 public:
   /**
-    * Uses an Wayland surface to render to.
-    * @param [in] surfaceSize the size of the surface
-    * @param [in] surface the native surface handle
-    * @param [in] isTransparent if it is true, surface has 32 bit color depth, otherwise, 24 bit
-    */
+   * Uses an Wayland surface to render to.
+   * @param [in] surfaceSize the size of the surface
+   * @param [in] surface the native surface handle
+   * @param [in] isTransparent if it is true, surface has 32 bit color depth, otherwise, 24 bit
+   */
   NativeRenderSurfaceEcoreWl(SurfaceSize surfaceSize, Any surface, bool isTransparent = false);
 
   /**
@@ -53,7 +54,13 @@ public:
    */
   virtual ~NativeRenderSurfaceEcoreWl();
 
-public: // from WindowRenderSurface
+public:
+  /**
+   * @brief Triggers the FrameRenderedCallback
+   */
+  void TriggerFrameRenderedCallback();
+
+public: // from NativeRenderSurface
   /**
    * @copydoc Dali::NativeRenderSurface::SetRenderNotification()
    */
@@ -64,6 +71,11 @@ public: // from WindowRenderSurface
    */
   virtual Any GetNativeRenderable() override;
 
+  /**
+   * @copydoc Dali::NativeRenderSurface::SetFrameRenderedCallback()
+   */
+  void SetFrameRenderedCallback(CallbackBase* callback) override;
+
 public: // from Dali::RenderSurfaceInterface
   /**
    * @copydoc Dali::RenderSurfaceInterface::GetPositionSize()
@@ -178,8 +190,9 @@ private: // Data
   bool                                  mOwnSurface;
   std::vector<Rect<int>>                mDamagedRects{}; ///< Keeps collected damaged render items rects for one render pass
 
-  tbm_surface_queue_h             mTbmQueue;
-  ThreadSynchronizationInterface* mThreadSynchronization; ///< A pointer to the thread-synchronization
+  tbm_surface_queue_h                  mTbmQueue;
+  ThreadSynchronizationInterface*      mThreadSynchronization; ///< A pointer to the thread-synchronization
+  std::unique_ptr<EventThreadCallback> mFrameRenderedCallback; ///< The FrameRendredCallback called from graphics driver
 };
 
 } // namespace Dali