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