| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2013 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | #define LOG_TAG "IGraphicBufferProducer_test" | 
|  | 18 | //#define LOG_NDEBUG 0 | 
|  | 19 |  | 
| Brian Anderson | 5ea5e59 | 2016-12-01 16:54:33 -0800 | [diff] [blame] | 20 | #include "DummyConsumer.h" | 
|  | 21 |  | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 22 | #include <gtest/gtest.h> | 
|  | 23 |  | 
|  | 24 | #include <utils/String8.h> | 
|  | 25 | #include <utils/threads.h> | 
|  | 26 |  | 
|  | 27 | #include <ui/GraphicBuffer.h> | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 28 |  | 
|  | 29 | #include <gui/BufferQueue.h> | 
| Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 30 | #include <gui/IProducerListener.h> | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 31 |  | 
| Mathias Agopian | 6a3c05b | 2017-04-27 20:06:55 -0700 | [diff] [blame] | 32 | #include <system/window.h> | 
|  | 33 |  | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 34 | #include <vector> | 
|  | 35 |  | 
|  | 36 | #define ASSERT_OK(x) ASSERT_EQ(OK, (x)) | 
|  | 37 | #define EXPECT_OK(x) EXPECT_EQ(OK, (x)) | 
|  | 38 |  | 
| Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 39 | #define TEST_TOKEN ((IProducerListener*)(NULL)) | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 40 | #define TEST_API NATIVE_WINDOW_API_CPU | 
|  | 41 | #define TEST_API_OTHER NATIVE_WINDOW_API_EGL // valid API that's not TEST_API | 
|  | 42 | #define TEST_CONTROLLED_BY_APP false | 
|  | 43 | #define TEST_PRODUCER_USAGE_BITS (0) | 
|  | 44 |  | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 45 | namespace android { | 
|  | 46 |  | 
|  | 47 | namespace { | 
| Dan Stoza | f8cebe5 | 2015-04-20 12:09:38 -0700 | [diff] [blame] | 48 | // Default dimensions before setDefaultBufferSize is called | 
|  | 49 | const uint32_t DEFAULT_WIDTH = 1; | 
|  | 50 | const uint32_t DEFAULT_HEIGHT = 1; | 
|  | 51 |  | 
|  | 52 | // Default format before setDefaultBufferFormat is called | 
|  | 53 | const PixelFormat DEFAULT_FORMAT = HAL_PIXEL_FORMAT_RGBA_8888; | 
|  | 54 |  | 
|  | 55 | // Default transform hint before setTransformHint is called | 
|  | 56 | const uint32_t DEFAULT_TRANSFORM_HINT = 0; | 
|  | 57 |  | 
|  | 58 | // TODO: Make these constants in header | 
|  | 59 | const int DEFAULT_CONSUMER_USAGE_BITS = 0; | 
|  | 60 |  | 
|  | 61 | // Parameters for a generic "valid" input for queueBuffer. | 
|  | 62 | const int64_t QUEUE_BUFFER_INPUT_TIMESTAMP = 1384888611; | 
|  | 63 | const bool QUEUE_BUFFER_INPUT_IS_AUTO_TIMESTAMP = false; | 
|  | 64 | const android_dataspace QUEUE_BUFFER_INPUT_DATASPACE = HAL_DATASPACE_UNKNOWN; | 
|  | 65 | const Rect QUEUE_BUFFER_INPUT_RECT = Rect(DEFAULT_WIDTH, DEFAULT_HEIGHT); | 
|  | 66 | const int QUEUE_BUFFER_INPUT_SCALING_MODE = 0; | 
|  | 67 | const int QUEUE_BUFFER_INPUT_TRANSFORM = 0; | 
| Dan Stoza | f8cebe5 | 2015-04-20 12:09:38 -0700 | [diff] [blame] | 68 | const sp<Fence> QUEUE_BUFFER_INPUT_FENCE = Fence::NO_FENCE; | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 69 | }; // namespace anonymous | 
|  | 70 |  | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 71 | class IGraphicBufferProducerTest : public ::testing::Test { | 
|  | 72 | protected: | 
|  | 73 |  | 
|  | 74 | IGraphicBufferProducerTest() {} | 
|  | 75 |  | 
|  | 76 | virtual void SetUp() { | 
|  | 77 | const ::testing::TestInfo* const testInfo = | 
|  | 78 | ::testing::UnitTest::GetInstance()->current_test_info(); | 
|  | 79 | ALOGV("Begin test: %s.%s", testInfo->test_case_name(), | 
|  | 80 | testInfo->name()); | 
|  | 81 |  | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 82 | mDC = new DummyConsumer; | 
|  | 83 |  | 
| Dan Stoza | 5603a2f | 2014-04-07 13:41:37 -0700 | [diff] [blame] | 84 | BufferQueue::createBufferQueue(&mProducer, &mConsumer); | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 85 |  | 
|  | 86 | // Test check: Can't connect producer if no consumer yet | 
|  | 87 | ASSERT_EQ(NO_INIT, TryConnectProducer()); | 
|  | 88 |  | 
|  | 89 | // Must connect consumer before producer connects will succeed. | 
|  | 90 | ASSERT_OK(mConsumer->consumerConnect(mDC, /*controlledByApp*/false)); | 
|  | 91 | } | 
|  | 92 |  | 
|  | 93 | virtual void TearDown() { | 
|  | 94 | const ::testing::TestInfo* const testInfo = | 
|  | 95 | ::testing::UnitTest::GetInstance()->current_test_info(); | 
|  | 96 | ALOGV("End test:   %s.%s", testInfo->test_case_name(), | 
|  | 97 | testInfo->name()); | 
|  | 98 | } | 
|  | 99 |  | 
|  | 100 | status_t TryConnectProducer() { | 
|  | 101 | IGraphicBufferProducer::QueueBufferOutput output; | 
|  | 102 | return mProducer->connect(TEST_TOKEN, | 
|  | 103 | TEST_API, | 
|  | 104 | TEST_CONTROLLED_BY_APP, | 
|  | 105 | &output); | 
|  | 106 | // TODO: use params to vary token, api, producercontrolledbyapp, etc | 
|  | 107 | } | 
|  | 108 |  | 
|  | 109 | // Connect to a producer in a 'correct' fashion. | 
|  | 110 | //   Precondition: Consumer is connected. | 
|  | 111 | void ConnectProducer() { | 
|  | 112 | ASSERT_OK(TryConnectProducer()); | 
|  | 113 | } | 
|  | 114 |  | 
|  | 115 | // Create a generic "valid" input for queueBuffer | 
|  | 116 | // -- uses the default buffer format, width, etc. | 
|  | 117 | static IGraphicBufferProducer::QueueBufferInput CreateBufferInput() { | 
|  | 118 | return QueueBufferInputBuilder().build(); | 
|  | 119 | } | 
|  | 120 |  | 
|  | 121 | // Builder pattern to slightly vary *almost* correct input | 
|  | 122 | // -- avoids copying and pasting | 
|  | 123 | struct QueueBufferInputBuilder { | 
|  | 124 | QueueBufferInputBuilder() { | 
|  | 125 | timestamp = QUEUE_BUFFER_INPUT_TIMESTAMP; | 
|  | 126 | isAutoTimestamp = QUEUE_BUFFER_INPUT_IS_AUTO_TIMESTAMP; | 
| Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 127 | dataSpace = QUEUE_BUFFER_INPUT_DATASPACE; | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 128 | crop = QUEUE_BUFFER_INPUT_RECT; | 
|  | 129 | scalingMode = QUEUE_BUFFER_INPUT_SCALING_MODE; | 
|  | 130 | transform = QUEUE_BUFFER_INPUT_TRANSFORM; | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 131 | fence = QUEUE_BUFFER_INPUT_FENCE; | 
|  | 132 | } | 
|  | 133 |  | 
|  | 134 | IGraphicBufferProducer::QueueBufferInput build() { | 
|  | 135 | return IGraphicBufferProducer::QueueBufferInput( | 
|  | 136 | timestamp, | 
|  | 137 | isAutoTimestamp, | 
| Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 138 | dataSpace, | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 139 | crop, | 
|  | 140 | scalingMode, | 
|  | 141 | transform, | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 142 | fence); | 
|  | 143 | } | 
|  | 144 |  | 
|  | 145 | QueueBufferInputBuilder& setTimestamp(int64_t timestamp) { | 
|  | 146 | this->timestamp = timestamp; | 
|  | 147 | return *this; | 
|  | 148 | } | 
|  | 149 |  | 
|  | 150 | QueueBufferInputBuilder& setIsAutoTimestamp(bool isAutoTimestamp) { | 
|  | 151 | this->isAutoTimestamp = isAutoTimestamp; | 
|  | 152 | return *this; | 
|  | 153 | } | 
|  | 154 |  | 
| Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 155 | QueueBufferInputBuilder& setDataSpace(android_dataspace dataSpace) { | 
|  | 156 | this->dataSpace = dataSpace; | 
|  | 157 | return *this; | 
|  | 158 | } | 
|  | 159 |  | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 160 | QueueBufferInputBuilder& setCrop(Rect crop) { | 
|  | 161 | this->crop = crop; | 
|  | 162 | return *this; | 
|  | 163 | } | 
|  | 164 |  | 
|  | 165 | QueueBufferInputBuilder& setScalingMode(int scalingMode) { | 
|  | 166 | this->scalingMode = scalingMode; | 
|  | 167 | return *this; | 
|  | 168 | } | 
|  | 169 |  | 
|  | 170 | QueueBufferInputBuilder& setTransform(uint32_t transform) { | 
|  | 171 | this->transform = transform; | 
|  | 172 | return *this; | 
|  | 173 | } | 
|  | 174 |  | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 175 | QueueBufferInputBuilder& setFence(sp<Fence> fence) { | 
|  | 176 | this->fence = fence; | 
|  | 177 | return *this; | 
|  | 178 | } | 
|  | 179 |  | 
|  | 180 | private: | 
|  | 181 | int64_t timestamp; | 
|  | 182 | bool isAutoTimestamp; | 
| Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 183 | android_dataspace dataSpace; | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 184 | Rect crop; | 
|  | 185 | int scalingMode; | 
|  | 186 | uint32_t transform; | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 187 | sp<Fence> fence; | 
|  | 188 | }; // struct QueueBufferInputBuilder | 
|  | 189 |  | 
|  | 190 | // To easily store dequeueBuffer results into containers | 
|  | 191 | struct DequeueBufferResult { | 
|  | 192 | int slot; | 
|  | 193 | sp<Fence> fence; | 
|  | 194 | }; | 
|  | 195 |  | 
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 196 | status_t dequeueBuffer(uint32_t w, uint32_t h, uint32_t format, uint32_t usage, DequeueBufferResult* result) { | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 197 | return mProducer->dequeueBuffer(&result->slot, &result->fence, w, h, format, usage, nullptr); | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 198 | } | 
|  | 199 |  | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 200 | void setupDequeueRequestBuffer(int *slot, sp<Fence> *fence, | 
|  | 201 | sp<GraphicBuffer> *buffer) | 
|  | 202 | { | 
|  | 203 | ASSERT_TRUE(slot != NULL); | 
|  | 204 | ASSERT_TRUE(fence != NULL); | 
|  | 205 | ASSERT_TRUE(buffer != NULL); | 
|  | 206 |  | 
|  | 207 | ASSERT_NO_FATAL_FAILURE(ConnectProducer()); | 
|  | 208 |  | 
|  | 209 | ASSERT_EQ(OK, ~IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION & | 
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 210 | (mProducer->dequeueBuffer(slot, fence, DEFAULT_WIDTH, | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 211 | DEFAULT_HEIGHT, DEFAULT_FORMAT, TEST_PRODUCER_USAGE_BITS, nullptr))); | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 212 |  | 
|  | 213 | EXPECT_LE(0, *slot); | 
|  | 214 | EXPECT_GT(BufferQueue::NUM_BUFFER_SLOTS, *slot); | 
|  | 215 |  | 
|  | 216 | // Request the buffer (pre-requisite for queueing) | 
|  | 217 | ASSERT_OK(mProducer->requestBuffer(*slot, buffer)); | 
|  | 218 | } | 
|  | 219 |  | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 220 | private: // hide from test body | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 221 | sp<DummyConsumer> mDC; | 
|  | 222 |  | 
|  | 223 | protected: // accessible from test body | 
|  | 224 | sp<IGraphicBufferProducer> mProducer; | 
|  | 225 | sp<IGraphicBufferConsumer> mConsumer; | 
|  | 226 | }; | 
|  | 227 |  | 
|  | 228 | TEST_F(IGraphicBufferProducerTest, ConnectFirst_ReturnsError) { | 
|  | 229 | IGraphicBufferProducer::QueueBufferOutput output; | 
|  | 230 |  | 
|  | 231 | // NULL output returns BAD_VALUE | 
|  | 232 | EXPECT_EQ(BAD_VALUE, mProducer->connect(TEST_TOKEN, | 
|  | 233 | TEST_API, | 
|  | 234 | TEST_CONTROLLED_BY_APP, | 
|  | 235 | /*output*/NULL)); | 
|  | 236 |  | 
|  | 237 | // Invalid API returns bad value | 
|  | 238 | EXPECT_EQ(BAD_VALUE, mProducer->connect(TEST_TOKEN, | 
|  | 239 | /*api*/0xDEADBEEF, | 
|  | 240 | TEST_CONTROLLED_BY_APP, | 
|  | 241 | &output)); | 
|  | 242 |  | 
|  | 243 | // TODO: get a token from a dead process somehow | 
|  | 244 | } | 
|  | 245 |  | 
|  | 246 | TEST_F(IGraphicBufferProducerTest, ConnectAgain_ReturnsError) { | 
|  | 247 | ASSERT_NO_FATAL_FAILURE(ConnectProducer()); | 
|  | 248 |  | 
|  | 249 | // Can't connect when there is already a producer connected | 
|  | 250 | IGraphicBufferProducer::QueueBufferOutput output; | 
|  | 251 | EXPECT_EQ(BAD_VALUE, mProducer->connect(TEST_TOKEN, | 
|  | 252 | TEST_API, | 
|  | 253 | TEST_CONTROLLED_BY_APP, | 
|  | 254 | &output)); | 
|  | 255 |  | 
|  | 256 | ASSERT_OK(mConsumer->consumerDisconnect()); | 
|  | 257 | // Can't connect when IGBP is abandoned | 
|  | 258 | EXPECT_EQ(NO_INIT, mProducer->connect(TEST_TOKEN, | 
|  | 259 | TEST_API, | 
|  | 260 | TEST_CONTROLLED_BY_APP, | 
|  | 261 | &output)); | 
|  | 262 | } | 
|  | 263 |  | 
|  | 264 | TEST_F(IGraphicBufferProducerTest, Disconnect_Succeeds) { | 
|  | 265 | ASSERT_NO_FATAL_FAILURE(ConnectProducer()); | 
|  | 266 |  | 
|  | 267 | ASSERT_OK(mProducer->disconnect(TEST_API)); | 
|  | 268 | } | 
|  | 269 |  | 
|  | 270 |  | 
|  | 271 | TEST_F(IGraphicBufferProducerTest, Disconnect_ReturnsError) { | 
|  | 272 | ASSERT_NO_FATAL_FAILURE(ConnectProducer()); | 
|  | 273 |  | 
|  | 274 | // Must disconnect with same API number | 
|  | 275 | ASSERT_EQ(BAD_VALUE, mProducer->disconnect(TEST_API_OTHER)); | 
|  | 276 | // API must not be out of range | 
|  | 277 | ASSERT_EQ(BAD_VALUE, mProducer->disconnect(/*api*/0xDEADBEEF)); | 
|  | 278 |  | 
|  | 279 | // TODO: somehow kill mProducer so that this returns DEAD_OBJECT | 
|  | 280 | } | 
|  | 281 |  | 
|  | 282 | TEST_F(IGraphicBufferProducerTest, Query_Succeeds) { | 
|  | 283 | ASSERT_NO_FATAL_FAILURE(ConnectProducer()); | 
|  | 284 |  | 
| Dan Stoza | f8cebe5 | 2015-04-20 12:09:38 -0700 | [diff] [blame] | 285 | int32_t value = -1; | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 286 | EXPECT_OK(mProducer->query(NATIVE_WINDOW_WIDTH, &value)); | 
| Dan Stoza | f8cebe5 | 2015-04-20 12:09:38 -0700 | [diff] [blame] | 287 | EXPECT_EQ(DEFAULT_WIDTH, static_cast<uint32_t>(value)); | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 288 |  | 
|  | 289 | EXPECT_OK(mProducer->query(NATIVE_WINDOW_HEIGHT, &value)); | 
| Dan Stoza | f8cebe5 | 2015-04-20 12:09:38 -0700 | [diff] [blame] | 290 | EXPECT_EQ(DEFAULT_HEIGHT, static_cast<uint32_t>(value)); | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 291 |  | 
|  | 292 | EXPECT_OK(mProducer->query(NATIVE_WINDOW_FORMAT, &value)); | 
|  | 293 | EXPECT_EQ(DEFAULT_FORMAT, value); | 
|  | 294 |  | 
|  | 295 | EXPECT_OK(mProducer->query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, &value)); | 
|  | 296 | EXPECT_LE(0, value); | 
|  | 297 | EXPECT_GE(BufferQueue::NUM_BUFFER_SLOTS, value); | 
|  | 298 |  | 
|  | 299 | EXPECT_OK(mProducer->query(NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND, &value)); | 
|  | 300 | EXPECT_FALSE(value); // Can't run behind when we haven't touched the queue | 
|  | 301 |  | 
|  | 302 | EXPECT_OK(mProducer->query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, &value)); | 
|  | 303 | EXPECT_EQ(DEFAULT_CONSUMER_USAGE_BITS, value); | 
|  | 304 |  | 
|  | 305 | } | 
|  | 306 |  | 
|  | 307 | TEST_F(IGraphicBufferProducerTest, Query_ReturnsError) { | 
|  | 308 | ASSERT_NO_FATAL_FAILURE(ConnectProducer()); | 
|  | 309 |  | 
|  | 310 | // One past the end of the last 'query' enum value. Update this if we add more enums. | 
| Michael Lentine | d8ead0c | 2015-05-19 15:23:43 -0700 | [diff] [blame] | 311 | const int NATIVE_WINDOW_QUERY_LAST_OFF_BY_ONE = NATIVE_WINDOW_BUFFER_AGE + 1; | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 312 |  | 
|  | 313 | int value; | 
|  | 314 | // What was out of range | 
|  | 315 | EXPECT_EQ(BAD_VALUE, mProducer->query(/*what*/-1, &value)); | 
|  | 316 | EXPECT_EQ(BAD_VALUE, mProducer->query(/*what*/0xDEADBEEF, &value)); | 
|  | 317 | EXPECT_EQ(BAD_VALUE, mProducer->query(NATIVE_WINDOW_QUERY_LAST_OFF_BY_ONE, &value)); | 
|  | 318 |  | 
|  | 319 | // Some enums from window.h are 'invalid' | 
|  | 320 | EXPECT_EQ(BAD_VALUE, mProducer->query(NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER, &value)); | 
|  | 321 | EXPECT_EQ(BAD_VALUE, mProducer->query(NATIVE_WINDOW_CONCRETE_TYPE, &value)); | 
|  | 322 | EXPECT_EQ(BAD_VALUE, mProducer->query(NATIVE_WINDOW_DEFAULT_WIDTH, &value)); | 
|  | 323 | EXPECT_EQ(BAD_VALUE, mProducer->query(NATIVE_WINDOW_DEFAULT_HEIGHT, &value)); | 
|  | 324 | EXPECT_EQ(BAD_VALUE, mProducer->query(NATIVE_WINDOW_TRANSFORM_HINT, &value)); | 
|  | 325 | // TODO: Consider documented the above enums as unsupported or make a new enum for IGBP | 
|  | 326 |  | 
|  | 327 | // Value was NULL | 
|  | 328 | EXPECT_EQ(BAD_VALUE, mProducer->query(NATIVE_WINDOW_FORMAT, /*value*/NULL)); | 
|  | 329 |  | 
|  | 330 | ASSERT_OK(mConsumer->consumerDisconnect()); | 
|  | 331 |  | 
|  | 332 | // BQ was abandoned | 
|  | 333 | EXPECT_EQ(NO_INIT, mProducer->query(NATIVE_WINDOW_FORMAT, &value)); | 
|  | 334 |  | 
|  | 335 | // TODO: other things in window.h that are supported by Surface::query | 
|  | 336 | // but not by BufferQueue::query | 
|  | 337 | } | 
|  | 338 |  | 
|  | 339 | // TODO: queue under more complicated situations not involving just a single buffer | 
|  | 340 | TEST_F(IGraphicBufferProducerTest, Queue_Succeeds) { | 
|  | 341 | ASSERT_NO_FATAL_FAILURE(ConnectProducer()); | 
|  | 342 |  | 
|  | 343 | int dequeuedSlot = -1; | 
|  | 344 | sp<Fence> dequeuedFence; | 
|  | 345 |  | 
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 346 |  | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 347 | ASSERT_EQ(OK, ~IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION & | 
|  | 348 | (mProducer->dequeueBuffer(&dequeuedSlot, &dequeuedFence, | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 349 | DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_FORMAT, | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 350 | TEST_PRODUCER_USAGE_BITS, nullptr))); | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 351 |  | 
|  | 352 | EXPECT_LE(0, dequeuedSlot); | 
|  | 353 | EXPECT_GT(BufferQueue::NUM_BUFFER_SLOTS, dequeuedSlot); | 
|  | 354 |  | 
|  | 355 | // Request the buffer (pre-requisite for queueing) | 
|  | 356 | sp<GraphicBuffer> dequeuedBuffer; | 
|  | 357 | ASSERT_OK(mProducer->requestBuffer(dequeuedSlot, &dequeuedBuffer)); | 
|  | 358 |  | 
|  | 359 | // A generic "valid" input | 
|  | 360 | IGraphicBufferProducer::QueueBufferInput input = CreateBufferInput(); | 
|  | 361 | IGraphicBufferProducer::QueueBufferOutput output; | 
|  | 362 |  | 
|  | 363 | // Queue the buffer back into the BQ | 
|  | 364 | ASSERT_OK(mProducer->queueBuffer(dequeuedSlot, input, &output)); | 
|  | 365 |  | 
|  | 366 | { | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 367 | EXPECT_EQ(DEFAULT_WIDTH, output.width); | 
|  | 368 | EXPECT_EQ(DEFAULT_HEIGHT, output.height); | 
|  | 369 | EXPECT_EQ(DEFAULT_TRANSFORM_HINT, output.transformHint); | 
|  | 370 | // Since queueBuffer was called exactly once | 
|  | 371 | EXPECT_EQ(1u, output.numPendingBuffers); | 
|  | 372 | EXPECT_EQ(2u, output.nextFrameNumber); | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 373 | } | 
|  | 374 |  | 
|  | 375 | // Buffer was not in the dequeued state | 
|  | 376 | EXPECT_EQ(BAD_VALUE, mProducer->queueBuffer(dequeuedSlot, input, &output)); | 
|  | 377 | } | 
|  | 378 |  | 
|  | 379 | TEST_F(IGraphicBufferProducerTest, Queue_ReturnsError) { | 
|  | 380 | ASSERT_NO_FATAL_FAILURE(ConnectProducer()); | 
|  | 381 |  | 
|  | 382 | // Invalid slot number | 
|  | 383 | { | 
|  | 384 | // A generic "valid" input | 
|  | 385 | IGraphicBufferProducer::QueueBufferInput input = CreateBufferInput(); | 
|  | 386 | IGraphicBufferProducer::QueueBufferOutput output; | 
|  | 387 |  | 
|  | 388 | EXPECT_EQ(BAD_VALUE, mProducer->queueBuffer(/*slot*/-1, input, &output)); | 
|  | 389 | EXPECT_EQ(BAD_VALUE, mProducer->queueBuffer(/*slot*/0xDEADBEEF, input, &output)); | 
|  | 390 | EXPECT_EQ(BAD_VALUE, mProducer->queueBuffer(BufferQueue::NUM_BUFFER_SLOTS, | 
|  | 391 | input, &output)); | 
|  | 392 | } | 
|  | 393 |  | 
|  | 394 | // Slot was not in the dequeued state (all slots start out in Free state) | 
|  | 395 | { | 
|  | 396 | IGraphicBufferProducer::QueueBufferInput input = CreateBufferInput(); | 
|  | 397 | IGraphicBufferProducer::QueueBufferOutput output; | 
|  | 398 |  | 
|  | 399 | EXPECT_EQ(BAD_VALUE, mProducer->queueBuffer(/*slot*/0, input, &output)); | 
|  | 400 | } | 
|  | 401 |  | 
|  | 402 | // Put the slot into the "dequeued" state for the rest of the test | 
|  | 403 | int dequeuedSlot = -1; | 
|  | 404 | sp<Fence> dequeuedFence; | 
|  | 405 |  | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 406 | ASSERT_EQ(OK, ~IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION & | 
|  | 407 | (mProducer->dequeueBuffer(&dequeuedSlot, &dequeuedFence, | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 408 | DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_FORMAT, | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 409 | TEST_PRODUCER_USAGE_BITS, nullptr))); | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 410 |  | 
|  | 411 | // Slot was enqueued without requesting a buffer | 
|  | 412 | { | 
|  | 413 | IGraphicBufferProducer::QueueBufferInput input = CreateBufferInput(); | 
|  | 414 | IGraphicBufferProducer::QueueBufferOutput output; | 
|  | 415 |  | 
|  | 416 | EXPECT_EQ(BAD_VALUE, mProducer->queueBuffer(dequeuedSlot, input, &output)); | 
|  | 417 | } | 
|  | 418 |  | 
|  | 419 | // Request the buffer so that the rest of the tests don't fail on earlier checks. | 
|  | 420 | sp<GraphicBuffer> dequeuedBuffer; | 
|  | 421 | ASSERT_OK(mProducer->requestBuffer(dequeuedSlot, &dequeuedBuffer)); | 
|  | 422 |  | 
|  | 423 | // Fence was NULL | 
|  | 424 | { | 
|  | 425 | sp<Fence> nullFence = NULL; | 
|  | 426 |  | 
|  | 427 | IGraphicBufferProducer::QueueBufferInput input = | 
|  | 428 | QueueBufferInputBuilder().setFence(nullFence).build(); | 
|  | 429 | IGraphicBufferProducer::QueueBufferOutput output; | 
|  | 430 |  | 
|  | 431 | EXPECT_EQ(BAD_VALUE, mProducer->queueBuffer(dequeuedSlot, input, &output)); | 
|  | 432 | } | 
|  | 433 |  | 
|  | 434 | // Scaling mode was unknown | 
|  | 435 | { | 
|  | 436 | IGraphicBufferProducer::QueueBufferInput input = | 
|  | 437 | QueueBufferInputBuilder().setScalingMode(-1).build(); | 
|  | 438 | IGraphicBufferProducer::QueueBufferOutput output; | 
|  | 439 |  | 
|  | 440 | EXPECT_EQ(BAD_VALUE, mProducer->queueBuffer(dequeuedSlot, input, &output)); | 
|  | 441 |  | 
|  | 442 | input = QueueBufferInputBuilder().setScalingMode(0xDEADBEEF).build(); | 
|  | 443 |  | 
|  | 444 | EXPECT_EQ(BAD_VALUE, mProducer->queueBuffer(dequeuedSlot, input, &output)); | 
|  | 445 | } | 
|  | 446 |  | 
|  | 447 | // Crop rect is out of bounds of the buffer dimensions | 
|  | 448 | { | 
|  | 449 | IGraphicBufferProducer::QueueBufferInput input = | 
|  | 450 | QueueBufferInputBuilder().setCrop(Rect(DEFAULT_WIDTH + 1, DEFAULT_HEIGHT + 1)) | 
|  | 451 | .build(); | 
|  | 452 | IGraphicBufferProducer::QueueBufferOutput output; | 
|  | 453 |  | 
|  | 454 | EXPECT_EQ(BAD_VALUE, mProducer->queueBuffer(dequeuedSlot, input, &output)); | 
|  | 455 | } | 
|  | 456 |  | 
|  | 457 | // Abandon the buffer queue so that the last test fails | 
|  | 458 | ASSERT_OK(mConsumer->consumerDisconnect()); | 
|  | 459 |  | 
|  | 460 | // The buffer queue has been abandoned. | 
|  | 461 | { | 
|  | 462 | IGraphicBufferProducer::QueueBufferInput input = CreateBufferInput(); | 
|  | 463 | IGraphicBufferProducer::QueueBufferOutput output; | 
|  | 464 |  | 
|  | 465 | EXPECT_EQ(NO_INIT, mProducer->queueBuffer(dequeuedSlot, input, &output)); | 
|  | 466 | } | 
|  | 467 | } | 
|  | 468 |  | 
|  | 469 | TEST_F(IGraphicBufferProducerTest, CancelBuffer_DoesntCrash) { | 
|  | 470 | ASSERT_NO_FATAL_FAILURE(ConnectProducer()); | 
|  | 471 |  | 
|  | 472 | int dequeuedSlot = -1; | 
|  | 473 | sp<Fence> dequeuedFence; | 
|  | 474 |  | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 475 | ASSERT_EQ(OK, ~IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION & | 
|  | 476 | (mProducer->dequeueBuffer(&dequeuedSlot, &dequeuedFence, | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 477 | DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_FORMAT, | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 478 | TEST_PRODUCER_USAGE_BITS, nullptr))); | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 479 |  | 
|  | 480 | // No return code, but at least test that it doesn't blow up... | 
|  | 481 | // TODO: add a return code | 
|  | 482 | mProducer->cancelBuffer(dequeuedSlot, dequeuedFence); | 
|  | 483 | } | 
|  | 484 |  | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 485 | TEST_F(IGraphicBufferProducerTest, SetMaxDequeuedBufferCount_Succeeds) { | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 486 | ASSERT_NO_FATAL_FAILURE(ConnectProducer()); | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 487 | int minUndequeuedBuffers; | 
|  | 488 | ASSERT_OK(mProducer->query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, | 
|  | 489 | &minUndequeuedBuffers)); | 
|  | 490 |  | 
|  | 491 | const int minBuffers = 1; | 
|  | 492 | const int maxBuffers = BufferQueue::NUM_BUFFER_SLOTS - minUndequeuedBuffers; | 
|  | 493 |  | 
|  | 494 | ASSERT_OK(mProducer->setAsyncMode(false)) << "async mode: " << false; | 
|  | 495 | ASSERT_OK(mProducer->setMaxDequeuedBufferCount(minBuffers)) | 
|  | 496 | << "bufferCount: " << minBuffers; | 
|  | 497 |  | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 498 | // Should now be able to dequeue up to minBuffers times | 
| Pablo Ceballos | 72daab6 | 2015-12-07 16:38:43 -0800 | [diff] [blame] | 499 | DequeueBufferResult result; | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 500 | for (int i = 0; i < minBuffers; ++i) { | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 501 |  | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 502 | EXPECT_EQ(OK, ~IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION & | 
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 503 | (dequeueBuffer(DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_FORMAT, | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 504 | TEST_PRODUCER_USAGE_BITS, &result))) | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 505 | << "iteration: " << i << ", slot: " << result.slot; | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 506 | } | 
|  | 507 |  | 
|  | 508 | ASSERT_OK(mProducer->setMaxDequeuedBufferCount(maxBuffers)); | 
|  | 509 |  | 
| Pablo Ceballos | 72daab6 | 2015-12-07 16:38:43 -0800 | [diff] [blame] | 510 | // queue the first buffer to enable max dequeued buffer count checking | 
|  | 511 | IGraphicBufferProducer::QueueBufferInput input = CreateBufferInput(); | 
|  | 512 | IGraphicBufferProducer::QueueBufferOutput output; | 
|  | 513 | sp<GraphicBuffer> buffer; | 
|  | 514 | ASSERT_OK(mProducer->requestBuffer(result.slot, &buffer)); | 
|  | 515 | ASSERT_OK(mProducer->queueBuffer(result.slot, input, &output)); | 
|  | 516 |  | 
|  | 517 |  | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 518 | // Should now be able to dequeue up to maxBuffers times | 
| Pablo Ceballos | 72daab6 | 2015-12-07 16:38:43 -0800 | [diff] [blame] | 519 | int dequeuedSlot = -1; | 
|  | 520 | sp<Fence> dequeuedFence; | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 521 | for (int i = 0; i < maxBuffers; ++i) { | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 522 |  | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 523 | EXPECT_EQ(OK, ~IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION & | 
|  | 524 | (mProducer->dequeueBuffer(&dequeuedSlot, &dequeuedFence, | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 525 | DEFAULT_WIDTH, DEFAULT_HEIGHT, | 
|  | 526 | DEFAULT_FORMAT, | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 527 | TEST_PRODUCER_USAGE_BITS, nullptr))) | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 528 | << "iteration: " << i << ", slot: " << dequeuedSlot; | 
|  | 529 | } | 
| Pablo Ceballos | 72daab6 | 2015-12-07 16:38:43 -0800 | [diff] [blame] | 530 |  | 
|  | 531 | // Cancel a buffer, so we can decrease the buffer count | 
|  | 532 | ASSERT_OK(mProducer->cancelBuffer(dequeuedSlot, dequeuedFence)); | 
|  | 533 |  | 
|  | 534 | // Should now be able to decrease the max dequeued count by 1 | 
|  | 535 | ASSERT_OK(mProducer->setMaxDequeuedBufferCount(maxBuffers-1)); | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 536 | } | 
|  | 537 |  | 
|  | 538 | TEST_F(IGraphicBufferProducerTest, SetMaxDequeuedBufferCount_Fails) { | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 539 | ASSERT_NO_FATAL_FAILURE(ConnectProducer()); | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 540 | int minUndequeuedBuffers; | 
|  | 541 | ASSERT_OK(mProducer->query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, | 
|  | 542 | &minUndequeuedBuffers)); | 
|  | 543 |  | 
|  | 544 | const int minBuffers = 1; | 
|  | 545 | const int maxBuffers = BufferQueue::NUM_BUFFER_SLOTS - minUndequeuedBuffers; | 
|  | 546 |  | 
|  | 547 | ASSERT_OK(mProducer->setAsyncMode(false)) << "async mode: " << false; | 
|  | 548 | // Buffer count was out of range | 
|  | 549 | EXPECT_EQ(BAD_VALUE, mProducer->setMaxDequeuedBufferCount(0)) | 
|  | 550 | << "bufferCount: " << 0; | 
|  | 551 | EXPECT_EQ(BAD_VALUE, mProducer->setMaxDequeuedBufferCount(maxBuffers + 1)) | 
|  | 552 | << "bufferCount: " << maxBuffers + 1; | 
|  | 553 |  | 
| Pablo Ceballos | 72daab6 | 2015-12-07 16:38:43 -0800 | [diff] [blame] | 554 | // Set max dequeue count to 2 | 
|  | 555 | ASSERT_OK(mProducer->setMaxDequeuedBufferCount(2)); | 
|  | 556 | // Dequeue 2 buffers | 
|  | 557 | int dequeuedSlot = -1; | 
|  | 558 | sp<Fence> dequeuedFence; | 
|  | 559 | for (int i = 0; i < 2; i++) { | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 560 | ASSERT_EQ(OK, ~IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION & | 
|  | 561 | (mProducer->dequeueBuffer(&dequeuedSlot, &dequeuedFence, | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 562 | DEFAULT_WIDTH, DEFAULT_HEIGHT, | 
|  | 563 | DEFAULT_FORMAT, | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 564 | TEST_PRODUCER_USAGE_BITS, nullptr))) | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 565 | << "slot: " << dequeuedSlot; | 
|  | 566 | } | 
|  | 567 |  | 
| Pablo Ceballos | 72daab6 | 2015-12-07 16:38:43 -0800 | [diff] [blame] | 568 | // Client has too many buffers dequeued | 
|  | 569 | EXPECT_EQ(BAD_VALUE, mProducer->setMaxDequeuedBufferCount(1)) | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 570 | << "bufferCount: " << minBuffers; | 
|  | 571 |  | 
|  | 572 | // Abandon buffer queue | 
|  | 573 | ASSERT_OK(mConsumer->consumerDisconnect()); | 
|  | 574 |  | 
|  | 575 | // Fail because the buffer queue was abandoned | 
|  | 576 | EXPECT_EQ(NO_INIT, mProducer->setMaxDequeuedBufferCount(minBuffers)) | 
|  | 577 | << "bufferCount: " << minBuffers; | 
|  | 578 |  | 
|  | 579 | } | 
|  | 580 |  | 
|  | 581 | TEST_F(IGraphicBufferProducerTest, SetAsyncMode_Succeeds) { | 
|  | 582 | ASSERT_OK(mConsumer->setMaxAcquiredBufferCount(1)) << "maxAcquire: " << 1; | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 583 | ASSERT_NO_FATAL_FAILURE(ConnectProducer()); | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 584 | ASSERT_OK(mProducer->setAsyncMode(true)) << "async mode: " << true; | 
|  | 585 | ASSERT_OK(mProducer->setMaxDequeuedBufferCount(1)) << "maxDequeue: " << 1; | 
|  | 586 |  | 
|  | 587 | int dequeuedSlot = -1; | 
|  | 588 | sp<Fence> dequeuedFence; | 
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 589 | IGraphicBufferProducer::QueueBufferInput input = CreateBufferInput(); | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 590 | IGraphicBufferProducer::QueueBufferOutput output; | 
|  | 591 | sp<GraphicBuffer> dequeuedBuffer; | 
|  | 592 |  | 
|  | 593 | // Should now be able to queue/dequeue as many buffers as we want without | 
|  | 594 | // blocking | 
|  | 595 | for (int i = 0; i < 5; ++i) { | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 596 | ASSERT_EQ(OK, ~IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION & | 
|  | 597 | (mProducer->dequeueBuffer(&dequeuedSlot, &dequeuedFence, | 
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 598 | DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_FORMAT, | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 599 | TEST_PRODUCER_USAGE_BITS, nullptr))) | 
|  | 600 | << "slot : " << dequeuedSlot; | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 601 | ASSERT_OK(mProducer->requestBuffer(dequeuedSlot, &dequeuedBuffer)); | 
|  | 602 | ASSERT_OK(mProducer->queueBuffer(dequeuedSlot, input, &output)); | 
|  | 603 | } | 
|  | 604 | } | 
|  | 605 |  | 
|  | 606 | TEST_F(IGraphicBufferProducerTest, SetAsyncMode_Fails) { | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 607 | ASSERT_NO_FATAL_FAILURE(ConnectProducer()); | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 608 | // Prerequisite to fail out a valid setBufferCount call | 
|  | 609 | { | 
|  | 610 | int dequeuedSlot = -1; | 
|  | 611 | sp<Fence> dequeuedFence; | 
|  | 612 |  | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 613 | ASSERT_EQ(OK, ~IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION & | 
|  | 614 | (mProducer->dequeueBuffer(&dequeuedSlot, &dequeuedFence, | 
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 615 | DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_FORMAT, | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 616 | TEST_PRODUCER_USAGE_BITS, nullptr))) | 
|  | 617 | << "slot: " << dequeuedSlot; | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 618 | } | 
|  | 619 |  | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 620 | // Abandon buffer queue | 
|  | 621 | ASSERT_OK(mConsumer->consumerDisconnect()); | 
|  | 622 |  | 
|  | 623 | // Fail because the buffer queue was abandoned | 
|  | 624 | EXPECT_EQ(NO_INIT, mProducer->setAsyncMode(false)) << "asyncMode: " | 
|  | 625 | << false; | 
|  | 626 | } | 
|  | 627 |  | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 628 | TEST_F(IGraphicBufferProducerTest, | 
|  | 629 | DisconnectedProducerReturnsError_dequeueBuffer) { | 
|  | 630 | int slot = -1; | 
|  | 631 | sp<Fence> fence; | 
|  | 632 |  | 
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 633 | ASSERT_EQ(NO_INIT, mProducer->dequeueBuffer(&slot, &fence, DEFAULT_WIDTH, | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 634 | DEFAULT_HEIGHT, DEFAULT_FORMAT, TEST_PRODUCER_USAGE_BITS, nullptr)); | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 635 | } | 
|  | 636 |  | 
|  | 637 | TEST_F(IGraphicBufferProducerTest, | 
|  | 638 | DisconnectedProducerReturnsError_detachNextBuffer) { | 
|  | 639 | sp<Fence> fence; | 
|  | 640 | sp<GraphicBuffer> buffer; | 
|  | 641 |  | 
|  | 642 | ASSERT_EQ(NO_INIT, mProducer->detachNextBuffer(&buffer, &fence)); | 
|  | 643 | } | 
|  | 644 |  | 
|  | 645 | TEST_F(IGraphicBufferProducerTest, | 
|  | 646 | DisconnectedProducerReturnsError_requestBuffer) { | 
|  | 647 | ASSERT_NO_FATAL_FAILURE(ConnectProducer()); | 
|  | 648 |  | 
|  | 649 | int slot = -1; | 
|  | 650 | sp<Fence> fence; | 
|  | 651 |  | 
|  | 652 | ASSERT_EQ(OK, ~IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION & | 
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 653 | (mProducer->dequeueBuffer(&slot, &fence, DEFAULT_WIDTH, | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 654 | DEFAULT_HEIGHT, DEFAULT_FORMAT, TEST_PRODUCER_USAGE_BITS, | 
|  | 655 | nullptr))); | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 656 |  | 
|  | 657 | EXPECT_LE(0, slot); | 
|  | 658 | EXPECT_GT(BufferQueue::NUM_BUFFER_SLOTS, slot); | 
|  | 659 |  | 
|  | 660 | ASSERT_OK(mProducer->disconnect(TEST_API)); | 
|  | 661 |  | 
|  | 662 | sp<GraphicBuffer> buffer; | 
|  | 663 |  | 
|  | 664 | ASSERT_EQ(NO_INIT, mProducer->requestBuffer(slot, &buffer)); | 
|  | 665 | } | 
|  | 666 |  | 
|  | 667 |  | 
|  | 668 | TEST_F(IGraphicBufferProducerTest, | 
|  | 669 | DisconnectedProducerReturnsError_detachBuffer) { | 
|  | 670 | int slot = -1; | 
|  | 671 | sp<Fence> fence; | 
|  | 672 | sp<GraphicBuffer> buffer; | 
|  | 673 |  | 
|  | 674 | setupDequeueRequestBuffer(&slot, &fence, &buffer); | 
|  | 675 |  | 
|  | 676 | ASSERT_OK(mProducer->disconnect(TEST_API)); | 
|  | 677 |  | 
|  | 678 | ASSERT_EQ(NO_INIT, mProducer->detachBuffer(slot)); | 
|  | 679 | } | 
|  | 680 |  | 
|  | 681 | TEST_F(IGraphicBufferProducerTest, | 
|  | 682 | DisconnectedProducerReturnsError_queueBuffer) { | 
|  | 683 | int slot = -1; | 
|  | 684 | sp<Fence> fence; | 
|  | 685 | sp<GraphicBuffer> buffer; | 
|  | 686 |  | 
|  | 687 | setupDequeueRequestBuffer(&slot, &fence, &buffer); | 
|  | 688 |  | 
|  | 689 | ASSERT_OK(mProducer->disconnect(TEST_API)); | 
|  | 690 |  | 
|  | 691 | // A generic "valid" input | 
|  | 692 | IGraphicBufferProducer::QueueBufferInput input = CreateBufferInput(); | 
|  | 693 | IGraphicBufferProducer::QueueBufferOutput output; | 
|  | 694 |  | 
|  | 695 | ASSERT_EQ(NO_INIT, mProducer->queueBuffer(slot, input, &output)); | 
|  | 696 | } | 
|  | 697 |  | 
|  | 698 | TEST_F(IGraphicBufferProducerTest, | 
|  | 699 | DisconnectedProducerReturnsError_cancelBuffer) { | 
|  | 700 | int slot = -1; | 
|  | 701 | sp<Fence> fence; | 
|  | 702 | sp<GraphicBuffer> buffer; | 
|  | 703 |  | 
|  | 704 | setupDequeueRequestBuffer(&slot, &fence, &buffer); | 
|  | 705 |  | 
|  | 706 | ASSERT_OK(mProducer->disconnect(TEST_API)); | 
|  | 707 |  | 
|  | 708 | ASSERT_EQ(NO_INIT, mProducer->cancelBuffer(slot, fence)); | 
|  | 709 | } | 
|  | 710 |  | 
|  | 711 | TEST_F(IGraphicBufferProducerTest, | 
|  | 712 | DisconnectedProducerReturnsError_attachBuffer) { | 
|  | 713 | int slot = -1; | 
|  | 714 | sp<Fence> fence; | 
|  | 715 | sp<GraphicBuffer> buffer; | 
|  | 716 |  | 
|  | 717 | setupDequeueRequestBuffer(&slot, &fence, &buffer); | 
|  | 718 |  | 
|  | 719 | ASSERT_OK(mProducer->detachBuffer(slot)); | 
|  | 720 |  | 
|  | 721 | ASSERT_OK(mProducer->disconnect(TEST_API)); | 
|  | 722 |  | 
|  | 723 | ASSERT_EQ(NO_INIT, mProducer->attachBuffer(&slot, buffer)); | 
|  | 724 | } | 
|  | 725 |  | 
| Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 726 | } // namespace android |