Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c8582e9a authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "C2 Decoders: Add a function to choose hal pixel format for 10 bit...

Merge "C2 Decoders: Add a function to choose hal pixel format for 10 bit decode" am: a4098763 am: 23b100fd

Original change: https://android-review.googlesource.com/c/platform/frameworks/av/+/1935519

Change-Id: I231de04d3c27bbfb7feb69fec6a6795fb188d6be
parents 5bcffd13 23b100fd
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -763,6 +763,43 @@ bool SimpleC2Component::processQueue() {
    return hasQueuedWork;
}

int SimpleC2Component::getHalPixelFormatForBitDepth10(bool allowRGBA1010102) {
    // Save supported hal pixel formats for bit depth of 10, the first time this is called
    if (!mBitDepth10HalPixelFormats.size()) {
        std::vector<int> halPixelFormats;
        // TODO(b/178229371) Enable HAL_PIXEL_FORMAT_YCBCR_P010 once framework supports it
        // halPixelFormats.push_back(HAL_PIXEL_FORMAT_YCBCR_P010);

        // since allowRGBA1010102 can chance in each call, but mBitDepth10HalPixelFormats
        // is populated only once, allowRGBA1010102 is not considered at this stage.
        halPixelFormats.push_back(HAL_PIXEL_FORMAT_RGBA_1010102);

        for (int halPixelFormat : halPixelFormats) {
            std::shared_ptr<C2GraphicBlock> block;

            uint32_t gpuConsumerFlags = halPixelFormat == HAL_PIXEL_FORMAT_RGBA_1010102
                                                ? C2AndroidMemoryUsage::HW_TEXTURE_READ
                                                : 0;
            C2MemoryUsage usage = {C2MemoryUsage::CPU_READ | gpuConsumerFlags,
                                   C2MemoryUsage::CPU_WRITE};
            // TODO(b/214411172) Use AHardwareBuffer_isSupported once it supports P010
            c2_status_t status =
                    mOutputBlockPool->fetchGraphicBlock(320, 240, halPixelFormat, usage, &block);
            if (status == C2_OK) {
                mBitDepth10HalPixelFormats.push_back(halPixelFormat);
            }
        }
        // Add YV12 in the end as a fall-back option
        mBitDepth10HalPixelFormats.push_back(HAL_PIXEL_FORMAT_YV12);
    }
    // When RGBA1010102 is not allowed and if the first supported hal pixel is format is
    // HAL_PIXEL_FORMAT_RGBA_1010102, then return HAL_PIXEL_FORMAT_YV12
    if (!allowRGBA1010102 && mBitDepth10HalPixelFormats[0] == HAL_PIXEL_FORMAT_RGBA_1010102) {
        return HAL_PIXEL_FORMAT_YV12;
    }
    // Return the first entry from supported formats
    return mBitDepth10HalPixelFormats[0];
}
std::shared_ptr<C2Buffer> SimpleC2Component::createLinearBuffer(
        const std::shared_ptr<C2LinearBlock> &block, size_t offset, size_t size) {
    return C2Buffer::CreateLinearBuffer(block->share(offset, size, ::C2Fence()));
+2 −0
Original line number Diff line number Diff line
@@ -167,6 +167,7 @@ protected:
    static constexpr uint32_t NO_DRAIN = ~0u;

    C2ReadView mDummyReadView;
    int getHalPixelFormatForBitDepth10(bool allowRGBA1010102);

private:
    const std::shared_ptr<C2ComponentInterface> mIntf;
@@ -250,6 +251,7 @@ private:
    class BlockingBlockPool;
    std::shared_ptr<BlockingBlockPool> mOutputBlockPool;

    std::vector<int> mBitDepth10HalPixelFormats;
    SimpleC2Component() = delete;
};

+10 −16
Original line number Diff line number Diff line
@@ -334,7 +334,6 @@ C2SoftGav1Dec::C2SoftGav1Dec(const char *name, c2_node_id_t id,
          std::make_shared<SimpleInterface<IntfImpl>>(name, id, intfImpl)),
      mIntf(intfImpl),
      mCodecCtx(nullptr) {
  mIsFormatR10G10B10A2Supported = IsFormatR10G10B10A2SupportedForLegacyRendering();
  gettimeofday(&mTimeStart, nullptr);
  gettimeofday(&mTimeEnd, nullptr);
}
@@ -632,26 +631,21 @@ bool C2SoftGav1Dec::outputBuffer(const std::shared_ptr<C2BlockPool> &pool,
    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;
      }
    }
  }
  C2MemoryUsage usage = {C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE};

+0 −1
Original line number Diff line number Diff line
@@ -82,7 +82,6 @@ struct C2SoftGav1Dec : public SimpleC2Component {

  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);
+3 −10
Original line number Diff line number Diff line
@@ -352,7 +352,6 @@ C2SoftVpxDec::C2SoftVpxDec(
      mCodecCtx(nullptr),
      mCoreCount(1),
      mQueue(new Mutexed<ConversionQueue>) {
      mIsFormatR10G10B10A2Supported = IsFormatR10G10B10A2SupportedForLegacyRendering();
}

C2SoftVpxDec::~C2SoftVpxDec() {
@@ -683,19 +682,13 @@ status_t C2SoftVpxDec::outputBuffer(
    if (img->fmt == VPX_IMG_FMT_I42016) {
        IntfImpl::Lock lock = mIntf->lock();
        std::shared_ptr<C2StreamColorAspectsTuning::output> defaultColorAspects = mIntf->getDefaultColorAspects_l();

        bool allowRGBA1010102 = false;
        if (defaultColorAspects->primaries == C2Color::PRIMARIES_BT2020 &&
            defaultColorAspects->matrix == C2Color::MATRIX_BT2020 &&
            defaultColorAspects->transfer == C2Color::TRANSFER_ST2084) {
            // 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;
            }
            allowRGBA1010102 = true;
        }
        format = getHalPixelFormatForBitDepth10(allowRGBA1010102);
    }
    C2MemoryUsage usage = { C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE };
    c2_status_t err = pool->fetchGraphicBlock(align(mWidth, 16), mHeight, format, usage, &block);
Loading