From a3f796e687ef9fa4b8a6d0661c4cd41aef2b1270 Mon Sep 17 00:00:00 2001 From: Daekwang Ryu Date: Fri, 16 Jun 2023 15:22:32 +0900 Subject: [PATCH] Add SetFrameRenderedCallback() in OffscreenWindow Change-Id: Idea04d1fa2b71cd66cdbfcb76da2841e111b89e5 --- .../adaptor-framework/offscreen-window.cpp | 7 ++++- .../devel-api/adaptor-framework/offscreen-window.h | 16 +++++++++- .../adaptor-framework/native-render-surface.h | 8 ++++- .../offscreen/common/offscreen-window-impl.cpp | 15 +++++++++- .../offscreen/common/offscreen-window-impl.h | 7 ++++- .../native-render-surface-ecore-wl.cpp | 35 ++++++++++++++++++++-- .../tizen-wayland/native-render-surface-ecore-wl.h | 31 +++++++++++++------ 7 files changed, 102 insertions(+), 17 deletions(-) diff --git a/dali/devel-api/adaptor-framework/offscreen-window.cpp b/dali/devel-api/adaptor-framework/offscreen-window.cpp index b6e6876..548d5f7 100644 --- a/dali/devel-api/adaptor-framework/offscreen-window.cpp +++ b/dali/devel-api/adaptor-framework/offscreen-window.cpp @@ -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) { diff --git a/dali/devel-api/adaptor-framework/offscreen-window.h b/dali/devel-api/adaptor-framework/offscreen-window.h index 2ba8838..3952ff0 100644 --- a/dali/devel-api/adaptor-framework/offscreen-window.h +++ b/dali/devel-api/adaptor-framework/offscreen-window.h @@ -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 diff --git a/dali/integration-api/adaptor-framework/native-render-surface.h b/dali/integration-api/adaptor-framework/native-render-surface.h index c55be78..edde560 100644 --- a/dali/integration-api/adaptor-framework/native-render-surface.h +++ b/dali/integration-api/adaptor-framework/native-render-surface.h @@ -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 diff --git a/dali/internal/offscreen/common/offscreen-window-impl.cpp b/dali/internal/offscreen/common/offscreen-window-impl.cpp index d85bdd3..c55fadb 100644 --- a/dali/internal/offscreen/common/offscreen-window-impl.cpp +++ b/dali/internal/offscreen/common/offscreen-window-impl.cpp @@ -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(mSurface.get()); diff --git a/dali/internal/offscreen/common/offscreen-window-impl.h b/dali/internal/offscreen/common/offscreen-window-impl.h index e45cf49..e9bc182 100644 --- a/dali/internal/offscreen/common/offscreen-window-impl.h +++ b/dali/internal/offscreen/common/offscreen-window-impl.h @@ -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 diff --git a/dali/internal/window-system/tizen-wayland/native-render-surface-ecore-wl.cpp b/dali/internal/window-system/tizen-wayland/native-render-surface-ecore-wl.cpp index c215b30..18a5a59 100644 --- a/dali/internal/window-system/tizen-wayland/native-render-surface-ecore-wl.cpp +++ b/dali/internal/window-system/tizen-wayland/native-render-surface-ecore-wl.cpp @@ -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(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(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(mSurfaceSize.GetWidth()), static_cast(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; } diff --git a/dali/internal/window-system/tizen-wayland/native-render-surface-ecore-wl.h b/dali/internal/window-system/tizen-wayland/native-render-surface-ecore-wl.h index 404a916..3a8968a 100644 --- a/dali/internal/window-system/tizen-wayland/native-render-surface-ecore-wl.h +++ b/dali/internal/window-system/tizen-wayland/native-render-surface-ecore-wl.h @@ -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 #include #include #include @@ -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> 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 mFrameRenderedCallback; ///< The FrameRendredCallback called from graphics driver }; } // namespace Dali -- 2.7.4