Loading libs/nativewindow/AHardwareBuffer.cpp +51 −2 Original line number Diff line number Diff line Loading @@ -93,8 +93,57 @@ void AHardwareBuffer_describe(const AHardwareBuffer* buffer, 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, int32_t fence, const ARect* rect, void** outVirtualAddress) { int32_t bytesPerPixel; int32_t bytesPerStride; if (!buffer) return BAD_VALUE; if (usage & ~(AHARDWAREBUFFER_USAGE_CPU_READ_MASK | Loading @@ -119,7 +168,7 @@ int AHardwareBuffer_lock(AHardwareBuffer* buffer, uint64_t usage, } else { 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, Loading libs/nativewindow/include/android/hardware_buffer.h +12 −0 Original line number Diff line number Diff line Loading @@ -421,6 +421,18 @@ void AHardwareBuffer_describe(const AHardwareBuffer* buffer, int AHardwareBuffer_lock(AHardwareBuffer* buffer, uint64_t usage, 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. * Loading libs/nativewindow/libnativewindow.map.txt +1 −0 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ LIBNATIVEWINDOW { AHardwareBuffer_getNativeHandle; # vndk AHardwareBuffer_isSupported; # introduced=29 AHardwareBuffer_lock; AHardwareBuffer_lockAndGetInfo; # introduced=29 AHardwareBuffer_recvHandleFromUnixSocket; AHardwareBuffer_release; AHardwareBuffer_sendHandleToUnixSocket; Loading libs/ui/GraphicBufferMapper.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,9 @@ GraphicBufferMapper::GraphicBufferMapper() { mMapper = std::make_unique<const Gralloc3Mapper>(); if (!mMapper->isLoaded()) { mMapper = std::make_unique<const Gralloc2Mapper>(); mMapperVersion = Version::GRALLOC_2; } else { mMapperVersion = Version::GRALLOC_3; } if (!mMapper->isLoaded()) { Loading libs/ui/include/ui/GraphicBuffer.h +5 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include <android/hardware_buffer.h> #include <ui/ANativeObjectBase.h> #include <ui/GraphicBufferMapper.h> #include <ui/PixelFormat.h> #include <ui/Rect.h> #include <utils/Flattenable.h> Loading Loading @@ -214,6 +215,10 @@ public: 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); GraphicBufferMapper::Version getBufferMapperVersion() const { return mBufferMapper.getMapperVersion(); } #ifndef LIBUI_IN_VNDK // Returns whether this GraphicBuffer is backed by BufferHubBuffer. bool isBufferHubBuffer() const; Loading Loading
libs/nativewindow/AHardwareBuffer.cpp +51 −2 Original line number Diff line number Diff line Loading @@ -93,8 +93,57 @@ void AHardwareBuffer_describe(const AHardwareBuffer* buffer, 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, int32_t fence, const ARect* rect, void** outVirtualAddress) { int32_t bytesPerPixel; int32_t bytesPerStride; if (!buffer) return BAD_VALUE; if (usage & ~(AHARDWAREBUFFER_USAGE_CPU_READ_MASK | Loading @@ -119,7 +168,7 @@ int AHardwareBuffer_lock(AHardwareBuffer* buffer, uint64_t usage, } else { 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, Loading
libs/nativewindow/include/android/hardware_buffer.h +12 −0 Original line number Diff line number Diff line Loading @@ -421,6 +421,18 @@ void AHardwareBuffer_describe(const AHardwareBuffer* buffer, int AHardwareBuffer_lock(AHardwareBuffer* buffer, uint64_t usage, 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. * Loading
libs/nativewindow/libnativewindow.map.txt +1 −0 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ LIBNATIVEWINDOW { AHardwareBuffer_getNativeHandle; # vndk AHardwareBuffer_isSupported; # introduced=29 AHardwareBuffer_lock; AHardwareBuffer_lockAndGetInfo; # introduced=29 AHardwareBuffer_recvHandleFromUnixSocket; AHardwareBuffer_release; AHardwareBuffer_sendHandleToUnixSocket; Loading
libs/ui/GraphicBufferMapper.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,9 @@ GraphicBufferMapper::GraphicBufferMapper() { mMapper = std::make_unique<const Gralloc3Mapper>(); if (!mMapper->isLoaded()) { mMapper = std::make_unique<const Gralloc2Mapper>(); mMapperVersion = Version::GRALLOC_2; } else { mMapperVersion = Version::GRALLOC_3; } if (!mMapper->isLoaded()) { Loading
libs/ui/include/ui/GraphicBuffer.h +5 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include <android/hardware_buffer.h> #include <ui/ANativeObjectBase.h> #include <ui/GraphicBufferMapper.h> #include <ui/PixelFormat.h> #include <ui/Rect.h> #include <utils/Flattenable.h> Loading Loading @@ -214,6 +215,10 @@ public: 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); GraphicBufferMapper::Version getBufferMapperVersion() const { return mBufferMapper.getMapperVersion(); } #ifndef LIBUI_IN_VNDK // Returns whether this GraphicBuffer is backed by BufferHubBuffer. bool isBufferHubBuffer() const; Loading