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> |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 31 | #include <ui/DisplayMode.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 | |
Vishnu Nair | a4fbca5 | 2021-07-07 16:52:34 -0700 | [diff] [blame] | 74 | sp<Surface> getSurface() { |
| 75 | return mBlastBufferQueueAdapter->getSurface(false /* includeSurfaceControlHandle */); |
| 76 | } |
| 77 | |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 78 | void waitForCallbacks() { |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 79 | std::unique_lock lock{mBlastBufferQueueAdapter->mMutex}; |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 80 | // Wait until all but one of the submitted buffers have been released. |
| 81 | while (mBlastBufferQueueAdapter->mSubmitted.size() > 1) { |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 82 | mBlastBufferQueueAdapter->mCallbackCV.wait(lock); |
| 83 | } |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 86 | void setTransactionCompleteCallback(int64_t frameNumber) { |
| 87 | mBlastBufferQueueAdapter->setTransactionCompleteCallback(frameNumber, [&](int64_t frame) { |
| 88 | std::unique_lock lock{mMutex}; |
| 89 | mLastTransactionCompleteFrameNumber = frame; |
| 90 | mCallbackCV.notify_all(); |
| 91 | }); |
| 92 | } |
| 93 | |
| 94 | void waitForCallback(int64_t frameNumber) { |
| 95 | std::unique_lock lock{mMutex}; |
| 96 | // Wait until all but one of the submitted buffers have been released. |
| 97 | while (mLastTransactionCompleteFrameNumber < frameNumber) { |
| 98 | mCallbackCV.wait(lock); |
| 99 | } |
| 100 | } |
| 101 | |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 102 | private: |
| 103 | sp<BLASTBufferQueue> mBlastBufferQueueAdapter; |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 104 | |
| 105 | std::mutex mMutex; |
| 106 | std::condition_variable mCallbackCV; |
| 107 | int64_t mLastTransactionCompleteFrameNumber = -1; |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | class BLASTBufferQueueTest : public ::testing::Test { |
| 111 | public: |
| 112 | protected: |
| 113 | BLASTBufferQueueTest() { |
| 114 | const ::testing::TestInfo* const testInfo = |
| 115 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 116 | ALOGV("Begin test: %s.%s", testInfo->test_case_name(), testInfo->name()); |
| 117 | } |
| 118 | |
| 119 | ~BLASTBufferQueueTest() { |
| 120 | const ::testing::TestInfo* const testInfo = |
| 121 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 122 | ALOGV("End test: %s.%s", testInfo->test_case_name(), testInfo->name()); |
| 123 | } |
| 124 | |
| 125 | void SetUp() { |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 126 | mComposer = ComposerService::getComposerService(); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 127 | mClient = new SurfaceComposerClient(); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 128 | mDisplayToken = mClient->getInternalDisplayToken(); |
| 129 | ASSERT_NE(nullptr, mDisplayToken.get()); |
| 130 | Transaction t; |
| 131 | t.setDisplayLayerStack(mDisplayToken, 0); |
| 132 | t.apply(); |
| 133 | t.clear(); |
| 134 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 135 | ui::DisplayMode mode; |
| 136 | ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(mDisplayToken, &mode)); |
| 137 | const ui::Size& resolution = mode.resolution; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 138 | mDisplayWidth = resolution.getWidth(); |
| 139 | mDisplayHeight = resolution.getHeight(); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 140 | |
| 141 | mSurfaceControl = mClient->createSurface(String8("TestSurface"), mDisplayWidth, |
| 142 | mDisplayHeight, PIXEL_FORMAT_RGBA_8888, |
| 143 | ISurfaceComposerClient::eFXSurfaceBufferState, |
| 144 | /*parent*/ nullptr); |
| 145 | t.setLayerStack(mSurfaceControl, 0) |
| 146 | .setLayer(mSurfaceControl, std::numeric_limits<int32_t>::max()) |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 147 | .show(mSurfaceControl) |
| 148 | .setDataspace(mSurfaceControl, ui::Dataspace::V0_SRGB) |
| 149 | .apply(); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 150 | |
| 151 | mCaptureArgs.displayToken = mDisplayToken; |
arthurhung | 6fa58b7 | 2020-11-05 11:56:00 +0800 | [diff] [blame] | 152 | mCaptureArgs.dataspace = ui::Dataspace::V0_SRGB; |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 155 | void setUpProducer(BLASTBufferQueueHelper& adapter, sp<IGraphicBufferProducer>& producer) { |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 156 | producer = adapter.getIGraphicBufferProducer(); |
| 157 | setUpProducer(producer); |
| 158 | } |
| 159 | |
| 160 | void setUpProducer(sp<IGraphicBufferProducer>& igbProducer) { |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 161 | ASSERT_NE(nullptr, igbProducer.get()); |
Valerie Hau | c78c43a | 2020-01-09 17:34:14 -0800 | [diff] [blame] | 162 | ASSERT_EQ(NO_ERROR, igbProducer->setMaxDequeuedBufferCount(2)); |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 163 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 164 | ASSERT_EQ(NO_ERROR, |
Peiyong Lin | d8460c8 | 2020-07-28 16:04:22 -0700 | [diff] [blame] | 165 | igbProducer->connect(new StubProducerListener, NATIVE_WINDOW_API_CPU, false, |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 166 | &qbOutput)); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 167 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 170 | void fillBuffer(uint32_t* bufData, Rect rect, uint32_t stride, uint8_t r, uint8_t g, |
| 171 | uint8_t b) { |
| 172 | for (uint32_t row = rect.top; row < rect.bottom; row++) { |
| 173 | for (uint32_t col = rect.left; col < rect.right; col++) { |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 174 | uint8_t* pixel = (uint8_t*)(bufData + (row * stride) + col); |
| 175 | *pixel = r; |
| 176 | *(pixel + 1) = g; |
| 177 | *(pixel + 2) = b; |
| 178 | *(pixel + 3) = 255; |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 183 | void fillQuadrants(sp<GraphicBuffer>& buf) { |
| 184 | const auto bufWidth = buf->getWidth(); |
| 185 | const auto bufHeight = buf->getHeight(); |
| 186 | uint32_t* bufData; |
| 187 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 188 | reinterpret_cast<void**>(&bufData)); |
| 189 | fillBuffer(bufData, Rect(0, 0, bufWidth / 2, bufHeight / 2), buf->getStride(), 0, 0, 0); |
| 190 | fillBuffer(bufData, Rect(bufWidth / 2, 0, bufWidth, bufHeight / 2), buf->getStride(), 255, |
| 191 | 0, 0); |
| 192 | fillBuffer(bufData, Rect(bufWidth / 2, bufHeight / 2, bufWidth, bufHeight), |
| 193 | buf->getStride(), 0, 255, 0); |
| 194 | fillBuffer(bufData, Rect(0, bufHeight / 2, bufWidth / 2, bufHeight), buf->getStride(), 0, 0, |
| 195 | 255); |
| 196 | buf->unlock(); |
| 197 | } |
| 198 | |
| 199 | void checkScreenCapture(uint8_t r, uint8_t g, uint8_t b, Rect region, int32_t border = 0, |
| 200 | bool outsideRegion = false) { |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 201 | sp<GraphicBuffer>& captureBuf = mCaptureResults.buffer; |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 202 | const auto epsilon = 3; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 203 | const auto width = captureBuf->getWidth(); |
| 204 | const auto height = captureBuf->getHeight(); |
| 205 | const auto stride = captureBuf->getStride(); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 206 | |
| 207 | uint32_t* bufData; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 208 | captureBuf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_READ_OFTEN), |
| 209 | reinterpret_cast<void**>(&bufData)); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 210 | |
| 211 | for (uint32_t row = 0; row < height; row++) { |
| 212 | for (uint32_t col = 0; col < width; col++) { |
| 213 | uint8_t* pixel = (uint8_t*)(bufData + (row * stride) + col); |
arthurhung | 6fa58b7 | 2020-11-05 11:56:00 +0800 | [diff] [blame] | 214 | ASSERT_NE(nullptr, pixel); |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 215 | bool inRegion; |
| 216 | if (!outsideRegion) { |
| 217 | inRegion = row >= region.top + border && row < region.bottom - border && |
| 218 | col >= region.left + border && col < region.right - border; |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 219 | } else { |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 220 | inRegion = row >= region.top - border && row < region.bottom + border && |
| 221 | col >= region.left - border && col < region.right + border; |
| 222 | } |
| 223 | if (!outsideRegion && inRegion) { |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 224 | ASSERT_GE(epsilon, abs(r - *(pixel))); |
| 225 | ASSERT_GE(epsilon, abs(g - *(pixel + 1))); |
| 226 | ASSERT_GE(epsilon, abs(b - *(pixel + 2))); |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 227 | } else if (outsideRegion && !inRegion) { |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 228 | ASSERT_GE(epsilon, abs(r - *(pixel))); |
| 229 | ASSERT_GE(epsilon, abs(g - *(pixel + 1))); |
| 230 | ASSERT_GE(epsilon, abs(b - *(pixel + 2))); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 231 | } |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 232 | ASSERT_EQ(false, ::testing::Test::HasFailure()); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 233 | } |
| 234 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 235 | captureBuf->unlock(); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 236 | } |
| 237 | |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 238 | static status_t captureDisplay(DisplayCaptureArgs& captureArgs, |
| 239 | ScreenCaptureResults& captureResults) { |
| 240 | const auto sf = ComposerService::getComposerService(); |
| 241 | SurfaceComposerClient::Transaction().apply(true); |
| 242 | |
| 243 | const sp<SyncScreenCaptureListener> captureListener = new SyncScreenCaptureListener(); |
| 244 | status_t status = sf->captureDisplay(captureArgs, captureListener); |
| 245 | if (status != NO_ERROR) { |
| 246 | return status; |
| 247 | } |
| 248 | captureResults = captureListener->waitForResults(); |
| 249 | return captureResults.result; |
| 250 | } |
| 251 | |
Vishnu Nair | 277142c | 2021-01-05 18:35:29 -0800 | [diff] [blame] | 252 | void queueBuffer(sp<IGraphicBufferProducer> igbp, uint8_t r, uint8_t g, uint8_t b, |
| 253 | nsecs_t presentTimeDelay) { |
| 254 | int slot; |
| 255 | sp<Fence> fence; |
| 256 | sp<GraphicBuffer> buf; |
| 257 | auto ret = igbp->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 258 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 259 | nullptr, nullptr); |
| 260 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 261 | ASSERT_EQ(OK, igbp->requestBuffer(slot, &buf)); |
| 262 | |
| 263 | uint32_t* bufData; |
| 264 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 265 | reinterpret_cast<void**>(&bufData)); |
| 266 | fillBuffer(bufData, Rect(buf->getWidth(), buf->getHeight() / 2), buf->getStride(), r, g, b); |
| 267 | buf->unlock(); |
| 268 | |
| 269 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 270 | nsecs_t timestampNanos = systemTime() + presentTimeDelay; |
| 271 | IGraphicBufferProducer::QueueBufferInput input(timestampNanos, false, HAL_DATASPACE_UNKNOWN, |
| 272 | Rect(mDisplayWidth, mDisplayHeight / 2), |
| 273 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 274 | Fence::NO_FENCE); |
| 275 | igbp->queueBuffer(slot, input, &qbOutput); |
| 276 | } |
| 277 | |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 278 | sp<SurfaceComposerClient> mClient; |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 279 | sp<ISurfaceComposer> mComposer; |
| 280 | |
| 281 | sp<IBinder> mDisplayToken; |
| 282 | |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 283 | sp<SurfaceControl> mSurfaceControl; |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 284 | |
| 285 | uint32_t mDisplayWidth; |
| 286 | uint32_t mDisplayHeight; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 287 | |
| 288 | DisplayCaptureArgs mCaptureArgs; |
| 289 | ScreenCaptureResults mCaptureResults; |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 290 | }; |
| 291 | |
| 292 | TEST_F(BLASTBufferQueueTest, CreateBLASTBufferQueue) { |
| 293 | // create BLASTBufferQueue adapter associated with this surface |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 294 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 295 | ASSERT_EQ(mSurfaceControl, adapter.getSurfaceControl()); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 296 | ASSERT_EQ(mDisplayWidth, adapter.getWidth()); |
| 297 | ASSERT_EQ(mDisplayHeight, adapter.getHeight()); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 298 | ASSERT_EQ(nullptr, adapter.getNextTransaction()); |
| 299 | } |
| 300 | |
| 301 | TEST_F(BLASTBufferQueueTest, Update) { |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 302 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 303 | sp<SurfaceControl> updateSurface = |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 304 | mClient->createSurface(String8("UpdateTest"), mDisplayWidth / 2, mDisplayHeight / 2, |
| 305 | PIXEL_FORMAT_RGBA_8888); |
| 306 | adapter.update(updateSurface, mDisplayWidth / 2, mDisplayHeight / 2); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 307 | ASSERT_EQ(updateSurface, adapter.getSurfaceControl()); |
Vishnu Nair | ea0de00 | 2020-11-17 17:42:37 -0800 | [diff] [blame] | 308 | sp<IGraphicBufferProducer> igbProducer; |
| 309 | setUpProducer(adapter, igbProducer); |
| 310 | |
| 311 | int32_t width; |
| 312 | igbProducer->query(NATIVE_WINDOW_WIDTH, &width); |
| 313 | ASSERT_EQ(mDisplayWidth / 2, width); |
| 314 | int32_t height; |
| 315 | igbProducer->query(NATIVE_WINDOW_HEIGHT, &height); |
| 316 | ASSERT_EQ(mDisplayHeight / 2, height); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | TEST_F(BLASTBufferQueueTest, SetNextTransaction) { |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 320 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 321 | Transaction next; |
| 322 | adapter.setNextTransaction(&next); |
| 323 | ASSERT_EQ(&next, adapter.getNextTransaction()); |
| 324 | } |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 325 | |
Valerie Hau | bf29e04 | 2020-02-06 11:40:38 -0800 | [diff] [blame] | 326 | TEST_F(BLASTBufferQueueTest, DISABLED_onFrameAvailable_ApplyDesiredPresentTime) { |
Valerie Hau | 181abd3 | 2020-01-27 14:18:28 -0800 | [diff] [blame] | 327 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 328 | sp<IGraphicBufferProducer> igbProducer; |
| 329 | setUpProducer(adapter, igbProducer); |
| 330 | |
| 331 | int slot; |
| 332 | sp<Fence> fence; |
| 333 | sp<GraphicBuffer> buf; |
| 334 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 335 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 336 | nullptr, nullptr); |
| 337 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 338 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 339 | |
| 340 | nsecs_t desiredPresentTime = systemTime() + nsecs_t(5 * 1e8); |
| 341 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 342 | IGraphicBufferProducer::QueueBufferInput input(desiredPresentTime, true /* autotimestamp */, |
| 343 | HAL_DATASPACE_UNKNOWN, |
Valerie Hau | 181abd3 | 2020-01-27 14:18:28 -0800 | [diff] [blame] | 344 | Rect(mDisplayWidth, mDisplayHeight), |
| 345 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 346 | Fence::NO_FENCE); |
| 347 | igbProducer->queueBuffer(slot, input, &qbOutput); |
| 348 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
| 349 | |
| 350 | adapter.waitForCallbacks(); |
| 351 | ASSERT_GE(systemTime(), desiredPresentTime); |
| 352 | } |
| 353 | |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 354 | TEST_F(BLASTBufferQueueTest, onFrameAvailable_Apply) { |
| 355 | uint8_t r = 255; |
| 356 | uint8_t g = 0; |
| 357 | uint8_t b = 0; |
| 358 | |
| 359 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 360 | sp<IGraphicBufferProducer> igbProducer; |
| 361 | setUpProducer(adapter, igbProducer); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 362 | |
| 363 | int slot; |
| 364 | sp<Fence> fence; |
| 365 | sp<GraphicBuffer> buf; |
| 366 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 367 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 368 | nullptr, nullptr); |
| 369 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 370 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 371 | |
| 372 | uint32_t* bufData; |
| 373 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 374 | reinterpret_cast<void**>(&bufData)); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 375 | fillBuffer(bufData, Rect(buf->getWidth(), buf->getHeight()), buf->getStride(), r, g, b); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 376 | buf->unlock(); |
| 377 | |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 378 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 379 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), true /* autotimestamp */, |
| 380 | HAL_DATASPACE_UNKNOWN, |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 381 | Rect(mDisplayWidth, mDisplayHeight), |
| 382 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 383 | Fence::NO_FENCE); |
| 384 | igbProducer->queueBuffer(slot, input, &qbOutput); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 385 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 386 | |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 387 | adapter.waitForCallbacks(); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 388 | |
| 389 | // capture screen and verify that it is red |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 390 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 391 | ASSERT_NO_FATAL_FAILURE( |
| 392 | checkScreenCapture(r, g, b, {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight})); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 393 | } |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 394 | |
| 395 | TEST_F(BLASTBufferQueueTest, TripleBuffering) { |
| 396 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 397 | sp<IGraphicBufferProducer> igbProducer; |
| 398 | setUpProducer(adapter, igbProducer); |
| 399 | |
| 400 | std::vector<std::pair<int, sp<Fence>>> allocated; |
Ady Abraham | 0bde6b5 | 2021-05-18 13:57:02 -0700 | [diff] [blame] | 401 | int minUndequeuedBuffers = 0; |
| 402 | ASSERT_EQ(OK, igbProducer->query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, &minUndequeuedBuffers)); |
| 403 | const auto bufferCount = minUndequeuedBuffers + 2; |
| 404 | |
| 405 | for (int i = 0; i < bufferCount; i++) { |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 406 | int slot; |
| 407 | sp<Fence> fence; |
| 408 | sp<GraphicBuffer> buf; |
| 409 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 410 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 411 | nullptr, nullptr); |
| 412 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 413 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 414 | allocated.push_back({slot, fence}); |
| 415 | } |
| 416 | for (int i = 0; i < allocated.size(); i++) { |
| 417 | igbProducer->cancelBuffer(allocated[i].first, allocated[i].second); |
| 418 | } |
| 419 | |
Valerie Hau | a32c552 | 2019-12-09 10:11:08 -0800 | [diff] [blame] | 420 | for (int i = 0; i < 100; i++) { |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 421 | int slot; |
| 422 | sp<Fence> fence; |
| 423 | sp<GraphicBuffer> buf; |
| 424 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 425 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 426 | nullptr, nullptr); |
| 427 | ASSERT_EQ(NO_ERROR, ret); |
| 428 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 429 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), true /* autotimestamp */, |
| 430 | HAL_DATASPACE_UNKNOWN, |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 431 | Rect(mDisplayWidth, mDisplayHeight), |
| 432 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 433 | Fence::NO_FENCE); |
| 434 | igbProducer->queueBuffer(slot, input, &qbOutput); |
| 435 | } |
| 436 | adapter.waitForCallbacks(); |
| 437 | } |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 438 | |
| 439 | TEST_F(BLASTBufferQueueTest, SetCrop_Item) { |
| 440 | uint8_t r = 255; |
| 441 | uint8_t g = 0; |
| 442 | uint8_t b = 0; |
| 443 | |
| 444 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 445 | sp<IGraphicBufferProducer> igbProducer; |
| 446 | setUpProducer(adapter, igbProducer); |
| 447 | int slot; |
| 448 | sp<Fence> fence; |
| 449 | sp<GraphicBuffer> buf; |
| 450 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 451 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 452 | nullptr, nullptr); |
| 453 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 454 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 455 | |
| 456 | uint32_t* bufData; |
| 457 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 458 | reinterpret_cast<void**>(&bufData)); |
| 459 | fillBuffer(bufData, Rect(buf->getWidth(), buf->getHeight() / 2), buf->getStride(), r, g, b); |
| 460 | buf->unlock(); |
| 461 | |
| 462 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 463 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), true /* autotimestamp */, |
| 464 | HAL_DATASPACE_UNKNOWN, |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 465 | Rect(mDisplayWidth, mDisplayHeight / 2), |
| 466 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 467 | Fence::NO_FENCE); |
| 468 | igbProducer->queueBuffer(slot, input, &qbOutput); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 469 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 470 | |
| 471 | adapter.waitForCallbacks(); |
| 472 | // capture screen and verify that it is red |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 473 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 474 | |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 475 | ASSERT_NO_FATAL_FAILURE( |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 476 | checkScreenCapture(r, g, b, |
| 477 | {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight / 2})); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | TEST_F(BLASTBufferQueueTest, SetCrop_ScalingModeScaleCrop) { |
| 481 | uint8_t r = 255; |
| 482 | uint8_t g = 0; |
| 483 | uint8_t b = 0; |
| 484 | |
| 485 | int32_t bufferSideLength = |
| 486 | (mDisplayWidth < mDisplayHeight) ? mDisplayWidth / 2 : mDisplayHeight / 2; |
| 487 | int32_t finalCropSideLength = bufferSideLength / 2; |
| 488 | |
| 489 | auto bg = mClient->createSurface(String8("BGTest"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 490 | ISurfaceComposerClient::eFXSurfaceEffect); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 491 | ASSERT_NE(nullptr, bg.get()); |
| 492 | Transaction t; |
| 493 | t.setLayerStack(bg, 0) |
chaviw | 2571450 | 2021-02-11 10:01:08 -0800 | [diff] [blame] | 494 | .setCrop(bg, Rect(0, 0, mDisplayWidth, mDisplayHeight)) |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 495 | .setColor(bg, half3{0, 0, 0}) |
| 496 | .setLayer(bg, 0) |
| 497 | .apply(); |
| 498 | |
| 499 | BLASTBufferQueueHelper adapter(mSurfaceControl, bufferSideLength, bufferSideLength); |
| 500 | sp<IGraphicBufferProducer> igbProducer; |
| 501 | setUpProducer(adapter, igbProducer); |
| 502 | int slot; |
| 503 | sp<Fence> fence; |
| 504 | sp<GraphicBuffer> buf; |
| 505 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, bufferSideLength, bufferSideLength, |
| 506 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 507 | nullptr, nullptr); |
| 508 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 509 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 510 | |
| 511 | uint32_t* bufData; |
| 512 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 513 | reinterpret_cast<void**>(&bufData)); |
| 514 | fillBuffer(bufData, Rect(buf->getWidth(), buf->getHeight()), buf->getStride(), 0, 0, 0); |
| 515 | fillBuffer(bufData, |
| 516 | Rect(finalCropSideLength / 2, 0, buf->getWidth() - finalCropSideLength / 2, |
| 517 | buf->getHeight()), |
| 518 | buf->getStride(), r, g, b); |
| 519 | buf->unlock(); |
| 520 | |
| 521 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 522 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), true /* autotimestamp */, |
| 523 | HAL_DATASPACE_UNKNOWN, |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 524 | Rect(bufferSideLength, finalCropSideLength), |
| 525 | NATIVE_WINDOW_SCALING_MODE_SCALE_CROP, 0, |
| 526 | Fence::NO_FENCE); |
| 527 | igbProducer->queueBuffer(slot, input, &qbOutput); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 528 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 529 | |
| 530 | adapter.waitForCallbacks(); |
| 531 | // capture screen and verify that it is red |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 532 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
Vishnu Nair | 5cc9ac0 | 2021-04-19 13:23:38 -0700 | [diff] [blame] | 533 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(r, g, b, |
| 534 | {10, 10, (int32_t)bufferSideLength - 10, |
| 535 | (int32_t)bufferSideLength - 10})); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 536 | ASSERT_NO_FATAL_FAILURE( |
Vishnu Nair | 5cc9ac0 | 2021-04-19 13:23:38 -0700 | [diff] [blame] | 537 | checkScreenCapture(0, 0, 0, |
| 538 | {0, 0, (int32_t)bufferSideLength, (int32_t)bufferSideLength}, |
| 539 | /*border*/ 0, /*outsideRegion*/ true)); |
| 540 | } |
| 541 | |
| 542 | TEST_F(BLASTBufferQueueTest, ScaleCroppedBufferToBufferSize) { |
| 543 | // add black background |
| 544 | auto bg = mClient->createSurface(String8("BGTest"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 545 | ISurfaceComposerClient::eFXSurfaceEffect); |
| 546 | ASSERT_NE(nullptr, bg.get()); |
| 547 | Transaction t; |
| 548 | t.setLayerStack(bg, 0) |
| 549 | .setCrop(bg, Rect(0, 0, mDisplayWidth, mDisplayHeight)) |
| 550 | .setColor(bg, half3{0, 0, 0}) |
| 551 | .setLayer(bg, 0) |
| 552 | .apply(); |
| 553 | |
| 554 | Rect windowSize(1000, 1000); |
| 555 | Rect bufferSize(windowSize); |
| 556 | Rect bufferCrop(200, 200, 700, 700); |
| 557 | |
| 558 | BLASTBufferQueueHelper adapter(mSurfaceControl, windowSize.getWidth(), windowSize.getHeight()); |
| 559 | sp<IGraphicBufferProducer> igbProducer; |
| 560 | setUpProducer(adapter, igbProducer); |
| 561 | int slot; |
| 562 | sp<Fence> fence; |
| 563 | sp<GraphicBuffer> buf; |
| 564 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, bufferSize.getWidth(), |
| 565 | bufferSize.getHeight(), PIXEL_FORMAT_RGBA_8888, |
| 566 | GRALLOC_USAGE_SW_WRITE_OFTEN, nullptr, nullptr); |
| 567 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 568 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 569 | |
| 570 | uint32_t* bufData; |
| 571 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 572 | reinterpret_cast<void**>(&bufData)); |
| 573 | // fill buffer with grey |
| 574 | fillBuffer(bufData, bufferSize, buf->getStride(), 127, 127, 127); |
| 575 | |
| 576 | // fill crop area with different colors so we can verify the cropped region has been scaled |
| 577 | // correctly. |
| 578 | fillBuffer(bufData, Rect(200, 200, 450, 450), buf->getStride(), /* rgb */ 255, 0, 0); |
| 579 | fillBuffer(bufData, Rect(200, 451, 450, 700), buf->getStride(), /* rgb */ 0, 255, 0); |
| 580 | fillBuffer(bufData, Rect(451, 200, 700, 450), buf->getStride(), /* rgb */ 0, 0, 255); |
| 581 | fillBuffer(bufData, Rect(451, 451, 700, 700), buf->getStride(), /* rgb */ 255, 0, 0); |
| 582 | buf->unlock(); |
| 583 | |
| 584 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 585 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), true /* autotimestamp */, |
| 586 | HAL_DATASPACE_UNKNOWN, |
| 587 | bufferCrop /* Rect::INVALID_RECT */, |
| 588 | NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW, 0, |
| 589 | Fence::NO_FENCE); |
| 590 | igbProducer->queueBuffer(slot, input, &qbOutput); |
| 591 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
| 592 | |
| 593 | adapter.waitForCallbacks(); |
| 594 | |
| 595 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 596 | |
| 597 | // Verify cropped region is scaled correctly. |
| 598 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(255, 0, 0, {10, 10, 490, 490})); |
| 599 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 255, 0, {10, 510, 490, 990})); |
| 600 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 0, 255, {510, 10, 990, 490})); |
| 601 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(255, 0, 0, {510, 510, 990, 990})); |
| 602 | // Verify outside region is black. |
| 603 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 0, 0, |
| 604 | {0, 0, (int32_t)windowSize.getWidth(), |
| 605 | (int32_t)windowSize.getHeight()}, |
| 606 | /*border*/ 0, /*outsideRegion*/ true)); |
| 607 | } |
| 608 | |
| 609 | TEST_F(BLASTBufferQueueTest, ScaleCroppedBufferToWindowSize) { |
| 610 | // add black background |
| 611 | auto bg = mClient->createSurface(String8("BGTest"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 612 | ISurfaceComposerClient::eFXSurfaceEffect); |
| 613 | ASSERT_NE(nullptr, bg.get()); |
| 614 | Transaction t; |
| 615 | t.setLayerStack(bg, 0) |
| 616 | .setCrop(bg, Rect(0, 0, mDisplayWidth, mDisplayHeight)) |
| 617 | .setColor(bg, half3{0, 0, 0}) |
| 618 | .setLayer(bg, 0) |
| 619 | .apply(); |
| 620 | |
| 621 | Rect windowSize(1000, 1000); |
| 622 | Rect bufferSize(500, 500); |
| 623 | Rect bufferCrop(100, 100, 350, 350); |
| 624 | |
| 625 | BLASTBufferQueueHelper adapter(mSurfaceControl, windowSize.getWidth(), windowSize.getHeight()); |
| 626 | sp<IGraphicBufferProducer> igbProducer; |
| 627 | setUpProducer(adapter, igbProducer); |
| 628 | int slot; |
| 629 | sp<Fence> fence; |
| 630 | sp<GraphicBuffer> buf; |
| 631 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, bufferSize.getWidth(), |
| 632 | bufferSize.getHeight(), PIXEL_FORMAT_RGBA_8888, |
| 633 | GRALLOC_USAGE_SW_WRITE_OFTEN, nullptr, nullptr); |
| 634 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 635 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 636 | |
| 637 | uint32_t* bufData; |
| 638 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 639 | reinterpret_cast<void**>(&bufData)); |
| 640 | // fill buffer with grey |
| 641 | fillBuffer(bufData, bufferSize, buf->getStride(), 127, 127, 127); |
| 642 | |
| 643 | // fill crop area with different colors so we can verify the cropped region has been scaled |
| 644 | // correctly. |
| 645 | fillBuffer(bufData, Rect(100, 100, 225, 225), buf->getStride(), /* rgb */ 255, 0, 0); |
| 646 | fillBuffer(bufData, Rect(100, 226, 225, 350), buf->getStride(), /* rgb */ 0, 255, 0); |
| 647 | fillBuffer(bufData, Rect(226, 100, 350, 225), buf->getStride(), /* rgb */ 0, 0, 255); |
| 648 | fillBuffer(bufData, Rect(226, 226, 350, 350), buf->getStride(), /* rgb */ 255, 0, 0); |
| 649 | buf->unlock(); |
| 650 | |
| 651 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 652 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), true /* autotimestamp */, |
| 653 | HAL_DATASPACE_UNKNOWN, |
| 654 | bufferCrop /* Rect::INVALID_RECT */, |
| 655 | NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW, 0, |
| 656 | Fence::NO_FENCE); |
| 657 | igbProducer->queueBuffer(slot, input, &qbOutput); |
| 658 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
| 659 | |
| 660 | adapter.waitForCallbacks(); |
| 661 | |
| 662 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 663 | // Verify cropped region is scaled correctly. |
| 664 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(255, 0, 0, {10, 10, 490, 490})); |
| 665 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 255, 0, {10, 510, 490, 990})); |
| 666 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 0, 255, {510, 10, 990, 490})); |
| 667 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(255, 0, 0, {510, 510, 990, 990})); |
| 668 | // Verify outside region is black. |
| 669 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 0, 0, |
| 670 | {0, 0, (int32_t)windowSize.getWidth(), |
| 671 | (int32_t)windowSize.getHeight()}, |
| 672 | /*border*/ 0, /*outsideRegion*/ true)); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 673 | } |
| 674 | |
Vishnu Nair | 932f6ae | 2021-09-29 17:33:10 -0700 | [diff] [blame^] | 675 | // b/196339769 verify we can can update the requested size while the in FREEZE scaling mode and |
| 676 | // scale the buffer properly when the mode changes to SCALE_TO_WINDOW |
| 677 | TEST_F(BLASTBufferQueueTest, ScalingModeChanges) { |
| 678 | uint8_t r = 255; |
| 679 | uint8_t g = 0; |
| 680 | uint8_t b = 0; |
| 681 | |
| 682 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight / 4); |
| 683 | sp<IGraphicBufferProducer> igbProducer; |
| 684 | setUpProducer(adapter, igbProducer); |
| 685 | { |
| 686 | int slot; |
| 687 | sp<Fence> fence; |
| 688 | sp<GraphicBuffer> buf; |
| 689 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight / 4, |
| 690 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 691 | nullptr, nullptr); |
| 692 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 693 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 694 | |
| 695 | uint32_t* bufData; |
| 696 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 697 | reinterpret_cast<void**>(&bufData)); |
| 698 | fillBuffer(bufData, Rect(buf->getWidth(), buf->getHeight()), buf->getStride(), r, g, b); |
| 699 | buf->unlock(); |
| 700 | |
| 701 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 702 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), true /* autotimestamp */, |
| 703 | HAL_DATASPACE_UNKNOWN, {}, |
| 704 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 705 | Fence::NO_FENCE); |
| 706 | igbProducer->queueBuffer(slot, input, &qbOutput); |
| 707 | adapter.waitForCallbacks(); |
| 708 | } |
| 709 | // capture screen and verify that it is red |
| 710 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 711 | |
| 712 | ASSERT_NO_FATAL_FAILURE( |
| 713 | checkScreenCapture(r, g, b, |
| 714 | {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight / 4})); |
| 715 | |
| 716 | // update the size to half the display and dequeue a buffer quarter of the display. |
| 717 | adapter.update(mSurfaceControl, mDisplayWidth, mDisplayHeight / 2); |
| 718 | |
| 719 | { |
| 720 | int slot; |
| 721 | sp<Fence> fence; |
| 722 | sp<GraphicBuffer> buf; |
| 723 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight / 8, |
| 724 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 725 | nullptr, nullptr); |
| 726 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 727 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 728 | |
| 729 | uint32_t* bufData; |
| 730 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 731 | reinterpret_cast<void**>(&bufData)); |
| 732 | g = 255; |
| 733 | fillBuffer(bufData, Rect(buf->getWidth(), buf->getHeight()), buf->getStride(), r, g, b); |
| 734 | buf->unlock(); |
| 735 | |
| 736 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 737 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), true /* autotimestamp */, |
| 738 | HAL_DATASPACE_UNKNOWN, {}, |
| 739 | NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW, |
| 740 | 0, Fence::NO_FENCE); |
| 741 | igbProducer->queueBuffer(slot, input, &qbOutput); |
| 742 | adapter.waitForCallbacks(); |
| 743 | } |
| 744 | // capture screen and verify that it is red |
| 745 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 746 | // verify we still scale the buffer to the new size (half the screen height) |
| 747 | ASSERT_NO_FATAL_FAILURE( |
| 748 | checkScreenCapture(r, g, b, |
| 749 | {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight / 2})); |
| 750 | } |
| 751 | |
Vishnu Nair | 8949612 | 2020-12-14 17:14:53 -0800 | [diff] [blame] | 752 | class TestProducerListener : public BnProducerListener { |
| 753 | public: |
| 754 | sp<IGraphicBufferProducer> mIgbp; |
| 755 | TestProducerListener(const sp<IGraphicBufferProducer>& igbp) : mIgbp(igbp) {} |
| 756 | void onBufferReleased() override { |
| 757 | sp<GraphicBuffer> buffer; |
| 758 | sp<Fence> fence; |
| 759 | mIgbp->detachNextBuffer(&buffer, &fence); |
| 760 | } |
| 761 | }; |
| 762 | |
| 763 | TEST_F(BLASTBufferQueueTest, CustomProducerListener) { |
| 764 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 765 | sp<IGraphicBufferProducer> igbProducer = adapter.getIGraphicBufferProducer(); |
| 766 | ASSERT_NE(nullptr, igbProducer.get()); |
| 767 | ASSERT_EQ(NO_ERROR, igbProducer->setMaxDequeuedBufferCount(2)); |
| 768 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 769 | ASSERT_EQ(NO_ERROR, |
| 770 | igbProducer->connect(new TestProducerListener(igbProducer), NATIVE_WINDOW_API_CPU, |
| 771 | false, &qbOutput)); |
| 772 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
| 773 | for (int i = 0; i < 3; i++) { |
| 774 | int slot; |
| 775 | sp<Fence> fence; |
| 776 | sp<GraphicBuffer> buf; |
| 777 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 778 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 779 | nullptr, nullptr); |
| 780 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 781 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 782 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 783 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), true /* autotimestamp */, |
| 784 | HAL_DATASPACE_UNKNOWN, |
Vishnu Nair | 8949612 | 2020-12-14 17:14:53 -0800 | [diff] [blame] | 785 | Rect(mDisplayWidth, mDisplayHeight), |
| 786 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 787 | Fence::NO_FENCE); |
| 788 | igbProducer->queueBuffer(slot, input, &qbOutput); |
| 789 | } |
| 790 | adapter.waitForCallbacks(); |
| 791 | } |
| 792 | |
Vishnu Nair | 17dde61 | 2020-12-28 11:39:59 -0800 | [diff] [blame] | 793 | TEST_F(BLASTBufferQueueTest, QueryNativeWindowQueuesToWindowComposer) { |
| 794 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 795 | |
| 796 | sp<android::Surface> surface = new Surface(adapter.getIGraphicBufferProducer()); |
| 797 | ANativeWindow* nativeWindow = (ANativeWindow*)(surface.get()); |
| 798 | int queuesToNativeWindow = 0; |
| 799 | int err = nativeWindow->query(nativeWindow, NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER, |
| 800 | &queuesToNativeWindow); |
| 801 | ASSERT_EQ(NO_ERROR, err); |
| 802 | ASSERT_EQ(queuesToNativeWindow, 1); |
| 803 | } |
| 804 | |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 805 | // Test a slow producer doesn't hold up a faster producer from the same client. Essentially tests |
| 806 | // BBQ uses separate transaction queues. |
Vishnu Nair | 277142c | 2021-01-05 18:35:29 -0800 | [diff] [blame] | 807 | TEST_F(BLASTBufferQueueTest, OutOfOrderTransactionTest) { |
| 808 | sp<SurfaceControl> bgSurface = |
| 809 | mClient->createSurface(String8("BGTest"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 810 | ISurfaceComposerClient::eFXSurfaceBufferState); |
| 811 | ASSERT_NE(nullptr, bgSurface.get()); |
| 812 | Transaction t; |
| 813 | t.setLayerStack(bgSurface, 0) |
| 814 | .show(bgSurface) |
| 815 | .setDataspace(bgSurface, ui::Dataspace::V0_SRGB) |
Vishnu Nair | 277142c | 2021-01-05 18:35:29 -0800 | [diff] [blame] | 816 | .setLayer(bgSurface, std::numeric_limits<int32_t>::max() - 1) |
| 817 | .apply(); |
| 818 | |
| 819 | BLASTBufferQueueHelper slowAdapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 820 | sp<IGraphicBufferProducer> slowIgbProducer; |
| 821 | setUpProducer(slowAdapter, slowIgbProducer); |
| 822 | nsecs_t presentTimeDelay = std::chrono::nanoseconds(500ms).count(); |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 823 | queueBuffer(slowIgbProducer, 0 /* r */, 255 /* g */, 0 /* b */, presentTimeDelay); |
Vishnu Nair | 277142c | 2021-01-05 18:35:29 -0800 | [diff] [blame] | 824 | |
| 825 | BLASTBufferQueueHelper fastAdapter(bgSurface, mDisplayWidth, mDisplayHeight); |
| 826 | sp<IGraphicBufferProducer> fastIgbProducer; |
| 827 | setUpProducer(fastAdapter, fastIgbProducer); |
| 828 | uint8_t r = 255; |
| 829 | uint8_t g = 0; |
| 830 | uint8_t b = 0; |
| 831 | queueBuffer(fastIgbProducer, r, g, b, 0 /* presentTimeDelay */); |
| 832 | fastAdapter.waitForCallbacks(); |
| 833 | |
| 834 | // capture screen and verify that it is red |
| 835 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 836 | |
| 837 | ASSERT_NO_FATAL_FAILURE( |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 838 | checkScreenCapture(r, g, b, |
| 839 | {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight / 2})); |
Vishnu Nair | 277142c | 2021-01-05 18:35:29 -0800 | [diff] [blame] | 840 | } |
| 841 | |
Vishnu Nair | a4fbca5 | 2021-07-07 16:52:34 -0700 | [diff] [blame] | 842 | TEST_F(BLASTBufferQueueTest, TransformHint) { |
| 843 | // Transform hint is provided to BBQ via the surface control passed by WM |
| 844 | mSurfaceControl->setTransformHint(ui::Transform::ROT_90); |
| 845 | |
| 846 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 847 | sp<IGraphicBufferProducer> igbProducer = adapter.getIGraphicBufferProducer(); |
| 848 | ASSERT_NE(nullptr, igbProducer.get()); |
| 849 | ASSERT_EQ(NO_ERROR, igbProducer->setMaxDequeuedBufferCount(2)); |
| 850 | sp<Surface> surface = adapter.getSurface(); |
| 851 | |
| 852 | // Before connecting to the surface, we do not get a valid transform hint |
| 853 | int transformHint; |
| 854 | surface->query(NATIVE_WINDOW_TRANSFORM_HINT, &transformHint); |
| 855 | ASSERT_EQ(ui::Transform::ROT_0, transformHint); |
| 856 | |
| 857 | ASSERT_EQ(NO_ERROR, |
| 858 | surface->connect(NATIVE_WINDOW_API_CPU, new TestProducerListener(igbProducer))); |
| 859 | |
| 860 | // After connecting to the surface, we should get the correct hint. |
| 861 | surface->query(NATIVE_WINDOW_TRANSFORM_HINT, &transformHint); |
| 862 | ASSERT_EQ(ui::Transform::ROT_90, transformHint); |
| 863 | |
| 864 | ANativeWindow_Buffer buffer; |
| 865 | surface->lock(&buffer, nullptr /* inOutDirtyBounds */); |
| 866 | |
| 867 | // Transform hint is updated via callbacks or surface control updates |
| 868 | mSurfaceControl->setTransformHint(ui::Transform::ROT_0); |
| 869 | adapter.update(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 870 | |
| 871 | // The hint does not change and matches the value used when dequeueing the buffer. |
| 872 | surface->query(NATIVE_WINDOW_TRANSFORM_HINT, &transformHint); |
| 873 | ASSERT_EQ(ui::Transform::ROT_90, transformHint); |
| 874 | |
| 875 | surface->unlockAndPost(); |
| 876 | |
| 877 | // After queuing the buffer, we get the updated transform hint |
| 878 | surface->query(NATIVE_WINDOW_TRANSFORM_HINT, &transformHint); |
| 879 | ASSERT_EQ(ui::Transform::ROT_0, transformHint); |
| 880 | |
| 881 | adapter.waitForCallbacks(); |
| 882 | } |
| 883 | |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 884 | class BLASTBufferQueueTransformTest : public BLASTBufferQueueTest { |
| 885 | public: |
| 886 | void test(uint32_t tr) { |
| 887 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 888 | sp<IGraphicBufferProducer> igbProducer; |
| 889 | setUpProducer(adapter, igbProducer); |
| 890 | |
| 891 | auto bufWidth = mDisplayWidth; |
| 892 | auto bufHeight = mDisplayHeight; |
| 893 | int slot; |
| 894 | sp<Fence> fence; |
| 895 | sp<GraphicBuffer> buf; |
| 896 | |
| 897 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, bufWidth, bufHeight, |
| 898 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 899 | nullptr, nullptr); |
| 900 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 901 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 902 | |
| 903 | fillQuadrants(buf); |
| 904 | |
| 905 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 906 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), true /* autotimestamp */, |
| 907 | HAL_DATASPACE_UNKNOWN, |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 908 | Rect(bufWidth, bufHeight), |
Vishnu Nair | e1a4232 | 2020-10-02 17:42:04 -0700 | [diff] [blame] | 909 | NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW, |
| 910 | tr, Fence::NO_FENCE); |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 911 | igbProducer->queueBuffer(slot, input, &qbOutput); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 912 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 913 | |
| 914 | adapter.waitForCallbacks(); |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 915 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 916 | |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 917 | switch (tr) { |
| 918 | case ui::Transform::ROT_0: |
| 919 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 0, 0, |
| 920 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 921 | (int32_t)mDisplayHeight / 2}, |
| 922 | 1)); |
| 923 | ASSERT_NO_FATAL_FAILURE( |
| 924 | checkScreenCapture(255, 0, 0, |
| 925 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 926 | (int32_t)mDisplayHeight / 2}, |
| 927 | 1)); |
| 928 | ASSERT_NO_FATAL_FAILURE( |
| 929 | checkScreenCapture(0, 255, 0, |
| 930 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 931 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 932 | 1)); |
| 933 | ASSERT_NO_FATAL_FAILURE( |
| 934 | checkScreenCapture(0, 0, 255, |
| 935 | {0, (int32_t)mDisplayHeight / 2, |
| 936 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 937 | 1)); |
| 938 | break; |
| 939 | case ui::Transform::FLIP_H: |
| 940 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(255, 0, 0, |
| 941 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 942 | (int32_t)mDisplayHeight / 2}, |
| 943 | 1)); |
| 944 | ASSERT_NO_FATAL_FAILURE( |
| 945 | checkScreenCapture(0, 0, 0, |
| 946 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 947 | (int32_t)mDisplayHeight / 2}, |
| 948 | 1)); |
| 949 | ASSERT_NO_FATAL_FAILURE( |
| 950 | checkScreenCapture(0, 0, 255, |
| 951 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 952 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 953 | 1)); |
| 954 | ASSERT_NO_FATAL_FAILURE( |
| 955 | checkScreenCapture(0, 255, 0, |
| 956 | {0, (int32_t)mDisplayHeight / 2, |
| 957 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 958 | 1)); |
| 959 | break; |
| 960 | case ui::Transform::FLIP_V: |
| 961 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 0, 255, |
| 962 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 963 | (int32_t)mDisplayHeight / 2}, |
| 964 | 1)); |
| 965 | ASSERT_NO_FATAL_FAILURE( |
| 966 | checkScreenCapture(0, 255, 0, |
| 967 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 968 | (int32_t)mDisplayHeight / 2}, |
| 969 | 1)); |
| 970 | ASSERT_NO_FATAL_FAILURE( |
| 971 | checkScreenCapture(255, 0, 0, |
| 972 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 973 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 974 | 1)); |
| 975 | ASSERT_NO_FATAL_FAILURE( |
| 976 | checkScreenCapture(0, 0, 0, |
| 977 | {0, (int32_t)mDisplayHeight / 2, |
| 978 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 979 | 1)); |
| 980 | break; |
| 981 | case ui::Transform::ROT_90: |
| 982 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 0, 255, |
| 983 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 984 | (int32_t)mDisplayHeight / 2}, |
| 985 | 1)); |
| 986 | ASSERT_NO_FATAL_FAILURE( |
| 987 | checkScreenCapture(0, 0, 0, |
| 988 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 989 | (int32_t)mDisplayHeight / 2}, |
| 990 | 1)); |
| 991 | ASSERT_NO_FATAL_FAILURE( |
| 992 | checkScreenCapture(255, 0, 0, |
| 993 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 994 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 995 | 1)); |
| 996 | ASSERT_NO_FATAL_FAILURE( |
| 997 | checkScreenCapture(0, 255, 0, |
| 998 | {0, (int32_t)mDisplayHeight / 2, |
| 999 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 1000 | 1)); |
| 1001 | break; |
| 1002 | case ui::Transform::ROT_180: |
| 1003 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 255, 0, |
| 1004 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 1005 | (int32_t)mDisplayHeight / 2}, |
| 1006 | 1)); |
| 1007 | ASSERT_NO_FATAL_FAILURE( |
| 1008 | checkScreenCapture(0, 0, 255, |
| 1009 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 1010 | (int32_t)mDisplayHeight / 2}, |
| 1011 | 1)); |
| 1012 | ASSERT_NO_FATAL_FAILURE( |
| 1013 | checkScreenCapture(0, 0, 0, |
| 1014 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 1015 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 1016 | 1)); |
| 1017 | ASSERT_NO_FATAL_FAILURE( |
| 1018 | checkScreenCapture(255, 0, 0, |
| 1019 | {0, (int32_t)mDisplayHeight / 2, |
| 1020 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 1021 | 1)); |
| 1022 | break; |
| 1023 | case ui::Transform::ROT_270: |
| 1024 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(255, 0, 0, |
| 1025 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 1026 | (int32_t)mDisplayHeight / 2}, |
| 1027 | 1)); |
| 1028 | ASSERT_NO_FATAL_FAILURE( |
| 1029 | checkScreenCapture(0, 255, 0, |
| 1030 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 1031 | (int32_t)mDisplayHeight / 2}, |
| 1032 | 1)); |
| 1033 | ASSERT_NO_FATAL_FAILURE( |
| 1034 | checkScreenCapture(0, 0, 255, |
| 1035 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 1036 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 1037 | 1)); |
| 1038 | ASSERT_NO_FATAL_FAILURE( |
| 1039 | checkScreenCapture(0, 0, 0, |
| 1040 | {0, (int32_t)mDisplayHeight / 2, |
| 1041 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 1042 | 1)); |
| 1043 | } |
| 1044 | } |
| 1045 | }; |
| 1046 | |
| 1047 | TEST_F(BLASTBufferQueueTransformTest, setTransform_ROT_0) { |
| 1048 | test(ui::Transform::ROT_0); |
| 1049 | } |
| 1050 | |
| 1051 | TEST_F(BLASTBufferQueueTransformTest, setTransform_FLIP_H) { |
| 1052 | test(ui::Transform::FLIP_H); |
| 1053 | } |
| 1054 | |
| 1055 | TEST_F(BLASTBufferQueueTransformTest, setTransform_FLIP_V) { |
| 1056 | test(ui::Transform::FLIP_V); |
| 1057 | } |
| 1058 | |
| 1059 | TEST_F(BLASTBufferQueueTransformTest, setTransform_ROT_90) { |
| 1060 | test(ui::Transform::ROT_90); |
| 1061 | } |
| 1062 | |
| 1063 | TEST_F(BLASTBufferQueueTransformTest, setTransform_ROT_180) { |
| 1064 | test(ui::Transform::ROT_180); |
| 1065 | } |
| 1066 | |
| 1067 | TEST_F(BLASTBufferQueueTransformTest, setTransform_ROT_270) { |
| 1068 | test(ui::Transform::ROT_270); |
| 1069 | } |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 1070 | |
| 1071 | class BLASTFrameEventHistoryTest : public BLASTBufferQueueTest { |
| 1072 | public: |
| 1073 | void setUpAndQueueBuffer(const sp<IGraphicBufferProducer>& igbProducer, |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1074 | nsecs_t* outRequestedPresentTime, nsecs_t* postedTime, |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 1075 | IGraphicBufferProducer::QueueBufferOutput* qbOutput, |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1076 | bool getFrameTimestamps, nsecs_t requestedPresentTime = systemTime()) { |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 1077 | int slot; |
| 1078 | sp<Fence> fence; |
| 1079 | sp<GraphicBuffer> buf; |
| 1080 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 1081 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 1082 | nullptr, nullptr); |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1083 | if (IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION == ret) { |
| 1084 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 1085 | } |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 1086 | |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1087 | *outRequestedPresentTime = requestedPresentTime; |
| 1088 | IGraphicBufferProducer::QueueBufferInput input(requestedPresentTime, false, |
| 1089 | HAL_DATASPACE_UNKNOWN, |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 1090 | Rect(mDisplayWidth, mDisplayHeight), |
| 1091 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 1092 | Fence::NO_FENCE, /*sticky*/ 0, |
| 1093 | getFrameTimestamps); |
| 1094 | if (postedTime) *postedTime = systemTime(); |
| 1095 | igbProducer->queueBuffer(slot, input, qbOutput); |
| 1096 | } |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1097 | sp<SurfaceControl> mBufferQueueSurfaceControl; |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 1098 | }; |
| 1099 | |
| 1100 | TEST_F(BLASTFrameEventHistoryTest, FrameEventHistory_Basic) { |
| 1101 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 1102 | sp<IGraphicBufferProducer> igbProducer; |
| 1103 | ProducerFrameEventHistory history; |
| 1104 | setUpProducer(adapter, igbProducer); |
| 1105 | |
| 1106 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 1107 | nsecs_t requestedPresentTimeA = 0; |
| 1108 | nsecs_t postedTimeA = 0; |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 1109 | adapter.setTransactionCompleteCallback(1); |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 1110 | setUpAndQueueBuffer(igbProducer, &requestedPresentTimeA, &postedTimeA, &qbOutput, true); |
| 1111 | history.applyDelta(qbOutput.frameTimestamps); |
| 1112 | |
| 1113 | FrameEvents* events = nullptr; |
| 1114 | events = history.getFrame(1); |
| 1115 | ASSERT_NE(nullptr, events); |
| 1116 | ASSERT_EQ(1, events->frameNumber); |
| 1117 | ASSERT_EQ(requestedPresentTimeA, events->requestedPresentTime); |
| 1118 | ASSERT_GE(events->postedTime, postedTimeA); |
| 1119 | |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 1120 | adapter.waitForCallback(1); |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 1121 | |
| 1122 | // queue another buffer so we query for frame event deltas |
| 1123 | nsecs_t requestedPresentTimeB = 0; |
| 1124 | nsecs_t postedTimeB = 0; |
| 1125 | setUpAndQueueBuffer(igbProducer, &requestedPresentTimeB, &postedTimeB, &qbOutput, true); |
| 1126 | history.applyDelta(qbOutput.frameTimestamps); |
| 1127 | events = history.getFrame(1); |
| 1128 | ASSERT_NE(nullptr, events); |
| 1129 | |
| 1130 | // frame number, requestedPresentTime, and postTime should not have changed |
| 1131 | ASSERT_EQ(1, events->frameNumber); |
| 1132 | ASSERT_EQ(requestedPresentTimeA, events->requestedPresentTime); |
| 1133 | ASSERT_GE(events->postedTime, postedTimeA); |
| 1134 | |
| 1135 | ASSERT_GE(events->latchTime, postedTimeA); |
| 1136 | ASSERT_GE(events->dequeueReadyTime, events->latchTime); |
| 1137 | ASSERT_NE(nullptr, events->gpuCompositionDoneFence); |
| 1138 | ASSERT_NE(nullptr, events->displayPresentFence); |
| 1139 | ASSERT_NE(nullptr, events->releaseFence); |
| 1140 | |
| 1141 | // we should also have gotten the initial values for the next frame |
| 1142 | events = history.getFrame(2); |
| 1143 | ASSERT_NE(nullptr, events); |
| 1144 | ASSERT_EQ(2, events->frameNumber); |
| 1145 | ASSERT_EQ(requestedPresentTimeB, events->requestedPresentTime); |
| 1146 | ASSERT_GE(events->postedTime, postedTimeB); |
Valerie Hau | 78491e9 | 2020-04-15 13:10:56 -0700 | [diff] [blame] | 1147 | |
| 1148 | // wait for any callbacks that have not been received |
| 1149 | adapter.waitForCallbacks(); |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 1150 | } |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1151 | |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1152 | TEST_F(BLASTFrameEventHistoryTest, FrameEventHistory_DroppedFrame) { |
| 1153 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 1154 | sp<IGraphicBufferProducer> igbProducer; |
| 1155 | setUpProducer(adapter, igbProducer); |
| 1156 | |
| 1157 | ProducerFrameEventHistory history; |
| 1158 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 1159 | nsecs_t requestedPresentTimeA = 0; |
| 1160 | nsecs_t postedTimeA = 0; |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1161 | // Present the frame sometime in the future so we can add two frames to the queue so the older |
| 1162 | // one will be dropped. |
| 1163 | nsecs_t presentTime = systemTime() + std::chrono::nanoseconds(500ms).count(); |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1164 | setUpAndQueueBuffer(igbProducer, &requestedPresentTimeA, &postedTimeA, &qbOutput, true, |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1165 | presentTime); |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1166 | history.applyDelta(qbOutput.frameTimestamps); |
| 1167 | |
| 1168 | FrameEvents* events = nullptr; |
| 1169 | events = history.getFrame(1); |
| 1170 | ASSERT_NE(nullptr, events); |
| 1171 | ASSERT_EQ(1, events->frameNumber); |
| 1172 | ASSERT_EQ(requestedPresentTimeA, events->requestedPresentTime); |
| 1173 | ASSERT_GE(events->postedTime, postedTimeA); |
| 1174 | |
| 1175 | // queue another buffer so the first can be dropped |
| 1176 | nsecs_t requestedPresentTimeB = 0; |
| 1177 | nsecs_t postedTimeB = 0; |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1178 | adapter.setTransactionCompleteCallback(2); |
| 1179 | presentTime = systemTime() + std::chrono::nanoseconds(1ms).count(); |
| 1180 | setUpAndQueueBuffer(igbProducer, &requestedPresentTimeB, &postedTimeB, &qbOutput, true, |
| 1181 | presentTime); |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1182 | history.applyDelta(qbOutput.frameTimestamps); |
| 1183 | events = history.getFrame(1); |
| 1184 | ASSERT_NE(nullptr, events); |
| 1185 | |
| 1186 | // frame number, requestedPresentTime, and postTime should not have changed |
| 1187 | ASSERT_EQ(1, events->frameNumber); |
| 1188 | ASSERT_EQ(requestedPresentTimeA, events->requestedPresentTime); |
| 1189 | ASSERT_GE(events->postedTime, postedTimeA); |
| 1190 | |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1191 | // a valid latchtime and pre and post composition info should not be set for the dropped frame |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1192 | ASSERT_FALSE(events->hasLatchInfo()); |
| 1193 | ASSERT_FALSE(events->hasDequeueReadyInfo()); |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1194 | ASSERT_FALSE(events->hasGpuCompositionDoneInfo()); |
| 1195 | ASSERT_FALSE(events->hasDisplayPresentInfo()); |
| 1196 | ASSERT_FALSE(events->hasReleaseInfo()); |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1197 | |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1198 | // wait for the last transaction to be completed. |
| 1199 | adapter.waitForCallback(2); |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1200 | |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1201 | // queue another buffer so we query for frame event deltas |
| 1202 | nsecs_t requestedPresentTimeC = 0; |
| 1203 | nsecs_t postedTimeC = 0; |
| 1204 | setUpAndQueueBuffer(igbProducer, &requestedPresentTimeC, &postedTimeC, &qbOutput, true); |
| 1205 | history.applyDelta(qbOutput.frameTimestamps); |
| 1206 | |
| 1207 | // frame number, requestedPresentTime, and postTime should not have changed |
| 1208 | ASSERT_EQ(1, events->frameNumber); |
| 1209 | ASSERT_EQ(requestedPresentTimeA, events->requestedPresentTime); |
| 1210 | ASSERT_GE(events->postedTime, postedTimeA); |
| 1211 | |
| 1212 | // a valid latchtime and pre and post composition info should not be set for the dropped frame |
| 1213 | ASSERT_FALSE(events->hasLatchInfo()); |
| 1214 | ASSERT_FALSE(events->hasDequeueReadyInfo()); |
| 1215 | ASSERT_FALSE(events->hasGpuCompositionDoneInfo()); |
| 1216 | ASSERT_FALSE(events->hasDisplayPresentInfo()); |
| 1217 | ASSERT_FALSE(events->hasReleaseInfo()); |
| 1218 | |
| 1219 | // we should also have gotten values for the presented frame |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1220 | events = history.getFrame(2); |
| 1221 | ASSERT_NE(nullptr, events); |
| 1222 | ASSERT_EQ(2, events->frameNumber); |
| 1223 | ASSERT_EQ(requestedPresentTimeB, events->requestedPresentTime); |
| 1224 | ASSERT_GE(events->postedTime, postedTimeB); |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1225 | ASSERT_GE(events->latchTime, postedTimeB); |
| 1226 | ASSERT_GE(events->dequeueReadyTime, events->latchTime); |
| 1227 | ASSERT_NE(nullptr, events->gpuCompositionDoneFence); |
| 1228 | ASSERT_NE(nullptr, events->displayPresentFence); |
| 1229 | ASSERT_NE(nullptr, events->releaseFence); |
| 1230 | |
| 1231 | // wait for any callbacks that have not been received |
| 1232 | adapter.waitForCallbacks(); |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1233 | } |
| 1234 | |
Vishnu Nair | 9a69a04 | 2021-06-18 13:19:49 -0700 | [diff] [blame] | 1235 | TEST_F(BLASTFrameEventHistoryTest, FrameEventHistory_CompositorTimings) { |
| 1236 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 1237 | sp<IGraphicBufferProducer> igbProducer; |
| 1238 | ProducerFrameEventHistory history; |
| 1239 | setUpProducer(adapter, igbProducer); |
| 1240 | |
| 1241 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 1242 | nsecs_t requestedPresentTimeA = 0; |
| 1243 | nsecs_t postedTimeA = 0; |
| 1244 | adapter.setTransactionCompleteCallback(1); |
| 1245 | setUpAndQueueBuffer(igbProducer, &requestedPresentTimeA, &postedTimeA, &qbOutput, true); |
| 1246 | history.applyDelta(qbOutput.frameTimestamps); |
| 1247 | adapter.waitForCallback(1); |
| 1248 | |
| 1249 | // queue another buffer so we query for frame event deltas |
| 1250 | nsecs_t requestedPresentTimeB = 0; |
| 1251 | nsecs_t postedTimeB = 0; |
| 1252 | setUpAndQueueBuffer(igbProducer, &requestedPresentTimeB, &postedTimeB, &qbOutput, true); |
| 1253 | history.applyDelta(qbOutput.frameTimestamps); |
| 1254 | |
| 1255 | // check for a valid compositor deadline |
| 1256 | ASSERT_NE(0, history.getReportedCompositeDeadline()); |
| 1257 | |
| 1258 | // wait for any callbacks that have not been received |
| 1259 | adapter.waitForCallbacks(); |
| 1260 | } |
| 1261 | |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 1262 | } // namespace android |