gralloc: Implement IMapper::2.1
Implements the new IMapper v2.1 APIs
Passes VTS for IMapper v2.1
Change-Id: I9762cd056a296c522ab3446408c3c4c5434b3dc4
diff --git a/gralloc/Android.mk b/gralloc/Android.mk
index 31ff81d..0e648fe 100644
--- a/gralloc/Android.mk
+++ b/gralloc/Android.mk
@@ -12,7 +12,8 @@
LOCAL_HEADER_LIBRARIES := display_headers
LOCAL_SHARED_LIBRARIES := $(common_libs) libqdMetaData libsync libgrallocutils \
libgralloccore \
- android.hardware.graphics.mapper@2.0
+ android.hardware.graphics.mapper@2.0 \
+ android.hardware.graphics.mapper@2.1
LOCAL_CFLAGS := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wall -Werror
LOCAL_CLANG := true
LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps) $(kernel_deps)
@@ -29,7 +30,8 @@
LOCAL_C_INCLUDES := $(common_includes) $(kernel_includes)
LOCAL_HEADER_LIBRARIES := display_headers
LOCAL_SHARED_LIBRARIES := $(common_libs) libqdMetaData libdl \
- android.hardware.graphics.mapper@2.0
+ android.hardware.graphics.mapper@2.0 \
+ android.hardware.graphics.mapper@2.1
LOCAL_CFLAGS := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wno-sign-conversion
LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps)
LOCAL_SRC_FILES := gr_utils.cpp gr_adreno_info.cpp
@@ -47,7 +49,7 @@
LOCAL_HEADER_LIBRARIES := display_headers
LOCAL_SHARED_LIBRARIES := $(common_libs) libqdMetaData libdl libgrallocutils libion \
- android.hardware.graphics.mapper@2.0
+ android.hardware.graphics.mapper@2.1
LOCAL_CFLAGS := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wno-sign-conversion
LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps) $(kernel_deps)
LOCAL_SRC_FILES := gr_allocator.cpp gr_buf_mgr.cpp gr_ion_alloc.cpp
@@ -78,7 +80,8 @@
libgrallocutils \
libgralloccore \
libsync \
- android.hardware.graphics.mapper@2.0
+ android.hardware.graphics.mapper@2.0 \
+ android.hardware.graphics.mapper@2.1
LOCAL_CFLAGS := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wno-sign-conversion
LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps)
LOCAL_SRC_FILES := QtiMapper.cpp
@@ -96,6 +99,7 @@
libqdMetaData \
libgrallocutils \
libgralloccore \
+ android.hardware.graphics.mapper@2.1 \
android.hardware.graphics.allocator@2.0
LOCAL_CFLAGS := -DLOG_TAG=\"qdgralloc\" $(common_flags)
LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps)
diff --git a/gralloc/QtiMapper.cpp b/gralloc/QtiMapper.cpp
index 8de28f5..490cf94 100644
--- a/gralloc/QtiMapper.cpp
+++ b/gralloc/QtiMapper.cpp
@@ -50,7 +50,7 @@
ALOGD_IF(DEBUG, "Created QtiMapper instance");
}
-bool QtiMapper::ValidDescriptor(const IMapper::BufferDescriptorInfo &bd) {
+bool QtiMapper::ValidDescriptor(const BufferDescriptorInfo_2_1 &bd) {
if (bd.width == 0 || bd.height == 0 || (static_cast<int32_t>(bd.format) <= 0) ||
bd.layerCount != 1) {
return false;
@@ -59,9 +59,8 @@
return true;
}
-// Methods from ::android::hardware::graphics::mapper::V2_0::IMapper follow.
-Return<void> QtiMapper::createDescriptor(const IMapper::BufferDescriptorInfo &descriptor_info,
- createDescriptor_cb hidl_cb) {
+Error QtiMapper::CreateDescriptor(const BufferDescriptorInfo_2_1& descriptor_info,
+ IMapperBufferDescriptor *descriptor) {
ALOGD_IF(DEBUG,
"BufferDescriptorInfo: wxh: %dx%d usage: 0x%" PRIu64 " format: %d layer_count: %d",
descriptor_info.width, descriptor_info.height, descriptor_info.usage,
@@ -69,10 +68,26 @@
if (ValidDescriptor(descriptor_info)) {
auto vec = gralloc::BufferDescriptor::Encode(descriptor_info);
- hidl_cb(Error::NONE, vec);
+ *descriptor = vec;
+ return Error::NONE;
} else {
- hidl_cb(Error::BAD_VALUE, hidl_vec<uint32_t>());
+ return Error::BAD_VALUE;
}
+}
+
+// Methods from ::android::hardware::graphics::mapper::V2_0::IMapper follow.
+Return<void> QtiMapper::createDescriptor(const BufferDescriptorInfo_2_0 &descriptor_info,
+ createDescriptor_cb hidl_cb) {
+ IMapperBufferDescriptor descriptor;
+ auto info_2_1 = BufferDescriptorInfo_2_1 {
+ descriptor_info.width,
+ descriptor_info.height,
+ descriptor_info.layerCount,
+ static_cast<PixelFormat>(descriptor_info.format),
+ descriptor_info.usage,
+ };
+ auto err = CreateDescriptor(info_2_1, &descriptor);
+ hidl_cb(err, descriptor);
return Void();
}
@@ -207,12 +222,54 @@
return Void();
}
+Return<Error> QtiMapper::validateBufferSize(void* buffer,
+ const BufferDescriptorInfo_2_1& descriptor_info,
+ uint32_t /*stride*/) {
+ auto err = Error::BAD_BUFFER;
+ auto hnd = static_cast<private_handle_t *>(buffer);
+ if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
+ if (buf_mgr_->IsBufferImported(hnd) != Error::NONE) {
+ return Error::BAD_BUFFER;
+ }
+ auto info = gralloc::BufferInfo(descriptor_info.width, descriptor_info.height,
+ static_cast<uint32_t>(descriptor_info.format),
+ static_cast<uint64_t>(descriptor_info.usage));
+ info.layer_count = descriptor_info.layerCount;
+ err = buf_mgr_->ValidateBufferSize(hnd, info);
+ }
+ return err;
+}
+
+Return<void> QtiMapper::getTransportSize(void *buffer,
+ IMapper_2_1::getTransportSize_cb hidl_cb) {
+ auto err = Error::BAD_BUFFER;
+ auto hnd = static_cast<private_handle_t *>(buffer);
+ uint32_t num_fds = 0, num_ints = 0;
+ if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
+ num_fds = 2;
+ // TODO(user): reduce to transported values;
+ num_ints = static_cast<uint32_t >(hnd->numInts);
+ err = Error::NONE;
+ }
+ ALOGD_IF(DEBUG, "GetTransportSize: num fds: %d num ints: %d err:%d", num_fds, num_ints, err);
+ hidl_cb(err, num_fds, num_ints);
+ return Void();
+}
+
+Return<void> QtiMapper::createDescriptor_2_1(const BufferDescriptorInfo_2_1& descriptor_info,
+ IMapper_2_1::createDescriptor_2_1_cb hidl_cb) {
+ IMapperBufferDescriptor descriptor;
+ auto err = CreateDescriptor(descriptor_info, &descriptor);
+ hidl_cb(err, descriptor);
+ return Void();
+}
+
#ifdef ENABLE_QTI_MAPPER_EXTENSION
Return<void> QtiMapper::getMapSecureBufferFlag(void *buffer, getMapSecureBufferFlag_cb hidl_cb) {
auto err = Error::BAD_BUFFER;
auto hnd = static_cast<private_handle_t *>(buffer);
int *map_secure_buffer = 0;
- if (buffer != nullptr && private_handle_t::validate(hnd) != 0) {
+ if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
if (getMetaData(hnd, GET_MAP_SECURE_BUFFER, map_secure_buffer) != 0) {
*map_secure_buffer = 0;
} else {
@@ -227,7 +284,7 @@
auto err = Error::BAD_BUFFER;
auto hnd = static_cast<private_handle_t *>(buffer);
int *interlaced_flag = nullptr;
- if (buffer != nullptr && private_handle_t::validate(hnd) != 0) {
+ if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
if (getMetaData(hnd, GET_PP_PARAM_INTERLACED, interlaced_flag) != 0) {
*interlaced_flag = 0;
} else {
@@ -243,7 +300,7 @@
auto hnd = static_cast<private_handle_t *>(buffer);
int stride = 0;
int height = 0;
- if (buffer != nullptr && private_handle_t::validate(hnd) != 0) {
+ if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
stride = hnd->width;
height = hnd->height;
gralloc::GetCustomDimensions(hnd, &stride, &height);
@@ -257,7 +314,7 @@
auto err = Error::BAD_BUFFER;
auto hnd = static_cast<private_handle_t *>(buffer);
void *rgb_data = nullptr;
- if (buffer != nullptr && private_handle_t::validate(hnd) != 0) {
+ if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
if (gralloc::GetRgbDataAddress(hnd, &rgb_data) == 0) {
err = Error::NONE;
}
@@ -281,7 +338,7 @@
auto err = Error::BAD_BUFFER;
auto hnd = static_cast<private_handle_t *>(buffer);
int color_space = 0;
- if (buffer != nullptr && private_handle_t::validate(hnd) != 0) {
+ if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
gralloc::GetColorSpaceFromMetadata(hnd, &color_space);
err = Error::NONE;
}
@@ -295,7 +352,7 @@
hidl_vec<YCbCrLayout> layout;
layout.resize(2);
android_ycbcr yuv_plane_info[2];
- if (buffer != nullptr && private_handle_t::validate(hnd) != 0) {
+ if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
if (gralloc::GetYUVPlaneInfo(hnd, yuv_plane_info) == 0) {
err = Error::NONE;
for (int i=0; i < 2; i++) {
@@ -315,7 +372,7 @@
Return<Error> QtiMapper::setSingleBufferMode(void *buffer, bool enable) {
auto err = Error::BAD_BUFFER;
auto hnd = static_cast<private_handle_t *>(buffer);
- if (buffer != nullptr && private_handle_t::validate(hnd) != 0) {
+ if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
if (setMetaData(hnd, SET_SINGLE_BUFFER_MODE, &enable) != 0) {
err = Error::UNSUPPORTED;
} else {
@@ -330,10 +387,10 @@
// When we are in passthrough mode, this method is used
// by hidl to obtain the SP HAL object
-IMapper *HIDL_FETCH_IMapper(const char * /* name */) {
+IMapper_2_1 *HIDL_FETCH_IMapper(const char * /* name */) {
ALOGD_IF(DEBUG, "Fetching IMapper from QtiMapper");
auto mapper = new QtiMapper();
- return static_cast<IMapper *>(mapper);
+ return static_cast<IMapper_2_1 *>(mapper);
}
} // namespace implementation
diff --git a/gralloc/QtiMapper.h b/gralloc/QtiMapper.h
index 218f074..e39ce8b 100644
--- a/gralloc/QtiMapper.h
+++ b/gralloc/QtiMapper.h
@@ -44,9 +44,10 @@
using ::android::hardware::Return;
using ::android::hardware::Void;
-using ::android::hardware::graphics::mapper::V2_0::Error;
using ::android::hardware::graphics::mapper::V2_0::IMapper;
+using ::android::hardware::graphics::mapper::V2_0::Error;
using ::android::hardware::graphics::mapper::V2_0::YCbCrLayout;
+using ::android::hardware::graphics::common::V1_1::PixelFormat;
using ::android::hardware::hidl_array;
using ::android::hardware::hidl_handle;
using ::android::hardware::hidl_memory;
@@ -57,11 +58,18 @@
using ::android::sp;
using gralloc::BufferManager;
-class QtiMapper : public IMapper {
+using IMapper_2_1 = android::hardware::graphics::mapper::V2_1::IMapper;
+using BufferDescriptorInfo_2_0 =
+android::hardware::graphics::mapper::V2_0::IMapper::BufferDescriptorInfo;
+using BufferDescriptorInfo_2_1 =
+android::hardware::graphics::mapper::V2_1::IMapper::BufferDescriptorInfo;
+using IMapperBufferDescriptor = android::hardware::graphics::mapper::V2_0::BufferDescriptor;
+
+class QtiMapper : public IMapper_2_1 {
public:
QtiMapper();
// Methods from ::android::hardware::graphics::mapper::V2_0::IMapper follow.
- Return<void> createDescriptor(const IMapper::BufferDescriptorInfo &descriptor_info,
+ Return<void> createDescriptor(const BufferDescriptorInfo_2_0 &descriptor_info,
createDescriptor_cb hidl_cb) override;
Return<void> importBuffer(const hidl_handle &raw_handle, importBuffer_cb hidl_cb) override;
Return<Error> freeBuffer(void *buffer) override;
@@ -71,6 +79,13 @@
const hidl_handle &acquire_fence, lockYCbCr_cb hidl_cb) override;
Return<void> unlock(void *buffer, unlock_cb hidl_cb) override;
+ // Methods from ::android::hardware::graphics::mapper::V2_1::IMapper follow.
+ Return<Error> validateBufferSize(void* buffer,
+ const BufferDescriptorInfo_2_1& descriptorInfo,
+ uint32_t stride) override;
+ Return<void> getTransportSize(void* buffer, IMapper_2_1::getTransportSize_cb hidl_cb) override;
+ Return<void> createDescriptor_2_1(const BufferDescriptorInfo_2_1& descriptorInfo,
+ createDescriptor_2_1_cb _hidl_cb) override;
#ifdef ENABLE_QTI_MAPPER_EXTENSION
Return<void> getMapSecureBufferFlag(void *buffer, getMapSecureBufferFlag_cb _hidl_cb) override;
Return<void> getInterlacedFlag(void *buffer, getInterlacedFlag_cb _hidl_cb) override;
@@ -86,13 +101,15 @@
private:
BufferManager *buf_mgr_ = nullptr;
+ Error CreateDescriptor(const BufferDescriptorInfo_2_1& descriptor_info,
+ IMapperBufferDescriptor * descriptor);
bool ValidDescriptor(const IMapper::BufferDescriptorInfo &bd);
bool GetFenceFd(const hidl_handle &fence_handle, int *outFenceFd);
void WaitFenceFd(int fence_fd);
Error LockBuffer(void *buffer, uint64_t usage, const hidl_handle &acquire_fence);
};
-extern "C" IMapper *HIDL_FETCH_IMapper(const char *name);
+extern "C" IMapper_2_1 *HIDL_FETCH_IMapper(const char *name);
} // namespace implementation
} // namespace V1_0
} // namespace mapper
diff --git a/gralloc/gr_buf_descriptor.h b/gralloc/gr_buf_descriptor.h
index 932db33..2d426da 100644
--- a/gralloc/gr_buf_descriptor.h
+++ b/gralloc/gr_buf_descriptor.h
@@ -30,12 +30,12 @@
#ifndef __GR_BUF_DESCRIPTOR_H__
#define __GR_BUF_DESCRIPTOR_H__
-#include <android/hardware/graphics/mapper/2.0/IMapper.h>
+#include <android/hardware/graphics/mapper/2.1/IMapper.h>
#include <atomic>
namespace gralloc {
using android::hardware::graphics::mapper::V2_0::Error;
-using android::hardware::graphics::mapper::V2_0::IMapper;
+using android::hardware::graphics::mapper::V2_1::IMapper;
using android::hardware::hidl_vec;
const uint32_t kBufferDescriptorSize = 7;
diff --git a/gralloc/gr_buf_mgr.cpp b/gralloc/gr_buf_mgr.cpp
index 42ac8ed..504e18d 100644
--- a/gralloc/gr_buf_mgr.cpp
+++ b/gralloc/gr_buf_mgr.cpp
@@ -92,6 +92,17 @@
return Error::NONE;
}
+Error BufferManager::ValidateBufferSize(private_handle_t const *hnd, BufferInfo info) {
+ unsigned int size, alignedw, alignedh;
+ info.format = allocator_->GetImplDefinedFormat(info.usage, info.format);
+ GetBufferSizeAndDimensions(info, &size, &alignedw, &alignedh);
+ auto ion_fd_size = static_cast<unsigned int>(lseek(hnd->fd, 0, SEEK_END));
+ if (size != ion_fd_size) {
+ return Error::BAD_VALUE;
+ }
+ return Error::NONE;
+}
+
void BufferManager::RegisterHandleLocked(const private_handle_t *hnd, int ion_handle,
int ion_handle_meta) {
auto buffer = std::make_shared<Buffer>(hnd, ion_handle, ion_handle_meta);
@@ -111,9 +122,13 @@
hnd->id);
return Error::BAD_BUFFER;
}
- // Set base pointers to NULL since the data here was received over binder
+ // Initialize members that aren't transported
+ hnd->size = static_cast<unsigned int>(lseek(hnd->fd, 0, SEEK_END));
+ hnd->offset = 0;
+ hnd->offset_metadata = 0;
hnd->base = 0;
hnd->base_metadata = 0;
+ hnd->gpuaddr = 0;
RegisterHandleLocked(hnd, ion_handle, ion_handle_meta);
return Error::NONE;
}
@@ -140,6 +155,15 @@
return Error::NONE;
}
+Error BufferManager::IsBufferImported(const private_handle_t *hnd) {
+ std::lock_guard<std::mutex> lock(buffer_lock_);
+ auto buf = GetBufferFromHandleLocked(hnd);
+ if (buf != nullptr) {
+ return Error::NONE;
+ }
+ return Error::BAD_BUFFER;
+}
+
Error BufferManager::RetainBuffer(private_handle_t const *hnd) {
ALOGD_IF(DEBUG, "Retain buffer handle:%p id: %" PRIu64, hnd, hnd->id);
auto err = Error::NONE;
diff --git a/gralloc/gr_buf_mgr.h b/gralloc/gr_buf_mgr.h
index 414ec38..b8be047 100644
--- a/gralloc/gr_buf_mgr.h
+++ b/gralloc/gr_buf_mgr.h
@@ -27,6 +27,7 @@
#include <utility>
#include "gr_allocator.h"
+#include "gr_utils.h"
#include "gr_buf_descriptor.h"
#include "gralloc_priv.h"
@@ -45,6 +46,8 @@
Error LockBuffer(const private_handle_t *hnd, uint64_t usage);
Error UnlockBuffer(const private_handle_t *hnd);
Error Dump(std::ostringstream *os);
+ Error ValidateBufferSize(private_handle_t const *hnd, BufferInfo info);
+ Error IsBufferImported(const private_handle_t *hnd);
static BufferManager *GetInstance();
private:
diff --git a/gralloc/gr_utils.h b/gralloc/gr_utils.h
index fe4fcf8..783453f 100644
--- a/gralloc/gr_utils.h
+++ b/gralloc/gr_utils.h
@@ -30,7 +30,7 @@
#ifndef __GR_UTILS_H__
#define __GR_UTILS_H__
-#include <android/hardware/graphics/common/1.0/types.h>
+#include <android/hardware/graphics/common/1.1/types.h>
#include "gralloc_priv.h"
#define SZ_2M 0x200000
@@ -49,7 +49,7 @@
#define INT(exp) static_cast<int>(exp)
#define UINT(exp) static_cast<unsigned int>(exp)
-using android::hardware::graphics::common::V1_0::BufferUsage;
+using android::hardware::graphics::common::V1_1::BufferUsage;
namespace gralloc {
struct BufferInfo {