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

Commit f64c2b7e authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 5058806 from a715100a to qt-release

Change-Id: I9d90b21407c4672508116a2fc0d5e9ae0ff7691a
parents a8a19f4c a715100a
Loading
Loading
Loading
Loading
+38 −37
Original line number Diff line number Diff line
@@ -34,39 +34,39 @@

#include <cstddef>

namespace android {
namespace ndk {

/**
 * Represents one strong pointer to an AIBinder object.
 */
class AutoAIBinder {
class SpAIBinder {
public:
    /**
     * Takes ownership of one strong refcount of binder.
     */
    explicit AutoAIBinder(AIBinder* binder = nullptr) : mBinder(binder) {}
    explicit SpAIBinder(AIBinder* binder = nullptr) : mBinder(binder) {}

    /**
     * Convenience operator for implicitly constructing an AutoAIBinder from nullptr. This is not
     * Convenience operator for implicitly constructing an SpAIBinder from nullptr. This is not
     * explicit because it is not taking ownership of anything.
     */
    AutoAIBinder(std::nullptr_t) : AutoAIBinder() {}
    SpAIBinder(std::nullptr_t) : SpAIBinder() {}

    /**
     * This will delete the underlying object if it exists. See operator=.
     */
    AutoAIBinder(const AutoAIBinder& other) { *this = other; }
    SpAIBinder(const SpAIBinder& other) { *this = other; }

    /**
     * This deletes the underlying object if it exists. See set.
     */
    ~AutoAIBinder() { set(nullptr); }
    ~SpAIBinder() { set(nullptr); }

