Add SetFrameRenderedCallback() in OffscreenWindow
[platform/core/uifw/dali-adaptor.git] / dali / internal / offscreen / common / offscreen-window-impl.cpp
index ed34e15..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.
@@ -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,41 @@ 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());
+}
+
+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());
@@ -119,13 +135,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