Add API to notify adaptor that scene has been created
[platform/core/uifw/dali-adaptor.git] / adaptors / common / adaptor-impl.cpp
index 31f2f38..5fd0e15 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 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.
@@ -19,7 +19,6 @@
 #include "adaptor-impl.h"
 
 // EXTERNAL INCLUDES
-#include <boost/thread/tss.hpp>
 #include <dali/public-api/common/dali-common.h>
 #include <dali/integration-api/debug.h>
 #include <dali/integration-api/core.h>
 
 // INTERNAL INCLUDES
 #include <base/update-render-controller.h>
-#include <base/environment-variables.h>
 #include <base/performance-logging/performance-interface-factory.h>
 #include <base/lifecycle-observer.h>
 
+#include <dali/devel-api/text-abstraction/font-client.h>
+
 #include <callback-manager.h>
 #include <trigger-event.h>
-#include <window-render-surface.h>
-#include <render-surface-impl.h>
+#include <render-surface.h>
 #include <tts-player-impl.h>
 #include <accessibility-manager-impl.h>
-#include <timer-impl.h>
 #include <events/gesture-manager.h>
 #include <events/event-handler.h>
 #include <feedback/feedback-controller.h>
 #include <clipboard-impl.h>
 #include <vsync-monitor.h>
 #include <object-profiler.h>
+#include <base/display-connection.h>
 
-#include <slp-logging.h>
-
+#include <tizen-logging.h>
 
