/*
- * Copyright (c) 2019 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.
*
*/
-#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-adaptor-impl.h>
#include <dali/integration-api/debug.h>
+#include <dali/integration-api/scene.h>
#include <test-application.h>
-#include <test-render-surface.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
+//
+///////////////////////////////////////////////////////////////////////////////
+
+Dali::Adaptor* gAdaptor = nullptr;
-bool Adaptor::mAvailable = false;
-Vector<CallbackBase*> Adaptor::mCallbacks = Vector<CallbackBase*>();
-Dali::WindowContainer Adaptor::mWindows;
-Dali::Adaptor::WindowCreatedSignalType* Adaptor::mWindowCreatedSignal = 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;
+}
+
+Adaptor::Adaptor()
+{
+}
+
+Adaptor::~Adaptor()
+{
+ gAdaptor = nullptr;
+
+ // 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();
+}
+
+void Adaptor::Start(Dali::Window window)
+{
+ AddWindow(&GetImplementation(window));
+}
+
+void Adaptor::Stop()
+{
+ if(mTestApplication)
+ {
+ Integration::Core& core = mTestApplication->GetCore();
+ tet_printf("Adaptor::UnregisterProcessors\n");
+ core.UnregisterProcessors();
+ }
+
+ mStopped = true;
+}
+
+Integration::Scene Adaptor::GetScene(Dali::Window window)
+{
+ return window.GetScene();
+}
+
+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;
+}
+
+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());
+}
+
+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);
+ }
+
+ mCallbacks.Clear();
+ mReturnCallbacks.Clear();
+ mReturnCallbacks.Swap(reusedCallbacks);
+}
+
+void Adaptor::RequestUpdateOnce()
+{
+ if(mTestApplication)
+ {
+ auto scene = mTestApplication->GetScene();
+ if(scene)
+ {
+ tet_printf("Adaptor::RequestUpdateOnce()\n");
+ scene.KeepRendering(0.0f);
+ }
+ }
}
-Dali::RenderSurfaceInterface& Adaptor::GetSurface()
+Dali::Integration::RenderSurfaceInterface& Adaptor::GetSurface()
{
- Dali::RenderSurfaceInterface* renderSurface = reinterpret_cast <Dali::RenderSurfaceInterface*>( new Dali::TestRenderSurface( Dali::PositionSize( 0, 0, 480, 800 ) ) );
- return *renderSurface;
+ DALI_ASSERT_ALWAYS(!mWindows.empty());
+
+ return reinterpret_cast<Dali::Integration::RenderSurfaceInterface&>(mWindows.front()->GetRenderSurface());
}
Dali::WindowContainer Adaptor::GetWindows()
{
- return Adaptor::mWindows;
+ 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;
}
-Dali::Adaptor::AdaptorSignalType& Adaptor::AdaptorSignal()
+Dali::SceneHolderList Adaptor::GetSceneHolders()
{
- Dali::Adaptor::AdaptorSignalType* signal = new Dali::Adaptor::AdaptorSignalType;
- return *signal;
+ Dali::SceneHolderList sceneHolderList;
+
+ for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
+ {
+ sceneHolderList.push_back(Dali::Integration::SceneHolder(*iter));
+ }
+
+ return sceneHolderList;
}
-Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
+Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow(Dali::Actor& actor)
{
- if ( !Adaptor::mWindowCreatedSignal )
+ Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
+
+ for(auto window : mWindows)
{
- Adaptor::mWindowCreatedSignal = new Dali::Adaptor::WindowCreatedSignalType;
+ if(scene == window->GetScene())
+ {
+ return window;
+ }
}
- return *Adaptor::mWindowCreatedSignal;
+ return nullptr;
}
-} // namespace Adaptor
-} // namespace Internal
+void Adaptor::AddWindow(Internal::Adaptor::SceneHolder* window)
+{
+ if(window)
+ {
+ mWindows.push_back(window);
+
+ Dali::Integration::SceneHolder newWindow(window);
+ mWindowCreatedSignal.Emit(newWindow);
+ }
+}
-Adaptor& Adaptor::New( Window 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( Window window, Configuration::ContextLoss configuration )
+void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
{
- return Internal::Adaptor::Adaptor::Get();
+ Integration::Core& core = mTestApplication->GetCore();
+ tet_printf("Adaptor::RegisterProcessor : %s\n", processor.GetProcessorName().data());
+ core.RegisterProcessor(processor, postProcessor);
}
-Adaptor& Adaptor::New( Window window, const Dali::RenderSurfaceInterface& surface )
+void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
{
- return Internal::Adaptor::Adaptor::Get();
+ Integration::Core& core = mTestApplication->GetCore();
+ tet_printf("Adaptor::UnregisterProcessor : %s\n", processor.GetProcessorName().data());
+ core.UnregisterProcessor(processor, postProcessor);
}
-Adaptor& Adaptor::New( Window window, const Dali::RenderSurfaceInterface& surface, Configuration::ContextLoss configuration )
+void Adaptor::RegisterProcessorOnce(Integration::Processor& processor, bool postProcessor)
{
- return Internal::Adaptor::Adaptor::Get();
+ Integration::Core& core = mTestApplication->GetCore();
+ tet_printf("Adaptor::RegisterProcessorOnce : %s\n", processor.GetProcessorName().data());
+ core.RegisterProcessorOnce(processor, postProcessor);
}
-Adaptor& Adaptor::New( Dali::Integration::SceneHolder window )
+void Adaptor::UnregisterProcessorOnce(Integration::Processor& processor, bool postProcessor)
{
- return Internal::Adaptor::Adaptor::Get();
+ Integration::Core& core = mTestApplication->GetCore();
+ tet_printf("Adaptor::UnregisterProcessorOnce : %s\n", processor.GetProcessorName().data());
+ core.UnregisterProcessorOnce(processor, postProcessor);
}
-Adaptor& Adaptor::New( Dali::Integration::SceneHolder window, Configuration::ContextLoss configuration )
+void Adaptor::SetApplication(Dali::TestApplication& testApplication)
{
- return Internal::Adaptor::Adaptor::Get();
+ mTestApplication = &testApplication;
}
-Adaptor& Adaptor::New( Dali::Integration::SceneHolder window, const Dali::RenderSurfaceInterface& surface )
+Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
{
- return Internal::Adaptor::Adaptor::Get();
+ return mResizedSignal;
}
-Adaptor& Adaptor::New( Dali::Integration::SceneHolder window, const Dali::RenderSurfaceInterface& surface, Configuration::ContextLoss configuration )
+Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
+{
+ return mLanguageChangedSignal;
+}
+
+Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
+{
+ return mWindowCreatedSignal;
+}
+
+} // 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()
void Adaptor::Stop()
{
+ mImpl->Stop();
}
-bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
+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 )
+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 )
+void Adaptor::ReplaceSurface(Window window, Dali::Integration::RenderSurfaceInterface& surface)
{
}
-void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface )
+void Adaptor::ReplaceSurface(Dali::Integration::SceneHolder window, Dali::Integration::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();
}
Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
{
- return Internal::Adaptor::Adaptor::WindowCreatedSignal();
+ return mImpl->WindowCreatedSignal();
}
-Dali::RenderSurfaceInterface& Adaptor::GetSurface()
+Dali::Integration::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()
return window;
}
+Any Adaptor::GetNativeWindowHandle(Actor actor)
+{
+ return GetNativeWindowHandle();
+}
+
void Adaptor::ReleaseSurfaceLock()
{
}
-void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
+void Adaptor::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender)
{
}
bool Adaptor::IsAvailable()
{
- return Internal::Adaptor::Adaptor::mAvailable;
+ return Internal::Adaptor::gAdaptor && (!Internal::Adaptor::Adaptor::GetImpl(*Internal::Adaptor::gAdaptor).IsStopped());
}
void Adaptor::NotifySceneCreated()
{
}
-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)
{
}
public:
virtual void InstallLogFunction() const
{
- Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
+ Dali::Integration::Log::LogFunction logFunction(&ToolkitTestApplication::LogMessage);
Dali::Integration::Log::InstallLogFunction(logFunction);
}
}
};
-LogFactory* gLogFactory = NULL;
+LogFactory* gLogFactory = NULL;
const LogFactoryInterface& Adaptor::GetLogFactory()
{
- if( gLogFactory == NULL )
+ if(gLogFactory == NULL)
{
gLogFactory = new LogFactory;
}
return *gLogFactory;
}
-Adaptor::Adaptor()
-: mImpl( NULL )
+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::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
{
- Dali::PositionSize win_size;
- win_size.width = 640;
- win_size.height = 800;
+ mImpl->RegisterProcessor(processor, postProcessor);
+}
+
+void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
+{
+ mImpl->UnregisterProcessor(processor, postProcessor);
+}
- Dali::Window window = Dali::Window::New( win_size, "" );
- Internal::Adaptor::Adaptor::mWindows.push_back( window );
+void Adaptor::RegisterProcessorOnce(Integration::Processor& processor, bool postProcessor)
+{
+ mImpl->RegisterProcessorOnce(processor, postProcessor);
+}
+
+void Adaptor::UnregisterProcessorOnce(Integration::Processor& processor, bool postProcessor)
+{
+ mImpl->UnregisterProcessorOnce(processor, postProcessor);
}
} // namespace Dali