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

Commit 1f31f244 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Minor updates AHardware accessor in AImageReader" into oc-dev

parents 126d7a28 e31bc872
Loading
Loading
Loading
Loading
+26 −10
Original line number Diff line number Diff line
@@ -307,22 +307,38 @@ media_status_t AImageReader_setImageListener(
 * for the consumer usage. All other parameters and the return values are identical to those passed
 * to {@line AImageReader_new}.
 *
 * @param usage0 specifies how the consumer will access the AImage, using combination of the
 *            AHARDWAREBUFFER_USAGE0 flags described in {@link hardware_buffer.h}.
 *            Passing {@link AHARDWAREBUFFER_USAGE0_CPU_READ_OFTEN} is equivalent to calling
 *            {@link AImageReader_new} with the same parameters. Note that consumers that do not
 *            require CPU access to the buffer should omit {@link
 *            AHARDWAREBUFFER_USAGE0_CPU_READ_OFTEN} to improve performance.
 * @param usage1 specifies how the consumer will access the AImage, using combination of the
 *            AHARDWAREBUFFER_USAGE1 flags described in {@link hardware_buffer.h}.
 * @param usage specifies how the consumer will access the AImage, using combination of the
 *            AHARDWAREBUFFER_USAGE flags described in {@link hardware_buffer.h}.
 *            Passing {@link AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN} is equivalent to calling
 *            {@link AImageReader_new} with the same parameters.
 *
 * Note that not all format and usage flag combination is supported by the {@link AImageReader}.
 * Below are the combinations supported by the {@link AImageReader}.
 * <table>
 * <tr>
 *   <th>Format</th>
 *   <th>Compatible usage flags</th>
 * </tr>
 * <tr>
 *   <td>non-{@link AIMAGE_FORMAT_PRIVATE PRIVATE} formats defined in {@link AImage.h}
 * </td>
 *   <td>{@link AHARDWAREBUFFER_USAGE_CPU_READ_RARELY} or
 *   {@link AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN}</td>
 * </tr>
 * <tr>
 *   <td>{@link AIMAGE_FORMAT_RGBA_8888}</td>
 *   <td>{@link AHARDWAREBUFFER_USAGE_VIDEO_ENCODE} or
 *   {@link AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE}, or combined</td>
 * </tr>
 * </table>
 *
 * @see AImage
 * @see AImageReader_new
 * @see AHardwareBuffer
 */
media_status_t AImageReader_newWithUsage(
        int32_t width, int32_t height, int32_t format, uint64_t usage0,
        uint64_t usage1, int32_t maxImages, /*out*/ AImageReader** reader);
        int32_t width, int32_t height, int32_t format, uint64_t usage, int32_t maxImages,
        /*out*/ AImageReader** reader);

