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

Commit 6fe9eea7 authored by Tianyu Jiang's avatar Tianyu Jiang Committed by Android (Google) Code Review
Browse files

Merge "Replace the use of helper function IsBufferReleased to member function"

parents 12cc230e a8df5f30
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -318,6 +318,11 @@ int BufferHubBuffer::Release() {
    return 0;
}

bool BufferHubBuffer::IsReleased() const {
    return (buffer_state_->load(std::memory_order_acquire) &
            active_clients_bit_mask_->load(std::memory_order_acquire)) == 0;
}

bool BufferHubBuffer::IsValid() const {
    return mBufferHandle.getNativeHandle() != nullptr && mId >= 0 && mClientStateMask != 0U &&
            mEventFd.get() >= 0 && mMetadata.IsValid() && mBufferClient != nullptr;
+4 −3
Original line number Diff line number Diff line
@@ -59,9 +59,7 @@ public:
    const BufferHubEventFd& eventFd() const { return mEventFd; }

    // Returns the current value of MetadataHeader::buffer_state.
    uint32_t buffer_state() {
        return mMetadata.metadata_header()->buffer_state.load(std::memory_order_acquire);
    }
    uint32_t buffer_state() const { return buffer_state_->load(std::memory_order_acquire); }

    // A state mask which is unique to a buffer hub client among all its siblings sharing the same
    // concrete graphic buffer.
@@ -97,6 +95,9 @@ public:
    // current cycle of the usage of the buffer.
    int Release();

    // Returns whether the buffer is released by all active clients or not.
    bool IsReleased() const;

    // Creates a token that stands for this BufferHubBuffer client and could be used for Import to
    // create another BufferHubBuffer. The new BufferHubBuffer will share the same underlying
    // gralloc buffer and ashmem region for metadata. Note that the caller owns the token and
+0 −5
Original line number Diff line number Diff line
@@ -106,11 +106,6 @@ static inline bool IsClientAcquired(uint32_t state, uint32_t client_bit_mask) {
    return high_bits == 0U;
}

// Returns true if all clients are in released state.
static inline bool IsBufferReleased(uint32_t state) {
    return state == 0U;
}

// Returns true if the input client is in released state.
static inline bool IsClientReleased(uint32_t state, uint32_t client_bit_mask) {
    return (state & client_bit_mask) == 0U;
+7 −8
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ namespace {
using ::android::BufferHubDefs::AnyClientAcquired;
using ::android::BufferHubDefs::AnyClientGained;
using ::android::BufferHubDefs::AnyClientPosted;
using ::android::BufferHubDefs::IsBufferReleased;
using ::android::BufferHubDefs::IsClientAcquired;
using ::android::BufferHubDefs::IsClientGained;
using ::android::BufferHubDefs::IsClientPosted;
@@ -162,8 +161,8 @@ TEST_F(BufferHubBufferTest, DuplicateAndImportBuffer) {
    EXPECT_NE(b1->client_state_mask(), b2->client_state_mask());

    // Both buffer instances should be in released state currently.
    EXPECT_TRUE(IsBufferReleased(b1->buffer_state()));
    EXPECT_TRUE(IsBufferReleased(b2->buffer_state()));
    EXPECT_TRUE(b1->IsReleased());
    EXPECT_TRUE(b2->IsReleased());

    // The event fd should behave like duped event fds.
    const BufferHubEventFd& eventFd1 = b1->eventFd();
@@ -230,7 +229,7 @@ TEST_F(BufferHubBufferTest, ImportInvalidToken) {
}

TEST_F(BufferHubBufferStateTransitionTest, GainBuffer_fromReleasedState) {
    ASSERT_TRUE(IsBufferReleased(b1->buffer_state()));
    ASSERT_TRUE(b1->IsReleased());

    // Successful gaining the buffer should change the buffer state bit of b1 to
    // gained state, other client state bits to released state.
@@ -319,7 +318,7 @@ TEST_F(BufferHubBufferStateTransitionTest, PostBuffer_fromAcquiredState) {
}

TEST_F(BufferHubBufferStateTransitionTest, PostBuffer_fromReleasedState) {
    ASSERT_TRUE(IsBufferReleased(b1->buffer_state()));
    ASSERT_TRUE(b1->IsReleased());

    // Posting from released state should fail.
    EXPECT_EQ(b1->Post(), -EBUSY);
@@ -357,7 +356,7 @@ TEST_F(BufferHubBufferStateTransitionTest, AcquireBuffer_fromSelfInAcquiredState
}

TEST_F(BufferHubBufferStateTransitionTest, AcquireBuffer_fromReleasedState) {
    ASSERT_TRUE(IsBufferReleased(b1->buffer_state()));
    ASSERT_TRUE(b1->IsReleased());

    // Acquiring form released state should fail.
    EXPECT_EQ(b1->Acquire(), -EBUSY);
@@ -374,13 +373,13 @@ TEST_F(BufferHubBufferStateTransitionTest, AcquireBuffer_fromGainedState) {
}

TEST_F(BufferHubBufferStateTransitionTest, ReleaseBuffer_fromSelfInReleasedState) {
    ASSERT_TRUE(IsBufferReleased(b1->buffer_state()));
    ASSERT_TRUE(b1->IsReleased());

    EXPECT_EQ(b1->Release(), 0);
}

TEST_F(BufferHubBufferStateTransitionTest, ReleaseBuffer_fromSelfInGainedState) {
    ASSERT_TRUE(IsBufferReleased(b1->buffer_state()));
    ASSERT_TRUE(b1->IsReleased());
    ASSERT_EQ(b1->Gain(), 0);
    ASSERT_TRUE(AnyClientGained(b1->buffer_state()));

+6 −4
Original line number Diff line number Diff line
@@ -17,8 +17,6 @@
#include <gtest/gtest.h>
#include <ui/BufferHubMetadata.h>

using android::BufferHubDefs::IsBufferReleased;

namespace android {
namespace dvr {

@@ -52,13 +50,17 @@ TEST_F(BufferHubMetadataTest, Import_Success) {
  BufferHubDefs::MetadataHeader* mh1 = m1.metadata_header();
  EXPECT_NE(mh1, nullptr);

  EXPECT_TRUE(IsBufferReleased(mh1->buffer_state.load()));
  // Check if the newly allocated buffer is initialized in released state (i.e.
  // state equals to 0U).
  EXPECT_TRUE(mh1->buffer_state.load() == 0U);

  EXPECT_TRUE(m2.IsValid());
  BufferHubDefs::MetadataHeader* mh2 = m2.metadata_header();
  EXPECT_NE(mh2, nullptr);

  EXPECT_TRUE(IsBufferReleased(mh2->buffer_state.load()));
  // Check if the newly allocated buffer is initialized in released state (i.e.
  // state equals to 0U).
  EXPECT_TRUE(mh2->buffer_state.load() == 0U);
}

TEST_F(BufferHubMetadataTest, MoveMetadataInvalidatesOldOne) {
Loading