gralloc4: move crop to seperate metadata type

Move crop out of PlaneLayout so it can be set and get independently
from PlaneLayout.

Bug: 141632767
Test: atest VtsHalGraphicsMapperV4_0

Change-Id: Ib685c0a065754e3e3bd697d3518b03b4c76d447e
This commit is contained in:
Marissa Wall 2020-02-07 09:51:58 -08:00
parent a22a72b286
commit b0923641d6
3 changed files with 88 additions and 38 deletions

View file

@ -107,19 +107,4 @@ parcelable PlaneLayout {
*/
long horizontalSubsampling;
long verticalSubsampling;
/**
* Some buffer producers require extra padding to their output buffer; therefore the
* physical size of the native buffer will be larger than its logical size.
* The crop rectangle determines the offset and logical size of the buffer that should be
* read by consumers.
*
* The crop rectangle is measured in samples and is relative to the offset of the
* plane. Valid crop rectangles are within the boundaries of the plane:
* [0, 0, widthInSamples, heightInSamples].
*
* The default crop rectangle is a rectangle the same size as the plane:
* [0, 0, widthInSamples, heightInSamples].
*/
Rect crop;
}

View file

@ -259,6 +259,32 @@ enum StandardMetadataType {
*/
PLANE_LAYOUTS = 15,
/**
* Can be used to get the crop of the buffer.
*
* Some buffer producers require extra padding to their output buffer; therefore the
* physical size of the native buffer will be larger than its logical size.
* The crop rectangle(s) determine the offset and logical size of the buffer that should be
* read by consumers.
*
* The crop is defined per plane. The crop(s) are represented by an array of
* android.hardware.graphics.common.Rects. The array must be the same length and in the same
* order as the array of PlaneLayouts. Eg. the first crop in the array is the crop for the
* first PlaneLayout in the PlaneLayout array.
*
* Each crop Rect is measured in samples and is relative to the offset of the plane. Valid crop
* rectangles are within the boundaries of the plane: [0, 0, widthInSamples, heightInSamples].
* The default crop rectangle of each plane is a rectangle the same size as the plane:
* [0, 0, widthInSamples, heightInSamples].
*
* When it is encoded into a byte stream, the total number of Rects is written using
* 8 bytes in little endian. It is followed by each Rect.
*
* To encode a Rect, write the following fields in this order each as 8 bytes in little endian:
* left, top, right and bottom.
*/
CROP = 16,
/**
* Can be used to get or set the dataspace of the buffer. The framework may attempt to set
* this value.
@ -273,7 +299,7 @@ enum StandardMetadataType {
* When it is encoded into a byte stream, it is first cast to a int32_t and then represented in
* the byte stream by 4 bytes written in little endian.
*/
DATASPACE = 16,
DATASPACE = 17,
/**
* Can be used to get or set the BlendMode. The framework may attempt to set this value.
@ -287,7 +313,7 @@ enum StandardMetadataType {
* When it is encoded into a byte stream, it is first cast to a int32_t and then represented by
* 4 bytes written in little endian.
*/
BLEND_MODE = 17,
BLEND_MODE = 18,
/**
* Can be used to get or set static HDR metadata specified by SMPTE ST 2086.
@ -300,7 +326,7 @@ enum StandardMetadataType {
* little endian. The ordering of float values follows the definition of Smpte2086 and XyColor.
* If this is unset when encoded into a byte stream, the byte stream is empty.
*/
SMPTE2086 = 18,
SMPTE2086 = 19,
/**
* Can be used to get or set static HDR metadata specified by CTA 861.3.
@ -313,7 +339,7 @@ enum StandardMetadataType {
* little endian. The ordering of float values follows the definition of Cta861_3.
* If this is unset when encoded into a byte stream, the byte stream is empty.
*/
CTA861_3 = 19,
CTA861_3 = 20,
/**
* Can be used to get or set dynamic HDR metadata specified by SMPTE ST 2094-40:2016.
@ -326,5 +352,5 @@ enum StandardMetadataType {
* using 8 bytes in little endian. It is followed by the uint8_t byte array.
* If this is unset when encoded into a byte stream, the byte stream is empty.
*/
SMPTE2094_40 = 20,
SMPTE2094_40 = 21,
}

View file

