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/graphics/common/egl-image-extensions.h>
59 #include <dali/internal/graphics/gles/egl-sync-implementation.h>
60 #include <dali/internal/graphics/gles/gl-implementation.h>
61 #include <dali/internal/graphics/gles/gl-proxy-implementation.h>
62 #include <dali/internal/system/common/callback-manager.h>
63 #include <dali/internal/system/common/object-profiler.h>
64 #include <dali/internal/system/common/system-factory.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/devel-api/adaptor-framework/environment-variable.h>
80 #include <dali/internal/system/common/configuration-manager.h>
81 #include <dali/internal/system/common/environment-variables.h>
83 using Dali::TextAbstraction::FontClient;
85 extern std::string GetSystemCachePath();
95 thread_local Adaptor* gThreadLocalAdaptor = NULL; // raw thread specific pointer to allow Adaptor::Get
97 DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_PERFORMANCE_MARKER, false);
99 const char* ENABLE_IMAGE_LOADER_PLUGIN_ENV = "DALI_ENABLE_IMAGE_LOADER_PLUGIN";
100 } // unnamed namespace
102 Dali::Adaptor* Adaptor::New(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode)
104 Dali::Adaptor* adaptor = new Dali::Adaptor;
105 Adaptor* impl = new Adaptor(window, *adaptor, surface, environmentOptions, threadMode);
106 adaptor->mImpl = impl;
108 Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder = new AdaptorBuilder(*(impl->mEnvironmentOptions));
109 auto graphicsFactory = mAdaptorBuilder->GetGraphicsFactory();
111 impl->Initialize(graphicsFactory);
112 delete mAdaptorBuilder; // Not needed anymore as the graphics interface has now been created
117 Dali::Adaptor* Adaptor::New(Dali::Integration::SceneHolder window, EnvironmentOptions* environmentOptions)
119 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(window);
120 Dali::Adaptor* adaptor = New(window, windowImpl.GetSurface(), environmentOptions, ThreadMode::NORMAL);
121 windowImpl.SetAdaptor(*adaptor);
125 Dali::Adaptor* Adaptor::New(GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode)
127 Dali::Adaptor* adaptor = new Dali::Adaptor; // Public adaptor
128 Adaptor* impl = new Adaptor(window, *adaptor, surface, environmentOptions, threadMode); // Impl adaptor
129 adaptor->mImpl = impl;
131 impl->Initialize(graphicsFactory);
136 Dali::Adaptor* Adaptor::New(GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, EnvironmentOptions* environmentOptions)
138 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(window);
139 Dali::Adaptor* adaptor = New(graphicsFactory, window, windowImpl.GetSurface(), environmentOptions, ThreadMode::NORMAL);
140 windowImpl.SetAdaptor(*adaptor);
144 void Adaptor::Initialize(GraphicsFactory& graphicsFactory)
146 // all threads here (event, update, and render) will send their logs to TIZEN Platform's LogMessage handler.
147 Dali::Integration::Log::LogFunction logFunction(Dali::TizenPlatform::LogMessage);
148 mEnvironmentOptions->SetLogFunction(logFunction);
149 mEnvironmentOptions->InstallLogFunction(); // install logging for main thread
151 mPlatformAbstraction = new TizenPlatform::TizenPlatformAbstraction;
154 GetDataStoragePath(path);
155 mPlatformAbstraction->SetDataStoragePath(path);
157 if(mEnvironmentOptions->PerformanceServerRequired())
159 mPerformanceInterface = PerformanceInterfaceFactory::CreateInterface(*this, *mEnvironmentOptions);
162 mEnvironmentOptions->CreateTraceManager(mPerformanceInterface);
163 mEnvironmentOptions->InstallTraceFunction(); // install tracing for main thread
165 mCallbackManager = Dali::Internal::Adaptor::GetSystemFactory()->CreateCallbackManager();
167 Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
169 DALI_ASSERT_DEBUG(defaultWindow->GetSurface() && "Surface not initialized");
171 mGraphics = std::unique_ptr<GraphicsInterface>(&graphicsFactory.Create());
173 // Create the AddOnManager
174 mAddOnManager.reset(Dali::Internal::AddOnManagerFactory::CreateAddOnManager());
176 mCore = Integration::Core::New(*this,
177 *mPlatformAbstraction,
178 mGraphics->GetController(),
179 (0u != mEnvironmentOptions->GetRenderToFboInterval()) ? Integration::RenderToFrameBuffer::TRUE : Integration::RenderToFrameBuffer::FALSE,
180 mGraphics->GetDepthBufferRequired(),
181 mGraphics->GetStencilBufferRequired(),
182 mGraphics->GetPartialUpdateRequired());
184 defaultWindow->SetAdaptor(Get());
186 Dali::Integration::SceneHolder defaultSceneHolder(defaultWindow);
188 mWindowCreatedSignal.Emit(defaultSceneHolder);
190 const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval();
191 if(0u < timeInterval)
193 mObjectProfiler = new ObjectProfiler(mCore->GetObjectRegistry(), timeInterval);
196 const uint32_t poolTimeInterval = mEnvironmentOptions->GetMemoryPoolInterval();
197 if(0u < poolTimeInterval)
199 mMemoryPoolTimer = Dali::Timer::New(poolTimeInterval * 1000);
200 mMemoryPoolTimer.TickSignal().Connect(mMemoryPoolTimerSlotDelegate, &Adaptor::MemoryPoolTimeout);
201 mMemoryPoolTimer.Start();
204 mNotificationTrigger = TriggerEventFactory::CreateTriggerEvent(MakeCallback(this, &Adaptor::ProcessCoreEvents), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
206 mDisplayConnection = Dali::DisplayConnection::New(*mGraphics, defaultWindow->GetSurface()->GetSurfaceType());
208 mThreadController = new ThreadController(*this, *mEnvironmentOptions, mThreadMode);
210 // Should be called after Core creation
211 if(mEnvironmentOptions->GetPanGestureLoggingLevel())
213 Integration::EnableProfiling(Dali::Integration::PROFILING_TYPE_PAN_GESTURE);
215 if(mEnvironmentOptions->GetPanGesturePredictionMode() >= 0)
217 Integration::SetPanGesturePredictionMode(mEnvironmentOptions->GetPanGesturePredictionMode());
219 if(mEnvironmentOptions->GetPanGesturePredictionAmount() >= 0)
221 Integration::SetPanGesturePredictionAmount(mEnvironmentOptions->GetPanGesturePredictionAmount());
223 if(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount() >= 0)
225 Integration::SetPanGestureMaximumPredictionAmount(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount());
227 if(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount() >= 0)
229 Integration::SetPanGestureMinimumPredictionAmount(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount());
231 if(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment() >= 0)
233 Integration::SetPanGesturePredictionAmountAdjustment(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment());
235 if(mEnvironmentOptions->GetPanGestureSmoothingMode() >= 0)
237 Integration::SetPanGestureSmoothingMode(mEnvironmentOptions->GetPanGestureSmoothingMode());
239 if(mEnvironmentOptions->GetPanGestureSmoothingAmount() >= 0.0f)
241 Integration::SetPanGestureSmoothingAmount(mEnvironmentOptions->GetPanGestureSmoothingAmount());
243 if(mEnvironmentOptions->GetPanGestureUseActualTimes() >= 0)
245 Integration::SetPanGestureUseActualTimes(mEnvironmentOptions->GetPanGestureUseActualTimes() == 0 ? true : false);
247 if(mEnvironmentOptions->GetPanGestureInterpolationTimeRange() >= 0)
249 Integration::SetPanGestureInterpolationTimeRange(mEnvironmentOptions->GetPanGestureInterpolationTimeRange());
251 if(mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() >= 0)
253 Integration::SetPanGestureScalarOnlyPredictionEnabled(mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() == 0 ? true : false);
255 if(mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() >= 0)
257 Integration::SetPanGestureTwoPointPredictionEnabled(mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() == 0 ? true : false);
259 if(mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() >= 0)
261 Integration::SetPanGestureTwoPointInterpolatePastTime(mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime());
263 if(mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() >= 0.0f)
265 Integration::SetPanGestureTwoPointVelocityBias(mEnvironmentOptions->GetPanGestureTwoPointVelocityBias());
267 if(mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() >= 0.0f)
269 Integration::SetPanGestureTwoPointAccelerationBias(mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias());
271 if(mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() >= 0)
273 Integration::SetPanGestureMultitapSmoothingRange(mEnvironmentOptions->GetPanGestureMultitapSmoothingRange());
275 if(mEnvironmentOptions->GetMinimumPanDistance() >= 0)
277 Integration::SetPanGestureMinimumDistance(mEnvironmentOptions->GetMinimumPanDistance());
279 if(mEnvironmentOptions->GetMinimumPanEvents() >= 0)
281 Integration::SetPanGestureMinimumPanEvents(mEnvironmentOptions->GetMinimumPanEvents());
283 if(mEnvironmentOptions->GetMinimumPinchDistance() >= 0)
285 Integration::SetPinchGestureMinimumDistance(mEnvironmentOptions->GetMinimumPinchDistance());
287 if(mEnvironmentOptions->GetMinimumPinchTouchEvents() >= 0)
289 Integration::SetPinchGestureMinimumTouchEvents(mEnvironmentOptions->GetMinimumPinchTouchEvents());
291 if(mEnvironmentOptions->GetMinimumPinchTouchEventsAfterStart() >= 0)
293 Integration::SetPinchGestureMinimumTouchEventsAfterStart(mEnvironmentOptions->GetMinimumPinchTouchEventsAfterStart());
295 if(mEnvironmentOptions->GetMinimumRotationTouchEvents() >= 0)
297 Integration::SetRotationGestureMinimumTouchEvents(mEnvironmentOptions->GetMinimumRotationTouchEvents());
299 if(mEnvironmentOptions->GetMinimumRotationTouchEventsAfterStart() >= 0)
301 Integration::SetRotationGestureMinimumTouchEventsAfterStart(mEnvironmentOptions->GetMinimumRotationTouchEventsAfterStart());
303 if(mEnvironmentOptions->GetLongPressMinimumHoldingTime() >= 0)
305 Integration::SetLongPressMinimumHoldingTime(mEnvironmentOptions->GetLongPressMinimumHoldingTime());
307 if(mEnvironmentOptions->GetTapMaximumAllowedTime() > 0)
309 Integration::SetTapMaximumAllowedTime(mEnvironmentOptions->GetTapMaximumAllowedTime());
312 std::string systemCachePath = GetSystemCachePath();
313 if(!systemCachePath.empty())
315 const int dir_err = mkdir(systemCachePath.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
316 if(0 != dir_err && errno != EEXIST)
318 DALI_LOG_ERROR("Error creating system cache directory: %s!\n", systemCachePath.c_str());
322 mConfigurationManager = Utils::MakeUnique<ConfigurationManager>(systemCachePath, mGraphics.get(), mThreadController);
325 void Adaptor::AccessibilityObserver::OnAccessibleKeyEvent(const Dali::KeyEvent& event)
327 Accessibility::KeyEventType type;
328 if(event.GetState() == Dali::KeyEvent::DOWN)
330 type = Accessibility::KeyEventType::KEY_PRESSED;
332 else if(event.GetState() == Dali::KeyEvent::UP)
334 type = Accessibility::KeyEventType::KEY_RELEASED;
340 Dali::Accessibility::Bridge::GetCurrentBridge()->Emit(type, event.GetKeyCode(), event.GetKeyName(), event.GetTime(), !event.GetKeyString().empty());
345 Accessibility::Bridge::GetCurrentBridge()->Terminate();
347 // Ensure stop status
350 // set to NULL first as we do not want any access to Adaptor as it is being destroyed.
351 gThreadLocalAdaptor = NULL;
353 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
355 (*iter)->OnDestroy();
358 // Clear out all the handles to Windows
361 delete mThreadController; // this will shutdown render thread, which will call Core::ContextDestroyed before exit
362 delete mObjectProfiler;
366 delete mDisplayConnection;
367 delete mPlatformAbstraction;
369 mCallbackManager.reset();
371 delete mPerformanceInterface;
373 mGraphics->Destroy();
375 // uninstall it on this thread (main actor thread)
376 Dali::Integration::Log::UninstallLogFunction();
378 // Delete environment options if we own it
379 if(mEnvironmentOptionsOwned)
381 delete mEnvironmentOptions;
385 void Adaptor::Start()
387 // It doesn't support restart after stop at this moment to support restarting, need more testing
395 SetupSystemInformation();
397 // Start the callback manager
398 mCallbackManager->Start();
400 // Initialize accessibility bridge after callback manager is started to use Idler callback
401 auto appName = GetApplicationPackageName();
402 auto bridge = Accessibility::Bridge::GetCurrentBridge();
403 bridge->SetApplicationName(appName);
404 bridge->Initialize();
405 Dali::Stage::GetCurrent().KeyEventSignal().Connect(&mAccessibilityObserver, &AccessibilityObserver::OnAccessibleKeyEvent);
407 Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
409 unsigned int dpiHor, dpiVer;
412 defaultWindow->GetSurface()->GetDpi(dpiHor, dpiVer);
413 Dali::Internal::Adaptor::WindowSystem::SetDpi(dpiHor, dpiVer);
415 // Initialize the thread controller
416 mThreadController->Initialize();
418 // Set max texture size
419 if(mEnvironmentOptions->GetMaxTextureSize() > 0)
421 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize(mEnvironmentOptions->GetMaxTextureSize());
425 unsigned int maxTextureSize = mConfigurationManager->GetMaxTextureSize();
426 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize(maxTextureSize);
429 // cache advanced blending and shader language version
430 mGraphics->CacheConfigurations(*mConfigurationManager.get());
432 ProcessCoreEvents(); // Ensure any startup messages are processed.
434 // Initialize the image loader plugin
435 auto enablePluginString = Dali::EnvironmentVariable::GetEnvironmentVariable(ENABLE_IMAGE_LOADER_PLUGIN_ENV);
436 bool enablePlugin = enablePluginString ? std::atoi(enablePluginString) : false;
439 Internal::Adaptor::ImageLoaderPluginProxy::Initialize();
442 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
449 mAddOnManager->Start();
453 // Dali::Internal::Adaptor::Adaptor::Pause
454 void Adaptor::Pause()
456 // Only pause the adaptor if we're actually running.
457 if(RUNNING == mState)
459 // Inform observers that we are about to be paused.
460 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
468 mAddOnManager->Pause();
471 // Pause all windows event handlers when adaptor paused
472 for(auto window : mWindows)
477 mThreadController->Pause();
480 // Ensure any messages queued during pause callbacks are processed by doing another update.
483 DALI_LOG_RELEASE_INFO("Adaptor::Pause: Paused\n");
487 DALI_LOG_RELEASE_INFO("Adaptor::Pause: Not paused [%d]\n", mState);
491 // Dali::Internal::Adaptor::Adaptor::Resume
492 void Adaptor::Resume()
494 // Only resume the adaptor if we are in the suspended state.
499 // Reset the event handlers when adaptor resumed
500 for(auto window : mWindows)
505 // Resume AddOnManager
508 mAddOnManager->Resume();
511 // Inform observers that we have resumed.
512 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
517 // Trigger processing of events queued up while paused
518 mCore->ProcessEvents();
520 // Do at end to ensure our first update/render after resumption includes the processed messages as well
521 mThreadController->Resume();
523 DALI_LOG_RELEASE_INFO("Adaptor::Resume: Resumed\n");
527 DALI_LOG_RELEASE_INFO("Adaptor::Resume: Not resumed [%d]\n", mState);
533 if(RUNNING == mState ||
535 PAUSED_WHILE_HIDDEN == mState)
537 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
544 mAddOnManager->Stop();
547 mThreadController->Stop();
549 // Delete the TTS player
550 for(int i = 0; i < Dali::TtsPlayer::MODE_NUM; i++)
554 mTtsPlayers[i].Reset();
558 // Destroy the image loader plugin
559 auto enablePluginString = Dali::EnvironmentVariable::GetEnvironmentVariable(ENABLE_IMAGE_LOADER_PLUGIN_ENV);
560 bool enablePlugin = enablePluginString ? std::atoi(enablePluginString) : false;
563 Internal::Adaptor::ImageLoaderPluginProxy::Destroy();
566 delete mNotificationTrigger;
567 mNotificationTrigger = NULL;
569 mCallbackManager->Stop();
573 DALI_LOG_RELEASE_INFO("Adaptor::Stop\n");
577 void Adaptor::ContextLost()
579 mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage
582 void Adaptor::ContextRegained()
584 // Inform core, so that texture resources can be reloaded
585 mCore->RecoverFromContextLoss();
587 mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage
590 void Adaptor::FeedTouchPoint(TouchPoint& point, int timeStamp)
592 Integration::Point convertedPoint(point);
593 mWindows.front()->FeedTouchPoint(convertedPoint, timeStamp);
596 void Adaptor::FeedWheelEvent(Dali::WheelEvent& wheelEvent)
598 Integration::WheelEvent event(static_cast<Integration::WheelEvent::Type>(wheelEvent.GetType()), wheelEvent.GetDirection(), wheelEvent.GetModifiers(), wheelEvent.GetPoint(), wheelEvent.GetDelta(), wheelEvent.GetTime());
599 mWindows.front()->FeedWheelEvent(event);
602 void Adaptor::FeedKeyEvent(Dali::KeyEvent& keyEvent)
604 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());
605 mWindows.front()->FeedKeyEvent(convertedEvent);
608 void Adaptor::ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& newSurface)
610 Internal::Adaptor::SceneHolder* windowImpl = &Dali::GetImplementation(window);
611 for(auto windowPtr : mWindows)
613 if(windowPtr == windowImpl) // the window is not deleted
615 mResizedSignal.Emit(mAdaptor);
617 windowImpl->SetSurface(&newSurface);
619 // Flush the event queue to give the update-render thread chance
620 // to start processing messages for new camera setup etc as soon as possible
623 // This method blocks until the render thread has completed the replace.
624 mThreadController->ReplaceSurface(&newSurface);
630 void Adaptor::DeleteSurface(Dali::RenderSurfaceInterface& surface)
632 // Flush the event queue to give the update-render thread chance
633 // to start processing messages for new camera setup etc as soon as possible
636 // This method blocks until the render thread has finished rendering the current surface.
637 mThreadController->DeleteSurface(&surface);
640 Dali::RenderSurfaceInterface& Adaptor::GetSurface() const
642 return *mWindows.front()->GetSurface();
645 void Adaptor::ReleaseSurfaceLock()
647 mWindows.front()->GetSurface()->ReleaseLock();
650 Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
652 if(!mTtsPlayers[mode])
654 // Create the TTS player when it needed, because it can reduce launching time.
655 mTtsPlayers[mode] = TtsPlayer::New(mode);
658 return mTtsPlayers[mode];
661 bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue, bool forceAdd)
663 bool idleAdded(false);
665 // Only add an idle if the Adaptor is actually running
666 if(RUNNING == mState || READY == mState || forceAdd)
668 idleAdded = mCallbackManager->AddIdleCallback(callback, hasReturnValue);
674 void Adaptor::RemoveIdle(CallbackBase* callback)
676 mCallbackManager->RemoveIdleCallback(callback);
679 void Adaptor::ProcessIdle()
681 bool idleProcessed = mCallbackManager->ProcessIdle();
682 mNotificationOnIdleInstalled = mNotificationOnIdleInstalled && !idleProcessed;
685 void Adaptor::SetPreRenderCallback(CallbackBase* callback)
687 mThreadController->SetPreRenderCallback(callback);
690 bool Adaptor::AddWindow(Dali::Integration::SceneHolder childWindow)
692 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(childWindow);
693 windowImpl.SetAdaptor(Get());
695 // ChildWindow is set to the layout direction of the default window.
696 windowImpl.GetRootLayer().SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, mRootLayoutDirection);
698 // Add the new Window to the container - the order is not important
700 Dali::Mutex::ScopedLock lock(mMutex);
701 mWindows.push_back(&windowImpl);
704 Dali::RenderSurfaceInterface* surface = windowImpl.GetSurface();
706 mThreadController->AddSurface(surface);
708 mWindowCreatedSignal.Emit(childWindow);
713 bool Adaptor::RemoveWindow(Dali::Integration::SceneHolder* childWindow)
715 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(*childWindow);
716 for(WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter)
718 if(*iter == &windowImpl)
720 Dali::Mutex::ScopedLock lock(mMutex);
721 mWindows.erase(iter);
729 bool Adaptor::RemoveWindow(std::string childWindowName)
731 for(WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter)
733 if((*iter)->GetName() == childWindowName)
735 Dali::Mutex::ScopedLock lock(mMutex);
736 mWindows.erase(iter);
744 bool Adaptor::RemoveWindow(Internal::Adaptor::SceneHolder* childWindow)
746 for(WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter)
748 if((*iter)->GetId() == childWindow->GetId())
750 Dali::Mutex::ScopedLock lock(mMutex);
751 mWindows.erase(iter);
759 Dali::Adaptor& Adaptor::Get()
761 DALI_ASSERT_ALWAYS(IsAvailable() && "Adaptor not instantiated");
762 return gThreadLocalAdaptor->mAdaptor;
765 bool Adaptor::IsAvailable()
767 return gThreadLocalAdaptor != NULL;
770 void Adaptor::SceneCreated()
772 mCore->SceneCreated();
775 Dali::Integration::Core& Adaptor::GetCore()
780 void Adaptor::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender)
782 mThreadController->SetRenderRefreshRate(numberOfVSyncsPerRender);
785 Dali::DisplayConnection& Adaptor::GetDisplayConnectionInterface()
787 DALI_ASSERT_DEBUG(mDisplayConnection && "Display connection not created");
788 return *mDisplayConnection;
791 GraphicsInterface& Adaptor::GetGraphicsInterface()
793 DALI_ASSERT_DEBUG(mGraphics && "Graphics interface not created");
794 return *(mGraphics.get());
797 Dali::Integration::PlatformAbstraction& Adaptor::GetPlatformAbstractionInterface()
799 return *mPlatformAbstraction;
802 TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
804 return *mNotificationTrigger;
807 SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
809 return mSocketFactory;
812 Dali::RenderSurfaceInterface* Adaptor::GetRenderSurfaceInterface()
814 if(!mWindows.empty())
816 return mWindows.front()->GetSurface();
822 TraceInterface& Adaptor::GetKernelTraceInterface()
824 return mKernelTracer;
827 TraceInterface& Adaptor::GetSystemTraceInterface()
829 return mSystemTracer;
832 PerformanceInterface* Adaptor::GetPerformanceInterface()
834 return mPerformanceInterface;
837 Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
839 DALI_ASSERT_DEBUG(mPlatformAbstraction && "PlatformAbstraction not created");
840 return *mPlatformAbstraction;
843 void Adaptor::GetWindowContainerInterface(WindowContainer& windows)
845 Dali::Mutex::ScopedLock lock(mMutex);
849 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
851 if(mTtsPlayers[mode])
853 mTtsPlayers[mode].Reset();
857 Any Adaptor::GetNativeWindowHandle()
859 return mWindows.front()->GetNativeHandle();
862 Any Adaptor::GetNativeWindowHandle(Dali::Actor actor)
864 Any nativeWindowHandle;
866 Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
868 for(auto sceneHolder : mWindows)
870 if(scene == sceneHolder->GetScene())
872 nativeWindowHandle = sceneHolder->GetNativeHandle();
877 return nativeWindowHandle;
880 Any Adaptor::GetGraphicsDisplay()
886 GraphicsInterface* graphics = mGraphics.get(); // This interface is temporary until Core has been updated to match
887 auto eglGraphics = static_cast<EglGraphics*>(graphics);
889 EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
890 display = eglImpl.GetDisplay();
896 void Adaptor::SetUseRemoteSurface(bool useRemoteSurface)
898 mUseRemoteSurface = useRemoteSurface;
901 void Adaptor::AddObserver(LifeCycleObserver& observer)
903 ObserverContainer::iterator match(find(mObservers.begin(), mObservers.end(), &observer));
905 if(match == mObservers.end())
907 mObservers.push_back(&observer);
911 void Adaptor::RemoveObserver(LifeCycleObserver& observer)
913 ObserverContainer::iterator match(find(mObservers.begin(), mObservers.end(), &observer));
915 if(match != mObservers.end())
917 mObservers.erase(match);
921 void Adaptor::QueueCoreEvent(const Dali::Integration::Event& event)
925 mCore->QueueEvent(event);
929 void Adaptor::ProcessCoreEvents()
933 DALI_TRACE_SCOPE(gTraceFilter, "DALI_PROCESS_CORE_EVENTS");
935 if(mPerformanceInterface)
937 mPerformanceInterface->AddMarker(PerformanceInterface::PROCESS_EVENTS_START);
940 mCore->ProcessEvents();
942 if(mPerformanceInterface)
944 mPerformanceInterface->AddMarker(PerformanceInterface::PROCESS_EVENTS_END);
949 void Adaptor::RequestUpdate()
955 mThreadController->RequestUpdate();
959 case PAUSED_WHILE_HIDDEN:
961 // Update (and resource upload) without rendering
962 mThreadController->RequestUpdateOnce(UpdateMode::SKIP_RENDER);
973 void Adaptor::RequestProcessEventsOnIdle()
975 // We want to run the processes even when paused
976 if(STOPPED != mState)
978 if(!mNotificationOnIdleInstalled)
980 // If we haven't installed the idle notification, install it idle enterer.
981 mNotificationOnIdleInstalled = AddIdleEnterer(MakeCallback(this, &Adaptor::ProcessCoreEventsFromIdle), true);
985 // Request comes during ProcessCoreEventsFromIdle running.
986 // Mark as we need to call ProcessEvents in next idle events.
987 mRequiredIdleRepeat = true;
992 void Adaptor::OnWindowShown()
994 if(PAUSED_WHILE_HIDDEN == mState)
996 // Adaptor can now be resumed
1001 // Force a render task
1002 RequestUpdateOnce();
1004 else if(RUNNING == mState)
1006 // Force a render task
1007 RequestUpdateOnce();
1009 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowShown: Update requested.\n");
1011 else if(PAUSED_WHILE_INITIALIZING == mState)
1013 // Change the state to READY again. It will be changed to RUNNING after the adaptor is started.
1018 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowShown: Adaptor is not paused state.[%d]\n", mState);
1022 void Adaptor::OnWindowHidden()
1024 if(RUNNING == mState || READY == mState)
1026 bool allWindowsHidden = true;
1028 for(auto window : mWindows)
1030 if(window->IsVisible())
1032 allWindowsHidden = false;
1037 // Only pause the adaptor when all the windows are hidden
1038 if(allWindowsHidden)
1040 if(mState == RUNNING)
1044 // Adaptor cannot be resumed until any window is shown
1045 mState = PAUSED_WHILE_HIDDEN;
1047 else // mState is READY
1049 // Pause the adaptor after the state gets RUNNING
1050 mState = PAUSED_WHILE_INITIALIZING;
1055 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowHidden: Some windows are shown. Don't pause adaptor.\n");
1060 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowHidden: Adaptor is not running state.[%d]\n", mState);
1064 // Dali::Internal::Adaptor::Adaptor::OnDamaged
1065 void Adaptor::OnDamaged(const DamageArea& area)
1067 // This is needed for the case where Dali window is partially obscured
1071 void Adaptor::SurfaceResizePrepare(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize)
1073 mResizedSignal.Emit(mAdaptor);
1076 void Adaptor::SurfaceResizeComplete(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize)
1078 // Nofify surface resizing before flushing event queue
1079 mThreadController->ResizeSurface();
1081 // Flush the event queue to give the update-render thread chance
1082 // to start processing messages for new camera setup etc as soon as possible
1083 ProcessCoreEvents();
1086 void Adaptor::NotifySceneCreated()
1088 GetCore().SceneCreated();
1090 // Flush the event queue to give the update-render thread chance
1091 // to start processing messages for new camera setup etc as soon as possible
1092 ProcessCoreEvents();
1094 // Start thread controller after the scene has been created
1095 mThreadController->Start();
1097 // Process after surface is created (registering to remote surface provider if required)
1098 SurfaceInitialized();
1100 if(mState != PAUSED_WHILE_INITIALIZING)
1104 DALI_LOG_RELEASE_INFO("Adaptor::NotifySceneCreated: Adaptor is running\n");
1112 mState = PAUSED_WHILE_HIDDEN;
1114 DALI_LOG_RELEASE_INFO("Adaptor::NotifySceneCreated: Adaptor is paused\n");
1118 void Adaptor::NotifyLanguageChanged()
1120 mLanguageChangedSignal.Emit(mAdaptor);
1123 void Adaptor::RenderOnce()
1125 if(mThreadController)
1127 UpdateMode updateMode;
1128 if(mThreadMode == ThreadMode::NORMAL)
1130 updateMode = UpdateMode::NORMAL;
1134 updateMode = UpdateMode::FORCE_RENDER;
1136 ProcessCoreEvents();
1140 for(auto&& iter : mWindows)
1142 iter->GetSurface()->SetFullSwapNextFrame();
1145 mThreadController->RequestUpdateOnce(updateMode);
1149 const LogFactoryInterface& Adaptor::GetLogFactory()
1151 return *mEnvironmentOptions;
1154 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
1156 GetCore().RegisterProcessor(processor, postProcessor);
1159 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
1161 GetCore().UnregisterProcessor(processor, postProcessor);
1164 bool Adaptor::IsMultipleWindowSupported() const
1166 return mConfigurationManager->IsMultipleWindowSupported();
1169 int32_t Adaptor::GetRenderThreadId() const
1171 if(mThreadController)
1173 return mThreadController->GetThreadId();
1178 void Adaptor::RequestUpdateOnce()
1180 if(mThreadController)
1182 mThreadController->RequestUpdateOnce(UpdateMode::NORMAL);
1186 bool Adaptor::ProcessCoreEventsFromIdle()
1188 // Reset repeat idler flag.
1189 mRequiredIdleRepeat = false;
1190 ProcessCoreEvents();
1192 // If someone request ProcessCoreEvents during above ProcessCoreEvents call, we might need to run idle one more times.
1193 // Else, the idle handle automatically un-installs itself
1194 mNotificationOnIdleInstalled = mRequiredIdleRepeat;
1196 if(mRequiredIdleRepeat)
1198 DALI_LOG_DEBUG_INFO("Required ProcessCoreEvents one more times\n");
1201 return mRequiredIdleRepeat;
1204 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow(Dali::Actor& actor)
1206 Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
1208 for(auto window : mWindows)
1210 if(scene == window->GetScene())
1219 Dali::WindowContainer Adaptor::GetWindows() const
1221 Dali::WindowContainer windows;
1223 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
1225 // Downcast to Dali::Window
1226 Dali::Window window(dynamic_cast<Dali::Internal::Adaptor::Window*>(*iter));
1229 windows.push_back(window);
1236 Dali::SceneHolderList Adaptor::GetSceneHolders() const
1238 Dali::SceneHolderList sceneHolderList;
1240 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
1242 sceneHolderList.push_back(Dali::Integration::SceneHolder(*iter));
1245 return sceneHolderList;
1248 Dali::ObjectRegistry Adaptor::GetObjectRegistry() const
1250 Dali::ObjectRegistry registry;
1253 registry = mCore->GetObjectRegistry();
1258 Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode)
1260 mLanguageChangedSignal(),
1261 mWindowCreatedSignal(),
1265 mThreadController(nullptr),
1267 mDisplayConnection(nullptr),
1269 mConfigurationManager(nullptr),
1270 mPlatformAbstraction(nullptr),
1271 mCallbackManager(nullptr),
1272 mNotificationOnIdleInstalled(false),
1273 mRequiredIdleRepeat(false),
1274 mNotificationTrigger(nullptr),
1275 mDaliFeedbackPlugin(),
1276 mFeedbackController(nullptr),
1279 mEnvironmentOptions(environmentOptions ? environmentOptions : new EnvironmentOptions /* Create the options if not provided */),
1280 mPerformanceInterface(nullptr),
1283 mObjectProfiler(nullptr),
1284 mMemoryPoolTimerSlotDelegate(this),
1287 mThreadMode(threadMode),
1288 mEnvironmentOptionsOwned(environmentOptions ? false : true /* If not provided then we own the object */),
1289 mUseRemoteSurface(false),
1290 mRootLayoutDirection(Dali::LayoutDirection::LEFT_TO_RIGHT)
1292 DALI_ASSERT_ALWAYS(!IsAvailable() && "Cannot create more than one Adaptor per thread");
1293 mWindows.insert(mWindows.begin(), &Dali::GetImplementation(window));
1295 gThreadLocalAdaptor = this;
1298 void Adaptor::SetRootLayoutDirection(std::string locale)
1300 mRootLayoutDirection = static_cast<LayoutDirection::Type>(Internal::Adaptor::Locale::GetDirection(std::string(locale)));
1301 for(auto& window : mWindows)
1303 Dali::Actor root = window->GetRootLayer();
1304 root.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, mRootLayoutDirection);
1308 bool Adaptor::AddIdleEnterer(CallbackBase* callback, bool forceAdd)
1310 bool idleAdded(false);
1312 // Only add an idle if the Adaptor is actually running
1313 if(RUNNING == mState || READY == mState || forceAdd)
1315 idleAdded = mCallbackManager->AddIdleEntererCallback(callback);
1327 void Adaptor::RemoveIdleEnterer(CallbackBase* callback)
1329 mCallbackManager->RemoveIdleEntererCallback(callback);
1332 bool Adaptor::MemoryPoolTimeout()
1334 mCore->LogMemoryPools();
1335 return true; // Keep logging forever
1338 } // namespace Adaptor
1340 } // namespace Internal