2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/adaptor/common/adaptor-impl.h>
20 #include <dali/internal/adaptor/common/adaptor-builder-impl.h>
23 #include <dali/public-api/common/stage.h>
24 #include <dali/public-api/actors/layer.h>
25 #include <dali/public-api/object/any.h>
26 #include <dali/devel-api/actors/actor-devel.h>
27 #include <dali/integration-api/debug.h>
28 #include <dali/integration-api/core.h>
29 #include <dali/integration-api/context-notifier.h>
30 #include <dali/integration-api/profiling.h>
31 #include <dali/integration-api/input-options.h>
32 #include <dali/integration-api/events/key-event-integ.h>
33 #include <dali/integration-api/events/touch-event-integ.h>
34 #include <dali/integration-api/events/wheel-event-integ.h>
35 #include <dali/integration-api/processor-interface.h>
38 #include <dali/public-api/dali-adaptor-common.h>
39 #include <dali/internal/system/common/thread-controller.h>
40 #include <dali/internal/system/common/performance-interface-factory.h>
41 #include <dali/internal/adaptor/common/lifecycle-observer.h>
43 #include <dali/internal/graphics/gles/egl-graphics-factory.h>
44 #include <dali/internal/graphics/gles/egl-graphics.h> // Temporary until Core is abstracted
46 #include <dali/devel-api/text-abstraction/font-client.h>
48 #include <dali/internal/system/common/callback-manager.h>
49 #include <dali/internal/accessibility/common/tts-player-impl.h>
50 #include <dali/internal/accessibility/common/accessibility-adaptor-impl.h>
51 #include <dali/internal/window-system/common/event-handler.h>
52 #include <dali/internal/graphics/gles/gl-proxy-implementation.h>
53 #include <dali/internal/graphics/gles/gl-implementation.h>
54 #include <dali/internal/graphics/gles/egl-sync-implementation.h>
55 #include <dali/internal/graphics/common/egl-image-extensions.h>
56 #include <dali/internal/clipboard/common/clipboard-impl.h>
57 #include <dali/internal/system/common/object-profiler.h>
58 #include <dali/internal/window-system/common/display-connection.h>
59 #include <dali/internal/window-system/common/window-impl.h>
60 #include <dali/internal/window-system/common/window-render-surface.h>
62 #include <dali/internal/system/common/logging.h>
64 #include <dali/internal/system/common/locale-utils.h>
65 #include <dali/internal/imaging/common/image-loader-plugin-proxy.h>
66 #include <dali/internal/imaging/common/image-loader.h>
69 using Dali::TextAbstraction::FontClient;
82 thread_local Adaptor* gThreadLocalAdaptor = NULL; // raw thread specific pointer to allow Adaptor::Get
83 } // unnamed namespace
85 Dali::Adaptor* Adaptor::New( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
87 Dali::Adaptor* adaptor = new Dali::Adaptor;
88 Adaptor* impl = new Adaptor( window, *adaptor, surface, environmentOptions );
89 adaptor->mImpl = impl;
91 Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder = new AdaptorBuilder();
92 auto graphicsFactory = mAdaptorBuilder->GetGraphicsFactory();
94 impl->Initialize( graphicsFactory, configuration );
95 delete mAdaptorBuilder; // Not needed anymore as the graphics interface has now been created
100 Dali::Adaptor* Adaptor::New( Dali::Integration::SceneHolder window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
102 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( window );
103 Dali::Adaptor* adaptor = New( window, windowImpl.GetSurface(), configuration, environmentOptions );
104 windowImpl.SetAdaptor( *adaptor );
108 Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
110 Dali::Adaptor* adaptor = new Dali::Adaptor; // Public adaptor
111 Adaptor* impl = new Adaptor( window, *adaptor, surface, environmentOptions ); // Impl adaptor
112 adaptor->mImpl = impl;
114 impl->Initialize( graphicsFactory, configuration );
119 Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
121 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( window );
122 Dali::Adaptor* adaptor = New( graphicsFactory, window, windowImpl.GetSurface(), configuration, environmentOptions );
123 windowImpl.SetAdaptor( *adaptor );
127 void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration::ContextLoss configuration )
129 // all threads here (event, update, and render) will send their logs to TIZEN Platform's LogMessage handler.
130 Dali::Integration::Log::LogFunction logFunction( Dali::TizenPlatform::LogMessage );
131 mEnvironmentOptions->SetLogFunction( logFunction );
132 mEnvironmentOptions->InstallLogFunction(); // install logging for main thread
134 mPlatformAbstraction = new TizenPlatform::TizenPlatformAbstraction;
137 GetDataStoragePath( path );
138 mPlatformAbstraction->SetDataStoragePath( path );
140 ResourcePolicy::DataRetention dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA;
141 if( configuration == Dali::Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS )
143 dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA;
146 // Note, Tizen does not use DALI_RETAINS_ALL_DATA, as it can reload images from files automatically.
148 if( mEnvironmentOptions->PerformanceServerRequired() )
150 mPerformanceInterface = PerformanceInterfaceFactory::CreateInterface( *this, *mEnvironmentOptions );
153 mEnvironmentOptions->CreateTraceManager( mPerformanceInterface );
154 mEnvironmentOptions->InstallTraceFunction(); // install tracing for main thread
156 mCallbackManager = CallbackManager::New();
158 Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
160 DALI_ASSERT_DEBUG( defaultWindow->GetSurface() && "Surface not initialized" );
162 mGraphics = &( graphicsFactory.Create() );
163 mGraphics->Initialize( mEnvironmentOptions );
165 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
167 // This will only be created once
168 eglGraphics->Create();
170 GlImplementation& mGLES = eglGraphics->GetGlesInterface();
171 EglSyncImplementation& eglSyncImpl = eglGraphics->GetSyncImplementation();
172 EglContextHelperImplementation& eglContextHelperImpl = eglGraphics->GetContextHelperImplementation();
174 mCore = Integration::Core::New( *this,
175 *mPlatformAbstraction,
178 eglContextHelperImpl,
179 dataRetentionPolicy ,
180 ( 0u != mEnvironmentOptions->GetRenderToFboInterval() ) ? Integration::RenderToFrameBuffer::TRUE : Integration::RenderToFrameBuffer::FALSE,
181 mGraphics->GetDepthBufferRequired(),
182 mGraphics->GetStencilBufferRequired() );
184 defaultWindow->SetAdaptor( Get() );
186 Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( defaultWindow ) );
189 mWindowCreatedSignal.Emit( window );
192 const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval();
193 if( 0u < timeInterval )
195 mObjectProfiler = new ObjectProfiler( timeInterval );
198 mNotificationTrigger = mTriggerEventFactory.CreateTriggerEvent( MakeCallback( this, &Adaptor::ProcessCoreEvents ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
200 mDisplayConnection = Dali::DisplayConnection::New( *mGraphics, defaultWindow->GetSurface()->GetSurfaceType() );
202 mThreadController = new ThreadController( *this, *mEnvironmentOptions );
204 // Should be called after Core creation
205 if( mEnvironmentOptions->GetPanGestureLoggingLevel() )
207 Integration::EnableProfiling( Dali::Integration::PROFILING_TYPE_PAN_GESTURE );
209 if( mEnvironmentOptions->GetPanGesturePredictionMode() >= 0 )
211 Integration::SetPanGesturePredictionMode(mEnvironmentOptions->GetPanGesturePredictionMode());
213 if( mEnvironmentOptions->GetPanGesturePredictionAmount() >= 0 )
215 Integration::SetPanGesturePredictionAmount(mEnvironmentOptions->GetPanGesturePredictionAmount());
217 if( mEnvironmentOptions->GetPanGestureMaximumPredictionAmount() >= 0 )
219 Integration::SetPanGestureMaximumPredictionAmount(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount());
221 if( mEnvironmentOptions->GetPanGestureMinimumPredictionAmount() >= 0 )
223 Integration::SetPanGestureMinimumPredictionAmount(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount());
225 if( mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment() >= 0 )
227 Integration::SetPanGesturePredictionAmountAdjustment(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment());
229 if( mEnvironmentOptions->GetPanGestureSmoothingMode() >= 0 )
231 Integration::SetPanGestureSmoothingMode(mEnvironmentOptions->GetPanGestureSmoothingMode());
233 if( mEnvironmentOptions->GetPanGestureSmoothingAmount() >= 0.0f )
235 Integration::SetPanGestureSmoothingAmount(mEnvironmentOptions->GetPanGestureSmoothingAmount());
237 if( mEnvironmentOptions->GetPanGestureUseActualTimes() >= 0 )
239 Integration::SetPanGestureUseActualTimes( mEnvironmentOptions->GetPanGestureUseActualTimes() == 0 ? true : false );
241 if( mEnvironmentOptions->GetPanGestureInterpolationTimeRange() >= 0 )
243 Integration::SetPanGestureInterpolationTimeRange( mEnvironmentOptions->GetPanGestureInterpolationTimeRange() );
245 if( mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() >= 0 )
247 Integration::SetPanGestureScalarOnlyPredictionEnabled( mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() == 0 ? true : false );
249 if( mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() >= 0 )
251 Integration::SetPanGestureTwoPointPredictionEnabled( mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() == 0 ? true : false );
253 if( mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() >= 0 )
255 Integration::SetPanGestureTwoPointInterpolatePastTime( mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() );
257 if( mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() >= 0.0f )
259 Integration::SetPanGestureTwoPointVelocityBias( mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() );
261 if( mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() >= 0.0f )
263 Integration::SetPanGestureTwoPointAccelerationBias( mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() );
265 if( mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() >= 0 )
267 Integration::SetPanGestureMultitapSmoothingRange( mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() );
269 if( mEnvironmentOptions->GetMinimumPanDistance() >= 0 )
271 Integration::SetPanGestureMinimumDistance( mEnvironmentOptions->GetMinimumPanDistance() );
273 if( mEnvironmentOptions->GetMinimumPanEvents() >= 0 )
275 Integration::SetPanGestureMinimumPanEvents( mEnvironmentOptions->GetMinimumPanEvents() );
277 if( mEnvironmentOptions->GetMinimumPinchDistance() >= 0 )
279 Integration::SetPinchGestureMinimumDistance( mEnvironmentOptions->GetMinimumPinchDistance() );
282 // Set max texture size
283 if( mEnvironmentOptions->GetMaxTextureSize() > 0 )
285 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize( mEnvironmentOptions->GetMaxTextureSize() );
291 // Ensure stop status
294 // set to NULL first as we do not want any access to Adaptor as it is being destroyed.
295 gThreadLocalAdaptor = NULL;
297 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
299 (*iter)->OnDestroy();
302 // Clear out all the handles to Windows
305 delete mThreadController; // this will shutdown render thread, which will call Core::ContextDestroyed before exit
306 delete mObjectProfiler;
310 delete mDisplayConnection;
311 delete mPlatformAbstraction;
312 delete mCallbackManager;
313 delete mPerformanceInterface;
315 mGraphics->Destroy();
317 // uninstall it on this thread (main actor thread)
318 Dali::Integration::Log::UninstallLogFunction();
320 // Delete environment options if we own it
321 if( mEnvironmentOptionsOwned )
323 delete mEnvironmentOptions;
327 void Adaptor::Start()
329 // It doesn't support restart after stop at this moment to support restarting, need more testing
330 if( READY != mState )
337 SetupSystemInformation();
339 // Start the callback manager
340 mCallbackManager->Start();
342 Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
344 unsigned int dpiHor, dpiVer;
347 defaultWindow->GetSurface()->GetDpi( dpiHor, dpiVer );
349 // set the DPI value for font rendering
350 FontClient fontClient = FontClient::Get();
351 fontClient.SetDpi( dpiHor, dpiVer );
353 // Initialize the thread controller
354 mThreadController->Initialize();
356 ProcessCoreEvents(); // Ensure any startup messages are processed.
358 // Initialize the image loader plugin
359 Internal::Adaptor::ImageLoaderPluginProxy::Initialize();
361 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
367 // Dali::Internal::Adaptor::Adaptor::Pause
368 void Adaptor::Pause()
370 // Only pause the adaptor if we're actually running.
371 if( RUNNING == mState )
373 // Inform observers that we are about to be paused.
374 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
379 // Pause all windows event handlers when adaptor paused
380 for( auto window : mWindows )
385 mThreadController->Pause();
388 // Ensure any messages queued during pause callbacks are processed by doing another update.
391 DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Paused\n" );
395 DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Not paused [%d]\n", mState );
399 // Dali::Internal::Adaptor::Adaptor::Resume
400 void Adaptor::Resume()
402 // Only resume the adaptor if we are in the suspended state.
403 if( PAUSED == mState )
407 // Reset the event handlers when adaptor resumed
408 for( auto window : mWindows )
413 // Inform observers that we have resumed.
414 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
419 // Trigger processing of events queued up while paused
420 mCore->ProcessEvents();
422 // Do at end to ensure our first update/render after resumption includes the processed messages as well
423 mThreadController->Resume();
425 DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Resumed\n");
429 DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Not resumed [%d]\n", mState );
435 if( RUNNING == mState ||
437 PAUSED_WHILE_HIDDEN == mState )
439 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
444 mThreadController->Stop();
446 // Delete the TTS player
447 for( int i =0; i < Dali::TtsPlayer::MODE_NUM; i++ )
451 mTtsPlayers[i].Reset();
455 // Destroy the image loader plugin
456 Internal::Adaptor::ImageLoaderPluginProxy::Destroy();
458 delete mNotificationTrigger;
459 mNotificationTrigger = NULL;
461 mCallbackManager->Stop();
465 DALI_LOG_RELEASE_INFO( "Adaptor::Stop\n" );
469 void Adaptor::ContextLost()
471 mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage
474 void Adaptor::ContextRegained()
476 // Inform core, so that texture resources can be reloaded
477 mCore->RecoverFromContextLoss();
479 mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage
482 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
484 Integration::Point convertedPoint( point );
485 mWindows.front()->FeedTouchPoint( convertedPoint, timeStamp );
488 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
490 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
491 mWindows.front()->FeedWheelEvent( event );
494 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
496 Integration::KeyEvent convertedEvent( keyEvent );
497 mWindows.front()->FeedKeyEvent( convertedEvent );
500 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& newSurface )
502 Internal::Adaptor::SceneHolder* windowImpl = &Dali::GetImplementation( window );
503 for( auto windowPtr : mWindows )
505 if( windowPtr == windowImpl ) // the window is not deleted
507 mResizedSignal.Emit( mAdaptor );
509 windowImpl->SetSurface( &newSurface );
511 // Flush the event queue to give the update-render thread chance
512 // to start processing messages for new camera setup etc as soon as possible
515 // This method blocks until the render thread has completed the replace.
516 mThreadController->ReplaceSurface( &newSurface );
522 void Adaptor::DeleteSurface( Dali::RenderSurfaceInterface& surface )
524 // Flush the event queue to give the update-render thread chance
525 // to start processing messages for new camera setup etc as soon as possible
528 // This method blocks until the render thread has finished rendering the current surface.
529 mThreadController->DeleteSurface( &surface );
532 Dali::RenderSurfaceInterface& Adaptor::GetSurface() const
534 return *mWindows.front()->GetSurface();
537 void Adaptor::ReleaseSurfaceLock()
539 mWindows.front()->GetSurface()->ReleaseLock();
542 Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
544 if( !mTtsPlayers[mode] )
546 // Create the TTS player when it needed, because it can reduce launching time.
547 mTtsPlayers[mode] = TtsPlayer::New(mode);
550 return mTtsPlayers[mode];
553 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd )
555 bool idleAdded(false);
557 // Only add an idle if the Adaptor is actually running
558 if( RUNNING == mState || READY == mState || forceAdd )
560 idleAdded = mCallbackManager->AddIdleCallback( callback, hasReturnValue );
566 void Adaptor::RemoveIdle( CallbackBase* callback )
568 mCallbackManager->RemoveIdleCallback( callback );
571 void Adaptor::SetPreRenderCallback( CallbackBase* callback )
573 mThreadController->SetPreRenderCallback( callback );
576 bool Adaptor::AddWindow( Dali::Integration::SceneHolder childWindow, const std::string& childWindowName, const std::string& childWindowClassName, bool childWindowMode )
578 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( childWindow );
579 windowImpl.SetAdaptor( Get() );
581 // Add the new Window to the container - the order is not important
582 mWindows.push_back( &windowImpl );
584 Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( &windowImpl ) );
587 mWindowCreatedSignal.Emit( window );
593 bool Adaptor::RemoveWindow( Dali::Integration::SceneHolder* childWindow )
595 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( *childWindow );
596 for ( WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter )
598 if( *iter == &windowImpl )
600 mWindows.erase( iter );
608 bool Adaptor::RemoveWindow( std::string childWindowName )
610 for ( WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter )
612 if( ( *iter )->GetName() == childWindowName )
614 mWindows.erase( iter );
622 bool Adaptor::RemoveWindow( Internal::Adaptor::SceneHolder* childWindow )
624 for ( WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter )
626 if( ( *iter )->GetId() == childWindow->GetId() )
628 mWindows.erase( iter );
636 Dali::Adaptor& Adaptor::Get()
638 DALI_ASSERT_ALWAYS( IsAvailable() && "Adaptor not instantiated" );
639 return gThreadLocalAdaptor->mAdaptor;
642 bool Adaptor::IsAvailable()
644 return gThreadLocalAdaptor != NULL;
647 void Adaptor::SceneCreated()
649 mCore->SceneCreated();
652 Dali::Integration::Core& Adaptor::GetCore()
657 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
659 mThreadController->SetRenderRefreshRate( numberOfVSyncsPerRender );
662 Dali::DisplayConnection& Adaptor::GetDisplayConnectionInterface()
664 DALI_ASSERT_DEBUG( mDisplayConnection && "Display connection not created" );
665 return *mDisplayConnection;
668 GraphicsInterface& Adaptor::GetGraphicsInterface()
670 DALI_ASSERT_DEBUG( mGraphics && "Graphics interface not created" );
674 Dali::Integration::PlatformAbstraction& Adaptor::GetPlatformAbstractionInterface()
676 return *mPlatformAbstraction;
679 TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
681 return *mNotificationTrigger;
684 TriggerEventFactoryInterface& Adaptor::GetTriggerEventFactoryInterface()
686 return mTriggerEventFactory;
689 SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
691 return mSocketFactory;
694 Dali::RenderSurfaceInterface* Adaptor::GetRenderSurfaceInterface()
696 if( !mWindows.empty() )
698 return mWindows.front()->GetSurface();
704 TraceInterface& Adaptor::GetKernelTraceInterface()
706 return mKernelTracer;
709 TraceInterface& Adaptor::GetSystemTraceInterface()
711 return mSystemTracer;
714 PerformanceInterface* Adaptor::GetPerformanceInterface()
716 return mPerformanceInterface;
719 Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
721 DALI_ASSERT_DEBUG( mPlatformAbstraction && "PlatformAbstraction not created" );
722 return *mPlatformAbstraction;
725 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
727 if( mTtsPlayers[mode] )
729 mTtsPlayers[mode].Reset();
733 Any Adaptor::GetNativeWindowHandle()
735 return mWindows.front()->GetNativeHandle();
738 Any Adaptor::GetGraphicsDisplay()
744 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
746 EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
747 display = eglImpl.GetDisplay();
753 void Adaptor::SetUseRemoteSurface(bool useRemoteSurface)
755 mUseRemoteSurface = useRemoteSurface;
758 void Adaptor::AddObserver( LifeCycleObserver& observer )
760 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
762 if ( match == mObservers.end() )
764 mObservers.push_back( &observer );
768 void Adaptor::RemoveObserver( LifeCycleObserver& observer )
770 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
772 if ( match != mObservers.end() )
774 mObservers.erase( match );
778 void Adaptor::QueueCoreEvent(const Dali::Integration::Event& event)
782 mCore->QueueEvent(event);
786 void Adaptor::ProcessCoreEvents()
790 if( mPerformanceInterface )
792 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_START );
795 mCore->ProcessEvents();
797 if( mPerformanceInterface )
799 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_END );
804 void Adaptor::RequestUpdate( bool forceUpdate )
810 mThreadController->RequestUpdate();
814 case PAUSED_WHILE_HIDDEN:
816 // When Dali applications are partially visible behind the lock-screen,
817 // the indicator must be updated (therefore allow updates in the PAUSED state)
820 mThreadController->RequestUpdateOnce();
832 void Adaptor::RequestProcessEventsOnIdle( bool forceProcess )
834 // Only request a notification if the Adaptor is actually running
835 // and we haven't installed the idle notification
836 if( ( ! mNotificationOnIdleInstalled ) && ( RUNNING == mState || READY == mState || forceProcess ) )
838 mNotificationOnIdleInstalled = AddIdleEnterer( MakeCallback( this, &Adaptor::ProcessCoreEventsFromIdle ), forceProcess );
842 void Adaptor::OnWindowShown()
844 if( PAUSED_WHILE_HIDDEN == mState )
846 // Adaptor can now be resumed
851 // Force a render task
854 else if( RUNNING == mState )
856 // Force a render task
859 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowShown: Update requested.\n" );
863 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowShown: Adaptor is not paused state.[%d]\n", mState );
867 void Adaptor::OnWindowHidden()
869 if( RUNNING == mState || READY == mState )
871 bool allWindowsHidden = true;
873 for( auto window : mWindows )
875 if ( window->IsVisible() )
877 allWindowsHidden = false;
882 // Only pause the adaptor when all the windows are hidden
883 if( allWindowsHidden )
885 if( mState == RUNNING )
889 // Adaptor cannot be resumed until any window is shown
890 mState = PAUSED_WHILE_HIDDEN;
892 else // mState is READY
894 // Pause the adaptor after the state gets RUNNING
895 mState = PAUSED_WHILE_INITIALIZING;
900 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowHidden: Some windows are shown. Don't pause adaptor.\n" );
905 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowHidden: Adaptor is not running state.[%d]\n", mState );
909 // Dali::Internal::Adaptor::Adaptor::OnDamaged
910 void Adaptor::OnDamaged( const DamageArea& area )
912 // This is needed for the case where Dali window is partially obscured
913 RequestUpdate( false );
916 void Adaptor::SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize )
918 mResizedSignal.Emit( mAdaptor );
921 void Adaptor::SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize )
923 // Flush the event queue to give the update-render thread chance
924 // to start processing messages for new camera setup etc as soon as possible
927 mThreadController->ResizeSurface();
930 void Adaptor::NotifySceneCreated()
932 GetCore().SceneCreated();
934 // Flush the event queue to give the update-render thread chance
935 // to start processing messages for new camera setup etc as soon as possible
938 // Start thread controller after the scene has been created
939 mThreadController->Start();
941 // Process after surface is created (registering to remote surface provider if required)
942 SurfaceInitialized();
944 if( mState != PAUSED_WHILE_INITIALIZING )
948 DALI_LOG_RELEASE_INFO( "Adaptor::NotifySceneCreated: Adaptor is running\n" );
956 mState = PAUSED_WHILE_HIDDEN;
958 DALI_LOG_RELEASE_INFO( "Adaptor::NotifySceneCreated: Adaptor is paused\n" );
962 void Adaptor::NotifyLanguageChanged()
964 mLanguageChangedSignal.Emit( mAdaptor );
967 void Adaptor::RenderOnce()
972 const LogFactoryInterface& Adaptor::GetLogFactory()
974 return *mEnvironmentOptions;
977 void Adaptor::RegisterProcessor( Integration::Processor& processor )
979 GetCore().RegisterProcessor(processor);
982 void Adaptor::UnregisterProcessor( Integration::Processor& processor )
984 GetCore().UnregisterProcessor(processor);
987 void Adaptor::RequestUpdateOnce()
989 if( mThreadController )
991 mThreadController->RequestUpdateOnce();
995 bool Adaptor::ProcessCoreEventsFromIdle()
999 // the idle handle automatically un-installs itself
1000 mNotificationOnIdleInstalled = false;
1005 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow( Dali::Actor& actor )
1007 Dali::Integration::Scene scene = Dali::Integration::Scene::Get( actor );
1009 for( auto window : mWindows )
1011 if ( scene == window->GetScene() )
1020 Dali::WindowContainer Adaptor::GetWindows() const
1022 Dali::WindowContainer windows;
1024 for ( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
1026 // Downcast to Dali::Window
1027 Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( *iter ) );
1030 windows.push_back( window );
1037 Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions)
1039 mLanguageChangedSignal(),
1040 mWindowCreatedSignal(),
1041 mAdaptor( adaptor ),
1044 mThreadController( nullptr ),
1045 mGraphics( nullptr ),
1046 mDisplayConnection( nullptr ),
1048 mPlatformAbstraction( nullptr ),
1049 mCallbackManager( nullptr ),
1050 mNotificationOnIdleInstalled( false ),
1051 mNotificationTrigger( nullptr ),
1052 mDaliFeedbackPlugin(),
1053 mFeedbackController( nullptr ),
1056 mEnvironmentOptions( environmentOptions ? environmentOptions : new EnvironmentOptions /* Create the options if not provided */),
1057 mPerformanceInterface( nullptr ),
1060 mTriggerEventFactory(),
1061 mObjectProfiler( nullptr ),
1063 mEnvironmentOptionsOwned( environmentOptions ? false : true /* If not provided then we own the object */ ),
1064 mUseRemoteSurface( false )
1066 DALI_ASSERT_ALWAYS( !IsAvailable() && "Cannot create more than one Adaptor per thread" );
1067 mWindows.insert( mWindows.begin(), &Dali::GetImplementation( window ) );
1069 gThreadLocalAdaptor = this;
1072 void Adaptor::SetRootLayoutDirection( std::string locale )
1074 Dali::Stage stage = Dali::Stage::GetCurrent();
1076 stage.GetRootLayer().SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,
1077 static_cast< LayoutDirection::Type >( Internal::Adaptor::Locale::GetDirection( std::string( locale ) ) ) );
1080 bool Adaptor::AddIdleEnterer( CallbackBase* callback, bool forceAdd )
1082 bool idleAdded( false );
1084 // Only add an idle if the Adaptor is actually running
1085 if( RUNNING == mState || READY == mState || forceAdd )
1087 idleAdded = mCallbackManager->AddIdleEntererCallback( callback );
1093 void Adaptor::RemoveIdleEnterer( CallbackBase* callback )
1095 mCallbackManager->RemoveIdleEntererCallback( callback );
1098 } // namespace Adaptor
1100 } // namespace Internal