[dali_2.3.25] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-adaptor.cpp
index 4e884e0..40c73ae 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
  *
  */
 
-// CLASS HEADER
-#include <dali/integration-api/adaptors/adaptor.h>
+#include <algorithm>
 
-#include <dali/public-api/object/base-object.h>
-#include <dali/devel-api/adaptor-framework/render-surface.h>
+#include <toolkit-window-impl.h>
+
+// Don't want to include the actual window.h which otherwise will be indirectly included by adaptor.h.
+#define DALI_WINDOW_H
+#include <dali/integration-api/adaptor-framework/adaptor.h>
+#include <dali/integration-api/adaptor-framework/scene-holder.h>
+
+#include <dali/integration-api/debug.h>
+#include <dali/integration-api/scene.h>
+#include <test-application.h>
+#include <toolkit-adaptor-impl.h>
+#include <toolkit-application.h>
+#include <toolkit-async-task-manager.h>
+#include <toolkit-scene-holder-impl.h>
+#include <toolkit-test-application.h>
+#include "dali-test-suite-utils.h"
 
 namespace Dali
 {
+namespace Internal
+{
+namespace Adaptor
+{
+///////////////////////////////////////////////////////////////////////////////
+//
+// Dali::Internal::Adaptor::Adaptor Stub
+//
+///////////////////////////////////////////////////////////////////////////////
 
-class EglInterface;
-class DisplayConnection;
-class ThreadSynchronizationInterface;
+Dali::Adaptor* gAdaptor = nullptr;
 
-namespace Integration
+Dali::Adaptor& Adaptor::New()
 {
+  DALI_ASSERT_ALWAYS(!gAdaptor);
+  gAdaptor = new Dali::Adaptor;
+  return *gAdaptor;
+}
 
-class GlAbstraction;
-
-} // namespace Integration
+Dali::Adaptor& Adaptor::Get()
+{
+  DALI_ASSERT_ALWAYS(gAdaptor);
+  return *gAdaptor;
+}
 
-class TestRenderSurface : public RenderSurface
+Adaptor::Adaptor()
 {
-public:
-  virtual PositionSize GetPositionSize() const { PositionSize size; return size; }
+}
 
-  virtual void InitializeEgl( EglInterface& egl ) {}
+Adaptor::~Adaptor()
+{
+  gAdaptor = nullptr;
 
-  virtual void CreateEglSurface( EglInterface& egl ) {}
+  // Ensure all threads and not-excuted tasks are destroyed.
+  // TODO : we'd better make some singletone service for toolkit UTC in future.
+  Test::AsyncTaskManager::DestroyAsyncTaskManager();
+}
 
-  virtual void DestroyEglSurface( EglInterface& egl ) {}
+void Adaptor::Start(Dali::Window window)
+{
+  AddWindow(&GetImplementation(window));
+}
 
-  virtual bool ReplaceEGLSurface( EglInterface& egl ) { return false; }
+void Adaptor::Stop()
+{
+  if(mTestApplication)
+  {
+    Integration::Core& core = mTestApplication->GetCore();
+    tet_printf("Adaptor::UnregisterProcessors\n");
+    core.UnregisterProcessors();
+  }
 
-  virtual void MoveResize( Dali::PositionSize positionSize ) {}
+  mStopped = true;
+}
 
-  virtual void SetViewMode( ViewMode viewMode ) {}
+Integration::Scene Adaptor::GetScene(Dali::Window window)
+{
+  return window.GetScene();
+}
 
-  virtual void StartRender() {}
+bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue)
+{
+  if(ToolkitApplication::ADD_IDLE_SUCCESS)
+  {
+    if(hasReturnValue)
+    {
+      mReturnCallbacks.PushBack(callback);
+    }
+    else
+    {
+      mCallbacks.PushBack(callback);
+    }
+  }
+  return ToolkitApplication::ADD_IDLE_SUCCESS;
+}
 
-  virtual bool PreRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction ) { return false; }
+void Adaptor::RemoveIdle(CallbackBase* callback)
+{
+  mCallbacks.Erase(std::remove_if(mCallbacks.Begin(), mCallbacks.End(), [&callback](CallbackBase* current) { return callback == current; }), mCallbacks.End());
+  mReturnCallbacks.Erase(std::remove_if(mReturnCallbacks.Begin(), mReturnCallbacks.End(), [&callback](CallbackBase* current) { return callback == current; }), mReturnCallbacks.End());
+}
 
-  virtual void PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, DisplayConnection* displayConnection, bool replacingSurface ) {}
+void Adaptor::RunIdles()
+{
+  Dali::Vector<CallbackBase*> reusedCallbacks;
+  for(auto& callback : mReturnCallbacks)
+  {
+    bool retValue = CallbackBase::ExecuteReturn<bool>(*callback);
+    if(retValue)
+    {
+      reusedCallbacks.PushBack(callback);
+    }
+  }
+  for(auto& callback : mCallbacks)
+  {
+    CallbackBase::Execute(*callback);
+  }
 
-  virtual void StopRender() {}
+  mCallbacks.Clear();
+  mReturnCallbacks.Clear();
+  mReturnCallbacks.Swap(reusedCallbacks);
+}
 
