diff options
author | Jörg Wagner <jorwag@google.com> | 2023-11-01 18:05:52 +0000 |
---|---|---|
committer | Joerg Wagner <jorwag@google.com> | 2023-11-06 07:35:26 +0000 |
commit | fe14dc20cf2e9bc07ddb3aea8cfc05fb959f0618 (patch) | |
tree | d8d527b2fcca002d110a20e9540340c86af63089 | |
parent | 177effbccc1d77d6c9c222355e1e79edea4ae375 (diff) | |
download | gchips-fe14dc20cf2e9bc07ddb3aea8cfc05fb959f0618.tar.gz |
Preserve as many error codes as possible in map/unmap paths.
While the given implementation only returns -EINVAL or GRALLOC1_ERROR_UNSUPPORTED from the backend functions we don't
have to drop the latter.
Though -EINVAL can't be preserved as long as the return Error is strongly typed and the type not extended.
Bug: 308432951
Test: New PTS EGLAHBLockTest
Change-Id: I066270d4d026e31fbf3e080cfa839236a4d7297f
-rw-r--r-- | gralloc4/src/hidl_common/Mapper.cpp | 67 |
1 files changed, 54 insertions, 13 deletions
diff --git a/gralloc4/src/hidl_common/Mapper.cpp b/gralloc4/src/hidl_common/Mapper.cpp index e308cfe..36829ea 100644 --- a/gralloc4/src/hidl_common/Mapper.cpp +++ b/gralloc4/src/hidl_common/Mapper.cpp @@ -18,6 +18,7 @@ #include <inttypes.h> #include <sync/sync.h> +#include <hardware/gralloc1.h> #include "RegisteredHandlePool.h" #include "Mapper.h" #include "BufferDescriptor.h" @@ -143,6 +144,37 @@ static hidl_handle getFenceHandle(int fenceFd, char* handleStorage) } /* + * Converts a gralloc error code to a mapper error code + * + * @param grallocError [in] Gralloc error as integer. + * + * @return Corresponding Mapper error code + * + * @note There is no full 1:1 correspondence, several gralloc errors may map to Error::UNSUPPORTED. + * @note -EINVAL is mapped to Error::BAD_VALUE. + */ +static Error grallocErrorToMapperError(int grallocError) +{ + switch(grallocError) + { + case GRALLOC1_ERROR_NONE: + return Error::NONE; + case GRALLOC1_ERROR_BAD_DESCRIPTOR: + return Error::BAD_DESCRIPTOR; + case GRALLOC1_ERROR_BAD_HANDLE: + return Error::BAD_BUFFER; + case GRALLOC1_ERROR_BAD_VALUE: + case -EINVAL: + return Error::BAD_VALUE; + case GRALLOC1_ERROR_NO_RESOURCES: + return Error::NO_RESOURCES; + default: + /* Covers NOT_SHARED, UNDEFINED, UNSUPPORTED */ + return Error::UNSUPPORTED; + } +} + +/* * Locks the given buffer for the specified CPU usage. * * @param bufferHandle [in] Buffer to lock. @@ -154,6 +186,7 @@ static hidl_handle getFenceHandle(int fenceFd, char* handleStorage) * @return Error::BAD_BUFFER for an invalid buffer * Error::NO_RESOURCES when unable to duplicate fence * Error::BAD_VALUE when locking fails + * Error::UNSUPPORTED when locking fails on unsupported image formats * Error::NONE on successful buffer lock */ static Error lockBuffer(buffer_handle_t bufferHandle, @@ -214,15 +247,20 @@ static Error lockBuffer(buffer_handle_t bufferHandle, } void* data = nullptr; - if (mali_gralloc_lock(bufferHandle, cpuUsage, accessRegion.left, accessRegion.top, accessRegion.width, - accessRegion.height, &data) != 0) + const int gralloc_err = mali_gralloc_lock(bufferHandle, cpuUsage, accessRegion.left, accessRegion.top, + accessRegion.width, accessRegion.height, &data); + const Error lock_err = grallocErrorToMapperError(gralloc_err); + + if(Error::NONE == lock_err) { - return Error::BAD_VALUE; + *outData = data; + } + else + { + MALI_GRALLOC_LOGE("Locking failed with error: %d", gralloc_err); } - *outData = data; - - return Error::NONE; + return lock_err; } /* @@ -246,16 +284,19 @@ static Error unlockBuffer(buffer_handle_t bufferHandle, auto private_handle = private_handle_t::dynamicCast(bufferHandle); - const int result = mali_gralloc_unlock(bufferHandle); - if (result) + const int gralloc_err = mali_gralloc_unlock(bufferHandle); + const Error unlock_err = grallocErrorToMapperError(gralloc_err); + + if (Error::NONE == unlock_err) { - MALI_GRALLOC_LOGE("Unlocking failed with error: %d", result); - return Error::BAD_VALUE; + *outFenceFd = -1; + } + else + { + MALI_GRALLOC_LOGE("Unlocking failed with error: %d", gralloc_err); } - *outFenceFd = -1; - - return Error::NONE; + return unlock_err; } void importBuffer(const hidl_handle& rawHandle, IMapper::importBuffer_cb hidl_cb) |