2 * Copyright (c) 2018 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>
35 #include <dali/public-api/dali-adaptor-common.h>
36 #include <dali/internal/system/common/thread-controller.h>
37 #include <dali/internal/system/common/performance-interface-factory.h>
38 #include <dali/internal/adaptor/common/lifecycle-observer.h>
40 #include <dali/internal/graphics/gles/egl-graphics-factory.h>
41 #include <dali/internal/graphics/gles/egl-graphics.h> // Temporary until Core is abstracted
43 #include <dali/devel-api/text-abstraction/font-client.h>
45 #include <dali/internal/system/common/callback-manager.h>
46 #include <dali/internal/accessibility/common/tts-player-impl.h>
47 #include <dali/internal/accessibility/common/accessibility-adaptor-impl.h>
48 #include <dali/internal/input/common/gesture-manager.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
85 Dali::Adaptor* Adaptor::New( Any nativeWindow, RenderSurface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
87 Dali::Adaptor* adaptor = new Dali::Adaptor;
88 Adaptor* impl = new Adaptor( nativeWindow, *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::Window window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
102 Any winId = window.GetNativeHandle();
104 Window& windowImpl = Dali::GetImplementation( window );
105 Dali::Adaptor* adaptor = New( winId, windowImpl.GetSurface(), configuration, environmentOptions );
106 windowImpl.SetAdaptor( *adaptor );
110 Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Any nativeWindow, RenderSurface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
112 Dali::Adaptor* adaptor = new Dali::Adaptor; // Public adaptor
113 Adaptor* impl = new Adaptor( nativeWindow, *adaptor, surface, environmentOptions ); // Impl adaptor
114 adaptor->mImpl = impl;
116 impl->Initialize( graphicsFactory, configuration );
121 Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Dali::Window window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
123 Any winId = window.GetNativeHandle();
125 Window& windowImpl = Dali::GetImplementation( window );
126 Dali::Adaptor* adaptor = New( graphicsFactory, winId, windowImpl.GetSurface(), configuration, environmentOptions );
127 windowImpl.SetAdaptor( *adaptor );
131 void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration::ContextLoss configuration )
133 // all threads here (event, update, and render) will send their logs to TIZEN Platform's LogMessage handler.
134 Dali::Integration::Log::LogFunction logFunction( Dali::TizenPlatform::LogMessage );
135 mEnvironmentOptions->SetLogFunction( logFunction );
136 mEnvironmentOptions->InstallLogFunction(); // install logging for main thread
138 mPlatformAbstraction = new TizenPlatform::TizenPlatformAbstraction;
141 GetDataStoragePath( path );
142 mPlatformAbstraction->SetDataStoragePath( path );
144 ResourcePolicy::DataRetention dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA;
145 if( configuration == Dali::Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS )
147 dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA;
150 // Note, Tizen does not use DALI_RETAINS_ALL_DATA, as it can reload images from files automatically.
152 if( mEnvironmentOptions->PerformanceServerRequired() )
154 mPerformanceInterface = PerformanceInterfaceFactory::CreateInterface( *this, *mEnvironmentOptions );
157 mEnvironmentOptions->CreateTraceManager( mPerformanceInterface );
158 mEnvironmentOptions->InstallTraceFunction(); // install tracing for main thread
160 mCallbackManager = CallbackManager::New();
162 WindowPane defaultWindow = mWindowFrame.front();
163 PositionSize size = defaultWindow.surface->GetPositionSize();
165 mGestureManager = new GestureManager(*this, Vector2(size.width, size.height), mCallbackManager, *mEnvironmentOptions);
167 mGraphics = &( graphicsFactory.Create() );
168 mGraphics->Initialize( mEnvironmentOptions );
170 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
172 GlImplementation& mGLES = eglGraphics->GetGlesInterface();
173 EglSyncImplementation& eglSyncImpl = eglGraphics->GetSyncImplementation();
175 mCore = Integration::Core::New( *this,
176 *mPlatformAbstraction,
180 dataRetentionPolicy ,
181 ( 0u != mEnvironmentOptions->GetRenderToFboInterval() ) ? Integration::RenderToFrameBuffer::TRUE : Integration::RenderToFrameBuffer::FALSE,
182 mGraphics->GetDepthBufferRequired(),
183 mGraphics->GetStencilBufferRequired() );
185 const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval();
186 if( 0u < timeInterval )
188 mObjectProfiler = new ObjectProfiler( timeInterval );
191 mNotificationTrigger = mTriggerEventFactory.CreateTriggerEvent( MakeCallback( this, &Adaptor::ProcessCoreEvents ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
193 mVSyncMonitor = new VSyncMonitor;
195 if( defaultWindow.surface )
197 mDisplayConnection = Dali::DisplayConnection::New( *mGraphics, defaultWindow.surface->GetSurfaceType() );
201 mDisplayConnection = Dali::DisplayConnection::New( *mGraphics );
204 mThreadController = new ThreadController( *this, *mEnvironmentOptions );
206 // Should be called after Core creation
207 if( mEnvironmentOptions->GetPanGestureLoggingLevel() )
209 Integration::EnableProfiling( Dali::Integration::PROFILING_TYPE_PAN_GESTURE );
211 if( mEnvironmentOptions->GetPanGesturePredictionMode() >= 0 )
213 Integration::SetPanGesturePredictionMode(mEnvironmentOptions->GetPanGesturePredictionMode());
215 if( mEnvironmentOptions->GetPanGesturePredictionAmount() >= 0 )
217 Integration::SetPanGesturePredictionAmount(mEnvironmentOptions->GetPanGesturePredictionAmount());
219 if( mEnvironmentOptions->GetPanGestureMaximumPredictionAmount() >= 0 )
221 Integration::SetPanGestureMaximumPredictionAmount(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount());
223 if( mEnvironmentOptions->GetPanGestureMinimumPredictionAmount() >= 0 )
225 Integration::SetPanGestureMinimumPredictionAmount(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount());
227 if( mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment() >= 0 )
229 Integration::SetPanGesturePredictionAmountAdjustment(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment());
231 if( mEnvironmentOptions->GetPanGestureSmoothingMode() >= 0 )
233 Integration::SetPanGestureSmoothingMode(mEnvironmentOptions->GetPanGestureSmoothingMode());
235 if( mEnvironmentOptions->GetPanGestureSmoothingAmount() >= 0.0f )
237 Integration::SetPanGestureSmoothingAmount(mEnvironmentOptions->GetPanGestureSmoothingAmount());
239 if( mEnvironmentOptions->GetPanGestureUseActualTimes() >= 0 )
241 Integration::SetPanGestureUseActualTimes( mEnvironmentOptions->GetPanGestureUseActualTimes() == 0 ? true : false );
243 if( mEnvironmentOptions->GetPanGestureInterpolationTimeRange() >= 0 )
245 Integration::SetPanGestureInterpolationTimeRange( mEnvironmentOptions->GetPanGestureInterpolationTimeRange() );
247 if( mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() >= 0 )
249 Integration::SetPanGestureScalarOnlyPredictionEnabled( mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() == 0 ? true : false );
251 if( mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() >= 0 )
253 Integration::SetPanGestureTwoPointPredictionEnabled( mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() == 0 ? true : false );
255 if( mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() >= 0 )
257 Integration::SetPanGestureTwoPointInterpolatePastTime( mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() );
259 if( mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() >= 0.0f )
261 Integration::SetPanGestureTwoPointVelocityBias( mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() );
263 if( mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() >= 0.0f )
265 Integration::SetPanGestureTwoPointAccelerationBias( mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() );
267 if( mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() >= 0 )
269 Integration::SetPanGestureMultitapSmoothingRange( mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() );
272 // Set max texture size
273 if( mEnvironmentOptions->GetMaxTextureSize() > 0 )
275 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize( mEnvironmentOptions->GetMaxTextureSize() );
278 SetupSystemInformation();
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 )
327 // Start the callback manager
328 mCallbackManager->Start();
330 WindowPane defaultWindow = mWindowFrame.front();
332 // Create event handler
333 mEventHandler = new EventHandler( defaultWindow.surface, *this, *mGestureManager, *this, mDragAndDropDetector );
335 if( mDeferredRotationObserver != NULL )
337 mEventHandler->SetRotationObserver(mDeferredRotationObserver);
338 mDeferredRotationObserver = NULL;
341 unsigned int dpiHor, dpiVer;
344 defaultWindow.surface->GetDpi( dpiHor, dpiVer );
346 // tell core about the DPI value
347 mCore->SetDpi(dpiHor, dpiVer);
349 // set the DPI value for font rendering
350 FontClient fontClient = FontClient::Get();
351 fontClient.SetDpi( dpiHor, dpiVer );
353 // Tell the core the size of the surface just before we start the render-thread
354 PositionSize size = defaultWindow.surface->GetPositionSize();
356 mCore->SurfaceResized( size.width, size.height );
358 // Initialize the thread controller
359 mThreadController->Initialize();
361 ProcessCoreEvents(); // Ensure any startup messages are processed.
363 // Initialize the image loader plugin
364 Internal::Adaptor::ImageLoaderPluginProxy::Initialize();
366 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
372 // Dali::Internal::Adaptor::Adaptor::Pause
373 void Adaptor::Pause()
375 // Only pause the adaptor if we're actually running.
376 if( RUNNING == mState )
378 // Inform observers that we are about to be paused.
379 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
384 // Reset the event handler when adaptor paused
387 mEventHandler->Pause();
390 mThreadController->Pause();
393 // Ensure any messages queued during pause callbacks are processed by doing another update.
398 // Dali::Internal::Adaptor::Adaptor::Resume
399 void Adaptor::Resume()
401 // Only resume the adaptor if we are in the suspended state.
402 if( PAUSED == mState )
406 // Reset the event handler when adaptor resumed
409 mEventHandler->Resume();
412 // Inform observers that we have resumed.
413 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
418 // Trigger processing of events queued up while paused
419 mCore->ProcessEvents();
421 // Do at end to ensure our first update/render after resumption includes the processed messages as well
422 mThreadController->Resume();
428 if( RUNNING == mState ||
430 PAUSED_WHILE_HIDDEN == mState )
432 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
437 mThreadController->Stop();
439 // Clear out all the handles to Windows
440 mWindowFrame.clear();
442 // Delete the TTS player
443 for(int i =0; i < Dali::TtsPlayer::MODE_NUM; i++)
447 mTtsPlayers[i].Reset();
451 // Destroy the image loader plugin
452 Internal::Adaptor::ImageLoaderPluginProxy::Destroy();
454 delete mEventHandler;
455 mEventHandler = NULL;
457 delete mNotificationTrigger;
458 mNotificationTrigger = NULL;
460 mCallbackManager->Stop();
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 mEventHandler->FeedTouchPoint( point, timeStamp );
484 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
486 mEventHandler->FeedWheelEvent( wheelEvent );
489 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
491 mEventHandler->FeedKeyEvent( keyEvent );
494 void Adaptor::ReplaceSurface( Any nativeWindow, RenderSurface& newSurface )
496 PositionSize positionSize = newSurface.GetPositionSize();
498 // Let the core know the surface size has changed
499 mCore->SurfaceResized( positionSize.width, positionSize.height );
501 mResizedSignal.Emit( mAdaptor );
503 WindowPane newDefaultWindow;
504 newDefaultWindow.nativeWindow = nativeWindow;
505 newDefaultWindow.surface = &newSurface;
507 // Must delete the old Window first before replacing it with the new one
508 WindowPane oldDefaultWindow = mWindowFrame.front();
509 oldDefaultWindow.surface->DestroySurface();
511 // Update WindowFrame
512 std::vector<WindowPane>::iterator iter = mWindowFrame.begin();
513 iter = mWindowFrame.insert( iter, newDefaultWindow );
515 // Flush the event queue to give the update-render thread chance
516 // to start processing messages for new camera setup etc as soon as possible
519 // This method blocks until the render thread has completed the replace.
520 mThreadController->ReplaceSurface( newDefaultWindow.surface );
523 RenderSurface& Adaptor::GetSurface() const
525 WindowPane defaultWindow = mWindowFrame.front();
526 return *(defaultWindow.surface);
529 void Adaptor::ReleaseSurfaceLock()
531 WindowPane defaultWindow = mWindowFrame.front();
532 defaultWindow.surface->ReleaseLock();
535 Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
537 if(!mTtsPlayers[mode])
539 // Create the TTS player when it needed, because it can reduce launching time.
540 mTtsPlayers[mode] = TtsPlayer::New(mode);
543 return mTtsPlayers[mode];
546 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd )
548 bool idleAdded(false);
550 // Only add an idle if the Adaptor is actually running
551 if( RUNNING == mState || READY == mState || forceAdd )
553 idleAdded = mCallbackManager->AddIdleCallback( callback, hasReturnValue );
559 void Adaptor::RemoveIdle( CallbackBase* callback )
561 mCallbackManager->RemoveIdleCallback( callback );
564 void Adaptor::SetPreRenderCallback( CallbackBase* callback )
566 mThreadController->SetPreRenderCallback( callback );
569 bool Adaptor::AddWindow( Dali::Window* childWindow, const std::string& childWindowName, const std::string& childWindowClassName, const bool& childWindowMode )
571 // This is any Window that is not the main (default) one
572 WindowPane additionalWindow;
573 additionalWindow.instance = childWindow;
574 additionalWindow.window_name = childWindowName;
575 additionalWindow.class_name = childWindowClassName;
576 additionalWindow.window_mode = childWindowMode;
578 // Add the new Window to the Frame - the order is not important
579 mWindowFrame.push_back( additionalWindow );
581 Window& windowImpl = Dali::GetImplementation( *childWindow );
582 windowImpl.SetAdaptor( Get() );
587 bool Adaptor::RemoveWindow( Dali::Window* childWindow )
589 for ( WindowFrames::iterator iter = mWindowFrame.begin(); iter != mWindowFrame.end(); ++iter )
591 if( iter->instance == childWindow )
593 mWindowFrame.erase( iter );
601 bool Adaptor::RemoveWindow( std::string childWindowName )
603 for ( WindowFrames::iterator iter = mWindowFrame.begin(); iter != mWindowFrame.end(); ++iter )
605 if( iter->window_name == childWindowName )
607 mWindowFrame.erase( iter );
615 Dali::Adaptor& Adaptor::Get()
617 DALI_ASSERT_ALWAYS( IsAvailable() && "Adaptor not instantiated" );
618 return gThreadLocalAdaptor->mAdaptor;
621 bool Adaptor::IsAvailable()
623 return gThreadLocalAdaptor != NULL;
626 void Adaptor::SceneCreated()
628 mCore->SceneCreated();
631 Dali::Integration::Core& Adaptor::GetCore()
636 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
638 mThreadController->SetRenderRefreshRate( numberOfVSyncsPerRender );
641 void Adaptor::SetUseHardwareVSync( bool useHardware )
643 mVSyncMonitor->SetUseHardwareVSync( useHardware );
646 Dali::DisplayConnection& Adaptor::GetDisplayConnectionInterface()
648 DALI_ASSERT_DEBUG( mDisplayConnection && "Display connection not created" );
649 return *mDisplayConnection;
652 GraphicsInterface& Adaptor::GetGraphicsInterface()
654 DALI_ASSERT_DEBUG( mGraphics && "Graphics interface not created" );
658 Dali::Integration::PlatformAbstraction& Adaptor::GetPlatformAbstractionInterface()
660 return *mPlatformAbstraction;
663 TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
665 return *mNotificationTrigger;
668 TriggerEventFactoryInterface& Adaptor::GetTriggerEventFactoryInterface()
670 return mTriggerEventFactory;
673 SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
675 return mSocketFactory;
678 RenderSurface* Adaptor::GetRenderSurfaceInterface()
680 if( !mWindowFrame.empty())
682 WindowPane defaultWindow = mWindowFrame.front();
683 return defaultWindow.surface;
691 VSyncMonitorInterface* Adaptor::GetVSyncMonitorInterface()
693 return mVSyncMonitor;
696 TraceInterface& Adaptor::GetKernelTraceInterface()
698 return mKernelTracer;
701 TraceInterface& Adaptor::GetSystemTraceInterface()
703 return mSystemTracer;
706 PerformanceInterface* Adaptor::GetPerformanceInterface()
708 return mPerformanceInterface;
711 Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
713 DALI_ASSERT_DEBUG( mPlatformAbstraction && "PlatformAbstraction not created" );
714 return *mPlatformAbstraction;
717 void Adaptor::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
719 mDragAndDropDetector = detector;
723 mEventHandler->SetDragAndDropDetector( detector );
727 void Adaptor::SetRotationObserver( RotationObserver* observer )
731 mEventHandler->SetRotationObserver( observer );
733 else if( mState == READY )
735 // Set once event handler exists
736 mDeferredRotationObserver = observer;
740 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
742 if(mTtsPlayers[mode])
744 mTtsPlayers[mode].Reset();
748 void Adaptor::SetMinimumPinchDistance(float distance)
750 if( mGestureManager )
752 mGestureManager->SetMinimumPinchDistance(distance);
756 Any Adaptor::GetNativeWindowHandle()
758 WindowPane defaultWindow = mWindowFrame.front();
759 return defaultWindow.nativeWindow;
762 Any Adaptor::GetGraphicsDisplay()
768 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
770 EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
771 display = eglImpl.GetDisplay();
777 void Adaptor::SetUseRemoteSurface(bool useRemoteSurface)
779 mUseRemoteSurface = useRemoteSurface;
782 void Adaptor::AddObserver( LifeCycleObserver& observer )
784 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
786 if ( match == mObservers.end() )
788 mObservers.push_back( &observer );
792 void Adaptor::RemoveObserver( LifeCycleObserver& observer )
794 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
796 if ( match != mObservers.end() )
798 mObservers.erase( match );
802 void Adaptor::QueueCoreEvent(const Dali::Integration::Event& event)
806 mCore->QueueEvent(event);
810 void Adaptor::ProcessCoreEvents()
814 if( mPerformanceInterface )
816 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_START );
819 mCore->ProcessEvents();
821 if( mPerformanceInterface )
823 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_END );
828 void Adaptor::RequestUpdate( bool forceUpdate )
834 mThreadController->RequestUpdate();
838 case PAUSED_WHILE_HIDDEN:
840 // When Dali applications are partially visible behind the lock-screen,
841 // the indicator must be updated (therefore allow updates in the PAUSED state)
844 mThreadController->RequestUpdateOnce();
856 void Adaptor::RequestProcessEventsOnIdle( bool forceProcess )
858 // Only request a notification if the Adaptor is actually running
859 // and we haven't installed the idle notification
860 if( ( ! mNotificationOnIdleInstalled ) && ( RUNNING == mState || READY == mState || forceProcess ) )
862 mNotificationOnIdleInstalled = AddIdleEnterer( MakeCallback( this, &Adaptor::ProcessCoreEventsFromIdle ), forceProcess );
866 void Adaptor::OnWindowShown()
868 if ( PAUSED_WHILE_HIDDEN == mState )
870 // Adaptor can now be resumed
875 // Force a render task
880 void Adaptor::OnWindowHidden()
882 if ( RUNNING == mState )
886 // Adaptor cannot be resumed until the window is shown
887 mState = PAUSED_WHILE_HIDDEN;
891 // Dali::Internal::Adaptor::Adaptor::OnDamaged
892 void Adaptor::OnDamaged( const DamageArea& area )
894 // This is needed for the case where Dali window is partially obscured
895 RequestUpdate( false );
898 void Adaptor::SurfaceResizePrepare( SurfaceSize surfaceSize )
900 // Let the core know the surface size has changed
901 mCore->SurfaceResized( surfaceSize.GetWidth(), surfaceSize.GetHeight() );
903 mResizedSignal.Emit( mAdaptor );
906 void Adaptor::SurfaceResizeComplete( SurfaceSize surfaceSize )
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 mThreadController->ResizeSurface();
915 void Adaptor::NotifySceneCreated()
917 GetCore().SceneCreated();
919 // Start thread controller after the scene has been created
920 mThreadController->Start();
922 // Process after surface is created (registering to remote surface provider if required)
923 SurfaceInitialized();
928 void Adaptor::NotifyLanguageChanged()
930 mLanguageChangedSignal.Emit( mAdaptor );
933 void Adaptor::RenderOnce()
938 const LogFactoryInterface& Adaptor::GetLogFactory()
940 return *mEnvironmentOptions;
943 void Adaptor::RequestUpdateOnce()
945 if( mThreadController )
947 mThreadController->RequestUpdateOnce();
951 void Adaptor::IndicatorSizeChanged(int height)
953 // Let the core know the indicator height is changed
954 mCore->SetTopMargin(height);
957 bool Adaptor::ProcessCoreEventsFromIdle()
961 // the idle handle automatically un-installs itself
962 mNotificationOnIdleInstalled = false;
967 Adaptor::Adaptor(Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface, EnvironmentOptions* environmentOptions)
969 mLanguageChangedSignal(),
973 mThreadController( nullptr ),
974 mVSyncMonitor( nullptr ),
975 mDisplayConnection( nullptr ),
976 mPlatformAbstraction( nullptr ),
977 mEventHandler( nullptr ),
978 mCallbackManager( nullptr ),
979 mNotificationOnIdleInstalled( false ),
980 mNotificationTrigger( nullptr ),
981 mGestureManager( nullptr ),
982 mDaliFeedbackPlugin(),
983 mFeedbackController( nullptr ),
986 mDragAndDropDetector(),
987 mDeferredRotationObserver( nullptr ),
988 mEnvironmentOptions( environmentOptions ? environmentOptions : new EnvironmentOptions /* Create the options if not provided */),
989 mPerformanceInterface( nullptr ),
992 mTriggerEventFactory(),
993 mObjectProfiler( nullptr ),
995 mEnvironmentOptionsOwned( environmentOptions ? false : true /* If not provided then we own the object */ ),
996 mUseRemoteSurface( false )
998 DALI_ASSERT_ALWAYS( !IsAvailable() && "Cannot create more than one Adaptor per thread" );
1000 WindowPane defaultWindow;
1001 defaultWindow.nativeWindow = nativeWindow;
1002 defaultWindow.surface = surface;
1004 std::vector<WindowPane>::iterator iter = mWindowFrame.begin();
1005 iter = mWindowFrame.insert( iter, defaultWindow );
1007 gThreadLocalAdaptor = this;
1010 void Adaptor::SetRootLayoutDirection( std::string locale )
1012 Dali::Stage stage = Dali::Stage::GetCurrent();
1014 stage.GetRootLayer().SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,
1015 static_cast< LayoutDirection::Type >( Internal::Adaptor::Locale::GetDirection( std::string( locale ) ) ) );
1018 bool Adaptor::AddIdleEnterer( CallbackBase* callback, bool forceAdd )
1020 bool idleAdded( false );
1022 // Only add an idle if the Adaptor is actually running
1023 if( RUNNING == mState || READY == mState || forceAdd )
1025 idleAdded = mCallbackManager->AddIdleEntererCallback( callback );
1031 void Adaptor::RemoveIdleEnterer( CallbackBase* callback )
1033 mCallbackManager->RemoveIdleEntererCallback( callback );
1036 } // namespace Adaptor
1038 } // namespace Internal