Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 "BLASTBufferQueue_test" |
| 18 | |
| 19 | #include <gui/BLASTBufferQueue.h> |
| 20 | |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 21 | #include <android/hardware/graphics/common/1.2/types.h> |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 22 | #include <gui/BufferQueueCore.h> |
| 23 | #include <gui/BufferQueueProducer.h> |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 24 | #include <gui/FrameTimestamps.h> |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 25 | #include <gui/IGraphicBufferProducer.h> |
| 26 | #include <gui/IProducerListener.h> |
Vishnu Nair | 17dde61 | 2020-12-28 11:39:59 -0800 | [diff] [blame] | 27 | #include <gui/Surface.h> |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 28 | #include <gui/SurfaceComposerClient.h> |
chaviw | e7b9f27 | 2020-08-18 16:08:59 -0700 | [diff] [blame] | 29 | #include <gui/SyncScreenCaptureListener.h> |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 30 | #include <private/gui/ComposerService.h> |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 31 | #include <ui/DisplayConfig.h> |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 32 | #include <ui/GraphicBuffer.h> |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 33 | #include <ui/GraphicTypes.h> |
Valerie Hau | 8cee3f9 | 2019-11-06 10:06:28 -0800 | [diff] [blame] | 34 | #include <ui/Transform.h> |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 35 | |
| 36 | #include <gtest/gtest.h> |
| 37 | |
| 38 | using namespace std::chrono_literals; |
| 39 | |
| 40 | namespace android { |
| 41 | |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 42 | using Transaction = SurfaceComposerClient::Transaction; |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 43 | using android::hardware::graphics::common::V1_2::BufferUsage; |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 44 | |
| 45 | class BLASTBufferQueueHelper { |
| 46 | public: |
| 47 | BLASTBufferQueueHelper(const sp<SurfaceControl>& sc, int width, int height) { |
chaviw | 565ee54 | 2021-01-14 10:21:23 -0800 | [diff] [blame^] | 48 | mBlastBufferQueueAdapter = new BLASTBufferQueue("TestBLASTBufferQueue", sc, width, height, |
| 49 | PIXEL_FORMAT_RGBA_8888); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void update(const sp<SurfaceControl>& sc, int width, int height) { |
chaviw | 565ee54 | 2021-01-14 10:21:23 -0800 | [diff] [blame^] | 53 | mBlastBufferQueueAdapter->update(sc, width, height, PIXEL_FORMAT_RGBA_8888); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | void setNextTransaction(Transaction* next) { |
| 57 | mBlastBufferQueueAdapter->setNextTransaction(next); |
| 58 | } |
| 59 | |
Vishnu Nair | ea0de00 | 2020-11-17 17:42:37 -0800 | [diff] [blame] | 60 | int getWidth() { return mBlastBufferQueueAdapter->mSize.width; } |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 61 | |
Vishnu Nair | ea0de00 | 2020-11-17 17:42:37 -0800 | [diff] [blame] | 62 | int getHeight() { return mBlastBufferQueueAdapter->mSize.height; } |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 63 | |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 64 | Transaction* getNextTransaction() { return mBlastBufferQueueAdapter->mNextTransaction; } |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 65 | |
| 66 | sp<IGraphicBufferProducer> getIGraphicBufferProducer() { |
| 67 | return mBlastBufferQueueAdapter->getIGraphicBufferProducer(); |
| 68 | } |
| 69 | |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 70 | const sp<SurfaceControl> getSurfaceControl() { |
| 71 | return mBlastBufferQueueAdapter->mSurfaceControl; |
| 72 | } |
| 73 | |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 74 | void waitForCallbacks() { |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 75 | std::unique_lock lock{mBlastBufferQueueAdapter->mMutex}; |
Valerie Hau | a32c552 | 2019-12-09 10:11:08 -0800 | [diff] [blame] | 76 | while (mBlastBufferQueueAdapter->mSubmitted.size() > 0) { |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 77 | mBlastBufferQueueAdapter->mCallbackCV.wait(lock); |
| 78 | } |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 81 | private: |
| 82 | sp<BLASTBufferQueue> mBlastBufferQueueAdapter; |
| 83 | }; |
| 84 | |
| 85 | class BLASTBufferQueueTest : public ::testing::Test { |
| 86 | public: |
| 87 | protected: |
| 88 | BLASTBufferQueueTest() { |
| 89 | const ::testing::TestInfo* const testInfo = |
| 90 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 91 | ALOGV("Begin test: %s.%s", testInfo->test_case_name(), testInfo->name()); |
| 92 | } |
| 93 | |
| 94 | ~BLASTBufferQueueTest() { |
| 95 | const ::testing::TestInfo* const testInfo = |
| 96 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 97 | ALOGV("End test: %s.%s", testInfo->test_case_name(), testInfo->name()); |
| 98 | } |
| 99 | |
| 100 | void SetUp() { |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 101 | mComposer = ComposerService::getComposerService(); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 102 | mClient = new SurfaceComposerClient(); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 103 | mDisplayToken = mClient->getInternalDisplayToken(); |
| 104 | ASSERT_NE(nullptr, mDisplayToken.get()); |
| 105 | Transaction t; |
| 106 | t.setDisplayLayerStack(mDisplayToken, 0); |
| 107 | t.apply(); |
| 108 | t.clear(); |
| 109 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 110 | DisplayConfig config; |
| 111 | ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(mDisplayToken, &config)); |
| 112 | const ui::Size& resolution = config.resolution; |
| 113 | mDisplayWidth = resolution.getWidth(); |
| 114 | mDisplayHeight = resolution.getHeight(); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 115 | |
| 116 | mSurfaceControl = mClient->createSurface(String8("TestSurface"), mDisplayWidth, |
| 117 | mDisplayHeight, PIXEL_FORMAT_RGBA_8888, |
| 118 | ISurfaceComposerClient::eFXSurfaceBufferState, |
| 119 | /*parent*/ nullptr); |
| 120 | t.setLayerStack(mSurfaceControl, 0) |
| 121 | .setLayer(mSurfaceControl, std::numeric_limits<int32_t>::max()) |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 122 | .setFrame(mSurfaceControl, Rect(resolution)) |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 123 | .show(mSurfaceControl) |
| 124 | .setDataspace(mSurfaceControl, ui::Dataspace::V0_SRGB) |
| 125 | .apply(); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 126 | |
| 127 | mCaptureArgs.displayToken = mDisplayToken; |
arthurhung | 6fa58b7 | 2020-11-05 11:56:00 +0800 | [diff] [blame] | 128 | mCaptureArgs.dataspace = ui::Dataspace::V0_SRGB; |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 131 | void setUpProducer(BLASTBufferQueueHelper adapter, sp<IGraphicBufferProducer>& producer) { |
| 132 | auto igbProducer = adapter.getIGraphicBufferProducer(); |
| 133 | ASSERT_NE(nullptr, igbProducer.get()); |
Valerie Hau | c78c43a | 2020-01-09 17:34:14 -0800 | [diff] [blame] | 134 | ASSERT_EQ(NO_ERROR, igbProducer->setMaxDequeuedBufferCount(2)); |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 135 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 136 | ASSERT_EQ(NO_ERROR, |
Peiyong Lin | d8460c8 | 2020-07-28 16:04:22 -0700 | [diff] [blame] | 137 | igbProducer->connect(new StubProducerListener, NATIVE_WINDOW_API_CPU, false, |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 138 | &qbOutput)); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 139 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 140 | producer = igbProducer; |
| 141 | } |
| 142 | |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 143 | void fillBuffer(uint32_t* bufData, Rect rect, uint32_t stride, uint8_t r, uint8_t g, |
| 144 | uint8_t b) { |
| 145 | for (uint32_t row = rect.top; row < rect.bottom; row++) { |
| 146 | for (uint32_t col = rect.left; col < rect.right; col++) { |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 147 | uint8_t* pixel = (uint8_t*)(bufData + (row * stride) + col); |
| 148 | *pixel = r; |
| 149 | *(pixel + 1) = g; |
| 150 | *(pixel + 2) = b; |
| 151 | *(pixel + 3) = 255; |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 156 | void fillQuadrants(sp<GraphicBuffer>& buf) { |
| 157 | const auto bufWidth = buf->getWidth(); |
| 158 | const auto bufHeight = buf->getHeight(); |
| 159 | uint32_t* bufData; |
| 160 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 161 | reinterpret_cast<void**>(&bufData)); |
| 162 | fillBuffer(bufData, Rect(0, 0, bufWidth / 2, bufHeight / 2), buf->getStride(), 0, 0, 0); |
| 163 | fillBuffer(bufData, Rect(bufWidth / 2, 0, bufWidth, bufHeight / 2), buf->getStride(), 255, |
| 164 | 0, 0); |
| 165 | fillBuffer(bufData, Rect(bufWidth / 2, bufHeight / 2, bufWidth, bufHeight), |
| 166 | buf->getStride(), 0, 255, 0); |
| 167 | fillBuffer(bufData, Rect(0, bufHeight / 2, bufWidth / 2, bufHeight), buf->getStride(), 0, 0, |
| 168 | 255); |
| 169 | buf->unlock(); |
| 170 | } |
| 171 | |
| 172 | void checkScreenCapture(uint8_t r, uint8_t g, uint8_t b, Rect region, int32_t border = 0, |
| 173 | bool outsideRegion = false) { |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 174 | sp<GraphicBuffer>& captureBuf = mCaptureResults.buffer; |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 175 | const auto epsilon = 3; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 176 | const auto width = captureBuf->getWidth(); |
| 177 | const auto height = captureBuf->getHeight(); |
| 178 | const auto stride = captureBuf->getStride(); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 179 | |
| 180 | uint32_t* bufData; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 181 | captureBuf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_READ_OFTEN), |
| 182 | reinterpret_cast<void**>(&bufData)); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 183 | |
| 184 | for (uint32_t row = 0; row < height; row++) { |
| 185 | for (uint32_t col = 0; col < width; col++) { |
| 186 | uint8_t* pixel = (uint8_t*)(bufData + (row * stride) + col); |
arthurhung | 6fa58b7 | 2020-11-05 11:56:00 +0800 | [diff] [blame] | 187 | ASSERT_NE(nullptr, pixel); |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 188 | bool inRegion; |
| 189 | if (!outsideRegion) { |
| 190 | inRegion = row >= region.top + border && row < region.bottom - border && |
| 191 | col >= region.left + border && col < region.right - border; |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 192 | } else { |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 193 | inRegion = row >= region.top - border && row < region.bottom + border && |
| 194 | col >= region.left - border && col < region.right + border; |
| 195 | } |
| 196 | if (!outsideRegion && inRegion) { |
| 197 | EXPECT_GE(epsilon, abs(r - *(pixel))); |
| 198 | EXPECT_GE(epsilon, abs(g - *(pixel + 1))); |
| 199 | EXPECT_GE(epsilon, abs(b - *(pixel + 2))); |
| 200 | } else if (outsideRegion && !inRegion) { |
| 201 | EXPECT_GE(epsilon, abs(r - *(pixel))); |
| 202 | EXPECT_GE(epsilon, abs(g - *(pixel + 1))); |
| 203 | EXPECT_GE(epsilon, abs(b - *(pixel + 2))); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 204 | } |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 205 | } |
| 206 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 207 | captureBuf->unlock(); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 208 | ASSERT_EQ(false, ::testing::Test::HasFailure()); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 209 | } |
| 210 | |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 211 | static status_t captureDisplay(DisplayCaptureArgs& captureArgs, |
| 212 | ScreenCaptureResults& captureResults) { |
| 213 | const auto sf = ComposerService::getComposerService(); |
| 214 | SurfaceComposerClient::Transaction().apply(true); |
| 215 | |
| 216 | const sp<SyncScreenCaptureListener> captureListener = new SyncScreenCaptureListener(); |
| 217 | status_t status = sf->captureDisplay(captureArgs, captureListener); |
| 218 | if (status != NO_ERROR) { |
| 219 | return status; |
| 220 | } |
| 221 | captureResults = captureListener->waitForResults(); |
| 222 | return captureResults.result; |
| 223 | } |
| 224 | |
Vishnu Nair | 277142c | 2021-01-05 18:35:29 -0800 | [diff] [blame] | 225 | void queueBuffer(sp<IGraphicBufferProducer> igbp, uint8_t r, uint8_t g, uint8_t b, |
| 226 | nsecs_t presentTimeDelay) { |
| 227 | int slot; |
| 228 | sp<Fence> fence; |
| 229 | sp<GraphicBuffer> buf; |
| 230 | auto ret = igbp->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 231 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 232 | nullptr, nullptr); |
| 233 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 234 | ASSERT_EQ(OK, igbp->requestBuffer(slot, &buf)); |
| 235 | |
| 236 | uint32_t* bufData; |
| 237 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 238 | reinterpret_cast<void**>(&bufData)); |
| 239 | fillBuffer(bufData, Rect(buf->getWidth(), buf->getHeight() / 2), buf->getStride(), r, g, b); |
| 240 | buf->unlock(); |
| 241 | |
| 242 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 243 | nsecs_t timestampNanos = systemTime() + presentTimeDelay; |
| 244 | IGraphicBufferProducer::QueueBufferInput input(timestampNanos, false, HAL_DATASPACE_UNKNOWN, |
| 245 | Rect(mDisplayWidth, mDisplayHeight / 2), |
| 246 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 247 | Fence::NO_FENCE); |
| 248 | igbp->queueBuffer(slot, input, &qbOutput); |
| 249 | } |
| 250 | |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 251 | sp<SurfaceComposerClient> mClient; |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 252 | sp<ISurfaceComposer> mComposer; |
| 253 | |
| 254 | sp<IBinder> mDisplayToken; |
| 255 | |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 256 | sp<SurfaceControl> mSurfaceControl; |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 257 | |
| 258 | uint32_t mDisplayWidth; |
| 259 | uint32_t mDisplayHeight; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 260 | |
| 261 | DisplayCaptureArgs mCaptureArgs; |
| 262 | ScreenCaptureResults mCaptureResults; |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 263 | }; |
| 264 | |
| 265 | TEST_F(BLASTBufferQueueTest, CreateBLASTBufferQueue) { |
| 266 | // create BLASTBufferQueue adapter associated with this surface |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 267 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 268 | ASSERT_EQ(mSurfaceControl, adapter.getSurfaceControl()); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 269 | ASSERT_EQ(mDisplayWidth, adapter.getWidth()); |
| 270 | ASSERT_EQ(mDisplayHeight, adapter.getHeight()); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 271 | ASSERT_EQ(nullptr, adapter.getNextTransaction()); |
| 272 | } |
| 273 | |
| 274 | TEST_F(BLASTBufferQueueTest, Update) { |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 275 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 276 | sp<SurfaceControl> updateSurface = |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 277 | mClient->createSurface(String8("UpdateTest"), mDisplayWidth / 2, mDisplayHeight / 2, |
| 278 | PIXEL_FORMAT_RGBA_8888); |
| 279 | adapter.update(updateSurface, mDisplayWidth / 2, mDisplayHeight / 2); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 280 | ASSERT_EQ(updateSurface, adapter.getSurfaceControl()); |
Vishnu Nair | ea0de00 | 2020-11-17 17:42:37 -0800 | [diff] [blame] | 281 | sp<IGraphicBufferProducer> igbProducer; |
| 282 | setUpProducer(adapter, igbProducer); |
| 283 | |
| 284 | int32_t width; |
| 285 | igbProducer->query(NATIVE_WINDOW_WIDTH, &width); |
| 286 | ASSERT_EQ(mDisplayWidth / 2, width); |
| 287 | int32_t height; |
| 288 | igbProducer->query(NATIVE_WINDOW_HEIGHT, &height); |
| 289 | ASSERT_EQ(mDisplayHeight / 2, height); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | TEST_F(BLASTBufferQueueTest, SetNextTransaction) { |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 293 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 294 | Transaction next; |
| 295 | adapter.setNextTransaction(&next); |
| 296 | ASSERT_EQ(&next, adapter.getNextTransaction()); |
| 297 | } |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 298 | |
Valerie Hau | bf29e04 | 2020-02-06 11:40:38 -0800 | [diff] [blame] | 299 | TEST_F(BLASTBufferQueueTest, DISABLED_onFrameAvailable_ApplyDesiredPresentTime) { |
Valerie Hau | 181abd3 | 2020-01-27 14:18:28 -0800 | [diff] [blame] | 300 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 301 | sp<IGraphicBufferProducer> igbProducer; |
| 302 | setUpProducer(adapter, igbProducer); |
| 303 | |
| 304 | int slot; |
| 305 | sp<Fence> fence; |
| 306 | sp<GraphicBuffer> buf; |
| 307 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 308 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 309 | nullptr, nullptr); |
| 310 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 311 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 312 | |
| 313 | nsecs_t desiredPresentTime = systemTime() + nsecs_t(5 * 1e8); |
| 314 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 315 | IGraphicBufferProducer::QueueBufferInput input(desiredPresentTime, false, HAL_DATASPACE_UNKNOWN, |
| 316 | Rect(mDisplayWidth, mDisplayHeight), |
| 317 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 318 | Fence::NO_FENCE); |
| 319 | igbProducer->queueBuffer(slot, input, &qbOutput); |
| 320 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
| 321 | |
| 322 | adapter.waitForCallbacks(); |
| 323 | ASSERT_GE(systemTime(), desiredPresentTime); |
| 324 | } |
| 325 | |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 326 | TEST_F(BLASTBufferQueueTest, onFrameAvailable_Apply) { |
| 327 | uint8_t r = 255; |
| 328 | uint8_t g = 0; |
| 329 | uint8_t b = 0; |
| 330 | |
| 331 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 332 | sp<IGraphicBufferProducer> igbProducer; |
| 333 | setUpProducer(adapter, igbProducer); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 334 | |
| 335 | int slot; |
| 336 | sp<Fence> fence; |
| 337 | sp<GraphicBuffer> buf; |
| 338 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 339 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 340 | nullptr, nullptr); |
| 341 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 342 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 343 | |
| 344 | uint32_t* bufData; |
| 345 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 346 | reinterpret_cast<void**>(&bufData)); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 347 | fillBuffer(bufData, Rect(buf->getWidth(), buf->getHeight()), buf->getStride(), r, g, b); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 348 | buf->unlock(); |
| 349 | |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 350 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 351 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), false, HAL_DATASPACE_UNKNOWN, |
| 352 | Rect(mDisplayWidth, mDisplayHeight), |
| 353 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 354 | Fence::NO_FENCE); |
| 355 | igbProducer->queueBuffer(slot, input, &qbOutput); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 356 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 357 | |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 358 | adapter.waitForCallbacks(); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 359 | |
| 360 | // capture screen and verify that it is red |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 361 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 362 | ASSERT_NO_FATAL_FAILURE( |
| 363 | checkScreenCapture(r, g, b, {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight})); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 364 | } |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 365 | |
| 366 | TEST_F(BLASTBufferQueueTest, TripleBuffering) { |
| 367 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 368 | sp<IGraphicBufferProducer> igbProducer; |
| 369 | setUpProducer(adapter, igbProducer); |
| 370 | |
| 371 | std::vector<std::pair<int, sp<Fence>>> allocated; |
| 372 | for (int i = 0; i < 3; i++) { |
| 373 | int slot; |
| 374 | sp<Fence> fence; |
| 375 | sp<GraphicBuffer> buf; |
| 376 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 377 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 378 | nullptr, nullptr); |
| 379 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 380 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 381 | allocated.push_back({slot, fence}); |
| 382 | } |
| 383 | for (int i = 0; i < allocated.size(); i++) { |
| 384 | igbProducer->cancelBuffer(allocated[i].first, allocated[i].second); |
| 385 | } |
| 386 | |
Valerie Hau | a32c552 | 2019-12-09 10:11:08 -0800 | [diff] [blame] | 387 | for (int i = 0; i < 100; i++) { |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 388 | int slot; |
| 389 | sp<Fence> fence; |
| 390 | sp<GraphicBuffer> buf; |
| 391 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 392 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 393 | nullptr, nullptr); |
| 394 | ASSERT_EQ(NO_ERROR, ret); |
| 395 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 396 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), false, HAL_DATASPACE_UNKNOWN, |
| 397 | Rect(mDisplayWidth, mDisplayHeight), |
| 398 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 399 | Fence::NO_FENCE); |
| 400 | igbProducer->queueBuffer(slot, input, &qbOutput); |
| 401 | } |
| 402 | adapter.waitForCallbacks(); |
| 403 | } |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 404 | |
| 405 | TEST_F(BLASTBufferQueueTest, SetCrop_Item) { |
| 406 | uint8_t r = 255; |
| 407 | uint8_t g = 0; |
| 408 | uint8_t b = 0; |
| 409 | |
| 410 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 411 | sp<IGraphicBufferProducer> igbProducer; |
| 412 | setUpProducer(adapter, igbProducer); |
| 413 | int slot; |
| 414 | sp<Fence> fence; |
| 415 | sp<GraphicBuffer> buf; |
| 416 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 417 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 418 | nullptr, nullptr); |
| 419 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 420 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 421 | |
| 422 | uint32_t* bufData; |
| 423 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 424 | reinterpret_cast<void**>(&bufData)); |
| 425 | fillBuffer(bufData, Rect(buf->getWidth(), buf->getHeight() / 2), buf->getStride(), r, g, b); |
| 426 | buf->unlock(); |
| 427 | |
| 428 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 429 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), false, HAL_DATASPACE_UNKNOWN, |
| 430 | Rect(mDisplayWidth, mDisplayHeight / 2), |
| 431 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 432 | Fence::NO_FENCE); |
| 433 | igbProducer->queueBuffer(slot, input, &qbOutput); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 434 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 435 | |
| 436 | adapter.waitForCallbacks(); |
| 437 | // capture screen and verify that it is red |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 438 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 439 | |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 440 | ASSERT_NO_FATAL_FAILURE( |
| 441 | checkScreenCapture(r, g, b, {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight})); |
| 442 | } |
| 443 | |
| 444 | TEST_F(BLASTBufferQueueTest, SetCrop_ScalingModeScaleCrop) { |
| 445 | uint8_t r = 255; |
| 446 | uint8_t g = 0; |
| 447 | uint8_t b = 0; |
| 448 | |
| 449 | int32_t bufferSideLength = |
| 450 | (mDisplayWidth < mDisplayHeight) ? mDisplayWidth / 2 : mDisplayHeight / 2; |
| 451 | int32_t finalCropSideLength = bufferSideLength / 2; |
| 452 | |
| 453 | auto bg = mClient->createSurface(String8("BGTest"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 454 | ISurfaceComposerClient::eFXSurfaceEffect); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 455 | ASSERT_NE(nullptr, bg.get()); |
| 456 | Transaction t; |
| 457 | t.setLayerStack(bg, 0) |
| 458 | .setCrop_legacy(bg, Rect(0, 0, mDisplayWidth, mDisplayHeight)) |
| 459 | .setColor(bg, half3{0, 0, 0}) |
| 460 | .setLayer(bg, 0) |
| 461 | .apply(); |
| 462 | |
| 463 | BLASTBufferQueueHelper adapter(mSurfaceControl, bufferSideLength, bufferSideLength); |
| 464 | sp<IGraphicBufferProducer> igbProducer; |
| 465 | setUpProducer(adapter, igbProducer); |
| 466 | int slot; |
| 467 | sp<Fence> fence; |
| 468 | sp<GraphicBuffer> buf; |
| 469 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, bufferSideLength, bufferSideLength, |
| 470 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 471 | nullptr, nullptr); |
| 472 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 473 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 474 | |
| 475 | uint32_t* bufData; |
| 476 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 477 | reinterpret_cast<void**>(&bufData)); |
| 478 | fillBuffer(bufData, Rect(buf->getWidth(), buf->getHeight()), buf->getStride(), 0, 0, 0); |
| 479 | fillBuffer(bufData, |
| 480 | Rect(finalCropSideLength / 2, 0, buf->getWidth() - finalCropSideLength / 2, |
| 481 | buf->getHeight()), |
| 482 | buf->getStride(), r, g, b); |
| 483 | buf->unlock(); |
| 484 | |
| 485 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 486 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), false, HAL_DATASPACE_UNKNOWN, |
| 487 | Rect(bufferSideLength, finalCropSideLength), |
| 488 | NATIVE_WINDOW_SCALING_MODE_SCALE_CROP, 0, |
| 489 | Fence::NO_FENCE); |
| 490 | igbProducer->queueBuffer(slot, input, &qbOutput); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 491 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 492 | |
| 493 | adapter.waitForCallbacks(); |
| 494 | // capture screen and verify that it is red |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 495 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 496 | |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 497 | ASSERT_NO_FATAL_FAILURE( |
| 498 | checkScreenCapture(r, g, b, |
| 499 | {0, 0, (int32_t)bufferSideLength, (int32_t)bufferSideLength})); |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 500 | ASSERT_NO_FATAL_FAILURE( |
| 501 | checkScreenCapture(0, 0, 0, |
| 502 | {0, 0, (int32_t)bufferSideLength, (int32_t)bufferSideLength}, |
| 503 | /*border*/ 0, /*outsideRegion*/ true)); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 504 | } |
| 505 | |
Vishnu Nair | 8949612 | 2020-12-14 17:14:53 -0800 | [diff] [blame] | 506 | class TestProducerListener : public BnProducerListener { |
| 507 | public: |
| 508 | sp<IGraphicBufferProducer> mIgbp; |
| 509 | TestProducerListener(const sp<IGraphicBufferProducer>& igbp) : mIgbp(igbp) {} |
| 510 | void onBufferReleased() override { |
| 511 | sp<GraphicBuffer> buffer; |
| 512 | sp<Fence> fence; |
| 513 | mIgbp->detachNextBuffer(&buffer, &fence); |
| 514 | } |
| 515 | }; |
| 516 | |
| 517 | TEST_F(BLASTBufferQueueTest, CustomProducerListener) { |
| 518 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 519 | sp<IGraphicBufferProducer> igbProducer = adapter.getIGraphicBufferProducer(); |
| 520 | ASSERT_NE(nullptr, igbProducer.get()); |
| 521 | ASSERT_EQ(NO_ERROR, igbProducer->setMaxDequeuedBufferCount(2)); |
| 522 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 523 | ASSERT_EQ(NO_ERROR, |
| 524 | igbProducer->connect(new TestProducerListener(igbProducer), NATIVE_WINDOW_API_CPU, |
| 525 | false, &qbOutput)); |
| 526 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
| 527 | for (int i = 0; i < 3; i++) { |
| 528 | int slot; |
| 529 | sp<Fence> fence; |
| 530 | sp<GraphicBuffer> buf; |
| 531 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 532 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 533 | nullptr, nullptr); |
| 534 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 535 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 536 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 537 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), false, HAL_DATASPACE_UNKNOWN, |
| 538 | Rect(mDisplayWidth, mDisplayHeight), |
| 539 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 540 | Fence::NO_FENCE); |
| 541 | igbProducer->queueBuffer(slot, input, &qbOutput); |
| 542 | } |
| 543 | adapter.waitForCallbacks(); |
| 544 | } |
| 545 | |
Vishnu Nair | 17dde61 | 2020-12-28 11:39:59 -0800 | [diff] [blame] | 546 | TEST_F(BLASTBufferQueueTest, QueryNativeWindowQueuesToWindowComposer) { |
| 547 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 548 | |
| 549 | sp<android::Surface> surface = new Surface(adapter.getIGraphicBufferProducer()); |
| 550 | ANativeWindow* nativeWindow = (ANativeWindow*)(surface.get()); |
| 551 | int queuesToNativeWindow = 0; |
| 552 | int err = nativeWindow->query(nativeWindow, NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER, |
| 553 | &queuesToNativeWindow); |
| 554 | ASSERT_EQ(NO_ERROR, err); |
| 555 | ASSERT_EQ(queuesToNativeWindow, 1); |
| 556 | } |
| 557 | |
Vishnu Nair | 277142c | 2021-01-05 18:35:29 -0800 | [diff] [blame] | 558 | TEST_F(BLASTBufferQueueTest, OutOfOrderTransactionTest) { |
| 559 | sp<SurfaceControl> bgSurface = |
| 560 | mClient->createSurface(String8("BGTest"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 561 | ISurfaceComposerClient::eFXSurfaceBufferState); |
| 562 | ASSERT_NE(nullptr, bgSurface.get()); |
| 563 | Transaction t; |
| 564 | t.setLayerStack(bgSurface, 0) |
| 565 | .show(bgSurface) |
| 566 | .setDataspace(bgSurface, ui::Dataspace::V0_SRGB) |
| 567 | .setFrame(bgSurface, Rect(0, 0, mDisplayWidth, mDisplayHeight)) |
| 568 | .setLayer(bgSurface, std::numeric_limits<int32_t>::max() - 1) |
| 569 | .apply(); |
| 570 | |
| 571 | BLASTBufferQueueHelper slowAdapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 572 | sp<IGraphicBufferProducer> slowIgbProducer; |
| 573 | setUpProducer(slowAdapter, slowIgbProducer); |
| 574 | nsecs_t presentTimeDelay = std::chrono::nanoseconds(500ms).count(); |
| 575 | queueBuffer(slowIgbProducer, 0 /* r */, 0 /* g */, 0 /* b */, presentTimeDelay); |
| 576 | |
| 577 | BLASTBufferQueueHelper fastAdapter(bgSurface, mDisplayWidth, mDisplayHeight); |
| 578 | sp<IGraphicBufferProducer> fastIgbProducer; |
| 579 | setUpProducer(fastAdapter, fastIgbProducer); |
| 580 | uint8_t r = 255; |
| 581 | uint8_t g = 0; |
| 582 | uint8_t b = 0; |
| 583 | queueBuffer(fastIgbProducer, r, g, b, 0 /* presentTimeDelay */); |
| 584 | fastAdapter.waitForCallbacks(); |
| 585 | |
| 586 | // capture screen and verify that it is red |
| 587 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 588 | |
| 589 | ASSERT_NO_FATAL_FAILURE( |
| 590 | checkScreenCapture(r, g, b, {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight})); |
| 591 | } |
| 592 | |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 593 | class BLASTBufferQueueTransformTest : public BLASTBufferQueueTest { |
| 594 | public: |
| 595 | void test(uint32_t tr) { |
| 596 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 597 | sp<IGraphicBufferProducer> igbProducer; |
| 598 | setUpProducer(adapter, igbProducer); |
| 599 | |
| 600 | auto bufWidth = mDisplayWidth; |
| 601 | auto bufHeight = mDisplayHeight; |
| 602 | int slot; |
| 603 | sp<Fence> fence; |
| 604 | sp<GraphicBuffer> buf; |
| 605 | |
| 606 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, bufWidth, bufHeight, |
| 607 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 608 | nullptr, nullptr); |
| 609 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 610 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 611 | |
| 612 | fillQuadrants(buf); |
| 613 | |
| 614 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 615 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), false, HAL_DATASPACE_UNKNOWN, |
| 616 | Rect(bufWidth, bufHeight), |
Vishnu Nair | e1a4232 | 2020-10-02 17:42:04 -0700 | [diff] [blame] | 617 | NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW, |
| 618 | tr, Fence::NO_FENCE); |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 619 | igbProducer->queueBuffer(slot, input, &qbOutput); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 620 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 621 | |
| 622 | adapter.waitForCallbacks(); |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 623 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 624 | |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 625 | switch (tr) { |
| 626 | case ui::Transform::ROT_0: |
| 627 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 0, 0, |
| 628 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 629 | (int32_t)mDisplayHeight / 2}, |
| 630 | 1)); |
| 631 | ASSERT_NO_FATAL_FAILURE( |
| 632 | checkScreenCapture(255, 0, 0, |
| 633 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 634 | (int32_t)mDisplayHeight / 2}, |
| 635 | 1)); |
| 636 | ASSERT_NO_FATAL_FAILURE( |
| 637 | checkScreenCapture(0, 255, 0, |
| 638 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 639 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 640 | 1)); |
| 641 | ASSERT_NO_FATAL_FAILURE( |
| 642 | checkScreenCapture(0, 0, 255, |
| 643 | {0, (int32_t)mDisplayHeight / 2, |
| 644 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 645 | 1)); |
| 646 | break; |
| 647 | case ui::Transform::FLIP_H: |
| 648 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(255, 0, 0, |
| 649 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 650 | (int32_t)mDisplayHeight / 2}, |
| 651 | 1)); |
| 652 | ASSERT_NO_FATAL_FAILURE( |
| 653 | checkScreenCapture(0, 0, 0, |
| 654 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 655 | (int32_t)mDisplayHeight / 2}, |
| 656 | 1)); |
| 657 | ASSERT_NO_FATAL_FAILURE( |
| 658 | checkScreenCapture(0, 0, 255, |
| 659 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 660 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 661 | 1)); |
| 662 | ASSERT_NO_FATAL_FAILURE( |
| 663 | checkScreenCapture(0, 255, 0, |
| 664 | {0, (int32_t)mDisplayHeight / 2, |
| 665 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 666 | 1)); |
| 667 | break; |
| 668 | case ui::Transform::FLIP_V: |
| 669 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 0, 255, |
| 670 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 671 | (int32_t)mDisplayHeight / 2}, |
| 672 | 1)); |
| 673 | ASSERT_NO_FATAL_FAILURE( |
| 674 | checkScreenCapture(0, 255, 0, |
| 675 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 676 | (int32_t)mDisplayHeight / 2}, |
| 677 | 1)); |
| 678 | ASSERT_NO_FATAL_FAILURE( |
| 679 | checkScreenCapture(255, 0, 0, |
| 680 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 681 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 682 | 1)); |
| 683 | ASSERT_NO_FATAL_FAILURE( |
| 684 | checkScreenCapture(0, 0, 0, |
| 685 | {0, (int32_t)mDisplayHeight / 2, |
| 686 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 687 | 1)); |
| 688 | break; |
| 689 | case ui::Transform::ROT_90: |
| 690 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 0, 255, |
| 691 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 692 | (int32_t)mDisplayHeight / 2}, |
| 693 | 1)); |
| 694 | ASSERT_NO_FATAL_FAILURE( |
| 695 | checkScreenCapture(0, 0, 0, |
| 696 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 697 | (int32_t)mDisplayHeight / 2}, |
| 698 | 1)); |
| 699 | ASSERT_NO_FATAL_FAILURE( |
| 700 | checkScreenCapture(255, 0, 0, |
| 701 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 702 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 703 | 1)); |
| 704 | ASSERT_NO_FATAL_FAILURE( |
| 705 | checkScreenCapture(0, 255, 0, |
| 706 | {0, (int32_t)mDisplayHeight / 2, |
| 707 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 708 | 1)); |
| 709 | break; |
| 710 | case ui::Transform::ROT_180: |
| 711 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 255, 0, |
| 712 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 713 | (int32_t)mDisplayHeight / 2}, |
| 714 | 1)); |
| 715 | ASSERT_NO_FATAL_FAILURE( |
| 716 | checkScreenCapture(0, 0, 255, |
| 717 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 718 | (int32_t)mDisplayHeight / 2}, |
| 719 | 1)); |
| 720 | ASSERT_NO_FATAL_FAILURE( |
| 721 | checkScreenCapture(0, 0, 0, |
| 722 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 723 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 724 | 1)); |
| 725 | ASSERT_NO_FATAL_FAILURE( |
| 726 | checkScreenCapture(255, 0, 0, |
| 727 | {0, (int32_t)mDisplayHeight / 2, |
| 728 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 729 | 1)); |
| 730 | break; |
| 731 | case ui::Transform::ROT_270: |
| 732 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(255, 0, 0, |
| 733 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 734 | (int32_t)mDisplayHeight / 2}, |
| 735 | 1)); |
| 736 | ASSERT_NO_FATAL_FAILURE( |
| 737 | checkScreenCapture(0, 255, 0, |
| 738 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 739 | (int32_t)mDisplayHeight / 2}, |
| 740 | 1)); |
| 741 | ASSERT_NO_FATAL_FAILURE( |
| 742 | checkScreenCapture(0, 0, 255, |
| 743 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 744 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 745 | 1)); |
| 746 | ASSERT_NO_FATAL_FAILURE( |
| 747 | checkScreenCapture(0, 0, 0, |
| 748 | {0, (int32_t)mDisplayHeight / 2, |
| 749 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 750 | 1)); |
| 751 | } |
| 752 | } |
| 753 | }; |
| 754 | |
| 755 | TEST_F(BLASTBufferQueueTransformTest, setTransform_ROT_0) { |
| 756 | test(ui::Transform::ROT_0); |
| 757 | } |
| 758 | |
| 759 | TEST_F(BLASTBufferQueueTransformTest, setTransform_FLIP_H) { |
| 760 | test(ui::Transform::FLIP_H); |
| 761 | } |
| 762 | |
| 763 | TEST_F(BLASTBufferQueueTransformTest, setTransform_FLIP_V) { |
| 764 | test(ui::Transform::FLIP_V); |
| 765 | } |
| 766 | |
| 767 | TEST_F(BLASTBufferQueueTransformTest, setTransform_ROT_90) { |
| 768 | test(ui::Transform::ROT_90); |
| 769 | } |
| 770 | |
| 771 | TEST_F(BLASTBufferQueueTransformTest, setTransform_ROT_180) { |
| 772 | test(ui::Transform::ROT_180); |
| 773 | } |
| 774 | |
| 775 | TEST_F(BLASTBufferQueueTransformTest, setTransform_ROT_270) { |
| 776 | test(ui::Transform::ROT_270); |
| 777 | } |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 778 | |
| 779 | class BLASTFrameEventHistoryTest : public BLASTBufferQueueTest { |
| 780 | public: |
| 781 | void setUpAndQueueBuffer(const sp<IGraphicBufferProducer>& igbProducer, |
| 782 | nsecs_t* requestedPresentTime, nsecs_t* postedTime, |
| 783 | IGraphicBufferProducer::QueueBufferOutput* qbOutput, |
| 784 | bool getFrameTimestamps) { |
| 785 | int slot; |
| 786 | sp<Fence> fence; |
| 787 | sp<GraphicBuffer> buf; |
| 788 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 789 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 790 | nullptr, nullptr); |
| 791 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 792 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 793 | |
| 794 | nsecs_t requestedTime = systemTime(); |
| 795 | if (requestedPresentTime) *requestedPresentTime = requestedTime; |
| 796 | IGraphicBufferProducer::QueueBufferInput input(requestedTime, false, HAL_DATASPACE_UNKNOWN, |
| 797 | Rect(mDisplayWidth, mDisplayHeight), |
| 798 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 799 | Fence::NO_FENCE, /*sticky*/ 0, |
| 800 | getFrameTimestamps); |
| 801 | if (postedTime) *postedTime = systemTime(); |
| 802 | igbProducer->queueBuffer(slot, input, qbOutput); |
| 803 | } |
| 804 | }; |
| 805 | |
| 806 | TEST_F(BLASTFrameEventHistoryTest, FrameEventHistory_Basic) { |
| 807 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 808 | sp<IGraphicBufferProducer> igbProducer; |
| 809 | ProducerFrameEventHistory history; |
| 810 | setUpProducer(adapter, igbProducer); |
| 811 | |
| 812 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 813 | nsecs_t requestedPresentTimeA = 0; |
| 814 | nsecs_t postedTimeA = 0; |
| 815 | setUpAndQueueBuffer(igbProducer, &requestedPresentTimeA, &postedTimeA, &qbOutput, true); |
| 816 | history.applyDelta(qbOutput.frameTimestamps); |
| 817 | |
| 818 | FrameEvents* events = nullptr; |
| 819 | events = history.getFrame(1); |
| 820 | ASSERT_NE(nullptr, events); |
| 821 | ASSERT_EQ(1, events->frameNumber); |
| 822 | ASSERT_EQ(requestedPresentTimeA, events->requestedPresentTime); |
| 823 | ASSERT_GE(events->postedTime, postedTimeA); |
| 824 | |
| 825 | adapter.waitForCallbacks(); |
| 826 | |
| 827 | // queue another buffer so we query for frame event deltas |
| 828 | nsecs_t requestedPresentTimeB = 0; |
| 829 | nsecs_t postedTimeB = 0; |
| 830 | setUpAndQueueBuffer(igbProducer, &requestedPresentTimeB, &postedTimeB, &qbOutput, true); |
| 831 | history.applyDelta(qbOutput.frameTimestamps); |
| 832 | events = history.getFrame(1); |
| 833 | ASSERT_NE(nullptr, events); |
| 834 | |
| 835 | // frame number, requestedPresentTime, and postTime should not have changed |
| 836 | ASSERT_EQ(1, events->frameNumber); |
| 837 | ASSERT_EQ(requestedPresentTimeA, events->requestedPresentTime); |
| 838 | ASSERT_GE(events->postedTime, postedTimeA); |
| 839 | |
| 840 | ASSERT_GE(events->latchTime, postedTimeA); |
| 841 | ASSERT_GE(events->dequeueReadyTime, events->latchTime); |
| 842 | ASSERT_NE(nullptr, events->gpuCompositionDoneFence); |
| 843 | ASSERT_NE(nullptr, events->displayPresentFence); |
| 844 | ASSERT_NE(nullptr, events->releaseFence); |
| 845 | |
| 846 | // we should also have gotten the initial values for the next frame |
| 847 | events = history.getFrame(2); |
| 848 | ASSERT_NE(nullptr, events); |
| 849 | ASSERT_EQ(2, events->frameNumber); |
| 850 | ASSERT_EQ(requestedPresentTimeB, events->requestedPresentTime); |
| 851 | ASSERT_GE(events->postedTime, postedTimeB); |
Valerie Hau | 78491e9 | 2020-04-15 13:10:56 -0700 | [diff] [blame] | 852 | |
| 853 | // wait for any callbacks that have not been received |
| 854 | adapter.waitForCallbacks(); |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 855 | } |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 856 | } // namespace android |