Merge "Deprecate producer/consumer usage: Step 3" into oc-dev
diff --git a/libs/vr/libbufferhub/buffer_hub_client.cpp b/libs/vr/libbufferhub/buffer_hub_client.cpp
index 07c921f..60dbe92 100644
--- a/libs/vr/libbufferhub/buffer_hub_client.cpp
+++ b/libs/vr/libbufferhub/buffer_hub_client.cpp
@@ -199,27 +199,18 @@
 }
 
 BufferProducer::BufferProducer(uint32_t width, uint32_t height, uint32_t format,
-                               uint32_t usage, size_t metadata_size,
+                               uint64_t usage, size_t metadata_size,
                                size_t slice_count)
-    : BufferProducer(width, height, format, usage, usage, metadata_size,
-                     slice_count) {}
-
-BufferProducer::BufferProducer(uint32_t width, uint32_t height, uint32_t format,
-                               uint64_t producer_usage, uint64_t consumer_usage,
-                               size_t metadata_size, size_t slice_count)
     : BASE(BufferHubRPC::kClientPath) {
   ATRACE_NAME("BufferProducer::BufferProducer");
   ALOGD_IF(TRACE,
            "BufferProducer::BufferProducer: fd=%d width=%u height=%u format=%u "
-           "producer_usage=%" PRIx64 " consumer_usage=%" PRIx64
-           " metadata_size=%zu slice_count=%zu",
-           event_fd(), width, height, format, producer_usage, consumer_usage,
-           metadata_size, slice_count);
+           "usage=%" PRIx64 " metadata_size=%zu slice_count=%zu",
+           event_fd(), width, height, format, usage, metadata_size,
+           slice_count);
 
