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> |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 22 | #include <gui/AidlStatusUtil.h> |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 23 | #include <gui/BufferQueueCore.h> |
| 24 | #include <gui/BufferQueueProducer.h> |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 25 | #include <gui/FrameTimestamps.h> |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 26 | #include <gui/IGraphicBufferProducer.h> |
| 27 | #include <gui/IProducerListener.h> |
Vishnu Nair | 17dde61 | 2020-12-28 11:39:59 -0800 | [diff] [blame] | 28 | #include <gui/Surface.h> |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 29 | #include <gui/SurfaceComposerClient.h> |
chaviw | e7b9f27 | 2020-08-18 16:08:59 -0700 | [diff] [blame] | 30 | #include <gui/SyncScreenCaptureListener.h> |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 31 | #include <gui/test/CallbackUtils.h> |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 32 | #include <private/gui/ComposerService.h> |
Huihong Luo | 9e84f33 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 33 | #include <private/gui/ComposerServiceAIDL.h> |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 34 | #include <ui/DisplayMode.h> |
Vishnu Nair | 5b5f693 | 2023-04-12 16:28:19 -0700 | [diff] [blame] | 35 | #include <ui/DisplayState.h> |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 36 | #include <ui/GraphicBuffer.h> |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 37 | #include <ui/GraphicTypes.h> |
Valerie Hau | 8cee3f9 | 2019-11-06 10:06:28 -0800 | [diff] [blame] | 38 | #include <ui/Transform.h> |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 39 | |
| 40 | #include <gtest/gtest.h> |
| 41 | |
| 42 | using namespace std::chrono_literals; |
| 43 | |
| 44 | namespace android { |
| 45 | |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 46 | using Transaction = SurfaceComposerClient::Transaction; |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 47 | using android::hardware::graphics::common::V1_2::BufferUsage; |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 48 | |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 49 | class CountProducerListener : public BnProducerListener { |
| 50 | public: |
| 51 | void onBufferReleased() override { |
| 52 | std::scoped_lock<std::mutex> lock(mMutex); |
| 53 | mNumReleased++; |
| 54 | mReleaseCallback.notify_one(); |
| 55 | } |
| 56 | |
| 57 | void waitOnNumberReleased(int32_t expectedNumReleased) { |
| 58 | std::unique_lock<std::mutex> lock(mMutex); |
| 59 | while (mNumReleased < expectedNumReleased) { |
| 60 | ASSERT_NE(mReleaseCallback.wait_for(lock, std::chrono::seconds(3)), |
| 61 | std::cv_status::timeout) |
| 62 | << "did not receive release"; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | private: |
| 67 | std::mutex mMutex; |
| 68 | std::condition_variable mReleaseCallback; |
| 69 | int32_t mNumReleased GUARDED_BY(mMutex) = 0; |
| 70 | }; |
| 71 | |
chaviw | f10b904 | 2021-10-13 15:48:59 -0500 | [diff] [blame] | 72 | class TestBLASTBufferQueue : public BLASTBufferQueue { |
| 73 | public: |
| 74 | TestBLASTBufferQueue(const std::string& name, const sp<SurfaceControl>& surface, int width, |
| 75 | int height, int32_t format) |
| 76 | : BLASTBufferQueue(name, surface, width, height, format) {} |
| 77 | |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 78 | void transactionCallback(nsecs_t latchTime, const sp<Fence>& presentFence, |
| 79 | const std::vector<SurfaceControlStats>& stats) override { |
| 80 | BLASTBufferQueue::transactionCallback(latchTime, presentFence, stats); |
chaviw | f10b904 | 2021-10-13 15:48:59 -0500 | [diff] [blame] | 81 | uint64_t frameNumber = stats[0].frameEventStats.frameNumber; |
| 82 | |
| 83 | { |
| 84 | std::unique_lock lock{frameNumberMutex}; |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 85 | mLastTransactionFrameNumber = frameNumber; |
| 86 | mWaitForCallbackCV.notify_all(); |
chaviw | f10b904 | 2021-10-13 15:48:59 -0500 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | |
| 90 | void waitForCallback(int64_t frameNumber) { |
| 91 | std::unique_lock lock{frameNumberMutex}; |
| 92 | // Wait until all but one of the submitted buffers have been released. |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 93 | while (mLastTransactionFrameNumber < frameNumber) { |
| 94 | mWaitForCallbackCV.wait(lock); |
chaviw | f10b904 | 2021-10-13 15:48:59 -0500 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
| 98 | private: |
| 99 | std::mutex frameNumberMutex; |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 100 | std::condition_variable mWaitForCallbackCV; |
| 101 | int64_t mLastTransactionFrameNumber = -1; |
chaviw | f10b904 | 2021-10-13 15:48:59 -0500 | [diff] [blame] | 102 | }; |
| 103 | |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 104 | class BLASTBufferQueueHelper { |
| 105 | public: |
| 106 | BLASTBufferQueueHelper(const sp<SurfaceControl>& sc, int width, int height) { |
chaviw | f10b904 | 2021-10-13 15:48:59 -0500 | [diff] [blame] | 107 | mBlastBufferQueueAdapter = new TestBLASTBufferQueue("TestBLASTBufferQueue", sc, width, |
| 108 | height, PIXEL_FORMAT_RGBA_8888); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | void update(const sp<SurfaceControl>& sc, int width, int height) { |
chaviw | 565ee54 | 2021-01-14 10:21:23 -0800 | [diff] [blame] | 112 | mBlastBufferQueueAdapter->update(sc, width, height, PIXEL_FORMAT_RGBA_8888); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 115 | void setSyncTransaction(Transaction& next, bool acquireSingleBuffer = true) { |
| 116 | auto callback = [&next](Transaction* t) { next.merge(std::move(*t)); }; |
| 117 | mBlastBufferQueueAdapter->syncNextTransaction(callback, acquireSingleBuffer); |
| 118 | } |
| 119 | |
Chavi Weingarten | c398c01 | 2023-04-12 17:26:02 +0000 | [diff] [blame] | 120 | bool syncNextTransaction(std::function<void(Transaction*)> callback, |
Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 121 | bool acquireSingleBuffer = true) { |
Chavi Weingarten | c398c01 | 2023-04-12 17:26:02 +0000 | [diff] [blame] | 122 | return mBlastBufferQueueAdapter->syncNextTransaction(callback, acquireSingleBuffer); |
Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | void stopContinuousSyncTransaction() { |
| 126 | mBlastBufferQueueAdapter->stopContinuousSyncTransaction(); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Chavi Weingarten | c398c01 | 2023-04-12 17:26:02 +0000 | [diff] [blame] | 129 | void clearSyncTransaction() { mBlastBufferQueueAdapter->clearSyncTransaction(); } |
| 130 | |
Vishnu Nair | ea0de00 | 2020-11-17 17:42:37 -0800 | [diff] [blame] | 131 | int getWidth() { return mBlastBufferQueueAdapter->mSize.width; } |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 132 | |
Vishnu Nair | ea0de00 | 2020-11-17 17:42:37 -0800 | [diff] [blame] | 133 | int getHeight() { return mBlastBufferQueueAdapter->mSize.height; } |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 134 | |
Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 135 | std::function<void(Transaction*)> getTransactionReadyCallback() { |
| 136 | return mBlastBufferQueueAdapter->mTransactionReadyCallback; |
| 137 | } |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 138 | |
| 139 | sp<IGraphicBufferProducer> getIGraphicBufferProducer() { |
| 140 | return mBlastBufferQueueAdapter->getIGraphicBufferProducer(); |
| 141 | } |
| 142 | |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 143 | const sp<SurfaceControl> getSurfaceControl() { |
| 144 | return mBlastBufferQueueAdapter->mSurfaceControl; |
| 145 | } |
| 146 | |
Vishnu Nair | a4fbca5 | 2021-07-07 16:52:34 -0700 | [diff] [blame] | 147 | sp<Surface> getSurface() { |
| 148 | return mBlastBufferQueueAdapter->getSurface(false /* includeSurfaceControlHandle */); |
| 149 | } |
| 150 | |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 151 | void waitForCallbacks() { |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 152 | std::unique_lock lock{mBlastBufferQueueAdapter->mMutex}; |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 153 | // Wait until all but one of the submitted buffers have been released. |
| 154 | while (mBlastBufferQueueAdapter->mSubmitted.size() > 1) { |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 155 | mBlastBufferQueueAdapter->mCallbackCV.wait(lock); |
| 156 | } |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 159 | void waitForCallback(int64_t frameNumber) { |
chaviw | f10b904 | 2021-10-13 15:48:59 -0500 | [diff] [blame] | 160 | mBlastBufferQueueAdapter->waitForCallback(frameNumber); |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 161 | } |
| 162 | |
chaviw | 0acd33a | 2021-11-02 11:55:37 -0500 | [diff] [blame] | 163 | void validateNumFramesSubmitted(int64_t numFramesSubmitted) { |
| 164 | std::unique_lock lock{mBlastBufferQueueAdapter->mMutex}; |
| 165 | ASSERT_EQ(numFramesSubmitted, mBlastBufferQueueAdapter->mSubmitted.size()); |
| 166 | } |
| 167 | |
chaviw | c1cf402 | 2022-06-03 13:32:33 -0500 | [diff] [blame] | 168 | void mergeWithNextTransaction(Transaction* merge, uint64_t frameNumber) { |
| 169 | mBlastBufferQueueAdapter->mergeWithNextTransaction(merge, frameNumber); |
| 170 | } |
| 171 | |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 172 | private: |
chaviw | f10b904 | 2021-10-13 15:48:59 -0500 | [diff] [blame] | 173 | sp<TestBLASTBufferQueue> mBlastBufferQueueAdapter; |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 174 | }; |
| 175 | |
| 176 | class BLASTBufferQueueTest : public ::testing::Test { |
| 177 | public: |
| 178 | protected: |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 179 | void SetUp() { |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 180 | mComposer = ComposerService::getComposerService(); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 181 | mClient = new SurfaceComposerClient(); |
Huihong Luo | 31b5ac2 | 2022-08-15 20:38:10 -0700 | [diff] [blame] | 182 | const auto ids = SurfaceComposerClient::getPhysicalDisplayIds(); |
| 183 | ASSERT_FALSE(ids.empty()); |
| 184 | // display 0 is picked as this test is not much display depedent |
| 185 | mDisplayToken = SurfaceComposerClient::getPhysicalDisplayToken(ids.front()); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 186 | ASSERT_NE(nullptr, mDisplayToken.get()); |
| 187 | Transaction t; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 188 | t.setDisplayLayerStack(mDisplayToken, ui::DEFAULT_LAYER_STACK); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 189 | t.apply(); |
| 190 | t.clear(); |
| 191 | |
Vishnu Nair | 5b5f693 | 2023-04-12 16:28:19 -0700 | [diff] [blame] | 192 | ui::DisplayState displayState; |
| 193 | ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayState(mDisplayToken, &displayState)); |
| 194 | const ui::Size& resolution = displayState.layerStackSpaceRect; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 195 | mDisplayWidth = resolution.getWidth(); |
| 196 | mDisplayHeight = resolution.getHeight(); |
Nolan Scobie | f50aebc | 2023-04-13 17:49:18 +0000 | [diff] [blame] | 197 | ALOGD("Display: %dx%d orientation:%d", mDisplayWidth, mDisplayHeight, |
Vishnu Nair | 5b5f693 | 2023-04-12 16:28:19 -0700 | [diff] [blame] | 198 | displayState.orientation); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 199 | |
| 200 | mSurfaceControl = mClient->createSurface(String8("TestSurface"), mDisplayWidth, |
| 201 | mDisplayHeight, PIXEL_FORMAT_RGBA_8888, |
| 202 | ISurfaceComposerClient::eFXSurfaceBufferState, |
| 203 | /*parent*/ nullptr); |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 204 | t.setLayerStack(mSurfaceControl, ui::DEFAULT_LAYER_STACK) |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 205 | .setLayer(mSurfaceControl, std::numeric_limits<int32_t>::max()) |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 206 | .show(mSurfaceControl) |
| 207 | .setDataspace(mSurfaceControl, ui::Dataspace::V0_SRGB) |
| 208 | .apply(); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 209 | |
| 210 | mCaptureArgs.displayToken = mDisplayToken; |
arthurhung | 6fa58b7 | 2020-11-05 11:56:00 +0800 | [diff] [blame] | 211 | mCaptureArgs.dataspace = ui::Dataspace::V0_SRGB; |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 212 | } |
| 213 | |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 214 | void setUpProducer(BLASTBufferQueueHelper& adapter, sp<IGraphicBufferProducer>& producer, |
| 215 | int32_t maxBufferCount = 2) { |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 216 | producer = adapter.getIGraphicBufferProducer(); |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 217 | setUpProducer(producer, maxBufferCount); |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 218 | } |
| 219 | |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 220 | void setUpProducer(sp<IGraphicBufferProducer>& igbProducer, int32_t maxBufferCount) { |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 221 | ASSERT_NE(nullptr, igbProducer.get()); |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 222 | ASSERT_EQ(NO_ERROR, igbProducer->setMaxDequeuedBufferCount(maxBufferCount)); |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 223 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 224 | mProducerListener = new CountProducerListener(); |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 225 | ASSERT_EQ(NO_ERROR, |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 226 | igbProducer->connect(mProducerListener, NATIVE_WINDOW_API_CPU, false, &qbOutput)); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 227 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 228 | } |
| 229 | |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 230 | void fillBuffer(uint32_t* bufData, Rect rect, uint32_t stride, uint8_t r, uint8_t g, |
| 231 | uint8_t b) { |
| 232 | for (uint32_t row = rect.top; row < rect.bottom; row++) { |
| 233 | for (uint32_t col = rect.left; col < rect.right; col++) { |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 234 | uint8_t* pixel = (uint8_t*)(bufData + (row * stride) + col); |
| 235 | *pixel = r; |
| 236 | *(pixel + 1) = g; |
| 237 | *(pixel + 2) = b; |
| 238 | *(pixel + 3) = 255; |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 243 | void fillQuadrants(sp<GraphicBuffer>& buf) { |
| 244 | const auto bufWidth = buf->getWidth(); |
| 245 | const auto bufHeight = buf->getHeight(); |
| 246 | uint32_t* bufData; |
| 247 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 248 | reinterpret_cast<void**>(&bufData)); |
| 249 | fillBuffer(bufData, Rect(0, 0, bufWidth / 2, bufHeight / 2), buf->getStride(), 0, 0, 0); |
| 250 | fillBuffer(bufData, Rect(bufWidth / 2, 0, bufWidth, bufHeight / 2), buf->getStride(), 255, |
| 251 | 0, 0); |
| 252 | fillBuffer(bufData, Rect(bufWidth / 2, bufHeight / 2, bufWidth, bufHeight), |
| 253 | buf->getStride(), 0, 255, 0); |
| 254 | fillBuffer(bufData, Rect(0, bufHeight / 2, bufWidth / 2, bufHeight), buf->getStride(), 0, 0, |
| 255 | 255); |
| 256 | buf->unlock(); |
| 257 | } |
| 258 | |
| 259 | void checkScreenCapture(uint8_t r, uint8_t g, uint8_t b, Rect region, int32_t border = 0, |
| 260 | bool outsideRegion = false) { |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 261 | sp<GraphicBuffer>& captureBuf = mCaptureResults.buffer; |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 262 | const auto epsilon = 3; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 263 | const auto width = captureBuf->getWidth(); |
| 264 | const auto height = captureBuf->getHeight(); |
| 265 | const auto stride = captureBuf->getStride(); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 266 | |
| 267 | uint32_t* bufData; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 268 | captureBuf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_READ_OFTEN), |
| 269 | reinterpret_cast<void**>(&bufData)); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 270 | |
| 271 | for (uint32_t row = 0; row < height; row++) { |
| 272 | for (uint32_t col = 0; col < width; col++) { |
| 273 | uint8_t* pixel = (uint8_t*)(bufData + (row * stride) + col); |
arthurhung | 6fa58b7 | 2020-11-05 11:56:00 +0800 | [diff] [blame] | 274 | ASSERT_NE(nullptr, pixel); |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 275 | bool inRegion; |
| 276 | if (!outsideRegion) { |
| 277 | inRegion = row >= region.top + border && row < region.bottom - border && |
| 278 | col >= region.left + border && col < region.right - border; |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 279 | } else { |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 280 | inRegion = row >= region.top - border && row < region.bottom + border && |
| 281 | col >= region.left - border && col < region.right + border; |
| 282 | } |
| 283 | if (!outsideRegion && inRegion) { |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 284 | ASSERT_GE(epsilon, abs(r - *(pixel))); |
| 285 | ASSERT_GE(epsilon, abs(g - *(pixel + 1))); |
| 286 | ASSERT_GE(epsilon, abs(b - *(pixel + 2))); |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 287 | } else if (outsideRegion && !inRegion) { |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 288 | ASSERT_GE(epsilon, abs(r - *(pixel))); |
| 289 | ASSERT_GE(epsilon, abs(g - *(pixel + 1))); |
| 290 | ASSERT_GE(epsilon, abs(b - *(pixel + 2))); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 291 | } |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 292 | ASSERT_EQ(false, ::testing::Test::HasFailure()); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 293 | } |
| 294 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 295 | captureBuf->unlock(); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 296 | } |
| 297 | |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 298 | static status_t captureDisplay(DisplayCaptureArgs& captureArgs, |
| 299 | ScreenCaptureResults& captureResults) { |
Huihong Luo | 9e84f33 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 300 | const auto sf = ComposerServiceAIDL::getComposerService(); |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 301 | SurfaceComposerClient::Transaction().apply(true); |
| 302 | |
| 303 | const sp<SyncScreenCaptureListener> captureListener = new SyncScreenCaptureListener(); |
Huihong Luo | 9e84f33 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 304 | binder::Status status = sf->captureDisplay(captureArgs, captureListener); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 305 | status_t err = gui::aidl_utils::statusTFromBinderStatus(status); |
| 306 | if (err != NO_ERROR) { |
| 307 | return err; |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 308 | } |
| 309 | captureResults = captureListener->waitForResults(); |
Patrick Williams | fdb57bb | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 310 | return fenceStatus(captureResults.fenceResult); |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Vishnu Nair | 277142c | 2021-01-05 18:35:29 -0800 | [diff] [blame] | 313 | void queueBuffer(sp<IGraphicBufferProducer> igbp, uint8_t r, uint8_t g, uint8_t b, |
| 314 | nsecs_t presentTimeDelay) { |
| 315 | int slot; |
| 316 | sp<Fence> fence; |
| 317 | sp<GraphicBuffer> buf; |
| 318 | auto ret = igbp->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 319 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 320 | nullptr, nullptr); |
chaviw | 0acd33a | 2021-11-02 11:55:37 -0500 | [diff] [blame] | 321 | ASSERT_TRUE(ret == IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION || ret == NO_ERROR); |
Vishnu Nair | 277142c | 2021-01-05 18:35:29 -0800 | [diff] [blame] | 322 | ASSERT_EQ(OK, igbp->requestBuffer(slot, &buf)); |
| 323 | |
| 324 | uint32_t* bufData; |
| 325 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 326 | reinterpret_cast<void**>(&bufData)); |
| 327 | fillBuffer(bufData, Rect(buf->getWidth(), buf->getHeight() / 2), buf->getStride(), r, g, b); |
| 328 | buf->unlock(); |
| 329 | |
| 330 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 331 | nsecs_t timestampNanos = systemTime() + presentTimeDelay; |
| 332 | IGraphicBufferProducer::QueueBufferInput input(timestampNanos, false, HAL_DATASPACE_UNKNOWN, |
| 333 | Rect(mDisplayWidth, mDisplayHeight / 2), |
| 334 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 335 | Fence::NO_FENCE); |
| 336 | igbp->queueBuffer(slot, input, &qbOutput); |
| 337 | } |
| 338 | |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 339 | sp<SurfaceComposerClient> mClient; |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 340 | sp<ISurfaceComposer> mComposer; |
| 341 | |
| 342 | sp<IBinder> mDisplayToken; |
| 343 | |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 344 | sp<SurfaceControl> mSurfaceControl; |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 345 | |
| 346 | uint32_t mDisplayWidth; |
| 347 | uint32_t mDisplayHeight; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 348 | |
| 349 | DisplayCaptureArgs mCaptureArgs; |
| 350 | ScreenCaptureResults mCaptureResults; |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 351 | sp<CountProducerListener> mProducerListener; |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 352 | }; |
| 353 | |
Patrick Williams | ed4745d | 2023-07-27 17:35:19 -0500 | [diff] [blame] | 354 | // Helper class to ensure the provided BBQ frame number has been committed in SurfaceFlinger. |
| 355 | class BBQSyncHelper { |
| 356 | public: |
| 357 | BBQSyncHelper(BLASTBufferQueueHelper& bbqHelper, uint64_t frameNumber) { |
| 358 | t.addTransactionCompletedCallback(callbackHelper.function, callbackHelper.getContext()); |
| 359 | bbqHelper.mergeWithNextTransaction(&t, frameNumber); |
| 360 | } |
| 361 | |
| 362 | void wait() { |
| 363 | CallbackData callbackData; |
| 364 | callbackHelper.getCallbackData(&callbackData); |
| 365 | } |
| 366 | |
| 367 | private: |
| 368 | Transaction t; |
| 369 | CallbackHelper callbackHelper; |
| 370 | }; |
| 371 | |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 372 | TEST_F(BLASTBufferQueueTest, CreateBLASTBufferQueue) { |
| 373 | // create BLASTBufferQueue adapter associated with this surface |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 374 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 375 | ASSERT_EQ(mSurfaceControl, adapter.getSurfaceControl()); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 376 | ASSERT_EQ(mDisplayWidth, adapter.getWidth()); |
| 377 | ASSERT_EQ(mDisplayHeight, adapter.getHeight()); |
Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 378 | ASSERT_EQ(nullptr, adapter.getTransactionReadyCallback()); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | TEST_F(BLASTBufferQueueTest, Update) { |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 382 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 383 | sp<SurfaceControl> updateSurface = |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 384 | mClient->createSurface(String8("UpdateTest"), mDisplayWidth / 2, mDisplayHeight / 2, |
| 385 | PIXEL_FORMAT_RGBA_8888); |
| 386 | adapter.update(updateSurface, mDisplayWidth / 2, mDisplayHeight / 2); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 387 | ASSERT_EQ(updateSurface, adapter.getSurfaceControl()); |
Vishnu Nair | ea0de00 | 2020-11-17 17:42:37 -0800 | [diff] [blame] | 388 | sp<IGraphicBufferProducer> igbProducer; |
| 389 | setUpProducer(adapter, igbProducer); |
| 390 | |
| 391 | int32_t width; |
| 392 | igbProducer->query(NATIVE_WINDOW_WIDTH, &width); |
| 393 | ASSERT_EQ(mDisplayWidth / 2, width); |
| 394 | int32_t height; |
| 395 | igbProducer->query(NATIVE_WINDOW_HEIGHT, &height); |
| 396 | ASSERT_EQ(mDisplayHeight / 2, height); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 399 | TEST_F(BLASTBufferQueueTest, SyncNextTransaction) { |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 400 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 401 | ASSERT_EQ(nullptr, adapter.getTransactionReadyCallback()); |
| 402 | auto callback = [](Transaction*) {}; |
| 403 | adapter.syncNextTransaction(callback); |
| 404 | ASSERT_NE(nullptr, adapter.getTransactionReadyCallback()); |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 405 | } |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 406 | |
Valerie Hau | bf29e04 | 2020-02-06 11:40:38 -0800 | [diff] [blame] | 407 | TEST_F(BLASTBufferQueueTest, DISABLED_onFrameAvailable_ApplyDesiredPresentTime) { |
Valerie Hau | 181abd3 | 2020-01-27 14:18:28 -0800 | [diff] [blame] | 408 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 409 | sp<IGraphicBufferProducer> igbProducer; |
| 410 | setUpProducer(adapter, igbProducer); |
| 411 | |
| 412 | int slot; |
| 413 | sp<Fence> fence; |
| 414 | sp<GraphicBuffer> buf; |
| 415 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 416 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 417 | nullptr, nullptr); |
| 418 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 419 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 420 | |
| 421 | nsecs_t desiredPresentTime = systemTime() + nsecs_t(5 * 1e8); |
| 422 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 423 | IGraphicBufferProducer::QueueBufferInput input(desiredPresentTime, true /* autotimestamp */, |
| 424 | HAL_DATASPACE_UNKNOWN, |
Valerie Hau | 181abd3 | 2020-01-27 14:18:28 -0800 | [diff] [blame] | 425 | Rect(mDisplayWidth, mDisplayHeight), |
| 426 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 427 | Fence::NO_FENCE); |
| 428 | igbProducer->queueBuffer(slot, input, &qbOutput); |
| 429 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
| 430 | |
| 431 | adapter.waitForCallbacks(); |
| 432 | ASSERT_GE(systemTime(), desiredPresentTime); |
| 433 | } |
| 434 | |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 435 | TEST_F(BLASTBufferQueueTest, onFrameAvailable_Apply) { |
| 436 | uint8_t r = 255; |
| 437 | uint8_t g = 0; |
| 438 | uint8_t b = 0; |
| 439 | |
| 440 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 441 | sp<IGraphicBufferProducer> igbProducer; |
| 442 | setUpProducer(adapter, igbProducer); |
Patrick Williams | ed4745d | 2023-07-27 17:35:19 -0500 | [diff] [blame] | 443 | BBQSyncHelper syncHelper{adapter, 1}; |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 444 | |
| 445 | int slot; |
| 446 | sp<Fence> fence; |
| 447 | sp<GraphicBuffer> buf; |
| 448 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 449 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 450 | nullptr, nullptr); |
| 451 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 452 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 453 | |
| 454 | uint32_t* bufData; |
| 455 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 456 | reinterpret_cast<void**>(&bufData)); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 457 | fillBuffer(bufData, Rect(buf->getWidth(), buf->getHeight()), buf->getStride(), r, g, b); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 458 | buf->unlock(); |
| 459 | |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 460 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 461 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), true /* autotimestamp */, |
| 462 | HAL_DATASPACE_UNKNOWN, |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 463 | Rect(mDisplayWidth, mDisplayHeight), |
| 464 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 465 | Fence::NO_FENCE); |
| 466 | igbProducer->queueBuffer(slot, input, &qbOutput); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 467 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 468 | |
Patrick Williams | ed4745d | 2023-07-27 17:35:19 -0500 | [diff] [blame] | 469 | syncHelper.wait(); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 470 | |
| 471 | // capture screen and verify that it is red |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 472 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 473 | ASSERT_NO_FATAL_FAILURE( |
| 474 | checkScreenCapture(r, g, b, {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight})); |
Valerie Hau | da3446e | 2019-10-14 15:49:22 -0700 | [diff] [blame] | 475 | } |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 476 | |
| 477 | TEST_F(BLASTBufferQueueTest, TripleBuffering) { |
| 478 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 479 | sp<IGraphicBufferProducer> igbProducer; |
| 480 | setUpProducer(adapter, igbProducer); |
| 481 | |
| 482 | std::vector<std::pair<int, sp<Fence>>> allocated; |
Ady Abraham | 0bde6b5 | 2021-05-18 13:57:02 -0700 | [diff] [blame] | 483 | int minUndequeuedBuffers = 0; |
| 484 | ASSERT_EQ(OK, igbProducer->query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, &minUndequeuedBuffers)); |
| 485 | const auto bufferCount = minUndequeuedBuffers + 2; |
| 486 | |
| 487 | for (int i = 0; i < bufferCount; i++) { |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 488 | int slot; |
| 489 | sp<Fence> fence; |
| 490 | sp<GraphicBuffer> buf; |
| 491 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 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 | allocated.push_back({slot, fence}); |
| 497 | } |
| 498 | for (int i = 0; i < allocated.size(); i++) { |
| 499 | igbProducer->cancelBuffer(allocated[i].first, allocated[i].second); |
| 500 | } |
| 501 | |
Valerie Hau | a32c552 | 2019-12-09 10:11:08 -0800 | [diff] [blame] | 502 | for (int i = 0; i < 100; i++) { |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 503 | int slot; |
| 504 | sp<Fence> fence; |
| 505 | sp<GraphicBuffer> buf; |
| 506 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 507 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 508 | nullptr, nullptr); |
| 509 | ASSERT_EQ(NO_ERROR, ret); |
| 510 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 511 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), true /* autotimestamp */, |
| 512 | HAL_DATASPACE_UNKNOWN, |
Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 513 | Rect(mDisplayWidth, mDisplayHeight), |
| 514 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 515 | Fence::NO_FENCE); |
| 516 | igbProducer->queueBuffer(slot, input, &qbOutput); |
| 517 | } |
| 518 | adapter.waitForCallbacks(); |
| 519 | } |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 520 | |
| 521 | TEST_F(BLASTBufferQueueTest, SetCrop_Item) { |
| 522 | uint8_t r = 255; |
| 523 | uint8_t g = 0; |
| 524 | uint8_t b = 0; |
| 525 | |
| 526 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 527 | sp<IGraphicBufferProducer> igbProducer; |
| 528 | setUpProducer(adapter, igbProducer); |
Patrick Williams | ed4745d | 2023-07-27 17:35:19 -0500 | [diff] [blame] | 529 | BBQSyncHelper syncHelper{adapter, 1}; |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 530 | int slot; |
| 531 | sp<Fence> fence; |
| 532 | sp<GraphicBuffer> buf; |
| 533 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 534 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 535 | nullptr, nullptr); |
| 536 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 537 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 538 | |
| 539 | uint32_t* bufData; |
| 540 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 541 | reinterpret_cast<void**>(&bufData)); |
| 542 | fillBuffer(bufData, Rect(buf->getWidth(), buf->getHeight() / 2), buf->getStride(), r, g, b); |
| 543 | buf->unlock(); |
| 544 | |
| 545 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 546 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), true /* autotimestamp */, |
| 547 | HAL_DATASPACE_UNKNOWN, |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 548 | Rect(mDisplayWidth, mDisplayHeight / 2), |
| 549 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 550 | Fence::NO_FENCE); |
| 551 | igbProducer->queueBuffer(slot, input, &qbOutput); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 552 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 553 | |
Patrick Williams | ed4745d | 2023-07-27 17:35:19 -0500 | [diff] [blame] | 554 | syncHelper.wait(); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 555 | // capture screen and verify that it is red |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 556 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 557 | |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 558 | ASSERT_NO_FATAL_FAILURE( |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 559 | checkScreenCapture(r, g, b, |
| 560 | {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight / 2})); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | TEST_F(BLASTBufferQueueTest, SetCrop_ScalingModeScaleCrop) { |
| 564 | uint8_t r = 255; |
| 565 | uint8_t g = 0; |
| 566 | uint8_t b = 0; |
| 567 | |
| 568 | int32_t bufferSideLength = |
| 569 | (mDisplayWidth < mDisplayHeight) ? mDisplayWidth / 2 : mDisplayHeight / 2; |
| 570 | int32_t finalCropSideLength = bufferSideLength / 2; |
| 571 | |
| 572 | auto bg = mClient->createSurface(String8("BGTest"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 573 | ISurfaceComposerClient::eFXSurfaceEffect); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 574 | ASSERT_NE(nullptr, bg.get()); |
| 575 | Transaction t; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 576 | t.setLayerStack(bg, ui::DEFAULT_LAYER_STACK) |
chaviw | 2571450 | 2021-02-11 10:01:08 -0800 | [diff] [blame] | 577 | .setCrop(bg, Rect(0, 0, mDisplayWidth, mDisplayHeight)) |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 578 | .setColor(bg, half3{0, 0, 0}) |
| 579 | .setLayer(bg, 0) |
| 580 | .apply(); |
| 581 | |
| 582 | BLASTBufferQueueHelper adapter(mSurfaceControl, bufferSideLength, bufferSideLength); |
| 583 | sp<IGraphicBufferProducer> igbProducer; |
| 584 | setUpProducer(adapter, igbProducer); |
Patrick Williams | ed4745d | 2023-07-27 17:35:19 -0500 | [diff] [blame] | 585 | BBQSyncHelper syncHelper{adapter, 1}; |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 586 | int slot; |
| 587 | sp<Fence> fence; |
| 588 | sp<GraphicBuffer> buf; |
| 589 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, bufferSideLength, bufferSideLength, |
| 590 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 591 | nullptr, nullptr); |
| 592 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 593 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 594 | |
| 595 | uint32_t* bufData; |
| 596 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 597 | reinterpret_cast<void**>(&bufData)); |
| 598 | fillBuffer(bufData, Rect(buf->getWidth(), buf->getHeight()), buf->getStride(), 0, 0, 0); |
| 599 | fillBuffer(bufData, |
| 600 | Rect(finalCropSideLength / 2, 0, buf->getWidth() - finalCropSideLength / 2, |
| 601 | buf->getHeight()), |
| 602 | buf->getStride(), r, g, b); |
| 603 | buf->unlock(); |
| 604 | |
| 605 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 606 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), true /* autotimestamp */, |
| 607 | HAL_DATASPACE_UNKNOWN, |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 608 | Rect(bufferSideLength, finalCropSideLength), |
| 609 | NATIVE_WINDOW_SCALING_MODE_SCALE_CROP, 0, |
| 610 | Fence::NO_FENCE); |
| 611 | igbProducer->queueBuffer(slot, input, &qbOutput); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 612 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 613 | |
Patrick Williams | ed4745d | 2023-07-27 17:35:19 -0500 | [diff] [blame] | 614 | syncHelper.wait(); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 615 | // capture screen and verify that it is red |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 616 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
Vishnu Nair | 5cc9ac0 | 2021-04-19 13:23:38 -0700 | [diff] [blame] | 617 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(r, g, b, |
| 618 | {10, 10, (int32_t)bufferSideLength - 10, |
| 619 | (int32_t)bufferSideLength - 10})); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 620 | ASSERT_NO_FATAL_FAILURE( |
Vishnu Nair | 5cc9ac0 | 2021-04-19 13:23:38 -0700 | [diff] [blame] | 621 | checkScreenCapture(0, 0, 0, |
| 622 | {0, 0, (int32_t)bufferSideLength, (int32_t)bufferSideLength}, |
| 623 | /*border*/ 0, /*outsideRegion*/ true)); |
| 624 | } |
| 625 | |
| 626 | TEST_F(BLASTBufferQueueTest, ScaleCroppedBufferToBufferSize) { |
| 627 | // add black background |
| 628 | auto bg = mClient->createSurface(String8("BGTest"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 629 | ISurfaceComposerClient::eFXSurfaceEffect); |
| 630 | ASSERT_NE(nullptr, bg.get()); |
| 631 | Transaction t; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 632 | t.setLayerStack(bg, ui::DEFAULT_LAYER_STACK) |
Vishnu Nair | 5cc9ac0 | 2021-04-19 13:23:38 -0700 | [diff] [blame] | 633 | .setCrop(bg, Rect(0, 0, mDisplayWidth, mDisplayHeight)) |
| 634 | .setColor(bg, half3{0, 0, 0}) |
| 635 | .setLayer(bg, 0) |
| 636 | .apply(); |
| 637 | |
| 638 | Rect windowSize(1000, 1000); |
| 639 | Rect bufferSize(windowSize); |
| 640 | Rect bufferCrop(200, 200, 700, 700); |
| 641 | |
| 642 | BLASTBufferQueueHelper adapter(mSurfaceControl, windowSize.getWidth(), windowSize.getHeight()); |
| 643 | sp<IGraphicBufferProducer> igbProducer; |
| 644 | setUpProducer(adapter, igbProducer); |
Patrick Williams | ed4745d | 2023-07-27 17:35:19 -0500 | [diff] [blame] | 645 | BBQSyncHelper syncHelper{adapter, 1}; |
Vishnu Nair | 5cc9ac0 | 2021-04-19 13:23:38 -0700 | [diff] [blame] | 646 | int slot; |
| 647 | sp<Fence> fence; |
| 648 | sp<GraphicBuffer> buf; |
| 649 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, bufferSize.getWidth(), |
| 650 | bufferSize.getHeight(), PIXEL_FORMAT_RGBA_8888, |
| 651 | GRALLOC_USAGE_SW_WRITE_OFTEN, nullptr, nullptr); |
| 652 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 653 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 654 | |
| 655 | uint32_t* bufData; |
| 656 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 657 | reinterpret_cast<void**>(&bufData)); |
| 658 | // fill buffer with grey |
| 659 | fillBuffer(bufData, bufferSize, buf->getStride(), 127, 127, 127); |
| 660 | |
| 661 | // fill crop area with different colors so we can verify the cropped region has been scaled |
| 662 | // correctly. |
| 663 | fillBuffer(bufData, Rect(200, 200, 450, 450), buf->getStride(), /* rgb */ 255, 0, 0); |
| 664 | fillBuffer(bufData, Rect(200, 451, 450, 700), buf->getStride(), /* rgb */ 0, 255, 0); |
| 665 | fillBuffer(bufData, Rect(451, 200, 700, 450), buf->getStride(), /* rgb */ 0, 0, 255); |
| 666 | fillBuffer(bufData, Rect(451, 451, 700, 700), buf->getStride(), /* rgb */ 255, 0, 0); |
| 667 | buf->unlock(); |
| 668 | |
| 669 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 670 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), true /* autotimestamp */, |
| 671 | HAL_DATASPACE_UNKNOWN, |
| 672 | bufferCrop /* Rect::INVALID_RECT */, |
| 673 | NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW, 0, |
| 674 | Fence::NO_FENCE); |
| 675 | igbProducer->queueBuffer(slot, input, &qbOutput); |
| 676 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
| 677 | |
Patrick Williams | ed4745d | 2023-07-27 17:35:19 -0500 | [diff] [blame] | 678 | syncHelper.wait(); |
Vishnu Nair | 5cc9ac0 | 2021-04-19 13:23:38 -0700 | [diff] [blame] | 679 | |
| 680 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 681 | |
| 682 | // Verify cropped region is scaled correctly. |
| 683 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(255, 0, 0, {10, 10, 490, 490})); |
| 684 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 255, 0, {10, 510, 490, 990})); |
| 685 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 0, 255, {510, 10, 990, 490})); |
| 686 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(255, 0, 0, {510, 510, 990, 990})); |
| 687 | // Verify outside region is black. |
| 688 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 0, 0, |
| 689 | {0, 0, (int32_t)windowSize.getWidth(), |
| 690 | (int32_t)windowSize.getHeight()}, |
| 691 | /*border*/ 0, /*outsideRegion*/ true)); |
| 692 | } |
| 693 | |
| 694 | TEST_F(BLASTBufferQueueTest, ScaleCroppedBufferToWindowSize) { |
| 695 | // add black background |
| 696 | auto bg = mClient->createSurface(String8("BGTest"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 697 | ISurfaceComposerClient::eFXSurfaceEffect); |
| 698 | ASSERT_NE(nullptr, bg.get()); |
| 699 | Transaction t; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 700 | t.setLayerStack(bg, ui::DEFAULT_LAYER_STACK) |
Vishnu Nair | 5cc9ac0 | 2021-04-19 13:23:38 -0700 | [diff] [blame] | 701 | .setCrop(bg, Rect(0, 0, mDisplayWidth, mDisplayHeight)) |
| 702 | .setColor(bg, half3{0, 0, 0}) |
| 703 | .setLayer(bg, 0) |
| 704 | .apply(); |
| 705 | |
| 706 | Rect windowSize(1000, 1000); |
| 707 | Rect bufferSize(500, 500); |
| 708 | Rect bufferCrop(100, 100, 350, 350); |
| 709 | |
| 710 | BLASTBufferQueueHelper adapter(mSurfaceControl, windowSize.getWidth(), windowSize.getHeight()); |
| 711 | sp<IGraphicBufferProducer> igbProducer; |
| 712 | setUpProducer(adapter, igbProducer); |
Patrick Williams | ed4745d | 2023-07-27 17:35:19 -0500 | [diff] [blame] | 713 | BBQSyncHelper syncHelper{adapter, 1}; |
Vishnu Nair | 5cc9ac0 | 2021-04-19 13:23:38 -0700 | [diff] [blame] | 714 | int slot; |
| 715 | sp<Fence> fence; |
| 716 | sp<GraphicBuffer> buf; |
| 717 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, bufferSize.getWidth(), |
| 718 | bufferSize.getHeight(), PIXEL_FORMAT_RGBA_8888, |
| 719 | GRALLOC_USAGE_SW_WRITE_OFTEN, nullptr, nullptr); |
| 720 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 721 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 722 | |
| 723 | uint32_t* bufData; |
| 724 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 725 | reinterpret_cast<void**>(&bufData)); |
| 726 | // fill buffer with grey |
| 727 | fillBuffer(bufData, bufferSize, buf->getStride(), 127, 127, 127); |
| 728 | |
| 729 | // fill crop area with different colors so we can verify the cropped region has been scaled |
| 730 | // correctly. |
| 731 | fillBuffer(bufData, Rect(100, 100, 225, 225), buf->getStride(), /* rgb */ 255, 0, 0); |
| 732 | fillBuffer(bufData, Rect(100, 226, 225, 350), buf->getStride(), /* rgb */ 0, 255, 0); |
| 733 | fillBuffer(bufData, Rect(226, 100, 350, 225), buf->getStride(), /* rgb */ 0, 0, 255); |
| 734 | fillBuffer(bufData, Rect(226, 226, 350, 350), buf->getStride(), /* rgb */ 255, 0, 0); |
| 735 | buf->unlock(); |
| 736 | |
| 737 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 738 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), true /* autotimestamp */, |
| 739 | HAL_DATASPACE_UNKNOWN, |
| 740 | bufferCrop /* Rect::INVALID_RECT */, |
| 741 | NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW, 0, |
| 742 | Fence::NO_FENCE); |
| 743 | igbProducer->queueBuffer(slot, input, &qbOutput); |
| 744 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
| 745 | |
Patrick Williams | ed4745d | 2023-07-27 17:35:19 -0500 | [diff] [blame] | 746 | syncHelper.wait(); |
Vishnu Nair | 5cc9ac0 | 2021-04-19 13:23:38 -0700 | [diff] [blame] | 747 | |
| 748 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 749 | // Verify cropped region is scaled correctly. |
| 750 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(255, 0, 0, {10, 10, 490, 490})); |
| 751 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 255, 0, {10, 510, 490, 990})); |
| 752 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 0, 255, {510, 10, 990, 490})); |
| 753 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(255, 0, 0, {510, 510, 990, 990})); |
| 754 | // Verify outside region is black. |
| 755 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 0, 0, |
| 756 | {0, 0, (int32_t)windowSize.getWidth(), |
| 757 | (int32_t)windowSize.getHeight()}, |
| 758 | /*border*/ 0, /*outsideRegion*/ true)); |
Valerie Hau | 45e4b3b | 2019-12-03 10:49:17 -0800 | [diff] [blame] | 759 | } |
| 760 | |
Vishnu Nair | 932f6ae | 2021-09-29 17:33:10 -0700 | [diff] [blame] | 761 | // b/196339769 verify we can can update the requested size while the in FREEZE scaling mode and |
| 762 | // scale the buffer properly when the mode changes to SCALE_TO_WINDOW |
| 763 | TEST_F(BLASTBufferQueueTest, ScalingModeChanges) { |
| 764 | uint8_t r = 255; |
| 765 | uint8_t g = 0; |
| 766 | uint8_t b = 0; |
| 767 | |
| 768 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight / 4); |
| 769 | sp<IGraphicBufferProducer> igbProducer; |
| 770 | setUpProducer(adapter, igbProducer); |
| 771 | { |
Patrick Williams | ed4745d | 2023-07-27 17:35:19 -0500 | [diff] [blame] | 772 | BBQSyncHelper syncHelper{adapter, 1}; |
Vishnu Nair | 932f6ae | 2021-09-29 17:33:10 -0700 | [diff] [blame] | 773 | int slot; |
| 774 | sp<Fence> fence; |
| 775 | sp<GraphicBuffer> buf; |
| 776 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight / 4, |
| 777 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 778 | nullptr, nullptr); |
| 779 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 780 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 781 | |
| 782 | uint32_t* bufData; |
| 783 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 784 | reinterpret_cast<void**>(&bufData)); |
| 785 | fillBuffer(bufData, Rect(buf->getWidth(), buf->getHeight()), buf->getStride(), r, g, b); |
| 786 | buf->unlock(); |
| 787 | |
| 788 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 789 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), true /* autotimestamp */, |
| 790 | HAL_DATASPACE_UNKNOWN, {}, |
| 791 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 792 | Fence::NO_FENCE); |
| 793 | igbProducer->queueBuffer(slot, input, &qbOutput); |
Patrick Williams | ed4745d | 2023-07-27 17:35:19 -0500 | [diff] [blame] | 794 | syncHelper.wait(); |
Vishnu Nair | 932f6ae | 2021-09-29 17:33:10 -0700 | [diff] [blame] | 795 | } |
| 796 | // capture screen and verify that it is red |
| 797 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 798 | |
| 799 | ASSERT_NO_FATAL_FAILURE( |
| 800 | checkScreenCapture(r, g, b, |
| 801 | {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight / 4})); |
| 802 | |
| 803 | // update the size to half the display and dequeue a buffer quarter of the display. |
| 804 | adapter.update(mSurfaceControl, mDisplayWidth, mDisplayHeight / 2); |
| 805 | |
| 806 | { |
Patrick Williams | ed4745d | 2023-07-27 17:35:19 -0500 | [diff] [blame] | 807 | BBQSyncHelper syncHelper{adapter, 1}; |
Vishnu Nair | 932f6ae | 2021-09-29 17:33:10 -0700 | [diff] [blame] | 808 | int slot; |
| 809 | sp<Fence> fence; |
| 810 | sp<GraphicBuffer> buf; |
| 811 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight / 8, |
| 812 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 813 | nullptr, nullptr); |
| 814 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 815 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 816 | |
| 817 | uint32_t* bufData; |
| 818 | buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN), |
| 819 | reinterpret_cast<void**>(&bufData)); |
| 820 | g = 255; |
| 821 | fillBuffer(bufData, Rect(buf->getWidth(), buf->getHeight()), buf->getStride(), r, g, b); |
| 822 | buf->unlock(); |
| 823 | |
| 824 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 825 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), true /* autotimestamp */, |
| 826 | HAL_DATASPACE_UNKNOWN, {}, |
| 827 | NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW, |
| 828 | 0, Fence::NO_FENCE); |
| 829 | igbProducer->queueBuffer(slot, input, &qbOutput); |
Patrick Williams | ed4745d | 2023-07-27 17:35:19 -0500 | [diff] [blame] | 830 | syncHelper.wait(); |
Vishnu Nair | 932f6ae | 2021-09-29 17:33:10 -0700 | [diff] [blame] | 831 | } |
| 832 | // capture screen and verify that it is red |
| 833 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 834 | // verify we still scale the buffer to the new size (half the screen height) |
| 835 | ASSERT_NO_FATAL_FAILURE( |
| 836 | checkScreenCapture(r, g, b, |
| 837 | {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight / 2})); |
| 838 | } |
| 839 | |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 840 | TEST_F(BLASTBufferQueueTest, SyncThenNoSync) { |
| 841 | uint8_t r = 255; |
| 842 | uint8_t g = 0; |
| 843 | uint8_t b = 0; |
| 844 | |
| 845 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 846 | |
| 847 | sp<IGraphicBufferProducer> igbProducer; |
| 848 | setUpProducer(adapter, igbProducer); |
| 849 | |
chaviw | a1c4c82 | 2021-11-10 18:11:58 -0600 | [diff] [blame] | 850 | Transaction sync; |
Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 851 | adapter.setSyncTransaction(sync); |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 852 | queueBuffer(igbProducer, 0, 255, 0, 0); |
| 853 | |
| 854 | // queue non sync buffer, so this one should get blocked |
| 855 | // Add a present delay to allow the first screenshot to get taken. |
| 856 | nsecs_t presentTimeDelay = std::chrono::nanoseconds(500ms).count(); |
| 857 | queueBuffer(igbProducer, r, g, b, presentTimeDelay); |
| 858 | |
| 859 | CallbackHelper transactionCallback; |
chaviw | a1c4c82 | 2021-11-10 18:11:58 -0600 | [diff] [blame] | 860 | sync.addTransactionCompletedCallback(transactionCallback.function, |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 861 | transactionCallback.getContext()) |
| 862 | .apply(); |
| 863 | |
| 864 | CallbackData callbackData; |
| 865 | transactionCallback.getCallbackData(&callbackData); |
| 866 | |
chaviw | 0acd33a | 2021-11-02 11:55:37 -0500 | [diff] [blame] | 867 | // capture screen and verify that it is green |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 868 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 869 | ASSERT_NO_FATAL_FAILURE( |
| 870 | checkScreenCapture(0, 255, 0, {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight})); |
| 871 | |
| 872 | mProducerListener->waitOnNumberReleased(1); |
| 873 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 874 | ASSERT_NO_FATAL_FAILURE( |
| 875 | checkScreenCapture(r, g, b, {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight})); |
| 876 | } |
| 877 | |
| 878 | TEST_F(BLASTBufferQueueTest, MultipleSyncTransactions) { |
| 879 | uint8_t r = 255; |
| 880 | uint8_t g = 0; |
| 881 | uint8_t b = 0; |
| 882 | |
| 883 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 884 | |
| 885 | sp<IGraphicBufferProducer> igbProducer; |
| 886 | setUpProducer(adapter, igbProducer); |
| 887 | |
| 888 | Transaction mainTransaction; |
| 889 | |
chaviw | a1c4c82 | 2021-11-10 18:11:58 -0600 | [diff] [blame] | 890 | Transaction sync; |
Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 891 | adapter.setSyncTransaction(sync); |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 892 | queueBuffer(igbProducer, 0, 255, 0, 0); |
| 893 | |
chaviw | a1c4c82 | 2021-11-10 18:11:58 -0600 | [diff] [blame] | 894 | mainTransaction.merge(std::move(sync)); |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 895 | |
Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 896 | adapter.setSyncTransaction(sync); |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 897 | queueBuffer(igbProducer, r, g, b, 0); |
| 898 | |
chaviw | a1c4c82 | 2021-11-10 18:11:58 -0600 | [diff] [blame] | 899 | mainTransaction.merge(std::move(sync)); |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 900 | // Expect 1 buffer to be released even before sending to SurfaceFlinger |
| 901 | mProducerListener->waitOnNumberReleased(1); |
| 902 | |
| 903 | CallbackHelper transactionCallback; |
| 904 | mainTransaction |
| 905 | .addTransactionCompletedCallback(transactionCallback.function, |
| 906 | transactionCallback.getContext()) |
| 907 | .apply(); |
| 908 | |
| 909 | CallbackData callbackData; |
| 910 | transactionCallback.getCallbackData(&callbackData); |
| 911 | |
| 912 | // capture screen and verify that it is red |
| 913 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 914 | ASSERT_NO_FATAL_FAILURE( |
| 915 | checkScreenCapture(r, g, b, {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight})); |
| 916 | } |
| 917 | |
| 918 | TEST_F(BLASTBufferQueueTest, MultipleSyncTransactionWithNonSync) { |
| 919 | uint8_t r = 255; |
| 920 | uint8_t g = 0; |
| 921 | uint8_t b = 0; |
| 922 | |
| 923 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 924 | |
| 925 | sp<IGraphicBufferProducer> igbProducer; |
| 926 | setUpProducer(adapter, igbProducer); |
| 927 | |
| 928 | Transaction mainTransaction; |
| 929 | |
chaviw | a1c4c82 | 2021-11-10 18:11:58 -0600 | [diff] [blame] | 930 | Transaction sync; |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 931 | // queue a sync transaction |
Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 932 | adapter.setSyncTransaction(sync); |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 933 | queueBuffer(igbProducer, 0, 255, 0, 0); |
| 934 | |
chaviw | a1c4c82 | 2021-11-10 18:11:58 -0600 | [diff] [blame] | 935 | mainTransaction.merge(std::move(sync)); |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 936 | |
chaviw | a1c4c82 | 2021-11-10 18:11:58 -0600 | [diff] [blame] | 937 | // queue another buffer without setting sync transaction |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 938 | queueBuffer(igbProducer, 0, 0, 255, 0); |
| 939 | |
| 940 | // queue another sync transaction |
Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 941 | adapter.setSyncTransaction(sync); |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 942 | queueBuffer(igbProducer, r, g, b, 0); |
| 943 | // Expect 1 buffer to be released because the non sync transaction should merge |
| 944 | // with the sync |
| 945 | mProducerListener->waitOnNumberReleased(1); |
| 946 | |
chaviw | a1c4c82 | 2021-11-10 18:11:58 -0600 | [diff] [blame] | 947 | mainTransaction.merge(std::move(sync)); |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 948 | // Expect 2 buffers to be released due to merging the two syncs. |
| 949 | mProducerListener->waitOnNumberReleased(2); |
| 950 | |
| 951 | CallbackHelper transactionCallback; |
| 952 | mainTransaction |
| 953 | .addTransactionCompletedCallback(transactionCallback.function, |
| 954 | transactionCallback.getContext()) |
| 955 | .apply(); |
| 956 | |
| 957 | CallbackData callbackData; |
| 958 | transactionCallback.getCallbackData(&callbackData); |
| 959 | |
| 960 | // capture screen and verify that it is red |
| 961 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 962 | ASSERT_NO_FATAL_FAILURE( |
| 963 | checkScreenCapture(r, g, b, {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight})); |
| 964 | } |
| 965 | |
| 966 | TEST_F(BLASTBufferQueueTest, MultipleSyncRunOutOfBuffers) { |
| 967 | uint8_t r = 255; |
| 968 | uint8_t g = 0; |
| 969 | uint8_t b = 0; |
| 970 | |
| 971 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 972 | |
| 973 | sp<IGraphicBufferProducer> igbProducer; |
| 974 | setUpProducer(adapter, igbProducer, 3); |
| 975 | |
| 976 | Transaction mainTransaction; |
| 977 | |
chaviw | a1c4c82 | 2021-11-10 18:11:58 -0600 | [diff] [blame] | 978 | Transaction sync; |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 979 | // queue a sync transaction |
Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 980 | adapter.setSyncTransaction(sync); |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 981 | queueBuffer(igbProducer, 0, 255, 0, 0); |
| 982 | |
chaviw | a1c4c82 | 2021-11-10 18:11:58 -0600 | [diff] [blame] | 983 | mainTransaction.merge(std::move(sync)); |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 984 | |
chaviw | a1c4c82 | 2021-11-10 18:11:58 -0600 | [diff] [blame] | 985 | // queue a few buffers without setting sync transaction |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 986 | queueBuffer(igbProducer, 0, 0, 255, 0); |
| 987 | queueBuffer(igbProducer, 0, 0, 255, 0); |
| 988 | queueBuffer(igbProducer, 0, 0, 255, 0); |
| 989 | |
| 990 | // queue another sync transaction |
Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 991 | adapter.setSyncTransaction(sync); |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 992 | queueBuffer(igbProducer, r, g, b, 0); |
| 993 | // Expect 3 buffers to be released because the non sync transactions should merge |
| 994 | // with the sync |
| 995 | mProducerListener->waitOnNumberReleased(3); |
| 996 | |
chaviw | a1c4c82 | 2021-11-10 18:11:58 -0600 | [diff] [blame] | 997 | mainTransaction.merge(std::move(sync)); |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 998 | // Expect 4 buffers to be released due to merging the two syncs. |
| 999 | mProducerListener->waitOnNumberReleased(4); |
| 1000 | |
| 1001 | CallbackHelper transactionCallback; |
| 1002 | mainTransaction |
| 1003 | .addTransactionCompletedCallback(transactionCallback.function, |
| 1004 | transactionCallback.getContext()) |
| 1005 | .apply(); |
| 1006 | |
| 1007 | CallbackData callbackData; |
| 1008 | transactionCallback.getCallbackData(&callbackData); |
| 1009 | |
| 1010 | // capture screen and verify that it is red |
| 1011 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 1012 | ASSERT_NO_FATAL_FAILURE( |
| 1013 | checkScreenCapture(r, g, b, {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight})); |
| 1014 | } |
| 1015 | |
| 1016 | // Tests BBQ with a sync transaction when the buffers acquired reaches max and the only way to |
| 1017 | // continue processing is for a release callback from SurfaceFlinger. |
| 1018 | // This is done by sending a buffer to SF so it can release the previous one and allow BBQ to |
| 1019 | // continue acquiring buffers. |
| 1020 | TEST_F(BLASTBufferQueueTest, RunOutOfBuffersWaitingOnSF) { |
| 1021 | uint8_t r = 255; |
| 1022 | uint8_t g = 0; |
| 1023 | uint8_t b = 0; |
| 1024 | |
| 1025 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 1026 | |
| 1027 | sp<IGraphicBufferProducer> igbProducer; |
| 1028 | setUpProducer(adapter, igbProducer, 4); |
| 1029 | |
| 1030 | Transaction mainTransaction; |
| 1031 | |
| 1032 | // Send a buffer to SF |
| 1033 | queueBuffer(igbProducer, 0, 255, 0, 0); |
| 1034 | |
chaviw | a1c4c82 | 2021-11-10 18:11:58 -0600 | [diff] [blame] | 1035 | Transaction sync; |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 1036 | // queue a sync transaction |
Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 1037 | adapter.setSyncTransaction(sync); |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 1038 | queueBuffer(igbProducer, 0, 255, 0, 0); |
| 1039 | |
chaviw | a1c4c82 | 2021-11-10 18:11:58 -0600 | [diff] [blame] | 1040 | mainTransaction.merge(std::move(sync)); |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 1041 | |
chaviw | a1c4c82 | 2021-11-10 18:11:58 -0600 | [diff] [blame] | 1042 | // queue a few buffers without setting sync transaction |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 1043 | queueBuffer(igbProducer, 0, 0, 255, 0); |
| 1044 | queueBuffer(igbProducer, 0, 0, 255, 0); |
| 1045 | queueBuffer(igbProducer, 0, 0, 255, 0); |
| 1046 | |
| 1047 | // apply the first synced buffer to ensure we have to wait on SF |
| 1048 | mainTransaction.apply(); |
| 1049 | |
| 1050 | // queue another sync transaction |
Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 1051 | adapter.setSyncTransaction(sync); |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 1052 | queueBuffer(igbProducer, r, g, b, 0); |
| 1053 | // Expect 2 buffers to be released because the non sync transactions should merge |
| 1054 | // with the sync |
| 1055 | mProducerListener->waitOnNumberReleased(3); |
| 1056 | |
chaviw | a1c4c82 | 2021-11-10 18:11:58 -0600 | [diff] [blame] | 1057 | mainTransaction.merge(std::move(sync)); |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 1058 | |
| 1059 | CallbackHelper transactionCallback; |
| 1060 | mainTransaction |
| 1061 | .addTransactionCompletedCallback(transactionCallback.function, |
| 1062 | transactionCallback.getContext()) |
| 1063 | .apply(); |
| 1064 | |
| 1065 | CallbackData callbackData; |
| 1066 | transactionCallback.getCallbackData(&callbackData); |
| 1067 | |
| 1068 | // capture screen and verify that it is red |
| 1069 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 1070 | ASSERT_NO_FATAL_FAILURE( |
| 1071 | checkScreenCapture(r, g, b, {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight})); |
| 1072 | } |
| 1073 | |
Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 1074 | TEST_F(BLASTBufferQueueTest, SyncNextTransactionAcquireMultipleBuffers) { |
chaviw | 0acd33a | 2021-11-02 11:55:37 -0500 | [diff] [blame] | 1075 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 1076 | |
| 1077 | sp<IGraphicBufferProducer> igbProducer; |
| 1078 | setUpProducer(adapter, igbProducer); |
| 1079 | |
| 1080 | Transaction next; |
Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 1081 | adapter.setSyncTransaction(next, false); |
chaviw | 0acd33a | 2021-11-02 11:55:37 -0500 | [diff] [blame] | 1082 | queueBuffer(igbProducer, 0, 255, 0, 0); |
| 1083 | queueBuffer(igbProducer, 0, 0, 255, 0); |
| 1084 | // There should only be one frame submitted since the first frame will be released. |
| 1085 | adapter.validateNumFramesSubmitted(1); |
Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 1086 | adapter.stopContinuousSyncTransaction(); |
chaviw | 0acd33a | 2021-11-02 11:55:37 -0500 | [diff] [blame] | 1087 | |
| 1088 | // queue non sync buffer, so this one should get blocked |
| 1089 | // Add a present delay to allow the first screenshot to get taken. |
| 1090 | nsecs_t presentTimeDelay = std::chrono::nanoseconds(500ms).count(); |
| 1091 | queueBuffer(igbProducer, 255, 0, 0, presentTimeDelay); |
| 1092 | |
| 1093 | CallbackHelper transactionCallback; |
| 1094 | next.addTransactionCompletedCallback(transactionCallback.function, |
| 1095 | transactionCallback.getContext()) |
| 1096 | .apply(); |
| 1097 | |
| 1098 | CallbackData callbackData; |
| 1099 | transactionCallback.getCallbackData(&callbackData); |
| 1100 | |
| 1101 | // capture screen and verify that it is blue |
| 1102 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 1103 | ASSERT_NO_FATAL_FAILURE( |
| 1104 | checkScreenCapture(0, 0, 255, {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight})); |
| 1105 | |
| 1106 | mProducerListener->waitOnNumberReleased(2); |
| 1107 | // capture screen and verify that it is red |
| 1108 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 1109 | ASSERT_NO_FATAL_FAILURE( |
| 1110 | checkScreenCapture(255, 0, 0, {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight})); |
| 1111 | } |
| 1112 | |
chaviw | 3b4bdcf | 2022-03-17 09:27:03 -0500 | [diff] [blame] | 1113 | TEST_F(BLASTBufferQueueTest, SyncNextTransactionOverwrite) { |
| 1114 | std::mutex mutex; |
| 1115 | std::condition_variable callbackReceivedCv; |
| 1116 | bool receivedCallback = false; |
| 1117 | |
| 1118 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 1119 | ASSERT_EQ(nullptr, adapter.getTransactionReadyCallback()); |
| 1120 | auto callback = [&](Transaction*) { |
| 1121 | std::unique_lock<std::mutex> lock(mutex); |
| 1122 | receivedCallback = true; |
| 1123 | callbackReceivedCv.notify_one(); |
| 1124 | }; |
| 1125 | adapter.syncNextTransaction(callback); |
| 1126 | ASSERT_NE(nullptr, adapter.getTransactionReadyCallback()); |
| 1127 | |
| 1128 | auto callback2 = [](Transaction*) {}; |
Chavi Weingarten | c398c01 | 2023-04-12 17:26:02 +0000 | [diff] [blame] | 1129 | ASSERT_FALSE(adapter.syncNextTransaction(callback2)); |
| 1130 | |
| 1131 | sp<IGraphicBufferProducer> igbProducer; |
| 1132 | setUpProducer(adapter, igbProducer); |
| 1133 | queueBuffer(igbProducer, 0, 255, 0, 0); |
chaviw | 3b4bdcf | 2022-03-17 09:27:03 -0500 | [diff] [blame] | 1134 | |
| 1135 | std::unique_lock<std::mutex> lock(mutex); |
| 1136 | if (!receivedCallback) { |
| 1137 | ASSERT_NE(callbackReceivedCv.wait_for(lock, std::chrono::seconds(3)), |
| 1138 | std::cv_status::timeout) |
| 1139 | << "did not receive callback"; |
| 1140 | } |
| 1141 | |
| 1142 | ASSERT_TRUE(receivedCallback); |
| 1143 | } |
| 1144 | |
Chavi Weingarten | c398c01 | 2023-04-12 17:26:02 +0000 | [diff] [blame] | 1145 | TEST_F(BLASTBufferQueueTest, ClearSyncTransaction) { |
| 1146 | std::mutex mutex; |
| 1147 | std::condition_variable callbackReceivedCv; |
| 1148 | bool receivedCallback = false; |
| 1149 | |
| 1150 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 1151 | ASSERT_EQ(nullptr, adapter.getTransactionReadyCallback()); |
| 1152 | auto callback = [&](Transaction*) { |
| 1153 | std::unique_lock<std::mutex> lock(mutex); |
| 1154 | receivedCallback = true; |
| 1155 | callbackReceivedCv.notify_one(); |
| 1156 | }; |
| 1157 | adapter.syncNextTransaction(callback); |
| 1158 | ASSERT_NE(nullptr, adapter.getTransactionReadyCallback()); |
| 1159 | |
| 1160 | adapter.clearSyncTransaction(); |
| 1161 | |
| 1162 | sp<IGraphicBufferProducer> igbProducer; |
| 1163 | setUpProducer(adapter, igbProducer); |
| 1164 | queueBuffer(igbProducer, 0, 255, 0, 0); |
| 1165 | |
| 1166 | std::unique_lock<std::mutex> lock(mutex); |
| 1167 | if (!receivedCallback) { |
| 1168 | ASSERT_EQ(callbackReceivedCv.wait_for(lock, std::chrono::seconds(3)), |
| 1169 | std::cv_status::timeout) |
| 1170 | << "did not receive callback"; |
| 1171 | } |
| 1172 | |
| 1173 | ASSERT_FALSE(receivedCallback); |
| 1174 | } |
| 1175 | |
chaviw | c1cf402 | 2022-06-03 13:32:33 -0500 | [diff] [blame] | 1176 | TEST_F(BLASTBufferQueueTest, SyncNextTransactionDropBuffer) { |
| 1177 | uint8_t r = 255; |
| 1178 | uint8_t g = 0; |
| 1179 | uint8_t b = 0; |
| 1180 | |
| 1181 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 1182 | |
| 1183 | sp<IGraphicBufferProducer> igbProducer; |
| 1184 | setUpProducer(adapter, igbProducer); |
| 1185 | |
| 1186 | Transaction sync; |
| 1187 | adapter.setSyncTransaction(sync); |
| 1188 | queueBuffer(igbProducer, 0, 255, 0, 0); |
| 1189 | |
| 1190 | // Merge a transaction that has a complete callback into the next frame so we can get notified |
| 1191 | // when to take a screenshot |
| 1192 | CallbackHelper transactionCallback; |
| 1193 | Transaction t; |
| 1194 | t.addTransactionCompletedCallback(transactionCallback.function, |
| 1195 | transactionCallback.getContext()); |
| 1196 | adapter.mergeWithNextTransaction(&t, 2); |
| 1197 | queueBuffer(igbProducer, r, g, b, 0); |
| 1198 | |
| 1199 | // Drop the buffer, but ensure the next one continues to get processed. |
| 1200 | sync.setBuffer(mSurfaceControl, nullptr); |
| 1201 | |
| 1202 | CallbackData callbackData; |
| 1203 | transactionCallback.getCallbackData(&callbackData); |
| 1204 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 1205 | ASSERT_NO_FATAL_FAILURE( |
| 1206 | checkScreenCapture(r, g, b, {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight})); |
Rob Carr | 4f797ab | 2022-07-07 18:29:22 +0000 | [diff] [blame] | 1207 | sync.apply(); |
chaviw | c1cf402 | 2022-06-03 13:32:33 -0500 | [diff] [blame] | 1208 | } |
| 1209 | |
Vishnu Nair | 1e8bf10 | 2021-12-28 14:36:59 -0800 | [diff] [blame] | 1210 | // This test will currently fail because the old surfacecontrol will steal the last presented buffer |
| 1211 | // until the old surface control is destroyed. This is not necessarily a bug but to document a |
| 1212 | // limitation with the update API and to test any changes to make the api more robust. The current |
| 1213 | // approach for the client is to recreate the blastbufferqueue when the surfacecontrol updates. |
| 1214 | TEST_F(BLASTBufferQueueTest, DISABLED_DisconnectProducerTest) { |
| 1215 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 1216 | std::vector<sp<SurfaceControl>> surfaceControls; |
| 1217 | sp<IGraphicBufferProducer> igbProducer; |
| 1218 | for (int i = 0; i < 10; i++) { |
| 1219 | sp<SurfaceControl> sc = |
| 1220 | mClient->createSurface(String8("TestSurface"), mDisplayWidth, mDisplayHeight, |
| 1221 | PIXEL_FORMAT_RGBA_8888, |
| 1222 | ISurfaceComposerClient::eFXSurfaceBufferState, |
| 1223 | /*parent*/ nullptr); |
| 1224 | Transaction() |
| 1225 | .setLayerStack(mSurfaceControl, ui::DEFAULT_LAYER_STACK) |
| 1226 | .setLayer(mSurfaceControl, std::numeric_limits<int32_t>::max()) |
| 1227 | .show(mSurfaceControl) |
| 1228 | .setDataspace(mSurfaceControl, ui::Dataspace::V0_SRGB) |
| 1229 | .apply(true); |
| 1230 | surfaceControls.push_back(sc); |
| 1231 | adapter.update(sc, mDisplayWidth, mDisplayHeight); |
| 1232 | |
| 1233 | setUpProducer(adapter, igbProducer); |
| 1234 | Transaction next; |
| 1235 | queueBuffer(igbProducer, 0, 255, 0, 0); |
| 1236 | queueBuffer(igbProducer, 0, 0, 255, 0); |
Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 1237 | adapter.setSyncTransaction(next, true); |
Vishnu Nair | 1e8bf10 | 2021-12-28 14:36:59 -0800 | [diff] [blame] | 1238 | queueBuffer(igbProducer, 255, 0, 0, 0); |
| 1239 | |
| 1240 | CallbackHelper transactionCallback; |
| 1241 | next.addTransactionCompletedCallback(transactionCallback.function, |
| 1242 | transactionCallback.getContext()) |
| 1243 | .apply(); |
| 1244 | |
| 1245 | CallbackData callbackData; |
| 1246 | transactionCallback.getCallbackData(&callbackData); |
| 1247 | // capture screen and verify that it is red |
| 1248 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 1249 | ASSERT_NO_FATAL_FAILURE( |
| 1250 | checkScreenCapture(255, 0, 0, |
| 1251 | {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight})); |
| 1252 | igbProducer->disconnect(NATIVE_WINDOW_API_CPU); |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | // See DISABLED_DisconnectProducerTest |
| 1257 | TEST_F(BLASTBufferQueueTest, DISABLED_UpdateSurfaceControlTest) { |
| 1258 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 1259 | std::vector<sp<SurfaceControl>> surfaceControls; |
| 1260 | sp<IGraphicBufferProducer> igbProducer; |
| 1261 | for (int i = 0; i < 10; i++) { |
| 1262 | sp<SurfaceControl> sc = |
| 1263 | mClient->createSurface(String8("TestSurface"), mDisplayWidth, mDisplayHeight, |
| 1264 | PIXEL_FORMAT_RGBA_8888, |
| 1265 | ISurfaceComposerClient::eFXSurfaceBufferState, |
| 1266 | /*parent*/ nullptr); |
| 1267 | Transaction() |
| 1268 | .setLayerStack(mSurfaceControl, ui::DEFAULT_LAYER_STACK) |
| 1269 | .setLayer(mSurfaceControl, std::numeric_limits<int32_t>::max()) |
| 1270 | .show(mSurfaceControl) |
| 1271 | .setDataspace(mSurfaceControl, ui::Dataspace::V0_SRGB) |
| 1272 | .apply(true); |
| 1273 | surfaceControls.push_back(sc); |
| 1274 | adapter.update(sc, mDisplayWidth, mDisplayHeight); |
| 1275 | setUpProducer(adapter, igbProducer); |
| 1276 | |
| 1277 | Transaction next; |
| 1278 | queueBuffer(igbProducer, 0, 255, 0, 0); |
| 1279 | queueBuffer(igbProducer, 0, 0, 255, 0); |
Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 1280 | adapter.setSyncTransaction(next, true); |
Vishnu Nair | 1e8bf10 | 2021-12-28 14:36:59 -0800 | [diff] [blame] | 1281 | queueBuffer(igbProducer, 255, 0, 0, 0); |
| 1282 | |
| 1283 | CallbackHelper transactionCallback; |
| 1284 | next.addTransactionCompletedCallback(transactionCallback.function, |
| 1285 | transactionCallback.getContext()) |
| 1286 | .apply(); |
| 1287 | |
| 1288 | CallbackData callbackData; |
| 1289 | transactionCallback.getCallbackData(&callbackData); |
| 1290 | // capture screen and verify that it is red |
| 1291 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 1292 | ASSERT_NO_FATAL_FAILURE( |
| 1293 | checkScreenCapture(255, 0, 0, |
| 1294 | {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight})); |
| 1295 | } |
| 1296 | } |
| 1297 | |
Vishnu Nair | 8949612 | 2020-12-14 17:14:53 -0800 | [diff] [blame] | 1298 | class TestProducerListener : public BnProducerListener { |
| 1299 | public: |
| 1300 | sp<IGraphicBufferProducer> mIgbp; |
| 1301 | TestProducerListener(const sp<IGraphicBufferProducer>& igbp) : mIgbp(igbp) {} |
| 1302 | void onBufferReleased() override { |
| 1303 | sp<GraphicBuffer> buffer; |
| 1304 | sp<Fence> fence; |
| 1305 | mIgbp->detachNextBuffer(&buffer, &fence); |
| 1306 | } |
| 1307 | }; |
| 1308 | |
| 1309 | TEST_F(BLASTBufferQueueTest, CustomProducerListener) { |
| 1310 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 1311 | sp<IGraphicBufferProducer> igbProducer = adapter.getIGraphicBufferProducer(); |
| 1312 | ASSERT_NE(nullptr, igbProducer.get()); |
| 1313 | ASSERT_EQ(NO_ERROR, igbProducer->setMaxDequeuedBufferCount(2)); |
| 1314 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 1315 | ASSERT_EQ(NO_ERROR, |
| 1316 | igbProducer->connect(new TestProducerListener(igbProducer), NATIVE_WINDOW_API_CPU, |
| 1317 | false, &qbOutput)); |
| 1318 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
| 1319 | for (int i = 0; i < 3; i++) { |
| 1320 | int slot; |
| 1321 | sp<Fence> fence; |
| 1322 | sp<GraphicBuffer> buf; |
| 1323 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 1324 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 1325 | nullptr, nullptr); |
| 1326 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 1327 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 1328 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 1329 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), true /* autotimestamp */, |
| 1330 | HAL_DATASPACE_UNKNOWN, |
Vishnu Nair | 8949612 | 2020-12-14 17:14:53 -0800 | [diff] [blame] | 1331 | Rect(mDisplayWidth, mDisplayHeight), |
| 1332 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 1333 | Fence::NO_FENCE); |
| 1334 | igbProducer->queueBuffer(slot, input, &qbOutput); |
| 1335 | } |
| 1336 | adapter.waitForCallbacks(); |
| 1337 | } |
| 1338 | |
Vishnu Nair | 17dde61 | 2020-12-28 11:39:59 -0800 | [diff] [blame] | 1339 | TEST_F(BLASTBufferQueueTest, QueryNativeWindowQueuesToWindowComposer) { |
| 1340 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 1341 | |
| 1342 | sp<android::Surface> surface = new Surface(adapter.getIGraphicBufferProducer()); |
| 1343 | ANativeWindow* nativeWindow = (ANativeWindow*)(surface.get()); |
| 1344 | int queuesToNativeWindow = 0; |
| 1345 | int err = nativeWindow->query(nativeWindow, NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER, |
| 1346 | &queuesToNativeWindow); |
| 1347 | ASSERT_EQ(NO_ERROR, err); |
| 1348 | ASSERT_EQ(queuesToNativeWindow, 1); |
| 1349 | } |
| 1350 | |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1351 | // Test a slow producer doesn't hold up a faster producer from the same client. Essentially tests |
| 1352 | // BBQ uses separate transaction queues. |
Vishnu Nair | 277142c | 2021-01-05 18:35:29 -0800 | [diff] [blame] | 1353 | TEST_F(BLASTBufferQueueTest, OutOfOrderTransactionTest) { |
| 1354 | sp<SurfaceControl> bgSurface = |
| 1355 | mClient->createSurface(String8("BGTest"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 1356 | ISurfaceComposerClient::eFXSurfaceBufferState); |
| 1357 | ASSERT_NE(nullptr, bgSurface.get()); |
| 1358 | Transaction t; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 1359 | t.setLayerStack(bgSurface, ui::DEFAULT_LAYER_STACK) |
Vishnu Nair | 277142c | 2021-01-05 18:35:29 -0800 | [diff] [blame] | 1360 | .show(bgSurface) |
| 1361 | .setDataspace(bgSurface, ui::Dataspace::V0_SRGB) |
Vishnu Nair | 277142c | 2021-01-05 18:35:29 -0800 | [diff] [blame] | 1362 | .setLayer(bgSurface, std::numeric_limits<int32_t>::max() - 1) |
| 1363 | .apply(); |
| 1364 | |
| 1365 | BLASTBufferQueueHelper slowAdapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 1366 | sp<IGraphicBufferProducer> slowIgbProducer; |
| 1367 | setUpProducer(slowAdapter, slowIgbProducer); |
| 1368 | nsecs_t presentTimeDelay = std::chrono::nanoseconds(500ms).count(); |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 1369 | queueBuffer(slowIgbProducer, 0 /* r */, 255 /* g */, 0 /* b */, presentTimeDelay); |
Vishnu Nair | 277142c | 2021-01-05 18:35:29 -0800 | [diff] [blame] | 1370 | |
| 1371 | BLASTBufferQueueHelper fastAdapter(bgSurface, mDisplayWidth, mDisplayHeight); |
| 1372 | sp<IGraphicBufferProducer> fastIgbProducer; |
| 1373 | setUpProducer(fastAdapter, fastIgbProducer); |
| 1374 | uint8_t r = 255; |
| 1375 | uint8_t g = 0; |
| 1376 | uint8_t b = 0; |
| 1377 | queueBuffer(fastIgbProducer, r, g, b, 0 /* presentTimeDelay */); |
| 1378 | fastAdapter.waitForCallbacks(); |
| 1379 | |
| 1380 | // capture screen and verify that it is red |
| 1381 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
| 1382 | |
| 1383 | ASSERT_NO_FATAL_FAILURE( |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 1384 | checkScreenCapture(r, g, b, |
| 1385 | {0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight / 2})); |
Vishnu Nair | 277142c | 2021-01-05 18:35:29 -0800 | [diff] [blame] | 1386 | } |
| 1387 | |
Vishnu Nair | a4fbca5 | 2021-07-07 16:52:34 -0700 | [diff] [blame] | 1388 | TEST_F(BLASTBufferQueueTest, TransformHint) { |
| 1389 | // Transform hint is provided to BBQ via the surface control passed by WM |
| 1390 | mSurfaceControl->setTransformHint(ui::Transform::ROT_90); |
| 1391 | |
| 1392 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 1393 | sp<IGraphicBufferProducer> igbProducer = adapter.getIGraphicBufferProducer(); |
| 1394 | ASSERT_NE(nullptr, igbProducer.get()); |
| 1395 | ASSERT_EQ(NO_ERROR, igbProducer->setMaxDequeuedBufferCount(2)); |
| 1396 | sp<Surface> surface = adapter.getSurface(); |
| 1397 | |
| 1398 | // Before connecting to the surface, we do not get a valid transform hint |
| 1399 | int transformHint; |
| 1400 | surface->query(NATIVE_WINDOW_TRANSFORM_HINT, &transformHint); |
| 1401 | ASSERT_EQ(ui::Transform::ROT_0, transformHint); |
| 1402 | |
| 1403 | ASSERT_EQ(NO_ERROR, |
| 1404 | surface->connect(NATIVE_WINDOW_API_CPU, new TestProducerListener(igbProducer))); |
| 1405 | |
| 1406 | // After connecting to the surface, we should get the correct hint. |
| 1407 | surface->query(NATIVE_WINDOW_TRANSFORM_HINT, &transformHint); |
| 1408 | ASSERT_EQ(ui::Transform::ROT_90, transformHint); |
| 1409 | |
| 1410 | ANativeWindow_Buffer buffer; |
| 1411 | surface->lock(&buffer, nullptr /* inOutDirtyBounds */); |
| 1412 | |
| 1413 | // Transform hint is updated via callbacks or surface control updates |
| 1414 | mSurfaceControl->setTransformHint(ui::Transform::ROT_0); |
| 1415 | adapter.update(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 1416 | |
| 1417 | // The hint does not change and matches the value used when dequeueing the buffer. |
| 1418 | surface->query(NATIVE_WINDOW_TRANSFORM_HINT, &transformHint); |
| 1419 | ASSERT_EQ(ui::Transform::ROT_90, transformHint); |
| 1420 | |
| 1421 | surface->unlockAndPost(); |
| 1422 | |
| 1423 | // After queuing the buffer, we get the updated transform hint |
| 1424 | surface->query(NATIVE_WINDOW_TRANSFORM_HINT, &transformHint); |
| 1425 | ASSERT_EQ(ui::Transform::ROT_0, transformHint); |
| 1426 | |
| 1427 | adapter.waitForCallbacks(); |
| 1428 | } |
| 1429 | |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 1430 | class BLASTBufferQueueTransformTest : public BLASTBufferQueueTest { |
| 1431 | public: |
| 1432 | void test(uint32_t tr) { |
| 1433 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 1434 | sp<IGraphicBufferProducer> igbProducer; |
| 1435 | setUpProducer(adapter, igbProducer); |
| 1436 | |
| 1437 | auto bufWidth = mDisplayWidth; |
| 1438 | auto bufHeight = mDisplayHeight; |
| 1439 | int slot; |
| 1440 | sp<Fence> fence; |
| 1441 | sp<GraphicBuffer> buf; |
| 1442 | |
| 1443 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, bufWidth, bufHeight, |
| 1444 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 1445 | nullptr, nullptr); |
| 1446 | ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret); |
| 1447 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 1448 | |
| 1449 | fillQuadrants(buf); |
| 1450 | |
| 1451 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 1452 | IGraphicBufferProducer::QueueBufferInput input(systemTime(), true /* autotimestamp */, |
| 1453 | HAL_DATASPACE_UNKNOWN, |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 1454 | Rect(bufWidth, bufHeight), |
Vishnu Nair | e1a4232 | 2020-10-02 17:42:04 -0700 | [diff] [blame] | 1455 | NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW, |
| 1456 | tr, Fence::NO_FENCE); |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 1457 | igbProducer->queueBuffer(slot, input, &qbOutput); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 1458 | ASSERT_NE(ui::Transform::ROT_INVALID, qbOutput.transformHint); |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 1459 | |
| 1460 | adapter.waitForCallbacks(); |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 1461 | ASSERT_EQ(NO_ERROR, captureDisplay(mCaptureArgs, mCaptureResults)); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 1462 | |
Valerie Hau | 5977fc8 | 2019-12-05 15:56:39 -0800 | [diff] [blame] | 1463 | switch (tr) { |
| 1464 | case ui::Transform::ROT_0: |
| 1465 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 0, 0, |
| 1466 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 1467 | (int32_t)mDisplayHeight / 2}, |
| 1468 | 1)); |
| 1469 | ASSERT_NO_FATAL_FAILURE( |
| 1470 | checkScreenCapture(255, 0, 0, |
| 1471 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 1472 | (int32_t)mDisplayHeight / 2}, |
| 1473 | 1)); |
| 1474 | ASSERT_NO_FATAL_FAILURE( |
| 1475 | checkScreenCapture(0, 255, 0, |
| 1476 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 1477 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 1478 | 1)); |
| 1479 | ASSERT_NO_FATAL_FAILURE( |
| 1480 | checkScreenCapture(0, 0, 255, |
| 1481 | {0, (int32_t)mDisplayHeight / 2, |
| 1482 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 1483 | 1)); |
| 1484 | break; |
| 1485 | case ui::Transform::FLIP_H: |
| 1486 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(255, 0, 0, |
| 1487 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 1488 | (int32_t)mDisplayHeight / 2}, |
| 1489 | 1)); |
| 1490 | ASSERT_NO_FATAL_FAILURE( |
| 1491 | checkScreenCapture(0, 0, 0, |
| 1492 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 1493 | (int32_t)mDisplayHeight / 2}, |
| 1494 | 1)); |
| 1495 | ASSERT_NO_FATAL_FAILURE( |
| 1496 | checkScreenCapture(0, 0, 255, |
| 1497 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 1498 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 1499 | 1)); |
| 1500 | ASSERT_NO_FATAL_FAILURE( |
| 1501 | checkScreenCapture(0, 255, 0, |
| 1502 | {0, (int32_t)mDisplayHeight / 2, |
| 1503 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 1504 | 1)); |
| 1505 | break; |
| 1506 | case ui::Transform::FLIP_V: |
| 1507 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 0, 255, |
| 1508 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 1509 | (int32_t)mDisplayHeight / 2}, |
| 1510 | 1)); |
| 1511 | ASSERT_NO_FATAL_FAILURE( |
| 1512 | checkScreenCapture(0, 255, 0, |
| 1513 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 1514 | (int32_t)mDisplayHeight / 2}, |
| 1515 | 1)); |
| 1516 | ASSERT_NO_FATAL_FAILURE( |
| 1517 | checkScreenCapture(255, 0, 0, |
| 1518 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 1519 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 1520 | 1)); |
| 1521 | ASSERT_NO_FATAL_FAILURE( |
| 1522 | checkScreenCapture(0, 0, 0, |
| 1523 | {0, (int32_t)mDisplayHeight / 2, |
| 1524 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 1525 | 1)); |
| 1526 | break; |
| 1527 | case ui::Transform::ROT_90: |
| 1528 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 0, 255, |
| 1529 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 1530 | (int32_t)mDisplayHeight / 2}, |
| 1531 | 1)); |
| 1532 | ASSERT_NO_FATAL_FAILURE( |
| 1533 | checkScreenCapture(0, 0, 0, |
| 1534 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 1535 | (int32_t)mDisplayHeight / 2}, |
| 1536 | 1)); |
| 1537 | ASSERT_NO_FATAL_FAILURE( |
| 1538 | checkScreenCapture(255, 0, 0, |
| 1539 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 1540 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 1541 | 1)); |
| 1542 | ASSERT_NO_FATAL_FAILURE( |
| 1543 | checkScreenCapture(0, 255, 0, |
| 1544 | {0, (int32_t)mDisplayHeight / 2, |
| 1545 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 1546 | 1)); |
| 1547 | break; |
| 1548 | case ui::Transform::ROT_180: |
| 1549 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(0, 255, 0, |
| 1550 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 1551 | (int32_t)mDisplayHeight / 2}, |
| 1552 | 1)); |
| 1553 | ASSERT_NO_FATAL_FAILURE( |
| 1554 | checkScreenCapture(0, 0, 255, |
| 1555 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 1556 | (int32_t)mDisplayHeight / 2}, |
| 1557 | 1)); |
| 1558 | ASSERT_NO_FATAL_FAILURE( |
| 1559 | checkScreenCapture(0, 0, 0, |
| 1560 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 1561 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 1562 | 1)); |
| 1563 | ASSERT_NO_FATAL_FAILURE( |
| 1564 | checkScreenCapture(255, 0, 0, |
| 1565 | {0, (int32_t)mDisplayHeight / 2, |
| 1566 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 1567 | 1)); |
| 1568 | break; |
| 1569 | case ui::Transform::ROT_270: |
| 1570 | ASSERT_NO_FATAL_FAILURE(checkScreenCapture(255, 0, 0, |
| 1571 | {0, 0, (int32_t)mDisplayWidth / 2, |
| 1572 | (int32_t)mDisplayHeight / 2}, |
| 1573 | 1)); |
| 1574 | ASSERT_NO_FATAL_FAILURE( |
| 1575 | checkScreenCapture(0, 255, 0, |
| 1576 | {(int32_t)mDisplayWidth / 2, 0, (int32_t)mDisplayWidth, |
| 1577 | (int32_t)mDisplayHeight / 2}, |
| 1578 | 1)); |
| 1579 | ASSERT_NO_FATAL_FAILURE( |
| 1580 | checkScreenCapture(0, 0, 255, |
| 1581 | {(int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight / 2, |
| 1582 | (int32_t)mDisplayWidth, (int32_t)mDisplayHeight}, |
| 1583 | 1)); |
| 1584 | ASSERT_NO_FATAL_FAILURE( |
| 1585 | checkScreenCapture(0, 0, 0, |
| 1586 | {0, (int32_t)mDisplayHeight / 2, |
| 1587 | (int32_t)mDisplayWidth / 2, (int32_t)mDisplayHeight}, |
| 1588 | 1)); |
| 1589 | } |
| 1590 | } |
| 1591 | }; |
| 1592 | |
| 1593 | TEST_F(BLASTBufferQueueTransformTest, setTransform_ROT_0) { |
| 1594 | test(ui::Transform::ROT_0); |
| 1595 | } |
| 1596 | |
| 1597 | TEST_F(BLASTBufferQueueTransformTest, setTransform_FLIP_H) { |
| 1598 | test(ui::Transform::FLIP_H); |
| 1599 | } |
| 1600 | |
| 1601 | TEST_F(BLASTBufferQueueTransformTest, setTransform_FLIP_V) { |
| 1602 | test(ui::Transform::FLIP_V); |
| 1603 | } |
| 1604 | |
| 1605 | TEST_F(BLASTBufferQueueTransformTest, setTransform_ROT_90) { |
| 1606 | test(ui::Transform::ROT_90); |
| 1607 | } |
| 1608 | |
| 1609 | TEST_F(BLASTBufferQueueTransformTest, setTransform_ROT_180) { |
| 1610 | test(ui::Transform::ROT_180); |
| 1611 | } |
| 1612 | |
| 1613 | TEST_F(BLASTBufferQueueTransformTest, setTransform_ROT_270) { |
| 1614 | test(ui::Transform::ROT_270); |
| 1615 | } |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 1616 | |
| 1617 | class BLASTFrameEventHistoryTest : public BLASTBufferQueueTest { |
| 1618 | public: |
| 1619 | void setUpAndQueueBuffer(const sp<IGraphicBufferProducer>& igbProducer, |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1620 | nsecs_t* outRequestedPresentTime, nsecs_t* postedTime, |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 1621 | IGraphicBufferProducer::QueueBufferOutput* qbOutput, |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1622 | bool getFrameTimestamps, nsecs_t requestedPresentTime = systemTime()) { |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 1623 | int slot; |
| 1624 | sp<Fence> fence; |
| 1625 | sp<GraphicBuffer> buf; |
| 1626 | auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight, |
| 1627 | PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 1628 | nullptr, nullptr); |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1629 | if (IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION == ret) { |
| 1630 | ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf)); |
| 1631 | } |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 1632 | |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1633 | *outRequestedPresentTime = requestedPresentTime; |
| 1634 | IGraphicBufferProducer::QueueBufferInput input(requestedPresentTime, false, |
| 1635 | HAL_DATASPACE_UNKNOWN, |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 1636 | Rect(mDisplayWidth, mDisplayHeight), |
| 1637 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0, |
| 1638 | Fence::NO_FENCE, /*sticky*/ 0, |
| 1639 | getFrameTimestamps); |
| 1640 | if (postedTime) *postedTime = systemTime(); |
| 1641 | igbProducer->queueBuffer(slot, input, qbOutput); |
| 1642 | } |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1643 | sp<SurfaceControl> mBufferQueueSurfaceControl; |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 1644 | }; |
| 1645 | |
| 1646 | TEST_F(BLASTFrameEventHistoryTest, FrameEventHistory_Basic) { |
| 1647 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 1648 | sp<IGraphicBufferProducer> igbProducer; |
| 1649 | ProducerFrameEventHistory history; |
| 1650 | setUpProducer(adapter, igbProducer); |
| 1651 | |
| 1652 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 1653 | nsecs_t requestedPresentTimeA = 0; |
| 1654 | nsecs_t postedTimeA = 0; |
| 1655 | setUpAndQueueBuffer(igbProducer, &requestedPresentTimeA, &postedTimeA, &qbOutput, true); |
| 1656 | history.applyDelta(qbOutput.frameTimestamps); |
| 1657 | |
| 1658 | FrameEvents* events = nullptr; |
| 1659 | events = history.getFrame(1); |
| 1660 | ASSERT_NE(nullptr, events); |
| 1661 | ASSERT_EQ(1, events->frameNumber); |
| 1662 | ASSERT_EQ(requestedPresentTimeA, events->requestedPresentTime); |
| 1663 | ASSERT_GE(events->postedTime, postedTimeA); |
| 1664 | |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 1665 | adapter.waitForCallback(1); |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 1666 | |
| 1667 | // queue another buffer so we query for frame event deltas |
| 1668 | nsecs_t requestedPresentTimeB = 0; |
| 1669 | nsecs_t postedTimeB = 0; |
| 1670 | setUpAndQueueBuffer(igbProducer, &requestedPresentTimeB, &postedTimeB, &qbOutput, true); |
| 1671 | history.applyDelta(qbOutput.frameTimestamps); |
| 1672 | events = history.getFrame(1); |
| 1673 | ASSERT_NE(nullptr, events); |
| 1674 | |
| 1675 | // frame number, requestedPresentTime, and postTime should not have changed |
| 1676 | ASSERT_EQ(1, events->frameNumber); |
| 1677 | ASSERT_EQ(requestedPresentTimeA, events->requestedPresentTime); |
| 1678 | ASSERT_GE(events->postedTime, postedTimeA); |
| 1679 | |
| 1680 | ASSERT_GE(events->latchTime, postedTimeA); |
| 1681 | ASSERT_GE(events->dequeueReadyTime, events->latchTime); |
| 1682 | ASSERT_NE(nullptr, events->gpuCompositionDoneFence); |
| 1683 | ASSERT_NE(nullptr, events->displayPresentFence); |
| 1684 | ASSERT_NE(nullptr, events->releaseFence); |
| 1685 | |
| 1686 | // we should also have gotten the initial values for the next frame |
| 1687 | events = history.getFrame(2); |
| 1688 | ASSERT_NE(nullptr, events); |
| 1689 | ASSERT_EQ(2, events->frameNumber); |
| 1690 | ASSERT_EQ(requestedPresentTimeB, events->requestedPresentTime); |
| 1691 | ASSERT_GE(events->postedTime, postedTimeB); |
Valerie Hau | 78491e9 | 2020-04-15 13:10:56 -0700 | [diff] [blame] | 1692 | |
| 1693 | // wait for any callbacks that have not been received |
| 1694 | adapter.waitForCallbacks(); |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 1695 | } |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1696 | |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1697 | TEST_F(BLASTFrameEventHistoryTest, FrameEventHistory_DroppedFrame) { |
| 1698 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 1699 | sp<IGraphicBufferProducer> igbProducer; |
| 1700 | setUpProducer(adapter, igbProducer); |
| 1701 | |
| 1702 | ProducerFrameEventHistory history; |
| 1703 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 1704 | nsecs_t requestedPresentTimeA = 0; |
| 1705 | nsecs_t postedTimeA = 0; |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1706 | // Present the frame sometime in the future so we can add two frames to the queue so the older |
| 1707 | // one will be dropped. |
| 1708 | nsecs_t presentTime = systemTime() + std::chrono::nanoseconds(500ms).count(); |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1709 | setUpAndQueueBuffer(igbProducer, &requestedPresentTimeA, &postedTimeA, &qbOutput, true, |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1710 | presentTime); |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1711 | history.applyDelta(qbOutput.frameTimestamps); |
| 1712 | |
| 1713 | FrameEvents* events = nullptr; |
| 1714 | events = history.getFrame(1); |
| 1715 | ASSERT_NE(nullptr, events); |
| 1716 | ASSERT_EQ(1, events->frameNumber); |
| 1717 | ASSERT_EQ(requestedPresentTimeA, events->requestedPresentTime); |
| 1718 | ASSERT_GE(events->postedTime, postedTimeA); |
| 1719 | |
| 1720 | // queue another buffer so the first can be dropped |
| 1721 | nsecs_t requestedPresentTimeB = 0; |
| 1722 | nsecs_t postedTimeB = 0; |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1723 | presentTime = systemTime() + std::chrono::nanoseconds(1ms).count(); |
| 1724 | setUpAndQueueBuffer(igbProducer, &requestedPresentTimeB, &postedTimeB, &qbOutput, true, |
| 1725 | presentTime); |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1726 | history.applyDelta(qbOutput.frameTimestamps); |
| 1727 | events = history.getFrame(1); |
| 1728 | ASSERT_NE(nullptr, events); |
| 1729 | |
| 1730 | // frame number, requestedPresentTime, and postTime should not have changed |
| 1731 | ASSERT_EQ(1, events->frameNumber); |
| 1732 | ASSERT_EQ(requestedPresentTimeA, events->requestedPresentTime); |
| 1733 | ASSERT_GE(events->postedTime, postedTimeA); |
| 1734 | |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1735 | // a valid latchtime and pre and post composition info should not be set for the dropped frame |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1736 | ASSERT_FALSE(events->hasLatchInfo()); |
| 1737 | ASSERT_FALSE(events->hasDequeueReadyInfo()); |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1738 | ASSERT_FALSE(events->hasGpuCompositionDoneInfo()); |
| 1739 | ASSERT_FALSE(events->hasDisplayPresentInfo()); |
| 1740 | ASSERT_FALSE(events->hasReleaseInfo()); |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1741 | |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1742 | // wait for the last transaction to be completed. |
| 1743 | adapter.waitForCallback(2); |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1744 | |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1745 | // queue another buffer so we query for frame event deltas |
| 1746 | nsecs_t requestedPresentTimeC = 0; |
| 1747 | nsecs_t postedTimeC = 0; |
| 1748 | setUpAndQueueBuffer(igbProducer, &requestedPresentTimeC, &postedTimeC, &qbOutput, true); |
| 1749 | history.applyDelta(qbOutput.frameTimestamps); |
| 1750 | |
| 1751 | // frame number, requestedPresentTime, and postTime should not have changed |
| 1752 | ASSERT_EQ(1, events->frameNumber); |
| 1753 | ASSERT_EQ(requestedPresentTimeA, events->requestedPresentTime); |
| 1754 | ASSERT_GE(events->postedTime, postedTimeA); |
| 1755 | |
| 1756 | // a valid latchtime and pre and post composition info should not be set for the dropped frame |
| 1757 | ASSERT_FALSE(events->hasLatchInfo()); |
| 1758 | ASSERT_FALSE(events->hasDequeueReadyInfo()); |
| 1759 | ASSERT_FALSE(events->hasGpuCompositionDoneInfo()); |
| 1760 | ASSERT_FALSE(events->hasDisplayPresentInfo()); |
| 1761 | ASSERT_FALSE(events->hasReleaseInfo()); |
| 1762 | |
| 1763 | // we should also have gotten values for the presented frame |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1764 | events = history.getFrame(2); |
| 1765 | ASSERT_NE(nullptr, events); |
| 1766 | ASSERT_EQ(2, events->frameNumber); |
| 1767 | ASSERT_EQ(requestedPresentTimeB, events->requestedPresentTime); |
| 1768 | ASSERT_GE(events->postedTime, postedTimeB); |
Vishnu Nair | de66dc7 | 2021-06-17 17:54:41 -0700 | [diff] [blame] | 1769 | ASSERT_GE(events->latchTime, postedTimeB); |
| 1770 | ASSERT_GE(events->dequeueReadyTime, events->latchTime); |
| 1771 | ASSERT_NE(nullptr, events->gpuCompositionDoneFence); |
| 1772 | ASSERT_NE(nullptr, events->displayPresentFence); |
| 1773 | ASSERT_NE(nullptr, events->releaseFence); |
| 1774 | |
| 1775 | // wait for any callbacks that have not been received |
| 1776 | adapter.waitForCallbacks(); |
Vishnu Nair | 083efd3 | 2021-02-12 09:32:30 -0800 | [diff] [blame] | 1777 | } |
| 1778 | |
Vishnu Nair | 9a69a04 | 2021-06-18 13:19:49 -0700 | [diff] [blame] | 1779 | TEST_F(BLASTFrameEventHistoryTest, FrameEventHistory_CompositorTimings) { |
| 1780 | BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight); |
| 1781 | sp<IGraphicBufferProducer> igbProducer; |
| 1782 | ProducerFrameEventHistory history; |
| 1783 | setUpProducer(adapter, igbProducer); |
| 1784 | |
| 1785 | IGraphicBufferProducer::QueueBufferOutput qbOutput; |
| 1786 | nsecs_t requestedPresentTimeA = 0; |
| 1787 | nsecs_t postedTimeA = 0; |
Vishnu Nair | 9a69a04 | 2021-06-18 13:19:49 -0700 | [diff] [blame] | 1788 | setUpAndQueueBuffer(igbProducer, &requestedPresentTimeA, &postedTimeA, &qbOutput, true); |
| 1789 | history.applyDelta(qbOutput.frameTimestamps); |
| 1790 | adapter.waitForCallback(1); |
| 1791 | |
| 1792 | // queue another buffer so we query for frame event deltas |
| 1793 | nsecs_t requestedPresentTimeB = 0; |
| 1794 | nsecs_t postedTimeB = 0; |
| 1795 | setUpAndQueueBuffer(igbProducer, &requestedPresentTimeB, &postedTimeB, &qbOutput, true); |
| 1796 | history.applyDelta(qbOutput.frameTimestamps); |
| 1797 | |
| 1798 | // check for a valid compositor deadline |
| 1799 | ASSERT_NE(0, history.getReportedCompositeDeadline()); |
| 1800 | |
| 1801 | // wait for any callbacks that have not been received |
| 1802 | adapter.waitForCallbacks(); |
| 1803 | } |
| 1804 | |
Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 1805 | } // namespace android |