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

Commit ef49ca62 authored by Tianyu Jiang's avatar Tianyu Jiang
Browse files

Move BufferHubBase::Lock and ::Unlock from public function to private helper.

User should be using GraphicBuffer/AHardwareBuffer::Lock/Unlock to lock/unlock
for CPU access to the data in the buffer.

BufferHubBase::Lock/Unlock exist were because this legacy class has IonBuffer,
which wraps a GraphicBuffer. The dependency will be reverted in the future, where
BufferHubBuffer backs GraphicBuffer.

Bug: None
Test: m, mma, vrflinger_test
Change-Id: I3e3287529326dce3ae57e344c5c738b898c3d44d
parent 4b70146a
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -21,16 +21,6 @@ class BufferHubBase : public pdx::Client {
  // a file descriptor for the new channel or a negative error code.
  Status<LocalChannelHandle> CreateConsumer();

  // Locks the area specified by (x, y, width, height) for a specific usage. If
  // the usage is software then |addr| will be updated to point to the address
  // of the buffer in virtual memory. The caller should only access/modify the
  // pixels in the specified area. anything else is undefined behavior.
  int Lock(int usage, int x, int y, int width, int height, void** addr);

  // Must be called after Lock() when the caller has finished changing the
  // buffer.
  int Unlock();

  // Gets a blob buffer that was created with ProducerBuffer::CreateBlob.
  // Locking and Unlocking is handled internally. There's no need to Unlock
  // after calling this method.
@@ -128,6 +118,16 @@ class BufferHubBase : public pdx::Client {
  int UpdateSharedFence(const LocalHandle& new_fence,
                        const LocalHandle& shared_fence);

  // Locks the area specified by (x, y, width, height) for a specific usage. If
  // the usage is software then |addr| will be updated to point to the address
  // of the buffer in virtual memory. The caller should only access/modify the
  // pixels in the specified area. anything else is undefined behavior.
  int Lock(int usage, int x, int y, int width, int height, void** addr);

  // Must be called after Lock() when the caller has finished changing the
  // buffer.
  int Unlock();

  // IonBuffer that is shared between bufferhubd, producer, and consumers.
  size_t metadata_buf_size_{0};
  size_t user_metadata_size_{0};
+4 −4
Original line number Diff line number Diff line
@@ -205,9 +205,9 @@ TEST(VrFlingerTest, ActivateDeactivate) {
    ASSERT_EQ(buffer.get()->height(), metrics.get().display_height);

    void* raw_buf = nullptr;
    ASSERT_GE(buffer.get()->Lock(AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN,
                                 /*x=*/0, /*y=*/0, buffer.get()->width(),
                                 buffer.get()->height(), &raw_buf),
    ASSERT_GE(buffer.get()->buffer()->Lock(
                  AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN, /*x=*/0, /*y=*/0,
                  buffer.get()->width(), buffer.get()->height(), &raw_buf),
              0);
    ASSERT_NE(raw_buf, nullptr);
    uint32_t* pixels = static_cast<uint32_t*>(raw_buf);
@@ -216,7 +216,7 @@ TEST(VrFlingerTest, ActivateDeactivate) {
      pixels[i] = 0x0000ff00;
    }

    ASSERT_GE(buffer.get()->Unlock(), 0);
    ASSERT_GE(buffer.get()->buffer()->Unlock(), 0);

    ASSERT_GE(buffer.get()->Post(/*ready_fence=*/pdx::LocalHandle()), 0);