    /**
     * This takes ownership of a binder from another AIBinder object but it does not affect the
     * ownership of that other object.
     */
    AutoAIBinder& operator=(const AutoAIBinder& other) {
    SpAIBinder& operator=(const SpAIBinder& other) {
        AIBinder_incStrong(other.mBinder);
        set(other.mBinder);
        return *this;
@@ -82,7 +82,7 @@ public:

    /**
     * This returns the underlying binder object for transactions. If it is used to create another
     * AutoAIBinder object, it should first be incremented.
     * SpAIBinder object, it should first be incremented.
     */
    AIBinder* get() const { return mBinder; }

@@ -92,7 +92,7 @@ public:
     * ownership to the object that is put in here.
     *
     * Recommended use is like this:
     *   AutoAIBinder a;  // will be nullptr
     *   SpAIBinder a;  // will be nullptr
     *   SomeInitFunction(a.getR());  // value is initialized with refcount
     *
     * Other usecases are discouraged.
@@ -108,17 +108,17 @@ private:
 * This baseclass owns a single object, used to make various classes RAII.
 */
template <typename T, void (*Destroy)(T*)>
class AutoA {
class ScopedAResource {
public:
    /**
     * Takes ownership of t.
     */
    explicit AutoA(T* t = nullptr) : mT(t) {}
    explicit ScopedAResource(T* t = nullptr) : mT(t) {}

    /**
     * This deletes the underlying object if it exists. See set.
     */
    ~AutoA() { set(nullptr); }
    ~ScopedAResource() { set(nullptr); }

    /**
     * Takes ownership of t.
@@ -144,7 +144,7 @@ public:
     * ownership to the object that is put in here.
     *
     * Recommended use is like this:
     *   AutoA<T> a; // will be nullptr
     *   ScopedAResource<T> a; // will be nullptr
     *   SomeInitFunction(a.getR()); // value is initialized with refcount
     *
     * Other usecases are discouraged.
@@ -153,12 +153,12 @@ public:
    T** getR() { return &mT; }

    // copy-constructing, or move/copy assignment is disallowed
    AutoA(const AutoA&) = delete;
    AutoA& operator=(const AutoA&) = delete;
    AutoA& operator=(AutoA&&) = delete;
    ScopedAResource(const ScopedAResource&) = delete;
    ScopedAResource& operator=(const ScopedAResource&) = delete;
    ScopedAResource& operator=(ScopedAResource&&) = delete;

    // move-constructing is okay
    AutoA(AutoA&&) = default;
    ScopedAResource(ScopedAResource&&) = default;

private:
    T* mT;
@@ -167,27 +167,27 @@ private:
/**
 * Convenience wrapper. See AParcel.
 */
class AutoAParcel : public AutoA<AParcel, AParcel_delete> {
class ScopedAParcel : public ScopedAResource<AParcel, AParcel_delete> {
public:
    /**
     * Takes ownership of a.
     */
    explicit AutoAParcel(AParcel* a = nullptr) : AutoA(a) {}
    ~AutoAParcel() {}
    AutoAParcel(AutoAParcel&&) = default;
    explicit ScopedAParcel(AParcel* a = nullptr) : ScopedAResource(a) {}
    ~ScopedAParcel() {}
    ScopedAParcel(ScopedAParcel&&) = default;
};

/**
 * Convenience wrapper. See AStatus.
 */
class AutoAStatus : public AutoA<AStatus, AStatus_delete> {
class ScopedAStatus : public ScopedAResource<AStatus, AStatus_delete> {
public:
    /**
     * Takes ownership of a.
     */
    explicit AutoAStatus(AStatus* a = nullptr) : AutoA(a) {}
    ~AutoAStatus() {}
    AutoAStatus(AutoAStatus&&) = default;
    explicit ScopedAStatus(AStatus* a = nullptr) : ScopedAResource(a) {}
    ~ScopedAStatus() {}
    ScopedAStatus(ScopedAStatus&&) = default;

    /**
     * See AStatus_isOk.
@@ -198,36 +198,37 @@ public:
/**
 * Convenience wrapper. See AIBinder_DeathRecipient.
 */
class AutoAIBinder_DeathRecipient
      : public AutoA<AIBinder_DeathRecipient, AIBinder_DeathRecipient_delete> {
class ScopedAIBinder_DeathRecipient
      : public ScopedAResource<AIBinder_DeathRecipient, AIBinder_DeathRecipient_delete> {
public:
    /**
     * Takes ownership of a.
     */
    explicit AutoAIBinder_DeathRecipient(AIBinder_DeathRecipient* a = nullptr) : AutoA(a) {}
    ~AutoAIBinder_DeathRecipient() {}
    AutoAIBinder_DeathRecipient(AutoAIBinder_DeathRecipient&&) = default;
    explicit ScopedAIBinder_DeathRecipient(AIBinder_DeathRecipient* a = nullptr)
          : ScopedAResource(a) {}
    ~ScopedAIBinder_DeathRecipient() {}
    ScopedAIBinder_DeathRecipient(ScopedAIBinder_DeathRecipient&&) = default;
};

/**
 * Convenience wrapper. See AIBinder_Weak.
 */
class AutoAIBinder_Weak : public AutoA<AIBinder_Weak, AIBinder_Weak_delete> {
class ScopedAIBinder_Weak : public ScopedAResource<AIBinder_Weak, AIBinder_Weak_delete> {
public:
    /**
     * Takes ownership of a.
     */
    explicit AutoAIBinder_Weak(AIBinder_Weak* a = nullptr) : AutoA(a) {}
    ~AutoAIBinder_Weak() {}
    AutoAIBinder_Weak(AutoAIBinder_Weak&&) = default;
    explicit ScopedAIBinder_Weak(AIBinder_Weak* a = nullptr) : ScopedAResource(a) {}
    ~ScopedAIBinder_Weak() {}
    ScopedAIBinder_Weak(ScopedAIBinder_Weak&&) = default;

    /**
     * See AIBinder_Weak_promote.
     */
    AutoAIBinder promote() { return AutoAIBinder(AIBinder_Weak_promote(get())); }
    SpAIBinder promote() { return SpAIBinder(AIBinder_Weak_promote(get())); }
};

} // namespace android
} // namespace ndk

#endif // __cplusplus

+32 −13
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@
#include <memory>
#include <mutex>

namespace android {
namespace ndk {

// analog using std::shared_ptr for RefBase-like semantics
class SharedRefBase {
@@ -56,6 +56,15 @@ public:
        return std::static_pointer_cast<CHILD>(ref());
    }

    /**
     * Convenience method for making an object directly with a reference.
     */
    template<class T, class... Args>
    static std::shared_ptr<T> make(Args&&... args) {
        T* t = new T(std::forward<Args>(args)...);
        return t->template ref<T>();
    }

private:
    std::once_flag mFlagThis;
    std::weak_ptr<SharedRefBase> mThis;
@@ -68,7 +77,13 @@ public:
    virtual ~ICInterface() {}

    // This either returns the single existing implementation or creates a new implementation.
    virtual AutoAIBinder asBinder() = 0;
    virtual SpAIBinder asBinder() = 0;

    /**
     * Returns whether this interface is in a remote process. If it cannot be determined locally,
     * this will be checked using AIBinder_isRemote.
     */
    virtual bool isRemote() = 0;
};

// wrapper analog to BnInterface
@@ -78,36 +93,40 @@ public:
    BnCInterface() {}
    virtual ~BnCInterface() {}

    AutoAIBinder asBinder() override;
    SpAIBinder asBinder() override;

    bool isRemote() override { return true; }

protected:
    // This function should only be called by asBinder. Otherwise, there is a possibility of
    // multiple AIBinder* objects being created for the same instance of an object.
    virtual AutoAIBinder createBinder() = 0;
    virtual SpAIBinder createBinder() = 0;

private:
    std::mutex mMutex; // for asBinder
    AutoAIBinder_Weak mWeakBinder;
    ScopedAIBinder_Weak mWeakBinder;
};

// wrapper analog to BpInterfae
template <typename INTERFACE>
class BpCInterface : public INTERFACE {
public:
    BpCInterface(const AutoAIBinder& binder) : mBinder(binder) {}
    BpCInterface(const SpAIBinder& binder) : mBinder(binder) {}
    virtual ~BpCInterface() {}

    AutoAIBinder asBinder() override;
    SpAIBinder asBinder() override;

    bool isRemote() override { return AIBinder_isRemote(mBinder.get()); }

private:
    AutoAIBinder mBinder;
    SpAIBinder mBinder;
};

template <typename INTERFACE>
AutoAIBinder BnCInterface<INTERFACE>::asBinder() {
SpAIBinder BnCInterface<INTERFACE>::asBinder() {
    std::lock_guard<std::mutex> l(mMutex);

    AutoAIBinder binder;
    SpAIBinder binder;
    if (mWeakBinder.get() != nullptr) {
        binder.set(AIBinder_Weak_promote(mWeakBinder.get()));
    }
@@ -120,12 +139,12 @@ AutoAIBinder BnCInterface<INTERFACE>::asBinder() {
}

template <typename INTERFACE>
AutoAIBinder BpCInterface<INTERFACE>::asBinder() {
SpAIBinder BpCInterface<INTERFACE>::asBinder() {
    return mBinder;
}

#endif // __cplusplus
} // namespace ndk

} // namespace android
#endif // __cplusplus

/** @} */
+4 −0
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@

#include <string>

namespace ndk {

/**
 * Takes a std::string and reallocates it to the specified length. For use with AParcel_readString.
 * See use below in AParcel_readString.
@@ -66,6 +68,8 @@ static inline binder_status_t AParcel_readString(const AParcel* parcel, std::str
                              &stringData);
}

} // namespace ndk

#endif // __cplusplus

/** @} */
+73 −73
Original line number Diff line number Diff line
@@ -21,9 +21,9 @@

using android::GraphicBuffer;
using android::sp;
using android::dvr::BufferConsumer;
using android::dvr::BufferProducer;
using android::dvr::ConsumerBuffer;
using android::dvr::DetachedBuffer;
using android::dvr::ProducerBuffer;
using android::dvr::BufferHubDefs::IsBufferAcquired;
using android::dvr::BufferHubDefs::IsBufferGained;
using android::dvr::BufferHubDefs::IsBufferPosted;
@@ -48,15 +48,15 @@ const int kPollTimeoutMs = 100;
using LibBufferHubTest = ::testing::Test;

TEST_F(LibBufferHubTest, TestBasicUsage) {
  std::unique_ptr<BufferProducer> p = BufferProducer::Create(
  std::unique_ptr<ProducerBuffer> p = ProducerBuffer::Create(
      kWidth, kHeight, kFormat, kUsage, sizeof(uint64_t));
  ASSERT_TRUE(p.get() != nullptr);
  std::unique_ptr<BufferConsumer> c =
      BufferConsumer::Import(p->CreateConsumer());
  std::unique_ptr<ConsumerBuffer> c =
      ConsumerBuffer::Import(p->CreateConsumer());
  ASSERT_TRUE(c.get() != nullptr);
  // Check that consumers can spawn other consumers.
  std::unique_ptr<BufferConsumer> c2 =
      BufferConsumer::Import(c->CreateConsumer());
  std::unique_ptr<ConsumerBuffer> c2 =
      ConsumerBuffer::Import(c->CreateConsumer());
  ASSERT_TRUE(c2.get() != nullptr);

  // Producer state mask is unique, i.e. 1.
@@ -110,11 +110,11 @@ TEST_F(LibBufferHubTest, TestBasicUsage) {
}

TEST_F(LibBufferHubTest, TestEpoll) {
  std::unique_ptr<BufferProducer> p = BufferProducer::Create(
  std::unique_ptr<ProducerBuffer> p = ProducerBuffer::Create(
      kWidth, kHeight, kFormat, kUsage, sizeof(uint64_t));
  ASSERT_TRUE(p.get() != nullptr);
  std::unique_ptr<BufferConsumer> c =
      BufferConsumer::Import(p->CreateConsumer());
  std::unique_ptr<ConsumerBuffer> c =
      ConsumerBuffer::Import(p->CreateConsumer());
  ASSERT_TRUE(c.get() != nullptr);

  LocalHandle epoll_fd{epoll_create1(EPOLL_CLOEXEC)};
@@ -177,15 +177,15 @@ TEST_F(LibBufferHubTest, TestEpoll) {
}

TEST_F(LibBufferHubTest, TestStateMask) {
  std::unique_ptr<BufferProducer> p = BufferProducer::Create(
  std::unique_ptr<ProducerBuffer> p = ProducerBuffer::Create(
      kWidth, kHeight, kFormat, kUsage, sizeof(uint64_t));
  ASSERT_TRUE(p.get() != nullptr);

  // It's ok to create up to kMaxConsumerCount consumer buffers.
  uint64_t buffer_state_bits = p->buffer_state_bit();
  std::array<std::unique_ptr<BufferConsumer>, kMaxConsumerCount> cs;
  std::array<std::unique_ptr<ConsumerBuffer>, kMaxConsumerCount> cs;
  for (size_t i = 0; i < kMaxConsumerCount; i++) {
    cs[i] = BufferConsumer::Import(p->CreateConsumer());
    cs[i] = ConsumerBuffer::Import(p->CreateConsumer());
    ASSERT_TRUE(cs[i].get() != nullptr);
    // Expect all buffers have unique state mask.
    EXPECT_EQ(buffer_state_bits & cs[i]->buffer_state_bit(), 0U);
@@ -201,7 +201,7 @@ TEST_F(LibBufferHubTest, TestStateMask) {
  for (size_t i = 0; i < kMaxConsumerCount; i++) {
    buffer_state_bits &= ~cs[i]->buffer_state_bit();
    cs[i] = nullptr;
    cs[i] = BufferConsumer::Import(p->CreateConsumer());
    cs[i] = ConsumerBuffer::Import(p->CreateConsumer());
    ASSERT_TRUE(cs[i].get() != nullptr);
    // The released state mask will be reused.
    EXPECT_EQ(buffer_state_bits & cs[i]->buffer_state_bit(), 0U);
@@ -211,11 +211,11 @@ TEST_F(LibBufferHubTest, TestStateMask) {
}

TEST_F(LibBufferHubTest, TestStateTransitions) {
  std::unique_ptr<BufferProducer> p = BufferProducer::Create(
  std::unique_ptr<ProducerBuffer> p = ProducerBuffer::Create(
      kWidth, kHeight, kFormat, kUsage, sizeof(uint64_t));
  ASSERT_TRUE(p.get() != nullptr);
  std::unique_ptr<BufferConsumer> c =
      BufferConsumer::Import(p->CreateConsumer());
  std::unique_ptr<ConsumerBuffer> c =
      ConsumerBuffer::Import(p->CreateConsumer());
  ASSERT_TRUE(c.get() != nullptr);

  uint64_t context;
@@ -263,11 +263,11 @@ TEST_F(LibBufferHubTest, TestStateTransitions) {
}

TEST_F(LibBufferHubTest, TestAsyncStateTransitions) {
  std::unique_ptr<BufferProducer> p = BufferProducer::Create(
  std::unique_ptr<ProducerBuffer> p = ProducerBuffer::Create(
      kWidth, kHeight, kFormat, kUsage, sizeof(uint64_t));
  ASSERT_TRUE(p.get() != nullptr);
  std::unique_ptr<BufferConsumer> c =
      BufferConsumer::Import(p->CreateConsumer());
  std::unique_ptr<ConsumerBuffer> c =
      ConsumerBuffer::Import(p->CreateConsumer());
  ASSERT_TRUE(c.get() != nullptr);

  DvrNativeBufferMetadata metadata;
@@ -334,7 +334,7 @@ TEST_F(LibBufferHubTest, TestAsyncStateTransitions) {
}

TEST_F(LibBufferHubTest, TestZeroConsumer) {
  std::unique_ptr<BufferProducer> p = BufferProducer::Create(
  std::unique_ptr<ProducerBuffer> p = ProducerBuffer::Create(
      kWidth, kHeight, kFormat, kUsage, sizeof(uint64_t));
  ASSERT_TRUE(p.get() != nullptr);

@@ -350,21 +350,21 @@ TEST_F(LibBufferHubTest, TestZeroConsumer) {
  EXPECT_GE(0, RETRY_EINTR(p->Poll(kPollTimeoutMs)));

  // A new consumer should still be able to acquire the buffer immediately.
  std::unique_ptr<BufferConsumer> c =
      BufferConsumer::Import(p->CreateConsumer());
  std::unique_ptr<ConsumerBuffer> c =
      ConsumerBuffer::Import(p->CreateConsumer());
  ASSERT_TRUE(c.get() != nullptr);
  EXPECT_EQ(0, c->AcquireAsync(&metadata, &invalid_fence));
  EXPECT_TRUE(IsBufferAcquired(c->buffer_state()));
}

TEST_F(LibBufferHubTest, TestMaxConsumers) {
  std::unique_ptr<BufferProducer> p = BufferProducer::Create(
  std::unique_ptr<ProducerBuffer> p = ProducerBuffer::Create(
      kWidth, kHeight, kFormat, kUsage, sizeof(uint64_t));
  ASSERT_TRUE(p.get() != nullptr);

  std::array<std::unique_ptr<BufferConsumer>, kMaxConsumerCount> cs;
  std::array<std::unique_ptr<ConsumerBuffer>, kMaxConsumerCount> cs;
  for (size_t i = 0; i < kMaxConsumerCount; i++) {
    cs[i] = BufferConsumer::Import(p->CreateConsumer());
    cs[i] = ConsumerBuffer::Import(p->CreateConsumer());
    ASSERT_TRUE(cs[i].get() != nullptr);
    EXPECT_TRUE(IsBufferGained(cs[i]->buffer_state()));
  }
@@ -400,13 +400,13 @@ TEST_F(LibBufferHubTest, TestMaxConsumers) {
}

TEST_F(LibBufferHubTest, TestCreateConsumerWhenBufferGained) {
  std::unique_ptr<BufferProducer> p = BufferProducer::Create(
  std::unique_ptr<ProducerBuffer> p = ProducerBuffer::Create(
      kWidth, kHeight, kFormat, kUsage, sizeof(uint64_t));
  ASSERT_TRUE(p.get() != nullptr);
  EXPECT_TRUE(IsBufferGained(p->buffer_state()));

  std::unique_ptr<BufferConsumer> c =
      BufferConsumer::Import(p->CreateConsumer());
  std::unique_ptr<ConsumerBuffer> c =
      ConsumerBuffer::Import(p->CreateConsumer());
  ASSERT_TRUE(c.get() != nullptr);
  EXPECT_TRUE(IsBufferGained(c->buffer_state()));

@@ -422,7 +422,7 @@ TEST_F(LibBufferHubTest, TestCreateConsumerWhenBufferGained) {
}

TEST_F(LibBufferHubTest, TestCreateConsumerWhenBufferPosted) {
  std::unique_ptr<BufferProducer> p = BufferProducer::Create(
  std::unique_ptr<ProducerBuffer> p = ProducerBuffer::Create(
      kWidth, kHeight, kFormat, kUsage, sizeof(uint64_t));
  ASSERT_TRUE(p.get() != nullptr);
  EXPECT_TRUE(IsBufferGained(p->buffer_state()));
@@ -435,8 +435,8 @@ TEST_F(LibBufferHubTest, TestCreateConsumerWhenBufferPosted) {
  EXPECT_TRUE(IsBufferPosted(p->buffer_state()));

  // Newly created consumer should be automatically sigalled.
  std::unique_ptr<BufferConsumer> c =
      BufferConsumer::Import(p->CreateConsumer());
  std::unique_ptr<ConsumerBuffer> c =
      ConsumerBuffer::Import(p->CreateConsumer());
  ASSERT_TRUE(c.get() != nullptr);
  EXPECT_TRUE(IsBufferPosted(c->buffer_state()));
  EXPECT_EQ(0, c->AcquireAsync(&metadata, &invalid_fence));
@@ -444,12 +444,12 @@ TEST_F(LibBufferHubTest, TestCreateConsumerWhenBufferPosted) {
}

TEST_F(LibBufferHubTest, TestCreateConsumerWhenBufferReleased) {
  std::unique_ptr<BufferProducer> p = BufferProducer::Create(
  std::unique_ptr<ProducerBuffer> p = ProducerBuffer::Create(
      kWidth, kHeight, kFormat, kUsage, sizeof(uint64_t));
  ASSERT_TRUE(p.get() != nullptr);

  std::unique_ptr<BufferConsumer> c1 =
      BufferConsumer::Import(p->CreateConsumer());
  std::unique_ptr<ConsumerBuffer> c1 =
      ConsumerBuffer::Import(p->CreateConsumer());
  ASSERT_TRUE(c1.get() != nullptr);

  DvrNativeBufferMetadata metadata;
@@ -470,8 +470,8 @@ TEST_F(LibBufferHubTest, TestCreateConsumerWhenBufferReleased) {

  // Create another consumer immediately after the release, should not make the
  // buffer un-released.
  std::unique_ptr<BufferConsumer> c2 =
      BufferConsumer::Import(p->CreateConsumer());
  std::unique_ptr<ConsumerBuffer> c2 =
      ConsumerBuffer::Import(p->CreateConsumer());
  ASSERT_TRUE(c2.get() != nullptr);

  EXPECT_TRUE(IsBufferReleased(p->buffer_state()));
@@ -484,11 +484,11 @@ TEST_F(LibBufferHubTest, TestWithCustomMetadata) {
    int64_t field1;
    int64_t field2;
  };
  std::unique_ptr<BufferProducer> p = BufferProducer::Create(
  std::unique_ptr<ProducerBuffer> p = ProducerBuffer::Create(
      kWidth, kHeight, kFormat, kUsage, sizeof(Metadata));
  ASSERT_TRUE(p.get() != nullptr);
  std::unique_ptr<BufferConsumer> c =
      BufferConsumer::Import(p->CreateConsumer());
  std::unique_ptr<ConsumerBuffer> c =
      ConsumerBuffer::Import(p->CreateConsumer());
  ASSERT_TRUE(c.get() != nullptr);

  Metadata m = {1, 3};
@@ -515,11 +515,11 @@ TEST_F(LibBufferHubTest, TestPostWithWrongMetaSize) {
    int64_t field2;
    int64_t field3;
  };
  std::unique_ptr<BufferProducer> p = BufferProducer::Create(
  std::unique_ptr<ProducerBuffer> p = ProducerBuffer::Create(
      kWidth, kHeight, kFormat, kUsage, sizeof(Metadata));
  ASSERT_TRUE(p.get() != nullptr);
  std::unique_ptr<BufferConsumer> c =
      BufferConsumer::Import(p->CreateConsumer());
  std::unique_ptr<ConsumerBuffer> c =
      ConsumerBuffer::Import(p->CreateConsumer());
  ASSERT_TRUE(c.get() != nullptr);

  // It is illegal to post metadata larger than originally requested during
@@ -544,11 +544,11 @@ TEST_F(LibBufferHubTest, TestAcquireWithWrongMetaSize) {
    int64_t field2;
    int64_t field3;
  };
  std::unique_ptr<BufferProducer> p = BufferProducer::Create(
  std::unique_ptr<ProducerBuffer> p = ProducerBuffer::Create(
      kWidth, kHeight, kFormat, kUsage, sizeof(Metadata));
  ASSERT_TRUE(p.get() != nullptr);
  std::unique_ptr<BufferConsumer> c =
      BufferConsumer::Import(p->CreateConsumer());
  std::unique_ptr<ConsumerBuffer> c =
      ConsumerBuffer::Import(p->CreateConsumer());
  ASSERT_TRUE(c.get() != nullptr);

  Metadata m = {1, 3};
@@ -569,11 +569,11 @@ TEST_F(LibBufferHubTest, TestAcquireWithWrongMetaSize) {
}

TEST_F(LibBufferHubTest, TestAcquireWithNoMeta) {
  std::unique_ptr<BufferProducer> p = BufferProducer::Create(
  std::unique_ptr<ProducerBuffer> p = ProducerBuffer::Create(
      kWidth, kHeight, kFormat, kUsage, sizeof(uint64_t));
  ASSERT_TRUE(p.get() != nullptr);
  std::unique_ptr<BufferConsumer> c =
      BufferConsumer::Import(p->CreateConsumer());
  std::unique_ptr<ConsumerBuffer> c =
      ConsumerBuffer::Import(p->CreateConsumer());
  ASSERT_TRUE(c.get() != nullptr);

  int64_t sequence = 3;
@@ -584,11 +584,11 @@ TEST_F(LibBufferHubTest, TestAcquireWithNoMeta) {
}

TEST_F(LibBufferHubTest, TestWithNoMeta) {
  std::unique_ptr<BufferProducer> p =
      BufferProducer::Create(kWidth, kHeight, kFormat, kUsage);
  std::unique_ptr<ProducerBuffer> p =
      ProducerBuffer::Create(kWidth, kHeight, kFormat, kUsage);
  ASSERT_TRUE(p.get() != nullptr);
  std::unique_ptr<BufferConsumer> c =
      BufferConsumer::Import(p->CreateConsumer());
  std::unique_ptr<ConsumerBuffer> c =
      ConsumerBuffer::Import(p->CreateConsumer());
  ASSERT_TRUE(c.get() != nullptr);

  LocalHandle fence;
@@ -598,11 +598,11 @@ TEST_F(LibBufferHubTest, TestWithNoMeta) {
}

TEST_F(LibBufferHubTest, TestFailureToPostMetaFromABufferWithoutMeta) {
  std::unique_ptr<BufferProducer> p =
      BufferProducer::Create(kWidth, kHeight, kFormat, kUsage);
  std::unique_ptr<ProducerBuffer> p =
      ProducerBuffer::Create(kWidth, kHeight, kFormat, kUsage);
  ASSERT_TRUE(p.get() != nullptr);
  std::unique_ptr<BufferConsumer> c =
      BufferConsumer::Import(p->CreateConsumer());
  std::unique_ptr<ConsumerBuffer> c =
      ConsumerBuffer::Import(p->CreateConsumer());
  ASSERT_TRUE(c.get() != nullptr);

  int64_t sequence = 3;
@@ -619,11 +619,11 @@ int PollFd(int fd, int timeout_ms) {
}  // namespace

TEST_F(LibBufferHubTest, TestAcquireFence) {
  std::unique_ptr<BufferProducer> p = BufferProducer::Create(
  std::unique_ptr<ProducerBuffer> p = ProducerBuffer::Create(
      kWidth, kHeight, kFormat, kUsage, /*metadata_size=*/0);
  ASSERT_TRUE(p.get() != nullptr);
  std::unique_ptr<BufferConsumer> c =
      BufferConsumer::Import(p->CreateConsumer());
  std::unique_ptr<ConsumerBuffer> c =
      ConsumerBuffer::Import(p->CreateConsumer());
  ASSERT_TRUE(c.get() != nullptr);

  DvrNativeBufferMetadata meta;
@@ -680,11 +680,11 @@ TEST_F(LibBufferHubTest, TestAcquireFence) {
}

TEST_F(LibBufferHubTest, TestOrphanedAcquire) {
  std::unique_ptr<BufferProducer> p = BufferProducer::Create(
  std::unique_ptr<ProducerBuffer> p = ProducerBuffer::Create(
      kWidth, kHeight, kFormat, kUsage, sizeof(uint64_t));
  ASSERT_TRUE(p.get() != nullptr);
  std::unique_ptr<BufferConsumer> c1 =
      BufferConsumer::Import(p->CreateConsumer());
  std::unique_ptr<ConsumerBuffer> c1 =
      ConsumerBuffer::Import(p->CreateConsumer());
  ASSERT_TRUE(c1.get() != nullptr);
  const uint64_t consumer_state_bit1 = c1->buffer_state_bit();

@@ -699,8 +699,8 @@ TEST_F(LibBufferHubTest, TestOrphanedAcquire) {
  c1 = nullptr;
  EXPECT_GE(0, RETRY_EINTR(p->Poll(kPollTimeoutMs)));

  std::unique_ptr<BufferConsumer> c2 =
      BufferConsumer::Import(p->CreateConsumer());
  std::unique_ptr<ConsumerBuffer> c2 =
      ConsumerBuffer::Import(p->CreateConsumer());
  ASSERT_TRUE(c2.get() != nullptr);
  const uint64_t consumer_state_bit2 = c2->buffer_state_bit();
  EXPECT_NE(consumer_state_bit1, consumer_state_bit2);
@@ -715,8 +715,8 @@ TEST_F(LibBufferHubTest, TestOrphanedAcquire) {
  EXPECT_LT(0, RETRY_EINTR(p->Poll(kPollTimeoutMs)));

  // But if another consumer is created in released state.
  std::unique_ptr<BufferConsumer> c3 =
      BufferConsumer::Import(p->CreateConsumer());
  std::unique_ptr<ConsumerBuffer> c3 =
      ConsumerBuffer::Import(p->CreateConsumer());
  ASSERT_TRUE(c3.get() != nullptr);
  const uint64_t consumer_state_bit3 = c3->buffer_state_bit();
  EXPECT_NE(consumer_state_bit2, consumer_state_bit3);
@@ -732,10 +732,10 @@ TEST_F(LibBufferHubTest, TestDetachBufferFromProducer) {
  // TODO(b/112338294) rewrite test after migration
  return;

  std::unique_ptr<BufferProducer> p = BufferProducer::Create(
  std::unique_ptr<ProducerBuffer> p = ProducerBuffer::Create(
      kWidth, kHeight, kFormat, kUsage, sizeof(uint64_t));
  std::unique_ptr<BufferConsumer> c =
      BufferConsumer::Import(p->CreateConsumer());
  std::unique_ptr<ConsumerBuffer> c =
      ConsumerBuffer::Import(p->CreateConsumer());
  ASSERT_TRUE(p.get() != nullptr);
  ASSERT_TRUE(c.get() != nullptr);

@@ -862,7 +862,7 @@ TEST_F(LibBufferHubTest, TestPromoteDetachedBuffer) {
  LocalChannelHandle h1 = status_or_handle.take();
  EXPECT_TRUE(h1.valid());

  std::unique_ptr<BufferProducer> p1 = BufferProducer::Import(std::move(h1));
  std::unique_ptr<ProducerBuffer> p1 = ProducerBuffer::Import(std::move(h1));
  EXPECT_FALSE(h1.valid());
  ASSERT_TRUE(p1 != nullptr);
  int p1_id = p1->id();
@@ -876,7 +876,7 @@ TEST_F(LibBufferHubTest, TestDetachThenPromote) {
  // TODO(b/112338294) rewrite test after migration
  return;

  std::unique_ptr<BufferProducer> p1 = BufferProducer::Create(
  std::unique_ptr<ProducerBuffer> p1 = ProducerBuffer::Create(
      kWidth, kHeight, kFormat, kUsage, sizeof(uint64_t));
  ASSERT_TRUE(p1.get() != nullptr);
  int p1_id = p1->id();
@@ -905,7 +905,7 @@ TEST_F(LibBufferHubTest, TestDetachThenPromote) {
  LocalChannelHandle h2 = status_or_handle.take();
  EXPECT_TRUE(h2.valid());

  std::unique_ptr<BufferProducer> p2 = BufferProducer::Import(std::move(h2));
  std::unique_ptr<ProducerBuffer> p2 = ProducerBuffer::Import(std::move(h2));
  EXPECT_FALSE(h2.valid());
  ASSERT_TRUE(p2 != nullptr);
  int p2_id = p2->id();
+3 −1
Original line number Diff line number Diff line
@@ -529,7 +529,7 @@ static void* load_angle(const char* kind, egl_connection_t* cnx) {
        property_get("ro.product.model", model, "UNSET");
        ANGLEPreference app_preference = getAnglePref(android_getAngleAppPref());

        so = load_angle_from_namespace("GLESv2", ns);
        so = load_angle_from_namespace("feature_support", ns);
        if (so) {
            ALOGV("Temporarily loaded ANGLE's opt-in/out logic from namespace");
            fpANGLEUseForApplication fp =
@@ -538,6 +538,8 @@ static void* load_angle(const char* kind, egl_connection_t* cnx) {
                use_angle = (fp)(app_name_str.c_str(), manufacturer, model, developer_option,
                                 app_preference);
                ALOGV("Result of opt-in/out logic is %s", use_angle ? "true" : "false");
            } else {
                ALOGW("Cannot find ANGLEUseForApplication in library");
            }

            ALOGV("Close temporarily-loaded ANGLE opt-in/out logic");
Loading