C2 Decoders: Add a function to choose hal pixel format for 10 bit decode

Added a function which will return supported hal pixel format
when decoding streams with bit depth of 10 for VP9 and AV1.

P010, RGBA1010102 (for specific color aspects) and YV12 is the order
in which formats are tried.

P010 format will be enabled once framework supports it

AHardwareBuffer_isSupported() doesn't handle P010 format and hence
fetchGraphicBlock() call is used to determine which are formats are
supported.

Bug: 178229371
Test: atest CtsMediaV2TestCases -- --module-arg \
 CtsMediaV2TestCases:instrumentation-arg:codec-prefix:=c2.android.

Change-Id: I6503ecf49934f7d0fb8d8ffcf95e3aa4905741d8
diff --git a/media/codec2/components/gav1/C2SoftGav1Dec.cpp b/media/codec2/components/gav1/C2SoftGav1Dec.cpp
index ff6080d..0f59d76 100644
--- a/media/codec2/components/gav1/C2SoftGav1Dec.cpp
+++ b/media/codec2/components/gav1/C2SoftGav1Dec.cpp
@@ -334,7 +334,6 @@
           std::make_shared<SimpleInterface<IntfImpl>>(name, id, intfImpl)),
       mIntf(intfImpl),
       mCodecCtx(nullptr) {
-  mIsFormatR10G10B10A2Supported = IsFormatR10G10B10A2SupportedForLegacyRendering();
   gettimeofday(&mTimeStart, nullptr);
   gettimeofday(&mTimeEnd, nullptr);
 }
@@ -632,25 +631,20 @@
     IntfImpl::Lock lock = mIntf->lock();
     std::shared_ptr<C2StreamColorAspectsInfo::output> codedColorAspects =
         mIntf->getColorAspects_l();
-
+    bool allowRGBA1010102 = false;
     if (codedColorAspects->primaries == C2Color::PRIMARIES_BT2020 &&
         codedColorAspects->matrix == C2Color::MATRIX_BT2020 &&
         codedColorAspects->transfer == C2Color::TRANSFER_ST2084) {
-      if (buffer->image_format != libgav1::kImageFormatYuv420) {
+      allowRGBA1010102 = true;
+    }
+    format = getHalPixelFormatForBitDepth10(allowRGBA1010102);
+    if ((format == HAL_PIXEL_FORMAT_RGBA_1010102) &&
+        (buffer->image_format != libgav1::kImageFormatYuv420)) {
         ALOGE("Only YUV420 output is supported when targeting RGBA_1010102");
-        mSignalledError = true;
-        work->result = C2_OMITTED;
-        work->workletsProcessed = 1u;
-        return false;
-      }
-      // TODO (b/201787956) For devices that do not support HAL_PIXEL_FORMAT_RGBA_1010102,
-      // HAL_PIXEL_FORMAT_YV12 is used as a temporary work around.
-      if (!mIsFormatR10G10B10A2Supported)  {
-        ALOGE("HAL_PIXEL_FORMAT_RGBA_1010102 isn't supported");
-        format = HAL_PIXEL_FORMAT_YV12;
-      } else {
-        format = HAL_PIXEL_FORMAT_RGBA_1010102;
-      }
+      mSignalledError = true;
+      work->result = C2_OMITTED;
+      work->workletsProcessed = 1u;
+      return false;
     }
   }
   C2MemoryUsage usage = {C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE};
diff --git a/media/codec2/components/gav1/C2SoftGav1Dec.h b/media/codec2/components/gav1/C2SoftGav1Dec.h
index f82992d..134fa0d 100644
--- a/media/codec2/components/gav1/C2SoftGav1Dec.h
+++ b/media/codec2/components/gav1/C2SoftGav1Dec.h
@@ -82,7 +82,6 @@
 
   struct timeval mTimeStart;  // Time at the start of decode()
   struct timeval mTimeEnd;    // Time at the end of decode()
-  bool mIsFormatR10G10B10A2Supported;
 
   bool initDecoder();
   void getVuiParams(const libgav1::DecoderBuffer *buffer);