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