+using Dali::TextAbstraction::FontClient;
 
 namespace Dali
 {
@@ -70,52 +69,13 @@ namespace Adaptor
 
 namespace
 {
-boost::thread_specific_ptr<Adaptor> gThreadLocalAdaptor;
-
-unsigned int GetIntegerEnvironmentVariable( const char* variable, unsigned int defaultValue )
-{
-  const char* variableParameter = std::getenv(variable);
-
-  // if the parameter exists convert it to an integer, else return the default value
-  unsigned int intValue = variableParameter ? atoi(variableParameter) : defaultValue;
-  return intValue;
-}
-
-bool GetIntegerEnvironmentVariable( const char* variable, int& intValue )
-{
-  const char* variableParameter = std::getenv(variable);
-
-  if( !variableParameter )
-  {
-    return false;
-  }
-  // if the parameter exists convert it to an integer, else return the default value
-  intValue = atoi(variableParameter);
-  return true;
-}
-
-bool GetFloatEnvironmentVariable( const char* variable, float& floatValue )
-{
-  const char* variableParameter = std::getenv(variable);
-
-  if( !variableParameter )
-  {
-    return false;
-  }
-  // if the parameter exists convert it to an integer, else return the default value
-  floatValue = atof(variableParameter);
-  return true;
-}
-
+__thread Adaptor* gThreadLocalAdaptor = NULL; // raw thread specific pointer to allow Adaptor::Get
 } // unnamed namespace
 
-Dali::Adaptor* Adaptor::New( RenderSurface *surface, const DeviceLayout& baseLayout,
-                             Dali::Configuration::ContextLoss configuration )
+Dali::Adaptor* Adaptor::New( Any nativeWindow, RenderSurface *surface, Dali::Configuration::ContextLoss configuration )
 {
-  DALI_ASSERT_ALWAYS( surface->GetType() != Dali::RenderSurface::NO_SURFACE && "No surface for adaptor" );
-
   Dali::Adaptor* adaptor = new Dali::Adaptor;
-  Adaptor* impl = new Adaptor( *adaptor, surface, baseLayout );
+  Adaptor* impl = new Adaptor( nativeWindow, *adaptor, surface );
   adaptor->mImpl = impl;
 
   impl->Initialize(configuration);
@@ -123,72 +83,19 @@ Dali::Adaptor* Adaptor::New( RenderSurface *surface, const DeviceLayout& baseLay
   return adaptor;
 }
 
-void Adaptor::ParseEnvironmentOptions()
-{
-  // get logging options
-  unsigned int logFrameRateFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
-  unsigned int logupdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
-  unsigned int logPerformanceLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE, 0 );
-  unsigned int logPanGesture = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
-
-  // all threads here (event, update, and render) will send their logs to SLP Platform's LogMessage handler.
-  Dali::Integration::Log::LogFunction  logFunction(Dali::SlpPlatform::LogMessage);
-
-  mEnvironmentOptions.SetLogOptions( logFunction, logFrameRateFrequency, logupdateStatusFrequency, logPerformanceLevel, logPanGesture );
-
-  int predictionMode;
-  if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
-  {
-    mEnvironmentOptions.SetPanGesturePredictionMode(predictionMode);
-  }
-  int predictionAmount = -1;
-  if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
-  {
-    if( predictionAmount < 0 )
-    {
-      // do not support times in the past
-      predictionAmount = 0;
-    }
-    mEnvironmentOptions.SetPanGesturePredictionAmount(predictionAmount);
-  }
-  int smoothingMode;
-  if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
-  {
-    mEnvironmentOptions.SetPanGestureSmoothingMode(smoothingMode);
-  }
-  float smoothingAmount = 1.0f;
-  if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
-  {
-    smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
-    mEnvironmentOptions.SetPanGestureSmoothingAmount(smoothingAmount);
-  }
-
-  int minimumDistance(-1);
-  if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
-  {
-    mEnvironmentOptions.SetMinimumPanDistance( minimumDistance );
-  }
 
-  int minimumEvents(-1);
-  if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
-  {
-    mEnvironmentOptions.SetMinimumPanEvents( minimumEvents );
-  }
-
-  int glesCallTime(0);
-  if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
-  {
-    mEnvironmentOptions.SetGlesCallTime( glesCallTime );
-  }
-
-  mEnvironmentOptions.InstallLogFunction();
-}
-
-void Adaptor::Initialize(Dali::Configuration::ContextLoss configuration)
+void Adaptor::Initialize( Dali::Configuration::ContextLoss configuration )
 {
-  ParseEnvironmentOptions();
+  // all threads here (event, update, and render) will send their logs to TIZEN Platform's LogMessage handler.
+  Dali::Integration::Log::LogFunction logFunction( Dali::TizenPlatform::LogMessage );
+  mEnvironmentOptions.SetLogFunction( logFunction );
+  mEnvironmentOptions.InstallLogFunction(); // install logging for main thread
+
+  mPlatformAbstraction = new TizenPlatform::TizenPlatformAbstraction;
 
-  mPlatformAbstraction = new SlpPlatform::SlpPlatformAbstraction;
+  std::string path;
+  GetDataStoragePath( path );
+  mPlatformAbstraction->SetDataStoragePath( path );
 
   ResourcePolicy::DataRetention dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA;
   if( configuration == Dali::Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS )
@@ -198,7 +105,7 @@ void Adaptor::Initialize(Dali::Configuration::ContextLoss configuration)
   // Note, Tizen does not use DALI_RETAINS_ALL_DATA, as it can reload images from
   // files automatically.
 
-  if( mEnvironmentOptions.GetPerformanceLoggingLevel() > 0 )
+  if( mEnvironmentOptions.PerformanceServerRequired() )
   {
     mPerformanceInterface = PerformanceInterfaceFactory::CreateInterface( *this, mEnvironmentOptions );
   }
@@ -226,7 +133,7 @@ void Adaptor::Initialize(Dali::Configuration::ContextLoss configuration)
 
   mObjectProfiler = new ObjectProfiler();
 
-  mNotificationTrigger = new TriggerEvent( boost::bind(&Adaptor::ProcessCoreEvents, this) );
+  mNotificationTrigger = new TriggerEvent( MakeCallback( this, &Adaptor::ProcessCoreEvents ) );
 
   mVSyncMonitor = new VSyncMonitor;
 
@@ -243,10 +150,22 @@ void Adaptor::Initialize(Dali::Configuration::ContextLoss configuration)
   {
     Integration::SetPanGesturePredictionMode(mEnvironmentOptions.GetPanGesturePredictionMode());
   }
-  if( mEnvironmentOptions.GetPanGesturePredictionAmount() >= 0.0f )
+  if( mEnvironmentOptions.GetPanGesturePredictionAmount() >= 0 )
   {
     Integration::SetPanGesturePredictionAmount(mEnvironmentOptions.GetPanGesturePredictionAmount());
   }
+  if( mEnvironmentOptions.GetPanGestureMaximumPredictionAmount() >= 0 )
+  {
+    Integration::SetPanGestureMaximumPredictionAmount(mEnvironmentOptions.GetPanGestureMaximumPredictionAmount());
+  }
+  if( mEnvironmentOptions.GetPanGestureMinimumPredictionAmount() >= 0 )
+  {
+    Integration::SetPanGestureMinimumPredictionAmount(mEnvironmentOptions.GetPanGestureMinimumPredictionAmount());
+  }
+  if( mEnvironmentOptions.GetPanGesturePredictionAmountAdjustment() >= 0 )
+  {
+    Integration::SetPanGesturePredictionAmountAdjustment(mEnvironmentOptions.GetPanGesturePredictionAmountAdjustment());
+  }
   if( mEnvironmentOptions.GetPanGestureSmoothingMode() >= 0 )
   {
     Integration::SetPanGestureSmoothingMode(mEnvironmentOptions.GetPanGestureSmoothingMode());
@@ -255,6 +174,10 @@ void Adaptor::Initialize(Dali::Configuration::ContextLoss configuration)
   {
     Integration::SetPanGestureSmoothingAmount(mEnvironmentOptions.GetPanGestureSmoothingAmount());
   }
+  if( mEnvironmentOptions.GetWindowWidth() && mEnvironmentOptions.GetWindowHeight() )
+  {
+    SurfaceResized( PositionSize( 0, 0, mEnvironmentOptions.GetWindowWidth(), mEnvironmentOptions.GetWindowHeight() ));
+  }
 }
 
 Adaptor::~Adaptor()
@@ -262,8 +185,8 @@ Adaptor::~Adaptor()
   // Ensure stop status
   Stop();
 
-  // Release first as we do not want any access to Adaptor as it is being destroyed.
-  gThreadLocalAdaptor.release();
+  // set to NULL first as we do not want any access to Adaptor as it is being destroyed.
+  gThreadLocalAdaptor = NULL;
 
   for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
   {
@@ -311,22 +234,16 @@ void Adaptor::Start()
     mDeferredRotationObserver = NULL;
   }
 
-  // guarantee map the surface before starting render-thread.
-  mSurface->Map();
-
-  // NOTE: dpi must be set before starting the render thread
-  // use default or command line settings if not run on device
-#ifdef __arm__
-  // set the DPI value for font rendering
   unsigned int dpiHor, dpiVer;
   dpiHor = dpiVer = 0;
-  mSurface->GetDpi(dpiHor, dpiVer);
+  Dali::DisplayConnection::GetDpi(dpiHor, dpiVer);
 
-  // tell core about the value
+  // tell core about the DPI value
   mCore->SetDpi(dpiHor, dpiVer);
-#else
-  mCore->SetDpi(mHDpi, mVDpi);
-#endif
+
+  // set the DPI value for font rendering
+  FontClient fontClient = FontClient::Get();
+  fontClient.SetDpi( dpiHor, dpiVer );
 
   // Tell the core the size of the surface just before we start the render-thread
   PositionSize size = mSurface->GetPositionSize();
@@ -451,7 +368,7 @@ void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
   mEventHandler->FeedTouchPoint( point, timeStamp );
 }
 
-void Adaptor::FeedWheelEvent( MouseWheelEvent& wheelEvent )
+void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
 {
   mEventHandler->FeedWheelEvent( wheelEvent );
 }
@@ -494,22 +411,12 @@ void Adaptor::SurfaceResized( const PositionSize& positionSize )
   }
 }
 
