diff --git a/frameworks/innerkitsimpl/common/src/pixel_astc.cpp b/frameworks/innerkitsimpl/common/src/pixel_astc.cpp index 3a752cc185ff3de29d8bebe002cde9f67c151ba3..73a451905414618084040c2f481bdd96903b174e 100644 --- a/frameworks/innerkitsimpl/common/src/pixel_astc.cpp +++ b/frameworks/innerkitsimpl/common/src/pixel_astc.cpp @@ -209,13 +209,13 @@ bool PixelAstc::IsSameImage(const PixelMap &other) uint32_t PixelAstc::ReadPixels(const uint64_t &bufferSize, const uint32_t &offset, const uint32_t &stride, const Rect ®ion, uint8_t *dst) { - IMAGE_LOGE("ReadPixels is not support on pixelastc"); + IMAGE_LOGE("%{public}d:ReadPixels is not support on pixelastc", uniqueId_); return ERR_IMAGE_INVALID_PARAMETER; } uint32_t PixelAstc::ReadPixels(const uint64_t &bufferSize, uint8_t *dst) { - IMAGE_LOGE("ReadPixels is not support on pixelastc"); + IMAGE_LOGE("%{public}d:ReadPixels is not support on pixelastc", uniqueId_); return ERR_IMAGE_INVALID_PARAMETER; } diff --git a/frameworks/innerkitsimpl/common/src/pixel_map.cpp b/frameworks/innerkitsimpl/common/src/pixel_map.cpp index 08a71722ba484348f5e1c1a21c67e335cf72a7cc..fe66140a1aac0f1276acc439306c9da9bd21ada1 100644 --- a/frameworks/innerkitsimpl/common/src/pixel_map.cpp +++ b/frameworks/innerkitsimpl/common/src/pixel_map.cpp @@ -236,6 +236,33 @@ void PixelMap::SetPixelsAddr(void *addr, void *context, uint32_t size, Allocator ImageUtils::FlushSurfaceBuffer(this); } +void PixelMap::SetPixelsAddr(void *addr, void *context, uint32_t size, AllocatorType type, bool displayOnly) +{ + if (type < AllocatorType::DEFAULT || type > AllocatorType::DMA_ALLOC) { + IMAGE_LOGE("Unmarshalling setPixelsAddr error invalid allocatorType"); + return; + } + if (data_ != nullptr) { + IMAGE_LOGD("Unmarshalling setPixelsAddr release the existed data first"); + FreePixelMap(); + } + if (type == AllocatorType::SHARE_MEM_ALLOC && context == nullptr) { + IMAGE_LOGE("Unmarshalling setPixelsAddr error type %{public}d ", type); + } + data_ = static_cast(addr); + isUnMap_ = false; + context_ = context; + pixelsSize_ = size; + allocatorType_ = type; + custFreePixelMap_ = nullptr; + if (type == AllocatorType::DMA_ALLOC && rowDataSize_ != 0) { + UpdateImageInfo(); + } + if (!displayOnly) { + ImageUtils::FlushSurfaceBuffer(this); + } +} + bool CheckPixelmap(std::unique_ptr &pixelMap, ImageInfo &imageInfo) { if (pixelMap == nullptr) { @@ -1886,7 +1913,7 @@ uint32_t PixelMap::ReadPixel(const Position &pos, uint32_t &dst) return ERR_IMAGE_INVALID_PARAMETER; } if (isUnMap_ || data_ == nullptr) { - IMAGE_LOGE("read pixel by pos source data is null, isUnMap %{public}d.", isUnMap_); + IMAGE_LOGE("%{public}d:read pixel by pos source data is null, isUnMap %{public}d.", uniqueId_, isUnMap_); return ERR_IMAGE_READ_PIXELMAP_FAILED; } ImageInfo dstImageInfo = @@ -3008,7 +3035,7 @@ bool PixelMap::UpdatePixelMapMemInfo(PixelMap *pixelMap, ImageInfo &imgInfo, Pix return false; } pixelMap->SetPixelsAddr(pixelMemInfo.base, pixelMemInfo.context, - pixelMemInfo.bufferSize, pixelMemInfo.allocatorType, nullptr); + pixelMemInfo.bufferSize, pixelMemInfo.allocatorType, pixelMap->IsDisplayOnly()); return true; } 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 8b24c760dda888c4273efd6ee770fc73dea973f8..59bb34fd8dbce3244b52030af6b0e6c1aedd2fd7 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 @@ -1024,6 +1024,8 @@ HWTEST_F(PixelMapTest, PixelMapTest006, TestSize.Level3) void *fdBuffer = nullptr; uint32_t bufferSize = pixelMap1->GetByteCount(); pixelMap1->SetPixelsAddr(dstPixels, fdBuffer, bufferSize, AllocatorType::HEAP_ALLOC, nullptr); + pixelMap1->SetPixelsAddr(dstPixels, fdBuffer, bufferSize, AllocatorType::HEAP_ALLOC, false); + pixelMap1->SetPixelsAddr(dstPixels, fdBuffer, bufferSize, AllocatorType::HEAP_ALLOC, true); ImageInfo info1; info1.size.width = INT32_MAX; // 300 means height diff --git a/interfaces/innerkits/include/pixel_map.h b/interfaces/innerkits/include/pixel_map.h index 42e5a3b11645088bf6d490e2156af0f304c8d257..93c147a3684c89b110c32c388f6dfadc352606b4 100644 --- a/interfaces/innerkits/include/pixel_map.h +++ b/interfaces/innerkits/include/pixel_map.h @@ -319,6 +319,18 @@ public: NATIVEEXPORT virtual void SetPixelsAddr(void *addr, void *context, uint32_t size, AllocatorType type, CustomFreePixelMap func); + /** + * Set pixel buffer information. + * + * @param addr Pixel address. + * @param context Buffer descriptor. + * @param size Pixel size. + * @param type Memory type. + * @param displayOnly Whether to flush buffer. + */ + NATIVEEXPORT virtual void SetPixelsAddr(void *addr, void *context, uint32_t size, AllocatorType type, + bool displayOnly); + /** * Get pixel step size. */