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

Commit 3be4ebb0 authored by Tianyu's avatar Tianyu Committed by Tianyu Jiang
Browse files

Fix return error

Previously, the allocate buffer does not return error if it runs out of
memory. This change adds the error in return.

Test: buffer_hub_queue-test passes on Vega on oc-dr1-daydream-dev branch
Test: buffer_hub_queue-test passes on Marlin on master branch
Bug: None

Change-Id: I2a37fd3221cf54c92d4f53e577e5f0055ef77b13
parent 78bc0453
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -440,6 +440,9 @@ ProducerQueue::ProducerQueue(const ProducerQueueConfig& config,
Status<std::vector<size_t>> ProducerQueue::AllocateBuffers(
    uint32_t width, uint32_t height, uint32_t layer_count, uint32_t format,
    uint64_t usage, size_t buffer_count) {
  if (buffer_count == 0) {
    return {};
  }
  if (capacity() + buffer_count > kMaxQueueCapacity) {
    ALOGE(
        "ProducerQueue::AllocateBuffers: queue is at capacity: %zu, cannot "
@@ -481,10 +484,13 @@ Status<std::vector<size_t>> ProducerQueue::AllocateBuffers(
    }
  }

  if (buffer_slots.size() == 0) {
    // Error out if no buffer is allocated and improted.
    ALOGE_IF(TRACE, "ProducerQueue::AllocateBuffers: no buffer allocated.");
    ErrorStatus(ENOMEM);
  if (buffer_slots.size() != buffer_count) {
    // Error out if the count of allocated/imported buffer(s) is not correct.
    ALOGE(
        "ProducerQueue::AllocateBuffers: requested to import %zu "
        "buffers, but actually imported %zu buffers.",
        buffer_count, buffer_slots.size());
    return ErrorStatus(ENOMEM);
  }

  return {std::move(buffer_slots)};
@@ -502,12 +508,6 @@ Status<size_t> ProducerQueue::AllocateBuffer(uint32_t width, uint32_t height,
          status.GetErrorMessage().c_str());
    return status.error_status();
  }

  if (status.get().size() == 0) {
    ALOGE_IF(TRACE, "ProducerQueue::AllocateBuffer: no buffer allocated.");
    ErrorStatus(ENOMEM);
  }

  return {status.get()[0]};
}

+22 −0
Original line number Diff line number Diff line
@@ -562,6 +562,28 @@ TEST_F(BufferHubQueueTest, TestAllocateBuffer) {
  ASSERT_EQ(cs2, ps2);
}

TEST_F(BufferHubQueueTest, TestAllocateTwoBuffers) {
  ASSERT_TRUE(CreateQueues(config_builder_.Build(), UsagePolicy{}));
  ASSERT_EQ(producer_queue_->capacity(), 0);

  auto status = producer_queue_->AllocateBuffers(
      kBufferWidth, kBufferHeight, kBufferLayerCount, kBufferFormat,
      kBufferUsage, 2);
  ASSERT_TRUE(status.ok());
  ASSERT_EQ(producer_queue_->capacity(), 2);
}

TEST_F(BufferHubQueueTest, TestAllocateZeroBuffers) {
  ASSERT_TRUE(CreateQueues(config_builder_.Build(), UsagePolicy{}));
  ASSERT_EQ(producer_queue_->capacity(), 0);

  auto status = producer_queue_->AllocateBuffers(
      kBufferWidth, kBufferHeight, kBufferLayerCount, kBufferFormat,
      kBufferUsage, 0);
  ASSERT_TRUE(status.ok());
  ASSERT_EQ(producer_queue_->capacity(), 0);
}

TEST_F(BufferHubQueueTest, TestUsageSetMask) {
  const uint32_t set_mask = GRALLOC_USAGE_SW_WRITE_OFTEN;
  ASSERT_TRUE(