-void Adaptor::ReplaceSurface( Dali::RenderSurface& surface )
+void Adaptor::ReplaceSurface( Any nativeWindow, RenderSurface& surface )
 {
-  // adaptor implementation needs the implementation of
-  RenderSurface* internalSurface = dynamic_cast<Internal::Adaptor::RenderSurface*>( &surface );
-  DALI_ASSERT_ALWAYS( internalSurface && "Incorrect surface" );
-
-  ECore::WindowRenderSurface* windowSurface = dynamic_cast<Internal::Adaptor::ECore::WindowRenderSurface*>( &surface);
-  if( windowSurface != NULL )
-  {
-    windowSurface->Map();
-    // @todo Restart event handler with new surface
-  }
-
-  mSurface = internalSurface;
+  mNativeWindow = nativeWindow;
+  mSurface = &surface;
 
-  SurfaceSizeChanged( internalSurface->GetPositionSize() );
+  SurfaceSizeChanged(mSurface->GetPositionSize());
 
   // flush the event queue to give update and render threads chance
   // to start processing messages for new camera setup etc as soon as possible
@@ -518,7 +425,7 @@ void Adaptor::ReplaceSurface( Dali::RenderSurface& surface )
   mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage
 
   // this method blocks until the render thread has completed the replace.
-  mUpdateRenderController->ReplaceSurface(internalSurface);
+  mUpdateRenderController->ReplaceSurface(mSurface);
 
   // Inform core, so that texture resources can be reloaded
   mCore->RecoverFromContextLoss();
@@ -526,7 +433,7 @@ void Adaptor::ReplaceSurface( Dali::RenderSurface& surface )
   mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage
 }
 
