Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e6b35c83 authored by Corey Tabaka's avatar Corey Tabaka Committed by android-build-merger
Browse files

Merge "Update BufferHub service/client with support for gralloc1 usage." into oc-dev

am: b162d089

Change-Id: Id86beec15d3b84749ce1949319f38222214596ab
parents 7374d160 b162d089
Loading
Loading
Loading
Loading
+52 −22
Original line number Diff line number Diff line
@@ -196,18 +196,27 @@ int BufferConsumer::SetIgnore(bool ignore) {
      InvokeRemoteMethod<BufferHubRPC::ConsumerSetIgnore>(ignore));
}

BufferProducer::BufferProducer(int width, int height, int format, int usage,
BufferProducer::BufferProducer(uint32_t width, uint32_t height, uint32_t format,
                               uint32_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=%d height=%d format=%d "
           "usage=%d, metadata_size=%zu, slice_count=%zu",
           event_fd(), width, height, format, usage, metadata_size,
           slice_count);
           "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);

  auto status = InvokeRemoteMethod<BufferHubRPC::CreateBuffer>(
      width, height, format, usage, metadata_size, slice_count);
      width, height, format, producer_usage, consumer_usage, metadata_size,
      slice_count);
  if (!status) {
    ALOGE(
        "BufferProducer::BufferProducer: Failed to create producer buffer: %s",
@@ -226,21 +235,29 @@ BufferProducer::BufferProducer(int width, int height, int format, int usage,
}

BufferProducer::BufferProducer(const std::string& name, int user_id,
                               int group_id, int width, int height, int format,
                               int usage, size_t meta_size_bytes,
                               int group_id, uint32_t width, uint32_t height,
                               uint32_t format, uint32_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=%d height=%d format=%d usage=%d, "
           "meta_size_bytes=%zu, slice_count=%zu",
           "group_id=%d width=%u height=%u format=%u producer_usage=%" PRIx64
           " consumer_usage=%" PRIx64 " meta_size_bytes=%zu slice_count=%zu",
           event_fd(), name.c_str(), user_id, group_id, width, height, format,
           usage, meta_size_bytes, slice_count);
           producer_usage, consumer_usage, meta_size_bytes, slice_count);

  auto status = InvokeRemoteMethod<BufferHubRPC::CreatePersistentBuffer>(
      name, user_id, group_id, width, height, format, usage, meta_size_bytes,
      slice_count);
      name, user_id, group_id, width, height, format, producer_usage,
      consumer_usage, meta_size_bytes, slice_count);
  if (!status) {
    ALOGE(
        "BufferProducer::BufferProducer: Failed to create/get persistent "
@@ -260,18 +277,25 @@ BufferProducer::BufferProducer(const std::string& name, int user_id,
  }
}

BufferProducer::BufferProducer(int usage, size_t size)
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)
    : BASE(BufferHubRPC::kClientPath) {
  ATRACE_NAME("BufferProducer::BufferProducer");
  ALOGD_IF(TRACE, "BufferProducer::BufferProducer: usage=%d size=%zu", usage,
           size);
  ALOGD_IF(TRACE,
           "BufferProducer::BufferProducer: producer_usage=%" PRIx64
           " consumer_usage=%" PRIx64 " size=%zu",
           producer_usage, consumer_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;
  auto status = InvokeRemoteMethod<BufferHubRPC::CreateBuffer>(
      width, height, format, usage, meta_size_bytes, slice_count);
      width, height, format, producer_usage, consumer_usage, meta_size_bytes,
      slice_count);
  if (!status) {
    ALOGE("BufferProducer::BufferProducer: Failed to create blob: %s",
          status.GetErrorMessage().c_str());
@@ -289,21 +313,27 @@ BufferProducer::BufferProducer(int usage, size_t size)
}

BufferProducer::BufferProducer(const std::string& name, int user_id,
                               int group_id, int usage, size_t size)
                               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)
    : BASE(BufferHubRPC::kClientPath) {
  ATRACE_NAME("BufferProducer::BufferProducer");
  ALOGD_IF(TRACE,
           "BufferProducer::BufferProducer: name=%s user_id=%d group=%d "
           "usage=%d size=%zu",
           name.c_str(), user_id, group_id, usage, size);
           "producer_usage=%" PRIx64 " consumer_usage=%" PRIx64 " size=%zu",
           name.c_str(), user_id, group_id, producer_usage, consumer_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;
  auto status = InvokeRemoteMethod<BufferHubRPC::CreatePersistentBuffer>(
      name, user_id, group_id, width, height, format, usage, meta_size_bytes,
      slice_count);
      name, user_id, group_id, width, height, format, producer_usage,
      consumer_usage, meta_size_bytes, slice_count);
  if (!status) {
    ALOGE(
        "BufferProducer::BufferProducer: Failed to create persistent "
+27 −12
Original line number Diff line number Diff line
@@ -107,11 +107,14 @@ class BufferHubBuffer : public pdx::Client {
  // The following methods return settings of the first buffer. Currently,
  // it is only possible to create multi-buffer BufferHubBuffers with the same
  // settings.
  int width() const { return slices_[0].width(); }
  int height() const { return slices_[0].height(); }
  int stride() const { return slices_[0].stride(); }
  int format() const { return slices_[0].format(); }
  int usage() const { return slices_[0].usage(); }
  uint32_t width() const { return slices_[0].width(); }
  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(); }
  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(); }

 protected:
  explicit BufferHubBuffer(LocalChannelHandle channel);
@@ -218,8 +221,12 @@ class BufferProducer : public pdx::ClientBase<BufferProducer, BufferHubBuffer> {
  // arguments as the constructors.

  // Constructs a buffer with the given geometry and parameters.
  BufferProducer(int width, int height, int format, int usage,
                 size_t metadata_size = 0, size_t slice_count = 1);
  BufferProducer(uint32_t width, uint32_t height, uint32_t format,
                 uint32_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
@@ -233,16 +240,24 @@ class BufferProducer : public pdx::ClientBase<BufferProducer, BufferHubBuffer> {
  // created and cannot be changed. A user or group id of -1 disables checks for
  // that respective id. A user or group id of 0 is substituted with the
  // effective user or group id of the calling process.
  BufferProducer(const std::string& name, int user_id, int group_id, int width,
                 int height, int format, int usage, size_t metadata_size = 0,
  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,
                 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(int usage, size_t size);
  BufferProducer(uint32_t usage, size_t size);
  BufferProducer(uint64_t producer_usage, uint64_t consumer_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, int usage,
                 size_t size);
  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);

  // Constructs a channel to persistent buffer by name only. The buffer must
  // have been previously created or made persistent.
+53 −27
Original line number Diff line number Diff line
@@ -24,7 +24,8 @@ class NativeBufferHandle {
        width_(buffer.width()),
        height_(buffer.height()),
        format_(buffer.format()),
        usage_(buffer.usage()) {
        producer_usage_(buffer.producer_usage()),
        consumer_usage_(buffer.consumer_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;
@@ -46,9 +47,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_, stride_, format_,
                       producer_usage_, consumer_usage_);
    if (ret < 0)
      return ret;

@@ -68,19 +70,24 @@ class NativeBufferHandle {

 private:
  int id_;
  int stride_;
  int width_;
  int height_;
  int format_;
  int usage_;
  uint32_t stride_;
  uint32_t width_;
  uint32_t height_;
  uint32_t format_;
  uint64_t producer_usage_;
  uint64_t consumer_usage_;
  std::vector<int> opaque_ints_;
  std::vector<FileHandleType> fds_;

  void Clear() { id_ = stride_ = width_ = height_ = format_ = usage_ = -1; }
  void Clear() {
    id_ = -1;
    stride_ = width_ = height_ = format_ = producer_usage_ = consumer_usage_ =
        0;
  }

  PDX_SERIALIZABLE_MEMBERS(NativeBufferHandle<FileHandleType>, id_, stride_,
                           width_, height_, format_, usage_, opaque_ints_,
                           fds_);
                           width_, height_, format_, producer_usage_,
                           consumer_usage_, opaque_ints_, fds_);

  NativeBufferHandle(const NativeBufferHandle&) = delete;
  void operator=(const NativeBufferHandle&) = delete;
@@ -127,6 +134,23 @@ struct QueueInfo {
  PDX_SERIALIZABLE_MEMBERS(QueueInfo, meta_size_bytes, id);
};

struct UsagePolicy {
  uint64_t producer_set_mask;
  uint64_t producer_clear_mask;
  uint64_t producer_deny_set_mask;
  uint64_t producer_deny_clear_mask;
  uint64_t consumer_set_mask;
  uint64_t consumer_clear_mask;
  uint64_t consumer_deny_set_mask;
  uint64_t consumer_deny_clear_mask;

 private:
  PDX_SERIALIZABLE_MEMBERS(UsagePolicy, producer_set_mask, producer_clear_mask,
                           producer_deny_set_mask, producer_deny_clear_mask,
                           consumer_set_mask, consumer_clear_mask,
                           consumer_deny_set_mask, consumer_deny_clear_mask);
};

// BufferHub Service RPC interface. Defines the endpoints, op codes, and method
// type signatures supported by bufferhubd.
struct BufferHubRPC {
@@ -173,44 +197,46 @@ struct BufferHubRPC {

  // Methods.
  PDX_REMOTE_METHOD(CreateBuffer, kOpCreateBuffer,
                    int(int width, int height, int format, int usage,
                    void(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));
  PDX_REMOTE_METHOD(CreatePersistentBuffer, kOpCreatePersistentBuffer,
                    int(const std::string& name, int user_id, int group_id,
                        int width, int height, int format, int usage,
                    void(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));
  PDX_REMOTE_METHOD(GetPersistentBuffer, kOpGetPersistentBuffer,
                    int(const std::string& name));
                    void(const std::string& name));
  PDX_REMOTE_METHOD(GetBuffer, kOpGetBuffer,
                    NativeBufferHandle<LocalHandle>(unsigned index));
  PDX_REMOTE_METHOD(GetBuffers, kOpGetBuffers,
                    std::vector<NativeBufferHandle<LocalHandle>>(Void));
  PDX_REMOTE_METHOD(NewConsumer, kOpNewConsumer, LocalChannelHandle(Void));
  PDX_REMOTE_METHOD(ProducerMakePersistent, kOpProducerMakePersistent,
                    int(const std::string& name, int user_id, int group_id));
                    void(const std::string& name, int user_id, int group_id));
  PDX_REMOTE_METHOD(ProducerRemovePersistence, kOpProducerRemovePersistence,
                    int(Void));
                    void(Void));
  PDX_REMOTE_METHOD(ProducerPost, kOpProducerPost,
                    int(LocalFence acquire_fence, MetaData));
                    void(LocalFence acquire_fence, MetaData));
  PDX_REMOTE_METHOD(ProducerGain, kOpProducerGain, LocalFence(Void));
  PDX_REMOTE_METHOD(ConsumerAcquire, kOpConsumerAcquire,
                    std::pair<LocalFence, MetaData>(std::size_t metadata_size));
  PDX_REMOTE_METHOD(ConsumerRelease, kOpConsumerRelease,
                    int(LocalFence release_fence));
  PDX_REMOTE_METHOD(ConsumerSetIgnore, kOpConsumerSetIgnore, int(bool ignore));
                    void(LocalFence release_fence));
  PDX_REMOTE_METHOD(ConsumerSetIgnore, kOpConsumerSetIgnore, void(bool ignore));

  // Buffer Queue Methods.
  PDX_REMOTE_METHOD(CreateProducerQueue, kOpCreateProducerQueue,
                    QueueInfo(size_t meta_size_bytes, int usage_set_mask,
                              int usage_clear_mask, int usage_deny_set_mask,
                              int usage_deny_clear_mask));
                    QueueInfo(size_t meta_size_bytes,
                              const UsagePolicy& usage_policy));
  PDX_REMOTE_METHOD(CreateConsumerQueue, kOpCreateConsumerQueue,
                    LocalChannelHandle(Void));
  PDX_REMOTE_METHOD(GetQueueInfo, kOpGetQueueInfo, QueueInfo(Void));
  PDX_REMOTE_METHOD(ProducerQueueAllocateBuffers,
                    kOpProducerQueueAllocateBuffers,
                    std::vector<std::pair<LocalChannelHandle, size_t>>(
                        int width, int height, int format, int usage,
                        uint32_t width, uint32_t height, uint32_t format,
                        uint64_t producer_usage, uint64_t consumer_usage,
                        size_t slice_count, size_t buffer_count));
  PDX_REMOTE_METHOD(ProducerQueueDetachBuffer, kOpProducerQueueDetachBuffer,
                    void(size_t slot));
+51 −21
Original line number Diff line number Diff line
@@ -12,11 +12,20 @@ namespace dvr {
class IonBuffer {
 public:
  IonBuffer();
  IonBuffer(int width, int height, int format, int usage);
  IonBuffer(buffer_handle_t handle, int width, int height, int stride,
            int format, int usage);
  IonBuffer(buffer_handle_t handle, int width, int height, int layer_count,
            int stride, int layer_stride, int format, int usage);
  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(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);
  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);
  ~IonBuffer();

  IonBuffer(IonBuffer&& other);
@@ -30,25 +39,36 @@ 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(int width, int height, int format, int usage);
  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);

  // Resets the underlying native handle and parameters, freeing the previous
  // native handle if necessary.
  void Reset(buffer_handle_t handle, int width, int height, int stride,
             int format, int usage);
  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);

  // 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, int width, int height, int stride,
             int format, int usage);
  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);

  // 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, int width, int height, int stride, int format,
             int usage);
             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);

  // Duplicates the native handle underlying |other| and then imports it. This
  // is useful for creating multiple, independent views of the same Ion/Gralloc
