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

Commit d2f4dafa authored by Valerie Hau's avatar Valerie Hau
Browse files

Adding lock function that obtains bytesPerPixel and bytesPerStride

Bug: 123423521
Test: build, boot, manual
Change-Id: I480d60fe4975c5ffee6d6c253c37ffd20cea79c3
parent 8760599e
Loading
Loading
Loading
Loading
+51 −2
Original line number Original line Diff line number Diff line
@@ -93,8 +93,57 @@ void AHardwareBuffer_describe(const AHardwareBuffer* buffer,
    outDesc->rfu1 = 0;
    outDesc->rfu1 = 0;
}
}


int AHardwareBuffer_lockAndGetInfo(AHardwareBuffer* buffer, uint64_t usage,
        int32_t fence, const ARect* rect, void** outVirtualAddress,
        int32_t* outBytesPerPixel, int32_t* outBytesPerStride) {
    if (!buffer) return BAD_VALUE;

    if (usage & ~(AHARDWAREBUFFER_USAGE_CPU_READ_MASK |
                  AHARDWAREBUFFER_USAGE_CPU_WRITE_MASK)) {
        ALOGE("Invalid usage flags passed to AHardwareBuffer_lock; only "
                "AHARDWAREBUFFER_USAGE_CPU_* flags are allowed");
        return BAD_VALUE;
    }

    usage = AHardwareBuffer_convertToGrallocUsageBits(usage);
    GraphicBuffer* gbuffer = AHardwareBuffer_to_GraphicBuffer(buffer);

    //Mapper implementations before 3.0 will not return bytes per pixel or
    //bytes per stride information.
    if (gbuffer->getBufferMapperVersion() == GraphicBufferMapper::Version::GRALLOC_2) {
        ALOGE("Mapper versions before 3.0 cannot retrieve bytes per pixel and bytes per stride info");
        return INVALID_OPERATION;
    }

    if (gbuffer->getLayerCount() > 1) {
        ALOGE("Buffer with multiple layers passed to AHardwareBuffer_lock; "
                "only buffers with one layer are allowed");
        return INVALID_OPERATION;
    }

    Rect bounds;
    if (!rect) {
        bounds.set(Rect(gbuffer->getWidth(), gbuffer->getHeight()));
    } else {
        bounds.set(Rect(rect->left, rect->top, rect->right, rect->bottom));
    }
    int result = gbuffer->lockAsync(usage, usage, bounds, outVirtualAddress, fence, outBytesPerPixel, outBytesPerStride);

    // if hardware returns -1 for bytes per pixel or bytes per stride, we fail
    // and unlock the buffer
    if (*outBytesPerPixel == -1 || *outBytesPerStride == -1) {
        gbuffer->unlock();
        return INVALID_OPERATION;
    }

    return result;
}

