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

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

Merge "gralloc: update lock and lockYCbCr"

parents f6042fcc 9c5ebfc5
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -252,8 +252,7 @@ void* HandleImporter::lock(
        // No need to use bytesPerPixel and bytesPerStride because we are using
        // an 1-D buffer and accressRegion.
        mMapperV4->lock(buffer, cpuUsage, accessRegion, acquireFenceHandle,
                        [&](const auto& tmpError, const auto& tmpPtr, const auto& /*bytesPerPixel*/,
                            const auto& /*bytesPerStride*/) {
                        [&](const auto& tmpError, const auto& tmpPtr) {
                            if (tmpError == MapperErrorV4::NONE) {
                                ret = tmpPtr;
                            } else {
@@ -301,7 +300,13 @@ YCbCrLayout HandleImporter::lockYCbCr(
    }

    if (mMapperV4 != nullptr) {
        return lockYCbCrInternal<IMapperV4, MapperErrorV4>(mMapperV4, buf, cpuUsage, accessRegion);
        // No device currently supports IMapper 4.0 so it is safe to just return an error code here.
        //
        // This will be supported by a combination of lock and BufferMetadata getters. We are going
        // to refactor all the IAllocator/IMapper versioning code into a shared library. We will
        // then add the IMapper 4.0 lockYCbCr support then.
        ALOGE("%s: MapperV4 doesn't support lockYCbCr directly!", __FUNCTION__);
        return {};
    }

    if (mMapperV3 != nullptr) {
+1 −4
Original line number Diff line number Diff line
@@ -369,10 +369,7 @@ void* Gralloc::lock(const native_handle_t* bufferHandle, uint64_t cpuUsage,
        accessRegion.top = accessRegionRect.top;
        accessRegion.width = accessRegionRect.width;
        accessRegion.height = accessRegionRect.height;
        int32_t bytesPerPixel;
        int32_t bytesPerStride;
        return mGralloc4->lock(bufferHandle, cpuUsage, accessRegion, acquireFence, &bytesPerPixel,
                               &bytesPerStride);
        return mGralloc4->lock(bufferHandle, cpuUsage, accessRegion, acquireFence);
    } else if (mGralloc3) {
        IMapper3::Rect accessRegion;
        accessRegion.left = accessRegionRect.left;
+11 −49
Original line number Diff line number Diff line
@@ -199,16 +199,20 @@ interface IMapper {
     * outside of @p accessRegion is undefined, except that it must not cause
     * process termination.
     *
     * This function can lock both single-planar and multi-planar formats. The caller
     * should use get() to get information about the buffer they are locking.
     * get() can be used to get information about the planes, offsets, stride,
     * etc.
     *
     * This function must also work on buffers with
     * `AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_*` if supported by the device, as well
     * as with any other formats requested by multimedia codecs when they are
     * configured with a flexible-YUV-compatible color format.
     *
     * On success, @p data must be filled with a pointer to the locked buffer
     * memory. This address will represent the top-left corner of the entire
     * buffer, even if @p accessRegion does not begin at the top-left corner.
     *
     * On success, bytesPerPixel must contain the number of bytes per pixel in
     * the buffer. If the bytesPerPixel is unknown or variable, a value of -1
     * should be returned. bytesPerStride must contain the bytes per stride of
     * the buffer. If the bytesPerStride is unknown or variable, a value of -1
     * should be returned.
     *
     * The locked buffer must adhere to the format requested at allocation time
     * in the BufferDescriptorInfo.
     *
@@ -231,55 +235,13 @@ interface IMapper {
     *     - `NO_RESOURCES` if the buffer cannot be locked at this time. Note
     *       that locking may succeed at a later time.
     * @return data CPU-accessible pointer to the buffer data.
     * @return bytesPerPixel the number of bytes per pixel in the buffer
     * @return bytesPerStride the number of bytes per stride of the buffer
     */
    lock(pointer buffer,
         uint64_t cpuUsage,
         Rect accessRegion,
         handle acquireFence)
            generates (Error error,
                       pointer data,
                       int32_t bytesPerPixel,
                       int32_t bytesPerStride);

    /**
     * Locks a YCbCr buffer for the specified CPU usage.
     *
     * This is largely the same as lock(), except that instead of returning a
     * pointer directly to the buffer data, it returns a `YCbCrLayout` struct
     * describing how to access the data planes.
     *
     * This function must work on buffers with
     * `AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_*` if supported by the device, as well
     * as with any other formats requested by multimedia codecs when they are
     * configured with a flexible-YUV-compatible color format.
     *
     * @param buffer Buffer to lock.
     * @param cpuUsage CPU usage flags to request. See +ndk
     *     libnativewindow#AHardwareBuffer_UsageFlags for possible values.
     * @param accessRegion Portion of the buffer that the client intends to
     *     access.
     * @param acquireFence Handle containing a file descriptor referring to a
     *     sync fence object, which will be signaled when it is safe for the
     *     mapper to lock the buffer. @p acquireFence may be empty if it is
     *     already safe to lock.
     * @return error Error status of the call, which may be
     *     - `NONE` upon success.
     *     - `BAD_BUFFER` if the buffer is invalid or is incompatible with this
     *       function.
     *     - `BAD_VALUE` if @p cpuUsage is 0, contains non-CPU usage flags, or
     *       is incompatible with the buffer.
     *     - `NO_RESOURCES` if the buffer cannot be locked at this time. Note
     *       that locking may succeed at a later time.
     * @return layout Data layout of the locked buffer.
     */
    lockYCbCr(pointer buffer,
              uint64_t cpuUsage,
              Rect accessRegion,
              handle acquireFence)
            generates (Error error,
                       YCbCrLayout layout);
                       pointer data);

    /**
     * Unlocks a buffer to indicate all CPU accesses to the buffer have
+0 −29
Original line number Diff line number Diff line
@@ -53,32 +53,3 @@ enum Error : int32_t {
 */
typedef vec<uint8_t> BufferDescriptor;
/**
 * Structure for describing YCbCr formats for consumption by applications.
 * This is used with PixelFormat::YCBCR_*_888.
 *
 * Buffer chroma subsampling is defined in the format.
 * e.g. PixelFormat::YCBCR_420_888 has subsampling 4:2:0.
 *
 * Buffers must have a 8 bit depth.
 *
 * y, cb, and cr point to the first byte of their respective planes.
 *
 * Stride describes the distance in bytes from the first value of one row of
 * the image to the first value of the next row. It includes the width of the
 * image plus padding.
 * yStride is the stride of the luma plane.
 * cStride is the stride of the chroma planes.
 *
 * chromaStep is the distance in bytes from one chroma pixel value to the
 * next. This is 2 bytes for semiplanar (because chroma values are interleaved
 * and each chroma value is one byte) and 1 for planar.
 */
struct YCbCrLayout {
    pointer y;
    pointer cb;
    pointer cr;
    uint32_t yStride;
    uint32_t cStride;
    uint32_t chromaStep;
};
+2 −36
Original line number Diff line number Diff line
@@ -199,8 +199,7 @@ void Gralloc::freeBuffer(const native_handle_t* bufferHandle) {
}

void* Gralloc::lock(const native_handle_t* bufferHandle, uint64_t cpuUsage,
                    const IMapper::Rect& accessRegion, int acquireFence, int32_t* outBytesPerPixel,
                    int32_t* outBytesPerStride) {
                    const IMapper::Rect& accessRegion, int acquireFence) {
    auto buffer = const_cast<native_handle_t*>(bufferHandle);

    NATIVE_HANDLE_DECLARE_STORAGE(acquireFenceStorage, 1, 0);
@@ -211,17 +210,11 @@ void* Gralloc::lock(const native_handle_t* bufferHandle, uint64_t cpuUsage,
        acquireFenceHandle = h;
    }

    *outBytesPerPixel = -1;
    *outBytesPerStride = -1;

    void* data = nullptr;
    mMapper->lock(buffer, cpuUsage, accessRegion, acquireFenceHandle,
                  [&](const auto& tmpError, const auto& tmpData, int32_t tmpBytesPerPixel,
                      int32_t tmpBytesPerStride) {
                  [&](const auto& tmpError, const auto& tmpData) {
                      ASSERT_EQ(Error::NONE, tmpError) << "failed to lock buffer " << buffer;
                      data = tmpData;
                      *outBytesPerPixel = tmpBytesPerPixel;
                      *outBytesPerStride = tmpBytesPerStride;
                  });

    if (acquireFence >= 0) {
@@ -231,33 +224,6 @@ void* Gralloc::lock(const native_handle_t* bufferHandle, uint64_t cpuUsage,
    return data;
}

YCbCrLayout Gralloc::lockYCbCr(const native_handle_t* bufferHandle, uint64_t cpuUsage,
                               const IMapper::Rect& accessRegion, int acquireFence) {
    auto buffer = const_cast<native_handle_t*>(bufferHandle);

    NATIVE_HANDLE_DECLARE_STORAGE(acquireFenceStorage, 1, 0);
    hidl_handle acquireFenceHandle;
    if (acquireFence >= 0) {
        auto h = native_handle_init(acquireFenceStorage, 1, 0);
        h->data[0] = acquireFence;
        acquireFenceHandle = h;
    }

    YCbCrLayout layout = {};
    mMapper->lockYCbCr(buffer, cpuUsage, accessRegion, acquireFenceHandle,
                       [&](const auto& tmpError, const auto& tmpLayout) {
                           ASSERT_EQ(Error::NONE, tmpError)
                                   << "failed to lockYCbCr buffer " << buffer;
                           layout = tmpLayout;
                       });

    if (acquireFence >= 0) {
        close(acquireFence);
    }

    return layout;
}

int Gralloc::unlock(const native_handle_t* bufferHandle) {
    auto buffer = const_cast<native_handle_t*>(bufferHandle);

Loading