From f4d374a7587e0109c8ff541ece13900150a258b3 Mon Sep 17 00:00:00 2001 From: Yichi Chen Date: Tue, 28 Apr 2020 21:52:20 +0800 Subject: [PATCH] gralloc4-vts: Extract YCbCr888 data operation from Lock_YCRCB_420_SP The patch extracts the common operation on YCbCr888 data to allow a better reuse in tests with other YCbCr color formats Bug: 150461327 Bug: 152510209 Test: VtsHalGraphicsMapperV4_0Target Change-Id: I530f6d895c338fb041f7705aa9a4fd36931a1588 --- .../VtsHalGraphicsMapperV4_0TargetTest.cpp | 99 ++++++++++--------- 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/graphics/mapper/4.0/vts/functional/VtsHalGraphicsMapperV4_0TargetTest.cpp b/graphics/mapper/4.0/vts/functional/VtsHalGraphicsMapperV4_0TargetTest.cpp index f5c4cb9942..77ed3cb885 100644 --- a/graphics/mapper/4.0/vts/functional/VtsHalGraphicsMapperV4_0TargetTest.cpp +++ b/graphics/mapper/4.0/vts/functional/VtsHalGraphicsMapperV4_0TargetTest.cpp @@ -277,7 +277,7 @@ class GraphicsMapperHidlTest } } - void verifyRGBA8888(const native_handle_t* bufferHandle, uint8_t* data, uint32_t height, + void verifyRGBA8888(const native_handle_t* bufferHandle, const uint8_t* data, uint32_t height, size_t strideInBytes, size_t widthInBytes, uint32_t seed = 0) { hidl_vec vec; ASSERT_EQ(Error::NONE, @@ -295,6 +295,49 @@ class GraphicsMapperHidlTest } } + void traverseYCbCr888Data(const android_ycbcr& yCbCr, int32_t width, int32_t height, + int64_t hSubsampling, int64_t vSubsampling, + std::function traverseFuncion) { + auto yData = static_cast(yCbCr.y); + auto cbData = static_cast(yCbCr.cb); + auto crData = static_cast(yCbCr.cr); + auto yStride = yCbCr.ystride; + auto cStride = yCbCr.cstride; + auto chromaStep = yCbCr.chroma_step; + + for (uint32_t y = 0; y < height; y++) { + for (uint32_t x = 0; x < width; x++) { + auto val = static_cast(height * y + x); + + traverseFuncion(yData + yStride * y + x, val); + + if (y % vSubsampling == 0 && x % hSubsampling == 0) { + uint32_t subSampleX = x / hSubsampling; + uint32_t subSampleY = y / vSubsampling; + const auto subSampleOffset = cStride * subSampleY + chromaStep * subSampleX; + const auto subSampleVal = + static_cast(height * subSampleY + subSampleX); + + traverseFuncion(cbData + subSampleOffset, subSampleVal); + traverseFuncion(crData + subSampleOffset, subSampleVal + 1); + } + } + } + } + + void fillYCbCr888Data(const android_ycbcr& yCbCr, int32_t width, int32_t height, + int64_t hSubsampling, int64_t vSubsampling) { + traverseYCbCr888Data(yCbCr, width, height, hSubsampling, vSubsampling, + [](auto address, auto fillingData) { *address = fillingData; }); + } + + void verifyYCbCr888Data(const android_ycbcr& yCbCr, int32_t width, int32_t height, + int64_t hSubsampling, int64_t vSubsampling) { + traverseYCbCr888Data( + yCbCr, width, height, hSubsampling, vSubsampling, + [](auto address, auto expectedData) { EXPECT_EQ(*address, expectedData); }); + } + bool isEqual(float a, float b) { return abs(a - b) < 0.0001; } std::unique_ptr mGralloc; @@ -591,37 +634,16 @@ TEST_P(GraphicsMapperHidlTest, Lock_YCRCB_420_SP) { ASSERT_NO_FATAL_FAILURE( getAndroidYCbCr(bufferHandle, data, &yCbCr, &hSubsampling, &vSubsampling)); - auto yData = static_cast(yCbCr.y); - auto cbData = static_cast(yCbCr.cb); - auto crData = static_cast(yCbCr.cr); - auto yStride = yCbCr.ystride; - auto cStride = yCbCr.cstride; - auto chromaStep = yCbCr.chroma_step; - constexpr uint32_t kCbCrSubSampleFactor = 2; - ASSERT_EQ(crData + 1, cbData); - ASSERT_EQ(2, chromaStep); ASSERT_EQ(kCbCrSubSampleFactor, hSubsampling); ASSERT_EQ(kCbCrSubSampleFactor, vSubsampling); - for (uint32_t y = 0; y < info.height; y++) { - for (uint32_t x = 0; x < info.width; x++) { - auto val = static_cast(info.height * y + x); + auto cbData = static_cast(yCbCr.cb); + auto crData = static_cast(yCbCr.cr); + ASSERT_EQ(crData + 1, cbData); + ASSERT_EQ(2, yCbCr.chroma_step); - yData[yStride * y + x] = val; - - if (y % vSubsampling == 0 && x % hSubsampling == 0) { - uint32_t subSampleX = x / hSubsampling; - uint32_t subSampleY = y / vSubsampling; - const auto subSampleOffset = cStride * subSampleY + chromaStep * subSampleX; - const auto subSampleVal = - static_cast(info.height * subSampleY + subSampleX); - - cbData[subSampleOffset] = subSampleVal; - crData[subSampleOffset] = subSampleVal + 1; - } - } - } + fillYCbCr888Data(yCbCr, info.width, info.height, hSubsampling, vSubsampling); ASSERT_NO_FATAL_FAILURE(fence = mGralloc->unlock(bufferHandle)); @@ -632,28 +654,7 @@ TEST_P(GraphicsMapperHidlTest, Lock_YCRCB_420_SP) { ASSERT_NO_FATAL_FAILURE( getAndroidYCbCr(bufferHandle, data, &yCbCr, &hSubsampling, &vSubsampling)); - yData = static_cast(yCbCr.y); - cbData = static_cast(yCbCr.cb); - crData = static_cast(yCbCr.cr); - - for (uint32_t y = 0; y < info.height; y++) { - for (uint32_t x = 0; x < info.width; x++) { - auto val = static_cast(info.height * y + x); - - EXPECT_EQ(val, yData[yStride * y + x]); - - if (y % vSubsampling == 0 && x % hSubsampling == 0) { - uint32_t subSampleX = x / hSubsampling; - uint32_t subSampleY = y / vSubsampling; - const auto subSampleOffset = cStride * subSampleY + chromaStep * subSampleX; - const auto subSampleVal = - static_cast(info.height * subSampleY + subSampleX); - - EXPECT_EQ(subSampleVal, cbData[subSampleOffset]); - EXPECT_EQ(subSampleVal + 1, crData[subSampleOffset]); - } - } - } + verifyYCbCr888Data(yCbCr, info.width, info.height, hSubsampling, vSubsampling); ASSERT_NO_FATAL_FAILURE(fence = mGralloc->unlock(bufferHandle)); if (fence >= 0) {