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

Commit 29160fb8 authored by Jiwen 'Steve' Cai's avatar Jiwen 'Steve' Cai
Browse files

Expose mBufferId for GraphicBuffer

Bug: 118844974
Test: GraphicBuffer_test
Change-Id: I75a58b21e9943ffed9219a37e0d05c6697232bf4
parent 48eead91
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ GraphicBuffer::GraphicBuffer(std::unique_ptr<BufferHubBuffer> buffer) : GraphicB
                                buffer->desc().width, buffer->desc().height,
                                static_cast<PixelFormat>(buffer->desc().format),
                                buffer->desc().layers, buffer->desc().usage, buffer->desc().stride);
    mBufferId = buffer->id();
    mBufferHubBuffer = std::move(buffer);
}
#endif // LIBUI_IN_VNDK
+7 −0
Original line number Diff line number Diff line
@@ -153,6 +153,7 @@ public:
    uint32_t getLayerCount() const      { return static_cast<uint32_t>(layerCount); }
    Rect getBounds() const              { return Rect(width, height); }
    uint64_t getId() const              { return mId; }
    int32_t getBufferId() const { return mBufferId; }

    uint32_t getGenerationNumber() const { return mGenerationNumber; }
    void setGenerationNumber(uint32_t generation) {
@@ -247,6 +248,12 @@ private:

    uint64_t mId;

    // System unique buffer ID. Note that this is different from mId, which is process unique. For
    // GraphicBuffer backed by BufferHub, the mBufferId is a system unique identifier that stays the
    // same cross process for the same chunck of underlying memory. Also note that this only applies
    // to GraphicBuffers that are backed by BufferHub.
    int32_t mBufferId = -1;

    // Stores the generation number of this buffer. If this number does not
    // match the BufferQueue's internal generation number (set through
    // IGBP::setGenerationNumber), attempts to attach the buffer will fail.
+23 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ TEST_F(GraphicBufferTest, CreateFromBufferHubBuffer) {
    std::unique_ptr<BufferHubBuffer> b1 =
            BufferHubBuffer::Create(kTestWidth, kTestHeight, kTestLayerCount, kTestFormat,
                                    kTestUsage, /*userMetadataSize=*/0);
    EXPECT_NE(b1, nullptr);
    EXPECT_TRUE(b1->IsValid());

    sp<GraphicBuffer> gb(new GraphicBuffer(std::move(b1)));
@@ -51,4 +52,26 @@ TEST_F(GraphicBufferTest, CreateFromBufferHubBuffer) {
    EXPECT_EQ(gb->getLayerCount(), kTestLayerCount);
}

TEST_F(GraphicBufferTest, InvalidBufferIdForNoneBufferHubBuffer) {
    sp<GraphicBuffer> gb(
            new GraphicBuffer(kTestWidth, kTestHeight, kTestFormat, kTestLayerCount, kTestUsage));
    EXPECT_FALSE(gb->isBufferHubBuffer());
    EXPECT_EQ(gb->getBufferId(), -1);
}

TEST_F(GraphicBufferTest, BufferIdMatchesBufferHubBufferId) {
    std::unique_ptr<BufferHubBuffer> b1 =
            BufferHubBuffer::Create(kTestWidth, kTestHeight, kTestLayerCount, kTestFormat,
                                    kTestUsage, /*userMetadataSize=*/0);
    EXPECT_NE(b1, nullptr);
    EXPECT_TRUE(b1->IsValid());

    int b1_id = b1->id();
    EXPECT_GE(b1_id, 0);

    sp<GraphicBuffer> gb(new GraphicBuffer(std::move(b1)));
    EXPECT_TRUE(gb->isBufferHubBuffer());
    EXPECT_EQ(gb->getBufferId(), b1_id);
}

} // namespace android