Remove RenderSurface from Core
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-adaptor.cpp
index 6507583..7c50cc7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
  *
  */
 
-#include <toolkit-window.h>
+#include <algorithm>
+
+#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/adaptors/adaptor.h>
-
-#include <dali/integration-api/adaptors/scene-holder.h>
-
-#include <dali/public-api/object/base-object.h>
+#include <dali/integration-api/adaptor-framework/adaptor.h>
+#include <dali/integration-api/adaptor-framework/scene-holder.h>
 
+#include <toolkit-scene-holder-impl.h>
 #include <toolkit-adaptor-impl.h>
 #include <dali/integration-api/debug.h>
+#include <dali/integration-api/scene.h>
 #include <test-application.h>
-#include <test-render-surface.h>
 
 namespace Dali
 {
 
+namespace
+{
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// LogFactoryStub
+//
+///////////////////////////////////////////////////////////////////////////////
+
+class LogFactory : public LogFactoryInterface
+{
+public:
+  LogFactory() = default;
+  virtual ~LogFactory() = default;
+
+private:
+  void InstallLogFunction() const override
+  {
+    Dali::Integration::Log::InstallLogFunction( &TestApplication::LogMessage );
+  }
+};
+LogFactory* gLogFactory = NULL; // For some reason, destroying this when the Adaptor is destroyed causes a crash in some test cases when running all of them.
+} //unnamed namespace
+
 namespace Internal
 {
 namespace Adaptor
 {
 
-bool Adaptor::mAvailable = false;
-Vector<CallbackBase*> Adaptor::mCallbacks = Vector<CallbackBase*>();
-Dali::WindowContainer Adaptor::mWindows;
-Dali::Adaptor::WindowCreatedSignalType* Adaptor::mWindowCreatedSignal = nullptr;
+///////////////////////////////////////////////////////////////////////////////
+//
+// Dali::Internal::Adaptor::Adaptor Stub
+//
+///////////////////////////////////////////////////////////////////////////////
+
+Dali::Adaptor* gAdaptor = nullptr;
+
+Dali::Adaptor& Adaptor::New()
+{
+  DALI_ASSERT_ALWAYS( ! gAdaptor );
+  gAdaptor = new Dali::Adaptor;
+  return *gAdaptor;
+}
 
 Dali::Adaptor& Adaptor::Get()
 {
-  Dali::Adaptor* adaptor = new Dali::Adaptor;
-  Adaptor::mAvailable = true;
-  return *adaptor;
+  DALI_ASSERT_ALWAYS( gAdaptor );
+  return *gAdaptor;
 }
 
-Dali::RenderSurfaceInterface& Adaptor::GetSurface()
+Adaptor::Adaptor()
 {
-  Dali::RenderSurfaceInterface* renderSurface = reinterpret_cast <Dali::RenderSurfaceInterface*>( new Dali::TestRenderSurface( Dali::PositionSize( 0, 0, 480, 800 ) ) );
-  return *renderSurface;
 }
 
-Dali::WindowContainer Adaptor::GetWindows()
+Adaptor::~Adaptor()
 {
-  return Adaptor::mWindows;
+  gAdaptor = nullptr;
 }
 
-Dali::Adaptor::AdaptorSignalType& Adaptor::AdaptorSignal()
+void Adaptor::Start( Dali::Window window )
 {
-  Dali::Adaptor::AdaptorSignalType* signal = new Dali::Adaptor::AdaptorSignalType;
-  return *signal;
+  AddWindow( &GetImplementation( window ) );
 }
 
-Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
+Integration::Scene Adaptor::GetScene( Dali::Window window )
+{
+  return window.GetScene();
+}
+
+bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
+{
+  mCallbacks.PushBack( callback );
+  return true;
+}
+
+void Adaptor::RemoveIdle( CallbackBase* callback )
 {
-  if ( !Adaptor::mWindowCreatedSignal )
+  mCallbacks.Erase( std::find_if( mCallbacks.Begin(), mCallbacks.End(),
+                                  [ &callback ] ( CallbackBase* current ) { return callback == current; } ) );
+}
+
+void Adaptor::RunIdles()
+{
+  for( auto& callback : mCallbacks )
   {
-    Adaptor::mWindowCreatedSignal = new Dali::Adaptor::WindowCreatedSignalType;
+    CallbackBase::Execute( *callback );
   }
 
-  return *Adaptor::mWindowCreatedSignal;
+  mCallbacks.Clear();
 }
 
-} // namespace Adaptor
-} // namespace Internal
+Dali::RenderSurfaceInterface& Adaptor::GetSurface()
+{
+  DALI_ASSERT_ALWAYS( ! mWindows.empty() );
 
-Adaptor& Adaptor::New( Window window )
+  return reinterpret_cast < Dali::RenderSurfaceInterface& >( mWindows.front()->GetRenderSurface() );
+}
+
+Dali::WindowContainer Adaptor::GetWindows()
 {
-  return Internal::Adaptor::Adaptor::Get();
+  Dali::WindowContainer windows;
+
+  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 );
+    }
+  }
+
+  return windows;
 }
 
