X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Fdali-toolkit-test-utils%2Ftoolkit-adaptor.cpp;h=7c50cc7d268f98a24639ae192c981db7287811b0;hp=4e884e0ee73e85f48f94bc6b21314c104f6c29cb;hb=7dbe383e1d72909ceb2ef46e33b880243911df7e;hpb=3a727ff0ae4baf350511079f016aeaadd4b0faa9 diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-adaptor.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-adaptor.cpp index 4e884e0..7c50cc7 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-adaptor.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-adaptor.cpp @@ -1,5 +1,5 @@ /* - * 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. @@ -15,122 +15,219 @@ * */ -// CLASS HEADER -#include +#include -#include -#include +#include -namespace Dali -{ +// Don't want to include the actual window.h which otherwise will be indirectly included by adaptor.h. +#define DALI_WINDOW_H +#include +#include -class EglInterface; -class DisplayConnection; -class ThreadSynchronizationInterface; +#include +#include +#include +#include +#include -namespace Integration +namespace Dali { -class GlAbstraction; +namespace +{ -} // namespace Integration +/////////////////////////////////////////////////////////////////////////////// +// +// LogFactoryStub +// +/////////////////////////////////////////////////////////////////////////////// -class TestRenderSurface : public RenderSurface +class LogFactory : public LogFactoryInterface { public: - virtual PositionSize GetPositionSize() const { PositionSize size; return size; } + 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 - virtual void InitializeEgl( EglInterface& egl ) {} +namespace Internal +{ +namespace Adaptor +{ - virtual void CreateEglSurface( EglInterface& egl ) {} +/////////////////////////////////////////////////////////////////////////////// +// +// Dali::Internal::Adaptor::Adaptor Stub +// +/////////////////////////////////////////////////////////////////////////////// - virtual void DestroyEglSurface( EglInterface& egl ) {} +Dali::Adaptor* gAdaptor = nullptr; - virtual bool ReplaceEGLSurface( EglInterface& egl ) { return false; } +Dali::Adaptor& Adaptor::New() +{ + DALI_ASSERT_ALWAYS( ! gAdaptor ); + gAdaptor = new Dali::Adaptor; + return *gAdaptor; +} - virtual void MoveResize( Dali::PositionSize positionSize ) {} +Dali::Adaptor& Adaptor::Get() +{ + DALI_ASSERT_ALWAYS( gAdaptor ); + return *gAdaptor; +} - virtual void SetViewMode( ViewMode viewMode ) {} +Adaptor::Adaptor() +{ +} - virtual void StartRender() {} +Adaptor::~Adaptor() +{ + gAdaptor = nullptr; +} - virtual bool PreRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction ) { return false; } +void Adaptor::Start( Dali::Window window ) +{ + AddWindow( &GetImplementation( window ) ); +} - virtual void PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, DisplayConnection* displayConnection, bool replacingSurface ) {} +Integration::Scene Adaptor::GetScene( Dali::Window window ) +{ + return window.GetScene(); +} - virtual void StopRender() {} +bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue ) +{ + mCallbacks.PushBack( callback ); + return true; +} - virtual void ReleaseLock() {} +void Adaptor::RemoveIdle( CallbackBase* callback ) +{ + mCallbacks.Erase( std::find_if( mCallbacks.Begin(), mCallbacks.End(), + [ &callback ] ( CallbackBase* current ) { return callback == current; } ) ); +} - virtual void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ) {} +void Adaptor::RunIdles() +{ + for( auto& callback : mCallbacks ) + { + CallbackBase::Execute( *callback ); + } - virtual RenderSurface::Type GetSurfaceType() { return RenderSurface::ECORE_RENDER_SURFACE; } -}; + mCallbacks.Clear(); +} -namespace Internal -{ -namespace Adaptor +Dali::RenderSurfaceInterface& Adaptor::GetSurface() { + DALI_ASSERT_ALWAYS( ! mWindows.empty() ); + + return reinterpret_cast < Dali::RenderSurfaceInterface& >( mWindows.front()->GetRenderSurface() ); +} -class Adaptor: public BaseObject +Dali::WindowContainer Adaptor::GetWindows() { -public: - static Dali::Adaptor& Get(); - Adaptor(); - ~Adaptor(); + Dali::WindowContainer windows; -public: - static Dali::RenderSurface& GetSurface(); - static Dali::Adaptor::AdaptorSignalType& AdaptorSignal(); -}; + for ( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter ) + { + // Downcast to Dali::Window + Dali::Window window( dynamic_cast( *iter ) ); + if ( window ) + { + windows.push_back( window ); + } + } -Dali::Adaptor& Adaptor::Get() -{ - Dali::Adaptor* adaptor = new Dali::Adaptor; - return *adaptor; + return windows; } -Dali::RenderSurface& Adaptor::GetSurface() +Dali::SceneHolderList Adaptor::GetSceneHolders() { - Dali::RenderSurface *renderSurface = new Dali::TestRenderSurface; - return *renderSurface; + Dali::SceneHolderList sceneHolderList; + + for( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter ) + { + sceneHolderList.push_back( Dali::Integration::SceneHolder( *iter ) ); + } + + return sceneHolderList; } -Dali::Adaptor::AdaptorSignalType& Adaptor::AdaptorSignal() +Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow( Dali::Actor& actor ) { - Dali::Adaptor::AdaptorSignalType* signal = new Dali::Adaptor::AdaptorSignalType; - return *signal; -} + Dali::Integration::Scene scene = Dali::Integration::Scene::Get( actor ); + for( auto window : mWindows ) + { + if ( scene == window->GetScene() ) + { + return window; + } + } + + return nullptr; } -} + +void Adaptor::AddWindow( Internal::Adaptor::SceneHolder* window ) +{ + if ( window ) + { + mWindows.push_back( window ); + + Dali::Integration::SceneHolder newWindow( window ); + mWindowCreatedSignal.Emit( newWindow ); + } } -namespace Dali +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::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() @@ -149,28 +246,52 @@ void Adaptor::Stop() { } -bool Adaptor::AddIdle( CallbackBase* callback ) +bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue ) +{ + return mImpl->AddIdle( callback, hasReturnValue ); +} + +void Adaptor::RemoveIdle( CallbackBase* callback ) { - return false; + mImpl->RemoveIdle( callback ); } -void Adaptor::ReplaceSurface( Any nativeWindow, Dali::RenderSurface& surface ) +void Adaptor::ReplaceSurface( Window window, Dali::RenderSurfaceInterface& 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() @@ -179,15 +300,16 @@ 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 ) { } @@ -198,7 +320,7 @@ Adaptor& Adaptor::Get() bool Adaptor::IsAvailable() { - return false; + return Internal::Adaptor::gAdaptor; } void Adaptor::NotifySceneCreated() @@ -209,10 +331,6 @@ void Adaptor::NotifyLanguageChanged() { } -void Adaptor::SetMinimumPinchDistance(float distance) -{ -} - void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp ) { } @@ -229,17 +347,13 @@ void Adaptor::SceneCreated() { } -void Adaptor::SetViewMode( ViewMode mode ) -{ -} - -void Adaptor::SetStereoBase( float stereoBase ) -{ -} - -Adaptor::Adaptor() -: mImpl( NULL ) +const LogFactoryInterface& Adaptor::GetLogFactory() { + if( gLogFactory == NULL ) + { + gLogFactory = new LogFactory; + } + return *gLogFactory; } } // namespace Dali