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

Commit ca14018b authored by Dan Stoza's avatar Dan Stoza Committed by Android (Google) Code Review
Browse files

Merge "libgui: Remove custom allocator from tests"

parents 6e1a9d32 3bb0c881
Loading
Loading
Loading
Loading
+22 −35
Original line number Diff line number Diff line
@@ -52,42 +52,16 @@ struct DummyListener : public BnConsumerListener {
    virtual void onSidebandStreamChanged() {}
};

class CountedAllocator : public BnGraphicBufferAlloc {
public:
    CountedAllocator() : mAllocCount(0) {
        sp<ISurfaceComposer> composer(ComposerService::getComposerService());
        mAllocator = composer->createGraphicBufferAlloc();
    }

    virtual ~CountedAllocator() {}

    virtual sp<GraphicBuffer> createGraphicBuffer(uint32_t w, uint32_t h,
            PixelFormat format, uint32_t usage, status_t* error) {
        ++mAllocCount;
        sp<GraphicBuffer> buffer = mAllocator->createGraphicBuffer(w, h, format,
                usage, error);
        return buffer;
    }

    int getAllocCount() const { return mAllocCount; }

private:
    sp<IGraphicBufferAlloc> mAllocator;
    int mAllocCount;
};

static const uint32_t TEST_DATA = 0x12345678u;

TEST_F(StreamSplitterTest, OneInputOneOutput) {
    sp<CountedAllocator> allocator(new CountedAllocator);

    sp<IGraphicBufferProducer> inputProducer;
    sp<IGraphicBufferConsumer> inputConsumer;
    BufferQueue::createBufferQueue(&inputProducer, &inputConsumer, allocator);
    BufferQueue::createBufferQueue(&inputProducer, &inputConsumer);

    sp<IGraphicBufferProducer> outputProducer;
    sp<IGraphicBufferConsumer> outputConsumer;
    BufferQueue::createBufferQueue(&outputProducer, &outputConsumer, allocator);
    BufferQueue::createBufferQueue(&outputProducer, &outputConsumer);
    ASSERT_EQ(OK, outputConsumer->consumerConnect(new DummyListener, false));

    sp<StreamSplitter> splitter;
@@ -95,6 +69,9 @@ TEST_F(StreamSplitterTest, OneInputOneOutput) {
    ASSERT_EQ(OK, status);
    ASSERT_EQ(OK, splitter->addOutput(outputProducer));

    // Never allow the output BufferQueue to allocate a buffer
    ASSERT_EQ(OK, outputProducer->allowAllocation(false));

    IGraphicBufferProducer::QueueBufferOutput qbOutput;
    ASSERT_EQ(OK, inputProducer->connect(new DummyProducerListener,
            NATIVE_WINDOW_API_CPU, false, &qbOutput));
@@ -118,6 +95,10 @@ TEST_F(StreamSplitterTest, OneInputOneOutput) {
            NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, Fence::NO_FENCE);
    ASSERT_EQ(OK, inputProducer->queueBuffer(slot, qbInput, &qbOutput));

    // Now that we have dequeued/allocated one buffer, prevent any further
    // allocations
    ASSERT_EQ(OK, inputProducer->allowAllocation(false));

    BufferItem item;
    ASSERT_EQ(OK, outputConsumer->acquireBuffer(&item, 0));

@@ -130,26 +111,25 @@ TEST_F(StreamSplitterTest, OneInputOneOutput) {
    ASSERT_EQ(OK, outputConsumer->releaseBuffer(item.mSlot, item.mFrameNumber,
            EGL_NO_DISPLAY, EGL_NO_SYNC_KHR, Fence::NO_FENCE));

    // This should succeed even with allocation disabled since it will have
    // received the buffer back from the output BufferQueue
    ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION,
            inputProducer->dequeueBuffer(&slot, &fence, 0, 0, 0,
                    GRALLOC_USAGE_SW_WRITE_OFTEN));

    ASSERT_EQ(1, allocator->getAllocCount());
}

TEST_F(StreamSplitterTest, OneInputMultipleOutputs) {
    const int NUM_OUTPUTS = 4;
    sp<CountedAllocator> allocator(new CountedAllocator);

    sp<IGraphicBufferProducer> inputProducer;
    sp<IGraphicBufferConsumer> inputConsumer;
    BufferQueue::createBufferQueue(&inputProducer, &inputConsumer, allocator);
    BufferQueue::createBufferQueue(&inputProducer, &inputConsumer);

    sp<IGraphicBufferProducer> outputProducers[NUM_OUTPUTS] = {};
    sp<IGraphicBufferConsumer> outputConsumers[NUM_OUTPUTS] = {};
    for (int output = 0; output < NUM_OUTPUTS; ++output) {
        BufferQueue::createBufferQueue(&outputProducers[output],
                &outputConsumers[output], allocator);
                &outputConsumers[output]);
        ASSERT_EQ(OK, outputConsumers[output]->consumerConnect(
                    new DummyListener, false));
    }
@@ -159,6 +139,9 @@ TEST_F(StreamSplitterTest, OneInputMultipleOutputs) {
    ASSERT_EQ(OK, status);
    for (int output = 0; output < NUM_OUTPUTS; ++output) {
        ASSERT_EQ(OK, splitter->addOutput(outputProducers[output]));

        // Never allow the output BufferQueues to allocate a buffer
        ASSERT_EQ(OK, outputProducers[output]->allowAllocation(false));
    }

    IGraphicBufferProducer::QueueBufferOutput qbOutput;
@@ -184,6 +167,10 @@ TEST_F(StreamSplitterTest, OneInputMultipleOutputs) {
            NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, Fence::NO_FENCE);
    ASSERT_EQ(OK, inputProducer->queueBuffer(slot, qbInput, &qbOutput));

    // Now that we have dequeued/allocated one buffer, prevent any further
    // allocations
    ASSERT_EQ(OK, inputProducer->allowAllocation(false));

    for (int output = 0; output < NUM_OUTPUTS; ++output) {
        BufferItem item;
        ASSERT_EQ(OK, outputConsumers[output]->acquireBuffer(&item, 0));
@@ -199,11 +186,11 @@ TEST_F(StreamSplitterTest, OneInputMultipleOutputs) {
                    Fence::NO_FENCE));
    }

    // This should succeed even with allocation disabled since it will have
    // received the buffer back from the output BufferQueues
    ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION,
            inputProducer->dequeueBuffer(&slot, &fence, 0, 0, 0,
                    GRALLOC_USAGE_SW_WRITE_OFTEN));

    ASSERT_EQ(1, allocator->getAllocCount());
}

TEST_F(StreamSplitterTest, OutputAbandonment) {