-Adaptor& Adaptor::New( Window window, Configuration::ContextLoss configuration )
+Dali::SceneHolderList Adaptor::GetSceneHolders()
 {
-  return Internal::Adaptor::Adaptor::Get();
+  Dali::SceneHolderList sceneHolderList;
+
+  for( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
+  {
+    sceneHolderList.push_back( Dali::Integration::SceneHolder( *iter ) );
+  }
+
+  return sceneHolderList;
 }
 
-Adaptor& Adaptor::New( Window window, const Dali::RenderSurfaceInterface& surface )
+Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow( Dali::Actor& actor )
 {
-  return Internal::Adaptor::Adaptor::Get();
+  Dali::Integration::Scene scene = Dali::Integration::Scene::Get( actor );
+
+  for( auto window : mWindows )
+  {
+    if ( scene == window->GetScene() )
+    {
+      return window;
+    }
+  }
+
+  return nullptr;
 }
 
-Adaptor& Adaptor::New( Window window, const Dali::RenderSurfaceInterface& surface, Configuration::ContextLoss configuration )
+void Adaptor::AddWindow( Internal::Adaptor::SceneHolder* window )
 {
-  return Internal::Adaptor::Adaptor::Get();
+  if ( window )
+  {
+    mWindows.push_back( window );
+
+    Dali::Integration::SceneHolder newWindow( window );
+    mWindowCreatedSignal.Emit( newWindow );
+  }
 }
 
-Adaptor& Adaptor::New( Dali::Integration::SceneHolder window )
+void Adaptor::RemoveWindow( Internal::Adaptor::SceneHolder* window )
 {
-  return Internal::Adaptor::Adaptor::Get();
+  auto iter = std::find( mWindows.begin(), mWindows.end(), window );
+  if( iter != mWindows.end() )
+  {
+    mWindows.erase( iter );
+  }
 }
 
-Adaptor& Adaptor::New( Dali::Integration::SceneHolder window, Configuration::ContextLoss configuration )
+Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
 {
-  return Internal::Adaptor::Adaptor::Get();
+  return mResizedSignal;
 }
 
-Adaptor& Adaptor::New( Dali::Integration::SceneHolder window, const Dali::RenderSurfaceInterface& surface )
+Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
 {
-  return Internal::Adaptor::Adaptor::Get();
+  return mLanguageChangedSignal;
+}
+
+Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
+{
+  return mWindowCreatedSignal;
 }
 
-Adaptor& Adaptor::New( Dali::Integration::SceneHolder window, const Dali::RenderSurfaceInterface& 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()
@@ -142,34 +248,12 @@ void Adaptor::Stop()
 
 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
 {
-  const bool isAvailable = IsAvailable();
-
-  if( isAvailable )
-  {
-    Internal::Adaptor::Adaptor::mCallbacks.PushBack( callback );
-  }
-
-  return isAvailable;
+  return mImpl->AddIdle( callback, hasReturnValue );
 }
 
 void Adaptor::RemoveIdle( CallbackBase* callback )
 {
-  const bool isAvailable = IsAvailable();
-
-  if( isAvailable )
-  {
-    for( Vector<CallbackBase*>::Iterator it = Internal::Adaptor::Adaptor::mCallbacks.Begin(),
-           endIt = Internal::Adaptor::Adaptor::mCallbacks.End();
-         it != endIt;
-         ++it )
-    {
-      if( callback == *it )
-      {
-        Internal::Adaptor::Adaptor::mCallbacks.Remove( it );
-        return;
-      }
-    }
-  }
+  mImpl->RemoveIdle( callback );
 }
 
 void Adaptor::ReplaceSurface( Window window, Dali::RenderSurfaceInterface& surface )
@@ -182,27 +266,32 @@ void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::Rende
 
 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
 {
-  return Internal::Adaptor::Adaptor::AdaptorSignal();
+  return mImpl->ResizedSignal();
 }
 
 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
 {
-  return Internal::Adaptor::Adaptor::AdaptorSignal();
+  return mImpl->LanguageChangedSignal();
 }
 
 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
 {
-  return Internal::Adaptor::Adaptor::WindowCreatedSignal();
+  return mImpl->WindowCreatedSignal();
 }
 
 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
 {
-  return Internal::Adaptor::Adaptor::GetSurface();
+  return mImpl->GetSurface();
 }
 
 Dali::WindowContainer Adaptor::GetWindows() const
 {
-  return Internal::Adaptor::Adaptor::GetWindows();
+  return mImpl->GetWindows();
+}
+
+Dali::SceneHolderList Adaptor::GetSceneHolders() const
+{
+  return mImpl->GetSceneHolders();
 }
 
 Any Adaptor::GetNativeWindowHandle()
@@ -211,6 +300,11 @@ Any Adaptor::GetNativeWindowHandle()
   return window;
 }
 
+Any Adaptor::GetNativeWindowHandle( Actor actor )
+{
+  return GetNativeWindowHandle();
+}
+
 void Adaptor::ReleaseSurfaceLock()
 {
 }
@@ -226,7 +320,7 @@ Adaptor& Adaptor::Get()
 
 bool Adaptor::IsAvailable()
 {
-  return Internal::Adaptor::Adaptor::mAvailable;
+  return Internal::Adaptor::gAdaptor;
 }
 
 void Adaptor::NotifySceneCreated()
@@ -253,24 +347,6 @@ void Adaptor::SceneCreated()
 {
 }
 
-class LogFactory : public LogFactoryInterface
-{
-public:
-  virtual void InstallLogFunction() const
-  {
-    Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
-    Dali::Integration::Log::InstallLogFunction(logFunction);
-  }
-
-  LogFactory()
-  {
-  }
-  virtual ~LogFactory()
-  {
-  }
-};
-
-LogFactory* gLogFactory = NULL;
 const LogFactoryInterface& Adaptor::GetLogFactory()
 {
   if( gLogFactory == NULL )
@@ -280,15 +356,4 @@ const LogFactoryInterface& Adaptor::GetLogFactory()
   return *gLogFactory;
 }
 
-Adaptor::Adaptor()
-: mImpl( NULL )
-{
-  Dali::PositionSize win_size;
-  win_size.width = 640;
-  win_size.height = 800;
-
-  Dali::Window window = Dali::Window::New( win_size, "" );
-  Internal::Adaptor::Adaptor::mWindows.push_back( window );
-}
-
 } // namespace Dali