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=186fadd9671933d0d27ac4cb5a27424edf60cd7d;hb=7dbe383e1d72909ceb2ef46e33b880243911df7e;hpb=fca68202d695c569739819fb8d58b9808b8decb5 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 186fadd..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,250 +15,345 @@ * */ -#define __DALI_ADAPTOR_H__ -#define __DALI_ACCESSIBILITY_MANAGER_H__ -#define __DALI_TIMER_H__ -#define __DALI_CLIPBOARD_H__ -#define __DALI_IMF_MANAGER_H__ +#include -#include "toolkit-adaptor.h" -#include -#include -#include +#include + +// Don't want to include the actual window.h which otherwise will be indirectly included by adaptor.h. +#define DALI_WINDOW_H +#include +#include + +#include +#include +#include +#include +#include namespace Dali { -//////////////////////////////////////////////////////////////////////////////////////////////////// +namespace +{ -class TestRenderSurface : public RenderSurface +/////////////////////////////////////////////////////////////////////////////// +// +// LogFactoryStub +// +/////////////////////////////////////////////////////////////////////////////// + +class LogFactory : public LogFactoryInterface { 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; } + 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 -typedef Dali::Rect PositionSize; +namespace Internal +{ +namespace Adaptor +{ -/** - * Stub for the Adaptor - */ -class Adaptor +/////////////////////////////////////////////////////////////////////////////// +// +// Dali::Internal::Adaptor::Adaptor Stub +// +/////////////////////////////////////////////////////////////////////////////// + +Dali::Adaptor* gAdaptor = nullptr; + +Dali::Adaptor& Adaptor::New() { -public: + DALI_ASSERT_ALWAYS( ! gAdaptor ); + gAdaptor = new Dali::Adaptor; + return *gAdaptor; +} + +Dali::Adaptor& Adaptor::Get() +{ + DALI_ASSERT_ALWAYS( gAdaptor ); + return *gAdaptor; +} - typedef SignalV2< void ( Adaptor& ) > AdaptorSignalV2; +Adaptor::Adaptor() +{ +} - typedef std::pair SingletonPair; - typedef std::map SingletonContainer; - typedef SingletonContainer::const_iterator SingletonConstIter; +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 Start(); - void Pause(); - void Resume(); - void Stop(); - bool AddIdle(boost::function 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(); +void Adaptor::RemoveIdle( CallbackBase* callback ) +{ + mCallbacks.Erase( std::find_if( mCallbacks.Begin(), mCallbacks.End(), + [ &callback ] ( CallbackBase* current ) { return callback == current; } ) ); +} - void RegisterSingleton(const std::type_info& info, Dali::BaseHandle singleton); - Dali::BaseHandle GetSingleton(const std::type_info& info) const; +void Adaptor::RunIdles() +{ + for( auto& callback : mCallbacks ) + { + CallbackBase::Execute( *callback ); + } + + 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( *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 ) ); + } - SingletonContainer mSingletonContainer; -}; + 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 ); + } +} + +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 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 ) { - mToolkitAdaptor.mFunctionsCalled.SurfaceResized = true; - mToolkitAdaptor.mLastSizeSet = positionSize; } -void Adaptor::ReplaceSurface(RenderSurface& surface) +Adaptor::AdaptorSignalType& Adaptor::ResizedSignal() { - mToolkitAdaptor.mFunctionsCalled.ReplaceSurface = true; + return mImpl->ResizedSignal(); } -void Adaptor::RenderSync() +Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal() { - mToolkitAdaptor.mFunctionsCalled.RenderSync = true; + return mImpl->LanguageChangedSignal(); } -RenderSurface& Adaptor::GetSurface() +Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal() { - mToolkitAdaptor.mFunctionsCalled.GetSurface = true; - return mRenderSurface; + return mImpl->WindowCreatedSignal(); } -Adaptor& Adaptor::Get() +Dali::RenderSurfaceInterface& Adaptor::GetSurface() { - DALI_ASSERT_ALWAYS(gAdaptor); - gAdaptor->mToolkitAdaptor.mFunctionsCalled.Get = true; - return *gAdaptor; + return mImpl->GetSurface(); } -bool Adaptor::IsAvailable() +Dali::WindowContainer Adaptor::GetWindows() const { - bool available(false); + return mImpl->GetWindows(); +} - if (gAdaptor) - { - gAdaptor->mToolkitAdaptor.mFunctionsCalled.IsAvailable = true; - available = true; - } +Dali::SceneHolderList Adaptor::GetSceneHolders() const +{ + return mImpl->GetSceneHolders(); +} - return available; +Any Adaptor::GetNativeWindowHandle() +{ + Any window; + return window; } -void Adaptor::RegisterSingleton(const std::type_info& info, Dali::BaseHandle singleton) +Any Adaptor::GetNativeWindowHandle( Actor actor ) { - mToolkitAdaptor.mFunctionsCalled.RegisterSingleton = true; + return GetNativeWindowHandle(); +} - if(singleton) - { - mSingletonContainer.insert(SingletonPair(info.name(), singleton)); - } +void Adaptor::ReleaseSurfaceLock() +{ } -Dali::BaseHandle Adaptor::GetSingleton(const std::type_info& info) const +void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender ) { - mToolkitAdaptor.mFunctionsCalled.GetSingleton = true; +} - Dali::BaseHandle object = Dali::BaseHandle(); +Adaptor& Adaptor::Get() +{ + return Internal::Adaptor::Adaptor::Get(); +} - SingletonConstIter iter = mSingletonContainer.find(info.name()); - if(iter != mSingletonContainer.end()) - { - object = (*iter).second; - } +bool Adaptor::IsAvailable() +{ + return Internal::Adaptor::gAdaptor; +} - return object; +void Adaptor::NotifySceneCreated() +{ } -Adaptor::AdaptorSignalV2& Adaptor::SignalResize() +void Adaptor::NotifyLanguageChanged() { - mToolkitAdaptor.mFunctionsCalled.SignalResize = true; - return mResizeSignal; } -//////////////////////////////////////////////////////////////////////////////////////////////////// +void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp ) +{ +} + +void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent ) +{ +} -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::FeedKeyEvent( KeyEvent& keyEvent ) { - gAdaptor = mAdaptorStub; } -ToolkitAdaptor::~ToolkitAdaptor() +void Adaptor::SceneCreated() { - delete mAdaptorStub; - gAdaptor = NULL; } -void ToolkitAdaptor::EmitSignalResize() +const LogFactoryInterface& Adaptor::GetLogFactory() { - mAdaptorStub->EmitSignalResize(); + if( gLogFactory == NULL ) + { + gLogFactory = new LogFactory; + } + return *gLogFactory; } } // namespace Dali