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 | |
Vishnu Nair | ea0de00 | 2020-11-17 17:42:37 -0800 | [diff] [blame^] | 58 | int getWidth() { return mBlastBufferQueueAdapter->mSize.width; } |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 59 | |
Vishnu Nair | ea0de00 | 2020-11-17 17:42:37 -0800 | [diff] [blame^] | 60 | int getHeight() { return mBlastBufferQueueAdapter->mSize.height; } |
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()); |
Vishnu Nair | ea0de00 | 2020-11-17 17:42:37 -0800 | [diff] [blame^] | 253 | sp<IGraphicBufferProducer> igbProducer; |
| 254 | setUpProducer(adapter, igbProducer); |
| 255 | |
| 256 | int32_t width; |
| 257 | igbProducer->query(NATIVE_WINDOW_WIDTH, &width); |
| 258 | ASSERT_EQ(mDisplayWidth / 2, width); |
| 259 | int32_t height; |
| 260 | igbProducer->query(NATIVE_WINDOW_HEIGHT, &height); |
| 261 | ASSERT_EQ(mDisplayHeight / 2, height); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | TEST_F(BLASTBufferQueueTest, SetNextTransaction) { |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 265 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 266 | Transaction next; |
| 267 | adapter.setNextTransaction(&next); |
| 268 | ASSERT_EQ(&next, adapter.getNextTransaction()); |
| 269 | } |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 270 | |
Valerie Hau | bf29e04 | 2020-02-06 11:40:38 -0800 | [diff] [blame] | 271 | TEST_F(BLASTBufferQueueTest, DISABLED_onFrameAvailable_ApplyDesiredPresentTime) { |
Valerie Hau | 181abd3 | 2020-01-27 14:18:28 -0800 | [diff] [blame] | 272 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 273 | sp<IGraphicBufferProducer> igbProducer; |
| 274 | setUpProducer(adapter, igbProducer); |
| 275 | |
| 276 | int slot; |
| 277 | sp<Fence> fence; |
| 278 | sp<GraphicBuffer> buf; |
| 279 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 280 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 281 | nullptr, nullptr); |
| 282 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 283 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 284 | |
| 285 | nsecs_t desiredPresentTime = systemTime() + nsecs_t(5 * 1e8); |
| 286 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 287 | IGraphicBufferProducer::QueueBufferInput input(desiredPresentTime, false, HAL_DATASPACE_UNKNOWN, |
| 288 | Rect(mDisplayWidth, mDisplayHeight), |
| 289 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 290 | Fence::NO_FENCE); |
| 291 | igbProducer->queueBuffer(slot, input, &qbOutput); |
| 292 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
| 293 | |
| 294 | adapter.waitForCallbacks(); |
| 295 | ASSERT_GE(systemTime(), desiredPresentTime); |
| 296 | } |
| 297 | |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 298 | TEST_F(BLASTBufferQueueTest, onFrameAvailable_Apply) { |
| 299 | uint8_t r = 255; |
| 300 | uint8_t g = 0; |
| 301 | uint8_t b = 0; |
| 302 | |
| 303 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 304 | sp<IGraphicBufferProducer> igbProducer; |
| 305 | setUpProducer(adapter, igbProducer); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 306 | |
| 307 | int slot; |
| 308 | sp<Fence> fence; |
| 309 | sp<GraphicBuffer> buf; |
| 310 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 311 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 312 | nullptr, nullptr); |
| 313 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 314 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 315 | |
| 316 | uint32_t* bufData; |
| 317 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 318 | reinterpret_cast<void**>(&bufData)); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 319 | fillBuffer(bufData, Rect(buf->getWidth(), buf->getHeight()), buf->getStride(), r, g, b); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 320 | buf->unlock(); |
| 321 | |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 322 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 323 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), false, HAL_DATASPACE_UNKNOWN, |
| 324 | Rect(mDisplayWidth, mDisplayHeight), |
| 325 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 326 | Fence::NO_FENCE); |
| 327 | igbProducer->queueBuffer(slot, input, &qbOutput); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 328 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 329 | |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 330 | adapter.waitForCallbacks(); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 331 | |
| 332 | // capture screen and verify that it is red |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 333 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 334 | ASSERT_NO_FATAL_FAILURE( |
| 335 | checkScreenCapture(r, g, b, {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight})); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 336 | } |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 337 | |
| 338 | TEST_F(BLASTBufferQueueTest, TripleBuffering) { |
| 339 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 340 | sp<IGraphicBufferProducer> igbProducer; |
| 341 | setUpProducer(adapter, igbProducer); |
| 342 | |
| 343 | std::vector<std::pair<int, sp<Fence>>> allocated; |
| 344 | for (int i = 0; i < 3; i++) { |
| 345 | int slot; |
| 346 | sp<Fence> fence; |
| 347 | sp<GraphicBuffer> buf; |
| 348 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 349 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 350 | nullptr, nullptr); |
| 351 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 352 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 353 | allocated.push_back({slot, fence}); |
| 354 | } |
| 355 | for (int i = 0; i < allocated.size(); i++) { |
| 356 | igbProducer->cancelBuffer(allocated[i].first, allocated[i].second); |
| 357 | } |
| 358 | |
Valerie Hau | a32c552 | 2019-12-09 10:11:08 -0800 | [diff] [blame] | 359 | for (int i = 0; i < 100; i++) { |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 360 | int slot; |
| 361 | sp<Fence> fence; |
| 362 | sp<GraphicBuffer> buf; |
| 363 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 364 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 365 | nullptr, nullptr); |
| 366 | ASSERT_EQ(NO_ERROR, ret); |
| 367 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 368 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), false, HAL_DATASPACE_UNKNOWN, |
| 369 | Rect(mDisplayWidth, mDisplayHeight), |
| 370 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 371 | Fence::NO_FENCE); |
| 372 | igbProducer->queueBuffer(slot, input, &qbOutput); |
| 373 | } |
| 374 | adapter.waitForCallbacks(); |
| 375 | } |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 376 | |
| 377 | TEST_F(BLASTBufferQueueTest, SetCrop_Item) { |
| 378 | uint8_t r = 255; |
| 379 | uint8_t g = 0; |
| 380 | uint8_t b = 0; |
| 381 | |
| 382 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 383 | sp<IGraphicBufferProducer> igbProducer; |
| 384 | setUpProducer(adapter, igbProducer); |
| 385 | int slot; |
| 386 | sp<Fence> fence; |
| 387 | sp<GraphicBuffer> buf; |
| 388 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 389 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 390 | nullptr, nullptr); |
| 391 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 392 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 393 | |
| 394 | uint32_t* bufData; |
| 395 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 396 | reinterpret_cast<void**>(&bufData)); |
| 397 | fillBuffer(bufData, Rect(buf->getWidth(), buf->getHeight() / 2), buf->getStride(), r, g, b); |
| 398 | buf->unlock(); |
| 399 | |
| 400 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 401 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), false, HAL_DATASPACE_UNKNOWN, |
| 402 | Rect(mDisplayWidth, mDisplayHeight / 2), |
| 403 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 404 | Fence::NO_FENCE); |
| 405 | igbProducer->queueBuffer(slot, input, &qbOutput); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 406 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 407 | |
| 408 | adapter.waitForCallbacks(); |
| 409 | // capture screen and verify that it is red |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 410 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 411 | |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 412 | ASSERT_NO_FATAL_FAILURE( |
| 413 | checkScreenCapture(r, g, b, {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight})); |
| 414 | } |
| 415 | |
| 416 | TEST_F(BLASTBufferQueueTest, SetCrop_ScalingModeScaleCrop) { |
| 417 | uint8_t r = 255; |
| 418 | uint8_t g = 0; |
| 419 | uint8_t b = 0; |
| 420 | |
| 421 | int32_t bufferSideLength = |
| 422 | (mDisplayWidth < mDisplayHeight) ? mDisplayWidth / 2 : mDisplayHeight / 2; |
| 423 | int32_t finalCropSideLength = bufferSideLength / 2; |
| 424 | |
| 425 | auto bg = mClient->createSurface(String8("BGTest"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 426 | ISurfaceComposerClient::eFXSurfaceEffect); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 427 | ASSERT_NE(nullptr, bg.get()); |
| 428 | Transaction t; |
| 429 | t.setLayerStack(bg, 0) |
| 430 | .setCrop_legacy(bg, Rect(0, 0, mDisplayWidth, mDisplayHeight)) |
| 431 | .setColor(bg, half3{0, 0, 0}) |
| 432 | .setLayer(bg, 0) |
| 433 | .apply(); |
| 434 | |
| 435 | BLASTBufferQueueHelper adapter(mSurfaceControl, bufferSideLength, bufferSideLength); |
| 436 | sp<IGraphicBufferProducer> igbProducer; |
| 437 | setUpProducer(adapter, igbProducer); |
| 438 | int slot; |
| 439 | sp<Fence> fence; |
| 440 | sp<GraphicBuffer> buf; |
| 441 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, bufferSideLength, bufferSideLength, |
| 442 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 443 | nullptr, nullptr); |
| 444 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 445 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 446 | |
| 447 | uint32_t* bufData; |
| 448 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 449 | reinterpret_cast<void**>(&bufData)); |
| 450 | fillBuffer(bufData, Rect(buf->getWidth(), buf->getHeight()), buf->getStride(), 0, 0, 0); |
| 451 | fillBuffer(bufData, |
| 452 | Rect(finalCropSideLength / 2, 0, buf->getWidth() - finalCropSideLength / 2, |
| 453 | buf->getHeight()), |
| 454 | buf->getStride(), r, g, b); |
| 455 | buf->unlock(); |
| 456 | |
| 457 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 458 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), false, HAL_DATASPACE_UNKNOWN, |
| 459 | Rect(bufferSideLength, finalCropSideLength), |
| 460 | NATIVE_WINDOW_SCALING_MODE_SCALE_CROP, 0, |
| 461 | Fence::NO_FENCE); |
| 462 | igbProducer->queueBuffer(slot, input, &qbOutput); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 463 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 464 | |
| 465 | adapter.waitForCallbacks(); |
| 466 | // capture screen and verify that it is red |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 467 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 468 | |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 469 | ASSERT_NO_FATAL_FAILURE( |
| 470 | checkScreenCapture(r, g, b, |
| 471 | {0, 0, (int32_t)bufferSideLength, (int32_t)bufferSideLength})); |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 472 | ASSERT_NO_FATAL_FAILURE( |
| 473 | checkScreenCapture(0, 0, 0, |
| 474 | {0, 0, (int32_t)bufferSideLength, (int32_t)bufferSideLength}, |
| 475 | /*border*/ 0, /*outsideRegion*/ true)); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 476 | } |
| 477 | |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 478 | class BLASTBufferQueueTransformTest : public BLASTBufferQueueTest { |
| 479 | public: |
| 480 | void test(uint32_t tr) { |
| 481 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 482 | sp<IGraphicBufferProducer> igbProducer; |
| 483 | setUpProducer(adapter, igbProducer); |
| 484 | |
| 485 | auto bufWidth = mDisplayWidth; |
| 486 | auto bufHeight = mDisplayHeight; |
| 487 | int slot; |
| 488 | sp<Fence> fence; |
| 489 | sp<GraphicBuffer> buf; |
| 490 | |
| 491 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, bufWidth, bufHeight, |
| 492 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 493 | nullptr, nullptr); |
| 494 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 495 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 496 | |
| 497 | fillQuadrants(buf); |
| 498 | |
| 499 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 500 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), false, HAL_DATASPACE_UNKNOWN, |
| 501 | Rect(bufWidth, bufHeight), |
Vishnu Nair | e1a4232 | 2020-10-02 17:42:04 -0700 | [diff] [blame] | 502 | NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW, |
| 503 | tr, Fence::NO_FENCE); |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 504 | igbProducer->queueBuffer(slot, input, &qbOutput); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 505 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 506 | |
| 507 | adapter.waitForCallbacks(); |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 508 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 509 | |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 510 | switch (tr) { |
| 511 | case ui::Transform::ROT_0: |
| 512 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 0, 0, |
| 513 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 514 | (int32_t)mDisplayHeight / 2}, |
| 515 | 1)); |
| 516 | ASSERT_NO_FATAL_FAILURE( |
| 517 | checkScreenCapture(255, 0, 0, |
| 518 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 519 | (int32_t)mDisplayHeight / 2}, |
| 520 | 1)); |
| 521 | ASSERT_NO_FATAL_FAILURE( |
| 522 | checkScreenCapture(0, 255, 0, |
| 523 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 524 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 525 | 1)); |
| 526 | ASSERT_NO_FATAL_FAILURE( |
| 527 | checkScreenCapture(0, 0, 255, |
| 528 | {0, (int32_t)mDisplayHeight / 2, |
| 529 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 530 | 1)); |
| 531 | break; |
| 532 | case ui::Transform::FLIP_H: |
| 533 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(255, 0, 0, |
| 534 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 535 | (int32_t)mDisplayHeight / 2}, |
| 536 | 1)); |
| 537 | ASSERT_NO_FATAL_FAILURE( |
| 538 | checkScreenCapture(0, 0, 0, |
| 539 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 540 | (int32_t)mDisplayHeight / 2}, |
| 541 | 1)); |
| 542 | ASSERT_NO_FATAL_FAILURE( |
| 543 | checkScreenCapture(0, 0, 255, |
| 544 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 545 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 546 | 1)); |
| 547 | ASSERT_NO_FATAL_FAILURE( |
| 548 | checkScreenCapture(0, 255, 0, |
| 549 | {0, (int32_t)mDisplayHeight / 2, |
| 550 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 551 | 1)); |
| 552 | break; |
| 553 | case ui::Transform::FLIP_V: |
| 554 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 0, 255, |
| 555 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 556 | (int32_t)mDisplayHeight / 2}, |
| 557 | 1)); |
| 558 | ASSERT_NO_FATAL_FAILURE( |
| 559 | checkScreenCapture(0, 255, 0, |
| 560 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 561 | (int32_t)mDisplayHeight / 2}, |
| 562 | 1)); |
| 563 | ASSERT_NO_FATAL_FAILURE( |
| 564 | checkScreenCapture(255, 0, 0, |
| 565 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 566 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 567 | 1)); |
| 568 | ASSERT_NO_FATAL_FAILURE( |
| 569 | checkScreenCapture(0, 0, 0, |
| 570 | {0, (int32_t)mDisplayHeight / 2, |
| 571 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 572 | 1)); |
| 573 | break; |
| 574 | case ui::Transform::ROT_90: |
| 575 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 0, 255, |
| 576 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 577 | (int32_t)mDisplayHeight / 2}, |
| 578 | 1)); |
| 579 | ASSERT_NO_FATAL_FAILURE( |
| 580 | checkScreenCapture(0, 0, 0, |
| 581 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 582 | (int32_t)mDisplayHeight / 2}, |
| 583 | 1)); |
| 584 | ASSERT_NO_FATAL_FAILURE( |
| 585 | checkScreenCapture(255, 0, 0, |
| 586 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 587 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 588 | 1)); |
| 589 | ASSERT_NO_FATAL_FAILURE( |
| 590 | checkScreenCapture(0, 255, 0, |
| 591 | {0, (int32_t)mDisplayHeight / 2, |
| 592 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 593 | 1)); |
| 594 | break; |
| 595 | case ui::Transform::ROT_180: |
| 596 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 255, 0, |
| 597 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 598 | (int32_t)mDisplayHeight / 2}, |
| 599 | 1)); |
| 600 | ASSERT_NO_FATAL_FAILURE( |
| 601 | checkScreenCapture(0, 0, 255, |
| 602 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 603 | (int32_t)mDisplayHeight / 2}, |
| 604 | 1)); |
| 605 | ASSERT_NO_FATAL_FAILURE( |
| 606 | checkScreenCapture(0, 0, 0, |
| 607 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 608 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 609 | 1)); |
| 610 | ASSERT_NO_FATAL_FAILURE( |
| 611 | checkScreenCapture(255, 0, 0, |
| 612 | {0, (int32_t)mDisplayHeight / 2, |
| 613 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 614 | 1)); |
| 615 | break; |
| 616 | case ui::Transform::ROT_270: |
| 617 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(255, 0, 0, |
| 618 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 619 | (int32_t)mDisplayHeight / 2}, |
| 620 | 1)); |
| 621 | ASSERT_NO_FATAL_FAILURE( |
| 622 | checkScreenCapture(0, 255, 0, |
| 623 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 624 | (int32_t)mDisplayHeight / 2}, |
| 625 | 1)); |
| 626 | ASSERT_NO_FATAL_FAILURE( |
| 627 | checkScreenCapture(0, 0, 255, |
| 628 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 629 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 630 | 1)); |
| 631 | ASSERT_NO_FATAL_FAILURE( |
| 632 | checkScreenCapture(0, 0, 0, |
| 633 | {0, (int32_t)mDisplayHeight / 2, |
| 634 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 635 | 1)); |
| 636 | } |
| 637 | } |
| 638 | }; |
| 639 | |
| 640 | TEST_F(BLASTBufferQueueTransformTest, setTransform_ROT_0) { |
| 641 | test(ui::Transform::ROT_0); |
| 642 | } |
| 643 | |
| 644 | TEST_F(BLASTBufferQueueTransformTest, setTransform_FLIP_H) { |
| 645 | test(ui::Transform::FLIP_H); |
| 646 | } |
| 647 | |
| 648 | TEST_F(BLASTBufferQueueTransformTest, setTransform_FLIP_V) { |
| 649 | test(ui::Transform::FLIP_V); |
| 650 | } |
| 651 | |
| 652 | TEST_F(BLASTBufferQueueTransformTest, setTransform_ROT_90) { |
| 653 | test(ui::Transform::ROT_90); |
| 654 | } |
| 655 | |
| 656 | TEST_F(BLASTBufferQueueTransformTest, setTransform_ROT_180) { |
| 657 | test(ui::Transform::ROT_180); |
| 658 | } |
| 659 | |
| 660 | TEST_F(BLASTBufferQueueTransformTest, setTransform_ROT_270) { |
| 661 | test(ui::Transform::ROT_270); |
| 662 | } |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 663 | |
| 664 | class BLASTFrameEventHistoryTest : public BLASTBufferQueueTest { |
| 665 | public: |
| 666 | void setUpAndQueueBuffer(const sp<IGraphicBufferProducer>& igbProducer, |
| 667 | nsecs_t* requestedPresentTime, nsecs_t* postedTime, |
| 668 | IGraphicBufferProducer::QueueBufferOutput* qbOutput, |
| 669 | bool getFrameTimestamps) { |
| 670 | int slot; |
| 671 | sp<Fence> fence; |
| 672 | sp<GraphicBuffer> buf; |
| 673 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 674 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 675 | nullptr, nullptr); |
| 676 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 677 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 678 | |
| 679 | nsecs_t requestedTime = systemTime(); |
| 680 | if (requestedPresentTime) *requestedPresentTime = requestedTime; |
| 681 | IGraphicBufferProducer::QueueBufferInput input(requestedTime, false, HAL_DATASPACE_UNKNOWN, |
| 682 | Rect(mDisplayWidth, mDisplayHeight), |
| 683 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 684 | Fence::NO_FENCE, /*sticky*/ 0, |
| 685 | getFrameTimestamps); |
| 686 | if (postedTime) *postedTime = systemTime(); |
| 687 | igbProducer->queueBuffer(slot, input, qbOutput); |
| 688 | } |
| 689 | }; |
| 690 | |
| 691 | TEST_F(BLASTFrameEventHistoryTest, FrameEventHistory_Basic) { |
| 692 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 693 | sp<IGraphicBufferProducer> igbProducer; |
| 694 | ProducerFrameEventHistory history; |
| 695 | setUpProducer(adapter, igbProducer); |
| 696 | |
| 697 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 698 | nsecs_t requestedPresentTimeA = 0; |
| 699 | nsecs_t postedTimeA = 0; |
| 700 | setUpAndQueueBuffer(igbProducer, &requestedPresentTimeA, &postedTimeA, &qbOutput, true); |
| 701 | history.applyDelta(qbOutput.frameTimestamps); |
| 702 | |
| 703 | FrameEvents* events = nullptr; |
| 704 | events = history.getFrame(1); |
| 705 | ASSERT_NE(nullptr, events); |
| 706 | ASSERT_EQ(1, events->frameNumber); |
| 707 | ASSERT_EQ(requestedPresentTimeA, events->requestedPresentTime); |
| 708 | ASSERT_GE(events->postedTime, postedTimeA); |
| 709 | |
| 710 | adapter.waitForCallbacks(); |
| 711 | |
| 712 | // queue another buffer so we query for frame event deltas |
| 713 | nsecs_t requestedPresentTimeB = 0; |
| 714 | nsecs_t postedTimeB = 0; |
| 715 | setUpAndQueueBuffer(igbProducer, &requestedPresentTimeB, &postedTimeB, &qbOutput, true); |
| 716 | history.applyDelta(qbOutput.frameTimestamps); |
| 717 | events = history.getFrame(1); |
| 718 | ASSERT_NE(nullptr, events); |
| 719 | |
| 720 | // frame number, requestedPresentTime, and postTime should not have changed |
| 721 | ASSERT_EQ(1, events->frameNumber); |
| 722 | ASSERT_EQ(requestedPresentTimeA, events->requestedPresentTime); |
| 723 | ASSERT_GE(events->postedTime, postedTimeA); |
| 724 | |
| 725 | ASSERT_GE(events->latchTime, postedTimeA); |
| 726 | ASSERT_GE(events->dequeueReadyTime, events->latchTime); |
| 727 | ASSERT_NE(nullptr, events->gpuCompositionDoneFence); |
| 728 | ASSERT_NE(nullptr, events->displayPresentFence); |
| 729 | ASSERT_NE(nullptr, events->releaseFence); |
| 730 | |
| 731 | // we should also have gotten the initial values for the next frame |
| 732 | events = history.getFrame(2); |
| 733 | ASSERT_NE(nullptr, events); |
| 734 | ASSERT_EQ(2, events->frameNumber); |
| 735 | ASSERT_EQ(requestedPresentTimeB, events->requestedPresentTime); |
| 736 | ASSERT_GE(events->postedTime, postedTimeB); |
Valerie Hau | 78491e9 | 2020-04-15 13:10:56 -0700 | [diff] [blame] | 737 | |
| 738 | // wait for any callbacks that have not been received |
| 739 | adapter.waitForCallbacks(); |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 740 | } |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 741 | } // namespace android |