IGraphicBufferProducer_test.cpp revision 567dbbb6dd42be5013fcde0dadb3316d85f2fa0d
17ea777f097784492f880623067becac1b276f884Igor Murashkin/* 27ea777f097784492f880623067becac1b276f884Igor Murashkin * Copyright (C) 2013 The Android Open Source Project 37ea777f097784492f880623067becac1b276f884Igor Murashkin * 47ea777f097784492f880623067becac1b276f884Igor Murashkin * Licensed under the Apache License, Version 2.0 (the "License"); 57ea777f097784492f880623067becac1b276f884Igor Murashkin * you may not use this file except in compliance with the License. 67ea777f097784492f880623067becac1b276f884Igor Murashkin * You may obtain a copy of the License at 77ea777f097784492f880623067becac1b276f884Igor Murashkin * 87ea777f097784492f880623067becac1b276f884Igor Murashkin * http://www.apache.org/licenses/LICENSE-2.0 97ea777f097784492f880623067becac1b276f884Igor Murashkin * 107ea777f097784492f880623067becac1b276f884Igor Murashkin * Unless required by applicable law or agreed to in writing, software 117ea777f097784492f880623067becac1b276f884Igor Murashkin * distributed under the License is distributed on an "AS IS" BASIS, 127ea777f097784492f880623067becac1b276f884Igor Murashkin * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137ea777f097784492f880623067becac1b276f884Igor Murashkin * See the License for the specific language governing permissions and 147ea777f097784492f880623067becac1b276f884Igor Murashkin * limitations under the License. 157ea777f097784492f880623067becac1b276f884Igor Murashkin */ 167ea777f097784492f880623067becac1b276f884Igor Murashkin 177ea777f097784492f880623067becac1b276f884Igor Murashkin#define LOG_TAG "IGraphicBufferProducer_test" 187ea777f097784492f880623067becac1b276f884Igor Murashkin//#define LOG_NDEBUG 0 197ea777f097784492f880623067becac1b276f884Igor Murashkin 207ea777f097784492f880623067becac1b276f884Igor Murashkin#include <gtest/gtest.h> 217ea777f097784492f880623067becac1b276f884Igor Murashkin 227ea777f097784492f880623067becac1b276f884Igor Murashkin#include <utils/String8.h> 237ea777f097784492f880623067becac1b276f884Igor Murashkin#include <utils/threads.h> 247ea777f097784492f880623067becac1b276f884Igor Murashkin 257ea777f097784492f880623067becac1b276f884Igor Murashkin#include <ui/GraphicBuffer.h> 267ea777f097784492f880623067becac1b276f884Igor Murashkin 277ea777f097784492f880623067becac1b276f884Igor Murashkin#include <gui/BufferQueue.h> 28f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza#include <gui/IProducerListener.h> 297ea777f097784492f880623067becac1b276f884Igor Murashkin 307ea777f097784492f880623067becac1b276f884Igor Murashkin#include <vector> 317ea777f097784492f880623067becac1b276f884Igor Murashkin 327ea777f097784492f880623067becac1b276f884Igor Murashkin#define ASSERT_OK(x) ASSERT_EQ(OK, (x)) 337ea777f097784492f880623067becac1b276f884Igor Murashkin#define EXPECT_OK(x) EXPECT_EQ(OK, (x)) 347ea777f097784492f880623067becac1b276f884Igor Murashkin 35f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza#define TEST_TOKEN ((IProducerListener*)(NULL)) 367ea777f097784492f880623067becac1b276f884Igor Murashkin#define TEST_API NATIVE_WINDOW_API_CPU 377ea777f097784492f880623067becac1b276f884Igor Murashkin#define TEST_API_OTHER NATIVE_WINDOW_API_EGL // valid API that's not TEST_API 387ea777f097784492f880623067becac1b276f884Igor Murashkin#define TEST_CONTROLLED_BY_APP false 397ea777f097784492f880623067becac1b276f884Igor Murashkin#define TEST_PRODUCER_USAGE_BITS (0) 407ea777f097784492f880623067becac1b276f884Igor Murashkin 41f8cebe54576c8100769e2515d4f67bdd013a6927Dan Stozanamespace android { 42f8cebe54576c8100769e2515d4f67bdd013a6927Dan Stoza 43f8cebe54576c8100769e2515d4f67bdd013a6927Dan Stozanamespace { 447ea777f097784492f880623067becac1b276f884Igor Murashkin // Default dimensions before setDefaultBufferSize is called 45f8cebe54576c8100769e2515d4f67bdd013a6927Dan Stoza const uint32_t DEFAULT_WIDTH = 1; 46f8cebe54576c8100769e2515d4f67bdd013a6927Dan Stoza const uint32_t DEFAULT_HEIGHT = 1; 477ea777f097784492f880623067becac1b276f884Igor Murashkin 487ea777f097784492f880623067becac1b276f884Igor Murashkin // Default format before setDefaultBufferFormat is called 49f8cebe54576c8100769e2515d4f67bdd013a6927Dan Stoza const PixelFormat DEFAULT_FORMAT = HAL_PIXEL_FORMAT_RGBA_8888; 507ea777f097784492f880623067becac1b276f884Igor Murashkin 517ea777f097784492f880623067becac1b276f884Igor Murashkin // Default transform hint before setTransformHint is called 52f8cebe54576c8100769e2515d4f67bdd013a6927Dan Stoza const uint32_t DEFAULT_TRANSFORM_HINT = 0; 537ea777f097784492f880623067becac1b276f884Igor Murashkin 54f8cebe54576c8100769e2515d4f67bdd013a6927Dan Stoza // TODO: Make these constants in header 55f8cebe54576c8100769e2515d4f67bdd013a6927Dan Stoza const int DEFAULT_CONSUMER_USAGE_BITS = 0; 567ea777f097784492f880623067becac1b276f884Igor Murashkin 57f8cebe54576c8100769e2515d4f67bdd013a6927Dan Stoza // Parameters for a generic "valid" input for queueBuffer. 58f8cebe54576c8100769e2515d4f67bdd013a6927Dan Stoza const int64_t QUEUE_BUFFER_INPUT_TIMESTAMP = 1384888611; 59f8cebe54576c8100769e2515d4f67bdd013a6927Dan Stoza const bool QUEUE_BUFFER_INPUT_IS_AUTO_TIMESTAMP = false; 60f8cebe54576c8100769e2515d4f67bdd013a6927Dan Stoza const android_dataspace QUEUE_BUFFER_INPUT_DATASPACE = HAL_DATASPACE_UNKNOWN; 61f8cebe54576c8100769e2515d4f67bdd013a6927Dan Stoza const Rect QUEUE_BUFFER_INPUT_RECT = Rect(DEFAULT_WIDTH, DEFAULT_HEIGHT); 62f8cebe54576c8100769e2515d4f67bdd013a6927Dan Stoza const int QUEUE_BUFFER_INPUT_SCALING_MODE = 0; 63f8cebe54576c8100769e2515d4f67bdd013a6927Dan Stoza const int QUEUE_BUFFER_INPUT_TRANSFORM = 0; 64f8cebe54576c8100769e2515d4f67bdd013a6927Dan Stoza const sp<Fence> QUEUE_BUFFER_INPUT_FENCE = Fence::NO_FENCE; 657ea777f097784492f880623067becac1b276f884Igor Murashkin}; // namespace anonymous 667ea777f097784492f880623067becac1b276f884Igor Murashkin 677ea777f097784492f880623067becac1b276f884Igor Murashkinstruct DummyConsumer : public BnConsumerListener { 688dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza virtual void onFrameAvailable(const BufferItem& /* item */) {} 697ea777f097784492f880623067becac1b276f884Igor Murashkin virtual void onBuffersReleased() {} 7049bfda1fbdf828a8ea63ae2c2fa25739f6e48527Jesse Hall virtual void onSidebandStreamChanged() {} 717ea777f097784492f880623067becac1b276f884Igor Murashkin}; 727ea777f097784492f880623067becac1b276f884Igor Murashkin 737ea777f097784492f880623067becac1b276f884Igor Murashkinclass IGraphicBufferProducerTest : public ::testing::Test { 747ea777f097784492f880623067becac1b276f884Igor Murashkinprotected: 757ea777f097784492f880623067becac1b276f884Igor Murashkin 767ea777f097784492f880623067becac1b276f884Igor Murashkin IGraphicBufferProducerTest() {} 777ea777f097784492f880623067becac1b276f884Igor Murashkin 787ea777f097784492f880623067becac1b276f884Igor Murashkin virtual void SetUp() { 797ea777f097784492f880623067becac1b276f884Igor Murashkin const ::testing::TestInfo* const testInfo = 807ea777f097784492f880623067becac1b276f884Igor Murashkin ::testing::UnitTest::GetInstance()->current_test_info(); 817ea777f097784492f880623067becac1b276f884Igor Murashkin ALOGV("Begin test: %s.%s", testInfo->test_case_name(), 827ea777f097784492f880623067becac1b276f884Igor Murashkin testInfo->name()); 837ea777f097784492f880623067becac1b276f884Igor Murashkin 847ea777f097784492f880623067becac1b276f884Igor Murashkin mDC = new DummyConsumer; 857ea777f097784492f880623067becac1b276f884Igor Murashkin 865603a2fbbd1aae74c4635e2f600819fb05d112e0Dan Stoza BufferQueue::createBufferQueue(&mProducer, &mConsumer); 877ea777f097784492f880623067becac1b276f884Igor Murashkin 887ea777f097784492f880623067becac1b276f884Igor Murashkin // Test check: Can't connect producer if no consumer yet 897ea777f097784492f880623067becac1b276f884Igor Murashkin ASSERT_EQ(NO_INIT, TryConnectProducer()); 907ea777f097784492f880623067becac1b276f884Igor Murashkin 917ea777f097784492f880623067becac1b276f884Igor Murashkin // Must connect consumer before producer connects will succeed. 927ea777f097784492f880623067becac1b276f884Igor Murashkin ASSERT_OK(mConsumer->consumerConnect(mDC, /*controlledByApp*/false)); 937ea777f097784492f880623067becac1b276f884Igor Murashkin } 947ea777f097784492f880623067becac1b276f884Igor Murashkin 957ea777f097784492f880623067becac1b276f884Igor Murashkin virtual void TearDown() { 967ea777f097784492f880623067becac1b276f884Igor Murashkin const ::testing::TestInfo* const testInfo = 977ea777f097784492f880623067becac1b276f884Igor Murashkin ::testing::UnitTest::GetInstance()->current_test_info(); 987ea777f097784492f880623067becac1b276f884Igor Murashkin ALOGV("End test: %s.%s", testInfo->test_case_name(), 997ea777f097784492f880623067becac1b276f884Igor Murashkin testInfo->name()); 1007ea777f097784492f880623067becac1b276f884Igor Murashkin } 1017ea777f097784492f880623067becac1b276f884Igor Murashkin 1027ea777f097784492f880623067becac1b276f884Igor Murashkin status_t TryConnectProducer() { 1037ea777f097784492f880623067becac1b276f884Igor Murashkin IGraphicBufferProducer::QueueBufferOutput output; 1047ea777f097784492f880623067becac1b276f884Igor Murashkin return mProducer->connect(TEST_TOKEN, 1057ea777f097784492f880623067becac1b276f884Igor Murashkin TEST_API, 1067ea777f097784492f880623067becac1b276f884Igor Murashkin TEST_CONTROLLED_BY_APP, 1077ea777f097784492f880623067becac1b276f884Igor Murashkin &output); 1087ea777f097784492f880623067becac1b276f884Igor Murashkin // TODO: use params to vary token, api, producercontrolledbyapp, etc 1097ea777f097784492f880623067becac1b276f884Igor Murashkin } 1107ea777f097784492f880623067becac1b276f884Igor Murashkin 1117ea777f097784492f880623067becac1b276f884Igor Murashkin // Connect to a producer in a 'correct' fashion. 1127ea777f097784492f880623067becac1b276f884Igor Murashkin // Precondition: Consumer is connected. 1137ea777f097784492f880623067becac1b276f884Igor Murashkin void ConnectProducer() { 1147ea777f097784492f880623067becac1b276f884Igor Murashkin ASSERT_OK(TryConnectProducer()); 1157ea777f097784492f880623067becac1b276f884Igor Murashkin } 1167ea777f097784492f880623067becac1b276f884Igor Murashkin 1177ea777f097784492f880623067becac1b276f884Igor Murashkin // Create a generic "valid" input for queueBuffer 1187ea777f097784492f880623067becac1b276f884Igor Murashkin // -- uses the default buffer format, width, etc. 1197ea777f097784492f880623067becac1b276f884Igor Murashkin static IGraphicBufferProducer::QueueBufferInput CreateBufferInput() { 1207ea777f097784492f880623067becac1b276f884Igor Murashkin return QueueBufferInputBuilder().build(); 1217ea777f097784492f880623067becac1b276f884Igor Murashkin } 1227ea777f097784492f880623067becac1b276f884Igor Murashkin 1237ea777f097784492f880623067becac1b276f884Igor Murashkin // Builder pattern to slightly vary *almost* correct input 1247ea777f097784492f880623067becac1b276f884Igor Murashkin // -- avoids copying and pasting 1257ea777f097784492f880623067becac1b276f884Igor Murashkin struct QueueBufferInputBuilder { 1267ea777f097784492f880623067becac1b276f884Igor Murashkin QueueBufferInputBuilder() { 1277ea777f097784492f880623067becac1b276f884Igor Murashkin timestamp = QUEUE_BUFFER_INPUT_TIMESTAMP; 1287ea777f097784492f880623067becac1b276f884Igor Murashkin isAutoTimestamp = QUEUE_BUFFER_INPUT_IS_AUTO_TIMESTAMP; 12982c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala dataSpace = QUEUE_BUFFER_INPUT_DATASPACE; 1307ea777f097784492f880623067becac1b276f884Igor Murashkin crop = QUEUE_BUFFER_INPUT_RECT; 1317ea777f097784492f880623067becac1b276f884Igor Murashkin scalingMode = QUEUE_BUFFER_INPUT_SCALING_MODE; 1327ea777f097784492f880623067becac1b276f884Igor Murashkin transform = QUEUE_BUFFER_INPUT_TRANSFORM; 1337ea777f097784492f880623067becac1b276f884Igor Murashkin fence = QUEUE_BUFFER_INPUT_FENCE; 1347ea777f097784492f880623067becac1b276f884Igor Murashkin } 1357ea777f097784492f880623067becac1b276f884Igor Murashkin 1367ea777f097784492f880623067becac1b276f884Igor Murashkin IGraphicBufferProducer::QueueBufferInput build() { 1377ea777f097784492f880623067becac1b276f884Igor Murashkin return IGraphicBufferProducer::QueueBufferInput( 1387ea777f097784492f880623067becac1b276f884Igor Murashkin timestamp, 1397ea777f097784492f880623067becac1b276f884Igor Murashkin isAutoTimestamp, 14082c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala dataSpace, 1417ea777f097784492f880623067becac1b276f884Igor Murashkin crop, 1427ea777f097784492f880623067becac1b276f884Igor Murashkin scalingMode, 1437ea777f097784492f880623067becac1b276f884Igor Murashkin transform, 1447ea777f097784492f880623067becac1b276f884Igor Murashkin fence); 1457ea777f097784492f880623067becac1b276f884Igor Murashkin } 1467ea777f097784492f880623067becac1b276f884Igor Murashkin 1477ea777f097784492f880623067becac1b276f884Igor Murashkin QueueBufferInputBuilder& setTimestamp(int64_t timestamp) { 1487ea777f097784492f880623067becac1b276f884Igor Murashkin this->timestamp = timestamp; 1497ea777f097784492f880623067becac1b276f884Igor Murashkin return *this; 1507ea777f097784492f880623067becac1b276f884Igor Murashkin } 1517ea777f097784492f880623067becac1b276f884Igor Murashkin 1527ea777f097784492f880623067becac1b276f884Igor Murashkin QueueBufferInputBuilder& setIsAutoTimestamp(bool isAutoTimestamp) { 1537ea777f097784492f880623067becac1b276f884Igor Murashkin this->isAutoTimestamp = isAutoTimestamp; 1547ea777f097784492f880623067becac1b276f884Igor Murashkin return *this; 1557ea777f097784492f880623067becac1b276f884Igor Murashkin } 1567ea777f097784492f880623067becac1b276f884Igor Murashkin 15782c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala QueueBufferInputBuilder& setDataSpace(android_dataspace dataSpace) { 15882c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala this->dataSpace = dataSpace; 15982c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala return *this; 16082c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala } 16182c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala 1627ea777f097784492f880623067becac1b276f884Igor Murashkin QueueBufferInputBuilder& setCrop(Rect crop) { 1637ea777f097784492f880623067becac1b276f884Igor Murashkin this->crop = crop; 1647ea777f097784492f880623067becac1b276f884Igor Murashkin return *this; 1657ea777f097784492f880623067becac1b276f884Igor Murashkin } 1667ea777f097784492f880623067becac1b276f884Igor Murashkin 1677ea777f097784492f880623067becac1b276f884Igor Murashkin QueueBufferInputBuilder& setScalingMode(int scalingMode) { 1687ea777f097784492f880623067becac1b276f884Igor Murashkin this->scalingMode = scalingMode; 1697ea777f097784492f880623067becac1b276f884Igor Murashkin return *this; 1707ea777f097784492f880623067becac1b276f884Igor Murashkin } 1717ea777f097784492f880623067becac1b276f884Igor Murashkin 1727ea777f097784492f880623067becac1b276f884Igor Murashkin QueueBufferInputBuilder& setTransform(uint32_t transform) { 1737ea777f097784492f880623067becac1b276f884Igor Murashkin this->transform = transform; 1747ea777f097784492f880623067becac1b276f884Igor Murashkin return *this; 1757ea777f097784492f880623067becac1b276f884Igor Murashkin } 1767ea777f097784492f880623067becac1b276f884Igor Murashkin 1777ea777f097784492f880623067becac1b276f884Igor Murashkin QueueBufferInputBuilder& setFence(sp<Fence> fence) { 1787ea777f097784492f880623067becac1b276f884Igor Murashkin this->fence = fence; 1797ea777f097784492f880623067becac1b276f884Igor Murashkin return *this; 1807ea777f097784492f880623067becac1b276f884Igor Murashkin } 1817ea777f097784492f880623067becac1b276f884Igor Murashkin 1827ea777f097784492f880623067becac1b276f884Igor Murashkin private: 1837ea777f097784492f880623067becac1b276f884Igor Murashkin int64_t timestamp; 1847ea777f097784492f880623067becac1b276f884Igor Murashkin bool isAutoTimestamp; 18582c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala android_dataspace dataSpace; 1867ea777f097784492f880623067becac1b276f884Igor Murashkin Rect crop; 1877ea777f097784492f880623067becac1b276f884Igor Murashkin int scalingMode; 1887ea777f097784492f880623067becac1b276f884Igor Murashkin uint32_t transform; 1897ea777f097784492f880623067becac1b276f884Igor Murashkin sp<Fence> fence; 1907ea777f097784492f880623067becac1b276f884Igor Murashkin }; // struct QueueBufferInputBuilder 1917ea777f097784492f880623067becac1b276f884Igor Murashkin 1927ea777f097784492f880623067becac1b276f884Igor Murashkin // To easily store dequeueBuffer results into containers 1937ea777f097784492f880623067becac1b276f884Igor Murashkin struct DequeueBufferResult { 1947ea777f097784492f880623067becac1b276f884Igor Murashkin int slot; 1957ea777f097784492f880623067becac1b276f884Igor Murashkin sp<Fence> fence; 1967ea777f097784492f880623067becac1b276f884Igor Murashkin }; 1977ea777f097784492f880623067becac1b276f884Igor Murashkin 198567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos status_t dequeueBuffer(uint32_t w, uint32_t h, uint32_t format, uint32_t usage, DequeueBufferResult* result) { 199567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos return mProducer->dequeueBuffer(&result->slot, &result->fence, w, h, format, usage); 2007ea777f097784492f880623067becac1b276f884Igor Murashkin } 2017ea777f097784492f880623067becac1b276f884Igor Murashkin 202583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos void setupDequeueRequestBuffer(int *slot, sp<Fence> *fence, 203583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos sp<GraphicBuffer> *buffer) 204583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos { 205583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_TRUE(slot != NULL); 206583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_TRUE(fence != NULL); 207583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_TRUE(buffer != NULL); 208583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 209583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_NO_FATAL_FAILURE(ConnectProducer()); 210583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 211583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_EQ(OK, ~IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION & 212567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos (mProducer->dequeueBuffer(slot, fence, DEFAULT_WIDTH, 213567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos DEFAULT_HEIGHT, DEFAULT_FORMAT, TEST_PRODUCER_USAGE_BITS))); 214583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 215583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos EXPECT_LE(0, *slot); 216583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos EXPECT_GT(BufferQueue::NUM_BUFFER_SLOTS, *slot); 217583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 218583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos // Request the buffer (pre-requisite for queueing) 219583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_OK(mProducer->requestBuffer(*slot, buffer)); 220583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos } 221583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 2227ea777f097784492f880623067becac1b276f884Igor Murashkinprivate: // hide from test body 2237ea777f097784492f880623067becac1b276f884Igor Murashkin sp<DummyConsumer> mDC; 2247ea777f097784492f880623067becac1b276f884Igor Murashkin 2257ea777f097784492f880623067becac1b276f884Igor Murashkinprotected: // accessible from test body 2267ea777f097784492f880623067becac1b276f884Igor Murashkin sp<IGraphicBufferProducer> mProducer; 2277ea777f097784492f880623067becac1b276f884Igor Murashkin sp<IGraphicBufferConsumer> mConsumer; 2287ea777f097784492f880623067becac1b276f884Igor Murashkin}; 2297ea777f097784492f880623067becac1b276f884Igor Murashkin 2307ea777f097784492f880623067becac1b276f884Igor MurashkinTEST_F(IGraphicBufferProducerTest, ConnectFirst_ReturnsError) { 2317ea777f097784492f880623067becac1b276f884Igor Murashkin IGraphicBufferProducer::QueueBufferOutput output; 2327ea777f097784492f880623067becac1b276f884Igor Murashkin 2337ea777f097784492f880623067becac1b276f884Igor Murashkin // NULL output returns BAD_VALUE 2347ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->connect(TEST_TOKEN, 2357ea777f097784492f880623067becac1b276f884Igor Murashkin TEST_API, 2367ea777f097784492f880623067becac1b276f884Igor Murashkin TEST_CONTROLLED_BY_APP, 2377ea777f097784492f880623067becac1b276f884Igor Murashkin /*output*/NULL)); 2387ea777f097784492f880623067becac1b276f884Igor Murashkin 2397ea777f097784492f880623067becac1b276f884Igor Murashkin // Invalid API returns bad value 2407ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->connect(TEST_TOKEN, 2417ea777f097784492f880623067becac1b276f884Igor Murashkin /*api*/0xDEADBEEF, 2427ea777f097784492f880623067becac1b276f884Igor Murashkin TEST_CONTROLLED_BY_APP, 2437ea777f097784492f880623067becac1b276f884Igor Murashkin &output)); 2447ea777f097784492f880623067becac1b276f884Igor Murashkin 2457ea777f097784492f880623067becac1b276f884Igor Murashkin // TODO: get a token from a dead process somehow 2467ea777f097784492f880623067becac1b276f884Igor Murashkin} 2477ea777f097784492f880623067becac1b276f884Igor Murashkin 2487ea777f097784492f880623067becac1b276f884Igor MurashkinTEST_F(IGraphicBufferProducerTest, ConnectAgain_ReturnsError) { 2497ea777f097784492f880623067becac1b276f884Igor Murashkin ASSERT_NO_FATAL_FAILURE(ConnectProducer()); 2507ea777f097784492f880623067becac1b276f884Igor Murashkin 2517ea777f097784492f880623067becac1b276f884Igor Murashkin // Can't connect when there is already a producer connected 2527ea777f097784492f880623067becac1b276f884Igor Murashkin IGraphicBufferProducer::QueueBufferOutput output; 2537ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->connect(TEST_TOKEN, 2547ea777f097784492f880623067becac1b276f884Igor Murashkin TEST_API, 2557ea777f097784492f880623067becac1b276f884Igor Murashkin TEST_CONTROLLED_BY_APP, 2567ea777f097784492f880623067becac1b276f884Igor Murashkin &output)); 2577ea777f097784492f880623067becac1b276f884Igor Murashkin 2587ea777f097784492f880623067becac1b276f884Igor Murashkin ASSERT_OK(mConsumer->consumerDisconnect()); 2597ea777f097784492f880623067becac1b276f884Igor Murashkin // Can't connect when IGBP is abandoned 2607ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(NO_INIT, mProducer->connect(TEST_TOKEN, 2617ea777f097784492f880623067becac1b276f884Igor Murashkin TEST_API, 2627ea777f097784492f880623067becac1b276f884Igor Murashkin TEST_CONTROLLED_BY_APP, 2637ea777f097784492f880623067becac1b276f884Igor Murashkin &output)); 2647ea777f097784492f880623067becac1b276f884Igor Murashkin} 2657ea777f097784492f880623067becac1b276f884Igor Murashkin 2667ea777f097784492f880623067becac1b276f884Igor MurashkinTEST_F(IGraphicBufferProducerTest, Disconnect_Succeeds) { 2677ea777f097784492f880623067becac1b276f884Igor Murashkin ASSERT_NO_FATAL_FAILURE(ConnectProducer()); 2687ea777f097784492f880623067becac1b276f884Igor Murashkin 2697ea777f097784492f880623067becac1b276f884Igor Murashkin ASSERT_OK(mProducer->disconnect(TEST_API)); 2707ea777f097784492f880623067becac1b276f884Igor Murashkin} 2717ea777f097784492f880623067becac1b276f884Igor Murashkin 2727ea777f097784492f880623067becac1b276f884Igor Murashkin 2737ea777f097784492f880623067becac1b276f884Igor MurashkinTEST_F(IGraphicBufferProducerTest, Disconnect_ReturnsError) { 2747ea777f097784492f880623067becac1b276f884Igor Murashkin ASSERT_NO_FATAL_FAILURE(ConnectProducer()); 2757ea777f097784492f880623067becac1b276f884Igor Murashkin 2767ea777f097784492f880623067becac1b276f884Igor Murashkin // Must disconnect with same API number 2777ea777f097784492f880623067becac1b276f884Igor Murashkin ASSERT_EQ(BAD_VALUE, mProducer->disconnect(TEST_API_OTHER)); 2787ea777f097784492f880623067becac1b276f884Igor Murashkin // API must not be out of range 2797ea777f097784492f880623067becac1b276f884Igor Murashkin ASSERT_EQ(BAD_VALUE, mProducer->disconnect(/*api*/0xDEADBEEF)); 2807ea777f097784492f880623067becac1b276f884Igor Murashkin 2817ea777f097784492f880623067becac1b276f884Igor Murashkin // TODO: somehow kill mProducer so that this returns DEAD_OBJECT 2827ea777f097784492f880623067becac1b276f884Igor Murashkin} 2837ea777f097784492f880623067becac1b276f884Igor Murashkin 2847ea777f097784492f880623067becac1b276f884Igor MurashkinTEST_F(IGraphicBufferProducerTest, Query_Succeeds) { 2857ea777f097784492f880623067becac1b276f884Igor Murashkin ASSERT_NO_FATAL_FAILURE(ConnectProducer()); 2867ea777f097784492f880623067becac1b276f884Igor Murashkin 287f8cebe54576c8100769e2515d4f67bdd013a6927Dan Stoza int32_t value = -1; 2887ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_OK(mProducer->query(NATIVE_WINDOW_WIDTH, &value)); 289f8cebe54576c8100769e2515d4f67bdd013a6927Dan Stoza EXPECT_EQ(DEFAULT_WIDTH, static_cast<uint32_t>(value)); 2907ea777f097784492f880623067becac1b276f884Igor Murashkin 2917ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_OK(mProducer->query(NATIVE_WINDOW_HEIGHT, &value)); 292f8cebe54576c8100769e2515d4f67bdd013a6927Dan Stoza EXPECT_EQ(DEFAULT_HEIGHT, static_cast<uint32_t>(value)); 2937ea777f097784492f880623067becac1b276f884Igor Murashkin 2947ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_OK(mProducer->query(NATIVE_WINDOW_FORMAT, &value)); 2957ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(DEFAULT_FORMAT, value); 2967ea777f097784492f880623067becac1b276f884Igor Murashkin 2977ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_OK(mProducer->query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, &value)); 2987ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_LE(0, value); 2997ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_GE(BufferQueue::NUM_BUFFER_SLOTS, value); 3007ea777f097784492f880623067becac1b276f884Igor Murashkin 3017ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_OK(mProducer->query(NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND, &value)); 3027ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_FALSE(value); // Can't run behind when we haven't touched the queue 3037ea777f097784492f880623067becac1b276f884Igor Murashkin 3047ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_OK(mProducer->query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, &value)); 3057ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(DEFAULT_CONSUMER_USAGE_BITS, value); 3067ea777f097784492f880623067becac1b276f884Igor Murashkin 3077ea777f097784492f880623067becac1b276f884Igor Murashkin} 3087ea777f097784492f880623067becac1b276f884Igor Murashkin 3097ea777f097784492f880623067becac1b276f884Igor MurashkinTEST_F(IGraphicBufferProducerTest, Query_ReturnsError) { 3107ea777f097784492f880623067becac1b276f884Igor Murashkin ASSERT_NO_FATAL_FAILURE(ConnectProducer()); 3117ea777f097784492f880623067becac1b276f884Igor Murashkin 3127ea777f097784492f880623067becac1b276f884Igor Murashkin // One past the end of the last 'query' enum value. Update this if we add more enums. 313d8ead0ccd4b700e43a78efe9b140d4a069dc343dMichael Lentine const int NATIVE_WINDOW_QUERY_LAST_OFF_BY_ONE = NATIVE_WINDOW_BUFFER_AGE + 1; 3147ea777f097784492f880623067becac1b276f884Igor Murashkin 3157ea777f097784492f880623067becac1b276f884Igor Murashkin int value; 3167ea777f097784492f880623067becac1b276f884Igor Murashkin // What was out of range 3177ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->query(/*what*/-1, &value)); 3187ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->query(/*what*/0xDEADBEEF, &value)); 3197ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->query(NATIVE_WINDOW_QUERY_LAST_OFF_BY_ONE, &value)); 3207ea777f097784492f880623067becac1b276f884Igor Murashkin 3217ea777f097784492f880623067becac1b276f884Igor Murashkin // Some enums from window.h are 'invalid' 3227ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->query(NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER, &value)); 3237ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->query(NATIVE_WINDOW_CONCRETE_TYPE, &value)); 3247ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->query(NATIVE_WINDOW_DEFAULT_WIDTH, &value)); 3257ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->query(NATIVE_WINDOW_DEFAULT_HEIGHT, &value)); 3267ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->query(NATIVE_WINDOW_TRANSFORM_HINT, &value)); 3277ea777f097784492f880623067becac1b276f884Igor Murashkin // TODO: Consider documented the above enums as unsupported or make a new enum for IGBP 3287ea777f097784492f880623067becac1b276f884Igor Murashkin 3297ea777f097784492f880623067becac1b276f884Igor Murashkin // Value was NULL 3307ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->query(NATIVE_WINDOW_FORMAT, /*value*/NULL)); 3317ea777f097784492f880623067becac1b276f884Igor Murashkin 3327ea777f097784492f880623067becac1b276f884Igor Murashkin ASSERT_OK(mConsumer->consumerDisconnect()); 3337ea777f097784492f880623067becac1b276f884Igor Murashkin 3347ea777f097784492f880623067becac1b276f884Igor Murashkin // BQ was abandoned 3357ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(NO_INIT, mProducer->query(NATIVE_WINDOW_FORMAT, &value)); 3367ea777f097784492f880623067becac1b276f884Igor Murashkin 3377ea777f097784492f880623067becac1b276f884Igor Murashkin // TODO: other things in window.h that are supported by Surface::query 3387ea777f097784492f880623067becac1b276f884Igor Murashkin // but not by BufferQueue::query 3397ea777f097784492f880623067becac1b276f884Igor Murashkin} 3407ea777f097784492f880623067becac1b276f884Igor Murashkin 3417ea777f097784492f880623067becac1b276f884Igor Murashkin// TODO: queue under more complicated situations not involving just a single buffer 3427ea777f097784492f880623067becac1b276f884Igor MurashkinTEST_F(IGraphicBufferProducerTest, Queue_Succeeds) { 3437ea777f097784492f880623067becac1b276f884Igor Murashkin ASSERT_NO_FATAL_FAILURE(ConnectProducer()); 3447ea777f097784492f880623067becac1b276f884Igor Murashkin 3457ea777f097784492f880623067becac1b276f884Igor Murashkin int dequeuedSlot = -1; 3467ea777f097784492f880623067becac1b276f884Igor Murashkin sp<Fence> dequeuedFence; 3477ea777f097784492f880623067becac1b276f884Igor Murashkin 348567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos 349583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_EQ(OK, ~IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION & 350583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos (mProducer->dequeueBuffer(&dequeuedSlot, &dequeuedFence, 3517ea777f097784492f880623067becac1b276f884Igor Murashkin DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_FORMAT, 352583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos TEST_PRODUCER_USAGE_BITS))); 3537ea777f097784492f880623067becac1b276f884Igor Murashkin 3547ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_LE(0, dequeuedSlot); 3557ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_GT(BufferQueue::NUM_BUFFER_SLOTS, dequeuedSlot); 3567ea777f097784492f880623067becac1b276f884Igor Murashkin 3577ea777f097784492f880623067becac1b276f884Igor Murashkin // Request the buffer (pre-requisite for queueing) 3587ea777f097784492f880623067becac1b276f884Igor Murashkin sp<GraphicBuffer> dequeuedBuffer; 3597ea777f097784492f880623067becac1b276f884Igor Murashkin ASSERT_OK(mProducer->requestBuffer(dequeuedSlot, &dequeuedBuffer)); 3607ea777f097784492f880623067becac1b276f884Igor Murashkin 3617ea777f097784492f880623067becac1b276f884Igor Murashkin // A generic "valid" input 3627ea777f097784492f880623067becac1b276f884Igor Murashkin IGraphicBufferProducer::QueueBufferInput input = CreateBufferInput(); 3637ea777f097784492f880623067becac1b276f884Igor Murashkin IGraphicBufferProducer::QueueBufferOutput output; 3647ea777f097784492f880623067becac1b276f884Igor Murashkin 3657ea777f097784492f880623067becac1b276f884Igor Murashkin // Queue the buffer back into the BQ 3667ea777f097784492f880623067becac1b276f884Igor Murashkin ASSERT_OK(mProducer->queueBuffer(dequeuedSlot, input, &output)); 3677ea777f097784492f880623067becac1b276f884Igor Murashkin 3687ea777f097784492f880623067becac1b276f884Igor Murashkin { 3697ea777f097784492f880623067becac1b276f884Igor Murashkin uint32_t width; 3707ea777f097784492f880623067becac1b276f884Igor Murashkin uint32_t height; 3717ea777f097784492f880623067becac1b276f884Igor Murashkin uint32_t transformHint; 3727ea777f097784492f880623067becac1b276f884Igor Murashkin uint32_t numPendingBuffers; 3737ea777f097784492f880623067becac1b276f884Igor Murashkin 3747ea777f097784492f880623067becac1b276f884Igor Murashkin output.deflate(&width, &height, &transformHint, &numPendingBuffers); 3757ea777f097784492f880623067becac1b276f884Igor Murashkin 3767ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(DEFAULT_WIDTH, width); 3777ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(DEFAULT_HEIGHT, height); 3787ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(DEFAULT_TRANSFORM_HINT, transformHint); 379f8cebe54576c8100769e2515d4f67bdd013a6927Dan Stoza EXPECT_EQ(1u, numPendingBuffers); // since queueBuffer was called exactly once 3807ea777f097784492f880623067becac1b276f884Igor Murashkin } 3817ea777f097784492f880623067becac1b276f884Igor Murashkin 3827ea777f097784492f880623067becac1b276f884Igor Murashkin // Buffer was not in the dequeued state 3837ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->queueBuffer(dequeuedSlot, input, &output)); 3847ea777f097784492f880623067becac1b276f884Igor Murashkin} 3857ea777f097784492f880623067becac1b276f884Igor Murashkin 3867ea777f097784492f880623067becac1b276f884Igor MurashkinTEST_F(IGraphicBufferProducerTest, Queue_ReturnsError) { 3877ea777f097784492f880623067becac1b276f884Igor Murashkin ASSERT_NO_FATAL_FAILURE(ConnectProducer()); 3887ea777f097784492f880623067becac1b276f884Igor Murashkin 3897ea777f097784492f880623067becac1b276f884Igor Murashkin // Invalid slot number 3907ea777f097784492f880623067becac1b276f884Igor Murashkin { 3917ea777f097784492f880623067becac1b276f884Igor Murashkin // A generic "valid" input 3927ea777f097784492f880623067becac1b276f884Igor Murashkin IGraphicBufferProducer::QueueBufferInput input = CreateBufferInput(); 3937ea777f097784492f880623067becac1b276f884Igor Murashkin IGraphicBufferProducer::QueueBufferOutput output; 3947ea777f097784492f880623067becac1b276f884Igor Murashkin 3957ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->queueBuffer(/*slot*/-1, input, &output)); 3967ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->queueBuffer(/*slot*/0xDEADBEEF, input, &output)); 3977ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->queueBuffer(BufferQueue::NUM_BUFFER_SLOTS, 3987ea777f097784492f880623067becac1b276f884Igor Murashkin input, &output)); 3997ea777f097784492f880623067becac1b276f884Igor Murashkin } 4007ea777f097784492f880623067becac1b276f884Igor Murashkin 4017ea777f097784492f880623067becac1b276f884Igor Murashkin // Slot was not in the dequeued state (all slots start out in Free state) 4027ea777f097784492f880623067becac1b276f884Igor Murashkin { 4037ea777f097784492f880623067becac1b276f884Igor Murashkin IGraphicBufferProducer::QueueBufferInput input = CreateBufferInput(); 4047ea777f097784492f880623067becac1b276f884Igor Murashkin IGraphicBufferProducer::QueueBufferOutput output; 4057ea777f097784492f880623067becac1b276f884Igor Murashkin 4067ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->queueBuffer(/*slot*/0, input, &output)); 4077ea777f097784492f880623067becac1b276f884Igor Murashkin } 4087ea777f097784492f880623067becac1b276f884Igor Murashkin 4097ea777f097784492f880623067becac1b276f884Igor Murashkin // Put the slot into the "dequeued" state for the rest of the test 4107ea777f097784492f880623067becac1b276f884Igor Murashkin int dequeuedSlot = -1; 4117ea777f097784492f880623067becac1b276f884Igor Murashkin sp<Fence> dequeuedFence; 4127ea777f097784492f880623067becac1b276f884Igor Murashkin 413583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_EQ(OK, ~IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION & 414583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos (mProducer->dequeueBuffer(&dequeuedSlot, &dequeuedFence, 4157ea777f097784492f880623067becac1b276f884Igor Murashkin DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_FORMAT, 416583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos TEST_PRODUCER_USAGE_BITS))); 4177ea777f097784492f880623067becac1b276f884Igor Murashkin 4187ea777f097784492f880623067becac1b276f884Igor Murashkin // Slot was enqueued without requesting a buffer 4197ea777f097784492f880623067becac1b276f884Igor Murashkin { 4207ea777f097784492f880623067becac1b276f884Igor Murashkin IGraphicBufferProducer::QueueBufferInput input = CreateBufferInput(); 4217ea777f097784492f880623067becac1b276f884Igor Murashkin IGraphicBufferProducer::QueueBufferOutput output; 4227ea777f097784492f880623067becac1b276f884Igor Murashkin 4237ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->queueBuffer(dequeuedSlot, input, &output)); 4247ea777f097784492f880623067becac1b276f884Igor Murashkin } 4257ea777f097784492f880623067becac1b276f884Igor Murashkin 4267ea777f097784492f880623067becac1b276f884Igor Murashkin // Request the buffer so that the rest of the tests don't fail on earlier checks. 4277ea777f097784492f880623067becac1b276f884Igor Murashkin sp<GraphicBuffer> dequeuedBuffer; 4287ea777f097784492f880623067becac1b276f884Igor Murashkin ASSERT_OK(mProducer->requestBuffer(dequeuedSlot, &dequeuedBuffer)); 4297ea777f097784492f880623067becac1b276f884Igor Murashkin 4307ea777f097784492f880623067becac1b276f884Igor Murashkin // Fence was NULL 4317ea777f097784492f880623067becac1b276f884Igor Murashkin { 4327ea777f097784492f880623067becac1b276f884Igor Murashkin sp<Fence> nullFence = NULL; 4337ea777f097784492f880623067becac1b276f884Igor Murashkin 4347ea777f097784492f880623067becac1b276f884Igor Murashkin IGraphicBufferProducer::QueueBufferInput input = 4357ea777f097784492f880623067becac1b276f884Igor Murashkin QueueBufferInputBuilder().setFence(nullFence).build(); 4367ea777f097784492f880623067becac1b276f884Igor Murashkin IGraphicBufferProducer::QueueBufferOutput output; 4377ea777f097784492f880623067becac1b276f884Igor Murashkin 4387ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->queueBuffer(dequeuedSlot, input, &output)); 4397ea777f097784492f880623067becac1b276f884Igor Murashkin } 4407ea777f097784492f880623067becac1b276f884Igor Murashkin 4417ea777f097784492f880623067becac1b276f884Igor Murashkin // Scaling mode was unknown 4427ea777f097784492f880623067becac1b276f884Igor Murashkin { 4437ea777f097784492f880623067becac1b276f884Igor Murashkin IGraphicBufferProducer::QueueBufferInput input = 4447ea777f097784492f880623067becac1b276f884Igor Murashkin QueueBufferInputBuilder().setScalingMode(-1).build(); 4457ea777f097784492f880623067becac1b276f884Igor Murashkin IGraphicBufferProducer::QueueBufferOutput output; 4467ea777f097784492f880623067becac1b276f884Igor Murashkin 4477ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->queueBuffer(dequeuedSlot, input, &output)); 4487ea777f097784492f880623067becac1b276f884Igor Murashkin 4497ea777f097784492f880623067becac1b276f884Igor Murashkin input = QueueBufferInputBuilder().setScalingMode(0xDEADBEEF).build(); 4507ea777f097784492f880623067becac1b276f884Igor Murashkin 4517ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->queueBuffer(dequeuedSlot, input, &output)); 4527ea777f097784492f880623067becac1b276f884Igor Murashkin } 4537ea777f097784492f880623067becac1b276f884Igor Murashkin 4547ea777f097784492f880623067becac1b276f884Igor Murashkin // Crop rect is out of bounds of the buffer dimensions 4557ea777f097784492f880623067becac1b276f884Igor Murashkin { 4567ea777f097784492f880623067becac1b276f884Igor Murashkin IGraphicBufferProducer::QueueBufferInput input = 4577ea777f097784492f880623067becac1b276f884Igor Murashkin QueueBufferInputBuilder().setCrop(Rect(DEFAULT_WIDTH + 1, DEFAULT_HEIGHT + 1)) 4587ea777f097784492f880623067becac1b276f884Igor Murashkin .build(); 4597ea777f097784492f880623067becac1b276f884Igor Murashkin IGraphicBufferProducer::QueueBufferOutput output; 4607ea777f097784492f880623067becac1b276f884Igor Murashkin 4617ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(BAD_VALUE, mProducer->queueBuffer(dequeuedSlot, input, &output)); 4627ea777f097784492f880623067becac1b276f884Igor Murashkin } 4637ea777f097784492f880623067becac1b276f884Igor Murashkin 4647ea777f097784492f880623067becac1b276f884Igor Murashkin // Abandon the buffer queue so that the last test fails 4657ea777f097784492f880623067becac1b276f884Igor Murashkin ASSERT_OK(mConsumer->consumerDisconnect()); 4667ea777f097784492f880623067becac1b276f884Igor Murashkin 4677ea777f097784492f880623067becac1b276f884Igor Murashkin // The buffer queue has been abandoned. 4687ea777f097784492f880623067becac1b276f884Igor Murashkin { 4697ea777f097784492f880623067becac1b276f884Igor Murashkin IGraphicBufferProducer::QueueBufferInput input = CreateBufferInput(); 4707ea777f097784492f880623067becac1b276f884Igor Murashkin IGraphicBufferProducer::QueueBufferOutput output; 4717ea777f097784492f880623067becac1b276f884Igor Murashkin 4727ea777f097784492f880623067becac1b276f884Igor Murashkin EXPECT_EQ(NO_INIT, mProducer->queueBuffer(dequeuedSlot, input, &output)); 4737ea777f097784492f880623067becac1b276f884Igor Murashkin } 4747ea777f097784492f880623067becac1b276f884Igor Murashkin} 4757ea777f097784492f880623067becac1b276f884Igor Murashkin 4767ea777f097784492f880623067becac1b276f884Igor MurashkinTEST_F(IGraphicBufferProducerTest, CancelBuffer_DoesntCrash) { 4777ea777f097784492f880623067becac1b276f884Igor Murashkin ASSERT_NO_FATAL_FAILURE(ConnectProducer()); 4787ea777f097784492f880623067becac1b276f884Igor Murashkin 4797ea777f097784492f880623067becac1b276f884Igor Murashkin int dequeuedSlot = -1; 4807ea777f097784492f880623067becac1b276f884Igor Murashkin sp<Fence> dequeuedFence; 4817ea777f097784492f880623067becac1b276f884Igor Murashkin 482583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_EQ(OK, ~IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION & 483583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos (mProducer->dequeueBuffer(&dequeuedSlot, &dequeuedFence, 4847ea777f097784492f880623067becac1b276f884Igor Murashkin DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_FORMAT, 485583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos TEST_PRODUCER_USAGE_BITS))); 4867ea777f097784492f880623067becac1b276f884Igor Murashkin 4877ea777f097784492f880623067becac1b276f884Igor Murashkin // No return code, but at least test that it doesn't blow up... 4887ea777f097784492f880623067becac1b276f884Igor Murashkin // TODO: add a return code 4897ea777f097784492f880623067becac1b276f884Igor Murashkin mProducer->cancelBuffer(dequeuedSlot, dequeuedFence); 4907ea777f097784492f880623067becac1b276f884Igor Murashkin} 4917ea777f097784492f880623067becac1b276f884Igor Murashkin 492fa455354557f6283ff3a7d76979e52fd251c155fPablo CeballosTEST_F(IGraphicBufferProducerTest, SetMaxDequeuedBufferCount_Succeeds) { 493583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_NO_FATAL_FAILURE(ConnectProducer()); 494fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos int minUndequeuedBuffers; 495fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos ASSERT_OK(mProducer->query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, 496fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos &minUndequeuedBuffers)); 497fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 498fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos const int minBuffers = 1; 499fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos const int maxBuffers = BufferQueue::NUM_BUFFER_SLOTS - minUndequeuedBuffers; 500fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 501fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos ASSERT_OK(mProducer->setAsyncMode(false)) << "async mode: " << false; 502fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos ASSERT_OK(mProducer->setMaxDequeuedBufferCount(minBuffers)) 503fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos << "bufferCount: " << minBuffers; 504fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 505fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos std::vector<DequeueBufferResult> dequeueList; 506fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 507fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos // Should now be able to dequeue up to minBuffers times 508fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos for (int i = 0; i < minBuffers; ++i) { 509fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos DequeueBufferResult result; 510fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 511583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos EXPECT_EQ(OK, ~IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION & 512567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos (dequeueBuffer(DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_FORMAT, 513583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos TEST_PRODUCER_USAGE_BITS, &result))) 514fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos << "iteration: " << i << ", slot: " << result.slot; 515fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 516fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos dequeueList.push_back(result); 517fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos } 518fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 519fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos // Cancel every buffer, so we can set buffer count again 520fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos for (auto& result : dequeueList) { 521fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos mProducer->cancelBuffer(result.slot, result.fence); 522fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos } 523fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 524fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos ASSERT_OK(mProducer->setMaxDequeuedBufferCount(maxBuffers)); 525fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 526fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos // Should now be able to dequeue up to maxBuffers times 527fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos for (int i = 0; i < maxBuffers; ++i) { 528fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos int dequeuedSlot = -1; 529fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos sp<Fence> dequeuedFence; 530fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 531583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos EXPECT_EQ(OK, ~IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION & 532583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos (mProducer->dequeueBuffer(&dequeuedSlot, &dequeuedFence, 533fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos DEFAULT_WIDTH, DEFAULT_HEIGHT, 534fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos DEFAULT_FORMAT, 535583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos TEST_PRODUCER_USAGE_BITS))) 536fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos << "iteration: " << i << ", slot: " << dequeuedSlot; 537fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos } 538fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos} 539fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 540fa455354557f6283ff3a7d76979e52fd251c155fPablo CeballosTEST_F(IGraphicBufferProducerTest, SetMaxDequeuedBufferCount_Fails) { 541583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_NO_FATAL_FAILURE(ConnectProducer()); 542fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos int minUndequeuedBuffers; 543fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos ASSERT_OK(mProducer->query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, 544fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos &minUndequeuedBuffers)); 545fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 546fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos const int minBuffers = 1; 547fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos const int maxBuffers = BufferQueue::NUM_BUFFER_SLOTS - minUndequeuedBuffers; 548fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 549fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos ASSERT_OK(mProducer->setAsyncMode(false)) << "async mode: " << false; 550fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos // Buffer count was out of range 551fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos EXPECT_EQ(BAD_VALUE, mProducer->setMaxDequeuedBufferCount(0)) 552fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos << "bufferCount: " << 0; 553fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos EXPECT_EQ(BAD_VALUE, mProducer->setMaxDequeuedBufferCount(maxBuffers + 1)) 554fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos << "bufferCount: " << maxBuffers + 1; 555fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 556fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos // Prerequisite to fail out a valid setBufferCount call 557fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos { 558fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos int dequeuedSlot = -1; 559fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos sp<Fence> dequeuedFence; 560fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 561583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_EQ(OK, ~IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION & 562583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos (mProducer->dequeueBuffer(&dequeuedSlot, &dequeuedFence, 563fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos DEFAULT_WIDTH, DEFAULT_HEIGHT, 564fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos DEFAULT_FORMAT, 565583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos TEST_PRODUCER_USAGE_BITS))) 566fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos << "slot: " << dequeuedSlot; 567fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos } 568fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 569fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos // Client has one or more buffers dequeued 570fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos EXPECT_EQ(BAD_VALUE, mProducer->setMaxDequeuedBufferCount(minBuffers)) 571fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos << "bufferCount: " << minBuffers; 572fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 573fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos // Abandon buffer queue 574fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos ASSERT_OK(mConsumer->consumerDisconnect()); 575fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 576fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos // Fail because the buffer queue was abandoned 577fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos EXPECT_EQ(NO_INIT, mProducer->setMaxDequeuedBufferCount(minBuffers)) 578fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos << "bufferCount: " << minBuffers; 579fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 580fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos} 581fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 582fa455354557f6283ff3a7d76979e52fd251c155fPablo CeballosTEST_F(IGraphicBufferProducerTest, SetAsyncMode_Succeeds) { 583fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos ASSERT_OK(mConsumer->setMaxAcquiredBufferCount(1)) << "maxAcquire: " << 1; 584583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_NO_FATAL_FAILURE(ConnectProducer()); 585fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos ASSERT_OK(mProducer->setAsyncMode(true)) << "async mode: " << true; 586fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos ASSERT_OK(mProducer->setMaxDequeuedBufferCount(1)) << "maxDequeue: " << 1; 587fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 588fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos int dequeuedSlot = -1; 589fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos sp<Fence> dequeuedFence; 590567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos IGraphicBufferProducer::QueueBufferInput input = CreateBufferInput(); 591fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos IGraphicBufferProducer::QueueBufferOutput output; 592fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos sp<GraphicBuffer> dequeuedBuffer; 593fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 594fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos // Should now be able to queue/dequeue as many buffers as we want without 595fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos // blocking 596fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos for (int i = 0; i < 5; ++i) { 597583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_EQ(OK, ~IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION & 598583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos (mProducer->dequeueBuffer(&dequeuedSlot, &dequeuedFence, 599567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_FORMAT, 600567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos TEST_PRODUCER_USAGE_BITS))) << "slot : " << dequeuedSlot; 601fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos ASSERT_OK(mProducer->requestBuffer(dequeuedSlot, &dequeuedBuffer)); 602fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos ASSERT_OK(mProducer->queueBuffer(dequeuedSlot, input, &output)); 603fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos } 604fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos} 605fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 606fa455354557f6283ff3a7d76979e52fd251c155fPablo CeballosTEST_F(IGraphicBufferProducerTest, SetAsyncMode_Fails) { 607583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_NO_FATAL_FAILURE(ConnectProducer()); 608fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos // Prerequisite to fail out a valid setBufferCount call 609fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos { 610fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos int dequeuedSlot = -1; 611fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos sp<Fence> dequeuedFence; 612fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 613583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_EQ(OK, ~IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION & 614583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos (mProducer->dequeueBuffer(&dequeuedSlot, &dequeuedFence, 615567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_FORMAT, 616567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos TEST_PRODUCER_USAGE_BITS))) << "slot: " << dequeuedSlot; 617fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos } 618fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 619fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos // Client has one or more buffers dequeued 620fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos EXPECT_EQ(BAD_VALUE, mProducer->setAsyncMode(false)) << "asyncMode: " 621fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos << false; 622fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 623fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos // Abandon buffer queue 624fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos ASSERT_OK(mConsumer->consumerDisconnect()); 625fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 626fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos // Fail because the buffer queue was abandoned 627fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos EXPECT_EQ(NO_INIT, mProducer->setAsyncMode(false)) << "asyncMode: " 628fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos << false; 629fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos} 630fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos 631583b1b32191992d6ada58b3c61c71932a71c0c4bPablo CeballosTEST_F(IGraphicBufferProducerTest, 632583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos DisconnectedProducerReturnsError_dequeueBuffer) { 633583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos int slot = -1; 634583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos sp<Fence> fence; 635583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 636567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos ASSERT_EQ(NO_INIT, mProducer->dequeueBuffer(&slot, &fence, DEFAULT_WIDTH, 637567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos DEFAULT_HEIGHT, DEFAULT_FORMAT, TEST_PRODUCER_USAGE_BITS)); 638583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos} 639583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 640583b1b32191992d6ada58b3c61c71932a71c0c4bPablo CeballosTEST_F(IGraphicBufferProducerTest, 641583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos DisconnectedProducerReturnsError_detachNextBuffer) { 642583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos sp<Fence> fence; 643583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos sp<GraphicBuffer> buffer; 644583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 645583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_EQ(NO_INIT, mProducer->detachNextBuffer(&buffer, &fence)); 646583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos} 647583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 648583b1b32191992d6ada58b3c61c71932a71c0c4bPablo CeballosTEST_F(IGraphicBufferProducerTest, 649583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos DisconnectedProducerReturnsError_requestBuffer) { 650583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_NO_FATAL_FAILURE(ConnectProducer()); 651583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 652583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos int slot = -1; 653583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos sp<Fence> fence; 654583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 655583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_EQ(OK, ~IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION & 656567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos (mProducer->dequeueBuffer(&slot, &fence, DEFAULT_WIDTH, 657567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos DEFAULT_HEIGHT, DEFAULT_FORMAT, TEST_PRODUCER_USAGE_BITS))); 658583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 659583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos EXPECT_LE(0, slot); 660583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos EXPECT_GT(BufferQueue::NUM_BUFFER_SLOTS, slot); 661583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 662583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_OK(mProducer->disconnect(TEST_API)); 663583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 664583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos sp<GraphicBuffer> buffer; 665583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 666583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_EQ(NO_INIT, mProducer->requestBuffer(slot, &buffer)); 667583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos} 668583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 669583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 670583b1b32191992d6ada58b3c61c71932a71c0c4bPablo CeballosTEST_F(IGraphicBufferProducerTest, 671583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos DisconnectedProducerReturnsError_detachBuffer) { 672583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos int slot = -1; 673583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos sp<Fence> fence; 674583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos sp<GraphicBuffer> buffer; 675583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 676583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos setupDequeueRequestBuffer(&slot, &fence, &buffer); 677583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 678583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_OK(mProducer->disconnect(TEST_API)); 679583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 680583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_EQ(NO_INIT, mProducer->detachBuffer(slot)); 681583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos} 682583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 683583b1b32191992d6ada58b3c61c71932a71c0c4bPablo CeballosTEST_F(IGraphicBufferProducerTest, 684583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos DisconnectedProducerReturnsError_queueBuffer) { 685583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos int slot = -1; 686583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos sp<Fence> fence; 687583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos sp<GraphicBuffer> buffer; 688583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 689583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos setupDequeueRequestBuffer(&slot, &fence, &buffer); 690583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 691583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_OK(mProducer->disconnect(TEST_API)); 692583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 693583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos // A generic "valid" input 694583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos IGraphicBufferProducer::QueueBufferInput input = CreateBufferInput(); 695583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos IGraphicBufferProducer::QueueBufferOutput output; 696583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 697583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_EQ(NO_INIT, mProducer->queueBuffer(slot, input, &output)); 698583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos} 699583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 700583b1b32191992d6ada58b3c61c71932a71c0c4bPablo CeballosTEST_F(IGraphicBufferProducerTest, 701583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos DisconnectedProducerReturnsError_cancelBuffer) { 702583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos int slot = -1; 703583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos sp<Fence> fence; 704583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos sp<GraphicBuffer> buffer; 705583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 706583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos setupDequeueRequestBuffer(&slot, &fence, &buffer); 707583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 708583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_OK(mProducer->disconnect(TEST_API)); 709583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 710583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_EQ(NO_INIT, mProducer->cancelBuffer(slot, fence)); 711583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos} 712583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 713583b1b32191992d6ada58b3c61c71932a71c0c4bPablo CeballosTEST_F(IGraphicBufferProducerTest, 714583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos DisconnectedProducerReturnsError_attachBuffer) { 715583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos int slot = -1; 716583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos sp<Fence> fence; 717583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos sp<GraphicBuffer> buffer; 718583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 719583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos setupDequeueRequestBuffer(&slot, &fence, &buffer); 720583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 721583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_OK(mProducer->detachBuffer(slot)); 722583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 723583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_OK(mProducer->disconnect(TEST_API)); 724583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 725583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos ASSERT_EQ(NO_INIT, mProducer->attachBuffer(&slot, buffer)); 726583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos} 727583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos 7287ea777f097784492f880623067becac1b276f884Igor Murashkin} // namespace android 729