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>
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, RenderSurface *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, RenderSurface *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 mGestureManager = new GestureManager(*this, Vector2(size.width, size.height), mCallbackManager, *mEnvironmentOptions);
171 mGraphics = &( graphicsFactory.Create() );
172 mGraphics->Initialize( mEnvironmentOptions );
174 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
176 GlImplementation& mGLES = eglGraphics->GetGlesInterface();
177 EglSyncImplementation& eglSyncImpl = eglGraphics->GetSyncImplementation();
179 mCore = Integration::Core::New( *this,
180 *mPlatformAbstraction,
184 dataRetentionPolicy ,
185 ( 0u != mEnvironmentOptions->GetRenderToFboInterval() ) ? Integration::RenderToFrameBuffer::TRUE : Integration::RenderToFrameBuffer::FALSE,
186 mGraphics->GetDepthBufferRequired(),
187 mGraphics->GetStencilBufferRequired() );
189 const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval();
190 if( 0u < timeInterval )
192 mObjectProfiler = new ObjectProfiler( timeInterval );
195 mNotificationTrigger = mTriggerEventFactory.CreateTriggerEvent( MakeCallback( this, &Adaptor::ProcessCoreEvents ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
197 mVSyncMonitor = new VSyncMonitor;
199 mDisplayConnection = Dali::DisplayConnection::New( *mGraphics, defaultWindow.surface->GetSurfaceType() );
201 mThreadController = new ThreadController( *this, *mEnvironmentOptions );
203 // Should be called after Core creation
204 if( mEnvironmentOptions->GetPanGestureLoggingLevel() )
206 Integration::EnableProfiling( Dali::Integration::PROFILING_TYPE_PAN_GESTURE );
208 if( mEnvironmentOptions->GetPanGesturePredictionMode() >= 0 )
210 Integration::SetPanGesturePredictionMode(mEnvironmentOptions->GetPanGesturePredictionMode());
212 if( mEnvironmentOptions->GetPanGesturePredictionAmount() >= 0 )
214 Integration::SetPanGesturePredictionAmount(mEnvironmentOptions->GetPanGesturePredictionAmount());
216 if( mEnvironmentOptions->GetPanGestureMaximumPredictionAmount() >= 0 )
218 Integration::SetPanGestureMaximumPredictionAmount(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount());
220 if( mEnvironmentOptions->GetPanGestureMinimumPredictionAmount() >= 0 )
222 Integration::SetPanGestureMinimumPredictionAmount(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount());
224 if( mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment() >= 0 )
226 Integration::SetPanGesturePredictionAmountAdjustment(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment());
228 if( mEnvironmentOptions->GetPanGestureSmoothingMode() >= 0 )
230 Integration::SetPanGestureSmoothingMode(mEnvironmentOptions->GetPanGestureSmoothingMode());
232 if( mEnvironmentOptions->GetPanGestureSmoothingAmount() >= 0.0f )
234 Integration::SetPanGestureSmoothingAmount(mEnvironmentOptions->GetPanGestureSmoothingAmount());
236 if( mEnvironmentOptions->GetPanGestureUseActualTimes() >= 0 )
238 Integration::SetPanGestureUseActualTimes( mEnvironmentOptions->GetPanGestureUseActualTimes() == 0 ? true : false );
240 if( mEnvironmentOptions->GetPanGestureInterpolationTimeRange() >= 0 )
242 Integration::SetPanGestureInterpolationTimeRange( mEnvironmentOptions->GetPanGestureInterpolationTimeRange() );
244 if( mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() >= 0 )
246 Integration::SetPanGestureScalarOnlyPredictionEnabled( mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() == 0 ? true : false );
248 if( mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() >= 0 )
250 Integration::SetPanGestureTwoPointPredictionEnabled( mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() == 0 ? true : false );
252 if( mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() >= 0 )
254 Integration::SetPanGestureTwoPointInterpolatePastTime( mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() );
256 if( mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() >= 0.0f )
258 Integration::SetPanGestureTwoPointVelocityBias( mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() );
260 if( mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() >= 0.0f )
262 Integration::SetPanGestureTwoPointAccelerationBias( mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() );
264 if( mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() >= 0 )
266 Integration::SetPanGestureMultitapSmoothingRange( mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() );
269 // Set max texture size
270 if( mEnvironmentOptions->GetMaxTextureSize() > 0 )
272 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize( mEnvironmentOptions->GetMaxTextureSize() );
275 SetupSystemInformation();
280 // Ensure stop status
283 // set to NULL first as we do not want any access to Adaptor as it is being destroyed.
284 gThreadLocalAdaptor = NULL;
286 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
288 (*iter)->OnDestroy();
291 delete mThreadController; // this will shutdown render thread, which will call Core::ContextDestroyed before exit
292 delete mVSyncMonitor;
293 delete mEventHandler;
294 delete mObjectProfiler;
298 delete mGestureManager;
299 delete mDisplayConnection;
300 delete mPlatformAbstraction;
301 delete mCallbackManager;
302 delete mPerformanceInterface;
304 mGraphics->Destroy();
306 // uninstall it on this thread (main actor thread)
307 Dali::Integration::Log::UninstallLogFunction();
309 // Delete environment options if we own it
310 if( mEnvironmentOptionsOwned )
312 delete mEnvironmentOptions;
316 void Adaptor::Start()
318 // It doesn't support restart after stop at this moment to support restarting, need more testing
319 if( READY != mState )
324 // Start the callback manager
325 mCallbackManager->Start();
327 WindowPane defaultWindow = mWindowFrame.front();
329 // Create event handler
330 mEventHandler = new EventHandler( defaultWindow.surface, *this, *mGestureManager, *this, mDragAndDropDetector );
332 if( mDeferredRotationObserver != NULL )
334 mEventHandler->SetRotationObserver(mDeferredRotationObserver);
335 mDeferredRotationObserver = NULL;
338 unsigned int dpiHor, dpiVer;
341 defaultWindow.surface->GetDpi( dpiHor, dpiVer );
343 // tell core about the DPI value
344 mCore->SetDpi(dpiHor, dpiVer);
346 // set the DPI value for font rendering
347 FontClient fontClient = FontClient::Get();
348 fontClient.SetDpi( dpiHor, dpiVer );
350 // Tell the core the size of the surface just before we start the render-thread
351 PositionSize size = defaultWindow.surface->GetPositionSize();
353 mCore->SurfaceResized( size.width, size.height );
355 // Initialize the thread controller
356 mThreadController->Initialize();
358 ProcessCoreEvents(); // Ensure any startup messages are processed.
360 // Initialize the image loader plugin
361 Internal::Adaptor::ImageLoaderPluginProxy::Initialize();
363 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
369 // Dali::Internal::Adaptor::Adaptor::Pause
370 void Adaptor::Pause()
372 // Only pause the adaptor if we're actually running.
373 if( RUNNING == mState )
375 // Inform observers that we are about to be paused.
376 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
381 // Reset the event handler when adaptor paused
384 mEventHandler->Pause();
387 mThreadController->Pause();
390 // Ensure any messages queued during pause callbacks are processed by doing another update.
395 // Dali::Internal::Adaptor::Adaptor::Resume
396 void Adaptor::Resume()
398 // Only resume the adaptor if we are in the suspended state.
399 if( PAUSED == mState )
403 // Reset the event handler when adaptor resumed
406 mEventHandler->Resume();
409 // Inform observers that we have resumed.
410 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
415 // Trigger processing of events queued up while paused
416 mCore->ProcessEvents();
418 // Do at end to ensure our first update/render after resumption includes the processed messages as well
419 mThreadController->Resume();
425 if( RUNNING == mState ||
427 PAUSED_WHILE_HIDDEN == mState )
429 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
434 mThreadController->Stop();
436 // Clear out all the handles to Windows
437 mWindowFrame.clear();
439 // Delete the TTS player
440 for(int i =0; i < Dali::TtsPlayer::MODE_NUM; i++)
444 mTtsPlayers[i].Reset();
448 // Destroy the image loader plugin
449 Internal::Adaptor::ImageLoaderPluginProxy::Destroy();
451 delete mEventHandler;
452 mEventHandler = NULL;
454 delete mNotificationTrigger;
455 mNotificationTrigger = NULL;
457 mCallbackManager->Stop();
463 void Adaptor::ContextLost()
465 mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage
468 void Adaptor::ContextRegained()
470 // Inform core, so that texture resources can be reloaded
471 mCore->RecoverFromContextLoss();
473 mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage
476 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
478 mEventHandler->FeedTouchPoint( point, timeStamp );
481 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
483 mEventHandler->FeedWheelEvent( wheelEvent );
486 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
488 mEventHandler->FeedKeyEvent( keyEvent );
491 void Adaptor::ReplaceSurface( Any nativeWindow, RenderSurface& newSurface )
493 PositionSize positionSize = newSurface.GetPositionSize();
495 // Let the core know the surface size has changed
496 mCore->SurfaceResized( positionSize.width, positionSize.height );
498 mResizedSignal.Emit( mAdaptor );
500 WindowPane newDefaultWindow;
501 newDefaultWindow.nativeWindow = nativeWindow;
502 newDefaultWindow.surface = &newSurface;
504 WindowPane oldDefaultWindow = mWindowFrame.front();
506 // Update WindowFrame
507 std::vector<WindowPane>::iterator iter = mWindowFrame.begin();
508 iter = mWindowFrame.insert( iter, newDefaultWindow );
510 // Flush the event queue to give the update-render thread chance
511 // to start processing messages for new camera setup etc as soon as possible
514 // This method blocks until the render thread has completed the replace.
515 mThreadController->ReplaceSurface( newDefaultWindow.surface );
517 // Must delete the old Window only after the render thread has completed the replace
518 oldDefaultWindow.surface->DestroySurface();
519 oldDefaultWindow.surface = nullptr;
522 RenderSurface& Adaptor::GetSurface() const
524 WindowPane defaultWindow = mWindowFrame.front();
525 return *(defaultWindow.surface);
528 void Adaptor::ReleaseSurfaceLock()
530 WindowPane defaultWindow = mWindowFrame.front();
531 defaultWindow.surface->ReleaseLock();
534 Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
536 if(!mTtsPlayers[mode])
538 // Create the TTS player when it needed, because it can reduce launching time.
539 mTtsPlayers[mode] = TtsPlayer::New(mode);
542 return mTtsPlayers[mode];
545 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd )
547 bool idleAdded(false);
549 // Only add an idle if the Adaptor is actually running
550 if( RUNNING == mState || READY == mState || forceAdd )
552 idleAdded = mCallbackManager->AddIdleCallback( callback, hasReturnValue );
558 void Adaptor::RemoveIdle( CallbackBase* callback )
560 mCallbackManager->RemoveIdleCallback( callback );
563 void Adaptor::SetPreRenderCallback( CallbackBase* callback )
565 mThreadController->SetPreRenderCallback( callback );
568 bool Adaptor::AddWindow( Dali::Window* childWindow, const std::string& childWindowName, const std::string& childWindowClassName, const bool& childWindowMode )
570 // This is any Window that is not the main (default) one
571 WindowPane additionalWindow;
572 additionalWindow.instance = childWindow;
573 additionalWindow.window_name = childWindowName;
574 additionalWindow.class_name = childWindowClassName;
575 additionalWindow.window_mode = childWindowMode;
577 // Add the new Window to the Frame - the order is not important
578 mWindowFrame.push_back( additionalWindow );
580 Window& windowImpl = Dali::GetImplementation( *childWindow );
581 windowImpl.SetAdaptor( Get() );
586 bool Adaptor::RemoveWindow( Dali::Window* childWindow )
588 for ( WindowFrames::iterator iter = mWindowFrame.begin(); iter != mWindowFrame.end(); ++iter )
590 if( iter->instance == childWindow )
592 mWindowFrame.erase( iter );
600 bool Adaptor::RemoveWindow( std::string childWindowName )
602 for ( WindowFrames::iterator iter = mWindowFrame.begin(); iter != mWindowFrame.end(); ++iter )
604 if( iter->window_name == childWindowName )
606 mWindowFrame.erase( iter );
614 Dali::Adaptor& Adaptor::Get()
616 DALI_ASSERT_ALWAYS( IsAvailable() && "Adaptor not instantiated" );
617 return gThreadLocalAdaptor->mAdaptor;
620 bool Adaptor::IsAvailable()
622 return gThreadLocalAdaptor != NULL;
625 void Adaptor::SceneCreated()
627 mCore->SceneCreated();
630 Dali::Integration::Core& Adaptor::GetCore()
635 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
637 mThreadController->SetRenderRefreshRate( numberOfVSyncsPerRender );
640 void Adaptor::SetUseHardwareVSync( bool useHardware )
642 mVSyncMonitor->SetUseHardwareVSync( useHardware );
645 Dali::DisplayConnection& Adaptor::GetDisplayConnectionInterface()
647 DALI_ASSERT_DEBUG( mDisplayConnection && "Display connection not created" );
648 return *mDisplayConnection;
651 GraphicsInterface& Adaptor::GetGraphicsInterface()
653 DALI_ASSERT_DEBUG( mGraphics && "Graphics interface not created" );
657 Dali::Integration::PlatformAbstraction& Adaptor::GetPlatformAbstractionInterface()
659 return *mPlatformAbstraction;
662 TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
664 return *mNotificationTrigger;
667 TriggerEventFactoryInterface& Adaptor::GetTriggerEventFactoryInterface()
669 return mTriggerEventFactory;
672 SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
674 return mSocketFactory;
677 RenderSurface* Adaptor::GetRenderSurfaceInterface()
679 if( !mWindowFrame.empty())
681 WindowPane defaultWindow = mWindowFrame.front();
682 return defaultWindow.surface;
690 VSyncMonitorInterface* Adaptor::GetVSyncMonitorInterface()
692 return mVSyncMonitor;
695 TraceInterface& Adaptor::GetKernelTraceInterface()
697 return mKernelTracer;
700 TraceInterface& Adaptor::GetSystemTraceInterface()
702 return mSystemTracer;
705 PerformanceInterface* Adaptor::GetPerformanceInterface()
707 return mPerformanceInterface;
710 Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
712 DALI_ASSERT_DEBUG( mPlatformAbstraction && "PlatformAbstraction not created" );
713 return *mPlatformAbstraction;
716 void Adaptor::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
718 mDragAndDropDetector = detector;
722 mEventHandler->SetDragAndDropDetector( detector );
726 void Adaptor::SetRotationObserver( RotationObserver* observer )
730 mEventHandler->SetRotationObserver( observer );
732 else if( mState == READY )
734 // Set once event handler exists
735 mDeferredRotationObserver = observer;
739 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
741 if(mTtsPlayers[mode])
743 mTtsPlayers[mode].Reset();
747 void Adaptor::SetMinimumPinchDistance(float distance)
749 if( mGestureManager )
751 mGestureManager->SetMinimumPinchDistance(distance);
755 Any Adaptor::GetNativeWindowHandle()
757 WindowPane defaultWindow = mWindowFrame.front();
758 return defaultWindow.nativeWindow;
761 Any Adaptor::GetGraphicsDisplay()
767 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
769 EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
770 display = eglImpl.GetDisplay();
776 void Adaptor::SetUseRemoteSurface(bool useRemoteSurface)
778 mUseRemoteSurface = useRemoteSurface;
781 void Adaptor::AddObserver( LifeCycleObserver& observer )
783 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
785 if ( match == mObservers.end() )
787 mObservers.push_back( &observer );
791 void Adaptor::RemoveObserver( LifeCycleObserver& observer )
793 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
795 if ( match != mObservers.end() )
797 mObservers.erase( match );
801 void Adaptor::QueueCoreEvent(const Dali::Integration::Event& event)
805 mCore->QueueEvent(event);
809 void Adaptor::ProcessCoreEvents()
813 if( mPerformanceInterface )
815 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_START );
818 mCore->ProcessEvents();
820 if( mPerformanceInterface )
822 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_END );
827 void Adaptor::RequestUpdate( bool forceUpdate )
833 mThreadController->RequestUpdate();
837 case PAUSED_WHILE_HIDDEN:
839 // When Dali applications are partially visible behind the lock-screen,
840 // the indicator must be updated (therefore allow updates in the PAUSED state)
843 mThreadController->RequestUpdateOnce();
855 void Adaptor::RequestProcessEventsOnIdle( bool forceProcess )
857 // Only request a notification if the Adaptor is actually running
858 // and we haven't installed the idle notification
859 if( ( ! mNotificationOnIdleInstalled ) && ( RUNNING == mState || READY == mState || forceProcess ) )
861 mNotificationOnIdleInstalled = AddIdleEnterer( MakeCallback( this, &Adaptor::ProcessCoreEventsFromIdle ), forceProcess );
865 void Adaptor::OnWindowShown()
867 if ( PAUSED_WHILE_HIDDEN == mState )
869 // Adaptor can now be resumed
874 // Force a render task
879 void Adaptor::OnWindowHidden()
881 if ( RUNNING == mState )
885 // Adaptor cannot be resumed until the window is shown
886 mState = PAUSED_WHILE_HIDDEN;
890 // Dali::Internal::Adaptor::Adaptor::OnDamaged
891 void Adaptor::OnDamaged( const DamageArea& area )
893 // This is needed for the case where Dali window is partially obscured
894 RequestUpdate( false );
897 void Adaptor::SurfaceResizePrepare( SurfaceSize surfaceSize )
899 // Let the core know the surface size has changed
900 mCore->SurfaceResized( surfaceSize.GetWidth(), surfaceSize.GetHeight() );
902 mResizedSignal.Emit( mAdaptor );
905 void Adaptor::SurfaceResizeComplete( SurfaceSize surfaceSize )
907 // Flush the event queue to give the update-render thread chance
908 // to start processing messages for new camera setup etc as soon as possible
911 mThreadController->ResizeSurface();
914 void Adaptor::NotifySceneCreated()
916 GetCore().SceneCreated();
918 // Start thread controller after the scene has been created
919 mThreadController->Start();
921 // Process after surface is created (registering to remote surface provider if required)
922 SurfaceInitialized();
927 void Adaptor::NotifyLanguageChanged()
929 mLanguageChangedSignal.Emit( mAdaptor );
932 void Adaptor::RenderOnce()
937 const LogFactoryInterface& Adaptor::GetLogFactory()
939 return *mEnvironmentOptions;
942 void Adaptor::RegisterProcessor( Integration::Processor& processor )
944 GetCore().RegisterProcessor(processor);
947 void Adaptor::UnregisterProcessor( Integration::Processor& processor )
949 GetCore().UnregisterProcessor(processor);
952 void Adaptor::RequestUpdateOnce()
954 if( mThreadController )
956 mThreadController->RequestUpdateOnce();
960 void Adaptor::IndicatorSizeChanged(int height)
962 // Let the core know the indicator height is changed
963 mCore->SetTopMargin(height);
966 bool Adaptor::ProcessCoreEventsFromIdle()
970 // the idle handle automatically un-installs itself
971 mNotificationOnIdleInstalled = false;
976 Adaptor::Adaptor(Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface, EnvironmentOptions* environmentOptions)
978 mLanguageChangedSignal(),
982 mThreadController( nullptr ),
983 mVSyncMonitor( nullptr ),
984 mGraphics( nullptr ),
985 mDisplayConnection( nullptr ),
987 mPlatformAbstraction( nullptr ),
988 mEventHandler( nullptr ),
989 mCallbackManager( nullptr ),
990 mNotificationOnIdleInstalled( false ),
991 mNotificationTrigger( nullptr ),
992 mGestureManager( nullptr ),
993 mDaliFeedbackPlugin(),
994 mFeedbackController( nullptr ),
997 mDragAndDropDetector(),
998 mDeferredRotationObserver( nullptr ),
999 mEnvironmentOptions( environmentOptions ? environmentOptions : new EnvironmentOptions /* Create the options if not provided */),
1000 mPerformanceInterface( nullptr ),
1003 mTriggerEventFactory(),
1004 mObjectProfiler( nullptr ),
1006 mEnvironmentOptionsOwned( environmentOptions ? false : true /* If not provided then we own the object */ ),
1007 mUseRemoteSurface( false )
1009 DALI_ASSERT_ALWAYS( !IsAvailable() && "Cannot create more than one Adaptor per thread" );
1011 WindowPane defaultWindow;
1012 defaultWindow.nativeWindow = nativeWindow;
1013 defaultWindow.surface = surface;
1015 std::vector<WindowPane>::iterator iter = mWindowFrame.begin();
1016 iter = mWindowFrame.insert( iter, defaultWindow );
1018 gThreadLocalAdaptor = this;
1021 void Adaptor::SetRootLayoutDirection( std::string locale )
1023 Dali::Stage stage = Dali::Stage::GetCurrent();
1025 stage.GetRootLayer().SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,
1026 static_cast< LayoutDirection::Type >( Internal::Adaptor::Locale::GetDirection( std::string( locale ) ) ) );
1029 bool Adaptor::AddIdleEnterer( CallbackBase* callback, bool forceAdd )
1031 bool idleAdded( false );
1033 // Only add an idle if the Adaptor is actually running
1034 if( RUNNING == mState || READY == mState || forceAdd )
1036 idleAdded = mCallbackManager->AddIdleEntererCallback( callback );
1042 void Adaptor::RemoveIdleEnterer( CallbackBase* callback )
1044 mCallbackManager->RemoveIdleEntererCallback( callback );
1047 } // namespace Adaptor
1049 } // namespace Internal