@ -151,11 +151,6 @@ class GraphicsMapperHidlTest
planeLayout.totalSizeInBytes);
EXPECT_EQ(1, planeLayout.horizontalSubsampling);
EXPECT_EQ(1, planeLayout.verticalSubsampling);
EXPECT_EQ(0, planeLayout.crop.left);
EXPECT_EQ(0, planeLayout.crop.top);
EXPECT_EQ(planeLayout.widthInSamples, planeLayout.crop.right);
EXPECT_EQ(planeLayout.heightInSamples, planeLayout.crop.bottom);
}
void verifyBufferDump(const IMapper::BufferDump& bufferDump,
@ -997,6 +992,22 @@ TEST_P(GraphicsMapperHidlTest, GetPlaneLayouts) {
ASSERT_NO_FATAL_FAILURE(verifyDummyDescriptorInfoPlaneLayouts(planeLayouts));
}
/**
* Test IMapper::get(Crop)
*/
TEST_P(GraphicsMapperHidlTest, GetCrop) {
auto info = mDummyDescriptorInfo;
info.format = PixelFormat::RGBA_8888;
info.usage = static_cast<uint64_t>(BufferUsage::CPU_WRITE_OFTEN | BufferUsage::CPU_READ_OFTEN);
testGet(info, gralloc4::MetadataType_Crop,
[](const IMapper::BufferDescriptorInfo& /*info*/, const hidl_vec<uint8_t>& vec) {
std::vector<aidl::android::hardware::graphics::common::Rect> crops;
ASSERT_EQ(NO_ERROR, gralloc4::decodeCrop(vec, &crops));
EXPECT_EQ(1, crops.size());
});
}
/**
* Test IMapper::get(Dataspace)
*/
@ -1104,6 +1115,8 @@ TEST_P(GraphicsMapperHidlTest, GetMetadataBadValue) {
ASSERT_EQ(Error::BAD_BUFFER,
mGralloc->get(bufferHandle, gralloc4::MetadataType_PlaneLayouts, &vec));
ASSERT_EQ(0, vec.size());
ASSERT_EQ(Error::BAD_BUFFER, mGralloc->get(bufferHandle, gralloc4::MetadataType_Crop, &vec));
ASSERT_EQ(0, vec.size());
ASSERT_EQ(Error::BAD_BUFFER,
mGralloc->get(bufferHandle, gralloc4::MetadataType_Dataspace, &vec));
ASSERT_EQ(0, vec.size());
@ -1362,10 +1375,6 @@ TEST_P(GraphicsMapperHidlTest, SetPlaneLayouts) {
planeLayoutA.totalSizeInBytes = planeLayoutA.strideInBytes * info.height;
planeLayoutA.horizontalSubsampling = 1;
planeLayoutA.verticalSubsampling = 1;
planeLayoutA.crop.left = 0;
planeLayoutA.crop.top = 0;
planeLayoutA.crop.right = info.width;
planeLayoutA.crop.bottom = info.height;
component.type = gralloc4::PlaneLayoutComponentType_A;
component.offsetInBits = 0;
@ -1382,10 +1391,6 @@ TEST_P(GraphicsMapperHidlTest, SetPlaneLayouts) {
planeLayoutRGB.totalSizeInBytes = planeLayoutRGB.strideInBytes * info.height;
planeLayoutRGB.horizontalSubsampling = 1;
planeLayoutRGB.verticalSubsampling = 1;
planeLayoutRGB.crop.left = 0;
planeLayoutRGB.crop.top = 0;
planeLayoutRGB.crop.right = info.width;
planeLayoutRGB.crop.bottom = info.height;
component.type = gralloc4::PlaneLayoutComponentType_R;
planeLayoutRGB.components.push_back(component);
@ -1423,11 +1428,6 @@ TEST_P(GraphicsMapperHidlTest, SetPlaneLayouts) {
EXPECT_EQ(planeLayout.horizontalSubsampling, realPlaneLayout.horizontalSubsampling);
EXPECT_EQ(planeLayout.verticalSubsampling, realPlaneLayout.verticalSubsampling);
EXPECT_EQ(planeLayout.crop.left, realPlaneLayout.crop.left);
EXPECT_EQ(planeLayout.crop.top, realPlaneLayout.crop.top);
EXPECT_EQ(planeLayout.crop.right, realPlaneLayout.crop.right);
EXPECT_EQ(planeLayout.crop.bottom, realPlaneLayout.crop.bottom);
ASSERT_EQ(planeLayout.components.size(), realPlaneLayout.components.size());
for (int j = 0; j < realPlaneLayout.components.size(); j++) {
@ -1442,6 +1442,26 @@ TEST_P(GraphicsMapperHidlTest, SetPlaneLayouts) {
}
}
/**
* Test IMapper::set(Crop)
*/
TEST_P(GraphicsMapperHidlTest, SetCrop) {
std::vector<aidl::android::hardware::graphics::common::Rect> crops{{0, 0, 32, 32}};
hidl_vec<uint8_t> vec;
ASSERT_EQ(NO_ERROR, gralloc4::encodeCrop(crops, &vec));
testSet(mDummyDescriptorInfo, gralloc4::MetadataType_Crop, vec,
[&](const IMapper::BufferDescriptorInfo& /*info*/, const hidl_vec<uint8_t>& vec) {
std::vector<aidl::android::hardware::graphics::common::Rect> realCrops;
ASSERT_EQ(NO_ERROR, gralloc4::decodeCrop(vec, &realCrops));
ASSERT_EQ(1, realCrops.size());
ASSERT_EQ(crops.front().left, realCrops.front().left);
ASSERT_EQ(crops.front().top, realCrops.front().top);
ASSERT_EQ(crops.front().right, realCrops.front().right);
ASSERT_EQ(crops.front().bottom, realCrops.front().bottom);
});
}
/**
* Test IMapper::set(Dataspace)
*/
@ -1589,6 +1609,7 @@ TEST_P(GraphicsMapperHidlTest, SetMetadataNullBuffer) {
mGralloc->set(bufferHandle, gralloc4::MetadataType_ChromaSiting, vec));
ASSERT_EQ(Error::BAD_BUFFER,
mGralloc->set(bufferHandle, gralloc4::MetadataType_PlaneLayouts, vec));
ASSERT_EQ(Error::BAD_BUFFER, mGralloc->set(bufferHandle, gralloc4::MetadataType_Crop, vec));
ASSERT_EQ(Error::BAD_BUFFER,
mGralloc->set(bufferHandle, gralloc4::MetadataType_Dataspace, vec));
ASSERT_EQ(Error::BAD_BUFFER,
@ -1653,6 +1674,7 @@ TEST_P(GraphicsMapperHidlTest, SetBadMetadata) {
mGralloc->set(bufferHandle, gralloc4::MetadataType_ChromaSiting, vec));
ASSERT_EQ(Error::UNSUPPORTED,
mGralloc->set(bufferHandle, gralloc4::MetadataType_PlaneLayouts, vec));
ASSERT_EQ(Error::UNSUPPORTED, mGralloc->set(bufferHandle, gralloc4::MetadataType_Crop, vec));
ASSERT_EQ(Error::UNSUPPORTED,
mGralloc->set(bufferHandle, gralloc4::MetadataType_Dataspace, vec));
ASSERT_EQ(Error::UNSUPPORTED,
@ -1866,6 +1888,23 @@ TEST_P(GraphicsMapperHidlTest, GetFromBufferDescriptorInfoPlaneLayouts) {
ASSERT_NO_FATAL_FAILURE(verifyDummyDescriptorInfoPlaneLayouts(planeLayouts));
}
/**
* Test IMapper::getFromBufferDescriptorInfo(Crop)
*/
TEST_P(GraphicsMapperHidlTest, GetFromBufferDescriptorInfoCrop) {
auto info = mDummyDescriptorInfo;
info.format = PixelFormat::RGBA_8888;
info.usage = static_cast<uint64_t>(BufferUsage::CPU_WRITE_OFTEN | BufferUsage::CPU_READ_OFTEN);
hidl_vec<uint8_t> vec;
ASSERT_EQ(Error::NONE,
mGralloc->getFromBufferDescriptorInfo(info, gralloc4::MetadataType_Crop, &vec));
std::vector<aidl::android::hardware::graphics::common::Rect> crops;
ASSERT_EQ(NO_ERROR, gralloc4::decodeCrop(vec, &crops));
EXPECT_EQ(1, crops.size());
}
/**
* Test IMapper::getFromBufferDescriptorInfo(Dataspace)
*/