已合并
feat(pixelmap): enable no-padding DMA by default with size threshold #5758
soul_like创建于 6 天前
feat(pixelmap): enable no-padding DMA by default with size threshold #5758
已合并
共 11 个文件变更+292-17
| @@ -3671,7 +3671,7 @@ static std::map<uint8_t, std::function<bool(TlvDecodeInfo&, vector<uint8_t>&, in | |||
| 3671 | } | 3671 | } |
| 3672 | if (decodeInfo.isHdr == NUM_1) { | 3672 | if (decodeInfo.isHdr == NUM_1) { |
| 3673 | decodeInfo.allocType = static_cast<int32_t>(AllocatorType::DMA_ALLOC); | 3673 | decodeInfo.allocType = static_cast<int32_t>(AllocatorType::DMA_ALLOC); |
| 3674 | } else if (ImageUtils::IsSupportDefaultDmaNopadding(decodeInfo.info.pixelFormat)) { | 3674 | } else if (ImageUtils::IsSupportDefaultDmaNopadding(decodeInfo.info.size, decodeInfo.info.pixelFormat)) { |
| 3675 | decodeInfo.allocType = static_cast<int32_t>(AllocatorType::DEFAULT); | 3675 | decodeInfo.allocType = static_cast<int32_t>(AllocatorType::DEFAULT); |
| 3676 | } | 3676 | } |
| 3677 | return true; | 3677 | return true; |
| @@ -1325,6 +1325,140 @@ HWTEST_F(ImageUtilsTest, IsSizeSupportDmaTest002, TestSize.Level3) | |||
| 1325 | GTEST_LOG_(INFO) << "ImageUtilsTest: IsSizeSupportDmaTest002 end"; | 1325 | GTEST_LOG_(INFO) << "ImageUtilsTest: IsSizeSupportDmaTest002 end"; |
| 1326 | } | 1326 | } |
| 1327 | 1327 | ||
| 1328 | /** | ||
| 1329 | * @tc.name: IsSizeSupportDmaTest003 | ||
| 1330 | * @tc.desc: test IsSizeSupportDma method with isUseDefaultDmaNopadding when size is below the 256x256 threshold | ||
| 1331 | * @tc.type: FUNC | ||
| 1332 | */ | ||
| 1333 | HWTEST_F(ImageUtilsTest, IsSizeSupportDmaTest003, TestSize.Level3) | ||
| 1334 | { | ||
| 1335 | Size size; | ||
| 1336 | size.width = 0; | ||
| 1337 | size.height = 0; | ||
| 1338 | EXPECT_FALSE(ImageUtils::IsSizeSupportDma(size, true)); | ||
| 1339 | |||
| 1340 | size.width = 0; | ||
| 1341 | size.height = 100; | ||
| 1342 | EXPECT_FALSE(ImageUtils::IsSizeSupportDma(size, true)); | ||
| 1343 | |||
| 1344 | size.width = 1; | ||
| 1345 | size.height = 1; | ||
| 1346 | EXPECT_FALSE(ImageUtils::IsSizeSupportDma(size, true)); | ||
| 1347 | |||
| 1348 | size.width = 256; | ||
| 1349 | size.height = 255; | ||
| 1350 | EXPECT_FALSE(ImageUtils::IsSizeSupportDma(size, true)); | ||
| 1351 | } | ||
| 1352 | |||
| 1353 | /** | ||
| 1354 | * @tc.name: IsSizeSupportDmaTest004 | ||
| 1355 | * @tc.desc: test IsSizeSupportDma method with isUseDefaultDmaNopadding at and above the 256x256 threshold boundary | ||
| 1356 | * @tc.type: FUNC | ||
| 1357 | */ | ||
| 1358 | HWTEST_F(ImageUtilsTest, IsSizeSupportDmaTest004, TestSize.Level3) | ||
| 1359 | { | ||
| 1360 | Size size; | ||
| 1361 | size.width = 256; | ||
| 1362 | size.height = 256; | ||
| 1363 | EXPECT_TRUE(ImageUtils::IsSizeSupportDma(size, true)); | ||
| 1364 | |||
| 1365 | size.width = 255; | ||
| 1366 | size.height = 256; | ||
| 1367 | EXPECT_FALSE(ImageUtils::IsSizeSupportDma(size, true)); | ||
| 1368 | |||
| 1369 | size.width = 1; | ||
| 1370 | size.height = 65535; | ||
| 1371 | EXPECT_FALSE(ImageUtils::IsSizeSupportDma(size, true)); | ||
| 1372 | |||
| 1373 | size.width = 1; | ||
| 1374 | size.height = 65536; | ||
| 1375 | EXPECT_TRUE(ImageUtils::IsSizeSupportDma(size, true)); | ||
| 1376 | |||
| 1377 | size.width = 512; | ||
| 1378 | size.height = 512; | ||
| 1379 | EXPECT_TRUE(ImageUtils::IsSizeSupportDma(size, true)); | ||
| 1380 | } | ||
| 1381 | |||
| 1382 | /** | ||
| 1383 | * @tc.name: IsSizeSupportDmaTest005 | ||
| 1384 | * @tc.desc: test IsSizeSupportDma method with isUseDefaultDmaNopadding when width is positive and height overflows | ||
| 1385 | * @tc.type: FUNC | ||
| 1386 | */ | ||
| 1387 | HWTEST_F(ImageUtilsTest, IsSizeSupportDmaTest005, TestSize.Level3) | ||
| 1388 | { | ||
| 1389 | Size size; | ||
| 1390 | size.width = TEST_HEIGHT_MEDIUM; | ||
| 1391 | size.height = TEST_BYTE_COUNT_LARGE; | ||
| 1392 | EXPECT_FALSE(ImageUtils::IsSizeSupportDma(size, true)); | ||
| 1393 | |||
| 1394 | size.width = 50000; | ||
| 1395 | size.height = 50000; | ||
| 1396 | EXPECT_FALSE(ImageUtils::IsSizeSupportDma(size, true)); | ||
| 1397 | } | ||
| 1398 | |||
| 1399 | /** | ||
| 1400 | * @tc.name: IsSupportDefaultDmaNopaddingTest001 | ||
| 1401 | * @tc.desc: test IsSupportDefaultDmaNopadding adapts to no-padding system property on different devices | ||
| 1402 | * @tc.type: FUNC | ||
| 1403 | */ | ||
| 1404 | HWTEST_F(ImageUtilsTest, IsSupportDefaultDmaNopaddingTest001, TestSize.Level3) | ||
| 1405 | { | ||
| 1406 | bool combinedEnabled = ImageSystemProperties::GetNoPaddingEnabled() && | ||
| 1407 | ImageSystemProperties::GetDefaultDmaNoPaddingEnabled(); | ||
| 1408 | Size size; | ||
| 1409 | size.width = 256; | ||
| 1410 | size.height = 256; | ||
| 1411 | EXPECT_EQ(ImageUtils::IsSupportDefaultDmaNopadding(size, PixelFormat::RGBA_8888), combinedEnabled); | ||
| 1412 | EXPECT_EQ(ImageUtils::IsSupportDefaultDmaNopadding(size, PixelFormat::BGRA_8888), combinedEnabled); | ||
| 1413 | EXPECT_FALSE(ImageUtils::IsSupportDefaultDmaNopadding(size, PixelFormat::RGB_565)); | ||
| 1414 | |||
| 1415 | size.width = 100; | ||
| 1416 | size.height = 100; | ||
| 1417 | EXPECT_FALSE(ImageUtils::IsSupportDefaultDmaNopadding(size, PixelFormat::RGBA_8888)); | ||
| 1418 | } | ||
| 1419 | |||
| 1420 | /** | ||
| 1421 | * @tc.name: GetPixelMapAllocatorTypeTest001 | ||
| 1422 | * @tc.desc: test GetPixelMapAllocatorType covers main DMA, no-padding DMA and SHARE_MEM branches | ||
| 1423 | * @tc.type: FUNC | ||
| 1424 | */ | ||
| 1425 | HWTEST_F(ImageUtilsTest, GetPixelMapAllocatorTypeTest001, TestSize.Level3) | ||
| 1426 | { | ||
| 1427 | bool combinedEnabled = ImageSystemProperties::GetNoPaddingEnabled() && | ||
| 1428 | ImageSystemProperties::GetDefaultDmaNoPaddingEnabled(); | ||
| 1429 | uint64_t usage = 0; | ||
| 1430 | bool isUseDefaultDmaNopadding = false; | ||
| 1431 | |||
| 1432 | Size dmaSize; | ||
| 1433 | dmaSize.width = 512; | ||
| 1434 | dmaSize.height = 512; | ||
| 1435 | usage = 0; | ||
| 1436 | AllocatorType type = ImageUtils::GetPixelMapAllocatorType(dmaSize, PixelFormat::RGBA_8888, false, usage); | ||
| 1437 | EXPECT_EQ(type, AllocatorType::DMA_ALLOC); | ||
| 1438 | |||
| 1439 | Size nopadSize; | ||
| 1440 | nopadSize.width = 256; | ||
| 1441 | nopadSize.height = 256; | ||
| 1442 | usage = 0; | ||
| 1443 | isUseDefaultDmaNopadding = false; | ||
| 1444 | type = ImageUtils::GetPixelMapAllocatorType(nopadSize, PixelFormat::BGRA_8888, false, usage, | ||
| 1445 | isUseDefaultDmaNopadding); | ||
| 1446 | if (combinedEnabled) { | ||
| 1447 | EXPECT_EQ(type, AllocatorType::DMA_ALLOC); | ||
| 1448 | EXPECT_TRUE(isUseDefaultDmaNopadding); | ||
| 1449 | } else { | ||
| 1450 | EXPECT_EQ(type, AllocatorType::SHARE_MEM_ALLOC); | ||
| 1451 | EXPECT_FALSE(isUseDefaultDmaNopadding); | ||
| 1452 | } | ||
| 1453 | |||
| 1454 | Size smallSize; | ||
| 1455 | smallSize.width = 100; | ||
| 1456 | smallSize.height = 100; | ||
| 1457 | usage = 0; | ||
| 1458 | type = ImageUtils::GetPixelMapAllocatorType(smallSize, PixelFormat::RGBA_8888, false, usage); | ||
| 1459 | EXPECT_EQ(type, AllocatorType::SHARE_MEM_ALLOC); | ||
| 1460 | } | ||
| 1461 | |||
| 1328 | /** | 1462 | /** |
| 1329 | * @tc.name: CheckMulOverflowTest011 | 1463 | * @tc.name: CheckMulOverflowTest011 |
| 1330 | * @tc.desc: test CheckMulOverflow witdh only method when size overflow | 1464 | * @tc.desc: test CheckMulOverflow witdh only method when size overflow |
| @@ -23,6 +23,7 @@ | |||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | |||
| 26 | 27 | ||
| 27 | 28 | ||
| 28 | 29 | ||
| @@ -5637,6 +5638,32 @@ HWTEST_F(PixelMapTest, HdrPixelMapTlvTest005, TestSize.Level3) | |||
| 5637 | ASSERT_NE(tlvPixelMap, nullptr); | 5638 | ASSERT_NE(tlvPixelMap, nullptr); |
| 5638 | } | 5639 | } |
| 5639 | 5640 | ||
| 5641 | /** | ||
| 5642 | * @tc.name: PixelMapTlvNopaddingDmaTest001 | ||
| 5643 | * @tc.desc: test DecodeTlv re-derives allocator via no-padding DMA DEFAULT branch | ||
| 5644 | * @tc.type: FUNC | ||
| 5645 | */ | ||
| 5646 | HWTEST_F(PixelMapTest, PixelMapTlvNopaddingDmaTest001, TestSize.Level3) | ||
| 5647 | { | ||
| 5648 | GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTlvNopaddingDmaTest001 start"; | ||
| 5649 | bool combinedEnabled = ImageSystemProperties::GetNoPaddingEnabled() && | ||
| 5650 | ImageSystemProperties::GetDefaultDmaNoPaddingEnabled(); | ||
| 5651 | InitializationOptions opts; | ||
| 5652 | opts.size.width = 512; | ||
| 5653 | opts.size.height = 512; | ||
| 5654 | opts.pixelFormat = PixelFormat::RGBA_8888; | ||
| 5655 | opts.allocatorType = AllocatorType::HEAP_ALLOC; | ||
| 5656 | std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(opts); | ||
| 5657 | ASSERT_NE(pixelMap, nullptr); | ||
| 5658 | vector<uint8_t> buff; | ||
| 5659 | ASSERT_TRUE(pixelMap->EncodeTlv(buff)); | ||
| 5660 | std::unique_ptr<PixelMap> tlvPixelMap(PixelMap::DecodeTlv(buff)); | ||
| 5661 | ASSERT_NE(tlvPixelMap, nullptr); | ||
| 5662 | EXPECT_EQ(tlvPixelMap->GetAllocatorType(), | ||
| 5663 | combinedEnabled ? AllocatorType::DMA_ALLOC : AllocatorType::HEAP_ALLOC); | ||
| 5664 | GTEST_LOG_(INFO) << "PixelMapTest: PixelMapTlvNopaddingDmaTest001 end"; | ||
| 5665 | } | ||
| 5666 | |||
| 5640 | /** | 5667 | /** |
| 5641 | * @tc.name: HdrPixelMapTlvTest006 | 5668 | * @tc.name: HdrPixelMapTlvTest006 |
| 5642 | * @tc.desc: Test HdrPixelMapTlvTest | 5669 | * @tc.desc: Test HdrPixelMapTlvTest |
| @@ -6450,5 +6477,25 @@ HWTEST_F(PixelMapTest, FlushCacheTest001, TestSize.Level3) | |||
| 6450 | pixelMap->isUseDefaultDmaNopadding_ = false; | 6477 | pixelMap->isUseDefaultDmaNopadding_ = false; |
| 6451 | GTEST_LOG_(INFO) << "PixelMapTest: FlushCacheTest001 end"; | 6478 | GTEST_LOG_(INFO) << "PixelMapTest: FlushCacheTest001 end"; |
| 6452 | } | 6479 | } |
| 6480 | |||
| 6481 | /** | ||
| 6482 | * @tc.name: IsUseDefaultDmaNopaddingTest001 | ||
| 6483 | * @tc.desc: test IsUseDefaultDmaNopadding accessor reflects the member flag state | ||
| 6484 | * @tc.type: FUNC | ||
| 6485 | */ | ||
| 6486 | HWTEST_F(PixelMapTest, IsUseDefaultDmaNopaddingTest001, TestSize.Level3) | ||
| 6487 | { | ||
| 6488 | GTEST_LOG_(INFO) << "PixelMapTest: IsUseDefaultDmaNopaddingTest001 start"; | ||
| 6489 | auto pixelMap = ConstructPixmap(AllocatorType::SHARE_MEM_ALLOC); | ||
| 6490 | ASSERT_NE(nullptr, pixelMap); | ||
| 6491 | EXPECT_FALSE(pixelMap->IsUseDefaultDmaNopadding()); | ||
| 6492 | |||
| 6493 | pixelMap->isUseDefaultDmaNopadding_ = true; | ||
| 6494 | EXPECT_TRUE(pixelMap->IsUseDefaultDmaNopadding()); | ||
| 6495 | |||
| 6496 | pixelMap->isUseDefaultDmaNopadding_ = false; | ||
| 6497 | EXPECT_FALSE(pixelMap->IsUseDefaultDmaNopadding()); | ||
| 6498 | GTEST_LOG_(INFO) << "PixelMapTest: IsUseDefaultDmaNopaddingTest001 end"; | ||
| 6499 | } | ||
| 6453 | } | 6500 | } |
| 6454 | } | 6501 | } |
| @@ -3102,5 +3102,84 @@ HWTEST_F(PixelMapNdk2Test, OH_PixelmapNative_ConvertAlphaType_Failure, TestSize. | |||
| 3102 | 3102 | ||
| 3103 | GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_ConvertAlphaType_Failure end"; | 3103 | GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_ConvertAlphaType_Failure end"; |
| 3104 | } | 3104 | } |
| 3105 | |||
| 3106 | /** | ||
| 3107 | * @tc.name: OH_PixelmapNative_SetMetadata_NopaddingDma001 | ||
| 3108 | * @tc.desc: test OH_PixelmapNative_SetMetadata returns IMAGE_DMA_NOT_EXIST when PixelMap is no-padding DMA | ||
| 3109 | * @tc.type: FUNC | ||
| 3110 | */ | ||
| 3111 | HWTEST_F(PixelMapNdk2Test, OH_PixelmapNative_SetMetadata_NopaddingDma001, TestSize.Level3) | ||
| 3112 | { | ||
| 3113 | GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_SetMetadata_NopaddingDma001 start"; | ||
| 3114 | OH_PixelmapNative* pixelmap = CreateEmptyPixelmapNativeForTest(); | ||
| 3115 | ASSERT_NE(pixelmap, nullptr); | ||
| 3116 | auto inner = pixelmap->GetInnerPixelmap(); | ||
| 3117 | ASSERT_NE(inner, nullptr); | ||
| 3118 | AllocatorType origType = inner->allocatorType_; | ||
| 3119 | inner->allocatorType_ = AllocatorType::DMA_ALLOC; | ||
| 3120 | inner->isUseDefaultDmaNopadding_ = true; | ||
| 3121 | |||
| 3122 | OH_Pixelmap_HdrMetadataValue value; | ||
| 3123 | Image_ErrorCode ret = OH_PixelmapNative_SetMetadata(pixelmap, OH_Pixelmap_HdrMetadataKey(ZERO), &value); | ||
| 3124 | EXPECT_EQ(ret, IMAGE_DMA_NOT_EXIST); | ||
| 3125 | |||
| 3126 | inner->isUseDefaultDmaNopadding_ = false; | ||
| 3127 | inner->allocatorType_ = origType; | ||
| 3128 | OH_PixelmapNative_Destroy(&pixelmap); | ||
| 3129 | GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_SetMetadata_NopaddingDma001 end"; | ||
| 3130 | } | ||
| 3131 | |||
| 3132 | /** | ||
| 3133 | * @tc.name: OH_PixelmapNative_GetMetadata_NopaddingDma001 | ||
| 3134 | * @tc.desc: test OH_PixelmapNative_GetMetadata returns IMAGE_DMA_NOT_EXIST when PixelMap is no-padding DMA | ||
| 3135 | * @tc.type: FUNC | ||
| 3136 | */ | ||
| 3137 | HWTEST_F(PixelMapNdk2Test, OH_PixelmapNative_GetMetadata_NopaddingDma001, TestSize.Level3) | ||
| 3138 | { | ||
| 3139 | GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_GetMetadata_NopaddingDma001 start"; | ||
| 3140 | OH_PixelmapNative* pixelmap = CreateEmptyPixelmapNativeForTest(); | ||
| 3141 | ASSERT_NE(pixelmap, nullptr); | ||
| 3142 | auto inner = pixelmap->GetInnerPixelmap(); | ||
| 3143 | ASSERT_NE(inner, nullptr); | ||
| 3144 | AllocatorType origType = inner->allocatorType_; | ||
| 3145 | inner->allocatorType_ = AllocatorType::DMA_ALLOC; | ||
| 3146 | inner->isUseDefaultDmaNopadding_ = true; | ||
| 3147 | |||
| 3148 | OH_Pixelmap_HdrMetadataValue value; | ||
| 3149 | OH_Pixelmap_HdrMetadataValue* valuePtr = &value; | ||
| 3150 | Image_ErrorCode ret = OH_PixelmapNative_GetMetadata(pixelmap, OH_Pixelmap_HdrMetadataKey(ZERO), &valuePtr); | ||
| 3151 | EXPECT_EQ(ret, IMAGE_DMA_NOT_EXIST); | ||
| 3152 | |||
| 3153 | inner->isUseDefaultDmaNopadding_ = false; | ||
| 3154 | inner->allocatorType_ = origType; | ||
| 3155 | OH_PixelmapNative_Destroy(&pixelmap); | ||
| 3156 | GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_GetMetadata_NopaddingDma001 end"; | ||
| 3157 | } | ||
| 3158 | |||
| 3159 | /** | ||
| 3160 | * @tc.name: OH_PixelmapNative_GetNativeBuffer_NopaddingDma001 | ||
| 3161 | * @tc.desc: test OH_PixelmapNative_GetNativeBuffer returns IMAGE_DMA_NOT_EXIST when PixelMap is no-padding DMA | ||
| 3162 | * @tc.type: FUNC | ||
| 3163 | */ | ||
| 3164 | HWTEST_F(PixelMapNdk2Test, OH_PixelmapNative_GetNativeBuffer_NopaddingDma001, TestSize.Level3) | ||
| 3165 | { | ||
| 3166 | GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_GetNativeBuffer_NopaddingDma001 start"; | ||
| 3167 | OH_PixelmapNative* pixelmap = CreateEmptyPixelmapNativeForTest(); | ||
| 3168 | ASSERT_NE(pixelmap, nullptr); | ||
| 3169 | auto inner = pixelmap->GetInnerPixelmap(); | ||
| 3170 | ASSERT_NE(inner, nullptr); | ||
| 3171 | AllocatorType origType = inner->allocatorType_; | ||
| 3172 | inner->allocatorType_ = AllocatorType::DMA_ALLOC; | ||
| 3173 | inner->isUseDefaultDmaNopadding_ = true; | ||
| 3174 | |||
| 3175 | OH_NativeBuffer* nativeBuffer = nullptr; | ||
| 3176 | Image_ErrorCode ret = OH_PixelmapNative_GetNativeBuffer(pixelmap, &nativeBuffer); | ||
| 3177 | EXPECT_EQ(ret, IMAGE_DMA_NOT_EXIST); | ||
| 3178 | |||
| 3179 | inner->isUseDefaultDmaNopadding_ = false; | ||
| 3180 | inner->allocatorType_ = origType; | ||
| 3181 | OH_PixelmapNative_Destroy(&pixelmap); | ||
| 3182 | GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_GetNativeBuffer_NopaddingDma001 end"; | ||
| 3183 | } | ||
| 3105 | } | 3184 | } |
| 3106 | } | 3185 | } |
| @@ -136,9 +136,9 @@ public: | |||
| 136 | static bool IsValidAuxiliaryInfo(const std::shared_ptr<PixelMap> &pixelMap, const AuxiliaryPictureInfo &info); | 136 | static bool IsValidAuxiliaryInfo(const std::shared_ptr<PixelMap> &pixelMap, const AuxiliaryPictureInfo &info); |
| 137 | static bool IsAstc(PixelFormat format); | 137 | static bool IsAstc(PixelFormat format); |
| 138 | static bool IsWidthAligned(const int32_t &width); | 138 | static bool IsWidthAligned(const int32_t &width); |
| 139 | static bool IsSizeSupportDma(const Size &size); | 139 | static bool IsSizeSupportDma(const Size &size, bool isUseDefaultDmaNopadding = false); |
| 140 | static bool IsFormatSupportDma(const PixelFormat &format); | 140 | static bool IsFormatSupportDma(const PixelFormat &format); |
| 141 | static bool IsSupportDefaultDmaNopadding(const PixelFormat &format); | 141 | static bool IsSupportDefaultDmaNopadding(const Size &size, const PixelFormat &format); |
| 142 | static bool Is10Bit(const PixelFormat &format); | 142 | static bool Is10Bit(const PixelFormat &format); |
| 143 | static MultimediaPlugin::PluginServer& GetPluginServer(); | 143 | static MultimediaPlugin::PluginServer& GetPluginServer(); |
| 144 | static bool CheckMulOverflow(int32_t width, int32_t bytesPerPixel); | 144 | static bool CheckMulOverflow(int32_t width, int32_t bytesPerPixel); |
| @@ -241,7 +241,7 @@ bool ImageSystemProperties::GetNoPaddingEnabled() | |||
| 241 | bool ImageSystemProperties::GetDefaultDmaNoPaddingEnabled() | 241 | bool ImageSystemProperties::GetDefaultDmaNoPaddingEnabled() |
| 242 | { | 242 | { |
| 243 | 243 | ||
| 244 | static bool ret = system::GetBoolParameter("persist.multimedia.defaultDmaNopadding.enabled", false); | 244 | static bool ret = system::GetBoolParameter("persist.multimedia.defaultDmaNopadding.enabled", true); |
| 245 | return ret; | 245 | return ret; |
| 246 | 246 | ||
| 247 | return false; | 247 | return false; |
| @@ -126,6 +126,7 @@ constexpr int32_t ASTC_HEADER_SIZE = 16; | |||
| 126 | constexpr uint8_t FILL_NUMBER = 3; | 126 | constexpr uint8_t FILL_NUMBER = 3; |
| 127 | constexpr uint8_t ALIGN_NUMBER = 4; | 127 | constexpr uint8_t ALIGN_NUMBER = 4; |
| 128 | constexpr int32_t DMA_SIZE = 512 * 512; // DMA minimum effective size | 128 | constexpr int32_t DMA_SIZE = 512 * 512; // DMA minimum effective size |
| 129 | constexpr int32_t NOPADDING_DMA_SIZE = 256 * 256; | ||
| 129 | constexpr int32_t FAULT_API_VERSION = -1; | 130 | constexpr int32_t FAULT_API_VERSION = -1; |
| 130 | constexpr int32_t BUNDLE_MGR_SERVICE_SYS_ABILITY_ID = 401; | 131 | constexpr int32_t BUNDLE_MGR_SERVICE_SYS_ABILITY_ID = 401; |
| 131 | constexpr int32_t BASE_EVEN_DIVISOR = 2; | 132 | constexpr int32_t BASE_EVEN_DIVISOR = 2; |
| @@ -552,7 +553,7 @@ AllocatorType ImageUtils::GetPixelMapAllocatorType(const Size &size, const Pixel | |||
| 552 | if (IsSizeSupportDma(size) && (preferDma || (IsWidthAligned(size.width) && IsFormatSupportDma(format))) && | 553 | if (IsSizeSupportDma(size) && (preferDma || (IsWidthAligned(size.width) && IsFormatSupportDma(format))) && |
| 553 | (format == PixelFormat::RGBA_8888 || format == PixelFormat::ALPHA_F16 || Is10Bit(format))) { | 554 | (format == PixelFormat::RGBA_8888 || format == PixelFormat::ALPHA_F16 || Is10Bit(format))) { |
| 554 | return AllocatorType::DMA_ALLOC; | 555 | return AllocatorType::DMA_ALLOC; |
| 555 | } else if (IsSupportDefaultDmaNopadding(format)) { | 556 | } else if (IsSupportDefaultDmaNopadding(size, format)) { |
| 556 | usage |= BUFFER_USAGE_PREFER_NO_PADDING | BUFFER_USAGE_ALLOC_NO_IPC; | 557 | usage |= BUFFER_USAGE_PREFER_NO_PADDING | BUFFER_USAGE_ALLOC_NO_IPC; |
| 557 | isUseDefaultDmaNopadding = true; | 558 | isUseDefaultDmaNopadding = true; |
| 558 | return AllocatorType::DMA_ALLOC; | 559 | return AllocatorType::DMA_ALLOC; |
| @@ -666,13 +667,14 @@ bool ImageUtils::IsWidthAligned(const int32_t &width) | |||
| 666 | return ((static_cast<uint32_t>(width) * NUM_4) & INT_255) == 0; | 667 | return ((static_cast<uint32_t>(width) * NUM_4) & INT_255) == 0; |
| 667 | } | 668 | } |
| 668 | 669 | ||
| 669 | bool ImageUtils::IsSizeSupportDma(const Size &size) | 670 | bool ImageUtils::IsSizeSupportDma(const Size &size, bool isUseDefaultDmaNopadding) |
| 670 | { | 671 | { |
| 671 | // Check for overflow risk | 672 | // Check for overflow risk |
| 672 | if (size.width > 0 && size.height > INT_MAX / size.width) { | 673 | if (size.width > 0 && size.height > INT_MAX / size.width) { |
| 673 | return false; | 674 | return false; |
| 674 | } | 675 | } |
| 675 | return size.width * size.height >= DMA_SIZE; | 676 | int32_t minSize = isUseDefaultDmaNopadding ? NOPADDING_DMA_SIZE : DMA_SIZE; |
| 677 | return size.width * size.height >= minSize; | ||
| 676 | } | 678 | } |
| 677 | 679 | ||
| 678 | bool ImageUtils::IsFormatSupportDma(const PixelFormat &format) | 680 | bool ImageUtils::IsFormatSupportDma(const PixelFormat &format) |
| @@ -680,10 +682,10 @@ bool ImageUtils::IsFormatSupportDma(const PixelFormat &format) | |||
| 680 | return format == PixelFormat::UNKNOWN || format == PixelFormat::RGBA_8888 || format == PixelFormat::ALPHA_F16; | 682 | return format == PixelFormat::UNKNOWN || format == PixelFormat::RGBA_8888 || format == PixelFormat::ALPHA_F16; |
| 681 | } | 683 | } |
| 682 | 684 | ||
| 683 | bool ImageUtils::IsSupportDefaultDmaNopadding(const PixelFormat &format) | 685 | bool ImageUtils::IsSupportDefaultDmaNopadding(const Size &size, const PixelFormat &format) |
| 684 | { | 686 | { |
| 685 | if (ImageSystemProperties::GetDefaultDmaNoPaddingEnabled() && ImageSystemProperties::GetNoPaddingEnabled() && | 687 | if (ImageSystemProperties::GetDefaultDmaNoPaddingEnabled() && ImageSystemProperties::GetNoPaddingEnabled() && |
| 686 | (format == PixelFormat::BGRA_8888 || format == PixelFormat::RGBA_8888)) { | 688 | IsSizeSupportDma(size, true) && (format == PixelFormat::BGRA_8888 || format == PixelFormat::RGBA_8888)) { |
| 687 | return true; | 689 | return true; |
| 688 | } | 690 | } |
| 689 | return false; | 691 | return false; |
| @@ -6976,7 +6976,8 @@ napi_value PixelMapNapi::GetMetadata(napi_env env, napi_callback_info info) | |||
| 6976 | return ImageNapiUtils::ThrowExceptionError(env, COMMON_ERR_INVALID_PARAMETER, "Fail to unwrap context"); | 6976 | return ImageNapiUtils::ThrowExceptionError(env, COMMON_ERR_INVALID_PARAMETER, "Fail to unwrap context"); |
| 6977 | } | 6977 | } |
| 6978 | std::shared_ptr<PixelMap> pixelMap = nVal.context->nConstructor->nativePixelMap_; | 6978 | std::shared_ptr<PixelMap> pixelMap = nVal.context->nConstructor->nativePixelMap_; |
| 6979 | if (pixelMap->GetAllocatorType() != AllocatorType::DMA_ALLOC) { | 6979 | if (pixelMap->GetAllocatorType() != AllocatorType::DMA_ALLOC || |
| 6980 | pixelMap->IsUseDefaultDmaNopadding()) { | ||
| 6980 | return ImageNapiUtils::ThrowExceptionError(env, ERR_DMA_NOT_EXIST, "Not DMA memory"); | 6981 | return ImageNapiUtils::ThrowExceptionError(env, ERR_DMA_NOT_EXIST, "Not DMA memory"); |
| 6981 | } | 6982 | } |
| 6982 | 6983 | ||
| @@ -7276,7 +7277,8 @@ napi_value PixelMapNapi::SetMetadataSync(napi_env env, napi_callback_info info) | |||
| 7276 | env, ERR_IMAGE_INVALID_PARAMETER, "Invalid parameter"); | 7277 | env, ERR_IMAGE_INVALID_PARAMETER, "Invalid parameter"); |
| 7277 | } | 7278 | } |
| 7278 | std::shared_ptr<PixelMap> pixelMap = nVal.context->nConstructor->nativePixelMap_; | 7279 | std::shared_ptr<PixelMap> pixelMap = nVal.context->nConstructor->nativePixelMap_; |
| 7279 | if (pixelMap->GetAllocatorType() != AllocatorType::DMA_ALLOC) { | 7280 | if (pixelMap->GetAllocatorType() != AllocatorType::DMA_ALLOC || |
| 7281 | pixelMap->IsUseDefaultDmaNopadding()) { | ||
| 7280 | return ImageNapiUtils::ThrowExceptionError( | 7282 | return ImageNapiUtils::ThrowExceptionError( |
| 7281 | env, ERR_DMA_NOT_EXIST, "Not DMA memory"); | 7283 | env, ERR_DMA_NOT_EXIST, "Not DMA memory"); |
| 7282 | } | 7284 | } |
| @@ -7317,7 +7319,8 @@ napi_value PixelMapNapi::SetMetadata(napi_env env, napi_callback_info info) | |||
| 7317 | nVal.context->status = ERR_IMAGE_INVALID_PARAMETER; | 7319 | nVal.context->status = ERR_IMAGE_INVALID_PARAMETER; |
| 7318 | } | 7320 | } |
| 7319 | nVal.context->rPixelMap = nVal.context->nConstructor->nativePixelMap_; | 7321 | nVal.context->rPixelMap = nVal.context->nConstructor->nativePixelMap_; |
| 7320 | if (nVal.context->rPixelMap->GetAllocatorType() != AllocatorType::DMA_ALLOC) { | 7322 | if (nVal.context->rPixelMap->GetAllocatorType() != AllocatorType::DMA_ALLOC || |
| 7323 | nVal.context->rPixelMap->IsUseDefaultDmaNopadding()) { | ||
| 7321 | nVal.context->status = ERR_DMA_NOT_EXIST; | 7324 | nVal.context->status = ERR_DMA_NOT_EXIST; |
| 7322 | } | 7325 | } |
| 7323 | if (nVal.context->status == napi_ok) { | 7326 | if (nVal.context->status == napi_ok) { |
| @@ -1528,7 +1528,8 @@ Image_ErrorCode OH_PixelmapNative_SetMetadata(OH_PixelmapNative *pixelmap, OH_Pi | |||
| 1528 | return IMAGE_BAD_PARAMETER; | 1528 | return IMAGE_BAD_PARAMETER; |
| 1529 | } | 1529 | } |
| 1530 | 1530 | ||
| 1531 | if (pixelmap->GetInnerPixelmap()->GetAllocatorType() != AllocatorType::DMA_ALLOC) { | 1531 | if (pixelmap->GetInnerPixelmap()->GetAllocatorType() != AllocatorType::DMA_ALLOC || |
| 1532 | pixelmap->GetInnerPixelmap()->IsUseDefaultDmaNopadding()) { | ||
| 1532 | return IMAGE_DMA_NOT_EXIST; | 1533 | return IMAGE_DMA_NOT_EXIST; |
| 1533 | } | 1534 | } |
| 1534 | 1535 | ||
| @@ -1664,7 +1665,8 @@ Image_ErrorCode OH_PixelmapNative_GetMetadata(OH_PixelmapNative *pixelmap, OH_Pi | |||
| 1664 | return IMAGE_BAD_PARAMETER; | 1665 | return IMAGE_BAD_PARAMETER; |
| 1665 | } | 1666 | } |
| 1666 | 1667 | ||
| 1667 | if (pixelmap->GetInnerPixelmap()->GetAllocatorType() != AllocatorType::DMA_ALLOC) { | 1668 | if (pixelmap->GetInnerPixelmap()->GetAllocatorType() != AllocatorType::DMA_ALLOC || |
| 1669 | pixelmap->GetInnerPixelmap()->IsUseDefaultDmaNopadding()) { | ||
| 1668 | return IMAGE_DMA_NOT_EXIST; | 1670 | return IMAGE_DMA_NOT_EXIST; |
| 1669 | } | 1671 | } |
| 1670 | 1672 | ||
| @@ -1683,7 +1685,8 @@ Image_ErrorCode OH_PixelmapNative_GetNativeBuffer(OH_PixelmapNative *pixelmap, O | |||
| 1683 | return IMAGE_BAD_PARAMETER; | 1685 | return IMAGE_BAD_PARAMETER; |
| 1684 | } | 1686 | } |
| 1685 | 1687 | ||
| 1686 | if (pixelmap->GetInnerPixelmap()->GetAllocatorType() != AllocatorType::DMA_ALLOC) { | 1688 | if (pixelmap->GetInnerPixelmap()->GetAllocatorType() != AllocatorType::DMA_ALLOC || |
| 1689 | pixelmap->GetInnerPixelmap()->IsUseDefaultDmaNopadding()) { | ||
| 1687 | return IMAGE_DMA_NOT_EXIST; | 1690 | return IMAGE_DMA_NOT_EXIST; |
| 1688 | } | 1691 | } |
| 1689 | 1692 | ||
| @@ -1713,7 +1713,8 @@ HdrMetadataValue PixelMapImpl::GetMetadata(HdrMetadataKey key) | |||
| 1713 | ImageTaiheUtils::ThrowExceptionError(Media::COMMON_ERR_INVALID_PARAMETER, "Native PixelMap has been released."); | 1713 | ImageTaiheUtils::ThrowExceptionError(Media::COMMON_ERR_INVALID_PARAMETER, "Native PixelMap has been released."); |
| 1714 | return HdrMetadataValue::make_hdrMetadataType(HdrMetadataType::key_t::NONE); | 1714 | return HdrMetadataValue::make_hdrMetadataType(HdrMetadataType::key_t::NONE); |
| 1715 | } | 1715 | } |
| 1716 | if (nativePixelMap_->GetAllocatorType() != Media::AllocatorType::DMA_ALLOC) { | 1716 | if (nativePixelMap_->GetAllocatorType() != Media::AllocatorType::DMA_ALLOC || |
| 1717 | nativePixelMap_->IsUseDefaultDmaNopadding()) { | ||
| 1717 | ImageTaiheUtils::ThrowExceptionError(Media::ERR_DMA_NOT_EXIST, "PixelMap memory type is not DMA memory."); | 1718 | ImageTaiheUtils::ThrowExceptionError(Media::ERR_DMA_NOT_EXIST, "PixelMap memory type is not DMA memory."); |
| 1718 | return HdrMetadataValue::make_hdrMetadataType(HdrMetadataType::key_t::NONE); | 1719 | return HdrMetadataValue::make_hdrMetadataType(HdrMetadataType::key_t::NONE); |
| 1719 | } | 1720 | } |
| @@ -1756,7 +1757,8 @@ void PixelMapImpl::SetMetadataSync(HdrMetadataKey key, HdrMetadataValue const& v | |||
| 1756 | ImageTaiheUtils::ThrowExceptionError(Media::ERR_IMAGE_INVALID_PARAMETER, "Native PixelMap has been released."); | 1757 | ImageTaiheUtils::ThrowExceptionError(Media::ERR_IMAGE_INVALID_PARAMETER, "Native PixelMap has been released."); |
| 1757 | return; | 1758 | return; |
| 1758 | } | 1759 | } |
| 1759 | if (nativePixelMap_->GetAllocatorType() != Media::AllocatorType::DMA_ALLOC) { | 1760 | if (nativePixelMap_->GetAllocatorType() != Media::AllocatorType::DMA_ALLOC || |
| 1761 | nativePixelMap_->IsUseDefaultDmaNopadding()) { | ||
| 1760 | ImageTaiheUtils::ThrowExceptionError(Media::ERR_DMA_NOT_EXIST, "PixelMap memory type is not DMA memory."); | 1762 | ImageTaiheUtils::ThrowExceptionError(Media::ERR_DMA_NOT_EXIST, "PixelMap memory type is not DMA memory."); |
| 1761 | return; | 1763 | return; |
| 1762 | } | 1764 | } |
| @@ -921,6 +921,11 @@ public: | |||
| 921 | editable_ = editable; | 921 | editable_ = editable; |
| 922 | } | 922 | } |
| 923 | 923 | ||
| 924 | NATIVEEXPORT bool IsUseDefaultDmaNopadding() const | ||
| 925 | { | ||
| 926 | return isUseDefaultDmaNopadding_; | ||
| 927 | } | ||
| 928 | |||
| 924 | NATIVEEXPORT void FlushCache() const; | 929 | NATIVEEXPORT void FlushCache() const; |
| 925 | 930 | ||
| 926 | static int32_t GetRGBxRowDataSize(const ImageInfo& info); | 931 | static int32_t GetRGBxRowDataSize(const ImageInfo& info); |