diff --git a/bundle.json b/bundle.json index 17c11185f3d10d885cac7898bfba3dabd58460c6..8a34f71354009a03bc88823af680209cb83a90ab 100644 --- a/bundle.json +++ b/bundle.json @@ -24,7 +24,6 @@ "hitrace", "init", "ipc", - "image_framework", "ffrt" ], "third_party": [] @@ -34,8 +33,7 @@ "//commonlibrary/memory_utils/libdmabufheap:libdmabufheap", "//commonlibrary/memory_utils/libmeminfo:libmeminfo", "//commonlibrary/memory_utils/libpurgeablemem:libpurgeablemem", - "//commonlibrary/memory_utils/libpurgeablemem:purgeable_memory_ndk", - "//commonlibrary/memory_utils/purgeable_builder:pixelmap_builder" + "//commonlibrary/memory_utils/libpurgeablemem:purgeable_memory_ndk" ], "inner_kits": [ { @@ -70,15 +68,6 @@ ], "header_base": "//commonlibrary/memory_utils/libpurgeablemem/cpp/include" } - }, - { - "name": "//commonlibrary/memory_utils/purgeable_builder:pixelmap_builder", - "header": { - "header_files": [ - "purgeable_pixelmap_builder.h" - ], - "header_base": "//commonlibrary/memory_utils/purgeable_builder/include" - } } ], "test": [ diff --git a/purgeable_builder/BUILD.gn b/purgeable_builder/BUILD.gn deleted file mode 100644 index c0f34a626bb687518d942279f752f826c067f5f1..0000000000000000000000000000000000000000 --- a/purgeable_builder/BUILD.gn +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//commonlibrary/memory_utils/purgeable_mem_config.gni") - -config("purgeable_builder_config") { - include_dirs = [ "include" ] - cflags_cc = [ - "-D_FORTIFY_SOURCE=2", - "-fexceptions", - "-fstack-protector-all", - "-O2", - ] -} - -ohos_shared_library("pixelmap_builder") { - sources = [ "src/purgeable_pixelmap_builder.cpp" ] - include_dirs = [ "include/purgeable_pixelmap_builder.h" ] - defines = [ "IMAGE_PURGEABLE_PIXELMAP" ] - - deps = [ "../libpurgeablemem:libpurgeablemem" ] - external_deps = [ - "c_utils:utils", - "hilog:libhilog", - "hitrace:hitrace_meter", - "image_framework:image", - "image_framework:image_native", - "init:libbegetutil", - ] - public_configs = [ ":purgeable_builder_config" ] - subsystem_name = "commonlibrary" - part_name = "memory_utils" -} diff --git a/purgeable_builder/include/purgeable_pixelmap_builder.h b/purgeable_builder/include/purgeable_pixelmap_builder.h deleted file mode 100644 index cd294ef348b53659f6dc7f0ec5e4ba144b668e12..0000000000000000000000000000000000000000 --- a/purgeable_builder/include/purgeable_pixelmap_builder.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef OHOS_MEMORY_UTILS_PURGEABLE_PIXELMAP_BUILDER_H -#define OHOS_MEMORY_UTILS_PURGEABLE_PIXELMAP_BUILDER_H - -#include "image_source.h" -#include "image_type.h" -#include "pixel_map.h" - -#include "purgeable_ashmem.h" -#include "purgeable_mem_builder.h" -#include "purgeable_resource_manager.h" - -#include "memory.h" - -namespace OHOS { -namespace PurgeableBuilder { -using namespace OHOS::Media; - -class PurgeablePixelMapBuilder : public PurgeableMem::PurgeableMemBuilder { -public: - PurgeablePixelMapBuilder(uint32_t index, std::unique_ptr &imageSource, - DecodeOptions opts); - - bool Build(void *data, size_t size) override; - - ~PurgeablePixelMapBuilder() {} - -private: - uint32_t index_; - DecodeOptions opts_; - std::unique_ptr imageSource_; -}; // class PurgeablePixelMapBuilder - -bool GetSysForPurgeable(); -void SetBuilderToBePurgeable(PixelMap *pixelMap, - std::unique_ptr &builder); -void RemoveFromPurgeableResourceMgr(PixelMap *pixelMap); -void AddToPurgeableResourceMgr(PixelMap *pixelMap); -bool MakePixelMapToBePurgeable(std::unique_ptr &pixelMap, - std::unique_ptr &backupImgSrc4Rebuild, DecodeOptions &decodeOpts); -bool MakePixelMapToBePurgeable(std::unique_ptr &pixelMap, const int fd, - const SourceOptions &opts, DecodeOptions &decodeOpts); -bool MakePixelMapToBePurgeableBySrc(PixelMap *pixelMap, - std::unique_ptr &backupImgSrc4Rebuild, DecodeOptions &decodeOpts); -bool MakePixelMapToBePurgeableByFd(PixelMap *pixelMap, const int fd, const SourceOptions &opts, - DecodeOptions &decodeOpts); -bool IfCanBePurgeable(DecodeOptions &decodeOpts); -} // namespace PurgeableBuilder -} // namespace OHOS -#endif /* OHOS_MEMORY_UTILS_PURGEABLE_PIXELMAP_BUILDER_H */ \ No newline at end of file diff --git a/purgeable_builder/src/purgeable_pixelmap_builder.cpp b/purgeable_builder/src/purgeable_pixelmap_builder.cpp deleted file mode 100644 index db31c215bae68bd8aae59d7316346e0231111eaa..0000000000000000000000000000000000000000 --- a/purgeable_builder/src/purgeable_pixelmap_builder.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "purgeable_pixelmap_builder.h" - -#include "hitrace_meter.h" -#include "hilog/log.h" -#include "media_errors.h" -#include "parameters.h" -#include "purgeable_ashmem.h" -#include "purgeable_mem_base.h" -#include "purgeable_mem_builder.h" -#include "purgeable_resource_manager.h" - -#ifndef _WIN32 -#include "securec.h" -#else -#include "memory.h" -#endif - -namespace OHOS { -namespace PurgeableBuilder { -constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001799, "PurgeablePixelMapBuilder" }; -constexpr int THRESHOLD_HEIGHT = 256; -constexpr int THRESHOLD_WIDGHT = 256; -const std::string SYSTEM_PARAM_PURGEABLE_ENABLE = "persist.resourceschedule.memmgr.purgeable.enable"; -const std::string SYSTEM_PARAM_PIXELMAP_THRESHOLD_HEIGHT = "persist.memmgr.purgeable.pixelmap.threshold.height"; -const std::string SYSTEM_PARAM_PIXELMAP_THRESHOLD_WIDGHT = "persist.memmgr.purgeable.pixelmap.threshold.widght"; - -PurgeablePixelMapBuilder::PurgeablePixelMapBuilder(uint32_t index, std::unique_ptr &imageSource, - DecodeOptions opts) - : index_(index), opts_(opts), imageSource_(move(imageSource)) {} - -bool PurgeablePixelMapBuilder::Build(void *data, size_t size) -{ - HiviewDFX::HiLog::Debug(LABEL, "purgeableMem build in."); - uint32_t errorCode; - if (imageSource_ == nullptr) { - return false; - } - - StartTrace(HITRACE_TAG_ZIMAGE, "OHOS::PurgeableBuilder::PixelMapPurgeableMemBuilder::Build"); - std::unique_ptr pixelMap = imageSource_->CreatePixelMap(index_, opts_, errorCode); - if (pixelMap == nullptr || data == nullptr) { - FinishTrace(HITRACE_TAG_ZIMAGE); - return false; - } - - StartTrace(HITRACE_TAG_ZIMAGE, ("OHOS::PurgeableBuilder::PixelMapPurgeableMemBuilder::CopyData " + - std::to_string(size))); - if (memcpy_s((char *)data, size, (char *)pixelMap->GetPixels(), size)) { - FinishTrace(HITRACE_TAG_ZIMAGE); - return false; - } - - DoRebuildSuccessCallback(); - - FinishTrace(HITRACE_TAG_ZIMAGE); // memcpy_s trace - FinishTrace(HITRACE_TAG_ZIMAGE); // PixelMapPurgeableMemBuilder::Build trace - - return true; -} - -bool GetSysForPurgeable() -{ - return system::GetBoolParameter(SYSTEM_PARAM_PURGEABLE_ENABLE, false); -} - -void SetBuilderToBePurgeable(PixelMap *pixelMap, - std::unique_ptr &builder) -{ - HiviewDFX::HiLog::Debug(LABEL, "set builder for purgeable pixelmap. allocatorType = %{public}d.", - pixelMap->GetAllocatorType()); - StartTrace(HITRACE_TAG_ZIMAGE, "OHOS::PurgeableBuilder::SetBuilderToBePurgeable"); - if (pixelMap == nullptr) { - FinishTrace(HITRACE_TAG_ZIMAGE); - return; - } - - if (builder == nullptr) { - FinishTrace(HITRACE_TAG_ZIMAGE); - return; - } - - if (pixelMap->GetAllocatorType() == AllocatorType::SHARE_MEM_ALLOC) { - std::shared_ptr tmpPtr = - std::make_shared(std::move(builder)); - bool isChanged = tmpPtr->ChangeAshmemData(pixelMap->GetCapacity(), - *(static_cast(pixelMap->GetFd())), pixelMap->GetWritablePixels()); - if (isChanged) { - pixelMap->SetPurgeableMemPtr(tmpPtr); - pixelMap->GetPurgeableMemPtr()->BeginReadWithDataLock(); - } else { - HiviewDFX::HiLog::Error(LABEL, "ChangeAshmemData fail."); - } - } - - FinishTrace(HITRACE_TAG_ZIMAGE); -} - -void RemoveFromPurgeableResourceMgr(PixelMap *pixelMap) -{ - StartTrace(HITRACE_TAG_ZIMAGE, "OHOS::PurgeableBuilder::RemoveFromPurgeableResourceMgr"); - HiviewDFX::HiLog::Debug(LABEL, "remove pixelmap from PurgeableResourceMgr."); - - if (pixelMap == nullptr) { - FinishTrace(HITRACE_TAG_ZIMAGE); - return; - } - - if (pixelMap->IsPurgeable()) { - PurgeableMem::PurgeableResourceManager::GetInstance().RemoveResource(pixelMap->GetPurgeableMemPtr()); - } - - FinishTrace(HITRACE_TAG_ZIMAGE); -} - -void AddToPurgeableResourceMgr(PixelMap *pixelMap) -{ - StartTrace(HITRACE_TAG_ZIMAGE, "OHOS::PurgeableBuilder::AddToPurgeableResourceMgr"); - HiviewDFX::HiLog::Debug(LABEL, "add pixelmap purgeablemem ptr to PurgeableResourceMgr"); - - if (pixelMap == nullptr) { - FinishTrace(HITRACE_TAG_ZIMAGE); - return; - } - - if (pixelMap->IsPurgeable()) { - PurgeableMem::PurgeableResourceManager::GetInstance().AddResource(pixelMap->GetPurgeableMemPtr()); - } - - FinishTrace(HITRACE_TAG_ZIMAGE); -} - -bool IfCanBePurgeable(DecodeOptions &decodeOpts) -{ - int thresholdHeight = system::GetIntParameter(SYSTEM_PARAM_PIXELMAP_THRESHOLD_HEIGHT, THRESHOLD_HEIGHT); - int thresholdWidght = system::GetIntParameter(SYSTEM_PARAM_PIXELMAP_THRESHOLD_WIDGHT, THRESHOLD_WIDGHT); - Size size = decodeOpts.desiredSize; - - if (size.height > thresholdHeight || size.width > thresholdWidght) { - return false; - } - return true; -} - -bool MakePixelMapToBePurgeable(std::unique_ptr &pixelMap, std::unique_ptr &backupImgSrc4Rebuild, - DecodeOptions &decodeOpts) -{ - return MakePixelMapToBePurgeableBySrc(pixelMap.get(), backupImgSrc4Rebuild, decodeOpts); -} - -bool MakePixelMapToBePurgeable(std::unique_ptr &pixelMap, const int fd, - const SourceOptions &opts, DecodeOptions &decodeOpts) -{ - return MakePixelMapToBePurgeableByFd(pixelMap.get(), fd, opts, decodeOpts); -} - -bool MakePixelMapToBePurgeableByFd(PixelMap *pixelMap, const int fd, const SourceOptions &opts, - DecodeOptions &decodeOpts) -{ - uint32_t errorCode = 0; - std::unique_ptr backupImgSrc = ImageSource::CreateImageSource(fd, opts, errorCode); - if (errorCode != Media::SUCCESS) { - return false; - } - return MakePixelMapToBePurgeableBySrc(pixelMap, backupImgSrc, decodeOpts); -} - -bool MakePixelMapToBePurgeableBySrc(PixelMap *pixelMap, - std::unique_ptr &backupImgSrc4Rebuild, DecodeOptions &decodeOpts) -{ - StartTrace(HITRACE_TAG_ZIMAGE, "OHOS::PurgeableBuilder::MakePixelMapToBePurgeable"); - HiviewDFX::HiLog::Debug(LABEL, "MakePixelMapToBePurgeable in."); - - if (!GetSysForPurgeable()) { - FinishTrace(HITRACE_TAG_ZIMAGE); - return false; - } - - if (!IfCanBePurgeable(decodeOpts)) { - FinishTrace(HITRACE_TAG_ZIMAGE); - return false; - } - - if (pixelMap == nullptr || backupImgSrc4Rebuild == nullptr) { - HiviewDFX::HiLog::Error(LABEL, "PixelMap or backupImgSrc4Rebuild is null."); - FinishTrace(HITRACE_TAG_ZIMAGE); - return false; - } - - if (pixelMap->IsPurgeable()) { - HiviewDFX::HiLog::Error(LABEL, "PixelMap is already purgeable."); - FinishTrace(HITRACE_TAG_ZIMAGE); - return false; - } - - std::unique_ptr purgeableMemBuilder = - std::make_unique(0, backupImgSrc4Rebuild, decodeOpts); - SetBuilderToBePurgeable(pixelMap, purgeableMemBuilder); - - if (pixelMap->IsPurgeable()) { - AddToPurgeableResourceMgr(pixelMap); - } - - FinishTrace(HITRACE_TAG_ZIMAGE); - return true; -} -} // namespace PurgeableBuilder -} // namespace OHOS \ No newline at end of file