-  // (b/37881101) Deprecate producer/consumer usage
   auto status = InvokeRemoteMethod<BufferHubRPC::CreateBuffer>(
-      width, height, format, (producer_usage | consumer_usage), metadata_size,
-      slice_count);
+      width, height, format, usage, metadata_size, slice_count);
   if (!status) {
     ALOGE(
         "BufferProducer::BufferProducer: Failed to create producer buffer: %s",
@@ -239,29 +230,20 @@
 
 BufferProducer::BufferProducer(const std::string& name, int user_id,
                                int group_id, uint32_t width, uint32_t height,
-                               uint32_t format, uint32_t usage,
+                               uint32_t format, uint64_t usage,
                                size_t meta_size_bytes, size_t slice_count)
-    : BufferProducer(name, user_id, group_id, width, height, format, usage,
-                     usage, meta_size_bytes, slice_count) {}
-
-BufferProducer::BufferProducer(const std::string& name, int user_id,
-                               int group_id, uint32_t width, uint32_t height,
-                               uint32_t format, uint64_t producer_usage,
-                               uint64_t consumer_usage, size_t meta_size_bytes,
-                               size_t slice_count)
     : BASE(BufferHubRPC::kClientPath) {
   ATRACE_NAME("BufferProducer::BufferProducer");
   ALOGD_IF(TRACE,
            "BufferProducer::BufferProducer: fd=%d name=%s user_id=%d "
-           "group_id=%d width=%u height=%u format=%u producer_usage=%" PRIx64
-           " consumer_usage=%" PRIx64 " meta_size_bytes=%zu slice_count=%zu",
+           "group_id=%d width=%u height=%u format=%u usage=%" PRIx64
+           " meta_size_bytes=%zu slice_count=%zu",
            event_fd(), name.c_str(), user_id, group_id, width, height, format,
-           producer_usage, consumer_usage, meta_size_bytes, slice_count);
+           usage, meta_size_bytes, slice_count);
 
-  // (b/37881101) Deprecate producer/consumer usage
   auto status = InvokeRemoteMethod<BufferHubRPC::CreatePersistentBuffer>(
-      name, user_id, group_id, width, height, format,
-      (producer_usage | consumer_usage), meta_size_bytes, slice_count);
+      name, user_id, group_id, width, height, format, usage, meta_size_bytes,
+      slice_count);
   if (!status) {
     ALOGE(
         "BufferProducer::BufferProducer: Failed to create/get persistent "
@@ -281,26 +263,19 @@
   }
 }
 
-BufferProducer::BufferProducer(uint32_t usage, size_t size)
-    : BufferProducer(usage, usage, size) {}
-
-BufferProducer::BufferProducer(uint64_t producer_usage, uint64_t consumer_usage,
-                               size_t size)
+BufferProducer::BufferProducer(uint64_t usage, size_t size)
     : BASE(BufferHubRPC::kClientPath) {
   ATRACE_NAME("BufferProducer::BufferProducer");
-  ALOGD_IF(TRACE,
-           "BufferProducer::BufferProducer: producer_usage=%" PRIx64
-           " consumer_usage=%" PRIx64 " size=%zu",
-           producer_usage, consumer_usage, size);
+  ALOGD_IF(TRACE, "BufferProducer::BufferProducer: usage=%" PRIx64 " size=%zu",
+           usage, size);
   const int width = static_cast<int>(size);
   const int height = 1;
   const int format = HAL_PIXEL_FORMAT_BLOB;
   const size_t meta_size_bytes = 0;
   const size_t slice_count = 1;
 
-  // (b/37881101) Deprecate producer/consumer usage
   auto status = InvokeRemoteMethod<BufferHubRPC::CreateBuffer>(
-      width, height, format, (producer_usage | consumer_usage), meta_size_bytes,
+      width, height, format, usage, meta_size_bytes,
       slice_count);
   if (!status) {
     ALOGE("BufferProducer::BufferProducer: Failed to create blob: %s",
@@ -319,29 +294,22 @@
 }
 
 BufferProducer::BufferProducer(const std::string& name, int user_id,
-                               int group_id, uint32_t usage, size_t size)
-    : BufferProducer(name, user_id, group_id, usage, usage, size) {}
-
-BufferProducer::BufferProducer(const std::string& name, int user_id,
-                               int group_id, uint64_t producer_usage,
-                               uint64_t consumer_usage, size_t size)
+                               int group_id, uint64_t usage, size_t size)
     : BASE(BufferHubRPC::kClientPath) {
   ATRACE_NAME("BufferProducer::BufferProducer");
   ALOGD_IF(TRACE,
            "BufferProducer::BufferProducer: name=%s user_id=%d group=%d "
-           "producer_usage=%" PRIx64 " consumer_usage=%" PRIx64 " size=%zu",
-           name.c_str(), user_id, group_id, producer_usage, consumer_usage,
-           size);
+           "usage=%" PRIx64 " size=%zu",
+           name.c_str(), user_id, group_id, usage, size);
   const int width = static_cast<int>(size);
   const int height = 1;
   const int format = HAL_PIXEL_FORMAT_BLOB;
   const size_t meta_size_bytes = 0;
   const size_t slice_count = 1;
 
-  // (b/37881101) Deprecate producer/consumer usage
   auto status = InvokeRemoteMethod<BufferHubRPC::CreatePersistentBuffer>(
-      name, user_id, group_id, width, height, format,
-      (producer_usage | consumer_usage), meta_size_bytes, slice_count);
+      name, user_id, group_id, width, height, format, usage, meta_size_bytes,
+      slice_count);
   if (!status) {
     ALOGE(
         "BufferProducer::BufferProducer: Failed to create persistent "
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 dbd4110..16ddad7 100644
--- a/libs/vr/libbufferhub/include/private/dvr/buffer_hub_client.h
+++ b/libs/vr/libbufferhub/include/private/dvr/buffer_hub_client.h
@@ -111,13 +111,9 @@
   uint32_t height() const { return slices_[0].height(); }
   uint32_t stride() const { return slices_[0].stride(); }
   uint32_t format() const { return slices_[0].format(); }
-  uint32_t usage() const { return slices_[0].usage(); }
+  uint64_t usage() const { return slices_[0].usage(); }
   uint32_t layer_count() const { return slices_[0].layer_count(); }
 
-  // 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);
   explicit BufferHubBuffer(const std::string& endpoint_path);
@@ -224,11 +220,8 @@
 
   // Constructs a buffer with the given geometry and parameters.
   BufferProducer(uint32_t width, uint32_t height, uint32_t format,
-                 uint32_t usage, size_t metadata_size = 0,
+                 uint64_t usage, size_t metadata_size = 0,
                  size_t slice_count = 1);
-  BufferProducer(uint32_t width, uint32_t height, uint32_t format,
-                 uint64_t producer_usage, uint64_t consumer_usage,
-                 size_t metadata_size, size_t slice_count);
 
   // Constructs a persistent buffer with the given geometry and parameters and
   // binds it to |name| in one shot. If a persistent buffer with the same name
@@ -244,22 +237,15 @@
   // effective user or group id of the calling process.
   BufferProducer(const std::string& name, int user_id, int group_id,
                  uint32_t width, uint32_t height, uint32_t format,
-                 uint32_t usage, size_t metadata_size = 0,
+                 uint64_t usage, size_t metadata_size = 0,
                  size_t slice_count = 1);
-  BufferProducer(const std::string& name, int user_id, int group_id,
-                 uint32_t width, uint32_t height, uint32_t format,
-                 uint64_t producer_usage, uint64_t consumer_usage,
-                 size_t metadata_size, size_t slice_count);
 
   // Constructs a blob (flat) buffer with the given usage flags.
-  BufferProducer(uint32_t usage, size_t size);
-  BufferProducer(uint64_t producer_usage, uint64_t consumer_usage, size_t size);
+  BufferProducer(uint64_t usage, size_t size);
 
   // Constructs a persistent blob (flat) buffer and binds it to |name|.
   BufferProducer(const std::string& name, int user_id, int group_id,
-                 uint32_t usage, size_t size);
-  BufferProducer(const std::string& name, int user_id, int group_id,
-                 uint64_t producer_usage, uint64_t consumer_usage, size_t size);
+                 uint64_t usage, size_t size);
 
   // Constructs a channel to persistent buffer by name only. The buffer must
   // have been previously created or made persistent.
diff --git a/libs/vr/libdvr/display_manager_client.cpp b/libs/vr/libdvr/display_manager_client.cpp
index 6830085..8c010fc 100644
--- a/libs/vr/libdvr/display_manager_client.cpp
+++ b/libs/vr/libdvr/display_manager_client.cpp
@@ -1,7 +1,6 @@
 #include "include/dvr/display_manager_client.h"
 
 #include <dvr/dvr_buffer.h>
-#include <grallocusage/GrallocUsageConversion.h>
 #include <private/android/AHardwareBufferHelpers.h>
 #include <private/dvr/buffer_hub_client.h>
 #include <private/dvr/display_manager_client_impl.h>
@@ -46,24 +45,11 @@
 
 DvrBuffer* dvrDisplayManagerSetupNamedBuffer(DvrDisplayManagerClient* client,
                                              const char* name, size_t size,
-                                             uint64_t hardware_buffer_usage,
-                                             uint64_t unused) {
-  uint64_t producer_usage = 0;
-  uint64_t consumer_usage = 0;
-
-  // Note: AHardwareBuffer no longer uses usage0/usage1
+                                             uint64_t usage) {
   uint64_t gralloc_usage =
-      android::AHardwareBuffer_convertToGrallocUsageBits(hardware_buffer_usage);
+      android::AHardwareBuffer_convertToGrallocUsageBits(usage);
 
-  // Note: split producer/consumer usage is deprecated, grallocV2 uses single
-  // 64-bits usage
-  // And, currently, 64-bits gralloc usage flags can safely be truncated to
-  // 32-bits
-  android_convertGralloc0To1Usage((uint32_t)gralloc_usage, &producer_usage,
-                                  &consumer_usage);
-
-  auto ion_buffer = client->client->SetupNamedBuffer(
-      name, size, (producer_usage | consumer_usage));
+  auto ion_buffer = client->client->SetupNamedBuffer(name, size, gralloc_usage);
   if (ion_buffer) {
     return CreateDvrBufferFromIonBuffer(std::move(ion_buffer));
   }
diff --git a/libs/vr/libdvr/dvr_surface.cpp b/libs/vr/libdvr/dvr_surface.cpp
index a04ed50..6daabca 100644
--- a/libs/vr/libdvr/dvr_surface.cpp
+++ b/libs/vr/libdvr/dvr_surface.cpp
@@ -1,5 +1,6 @@
 #include "include/dvr/dvr_surface.h"
 
+#include <private/android/AHardwareBufferHelpers.h>
 #include <private/dvr/display_client.h>
 
 using namespace android;
@@ -10,8 +11,8 @@
 
 extern "C" {
 
-int dvrSurfaceCreate(int width, int height, int format, uint64_t usage0,
-                     uint64_t usage1, int flags, DvrSurface** out_surface) {
+int dvrSurfaceCreate(int width, int height, int format, uint64_t usage,
+                     int flags, DvrSurface** out_surface) {
   if (out_surface == nullptr) {
     ALOGE("dvrSurfaceCreate: invalid inputs: out_surface=%p.", out_surface);
     return -EINVAL;
@@ -24,10 +25,12 @@
     return error;
   }
 
-  // TODO(hendrikw): When we move to gralloc1, pass both usage0 and usage1 down.
+  // The following convertion is sort of unnecessary as AHARDWAREBUFFER_USAGE
+  // and BufferUsage should be synced up now.
+  uint64_t gralloc_usage = AHardwareBuffer_convertToGrallocUsageBits(usage);
   std::unique_ptr<dvr::DisplaySurfaceClient> surface =
       client->CreateDisplaySurface(
-          width, height, static_cast<int>(usage0 | usage1), format, flags);
+          width, height, static_cast<int>(gralloc_usage), format, flags);
 
   DvrSurface* dvr_surface = new DvrSurface;
   dvr_surface->display_surface_ = std::move(surface);
diff --git a/libs/vr/libdvr/include/dvr/display_manager_client.h b/libs/vr/libdvr/include/dvr/display_manager_client.h
index 8cd948c..a2c69b2 100644
--- a/libs/vr/libdvr/include/dvr/display_manager_client.h
+++ b/libs/vr/libdvr/include/dvr/display_manager_client.h
@@ -22,7 +22,7 @@
 
 DvrBuffer* dvrDisplayManagerSetupNamedBuffer(DvrDisplayManagerClient* client,
                                              const char* name, size_t size,
-                                             uint64_t usage0, uint64_t usage1);
+                                             uint64_t usage);
 
 // Return an event fd for checking if there was an event on the server
 // Note that the only event which will be flagged is POLLIN. You must use
diff --git a/libs/vr/libdvr/include/dvr/dvr_api.h b/libs/vr/libdvr/include/dvr/dvr_api.h
index 3cd401d..8849942 100644
--- a/libs/vr/libdvr/include/dvr/dvr_api.h
+++ b/libs/vr/libdvr/include/dvr/dvr_api.h
@@ -48,7 +48,7 @@
     DvrDisplayManagerClientSurfaceList* surface_list);
 typedef DvrBuffer* (*DvrDisplayManagerSetupNamedBufferPtr)(
     DvrDisplayManagerClient* client, const char* name, size_t size,
-    uint64_t usage0, uint64_t usage1);
+    uint64_t usage);
 typedef size_t (*DvrDisplayManagerClientSurfaceListGetSizePtr)(
     DvrDisplayManagerClientSurfaceList* surface_list);
 typedef int (*DvrDisplayManagerClientSurfaceListGetSurfaceIdPtr)(
@@ -119,7 +119,7 @@
 // dvr_surface.h
 typedef int (*DvrGetNamedBufferPtr)(const char* name, DvrBuffer** out_buffer);
 typedef int (*DvrSurfaceCreatePtr)(int width, int height, int format,
-                                   uint64_t usage0, uint64_t usage1, int flags,
+                                   uint64_t usage, int flags,
                                    DvrSurface** out_surface);
 typedef int (*DvrSurfaceGetWriteBufferQueuePtr)(
     DvrSurface* surface, DvrWriteBufferQueue** out_writer);
diff --git a/libs/vr/libdvr/include/dvr/dvr_surface.h b/libs/vr/libdvr/include/dvr/dvr_surface.h
index e5228d6..a9d02d6 100644
--- a/libs/vr/libdvr/include/dvr/dvr_surface.h
+++ b/libs/vr/libdvr/include/dvr/dvr_surface.h
@@ -14,8 +14,8 @@
 // Get a pointer to the global pose buffer.
 int dvrGetNamedBuffer(const char* name, DvrBuffer** out_buffer);
 
-int dvrSurfaceCreate(int width, int height, int format, uint64_t usage0,
-                     uint64_t usage1, int flags, DvrSurface** out_surface);
+int dvrSurfaceCreate(int width, int height, int format, uint64_t usage,
+                     int flags, DvrSurface** out_surface);
 
 // TODO(eieio, jwcai) Change this once we have multiple buffer queue support.
 int dvrSurfaceGetWriteBufferQueue(DvrSurface* surface,
diff --git a/libs/vr/libdvr/tests/dvr_named_buffer-test.cpp b/libs/vr/libdvr/tests/dvr_named_buffer-test.cpp
index 6a02342..32bdcee 100644
--- a/libs/vr/libdvr/tests/dvr_named_buffer-test.cpp
+++ b/libs/vr/libdvr/tests/dvr_named_buffer-test.cpp
@@ -32,11 +32,11 @@
 TEST_F(DvrNamedBufferTest, TestNamedBuffersSameName) {
   const char* buffer_name = "same_name";
   DvrBuffer* buffer1 =
-      dvrDisplayManagerSetupNamedBuffer(client_, buffer_name, 10, 0, 0);
+      dvrDisplayManagerSetupNamedBuffer(client_, buffer_name, 10, 0);
   ASSERT_NE(nullptr, buffer1);
 
   DvrBuffer* buffer2 =
-      dvrDisplayManagerSetupNamedBuffer(client_, buffer_name, 10, 0, 0);
+      dvrDisplayManagerSetupNamedBuffer(client_, buffer_name, 10, 0);
   ASSERT_NE(nullptr, buffer2);
 
   AHardwareBuffer* hardware_buffer1 = nullptr;
@@ -96,12 +96,12 @@
   const char* buffer_name1 = "test1";
   const char* buffer_name2 = "test2";
   DvrBuffer* setup_buffer1 =
-      dvrDisplayManagerSetupNamedBuffer(client_, buffer_name1, 10, 0, 0);
+      dvrDisplayManagerSetupNamedBuffer(client_, buffer_name1, 10, 0);
   ASSERT_NE(nullptr, setup_buffer1);
   dvrBufferDestroy(setup_buffer1);
 
   DvrBuffer* setup_buffer2 =
-      dvrDisplayManagerSetupNamedBuffer(client_, buffer_name2, 10, 0, 0);
+      dvrDisplayManagerSetupNamedBuffer(client_, buffer_name2, 10, 0);
   ASSERT_NE(nullptr, setup_buffer2);
   dvrBufferDestroy(setup_buffer2);
 
@@ -129,7 +129,7 @@
   const int64_t usage = AHARDWAREBUFFER_USAGE_VIDEO_ENCODE;
 
   DvrBuffer* setup_buffer =
-      dvrDisplayManagerSetupNamedBuffer(client_, buffer_name, 10, usage, 0);
+      dvrDisplayManagerSetupNamedBuffer(client_, buffer_name, 10, usage);
   ASSERT_NE(nullptr, setup_buffer);
 
   AHardwareBuffer* hardware_buffer = nullptr;