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

Commit c0a81bb8 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "BufferHubQueue rename DetachBuffer to RemoveBuffer"

parents 77a24dba bb701dba
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -264,7 +264,7 @@ struct BufferHubRPC {
    kOpCreateConsumerQueue,
    kOpGetQueueInfo,
    kOpProducerQueueAllocateBuffers,
    kOpProducerQueueDetachBuffer,
    kOpProducerQueueRemoveBuffer,
    kOpConsumerQueueImportBuffers,
  };

@@ -312,7 +312,7 @@ struct BufferHubRPC {
                    std::vector<std::pair<LocalChannelHandle, size_t>>(
                        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,
  PDX_REMOTE_METHOD(ProducerQueueRemoveBuffer, kOpProducerQueueRemoveBuffer,
                    void(size_t slot));
  PDX_REMOTE_METHOD(ConsumerQueueImportBuffers, kOpConsumerQueueImportBuffers,
                    std::vector<std::pair<LocalChannelHandle, size_t>>(Void));
+12 −12
Original line number Diff line number Diff line
@@ -259,7 +259,7 @@ Status<void> BufferHubQueue::HandleBufferEvent(size_t slot, int event_fd,
        poll_status.get());

    if (hangup_pending) {
      return DetachBuffer(slot);
      return RemoveBuffer(slot);
    } else {
      // Clean up the bookkeeping for the event fd. This is a bit of paranoia to
      // deal with the epoll set getting out of sync with the buffer slots.
@@ -323,11 +323,11 @@ Status<void> BufferHubQueue::AddBuffer(

  if (buffers_[slot]) {
    // Replace the buffer if the slot is occupied. This could happen when the
    // producer side replaced the slot with a newly allocated buffer. Detach the
    // producer side replaced the slot with a newly allocated buffer. Remove the
    // buffer before setting up with the new one.
    auto detach_status = DetachBuffer(slot);
    if (!detach_status)
      return detach_status.error_status();
    auto remove_status = RemoveBuffer(slot);
    if (!remove_status)
      return remove_status.error_status();
  }

  epoll_event event = {.events = EPOLLIN | EPOLLET,
@@ -344,15 +344,15 @@ Status<void> BufferHubQueue::AddBuffer(
  return {};
}

Status<void> BufferHubQueue::DetachBuffer(size_t slot) {
  ALOGD_IF(TRACE, "BufferHubQueue::DetachBuffer: slot=%zu", slot);
Status<void> BufferHubQueue::RemoveBuffer(size_t slot) {
  ALOGD_IF(TRACE, "BufferHubQueue::RemoveBuffer: slot=%zu", slot);

  if (buffers_[slot]) {
    const int ret =
        epoll_fd_.Control(EPOLL_CTL_DEL, buffers_[slot]->event_fd(), nullptr);
    if (ret < 0) {
      ALOGE(
          "BufferHubQueue::DetachBuffer: Failed to detach buffer from epoll "
          "BufferHubQueue::RemoveBuffer: Failed to remove buffer from epoll "
          "set: "
          "%s",
          strerror(-ret));
@@ -479,16 +479,16 @@ Status<void> ProducerQueue::AddBuffer(
  return Enqueue(buffer, slot);
}

Status<void> ProducerQueue::DetachBuffer(size_t slot) {
Status<void> ProducerQueue::RemoveBuffer(size_t slot) {
  auto status =
      InvokeRemoteMethod<BufferHubRPC::ProducerQueueDetachBuffer>(slot);
      InvokeRemoteMethod<BufferHubRPC::ProducerQueueRemoveBuffer>(slot);
  if (!status) {
    ALOGE("ProducerQueue::DetachBuffer: Failed to detach producer buffer: %s",
    ALOGE("ProducerQueue::RemoveBuffer: Failed to remove producer buffer: %s",
          status.GetErrorMessage().c_str());
    return status.error_status();
  }

  return BufferHubQueue::DetachBuffer(slot);
  return BufferHubQueue::RemoveBuffer(slot);
}

Status<std::shared_ptr<BufferProducer>> ProducerQueue::Dequeue(
+2 −2
Original line number Diff line number Diff line
@@ -633,9 +633,9 @@ status_t BufferHubQueueProducer::AllocateBuffer(uint32_t width, uint32_t height,
}

status_t BufferHubQueueProducer::RemoveBuffer(size_t slot) {
  auto status = queue_->DetachBuffer(slot);
  auto status = queue_->RemoveBuffer(slot);
  if (!status) {
    ALOGE("BufferHubQueueProducer::RemoveBuffer: Failed to detach buffer: %s",
    ALOGE("BufferHubQueueProducer::RemoveBuffer: Failed to remove buffer: %s",
          status.GetErrorMessage().c_str());
    return INVALID_OPERATION;
  }
+4 −4
Original line number Diff line number Diff line
@@ -109,9 +109,9 @@ class BufferHubQueue : public pdx::Client {
  pdx::Status<void> AddBuffer(const std::shared_ptr<BufferHubBuffer>& buffer,
                              size_t slot);

  // Called by ProducerQueue::DetachBuffer and ConsumerQueue::DetachBuffer only
  // Called by ProducerQueue::RemoveBuffer and ConsumerQueue::RemoveBuffer only
  // to deregister a buffer for epoll and internal bookkeeping.
  virtual pdx::Status<void> DetachBuffer(size_t slot);
  virtual pdx::Status<void> RemoveBuffer(size_t slot);

  // Dequeue a buffer from the free queue, blocking until one is available. The
  // timeout argument specifies the number of milliseconds that |Dequeue()| will
@@ -273,8 +273,8 @@ class ProducerQueue : public pdx::ClientBase<ProducerQueue, BufferHubQueue> {
  pdx::Status<void> AddBuffer(const std::shared_ptr<BufferProducer>& buffer,
                              size_t slot);

  // Detach producer buffer from the queue.
  pdx::Status<void> DetachBuffer(size_t slot) override;
  // Remove producer buffer from the queue.
  pdx::Status<void> RemoveBuffer(size_t slot) override;

  // Dequeue a producer buffer to write. The returned buffer in |Gain|'ed mode,
  // and caller should call Post() once it's done writing to release the buffer
+10 −10
Original line number Diff line number Diff line
@@ -167,7 +167,7 @@ TEST_F(BufferHubQueueTest, TestProducerConsumer) {
  }
}

TEST_F(BufferHubQueueTest, TestDetach) {
TEST_F(BufferHubQueueTest, TestRemoveBuffer) {
  ASSERT_TRUE(CreateProducerQueue(config_builder_.Build(), UsagePolicy{}));

  // Allocate buffers.
@@ -204,17 +204,17 @@ TEST_F(BufferHubQueueTest, TestDetach) {
    EXPECT_EQ(i, entry->slot);
  }

  // Detach a buffer and make sure both queues reflect the change.
  ASSERT_TRUE(producer_queue_->DetachBuffer(buffers[0].slot));
  // Remove a buffer and make sure both queues reflect the change.
  ASSERT_TRUE(producer_queue_->RemoveBuffer(buffers[0].slot));
  EXPECT_EQ(kBufferCount - 1, producer_queue_->capacity());

  // As long as the detached buffer is still alive the consumer queue won't know
  // As long as the removed buffer is still alive the consumer queue won't know
  // its gone.
  EXPECT_EQ(kBufferCount, consumer_queue_->capacity());
  EXPECT_FALSE(consumer_queue_->HandleQueueEvents());
  EXPECT_EQ(kBufferCount, consumer_queue_->capacity());

  // Release the detached buffer.
  // Release the removed buffer.
  buffers[0].buffer = nullptr;

  // Now the consumer queue should know it's gone.
@@ -233,8 +233,8 @@ TEST_F(BufferHubQueueTest, TestDetach) {
  EXPECT_FALSE(consumer_queue_->HandleQueueEvents());
  EXPECT_EQ(kBufferCount, consumer_queue_->capacity());

  // Detach and allocate a buffer.
  ASSERT_TRUE(producer_queue_->DetachBuffer(buffers[1].slot));
  // Remove and allocate a buffer.
  ASSERT_TRUE(producer_queue_->RemoveBuffer(buffers[1].slot));
  EXPECT_EQ(kBufferCount - 1, producer_queue_->capacity());
  buffers[1].buffer = nullptr;

@@ -249,8 +249,8 @@ TEST_F(BufferHubQueueTest, TestDetach) {
  EXPECT_FALSE(consumer_queue_->HandleQueueEvents());
  EXPECT_EQ(kBufferCount, consumer_queue_->capacity());

  // Detach and allocate a buffer, but don't free the buffer right away.
  ASSERT_TRUE(producer_queue_->DetachBuffer(buffers[2].slot));
  // Remove and allocate a buffer, but don't free the buffer right away.
  ASSERT_TRUE(producer_queue_->RemoveBuffer(buffers[2].slot));
  EXPECT_EQ(kBufferCount - 1, producer_queue_->capacity());

  AllocateBuffer(&slot);
@@ -263,7 +263,7 @@ TEST_F(BufferHubQueueTest, TestDetach) {
  EXPECT_EQ(kBufferCount, consumer_queue_->capacity());

  // Release the producer buffer to trigger a POLLHUP event for an already
  // detached buffer.
  // removed buffer.
  buffers[2].buffer = nullptr;
  EXPECT_EQ(kBufferCount, consumer_queue_->capacity());
  EXPECT_FALSE(consumer_queue_->HandleQueueEvents());
Loading