From: Eunki, Hong Date: Wed, 14 Aug 2024 08:15:23 +0000 (+0900) Subject: Ensure destroy and re-create adaptor builder after application terminated X-Git-Tag: dali_2.3.38~14^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F62%2F316162%2F3;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git Ensure destroy and re-create adaptor builder after application terminated Since we can destroy and re-create adaptor, We need to release whole items ensurely after terminate application. To support this system, - Let we keep environment options for OffscreenApplication - Make static API to terminate adaptor builder (Allow to recreate adaptor builder by options) - Terminate adaptor builder after initalize adaptor done. Change-Id: Ie9dadd29f6d9894db73ef01bdb42e09299fcea57 Signed-off-by: Eunki, Hong --- diff --git a/dali/internal/adaptor/common/adaptor-builder-impl.cpp b/dali/internal/adaptor/common/adaptor-builder-impl.cpp index f3e84c9..1520de4 100644 --- a/dali/internal/adaptor/common/adaptor-builder-impl.cpp +++ b/dali/internal/adaptor/common/adaptor-builder-impl.cpp @@ -29,10 +29,12 @@ namespace Dali::Internal::Adaptor { +namespace +{ +static AdaptorBuilder* gAdaptorBuilder = nullptr; +} AdaptorBuilder& AdaptorBuilder::Get(EnvironmentOptions& environmentOptions) { - static AdaptorBuilder* gAdaptorBuilder = nullptr; - if(gAdaptorBuilder == nullptr) { gAdaptorBuilder = new AdaptorBuilder(environmentOptions); @@ -40,6 +42,12 @@ AdaptorBuilder& AdaptorBuilder::Get(EnvironmentOptions& environmentOptions) return *gAdaptorBuilder; } +void AdaptorBuilder::Finalize() +{ + delete gAdaptorBuilder; + gAdaptorBuilder = nullptr; +} + AdaptorBuilder::AdaptorBuilder(EnvironmentOptions& environmentOptions) : mEnvironmentOptions(environmentOptions) { diff --git a/dali/internal/adaptor/common/adaptor-builder-impl.h b/dali/internal/adaptor/common/adaptor-builder-impl.h index 607a461..5496399 100644 --- a/dali/internal/adaptor/common/adaptor-builder-impl.h +++ b/dali/internal/adaptor/common/adaptor-builder-impl.h @@ -31,6 +31,7 @@ class AdaptorBuilder { public: static AdaptorBuilder& Get(EnvironmentOptions& environmentOptions); + static void Finalize(); /** * Destructor diff --git a/dali/internal/adaptor/common/adaptor-impl.cpp b/dali/internal/adaptor/common/adaptor-impl.cpp index 75d6b35..c1cb59e 100644 --- a/dali/internal/adaptor/common/adaptor-impl.cpp +++ b/dali/internal/adaptor/common/adaptor-impl.cpp @@ -101,6 +101,8 @@ Dali::Adaptor* Adaptor::New(Dali::Integration::SceneHolder window, Dali::Integra auto& graphicsFactory = adaptorBuilder.GetGraphicsFactory(); impl->Initialize(graphicsFactory); + AdaptorBuilder::Finalize(); + return adaptor; } diff --git a/dali/internal/adaptor/common/application-impl.cpp b/dali/internal/adaptor/common/application-impl.cpp index 6c9cb29..c81d815 100644 --- a/dali/internal/adaptor/common/application-impl.cpp +++ b/dali/internal/adaptor/common/application-impl.cpp @@ -130,7 +130,6 @@ Application::Application(int* argc, char** argv[], const std::string& stylesheet mFramework(nullptr), mFrameworkFactory(nullptr), mCommandLineOptions(nullptr), - mAdaptorBuilder(nullptr), mAdaptor(nullptr), mEnvironmentOptions(nullptr), mMainWindow(), @@ -185,7 +184,6 @@ Application::~Application() if(!mUseUiThread) { delete mAdaptor; - delete mAdaptorBuilder; if(mIsSystemInitialized) { WindowSystem::Shutdown(); @@ -313,11 +311,11 @@ void Application::CreateWindow() GetImplementation(mMainWindow).DeleteRequestSignal().Connect(mSlotDelegate, &Application::Quit); } -void Application::CreateAdaptor() +void Application::CreateAdaptor(AdaptorBuilder& adaptorBuilder) { DALI_ASSERT_ALWAYS(mMainWindow && "Window required to create adaptor"); - auto& graphicsFactory = mAdaptorBuilder->GetGraphicsFactory(); + auto& graphicsFactory = adaptorBuilder.GetGraphicsFactory(); Integration::SceneHolder sceneHolder = Integration::SceneHolder(&Dali::GetImplementation(mMainWindow)); @@ -326,11 +324,6 @@ void Application::CreateAdaptor() Adaptor::GetImplementation(*mAdaptor).SetUseRemoteSurface(mUseRemoteSurface); } -void Application::CreateAdaptorBuilder() -{ - mAdaptorBuilder = &AdaptorBuilder::Get(*mEnvironmentOptions); -} - void Application::MainLoop() { // Run the application @@ -366,7 +359,7 @@ void Application::OnInit() mFramework->AddAbortCallback(MakeCallback(this, &Application::QuitFromMainLoop)); - CreateAdaptorBuilder(); + auto& adaptorBuilder = AdaptorBuilder::Get(*mEnvironmentOptions); // If an application was pre-initialized, a window was made in advance if(mLaunchpadState == Launchpad::NONE) { @@ -374,7 +367,10 @@ void Application::OnInit() CreateWindow(); } - CreateAdaptor(); + CreateAdaptor(adaptorBuilder); + + // adaptorBuilder invalidate after now. + AdaptorBuilder::Finalize(); if(mLaunchpadState == Launchpad::PRE_INITIALIZED) { @@ -435,7 +431,6 @@ void Application::OnTerminate() if(mUseUiThread) { delete mAdaptor; - delete mAdaptorBuilder; WindowSystem::Shutdown(); } } diff --git a/dali/internal/adaptor/common/application-impl.h b/dali/internal/adaptor/common/application-impl.h index 8d0d9c4..1f10290 100644 --- a/dali/internal/adaptor/common/application-impl.h +++ b/dali/internal/adaptor/common/application-impl.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_APPLICATION_H /* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -492,12 +492,7 @@ protected: /** * Creates the adaptor */ - void CreateAdaptor(); - - /** - * Creates the adaptor builder - */ - void CreateAdaptorBuilder(); + void CreateAdaptor(AdaptorBuilder& adaptorBuilder); /** * Quits from the main loop @@ -536,7 +531,6 @@ private: CommandLineOptions* mCommandLineOptions; - Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder; ///< The adaptor builder Dali::Adaptor* mAdaptor; std::unique_ptr mEnvironmentOptions; diff --git a/dali/internal/offscreen/common/offscreen-application-impl.cpp b/dali/internal/offscreen/common/offscreen-application-impl.cpp index f1fc2e7..25893d5 100644 --- a/dali/internal/offscreen/common/offscreen-application-impl.cpp +++ b/dali/internal/offscreen/common/offscreen-application-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,6 +63,11 @@ OffscreenApplication::OffscreenApplication(uint16_t width, uint16_t height, Dali // Disable ATSPI Dali::Accessibility::Bridge::DisableAutoInit(); + // Create environment options after environmnet value changed. + mEnvironmentOptions = std::unique_ptr(new Dali::Internal::Adaptor::EnvironmentOptions()); + + auto& adaptorBuilder = Dali::Internal::Adaptor::AdaptorBuilder::Get(*mEnvironmentOptions); + // Now we assume separated main loop for the offscreen application mFrameworkFactory = std::unique_ptr(Dali::Internal::Adaptor::CreateFrameworkFactory()); mFramework = mFrameworkFactory->CreateFramework(Internal::Adaptor::FrameworkBackend::GLIB, *this, *this, nullptr, nullptr, Adaptor::Framework::NORMAL, false); @@ -71,7 +76,12 @@ OffscreenApplication::OffscreenApplication(uint16_t width, uint16_t height, Dali IntrusivePtr impl = Internal::OffscreenWindow::New(width, height, surface, isTranslucent); mDefaultWindow = Dali::OffscreenWindow(impl.Get()); - mAdaptor.reset(Dali::Internal::Adaptor::Adaptor::New(Dali::Integration::SceneHolder(impl.Get()), impl->GetSurface(), NULL, renderMode == RenderMode::AUTO ? Dali::Internal::Adaptor::ThreadMode::NORMAL : Dali::Internal::Adaptor::ThreadMode::RUN_IF_REQUESTED)); + auto& graphicsFactory = adaptorBuilder.GetGraphicsFactory(); + + mAdaptor.reset(Dali::Internal::Adaptor::Adaptor::New(graphicsFactory, Dali::Integration::SceneHolder(impl.Get()), impl->GetSurface(), mEnvironmentOptions.get(), renderMode == RenderMode::AUTO ? Dali::Internal::Adaptor::ThreadMode::NORMAL : Dali::Internal::Adaptor::ThreadMode::RUN_IF_REQUESTED)); + + // adaptorBuilder invalidate after now. + Dali::Internal::Adaptor::AdaptorBuilder::Finalize(); // Initialize default window impl->Initialize(true); diff --git a/dali/internal/offscreen/common/offscreen-application-impl.h b/dali/internal/offscreen/common/offscreen-application-impl.h index 5e568a3..441a05b 100644 --- a/dali/internal/offscreen/common/offscreen-application-impl.h +++ b/dali/internal/offscreen/common/offscreen-application-impl.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_OFFSCREEN_APPLICATION_IMPL_H /* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,9 @@ #include #include #include +#include #include +#include namespace Dali { @@ -192,8 +194,10 @@ private: OffscreenApplication& operator=(OffscreenApplication&&) = delete; private: - std::unique_ptr mAdaptor; - Dali::OffscreenWindow mDefaultWindow; + std::unique_ptr mAdaptor; + std::unique_ptr mEnvironmentOptions; + + Dali::OffscreenWindow mDefaultWindow; std::unique_ptr mFramework; std::unique_ptr mFrameworkFactory;