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/touch-event-integ.h>
33 #include <dali/integration-api/processor-interface.h>
36 #include <dali/public-api/dali-adaptor-common.h>
37 #include <dali/internal/system/common/thread-controller.h>
38 #include <dali/internal/system/common/performance-interface-factory.h>
39 #include <dali/internal/adaptor/common/lifecycle-observer.h>
41 #include <dali/internal/graphics/gles/egl-graphics-factory.h>
42 #include <dali/internal/graphics/gles/egl-graphics.h> // Temporary until Core is abstracted
44 #include <dali/devel-api/text-abstraction/font-client.h>
46 #include <dali/internal/system/common/callback-manager.h>
47 #include <dali/internal/accessibility/common/tts-player-impl.h>
48 #include <dali/internal/accessibility/common/accessibility-adaptor-impl.h>
49 #include <dali/internal/window-system/common/event-handler.h>
50 #include <dali/internal/graphics/gles/gl-proxy-implementation.h>
51 #include <dali/internal/graphics/gles/gl-implementation.h>
52 #include <dali/internal/graphics/gles/egl-sync-implementation.h>
53 #include <dali/internal/graphics/common/egl-image-extensions.h>
54 #include <dali/internal/clipboard/common/clipboard-impl.h>
55 #include <dali/internal/graphics/common/vsync-monitor.h>
56 #include <dali/internal/system/common/object-profiler.h>
57 #include <dali/internal/window-system/common/display-connection.h>
58 #include <dali/internal/window-system/common/window-impl.h>
59 #include <dali/internal/window-system/common/window-render-surface.h>
61 #include <dali/internal/system/common/logging.h>
63 #include <dali/internal/system/common/locale-utils.h>
64 #include <dali/internal/imaging/common/image-loader-plugin-proxy.h>
65 #include <dali/internal/imaging/common/image-loader.h>
68 using Dali::TextAbstraction::FontClient;
81 thread_local Adaptor* gThreadLocalAdaptor = NULL; // raw thread specific pointer to allow Adaptor::Get
82 } // unnamed namespace
84 Dali::Adaptor* Adaptor::New( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
86 Dali::Adaptor* adaptor = new Dali::Adaptor;
87 Adaptor* impl = new Adaptor( window, *adaptor, surface, environmentOptions );
88 adaptor->mImpl = impl;
90 Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder = new AdaptorBuilder();
91 auto graphicsFactory = mAdaptorBuilder->GetGraphicsFactory();
93 impl->Initialize( graphicsFactory, configuration );
94 delete mAdaptorBuilder; // Not needed anymore as the graphics interface has now been created
99 Dali::Adaptor* Adaptor::New( Dali::Integration::SceneHolder window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
101 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( window );
102 Dali::Adaptor* adaptor = New( window, windowImpl.GetSurface(), configuration, environmentOptions );
103 windowImpl.SetAdaptor( *adaptor );
107 Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
109 Dali::Adaptor* adaptor = new Dali::Adaptor; // Public adaptor
110 Adaptor* impl = new Adaptor( window, *adaptor, surface, environmentOptions ); // Impl adaptor
111 adaptor->mImpl = impl;
113 impl->Initialize( graphicsFactory, configuration );
118 Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
120 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( window );
121 Dali::Adaptor* adaptor = New( graphicsFactory, window, windowImpl.GetSurface(), configuration, environmentOptions );
122 windowImpl.SetAdaptor( *adaptor );
126 void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration::ContextLoss configuration )
128 // all threads here (event, update, and render) will send their logs to TIZEN Platform's LogMessage handler.
129 Dali::Integration::Log::LogFunction logFunction( Dali::TizenPlatform::LogMessage );
130 mEnvironmentOptions->SetLogFunction( logFunction );
131 mEnvironmentOptions->InstallLogFunction(); // install logging for main thread
133 mPlatformAbstraction = new TizenPlatform::TizenPlatformAbstraction;
136 GetDataStoragePath( path );
137 mPlatformAbstraction->SetDataStoragePath( path );
139 ResourcePolicy::DataRetention dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA;
140 if( configuration == Dali::Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS )
142 dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA;
145 // Note, Tizen does not use DALI_RETAINS_ALL_DATA, as it can reload images from files automatically.
147 if( mEnvironmentOptions->PerformanceServerRequired() )
149 mPerformanceInterface = PerformanceInterfaceFactory::CreateInterface( *this, *mEnvironmentOptions );
152 mEnvironmentOptions->CreateTraceManager( mPerformanceInterface );
153 mEnvironmentOptions->InstallTraceFunction(); // install tracing for main thread
155 mCallbackManager = CallbackManager::New();
157 SceneHolderPtr defaultWindow = mWindows.front();
159 DALI_ASSERT_DEBUG( defaultWindow->GetSurface() && "Surface not initialized" );
161 mGraphics = &( graphicsFactory.Create() );
162 mGraphics->Initialize( mEnvironmentOptions );
164 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
166 // This will only be created once
167 eglGraphics->Create();
169 GlImplementation& mGLES = eglGraphics->GetGlesInterface();
170 EglSyncImplementation& eglSyncImpl = eglGraphics->GetSyncImplementation();
172 mCore = Integration::Core::New( *this,
173 *mPlatformAbstraction,
176 dataRetentionPolicy ,
177 ( 0u != mEnvironmentOptions->GetRenderToFboInterval() ) ? Integration::RenderToFrameBuffer::TRUE : Integration::RenderToFrameBuffer::FALSE,
178 mGraphics->GetDepthBufferRequired(),
179 mGraphics->GetStencilBufferRequired() );
181 defaultWindow->SetAdaptor( Get() );
183 const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval();
184 if( 0u < timeInterval )
186 mObjectProfiler = new ObjectProfiler( timeInterval );
189 mNotificationTrigger = mTriggerEventFactory.CreateTriggerEvent( MakeCallback( this, &Adaptor::ProcessCoreEvents ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
191 mVSyncMonitor = new VSyncMonitor;
193 mDisplayConnection = Dali::DisplayConnection::New( *mGraphics, defaultWindow->GetSurface()->GetSurfaceType() );
195 mThreadController = new ThreadController( *this, *mEnvironmentOptions );
197 // Should be called after Core creation
198 if( mEnvironmentOptions->GetPanGestureLoggingLevel() )
200 Integration::EnableProfiling( Dali::Integration::PROFILING_TYPE_PAN_GESTURE );
202 if( mEnvironmentOptions->GetPanGesturePredictionMode() >= 0 )
204 Integration::SetPanGesturePredictionMode(mEnvironmentOptions->GetPanGesturePredictionMode());
206 if( mEnvironmentOptions->GetPanGesturePredictionAmount() >= 0 )
208 Integration::SetPanGesturePredictionAmount(mEnvironmentOptions->GetPanGesturePredictionAmount());
210 if( mEnvironmentOptions->GetPanGestureMaximumPredictionAmount() >= 0 )
212 Integration::SetPanGestureMaximumPredictionAmount(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount());
214 if( mEnvironmentOptions->GetPanGestureMinimumPredictionAmount() >= 0 )
216 Integration::SetPanGestureMinimumPredictionAmount(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount());
218 if( mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment() >= 0 )
220 Integration::SetPanGesturePredictionAmountAdjustment(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment());
222 if( mEnvironmentOptions->GetPanGestureSmoothingMode() >= 0 )
224 Integration::SetPanGestureSmoothingMode(mEnvironmentOptions->GetPanGestureSmoothingMode());
226 if( mEnvironmentOptions->GetPanGestureSmoothingAmount() >= 0.0f )
228 Integration::SetPanGestureSmoothingAmount(mEnvironmentOptions->GetPanGestureSmoothingAmount());
230 if( mEnvironmentOptions->GetPanGestureUseActualTimes() >= 0 )
232 Integration::SetPanGestureUseActualTimes( mEnvironmentOptions->GetPanGestureUseActualTimes() == 0 ? true : false );
234 if( mEnvironmentOptions->GetPanGestureInterpolationTimeRange() >= 0 )
236 Integration::SetPanGestureInterpolationTimeRange( mEnvironmentOptions->GetPanGestureInterpolationTimeRange() );
238 if( mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() >= 0 )
240 Integration::SetPanGestureScalarOnlyPredictionEnabled( mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() == 0 ? true : false );
242 if( mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() >= 0 )
244 Integration::SetPanGestureTwoPointPredictionEnabled( mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() == 0 ? true : false );
246 if( mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() >= 0 )
248 Integration::SetPanGestureTwoPointInterpolatePastTime( mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() );
250 if( mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() >= 0.0f )
252 Integration::SetPanGestureTwoPointVelocityBias( mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() );
254 if( mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() >= 0.0f )
256 Integration::SetPanGestureTwoPointAccelerationBias( mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() );
258 if( mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() >= 0 )
260 Integration::SetPanGestureMultitapSmoothingRange( mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() );
262 if( mEnvironmentOptions->GetMinimumPanDistance() >= 0 )
264 Integration::SetPanGestureMinimumDistance( mEnvironmentOptions->GetMinimumPanDistance() );
266 if( mEnvironmentOptions->GetMinimumPanEvents() >= 0 )
268 Integration::SetPanGestureMinimumPanEvents( mEnvironmentOptions->GetMinimumPanEvents() );
270 if( mEnvironmentOptions->GetMinimumPinchDistance() >= 0 )
272 Integration::SetPinchGestureMinimumDistance( mEnvironmentOptions->GetMinimumPinchDistance() );
275 // Set max texture size
276 if( mEnvironmentOptions->GetMaxTextureSize() > 0 )
278 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize( mEnvironmentOptions->GetMaxTextureSize() );
284 // Ensure stop status
287 // set to NULL first as we do not want any access to Adaptor as it is being destroyed.
288 gThreadLocalAdaptor = NULL;
290 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
292 (*iter)->OnDestroy();
295 // Clear out all the handles to Windows
298 delete mThreadController; // this will shutdown render thread, which will call Core::ContextDestroyed before exit
299 delete mVSyncMonitor;
300 delete mObjectProfiler;
304 delete mDisplayConnection;
305 delete mPlatformAbstraction;
306 delete mCallbackManager;
307 delete mPerformanceInterface;
309 mGraphics->Destroy();
311 // uninstall it on this thread (main actor thread)
312 Dali::Integration::Log::UninstallLogFunction();
314 // Delete environment options if we own it
315 if( mEnvironmentOptionsOwned )
317 delete mEnvironmentOptions;
321 void Adaptor::Start()
323 // It doesn't support restart after stop at this moment to support restarting, need more testing
324 if( READY != mState )
331 SetupSystemInformation();
333 // Start the callback manager
334 mCallbackManager->Start();
336 SceneHolderPtr defaultWindow = mWindows.front();
338 unsigned int dpiHor, dpiVer;
341 defaultWindow->GetSurface()->GetDpi( dpiHor, dpiVer );
343 // set the DPI value for font rendering
344 FontClient fontClient = FontClient::Get();
345 fontClient.SetDpi( dpiHor, dpiVer );
347 // Tell the core the size of the surface just before we start the render-thread
348 mCore->SurfaceResized( defaultWindow->GetSurface() );
350 // Initialize the thread controller
351 mThreadController->Initialize();
353 ProcessCoreEvents(); // Ensure any startup messages are processed.
355 // Initialize the image loader plugin
356 Internal::Adaptor::ImageLoaderPluginProxy::Initialize();
358 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
364 // Dali::Internal::Adaptor::Adaptor::Pause
365 void Adaptor::Pause()
367 // Only pause the adaptor if we're actually running.
368 if( RUNNING == mState )
370 // Inform observers that we are about to be paused.
371 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
376 // Pause all windows event handlers when adaptor paused
377 for( SceneHolderPtr window : mWindows )
382 mThreadController->Pause();
385 // Ensure any messages queued during pause callbacks are processed by doing another update.
388 DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Paused\n" );
392 DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Not paused [%d]\n", mState );
396 // Dali::Internal::Adaptor::Adaptor::Resume
397 void Adaptor::Resume()
399 // Only resume the adaptor if we are in the suspended state.
400 if( PAUSED == mState )
404 // Reset the event handlers when adaptor resumed
405 for( SceneHolderPtr window : mWindows )
410 // Inform observers that we have resumed.
411 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
416 // Trigger processing of events queued up while paused
417 mCore->ProcessEvents();
419 // Do at end to ensure our first update/render after resumption includes the processed messages as well
420 mThreadController->Resume();
422 DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Resumed\n");
426 DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Not resumed [%d]\n", mState );
432 if( RUNNING == mState ||
434 PAUSED_WHILE_HIDDEN == mState )
436 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
441 mThreadController->Stop();
443 // Delete the TTS player
444 for( int i =0; i < Dali::TtsPlayer::MODE_NUM; i++ )
448 mTtsPlayers[i].Reset();
452 // Destroy the image loader plugin
453 Internal::Adaptor::ImageLoaderPluginProxy::Destroy();
455 delete mNotificationTrigger;
456 mNotificationTrigger = NULL;
458 mCallbackManager->Stop();
462 DALI_LOG_RELEASE_INFO( "Adaptor::Stop\n" );
466 void Adaptor::ContextLost()
468 mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage
471 void Adaptor::ContextRegained()
473 // Inform core, so that texture resources can be reloaded
474 mCore->RecoverFromContextLoss();
476 mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage
479 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
481 mWindows.front()->FeedTouchPoint( point, timeStamp );
484 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
486 mWindows.front()->FeedWheelEvent( wheelEvent );
489 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
491 mWindows.front()->FeedKeyEvent( keyEvent );
494 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& newSurface )
496 Internal::Adaptor::SceneHolder* windowImpl = &Dali::GetImplementation( window );
497 for( SceneHolderPtr windowPtr : mWindows )
499 if( windowPtr.Get() == windowImpl ) // the window is not deleted
501 // Let the core know the surface size has changed
502 mCore->SurfaceResized( &newSurface );
504 mResizedSignal.Emit( mAdaptor );
506 windowImpl->SetSurface( &newSurface );
508 // Flush the event queue to give the update-render thread chance
509 // to start processing messages for new camera setup etc as soon as possible
512 // This method blocks until the render thread has completed the replace.
513 mThreadController->ReplaceSurface( &newSurface );
519 Dali::RenderSurfaceInterface& Adaptor::GetSurface() const
521 return *mWindows.front()->GetSurface();
524 void Adaptor::ReleaseSurfaceLock()
526 mWindows.front()->GetSurface()->ReleaseLock();
529 Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
531 if( !mTtsPlayers[mode] )
533 // Create the TTS player when it needed, because it can reduce launching time.
534 mTtsPlayers[mode] = TtsPlayer::New(mode);
537 return mTtsPlayers[mode];
540 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd )
542 bool idleAdded(false);
544 // Only add an idle if the Adaptor is actually running
545 if( RUNNING == mState || READY == mState || forceAdd )
547 idleAdded = mCallbackManager->AddIdleCallback( callback, hasReturnValue );
553 void Adaptor::RemoveIdle( CallbackBase* callback )
555 mCallbackManager->RemoveIdleCallback( callback );
558 void Adaptor::SetPreRenderCallback( CallbackBase* callback )
560 mThreadController->SetPreRenderCallback( callback );
563 bool Adaptor::AddWindow( Dali::Integration::SceneHolder* childWindow, const std::string& childWindowName, const std::string& childWindowClassName, const bool& childWindowMode )
565 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( *childWindow );
566 windowImpl.SetAdaptor( Get() );
568 // Add the new Window to the container - the order is not important
569 mWindows.push_back( SceneHolderPtr( &windowImpl ) );
573 bool Adaptor::RemoveWindow( Dali::Integration::SceneHolder* childWindow )
575 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( *childWindow );
576 for ( WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter )
578 if( *iter == &windowImpl )
580 mWindows.erase( iter );
588 bool Adaptor::RemoveWindow( std::string childWindowName )
590 for ( WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter )
592 if( ( *iter )->GetName() == childWindowName )
594 mWindows.erase( iter );
602 bool Adaptor::RemoveWindow( Internal::Adaptor::SceneHolder* childWindow )
604 for ( WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter )
606 if( ( *iter )->GetId() == childWindow->GetId() )
608 mWindows.erase( iter );
616 Dali::Adaptor& Adaptor::Get()
618 DALI_ASSERT_ALWAYS( IsAvailable() && "Adaptor not instantiated" );
619 return gThreadLocalAdaptor->mAdaptor;
622 bool Adaptor::IsAvailable()
624 return gThreadLocalAdaptor != NULL;
627 void Adaptor::SceneCreated()
629 mCore->SceneCreated();
632 Dali::Integration::Core& Adaptor::GetCore()
637 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
639 mThreadController->SetRenderRefreshRate( numberOfVSyncsPerRender );
642 void Adaptor::SetUseHardwareVSync( bool useHardware )
644 mVSyncMonitor->SetUseHardwareVSync( useHardware );
647 Dali::DisplayConnection& Adaptor::GetDisplayConnectionInterface()
649 DALI_ASSERT_DEBUG( mDisplayConnection && "Display connection not created" );
650 return *mDisplayConnection;
653 GraphicsInterface& Adaptor::GetGraphicsInterface()
655 DALI_ASSERT_DEBUG( mGraphics && "Graphics interface not created" );
659 Dali::Integration::PlatformAbstraction& Adaptor::GetPlatformAbstractionInterface()
661 return *mPlatformAbstraction;
664 TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
666 return *mNotificationTrigger;
669 TriggerEventFactoryInterface& Adaptor::GetTriggerEventFactoryInterface()
671 return mTriggerEventFactory;
674 SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
676 return mSocketFactory;
679 Dali::RenderSurfaceInterface* Adaptor::GetRenderSurfaceInterface()
681 if( !mWindows.empty() )
683 return mWindows.front()->GetSurface();
689 VSyncMonitorInterface* Adaptor::GetVSyncMonitorInterface()
691 return mVSyncMonitor;
694 TraceInterface& Adaptor::GetKernelTraceInterface()
696 return mKernelTracer;
699 TraceInterface& Adaptor::GetSystemTraceInterface()
701 return mSystemTracer;
704 PerformanceInterface* Adaptor::GetPerformanceInterface()
706 return mPerformanceInterface;
709 Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
711 DALI_ASSERT_DEBUG( mPlatformAbstraction && "PlatformAbstraction not created" );
712 return *mPlatformAbstraction;
715 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
717 if( mTtsPlayers[mode] )
719 mTtsPlayers[mode].Reset();
723 Any Adaptor::GetNativeWindowHandle()
725 return mWindows.front()->GetNativeHandle();
728 Any Adaptor::GetGraphicsDisplay()
734 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
736 EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
737 display = eglImpl.GetDisplay();
743 void Adaptor::SetUseRemoteSurface(bool useRemoteSurface)
745 mUseRemoteSurface = useRemoteSurface;
748 void Adaptor::AddObserver( LifeCycleObserver& observer )
750 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
752 if ( match == mObservers.end() )
754 mObservers.push_back( &observer );
758 void Adaptor::RemoveObserver( LifeCycleObserver& observer )
760 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
762 if ( match != mObservers.end() )
764 mObservers.erase( match );
768 void Adaptor::QueueCoreEvent(const Dali::Integration::Event& event)
772 mCore->QueueEvent(event);
776 void Adaptor::ProcessCoreEvents()
780 if( mPerformanceInterface )
782 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_START );
785 mCore->ProcessEvents();
787 if( mPerformanceInterface )
789 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_END );
794 void Adaptor::RequestUpdate( bool forceUpdate )
800 mThreadController->RequestUpdate();
804 case PAUSED_WHILE_HIDDEN:
806 // When Dali applications are partially visible behind the lock-screen,
807 // the indicator must be updated (therefore allow updates in the PAUSED state)
810 mThreadController->RequestUpdateOnce();
822 void Adaptor::RequestProcessEventsOnIdle( bool forceProcess )
824 // Only request a notification if the Adaptor is actually running
825 // and we haven't installed the idle notification
826 if( ( ! mNotificationOnIdleInstalled ) && ( RUNNING == mState || READY == mState || forceProcess ) )
828 mNotificationOnIdleInstalled = AddIdleEnterer( MakeCallback( this, &Adaptor::ProcessCoreEventsFromIdle ), forceProcess );
832 void Adaptor::OnWindowShown()
834 if ( PAUSED_WHILE_HIDDEN == mState )
836 // Adaptor can now be resumed
841 // Force a render task
846 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowShown: Not shown [%d]\n", mState );
850 void Adaptor::OnWindowHidden()
852 if ( RUNNING == mState )
854 bool allWindowsHidden = true;
856 for( SceneHolderPtr window : mWindows )
858 if ( window->IsVisible() )
860 allWindowsHidden = false;
865 // Only pause the adaptor when all the windows are hidden
866 if ( allWindowsHidden )
870 // Adaptor cannot be resumed until any window is shown
871 mState = PAUSED_WHILE_HIDDEN;
876 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowHidden: Not hidden [%d]\n", mState );
880 // Dali::Internal::Adaptor::Adaptor::OnDamaged
881 void Adaptor::OnDamaged( const DamageArea& area )
883 // This is needed for the case where Dali window is partially obscured
884 RequestUpdate( false );
887 void Adaptor::SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize )
889 // Let the core know the surface size has changed
890 mCore->SurfaceResized( surface );
892 mResizedSignal.Emit( mAdaptor );
895 void Adaptor::SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize )
897 // Flush the event queue to give the update-render thread chance
898 // to start processing messages for new camera setup etc as soon as possible
901 mThreadController->ResizeSurface();
904 void Adaptor::NotifySceneCreated()
906 GetCore().SceneCreated();
908 // Flush the event queue to give the update-render thread chance
909 // to start processing messages for new camera setup etc as soon as possible
912 // Start thread controller after the scene has been created
913 mThreadController->Start();
915 // Process after surface is created (registering to remote surface provider if required)
916 SurfaceInitialized();
920 DALI_LOG_RELEASE_INFO( "Adaptor::NotifySceneCreated\n" );
923 void Adaptor::NotifyLanguageChanged()
925 mLanguageChangedSignal.Emit( mAdaptor );
928 void Adaptor::RenderOnce()
933 const LogFactoryInterface& Adaptor::GetLogFactory()
935 return *mEnvironmentOptions;
938 void Adaptor::RegisterProcessor( Integration::Processor& processor )
940 GetCore().RegisterProcessor(processor);
943 void Adaptor::UnregisterProcessor( Integration::Processor& processor )
945 GetCore().UnregisterProcessor(processor);
948 void Adaptor::RequestUpdateOnce()
950 if( mThreadController )
952 mThreadController->RequestUpdateOnce();
956 bool Adaptor::ProcessCoreEventsFromIdle()
960 // the idle handle automatically un-installs itself
961 mNotificationOnIdleInstalled = false;
966 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow( Dali::Actor& actor )
968 Dali::Integration::Scene scene = Dali::Integration::Scene::Get( actor );
970 for( auto window : mWindows )
972 if ( scene == window->GetScene() )
981 Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions)
983 mLanguageChangedSignal(),
987 mThreadController( nullptr ),
988 mVSyncMonitor( nullptr ),
989 mGraphics( nullptr ),
990 mDisplayConnection( nullptr ),
992 mPlatformAbstraction( nullptr ),
993 mCallbackManager( nullptr ),
994 mNotificationOnIdleInstalled( false ),
995 mNotificationTrigger( nullptr ),
996 mDaliFeedbackPlugin(),
997 mFeedbackController( nullptr ),
1000 mEnvironmentOptions( environmentOptions ? environmentOptions : new EnvironmentOptions /* Create the options if not provided */),
1001 mPerformanceInterface( nullptr ),
1004 mTriggerEventFactory(),
1005 mObjectProfiler( nullptr ),
1007 mEnvironmentOptionsOwned( environmentOptions ? false : true /* If not provided then we own the object */ ),
1008 mUseRemoteSurface( false )
1010 DALI_ASSERT_ALWAYS( !IsAvailable() && "Cannot create more than one Adaptor per thread" );
1011 mWindows.insert( mWindows.begin(), SceneHolderPtr( &Dali::GetImplementation( window ) ) );
1013 gThreadLocalAdaptor = this;
1016 void Adaptor::SetRootLayoutDirection( std::string locale )
1018 Dali::Stage stage = Dali::Stage::GetCurrent();
1020 stage.GetRootLayer().SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,
1021 static_cast< LayoutDirection::Type >( Internal::Adaptor::Locale::GetDirection( std::string( locale ) ) ) );
1024 bool Adaptor::AddIdleEnterer( CallbackBase* callback, bool forceAdd )
1026 bool idleAdded( false );
1028 // Only add an idle if the Adaptor is actually running
1029 if( RUNNING == mState || READY == mState || forceAdd )
1031 idleAdded = mCallbackManager->AddIdleEntererCallback( callback );
1037 void Adaptor::RemoveIdleEnterer( CallbackBase* callback )
1039 mCallbackManager->RemoveIdleEntererCallback( callback );
1042 } // namespace Adaptor
1044 } // namespace Internal