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>
70 #include <dali/internal/window-system/common/window-system.h>
72 #include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
73 #include <dali/internal/system/common/logging.h>
75 #include <dali/internal/imaging/common/image-loader-plugin-proxy.h>
76 #include <dali/internal/imaging/common/image-loader.h>
77 #include <dali/internal/system/common/locale-utils.h>
79 #include <dali/internal/system/common/configuration-manager.h>
80 #include <dali/internal/system/common/environment-variables.h>
82 using Dali::TextAbstraction::FontClient;
84 extern std::string GetSystemCachePath();
94 thread_local Adaptor* gThreadLocalAdaptor = NULL; // raw thread specific pointer to allow Adaptor::Get
96 DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_PERFORMANCE_MARKER, false);
97 } // unnamed namespace
99 Dali::Adaptor* Adaptor::New(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode)
101 Dali::Adaptor* adaptor = new Dali::Adaptor;
102 Adaptor* impl = new Adaptor(window, *adaptor, surface, environmentOptions, threadMode);
103 adaptor->mImpl = impl;
105 Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder = new AdaptorBuilder(*(impl->mEnvironmentOptions));
106 auto graphicsFactory = mAdaptorBuilder->GetGraphicsFactory();
108 impl->Initialize(graphicsFactory);
109 delete mAdaptorBuilder; // Not needed anymore as the graphics interface has now been created
114 Dali::Adaptor* Adaptor::New(Dali::Integration::SceneHolder window, EnvironmentOptions* environmentOptions)
116 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(window);
117 Dali::Adaptor* adaptor = New(window, windowImpl.GetSurface(), environmentOptions, ThreadMode::NORMAL);
118 windowImpl.SetAdaptor(*adaptor);
122 Dali::Adaptor* Adaptor::New(GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode)
124 Dali::Adaptor* adaptor = new Dali::Adaptor; // Public adaptor
125 Adaptor* impl = new Adaptor(window, *adaptor, surface, environmentOptions, threadMode); // Impl adaptor
126 adaptor->mImpl = impl;
128 impl->Initialize(graphicsFactory);
133 Dali::Adaptor* Adaptor::New(GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, EnvironmentOptions* environmentOptions)
135 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(window);
136 Dali::Adaptor* adaptor = New(graphicsFactory, window, windowImpl.GetSurface(), environmentOptions, ThreadMode::NORMAL);
137 windowImpl.SetAdaptor(*adaptor);
141 void Adaptor::Initialize(GraphicsFactory& graphicsFactory)
143 // all threads here (event, update, and render) will send their logs to TIZEN Platform's LogMessage handler.
144 Dali::Integration::Log::LogFunction logFunction(Dali::TizenPlatform::LogMessage);
145 mEnvironmentOptions->SetLogFunction(logFunction);
146 mEnvironmentOptions->InstallLogFunction(); // install logging for main thread
148 mPlatformAbstraction = new TizenPlatform::TizenPlatformAbstraction;
151 GetDataStoragePath(path);
152 mPlatformAbstraction->SetDataStoragePath(path);
154 if(mEnvironmentOptions->PerformanceServerRequired())
156 mPerformanceInterface = PerformanceInterfaceFactory::CreateInterface(*this, *mEnvironmentOptions);
159 mEnvironmentOptions->CreateTraceManager(mPerformanceInterface);
160 mEnvironmentOptions->InstallTraceFunction(); // install tracing for main thread
162 mCallbackManager = CallbackManager::New();
164 Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
166 DALI_ASSERT_DEBUG(defaultWindow->GetSurface() && "Surface not initialized");
168 mGraphics = std::unique_ptr<GraphicsInterface>(&graphicsFactory.Create());
170 // Create the AddOnManager
171 mAddOnManager.reset(Dali::Internal::AddOnManagerFactory::CreateAddOnManager());
173 mCore = Integration::Core::New(*this,
174 *mPlatformAbstraction,
175 mGraphics->GetController(),
176 (0u != mEnvironmentOptions->GetRenderToFboInterval()) ? Integration::RenderToFrameBuffer::TRUE : Integration::RenderToFrameBuffer::FALSE,
177 mGraphics->GetDepthBufferRequired(),
178 mGraphics->GetStencilBufferRequired(),
179 mGraphics->GetPartialUpdateRequired());
181 defaultWindow->SetAdaptor(Get());
183 Dali::Integration::SceneHolder defaultSceneHolder(defaultWindow);
185 mWindowCreatedSignal.Emit(defaultSceneHolder);
187 const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval();
188 if(0u < timeInterval)
190 mObjectProfiler = new ObjectProfiler(mCore->GetObjectRegistry(), timeInterval);
193 mNotificationTrigger = TriggerEventFactory::CreateTriggerEvent(MakeCallback(this, &Adaptor::ProcessCoreEvents), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
195 mDisplayConnection = Dali::DisplayConnection::New(*mGraphics, defaultWindow->GetSurface()->GetSurfaceType());
197 mThreadController = new ThreadController(*this, *mEnvironmentOptions, mThreadMode);
199 // Should be called after Core creation
200 if(mEnvironmentOptions->GetPanGestureLoggingLevel())
202 Integration::EnableProfiling(Dali::Integration::PROFILING_TYPE_PAN_GESTURE);
204 if(mEnvironmentOptions->GetPanGesturePredictionMode() >= 0)
206 Integration::SetPanGesturePredictionMode(mEnvironmentOptions->GetPanGesturePredictionMode());
208 if(mEnvironmentOptions->GetPanGesturePredictionAmount() >= 0)
210 Integration::SetPanGesturePredictionAmount(mEnvironmentOptions->GetPanGesturePredictionAmount());
212 if(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount() >= 0)
214 Integration::SetPanGestureMaximumPredictionAmount(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount());
216 if(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount() >= 0)
218 Integration::SetPanGestureMinimumPredictionAmount(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount());
220 if(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment() >= 0)
222 Integration::SetPanGesturePredictionAmountAdjustment(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment());
224 if(mEnvironmentOptions->GetPanGestureSmoothingMode() >= 0)
226 Integration::SetPanGestureSmoothingMode(mEnvironmentOptions->GetPanGestureSmoothingMode());
228 if(mEnvironmentOptions->GetPanGestureSmoothingAmount() >= 0.0f)
230 Integration::SetPanGestureSmoothingAmount(mEnvironmentOptions->GetPanGestureSmoothingAmount());
232 if(mEnvironmentOptions->GetPanGestureUseActualTimes() >= 0)
234 Integration::SetPanGestureUseActualTimes(mEnvironmentOptions->GetPanGestureUseActualTimes() == 0 ? true : false);
236 if(mEnvironmentOptions->GetPanGestureInterpolationTimeRange() >= 0)
238 Integration::SetPanGestureInterpolationTimeRange(mEnvironmentOptions->GetPanGestureInterpolationTimeRange());
240 if(mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() >= 0)
242 Integration::SetPanGestureScalarOnlyPredictionEnabled(mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() == 0 ? true : false);
244 if(mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() >= 0)
246 Integration::SetPanGestureTwoPointPredictionEnabled(mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() == 0 ? true : false);
248 if(mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() >= 0)
250 Integration::SetPanGestureTwoPointInterpolatePastTime(mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime());
252 if(mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() >= 0.0f)
254 Integration::SetPanGestureTwoPointVelocityBias(mEnvironmentOptions->GetPanGestureTwoPointVelocityBias());
256 if(mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() >= 0.0f)
258 Integration::SetPanGestureTwoPointAccelerationBias(mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias());
260 if(mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() >= 0)
262 Integration::SetPanGestureMultitapSmoothingRange(mEnvironmentOptions->GetPanGestureMultitapSmoothingRange());
264 if(mEnvironmentOptions->GetMinimumPanDistance() >= 0)
266 Integration::SetPanGestureMinimumDistance(mEnvironmentOptions->GetMinimumPanDistance());
268 if(mEnvironmentOptions->GetMinimumPanEvents() >= 0)
270 Integration::SetPanGestureMinimumPanEvents(mEnvironmentOptions->GetMinimumPanEvents());
272 if(mEnvironmentOptions->GetMinimumPinchDistance() >= 0)
274 Integration::SetPinchGestureMinimumDistance(mEnvironmentOptions->GetMinimumPinchDistance());
276 if(mEnvironmentOptions->GetMinimumPinchTouchEvents() >= 0)
278 Integration::SetPinchGestureMinimumTouchEvents(mEnvironmentOptions->GetMinimumPinchTouchEvents());
280 if(mEnvironmentOptions->GetMinimumPinchTouchEventsAfterStart() >= 0)
282 Integration::SetPinchGestureMinimumTouchEventsAfterStart(mEnvironmentOptions->GetMinimumPinchTouchEventsAfterStart());
284 if(mEnvironmentOptions->GetMinimumRotationTouchEvents() >= 0)
286 Integration::SetRotationGestureMinimumTouchEvents(mEnvironmentOptions->GetMinimumRotationTouchEvents());
288 if(mEnvironmentOptions->GetMinimumRotationTouchEventsAfterStart() >= 0)
290 Integration::SetRotationGestureMinimumTouchEventsAfterStart(mEnvironmentOptions->GetMinimumRotationTouchEventsAfterStart());
292 if(mEnvironmentOptions->GetLongPressMinimumHoldingTime() >= 0)
294 Integration::SetLongPressMinimumHoldingTime(mEnvironmentOptions->GetLongPressMinimumHoldingTime());
296 if(mEnvironmentOptions->GetTapMaximumAllowedTime() > 0)
298 Integration::SetTapMaximumAllowedTime(mEnvironmentOptions->GetTapMaximumAllowedTime());
301 std::string systemCachePath = GetSystemCachePath();
302 if(!systemCachePath.empty())
304 const int dir_err = mkdir(systemCachePath.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
305 if(0 != dir_err && errno != EEXIST)
307 DALI_LOG_ERROR("Error creating system cache directory: %s!\n", systemCachePath.c_str());
311 mConfigurationManager = Utils::MakeUnique<ConfigurationManager>(systemCachePath, mGraphics.get(), mThreadController);
314 void Adaptor::AccessibilityObserver::OnAccessibleKeyEvent(const Dali::KeyEvent& event)
316 Accessibility::KeyEventType type;
317 if(event.GetState() == Dali::KeyEvent::DOWN)
319 type = Accessibility::KeyEventType::KEY_PRESSED;
321 else if(event.GetState() == Dali::KeyEvent::UP)
323 type = Accessibility::KeyEventType::KEY_RELEASED;
329 Dali::Accessibility::Bridge::GetCurrentBridge()->Emit(type, event.GetKeyCode(), event.GetKeyName(), event.GetTime(), !event.GetKeyString().empty());
334 Accessibility::Bridge::GetCurrentBridge()->Terminate();
336 // Ensure stop status
339 // set to NULL first as we do not want any access to Adaptor as it is being destroyed.
340 gThreadLocalAdaptor = NULL;
342 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
344 (*iter)->OnDestroy();
347 // Clear out all the handles to Windows
350 delete mThreadController; // this will shutdown render thread, which will call Core::ContextDestroyed before exit
351 delete mObjectProfiler;
355 delete mDisplayConnection;
356 delete mPlatformAbstraction;
357 delete mCallbackManager;
358 delete mPerformanceInterface;
360 mGraphics->Destroy();
362 // uninstall it on this thread (main actor thread)
363 Dali::Integration::Log::UninstallLogFunction();
365 // Delete environment options if we own it
366 if(mEnvironmentOptionsOwned)
368 delete mEnvironmentOptions;
372 void Adaptor::Start()
374 // It doesn't support restart after stop at this moment to support restarting, need more testing
382 SetupSystemInformation();
384 // Start the callback manager
385 mCallbackManager->Start();
387 // Initialize accessibility bridge after callback manager is started to use Idler callback
388 auto appName = GetApplicationPackageName();
389 auto bridge = Accessibility::Bridge::GetCurrentBridge();
390 bridge->SetApplicationName(appName);
391 bridge->Initialize();
392 Dali::Stage::GetCurrent().KeyEventSignal().Connect(&mAccessibilityObserver, &AccessibilityObserver::OnAccessibleKeyEvent);
394 Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
396 unsigned int dpiHor, dpiVer;
399 defaultWindow->GetSurface()->GetDpi(dpiHor, dpiVer);
400 Dali::Internal::Adaptor::WindowSystem::SetDpi(dpiHor, dpiVer);
402 // Initialize the thread controller
403 mThreadController->Initialize();
405 // Set max texture size
406 if(mEnvironmentOptions->GetMaxTextureSize() > 0)
408 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize(mEnvironmentOptions->GetMaxTextureSize());
412 unsigned int maxTextureSize = mConfigurationManager->GetMaxTextureSize();
413 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize(maxTextureSize);
416 // cache advanced blending and shader language version
417 mGraphics->CacheConfigurations(*mConfigurationManager.get());
419 ProcessCoreEvents(); // Ensure any startup messages are processed.
421 // Initialize the image loader plugin
422 Internal::Adaptor::ImageLoaderPluginProxy::Initialize();
424 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
431 mAddOnManager->Start();
435 // Dali::Internal::Adaptor::Adaptor::Pause
436 void Adaptor::Pause()
438 // Only pause the adaptor if we're actually running.
439 if(RUNNING == mState)
441 // Inform observers that we are about to be paused.
442 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
450 mAddOnManager->Pause();
453 // Pause all windows event handlers when adaptor paused
454 for(auto window : mWindows)
459 mThreadController->Pause();
462 // Ensure any messages queued during pause callbacks are processed by doing another update.
465 DALI_LOG_RELEASE_INFO("Adaptor::Pause: Paused\n");
469 DALI_LOG_RELEASE_INFO("Adaptor::Pause: Not paused [%d]\n", mState);
473 // Dali::Internal::Adaptor::Adaptor::Resume
474 void Adaptor::Resume()
476 // Only resume the adaptor if we are in the suspended state.
481 // Reset the event handlers when adaptor resumed
482 for(auto window : mWindows)
487 // Resume AddOnManager
490 mAddOnManager->Resume();
493 // Inform observers that we have resumed.
494 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
499 // Trigger processing of events queued up while paused
500 mCore->ProcessEvents();
502 // Do at end to ensure our first update/render after resumption includes the processed messages as well
503 mThreadController->Resume();
505 DALI_LOG_RELEASE_INFO("Adaptor::Resume: Resumed\n");
509 DALI_LOG_RELEASE_INFO("Adaptor::Resume: Not resumed [%d]\n", mState);
515 if(RUNNING == mState ||
517 PAUSED_WHILE_HIDDEN == mState)
519 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
526 mAddOnManager->Stop();
529 mThreadController->Stop();
531 // Delete the TTS player
532 for(int i = 0; i < Dali::TtsPlayer::MODE_NUM; i++)
536 mTtsPlayers[i].Reset();
540 // Destroy the image loader plugin
541 Internal::Adaptor::ImageLoaderPluginProxy::Destroy();
543 delete mNotificationTrigger;
544 mNotificationTrigger = NULL;
546 mCallbackManager->Stop();
550 DALI_LOG_RELEASE_INFO("Adaptor::Stop\n");
554 void Adaptor::ContextLost()
556 mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage
559 void Adaptor::ContextRegained()
561 // Inform core, so that texture resources can be reloaded
562 mCore->RecoverFromContextLoss();
564 mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage
567 void Adaptor::FeedTouchPoint(TouchPoint& point, int timeStamp)
569 Integration::Point convertedPoint(point);
570 mWindows.front()->FeedTouchPoint(convertedPoint, timeStamp);
573 void Adaptor::FeedWheelEvent(Dali::WheelEvent& wheelEvent)
575 Integration::WheelEvent event(static_cast<Integration::WheelEvent::Type>(wheelEvent.GetType()), wheelEvent.GetDirection(), wheelEvent.GetModifiers(), wheelEvent.GetPoint(), wheelEvent.GetDelta(), wheelEvent.GetTime());
576 mWindows.front()->FeedWheelEvent(event);
579 void Adaptor::FeedKeyEvent(Dali::KeyEvent& keyEvent)
581 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());
582 mWindows.front()->FeedKeyEvent(convertedEvent);
585 void Adaptor::ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& newSurface)
587 Internal::Adaptor::SceneHolder* windowImpl = &Dali::GetImplementation(window);
588 for(auto windowPtr : mWindows)
590 if(windowPtr == windowImpl) // the window is not deleted
592 mResizedSignal.Emit(mAdaptor);
594 windowImpl->SetSurface(&newSurface);
596 // Flush the event queue to give the update-render thread chance
597 // to start processing messages for new camera setup etc as soon as possible
600 // This method blocks until the render thread has completed the replace.
601 mThreadController->ReplaceSurface(&newSurface);
607 void Adaptor::DeleteSurface(Dali::RenderSurfaceInterface& surface)
609 // Flush the event queue to give the update-render thread chance
610 // to start processing messages for new camera setup etc as soon as possible
613 // This method blocks until the render thread has finished rendering the current surface.
614 mThreadController->DeleteSurface(&surface);
617 Dali::RenderSurfaceInterface& Adaptor::GetSurface() const
619 return *mWindows.front()->GetSurface();
622 void Adaptor::ReleaseSurfaceLock()
624 mWindows.front()->GetSurface()->ReleaseLock();
627 Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
629 if(!mTtsPlayers[mode])
631 // Create the TTS player when it needed, because it can reduce launching time.
632 mTtsPlayers[mode] = TtsPlayer::New(mode);
635 return mTtsPlayers[mode];
638 bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue, bool forceAdd)
640 bool idleAdded(false);
642 // Only add an idle if the Adaptor is actually running
643 if(RUNNING == mState || READY == mState || forceAdd)
645 idleAdded = mCallbackManager->AddIdleCallback(callback, hasReturnValue);
651 void Adaptor::RemoveIdle(CallbackBase* callback)
653 mCallbackManager->RemoveIdleCallback(callback);
656 void Adaptor::ProcessIdle()
658 bool idleProcessed = mCallbackManager->ProcessIdle();
659 mNotificationOnIdleInstalled = mNotificationOnIdleInstalled && !idleProcessed;
662 void Adaptor::SetPreRenderCallback(CallbackBase* callback)
664 mThreadController->SetPreRenderCallback(callback);
667 bool Adaptor::AddWindow(Dali::Integration::SceneHolder childWindow)
669 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(childWindow);
670 windowImpl.SetAdaptor(Get());
672 // ChildWindow is set to the layout direction of the default window.
673 windowImpl.GetRootLayer().SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, mRootLayoutDirection);
675 // Add the new Window to the container - the order is not important
677 Dali::Mutex::ScopedLock lock(mMutex);
678 mWindows.push_back(&windowImpl);
681 Dali::RenderSurfaceInterface* surface = windowImpl.GetSurface();
683 mThreadController->AddSurface(surface);
685 mWindowCreatedSignal.Emit(childWindow);
690 bool Adaptor::RemoveWindow(Dali::Integration::SceneHolder* childWindow)
692 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(*childWindow);
693 for(WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter)
695 if(*iter == &windowImpl)
697 Dali::Mutex::ScopedLock lock(mMutex);
698 mWindows.erase(iter);
706 bool Adaptor::RemoveWindow(std::string childWindowName)
708 for(WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter)
710 if((*iter)->GetName() == childWindowName)
712 Dali::Mutex::ScopedLock lock(mMutex);
713 mWindows.erase(iter);
721 bool Adaptor::RemoveWindow(Internal::Adaptor::SceneHolder* childWindow)
723 for(WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter)
725 if((*iter)->GetId() == childWindow->GetId())
727 Dali::Mutex::ScopedLock lock(mMutex);
728 mWindows.erase(iter);
736 Dali::Adaptor& Adaptor::Get()
738 DALI_ASSERT_ALWAYS(IsAvailable() && "Adaptor not instantiated");
739 return gThreadLocalAdaptor->mAdaptor;
742 bool Adaptor::IsAvailable()
744 return gThreadLocalAdaptor != NULL;
747 void Adaptor::SceneCreated()
749 mCore->SceneCreated();
752 Dali::Integration::Core& Adaptor::GetCore()
757 void Adaptor::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender)
759 mThreadController->SetRenderRefreshRate(numberOfVSyncsPerRender);
762 Dali::DisplayConnection& Adaptor::GetDisplayConnectionInterface()
764 DALI_ASSERT_DEBUG(mDisplayConnection && "Display connection not created");
765 return *mDisplayConnection;
768 GraphicsInterface& Adaptor::GetGraphicsInterface()
770 DALI_ASSERT_DEBUG(mGraphics && "Graphics interface not created");
771 return *(mGraphics.get());
774 Dali::Integration::PlatformAbstraction& Adaptor::GetPlatformAbstractionInterface()
776 return *mPlatformAbstraction;
779 TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
781 return *mNotificationTrigger;
784 SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
786 return mSocketFactory;
789 Dali::RenderSurfaceInterface* Adaptor::GetRenderSurfaceInterface()
791 if(!mWindows.empty())
793 return mWindows.front()->GetSurface();
799 TraceInterface& Adaptor::GetKernelTraceInterface()
801 return mKernelTracer;
804 TraceInterface& Adaptor::GetSystemTraceInterface()
806 return mSystemTracer;
809 PerformanceInterface* Adaptor::GetPerformanceInterface()
811 return mPerformanceInterface;
814 Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
816 DALI_ASSERT_DEBUG(mPlatformAbstraction && "PlatformAbstraction not created");
817 return *mPlatformAbstraction;
820 void Adaptor::GetWindowContainerInterface(WindowContainer& windows)
822 Dali::Mutex::ScopedLock lock(mMutex);
826 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
828 if(mTtsPlayers[mode])
830 mTtsPlayers[mode].Reset();
834 Any Adaptor::GetNativeWindowHandle()
836 return mWindows.front()->GetNativeHandle();
839 Any Adaptor::GetNativeWindowHandle(Dali::Actor actor)
841 Any nativeWindowHandle;
843 Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
845 for(auto sceneHolder : mWindows)
847 if(scene == sceneHolder->GetScene())
849 nativeWindowHandle = sceneHolder->GetNativeHandle();
854 return nativeWindowHandle;
857 Any Adaptor::GetGraphicsDisplay()
863 GraphicsInterface* graphics = mGraphics.get(); // This interface is temporary until Core has been updated to match
864 auto eglGraphics = static_cast<EglGraphics*>(graphics);
866 EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
867 display = eglImpl.GetDisplay();
873 void Adaptor::SetUseRemoteSurface(bool useRemoteSurface)
875 mUseRemoteSurface = useRemoteSurface;
878 void Adaptor::AddObserver(LifeCycleObserver& observer)
880 ObserverContainer::iterator match(find(mObservers.begin(), mObservers.end(), &observer));
882 if(match == mObservers.end())
884 mObservers.push_back(&observer);
888 void Adaptor::RemoveObserver(LifeCycleObserver& observer)
890 ObserverContainer::iterator match(find(mObservers.begin(), mObservers.end(), &observer));
892 if(match != mObservers.end())
894 mObservers.erase(match);
898 void Adaptor::QueueCoreEvent(const Dali::Integration::Event& event)
902 mCore->QueueEvent(event);
906 void Adaptor::ProcessCoreEvents()
910 if(mPerformanceInterface)
912 mPerformanceInterface->AddMarker(PerformanceInterface::PROCESS_EVENTS_START);
915 DALI_TRACE_BEGIN(gTraceFilter, "DALI_PROCESS_CORE_EVENTS");
917 mCore->ProcessEvents();
919 DALI_TRACE_END(gTraceFilter, "DALI_PROCESS_CORE_EVENTS");
921 if(mPerformanceInterface)
923 mPerformanceInterface->AddMarker(PerformanceInterface::PROCESS_EVENTS_END);
928 void Adaptor::RequestUpdate(bool forceUpdate)
934 mThreadController->RequestUpdate();
938 case PAUSED_WHILE_HIDDEN:
942 // Update (and resource upload) without rendering
943 mThreadController->RequestUpdateOnce(UpdateMode::SKIP_RENDER);
955 void Adaptor::RequestProcessEventsOnIdle(bool forceProcess)
957 // Only request a notification if the Adaptor is actually running
958 // and we haven't installed the idle notification
959 if((!mNotificationOnIdleInstalled) && (RUNNING == mState || READY == mState || forceProcess))
961 mNotificationOnIdleInstalled = AddIdleEnterer(MakeCallback(this, &Adaptor::ProcessCoreEventsFromIdle), forceProcess);
965 void Adaptor::OnWindowShown()
967 if(PAUSED_WHILE_HIDDEN == mState)
969 // Adaptor can now be resumed
974 // Force a render task
977 else if(RUNNING == mState)
979 // Force a render task
982 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowShown: Update requested.\n");
984 else if(PAUSED_WHILE_INITIALIZING == mState)
986 // Change the state to READY again. It will be changed to RUNNING after the adaptor is started.
991 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowShown: Adaptor is not paused state.[%d]\n", mState);
995 void Adaptor::OnWindowHidden()
997 if(RUNNING == mState || READY == mState)
999 bool allWindowsHidden = true;
1001 for(auto window : mWindows)
1003 if(window->IsVisible())
1005 allWindowsHidden = false;
1010 // Only pause the adaptor when all the windows are hidden
1011 if(allWindowsHidden)
1013 if(mState == RUNNING)
1017 // Adaptor cannot be resumed until any window is shown
1018 mState = PAUSED_WHILE_HIDDEN;
1020 else // mState is READY
1022 // Pause the adaptor after the state gets RUNNING
1023 mState = PAUSED_WHILE_INITIALIZING;
1028 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowHidden: Some windows are shown. Don't pause adaptor.\n");
1033 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowHidden: Adaptor is not running state.[%d]\n", mState);
1037 // Dali::Internal::Adaptor::Adaptor::OnDamaged
1038 void Adaptor::OnDamaged(const DamageArea& area)
1040 // This is needed for the case where Dali window is partially obscured
1041 RequestUpdate(false);
1044 void Adaptor::SurfaceResizePrepare(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize)
1046 mResizedSignal.Emit(mAdaptor);
1049 void Adaptor::SurfaceResizeComplete(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize)
1051 // Nofify surface resizing before flushing event queue
1052 mThreadController->ResizeSurface();
1054 // Flush the event queue to give the update-render thread chance
1055 // to start processing messages for new camera setup etc as soon as possible
1056 ProcessCoreEvents();
1059 void Adaptor::NotifySceneCreated()
1061 GetCore().SceneCreated();
1063 // Flush the event queue to give the update-render thread chance
1064 // to start processing messages for new camera setup etc as soon as possible
1065 ProcessCoreEvents();
1067 // Start thread controller after the scene has been created
1068 mThreadController->Start();
1070 // Process after surface is created (registering to remote surface provider if required)
1071 SurfaceInitialized();
1073 if(mState != PAUSED_WHILE_INITIALIZING)
1077 DALI_LOG_RELEASE_INFO("Adaptor::NotifySceneCreated: Adaptor is running\n");
1085 mState = PAUSED_WHILE_HIDDEN;
1087 DALI_LOG_RELEASE_INFO("Adaptor::NotifySceneCreated: Adaptor is paused\n");
1091 void Adaptor::NotifyLanguageChanged()
1093 mLanguageChangedSignal.Emit(mAdaptor);
1096 void Adaptor::RenderOnce()
1098 if(mThreadController)
1100 UpdateMode updateMode;
1101 if(mThreadMode == ThreadMode::NORMAL)
1103 updateMode = UpdateMode::NORMAL;
1107 updateMode = UpdateMode::FORCE_RENDER;
1109 ProcessCoreEvents();
1111 mThreadController->RequestUpdateOnce(updateMode);
1115 const LogFactoryInterface& Adaptor::GetLogFactory()
1117 return *mEnvironmentOptions;
1120 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
1122 GetCore().RegisterProcessor(processor, postProcessor);
1125 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
1127 GetCore().UnregisterProcessor(processor, postProcessor);
1130 bool Adaptor::IsMultipleWindowSupported() const
1132 return mConfigurationManager->IsMultipleWindowSupported();
1135 int32_t Adaptor::GetRenderThreadId() const
1137 if(mThreadController)
1139 return mThreadController->GetThreadId();
1144 void Adaptor::RequestUpdateOnce()
1146 if(mThreadController)
1148 mThreadController->RequestUpdateOnce(UpdateMode::NORMAL);
1152 bool Adaptor::ProcessCoreEventsFromIdle()
1154 ProcessCoreEvents();
1156 // the idle handle automatically un-installs itself
1157 mNotificationOnIdleInstalled = false;
1162 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow(Dali::Actor& actor)
1164 Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
1166 for(auto window : mWindows)
1168 if(scene == window->GetScene())
1177 Dali::WindowContainer Adaptor::GetWindows() const
1179 Dali::WindowContainer windows;
1181 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
1183 // Downcast to Dali::Window
1184 Dali::Window window(dynamic_cast<Dali::Internal::Adaptor::Window*>(*iter));
1187 windows.push_back(window);
1194 Dali::SceneHolderList Adaptor::GetSceneHolders() const
1196 Dali::SceneHolderList sceneHolderList;
1198 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
1200 sceneHolderList.push_back(Dali::Integration::SceneHolder(*iter));
1203 return sceneHolderList;
1206 Dali::ObjectRegistry Adaptor::GetObjectRegistry() const
1208 Dali::ObjectRegistry registry;
1211 registry = mCore->GetObjectRegistry();
1216 Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode)
1218 mLanguageChangedSignal(),
1219 mWindowCreatedSignal(),
1223 mThreadController(nullptr),
1225 mDisplayConnection(nullptr),
1227 mConfigurationManager(nullptr),
1228 mPlatformAbstraction(nullptr),
1229 mCallbackManager(nullptr),
1230 mNotificationOnIdleInstalled(false),
1231 mNotificationTrigger(nullptr),
1232 mDaliFeedbackPlugin(),
1233 mFeedbackController(nullptr),
1236 mEnvironmentOptions(environmentOptions ? environmentOptions : new EnvironmentOptions /* Create the options if not provided */),
1237 mPerformanceInterface(nullptr),
1240 mObjectProfiler(nullptr),
1243 mThreadMode(threadMode),
1244 mEnvironmentOptionsOwned(environmentOptions ? false : true /* If not provided then we own the object */),
1245 mUseRemoteSurface(false),
1246 mRootLayoutDirection(Dali::LayoutDirection::LEFT_TO_RIGHT)
1248 DALI_ASSERT_ALWAYS(!IsAvailable() && "Cannot create more than one Adaptor per thread");
1249 mWindows.insert(mWindows.begin(), &Dali::GetImplementation(window));
1251 gThreadLocalAdaptor = this;
1254 void Adaptor::SetRootLayoutDirection(std::string locale)
1256 mRootLayoutDirection = static_cast<LayoutDirection::Type>(Internal::Adaptor::Locale::GetDirection(std::string(locale)));
1257 for(auto& window : mWindows)
1259 Dali::Actor root = window->GetRootLayer();
1260 root.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, mRootLayoutDirection);
1264 bool Adaptor::AddIdleEnterer(CallbackBase* callback, bool forceAdd)
1266 bool idleAdded(false);
1268 // Only add an idle if the Adaptor is actually running
1269 if(RUNNING == mState || READY == mState || forceAdd)
1271 idleAdded = mCallbackManager->AddIdleEntererCallback(callback);
1283 void Adaptor::RemoveIdleEnterer(CallbackBase* callback)
1285 mCallbackManager->RemoveIdleEntererCallback(callback);
1288 } // namespace Adaptor
1290 } // namespace Internal