-Dali::RenderSurface& Adaptor::GetSurface() const
+RenderSurface& Adaptor::GetSurface() const
 {
   return *mSurface;
 }
@@ -547,27 +454,27 @@ Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
   return mTtsPlayers[mode];
 }
 
-bool Adaptor::AddIdle(boost::function<void(void)> callBack)
+bool Adaptor::AddIdle( CallbackBase* callback )
 {
   bool idleAdded(false);
 
   // Only add an idle if the Adaptor is actually running
   if( RUNNING == mState )
   {
-    idleAdded = mCallbackManager->AddCallback(callBack, CallbackManager::IDLE_PRIORITY);
+    idleAdded = mCallbackManager->AddCallback( callback, CallbackManager::IDLE_PRIORITY );
   }
 
   return idleAdded;
 }
 
-bool Adaptor::CallFromMainLoop(boost::function<void(void)> callBack)
+bool Adaptor::CallFromMainLoop( CallbackBase* callback )
 {
   bool callAdded(false);
 
   // Only allow the callback if the Adaptor is actually running
   if ( RUNNING == mState )
   {
-    callAdded = mCallbackManager->AddCallback(callBack, CallbackManager::DEFAULT_PRIORITY);
+    callAdded = mCallbackManager->AddCallback( callback, CallbackManager::DEFAULT_PRIORITY );
   }
 
   return callAdded;
@@ -575,13 +482,13 @@ bool Adaptor::CallFromMainLoop(boost::function<void(void)> callBack)
 
 Dali::Adaptor& Adaptor::Get()
 {
-  DALI_ASSERT_ALWAYS( gThreadLocalAdaptor.get() != NULL && "Adaptor not instantiated" );
+  DALI_ASSERT_ALWAYS( IsAvailable() && "Adaptor not instantiated" );
   return gThreadLocalAdaptor->mAdaptor;
 }
 
 bool Adaptor::IsAvailable()
 {
-  return gThreadLocalAdaptor.get() != NULL;
+  return gThreadLocalAdaptor != NULL;
 }
 
 Dali::Integration::Core& Adaptor::GetCore()
@@ -599,12 +506,6 @@ void Adaptor::SetUseHardwareVSync( bool useHardware )
   mVSyncMonitor->SetUseHardwareVSync( useHardware );
 }
 
-void Adaptor::SetDpi(size_t hDpi, size_t vDpi)
-{
-  mHDpi = hDpi;
-  mVDpi = vDpi;
-}
-
 EglFactory& Adaptor::GetEGLFactory() const
 {
   DALI_ASSERT_DEBUG( mEglFactory && "EGL Factory not created" );
@@ -636,24 +537,37 @@ TriggerEventInterface& Adaptor::GetTriggerEventInterface()
 {
   return *mNotificationTrigger;
 }
+
 TriggerEventFactoryInterface& Adaptor::GetTriggerEventFactoryInterface()
 {
   return mTriggerEventFactory;
 }
+
+SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
+{
+  return mSocketFactory;
+}
+
 RenderSurface* Adaptor::GetRenderSurfaceInterface()
 {
   return mSurface;
 }
+
 VSyncMonitorInterface* Adaptor::GetVSyncMonitorInterface()
 {
   return mVSyncMonitor;
 }
 
-KernelTraceInterface& Adaptor::GetKernelTraceInterface()
+TraceInterface& Adaptor::GetKernelTraceInterface()
 {
   return mKernelTracer;
 }
 
+TraceInterface& Adaptor::GetSystemTraceInterface()
+{
+  return mSystemTracer;
+}
+
 PerformanceInterface* Adaptor::GetPerformanceInterface()
 {
   return mPerformanceInterface;
@@ -704,6 +618,10 @@ void Adaptor::SetMinimumPinchDistance(float distance)
   }
 }
 
