Deprecate producer/consumer usage: Step 1
Clean up producer/consumer usage from IonBuffer.
Bug: 37881101
Test: Build, flash, ran particles.apk
Change-Id: I66a8c4db2348b014a7b458b69157ed7c150112e1
diff --git a/libs/vr/libbufferhub/Android.bp b/libs/vr/libbufferhub/Android.bp
index 68b9c81..452bad0 100644
--- a/libs/vr/libbufferhub/Android.bp
+++ b/libs/vr/libbufferhub/Android.bp
@@ -25,7 +25,6 @@
staticLibraries = [
"libdvrcommon",
"libpdx_default_transport",
- "libgrallocusage",
]
sharedLibraries = [
diff --git a/libs/vr/libbufferhub/include/private/dvr/buffer_hub_client.h b/libs/vr/libbufferhub/include/private/dvr/buffer_hub_client.h
index c772ed3..dbd4110 100644
--- a/libs/vr/libbufferhub/include/private/dvr/buffer_hub_client.h
+++ b/libs/vr/libbufferhub/include/private/dvr/buffer_hub_client.h
@@ -113,8 +113,10 @@
uint32_t format() const { return slices_[0].format(); }
uint32_t usage() const { return slices_[0].usage(); }
uint32_t layer_count() const { return slices_[0].layer_count(); }
- uint64_t producer_usage() const { return slices_[0].producer_usage(); }
- uint64_t consumer_usage() const { return slices_[0].consumer_usage(); }
+
+ // TODO(b/37881101) Clean up producer/consumer usage.
+ uint64_t producer_usage() const { return slices_[0].usage(); }
+ uint64_t consumer_usage() const { return slices_[0].usage(); }
protected:
explicit BufferHubBuffer(LocalChannelHandle channel);
diff --git a/libs/vr/libbufferhub/include/private/dvr/bufferhub_rpc.h b/libs/vr/libbufferhub/include/private/dvr/bufferhub_rpc.h
index b6302f1..02e9f27 100644
--- a/libs/vr/libbufferhub/include/private/dvr/bufferhub_rpc.h
+++ b/libs/vr/libbufferhub/include/private/dvr/bufferhub_rpc.h
@@ -24,8 +24,8 @@
width_(buffer.width()),
height_(buffer.height()),
format_(buffer.format()),
- producer_usage_(buffer.producer_usage()),
- consumer_usage_(buffer.consumer_usage()) {
+ producer_usage_(buffer.usage()),
+ consumer_usage_(buffer.usage()) {
// Populate the fd and int vectors: native_handle->data[] is an array of fds
// followed by an array of opaque ints.
const int fd_count = buffer.handle()->numFds;
@@ -48,10 +48,11 @@
for (const auto& fd : fds_)
fd_ints.push_back(fd.Get());
+ // TODO(b/37881101) Get rid of producer/consumer usage.
const int ret =
buffer->Import(fd_ints.data(), fd_ints.size(), opaque_ints_.data(),
opaque_ints_.size(), width_, height_, stride_, format_,
- producer_usage_, consumer_usage_);
+ (producer_usage_ | consumer_usage_));
if (ret < 0)
return ret;
diff --git a/libs/vr/libbufferhub/include/private/dvr/ion_buffer.h b/libs/vr/libbufferhub/include/private/dvr/ion_buffer.h
index e167a17..72c8d81 100644
--- a/libs/vr/libbufferhub/include/private/dvr/ion_buffer.h
+++ b/libs/vr/libbufferhub/include/private/dvr/ion_buffer.h
@@ -12,20 +12,12 @@
class IonBuffer {
public:
IonBuffer();
- IonBuffer(uint32_t width, uint32_t height, uint32_t format, uint32_t usage);
- IonBuffer(uint32_t width, uint32_t height, uint32_t format,
- uint64_t producer_usage, uint64_t consumer_usage);
+ IonBuffer(uint32_t width, uint32_t height, uint32_t format, uint64_t usage);
IonBuffer(buffer_handle_t handle, uint32_t width, uint32_t height,
- uint32_t stride, uint32_t format, uint32_t usage);
- IonBuffer(buffer_handle_t handle, uint32_t width, uint32_t height,
- uint32_t stride, uint32_t format, uint64_t producer_usage,
- uint64_t consumer_usage);
+ 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, uint32_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 producer_usage, uint64_t consumer_usage);
+ uint32_t format, uint64_t usage);
~IonBuffer();
IonBuffer(IonBuffer&& other);
@@ -39,36 +31,25 @@
// 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, uint32_t usage);
- int Alloc(uint32_t width, uint32_t height, uint32_t format,
- uint64_t producer_usage, uint64_t consumer_usage);
+ int Alloc(uint32_t width, uint32_t height, 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, uint32_t usage);
- void Reset(buffer_handle_t handle, uint32_t width, uint32_t height,
- uint32_t stride, uint32_t format, uint64_t producer_usage,
- uint64_t consumer_usage);
+ 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, uint32_t usage);
- int Import(buffer_handle_t handle, uint32_t width, uint32_t height,
- uint32_t stride, uint32_t format, uint64_t producer_usage,
- uint64_t consumer_usage);
+ 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, uint32_t usage);
- 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 producer_usage, uint64_t consumer_usage);
+ 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
@@ -95,19 +76,13 @@
uint32_t format() const {
return buffer_.get() ? buffer_->getPixelFormat() : 0;
}
- uint64_t producer_usage() const { return producer_usage_; }
- uint64_t consumer_usage() const { return consumer_usage_; }
- uint32_t usage() const { return buffer_.get() ? buffer_->getUsage() : 0; }
+ uint64_t usage() const {
+ return buffer_.get() ? static_cast<uint64_t>(buffer_->getUsage()) : 0;
+ }
private:
sp<GraphicBuffer> buffer_;
- // GraphicBuffer doesn't expose these separately. Keep these values cached for
- // BufferHub to check policy against. Clients that import these buffers won't
- // get the full picture, which is okay.
- uint64_t producer_usage_;
- uint64_t consumer_usage_;
-
IonBuffer(const IonBuffer&) = delete;
void operator=(const IonBuffer&) = delete;
};
diff --git a/libs/vr/libbufferhub/ion_buffer.cpp b/libs/vr/libbufferhub/ion_buffer.cpp
index 0a6996e..716ab42 100644
--- a/libs/vr/libbufferhub/ion_buffer.cpp
+++ b/libs/vr/libbufferhub/ion_buffer.cpp
@@ -2,7 +2,6 @@
#include <log/log.h>
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
-#include <grallocusage/GrallocUsageConversion.h>
#include <utils/Trace.h>
#include <mutex>
@@ -19,39 +18,26 @@
IonBuffer::IonBuffer() : IonBuffer(nullptr, 0, 0, 0, 0, 0, 0, 0) {}
IonBuffer::IonBuffer(uint32_t width, uint32_t height, uint32_t format,
- uint32_t usage)
- : IonBuffer(width, height, format, usage, usage) {}
-
-IonBuffer::IonBuffer(uint32_t width, uint32_t height, uint32_t format,
- uint64_t producer_usage, uint64_t consumer_usage)
+ uint64_t usage)
: IonBuffer() {
- Alloc(width, height, format, producer_usage, consumer_usage);
+ Alloc(width, height, format, usage);
}
IonBuffer::IonBuffer(buffer_handle_t handle, uint32_t width, uint32_t height,
- uint32_t stride, uint32_t format, uint32_t usage)
+ uint32_t stride, uint32_t format, uint64_t usage)
: IonBuffer(handle, width, height, 1, stride, 0, 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, uint32_t usage)
- : IonBuffer(handle, width, height, layer_count, stride, layer_stride,
- format, usage, 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 producer_usage, uint64_t consumer_usage)
+ uint32_t layer_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 producer_usage=%" PRIx64
- " consumer_usage=%" PRIx64,
+ "stride=%u layer stride=%u format=%u usage=%" PRIx64,
handle, width, height, layer_count, stride, layer_stride, format,
- producer_usage, consumer_usage);
+ usage);
if (handle != 0) {
- Import(handle, width, height, stride, format, producer_usage,
- consumer_usage);
+ Import(handle, width, height, stride, format, usage);
}
}
@@ -82,105 +68,64 @@
if (buffer_.get()) {
// GraphicBuffer unregisters and cleans up the handle if needed
buffer_ = nullptr;
- producer_usage_ = 0;
- consumer_usage_ = 0;
}
}
int IonBuffer::Alloc(uint32_t width, uint32_t height, uint32_t format,
- uint32_t usage) {
- return Alloc(width, height, format, usage, usage);
-}
+ uint64_t usage) {
+ ALOGD_IF(TRACE,
+ "IonBuffer::Alloc: width=%u height=%u format=%u usage=%" PRIx64,
+ width, height, format, usage);
-int IonBuffer::Alloc(uint32_t width, uint32_t height, uint32_t format,
- uint64_t producer_usage, uint64_t consumer_usage) {
- ALOGD_IF(
- TRACE,
- "IonBuffer::Alloc: width=%u height=%u format=%u producer_usage=%" PRIx64
- " consumer_usage=%" PRIx64,
- width, height, format, producer_usage, consumer_usage);
-
- // TODO: forget about split producer/consumer usage
sp<GraphicBuffer> buffer = new GraphicBuffer(
- width, height, format, kDefaultGraphicBufferLayerCount,
- android_convertGralloc1To0Usage(producer_usage, consumer_usage));
+ width, height, format, kDefaultGraphicBufferLayerCount, usage);
if (buffer->initCheck() != OK) {
ALOGE("IonBuffer::Aloc: Failed to allocate buffer");
return -EINVAL;
} else {
buffer_ = buffer;
- producer_usage_ = producer_usage;
- consumer_usage_ = consumer_usage;
return 0;
}
}
void IonBuffer::Reset(buffer_handle_t handle, uint32_t width, uint32_t height,
- uint32_t stride, uint32_t format, uint32_t usage) {
- Reset(handle, width, height, stride, format, usage, usage);
-}
-
-void IonBuffer::Reset(buffer_handle_t handle, uint32_t width, uint32_t height,
- uint32_t stride, uint32_t format, uint64_t producer_usage,
- uint64_t consumer_usage) {
+ uint32_t stride, uint32_t format, uint64_t usage) {
ALOGD_IF(TRACE,
"IonBuffer::Reset: handle=%p width=%u height=%u stride=%u format=%u "
- "producer_usage=%" PRIx64 " consumer_usage=%" PRIx64,
- handle, width, height, stride, format, producer_usage,
- consumer_usage);
- Import(handle, width, height, stride, format, producer_usage, consumer_usage);
+ "usage=%" PRIx64,
+ handle, width, height, stride, format, usage);
+ Import(handle, width, height, stride, format, usage);
}
int IonBuffer::Import(buffer_handle_t handle, uint32_t width, uint32_t height,
- uint32_t stride, uint32_t format, uint32_t usage) {
- return Import(handle, width, height, stride, format, usage, usage);
-}
-
-int IonBuffer::Import(buffer_handle_t handle, uint32_t width, uint32_t height,
- uint32_t stride, uint32_t format, uint64_t producer_usage,
- uint64_t consumer_usage) {
+ 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 "
- "producer_usage=%" PRIx64 " consumer_usage=%" PRIx64,
- handle, width, height, stride, format, producer_usage, consumer_usage);
+ "usage=%" PRIx64,
+ handle, width, height, stride, format, usage);
FreeHandle();
- sp<GraphicBuffer> buffer =
- new GraphicBuffer(handle, GraphicBuffer::TAKE_UNREGISTERED_HANDLE, width,
- height, format, kDefaultGraphicBufferLayerCount,
- static_cast<uint64_t>(android_convertGralloc1To0Usage(
- producer_usage, consumer_usage)),
- stride);
+ sp<GraphicBuffer> buffer = new GraphicBuffer(
+ handle, GraphicBuffer::TAKE_UNREGISTERED_HANDLE, width, height, format,
+ kDefaultGraphicBufferLayerCount, usage, stride);
if (buffer->initCheck() != OK) {
ALOGE("IonBuffer::Import: Failed to import buffer");
return -EINVAL;
} else {
buffer_ = buffer;
- producer_usage_ = producer_usage;
- consumer_usage_ = consumer_usage;
return 0;
}
}
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, uint32_t usage) {
- return Import(fd_array, fd_count, int_array, int_count, width, height, stride,
- format, usage, usage);
-}
-
-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 producer_usage,
- uint64_t consumer_usage) {
+ 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 producer_usage=%" PRIx64
- " consumer_usage=%" PRIx64,
- fd_count, int_count, width, height, stride, format, producer_usage,
- consumer_usage);
+ "stride=%u format=%u usage=%" PRIx64,
+ fd_count, int_count, width, height, stride, format, usage);
if (fd_count < 0 || int_count < 0) {
ALOGE("IonBuffer::Import: invalid arguments.");
@@ -198,8 +143,7 @@
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, producer_usage,
- consumer_usage);
+ const int ret = Import(handle, width, height, stride, format, usage);
if (ret < 0) {
ALOGE("IonBuffer::Import: failed to import raw native handle: %s",
strerror(-ret));
@@ -236,7 +180,7 @@
const int ret =
Import(handle, other->width(), other->height(), other->stride(),
- other->format(), other->producer_usage(), other->consumer_usage());
+ other->format(), other->usage());
if (ret < 0) {
ALOGE("IonBuffer::Duplicate: Failed to import duplicate native handle: %s",
strerror(-ret));