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

Commit fe603eda authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Expose mBufferId for GraphicBuffer"

parents ae745515 29160fb8
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