/*
- * Copyright (c) 2014 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.
*
*/
-// 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 <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
{
-class EglInterface;
-class DisplayConnection;
-class ThreadSynchronizationInterface;
-
-namespace Integration
+namespace Internal
+{
+namespace Adaptor
{
-class GlAbstraction;
+///////////////////////////////////////////////////////////////////////////////
+//
+// Dali::Internal::Adaptor::Adaptor Stub
+//
+///////////////////////////////////////////////////////////////////////////////
-} // namespace Integration
+Dali::Adaptor* gAdaptor = nullptr;
-class TestRenderSurface : public RenderSurface
+Dali::Adaptor& Adaptor::New()
{
-public:
- virtual PositionSize GetPositionSize() const { PositionSize size; return size; }
+ DALI_ASSERT_ALWAYS( ! gAdaptor );
+ gAdaptor = new Dali::Adaptor;
+ return *gAdaptor;
+}
- virtual void InitializeEgl( EglInterface& egl ) {}
+Dali::Adaptor& Adaptor::Get()
+{
+ DALI_ASSERT_ALWAYS( gAdaptor );
+ return *gAdaptor;
+}
- virtual void CreateEglSurface( EglInterface& egl ) {}
+Adaptor::Adaptor()
+{
+}
- virtual void DestroyEglSurface( EglInterface& egl ) {}
+Adaptor::~Adaptor()
+{
+ gAdaptor = nullptr;
+}
- virtual bool ReplaceEGLSurface( EglInterface& egl ) { return false; }
+void Adaptor::Start( Dali::Window window )
+{
+ AddWindow( &GetImplementation( window ) );
+}
- virtual void MoveResize( Dali::PositionSize positionSize ) {}
+Integration::Scene Adaptor::GetScene( Dali::Window window )
+{
+ return window.GetScene();
+}
- virtual void SetViewMode( ViewMode viewMode ) {}
+bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
+{
+ mCallbacks.PushBack( callback );
+ return true;
+}
- virtual void StartRender() {}
+void Adaptor::RemoveIdle( CallbackBase* callback )
+{
+ mCallbacks.Erase( std::find_if( mCallbacks.Begin(), mCallbacks.End(),
+ [ &callback ] ( CallbackBase* current ) { return callback == current; } ) );
+}
- virtual bool PreRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction ) { return false; }
+void Adaptor::RunIdles()
+{
+ for( auto& callback : mCallbacks )
+ {
+ CallbackBase::Execute( *callback );
+ }
- virtual void PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, DisplayConnection* displayConnection, bool replacingSurface ) {}
+ mCallbacks.Clear();
+}
- virtual void StopRender() {}
+Dali::RenderSurfaceInterface& Adaptor::GetSurface()
+{
+ DALI_ASSERT_ALWAYS( ! mWindows.empty() );
- virtual void ReleaseLock() {}
+ return reinterpret_cast < Dali::RenderSurfaceInterface& >( mWindows.front()->GetRenderSurface() );
+}
- virtual void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ) {}
+Dali::WindowContainer Adaptor::GetWindows()
+{
+ 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 );
+ }
+ }
-namespace Internal
-{
-namespace Adaptor
-{
+ return windows;
+}
-class Adaptor: public BaseObject
+Dali::SceneHolderList Adaptor::GetSceneHolders()
{
-public:
- static Dali::Adaptor& Get();
- Adaptor();
- ~Adaptor();
+ Dali::SceneHolderList sceneHolderList;
-public:
- static Dali::RenderSurface& GetSurface();
- static Dali::Adaptor::AdaptorSignalType& AdaptorSignal();
-};
+ for( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
+ {
+ sceneHolderList.push_back( Dali::Integration::SceneHolder( *iter ) );
+ }
-Dali::Adaptor& Adaptor::Get()
-{
- Dali::Adaptor* adaptor = new Dali::Adaptor;
- return *adaptor;
+ 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 )
+{
+ Integration::Core& core = mTestApplication->GetCore();
+ core.RegisterProcessor( processor );
}
+
+void Adaptor::UnregisterProcessor( Integration::Processor& processor )
+{
+ Integration::Core& core = mTestApplication->GetCore();
+ core.UnregisterProcessor( processor );
}
-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()
{
}
-bool Adaptor::AddIdle( CallbackBase* callback )
+bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
+{
+ return mImpl->AddIdle( callback, hasReturnValue );
+}
+
+void Adaptor::RemoveIdle( CallbackBase* callback )
+{
+ mImpl->RemoveIdle( 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()
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 )
{
}
bool Adaptor::IsAvailable()
{
- return false;
+ return Internal::Adaptor::gAdaptor;
}
void Adaptor::NotifySceneCreated()
{
}
-void Adaptor::SetMinimumPinchDistance(float distance)
-{
-}
-
void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
{
}
{
}
-void Adaptor::SetViewMode( ViewMode mode )
+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::SetStereoBase( float stereoBase )
+void Adaptor::RegisterProcessor( Integration::Processor& processor )
{
+ mImpl->RegisterProcessor( processor );
}
-Adaptor::Adaptor()
-: mImpl( NULL )
+void Adaptor::UnregisterProcessor( Integration::Processor& processor )
{
+ mImpl->UnregisterProcessor( processor );
}
} // namespace Dali