2 * Copyright (c) 2022 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-builder-impl.h>
20 #include <dali/internal/adaptor/common/adaptor-impl.h>
21 #include <dali/internal/addons/common/addon-manager-factory.h>
22 #include <dali/internal/addons/common/addon-manager-impl.h>
25 #include <dali/devel-api/actors/actor-devel.h>
26 #include <dali/devel-api/common/stage.h>
27 #include <dali/integration-api/addon-manager.h>
28 #include <dali/integration-api/context-notifier.h>
29 #include <dali/integration-api/core.h>
30 #include <dali/integration-api/debug.h>
31 #include <dali/integration-api/events/key-event-integ.h>
32 #include <dali/integration-api/events/touch-event-integ.h>
33 #include <dali/integration-api/events/wheel-event-integ.h>
34 #include <dali/integration-api/input-options.h>
35 #include <dali/integration-api/processor-interface.h>
36 #include <dali/integration-api/profiling.h>
37 #include <dali/integration-api/trace.h>
38 #include <dali/public-api/actors/layer.h>
39 #include <dali/public-api/events/wheel-event.h>
40 #include <dali/public-api/object/any.h>
41 #include <dali/public-api/object/object-registry.h>
46 #include <dali/internal/adaptor/common/lifecycle-observer.h>
47 #include <dali/internal/adaptor/common/thread-controller-interface.h>
48 #include <dali/internal/system/common/performance-interface-factory.h>
49 #include <dali/internal/system/common/thread-controller.h>
50 #include <dali/public-api/dali-adaptor-common.h>
52 #include <dali/internal/graphics/gles/egl-graphics-factory.h>
53 #include <dali/internal/graphics/gles/egl-graphics.h> // Temporary until Core is abstracted
55 #include <dali/devel-api/text-abstraction/font-client.h>
57 #include <dali/internal/accessibility/common/tts-player-impl.h>
58 #include <dali/internal/clipboard/common/clipboard-impl.h>
59 #include <dali/internal/graphics/common/egl-image-extensions.h>
60 #include <dali/internal/graphics/gles/egl-sync-implementation.h>
61 #include <dali/internal/graphics/gles/gl-implementation.h>
62 #include <dali/internal/graphics/gles/gl-proxy-implementation.h>
63 #include <dali/internal/system/common/callback-manager.h>
64 #include <dali/internal/system/common/object-profiler.h>
65 #include <dali/internal/window-system/common/display-connection.h>
66 #include <dali/internal/window-system/common/display-utils.h> // For Utils::MakeUnique
67 #include <dali/internal/window-system/common/event-handler.h>
68 #include <dali/internal/window-system/common/window-impl.h>
69 #include <dali/internal/window-system/common/window-render-surface.h>
71 #include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
72 #include <dali/internal/system/common/logging.h>
74 #include <dali/internal/imaging/common/image-loader-plugin-proxy.h>
75 #include <dali/internal/imaging/common/image-loader.h>
76 #include <dali/internal/system/common/locale-utils.h>
78 #include <dali/internal/system/common/configuration-manager.h>
79 #include <dali/internal/system/common/environment-variables.h>
81 using Dali::TextAbstraction::FontClient;
83 extern std::string GetSystemCachePath();
93 thread_local Adaptor* gThreadLocalAdaptor = NULL; // raw thread specific pointer to allow Adaptor::Get
95 DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_PERFORMANCE_MARKER, false);
96 } // unnamed namespace
98 Dali::Adaptor* Adaptor::New(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode)
100 Dali::Adaptor* adaptor = new Dali::Adaptor;
101 Adaptor* impl = new Adaptor(window, *adaptor, surface, environmentOptions, threadMode);
102 adaptor->mImpl = impl;
104 Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder = new AdaptorBuilder(*(impl->mEnvironmentOptions));
105 auto graphicsFactory = mAdaptorBuilder->GetGraphicsFactory();
107 impl->Initialize(graphicsFactory);
108 delete mAdaptorBuilder; // Not needed anymore as the graphics interface has now been created
113 Dali::Adaptor* Adaptor::New(Dali::Integration::SceneHolder window, EnvironmentOptions* environmentOptions)
115 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(window);
116 Dali::Adaptor* adaptor = New(window, windowImpl.GetSurface(), environmentOptions, ThreadMode::NORMAL);
117 windowImpl.SetAdaptor(*adaptor);
121 Dali::Adaptor* Adaptor::New(GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode)
123 Dali::Adaptor* adaptor = new Dali::Adaptor; // Public adaptor
124 Adaptor* impl = new Adaptor(window, *adaptor, surface, environmentOptions, threadMode); // Impl adaptor
125 adaptor->mImpl = impl;
127 impl->Initialize(graphicsFactory);
132 Dali::Adaptor* Adaptor::New(GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, EnvironmentOptions* environmentOptions)
134 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(window);
135 Dali::Adaptor* adaptor = New(graphicsFactory, window, windowImpl.GetSurface(), environmentOptions, ThreadMode::NORMAL);
136 windowImpl.SetAdaptor(*adaptor);
140 void Adaptor::Initialize(GraphicsFactory& graphicsFactory)
142 // all threads here (event, update, and render) will send their logs to TIZEN Platform's LogMessage handler.
143 Dali::Integration::Log::LogFunction logFunction(Dali::TizenPlatform::LogMessage);
144 mEnvironmentOptions->SetLogFunction(logFunction);
145 mEnvironmentOptions->InstallLogFunction(); // install logging for main thread
147 mPlatformAbstraction = new TizenPlatform::TizenPlatformAbstraction;
150 GetDataStoragePath(path);
151 mPlatformAbstraction->SetDataStoragePath(path);
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 Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
165 DALI_ASSERT_DEBUG(defaultWindow->GetSurface() && "Surface not initialized");
167 mGraphics = std::unique_ptr<GraphicsInterface>(&graphicsFactory.Create());
169 // Create the AddOnManager
170 mAddOnManager.reset(Dali::Internal::AddOnManagerFactory::CreateAddOnManager());
172 mCore = Integration::Core::New(*this,
173 *mPlatformAbstraction,
174 mGraphics->GetController(),
175 (0u != mEnvironmentOptions->GetRenderToFboInterval()) ? Integration::RenderToFrameBuffer::TRUE : Integration::RenderToFrameBuffer::FALSE,
176 mGraphics->GetDepthBufferRequired(),
177 mGraphics->GetStencilBufferRequired(),
178 mGraphics->GetPartialUpdateRequired());
180 defaultWindow->SetAdaptor(Get());
182 Dali::Integration::SceneHolder defaultSceneHolder(defaultWindow);
184 mWindowCreatedSignal.Emit(defaultSceneHolder);
186 const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval();
187 if(0u < timeInterval)
189 mObjectProfiler = new ObjectProfiler(mCore->GetObjectRegistry(), timeInterval);
192 mNotificationTrigger = TriggerEventFactory::CreateTriggerEvent(MakeCallback(this, &Adaptor::ProcessCoreEvents), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
194 mDisplayConnection = Dali::DisplayConnection::New(*mGraphics, defaultWindow->GetSurface()->GetSurfaceType());
196 mThreadController = new ThreadController(*this, *mEnvironmentOptions, mThreadMode);
198 // Should be called after Core creation
199 if(mEnvironmentOptions->GetPanGestureLoggingLevel())
201 Integration::EnableProfiling(Dali::Integration::PROFILING_TYPE_PAN_GESTURE);
203 if(mEnvironmentOptions->GetPanGesturePredictionMode() >= 0)
205 Integration::SetPanGesturePredictionMode(mEnvironmentOptions->GetPanGesturePredictionMode());
207 if(mEnvironmentOptions->GetPanGesturePredictionAmount() >= 0)
209 Integration::SetPanGesturePredictionAmount(mEnvironmentOptions->GetPanGesturePredictionAmount());
211 if(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount() >= 0)
213 Integration::SetPanGestureMaximumPredictionAmount(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount());
215 if(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount() >= 0)
217 Integration::SetPanGestureMinimumPredictionAmount(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount());
219 if(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment() >= 0)
221 Integration::SetPanGesturePredictionAmountAdjustment(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment());
223 if(mEnvironmentOptions->GetPanGestureSmoothingMode() >= 0)
225 Integration::SetPanGestureSmoothingMode(mEnvironmentOptions->GetPanGestureSmoothingMode());
227 if(mEnvironmentOptions->GetPanGestureSmoothingAmount() >= 0.0f)
229 Integration::SetPanGestureSmoothingAmount(mEnvironmentOptions->GetPanGestureSmoothingAmount());
231 if(mEnvironmentOptions->GetPanGestureUseActualTimes() >= 0)
233 Integration::SetPanGestureUseActualTimes(mEnvironmentOptions->GetPanGestureUseActualTimes() == 0 ? true : false);
235 if(mEnvironmentOptions->GetPanGestureInterpolationTimeRange() >= 0)
237 Integration::SetPanGestureInterpolationTimeRange(mEnvironmentOptions->GetPanGestureInterpolationTimeRange());
239 if(mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() >= 0)
241 Integration::SetPanGestureScalarOnlyPredictionEnabled(mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() == 0 ? true : false);
243 if(mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() >= 0)
245 Integration::SetPanGestureTwoPointPredictionEnabled(mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() == 0 ? true : false);
247 if(mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() >= 0)
249 Integration::SetPanGestureTwoPointInterpolatePastTime(mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime());
251 if(mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() >= 0.0f)
253 Integration::SetPanGestureTwoPointVelocityBias(mEnvironmentOptions->GetPanGestureTwoPointVelocityBias());
255 if(mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() >= 0.0f)
257 Integration::SetPanGestureTwoPointAccelerationBias(mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias());
259 if(mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() >= 0)
261 Integration::SetPanGestureMultitapSmoothingRange(mEnvironmentOptions->GetPanGestureMultitapSmoothingRange());
263 if(mEnvironmentOptions->GetMinimumPanDistance() >= 0)
265 Integration::SetPanGestureMinimumDistance(mEnvironmentOptions->GetMinimumPanDistance());
267 if(mEnvironmentOptions->GetMinimumPanEvents() >= 0)
269 Integration::SetPanGestureMinimumPanEvents(mEnvironmentOptions->GetMinimumPanEvents());
271 if(mEnvironmentOptions->GetMinimumPinchDistance() >= 0)
273 Integration::SetPinchGestureMinimumDistance(mEnvironmentOptions->GetMinimumPinchDistance());
275 if(mEnvironmentOptions->GetMinimumPinchTouchEvents() >= 0)
277 Integration::SetPinchGestureMinimumTouchEvents(mEnvironmentOptions->GetMinimumPinchTouchEvents());
279 if(mEnvironmentOptions->GetMinimumPinchTouchEventsAfterStart() >= 0)
281 Integration::SetPinchGestureMinimumTouchEventsAfterStart(mEnvironmentOptions->GetMinimumPinchTouchEventsAfterStart());
283 if(mEnvironmentOptions->GetMinimumRotationTouchEvents() >= 0)
285 Integration::SetRotationGestureMinimumTouchEvents(mEnvironmentOptions->GetMinimumRotationTouchEvents());
287 if(mEnvironmentOptions->GetMinimumRotationTouchEventsAfterStart() >= 0)
289 Integration::SetRotationGestureMinimumTouchEventsAfterStart(mEnvironmentOptions->GetMinimumRotationTouchEventsAfterStart());
291 if(mEnvironmentOptions->GetLongPressMinimumHoldingTime() >= 0)
293 Integration::SetLongPressMinimumHoldingTime(mEnvironmentOptions->GetLongPressMinimumHoldingTime());
295 if(mEnvironmentOptions->GetTapMaximumAllowedTime() > 0)
297 Integration::SetTapMaximumAllowedTime(mEnvironmentOptions->GetTapMaximumAllowedTime());
300 std::string systemCachePath = GetSystemCachePath();
301 if(!systemCachePath.empty())
303 const int dir_err = mkdir(systemCachePath.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
304 if(0 != dir_err && errno != EEXIST)
306 DALI_LOG_ERROR("Error creating system cache directory: %s!\n", systemCachePath.c_str());
310 mConfigurationManager = Utils::MakeUnique<ConfigurationManager>(systemCachePath, mGraphics.get(), mThreadController);
313 void Adaptor::AccessibilityObserver::OnAccessibleKeyEvent(const Dali::KeyEvent& event)
315 Accessibility::KeyEventType type;
316 if(event.GetState() == Dali::KeyEvent::DOWN)
318 type = Accessibility::KeyEventType::KEY_PRESSED;
320 else if(event.GetState() == Dali::KeyEvent::UP)
322 type = Accessibility::KeyEventType::KEY_RELEASED;
328 Dali::Accessibility::Bridge::GetCurrentBridge()->Emit(type, event.GetKeyCode(), event.GetKeyName(), event.GetTime(), !event.GetKeyString().empty());
333 Accessibility::Bridge::GetCurrentBridge()->Terminate();
335 // Ensure stop status
338 // set to NULL first as we do not want any access to Adaptor as it is being destroyed.
339 gThreadLocalAdaptor = NULL;
341 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
343 (*iter)->OnDestroy();
346 // Clear out all the handles to Windows
349 delete mThreadController; // this will shutdown render thread, which will call Core::ContextDestroyed before exit
350 delete mObjectProfiler;
354 delete mDisplayConnection;
355 delete mPlatformAbstraction;
356 delete mCallbackManager;
357 delete mPerformanceInterface;
359 mGraphics->Destroy();
361 // uninstall it on this thread (main actor thread)
362 Dali::Integration::Log::UninstallLogFunction();
364 // Delete environment options if we own it
365 if(mEnvironmentOptionsOwned)
367 delete mEnvironmentOptions;
371 void Adaptor::Start()
373 // It doesn't support restart after stop at this moment to support restarting, need more testing
381 SetupSystemInformation();
383 // Start the callback manager
384 mCallbackManager->Start();
386 // Initialize accessibility bridge after callback manager is started to use Idler callback
387 auto appName = GetApplicationPackageName();
388 auto bridge = Accessibility::Bridge::GetCurrentBridge();
389 bridge->SetApplicationName(appName);
390 bridge->Initialize();
391 Dali::Stage::GetCurrent().KeyEventSignal().Connect(&mAccessibilityObserver, &AccessibilityObserver::OnAccessibleKeyEvent);
393 Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
395 unsigned int dpiHor, dpiVer;
398 defaultWindow->GetSurface()->GetDpi(dpiHor, dpiVer);
400 // set the DPI value for font rendering
401 FontClient fontClient = FontClient::Get();
402 fontClient.SetDpi(dpiHor, dpiVer);
404 // Initialize the thread controller
405 mThreadController->Initialize();
407 // Set max texture size
408 if(mEnvironmentOptions->GetMaxTextureSize() > 0)
410 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize(mEnvironmentOptions->GetMaxTextureSize());
414 unsigned int maxTextureSize = mConfigurationManager->GetMaxTextureSize();
415 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize(maxTextureSize);
418 // cache advanced blending and shader language version
419 mGraphics->CacheConfigurations(*mConfigurationManager.get());
421 ProcessCoreEvents(); // Ensure any startup messages are processed.
423 // Initialize the image loader plugin
424 Internal::Adaptor::ImageLoaderPluginProxy::Initialize();
426 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
433 mAddOnManager->Start();
437 // Dali::Internal::Adaptor::Adaptor::Pause
438 void Adaptor::Pause()
440 // Only pause the adaptor if we're actually running.
441 if(RUNNING == mState)
443 // Inform observers that we are about to be paused.
444 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
452 mAddOnManager->Pause();
455 // Pause all windows event handlers when adaptor paused
456 for(auto window : mWindows)
461 mThreadController->Pause();
464 // Ensure any messages queued during pause callbacks are processed by doing another update.
467 DALI_LOG_RELEASE_INFO("Adaptor::Pause: Paused\n");
471 DALI_LOG_RELEASE_INFO("Adaptor::Pause: Not paused [%d]\n", mState);
475 // Dali::Internal::Adaptor::Adaptor::Resume
476 void Adaptor::Resume()
478 // Only resume the adaptor if we are in the suspended state.
483 // Reset the event handlers when adaptor resumed
484 for(auto window : mWindows)
489 // Resume AddOnManager
492 mAddOnManager->Resume();
495 // Inform observers that we have resumed.
496 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
501 // Trigger processing of events queued up while paused
502 mCore->ProcessEvents();
504 // Do at end to ensure our first update/render after resumption includes the processed messages as well
505 mThreadController->Resume();
507 DALI_LOG_RELEASE_INFO("Adaptor::Resume: Resumed\n");
511 DALI_LOG_RELEASE_INFO("Adaptor::Resume: Not resumed [%d]\n", mState);
517 if(RUNNING == mState ||
519 PAUSED_WHILE_HIDDEN == mState)
521 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
528 mAddOnManager->Stop();
531 mThreadController->Stop();
533 // Delete the TTS player
534 for(int i = 0; i < Dali::TtsPlayer::MODE_NUM; i++)
538 mTtsPlayers[i].Reset();
542 // Destroy the image loader plugin
543 Internal::Adaptor::ImageLoaderPluginProxy::Destroy();
545 delete mNotificationTrigger;
546 mNotificationTrigger = NULL;
548 mCallbackManager->Stop();
552 DALI_LOG_RELEASE_INFO("Adaptor::Stop\n");
556 void Adaptor::ContextLost()
558 mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage
561 void Adaptor::ContextRegained()
563 // Inform core, so that texture resources can be reloaded
564 mCore->RecoverFromContextLoss();
566 mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage
569 void Adaptor::FeedTouchPoint(TouchPoint& point, int timeStamp)
571 Integration::Point convertedPoint(point);
572 mWindows.front()->FeedTouchPoint(convertedPoint, timeStamp);
575 void Adaptor::FeedWheelEvent(Dali::WheelEvent& wheelEvent)
577 Integration::WheelEvent event(static_cast<Integration::WheelEvent::Type>(wheelEvent.GetType()), wheelEvent.GetDirection(), wheelEvent.GetModifiers(), wheelEvent.GetPoint(), wheelEvent.GetDelta(), wheelEvent.GetTime());
578 mWindows.front()->FeedWheelEvent(event);
581 void Adaptor::FeedKeyEvent(Dali::KeyEvent& keyEvent)
583 Integration::KeyEvent convertedEvent(keyEvent.GetKeyName(), keyEvent.GetLogicalKey(), keyEvent.GetKeyString(), keyEvent.GetKeyCode(), keyEvent.GetKeyModifier(), keyEvent.GetTime(), static_cast<Integration::KeyEvent::State>(keyEvent.GetState()), keyEvent.GetCompose(), keyEvent.GetDeviceName(), keyEvent.GetDeviceClass(), keyEvent.GetDeviceSubclass());
584 mWindows.front()->FeedKeyEvent(convertedEvent);
587 void Adaptor::ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& newSurface)
589 Internal::Adaptor::SceneHolder* windowImpl = &Dali::GetImplementation(window);
590 for(auto windowPtr : mWindows)
592 if(windowPtr == windowImpl) // the window is not deleted
594 mResizedSignal.Emit(mAdaptor);
596 windowImpl->SetSurface(&newSurface);
598 // Flush the event queue to give the update-render thread chance
599 // to start processing messages for new camera setup etc as soon as possible
602 // This method blocks until the render thread has completed the replace.
603 mThreadController->ReplaceSurface(&newSurface);
609 void Adaptor::DeleteSurface(Dali::RenderSurfaceInterface& surface)
611 // Flush the event queue to give the update-render thread chance
612 // to start processing messages for new camera setup etc as soon as possible
615 // This method blocks until the render thread has finished rendering the current surface.
616 mThreadController->DeleteSurface(&surface);
619 Dali::RenderSurfaceInterface& Adaptor::GetSurface() const
621 return *mWindows.front()->GetSurface();
624 void Adaptor::ReleaseSurfaceLock()
626 mWindows.front()->GetSurface()->ReleaseLock();
629 Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
631 if(!mTtsPlayers[mode])
633 // Create the TTS player when it needed, because it can reduce launching time.
634 mTtsPlayers[mode] = TtsPlayer::New(mode);
637 return mTtsPlayers[mode];
640 bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue, bool forceAdd)
642 bool idleAdded(false);
644 // Only add an idle if the Adaptor is actually running
645 if(RUNNING == mState || READY == mState || forceAdd)
647 idleAdded = mCallbackManager->AddIdleCallback(callback, hasReturnValue);
653 void Adaptor::RemoveIdle(CallbackBase* callback)
655 mCallbackManager->RemoveIdleCallback(callback);
658 void Adaptor::ProcessIdle()
660 bool idleProcessed = mCallbackManager->ProcessIdle();
661 mNotificationOnIdleInstalled = mNotificationOnIdleInstalled && !idleProcessed;
664 void Adaptor::SetPreRenderCallback(CallbackBase* callback)
666 mThreadController->SetPreRenderCallback(callback);
669 bool Adaptor::AddWindow(Dali::Integration::SceneHolder childWindow)
671 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(childWindow);
672 windowImpl.SetAdaptor(Get());
674 // ChildWindow is set to the layout direction of the default window.
675 windowImpl.GetRootLayer().SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, mRootLayoutDirection);
677 // Add the new Window to the container - the order is not important
679 Dali::Mutex::ScopedLock lock(mMutex);
680 mWindows.push_back(&windowImpl);
683 Dali::RenderSurfaceInterface* surface = windowImpl.GetSurface();
685 mThreadController->AddSurface(surface);
687 mWindowCreatedSignal.Emit(childWindow);
692 bool Adaptor::RemoveWindow(Dali::Integration::SceneHolder* childWindow)
694 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(*childWindow);
695 for(WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter)
697 if(*iter == &windowImpl)
699 Dali::Mutex::ScopedLock lock(mMutex);
700 mWindows.erase(iter);
708 bool Adaptor::RemoveWindow(std::string childWindowName)
710 for(WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter)
712 if((*iter)->GetName() == childWindowName)
714 Dali::Mutex::ScopedLock lock(mMutex);
715 mWindows.erase(iter);
723 bool Adaptor::RemoveWindow(Internal::Adaptor::SceneHolder* childWindow)
725 for(WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter)
727 if((*iter)->GetId() == childWindow->GetId())
729 Dali::Mutex::ScopedLock lock(mMutex);
730 mWindows.erase(iter);
738 Dali::Adaptor& Adaptor::Get()
740 DALI_ASSERT_ALWAYS(IsAvailable() && "Adaptor not instantiated");
741 return gThreadLocalAdaptor->mAdaptor;
744 bool Adaptor::IsAvailable()
746 return gThreadLocalAdaptor != NULL;
749 void Adaptor::SceneCreated()
751 mCore->SceneCreated();
754 Dali::Integration::Core& Adaptor::GetCore()
759 void Adaptor::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender)
761 mThreadController->SetRenderRefreshRate(numberOfVSyncsPerRender);
764 Dali::DisplayConnection& Adaptor::GetDisplayConnectionInterface()
766 DALI_ASSERT_DEBUG(mDisplayConnection && "Display connection not created");
767 return *mDisplayConnection;
770 GraphicsInterface& Adaptor::GetGraphicsInterface()
772 DALI_ASSERT_DEBUG(mGraphics && "Graphics interface not created");
773 return *(mGraphics.get());
776 Dali::Integration::PlatformAbstraction& Adaptor::GetPlatformAbstractionInterface()
778 return *mPlatformAbstraction;
781 TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
783 return *mNotificationTrigger;
786 SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
788 return mSocketFactory;
791 Dali::RenderSurfaceInterface* Adaptor::GetRenderSurfaceInterface()
793 if(!mWindows.empty())
795 return mWindows.front()->GetSurface();
801 TraceInterface& Adaptor::GetKernelTraceInterface()
803 return mKernelTracer;
806 TraceInterface& Adaptor::GetSystemTraceInterface()
808 return mSystemTracer;
811 PerformanceInterface* Adaptor::GetPerformanceInterface()
813 return mPerformanceInterface;
816 Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
818 DALI_ASSERT_DEBUG(mPlatformAbstraction && "PlatformAbstraction not created");
819 return *mPlatformAbstraction;
822 void Adaptor::GetWindowContainerInterface(WindowContainer& windows)
824 Dali::Mutex::ScopedLock lock(mMutex);
828 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
830 if(mTtsPlayers[mode])
832 mTtsPlayers[mode].Reset();
836 Any Adaptor::GetNativeWindowHandle()
838 return mWindows.front()->GetNativeHandle();
841 Any Adaptor::GetNativeWindowHandle(Dali::Actor actor)
843 Any nativeWindowHandle;
845 Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
847 for(auto sceneHolder : mWindows)
849 if(scene == sceneHolder->GetScene())
851 nativeWindowHandle = sceneHolder->GetNativeHandle();
856 return nativeWindowHandle;
859 Any Adaptor::GetGraphicsDisplay()
865 GraphicsInterface* graphics = mGraphics.get(); // This interface is temporary until Core has been updated to match
866 auto eglGraphics = static_cast<EglGraphics*>(graphics);
868 EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
869 display = eglImpl.GetDisplay();
875 void Adaptor::SetUseRemoteSurface(bool useRemoteSurface)
877 mUseRemoteSurface = useRemoteSurface;
880 void Adaptor::AddObserver(LifeCycleObserver& observer)
882 ObserverContainer::iterator match(find(mObservers.begin(), mObservers.end(), &observer));
884 if(match == mObservers.end())
886 mObservers.push_back(&observer);
890 void Adaptor::RemoveObserver(LifeCycleObserver& observer)
892 ObserverContainer::iterator match(find(mObservers.begin(), mObservers.end(), &observer));
894 if(match != mObservers.end())
896 mObservers.erase(match);
900 void Adaptor::QueueCoreEvent(const Dali::Integration::Event& event)
904 mCore->QueueEvent(event);
908 void Adaptor::ProcessCoreEvents()
912 if(mPerformanceInterface)
914 mPerformanceInterface->AddMarker(PerformanceInterface::PROCESS_EVENTS_START);
917 DALI_TRACE_BEGIN(gTraceFilter, "DALI_PROCESS_CORE_EVENTS");
919 mCore->ProcessEvents();
921 DALI_TRACE_END(gTraceFilter, "DALI_PROCESS_CORE_EVENTS");
923 if(mPerformanceInterface)
925 mPerformanceInterface->AddMarker(PerformanceInterface::PROCESS_EVENTS_END);
930 void Adaptor::RequestUpdate(bool forceUpdate)
936 mThreadController->RequestUpdate();
940 case PAUSED_WHILE_HIDDEN:
944 // Update (and resource upload) without rendering
945 mThreadController->RequestUpdateOnce(UpdateMode::SKIP_RENDER);
957 void Adaptor::RequestProcessEventsOnIdle(bool forceProcess)
959 // Only request a notification if the Adaptor is actually running
960 // and we haven't installed the idle notification
961 if((!mNotificationOnIdleInstalled) && (RUNNING == mState || READY == mState || forceProcess))
963 mNotificationOnIdleInstalled = AddIdleEnterer(MakeCallback(this, &Adaptor::ProcessCoreEventsFromIdle), forceProcess);
967 void Adaptor::OnWindowShown()
969 if(PAUSED_WHILE_HIDDEN == mState)
971 // Adaptor can now be resumed
976 // Force a render task
979 else if(RUNNING == mState)
981 // Force a render task
984 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowShown: Update requested.\n");
986 else if(PAUSED_WHILE_INITIALIZING == mState)
988 // Change the state to READY again. It will be changed to RUNNING after the adaptor is started.
993 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowShown: Adaptor is not paused state.[%d]\n", mState);
997 void Adaptor::OnWindowHidden()
999 if(RUNNING == mState || READY == mState)
1001 bool allWindowsHidden = true;
1003 for(auto window : mWindows)
1005 if(window->IsVisible())
1007 allWindowsHidden = false;
1012 // Only pause the adaptor when all the windows are hidden
1013 if(allWindowsHidden)
1015 if(mState == RUNNING)
1019 // Adaptor cannot be resumed until any window is shown
1020 mState = PAUSED_WHILE_HIDDEN;
1022 else // mState is READY
1024 // Pause the adaptor after the state gets RUNNING
1025 mState = PAUSED_WHILE_INITIALIZING;
1030 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowHidden: Some windows are shown. Don't pause adaptor.\n");
1035 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowHidden: Adaptor is not running state.[%d]\n", mState);
1039 // Dali::Internal::Adaptor::Adaptor::OnDamaged
1040 void Adaptor::OnDamaged(const DamageArea& area)
1042 // This is needed for the case where Dali window is partially obscured
1043 RequestUpdate(false);
1046 void Adaptor::SurfaceResizePrepare(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize)
1048 mResizedSignal.Emit(mAdaptor);
1051 void Adaptor::SurfaceResizeComplete(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize)
1053 // Nofify surface resizing before flushing event queue
1054 mThreadController->ResizeSurface();
1056 // Flush the event queue to give the update-render thread chance
1057 // to start processing messages for new camera setup etc as soon as possible
1058 ProcessCoreEvents();
1061 void Adaptor::NotifySceneCreated()
1063 GetCore().SceneCreated();
1065 // Flush the event queue to give the update-render thread chance
1066 // to start processing messages for new camera setup etc as soon as possible
1067 ProcessCoreEvents();
1069 // Start thread controller after the scene has been created
1070 mThreadController->Start();
1072 // Process after surface is created (registering to remote surface provider if required)
1073 SurfaceInitialized();
1075 if(mState != PAUSED_WHILE_INITIALIZING)
1079 DALI_LOG_RELEASE_INFO("Adaptor::NotifySceneCreated: Adaptor is running\n");
1087 mState = PAUSED_WHILE_HIDDEN;
1089 DALI_LOG_RELEASE_INFO("Adaptor::NotifySceneCreated: Adaptor is paused\n");
1093 void Adaptor::NotifyLanguageChanged()
1095 mLanguageChangedSignal.Emit(mAdaptor);
1098 void Adaptor::RenderOnce()
1100 if(mThreadController)
1102 UpdateMode updateMode;
1103 if(mThreadMode == ThreadMode::NORMAL)
1105 updateMode = UpdateMode::NORMAL;
1109 updateMode = UpdateMode::FORCE_RENDER;
1111 ProcessCoreEvents();
1113 mThreadController->RequestUpdateOnce(updateMode);
1117 const LogFactoryInterface& Adaptor::GetLogFactory()
1119 return *mEnvironmentOptions;
1122 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
1124 GetCore().RegisterProcessor(processor, postProcessor);
1127 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
1129 GetCore().UnregisterProcessor(processor, postProcessor);
1132 bool Adaptor::IsMultipleWindowSupported() const
1134 return mConfigurationManager->IsMultipleWindowSupported();
1137 void Adaptor::RequestUpdateOnce()
1139 if(mThreadController)
1141 mThreadController->RequestUpdateOnce(UpdateMode::NORMAL);
1145 bool Adaptor::ProcessCoreEventsFromIdle()
1147 ProcessCoreEvents();
1149 // the idle handle automatically un-installs itself
1150 mNotificationOnIdleInstalled = false;
1155 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow(Dali::Actor& actor)
1157 Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
1159 for(auto window : mWindows)
1161 if(scene == window->GetScene())
1170 Dali::WindowContainer Adaptor::GetWindows() const
1172 Dali::WindowContainer windows;
1174 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
1176 // Downcast to Dali::Window
1177 Dali::Window window(dynamic_cast<Dali::Internal::Adaptor::Window*>(*iter));
1180 windows.push_back(window);
1187 Dali::SceneHolderList Adaptor::GetSceneHolders() const
1189 Dali::SceneHolderList sceneHolderList;
1191 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
1193 sceneHolderList.push_back(Dali::Integration::SceneHolder(*iter));
1196 return sceneHolderList;
1199 Dali::ObjectRegistry Adaptor::GetObjectRegistry() const
1201 Dali::ObjectRegistry registry;
1204 registry = mCore->GetObjectRegistry();
1209 Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode)
1211 mLanguageChangedSignal(),
1212 mWindowCreatedSignal(),
1216 mThreadController(nullptr),
1218 mDisplayConnection(nullptr),
1220 mConfigurationManager(nullptr),
1221 mPlatformAbstraction(nullptr),
1222 mCallbackManager(nullptr),
1223 mNotificationOnIdleInstalled(false),
1224 mNotificationTrigger(nullptr),
1225 mDaliFeedbackPlugin(),
1226 mFeedbackController(nullptr),
1229 mEnvironmentOptions(environmentOptions ? environmentOptions : new EnvironmentOptions /* Create the options if not provided */),
1230 mPerformanceInterface(nullptr),
1233 mObjectProfiler(nullptr),
1236 mThreadMode(threadMode),
1237 mEnvironmentOptionsOwned(environmentOptions ? false : true /* If not provided then we own the object */),
1238 mUseRemoteSurface(false),
1239 mRootLayoutDirection(Dali::LayoutDirection::LEFT_TO_RIGHT)
1241 DALI_ASSERT_ALWAYS(!IsAvailable() && "Cannot create more than one Adaptor per thread");
1242 mWindows.insert(mWindows.begin(), &Dali::GetImplementation(window));
1244 gThreadLocalAdaptor = this;
1247 void Adaptor::SetRootLayoutDirection(std::string locale)
1249 mRootLayoutDirection = static_cast<LayoutDirection::Type>(Internal::Adaptor::Locale::GetDirection(std::string(locale)));
1250 for(auto& window : mWindows)
1252 Dali::Actor root = window->GetRootLayer();
1253 root.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, mRootLayoutDirection);
1257 bool Adaptor::AddIdleEnterer(CallbackBase* callback, bool forceAdd)
1259 bool idleAdded(false);
1261 // Only add an idle if the Adaptor is actually running
1262 if(RUNNING == mState || READY == mState || forceAdd)
1264 idleAdded = mCallbackManager->AddIdleEntererCallback(callback);
1276 void Adaptor::RemoveIdleEnterer(CallbackBase* callback)
1278 mCallbackManager->RemoveIdleEntererCallback(callback);
1281 } // namespace Adaptor
1283 } // namespace Internal