From bee57906ea6c5063bc77c7fbcad883f148bc1419 Mon Sep 17 00:00:00 2001 From: x00678224 Date: Wed, 26 Apr 2023 15:40:21 +0800 Subject: [PATCH] make pixelmap to be purgeable Signed-off-by: x00678224 Change-Id: I95a4c64ab17829011ef01d7fdaa9067b35f02990 --- frameworks/native/ability/native/BUILD.gn | 6 ++++++ frameworks/native/ability/native/ability.cpp | 8 ++++++++ frameworks/native/appkit/app/main_thread.cpp | 9 +++++++++ 3 files changed, 23 insertions(+) diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index d789c07e45b..5876e7003ac 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/ohos.gni") +import("//commonlibrary/memory_utils/purgeable_mem_config.gni") import("//foundation/ability/ability_runtime/ability_runtime.gni") import("//foundation/distributeddatamgr/relational_store/relational_store.gni") @@ -296,6 +297,11 @@ ohos_shared_library("abilitykit_native") { defines += [ "BGTASKMGR_CONTINUOUS_TASK_ENABLE" ] } + if (purgeable_ashmem_enable) { + external_deps += [ "memory_utils:libpurgeablemem" ] + defines += [ "IMAGE_PURGEABLE_PIXELMAP" ] + } + if (efficiency_manager) { external_deps += [ "efficiency_manager:suspend_manager_client" ] defines += [ "EFFICIENCY_MANAGER_ENABLE" ] diff --git a/frameworks/native/ability/native/ability.cpp b/frameworks/native/ability/native/ability.cpp index 0e2eddb36cb..8ba87945a9c 100644 --- a/frameworks/native/ability/native/ability.cpp +++ b/frameworks/native/ability/native/ability.cpp @@ -56,6 +56,10 @@ #include "key_event.h" #endif +#ifdef IMAGE_PURGEABLE_PIXELMAP +#include "purgeable_resource_manager.h" +#endif + namespace OHOS { namespace AppExecFwk { const std::string Ability::SYSTEM_UI("com.ohos.systemui"); @@ -1585,6 +1589,10 @@ void Ability::OnBackground() HILOG_ERROR("Ability::OnBackground error. lifecycle_ == nullptr."); return; } +#ifdef IMAGE_PURGEABLE_PIXELMAP + HILOG_DEBUG("[PurgeableResourceManager] Ability OnBackground ExecEndVisitPurgeableMem."); + PurgeableMem::PurgeableResourceManager::GetInstance().ExecEndVisitPurgeableMem(); +#endif lifecycle_->DispatchLifecycle(LifeCycle::Event::ON_BACKGROUND); HILOG_DEBUG("%{public}s end", __func__); AAFwk::EventInfo eventInfo; diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 88cf3bcd023..44f30cd5deb 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -68,6 +68,10 @@ #include "nweb_helper.h" #endif +#ifdef IMAGE_PURGEABLE_PIXELMAP +#include "purgeable_resource_manager.h" +#endif + #if defined(ABILITY_LIBRARY_LOADER) || defined(APPLICATION_LIBRARY_LOADER) #include #include @@ -1786,6 +1790,11 @@ void MainThread::HandleForegroundApplication() return; } +#ifdef IMAGE_PURGEABLE_PIXELMAP + HILOG_DEBUG("[PurgeableResourceManager] Ability OnForeground ExecBeginVisitPurgeableMem."); + PurgeableMem::PurgeableResourceManager::GetInstance().ExecBeginVisitPurgeableMem(); +#endif + if (!applicationImpl_->PerformForeground()) { HILOG_ERROR("MainThread::handleForegroundApplication error!, applicationImpl_->PerformForeground() failed"); return; -- Gitee