2012-08-31 22:32:45 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOG_TAG "BufferQueue_test"
|
|
|
|
//#define LOG_NDEBUG 0
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include <utils/String8.h>
|
|
|
|
#include <utils/threads.h>
|
|
|
|
|
|
|
|
#include <ui/GraphicBuffer.h>
|
|
|
|
|
2014-03-20 22:36:31 +00:00
|
|
|
#include <binder/IPCThreadState.h>
|
2014-03-06 23:14:33 +00:00
|
|
|
#include <binder/IServiceManager.h>
|
2014-03-20 22:36:31 +00:00
|
|
|
#include <binder/ProcessState.h>
|
2012-08-31 22:32:45 +00:00
|
|
|
#include <gui/BufferQueue.h>
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
|
|
|
class BufferQueueTest : public ::testing::Test {
|
|
|
|
|
2014-03-06 23:14:33 +00:00
|
|
|
public:
|
|
|
|
protected:
|
|
|
|
BufferQueueTest() {
|
2012-08-31 22:32:45 +00:00
|
|
|
const ::testing::TestInfo* const testInfo =
|
|
|
|
::testing::UnitTest::GetInstance()->current_test_info();
|
|
|
|
ALOGV("Begin test: %s.%s", testInfo->test_case_name(),
|
|
|
|
testInfo->name());
|
|
|
|
}
|
|
|
|
|
2014-03-06 23:14:33 +00:00
|
|
|
~BufferQueueTest() {
|
2012-08-31 22:32:45 +00:00
|
|
|
const ::testing::TestInfo* const testInfo =
|
|
|
|
::testing::UnitTest::GetInstance()->current_test_info();
|
|
|
|
ALOGV("End test: %s.%s", testInfo->test_case_name(),
|
|
|
|
testInfo->name());
|
|
|
|
}
|
|
|
|
|
2013-11-19 00:58:36 +00:00
|
|
|
void GetMinUndequeuedBufferCount(int* bufferCount) {
|
2014-03-06 23:14:33 +00:00
|
|
|
ASSERT_TRUE(bufferCount != NULL);
|
|
|
|
ASSERT_EQ(OK, mProducer->query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS,
|
|
|
|
bufferCount));
|
|
|
|
ASSERT_GE(*bufferCount, 0);
|
2013-11-19 00:58:36 +00:00
|
|
|
}
|
|
|
|
|
2014-03-20 22:36:31 +00:00
|
|
|
void createBufferQueue() {
|
|
|
|
BufferQueue::createBufferQueue(&mProducer, &mConsumer);
|
|
|
|
}
|
2012-08-31 22:32:45 +00:00
|
|
|
|
2014-03-20 22:36:31 +00:00
|
|
|
sp<IGraphicBufferProducer> mProducer;
|
|
|
|
sp<IGraphicBufferConsumer> mConsumer;
|
|
|
|
};
|
2014-03-06 23:14:33 +00:00
|
|
|
|
2013-08-01 03:09:53 +00:00
|
|
|
struct DummyConsumer : public BnConsumerListener {
|
2012-08-31 22:32:45 +00:00
|
|
|
virtual void onFrameAvailable() {}
|
|
|
|
virtual void onBuffersReleased() {}
|
2014-03-13 22:09:17 +00:00
|
|
|
virtual void onSidebandStreamChanged() {}
|
2012-08-31 22:32:45 +00:00
|
|
|
};
|
|
|
|
|
2014-03-20 22:36:31 +00:00
|
|
|
// XXX: Tests that fork a process to hold the BufferQueue must run before tests
|
|
|
|
// that use a local BufferQueue, or else Binder will get unhappy
|
|
|
|
TEST_F(BufferQueueTest, BufferQueueInAnotherProcess) {
|
|
|
|
const String16 PRODUCER_NAME = String16("BQTestProducer");
|
|
|
|
const String16 CONSUMER_NAME = String16("BQTestConsumer");
|
|
|
|
|
|
|
|
pid_t forkPid = fork();
|
|
|
|
ASSERT_NE(forkPid, -1);
|
|
|
|
|
|
|
|
if (forkPid == 0) {
|
|
|
|
// Child process
|
2014-04-07 23:33:59 +00:00
|
|
|
sp<IGraphicBufferProducer> producer;
|
|
|
|
sp<IGraphicBufferConsumer> consumer;
|
2014-03-20 22:36:31 +00:00
|
|
|
BufferQueue::createBufferQueue(&producer, &consumer);
|
|
|
|
sp<IServiceManager> serviceManager = defaultServiceManager();
|
2014-04-07 23:33:59 +00:00
|
|
|
serviceManager->addService(PRODUCER_NAME, producer->asBinder());
|
|
|
|
serviceManager->addService(CONSUMER_NAME, consumer->asBinder());
|
2014-03-20 22:36:31 +00:00
|
|
|
ProcessState::self()->startThreadPool();
|
|
|
|
IPCThreadState::self()->joinThreadPool();
|
|
|
|
LOG_ALWAYS_FATAL("Shouldn't be here");
|
|
|
|
}
|
|
|
|
|
|
|
|
sp<IServiceManager> serviceManager = defaultServiceManager();
|
|
|
|
sp<IBinder> binderProducer =
|
|
|
|
serviceManager->getService(PRODUCER_NAME);
|
|
|
|
mProducer = interface_cast<IGraphicBufferProducer>(binderProducer);
|
|
|
|
EXPECT_TRUE(mProducer != NULL);
|
|
|
|
sp<IBinder> binderConsumer =
|
|
|
|
serviceManager->getService(CONSUMER_NAME);
|
|
|
|
mConsumer = interface_cast<IGraphicBufferConsumer>(binderConsumer);
|
|
|
|
EXPECT_TRUE(mConsumer != NULL);
|
|
|
|
|
|
|
|
sp<DummyConsumer> dc(new DummyConsumer);
|
|
|
|
ASSERT_EQ(OK, mConsumer->consumerConnect(dc, false));
|
|
|
|
IGraphicBufferProducer::QueueBufferOutput output;
|
|
|
|
ASSERT_EQ(OK,
|
|
|
|
mProducer->connect(NULL, NATIVE_WINDOW_API_CPU, false, &output));
|
|
|
|
|
|
|
|
int slot;
|
|
|
|
sp<Fence> fence;
|
|
|
|
sp<GraphicBuffer> buffer;
|
|
|
|
ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION,
|
|
|
|
mProducer->dequeueBuffer(&slot, &fence, false, 0, 0, 0,
|
|
|
|
GRALLOC_USAGE_SW_WRITE_OFTEN));
|
|
|
|
ASSERT_EQ(OK, mProducer->requestBuffer(slot, &buffer));
|
|
|
|
|
|
|
|
uint32_t* dataIn;
|
|
|
|
ASSERT_EQ(OK, buffer->lock(GraphicBuffer::USAGE_SW_WRITE_OFTEN,
|
|
|
|
reinterpret_cast<void**>(&dataIn)));
|
|
|
|
*dataIn = 0x12345678;
|
|
|
|
ASSERT_EQ(OK, buffer->unlock());
|
|
|
|
|
|
|
|
IGraphicBufferProducer::QueueBufferInput input(0, false, Rect(0, 0, 1, 1),
|
|
|
|
NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, false, Fence::NO_FENCE);
|
|
|
|
ASSERT_EQ(OK, mProducer->queueBuffer(slot, input, &output));
|
|
|
|
|
|
|
|
IGraphicBufferConsumer::BufferItem item;
|
|
|
|
ASSERT_EQ(OK, mConsumer->acquireBuffer(&item, 0));
|
|
|
|
|
|
|
|
uint32_t* dataOut;
|
|
|
|
ASSERT_EQ(OK, item.mGraphicBuffer->lock(GraphicBuffer::USAGE_SW_READ_OFTEN,
|
|
|
|
reinterpret_cast<void**>(&dataOut)));
|
|
|
|
ASSERT_EQ(*dataOut, 0x12345678);
|
|
|
|
ASSERT_EQ(OK, item.mGraphicBuffer->unlock());
|
|
|
|
}
|
|
|
|
|
2012-08-31 22:32:45 +00:00
|
|
|
TEST_F(BufferQueueTest, AcquireBuffer_ExceedsMaxAcquireCount_Fails) {
|
2014-03-20 22:36:31 +00:00
|
|
|
createBufferQueue();
|
2012-08-31 22:32:45 +00:00
|
|
|
sp<DummyConsumer> dc(new DummyConsumer);
|
2014-03-06 23:14:33 +00:00
|
|
|
mConsumer->consumerConnect(dc, false);
|
2012-12-18 17:49:45 +00:00
|
|
|
IGraphicBufferProducer::QueueBufferOutput qbo;
|
2014-03-06 23:14:33 +00:00
|
|
|
mProducer->connect(NULL, NATIVE_WINDOW_API_CPU, false, &qbo);
|
|
|
|
mProducer->setBufferCount(4);
|
2012-08-31 22:32:45 +00:00
|
|
|
|
|
|
|
int slot;
|
|
|
|
sp<Fence> fence;
|
|
|
|
sp<GraphicBuffer> buf;
|
2013-08-19 15:56:07 +00:00
|
|
|
IGraphicBufferProducer::QueueBufferInput qbi(0, false, Rect(0, 0, 1, 1),
|
2013-07-19 05:10:56 +00:00
|
|
|
NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, false, Fence::NO_FENCE);
|
2012-08-31 22:32:45 +00:00
|
|
|
BufferQueue::BufferItem item;
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++) {
|
2012-12-18 17:49:45 +00:00
|
|
|
ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION,
|
2014-03-06 23:14:33 +00:00
|
|
|
mProducer->dequeueBuffer(&slot, &fence, false, 1, 1, 0,
|
2012-08-31 22:32:45 +00:00
|
|
|
GRALLOC_USAGE_SW_READ_OFTEN));
|
2014-03-06 23:14:33 +00:00
|
|
|
ASSERT_EQ(OK, mProducer->requestBuffer(slot, &buf));
|
|
|
|
ASSERT_EQ(OK, mProducer->queueBuffer(slot, qbi, &qbo));
|
|
|
|
ASSERT_EQ(OK, mConsumer->acquireBuffer(&item, 0));
|
2012-08-31 22:32:45 +00:00
|
|
|
}
|
|
|
|
|
2012-12-18 17:49:45 +00:00
|
|
|
ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION,
|
2014-03-06 23:14:33 +00:00
|
|
|
mProducer->dequeueBuffer(&slot, &fence, false, 1, 1, 0,
|
2012-08-31 22:32:45 +00:00
|
|
|
GRALLOC_USAGE_SW_READ_OFTEN));
|
2014-03-06 23:14:33 +00:00
|
|
|
ASSERT_EQ(OK, mProducer->requestBuffer(slot, &buf));
|
|
|
|
ASSERT_EQ(OK, mProducer->queueBuffer(slot, qbi, &qbo));
|
2012-08-31 22:32:45 +00:00
|
|
|
|
|
|
|
// Acquire the third buffer, which should fail.
|
2014-03-06 23:14:33 +00:00
|
|
|
ASSERT_EQ(INVALID_OPERATION, mConsumer->acquireBuffer(&item, 0));
|
2012-08-31 22:32:45 +00:00
|
|
|
}
|
|
|
|
|
2012-08-31 01:36:22 +00:00
|
|
|
TEST_F(BufferQueueTest, SetMaxAcquiredBufferCountWithIllegalValues_ReturnsError) {
|
2014-03-20 22:36:31 +00:00
|
|
|
createBufferQueue();
|
2012-08-31 01:36:22 +00:00
|
|
|
sp<DummyConsumer> dc(new DummyConsumer);
|
2014-03-06 23:14:33 +00:00
|
|
|
mConsumer->consumerConnect(dc, false);
|
2012-08-31 01:36:22 +00:00
|
|
|
|
2013-11-19 00:58:36 +00:00
|
|
|
int minBufferCount;
|
|
|
|
ASSERT_NO_FATAL_FAILURE(GetMinUndequeuedBufferCount(&minBufferCount));
|
2014-03-06 23:14:33 +00:00
|
|
|
EXPECT_EQ(BAD_VALUE, mConsumer->setMaxAcquiredBufferCount(
|
|
|
|
minBufferCount - 1));
|
2013-11-19 00:58:36 +00:00
|
|
|
|
2014-03-06 23:14:33 +00:00
|
|
|
EXPECT_EQ(BAD_VALUE, mConsumer->setMaxAcquiredBufferCount(0));
|
|
|
|
EXPECT_EQ(BAD_VALUE, mConsumer->setMaxAcquiredBufferCount(-3));
|
|
|
|
EXPECT_EQ(BAD_VALUE, mConsumer->setMaxAcquiredBufferCount(
|
2012-08-31 01:36:22 +00:00
|
|
|
BufferQueue::MAX_MAX_ACQUIRED_BUFFERS+1));
|
2014-03-06 23:14:33 +00:00
|
|
|
EXPECT_EQ(BAD_VALUE, mConsumer->setMaxAcquiredBufferCount(100));
|
2012-08-31 01:36:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BufferQueueTest, SetMaxAcquiredBufferCountWithLegalValues_Succeeds) {
|
2014-03-20 22:36:31 +00:00
|
|
|
createBufferQueue();
|
2012-08-31 01:36:22 +00:00
|
|
|
sp<DummyConsumer> dc(new DummyConsumer);
|
2014-03-06 23:14:33 +00:00
|
|
|
mConsumer->consumerConnect(dc, false);
|
2012-08-31 01:36:22 +00:00
|
|
|
|
2013-11-19 00:58:36 +00:00
|
|
|
int minBufferCount;
|
|
|
|
ASSERT_NO_FATAL_FAILURE(GetMinUndequeuedBufferCount(&minBufferCount));
|
|
|
|
|
2014-03-06 23:14:33 +00:00
|
|
|
EXPECT_EQ(OK, mConsumer->setMaxAcquiredBufferCount(1));
|
|
|
|
EXPECT_EQ(OK, mConsumer->setMaxAcquiredBufferCount(2));
|
|
|
|
EXPECT_EQ(OK, mConsumer->setMaxAcquiredBufferCount(minBufferCount));
|
|
|
|
EXPECT_EQ(OK, mConsumer->setMaxAcquiredBufferCount(
|
2012-08-31 01:36:22 +00:00
|
|
|
BufferQueue::MAX_MAX_ACQUIRED_BUFFERS));
|
|
|
|
}
|
|
|
|
|
2014-03-06 23:14:33 +00:00
|
|
|
TEST_F(BufferQueueTest, DetachAndReattachOnProducerSide) {
|
2014-03-20 22:36:31 +00:00
|
|
|
createBufferQueue();
|
2014-03-06 23:14:33 +00:00
|
|
|
sp<DummyConsumer> dc(new DummyConsumer);
|
|
|
|
ASSERT_EQ(OK, mConsumer->consumerConnect(dc, false));
|
|
|
|
IGraphicBufferProducer::QueueBufferOutput output;
|
|
|
|
ASSERT_EQ(OK,
|
|
|
|
mProducer->connect(NULL, NATIVE_WINDOW_API_CPU, false, &output));
|
|
|
|
|
|
|
|
ASSERT_EQ(BAD_VALUE, mProducer->detachBuffer(-1)); // Index too low
|
|
|
|
ASSERT_EQ(BAD_VALUE, mProducer->detachBuffer(
|
|
|
|
BufferQueueDefs::NUM_BUFFER_SLOTS)); // Index too high
|
|
|
|
ASSERT_EQ(BAD_VALUE, mProducer->detachBuffer(0)); // Not dequeued
|
|
|
|
|
|
|
|
int slot;
|
|
|
|
sp<Fence> fence;
|
|
|
|
sp<GraphicBuffer> buffer;
|
|
|
|
ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION,
|
|
|
|
mProducer->dequeueBuffer(&slot, &fence, false, 0, 0, 0,
|
|
|
|
GRALLOC_USAGE_SW_WRITE_OFTEN));
|
|
|
|
ASSERT_EQ(BAD_VALUE, mProducer->detachBuffer(slot)); // Not requested
|
|
|
|
ASSERT_EQ(OK, mProducer->requestBuffer(slot, &buffer));
|
|
|
|
ASSERT_EQ(OK, mProducer->detachBuffer(slot));
|
|
|
|
ASSERT_EQ(BAD_VALUE, mProducer->detachBuffer(slot)); // Not dequeued
|
|
|
|
|
|
|
|
sp<GraphicBuffer> safeToClobberBuffer;
|
|
|
|
// Can no longer request buffer from this slot
|
|
|
|
ASSERT_EQ(BAD_VALUE, mProducer->requestBuffer(slot, &safeToClobberBuffer));
|
|
|
|
|
|
|
|
uint32_t* dataIn;
|
|
|
|
ASSERT_EQ(OK, buffer->lock(GraphicBuffer::USAGE_SW_WRITE_OFTEN,
|
|
|
|
reinterpret_cast<void**>(&dataIn)));
|
|
|
|
*dataIn = 0x12345678;
|
|
|
|
ASSERT_EQ(OK, buffer->unlock());
|
|
|
|
|
|
|
|
int newSlot;
|
|
|
|
ASSERT_EQ(BAD_VALUE, mProducer->attachBuffer(NULL, safeToClobberBuffer));
|
|
|
|
ASSERT_EQ(BAD_VALUE, mProducer->attachBuffer(&newSlot, NULL));
|
|
|
|
|
|
|
|
ASSERT_EQ(OK, mProducer->attachBuffer(&newSlot, buffer));
|
|
|
|
IGraphicBufferProducer::QueueBufferInput input(0, false, Rect(0, 0, 1, 1),
|
|
|
|
NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, false, Fence::NO_FENCE);
|
|
|
|
ASSERT_EQ(OK, mProducer->queueBuffer(newSlot, input, &output));
|
|
|
|
|
|
|
|
IGraphicBufferConsumer::BufferItem item;
|
|
|
|
ASSERT_EQ(OK, mConsumer->acquireBuffer(&item, static_cast<nsecs_t>(0)));
|
|
|
|
|
|
|
|
uint32_t* dataOut;
|
|
|
|
ASSERT_EQ(OK, item.mGraphicBuffer->lock(GraphicBuffer::USAGE_SW_READ_OFTEN,
|
|
|
|
reinterpret_cast<void**>(&dataOut)));
|
|
|
|
ASSERT_EQ(*dataOut, 0x12345678);
|
2014-03-20 22:36:31 +00:00
|
|
|
ASSERT_EQ(OK, item.mGraphicBuffer->unlock());
|
2014-03-06 23:14:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BufferQueueTest, DetachAndReattachOnConsumerSide) {
|
2014-03-20 22:36:31 +00:00
|
|
|
createBufferQueue();
|
2014-03-06 23:14:33 +00:00
|
|
|
sp<DummyConsumer> dc(new DummyConsumer);
|
|
|
|
ASSERT_EQ(OK, mConsumer->consumerConnect(dc, false));
|
|
|
|
IGraphicBufferProducer::QueueBufferOutput output;
|
|
|
|
ASSERT_EQ(OK,
|
|
|
|
mProducer->connect(NULL, NATIVE_WINDOW_API_CPU, false, &output));
|
|
|
|
|
|
|
|
int slot;
|
|
|
|
sp<Fence> fence;
|
|
|
|
sp<GraphicBuffer> buffer;
|
|
|
|
ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION,
|
|
|
|
mProducer->dequeueBuffer(&slot, &fence, false, 0, 0, 0,
|
|
|
|
GRALLOC_USAGE_SW_WRITE_OFTEN));
|
|
|
|
ASSERT_EQ(OK, mProducer->requestBuffer(slot, &buffer));
|
|
|
|
IGraphicBufferProducer::QueueBufferInput input(0, false, Rect(0, 0, 1, 1),
|
|
|
|
NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, false, Fence::NO_FENCE);
|
|
|
|
ASSERT_EQ(OK, mProducer->queueBuffer(slot, input, &output));
|
|
|
|
|
|
|
|
ASSERT_EQ(BAD_VALUE, mConsumer->detachBuffer(-1)); // Index too low
|
|
|
|
ASSERT_EQ(BAD_VALUE, mConsumer->detachBuffer(
|
|
|
|
BufferQueueDefs::NUM_BUFFER_SLOTS)); // Index too high
|
|
|
|
ASSERT_EQ(BAD_VALUE, mConsumer->detachBuffer(0)); // Not acquired
|
|
|
|
|
|
|
|
IGraphicBufferConsumer::BufferItem item;
|
|
|
|
ASSERT_EQ(OK, mConsumer->acquireBuffer(&item, static_cast<nsecs_t>(0)));
|
|
|
|
|
|
|
|
ASSERT_EQ(OK, mConsumer->detachBuffer(item.mBuf));
|
|
|
|
ASSERT_EQ(BAD_VALUE, mConsumer->detachBuffer(item.mBuf)); // Not acquired
|
|
|
|
|
|
|
|
uint32_t* dataIn;
|
|
|
|
ASSERT_EQ(OK, item.mGraphicBuffer->lock(
|
|
|
|
GraphicBuffer::USAGE_SW_WRITE_OFTEN,
|
|
|
|
reinterpret_cast<void**>(&dataIn)));
|
|
|
|
*dataIn = 0x12345678;
|
|
|
|
ASSERT_EQ(OK, item.mGraphicBuffer->unlock());
|
|
|
|
|
|
|
|
int newSlot;
|
|
|
|
sp<GraphicBuffer> safeToClobberBuffer;
|
|
|
|
ASSERT_EQ(BAD_VALUE, mConsumer->attachBuffer(NULL, safeToClobberBuffer));
|
|
|
|
ASSERT_EQ(BAD_VALUE, mConsumer->attachBuffer(&newSlot, NULL));
|
|
|
|
ASSERT_EQ(OK, mConsumer->attachBuffer(&newSlot, item.mGraphicBuffer));
|
|
|
|
|
|
|
|
ASSERT_EQ(OK, mConsumer->releaseBuffer(item.mBuf, 0, EGL_NO_DISPLAY,
|
|
|
|
EGL_NO_SYNC_KHR, Fence::NO_FENCE));
|
|
|
|
|
|
|
|
ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION,
|
|
|
|
mProducer->dequeueBuffer(&slot, &fence, false, 0, 0, 0,
|
|
|
|
GRALLOC_USAGE_SW_WRITE_OFTEN));
|
|
|
|
ASSERT_EQ(OK, mProducer->requestBuffer(slot, &buffer));
|
|
|
|
|
|
|
|
uint32_t* dataOut;
|
|
|
|
ASSERT_EQ(OK, buffer->lock(GraphicBuffer::USAGE_SW_READ_OFTEN,
|
|
|
|
reinterpret_cast<void**>(&dataOut)));
|
|
|
|
ASSERT_EQ(*dataOut, 0x12345678);
|
2014-03-20 22:36:31 +00:00
|
|
|
ASSERT_EQ(OK, buffer->unlock());
|
2014-03-06 23:14:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BufferQueueTest, MoveFromConsumerToProducer) {
|
2014-03-20 22:36:31 +00:00
|
|
|
createBufferQueue();
|
2014-03-06 23:14:33 +00:00
|
|
|
sp<DummyConsumer> dc(new DummyConsumer);
|
|
|
|
ASSERT_EQ(OK, mConsumer->consumerConnect(dc, false));
|
|
|
|
IGraphicBufferProducer::QueueBufferOutput output;
|
|
|
|
ASSERT_EQ(OK,
|
|
|
|
mProducer->connect(NULL, NATIVE_WINDOW_API_CPU, false, &output));
|
|
|
|
|
|
|
|
int slot;
|
|
|
|
sp<Fence> fence;
|
|
|
|
sp<GraphicBuffer> buffer;
|
|
|
|
ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION,
|
|
|
|
mProducer->dequeueBuffer(&slot, &fence, false, 0, 0, 0,
|
|
|
|
GRALLOC_USAGE_SW_WRITE_OFTEN));
|
|
|
|
ASSERT_EQ(OK, mProducer->requestBuffer(slot, &buffer));
|
|
|
|
|
|
|
|
uint32_t* dataIn;
|
|
|
|
ASSERT_EQ(OK, buffer->lock(GraphicBuffer::USAGE_SW_WRITE_OFTEN,
|
|
|
|
reinterpret_cast<void**>(&dataIn)));
|
|
|
|
*dataIn = 0x12345678;
|
|
|
|
ASSERT_EQ(OK, buffer->unlock());
|
|
|
|
|
|
|
|
IGraphicBufferProducer::QueueBufferInput input(0, false, Rect(0, 0, 1, 1),
|
|
|
|
NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, false, Fence::NO_FENCE);
|
|
|
|
ASSERT_EQ(OK, mProducer->queueBuffer(slot, input, &output));
|
|
|
|
|
|
|
|
IGraphicBufferConsumer::BufferItem item;
|
|
|
|
ASSERT_EQ(OK, mConsumer->acquireBuffer(&item, static_cast<nsecs_t>(0)));
|
|
|
|
ASSERT_EQ(OK, mConsumer->detachBuffer(item.mBuf));
|
|
|
|
|
|
|
|
int newSlot;
|
|
|
|
ASSERT_EQ(OK, mProducer->attachBuffer(&newSlot, item.mGraphicBuffer));
|
|
|
|
ASSERT_EQ(OK, mProducer->queueBuffer(newSlot, input, &output));
|
|
|
|
ASSERT_EQ(OK, mConsumer->acquireBuffer(&item, static_cast<nsecs_t>(0)));
|
|
|
|
|
|
|
|
uint32_t* dataOut;
|
|
|
|
ASSERT_EQ(OK, item.mGraphicBuffer->lock(GraphicBuffer::USAGE_SW_READ_OFTEN,
|
|
|
|
reinterpret_cast<void**>(&dataOut)));
|
|
|
|
ASSERT_EQ(*dataOut, 0x12345678);
|
2014-03-20 22:36:31 +00:00
|
|
|
ASSERT_EQ(OK, item.mGraphicBuffer->unlock());
|
2014-03-06 23:14:33 +00:00
|
|
|
}
|
|
|
|
|
2012-08-31 22:32:45 +00:00
|
|
|
} // namespace android
|