Skip to content

Commit

Permalink
Merge "dvrapi: Pass layer_count down" into oc-dev am: 9a2b294
Browse files Browse the repository at this point in the history
am: d00f100

Change-Id: I0ba89439d448ef1068a34f44e6a977c55af1d9f1
  • Loading branch information
Hendrik Wagenaar authored and android-build-merger committed May 9, 2017
2 parents b1f28f3 + d00f100 commit 183685e
Show file tree
Hide file tree
Showing 26 changed files with 226 additions and 161 deletions.
6 changes: 2 additions & 4 deletions libs/vr/libbufferhub/buffer_hub_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ int BufferHubBuffer::ImportBuffer() {
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;
}

Expand Down
17 changes: 10 additions & 7 deletions libs/vr/libbufferhub/include/private/dvr/bufferhub_rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class NativeBufferHandle {
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
Expand All @@ -47,9 +48,10 @@ class NativeBufferHandle {
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;

Expand All @@ -72,6 +74,7 @@ class NativeBufferHandle {
uint32_t stride_;
uint32_t width_;
uint32_t height_;
uint32_t layer_count_;
uint32_t format_;
uint64_t usage_;
std::vector<int> opaque_ints_;
Expand All @@ -83,8 +86,8 @@ class NativeBufferHandle {
}

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;
Expand Down Expand Up @@ -224,8 +227,8 @@ struct BufferHubRPC {
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,
Expand Down
19 changes: 11 additions & 8 deletions libs/vr/libbufferhub/include/private/dvr/ion_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class IonBuffer {
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);
Expand All @@ -31,25 +31,29 @@ class IonBuffer {
// 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
Expand All @@ -72,7 +76,6 @@ class IonBuffer {
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;
}
Expand Down
76 changes: 40 additions & 36 deletions libs/vr/libbufferhub/ion_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,36 @@ constexpr uint32_t kDefaultGraphicBufferLayerCount = 1;
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();
}
Expand All @@ -71,14 +71,14 @@ void IonBuffer::FreeHandle() {
}
}

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;
Expand All @@ -89,26 +89,27 @@ int IonBuffer::Alloc(uint32_t width, uint32_t height, uint32_t format,
}

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;
Expand All @@ -120,12 +121,14 @@ int IonBuffer::Import(buffer_handle_t handle, uint32_t width, uint32_t height,

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.");
Expand All @@ -143,7 +146,8 @@ int IonBuffer::Import(const int* fd_array, int fd_count, const int* int_array,
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));
Expand Down Expand Up @@ -179,8 +183,8 @@ int IonBuffer::Duplicate(const IonBuffer* other) {
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));
Expand Down
24 changes: 12 additions & 12 deletions libs/vr/libbufferhub/mocks/ion_buffer/private/dvr/ion_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ class IonBufferMock {
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());
Expand All @@ -29,7 +30,6 @@ class IonBufferMock {
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());
};
Expand All @@ -46,15 +46,16 @@ class IonBuffer {
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);
Expand All @@ -65,7 +66,6 @@ class IonBuffer {
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_;
Expand Down
6 changes: 3 additions & 3 deletions libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ ProducerQueue::ProducerQueue(size_t meta_size, uint64_t usage_set_mask,
}

int ProducerQueue::AllocateBuffer(uint32_t width, uint32_t height,
uint32_t format, uint64_t usage,
size_t* out_slot) {
uint32_t layer_count, uint32_t format,
uint64_t usage, size_t* out_slot) {
if (out_slot == nullptr) {
ALOGE("ProducerQueue::AllocateBuffer: Parameter out_slot cannot be null.");
return -EINVAL;
Expand All @@ -405,7 +405,7 @@ int ProducerQueue::AllocateBuffer(uint32_t width, uint32_t height,
const size_t kBufferCount = 1U;
Status<std::vector<std::pair<LocalChannelHandle, size_t>>> status =
InvokeRemoteMethod<BufferHubRPC::ProducerQueueAllocateBuffers>(
width, height, format, usage, kBufferCount);
width, height, layer_count, format, usage, kBufferCount);
if (!status) {
ALOGE("ProducerQueue::AllocateBuffer failed to create producer buffer: %s",
status.GetErrorMessage().c_str());
Expand Down
6 changes: 4 additions & 2 deletions libs/vr/libbufferhubqueue/buffer_hub_queue_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ BufferHubQueueCore::BufferHubQueueCore()
unique_id_(getUniqueId()) {}

status_t BufferHubQueueCore::AllocateBuffer(uint32_t width, uint32_t height,
uint32_t layer_count,
PixelFormat format,
uint32_t usage) {
uint64_t usage) {
size_t slot;

// Allocate new buffer through BufferHub and add it into |producer_| queue for
// bookkeeping.
if (producer_->AllocateBuffer(width, height, format, usage, &slot) < 0) {
if (producer_->AllocateBuffer(width, height, layer_count, format, usage,
&slot) < 0) {
ALOGE("Failed to allocate new buffer in BufferHub.");
return NO_MEMORY;
}
Expand Down
5 changes: 3 additions & 2 deletions libs/vr/libbufferhubqueue/buffer_hub_queue_producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,15 @@ status_t BufferHubQueueProducer::dequeueBuffer(
return NO_INIT;
}

const uint32_t kLayerCount = 1;
if (static_cast<int32_t>(core_->producer_->capacity()) <
max_dequeued_buffer_count_ +
BufferHubQueueCore::kDefaultUndequeuedBuffers) {
// Lazy allocation. When the capacity of |core_->producer_| has not reach
// |max_dequeued_buffer_count_|, allocate new buffer.
// TODO(jwcai) To save memory, the really reasonable thing to do is to go
// over existing slots and find first existing one to dequeue.
ret = core_->AllocateBuffer(width, height, format, usage);
ret = core_->AllocateBuffer(width, height, kLayerCount, format, usage);
if (ret < 0)
return ret;
}
Expand Down Expand Up @@ -172,7 +173,7 @@ status_t BufferHubQueueProducer::dequeueBuffer(
// there are already multiple buffers in the queue, the next one returned
// from |core_->producer_->Dequeue| may not be the new buffer we just
// reallocated. Retry up to BufferHubQueue::kMaxQueueCapacity times.
ret = core_->AllocateBuffer(width, height, format, usage);
ret = core_->AllocateBuffer(width, height, kLayerCount, format, usage);
if (ret < 0)
return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ class ProducerQueue : public pdx::ClientBase<ProducerQueue, BufferHubQueue> {
// use (i.e. in |Gain|'ed mode).
// Returns Zero on success and negative error code when buffer allocation
// fails.
int AllocateBuffer(uint32_t width, uint32_t height, uint32_t format,
uint64_t usage, size_t* out_slot);
int AllocateBuffer(uint32_t width, uint32_t height, uint32_t layer_count,
uint32_t format, uint64_t usage, size_t* out_slot);

// Add a producer buffer to populate the queue. Once added, a producer buffer
// is available to use (i.e. in |Gain|'ed mode).
Expand Down
Loading

0 comments on commit 183685e

Please sign in to comment.