C2AllocatorGralloc: Limit Gralloc4Mapper_lock to T and above
Gralloc4Mapper_lock() returns few wrong parameters when called
on few devices running older Android versions as part of mainline
module.
Since this function was added in Android T to support vendor P010
format and P010 support is Android T and above, this function is
now limited to devices running Android T and above.
Bug: 237366327
Test: atest CtsMediaCodecTestCases:EncodeVirtualDisplayTest \
CtsMediaV2TestCases:android.mediav2.cts.CodecEncoderSurfaceTest
Change-Id: I58590098d47bb3eb6d871235c200a5bb82faed25
diff --git a/media/codec2/vndk/C2AllocatorGralloc.cpp b/media/codec2/vndk/C2AllocatorGralloc.cpp
index bc4053d..a4a9b3a 100644
--- a/media/codec2/vndk/C2AllocatorGralloc.cpp
+++ b/media/codec2/vndk/C2AllocatorGralloc.cpp
@@ -54,6 +54,10 @@
static_assert((~C2MemoryUsage::PLATFORM_MASK & PASSTHROUGH_USAGE_MASK) == 0, "");
} // unnamed
+static bool isAtLeastT() {
+ return android_get_device_api_level() >= __ANDROID_API_T__;
+}
+
C2MemoryUsage C2AndroidMemoryUsage::FromGrallocUsage(uint64_t usage) {
// gralloc does not support WRITE_PROTECTED
return C2MemoryUsage(
@@ -760,10 +764,12 @@
default: {
// We don't know what it is, let's try to lock it with gralloc4
android_ycbcr ycbcrLayout;
- c2_status_t status = Gralloc4Mapper_lock(
- const_cast<native_handle_t*>(mBuffer), grallocUsage, rect, layout, addr);
- if (status == C2_OK) {
- break;
+ if (isAtLeastT()) {
+ c2_status_t status = Gralloc4Mapper_lock(
+ const_cast<native_handle_t*>(mBuffer), grallocUsage, rect, layout, addr);
+ if (status == C2_OK) {
+ break;
+ }
}
// fallback to lockYCbCr