Change Adaptor implementation API in toolkit for multiple windows.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-adaptor.cpp
index 17bd210..10a2659 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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__
+// CLASS HEADER
+#include <dali/integration-api/adaptors/adaptor.h>
 
-#include "toolkit-adaptor.h"
-#include <map>
-#include <dali/public-api/common/dali-common.h>
-#include <dali/public-api/signals/dali-signal-v2.h>
+#include <dali/public-api/object/base-object.h>
+
+#include <toolkit-adaptor-impl.h>
+#include <dali/integration-api/debug.h>
+#include <test-application.h>
+#include <test-render-surface.h>
 
 namespace Dali
 {
 
-////////////////////////////////////////////////////////////////////////////////////////////////////
-
-class TestRenderSurface : public RenderSurface
+namespace Internal
 {
-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);}
-};
-
-typedef Dali::Rect<int> PositionSize;
-
-/**
- * Stub for the Adaptor
- */
-class Adaptor
+namespace Adaptor
 {
-public:
 
-  typedef SignalV2< void ( Adaptor& ) > AdaptorSignalV2;
-
-public:
+bool Adaptor::mAvailable = false;
+Vector<CallbackBase*> Adaptor::mCallbacks = Vector<CallbackBase*>();
 
-  Adaptor(ToolkitAdaptor& toolkitAdaptor);
-  ~Adaptor();
-
-public:
-
-  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();
-
-public: // static methods
-  static Adaptor& Get();
-  static bool IsAvailable();
-
-public:  // Signals
-
-  AdaptorSignalV2& SignalResize();
+Dali::Adaptor& Adaptor::Get()
+{
+  Dali::Adaptor* adaptor = new Dali::Adaptor;
+  Adaptor::mAvailable = true;
+  return *adaptor;
+}
 
-  void EmitSignalResize()
-  {
-    mResizeSignal.Emit( *this );
-  }
+Dali::RenderSurfaceInterface& Adaptor::GetSurface()
+{
+  Dali::RenderSurfaceInterface* renderSurface = reinterpret_cast <Dali::RenderSurfaceInterface*>( new Dali::TestRenderSurface( Dali::PositionSize( 0, 0, 480, 800 ) ) );
+  return *renderSurface;
+}
 
-private:
+Dali::Adaptor::AdaptorSignalType& Adaptor::AdaptorSignal()
+{
+  Dali::Adaptor::AdaptorSignalType* signal = new Dali::Adaptor::AdaptorSignalType;
+  return *signal;
+}
 
-  // Undefined
-  Adaptor(const Adaptor&);
-  Adaptor& operator=(Adaptor&);
+} // namespace Adaptor
+} // namespace Internal
 
-  AdaptorSignalV2 mResizeSignal;
-  TestRenderSurface mRenderSurface;
-  ToolkitAdaptor& mToolkitAdaptor;
-};
+Adaptor& Adaptor::New( Window window )
+{
+  return Internal::Adaptor::Adaptor::Get();
+}
 
-namespace
+Adaptor& Adaptor::New( Window window, Configuration::ContextLoss configuration )
 {
-Adaptor* gAdaptor = NULL;
+  return Internal::Adaptor::Adaptor::Get();
+}
 
+Adaptor& Adaptor::New( Window window, const Dali::RenderSurfaceInterface& surface )
+{
+  return Internal::Adaptor::Adaptor::Get();
 }
 
-Adaptor::Adaptor(ToolkitAdaptor& toolkitAdaptor)
-: mToolkitAdaptor(toolkitAdaptor)
+Adaptor& Adaptor::New( Window window, const Dali::RenderSurfaceInterface& surface, Configuration::ContextLoss configuration )
 {
+  return Internal::Adaptor::Adaptor::Get();
 }
 
 Adaptor::~Adaptor()
 {
-
 }
 
 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;
+  const bool isAvailable = IsAvailable();
+
+  if( isAvailable )
+  {
+    Internal::Adaptor::Adaptor::mCallbacks.PushBack( callback );
+  }
+
+  return isAvailable;
 }
 
-void Adaptor::FeedEvent(TouchPoint& point, int timeStamp)
+void Adaptor::RemoveIdle( CallbackBase* callback )
 {
-  mToolkitAdaptor.mFunctionsCalled.FeedEvent = true;
-  mToolkitAdaptor.mLastTouchPointFed = point;
-  mToolkitAdaptor.mLastTimeStampFed = timeStamp;
+  const bool isAvailable = IsAvailable();
+
+  if( isAvailable )
+  {
+    for( Vector<CallbackBase*>::Iterator it = Internal::Adaptor::Adaptor::mCallbacks.Begin(),
+           endIt = Internal::Adaptor::Adaptor::mCallbacks.End();
+         it != endIt;
+         ++it )
+    {
+      if( callback == *it )
+      {
+        Internal::Adaptor::Adaptor::mCallbacks.Remove( it );
+        return;
+      }
+    }
+  }
 }
 
-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)
+Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
 {
-  mToolkitAdaptor.mFunctionsCalled.SurfaceResized = true;
-  mToolkitAdaptor.mLastSizeSet = positionSize;
+  return Internal::Adaptor::Adaptor::AdaptorSignal();
 }
 
-void Adaptor::ReplaceSurface(RenderSurface& surface)
+Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
 {
-  mToolkitAdaptor.mFunctionsCalled.ReplaceSurface = true;
+  return Internal::Adaptor::Adaptor::AdaptorSignal();
 }
 
-void Adaptor::RenderSync()
+Dali::RenderSurfaceInterface& Adaptor::GetSurface()
 {
-  mToolkitAdaptor.mFunctionsCalled.RenderSync = true;
+  return Internal::Adaptor::Adaptor::GetSurface();
 }
 
-RenderSurface& Adaptor::GetSurface()
+Any Adaptor::GetNativeWindowHandle()
+{
+  Any window;
+  return window;
+}
+
+void Adaptor::ReleaseSurfaceLock()
+{
+}
+
+void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
+{
+}
+
+void Adaptor::SetUseHardwareVSync(bool useHardware)
 {
-  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::Adaptor::mAvailable;
+}
 
-  if (gAdaptor)
-  {
-    gAdaptor->mToolkitAdaptor.mFunctionsCalled.IsAvailable = true;
-    available = true;
-  }
+void Adaptor::NotifySceneCreated()
+{
+}
+
+void Adaptor::NotifyLanguageChanged()
+{
+}
+
+void Adaptor::SetMinimumPinchDistance(float distance)
+{
+}
 
-  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(&TestApplication::LogMessage);
+    Dali::Integration::Log::InstallLogFunction(logFunction);
+  }
+
+  LogFactory()
+  {
+  }
+  virtual ~LogFactory()
+  {
+  }
+};
+
+LogFactory* gLogFactory = NULL;
+const LogFactoryInterface& Adaptor::GetLogFactory()
 {
-  delete mAdaptorStub;
-  gAdaptor = NULL;
+  if( gLogFactory == NULL )
+  {
+    gLogFactory = new LogFactory;
+  }
+  return *gLogFactory;
 }
 
-void ToolkitAdaptor::EmitSignalResize()
+Adaptor::Adaptor()
+: mImpl( NULL )
 {
-  mAdaptorStub->EmitSignalResize();
 }
 
 } // namespace Dali