/*
 * Acquire the next {@link AImage} from the image reader's queue asynchronously.
+8 −13
Original line number Diff line number Diff line
@@ -31,12 +31,10 @@ using namespace android;

#define ALIGN(x, mask) ( ((x) + (mask) - 1) & ~((mask) - 1) )

AImage::AImage(AImageReader* reader, int32_t format, uint64_t usage0, uint64_t usage1,
        BufferItem* buffer, int64_t timestamp,
        int32_t width, int32_t height, int32_t numPlanes) :
        mReader(reader), mFormat(format), mUsage0(usage0), mUsage1(usage1),
        mBuffer(buffer), mLockedBuffer(nullptr), mTimestamp(timestamp),
        mWidth(width), mHeight(height), mNumPlanes(numPlanes) {
AImage::AImage(AImageReader* reader, int32_t format, uint64_t usage, BufferItem* buffer,
        int64_t timestamp, int32_t width, int32_t height, int32_t numPlanes) :
        mReader(reader), mFormat(format), mUsage(usage), mBuffer(buffer), mLockedBuffer(nullptr),
        mTimestamp(timestamp), mWidth(width), mHeight(height), mNumPlanes(numPlanes) {
}

// Can only be called by free() with mLock hold
@@ -178,9 +176,9 @@ media_status_t AImage::lockImage() {
        return AMEDIA_ERROR_INVALID_OBJECT;
    }

    if ((mUsage0 & AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN) == 0) {
    if ((mUsage & AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN) == 0) {
        ALOGE("%s: AImage %p does not have any software read usage bits set, usage=%" PRIu64 "",
              __FUNCTION__, this, mUsage0);
              __FUNCTION__, this, mUsage);
        return AMEDIA_IMGREADER_CANNOT_LOCK_IMAGE;
    }

@@ -191,13 +189,10 @@ media_status_t AImage::lockImage() {

    auto lockedBuffer = std::make_unique<CpuConsumer::LockedBuffer>();

    uint64_t producerUsage;
    uint64_t consumerUsage;
    android_hardware_HardwareBuffer_convertToGrallocUsageBits(
            &producerUsage, &consumerUsage, mUsage0, mUsage1);
    uint64_t grallocUsage = android_hardware_HardwareBuffer_convertToGrallocUsageBits(mUsage);

    status_t ret =
            lockImageFromBuffer(mBuffer, consumerUsage, mBuffer->mFence->dup(), lockedBuffer.get());
            lockImageFromBuffer(mBuffer, grallocUsage, mBuffer->mFence->dup(), lockedBuffer.get());
    if (ret != OK) {
        ALOGE("%s: AImage %p failed to lock, error=%d", __FUNCTION__, this, ret);
        return AMEDIA_IMGREADER_CANNOT_LOCK_IMAGE;
+3 −5
Original line number Diff line number Diff line
@@ -32,9 +32,8 @@ using namespace android;

// TODO: this only supports ImageReader
struct AImage {
    AImage(AImageReader* reader, int32_t format, uint64_t usage0, uint64_t usage1,
           BufferItem* buffer, int64_t timestamp,
           int32_t width, int32_t height, int32_t numPlanes);
    AImage(AImageReader* reader, int32_t format, uint64_t usage, BufferItem* buffer,
           int64_t timestamp, int32_t width, int32_t height, int32_t numPlanes);

    // free all resources while keeping object alive. Caller must obtain reader lock
    void close() { close(-1); }
@@ -75,8 +74,7 @@ struct AImage {
    // When reader is close, AImage will only accept close API call
    wp<AImageReader>           mReader;
    const int32_t              mFormat;
    const uint64_t             mUsage0;  // AHARDWAREBUFFER_USAGE0* flags.
    const uint64_t             mUsage1;  // AHARDWAREBUFFER_USAGE1* flags.
    const uint64_t             mUsage;  // AHARDWAREBUFFER_USAGE_* flags.
    BufferItem*                mBuffer;
    std::unique_ptr<CpuConsumer::LockedBuffer> mLockedBuffer;
    const int64_t              mTimestamp;
+10 −18
Original line number Diff line number Diff line
@@ -238,14 +238,12 @@ void AImageReader::CallbackHandler::onMessageReceived(
AImageReader::AImageReader(int32_t width,
                           int32_t height,
                           int32_t format,
                           uint64_t usage0,
                           uint64_t usage1,
                           uint64_t usage,
                           int32_t maxImages)
    : mWidth(width),
      mHeight(height),
      mFormat(format),
      mUsage0(usage0),
      mUsage1(usage1),
      mUsage(usage),
      mMaxImages(maxImages),
      mNumPlanes(getNumPlanesForFormat(format)),
      mFrameListener(new FrameListener(this)),
@@ -256,20 +254,14 @@ AImageReader::init() {
    PublicFormat publicFormat = static_cast<PublicFormat>(mFormat);
    mHalFormat = android_view_Surface_mapPublicFormatToHalFormat(publicFormat);
    mHalDataSpace = android_view_Surface_mapPublicFormatToHalDataspace(publicFormat);

    uint64_t producerUsage;
    uint64_t consumerUsage;
    android_hardware_HardwareBuffer_convertToGrallocUsageBits(
            &producerUsage, &consumerUsage, mUsage0, mUsage1);
    // Strip out producerUsage here.
    mHalUsage = android_convertGralloc1To0Usage(0, consumerUsage);
    mHalUsage = android_hardware_HardwareBuffer_convertToGrallocUsageBits(mUsage);

    sp<IGraphicBufferProducer> gbProducer;
    sp<IGraphicBufferConsumer> gbConsumer;
    BufferQueue::createBufferQueue(&gbProducer, &gbConsumer);

    String8 consumerName = String8::format("ImageReader-%dx%df%xu%" PRIu64 "u%" PRIu64 "m%d-%d-%d",
            mWidth, mHeight, mFormat, mUsage0, mUsage1, mMaxImages, getpid(),
    String8 consumerName = String8::format("ImageReader-%dx%df%xu%" PRIu64 "m%d-%d-%d",
            mWidth, mHeight, mFormat, mUsage, mMaxImages, getpid(),
            createProcessUniqueId());

    mBufferItemConsumer =
@@ -445,10 +437,10 @@ AImageReader::acquireImageLocked(/*out*/AImage** image, /*out*/int* acquireFence
    }

    if (mHalFormat == HAL_PIXEL_FORMAT_BLOB) {
        *image = new AImage(this, mFormat, mUsage0, mUsage1, buffer, buffer->mTimestamp,
        *image = new AImage(this, mFormat, mUsage, buffer, buffer->mTimestamp,
                readerWidth, readerHeight, mNumPlanes);
    } else {
        *image = new AImage(this, mFormat, mUsage0, mUsage1, buffer, buffer->mTimestamp,
        *image = new AImage(this, mFormat, mUsage, buffer, buffer->mTimestamp,
                bufferWidth, bufferHeight, mNumPlanes);
    }
    mAcquiredImages.push_back(*image);
@@ -587,12 +579,12 @@ media_status_t AImageReader_new(
        /*out*/AImageReader** reader) {
    ALOGV("%s", __FUNCTION__);
    return AImageReader_newWithUsage(
            width, height, format, AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN, 0, maxImages, reader);
            width, height, format, AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN, maxImages, reader);
}

EXPORT
media_status_t AImageReader_newWithUsage(
        int32_t width, int32_t height, int32_t format, uint64_t usage0, uint64_t usage1,
        int32_t width, int32_t height, int32_t format, uint64_t usage,
        int32_t maxImages, /*out*/ AImageReader** reader) {
    ALOGV("%s", __FUNCTION__);

@@ -626,7 +618,7 @@ media_status_t AImageReader_newWithUsage(
    }

    AImageReader* tmpReader = new AImageReader(
        width, height, format, usage0, usage1, maxImages);
        width, height, format, usage, maxImages);
    if (tmpReader == nullptr) {
        ALOGE("%s: AImageReader allocation failed", __FUNCTION__);
        return AMEDIA_ERROR_UNKNOWN;
+2 −4
Original line number Diff line number Diff line
@@ -55,8 +55,7 @@ struct AImageReader : public RefBase {
    AImageReader(int32_t width,
                 int32_t height,
                 int32_t format,
                 uint64_t usage0,
                 uint64_t usage1,
                 uint64_t usage,
                 int32_t maxImages);
    ~AImageReader();

@@ -117,8 +116,7 @@ struct AImageReader : public RefBase {
    const int32_t mWidth;
    const int32_t mHeight;
    const int32_t mFormat;
    const uint64_t mUsage0;  // AHARDWAREBUFFER_USAGE0* flags.
    const uint64_t mUsage1;  // AHARDWAREBUFFER_USAGE1* flags.
    const uint64_t mUsage;  // AHARDWAREBUFFER_USAGE_* flags.
    const int32_t mMaxImages;

    // TODO(jwcai) Seems completely unused in AImageReader class.