-  virtual void ReleaseLock() {}
+void Adaptor::RequestUpdateOnce()
+{
+  if(mTestApplication)
+  {
+    auto scene = mTestApplication->GetScene();
+    if(scene)
+    {
+      tet_printf("Adaptor::RequestUpdateOnce()\n");
+      scene.KeepRendering(0.0f);
+    }
+  }
+}
 
-  virtual void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ) {}
+Dali::RenderSurfaceInterface& Adaptor::GetSurface()
+{
+  DALI_ASSERT_ALWAYS(!mWindows.empty());
 
-  virtual RenderSurface::Type GetSurfaceType() { return RenderSurface::ECORE_RENDER_SURFACE; }
-};
+  return reinterpret_cast<Dali::RenderSurfaceInterface&>(mWindows.front()->GetRenderSurface());
+}
 
-namespace Internal
-{
-namespace Adaptor
+Dali::WindowContainer Adaptor::GetWindows()
 {
+  Dali::WindowContainer windows;
 
-class Adaptor: public BaseObject
-{
-public:
-  static Dali::Adaptor& Get();
-  Adaptor();
-  ~Adaptor();
+  for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
+  {
+    // Downcast to Dali::Window
+    Dali::Window window(dynamic_cast<Dali::Internal::Adaptor::Window*>(*iter));
+    if(window)
+    {
+      windows.push_back(window);
+    }
+  }
 
-public:
-  static Dali::RenderSurface& GetSurface();
-  static Dali::Adaptor::AdaptorSignalType& AdaptorSignal();
-};
+  return windows;
+}
 
-Dali::Adaptor& Adaptor::Get()
+Dali::SceneHolderList Adaptor::GetSceneHolders()
 {
-  Dali::Adaptor* adaptor = new Dali::Adaptor;
-  return *adaptor;
+  Dali::SceneHolderList sceneHolderList;
+
+  for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
+  {
+    sceneHolderList.push_back(Dali::Integration::SceneHolder(*iter));
+  }
+
+  return sceneHolderList;
 }
 
-Dali::RenderSurface& Adaptor::GetSurface()
+Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow(Dali::Actor& actor)
 {
-  Dali::RenderSurface *renderSurface = new Dali::TestRenderSurface;
-  return *renderSurface;
+  Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
+
+  for(auto window : mWindows)
+  {
+    if(scene == window->GetScene())
+    {
+      return window;
+    }
+  }
+
+  return nullptr;
 }
 
-Dali::Adaptor::AdaptorSignalType& Adaptor::AdaptorSignal()
+void Adaptor::AddWindow(Internal::Adaptor::SceneHolder* window)
 {
-  Dali::Adaptor::AdaptorSignalType* signal = new Dali::Adaptor::AdaptorSignalType;
-  return *signal;
+  if(window)
+  {
+    mWindows.push_back(window);
+
+    Dali::Integration::SceneHolder newWindow(window);
+    mWindowCreatedSignal.Emit(newWindow);
+  }
 }
 
+void Adaptor::RemoveWindow(Internal::Adaptor::SceneHolder* window)
+{
+  auto iter = std::find(mWindows.begin(), mWindows.end(), window);
+  if(iter != mWindows.end())
+  {
+    mWindows.erase(iter);
+  }
 }
+
+void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
+{
+  Integration::Core& core = mTestApplication->GetCore();
+  tet_printf("Adaptor::RegisterProcessor : %s\n", processor.GetProcessorName().data());
+  core.RegisterProcessor(processor, postProcessor);
 }
+
+void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
+{
+  Integration::Core& core = mTestApplication->GetCore();
+  tet_printf("Adaptor::UnregisterProcessor : %s\n", processor.GetProcessorName().data());
+  core.UnregisterProcessor(processor, postProcessor);
 }
 
-namespace Dali
+void Adaptor::SetApplication(Dali::TestApplication& testApplication)
 {
+  mTestApplication = &testApplication;
+}
 
-Adaptor& Adaptor::New( Window window )
+Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
 {
-  return Internal::Adaptor::Adaptor::Get();
+  return mResizedSignal;
 }
 
-Adaptor& Adaptor::New( Window window, Configuration::ContextLoss configuration )
+Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
 {
-  return Internal::Adaptor::Adaptor::Get();
+  return mLanguageChangedSignal;
 }
 
-Adaptor& Adaptor::New( Any nativeWindow, const Dali::RenderSurface& surface )
+Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
 {
-  return Internal::Adaptor::Adaptor::Get();
+  return mWindowCreatedSignal;
 }
 
-Adaptor& Adaptor::New( Any nativeWindow, const Dali::RenderSurface& surface, Configuration::ContextLoss configuration )
+} // namespace Adaptor
+} // namespace Internal
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Dali::Adaptor Stub
+//
+///////////////////////////////////////////////////////////////////////////////
+
+Adaptor::Adaptor()
+: mImpl(new Internal::Adaptor::Adaptor)
 {
-  return Internal::Adaptor::Adaptor::Get();
 }
 
 Adaptor::~Adaptor()
 {
+  Internal::Adaptor::gAdaptor = nullptr;
+  delete mImpl;
 }
 
 void Adaptor::Start()
