From ace0d0d39d2e67312c65bf21036d349f6a512574 Mon Sep 17 00:00:00 2001 From: x00678224 Date: Sat, 20 May 2023 16:30:28 +0800 Subject: [PATCH] 0520 make pixelmap purgeable Signed-off-by: x00678224 Change-Id: Ice067a1e4ac2f02abb9f62e68b1e8b7318c665b3 --- frameworks/native/ability/native/BUILD.gn | 6 ++++++ frameworks/native/ability/native/ability.cpp | 8 ++++++++ frameworks/native/appkit/BUILD.gn | 6 ++++++ frameworks/native/appkit/app/main_thread.cpp | 9 +++++++++ 4 files changed, 29 insertions(+) diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index 90ca20d9720..053311d9ca0 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") @@ -279,6 +280,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 5ff475e9050..3a7710f133d 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"); @@ -1584,6 +1588,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/BUILD.gn b/frameworks/native/appkit/BUILD.gn index f3e6144bfbd..e510f2e32dd 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -13,6 +13,7 @@ import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni") import("//build/ohos.gni") +import("//commonlibrary/memory_utils/purgeable_mem_config.gni") import("//foundation/ability/ability_runtime/ability_runtime.gni") es2abc_gen_abc("gen_delegator_mgmt_abc") { @@ -178,6 +179,11 @@ ohos_shared_library("appkit_native") { defines += [ "NWEB" ] } + if (purgeable_ashmem_enable) { + external_deps += [ "memory_utils:libpurgeablemem" ] + defines += [ "IMAGE_PURGEABLE_PIXELMAP" ] + } + innerapi_tags = [ "platformsdk" ] version_script = "libappkit_native.map" subsystem_name = "ability" diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 1f2e22664b3..ea6d135ca98 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -69,6 +69,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 @@ -1788,6 +1792,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