2 * Copyright (c) 2023 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/text-clipboard/common/text-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/system/common/system-factory.h>
66 #include <dali/internal/window-system/common/display-connection.h>
67 #include <dali/internal/window-system/common/display-utils.h> // For Utils::MakeUnique
68 #include <dali/internal/window-system/common/event-handler.h>
69 #include <dali/internal/window-system/common/window-impl.h>
70 #include <dali/internal/window-system/common/window-render-surface.h>
71 #include <dali/internal/window-system/common/window-system.h>
73 #include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
74 #include <dali/internal/system/common/logging.h>
76 #include <dali/internal/imaging/common/image-loader-plugin-proxy.h>
77 #include <dali/internal/imaging/common/image-loader.h>
78 #include <dali/internal/system/common/locale-utils.h>
80 #include <dali/devel-api/adaptor-framework/environment-variable.h>
81 #include <dali/internal/system/common/configuration-manager.h>
82 #include <dali/internal/system/common/environment-variables.h>
84 using Dali::TextAbstraction::FontClient;
86 extern std::string GetSystemCachePath();
96 thread_local Adaptor* gThreadLocalAdaptor = NULL; // raw thread specific pointer to allow Adaptor::Get
98 DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_PERFORMANCE_MARKER, false);
100 const char* ENABLE_IMAGE_LOADER_PLUGIN_ENV = "DALI_ENABLE_IMAGE_LOADER_PLUGIN";
101 } // unnamed namespace
103 Dali::Adaptor* Adaptor::New(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode)
105 Dali::Adaptor* adaptor = new Dali::Adaptor;
106 Adaptor* impl = new Adaptor(window, *adaptor, surface, environmentOptions, threadMode);
107 adaptor->mImpl = impl;
109 Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder = new AdaptorBuilder(*(impl->mEnvironmentOptions));
110 auto graphicsFactory = mAdaptorBuilder->GetGraphicsFactory();
112 impl->Initialize(graphicsFactory);
113 delete mAdaptorBuilder; // Not needed anymore as the graphics interface has now been created
118 Dali::Adaptor* Adaptor::New(Dali::Integration::SceneHolder window, EnvironmentOptions* environmentOptions)
120 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(window);
121 Dali::Adaptor* adaptor = New(window, windowImpl.GetSurface(), environmentOptions, ThreadMode::NORMAL);
122 windowImpl.SetAdaptor(*adaptor);
126 Dali::Adaptor* Adaptor::New(GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode)
128 Dali::Adaptor* adaptor = new Dali::Adaptor; // Public adaptor
129 Adaptor* impl = new Adaptor(window, *adaptor, surface, environmentOptions, threadMode); // Impl adaptor
130 adaptor->mImpl = impl;
132 impl->Initialize(graphicsFactory);
137 Dali::Adaptor* Adaptor::New(GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, EnvironmentOptions* environmentOptions)
139 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(window);
140 Dali::Adaptor* adaptor = New(graphicsFactory, window, windowImpl.GetSurface(), environmentOptions, ThreadMode::NORMAL);
141 windowImpl.SetAdaptor(*adaptor);
145 void Adaptor::Initialize(GraphicsFactory& graphicsFactory)
147 // all threads here (event, update, and render) will send their logs to TIZEN Platform's LogMessage handler.
148 Dali::Integration::Log::LogFunction logFunction(Dali::TizenPlatform::LogMessage);
149 mEnvironmentOptions->SetLogFunction(logFunction);
150 mEnvironmentOptions->InstallLogFunction(); // install logging for main thread
152 mPlatformAbstraction = new TizenPlatform::TizenPlatformAbstraction;
155 GetDataStoragePath(path);
156 mPlatformAbstraction->SetDataStoragePath(path);
158 if(mEnvironmentOptions->PerformanceServerRequired())
160 mPerformanceInterface = PerformanceInterfaceFactory::CreateInterface(*this, *mEnvironmentOptions);
163 mEnvironmentOptions->CreateTraceManager(mPerformanceInterface);
164 mEnvironmentOptions->InstallTraceFunction(); // install tracing for main thread
166 mCallbackManager = Dali::Internal::Adaptor::GetSystemFactory()->CreateCallbackManager();
168 Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
170 DALI_ASSERT_DEBUG(defaultWindow->GetSurface() && "Surface not initialized");
172 mGraphics = std::unique_ptr<GraphicsInterface>(&graphicsFactory.Create());
174 // Create the AddOnManager
175 mAddOnManager.reset(Dali::Internal::AddOnManagerFactory::CreateAddOnManager());
177 mCore = Integration::Core::New(*this,
178 *mPlatformAbstraction,
179 mGraphics->GetController(),
180 (0u != mEnvironmentOptions->GetRenderToFboInterval()) ? Integration::RenderToFrameBuffer::TRUE : Integration::RenderToFrameBuffer::FALSE,
181 mGraphics->GetDepthBufferRequired(),
182 mGraphics->GetStencilBufferRequired(),
183 mGraphics->GetPartialUpdateRequired());
185 defaultWindow->SetAdaptor(Get());
187 Dali::Integration::SceneHolder defaultSceneHolder(defaultWindow);
189 mWindowCreatedSignal.Emit(defaultSceneHolder);
191 const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval();
192 if(0u < timeInterval)
194 mObjectProfiler = new ObjectProfiler(mCore->GetObjectRegistry(), timeInterval);
197 const uint32_t poolTimeInterval = mEnvironmentOptions->GetMemoryPoolInterval();
198 if(0u < poolTimeInterval)
200 mMemoryPoolTimer = Dali::Timer::New(poolTimeInterval * 1000);
201 mMemoryPoolTimer.TickSignal().Connect(mMemoryPoolTimerSlotDelegate, &Adaptor::MemoryPoolTimeout);
202 mMemoryPoolTimer.Start();
205 mNotificationTrigger = TriggerEventFactory::CreateTriggerEvent(MakeCallback(this, &Adaptor::ProcessCoreEvents), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
207 mDisplayConnection = Dali::DisplayConnection::New(*mGraphics, defaultWindow->GetSurface()->GetSurfaceType());
209 mThreadController = new ThreadController(*this, *mEnvironmentOptions, mThreadMode);
211 // Should be called after Core creation
212 if(mEnvironmentOptions->GetPanGestureLoggingLevel())
214 Integration::EnableProfiling(Dali::Integration::PROFILING_TYPE_PAN_GESTURE);
216 if(mEnvironmentOptions->GetPanGesturePredictionMode() >= 0)
218 Integration::SetPanGesturePredictionMode(mEnvironmentOptions->GetPanGesturePredictionMode());
220 if(mEnvironmentOptions->GetPanGesturePredictionAmount() >= 0)
222 Integration::SetPanGesturePredictionAmount(mEnvironmentOptions->GetPanGesturePredictionAmount());
224 if(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount() >= 0)
226 Integration::SetPanGestureMaximumPredictionAmount(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount());
228 if(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount() >= 0)
230 Integration::SetPanGestureMinimumPredictionAmount(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount());
232 if(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment() >= 0)
234 Integration::SetPanGesturePredictionAmountAdjustment(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment());
236 if(mEnvironmentOptions->GetPanGestureSmoothingMode() >= 0)
238 Integration::SetPanGestureSmoothingMode(mEnvironmentOptions->GetPanGestureSmoothingMode());
240 if(mEnvironmentOptions->GetPanGestureSmoothingAmount() >= 0.0f)
242 Integration::SetPanGestureSmoothingAmount(mEnvironmentOptions->GetPanGestureSmoothingAmount());
244 if(mEnvironmentOptions->GetPanGestureUseActualTimes() >= 0)
246 Integration::SetPanGestureUseActualTimes(mEnvironmentOptions->GetPanGestureUseActualTimes() == 0 ? true : false);
248 if(mEnvironmentOptions->GetPanGestureInterpolationTimeRange() >= 0)
250 Integration::SetPanGestureInterpolationTimeRange(mEnvironmentOptions->GetPanGestureInterpolationTimeRange());
252 if(mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() >= 0)
254 Integration::SetPanGestureScalarOnlyPredictionEnabled(mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() == 0 ? true : false);
256 if(mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() >= 0)
258 Integration::SetPanGestureTwoPointPredictionEnabled(mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() == 0 ? true : false);
260 if(mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() >= 0)
262 Integration::SetPanGestureTwoPointInterpolatePastTime(mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime());
264 if(mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() >= 0.0f)
266 Integration::SetPanGestureTwoPointVelocityBias(mEnvironmentOptions->GetPanGestureTwoPointVelocityBias());
268 if(mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() >= 0.0f)
270 Integration::SetPanGestureTwoPointAccelerationBias(mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias());
272 if(mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() >= 0)
274 Integration::SetPanGestureMultitapSmoothingRange(mEnvironmentOptions->GetPanGestureMultitapSmoothingRange());
276 if(mEnvironmentOptions->GetMinimumPanDistance() >= 0)
278 Integration::SetPanGestureMinimumDistance(mEnvironmentOptions->GetMinimumPanDistance());
280 if(mEnvironmentOptions->GetMinimumPanEvents() >= 0)
282 Integration::SetPanGestureMinimumPanEvents(mEnvironmentOptions->GetMinimumPanEvents());
284 if(mEnvironmentOptions->GetMinimumPinchDistance() >= 0)
286 Integration::SetPinchGestureMinimumDistance(mEnvironmentOptions->GetMinimumPinchDistance());
288 if(mEnvironmentOptions->GetMinimumPinchTouchEvents() >= 0)
290 Integration::SetPinchGestureMinimumTouchEvents(mEnvironmentOptions->GetMinimumPinchTouchEvents());
292 if(mEnvironmentOptions->GetMinimumPinchTouchEventsAfterStart() >= 0)
294 Integration::SetPinchGestureMinimumTouchEventsAfterStart(mEnvironmentOptions->GetMinimumPinchTouchEventsAfterStart());
296 if(mEnvironmentOptions->GetMinimumRotationTouchEvents() >= 0)
298 Integration::SetRotationGestureMinimumTouchEvents(mEnvironmentOptions->GetMinimumRotationTouchEvents());
300 if(mEnvironmentOptions->GetMinimumRotationTouchEventsAfterStart() >= 0)
302 Integration::SetRotationGestureMinimumTouchEventsAfterStart(mEnvironmentOptions->GetMinimumRotationTouchEventsAfterStart());
304 if(mEnvironmentOptions->GetLongPressMinimumHoldingTime() >= 0)
306 Integration::SetLongPressMinimumHoldingTime(mEnvironmentOptions->GetLongPressMinimumHoldingTime());
308 if(mEnvironmentOptions->GetTapMaximumAllowedTime() > 0)
310 Integration::SetTapMaximumAllowedTime(mEnvironmentOptions->GetTapMaximumAllowedTime());
313 std::string systemCachePath = GetSystemCachePath();
314 if(!systemCachePath.empty())
316 const int dir_err = mkdir(systemCachePath.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
317 if(0 != dir_err && errno != EEXIST)
319 DALI_LOG_ERROR("Error creating system cache directory: %s!\n", systemCachePath.c_str());
323 mConfigurationManager = Utils::MakeUnique<ConfigurationManager>(systemCachePath, mGraphics.get(), mThreadController);
326 void Adaptor::AccessibilityObserver::OnAccessibleKeyEvent(const Dali::KeyEvent& event)
328 Accessibility::KeyEventType type;
329 if(event.GetState() == Dali::KeyEvent::DOWN)
331 type = Accessibility::KeyEventType::KEY_PRESSED;
333 else if(event.GetState() == Dali::KeyEvent::UP)
335 type = Accessibility::KeyEventType::KEY_RELEASED;
341 Dali::Accessibility::Bridge::GetCurrentBridge()->Emit(type, event.GetKeyCode(), event.GetKeyName(), event.GetTime(), !event.GetKeyString().empty());
346 Accessibility::Bridge::GetCurrentBridge()->Terminate();
348 // Ensure stop status
351 // set to NULL first as we do not want any access to Adaptor as it is being destroyed.
352 gThreadLocalAdaptor = NULL;
354 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
356 (*iter)->OnDestroy();
359 // Clear out all the handles to Windows
362 delete mThreadController; // this will shutdown render thread, which will call Core::ContextDestroyed before exit
363 delete mObjectProfiler;
367 delete mDisplayConnection;
368 delete mPlatformAbstraction;
370 mCallbackManager.reset();
372 delete mPerformanceInterface;
374 mGraphics->Destroy();
376 // uninstall it on this thread (main actor thread)
377 Dali::Integration::Log::UninstallLogFunction();
379 // Delete environment options if we own it
380 if(mEnvironmentOptionsOwned)
382 delete mEnvironmentOptions;
386 void Adaptor::Start()
388 // It doesn't support restart after stop at this moment to support restarting, need more testing
396 SetupSystemInformation();
398 // Start the callback manager
399 mCallbackManager->Start();
401 // Initialize accessibility bridge after callback manager is started to use Idler callback
402 auto appName = GetApplicationPackageName();
403 auto bridge = Accessibility::Bridge::GetCurrentBridge();
404 bridge->SetApplicationName(appName);
405 bridge->Initialize();
406 Dali::Stage::GetCurrent().KeyEventSignal().Connect(&mAccessibilityObserver, &AccessibilityObserver::OnAccessibleKeyEvent);
408 Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
410 unsigned int dpiHor, dpiVer;
413 defaultWindow->GetSurface()->GetDpi(dpiHor, dpiVer);
414 Dali::Internal::Adaptor::WindowSystem::SetDpi(dpiHor, dpiVer);
416 // Initialize the thread controller
417 mThreadController->Initialize();
419 // Set max texture size
420 if(mEnvironmentOptions->GetMaxTextureSize() > 0)
422 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize(mEnvironmentOptions->GetMaxTextureSize());
426 unsigned int maxTextureSize = mConfigurationManager->GetMaxTextureSize();
427 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize(maxTextureSize);
430 // cache advanced blending and shader language version
431 mGraphics->CacheConfigurations(*mConfigurationManager.get());
433 ProcessCoreEvents(); // Ensure any startup messages are processed.
435 // Initialize the image loader plugin
436 auto enablePluginString = Dali::EnvironmentVariable::GetEnvironmentVariable(ENABLE_IMAGE_LOADER_PLUGIN_ENV);
437 bool enablePlugin = enablePluginString ? std::atoi(enablePluginString) : false;
440 Internal::Adaptor::ImageLoaderPluginProxy::Initialize();
443 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
450 mAddOnManager->Start();
454 // Dali::Internal::Adaptor::Adaptor::Pause
455 void Adaptor::Pause()
457 // Only pause the adaptor if we're actually running.
458 if(RUNNING == mState)
460 // Inform observers that we are about to be paused.
461 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
469 mAddOnManager->Pause();
472 // Pause all windows event handlers when adaptor paused
473 for(auto window : mWindows)
478 mThreadController->Pause();
481 // Ensure any messages queued during pause callbacks are processed by doing another update.
484 DALI_LOG_RELEASE_INFO("Adaptor::Pause: Paused\n");
488 DALI_LOG_RELEASE_INFO("Adaptor::Pause: Not paused [%d]\n", mState);
492 // Dali::Internal::Adaptor::Adaptor::Resume
493 void Adaptor::Resume()
495 // Only resume the adaptor if we are in the suspended state.
500 // Reset the event handlers when adaptor resumed
501 for(auto window : mWindows)
506 // Resume AddOnManager
509 mAddOnManager->Resume();
512 // Inform observers that we have resumed.
513 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
518 // Trigger processing of events queued up while paused
519 mCore->ProcessEvents();
521 // Do at end to ensure our first update/render after resumption includes the processed messages as well
522 mThreadController->Resume();
524 DALI_LOG_RELEASE_INFO("Adaptor::Resume: Resumed\n");
528 DALI_LOG_RELEASE_INFO("Adaptor::Resume: Not resumed [%d]\n", mState);
534 if(RUNNING == mState ||
536 PAUSED_WHILE_HIDDEN == mState)
538 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
545 mAddOnManager->Stop();
548 mThreadController->Stop();
550 // Delete the TTS player
551 for(int i = 0; i < Dali::TtsPlayer::MODE_NUM; i++)
555 mTtsPlayers[i].Reset();
559 // Destroy the image loader plugin
560 auto enablePluginString = Dali::EnvironmentVariable::GetEnvironmentVariable(ENABLE_IMAGE_LOADER_PLUGIN_ENV);
561 bool enablePlugin = enablePluginString ? std::atoi(enablePluginString) : false;
564 Internal::Adaptor::ImageLoaderPluginProxy::Destroy();
567 delete mNotificationTrigger;
568 mNotificationTrigger = NULL;
570 mCallbackManager->Stop();
574 DALI_LOG_RELEASE_INFO("Adaptor::Stop\n");
578 void Adaptor::ContextLost()
580 mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage
583 void Adaptor::ContextRegained()
585 // Inform core, so that texture resources can be reloaded
586 mCore->RecoverFromContextLoss();
588 mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage
591 void Adaptor::FeedTouchPoint(TouchPoint& point, int timeStamp)
593 Integration::Point convertedPoint(point);
594 mWindows.front()->FeedTouchPoint(convertedPoint, timeStamp);
597 void Adaptor::FeedWheelEvent(Dali::WheelEvent& wheelEvent)
599 Integration::WheelEvent event(static_cast<Integration::WheelEvent::Type>(wheelEvent.GetType()), wheelEvent.GetDirection(), wheelEvent.GetModifiers(), wheelEvent.GetPoint(), wheelEvent.GetDelta(), wheelEvent.GetTime());
600 mWindows.front()->FeedWheelEvent(event);
603 void Adaptor::FeedKeyEvent(Dali::KeyEvent& keyEvent)
605 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());
606 mWindows.front()->FeedKeyEvent(convertedEvent);
609 void Adaptor::ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& newSurface)
611 Internal::Adaptor::SceneHolder* windowImpl = &Dali::GetImplementation(window);
612 for(auto windowPtr : mWindows)
614 if(windowPtr == windowImpl) // the window is not deleted
616 mResizedSignal.Emit(mAdaptor);
618 windowImpl->SetSurface(&newSurface);
620 // Flush the event queue to give the update-render thread chance
621 // to start processing messages for new camera setup etc as soon as possible
624 // This method blocks until the render thread has completed the replace.
625 mThreadController->ReplaceSurface(&newSurface);
631 void Adaptor::DeleteSurface(Dali::RenderSurfaceInterface& surface)
633 // Flush the event queue to give the update-render thread chance
634 // to start processing messages for new camera setup etc as soon as possible
637 // This method blocks until the render thread has finished rendering the current surface.
638 mThreadController->DeleteSurface(&surface);
641 Dali::RenderSurfaceInterface& Adaptor::GetSurface() const
643 return *mWindows.front()->GetSurface();
646 void Adaptor::ReleaseSurfaceLock()
648 mWindows.front()->GetSurface()->ReleaseLock();
651 Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
653 if(!mTtsPlayers[mode])
655 // Create the TTS player when it needed, because it can reduce launching time.
656 mTtsPlayers[mode] = TtsPlayer::New(mode);
659 return mTtsPlayers[mode];
662 bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue, bool forceAdd)
664 bool idleAdded(false);
666 // Only add an idle if the Adaptor is actually running
667 if(RUNNING == mState || READY == mState || forceAdd)
669 idleAdded = mCallbackManager->AddIdleCallback(callback, hasReturnValue);
675 void Adaptor::RemoveIdle(CallbackBase* callback)
677 mCallbackManager->RemoveIdleCallback(callback);
680 void Adaptor::ProcessIdle()
682 bool idleProcessed = mCallbackManager->ProcessIdle();
683 mNotificationOnIdleInstalled = mNotificationOnIdleInstalled && !idleProcessed;
686 void Adaptor::SetPreRenderCallback(CallbackBase* callback)
688 mThreadController->SetPreRenderCallback(callback);
691 bool Adaptor::AddWindow(Dali::Integration::SceneHolder childWindow)
693 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(childWindow);
694 windowImpl.SetAdaptor(Get());
696 // ChildWindow is set to the layout direction of the default window.
697 windowImpl.GetRootLayer().SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, mRootLayoutDirection);
699 // Add the new Window to the container - the order is not important
701 Dali::Mutex::ScopedLock lock(mMutex);
702 mWindows.push_back(&windowImpl);
705 Dali::RenderSurfaceInterface* surface = windowImpl.GetSurface();
707 mThreadController->AddSurface(surface);
709 mWindowCreatedSignal.Emit(childWindow);
714 bool Adaptor::RemoveWindow(Dali::Integration::SceneHolder* childWindow)
716 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(*childWindow);
717 for(WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter)
719 if(*iter == &windowImpl)
721 Dali::Mutex::ScopedLock lock(mMutex);
722 mWindows.erase(iter);
730 bool Adaptor::RemoveWindow(std::string childWindowName)
732 for(WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter)
734 if((*iter)->GetName() == childWindowName)
736 Dali::Mutex::ScopedLock lock(mMutex);
737 mWindows.erase(iter);
745 bool Adaptor::RemoveWindow(Internal::Adaptor::SceneHolder* childWindow)
747 for(WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter)
749 if((*iter)->GetId() == childWindow->GetId())
751 Dali::Mutex::ScopedLock lock(mMutex);
752 mWindows.erase(iter);
760 Dali::Adaptor& Adaptor::Get()
762 DALI_ASSERT_ALWAYS(IsAvailable() && "Adaptor not instantiated");
763 return gThreadLocalAdaptor->mAdaptor;
766 bool Adaptor::IsAvailable()
768 return gThreadLocalAdaptor != NULL;
771 void Adaptor::SceneCreated()
773 mCore->SceneCreated();
776 Dali::Integration::Core& Adaptor::GetCore()
781 void Adaptor::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender)
783 mThreadController->SetRenderRefreshRate(numberOfVSyncsPerRender);
786 Dali::DisplayConnection& Adaptor::GetDisplayConnectionInterface()
788 DALI_ASSERT_DEBUG(mDisplayConnection && "Display connection not created");
789 return *mDisplayConnection;
792 GraphicsInterface& Adaptor::GetGraphicsInterface()
794 DALI_ASSERT_DEBUG(mGraphics && "Graphics interface not created");
795 return *(mGraphics.get());
798 Dali::Integration::PlatformAbstraction& Adaptor::GetPlatformAbstractionInterface()
800 return *mPlatformAbstraction;
803 TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
805 return *mNotificationTrigger;
808 SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
810 return mSocketFactory;
813 Dali::RenderSurfaceInterface* Adaptor::GetRenderSurfaceInterface()
815 if(!mWindows.empty())
817 return mWindows.front()->GetSurface();
823 TraceInterface& Adaptor::GetKernelTraceInterface()
825 return mKernelTracer;
828 TraceInterface& Adaptor::GetSystemTraceInterface()
830 return mSystemTracer;
833 PerformanceInterface* Adaptor::GetPerformanceInterface()
835 return mPerformanceInterface;
838 Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
840 DALI_ASSERT_DEBUG(mPlatformAbstraction && "PlatformAbstraction not created");
841 return *mPlatformAbstraction;
844 void Adaptor::GetWindowContainerInterface(WindowContainer& windows)
846 Dali::Mutex::ScopedLock lock(mMutex);
850 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
852 if(mTtsPlayers[mode])
854 mTtsPlayers[mode].Reset();
858 Any Adaptor::GetNativeWindowHandle()
860 return mWindows.front()->GetNativeHandle();
863 Any Adaptor::GetNativeWindowHandle(Dali::Actor actor)
865 Any nativeWindowHandle;
867 Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
869 for(auto sceneHolder : mWindows)
871 if(scene == sceneHolder->GetScene())
873 nativeWindowHandle = sceneHolder->GetNativeHandle();
878 return nativeWindowHandle;
881 Any Adaptor::GetGraphicsDisplay()
887 GraphicsInterface* graphics = mGraphics.get(); // This interface is temporary until Core has been updated to match
888 auto eglGraphics = static_cast<EglGraphics*>(graphics);
890 EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
891 display = eglImpl.GetDisplay();
897 void Adaptor::SetUseRemoteSurface(bool useRemoteSurface)
899 mUseRemoteSurface = useRemoteSurface;
902 void Adaptor::AddObserver(LifeCycleObserver& observer)
904 ObserverContainer::iterator match(find(mObservers.begin(), mObservers.end(), &observer));
906 if(match == mObservers.end())
908 mObservers.push_back(&observer);
912 void Adaptor::RemoveObserver(LifeCycleObserver& observer)
914 ObserverContainer::iterator match(find(mObservers.begin(), mObservers.end(), &observer));
916 if(match != mObservers.end())
918 mObservers.erase(match);
922 void Adaptor::QueueCoreEvent(const Dali::Integration::Event& event)
926 mCore->QueueEvent(event);
930 void Adaptor::ProcessCoreEvents()
934 DALI_TRACE_SCOPE(gTraceFilter, "DALI_PROCESS_CORE_EVENTS");
936 if(mPerformanceInterface)
938 mPerformanceInterface->AddMarker(PerformanceInterface::PROCESS_EVENTS_START);
941 mCore->ProcessEvents();
943 if(mPerformanceInterface)
945 mPerformanceInterface->AddMarker(PerformanceInterface::PROCESS_EVENTS_END);
950 void Adaptor::RequestUpdate()
956 mThreadController->RequestUpdate();
960 case PAUSED_WHILE_HIDDEN:
962 // Update (and resource upload) without rendering
963 mThreadController->RequestUpdateOnce(UpdateMode::SKIP_RENDER);
974 void Adaptor::RequestProcessEventsOnIdle()
976 // Only request a notification if we haven't installed the idle notification
977 // We want to run the processes even when paused
978 if(!mNotificationOnIdleInstalled && STOPPED != mState)
980 mNotificationOnIdleInstalled = AddIdleEnterer(MakeCallback(this, &Adaptor::ProcessCoreEventsFromIdle), true);
984 void Adaptor::OnWindowShown()
986 if(PAUSED_WHILE_HIDDEN == mState)
988 // Adaptor can now be resumed
993 // Force a render task
996 else if(RUNNING == mState)
998 // Force a render task
1001 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowShown: Update requested.\n");
1003 else if(PAUSED_WHILE_INITIALIZING == mState)
1005 // Change the state to READY again. It will be changed to RUNNING after the adaptor is started.
1010 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowShown: Adaptor is not paused state.[%d]\n", mState);
1014 void Adaptor::OnWindowHidden()
1016 if(RUNNING == mState || READY == mState)
1018 bool allWindowsHidden = true;
1020 for(auto window : mWindows)
1022 if(window->IsVisible())
1024 allWindowsHidden = false;
1029 // Only pause the adaptor when all the windows are hidden
1030 if(allWindowsHidden)
1032 if(mState == RUNNING)
1036 // Adaptor cannot be resumed until any window is shown
1037 mState = PAUSED_WHILE_HIDDEN;
1039 else // mState is READY
1041 // Pause the adaptor after the state gets RUNNING
1042 mState = PAUSED_WHILE_INITIALIZING;
1047 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowHidden: Some windows are shown. Don't pause adaptor.\n");
1052 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowHidden: Adaptor is not running state.[%d]\n", mState);
1056 // Dali::Internal::Adaptor::Adaptor::OnDamaged
1057 void Adaptor::OnDamaged(const DamageArea& area)
1059 // This is needed for the case where Dali window is partially obscured
1063 void Adaptor::SurfaceResizePrepare(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize)
1065 mResizedSignal.Emit(mAdaptor);
1068 void Adaptor::SurfaceResizeComplete(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize)
1070 // Nofify surface resizing before flushing event queue
1071 mThreadController->ResizeSurface();
1073 // Flush the event queue to give the update-render thread chance
1074 // to start processing messages for new camera setup etc as soon as possible
1075 ProcessCoreEvents();
1078 void Adaptor::NotifySceneCreated()
1080 GetCore().SceneCreated();
1082 // Flush the event queue to give the update-render thread chance
1083 // to start processing messages for new camera setup etc as soon as possible
1084 ProcessCoreEvents();
1086 // Start thread controller after the scene has been created
1087 mThreadController->Start();
1089 // Process after surface is created (registering to remote surface provider if required)
1090 SurfaceInitialized();
1092 if(mState != PAUSED_WHILE_INITIALIZING)
1096 DALI_LOG_RELEASE_INFO("Adaptor::NotifySceneCreated: Adaptor is running\n");
1104 mState = PAUSED_WHILE_HIDDEN;
1106 DALI_LOG_RELEASE_INFO("Adaptor::NotifySceneCreated: Adaptor is paused\n");
1110 void Adaptor::NotifyLanguageChanged()
1112 mLanguageChangedSignal.Emit(mAdaptor);
1115 void Adaptor::RenderOnce()
1117 if(mThreadController)
1119 UpdateMode updateMode;
1120 if(mThreadMode == ThreadMode::NORMAL)
1122 updateMode = UpdateMode::NORMAL;
1126 updateMode = UpdateMode::FORCE_RENDER;
1128 ProcessCoreEvents();
1130 mThreadController->RequestUpdateOnce(updateMode);
1134 const LogFactoryInterface& Adaptor::GetLogFactory()
1136 return *mEnvironmentOptions;
1139 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
1141 GetCore().RegisterProcessor(processor, postProcessor);
1144 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
1146 GetCore().UnregisterProcessor(processor, postProcessor);
1149 bool Adaptor::IsMultipleWindowSupported() const
1151 return mConfigurationManager->IsMultipleWindowSupported();
1154 int32_t Adaptor::GetRenderThreadId() const
1156 if(mThreadController)
1158 return mThreadController->GetThreadId();
1163 void Adaptor::RequestUpdateOnce()
1165 if(mThreadController)
1167 mThreadController->RequestUpdateOnce(UpdateMode::NORMAL);
1171 bool Adaptor::ProcessCoreEventsFromIdle()
1173 ProcessCoreEvents();
1175 // the idle handle automatically un-installs itself
1176 mNotificationOnIdleInstalled = false;
1181 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow(Dali::Actor& actor)
1183 Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
1185 for(auto window : mWindows)
1187 if(scene == window->GetScene())
1196 Dali::WindowContainer Adaptor::GetWindows() const
1198 Dali::WindowContainer windows;
1200 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
1202 // Downcast to Dali::Window
1203 Dali::Window window(dynamic_cast<Dali::Internal::Adaptor::Window*>(*iter));
1206 windows.push_back(window);
1213 Dali::SceneHolderList Adaptor::GetSceneHolders() const
1215 Dali::SceneHolderList sceneHolderList;
1217 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
1219 sceneHolderList.push_back(Dali::Integration::SceneHolder(*iter));
1222 return sceneHolderList;
1225 Dali::ObjectRegistry Adaptor::GetObjectRegistry() const
1227 Dali::ObjectRegistry registry;
1230 registry = mCore->GetObjectRegistry();
1235 Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode)
1237 mLanguageChangedSignal(),
1238 mWindowCreatedSignal(),
1242 mThreadController(nullptr),
1244 mDisplayConnection(nullptr),
1246 mConfigurationManager(nullptr),
1247 mPlatformAbstraction(nullptr),
1248 mCallbackManager(nullptr),
1249 mNotificationOnIdleInstalled(false),
1250 mNotificationTrigger(nullptr),
1251 mDaliFeedbackPlugin(),
1252 mFeedbackController(nullptr),
1255 mEnvironmentOptions(environmentOptions ? environmentOptions : new EnvironmentOptions /* Create the options if not provided */),
1256 mPerformanceInterface(nullptr),
1259 mObjectProfiler(nullptr),
1260 mMemoryPoolTimerSlotDelegate(this),
1263 mThreadMode(threadMode),
1264 mEnvironmentOptionsOwned(environmentOptions ? false : true /* If not provided then we own the object */),
1265 mUseRemoteSurface(false),
1266 mRootLayoutDirection(Dali::LayoutDirection::LEFT_TO_RIGHT)
1268 DALI_ASSERT_ALWAYS(!IsAvailable() && "Cannot create more than one Adaptor per thread");
1269 mWindows.insert(mWindows.begin(), &Dali::GetImplementation(window));
1271 gThreadLocalAdaptor = this;
1274 void Adaptor::SetRootLayoutDirection(std::string locale)
1276 mRootLayoutDirection = static_cast<LayoutDirection::Type>(Internal::Adaptor::Locale::GetDirection(std::string(locale)));
1277 for(auto& window : mWindows)
1279 Dali::Actor root = window->GetRootLayer();
1280 root.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, mRootLayoutDirection);
1284 bool Adaptor::AddIdleEnterer(CallbackBase* callback, bool forceAdd)
1286 bool idleAdded(false);
1288 // Only add an idle if the Adaptor is actually running
1289 if(RUNNING == mState || READY == mState || forceAdd)
1291 idleAdded = mCallbackManager->AddIdleEntererCallback(callback);
1303 void Adaptor::RemoveIdleEnterer(CallbackBase* callback)
1305 mCallbackManager->RemoveIdleEntererCallback(callback);
1308 bool Adaptor::MemoryPoolTimeout()
1310 mCore->LogMemoryPools();
1311 return true; // Keep logging forever
1314 } // namespace Adaptor
1316 } // namespace Internal