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