diff --git a/frameworks/innerkitsimpl/common/src/pixel_map.cpp b/frameworks/innerkitsimpl/common/src/pixel_map.cpp index 465113e6eb124794ec53e47efaf33adfbc45a5b4..81d004881a596aa19ffcf69df8f0ed17c8439d44 100644 --- a/frameworks/innerkitsimpl/common/src/pixel_map.cpp +++ b/frameworks/innerkitsimpl/common/src/pixel_map.cpp @@ -4449,5 +4449,49 @@ std::unique_ptr PixelMap::ConvertFromAstc(PixelMap *source, uint32_t & { return PixelConvert::AstcToRgba(source, errorCode, destFormat); } + +bool PixelMap::IsReclaimed() const +{ + if (allocatorType_ != AllocatorType::DMA_ALLOC) { + IMAGE_LOGD("[Pixelmap] allocatorType is not dma"); + return false; + } + auto surfaceBuffer = static_cast(context_); + if (surfaceBuffer == nullptr) { + IMAGE_LOGD("[Pixelmap] surfaceBuffer is null"); + return false; + } + return surfaceBuffer->IsReclaimed(); +} + +int32_t PixelMap::ReclaimDMA() +{ + ImageTrace imageTrace("PixelMap Reclaim"); + if (allocatorType_ != AllocatorType::DMA_ALLOC) { + IMAGE_LOGD("[Pixelmap] allocatorType is not dma"); + return ERR_IMAGE_DATA_UNSUPPORT; + } + auto surfaceBuffer = static_cast(context_); + if (surfaceBuffer == nullptr) { + IMAGE_LOGD("[Pixelmap] surfaceBuffer is null"); + return ERR_IMAGE_GET_DATA_ABNORMAL; + } + return surfaceBuffer->TryReclaim(); +} + +int32_t PixelMap::ResumeDMA() +{ + ImageTrace imageTrace("PixelMap Resume"); + if (allocatorType_ != AllocatorType::DMA_ALLOC) { + IMAGE_LOGD("[Pixelmap] allocatorType is not dma"); + return ERR_IMAGE_DATA_UNSUPPORT; + } + auto surfaceBuffer = static_cast(context_); + if (surfaceBuffer == nullptr) { + IMAGE_LOGD("[Pixelmap] surfaceBuffer is null"); + return ERR_IMAGE_GET_DATA_ABNORMAL; + } + return surfaceBuffer->TryResumeIfNeeded(); +} } // namespace Media } // namespace OHOS diff --git a/frameworks/innerkitsimpl/test/unittest/pixel_map_test/pixel_map_test.cpp b/frameworks/innerkitsimpl/test/unittest/pixel_map_test/pixel_map_test.cpp index e5b5beeaa708a62a05ecdfc73b410c54ef0e961c..5a02b62c2216d3732b4e7bfb99a5ae43118e44f1 100644 --- a/frameworks/innerkitsimpl/test/unittest/pixel_map_test/pixel_map_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/pixel_map_test/pixel_map_test.cpp @@ -19,6 +19,7 @@ #include "image_type.h" #include "image_utils.h" #include "media_errors.h" +#include "memory_manager.h" #include "pixel_map.h" #include "pixel_convert_adapter.h" #include "securec.h" @@ -2878,6 +2879,49 @@ HWTEST_F(PixelMapTest, UnmodifiablePixelMapTest, TestSize.Level3) GTEST_LOG_(INFO) << "PixelMapTest: UnmodifiablePixelMapTest end"; } +/** + * @tc.name: ReclaimAndResumePixelMapTest + * @tc.desc: Test Reclaim PixelMap and Resume PixelMap + * @tc.type: FUNC + */ +HWTEST_F(PixelMapTest, ReclaimAndResumePixelMapTest, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapTest: ReclaimAndResumePixelMapTest start"; + + int32_t pixelMapWidth = 700; + int32_t pixelMapHeight = 700; + int32_t bytesPerPixel = 3; + + std::unique_ptr pixelMap = std::make_unique(); + ImageInfo info; + info.size.width = pixelMapWidth; + info.size.height = pixelMapHeight; + info.pixelFormat = PixelFormat::RGB_888; + info.colorSpace = ColorSpace::SRGB; + pixelMap->SetImageInfo(info); + + int32_t rowDataSize = pixelMapWidth * bytesPerPixel; + int32_t bufferSize = rowDataSize * pixelMapHeight; + + Media::MemoryData memoryData = {nullptr, static_cast(bufferSize), "Create PixelMap", info.size, + info.pixelFormat}; + std::unique_ptr memory = Media::MemoryManager::CreateMemory(Media::AllocatorType::DMA_ALLOC, memoryData); + pixelMap->SetPixelsAddr(memory->data.data, memory->extend.data, memory->data.size, memory->GetType(), + nullptr); + + EXPECT_EQ(pixelMap->IsReclaimed(), false); + EXPECT_EQ(pixelMap->ReclaimDMA(), 0); + EXPECT_EQ(pixelMap->IsReclaimed(), true); + EXPECT_NE(pixelMap->ReclaimDMA(), 0); + EXPECT_EQ(pixelMap->IsReclaimed(), true); + EXPECT_EQ(pixelMap->ResumeDMA(), 0); + EXPECT_EQ(pixelMap->IsReclaimed(), false); + EXPECT_NE(pixelMap->ResumeDMA(), 0); + EXPECT_EQ(pixelMap->IsReclaimed(), false); + + GTEST_LOG_(INFO) << "PixelMapTest: ReclaimAndResumePixelMapTest end"; +} + /** * @tc.name: UnMapPixelMapTest * @tc.desc: Test UnMap PixelMap diff --git a/interfaces/innerkits/include/pixel_map.h b/interfaces/innerkits/include/pixel_map.h index 1702ed9dbcecfb8560cd967c1381e0789e89ffa9..ebfb6cba00364703ba5d776810f57eb7520a7a0c 100644 --- a/interfaces/innerkits/include/pixel_map.h +++ b/interfaces/innerkits/include/pixel_map.h @@ -409,6 +409,10 @@ public: NATIVEEXPORT uint32_t GetVersionId(); NATIVEEXPORT void AddVersionId(); + + NATIVEEXPORT bool IsReclaimed() const; + NATIVEEXPORT int32_t ReclaimDMA(); + NATIVEEXPORT int32_t ResumeDMA(); protected: static constexpr uint8_t TLV_VARINT_BITS = 7; static constexpr uint8_t TLV_VARINT_MASK = 0x7F;