/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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 <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 <toolkit-test-application.h>
namespace Dali
{
-////////////////////////////////////////////////////////////////////////////////////////////////////
+namespace Internal
+{
+namespace Adaptor
+{
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Dali::Internal::Adaptor::Adaptor Stub
+//
+///////////////////////////////////////////////////////////////////////////////
-class TestRenderSurface : public RenderSurface
+Dali::Adaptor* gAdaptor = nullptr;
+
+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);}
-};
+ DALI_ASSERT_ALWAYS( ! gAdaptor );
+ gAdaptor = new Dali::Adaptor;
+ return *gAdaptor;
+}
-typedef Dali::Rect<int> PositionSize;
+Dali::Adaptor& Adaptor::Get()
+{
+ DALI_ASSERT_ALWAYS( gAdaptor );
+ return *gAdaptor;
+}
-/**
- * Stub for the Adaptor
- */
-class Adaptor
+Adaptor::Adaptor()
{
-public:
+}
- typedef SignalV2< void ( Adaptor& ) > AdaptorSignalV2;
+Adaptor::~Adaptor()
+{
+ gAdaptor = nullptr;
+}
-public:
+void Adaptor::Start( Dali::Window window )
+{
+ AddWindow( &GetImplementation( window ) );
+}
- Adaptor(ToolkitAdaptor& toolkitAdaptor);
- ~Adaptor();
+Integration::Scene Adaptor::GetScene( Dali::Window window )
+{
+ return window.GetScene();
+}
-public:
+bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
+{
+ mCallbacks.PushBack( callback );
+ return true;
+}
+
+void Adaptor::RemoveIdle( CallbackBase* callback )
+{
+ mCallbacks.Erase( std::find_if( mCallbacks.Begin(), mCallbacks.End(),
+ [ &callback ] ( CallbackBase* current ) { return callback == current; } ) );
+}
+
+void Adaptor::RunIdles()
+{
+ 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();
+}
-public: // static methods
- static Adaptor& Get();
- static bool IsAvailable();
+Dali::RenderSurfaceInterface& Adaptor::GetSurface()
+{
+ DALI_ASSERT_ALWAYS( ! mWindows.empty() );
-public: // Signals
+ return reinterpret_cast < Dali::RenderSurfaceInterface& >( mWindows.front()->GetRenderSurface() );
+}
- AdaptorSignalV2& SignalResize();
+Dali::WindowContainer Adaptor::GetWindows()
+{
+ Dali::WindowContainer windows;
- void EmitSignalResize()
+ for ( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
{
- mResizeSignal.Emit( *this );
+ // Downcast to Dali::Window
+ Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( *iter ) );
+ if ( window )
+ {
+ windows.push_back( window );
+ }
}
-private:
+ return windows;
+}
- // Undefined
- Adaptor(const Adaptor&);
- Adaptor& operator=(Adaptor&);
+Dali::SceneHolderList Adaptor::GetSceneHolders()
+{
+ Dali::SceneHolderList sceneHolderList;
- AdaptorSignalV2 mResizeSignal;
- TestRenderSurface mRenderSurface;
- ToolkitAdaptor& mToolkitAdaptor;
-};
+ for( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
+ {
+ sceneHolderList.push_back( Dali::Integration::SceneHolder( *iter ) );
+ }
+
+ return sceneHolderList;
+}
-namespace
+Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow( Dali::Actor& actor )
{
-Adaptor* gAdaptor = NULL;
+ Dali::Integration::Scene scene = Dali::Integration::Scene::Get( actor );
+ for( auto window : mWindows )
+ {
+ if ( scene == window->GetScene() )
+ {
+ return window;
+ }
+ }
+
+ return nullptr;
}
-Adaptor::Adaptor(ToolkitAdaptor& toolkitAdaptor)
-: mToolkitAdaptor(toolkitAdaptor)
+void Adaptor::AddWindow( Internal::Adaptor::SceneHolder* window )
{
+ if ( window )
+ {
+ mWindows.push_back( window );
+
+ Dali::Integration::SceneHolder newWindow( window );
+ mWindowCreatedSignal.Emit( newWindow );
+ }
}
-Adaptor::~Adaptor()
+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();
+ 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
+{
+ return mImpl->GetWindows();
+}
+
+Dali::SceneHolderList Adaptor::GetSceneHolders() const
+{
+ return mImpl->GetSceneHolders();
+}
+
+Any Adaptor::GetNativeWindowHandle()
{
- mToolkitAdaptor.mFunctionsCalled.SurfaceResized = true;
- mToolkitAdaptor.mLastSizeSet = positionSize;
+ Any window;
+ return window;
}
-void Adaptor::ReplaceSurface(RenderSurface& surface)
+Any Adaptor::GetNativeWindowHandle( Actor actor )
{
- mToolkitAdaptor.mFunctionsCalled.ReplaceSurface = true;
+ return GetNativeWindowHandle();
}
-void Adaptor::RenderSync()
+void Adaptor::ReleaseSurfaceLock()
{
- mToolkitAdaptor.mFunctionsCalled.RenderSync = true;
}
-RenderSurface& Adaptor::GetSurface()
+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()
+{
+}
+
+void Adaptor::NotifyLanguageChanged()
+{
+}
- return available;
+void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
+{
}
-Adaptor::AdaptorSignalV2& Adaptor::SignalResize()
+void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
{
- mToolkitAdaptor.mFunctionsCalled.SignalResize = true;
- return mResizeSignal;
}
-////////////////////////////////////////////////////////////////////////////////////////////////////
+void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
+{
+}
-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))
+void Adaptor::SceneCreated()
{
- gAdaptor = mAdaptorStub;
}
-ToolkitAdaptor::~ToolkitAdaptor()
+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::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