summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-11-15 00:17:21 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-11-15 00:17:21 +0000
commit0982c095c6749ec685e49ce3e4397854177552d7 (patch)
treef3d79dc16fa707d5069a6f7d5811bbc37956f98a
parent7d24e1b4c387fad74aeb94a63c5935d2f1e05f53 (diff)
parent64b44baa8e9365599ea6669ae5e5a0bc2b9e73c7 (diff)
downloadgchips-0982c095c6749ec685e49ce3e4397854177552d7.tar.gz
Snap for 11097608 from 64b44baa8e9365599ea6669ae5e5a0bc2b9e73c7 to 24Q1-release
Change-Id: Iff0e9ad39129d0d2a08293da4b0d5ced428c4e34
-rw-r--r--gralloc4/TEST_MAPPING7
-rw-r--r--gralloc4/src/4.x/Android.bp3
-rw-r--r--gralloc4/src/4.x/GrallocMapper.cpp154
-rw-r--r--gralloc4/src/4.x/GrallocMapper.h8
-rw-r--r--gralloc4/src/4.x/gralloc_mapper_hidl_header.h32
-rw-r--r--gralloc4/src/gralloc_priv.h5
-rw-r--r--gralloc4/src/hidl_common/BufferDescriptor.h59
-rw-r--r--gralloc4/src/hidl_common/Mapper.cpp407
-rw-r--r--gralloc4/src/hidl_common/Mapper.h79
-rw-r--r--gralloc4/src/hidl_common/MapperMetadata.cpp63
-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
-rw-r--r--gralloc4/src/mali_gralloc_error.h31
-rw-r--r--libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp1
17 files changed, 619 insertions, 419 deletions
diff --git a/gralloc4/TEST_MAPPING b/gralloc4/TEST_MAPPING
deleted file mode 100644
index 5489057..0000000
--- a/gralloc4/TEST_MAPPING
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "postsubmit": [
- {
- "name": "VtsHalGraphicsMapperV4_0TargetTest"
- }
- ]
-} \ No newline at end of file
diff --git a/gralloc4/src/4.x/Android.bp b/gralloc4/src/4.x/Android.bp
index 16eec6a..fb2363b 100644
--- a/gralloc4/src/4.x/Android.bp
+++ b/gralloc4/src/4.x/Android.bp
@@ -92,4 +92,7 @@ cc_library_shared {
include_dirs: [
"hardware/google/gchips/include",
],
+ cflags: [
+ "-DGRALLOC_MAPPER_4=1",
+ ],
}
diff --git a/gralloc4/src/4.x/GrallocMapper.cpp b/gralloc4/src/4.x/GrallocMapper.cpp
index c0b5f5f..11ee90b 100644
--- a/gralloc4/src/4.x/GrallocMapper.cpp
+++ b/gralloc4/src/4.x/GrallocMapper.cpp
@@ -18,6 +18,7 @@
#include "GrallocMapper.h"
#include "hidl_common/BufferDescriptor.h"
#include "hidl_common/MapperMetadata.h"
+#include "hidl_common/Mapper.h"
#include "allocator/mali_gralloc_ion.h"
@@ -26,7 +27,9 @@ namespace arm
namespace mapper
{
+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 android::hardware::Return;
@@ -34,7 +37,6 @@ using android::hardware::hidl_handle;
using android::hardware::hidl_vec;
using android::hardware::Void;
-
GrallocMapper::GrallocMapper() {}
GrallocMapper::~GrallocMapper() {}
@@ -43,12 +45,12 @@ Return<void> GrallocMapper::createDescriptor(const BufferDescriptorInfo &descrip
{
if (common::validateDescriptorInfo(descriptorInfo))
{
- hidl_cb(Error::NONE, common::grallocEncodeBufferDescriptor<uint8_t>(descriptorInfo));
+ hidl_cb(hidl::Error::NONE, common::grallocEncodeBufferDescriptor<uint8_t>(descriptorInfo));
}
else
{
MALI_GRALLOC_LOGE("Invalid attributes to create descriptor for Mapper 3.0");
- hidl_cb(Error::BAD_VALUE, BufferDescriptor());
+ hidl_cb(hidl::Error::BAD_VALUE, BufferDescriptor());
}
return Void();
@@ -56,73 +58,156 @@ Return<void> GrallocMapper::createDescriptor(const BufferDescriptorInfo &descrip
Return<void> GrallocMapper::importBuffer(const hidl_handle &rawHandle, importBuffer_cb hidl_cb)
{
- common::importBuffer(rawHandle, hidl_cb);
+ if (!rawHandle.getNativeHandle()) {
+ hidl_cb(hidl::Error::BAD_BUFFER, nullptr);
+ return Void();
+ }
+
+ auto *inHandle = const_cast<native_handle_t *>(rawHandle.getNativeHandle());
+ buffer_handle_t outHandle = nullptr;
+
+ hidl::Error err = static_cast<hidl::Error>(
+ common::importBuffer(inHandle, &outHandle));
+
+ hidl_cb(err, static_cast<void*>(const_cast<native_handle_t*>(outHandle)));
return Void();
}
-Return<Error> GrallocMapper::freeBuffer(void *buffer)
+Return<hidl::Error> GrallocMapper::freeBuffer(void *buffer)
{
- return common::freeBuffer(buffer);
+ buffer_handle_t handle = common::getBuffer(buffer);
+ if (handle == nullptr) return hidl::Error::BAD_BUFFER;
+ return static_cast<hidl::Error>(common::freeBuffer(handle));
}
-Return<Error> GrallocMapper::validateBufferSize(void *buffer, const BufferDescriptorInfo &descriptorInfo,
+Return<hidl::Error> GrallocMapper::validateBufferSize(void *buffer, const BufferDescriptorInfo &descriptorInfo,
uint32_t in_stride)
{
/* All Gralloc allocated buffers must be conform to local descriptor validation */
if (!common::validateDescriptorInfo<BufferDescriptorInfo>(descriptorInfo))
{
MALI_GRALLOC_LOGE("Invalid descriptor attributes for validating buffer size");
- return Error::BAD_VALUE;
+ return hidl::Error::BAD_VALUE;
}
- return common::validateBufferSize(buffer, descriptorInfo, in_stride);
+ return static_cast<hidl::Error>(common::validateBufferSize(buffer, descriptorInfo, in_stride));
+}
+
+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;
}
Return<void> GrallocMapper::lock(void *buffer, uint64_t cpuUsage, const IMapper::Rect &accessRegion,
const hidl_handle &acquireFence, lock_cb hidl_cb)
{
- common::lock(buffer, cpuUsage, accessRegion, acquireFence, hidl_cb);
+ void *outData = nullptr;
+ int fenceFd;
+ if (!getFenceFd(acquireFence, &fenceFd)) {
+ hidl_cb(hidl::Error::BAD_VALUE, nullptr);
+ return Void();
+ }
+
+ hidl::Error err = static_cast<hidl::Error>(
+ common::lock(static_cast<buffer_handle_t>(buffer), cpuUsage,
+ common::GrallocRect(accessRegion), fenceFd, &outData));
+ if (err != hidl::Error::NONE) outData = nullptr;
+ hidl_cb(err, outData);
return Void();
}
+/*
+ * Populates the HIDL fence handle for the given fence object
+ *
+ * @param fenceFd [in] Fence file descriptor
+ * @param handleStorage [in] HIDL handle storage for fence
+ *
+ * @return HIDL fence handle
+ */
+static hidl_handle buildFenceHandle(int fenceFd, char *handleStorage) {
+ native_handle_t *handle = nullptr;
+ if (fenceFd >= 0) {
+ handle = native_handle_init(handleStorage, 1, 0);
+ handle->data[0] = fenceFd;
+ }
+
+ return hidl_handle(handle);
+}
+
Return<void> GrallocMapper::unlock(void *buffer, unlock_cb hidl_cb)
{
- common::unlock(buffer, hidl_cb);
+ int fenceFd = -1;
+ const native_handle_t *handle = common::getBuffer(buffer);
+
+ if (handle == nullptr) {
+ hidl_cb(hidl::Error::BAD_BUFFER, nullptr);
+ }
+
+ hidl::Error err =
+ static_cast<hidl::Error>(common::unlock(handle, &fenceFd));
+ if (err == hidl::Error::NONE) {
+ NATIVE_HANDLE_DECLARE_STORAGE(fenceStorage, 1, 0);
+ hidl_cb(err, buildFenceHandle(fenceFd, fenceStorage));
+
+ if (fenceFd >= 0) {
+ close(fenceFd);
+ }
+ } else {
+ hidl_cb(err, nullptr);
+ }
return Void();
}
Return<void> GrallocMapper::flushLockedBuffer(void *buffer, flushLockedBuffer_cb hidl_cb)
{
- common::flushLockedBuffer(buffer, hidl_cb);
+ hidl::Error err = static_cast<hidl::Error>(common::flushLockedBuffer(static_cast<buffer_handle_t>(buffer)));
+ hidl_cb(err, hidl_handle{});
return Void();
}
-Return<Error> GrallocMapper::rereadLockedBuffer(void *buffer)
+Return<hidl::Error> GrallocMapper::rereadLockedBuffer(void *buffer)
{
- return common::rereadLockedBuffer(buffer);
+ return static_cast<hidl::Error>(common::rereadLockedBuffer(common::getBuffer(buffer)));
}
Return<void> GrallocMapper::get(void *buffer, const MetadataType &metadataType, IMapper::get_cb hidl_cb)
{
- common::get(buffer, metadataType, hidl_cb);
+ std::vector<uint8_t> vec;
+ hidl::Error err = static_cast<hidl::Error>(
+ common::get(common::getBuffer(buffer), common::MetadataType(metadataType), vec));
+ hidl_cb(err, hidl_vec(vec));
return Void();
}
-Return<Error> GrallocMapper::set(void *buffer, const MetadataType &metadataType, const hidl_vec<uint8_t> &metadata)
+Return<hidl::Error> GrallocMapper::set(void *buffer, const MetadataType &metadataType, const hidl_vec<uint8_t> &metadata)
{
- return common::set(buffer, metadataType, metadata);
+ buffer_handle_t bufferHandle = common::getBuffer(buffer);
+ return static_cast<hidl::Error>(common::set(bufferHandle, common::MetadataType(metadataType), metadata));
}
Return<void> GrallocMapper::getFromBufferDescriptorInfo(const BufferDescriptorInfo &description,
const MetadataType &metadataType,
getFromBufferDescriptorInfo_cb hidl_cb)
{
- common::getFromBufferDescriptorInfo(description, metadataType, hidl_cb);
+ std::vector<uint8_t> vec;
+ hidl::Error err = static_cast<hidl::Error>(common::getFromBufferDescriptorInfo(
+ description, common::MetadataType(metadataType), vec));
+ hidl_cb(err, vec);
return Void();
}
Return<void> GrallocMapper::getTransportSize(void *buffer, getTransportSize_cb hidl_cb)
{
- common::getTransportSize(buffer, hidl_cb);
+ uint32_t outNumFds = 0, outNumInts = 0;
+ buffer_handle_t bufferHandle = common::getBuffer(buffer);
+ hidl::Error err = static_cast<hidl::Error>(common::getTransportSize(bufferHandle, &outNumFds, &outNumInts));
+ hidl_cb(err, outNumFds, outNumInts);
return Void();
}
@@ -131,33 +216,52 @@ Return<void> GrallocMapper::isSupported(const IMapper::BufferDescriptorInfo &des
if (!common::validateDescriptorInfo<BufferDescriptorInfo>(description))
{
MALI_GRALLOC_LOGE("Invalid descriptor attributes for validating buffer size");
- hidl_cb(Error::BAD_VALUE, false);
+ hidl_cb(hidl::Error::BAD_VALUE, false);
}
- common::isSupported(description, hidl_cb);
+ hidl_cb(hidl::Error::NONE, common::isSupported(description));
return Void();
}
Return<void> GrallocMapper::listSupportedMetadataTypes(listSupportedMetadataTypes_cb hidl_cb)
{
- common::listSupportedMetadataTypes(hidl_cb);
+ std::vector<common::MetadataTypeDescription> desc = common::listSupportedMetadataTypes();
+ std::vector<IMapper::MetadataTypeDescription> hidl_description(desc.size());
+ std::copy(desc.begin(), desc.end(), hidl_description.begin());
+ hidl_cb(hidl::Error::NONE, hidl_vec(hidl_description));
return Void();
}
Return<void> GrallocMapper::dumpBuffer(void *buffer, dumpBuffer_cb hidl_cb)
{
- common::dumpBuffer(buffer, hidl_cb);
+ common::BufferDump out;
+ hidl::Error err = static_cast<hidl::Error>(common::dumpBuffer(common::getBuffer(buffer), out));
+ hidl_cb(err, static_cast<IMapper::BufferDump>(out));
return Void();
}
Return<void> GrallocMapper::dumpBuffers(dumpBuffers_cb hidl_cb)
{
- common::dumpBuffers(hidl_cb);
+ auto bufferDump = common::dumpBuffers();
+ std::vector<IMapper::BufferDump> outBufDump;
+ for (auto dump : bufferDump) {
+ outBufDump.push_back(static_cast<IMapper::BufferDump>(dump));
+ }
+ hidl_cb(hidl::Error::NONE, hidl_vec(outBufDump));
return Void();
}
Return<void> GrallocMapper::getReservedRegion(void *buffer, getReservedRegion_cb hidl_cb)
{
- common::getReservedRegion(buffer, hidl_cb);
+ void *reservedRegion = nullptr;
+ uint64_t reservedSize = 0;
+ hidl::Error err = static_cast<hidl::Error>(
+ common::getReservedRegion(static_cast<buffer_handle_t>(buffer),
+ &reservedRegion, reservedSize));
+ if (err != hidl::Error::NONE) {
+ reservedRegion = nullptr;
+ reservedSize = 0;
+ }
+ hidl_cb(err, reservedRegion, reservedSize);
return Void();
}
diff --git a/gralloc4/src/4.x/GrallocMapper.h b/gralloc4/src/4.x/GrallocMapper.h
index 959efa5..7c45199 100644
--- a/gralloc4/src/4.x/GrallocMapper.h
+++ b/gralloc4/src/4.x/GrallocMapper.h
@@ -50,9 +50,9 @@ public:
Return<void> importBuffer(const hidl_handle &rawHandle, importBuffer_cb hidl_cb) override;
- Return<Error> freeBuffer(void *buffer) override;
+ Return<hidl::Error> freeBuffer(void *buffer) override;
- Return<Error> validateBufferSize(void *buffer, const IMapper::BufferDescriptorInfo &descriptorInfo,
+ Return<hidl::Error> validateBufferSize(void *buffer, const IMapper::BufferDescriptorInfo &descriptorInfo,
uint32_t stride) override;
Return<void> getTransportSize(void *buffer, getTransportSize_cb _hidl_cb) override;
@@ -64,13 +64,13 @@ public:
Return<void> flushLockedBuffer(void *buffer, flushLockedBuffer_cb hidl_cb) override;
- Return<Error> rereadLockedBuffer(void *buffer) override;
+ Return<hidl::Error> rereadLockedBuffer(void *buffer) override;
Return<void> isSupported(const IMapper::BufferDescriptorInfo &description, isSupported_cb hidl_cb) override;
Return<void> get(void *buffer, const MetadataType &metadataType, IMapper::get_cb hidl_cb) override;
- Return<Error> set(void *buffer, const MetadataType &metadataType, const hidl_vec<uint8_t> &metadata) override;
+ Return<hidl::Error> set(void *buffer, const MetadataType &metadataType, const hidl_vec<uint8_t> &metadata) override;
Return<void> getFromBufferDescriptorInfo(BufferDescriptorInfo const &description, MetadataType const &metadataType,
getFromBufferDescriptorInfo_cb hidl_cb) override;
diff --git a/gralloc4/src/4.x/gralloc_mapper_hidl_header.h b/gralloc4/src/4.x/gralloc_mapper_hidl_header.h
deleted file mode 100644
index 6d3d549..0000000
--- a/gralloc4/src/4.x/gralloc_mapper_hidl_header.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2020 Arm Limited. All rights reserved.
- *
- * Copyright 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef GRALLOC_MAPPER_HIDL_HEADER_H
-#define GRALLOC_MAPPER_HIDL_HEADER_H
-
-#include <android/hardware/graphics/mapper/4.0/IMapper.h>
-#include "mali_fourcc.h"
-#include <gralloctypes/Gralloc4.h>
-
-using android::hardware::graphics::mapper::V4_0::Error;
-using android::hardware::graphics::mapper::V4_0::BufferDescriptor;
-using android::hardware::graphics::common::V1_2::PixelFormat;
-using android::hardware::graphics::common::V1_2::BufferUsage;
-using android::hardware::graphics::mapper::V4_0::IMapper;
-
-#endif
diff --git a/gralloc4/src/gralloc_priv.h b/gralloc4/src/gralloc_priv.h
index bbef1b6..1074e42 100644
--- a/gralloc4/src/gralloc_priv.h
+++ b/gralloc4/src/gralloc_priv.h
@@ -28,11 +28,6 @@
#include <sys/mman.h>
#include <cutils/native_handle.h>
-/* Allocator = 4.0, Mapper = 4.0 and Common = 1.2 */
-#define HIDL_ALLOCATOR_VERSION_SCALED 400
-#define HIDL_MAPPER_VERSION_SCALED 400
-#define HIDL_COMMON_VERSION_SCALED 120
-
#include "mali_gralloc_formats.h"
#include "mali_gralloc_usages.h"
#include "gralloc_helper.h"
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 874f4db..288b5a3 100644
--- a/gralloc4/src/hidl_common/Mapper.cpp
+++ b/gralloc4/src/hidl_common/Mapper.cpp
@@ -35,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
@@ -50,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
*
@@ -102,48 +108,6 @@ 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
- *
- * @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 fenceFd [in] Fence file descriptor
- * @param handleStorage [in] HIDL handle storage for fence
- *
- * @return HIDL fence handle
- */
-static hidl_handle getFenceHandle(int fenceFd, char* handleStorage)
-{
- native_handle_t* handle = nullptr;
- if (fenceFd >= 0)
- {
- handle = native_handle_init(handleStorage, 1, 0);
- handle->data[0] = fenceFd;
- }
-
- return hidl_handle(handle);
-}
-
-/*
* Converts a gralloc error code to a mapper error code
*
* @param grallocError [in] Gralloc error as integer.
@@ -179,7 +143,8 @@ static Error grallocErrorToMapperError(int grallocError)
*
* @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
*
@@ -191,7 +156,7 @@ static Error grallocErrorToMapperError(int grallocError)
*/
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
@@ -228,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)
{
@@ -248,7 +213,7 @@ static Error lockBuffer(buffer_handle_t bufferHandle,
void* data = nullptr;
const int gralloc_err = mali_gralloc_lock(bufferHandle, cpuUsage, accessRegion.left, accessRegion.top,
- accessRegion.width, accessRegion.height, &data);
+ accessRegion.right, accessRegion.bottom, &data);
const Error lock_err = grallocErrorToMapperError(gralloc_err);
if(Error::NONE == lock_err)
@@ -282,8 +247,6 @@ 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);
@@ -293,133 +256,86 @@ static Error unlockBuffer(buffer_handle_t bufferHandle,
}
else
{
- MALI_GRALLOC_LOGE("Unlocking failed with error: %d", gralloc_err);
+ MALI_GRALLOC_LOGE("Unlocking failed with error: %d",
+ gralloc_err);
+ return Error::BAD_BUFFER;
}
return unlock_err;
}
-void importBuffer(const hidl_handle& rawHandle, IMapper::importBuffer_cb hidl_cb)
+Error importBuffer(const native_handle_t *inBuffer, buffer_handle_t *outBuffer)
{
- if (!rawHandle.getNativeHandle())
- {
- MALI_GRALLOC_LOGE("Invalid buffer handle to import");
- hidl_cb(Error::BAD_BUFFER, nullptr);
- return;
- }
-
- 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;
- }
-
- const Error error = registerBuffer(bufferHandle);
+ *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)
@@ -540,28 +456,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;
@@ -577,39 +497,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);
@@ -627,31 +544,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);
@@ -667,135 +582,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 fdff90a..76a9865 100644
--- a/gralloc4/src/hidl_common/MapperMetadata.cpp
+++ b/gralloc4/src/hidl_common/MapperMetadata.cpp
@@ -53,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()))
{
@@ -283,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;
@@ -387,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);
@@ -425,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);
@@ -450,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;
}
@@ -603,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:
{
@@ -705,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;
@@ -726,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
@@ -737,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);
@@ -756,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);
@@ -784,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;
}
@@ -886,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
diff --git a/gralloc4/src/mali_gralloc_error.h b/gralloc4/src/mali_gralloc_error.h
new file mode 100644
index 0000000..6045b65
--- /dev/null
+++ b/gralloc4/src/mali_gralloc_error.h
@@ -0,0 +1,31 @@
+#ifndef MALI_GRALLOC_ERROR
+#define MALI_GRALLOC_ERROR
+
+enum class Error : int32_t {
+ /**
+ * No error.
+ */
+ NONE = 0,
+ /**
+ * Invalid BufferDescriptor.
+ */
+ BAD_DESCRIPTOR = 1,
+ /**
+ * Invalid buffer handle.
+ */
+ BAD_BUFFER = 2,
+ /**
+ * Invalid HardwareBufferDescription.
+ */
+ BAD_VALUE = 3,
+ /**
+ * Resource unavailable.
+ */
+ NO_RESOURCES = 5,
+ /**
+ * Permanent failure.
+ */
+ UNSUPPORTED = 7,
+};
+
+#endif
diff --git a/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp b/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp
index a39b4db..a2bf1c4 100644
--- a/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp
+++ b/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp
@@ -25,6 +25,7 @@
#include "mali_gralloc_formats.h"
#include "hidl_common/SharedMetadata.h"
#include "hidl_common/SharedMetadata_struct.h"
+#include "hidl_common/hidl_common.h"
#include "exynos_format.h"
#include <pixel-gralloc/metadata.h>