/*
- * Copyright (c) 2014 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.
*
*/
-#define __DALI_ADAPTOR_H__
-#define __DALI_ACCESSIBILITY_MANAGER_H__
-#define __DALI_TIMER_H__
-#define __DALI_CLIPBOARD_H__
-#define __DALI_IMF_MANAGER_H__
+#include <algorithm>
-#include "toolkit-adaptor.h"
-#include <map>
-#include <dali/public-api/common/dali-common.h>
-#include <dali/public-api/signals/dali-signal-v2.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-scene-holder-impl.h>
+#include <toolkit-test-application.h>
namespace Dali
{
+namespace Internal
+{
+namespace Adaptor
+{
+///////////////////////////////////////////////////////////////////////////////
+//
+// Dali::Internal::Adaptor::Adaptor Stub
+//
+///////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////////////////////////
+Dali::Adaptor* gAdaptor = nullptr;
-class TestRenderSurface : public RenderSurface
+Dali::Adaptor& Adaptor::New()
{
-public:
- TestRenderSurface(){}
- virtual ~TestRenderSurface(){}
- virtual SurfaceType GetType() { return RenderSurface::WINDOW; }
- virtual Dali::Any GetSurface() { return Dali::Any(); }
- virtual Dali::Any GetDisplay() { return Dali::Any(); }
- virtual PositionSize GetPositionSize() const { return PositionSize(0, 0, 640, 480);}
- virtual void SetRenderMode(RenderMode mode){}
- virtual RenderMode GetRenderMode() const { return RenderSurface::RENDER_60FPS; }
-};
+ DALI_ASSERT_ALWAYS(!gAdaptor);
+ gAdaptor = new Dali::Adaptor;
+ return *gAdaptor;
+}
+
+Dali::Adaptor& Adaptor::Get()
+{
+ DALI_ASSERT_ALWAYS(gAdaptor);
+ return *gAdaptor;
+}
-typedef Dali::Rect<int> PositionSize;
+Adaptor::Adaptor()
+{
+}
-/**
- * Stub for the Adaptor
- */
-class Adaptor
+Adaptor::~Adaptor()
{
-public:
+ gAdaptor = nullptr;
+}
- typedef SignalV2< void ( Adaptor& ) > AdaptorSignalV2;
+void Adaptor::Start(Dali::Window window)
+{
+ AddWindow(&GetImplementation(window));
+}
- typedef std::pair<std::string, Dali::BaseHandle> SingletonPair;
- typedef std::map<std::string, Dali::BaseHandle> SingletonContainer;
- typedef SingletonContainer::const_iterator SingletonConstIter;
+Integration::Scene Adaptor::GetScene(Dali::Window window)
+{
+ return window.GetScene();
+}
-public:
+bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue)
+{
+ if(hasReturnValue)
+ {
+ mReturnCallbacks.PushBack(callback);
+ }
+ else
+ {
+ mCallbacks.PushBack(callback);
+ }
+ return true;
+}
- Adaptor(ToolkitAdaptor& toolkitAdaptor);
- ~Adaptor();
+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());
+}
-public:
+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);
+ }
- void Start();
- void Pause();
- void Resume();
- void Stop();
- bool AddIdle(boost::function<void(void)> callBack);
- void FeedEvent(TouchPoint& point, int timeStamp);
- bool MoveResize(const PositionSize& positionSize);
- void SurfaceResized(const PositionSize& positionSize);
- void ReplaceSurface(RenderSurface& surface);
- void RenderSync();
- RenderSurface& GetSurface();
+ mCallbacks.Clear();
+ mReturnCallbacks.Clear();
+ mReturnCallbacks.Swap(reusedCallbacks);
+}
- void RegisterSingleton(const std::type_info& info, Dali::BaseHandle singleton);
- Dali::BaseHandle GetSingleton(const std::type_info& info) const;
+Dali::RenderSurfaceInterface& Adaptor::GetSurface()
+{
+ DALI_ASSERT_ALWAYS(!mWindows.empty());
+
+ return reinterpret_cast<Dali::RenderSurfaceInterface&>(mWindows.front()->GetRenderSurface());
+}
+
+Dali::WindowContainer Adaptor::GetWindows()
+{
+ Dali::WindowContainer windows;
-public: // static methods
- static Adaptor& Get();
- static bool IsAvailable();
+ 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: // Signals
+ return windows;
+}
- AdaptorSignalV2& SignalResize();
+Dali::SceneHolderList Adaptor::GetSceneHolders()
+{
+ Dali::SceneHolderList sceneHolderList;
- void EmitSignalResize()
+ for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
{
- mResizeSignal.Emit( *this );
+ sceneHolderList.push_back(Dali::Integration::SceneHolder(*iter));
}
-private:
+ return sceneHolderList;
+}
- // Undefined
- Adaptor(const Adaptor&);
- Adaptor& operator=(Adaptor&);
+Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow(Dali::Actor& actor)
+{
+ Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
- AdaptorSignalV2 mResizeSignal;
- TestRenderSurface mRenderSurface;
- ToolkitAdaptor& mToolkitAdaptor;
+ for(auto window : mWindows)
+ {
+ if(scene == window->GetScene())
+ {
+ return window;
+ }
+ }
- SingletonContainer mSingletonContainer;
-};
+ return nullptr;
+}
-namespace
+void Adaptor::AddWindow(Internal::Adaptor::SceneHolder* window)
{
-Adaptor* gAdaptor = NULL;
+ if(window)
+ {
+ mWindows.push_back(window);
+ Dali::Integration::SceneHolder newWindow(window);
+ mWindowCreatedSignal.Emit(newWindow);
+ }
}
-Adaptor::Adaptor(ToolkitAdaptor& toolkitAdaptor)
-: mToolkitAdaptor(toolkitAdaptor)
+void Adaptor::RemoveWindow(Internal::Adaptor::SceneHolder* window)
{
+ auto iter = std::find(mWindows.begin(), mWindows.end(), window);
+ if(iter != mWindows.end())
+ {
+ mWindows.erase(iter);
+ }
}
-Adaptor::~Adaptor()
+void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
+{
+ Integration::Core& core = mTestApplication->GetCore();
+ core.RegisterProcessor(processor, postProcessor);
+}
+
+void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
{
+ Integration::Core& core = mTestApplication->GetCore();
+ core.UnregisterProcessor(processor, postProcessor);
+}
+void Adaptor::SetApplication(Dali::TestApplication& testApplication)
+{
+ mTestApplication = &testApplication;
+}
+
+Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
+{
+ return mResizedSignal;
+}
+
+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)
+{
+}
+
+Adaptor::~Adaptor()
+{
+ Internal::Adaptor::gAdaptor = nullptr;
+ delete mImpl;
}
void Adaptor::Start()
{
- mToolkitAdaptor.mFunctionsCalled.Start = true;
}
void Adaptor::Pause()
{
- mToolkitAdaptor.mFunctionsCalled.Pause = true;
}
void Adaptor::Resume()
{
- mToolkitAdaptor.mFunctionsCalled.Resume = true;
}
void Adaptor::Stop()
{
- mToolkitAdaptor.mFunctionsCalled.Stop = true;
}
-bool Adaptor::AddIdle(boost::function<void(void)> callBack)
+bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue)
{
- mToolkitAdaptor.mFunctionsCalled.AddIdle = true;
- mToolkitAdaptor.mLastIdleAdded = callBack;
- return true;
+ return mImpl->AddIdle(callback, hasReturnValue);
}
-void Adaptor::FeedEvent(TouchPoint& point, int timeStamp)
+void Adaptor::RemoveIdle(CallbackBase* callback)
{
- mToolkitAdaptor.mFunctionsCalled.FeedEvent = true;
- mToolkitAdaptor.mLastTouchPointFed = point;
- mToolkitAdaptor.mLastTimeStampFed = timeStamp;
+ mImpl->RemoveIdle(callback);
}
-bool Adaptor::MoveResize(const PositionSize& positionSize)
+void Adaptor::ReplaceSurface(Window window, Dali::RenderSurfaceInterface& surface)
{
- mToolkitAdaptor.mFunctionsCalled.MoveResize = true;
- mToolkitAdaptor.mLastSizeSet = positionSize;
- return true;
}
-void Adaptor::SurfaceResized(const PositionSize& positionSize)
+void Adaptor::ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface)
+{
+}
+
+Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
+{
+ return mImpl->ResizedSignal();
+}
+
+Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
+{
+ return mImpl->LanguageChangedSignal();
+}
+
+Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
+{
+ return mImpl->WindowCreatedSignal();
+}
+
+Dali::RenderSurfaceInterface& Adaptor::GetSurface()
+{
+ return mImpl->GetSurface();
+}
+
+Dali::WindowContainer Adaptor::GetWindows() const
{
- mToolkitAdaptor.mFunctionsCalled.SurfaceResized = true;
- mToolkitAdaptor.mLastSizeSet = positionSize;
+ return mImpl->GetWindows();
}
-void Adaptor::ReplaceSurface(RenderSurface& surface)
+Dali::SceneHolderList Adaptor::GetSceneHolders() const
{
- mToolkitAdaptor.mFunctionsCalled.ReplaceSurface = true;
+ return mImpl->GetSceneHolders();
}
-void Adaptor::RenderSync()
+Any Adaptor::GetNativeWindowHandle()
{
- mToolkitAdaptor.mFunctionsCalled.RenderSync = true;
+ Any window;
+ return window;
}
-RenderSurface& Adaptor::GetSurface()
+Any Adaptor::GetNativeWindowHandle(Actor actor)
+{
+ return GetNativeWindowHandle();
+}
+
+void Adaptor::ReleaseSurfaceLock()
+{
+}
+
+void Adaptor::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender)
{
- mToolkitAdaptor.mFunctionsCalled.GetSurface = true;
- return mRenderSurface;
}
Adaptor& Adaptor::Get()
{
- DALI_ASSERT_ALWAYS(gAdaptor);
- gAdaptor->mToolkitAdaptor.mFunctionsCalled.Get = true;
- return *gAdaptor;
+ return Internal::Adaptor::Adaptor::Get();
}
bool Adaptor::IsAvailable()
{
- bool available(false);
+ return Internal::Adaptor::gAdaptor;
+}
- if (gAdaptor)
- {
- gAdaptor->mToolkitAdaptor.mFunctionsCalled.IsAvailable = true;
- available = true;
- }
+void Adaptor::NotifySceneCreated()
+{
+}
- return available;
+void Adaptor::NotifyLanguageChanged()
+{
}
-void Adaptor::RegisterSingleton(const std::type_info& info, Dali::BaseHandle singleton)
+void Adaptor::FeedTouchPoint(TouchPoint& point, int timeStamp)
{
- mToolkitAdaptor.mFunctionsCalled.RegisterSingleton = true;
+}
- if(singleton)
- {
- mSingletonContainer.insert(SingletonPair(info.name(), singleton));
- }
+void Adaptor::FeedWheelEvent(WheelEvent& wheelEvent)
+{
}
-Dali::BaseHandle Adaptor::GetSingleton(const std::type_info& info) const
+void Adaptor::FeedKeyEvent(KeyEvent& keyEvent)
{
- mToolkitAdaptor.mFunctionsCalled.GetSingleton = true;
+}
- Dali::BaseHandle object = Dali::BaseHandle();
+void Adaptor::SceneCreated()
+{
+}
- SingletonConstIter iter = mSingletonContainer.find(info.name());
- if(iter != mSingletonContainer.end())
+class LogFactory : public LogFactoryInterface
+{
+public:
+ virtual void InstallLogFunction() const
{
- object = (*iter).second;
+ Dali::Integration::Log::LogFunction logFunction(&ToolkitTestApplication::LogMessage);
+ Dali::Integration::Log::InstallLogFunction(logFunction);
}
- return object;
-}
+ LogFactory()
+ {
+ }
+ virtual ~LogFactory()
+ {
+ }
+};
-Adaptor::AdaptorSignalV2& Adaptor::SignalResize()
+LogFactory* gLogFactory = NULL;
+const LogFactoryInterface& Adaptor::GetLogFactory()
{
- mToolkitAdaptor.mFunctionsCalled.SignalResize = true;
- return mResizeSignal;
+ if(gLogFactory == NULL)
+ {
+ gLogFactory = new LogFactory;
+ }
+ return *gLogFactory;
}
-////////////////////////////////////////////////////////////////////////////////////////////////////
+class TraceFactory : public TraceFactoryInterface
+{
+public:
+ virtual void InstallTraceFunction() const
+ {
+ Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
+ Dali::Integration::Trace::InstallLogContextFunction(logContextFunction);
+ }
-ToolkitAdaptor::ToolkitAdaptor()
-: mLastTouchPointFed(0, TouchPoint::Down, 0.0f, 0.0f),
- mLastTimeStampFed(0),
- mStyleMonitor(StyleMonitor::Get()),
- mAccessibilityManager(AccessibilityManager::Get()),
- mImfManager(ImfManager::Get()),
- mAdaptorStub(new Adaptor(*this))
+ TraceFactory()
+ {
+ }
+ virtual ~TraceFactory()
+ {
+ }
+};
+
+TraceFactory* gTraceFactory = NULL;
+const TraceFactoryInterface& Adaptor::GetTraceFactory()
{
- gAdaptor = mAdaptorStub;
+ if(gTraceFactory == NULL)
+ {
+ gTraceFactory = new TraceFactory;
+ }
+ return *gTraceFactory;
}
-ToolkitAdaptor::~ToolkitAdaptor()
+void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
{
- delete mAdaptorStub;
- gAdaptor = NULL;
+ mImpl->RegisterProcessor(processor, postProcessor);
}
-void ToolkitAdaptor::EmitSignalResize()
+void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
{
- mAdaptorStub->EmitSignalResize();
+ mImpl->UnregisterProcessor(processor, postProcessor);
}
} // namespace Dali