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/input/common/gesture-manager.h>
50 #include <dali/internal/window-system/common/event-handler.h>
51 #include <dali/internal/graphics/gles/gl-proxy-implementation.h>
52 #include <dali/internal/graphics/gles/gl-implementation.h>
53 #include <dali/internal/graphics/gles/egl-sync-implementation.h>
54 #include <dali/internal/graphics/common/egl-image-extensions.h>
55 #include <dali/internal/clipboard/common/clipboard-impl.h>
56 #include <dali/internal/graphics/common/vsync-monitor.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
86 Dali::Adaptor* Adaptor::New( Any nativeWindow, Dali::RenderSurfaceInterface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
88 Dali::Adaptor* adaptor = new Dali::Adaptor;
89 Adaptor* impl = new Adaptor( nativeWindow, *adaptor, surface, environmentOptions );
90 adaptor->mImpl = impl;
92 Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder = new AdaptorBuilder();
93 auto graphicsFactory = mAdaptorBuilder->GetGraphicsFactory();
95 impl->Initialize( graphicsFactory, configuration );
96 delete mAdaptorBuilder; // Not needed anymore as the graphics interface has now been created
101 Dali::Adaptor* Adaptor::New( Dali::Window window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
103 Any winId = window.GetNativeHandle();
105 Window& windowImpl = Dali::GetImplementation( window );
106 Dali::Adaptor* adaptor = New( winId, windowImpl.GetSurface(), configuration, environmentOptions );
107 windowImpl.SetAdaptor( *adaptor );
111 Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Any nativeWindow, Dali::RenderSurfaceInterface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
113 Dali::Adaptor* adaptor = new Dali::Adaptor; // Public adaptor
114 Adaptor* impl = new Adaptor( nativeWindow, *adaptor, surface, environmentOptions ); // Impl adaptor
115 adaptor->mImpl = impl;
117 impl->Initialize( graphicsFactory, configuration );
122 Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Dali::Window window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
124 Any winId = window.GetNativeHandle();
126 Window& windowImpl = Dali::GetImplementation( window );
127 Dali::Adaptor* adaptor = New( graphicsFactory, winId, windowImpl.GetSurface(), configuration, environmentOptions );
128 windowImpl.SetAdaptor( *adaptor );
132 void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration::ContextLoss configuration )
134 // all threads here (event, update, and render) will send their logs to TIZEN Platform's LogMessage handler.
135 Dali::Integration::Log::LogFunction logFunction( Dali::TizenPlatform::LogMessage );
136 mEnvironmentOptions->SetLogFunction( logFunction );
137 mEnvironmentOptions->InstallLogFunction(); // install logging for main thread
139 mPlatformAbstraction = new TizenPlatform::TizenPlatformAbstraction;
142 GetDataStoragePath( path );
143 mPlatformAbstraction->SetDataStoragePath( path );
145 ResourcePolicy::DataRetention dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA;
146 if( configuration == Dali::Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS )
148 dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA;
151 // Note, Tizen does not use DALI_RETAINS_ALL_DATA, as it can reload images from files automatically.
153 if( mEnvironmentOptions->PerformanceServerRequired() )
155 mPerformanceInterface = PerformanceInterfaceFactory::CreateInterface( *this, *mEnvironmentOptions );
158 mEnvironmentOptions->CreateTraceManager( mPerformanceInterface );
159 mEnvironmentOptions->InstallTraceFunction(); // install tracing for main thread
161 mCallbackManager = CallbackManager::New();
163 WindowPane defaultWindow = mWindowFrame.front();
165 DALI_ASSERT_DEBUG( defaultWindow.surface && "Surface not initialized" );
167 PositionSize size = defaultWindow.surface->GetPositionSize();
169 defaultWindow.surface->SetAdaptor(*this);
171 mGestureManager = new GestureManager(*this, Vector2(size.width, size.height), mCallbackManager, *mEnvironmentOptions);
173 mGraphics = &( graphicsFactory.Create() );
174 mGraphics->Initialize( mEnvironmentOptions );
176 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
178 // This will only be created once
179 eglGraphics->Create();
181 GlImplementation& mGLES = eglGraphics->GetGlesInterface();
182 EglSyncImplementation& eglSyncImpl = eglGraphics->GetSyncImplementation();
184 mCore = Integration::Core::New( *this,
185 *mPlatformAbstraction,
189 dataRetentionPolicy ,
190 ( 0u != mEnvironmentOptions->GetRenderToFboInterval() ) ? Integration::RenderToFrameBuffer::TRUE : Integration::RenderToFrameBuffer::FALSE,
191 mGraphics->GetDepthBufferRequired(),
192 mGraphics->GetStencilBufferRequired() );
194 const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval();
195 if( 0u < timeInterval )
197 mObjectProfiler = new ObjectProfiler( timeInterval );
200 mNotificationTrigger = mTriggerEventFactory.CreateTriggerEvent( MakeCallback( this, &Adaptor::ProcessCoreEvents ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
202 mVSyncMonitor = new VSyncMonitor;
204 mDisplayConnection = Dali::DisplayConnection::New( *mGraphics, defaultWindow.surface->GetSurfaceType() );
206 mThreadController = new ThreadController( *this, *mEnvironmentOptions );
208 // Should be called after Core creation
209 if( mEnvironmentOptions->GetPanGestureLoggingLevel() )
211 Integration::EnableProfiling( Dali::Integration::PROFILING_TYPE_PAN_GESTURE );
213 if( mEnvironmentOptions->GetPanGesturePredictionMode() >= 0 )
215 Integration::SetPanGesturePredictionMode(mEnvironmentOptions->GetPanGesturePredictionMode());
217 if( mEnvironmentOptions->GetPanGesturePredictionAmount() >= 0 )
219 Integration::SetPanGesturePredictionAmount(mEnvironmentOptions->GetPanGesturePredictionAmount());
221 if( mEnvironmentOptions->GetPanGestureMaximumPredictionAmount() >= 0 )
223 Integration::SetPanGestureMaximumPredictionAmount(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount());
225 if( mEnvironmentOptions->GetPanGestureMinimumPredictionAmount() >= 0 )
227 Integration::SetPanGestureMinimumPredictionAmount(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount());
229 if( mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment() >= 0 )
231 Integration::SetPanGesturePredictionAmountAdjustment(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment());
233 if( mEnvironmentOptions->GetPanGestureSmoothingMode() >= 0 )
235 Integration::SetPanGestureSmoothingMode(mEnvironmentOptions->GetPanGestureSmoothingMode());
237 if( mEnvironmentOptions->GetPanGestureSmoothingAmount() >= 0.0f )
239 Integration::SetPanGestureSmoothingAmount(mEnvironmentOptions->GetPanGestureSmoothingAmount());
241 if( mEnvironmentOptions->GetPanGestureUseActualTimes() >= 0 )
243 Integration::SetPanGestureUseActualTimes( mEnvironmentOptions->GetPanGestureUseActualTimes() == 0 ? true : false );
245 if( mEnvironmentOptions->GetPanGestureInterpolationTimeRange() >= 0 )
247 Integration::SetPanGestureInterpolationTimeRange( mEnvironmentOptions->GetPanGestureInterpolationTimeRange() );
249 if( mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() >= 0 )
251 Integration::SetPanGestureScalarOnlyPredictionEnabled( mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() == 0 ? true : false );
253 if( mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() >= 0 )
255 Integration::SetPanGestureTwoPointPredictionEnabled( mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() == 0 ? true : false );
257 if( mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() >= 0 )
259 Integration::SetPanGestureTwoPointInterpolatePastTime( mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() );
261 if( mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() >= 0.0f )
263 Integration::SetPanGestureTwoPointVelocityBias( mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() );
265 if( mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() >= 0.0f )
267 Integration::SetPanGestureTwoPointAccelerationBias( mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() );
269 if( mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() >= 0 )
271 Integration::SetPanGestureMultitapSmoothingRange( mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() );
274 // Set max texture size
275 if( mEnvironmentOptions->GetMaxTextureSize() > 0 )
277 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize( mEnvironmentOptions->GetMaxTextureSize() );
283 // Ensure stop status
286 // set to NULL first as we do not want any access to Adaptor as it is being destroyed.
287 gThreadLocalAdaptor = NULL;
289 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
291 (*iter)->OnDestroy();
294 delete mThreadController; // this will shutdown render thread, which will call Core::ContextDestroyed before exit
295 delete mVSyncMonitor;
296 delete mEventHandler;
297 delete mObjectProfiler;
301 delete mGestureManager;
302 delete mDisplayConnection;
303 delete mPlatformAbstraction;
304 delete mCallbackManager;
305 delete mPerformanceInterface;
307 mGraphics->Destroy();
309 // uninstall it on this thread (main actor thread)
310 Dali::Integration::Log::UninstallLogFunction();
312 // Delete environment options if we own it
313 if( mEnvironmentOptionsOwned )
315 delete mEnvironmentOptions;
319 void Adaptor::Start()
321 // It doesn't support restart after stop at this moment to support restarting, need more testing
322 if( READY != mState )
329 SetupSystemInformation();
331 // Start the callback manager
332 mCallbackManager->Start();
334 WindowPane defaultWindow = mWindowFrame.front();
336 // Create event handler
337 mEventHandler = new EventHandler( defaultWindow.surface, *this, *mGestureManager, *this, mDragAndDropDetector );
339 if( mDeferredRotationObserver != NULL )
341 mEventHandler->SetRotationObserver(mDeferredRotationObserver);
342 mDeferredRotationObserver = NULL;
345 unsigned int dpiHor, dpiVer;
348 defaultWindow.surface->GetDpi( dpiHor, dpiVer );
350 // set the DPI value for font rendering
351 FontClient fontClient = FontClient::Get();
352 fontClient.SetDpi( dpiHor, dpiVer );
354 // Tell the core the size of the surface just before we start the render-thread
355 mCore->SurfaceResized( defaultWindow.surface );
357 // Initialize the thread controller
358 mThreadController->Initialize();
360 ProcessCoreEvents(); // Ensure any startup messages are processed.
362 // Initialize the image loader plugin
363 Internal::Adaptor::ImageLoaderPluginProxy::Initialize();
365 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
371 // Dali::Internal::Adaptor::Adaptor::Pause
372 void Adaptor::Pause()
374 // Only pause the adaptor if we're actually running.
375 if( RUNNING == mState )
377 // Inform observers that we are about to be paused.
378 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
383 // Reset the event handler when adaptor paused
386 mEventHandler->Pause();
389 mThreadController->Pause();
392 // Ensure any messages queued during pause callbacks are processed by doing another update.
395 DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Paused\n" );
399 DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Not paused [%d]\n", mState );
403 // Dali::Internal::Adaptor::Adaptor::Resume
404 void Adaptor::Resume()
406 // Only resume the adaptor if we are in the suspended state.
407 if( PAUSED == mState )
411 // Reset the event handler when adaptor resumed
414 mEventHandler->Resume();
417 // Inform observers that we have resumed.
418 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
423 // Trigger processing of events queued up while paused
424 mCore->ProcessEvents();
426 // Do at end to ensure our first update/render after resumption includes the processed messages as well
427 mThreadController->Resume();
429 DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Resumed\n");
433 DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Not resumed [%d]\n", mState );
439 if( RUNNING == mState ||
441 PAUSED_WHILE_HIDDEN == mState )
443 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
448 mThreadController->Stop();
450 // Clear out all the handles to Windows
451 mWindowFrame.clear();
453 // Delete the TTS player
454 for(int i =0; i < Dali::TtsPlayer::MODE_NUM; i++)
458 mTtsPlayers[i].Reset();
462 // Destroy the image loader plugin
463 Internal::Adaptor::ImageLoaderPluginProxy::Destroy();
465 delete mEventHandler;
466 mEventHandler = NULL;
468 delete mNotificationTrigger;
469 mNotificationTrigger = NULL;
471 mCallbackManager->Stop();
475 DALI_LOG_RELEASE_INFO( "Adaptor::Stop\n" );
479 void Adaptor::ContextLost()
481 mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage
484 void Adaptor::ContextRegained()
486 // Inform core, so that texture resources can be reloaded
487 mCore->RecoverFromContextLoss();
489 mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage
492 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
494 mEventHandler->FeedTouchPoint( point, timeStamp );
497 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
499 mEventHandler->FeedWheelEvent( wheelEvent );
502 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
504 mEventHandler->FeedKeyEvent( keyEvent );
507 void Adaptor::ReplaceSurface( Any nativeWindow, Dali::RenderSurfaceInterface& newSurface )
509 // Let the core know the surface size has changed
510 mCore->SurfaceResized( &newSurface );
512 mResizedSignal.Emit( mAdaptor );
514 WindowPane newDefaultWindow;
515 newDefaultWindow.nativeWindow = nativeWindow;
516 newDefaultWindow.surface = &newSurface;
517 newDefaultWindow.surface->SetAdaptor(*this);
519 WindowPane oldDefaultWindow = mWindowFrame.front();
521 // Update WindowFrame
522 std::vector<WindowPane>::iterator iter = mWindowFrame.begin();
523 iter = mWindowFrame.insert( iter, newDefaultWindow );
525 // Flush the event queue to give the update-render thread chance
526 // to start processing messages for new camera setup etc as soon as possible
529 // This method blocks until the render thread has completed the replace.
530 mThreadController->ReplaceSurface( newDefaultWindow.surface );
532 // Must delete the old Window only after the render thread has completed the replace
533 oldDefaultWindow.surface->DestroySurface();
534 oldDefaultWindow.surface = nullptr;
537 Dali::RenderSurfaceInterface& Adaptor::GetSurface() const
539 WindowPane defaultWindow = mWindowFrame.front();
540 return *(defaultWindow.surface);
543 void Adaptor::ReleaseSurfaceLock()
545 WindowPane defaultWindow = mWindowFrame.front();
546 defaultWindow.surface->ReleaseLock();
549 Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
551 if(!mTtsPlayers[mode])
553 // Create the TTS player when it needed, because it can reduce launching time.
554 mTtsPlayers[mode] = TtsPlayer::New(mode);
557 return mTtsPlayers[mode];
560 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd )
562 bool idleAdded(false);
564 // Only add an idle if the Adaptor is actually running
565 if( RUNNING == mState || READY == mState || forceAdd )
567 idleAdded = mCallbackManager->AddIdleCallback( callback, hasReturnValue );
573 void Adaptor::RemoveIdle( CallbackBase* callback )
575 mCallbackManager->RemoveIdleCallback( callback );
578 void Adaptor::SetPreRenderCallback( CallbackBase* callback )
580 mThreadController->SetPreRenderCallback( callback );
583 bool Adaptor::AddWindow( Dali::Window* childWindow, const std::string& childWindowName, const std::string& childWindowClassName, const bool& childWindowMode )
585 Window& windowImpl = Dali::GetImplementation( *childWindow );
586 windowImpl.SetAdaptor( Get() );
588 // This is any Window that is not the main (default) one
589 WindowPane additionalWindow;
590 additionalWindow.instance = childWindow;
591 additionalWindow.window_name = childWindowName;
592 additionalWindow.class_name = childWindowClassName;
593 additionalWindow.window_mode = childWindowMode;
594 additionalWindow.surface = windowImpl.GetSurface();
595 additionalWindow.id = windowImpl.GetId();
597 // Add the new Window to the Frame - the order is not important
598 mWindowFrame.push_back( additionalWindow );
603 bool Adaptor::RemoveWindow( Dali::Window* childWindow )
605 for ( WindowFrames::iterator iter = mWindowFrame.begin(); iter != mWindowFrame.end(); ++iter )
607 if( iter->instance == childWindow )
609 mWindowFrame.erase( iter );
617 bool Adaptor::RemoveWindow( std::string childWindowName )
619 for ( WindowFrames::iterator iter = mWindowFrame.begin(); iter != mWindowFrame.end(); ++iter )
621 if( iter->window_name == childWindowName )
623 mWindowFrame.erase( iter );
631 bool Adaptor::RemoveWindow( Window* childWindow )
633 for ( WindowFrames::iterator iter = mWindowFrame.begin(); iter != mWindowFrame.end(); ++iter )
635 if( iter->id == childWindow->GetId() )
637 mWindowFrame.erase( iter );
645 Dali::Adaptor& Adaptor::Get()
647 DALI_ASSERT_ALWAYS( IsAvailable() && "Adaptor not instantiated" );
648 return gThreadLocalAdaptor->mAdaptor;
651 bool Adaptor::IsAvailable()
653 return gThreadLocalAdaptor != NULL;
656 void Adaptor::SceneCreated()
658 mCore->SceneCreated();
661 Dali::Integration::Core& Adaptor::GetCore()
666 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
668 mThreadController->SetRenderRefreshRate( numberOfVSyncsPerRender );
671 void Adaptor::SetUseHardwareVSync( bool useHardware )
673 mVSyncMonitor->SetUseHardwareVSync( useHardware );
676 Dali::DisplayConnection& Adaptor::GetDisplayConnectionInterface()
678 DALI_ASSERT_DEBUG( mDisplayConnection && "Display connection not created" );
679 return *mDisplayConnection;
682 GraphicsInterface& Adaptor::GetGraphicsInterface()
684 DALI_ASSERT_DEBUG( mGraphics && "Graphics interface not created" );
688 Dali::Integration::PlatformAbstraction& Adaptor::GetPlatformAbstractionInterface()
690 return *mPlatformAbstraction;
693 TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
695 return *mNotificationTrigger;
698 TriggerEventFactoryInterface& Adaptor::GetTriggerEventFactoryInterface()
700 return mTriggerEventFactory;
703 SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
705 return mSocketFactory;
708 Dali::RenderSurfaceInterface* Adaptor::GetRenderSurfaceInterface()
710 if( !mWindowFrame.empty())
712 WindowPane defaultWindow = mWindowFrame.front();
713 return defaultWindow.surface;
721 VSyncMonitorInterface* Adaptor::GetVSyncMonitorInterface()
723 return mVSyncMonitor;
726 TraceInterface& Adaptor::GetKernelTraceInterface()
728 return mKernelTracer;
731 TraceInterface& Adaptor::GetSystemTraceInterface()
733 return mSystemTracer;
736 PerformanceInterface* Adaptor::GetPerformanceInterface()
738 return mPerformanceInterface;
741 Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
743 DALI_ASSERT_DEBUG( mPlatformAbstraction && "PlatformAbstraction not created" );
744 return *mPlatformAbstraction;
747 void Adaptor::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
749 mDragAndDropDetector = detector;
753 mEventHandler->SetDragAndDropDetector( detector );
757 void Adaptor::SetRotationObserver( RotationObserver* observer )
761 mEventHandler->SetRotationObserver( observer );
763 else if( mState == READY )
765 // Set once event handler exists
766 mDeferredRotationObserver = observer;
770 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
772 if(mTtsPlayers[mode])
774 mTtsPlayers[mode].Reset();
778 void Adaptor::SetMinimumPinchDistance(float distance)
780 if( mGestureManager )
782 mGestureManager->SetMinimumPinchDistance(distance);
786 Any Adaptor::GetNativeWindowHandle()
788 WindowPane defaultWindow = mWindowFrame.front();
789 return defaultWindow.nativeWindow;
792 Any Adaptor::GetGraphicsDisplay()
798 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
800 EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
801 display = eglImpl.GetDisplay();
807 void Adaptor::SetUseRemoteSurface(bool useRemoteSurface)
809 mUseRemoteSurface = useRemoteSurface;
812 void Adaptor::AddObserver( LifeCycleObserver& observer )
814 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
816 if ( match == mObservers.end() )
818 mObservers.push_back( &observer );
822 void Adaptor::RemoveObserver( LifeCycleObserver& observer )
824 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
826 if ( match != mObservers.end() )
828 mObservers.erase( match );
832 void Adaptor::QueueCoreEvent(const Dali::Integration::Event& event)
836 mCore->QueueEvent(event);
840 void Adaptor::ProcessCoreEvents()
844 if( mPerformanceInterface )
846 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_START );
849 mCore->ProcessEvents();
851 if( mPerformanceInterface )
853 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_END );
858 void Adaptor::RequestUpdate( bool forceUpdate )
864 mThreadController->RequestUpdate();
868 case PAUSED_WHILE_HIDDEN:
870 // When Dali applications are partially visible behind the lock-screen,
871 // the indicator must be updated (therefore allow updates in the PAUSED state)
874 mThreadController->RequestUpdateOnce();
886 void Adaptor::RequestProcessEventsOnIdle( bool forceProcess )
888 // Only request a notification if the Adaptor is actually running
889 // and we haven't installed the idle notification
890 if( ( ! mNotificationOnIdleInstalled ) && ( RUNNING == mState || READY == mState || forceProcess ) )
892 mNotificationOnIdleInstalled = AddIdleEnterer( MakeCallback( this, &Adaptor::ProcessCoreEventsFromIdle ), forceProcess );
896 void Adaptor::OnWindowShown()
898 if ( PAUSED_WHILE_HIDDEN == mState )
900 // Adaptor can now be resumed
905 // Force a render task
910 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowShown: Not shown [%d]\n", mState );
914 void Adaptor::OnWindowHidden()
916 if ( RUNNING == mState )
920 // Adaptor cannot be resumed until the window is shown
921 mState = PAUSED_WHILE_HIDDEN;
925 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowHidden: Not hidden [%d]\n", mState );
929 // Dali::Internal::Adaptor::Adaptor::OnDamaged
930 void Adaptor::OnDamaged( const DamageArea& area )
932 // This is needed for the case where Dali window is partially obscured
933 RequestUpdate( false );
936 void Adaptor::SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize )
938 // Let the core know the surface size has changed
939 mCore->SurfaceResized( surface );
941 mResizedSignal.Emit( mAdaptor );
944 void Adaptor::SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize )
946 // Flush the event queue to give the update-render thread chance
947 // to start processing messages for new camera setup etc as soon as possible
950 mThreadController->ResizeSurface();
953 void Adaptor::NotifySceneCreated()
955 GetCore().SceneCreated();
957 // Flush the event queue to give the update-render thread chance
958 // to start processing messages for new camera setup etc as soon as possible
961 // Start thread controller after the scene has been created
962 mThreadController->Start();
964 // Process after surface is created (registering to remote surface provider if required)
965 SurfaceInitialized();
969 DALI_LOG_RELEASE_INFO( "Adaptor::NotifySceneCreated\n" );
972 void Adaptor::NotifyLanguageChanged()
974 mLanguageChangedSignal.Emit( mAdaptor );
977 void Adaptor::RenderOnce()
982 const LogFactoryInterface& Adaptor::GetLogFactory()
984 return *mEnvironmentOptions;
987 void Adaptor::RegisterProcessor( Integration::Processor& processor )
989 GetCore().RegisterProcessor(processor);
992 void Adaptor::UnregisterProcessor( Integration::Processor& processor )
994 GetCore().UnregisterProcessor(processor);
997 void Adaptor::RequestUpdateOnce()
999 if( mThreadController )
1001 mThreadController->RequestUpdateOnce();
1005 bool Adaptor::ProcessCoreEventsFromIdle()
1007 ProcessCoreEvents();
1009 // the idle handle automatically un-installs itself
1010 mNotificationOnIdleInstalled = false;
1015 Adaptor::Adaptor(Any nativeWindow, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions)
1017 mLanguageChangedSignal(),
1018 mAdaptor( adaptor ),
1021 mThreadController( nullptr ),
1022 mVSyncMonitor( nullptr ),
1023 mGraphics( nullptr ),
1024 mDisplayConnection( nullptr ),
1026 mPlatformAbstraction( nullptr ),
1027 mEventHandler( nullptr ),
1028 mCallbackManager( nullptr ),
1029 mNotificationOnIdleInstalled( false ),
1030 mNotificationTrigger( nullptr ),
1031 mGestureManager( nullptr ),
1032 mDaliFeedbackPlugin(),
1033 mFeedbackController( nullptr ),
1036 mDragAndDropDetector(),
1037 mDeferredRotationObserver( nullptr ),
1038 mEnvironmentOptions( environmentOptions ? environmentOptions : new EnvironmentOptions /* Create the options if not provided */),
1039 mPerformanceInterface( nullptr ),
1042 mTriggerEventFactory(),
1043 mObjectProfiler( nullptr ),
1045 mEnvironmentOptionsOwned( environmentOptions ? false : true /* If not provided then we own the object */ ),
1046 mUseRemoteSurface( false )
1048 DALI_ASSERT_ALWAYS( !IsAvailable() && "Cannot create more than one Adaptor per thread" );
1050 WindowPane defaultWindow;
1051 defaultWindow.nativeWindow = nativeWindow;
1052 defaultWindow.surface = surface;
1053 defaultWindow.id = 0;
1055 std::vector<WindowPane>::iterator iter = mWindowFrame.begin();
1056 iter = mWindowFrame.insert( iter, defaultWindow );
1058 gThreadLocalAdaptor = this;
1061 void Adaptor::SetRootLayoutDirection( std::string locale )
1063 Dali::Stage stage = Dali::Stage::GetCurrent();
1065 stage.GetRootLayer().SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,
1066 static_cast< LayoutDirection::Type >( Internal::Adaptor::Locale::GetDirection( std::string( locale ) ) ) );
1069 bool Adaptor::AddIdleEnterer( CallbackBase* callback, bool forceAdd )
1071 bool idleAdded( false );
1073 // Only add an idle if the Adaptor is actually running
1074 if( RUNNING == mState || READY == mState || forceAdd )
1076 idleAdded = mCallbackManager->AddIdleEntererCallback( callback );
1082 void Adaptor::RemoveIdleEnterer( CallbackBase* callback )
1084 mCallbackManager->RemoveIdleEntererCallback( callback );
1087 } // namespace Adaptor
1089 } // namespace Internal