X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=adaptors%2Fcommon%2Fadaptor-impl.cpp;h=cdc1405ca996cfe5bfb767d64df9634a05e080df;hb=92191e13d5922ba1de4e094951becf436256510d;hp=8cd32dc7cbb1fac20c3aa3796ff1d2fb395ab25a;hpb=643f530ebe0e8b17dd703ba5238b0dee5eab7647;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/adaptors/common/adaptor-impl.cpp b/adaptors/common/adaptor-impl.cpp index 8cd32dc..cdc1405 100644 --- a/adaptors/common/adaptor-impl.cpp +++ b/adaptors/common/adaptor-impl.cpp @@ -28,21 +28,18 @@ #include // INTERNAL INCLUDES -#include -#include +#include +# include #include -#include +#include #include -#include #include #include -#include +#include #include #include -#include -#include #include #include #include @@ -53,6 +50,7 @@ #include #include #include +#include #include @@ -72,11 +70,10 @@ namespace __thread Adaptor* gThreadLocalAdaptor = NULL; // raw thread specific pointer to allow Adaptor::Get } // unnamed namespace -Dali::Adaptor* Adaptor::New( Any nativeWindow, RenderSurface *surface, const DeviceLayout& baseLayout, - Dali::Configuration::ContextLoss configuration ) +Dali::Adaptor* Adaptor::New( Any nativeWindow, RenderSurface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions ) { Dali::Adaptor* adaptor = new Dali::Adaptor; - Adaptor* impl = new Adaptor( nativeWindow, *adaptor, surface, baseLayout ); + Adaptor* impl = new Adaptor( nativeWindow, *adaptor, surface, environmentOptions ); adaptor->mImpl = impl; impl->Initialize(configuration); @@ -84,13 +81,22 @@ Dali::Adaptor* Adaptor::New( Any nativeWindow, RenderSurface *surface, const Dev return adaptor; } +Dali::Adaptor* Adaptor::New( Dali::Window window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions ) +{ + Any winId = window.GetNativeHandle(); + + Window& windowImpl = Dali::GetImplementation(window); + Dali::Adaptor* adaptor = New( winId, windowImpl.GetSurface(), configuration, environmentOptions ); + windowImpl.SetAdaptor(*adaptor); + return adaptor; +} void Adaptor::Initialize( Dali::Configuration::ContextLoss configuration ) { // 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 + mEnvironmentOptions->SetLogFunction( logFunction ); + mEnvironmentOptions->InstallLogFunction(); // install logging for main thread mPlatformAbstraction = new TizenPlatform::TizenPlatformAbstraction; @@ -101,25 +107,25 @@ void Adaptor::Initialize( Dali::Configuration::ContextLoss configuration ) ResourcePolicy::DataRetention dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA; if( configuration == Dali::Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS ) { - dataRetentionPolicy = ResourcePolicy::DALI_RETAINS_MESH_DATA; + dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA; } // Note, Tizen does not use DALI_RETAINS_ALL_DATA, as it can reload images from // files automatically. - if( mEnvironmentOptions.PerformanceServerRequired() ) + if( mEnvironmentOptions->PerformanceServerRequired() ) { - mPerformanceInterface = PerformanceInterfaceFactory::CreateInterface( *this, mEnvironmentOptions ); + mPerformanceInterface = PerformanceInterfaceFactory::CreateInterface( *this, *mEnvironmentOptions ); } mCallbackManager = CallbackManager::New(); PositionSize size = mSurface->GetPositionSize(); - mGestureManager = new GestureManager(*this, Vector2(size.width, size.height), mCallbackManager, mEnvironmentOptions); + mGestureManager = new GestureManager(*this, Vector2(size.width, size.height), mCallbackManager, *mEnvironmentOptions); - if( mEnvironmentOptions.GetGlesCallTime() > 0 ) + if( mEnvironmentOptions->GetGlesCallTime() > 0 ) { - mGLES = new GlProxyImplementation( mEnvironmentOptions ); + mGLES = new GlProxyImplementation( *mEnvironmentOptions ); } else { @@ -132,52 +138,50 @@ void Adaptor::Initialize( Dali::Configuration::ContextLoss configuration ) mCore = Integration::Core::New( *this, *mPlatformAbstraction, *mGLES, *eglSyncImpl, *mGestureManager, dataRetentionPolicy ); - mObjectProfiler = new ObjectProfiler(); + const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval(); + if( 0u < timeInterval ) + { + mObjectProfiler = new ObjectProfiler( timeInterval ); + } - mNotificationTrigger = new TriggerEvent( MakeCallback( this, &Adaptor::ProcessCoreEvents ) ); + mNotificationTrigger = mTriggerEventFactory.CreateTriggerEvent( MakeCallback( this, &Adaptor::ProcessCoreEvents ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER); mVSyncMonitor = new VSyncMonitor; - mUpdateRenderController = new UpdateRenderController( *this, mEnvironmentOptions ); - - mDaliFeedbackPlugin = new FeedbackPluginProxy( FeedbackPluginProxy::DEFAULT_OBJECT_NAME ); + mThreadController = new ThreadController( *this, *mEnvironmentOptions ); // Should be called after Core creation - if( mEnvironmentOptions.GetPanGestureLoggingLevel() ) + if( mEnvironmentOptions->GetPanGestureLoggingLevel() ) { Integration::EnableProfiling( Dali::Integration::PROFILING_TYPE_PAN_GESTURE ); } - if( mEnvironmentOptions.GetPanGesturePredictionMode() >= 0 ) + if( mEnvironmentOptions->GetPanGesturePredictionMode() >= 0 ) { - Integration::SetPanGesturePredictionMode(mEnvironmentOptions.GetPanGesturePredictionMode()); + Integration::SetPanGesturePredictionMode(mEnvironmentOptions->GetPanGesturePredictionMode()); } - if( mEnvironmentOptions.GetPanGesturePredictionAmount() >= 0 ) + if( mEnvironmentOptions->GetPanGesturePredictionAmount() >= 0 ) { - Integration::SetPanGesturePredictionAmount(mEnvironmentOptions.GetPanGesturePredictionAmount()); + Integration::SetPanGesturePredictionAmount(mEnvironmentOptions->GetPanGesturePredictionAmount()); } - if( mEnvironmentOptions.GetPanGestureMaximumPredictionAmount() >= 0 ) + if( mEnvironmentOptions->GetPanGestureMaximumPredictionAmount() >= 0 ) { - Integration::SetPanGestureMaximumPredictionAmount(mEnvironmentOptions.GetPanGestureMaximumPredictionAmount()); + Integration::SetPanGestureMaximumPredictionAmount(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount()); } - if( mEnvironmentOptions.GetPanGestureMinimumPredictionAmount() >= 0 ) + if( mEnvironmentOptions->GetPanGestureMinimumPredictionAmount() >= 0 ) { - Integration::SetPanGestureMinimumPredictionAmount(mEnvironmentOptions.GetPanGestureMinimumPredictionAmount()); + Integration::SetPanGestureMinimumPredictionAmount(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount()); } - if( mEnvironmentOptions.GetPanGesturePredictionAmountAdjustment() >= 0 ) + if( mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment() >= 0 ) { - Integration::SetPanGesturePredictionAmountAdjustment(mEnvironmentOptions.GetPanGesturePredictionAmountAdjustment()); + Integration::SetPanGesturePredictionAmountAdjustment(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment()); } - if( mEnvironmentOptions.GetPanGestureSmoothingMode() >= 0 ) + if( mEnvironmentOptions->GetPanGestureSmoothingMode() >= 0 ) { - Integration::SetPanGestureSmoothingMode(mEnvironmentOptions.GetPanGestureSmoothingMode()); + Integration::SetPanGestureSmoothingMode(mEnvironmentOptions->GetPanGestureSmoothingMode()); } - if( mEnvironmentOptions.GetPanGestureSmoothingAmount() >= 0.0f ) + if( mEnvironmentOptions->GetPanGestureSmoothingAmount() >= 0.0f ) { - Integration::SetPanGestureSmoothingAmount(mEnvironmentOptions.GetPanGestureSmoothingAmount()); - } - if( mEnvironmentOptions.GetWindowWidth() && mEnvironmentOptions.GetWindowHeight() ) - { - SurfaceResized( PositionSize( 0, 0, mEnvironmentOptions.GetWindowWidth(), mEnvironmentOptions.GetWindowHeight() )); + Integration::SetPanGestureSmoothingAmount(mEnvironmentOptions->GetPanGestureSmoothingAmount()); } } @@ -194,16 +198,13 @@ Adaptor::~Adaptor() (*iter)->OnDestroy(); } - delete mUpdateRenderController; // this will shutdown render thread, which will call Core::ContextDestroyed before exit + delete mThreadController; // this will shutdown render thread, which will call Core::ContextDestroyed before exit delete mVSyncMonitor; delete mEventHandler; delete mObjectProfiler; delete mCore; delete mEglFactory; - // Delete feedback controller before feedback plugin & style monitor dependencies - delete mFeedbackController; - delete mDaliFeedbackPlugin; delete mGLES; delete mGestureManager; delete mPlatformAbstraction; @@ -212,6 +213,12 @@ Adaptor::~Adaptor() // uninstall it on this thread (main actor thread) Dali::Integration::Log::UninstallLogFunction(); + + // Delete environment options if we own it + if( mEnvironmentOptionsOwned ) + { + delete mEnvironmentOptions; + } } void Adaptor::Start() @@ -250,19 +257,13 @@ void Adaptor::Start() PositionSize size = mSurface->GetPositionSize(); mCore->SurfaceResized( size.width, size.height ); - // Start the update & render threads - mUpdateRenderController->Start(); + // Initialize the thread controller + mThreadController->Initialize(); mState = RUNNING; ProcessCoreEvents(); // Ensure any startup messages are processed. - if ( !mFeedbackController ) - { - // Start sound & haptic feedback - mFeedbackController = new FeedbackController( *mDaliFeedbackPlugin ); - } - for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter ) { (*iter)->OnStart(); @@ -284,10 +285,10 @@ void Adaptor::Pause() // Reset the event handler when adaptor paused if( mEventHandler ) { - mEventHandler->Reset(); + mEventHandler->Pause(); } - mUpdateRenderController->Pause(); + mThreadController->Pause(); mCore->Suspend(); mState = PAUSED; } @@ -299,24 +300,12 @@ void Adaptor::Resume() // Only resume the adaptor if we are in the suspended state. if( PAUSED == mState ) { - // We put ResumeFrameTime first, as this was originally called at the start of mCore->Resume() - // If there were events pending, mCore->Resume() will call - // RenderController->RequestUpdate() - // UpdateRenderController->RequestUpdate() - // UpdateRenderSynchronization->RequestUpdate() - // and we should have reset the frame timers before allowing Core->Update() to be called. - //@todo Should we call UpdateRenderController->Resume before mCore->Resume()? - - mUpdateRenderController->ResumeFrameTime(); - mCore->Resume(); - mUpdateRenderController->Resume(); - mState = RUNNING; // Reset the event handler when adaptor resumed if( mEventHandler ) { - mEventHandler->Reset(); + mEventHandler->Resume(); } // Inform observers that we have resumed. @@ -325,7 +314,11 @@ void Adaptor::Resume() (*iter)->OnResume(); } - ProcessCoreEvents(); // Ensure any outstanding messages are processed + // Resume core so it processes any requests as well + mCore->Resume(); + + // Do at end to ensure our first update/render after resumption includes the processed messages as well + mThreadController->Resume(); } } @@ -340,7 +333,7 @@ void Adaptor::Stop() (*iter)->OnStop(); } - mUpdateRenderController->Stop(); + mThreadController->Stop(); mCore->Suspend(); // Delete the TTS player @@ -364,12 +357,25 @@ void Adaptor::Stop() } } +void Adaptor::ContextLost() +{ + mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage +} + +void Adaptor::ContextRegained() +{ + // Inform core, so that texture resources can be reloaded + mCore->RecoverFromContextLoss(); + + mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage +} + void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp ) { mEventHandler->FeedTouchPoint( point, timeStamp ); } -void Adaptor::FeedWheelEvent( MouseWheelEvent& wheelEvent ) +void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent ) { mEventHandler->FeedWheelEvent( wheelEvent ); } @@ -423,15 +429,8 @@ void Adaptor::ReplaceSurface( Any nativeWindow, RenderSurface& surface ) // to start processing messages for new camera setup etc as soon as possible ProcessCoreEvents(); - mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage - // this method blocks until the render thread has completed the replace. - mUpdateRenderController->ReplaceSurface(mSurface); - - // Inform core, so that texture resources can be reloaded - mCore->RecoverFromContextLoss(); - - mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage + mThreadController->ReplaceSurface(mSurface); } RenderSurface& Adaptor::GetSurface() const @@ -462,24 +461,12 @@ bool Adaptor::AddIdle( CallbackBase* callback ) // Only add an idle if the Adaptor is actually running if( RUNNING == mState ) { - idleAdded = mCallbackManager->AddCallback( callback, CallbackManager::IDLE_PRIORITY ); + idleAdded = mCallbackManager->AddIdleCallback( callback ); } return idleAdded; } -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 ); - } - - return callAdded; -} Dali::Adaptor& Adaptor::Get() { @@ -492,6 +479,11 @@ bool Adaptor::IsAvailable() return gThreadLocalAdaptor != NULL; } +void Adaptor::SceneCreated() +{ + mCore->SceneCreated(); +} + Dali::Integration::Core& Adaptor::GetCore() { return *mCore; @@ -499,7 +491,7 @@ Dali::Integration::Core& Adaptor::GetCore() void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender ) { - mUpdateRenderController->SetRenderRefreshRate( numberOfVSyncsPerRender ); + mThreadController->SetRenderRefreshRate( numberOfVSyncsPerRender ); } void Adaptor::SetUseHardwareVSync( bool useHardware ) @@ -534,7 +526,7 @@ Dali::Integration::GlAbstraction& Adaptor::GetGlesInterface() return *mGLES; } -TriggerEventInterface& Adaptor::GetTriggerEventInterface() +TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger() { return *mNotificationTrigger; } @@ -677,7 +669,7 @@ void Adaptor::RequestUpdate() if ( PAUSED == mState || RUNNING == mState ) { - mUpdateRenderController->RequestUpdate(); + mThreadController->RequestUpdate(); } } @@ -731,6 +723,14 @@ void Adaptor::SurfaceSizeChanged(const PositionSize& positionSize) mResizedSignal.Emit( mAdaptor ); } +void Adaptor::NotifySceneCreated() +{ + GetCore().SceneCreated(); + + // Start thread controller after the scene has been created + mThreadController->Start(); +} + void Adaptor::NotifyLanguageChanged() { mLanguageChangedSignal.Emit( mAdaptor ); @@ -740,9 +740,9 @@ void Adaptor::RequestUpdateOnce() { if( PAUSED_WHILE_HIDDEN != mState ) { - if( mUpdateRenderController ) + if( mThreadController ) { - mUpdateRenderController->RequestUpdateOnce(); + mThreadController->RequestUpdateOnce(); } } } @@ -755,15 +755,16 @@ void Adaptor::ProcessCoreEventsFromIdle() mNotificationOnIdleInstalled = false; } -Adaptor::Adaptor(Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface, const DeviceLayout& baseLayout) +Adaptor::Adaptor(Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface, EnvironmentOptions* environmentOptions) : mResizedSignal(), mLanguageChangedSignal(), - mAdaptor(adaptor), - mState(READY), - mCore(NULL), - mUpdateRenderController(NULL), - mVSyncMonitor(NULL), + mAdaptor( adaptor ), + mState( READY ), + mCore( NULL ), + mThreadController( NULL ), + mVSyncMonitor( NULL ), mGLES( NULL ), + mGlSync( NULL ), mEglFactory( NULL ), mNativeWindow( nativeWindow ), mSurface( surface ), @@ -771,17 +772,22 @@ Adaptor::Adaptor(Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surfac mEventHandler( NULL ), mCallbackManager( NULL ), mNotificationOnIdleInstalled( false ), - mNotificationTrigger(NULL), - mGestureManager(NULL), - mDaliFeedbackPlugin(NULL), - mFeedbackController(NULL), + mNotificationTrigger( NULL ), + mGestureManager( NULL ), + mDaliFeedbackPlugin(), + mFeedbackController( NULL ), + mTtsPlayers(), mObservers(), mDragAndDropDetector(), - mDeferredRotationObserver(NULL), - mBaseLayout(baseLayout), - mEnvironmentOptions(), - mPerformanceInterface(NULL), - mObjectProfiler(NULL) + mDeferredRotationObserver( NULL ), + mEnvironmentOptions( environmentOptions ? environmentOptions : new EnvironmentOptions /* Create the options if not provided */), + mPerformanceInterface( NULL ), + mKernelTracer(), + mSystemTracer(), + mTriggerEventFactory(), + mObjectProfiler( NULL ), + mSocketFactory(), + mEnvironmentOptionsOwned( environmentOptions ? false : true /* If not provided then we own the object */ ) { DALI_ASSERT_ALWAYS( !IsAvailable() && "Cannot create more than one Adaptor per thread" ); gThreadLocalAdaptor = this;