+Any Adaptor::GetNativeWindowHandle()
+{
+  return mNativeWindow;
+}
 
 void Adaptor::AddObserver( LifeCycleObserver& observer )
 {
@@ -768,7 +686,7 @@ void Adaptor::RequestProcessEventsOnIdle()
   // and we haven't installed the idle notification
   if( ( ! mNotificationOnIdleInstalled ) && ( RUNNING == mState ) )
   {
-    mNotificationOnIdleInstalled = AddIdle( boost::bind( &Adaptor::ProcessCoreEventsFromIdle, this ) );
+    mNotificationOnIdleInstalled = AddIdle( MakeCallback( this, &Adaptor::ProcessCoreEventsFromIdle ) );
   }
 }
 
@@ -809,12 +727,17 @@ void Adaptor::SurfaceSizeChanged(const PositionSize& positionSize)
   // let the core know the surface size has changed
   mCore->SurfaceResized(positionSize.width, positionSize.height);
 
-  mResizedSignalV2.Emit( mAdaptor );
+  mResizedSignal.Emit( mAdaptor );
+}
+
+void Adaptor::NotifySceneCreated()
+{
+  GetCore().SceneCreated();
 }
 
 void Adaptor::NotifyLanguageChanged()
 {
-  mLanguageChangedSignalV2.Emit( mAdaptor );
+  mLanguageChangedSignal.Emit( mAdaptor );
 }
 
 void Adaptor::RequestUpdateOnce()
@@ -836,9 +759,9 @@ void Adaptor::ProcessCoreEventsFromIdle()
   mNotificationOnIdleInstalled = false;
 }
 
-Adaptor::Adaptor(Dali::Adaptor& adaptor, RenderSurface* surface, const DeviceLayout& baseLayout)
-: mResizedSignalV2(),
-  mLanguageChangedSignalV2(),
+Adaptor::Adaptor(Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface)
+: mResizedSignal(),
+  mLanguageChangedSignal(),
   mAdaptor(adaptor),
   mState(READY),
   mCore(NULL),
@@ -846,6 +769,7 @@ Adaptor::Adaptor(Dali::Adaptor& adaptor, RenderSurface* surface, const DeviceLay
   mVSyncMonitor(NULL),
   mGLES( NULL ),
   mEglFactory( NULL ),
+  mNativeWindow( nativeWindow ),
   mSurface( surface ),
   mPlatformAbstraction( NULL ),
   mEventHandler( NULL ),
@@ -853,20 +777,17 @@ Adaptor::Adaptor(Dali::Adaptor& adaptor, RenderSurface* surface, const DeviceLay
   mNotificationOnIdleInstalled( false ),
   mNotificationTrigger(NULL),
   mGestureManager(NULL),
-  mHDpi( 0 ),
-  mVDpi( 0 ),
   mDaliFeedbackPlugin(NULL),
   mFeedbackController(NULL),
   mObservers(),
   mDragAndDropDetector(),
   mDeferredRotationObserver(NULL),
-  mBaseLayout(baseLayout),
   mEnvironmentOptions(),
   mPerformanceInterface(NULL),
   mObjectProfiler(NULL)
 {
-  DALI_ASSERT_ALWAYS( gThreadLocalAdaptor.get() == NULL && "Cannot create more than one Adaptor per thread" );
-  gThreadLocalAdaptor.reset(this);
+  DALI_ASSERT_ALWAYS( !IsAvailable() && "Cannot create more than one Adaptor per thread" );
+  gThreadLocalAdaptor = this;
 }
 
 // Stereoscopy