@@ -56,8 +76,8 @@ class IonBuffer {
  // duplication or import fail the previous native handle is left intact.
  int Duplicate(const IonBuffer* other);

  int Lock(int usage, int x, int y, int width, int height, void** address);
  int LockYUV(int usage, int x, int y, int width, int height,
  int Lock(uint32_t usage, int x, int y, int width, int height, void** address);
  int LockYUV(uint32_t usage, int x, int y, int width, int height,
              struct android_ycbcr* yuv);
  int Unlock();

@@ -65,19 +85,29 @@ class IonBuffer {
  buffer_handle_t handle() const {
    return buffer_.get() ? buffer_->handle : nullptr;
  }
  int width() const { return buffer_.get() ? buffer_->getWidth() : 0; }
  int height() const { return buffer_.get() ? buffer_->getHeight() : 0; }
  int layer_count() const {
  uint32_t width() const { return buffer_.get() ? buffer_->getWidth() : 0; }
  uint32_t height() const { return buffer_.get() ? buffer_->getHeight() : 0; }
  uint32_t layer_count() const {
    return buffer_.get() ? buffer_->getLayerCount() : 0;
  }
  int stride() const { return buffer_.get() ? buffer_->getStride() : 0; }
  int layer_stride() const { return 0; }
  int format() const { return buffer_.get() ? buffer_->getPixelFormat() : 0; }
  int usage() const { return buffer_.get() ? buffer_->getUsage() : 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;
  }
  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; }

 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;
};
+119 −52

File changed.

Preview size limit exceeded, changes collapsed.

Loading