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=c27157d0b45f3956d2ba781fe2b1b7d5a9e3cabb;hb=7dbe383e1d72909ceb2ef46e33b880243911df7e;hpb=30f6ca1e541089b19f2b349a8a12d8a5bcaf2f9e 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 c27157d..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,263 +1,359 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#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 +{ + +/////////////////////////////////////////////////////////////////////////////// // -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at +// LogFactoryStub // -// http://floralicense.org/license/ +/////////////////////////////////////////////////////////////////////////////// + +class LogFactory : public LogFactoryInterface +{ +public: + 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 + +namespace Internal +{ +namespace Adaptor +{ + +/////////////////////////////////////////////////////////////////////////////// // -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// Dali::Internal::Adaptor::Adaptor Stub // +/////////////////////////////////////////////////////////////////////////////// -#define __DALI_ADAPTOR_H__ -#define __DALI_ACCESSIBILITY_MANAGER_H__ -#define __DALI_TIMER_H__ -#define __DALI_CLIPBOARD_H__ -#define IMFMANAGER_H +Dali::Adaptor* gAdaptor = nullptr; -#include "toolkit-adaptor.h" -#include -#include -#include +Dali::Adaptor& Adaptor::New() +{ + DALI_ASSERT_ALWAYS( ! gAdaptor ); + gAdaptor = new Dali::Adaptor; + return *gAdaptor; +} -namespace Dali +Dali::Adaptor& Adaptor::Get() { + DALI_ASSERT_ALWAYS( gAdaptor ); + return *gAdaptor; +} -//////////////////////////////////////////////////////////////////////////////////////////////////// +Adaptor::Adaptor() +{ +} -class TestRenderSurface : public RenderSurface +Adaptor::~Adaptor() { -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; } -}; + gAdaptor = nullptr; +} -typedef Dali::Rect PositionSize; +void Adaptor::Start( Dali::Window window ) +{ + AddWindow( &GetImplementation( window ) ); +} -/** - * Stub for the Adaptor - */ -class Adaptor +Integration::Scene Adaptor::GetScene( Dali::Window window ) { -public: + return window.GetScene(); +} - typedef SignalV2< void ( Adaptor& ) > AdaptorSignalV2; +bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue ) +{ + mCallbacks.PushBack( callback ); + return true; +} - typedef std::pair SingletonPair; - typedef std::map SingletonContainer; - typedef SingletonContainer::const_iterator SingletonConstIter; +void Adaptor::RemoveIdle( CallbackBase* callback ) +{ + mCallbacks.Erase( std::find_if( mCallbacks.Begin(), mCallbacks.End(), + [ &callback ] ( CallbackBase* current ) { return callback == current; } ) ); +} -public: +void Adaptor::RunIdles() +{ + for( auto& callback : mCallbacks ) + { + CallbackBase::Execute( *callback ); + } - Adaptor(ToolkitAdaptor& toolkitAdaptor); - ~Adaptor(); + mCallbacks.Clear(); +} -public: +Dali::RenderSurfaceInterface& Adaptor::GetSurface() +{ + DALI_ASSERT_ALWAYS( ! mWindows.empty() ); - 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(); + return reinterpret_cast < Dali::RenderSurfaceInterface& >( mWindows.front()->GetRenderSurface() ); +} - void RegisterSingleton(const std::type_info& info, Dali::BaseHandle singleton); - Dali::BaseHandle GetSingleton(const std::type_info& info) const; +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( *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() +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() +{ +} + +void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender ) +{ } -Dali::BaseHandle Adaptor::GetSingleton(const std::type_info& info) const +Adaptor& Adaptor::Get() { - mToolkitAdaptor.mFunctionsCalled.GetSingleton = true; + return Internal::Adaptor::Adaptor::Get(); +} - Dali::BaseHandle object = Dali::BaseHandle(); +bool Adaptor::IsAvailable() +{ + return Internal::Adaptor::gAdaptor; +} - SingletonConstIter iter = mSingletonContainer.find(info.name()); - if(iter != mSingletonContainer.end()) - { - object = (*iter).second; - } +void Adaptor::NotifySceneCreated() +{ +} - return object; +void Adaptor::NotifyLanguageChanged() +{ } -Adaptor::AdaptorSignalV2& Adaptor::SignalResize() +void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp ) { - mToolkitAdaptor.mFunctionsCalled.SignalResize = true; - return mResizeSignal; } -//////////////////////////////////////////////////////////////////////////////////////////////////// +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