summaryrefslogtreecommitdiff
path: root/gralloc4/src/hidl_common
diff options
context:
space:
mode:
Diffstat (limited to 'gralloc4/src/hidl_common')
-rw-r--r--gralloc4/src/hidl_common/Allocator.cpp95
-rw-r--r--gralloc4/src/hidl_common/Allocator.h4
-rw-r--r--gralloc4/src/hidl_common/BufferDescriptor.h59
-rw-r--r--gralloc4/src/hidl_common/Mapper.cpp460
-rw-r--r--gralloc4/src/hidl_common/Mapper.h79
-rw-r--r--gralloc4/src/hidl_common/MapperMetadata.cpp89
-rw-r--r--gralloc4/src/hidl_common/MapperMetadata.h130
-rw-r--r--gralloc4/src/hidl_common/RegisteredHandlePool.cpp11
-rw-r--r--gralloc4/src/hidl_common/RegisteredHandlePool.h4
-rw-r--r--gralloc4/src/hidl_common/SharedMetadata.h2
-rw-r--r--gralloc4/src/hidl_common/hidl_common.h42
11 files changed, 615 insertions, 360 deletions
diff --git a/gralloc4/src/hidl_common/Allocator.cpp b/gralloc4/src/hidl_common/Allocator.cpp
index 29cf3ca..08f2e8e 100644
--- a/gralloc4/src/hidl_common/Allocator.cpp
+++ b/gralloc4/src/hidl_common/Allocator.cpp
@@ -18,7 +18,13 @@
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
+#include <array>
+#include <atomic>
+#include <chrono>
#include <utils/Trace.h>
+#include <shared_mutex>
+#include <sstream>
+#include <sys/stat.h>
#include "Allocator.h"
#include "core/mali_gralloc_bufferallocation.h"
@@ -35,6 +41,35 @@ namespace allocator
namespace common
{
+struct BufferDetails {
+ std::string name;
+ uint64_t buffer_id;
+ std::vector<ino_t> inodes;
+ uint64_t format;
+ uint64_t usage;
+ uint32_t width;
+ uint32_t height;
+};
+
+uint64_t total_allocated = 0;
+std::atomic<uint16_t> next_idx = 0;
+
+// There is no atomic rounding off for atomics so next_idx can overflow. allocated_buffers should be
+// a power of 2.
+std::array<BufferDetails, 2048> allocated_buffers;
+std::shared_timed_mutex allocated_buffers_mutex;
+static_assert((allocated_buffers.size() & (allocated_buffers.size() - 1)) == 0);
+
+ino_t get_inode(int fd) {
+ struct stat fd_info;
+ int error = fstat(fd, &fd_info);
+ if (error != 0) {
+ return error;
+ }
+
+ return fd_info.st_ino;
+}
+
void allocate(const buffer_descriptor_t &bufferDescriptor, uint32_t count, IAllocator::allocate_cb hidl_cb,
std::function<int(const buffer_descriptor_t *, buffer_handle_t *)> fb_allocator)
{
@@ -45,6 +80,7 @@ void allocate(const buffer_descriptor_t &bufferDescriptor, uint32_t count, IAllo
Error error = Error::NONE;
int stride = 0;
+ bool use_placeholder = bufferDescriptor.producer_usage & GRALLOC_USAGE_PLACEHOLDER_BUFFER;
std::vector<hidl_handle> grallocBuffers;
gralloc_buffer_descriptor_t grallocBufferDescriptor[1];
@@ -66,7 +102,7 @@ void allocate(const buffer_descriptor_t &bufferDescriptor, uint32_t count, IAllo
else
#endif
{
- allocResult = mali_gralloc_buffer_allocate(grallocBufferDescriptor, 1, &tmpBuffer, nullptr);
+ allocResult = mali_gralloc_buffer_allocate(grallocBufferDescriptor, 1, &tmpBuffer, nullptr, use_placeholder);
if (allocResult != 0)
{
MALI_GRALLOC_LOGE("%s, buffer allocation failed with %d", __func__, allocResult);
@@ -118,6 +154,31 @@ void allocate(const buffer_descriptor_t &bufferDescriptor, uint32_t count, IAllo
(static_cast<shared_metadata*>(metadata_vaddr))->dataspace = aligned_optional(static_cast<Dataspace>(dataspace));
}
+ {
+ ATRACE_NAME("Update dump details");
+ const auto fd_count = hnd->fd_count + 1 /* metadata fd */;
+ std::vector<ino_t> inodes(fd_count);
+ for (size_t idx = 0; idx < fd_count; idx++) {
+ inodes[idx] = get_inode(hnd->fds[idx]);
+ }
+
+ auto idx = next_idx.fetch_add(1);
+ idx %= allocated_buffers.size();
+
+ allocated_buffers_mutex.lock_shared();
+ allocated_buffers[idx] =
+ BufferDetails{bufferDescriptor.name,
+ hnd->backing_store_id,
+ inodes,
+ bufferDescriptor.hal_format,
+ bufferDescriptor.producer_usage,
+ bufferDescriptor.width,
+ bufferDescriptor.height};
+ allocated_buffers_mutex.unlock_shared();
+
+ total_allocated++;
+ }
+
munmap(metadata_vaddr, hnd->attr_size);
}
@@ -157,6 +218,38 @@ void allocate(const buffer_descriptor_t &bufferDescriptor, uint32_t count, IAllo
}
}
+const std::string dump() {
+ using namespace std::chrono_literals;
+ if (!allocated_buffers_mutex.try_lock_for(100ms)) {
+ return "";
+ }
+
+ std::stringstream ss;
+ // TODO: Add logs to indicate overflow
+ for (int i = 0; i < std::min(total_allocated, static_cast<uint64_t>(allocated_buffers.size())); i++) {
+ const auto& [name, buffer_id, inodes, format, usage, width, height] = allocated_buffers[i];
+ ss << "buffer_id: " << buffer_id << ", inodes: ";
+ for (auto it = inodes.begin(); it != inodes.end(); it++) {
+ if (it != inodes.begin()) {
+ ss << ",";
+ }
+ ss << static_cast<int>(*it);
+ }
+ ss << ", format: 0x" << std::hex << format << std::dec;
+ ss << ", usage: 0x" << std::hex << usage << std::dec;
+ ss << ", width: " << width << ", height: " << height;
+ ss << ", name: " << name << std::endl;
+ }
+
+ allocated_buffers_mutex.unlock();
+ return ss.str();
+}
+
+int isSupported(buffer_descriptor_t *const bufDescriptor) {
+ // this is used as the criteria to determine which allocations succeed.
+ return mali_gralloc_derive_format_and_size(bufDescriptor);
+}
+
} // namespace common
} // namespace allocator
} // namespace arm
diff --git a/gralloc4/src/hidl_common/Allocator.h b/gralloc4/src/hidl_common/Allocator.h
index 8fdd5ba..e5ce174 100644
--- a/gralloc4/src/hidl_common/Allocator.h
+++ b/gralloc4/src/hidl_common/Allocator.h
@@ -54,6 +54,10 @@ using android::hardware::hidl_vec;
void allocate(const buffer_descriptor_t &bufferDescriptor, uint32_t count, IAllocator::allocate_cb hidl_cb,
std::function<int(const buffer_descriptor_t *, buffer_handle_t *)> fb_allocator = nullptr);
+const std::string dump();
+
+int isSupported(buffer_descriptor_t *const bufDescriptor);
+
} // namespace common
} // namespace allocator
} // namespace arm
diff --git a/gralloc4/src/hidl_common/BufferDescriptor.h b/gralloc4/src/hidl_common/BufferDescriptor.h
index 0d93811..2c63b6f 100644
--- a/gralloc4/src/hidl_common/BufferDescriptor.h
+++ b/gralloc4/src/hidl_common/BufferDescriptor.h
@@ -19,8 +19,7 @@
#define _GRALLOC_BUFFER_DESCRIPTOR_H_
#include "core/mali_gralloc_bufferdescriptor.h"
-
-#include "4.x/gralloc_mapper_hidl_header.h"
+#include "hidl_common.h"
#include <assert.h>
#include <inttypes.h>
@@ -30,27 +29,25 @@ namespace arm {
namespace mapper {
namespace common {
-using android::hardware::hidl_vec;
-
const size_t DESCRIPTOR_32BIT_FIELDS = 5;
const size_t DESCRIPTOR_64BIT_FIELDS = 2;
const uint64_t validUsageBits =
- BufferUsage::GPU_CUBE_MAP |
- BufferUsage::GPU_MIPMAP_COMPLETE |
- BufferUsage::CPU_READ_MASK | BufferUsage::CPU_WRITE_MASK |
- BufferUsage::GPU_TEXTURE | BufferUsage::GPU_RENDER_TARGET |
- BufferUsage::COMPOSER_OVERLAY | BufferUsage::COMPOSER_CLIENT_TARGET |
- BufferUsage::CAMERA_INPUT | BufferUsage::CAMERA_OUTPUT |
- BufferUsage::PROTECTED |
- BufferUsage::COMPOSER_CURSOR |
- BufferUsage::VIDEO_ENCODER |
- BufferUsage::RENDERSCRIPT |
- BufferUsage::VIDEO_DECODER |
- BufferUsage::SENSOR_DIRECT_DATA |
- BufferUsage::GPU_DATA_BUFFER |
- BufferUsage::VENDOR_MASK |
- BufferUsage::VENDOR_MASK_HI;
+ static_cast<uint64_t>(BufferUsage::GPU_CUBE_MAP) |
+ static_cast<uint64_t>(BufferUsage::GPU_MIPMAP_COMPLETE) |
+ static_cast<uint64_t>(BufferUsage::CPU_READ_MASK) | static_cast<uint64_t>(BufferUsage::CPU_WRITE_MASK) |
+ static_cast<uint64_t>(BufferUsage::GPU_TEXTURE) | static_cast<uint64_t>(BufferUsage::GPU_RENDER_TARGET) |
+ static_cast<uint64_t>(BufferUsage::COMPOSER_OVERLAY) | static_cast<uint64_t>(BufferUsage::COMPOSER_CLIENT_TARGET) |
+ static_cast<uint64_t>(BufferUsage::CAMERA_INPUT) | static_cast<uint64_t>(BufferUsage::CAMERA_OUTPUT) |
+ static_cast<uint64_t>(BufferUsage::PROTECTED) |
+ static_cast<uint64_t>(BufferUsage::COMPOSER_CURSOR) |
+ static_cast<uint64_t>(BufferUsage::VIDEO_ENCODER) |
+ static_cast<uint64_t>(BufferUsage::RENDERSCRIPT) |
+ static_cast<uint64_t>(BufferUsage::VIDEO_DECODER) |
+ static_cast<uint64_t>(BufferUsage::SENSOR_DIRECT_DATA) |
+ static_cast<uint64_t>(BufferUsage::GPU_DATA_BUFFER) |
+ static_cast<uint64_t>(BufferUsage::VENDOR_MASK) |
+ static_cast<uint64_t>(BufferUsage::VENDOR_MASK_HI);
template<typename BufferDescriptorInfoT>
static bool validateDescriptorInfo(const BufferDescriptorInfoT &descriptorInfo)
@@ -69,7 +66,7 @@ static bool validateDescriptorInfo(const BufferDescriptorInfoT &descriptorInfo)
}
template <typename vecT>
-static void push_descriptor_uint32(hidl_vec<vecT> *vec, size_t *pos, uint32_t val)
+static void push_descriptor_uint32(frameworks_vec<vecT> *vec, size_t *pos, uint32_t val)
{
static_assert(sizeof(val) % sizeof(vecT) == 0, "Unsupported vector type");
memcpy(vec->data() + *pos, &val, sizeof(val));
@@ -77,7 +74,7 @@ static void push_descriptor_uint32(hidl_vec<vecT> *vec, size_t *pos, uint32_t va
}
template <typename vecT>
-static uint32_t pop_descriptor_uint32(const hidl_vec<vecT> &vec, size_t *pos)
+static uint32_t pop_descriptor_uint32(const frameworks_vec<vecT> &vec, size_t *pos)
{
uint32_t val;
static_assert(sizeof(val) % sizeof(vecT) == 0, "Unsupported vector type");
@@ -87,7 +84,7 @@ static uint32_t pop_descriptor_uint32(const hidl_vec<vecT> &vec, size_t *pos)
}
template <typename vecT>
-static void push_descriptor_uint64(hidl_vec<vecT> *vec, size_t *pos, uint64_t val)
+static void push_descriptor_uint64(frameworks_vec<vecT> *vec, size_t *pos, uint64_t val)
{
static_assert(sizeof(val) % sizeof(vecT) == 0, "Unsupported vector type");
memcpy(vec->data() + *pos, &val, sizeof(val));
@@ -95,7 +92,7 @@ static void push_descriptor_uint64(hidl_vec<vecT> *vec, size_t *pos, uint64_t va
}
template <typename vecT>
-static uint64_t pop_descriptor_uint64(const hidl_vec<vecT> &vec, size_t *pos)
+static uint64_t pop_descriptor_uint64(const frameworks_vec<vecT> &vec, size_t *pos)
{
uint64_t val;
static_assert(sizeof(val) % sizeof(vecT) == 0, "Unsupported vector type");
@@ -105,23 +102,25 @@ static uint64_t pop_descriptor_uint64(const hidl_vec<vecT> &vec, size_t *pos)
}
// There can only be one string at the end of the descriptor
-static void push_descriptor_string(hidl_vec<uint8_t> *vec, size_t *pos, const std::string &str)
+static void push_descriptor_string(frameworks_vec<uint8_t> *vec, size_t *pos, const std::string &str)
{
strcpy(reinterpret_cast<char *>(vec->data() + *pos), str.c_str());
*pos += strlen(str.c_str()) + 1;
}
-static std::string pop_descriptor_string(const hidl_vec<uint8_t> &vec, size_t *pos)
+static std::string pop_descriptor_string(const frameworks_vec<uint8_t> &vec, size_t *pos)
{
- std::string str(reinterpret_cast<const char *>(vec.data() + *pos));
- *pos += str.size() + 1;
+ const char* charstr = reinterpret_cast<const char *>(vec.data() + *pos);
+ charstr += '\0';
+ std::string str(charstr);
+ str.resize(strlen(charstr));
return str;
}
template <typename vecT, typename BufferDescriptorInfoT>
-static const hidl_vec<vecT> grallocEncodeBufferDescriptor(const BufferDescriptorInfoT &descriptorInfo)
+static const frameworks_vec<vecT> grallocEncodeBufferDescriptor(const BufferDescriptorInfoT &descriptorInfo)
{
- hidl_vec<vecT> descriptor;
+ frameworks_vec<vecT> descriptor;
static_assert(sizeof(uint32_t) % sizeof(vecT) == 0, "Unsupported vector type");
size_t dynamic_size = 0;
@@ -150,7 +149,7 @@ static const hidl_vec<vecT> grallocEncodeBufferDescriptor(const BufferDescriptor
}
template <typename vecT>
-static bool grallocDecodeBufferDescriptor(const hidl_vec<vecT> &androidDescriptor, buffer_descriptor_t &grallocDescriptor)
+static bool grallocDecodeBufferDescriptor(const frameworks_vec<vecT> &androidDescriptor, buffer_descriptor_t &grallocDescriptor)
{
static_assert(sizeof(uint32_t) % sizeof(vecT) == 0, "Unsupported vector type");
size_t pos = 0;
diff --git a/gralloc4/src/hidl_common/Mapper.cpp b/gralloc4/src/hidl_common/Mapper.cpp
index 38d5377..62cac7c 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"
@@ -34,6 +35,8 @@
#include "MapperMetadata.h"
#include "SharedMetadata.h"
+#include <cstdio>
+
/* GraphicBufferMapper is expected to be valid (and leaked) during process
* termination. IMapper, and in turn, gRegisteredHandles must be valid as
* well. Create the registered handle pool on the heap, and let
@@ -49,6 +52,10 @@ namespace arm {
namespace mapper {
namespace common {
+buffer_handle_t getBuffer(void *buffer) {
+ return gRegisteredHandles->get(buffer);
+}
+
/*
* Translates the register buffer API into existing gralloc implementation
*
@@ -101,45 +108,34 @@ static Error unregisterBuffer(buffer_handle_t bufferHandle)
}
/*
- * Retrieves the file descriptor referring to a sync fence object
- *
- * @param fenceHandle [in] HIDL fence handle
- * @param outFenceFd [out] Fence file descriptor. '-1' indicates no fence
+ * Converts a gralloc error code to a mapper error code
*
- * @return false, for an invalid HIDL fence handle
- * true, otherwise
- */
-static bool getFenceFd(const hidl_handle& fenceHandle, int* outFenceFd)
-{
- auto const handle = fenceHandle.getNativeHandle();
- if (handle && handle->numFds > 1)
- {
- MALI_GRALLOC_LOGE("Invalid fence handle with %d fds", handle->numFds);
- return false;
- }
-
- *outFenceFd = (handle && handle->numFds == 1) ? handle->data[0] : -1;
- return true;
-}
-
-/*
- * Populates the HIDL fence handle for the given fence object
+ * @param grallocError [in] Gralloc error as integer.
*
- * @param fenceFd [in] Fence file descriptor
- * @param handleStorage [in] HIDL handle storage for fence
+ * @return Corresponding Mapper error code
*
- * @return HIDL fence handle
+ * @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 hidl_handle getFenceHandle(int fenceFd, char* handleStorage)
+static Error grallocErrorToMapperError(int grallocError)
{
- native_handle_t* handle = nullptr;
- if (fenceFd >= 0)
- {
- handle = native_handle_init(handleStorage, 1, 0);
- handle->data[0] = fenceFd;
+ 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;
}
-
- return hidl_handle(handle);
}
/*
@@ -147,18 +143,20 @@ static hidl_handle getFenceHandle(int fenceFd, char* handleStorage)
*
* @param bufferHandle [in] Buffer to lock.
* @param cpuUsage [in] Specifies one or more CPU usage flags to request
- * @param accessRegion [in] Portion of the buffer that the client intends to access.
+ * @param accessRegion [in] Portion of the buffer that the client intends to
+ * access.
* @param fenceFd [in] Fence file descriptor
* @param outData [out] CPU accessible buffer address
*
* @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,
uint64_t cpuUsage,
- const IMapper::Rect& accessRegion, int fenceFd,
+ const GrallocRect& accessRegion, int fenceFd,
void** outData)
{
/* dup fenceFd as it is going to be owned by gralloc. Note that it is
@@ -195,7 +193,7 @@ static Error lockBuffer(buffer_handle_t bufferHandle,
}
auto private_handle = private_handle_t::dynamicCast(bufferHandle);
- if (private_handle->cpu_write != 0 && (cpuUsage & BufferUsage::CPU_WRITE_MASK))
+ if (private_handle->cpu_write != 0 && (cpuUsage & static_cast<uint64_t>(BufferUsage::CPU_WRITE_MASK)))
{
if (fenceFd >= 0)
{
@@ -214,15 +212,22 @@ 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.right - accessRegion.left,
+ accessRegion.bottom - accessRegion.top, &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;
}
/*
@@ -244,141 +249,95 @@ static Error unlockBuffer(buffer_handle_t bufferHandle,
return Error::BAD_BUFFER;
}
- auto private_handle = private_handle_t::dynamicCast(bufferHandle);
+ const int gralloc_err = mali_gralloc_unlock(bufferHandle);
+ const Error unlock_err = grallocErrorToMapperError(gralloc_err);
- const int result = mali_gralloc_unlock(bufferHandle);
- if (result)
+ if (Error::NONE == unlock_err)
{
- MALI_GRALLOC_LOGE("Unlocking failed with error: %d", result);
- return Error::BAD_VALUE;
+ *outFenceFd = -1;
}
-
- *outFenceFd = -1;
-
- return Error::NONE;
-}
-
-void importBuffer(const hidl_handle& rawHandle, IMapper::importBuffer_cb hidl_cb)
-{
- if (!rawHandle.getNativeHandle())
+ else
{
- MALI_GRALLOC_LOGE("Invalid buffer handle to import");
- hidl_cb(Error::BAD_BUFFER, nullptr);
- return;
+ MALI_GRALLOC_LOGE("Unlocking failed with error: %d",
+ gralloc_err);
+ return Error::BAD_BUFFER;
}
- native_handle_t* bufferHandle = native_handle_clone(rawHandle.getNativeHandle());
- if (!bufferHandle)
- {
- MALI_GRALLOC_LOGE("Failed to clone buffer handle");
- hidl_cb(Error::NO_RESOURCES, nullptr);
- return;
- }
+ return unlock_err;
+}
- const Error error = registerBuffer(bufferHandle);
+Error importBuffer(const native_handle_t *inBuffer, buffer_handle_t *outBuffer)
+{
+ *outBuffer = const_cast<buffer_handle_t>(native_handle_clone(inBuffer));
+ const Error error = registerBuffer(*outBuffer);
if (error != Error::NONE)
{
- native_handle_close(bufferHandle);
- native_handle_delete(bufferHandle);
-
- hidl_cb(error, nullptr);
- return;
+ return error;
}
- auto *private_handle = static_cast<private_handle_t *>(bufferHandle);
-
- if (gRegisteredHandles->add(bufferHandle) == false)
+ if (gRegisteredHandles->add(*outBuffer) == false)
{
/* The newly cloned handle is already registered. This can only happen
* when a handle previously registered was native_handle_delete'd instead
* of freeBuffer'd.
*/
MALI_GRALLOC_LOGE("Handle %p has already been imported; potential fd leaking",
- bufferHandle);
- unregisterBuffer(bufferHandle);
- native_handle_close(bufferHandle);
- native_handle_delete(bufferHandle);
-
- hidl_cb(Error::NO_RESOURCES, nullptr);
- return;
+ outBuffer);
+ unregisterBuffer(*outBuffer);
+ return Error::NO_RESOURCES;
}
- hidl_cb(Error::NONE, bufferHandle);
+ return Error::NONE;
}
-Error freeBuffer(void* buffer)
+Error freeBuffer(buffer_handle_t bufferHandle)
{
- native_handle_t * const bufferHandle = gRegisteredHandles->remove(buffer);
- if (!bufferHandle)
+ native_handle_t *handle = gRegisteredHandles->remove(bufferHandle);
+ if (handle == nullptr)
{
- MALI_GRALLOC_LOGE("Invalid buffer handle %p to freeBuffer", buffer);
+ MALI_GRALLOC_LOGE("Invalid buffer handle %p to freeBuffer", bufferHandle);
return Error::BAD_BUFFER;
}
- const Error status = unregisterBuffer(bufferHandle);
+ const Error status = unregisterBuffer(handle);
if (status != Error::NONE)
{
return status;
}
- native_handle_close(bufferHandle);
- native_handle_delete(bufferHandle);
+ native_handle_close(handle);
+ native_handle_delete(handle);
return Error::NONE;
}
-void lock(void* buffer, uint64_t cpuUsage, const IMapper::Rect& accessRegion,
- const hidl_handle& acquireFence, IMapper::lock_cb hidl_cb)
+Error lock(buffer_handle_t bufferHandle, uint64_t cpuUsage, const GrallocRect &accessRegion, int acquireFence, void **outData)
{
- buffer_handle_t bufferHandle = gRegisteredHandles->get(buffer);
+ *outData = nullptr;
if (!bufferHandle || private_handle_t::validate(bufferHandle) < 0)
{
- MALI_GRALLOC_LOGE("Buffer to lock: %p is not valid", buffer);
- hidl_cb(Error::BAD_BUFFER, nullptr);
- return;
- }
-
- int fenceFd;
- if (!getFenceFd(acquireFence, &fenceFd))
- {
- hidl_cb(Error::BAD_VALUE, nullptr);
- return;
+ MALI_GRALLOC_LOGE("Buffer to lock: %p is not valid",
+ bufferHandle);
+ return Error::BAD_BUFFER;
}
- void* data = nullptr;
- const Error error = lockBuffer(bufferHandle, cpuUsage, accessRegion, fenceFd, &data);
-
- hidl_cb(error, data);
+ const Error error = lockBuffer(bufferHandle, cpuUsage, accessRegion,
+ acquireFence, outData);
+ return error;
}
-void unlock(void* buffer, IMapper::unlock_cb hidl_cb)
-{
- buffer_handle_t bufferHandle = gRegisteredHandles->get(buffer);
- if (!bufferHandle)
- {
- MALI_GRALLOC_LOGE("Buffer to unlock: %p has not been registered with Gralloc", buffer);
- hidl_cb(Error::BAD_BUFFER, nullptr);
- return;
+Error unlock(buffer_handle_t bufferHandle, int *releaseFence) {
+ if(bufferHandle == nullptr) return Error::BAD_BUFFER;
+ if(!gRegisteredHandles->isRegistered(bufferHandle)) {
+ MALI_GRALLOC_LOGE("Buffer to unlock: %p has not been registered with Gralloc",
+ bufferHandle);
+ return Error::BAD_BUFFER;
}
- int fenceFd;
- const Error error = unlockBuffer(bufferHandle, &fenceFd);
- if (error == Error::NONE)
- {
- NATIVE_HANDLE_DECLARE_STORAGE(fenceStorage, 1, 0);
- hidl_cb(error, getFenceHandle(fenceFd, fenceStorage));
-
- if (fenceFd >= 0)
- {
- close(fenceFd);
- }
- }
- else
- {
- hidl_cb(error, nullptr);
- }
+ const Error error = unlockBuffer(bufferHandle, releaseFence);
+ return error;
}
-
+#ifdef GRALLOC_MAPPER_4
Error validateBufferSize(void* buffer,
const IMapper::BufferDescriptorInfo& descriptorInfo,
uint32_t in_stride)
@@ -430,7 +389,7 @@ Error validateBufferSize(void* buffer,
if (in_stride != 0 && (uint32_t)gralloc_buffer->stride != in_stride)
{
- MALI_GRALLOC_LOGE("Stride mismatch. Expected stride = %d, Buffer stride = %d",
+ MALI_GRALLOC_LOGE("Stride mismatch. Expected stride = %d, Buffer stride = %" PRIu64,
in_stride, gralloc_buffer->stride);
return Error::BAD_VALUE;
}
@@ -455,21 +414,21 @@ Error validateBufferSize(void* buffer,
{
if (gralloc_buffer->plane_info[i].byte_stride != grallocDescriptor.plane_info[i].byte_stride)
{
- MALI_GRALLOC_LOGE("Buffer byte stride 0x%x mismatch with desc byte stride 0x%x in plane %d ",
+ MALI_GRALLOC_LOGE("Buffer byte stride %" PRIu64 " mismatch with desc byte stride %" PRIu64 " in plane %d ",
gralloc_buffer->plane_info[i].byte_stride, grallocDescriptor.plane_info[i].byte_stride, i);
return Error::BAD_VALUE;
}
if (gralloc_buffer->plane_info[i].alloc_width != grallocDescriptor.plane_info[i].alloc_width)
{
- MALI_GRALLOC_LOGE("Buffer alloc width 0x%x mismatch with desc alloc width 0x%x in plane %d ",
+ MALI_GRALLOC_LOGE("Buffer alloc width %" PRIu64 " mismatch with desc alloc width %" PRIu64 " in plane %d ",
gralloc_buffer->plane_info[i].alloc_width, grallocDescriptor.plane_info[i].alloc_width, i);
return Error::BAD_VALUE;
}
if (gralloc_buffer->plane_info[i].alloc_height != grallocDescriptor.plane_info[i].alloc_height)
{
- MALI_GRALLOC_LOGE("Buffer alloc height 0x%x mismatch with desc alloc height 0x%x in plane %d ",
+ MALI_GRALLOC_LOGE("Buffer alloc height %" PRIu64 " mismatch with desc alloc height %" PRIu64 " in plane %d ",
gralloc_buffer->plane_info[i].alloc_height, grallocDescriptor.plane_info[i].alloc_height, i);
return Error::BAD_VALUE;
}
@@ -499,28 +458,32 @@ Error validateBufferSize(void* buffer,
return Error::NONE;
}
+#endif
-void getTransportSize(void* buffer, IMapper::getTransportSize_cb hidl_cb)
+Error getTransportSize(buffer_handle_t bufferHandle, uint32_t *outNumFds, uint32_t *outNumInts)
{
+ *outNumFds = 0;
+ *outNumInts = 0;
/* The buffer must have been allocated by Gralloc */
- buffer_handle_t bufferHandle = gRegisteredHandles->get(buffer);
if (!bufferHandle)
{
- MALI_GRALLOC_LOGE("Buffer %p is not registered with Gralloc", bufferHandle);
- hidl_cb(Error::BAD_BUFFER, -1, -1);
- return;
+ MALI_GRALLOC_LOGE("Buffer %p is not registered with Gralloc",
+ bufferHandle);
+ return Error::BAD_BUFFER;
}
if (private_handle_t::validate(bufferHandle) < 0)
{
- MALI_GRALLOC_LOGE("Buffer %p is corrupted", buffer);
- hidl_cb(Error::BAD_BUFFER, -1, -1);
- return;
+ MALI_GRALLOC_LOGE("Buffer %p is corrupted", bufferHandle);
+ return Error::BAD_BUFFER;
}
- hidl_cb(Error::NONE, bufferHandle->numFds, bufferHandle->numInts);
+ *outNumFds = bufferHandle->numFds;
+ *outNumInts = bufferHandle->numInts;
+ return Error::NONE;
}
-void isSupported(const IMapper::BufferDescriptorInfo& description, IMapper::isSupported_cb hidl_cb)
+#ifdef GRALLOC_MAPPER_4
+bool isSupported(const IMapper::BufferDescriptorInfo &description)
{
buffer_descriptor_t grallocDescriptor;
grallocDescriptor.width = description.width;
@@ -536,39 +499,36 @@ void isSupported(const IMapper::BufferDescriptorInfo& description, IMapper::isSu
if (result != 0)
{
MALI_GRALLOC_LOGV("Allocation for the given description will not succeed. error: %d", result);
- hidl_cb(Error::NONE, false);
+ return false;
}
else
{
- hidl_cb(Error::NONE, true);
+ return true;
}
}
-void flushLockedBuffer(void *buffer, IMapper::flushLockedBuffer_cb hidl_cb)
+#endif
+Error flushLockedBuffer(buffer_handle_t handle)
{
- buffer_handle_t handle = gRegisteredHandles->get(buffer);
if (private_handle_t::validate(handle) < 0)
{
- MALI_GRALLOC_LOGE("Bandle: %p is corrupted", handle);
- hidl_cb(Error::BAD_BUFFER, hidl_handle{});
- return;
+ MALI_GRALLOC_LOGE("Handle: %p is corrupted", handle);
+ return Error::BAD_BUFFER;
}
auto private_handle = static_cast<const private_handle_t *>(handle);
if (!private_handle->cpu_write && !private_handle->cpu_read)
{
MALI_GRALLOC_LOGE("Attempt to call flushLockedBuffer() on an unlocked buffer (%p)", handle);
- hidl_cb(Error::BAD_BUFFER, hidl_handle{});
- return;
+ return Error::BAD_BUFFER;
}
mali_gralloc_ion_sync_end(private_handle, false, true);
- hidl_cb(Error::NONE, hidl_handle{});
+ return Error::NONE;
}
-Error rereadLockedBuffer(void *buffer)
+Error rereadLockedBuffer(buffer_handle_t handle)
{
- buffer_handle_t handle = gRegisteredHandles->get(buffer);
if (private_handle_t::validate(handle) < 0)
{
MALI_GRALLOC_LOGE("Buffer: %p is corrupted", handle);
@@ -586,31 +546,29 @@ Error rereadLockedBuffer(void *buffer)
return Error::NONE;
}
-void get(void *buffer, const IMapper::MetadataType &metadataType, IMapper::get_cb hidl_cb)
+Error get(buffer_handle_t buffer, const MetadataType &metadataType, std::vector<uint8_t> &vec)
{
/* The buffer must have been allocated by Gralloc */
- const private_handle_t *handle = static_cast<const private_handle_t *>(gRegisteredHandles->get(buffer));
+ const private_handle_t *handle = static_cast<const private_handle_t *>(buffer);
if (handle == nullptr)
{
MALI_GRALLOC_LOGE("Buffer: %p has not been registered with Gralloc", buffer);
- hidl_cb(Error::BAD_BUFFER, hidl_vec<uint8_t>());
- return;
+ return Error::BAD_BUFFER;
}
if (mali_gralloc_reference_validate((buffer_handle_t)handle) < 0)
{
MALI_GRALLOC_LOGE("Buffer: %p is not imported", handle);
- hidl_cb(Error::BAD_VALUE, hidl_vec<uint8_t>());
- return;
+ return Error::BAD_VALUE;
}
- get_metadata(handle, metadataType, hidl_cb);
+ return get_metadata(handle, metadataType, vec);
}
-Error set(void *buffer, const IMapper::MetadataType &metadataType, const hidl_vec<uint8_t> &metadata)
+Error set(buffer_handle_t buffer, const MetadataType &metadataType, const hidl_vec<uint8_t> &metadata)
{
/* The buffer must have been allocated by Gralloc */
- const private_handle_t *handle = static_cast<const private_handle_t *>(gRegisteredHandles->get(buffer));
+ const private_handle_t *handle = static_cast<const private_handle_t *>(buffer);
if (handle == nullptr)
{
MALI_GRALLOC_LOGE("Buffer: %p has not been registered with Gralloc", buffer);
@@ -626,135 +584,137 @@ Error set(void *buffer, const IMapper::MetadataType &metadataType, const hidl_ve
return set_metadata(handle, metadataType, metadata);
}
-void listSupportedMetadataTypes(IMapper::listSupportedMetadataTypes_cb hidl_cb)
+MetadataTypeDescription describeStandard(StandardMetadataType meta, bool isGettable, bool isSettable)
+{
+ return MetadataTypeDescription(MetadataType(GRALLOC4_STANDARD_METADATA_TYPE,
+ static_cast<uint64_t>(meta)), "", isGettable, isSettable);
+}
+
+std::vector<MetadataTypeDescription> listSupportedMetadataTypes()
{
/* Returns a vector of {metadata type, description, isGettable, isSettable}
* Only non-standardMetadataTypes require a description.
*/
- hidl_vec<IMapper::MetadataTypeDescription> descriptions = {
- { android::gralloc4::MetadataType_BufferId, "", true, false },
- { android::gralloc4::MetadataType_Name, "", true, false },
- { android::gralloc4::MetadataType_Width, "", true, false },
- { android::gralloc4::MetadataType_Height, "", true, false },
- { android::gralloc4::MetadataType_LayerCount, "", true, false },
- { android::gralloc4::MetadataType_PixelFormatRequested, "", true, false },
- { android::gralloc4::MetadataType_PixelFormatFourCC, "", true, false },
- { android::gralloc4::MetadataType_PixelFormatModifier, "", true, false },
- { android::gralloc4::MetadataType_Usage, "", true, false },
- { android::gralloc4::MetadataType_AllocationSize, "", true, false },
- { android::gralloc4::MetadataType_ProtectedContent, "", true, false },
- { android::gralloc4::MetadataType_Compression, "", true, false },
- { android::gralloc4::MetadataType_Interlaced, "", true, false },
- { android::gralloc4::MetadataType_ChromaSiting, "", true, false },
- { android::gralloc4::MetadataType_PlaneLayouts, "", true, false },
- { android::gralloc4::MetadataType_Dataspace, "", true, true },
- { android::gralloc4::MetadataType_BlendMode, "", true, true },
- { android::gralloc4::MetadataType_Smpte2086, "", true, true },
- { android::gralloc4::MetadataType_Cta861_3, "", true, true },
- { android::gralloc4::MetadataType_Smpte2094_40, "", true, true },
- { android::gralloc4::MetadataType_Crop, "", true, true },
+ std::array<MetadataTypeDescription, 23> descriptions = {
+ describeStandard(StandardMetadataType::BUFFER_ID, true, false ),
+ describeStandard(StandardMetadataType::NAME, true, false ),
+ describeStandard(StandardMetadataType::WIDTH, true, false ),
+ describeStandard(StandardMetadataType::STRIDE, true, false ),
+ describeStandard(StandardMetadataType::HEIGHT, true, false ),
+ describeStandard(StandardMetadataType::LAYER_COUNT, true, false ),
+ describeStandard(StandardMetadataType::PIXEL_FORMAT_REQUESTED, true, false ),
+ describeStandard(StandardMetadataType::PIXEL_FORMAT_FOURCC, true, false ),
+ describeStandard(StandardMetadataType::PIXEL_FORMAT_MODIFIER, true, false ),
+ describeStandard(StandardMetadataType::USAGE, true, false ),
+ describeStandard(StandardMetadataType::ALLOCATION_SIZE, true, false ),
+ describeStandard(StandardMetadataType::PROTECTED_CONTENT, true, false ),
+ describeStandard(StandardMetadataType::COMPRESSION, true, false ),
+ describeStandard(StandardMetadataType::INTERLACED, true, false ),
+ describeStandard(StandardMetadataType::CHROMA_SITING, true, false ),
+ describeStandard(StandardMetadataType::PLANE_LAYOUTS, true, false ),
+ describeStandard(StandardMetadataType::DATASPACE, true, true ),
+ describeStandard(StandardMetadataType::BLEND_MODE, true, true ),
+ describeStandard(StandardMetadataType::SMPTE2086, true, true ),
+ describeStandard(StandardMetadataType::CTA861_3, true, true ),
+ describeStandard(StandardMetadataType::SMPTE2094_40, true, true ),
+ describeStandard(StandardMetadataType::CROP, true, true ),
/* Arm vendor metadata */
{ ArmMetadataType_PLANE_FDS,
- "Vector of file descriptors of each plane", true, false },
- };
- hidl_cb(Error::NONE, descriptions);
- return;
+ "Vector of file descriptors of each plane", true, false},
+ };
+ return std::vector<MetadataTypeDescription>(descriptions.begin(), descriptions.end());
}
-static hidl_vec<IMapper::MetadataDump> dumpBufferHelper(const private_handle_t* handle)
+static BufferDump dumpBufferHelper(const private_handle_t *handle)
{
- hidl_vec<IMapper::MetadataType> standardMetadataTypes = {
- android::gralloc4::MetadataType_BufferId,
- android::gralloc4::MetadataType_Name,
- android::gralloc4::MetadataType_Width,
- android::gralloc4::MetadataType_Height,
- android::gralloc4::MetadataType_LayerCount,
- android::gralloc4::MetadataType_PixelFormatRequested,
- android::gralloc4::MetadataType_PixelFormatFourCC,
- android::gralloc4::MetadataType_PixelFormatModifier,
- android::gralloc4::MetadataType_Usage,
- android::gralloc4::MetadataType_AllocationSize,
- android::gralloc4::MetadataType_ProtectedContent,
- android::gralloc4::MetadataType_Compression,
- android::gralloc4::MetadataType_Interlaced,
- android::gralloc4::MetadataType_ChromaSiting,
- android::gralloc4::MetadataType_PlaneLayouts,
- android::gralloc4::MetadataType_Dataspace,
- android::gralloc4::MetadataType_BlendMode,
- android::gralloc4::MetadataType_Smpte2086,
- android::gralloc4::MetadataType_Cta861_3,
- android::gralloc4::MetadataType_Smpte2094_40,
- android::gralloc4::MetadataType_Crop,
+ static std::array<MetadataType, 21> standardMetadataTypes = {
+ MetadataType(StandardMetadataType::BUFFER_ID),
+ MetadataType(StandardMetadataType::NAME),
+ MetadataType(StandardMetadataType::WIDTH),
+ MetadataType(StandardMetadataType::HEIGHT),
+ MetadataType(StandardMetadataType::LAYER_COUNT),
+ MetadataType(StandardMetadataType::PIXEL_FORMAT_REQUESTED),
+ MetadataType(StandardMetadataType::PIXEL_FORMAT_FOURCC),
+ MetadataType(StandardMetadataType::PIXEL_FORMAT_MODIFIER),
+ MetadataType(StandardMetadataType::USAGE),
+ MetadataType(StandardMetadataType::ALLOCATION_SIZE),
+ MetadataType(StandardMetadataType::PROTECTED_CONTENT),
+ MetadataType(StandardMetadataType::COMPRESSION),
+ MetadataType(StandardMetadataType::INTERLACED),
+ MetadataType(StandardMetadataType::CHROMA_SITING),
+ MetadataType(StandardMetadataType::PLANE_LAYOUTS),
+ MetadataType(StandardMetadataType::DATASPACE),
+ MetadataType(StandardMetadataType::BLEND_MODE),
+ MetadataType(StandardMetadataType::SMPTE2086),
+ MetadataType(StandardMetadataType::CTA861_3),
+ MetadataType(StandardMetadataType::SMPTE2094_40),
+ MetadataType(StandardMetadataType::CROP),
};
- std::vector<IMapper::MetadataDump> metadataDumps;
+ std::vector<MetadataDump> metadataDumps;
for (const auto& metadataType: standardMetadataTypes)
{
- get_metadata(handle, metadataType, [&metadataDumps, &metadataType](Error error, hidl_vec<uint8_t> metadata) {
- switch(error)
- {
- case Error::NONE:
- metadataDumps.push_back({metadataType, metadata});
- break;
- case Error::UNSUPPORTED:
- default:
- return;
- }
- });
+ std::vector<uint8_t> metadata;
+ Error error = get_metadata(handle, metadataType, metadata);
+ if (error == Error::NONE)
+ {
+ metadataDumps.push_back(MetadataDump(MetadataType(metadataType), metadata));
+ }
+ else
+ {
+ return BufferDump();
+ }
}
- return hidl_vec<IMapper::MetadataDump>(metadataDumps);
+ return BufferDump(metadataDumps);
}
-void dumpBuffer(void *buffer, IMapper::dumpBuffer_cb hidl_cb)
+Error dumpBuffer(buffer_handle_t buffer, BufferDump &bufferDump)
{
- IMapper::BufferDump bufferDump{};
- auto handle = static_cast<const private_handle_t *>(gRegisteredHandles->get(buffer));
+ auto handle = static_cast<const private_handle_t *>(buffer);
if (handle == nullptr)
{
MALI_GRALLOC_LOGE("Buffer: %p has not been registered with Gralloc", buffer);
- hidl_cb(Error::BAD_BUFFER, bufferDump);
- return;
+ return Error::BAD_BUFFER;
}
- bufferDump.metadataDump = dumpBufferHelper(handle);
- hidl_cb(Error::NONE, bufferDump);
+ bufferDump = dumpBufferHelper(handle);
+ return Error::NONE;
}
-void dumpBuffers(IMapper::dumpBuffers_cb hidl_cb)
+std::vector<BufferDump> dumpBuffers()
{
- std::vector<IMapper::BufferDump> bufferDumps;
+ std::vector<BufferDump> bufferDumps;
gRegisteredHandles->for_each([&bufferDumps](buffer_handle_t buffer) {
- IMapper::BufferDump bufferDump { dumpBufferHelper(static_cast<const private_handle_t *>(buffer)) };
+ BufferDump bufferDump { dumpBufferHelper(static_cast<const private_handle_t *>(buffer)) };
bufferDumps.push_back(bufferDump);
});
- hidl_cb(Error::NONE, hidl_vec<IMapper::BufferDump>(bufferDumps));
+ return bufferDumps;
}
-void getReservedRegion(void *buffer, IMapper::getReservedRegion_cb hidl_cb)
+Error getReservedRegion(buffer_handle_t buffer, void **outReservedRegion, uint64_t &outReservedSize)
{
- auto handle = static_cast<const private_handle_t *>(gRegisteredHandles->get(buffer));
+ auto handle = static_cast<const private_handle_t *>(buffer);
if (handle == nullptr)
{
MALI_GRALLOC_LOGE("Buffer: %p has not been registered with Gralloc", buffer);
- hidl_cb(Error::BAD_BUFFER, 0, 0);
- return;
+ return Error::BAD_BUFFER;
}
else if (handle->reserved_region_size == 0)
{
MALI_GRALLOC_LOGE("Buffer: %p has no reserved region", buffer);
- hidl_cb(Error::BAD_BUFFER, 0, 0);
- return;
+ return Error::BAD_BUFFER;
}
auto metadata_addr_oe = mali_gralloc_reference_get_metadata_addr(handle);
if (!metadata_addr_oe.has_value()) {
- hidl_cb(Error::BAD_BUFFER, 0, 0);
+ return Error::BAD_BUFFER;
}
- void *reserved_region = static_cast<std::byte *>(metadata_addr_oe.value())
+ *outReservedRegion = static_cast<std::byte *>(metadata_addr_oe.value())
+ mapper::common::shared_metadata_size();
- hidl_cb(Error::NONE, reserved_region, handle->reserved_region_size);
+ outReservedSize = handle->reserved_region_size;
+ return Error::NONE;
}
} // namespace common
diff --git a/gralloc4/src/hidl_common/Mapper.h b/gralloc4/src/hidl_common/Mapper.h
index 6d114cc..c77128c 100644
--- a/gralloc4/src/hidl_common/Mapper.h
+++ b/gralloc4/src/hidl_common/Mapper.h
@@ -23,7 +23,9 @@
#include "mali_gralloc_log.h"
#include "core/mali_gralloc_bufferdescriptor.h"
-#include "4.x/gralloc_mapper_hidl_header.h"
+#include "MapperMetadata.h"
+#include "hidl_common.h"
+#include "mali_gralloc_error.h"
namespace arm
{
@@ -32,24 +34,42 @@ namespace mapper
namespace common
{
-using android::hardware::hidl_handle;
-using android::hardware::hidl_vec;
+
+using aidl::android::hardware::graphics::common::Rect;
+
using android::hardware::Void;
+class GrallocRect {
+ public:
+ int left;
+ int top;
+ int right;
+ int bottom;
+ GrallocRect(Rect rect) {
+ left = rect.left;
+ top = rect.top;
+ right = rect.right;
+ bottom = rect.bottom;
+ }
+#ifdef GRALLOC_MAPPER_4
+ GrallocRect(IMapper::Rect rect) {
+ left = rect.left;
+ top = rect.top;
+ right = rect.left + rect.width;
+ bottom = rect.top + rect.height;
+ }
+#endif
+};
+
/**
* Imports a raw buffer handle to create an imported buffer handle for use with
* the rest of the mapper or with other in-process libraries.
*
- * @param rawHandle [in] Raw buffer handle to import.
- * @param hidl_cb [in] HIDL Callback function to export output information
- * @param hidl_cb [in] HIDL callback function generating -
- * error : NONE upon success. Otherwise,
- * BAD_BUFFER for an invalid buffer
- * NO_RESOURCES when the raw handle cannot be imported
- * BAD_VALUE when any of the specified attributes are invalid
- * buffer : Imported buffer handle
+ * @param bufferHandle [in] Buffer handle to import.
+ * @param outBuffer [in] imported Buffer
*/
-void importBuffer(const hidl_handle &rawHandle, IMapper::importBuffer_cb hidl_cb);
+Error importBuffer(const native_handle_t *inBuffer, buffer_handle_t *outBuffer);
+
/**
* Frees a buffer handle and releases all the resources associated with it
@@ -59,7 +79,10 @@ void importBuffer(const hidl_handle &rawHandle, IMapper::importBuffer_cb hidl_cb
* @return Error::BAD_BUFFER for an invalid buffer / when failed to free the buffer
* Error::NONE on successful free
*/
-Error freeBuffer(void *buffer);
+Error freeBuffer(buffer_handle_t buffer);
+
+buffer_handle_t getBuffer(void *buffer);
+native_handle_t* removeBuffer(void **buffer);
/**
* Locks the given buffer for the specified CPU usage.
@@ -76,8 +99,7 @@ Error freeBuffer(void *buffer);
* bytesPerPixel: v3.X Only. Number of bytes per pixel in the buffer
* bytesPerStride: v3.X Only. Bytes per stride of the buffer
*/
-void lock(void *buffer, uint64_t cpuUsage, const IMapper::Rect &accessRegion, const hidl_handle &acquireFence,
- IMapper::lock_cb hidl_cb);
+Error lock(buffer_handle_t buffer, uint64_t cpuUsage, const GrallocRect &accessRegion, int acquireFence, void **outData);
/**
* Unlocks a buffer to indicate all CPU accesses to the buffer have completed
@@ -88,7 +110,7 @@ void lock(void *buffer, uint64_t cpuUsage, const IMapper::Rect &accessRegion, co
* BAD_BUFFER for an invalid buffer
* releaseFence: Referrs to a sync fence object
*/
-void unlock(void *buffer, IMapper::unlock_cb hidl_cb);
+Error unlock(const native_handle_t *buffer, int *releaseFence);
/**
* Validates the buffer against specified descriptor attributes
@@ -102,7 +124,9 @@ void unlock(void *buffer, IMapper::unlock_cb hidl_cb);
* Error::BAD_BUFFER upon bad buffer input
* Error::BAD_VALUE when any of the specified attributes are invalid
*/
+#ifdef GRALLOC_MAPPER_4
Error validateBufferSize(void *buffer, const IMapper::BufferDescriptorInfo &descriptorInfo, uint32_t stride);
+#endif
/**
* Get the transport size of a buffer
@@ -114,7 +138,7 @@ Error validateBufferSize(void *buffer, const IMapper::BufferDescriptorInfo &desc
* numFds: Number of file descriptors needed for transport
* numInts: Number of integers needed for transport
*/
-void getTransportSize(void *buffer, IMapper::getTransportSize_cb hidl_cb);
+Error getTransportSize(buffer_handle_t bufferHandle, uint32_t *outNumFds, uint32_t *outNumInts);
/**
* Test whether the given BufferDescriptorInfo is allocatable.
@@ -125,8 +149,9 @@ void getTransportSize(void *buffer, IMapper::getTransportSize_cb hidl_cb);
* BAD_VALUE, Otherwise,
* supported: Whether the description can be allocated
*/
-void isSupported(const IMapper::BufferDescriptorInfo &description, IMapper::isSupported_cb hidl_cb);
-
+#ifdef GRALLOC_MAPPER_4
+bool isSupported(const IMapper::BufferDescriptorInfo &description);
+#endif
/* TODO: implement this feature for exynos */
/**
* Flushes the CPU caches of a mapped buffer.
@@ -137,7 +162,7 @@ void isSupported(const IMapper::BufferDescriptorInfo &description, IMapper::isSu
* has not been locked.
* releaseFence: Empty fence signaling completion as all work is completed within the call.
*/
-void flushLockedBuffer(void *buffer, IMapper::flushLockedBuffer_cb hidl_cb);
+Error flushLockedBuffer(buffer_handle_t buffer);
/* TODO: implement this feature for exynos */
/**
@@ -148,7 +173,7 @@ void flushLockedBuffer(void *buffer, IMapper::flushLockedBuffer_cb hidl_cb);
* @return Error::NONE upon success.
* Error::BAD_BUFFER for an invalid buffer or a buffer that has not been locked.
*/
-Error rereadLockedBuffer(void *buffer);
+Error rereadLockedBuffer(buffer_handle_t handle);
/**
* Retrieves a Buffer's metadata value.
@@ -161,7 +186,7 @@ Error rereadLockedBuffer(void *buffer);
* UNSUPPORTED on error when reading or unsupported metadata type.
* metadata: Vector of bytes representing the metadata value.
*/
-void get(void *buffer, const IMapper::MetadataType &metadataType, IMapper::get_cb hidl_cb);
+Error get(buffer_handle_t buffer, const MetadataType &metadataType, std::vector<uint8_t> &vec);
/**
* Sets a Buffer's metadata value.
@@ -174,7 +199,7 @@ void get(void *buffer, const IMapper::MetadataType &metadataType, IMapper::get_c
* Error::BAD_BUFFER on invalid buffer argument.
* Error::UNSUPPORTED on error when writing or unsupported metadata type.
*/
-Error set(void *buffer, const IMapper::MetadataType &metadataType, const hidl_vec<uint8_t> &metadata);
+Error set(buffer_handle_t buffer, const MetadataType &metadataType, const frameworks_vec<uint8_t> &metadata);
/**
* Lists all the MetadataTypes supported by IMapper as well as a description
@@ -189,7 +214,7 @@ Error set(void *buffer, const IMapper::MetadataType &metadataType, const hidl_ve
* descriptions: vector of MetadataTypeDescriptions that represent the
* MetadataTypes supported by the device.
*/
-void listSupportedMetadataTypes(IMapper::listSupportedMetadataTypes_cb hidl_cb);
+std::vector<MetadataTypeDescription> listSupportedMetadataTypes();
/**
* Dumps a buffer's metadata.
@@ -203,7 +228,7 @@ void listSupportedMetadataTypes(IMapper::listSupportedMetadataTypes_cb hidl_cb);
* resources.
* bufferDump: Struct representing the metadata being dumped
*/
-void dumpBuffer(void *buffer, IMapper::dumpBuffer_cb hidl_cb);
+Error dumpBuffer(buffer_handle_t buffer, BufferDump &out);
/**
* Dumps the metadata for all the buffers in the current process.
@@ -215,7 +240,7 @@ void dumpBuffer(void *buffer, IMapper::dumpBuffer_cb hidl_cb);
* resources.
* bufferDumps: Vector of structs representing the buffers being dumped
*/
-void dumpBuffers(IMapper::dumpBuffers_cb hidl_cb);
+std::vector<BufferDump> dumpBuffers();
/**
* Returns the region of shared memory associated with the buffer that is
@@ -243,7 +268,7 @@ void dumpBuffers(IMapper::dumpBuffers_cb hidl_cb);
* reservedSize: the size of the reservedRegion that was requested
* in the BufferDescriptorInfo.
*/
-void getReservedRegion(void *buffer, IMapper::getReservedRegion_cb _hidl_cb);
+Error getReservedRegion(buffer_handle_t buffer, void **outReservedRegion, uint64_t &outReservedSize);
} // namespace common
} // namespace mapper
diff --git a/gralloc4/src/hidl_common/MapperMetadata.cpp b/gralloc4/src/hidl_common/MapperMetadata.cpp
index 81835a3..76a9865 100644
--- a/gralloc4/src/hidl_common/MapperMetadata.cpp
+++ b/gralloc4/src/hidl_common/MapperMetadata.cpp
@@ -29,6 +29,7 @@
#include "mali_gralloc_formats.h"
#include <pixel-gralloc/metadata.h>
+#include <pixel-gralloc/utils.h>
#include <vector>
@@ -52,9 +53,13 @@ using aidl::android::hardware::graphics::common::Cta861_3;
using aidl::arm::graphics::ArmMetadataType;
#endif
-using MetadataType = android::hardware::graphics::mapper::V4_0::IMapper::MetadataType;
+bool isStandardMetadataType(const MetadataType &metadataType) {
+ return !std::strncmp(metadataType.name.c_str(),
+ GRALLOC4_STANDARD_METADATA_TYPE,
+ metadataType.name.size());
+}
-static int get_num_planes(const private_handle_t *hnd)
+int get_num_planes(const private_handle_t *hnd)
{
if (is_exynos_format(hnd->get_alloc_format()))
{
@@ -282,7 +287,7 @@ static std::vector<std::vector<PlaneLayoutComponent>> plane_layout_components_fr
return std::vector<std::vector<PlaneLayoutComponent>>(0);
}
-static android::status_t get_plane_layouts(const private_handle_t *handle, std::vector<PlaneLayout> *layouts)
+android::status_t get_plane_layouts(const private_handle_t *handle, std::vector<PlaneLayout> *layouts)
{
const int num_planes = get_num_planes(handle);
uint32_t base_format = handle->alloc_format & MALI_GRALLOC_INTFMT_FMT_MASK;
@@ -317,9 +322,9 @@ static android::status_t get_plane_layouts(const private_handle_t *handle, std::
PlaneLayout layout = {.offsetInBytes = offset,
.sampleIncrementInBits = sample_increment_in_bits,
- .strideInBytes = handle->plane_info[plane_index].byte_stride,
- .widthInSamples = handle->plane_info[plane_index].alloc_width,
- .heightInSamples = handle->plane_info[plane_index].alloc_height,
+ .strideInBytes = static_cast<int64_t>(handle->plane_info[plane_index].byte_stride),
+ .widthInSamples = static_cast<int64_t>(handle->plane_info[plane_index].alloc_width),
+ .heightInSamples = static_cast<int64_t>(handle->plane_info[plane_index].alloc_height),
.totalSizeInBytes = plane_size,
.horizontalSubsampling = (plane_index == 0 ? 1 : format_info.hsub),
.verticalSubsampling = (plane_index == 0 ? 1 : format_info.vsub),
@@ -371,9 +376,9 @@ static android::status_t get_plane_layouts(const private_handle_t *handle, std::
PlaneLayout layout = {.offsetInBytes = handle->plane_info[plane_index].offset,
.sampleIncrementInBits = sample_increment_in_bits,
- .strideInBytes = handle->plane_info[plane_index].byte_stride,
- .widthInSamples = handle->plane_info[plane_index].alloc_width,
- .heightInSamples = handle->plane_info[plane_index].alloc_height,
+ .strideInBytes = static_cast<int64_t>(handle->plane_info[plane_index].byte_stride),
+ .widthInSamples = static_cast<int64_t>(handle->plane_info[plane_index].alloc_width),
+ .heightInSamples = static_cast<int64_t>(handle->plane_info[plane_index].alloc_height),
.totalSizeInBytes = plane_size,
.horizontalSubsampling = (plane_index == 0 ? 1 : format_info.hsub),
.verticalSubsampling = (plane_index == 0 ? 1 : format_info.vsub),
@@ -386,23 +391,23 @@ static android::status_t get_plane_layouts(const private_handle_t *handle, std::
return android::OK;
}
-static hidl_vec<uint8_t> encodePointer(void* ptr) {
+static frameworks_vec<uint8_t> encodePointer(void* ptr) {
constexpr uint8_t kPtrSize = sizeof(void*);
- hidl_vec<uint8_t> output(kPtrSize);
+ frameworks_vec<uint8_t> output(kPtrSize);
std::memcpy(output.data(), &ptr, kPtrSize);
return output;
}
-void get_metadata(const private_handle_t *handle, const IMapper::MetadataType &metadataType, IMapper::get_cb hidl_cb)
+Error get_metadata(const private_handle_t *handle, const MetadataType &metadataType, std::vector<uint8_t> &outVec)
{
android::status_t err = android::OK;
- hidl_vec<uint8_t> vec;
+ frameworks_vec<uint8_t> vec;
- if (android::gralloc4::isStandardMetadataType(metadataType))
+ if (isStandardMetadataType(metadataType))
{
- switch (android::gralloc4::getStandardMetadataTypeValue(metadataType))
+ switch (static_cast<StandardMetadataType>(metadataType.value))
{
case StandardMetadataType::BUFFER_ID:
err = android::gralloc4::encodeBufferId(handle->backing_store_id, &vec);
@@ -424,7 +429,7 @@ void get_metadata(const private_handle_t *handle, const IMapper::MetadataType &m
err = android::gralloc4::encodeLayerCount(handle->layer_count, &vec);
break;
case StandardMetadataType::PIXEL_FORMAT_REQUESTED:
- err = android::gralloc4::encodePixelFormatRequested(static_cast<PixelFormat>(handle->req_format), &vec);
+ err = android::gralloc4::encodePixelFormatRequested(static_cast<hidl::PixelFormat>(handle->req_format), &vec);
break;
case StandardMetadataType::PIXEL_FORMAT_FOURCC:
err = android::gralloc4::encodePixelFormatFourCC(drm_fourcc_from_handle(handle), &vec);
@@ -449,7 +454,7 @@ void get_metadata(const private_handle_t *handle, const IMapper::MetadataType &m
{
/* This is set to 1 if the buffer has protected content. */
const int is_protected =
- (((handle->consumer_usage | handle->producer_usage) & BufferUsage::PROTECTED) == 0) ? 0 : 1;
+ (((handle->consumer_usage | handle->producer_usage) & static_cast<uint64_t>(BufferUsage::PROTECTED)) == 0) ? 0 : 1;
err = android::gralloc4::encodeProtectedContent(is_protected, &vec);
break;
}
@@ -572,7 +577,7 @@ void get_metadata(const private_handle_t *handle, const IMapper::MetadataType &m
else if (metadataType.name == ::pixel::graphics::kPixelMetadataTypeName) {
switch (static_cast<::pixel::graphics::MetadataType>(metadataType.value)) {
case ::pixel::graphics::MetadataType::VIDEO_HDR:
- vec = encodePointer(get_video_hdr(handle));
+ vec = ::pixel::graphics::utils::encode(get_video_hdr(handle));
break;
case ::pixel::graphics::MetadataType::VIDEO_ROI:
{
@@ -580,10 +585,19 @@ void get_metadata(const private_handle_t *handle, const IMapper::MetadataType &m
if (roi == nullptr) {
err = android::BAD_VALUE;
} else {
- vec = encodePointer(roi);
+ vec = ::pixel::graphics::utils::encode(roi);
}
break;
}
+ case ::pixel::graphics::MetadataType::PLANE_DMA_BUFS:
+ {
+ std::vector<int> plane_fds(MAX_BUFFER_FDS, -1);
+ for (int i = 0; i < get_num_planes(handle); i++) {
+ plane_fds[i] = handle->fds[handle->plane_info[i].fd_idx];
+ }
+ vec = ::pixel::graphics::utils::encode(plane_fds);
+ break;
+ }
default:
err = android::BAD_VALUE;
}
@@ -593,16 +607,16 @@ void get_metadata(const private_handle_t *handle, const IMapper::MetadataType &m
err = android::BAD_VALUE;
}
- hidl_cb((err) ? Error::UNSUPPORTED : Error::NONE, vec);
+ outVec = std::vector<uint8_t>(vec);
+ return ((err) ? Error::UNSUPPORTED : Error::NONE);
}
-Error set_metadata(const private_handle_t *handle, const IMapper::MetadataType &metadataType,
- const hidl_vec<uint8_t> &metadata)
+Error set_metadata(const private_handle_t *handle, const MetadataType &metadataType, const frameworks_vec<uint8_t> &metadata)
{
- if (android::gralloc4::isStandardMetadataType(metadataType))
+ if (isStandardMetadataType(metadataType))
{
android::status_t err = android::OK;
- switch (android::gralloc4::getStandardMetadataTypeValue(metadataType))
+ switch (static_cast<StandardMetadataType>(metadataType.value))
{
case StandardMetadataType::DATASPACE:
{
@@ -695,12 +709,12 @@ Error set_metadata(const private_handle_t *handle, const IMapper::MetadataType &
}
}
-void getFromBufferDescriptorInfo(IMapper::BufferDescriptorInfo const &description,
- IMapper::MetadataType const &metadataType,
- IMapper::getFromBufferDescriptorInfo_cb hidl_cb)
+#ifdef GRALLOC_MAPPER_4
+Error getFromBufferDescriptorInfo(IMapper::BufferDescriptorInfo const &description,
+ MetadataType const &metadataType, std::vector<uint8_t> &outVec)
{
/* This will hold the metadata that is returned. */
- hidl_vec<uint8_t> vec;
+ frameworks_vec<uint8_t> vec;
buffer_descriptor_t descriptor;
descriptor.width = description.width;
@@ -716,8 +730,8 @@ void getFromBufferDescriptorInfo(IMapper::BufferDescriptorInfo const &descriptio
if (alloc_result != 0)
{
MALI_GRALLOC_LOGV("Allocation for the given description will not succeed. error: %d", alloc_result);
- hidl_cb(Error::BAD_VALUE, vec);
- return;
+ outVec = vec;
+ return Error::BAD_VALUE;
}
/* Create buffer handle from the initialized descriptor without a backing store or shared metadata region.
* Used to share functionality with the normal metadata get function that can only use the allocated buffer handle
@@ -727,11 +741,11 @@ void getFromBufferDescriptorInfo(IMapper::BufferDescriptorInfo const &descriptio
descriptor.hal_format, descriptor.alloc_format,
descriptor.width, descriptor.height, descriptor.pixel_stride,
descriptor.layer_count, descriptor.plane_info);
- if (android::gralloc4::isStandardMetadataType(metadataType))
+ if (isStandardMetadataType(metadataType))
{
android::status_t err = android::OK;
- switch (android::gralloc4::getStandardMetadataTypeValue(metadataType))
+ switch (static_cast<StandardMetadataType>(metadataType.value))
{
case StandardMetadataType::NAME:
err = android::gralloc4::encodeName(description.name, &vec);
@@ -746,7 +760,7 @@ void getFromBufferDescriptorInfo(IMapper::BufferDescriptorInfo const &descriptio
err = android::gralloc4::encodeLayerCount(description.layerCount, &vec);
break;
case StandardMetadataType::PIXEL_FORMAT_REQUESTED:
- err = android::gralloc4::encodePixelFormatRequested(static_cast<PixelFormat>(description.format), &vec);
+ err = android::gralloc4::encodePixelFormatRequested(static_cast<hidl::PixelFormat>(description.format), &vec);
break;
case StandardMetadataType::USAGE:
err = android::gralloc4::encodeUsage(description.usage, &vec);
@@ -774,7 +788,7 @@ void getFromBufferDescriptorInfo(IMapper::BufferDescriptorInfo const &descriptio
{
/* This is set to 1 if the buffer has protected content. */
const int is_protected =
- (((partial_handle.consumer_usage | partial_handle.producer_usage) & BufferUsage::PROTECTED)) ? 1 : 0;
+ (((partial_handle.consumer_usage | partial_handle.producer_usage) & static_cast<uint64_t>(BufferUsage::PROTECTED))) ? 1 : 0;
err = android::gralloc4::encodeProtectedContent(is_protected, &vec);
break;
}
@@ -876,14 +890,17 @@ void getFromBufferDescriptorInfo(IMapper::BufferDescriptorInfo const &descriptio
default:
err = android::BAD_VALUE;
}
- hidl_cb((err) ? Error::UNSUPPORTED : Error::NONE, vec);
+ outVec = vec;
+ return ((err) ? Error::UNSUPPORTED : Error::NONE);
}
else
{
- hidl_cb(Error::UNSUPPORTED, vec);
+ outVec = vec;
+ return Error::UNSUPPORTED;
}
}
+#endif // GRALLOC_MAPPER_4
} // namespace common
} // namespace mapper
} // namespace arm
diff --git a/gralloc4/src/hidl_common/MapperMetadata.h b/gralloc4/src/hidl_common/MapperMetadata.h
index cbf9b47..7027487 100644
--- a/gralloc4/src/hidl_common/MapperMetadata.h
+++ b/gralloc4/src/hidl_common/MapperMetadata.h
@@ -23,13 +23,16 @@
#include "mali_gralloc_log.h"
#include "core/mali_gralloc_bufferdescriptor.h"
#include "mali_gralloc_buffer.h"
+#include "mali_gralloc_error.h"
+#include <cstring>
-#include "4.x/gralloc_mapper_hidl_header.h"
+#include "hidl_common/hidl_common.h"
+#include <algorithm>
+#include <iterator>
#include <aidl/arm/graphics/Compression.h>
#include <aidl/arm/graphics/ArmMetadataType.h>
-
namespace arm
{
namespace mapper
@@ -44,8 +47,116 @@ const static ExtendableType Compression_AFBC{ GRALLOC_ARM_COMPRESSION_TYPE_NAME,
static_cast<int64_t>(aidl::arm::graphics::Compression::AFBC) };
#define GRALLOC_ARM_METADATA_TYPE_NAME "arm.graphics.ArmMetadataType"
-const static IMapper::MetadataType ArmMetadataType_PLANE_FDS{ GRALLOC_ARM_METADATA_TYPE_NAME,
- static_cast<int64_t>(aidl::arm::graphics::ArmMetadataType::PLANE_FDS) };
+
+
+class MetadataType {
+ public:
+ std::string name;
+ uint64_t value;
+#ifdef GRALLOC_MAPPER_4
+ MetadataType(const IMapper::MetadataType &meta) {
+ name = meta.name;
+ value = meta.value;
+ }
+ operator IMapper::MetadataType() const {
+ IMapper::MetadataType meta;
+ meta.name = name;
+ meta.value = value;
+ return meta;
+ }
+#endif
+ MetadataType() {}
+ MetadataType(std::string strname, uint64_t val) {
+ name = strname;
+ value = val;
+ }
+ MetadataType(StandardMetadataType meta) : MetadataType(GRALLOC4_STANDARD_METADATA_TYPE, static_cast<uint64_t>(meta)) {}
+};
+
+const static MetadataType ArmMetadataType_PLANE_FDS = MetadataType(GRALLOC_ARM_METADATA_TYPE_NAME, static_cast<int64_t>(aidl::arm::graphics::ArmMetadataType::PLANE_FDS));
+
+constexpr int RES_SIZE = 32;
+
+struct MetadataTypeDescription {
+ MetadataType metadataType;
+ const char* description;
+ bool isGettable;
+ bool isSettable;
+#ifdef GRALLOC_MAPPER_4
+ MetadataTypeDescription(const IMapper::MetadataTypeDescription &desc) {
+ metadataType = desc.metadataType;
+ description = (desc.description).c_str();
+ isGettable = desc.isGettable;
+ isSettable = desc.isSettable;
+ }
+ operator IMapper::MetadataTypeDescription() const {
+ IMapper::MetadataTypeDescription desc;
+ desc.metadataType = static_cast<IMapper::MetadataType>(metadataType);
+ desc.description = description;
+ desc.isGettable = isGettable;
+ desc.isSettable = isSettable;
+ return desc;
+ }
+#endif
+ MetadataTypeDescription(MetadataType meta, const char* desc, bool gettable, bool settable) {
+ metadataType = meta;
+ description = desc;
+ isGettable = gettable;
+ isSettable = settable;
+ }
+};
+
+struct MetadataDump {
+ MetadataType metadataType;
+ std::vector<uint8_t> metadata;
+#ifdef GRALLOC_MAPPER_4
+ MetadataDump(const IMapper::MetadataDump &meta) {
+ metadataType = MetadataType(meta.metadataType);
+ metadata = static_cast<std::vector<uint8_t> >(metadata);
+ }
+ operator IMapper::MetadataDump() const {
+ IMapper::MetadataDump dump;
+ dump.metadataType = static_cast<IMapper::MetadataType>(metadataType);
+ dump.metadata = hidl_vec(metadata);
+ return dump;
+ }
+#endif
+ MetadataDump() {}
+ MetadataDump(MetadataType metaType, std::vector<uint8_t> &meta) {
+ metadataType = metaType;
+ metadata = meta;
+ }
+};
+
+struct BufferDump {
+ std::vector<MetadataDump> metadataDump;
+#ifdef GRALLOC_MAPPER_4
+ BufferDump(const IMapper::BufferDump &dump) {
+ for (auto meta : dump.metadataDump)
+ metadataDump.push_back(MetadataDump(meta));
+ }
+ operator IMapper::BufferDump() const {
+ IMapper::BufferDump bufferdump;
+ std::vector<IMapper::MetadataDump> metaDump;
+ for (auto meta : metadataDump) {
+ metaDump.push_back(static_cast<IMapper::MetadataDump>(meta));
+ }
+ bufferdump.metadataDump = metaDump;
+ return bufferdump;
+ }
+#endif
+ BufferDump(std::vector<MetadataDump> &meta) { metadataDump = meta; }
+ BufferDump() {}
+};
+
+
+int get_num_planes(const private_handle_t *hnd);
+
+static std::vector<std::vector<PlaneLayoutComponent>> plane_layout_components_from_handle(const private_handle_t *hnd);
+
+android::status_t get_plane_layouts(const private_handle_t *handle, std::vector<PlaneLayout> *layouts);
+
+bool isStandardMetadataType(const MetadataType &metadataType);
/**
* Retrieves a Buffer's metadata value.
@@ -57,7 +168,7 @@ const static IMapper::MetadataType ArmMetadataType_PLANE_FDS{ GRALLOC_ARM_METADA
* UNSUPPORTED on error when reading or unsupported metadata type.
* metadata: Vector of bytes representing the metadata value.
*/
-void get_metadata(const private_handle_t *handle, const IMapper::MetadataType &metadataType, IMapper::get_cb hidl_cb);
+Error get_metadata(const private_handle_t *handle, const MetadataType &metadataType, std::vector<uint8_t> &outVec);
/**
* Sets a Buffer's metadata value.
@@ -69,8 +180,7 @@ void get_metadata(const private_handle_t *handle, const IMapper::MetadataType &m
* @return Error::NONE on success.
* Error::UNSUPPORTED on error when writing or unsupported metadata type.
*/
-Error set_metadata(const private_handle_t *handle, const IMapper::MetadataType &metadataType,
- const hidl_vec<uint8_t> &metadata);
+Error set_metadata(const private_handle_t *handle, const MetadataType &metadataType, const frameworks_vec<uint8_t> &metadata);
/**
* Query basic metadata information about a buffer form its descriptor before allocation.
@@ -82,9 +192,9 @@ Error set_metadata(const private_handle_t *handle, const IMapper::MetadataType &
* UNSUPPORTED on unsupported metadata type.
* metadata: Vector of bytes representing the metadata value.
*/
-void getFromBufferDescriptorInfo(IMapper::BufferDescriptorInfo const &description,
- IMapper::MetadataType const &metadataType,
- IMapper::getFromBufferDescriptorInfo_cb hidl_cb);
+#ifdef GRALLOC_MAPPER_4
+Error getFromBufferDescriptorInfo(IMapper::BufferDescriptorInfo const &description, MetadataType const &metadataType, std::vector<uint8_t> &outVec);
+#endif
} // namespace common
} // namespace mapper
diff --git a/gralloc4/src/hidl_common/RegisteredHandlePool.cpp b/gralloc4/src/hidl_common/RegisteredHandlePool.cpp
index b598d8a..3c99e4f 100644
--- a/gralloc4/src/hidl_common/RegisteredHandlePool.cpp
+++ b/gralloc4/src/hidl_common/RegisteredHandlePool.cpp
@@ -24,9 +24,9 @@ bool RegisteredHandlePool::add(buffer_handle_t bufferHandle)
return bufPool.insert(bufferHandle).second;
}
-native_handle_t* RegisteredHandlePool::remove(void* buffer)
+native_handle_t* RegisteredHandlePool::remove(buffer_handle_t buffer)
{
- auto bufferHandle = static_cast<native_handle_t*>(buffer);
+ auto bufferHandle = const_cast<native_handle_t*>(buffer);
std::lock_guard<std::mutex> lock(mutex);
return bufPool.erase(bufferHandle) == 1 ? bufferHandle : nullptr;
@@ -40,8 +40,13 @@ buffer_handle_t RegisteredHandlePool::get(const void* buffer)
return bufPool.count(bufferHandle) == 1 ? bufferHandle : nullptr;
}
+bool RegisteredHandlePool::isRegistered(buffer_handle_t buffer)
+{
+ return (bufPool.find(buffer) != bufPool.end());
+}
+
void RegisteredHandlePool::for_each(std::function<void(const buffer_handle_t &)> fn)
{
std::lock_guard<std::mutex> lock(mutex);
std::for_each(bufPool.begin(), bufPool.end(), fn);
-} \ No newline at end of file
+}
diff --git a/gralloc4/src/hidl_common/RegisteredHandlePool.h b/gralloc4/src/hidl_common/RegisteredHandlePool.h
index d3fb9b0..b318e54 100644
--- a/gralloc4/src/hidl_common/RegisteredHandlePool.h
+++ b/gralloc4/src/hidl_common/RegisteredHandlePool.h
@@ -33,7 +33,7 @@ public:
bool add(buffer_handle_t bufferHandle);
/* Retrieves and removes the buffer handle from internal list */
- native_handle_t* remove(void* buffer);
+ native_handle_t* remove(buffer_handle_t buffer);
/* Retrieves the buffer handle from internal list */
buffer_handle_t get(const void* buffer);
@@ -41,6 +41,8 @@ public:
/* Applies a function to each buffer handle */
void for_each(std::function<void(const buffer_handle_t &)> fn);
+ bool isRegistered(buffer_handle_t handle);
+
private:
std::mutex mutex;
std::unordered_set<buffer_handle_t> bufPool;
diff --git a/gralloc4/src/hidl_common/SharedMetadata.h b/gralloc4/src/hidl_common/SharedMetadata.h
index f3aad7c..5e72b1c 100644
--- a/gralloc4/src/hidl_common/SharedMetadata.h
+++ b/gralloc4/src/hidl_common/SharedMetadata.h
@@ -26,8 +26,6 @@
#include "core/mali_gralloc_bufferdescriptor.h"
#include "gralloc_helper.h"
-#include "4.x/gralloc_mapper_hidl_header.h"
-
#include "SharedMetadata_struct.h"
namespace arm
diff --git a/gralloc4/src/hidl_common/hidl_common.h b/gralloc4/src/hidl_common/hidl_common.h
new file mode 100644
index 0000000..28850e9
--- /dev/null
+++ b/gralloc4/src/hidl_common/hidl_common.h
@@ -0,0 +1,42 @@
+#ifndef HIDL_COMMON
+#define HIDL_COMMON
+
+#include "mali_fourcc.h"
+#include <gralloctypes/Gralloc4.h>
+#include <aidl/android/hardware/graphics/common/BufferUsage.h>
+#include <aidl/android/hardware/graphics/common/PixelFormat.h>
+#include <aidl/android/hardware/graphics/common/StandardMetadataType.h>
+
+using aidl::android::hardware::graphics::common::BufferUsage;
+using aidl::android::hardware::graphics::common::PixelFormat;
+using aidl::android::hardware::graphics::common::StandardMetadataType;
+using aidl::android::hardware::graphics::common::ExtendableType;
+using aidl::android::hardware::graphics::common::PlaneLayout;
+using aidl::android::hardware::graphics::common::PlaneLayoutComponent;
+using aidl::android::hardware::graphics::common::Rect;
+using aidl::android::hardware::graphics::common::BlendMode;
+using aidl::android::hardware::graphics::common::Dataspace;
+
+namespace hidl {
+using PixelFormat = android::hardware::graphics::common::V1_2::PixelFormat;
+} // namespace hidl
+
+
+template <typename T>
+using frameworks_vec = android::hardware::hidl_vec<T>;
+
+#ifdef GRALLOC_MAPPER_4
+
+#include <android/hardware/graphics/mapper/4.0/IMapper.h>
+
+namespace hidl {
+using android::hardware::graphics::mapper::V4_0::Error;
+} // namespace hidl
+using android::hardware::graphics::mapper::V4_0::BufferDescriptor;
+using android::hardware::graphics::mapper::V4_0::IMapper;
+
+using frameworks_handle = android::hardware::hidl_handle;
+
+#endif // GRALLOC_MAPPER_4
+
+#endif // HIDL_COMMON