diff --git a/frameworks/js/src/file_asset_napi.cpp b/frameworks/js/src/file_asset_napi.cpp index e18e5e201a9b6781d7cb77f5a65b412f9f3807ca..16681dfc859280c420a9cfe44eae10997801d813 100644 --- a/frameworks/js/src/file_asset_napi.cpp +++ b/frameworks/js/src/file_asset_napi.cpp @@ -39,6 +39,10 @@ #include "userfile_client.h" #include "userfilemgr_uri.h" +#ifdef IMAGE_PURGEABLE_PIXELMAP +#include "purgeable_pixel_map_builder.h" +#endif + using OHOS::HiviewDFX::HiLog; using OHOS::HiviewDFX::HiLogLabel; using namespace std; @@ -1456,7 +1460,21 @@ static unique_ptr QueryThumbnail(const std::string &uri, Size &size, c DecodeOptions decodeOpts; decodeOpts.desiredSize = size; decodeOpts.allocatorType = AllocatorType::SHARE_MEM_ALLOC; +#ifndef IMAGE_PURGEABLE_PIXELMAP return imageSource->CreatePixelMap(decodeOpts, err); +#else + unique_ptr pixelMap = imageSource->CreatePixelMap(decodeOpts, err); + uint32_t errorCode = 0; + unique_ptr backupImgSrc = ImageSource::CreateImageSource(uniqueFd.Get(), opts, errorCode); + NAPI_DEBUG_LOG("Prepare to bckup iamge source when to be purgeable: %{public}d.", errorCode); + if (errorCode == Media::SUCCESS) { + MakePixelMapToBePurgeable(pixelMap, backupImgSrc, decodeOpts); + } else { + NAPI_ERR_LOG("Failed to backup image source when to be purgeable: %{public}d", errorCode); + } + + return pixelMap; +#endif } static void JSGetThumbnailExecute(FileAssetAsyncContext* context) diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index c6ca749183a90c843fa1ebc1ec178efe7fde6f1a..1f808c96383a013186b4a32aeeedf0c6891fc3c2 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/ohos.gni") import("//build/ohos/ace/ace.gni") +import("//commonlibrary/memory_utils/purgeable_mem_config.gni") import("//foundation/multimedia/media_library/media_library.gni") import("../../../../../../arkcompiler/ets_frontend/ts2panda/ts2abc_config.gni") import("../../../../../../foundation/arkui/ace_engine/ace_config.gni") @@ -138,6 +139,11 @@ ohos_shared_library("medialibrary") { debug = false } + if (purgeable_ashmem_enable) { + defines = [ "IMAGE_PURGEABLE_PIXELMAP" ] + external_deps += [ "memory_utils:libpurgeablemem" ] + } + relative_install_dir = "module/multimedia" subsystem_name = "multimedia" part_name = "media_library"