int AHardwareBuffer_lock(AHardwareBuffer* buffer, uint64_t usage,
int AHardwareBuffer_lock(AHardwareBuffer* buffer, uint64_t usage,
                         int32_t fence, const ARect* rect, void** outVirtualAddress) {
                         int32_t fence, const ARect* rect, void** outVirtualAddress) {
    int32_t bytesPerPixel;
    int32_t bytesPerStride;

    if (!buffer) return BAD_VALUE;
    if (!buffer) return BAD_VALUE;


    if (usage & ~(AHARDWAREBUFFER_USAGE_CPU_READ_MASK |
    if (usage & ~(AHARDWAREBUFFER_USAGE_CPU_READ_MASK |
@@ -119,7 +168,7 @@ int AHardwareBuffer_lock(AHardwareBuffer* buffer, uint64_t usage,
    } else {
    } else {
        bounds.set(Rect(rect->left, rect->top, rect->right, rect->bottom));
        bounds.set(Rect(rect->left, rect->top, rect->right, rect->bottom));
    }
    }
    return gbuffer->lockAsync(usage, usage, bounds, outVirtualAddress, fence);
    return gbuffer->lockAsync(usage, usage, bounds, outVirtualAddress, fence, &bytesPerPixel, &bytesPerStride);
}
}


int AHardwareBuffer_lockPlanes(AHardwareBuffer* buffer, uint64_t usage,
int AHardwareBuffer_lockPlanes(AHardwareBuffer* buffer, uint64_t usage,
+12 −0
Original line number Original line Diff line number Diff line
@@ -421,6 +421,18 @@ void AHardwareBuffer_describe(const AHardwareBuffer* buffer,
int AHardwareBuffer_lock(AHardwareBuffer* buffer, uint64_t usage,
int AHardwareBuffer_lock(AHardwareBuffer* buffer, uint64_t usage,
        int32_t fence, const ARect* rect, void** outVirtualAddress) __INTRODUCED_IN(26);
        int32_t fence, const ARect* rect, void** outVirtualAddress) __INTRODUCED_IN(26);


/**
 * Lock an AHardwareBuffer for direct CPU access.
 *
 * This function is the same as the above lock function, but passes back
 * additional information about the bytes per pixel and the bytes per stride
 * of the locked buffer.  If the bytes per pixel or bytes per stride are unknown
 * or variable, or if the underlying mapper implementation does not support returning
 * additional information, then this call will fail with INVALID_OPERATION
 */
int AHardwareBuffer_lockAndGetInfo(AHardwareBuffer* buffer, uint64_t usage,
        int32_t fence, const ARect* rect, void** outVirtualAddress,
        int32_t* outBytesPerPixel, int32_t* outBytesPerStride) __INTRODUCED_IN(29);
/**
/**
 * Lock a potentially multi-planar AHardwareBuffer for direct CPU access.
 * Lock a potentially multi-planar AHardwareBuffer for direct CPU access.
 *
 *
+1 −0
Original line number Original line Diff line number Diff line
@@ -7,6 +7,7 @@ LIBNATIVEWINDOW {
    AHardwareBuffer_getNativeHandle; # vndk
    AHardwareBuffer_getNativeHandle; # vndk
    AHardwareBuffer_isSupported; # introduced=29
    AHardwareBuffer_isSupported; # introduced=29
    AHardwareBuffer_lock;
    AHardwareBuffer_lock;
    AHardwareBuffer_lockAndGetInfo; # introduced=29
    AHardwareBuffer_recvHandleFromUnixSocket;
    AHardwareBuffer_recvHandleFromUnixSocket;
    AHardwareBuffer_release;
    AHardwareBuffer_release;
    AHardwareBuffer_sendHandleToUnixSocket;
    AHardwareBuffer_sendHandleToUnixSocket;
+3 −0
Original line number Original line Diff line number Diff line
@@ -53,6 +53,9 @@ GraphicBufferMapper::GraphicBufferMapper() {
    mMapper = std::make_unique<const Gralloc3Mapper>();
    mMapper = std::make_unique<const Gralloc3Mapper>();
    if (!mMapper->isLoaded()) {
    if (!mMapper->isLoaded()) {
        mMapper = std::make_unique<const Gralloc2Mapper>();
        mMapper = std::make_unique<const Gralloc2Mapper>();
        mMapperVersion = Version::GRALLOC_2;
    } else {
        mMapperVersion = Version::GRALLOC_3;
    }
    }


    if (!mMapper->isLoaded()) {
    if (!mMapper->isLoaded()) {
+5 −0
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@


#include <android/hardware_buffer.h>
#include <android/hardware_buffer.h>
#include <ui/ANativeObjectBase.h>
#include <ui/ANativeObjectBase.h>
#include <ui/GraphicBufferMapper.h>
#include <ui/PixelFormat.h>
#include <ui/PixelFormat.h>
#include <ui/Rect.h>
#include <ui/Rect.h>
#include <utils/Flattenable.h>
#include <utils/Flattenable.h>
@@ -214,6 +215,10 @@ public:
    status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
    status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
    status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);
    status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);


    GraphicBufferMapper::Version getBufferMapperVersion() const {
        return mBufferMapper.getMapperVersion();
    }

#ifndef LIBUI_IN_VNDK
#ifndef LIBUI_IN_VNDK
    // Returns whether this GraphicBuffer is backed by BufferHubBuffer.
    // Returns whether this GraphicBuffer is backed by BufferHubBuffer.
    bool isBufferHubBuffer() const;
    bool isBufferHubBuffer() const;
Loading