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