@@ -147,30 +291,55 @@ void Adaptor::Resume()
 
 void Adaptor::Stop()
 {
+  mImpl->Stop();
+}
+
+bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue)
+{
+  return mImpl->AddIdle(callback, hasReturnValue);
+}
+
+void Adaptor::RemoveIdle(CallbackBase* callback)
+{
+  mImpl->RemoveIdle(callback);
 }
 
-bool Adaptor::AddIdle( CallbackBase* callback )
+void Adaptor::ReplaceSurface(Window window, Dali::RenderSurfaceInterface& surface)
 {
-  return false;
 }
 
-void Adaptor::ReplaceSurface( Any nativeWindow, Dali::RenderSurface& surface )
+void Adaptor::ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface)
 {
 }
 
 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
 {
-  return Internal::Adaptor::Adaptor::AdaptorSignal();
+  return mImpl->ResizedSignal();
 }
 
 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
 {
-  return Internal::Adaptor::Adaptor::AdaptorSignal();
+  return mImpl->LanguageChangedSignal();
 }
 
-RenderSurface& Adaptor::GetSurface()
+Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
 {
-  return Internal::Adaptor::Adaptor::GetSurface();
+  return mImpl->WindowCreatedSignal();
+}
+
+Dali::RenderSurfaceInterface& Adaptor::GetSurface()
+{
+  return mImpl->GetSurface();
+}
+
+Dali::WindowContainer Adaptor::GetWindows() const
+{
+  return mImpl->GetWindows();
+}
+
+Dali::SceneHolderList Adaptor::GetSceneHolders() const
+{
+  return mImpl->GetSceneHolders();
 }
 
 Any Adaptor::GetNativeWindowHandle()
@@ -179,15 +348,16 @@ Any Adaptor::GetNativeWindowHandle()
   return window;
 }
 
-void Adaptor::ReleaseSurfaceLock()
+Any Adaptor::GetNativeWindowHandle(Actor actor)
 {
+  return GetNativeWindowHandle();
 }
 
-void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
+void Adaptor::ReleaseSurfaceLock()
 {
 }
 
-void Adaptor::SetUseHardwareVSync(bool useHardware)
+void Adaptor::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender)
 {
 }
 
@@ -198,7 +368,7 @@ Adaptor& Adaptor::Get()
 
 bool Adaptor::IsAvailable()
 {
-  return false;
+  return Internal::Adaptor::gAdaptor && (!Internal::Adaptor::Adaptor::GetImpl(*Internal::Adaptor::gAdaptor).IsStopped());
 }
 
 void Adaptor::NotifySceneCreated()
@@ -209,37 +379,84 @@ void Adaptor::NotifyLanguageChanged()
 {
 }
 
-void Adaptor::SetMinimumPinchDistance(float distance)
+void Adaptor::FeedTouchPoint(TouchPoint& point, int timeStamp)
 {
 }
 
-void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
+void Adaptor::FeedWheelEvent(WheelEvent& wheelEvent)
 {
 }
 
-void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
+void Adaptor::FeedKeyEvent(KeyEvent& keyEvent)
 {
 }
 
-void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
+void Adaptor::SceneCreated()
 {
 }
 
-void Adaptor::SceneCreated()
+class LogFactory : public LogFactoryInterface
+{
+public:
+  virtual void InstallLogFunction() const
+  {
+    Dali::Integration::Log::LogFunction logFunction(&ToolkitTestApplication::LogMessage);
+    Dali::Integration::Log::InstallLogFunction(logFunction);
+  }
+
+  LogFactory()
+  {
+  }
+  virtual ~LogFactory()
+  {
+  }
+};
+
+LogFactory*                gLogFactory = NULL;
+const LogFactoryInterface& Adaptor::GetLogFactory()
 {
+  if(gLogFactory == NULL)
+  {
+    gLogFactory = new LogFactory;
+  }
+  return *gLogFactory;
 }
 
-void Adaptor::SetViewMode( ViewMode mode )
+class TraceFactory : public TraceFactoryInterface
 {
+public:
+  virtual void InstallTraceFunction() const
+  {
+    Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
+    Dali::Integration::Trace::InstallLogContextFunction(logContextFunction);
+  }
+
+  TraceFactory()
+  {
+  }
+  virtual ~TraceFactory()
+  {
+  }
+};
+
+TraceFactory*                gTraceFactory = NULL;
+const TraceFactoryInterface& Adaptor::GetTraceFactory()
+{
+  if(gTraceFactory == NULL)
+  {
+    gTraceFactory = new TraceFactory;
+  }
+  return *gTraceFactory;
 }
 
-void Adaptor::SetStereoBase(  float stereoBase )
+void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
 {
+  mImpl->RegisterProcessor(processor, postProcessor);
 }
 
-Adaptor::Adaptor()
-: mImpl( NULL )
+void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
 {
+  mImpl->UnregisterProcessor(processor, postProcessor);
 }
 
 } // namespace Dali