dvrapi: Pass layer_count down
* We were missing layer count, which would prevent multiview
from working
Bug: 37245304
Test: MultiLayerBufferQueue
Change-Id: I88b41f1aa7665df01e89a7386cbc23b15c9a79b0
diff --git a/libs/vr/libbufferhub/buffer_hub_client.cpp b/libs/vr/libbufferhub/buffer_hub_client.cpp
index 0326084..a09a7a1 100644
--- a/libs/vr/libbufferhub/buffer_hub_client.cpp
+++ b/libs/vr/libbufferhub/buffer_hub_client.cpp
@@ -59,10 +59,8 @@
ALOGE("BufferHubBuffer::ImportBuffer: Failed to get buffer: %s",
status.GetErrorMessage().c_str());
return -status.error();
- } else if (status.get().id() >= 0) {
- ALOGE(
- "BufferHubBuffer::ImportBuffer: Expected to receive a buffer handle "
- "but got null!");
+ } else if (status.get().id() < 0) {
+ ALOGE("BufferHubBuffer::ImportBuffer: Received an invalid id!");
return -EIO;
}
diff --git a/libs/vr/libbufferhub/include/private/dvr/bufferhub_rpc.h b/libs/vr/libbufferhub/include/private/dvr/bufferhub_rpc.h
index 6fee7a0..ffdc9e2 100644
--- a/libs/vr/libbufferhub/include/private/dvr/bufferhub_rpc.h
+++ b/libs/vr/libbufferhub/include/private/dvr/bufferhub_rpc.h
@@ -23,6 +23,7 @@
stride_(buffer.stride()),
width_(buffer.width()),
height_(buffer.height()),
+ layer_count_(buffer.layer_count()),
format_(buffer.format()),
usage_(buffer.usage()) {
// Populate the fd and int vectors: native_handle->data[] is an array of fds
@@ -47,9 +48,10 @@
for (const auto& fd : fds_)
fd_ints.push_back(fd.Get());
- const int ret = buffer->Import(fd_ints.data(), fd_ints.size(),
- opaque_ints_.data(), opaque_ints_.size(),
- width_, height_, stride_, format_, usage_);
+ const int ret =
+ buffer->Import(fd_ints.data(), fd_ints.size(), opaque_ints_.data(),
+ opaque_ints_.size(), width_, height_, layer_count_,
+ stride_, format_, usage_);
if (ret < 0)
return ret;
@@ -72,6 +74,7 @@
uint32_t stride_;
uint32_t width_;
uint32_t height_;
+ uint32_t layer_count_;
uint32_t format_;
uint64_t usage_;
std::vector<int> opaque_ints_;
@@ -83,8 +86,8 @@
}
PDX_SERIALIZABLE_MEMBERS(NativeBufferHandle<FileHandleType>, id_, stride_,
- width_, height_, format_, usage_, opaque_ints_,
- fds_);
+ width_, height_, layer_count_, format_, usage_,
+ opaque_ints_, fds_);
NativeBufferHandle(const NativeBufferHandle&) = delete;
void operator=(const NativeBufferHandle&) = delete;
@@ -224,8 +227,8 @@
PDX_REMOTE_METHOD(ProducerQueueAllocateBuffers,
kOpProducerQueueAllocateBuffers,
std::vector<std::pair<LocalChannelHandle, size_t>>(
- uint32_t width, uint32_t height, uint32_t format,
- uint64_t usage, size_t buffer_count));
+ uint32_t width, uint32_t height, uint32_t layer_count,
+ uint32_t format, uint64_t usage, size_t buffer_count));
PDX_REMOTE_METHOD(ProducerQueueDetachBuffer, kOpProducerQueueDetachBuffer,
void(size_t slot));
PDX_REMOTE_METHOD(ConsumerQueueImportBuffers, kOpConsumerQueueImportBuffers,
diff --git a/libs/vr/libbufferhub/include/private/dvr/ion_buffer.h b/libs/vr/libbufferhub/include/private/dvr/ion_buffer.h
index 72c8d81..0d337f7 100644
--- a/libs/vr/libbufferhub/include/private/dvr/ion_buffer.h
+++ b/libs/vr/libbufferhub/include/private/dvr/ion_buffer.h
@@ -16,8 +16,8 @@
IonBuffer(buffer_handle_t handle, uint32_t width, uint32_t height,
uint32_t stride, uint32_t format, uint64_t usage);
IonBuffer(buffer_handle_t handle, uint32_t width, uint32_t height,
- uint32_t layer_count, uint32_t stride, uint32_t layer_stride,
- uint32_t format, uint64_t usage);
+ uint32_t layer_count, uint32_t stride, uint32_t format,
+ uint64_t usage);
~IonBuffer();
IonBuffer(IonBuffer&& other);
@@ -31,25 +31,29 @@
// previous native handle if necessary. Returns 0 on success or a negative
// errno code otherwise. If allocation fails the previous native handle is
// left intact.
- int Alloc(uint32_t width, uint32_t height, uint32_t format, uint64_t usage);
+ int Alloc(uint32_t width, uint32_t height, uint32_t layer_count,
+ uint32_t format, uint64_t usage);
// Resets the underlying native handle and parameters, freeing the previous
// native handle if necessary.
void Reset(buffer_handle_t handle, uint32_t width, uint32_t height,
- uint32_t stride, uint32_t format, uint64_t usage);
+ uint32_t layer_count, uint32_t stride, uint32_t format,
+ uint64_t usage);
// Like Reset but also registers the native handle, which is necessary for
// native handles received over IPC. Returns 0 on success or a negative errno
// code otherwise. If import fails the previous native handle is left intact.
int Import(buffer_handle_t handle, uint32_t width, uint32_t height,
- uint32_t stride, uint32_t format, uint64_t usage);
+ uint32_t layer_count, uint32_t stride, uint32_t format,
+ uint64_t usage);
// Like Reset but imports a native handle from raw fd and int arrays. Returns
// 0 on success or a negative errno code otherwise. If import fails the
// previous native handle is left intact.
int Import(const int* fd_array, int fd_count, const int* int_array,
- int int_count, uint32_t width, uint32_t height, uint32_t stride,
- uint32_t format, uint64_t usage);
+ int int_count, uint32_t width, uint32_t height,
+ uint32_t layer_count, uint32_t stride, uint32_t format,
+ uint64_t usage);
// Duplicates the native handle underlying |other| and then imports it. This
// is useful for creating multiple, independent views of the same Ion/Gralloc
@@ -72,7 +76,6 @@
return buffer_.get() ? buffer_->getLayerCount() : 0;
}
uint32_t stride() const { return buffer_.get() ? buffer_->getStride() : 0; }
- uint32_t layer_stride() const { return 0; }
uint32_t format() const {
return buffer_.get() ? buffer_->getPixelFormat() : 0;
}
diff --git a/libs/vr/libbufferhub/ion_buffer.cpp b/libs/vr/libbufferhub/ion_buffer.cpp
index 716ab42..cbaa24a 100644
--- a/libs/vr/libbufferhub/ion_buffer.cpp
+++ b/libs/vr/libbufferhub/ion_buffer.cpp
@@ -15,36 +15,36 @@
namespace android {
namespace dvr {
-IonBuffer::IonBuffer() : IonBuffer(nullptr, 0, 0, 0, 0, 0, 0, 0) {}
+IonBuffer::IonBuffer() : IonBuffer(nullptr, 0, 0, 0, 0, 0, 0) {}
IonBuffer::IonBuffer(uint32_t width, uint32_t height, uint32_t format,
uint64_t usage)
: IonBuffer() {
- Alloc(width, height, format, usage);
+ Alloc(width, height, kDefaultGraphicBufferLayerCount, format, usage);
}
IonBuffer::IonBuffer(buffer_handle_t handle, uint32_t width, uint32_t height,
uint32_t stride, uint32_t format, uint64_t usage)
- : IonBuffer(handle, width, height, 1, stride, 0, format, usage) {}
+ : IonBuffer(handle, width, height, kDefaultGraphicBufferLayerCount, stride,
+ format, usage) {}
IonBuffer::IonBuffer(buffer_handle_t handle, uint32_t width, uint32_t height,
- uint32_t layer_count, uint32_t stride,
- uint32_t layer_stride, uint32_t format, uint64_t usage)
+ uint32_t layer_count, uint32_t stride, uint32_t format,
+ uint64_t usage)
: buffer_(nullptr) {
ALOGD_IF(TRACE,
"IonBuffer::IonBuffer: handle=%p width=%u height=%u layer_count=%u "
- "stride=%u layer stride=%u format=%u usage=%" PRIx64,
- handle, width, height, layer_count, stride, layer_stride, format,
- usage);
+ "stride=%u format=%u usage=%" PRIx64,
+ handle, width, height, layer_count, stride, format, usage);
if (handle != 0) {
- Import(handle, width, height, stride, format, usage);
+ Import(handle, width, height, layer_count, stride, format, usage);
}
}
IonBuffer::~IonBuffer() {
ALOGD_IF(TRACE,
"IonBuffer::~IonBuffer: handle=%p width=%u height=%u stride=%u "
- "format=%u usage=%x",
+ "format=%u usage=%" PRIx64,
handle(), width(), height(), stride(), format(), usage());
FreeHandle();
}
@@ -71,14 +71,14 @@
}
}
-int IonBuffer::Alloc(uint32_t width, uint32_t height, uint32_t format,
- uint64_t usage) {
+int IonBuffer::Alloc(uint32_t width, uint32_t height, uint32_t layer_count,
+ uint32_t format, uint64_t usage) {
ALOGD_IF(TRACE,
- "IonBuffer::Alloc: width=%u height=%u format=%u usage=%" PRIx64,
- width, height, format, usage);
+ "IonBuffer::Alloc: width=%u height=%u layer_count=%u format=%u "
+ "usage=%" PRIx64, width, height, layer_count, format, usage);
- sp<GraphicBuffer> buffer = new GraphicBuffer(
- width, height, format, kDefaultGraphicBufferLayerCount, usage);
+ sp<GraphicBuffer> buffer =
+ new GraphicBuffer(width, height, format, layer_count, usage);
if (buffer->initCheck() != OK) {
ALOGE("IonBuffer::Aloc: Failed to allocate buffer");
return -EINVAL;
@@ -89,26 +89,27 @@
}
void IonBuffer::Reset(buffer_handle_t handle, uint32_t width, uint32_t height,
- uint32_t stride, uint32_t format, uint64_t usage) {
+ uint32_t layer_count, uint32_t stride, uint32_t format,
+ uint64_t usage) {
ALOGD_IF(TRACE,
- "IonBuffer::Reset: handle=%p width=%u height=%u stride=%u format=%u "
- "usage=%" PRIx64,
- handle, width, height, stride, format, usage);
- Import(handle, width, height, stride, format, usage);
+ "IonBuffer::Reset: handle=%p width=%u height=%u layer_count=%u "
+ "stride=%u format=%u usage=%" PRIx64,
+ handle, width, height, layer_count, stride, format, usage);
+ Import(handle, width, height, layer_count, stride, format, usage);
}
int IonBuffer::Import(buffer_handle_t handle, uint32_t width, uint32_t height,
- uint32_t stride, uint32_t format, uint64_t usage) {
+ uint32_t layer_count, uint32_t stride, uint32_t format,
+ uint64_t usage) {
ATRACE_NAME("IonBuffer::Import1");
- ALOGD_IF(
- TRACE,
- "IonBuffer::Import: handle=%p width=%u height=%u stride=%u format=%u "
- "usage=%" PRIx64,
- handle, width, height, stride, format, usage);
+ ALOGD_IF(TRACE,
+ "IonBuffer::Import: handle=%p width=%u height=%u layer_count=%u "
+ "stride=%u format=%u usage=%" PRIx64,
+ handle, width, height, layer_count, stride, format, usage);
FreeHandle();
- sp<GraphicBuffer> buffer = new GraphicBuffer(
- handle, GraphicBuffer::TAKE_UNREGISTERED_HANDLE, width, height, format,
- kDefaultGraphicBufferLayerCount, usage, stride);
+ sp<GraphicBuffer> buffer =
+ new GraphicBuffer(handle, GraphicBuffer::TAKE_UNREGISTERED_HANDLE, width,
+ height, format, layer_count, usage, stride);
if (buffer->initCheck() != OK) {
ALOGE("IonBuffer::Import: Failed to import buffer");
return -EINVAL;
@@ -120,12 +121,14 @@
int IonBuffer::Import(const int* fd_array, int fd_count, const int* int_array,
int int_count, uint32_t width, uint32_t height,
- uint32_t stride, uint32_t format, uint64_t usage) {
+ uint32_t layer_count, uint32_t stride, uint32_t format,
+ uint64_t usage) {
ATRACE_NAME("IonBuffer::Import2");
ALOGD_IF(TRACE,
"IonBuffer::Import: fd_count=%d int_count=%d width=%u height=%u "
- "stride=%u format=%u usage=%" PRIx64,
- fd_count, int_count, width, height, stride, format, usage);
+ "layer_count=%u stride=%u format=%u usage=%" PRIx64,
+ fd_count, int_count, width, height, layer_count, stride, format,
+ usage);
if (fd_count < 0 || int_count < 0) {
ALOGE("IonBuffer::Import: invalid arguments.");
@@ -143,7 +146,8 @@
memcpy(handle->data, fd_array, sizeof(int) * fd_count);
memcpy(handle->data + fd_count, int_array, sizeof(int) * int_count);
- const int ret = Import(handle, width, height, stride, format, usage);
+ const int ret =
+ Import(handle, width, height, layer_count, stride, format, usage);
if (ret < 0) {
ALOGE("IonBuffer::Import: failed to import raw native handle: %s",
strerror(-ret));
@@ -179,8 +183,8 @@
sizeof(int) * int_count);
const int ret =
- Import(handle, other->width(), other->height(), other->stride(),
- other->format(), other->usage());
+ Import(handle, other->width(), other->height(), other->layer_count(),
+ other->stride(), other->format(), other->usage());
if (ret < 0) {
ALOGE("IonBuffer::Duplicate: Failed to import duplicate native handle: %s",
strerror(-ret));
diff --git a/libs/vr/libbufferhub/mocks/ion_buffer/private/dvr/ion_buffer.h b/libs/vr/libbufferhub/mocks/ion_buffer/private/dvr/ion_buffer.h
index fac6db0..8929c95 100644
--- a/libs/vr/libbufferhub/mocks/ion_buffer/private/dvr/ion_buffer.h
+++ b/libs/vr/libbufferhub/mocks/ion_buffer/private/dvr/ion_buffer.h
@@ -17,10 +17,11 @@
IonBufferMock() {}
MOCK_METHOD0(GetGrallocModuleImpl, gralloc_module_t const*());
MOCK_METHOD6(Import, int(buffer_handle_t handle, int width, int height,
- int stride, int format, int usage));
- MOCK_METHOD9(Import, int(const int* fd_array, int fd_count,
- const int* int_array, int int_count, int width,
- int height, int stride, int format, int usage));
+ int layer_count, int stride, int format, int usage));
+ MOCK_METHOD9(Import,
+ int(const int* fd_array, int fd_count, const int* int_array,
+ int int_count, int width, int height, int layer_count,
+ int stride, int format, int usage));
MOCK_METHOD6(Lock, int(int usage, int x, int y, int width, int height,
void** address));
MOCK_METHOD0(Unlock, int());
@@ -29,7 +30,6 @@
MOCK_CONST_METHOD0(height, int());
MOCK_CONST_METHOD0(layer_count, int());
MOCK_CONST_METHOD0(stride, int());
- MOCK_CONST_METHOD0(layer_stride, int());
MOCK_CONST_METHOD0(format, int());
MOCK_CONST_METHOD0(usage, int());
};
@@ -46,15 +46,16 @@
static gralloc_module_t const* GetGrallocModule() {
return staticObject->GetGrallocModuleImpl();
}
- int Import(buffer_handle_t handle, int width, int height, int stride,
- int format, int usage) {
- return mock_->Import(handle, width, height, stride, format, usage);
+ int Import(buffer_handle_t handle, int width, int height, int layer_count,
+ int stride, int format, int usage) {
+ return mock_->Import(handle, width, height, layer_count, stride, format,
+ usage);
}
int Import(const int* fd_array, int fd_count, const int* int_array,
- int int_count, int width, int height, int stride, int format,
- int usage) {
+ int int_count, int width, int height, int layer_count, int stride,
+ int format, int usage) {
return mock_->Import(fd_array, fd_count, int_array, int_count, width,
- height, stride, format, usage);
+ height, layer_count, stride, format, usage);
}
int Lock(int usage, int x, int y, int width, int height, void** address) {
return mock_->Lock(usage, x, y, width, height, address);
@@ -65,7 +66,6 @@
int height() const { return mock_->height(); }
int layer_count() const { return mock_->layer_count(); }
int stride() const { return mock_->stride(); }
- int layer_stride() const { return mock_->layer_stride(); }
int format() const { return mock_->format(); }
int usage() const { return mock_->usage(); }
std::unique_ptr<IonBufferMock> mock_;