blob: 495418b921f5c383163f1719350fe581e2f392e9 [file] [log] [blame]
Robert Carr78c25dd2019-08-15 14:10:33 -07001/*
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
Valerie Haud3b90d22019-11-06 09:37:31 -080017#undef LOG_TAG
18#define LOG_TAG "BLASTBufferQueue"
19
Valerie Haua32c5522019-12-09 10:11:08 -080020#define ATRACE_TAG ATRACE_TAG_GRAPHICS
Vishnu Naire1a42322020-10-02 17:42:04 -070021//#define LOG_NDEBUG 0
Valerie Haua32c5522019-12-09 10:11:08 -080022
Jim Shargod30823a2024-07-27 02:49:39 +000023#include <com_android_graphics_libgui_flags.h>
liulijuneb489f62022-10-17 22:02:14 +080024#include <cutils/atomic.h>
Patrick Williams7c9fa272024-08-30 12:38:43 +000025#include <ftl/fake_guard.h>
Robert Carr78c25dd2019-08-15 14:10:33 -070026#include <gui/BLASTBufferQueue.h>
27#include <gui/BufferItemConsumer.h>
Vishnu Nair89496122020-12-14 17:14:53 -080028#include <gui/BufferQueueConsumer.h>
29#include <gui/BufferQueueCore.h>
30#include <gui/BufferQueueProducer.h>
Patrick Williams7c9fa272024-08-30 12:38:43 +000031#include <sys/epoll.h>
32#include <sys/eventfd.h>
Ady Abraham107788e2023-10-17 12:31:08 -070033
Ady Abraham6cdd3fd2023-09-07 18:45:58 -070034#include <gui/FrameRateUtils.h>
Valerie Hau45e4b3b2019-12-03 10:49:17 -080035#include <gui/GLConsumer.h>
Vishnu Nair89496122020-12-14 17:14:53 -080036#include <gui/IProducerListener.h>
Robert Carr05086b22020-10-13 18:22:51 -070037#include <gui/Surface.h>
chaviw57ae4b22022-02-03 16:51:39 -060038#include <gui/TraceUtils.h>
Vishnu Nair89496122020-12-14 17:14:53 -080039#include <utils/Singleton.h>
Valerie Haua32c5522019-12-09 10:11:08 -080040#include <utils/Trace.h>
41
Ady Abraham0bde6b52021-05-18 13:57:02 -070042#include <private/gui/ComposerService.h>
Huihong Luo02186fb2022-02-23 14:21:54 -080043#include <private/gui/ComposerServiceAIDL.h>
Ady Abraham0bde6b52021-05-18 13:57:02 -070044
Chavi Weingartene0237bb2023-02-06 21:48:32 +000045#include <android-base/thread_annotations.h>
Robert Carr78c25dd2019-08-15 14:10:33 -070046
Alec Mouri21d94322023-10-17 19:51:39 +000047#include <com_android_graphics_libgui_flags.h>
48
Ady Abraham6cdd3fd2023-09-07 18:45:58 -070049using namespace com::android::graphics::libgui;
Robert Carr78c25dd2019-08-15 14:10:33 -070050using namespace std::chrono_literals;
51
Vishnu Nairdab94092020-09-29 16:09:04 -070052namespace {
Patrick Williams078d7362024-08-27 10:20:39 -050053
54#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BUFFER_RELEASE_CHANNEL)
Patrick Williamsc16a4a52024-10-26 01:48:01 -050055template <class Mutex>
56class UnlockGuard {
Patrick Williams078d7362024-08-27 10:20:39 -050057public:
Patrick Williamsc16a4a52024-10-26 01:48:01 -050058 explicit UnlockGuard(Mutex& lock) : mLock{lock} { mLock.unlock(); }
Patrick Williams078d7362024-08-27 10:20:39 -050059
Patrick Williamsc16a4a52024-10-26 01:48:01 -050060 ~UnlockGuard() { mLock.lock(); }
Patrick Williams078d7362024-08-27 10:20:39 -050061
Patrick Williamsc16a4a52024-10-26 01:48:01 -050062 UnlockGuard(const UnlockGuard&) = delete;
63 UnlockGuard& operator=(const UnlockGuard&) = delete;
Patrick Williams078d7362024-08-27 10:20:39 -050064
65private:
Patrick Williamsc16a4a52024-10-26 01:48:01 -050066 Mutex& mLock;
Patrick Williams078d7362024-08-27 10:20:39 -050067};
68#endif
69
chaviw3277faf2021-05-19 16:45:23 -050070inline const char* boolToString(bool b) {
Vishnu Nairdab94092020-09-29 16:09:04 -070071 return b ? "true" : "false";
72}
Patrick Williams078d7362024-08-27 10:20:39 -050073
Vishnu Nairdab94092020-09-29 16:09:04 -070074} // namespace
75
Robert Carr78c25dd2019-08-15 14:10:33 -070076namespace android {
77
Vishnu Nairdab94092020-09-29 16:09:04 -070078// Macros to include adapter info in log messages
chaviwd7deef72021-10-06 11:53:40 -050079#define BQA_LOGD(x, ...) \
80 ALOGD("[%s](f:%u,a:%u) " x, mName.c_str(), mNumFrameAvailable, mNumAcquired, ##__VA_ARGS__)
Vishnu Nairdab94092020-09-29 16:09:04 -070081#define BQA_LOGV(x, ...) \
82 ALOGV("[%s](f:%u,a:%u) " x, mName.c_str(), mNumFrameAvailable, mNumAcquired, ##__VA_ARGS__)
Vishnu Nairc6f89ee2020-12-11 14:27:32 -080083// enable logs for a single layer
84//#define BQA_LOGV(x, ...) \
85// ALOGV_IF((strstr(mName.c_str(), "SurfaceView") != nullptr), "[%s](f:%u,a:%u) " x, \
86// mName.c_str(), mNumFrameAvailable, mNumAcquired, ##__VA_ARGS__)
Vishnu Nairdab94092020-09-29 16:09:04 -070087#define BQA_LOGE(x, ...) \
88 ALOGE("[%s](f:%u,a:%u) " x, mName.c_str(), mNumFrameAvailable, mNumAcquired, ##__VA_ARGS__)
89
chaviw57ae4b22022-02-03 16:51:39 -060090#define BBQ_TRACE(x, ...) \
91 ATRACE_FORMAT("%s - %s(f:%u,a:%u)" x, __FUNCTION__, mName.c_str(), mNumFrameAvailable, \
92 mNumAcquired, ##__VA_ARGS__)
93
Chavi Weingartene0237bb2023-02-06 21:48:32 +000094#define UNIQUE_LOCK_WITH_ASSERTION(mutex) \
95 std::unique_lock _lock{mutex}; \
96 base::ScopedLockAssertion assumeLocked(mutex);
97
Valerie Hau871d6352020-01-29 08:44:02 -080098void BLASTBufferItemConsumer::onDisconnect() {
Jiakai Zhangc33c63a2021-11-09 11:24:04 +000099 Mutex::Autolock lock(mMutex);
100 mPreviouslyConnected = mCurrentlyConnected;
101 mCurrentlyConnected = false;
102 if (mPreviouslyConnected) {
103 mDisconnectEvents.push(mCurrentFrameNumber);
Valerie Hau871d6352020-01-29 08:44:02 -0800104 }
Jiakai Zhangc33c63a2021-11-09 11:24:04 +0000105 mFrameEventHistory.onDisconnect();
Valerie Hau871d6352020-01-29 08:44:02 -0800106}
107
108void BLASTBufferItemConsumer::addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps,
109 FrameEventHistoryDelta* outDelta) {
Hongguang Chen621ec582021-02-16 15:42:35 -0800110 Mutex::Autolock lock(mMutex);
Valerie Hau871d6352020-01-29 08:44:02 -0800111 if (newTimestamps) {
112 // BufferQueueProducer only adds a new timestamp on
113 // queueBuffer
114 mCurrentFrameNumber = newTimestamps->frameNumber;
115 mFrameEventHistory.addQueue(*newTimestamps);
116 }
117 if (outDelta) {
118 // frame event histories will be processed
119 // only after the producer connects and requests
120 // deltas for the first time. Forward this intent
121 // to SF-side to turn event processing back on
122 mPreviouslyConnected = mCurrentlyConnected;
123 mCurrentlyConnected = true;
124 mFrameEventHistory.getAndResetDelta(outDelta);
125 }
126}
127
Alec Mouri21d94322023-10-17 19:51:39 +0000128void BLASTBufferItemConsumer::updateFrameTimestamps(
129 uint64_t frameNumber, uint64_t previousFrameNumber, nsecs_t refreshStartTime,
130 const sp<Fence>& glDoneFence, const sp<Fence>& presentFence,
131 const sp<Fence>& prevReleaseFence, CompositorTiming compositorTiming, nsecs_t latchTime,
132 nsecs_t dequeueReadyTime) {
Hongguang Chen621ec582021-02-16 15:42:35 -0800133 Mutex::Autolock lock(mMutex);
Valerie Hau871d6352020-01-29 08:44:02 -0800134
135 // if the producer is not connected, don't bother updating,
136 // the next producer that connects won't access this frame event
137 if (!mCurrentlyConnected) return;
138 std::shared_ptr<FenceTime> glDoneFenceTime = std::make_shared<FenceTime>(glDoneFence);
139 std::shared_ptr<FenceTime> presentFenceTime = std::make_shared<FenceTime>(presentFence);
140 std::shared_ptr<FenceTime> releaseFenceTime = std::make_shared<FenceTime>(prevReleaseFence);
141
142 mFrameEventHistory.addLatch(frameNumber, latchTime);
Alec Mouri21d94322023-10-17 19:51:39 +0000143 if (flags::frametimestamps_previousrelease()) {
144 if (previousFrameNumber > 0) {
145 mFrameEventHistory.addRelease(previousFrameNumber, dequeueReadyTime,
146 std::move(releaseFenceTime));
147 }
148 } else {
149 mFrameEventHistory.addRelease(frameNumber, dequeueReadyTime, std::move(releaseFenceTime));
150 }
151
Valerie Hau871d6352020-01-29 08:44:02 -0800152 mFrameEventHistory.addPreComposition(frameNumber, refreshStartTime);
153 mFrameEventHistory.addPostComposition(frameNumber, glDoneFenceTime, presentFenceTime,
154 compositorTiming);
155}
156
157void BLASTBufferItemConsumer::getConnectionEvents(uint64_t frameNumber, bool* needsDisconnect) {
158 bool disconnect = false;
Hongguang Chen621ec582021-02-16 15:42:35 -0800159 Mutex::Autolock lock(mMutex);
Valerie Hau871d6352020-01-29 08:44:02 -0800160 while (!mDisconnectEvents.empty() && mDisconnectEvents.front() <= frameNumber) {
161 disconnect = true;
162 mDisconnectEvents.pop();
163 }
164 if (needsDisconnect != nullptr) *needsDisconnect = disconnect;
165}
166
Hongguang Chen621ec582021-02-16 15:42:35 -0800167void BLASTBufferItemConsumer::onSidebandStreamChanged() {
Ady Abrahamdbca1352021-12-15 11:58:56 -0800168 sp<BLASTBufferQueue> bbq = mBLASTBufferQueue.promote();
169 if (bbq != nullptr) {
Hongguang Chen621ec582021-02-16 15:42:35 -0800170 sp<NativeHandle> stream = getSidebandStream();
Ady Abrahamdbca1352021-12-15 11:58:56 -0800171 bbq->setSidebandStream(stream);
Hongguang Chen621ec582021-02-16 15:42:35 -0800172 }
173}
174
Ady Abraham107788e2023-10-17 12:31:08 -0700175#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE)
Ady Abraham6cdd3fd2023-09-07 18:45:58 -0700176void BLASTBufferItemConsumer::onSetFrameRate(float frameRate, int8_t compatibility,
177 int8_t changeFrameRateStrategy) {
178 sp<BLASTBufferQueue> bbq = mBLASTBufferQueue.promote();
179 if (bbq != nullptr) {
180 bbq->setFrameRate(frameRate, compatibility, changeFrameRateStrategy);
181 }
182}
183#endif
184
Brian Lindahlc794b692023-01-31 15:42:47 -0700185void BLASTBufferItemConsumer::resizeFrameEventHistory(size_t newSize) {
186 Mutex::Autolock lock(mMutex);
187 mFrameEventHistory.resize(newSize);
188}
189
Vishnu Naird2aaab12022-02-10 14:49:09 -0800190BLASTBufferQueue::BLASTBufferQueue(const std::string& name, bool updateDestinationFrame)
Vishnu Nair1cb8e892021-12-06 16:45:48 -0800191 : mSurfaceControl(nullptr),
192 mSize(1, 1),
Vishnu Nairea0de002020-11-17 17:42:37 -0800193 mRequestedSize(mSize),
Vishnu Nair1cb8e892021-12-06 16:45:48 -0800194 mFormat(PIXEL_FORMAT_RGBA_8888),
Tianhao Yao4861b102022-02-03 20:18:35 +0000195 mTransactionReadyCallback(nullptr),
Vishnu Naird2aaab12022-02-10 14:49:09 -0800196 mSyncTransaction(nullptr),
197 mUpdateDestinationFrame(updateDestinationFrame) {
Vishnu Nair89496122020-12-14 17:14:53 -0800198 createBufferQueue(&mProducer, &mConsumer);
Jim Shargod30823a2024-07-27 02:49:39 +0000199#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
200 mBufferItemConsumer = new BLASTBufferItemConsumer(mProducer, mConsumer,
201 GraphicBuffer::USAGE_HW_COMPOSER |
202 GraphicBuffer::USAGE_HW_TEXTURE,
203 1, false, this);
204#else
Vishnu Nair1618c672021-02-05 13:08:26 -0800205 mBufferItemConsumer = new BLASTBufferItemConsumer(mConsumer,
206 GraphicBuffer::USAGE_HW_COMPOSER |
207 GraphicBuffer::USAGE_HW_TEXTURE,
Ady Abrahamdbca1352021-12-15 11:58:56 -0800208 1, false, this);
Jim Shargod30823a2024-07-27 02:49:39 +0000209#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
210 // since the adapter is in the client process, set dequeue timeout
211 // explicitly so that dequeueBuffer will block
212 mProducer->setDequeueTimeout(std::numeric_limits<int64_t>::max());
213
liulijuneb489f62022-10-17 22:02:14 +0800214 static std::atomic<uint32_t> nextId = 0;
215 mProducerId = nextId++;
216 mName = name + "#" + std::to_string(mProducerId);
217 auto consumerName = mName + "(BLAST Consumer)" + std::to_string(mProducerId);
218 mQueuedBufferTrace = "QueuedBuffer - " + mName + "BLAST#" + std::to_string(mProducerId);
Vishnu Nairdab94092020-09-29 16:09:04 -0700219 mBufferItemConsumer->setName(String8(consumerName.c_str()));
Robert Carr78c25dd2019-08-15 14:10:33 -0700220 mBufferItemConsumer->setFrameAvailableListener(this);
Robert Carr9f133d72020-04-01 15:51:46 -0700221
Huihong Luo02186fb2022-02-23 14:21:54 -0800222 ComposerServiceAIDL::getComposerService()->getMaxAcquiredBufferCount(&mMaxAcquiredBuffers);
Ady Abraham0bde6b52021-05-18 13:57:02 -0700223 mBufferItemConsumer->setMaxAcquiredBufferCount(mMaxAcquiredBuffers);
chaviw69058fb2021-09-27 09:37:30 -0500224 mCurrentMaxAcquiredBufferCount = mMaxAcquiredBuffers;
Valerie Haua32c5522019-12-09 10:11:08 -0800225 mNumAcquired = 0;
226 mNumFrameAvailable = 0;
Robert Carr4c1b6462021-12-21 10:30:50 -0800227
228 TransactionCompletedListener::getInstance()->addQueueStallListener(
Patrick Williamsf1e5df12022-10-17 21:37:42 +0000229 [&](const std::string& reason) {
230 std::function<void(const std::string&)> callbackCopy;
231 {
232 std::unique_lock _lock{mMutex};
233 callbackCopy = mTransactionHangCallback;
234 }
235 if (callbackCopy) callbackCopy(reason);
236 },
237 this);
Robert Carr4c1b6462021-12-21 10:30:50 -0800238
Patrick Williams7c9fa272024-08-30 12:38:43 +0000239#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BUFFER_RELEASE_CHANNEL)
Patrick Williams078d7362024-08-27 10:20:39 -0500240 gui::BufferReleaseChannel::open(mName, mBufferReleaseConsumer, mBufferReleaseProducer);
241 mBufferReleaseReader.emplace(*this);
Patrick Williams7c9fa272024-08-30 12:38:43 +0000242#endif
243
Vishnu Nair1e8bf102021-12-28 14:36:59 -0800244 BQA_LOGV("BLASTBufferQueue created");
Vishnu Nair1cb8e892021-12-06 16:45:48 -0800245}
246
247BLASTBufferQueue::BLASTBufferQueue(const std::string& name, const sp<SurfaceControl>& surface,
248 int width, int height, int32_t format)
249 : BLASTBufferQueue(name) {
250 update(surface, width, height, format);
Robert Carr78c25dd2019-08-15 14:10:33 -0700251}
252
Vishnu Nairc4a40c12020-12-23 09:14:32 -0800253BLASTBufferQueue::~BLASTBufferQueue() {
Robert Carr4c1b6462021-12-21 10:30:50 -0800254 TransactionCompletedListener::getInstance()->removeQueueStallListener(this);
Vishnu Nairc4a40c12020-12-23 09:14:32 -0800255 if (mPendingTransactions.empty()) {
256 return;
257 }
258 BQA_LOGE("Applying pending transactions on dtor %d",
259 static_cast<uint32_t>(mPendingTransactions.size()));
260 SurfaceComposerClient::Transaction t;
Vishnu Nair1e8bf102021-12-28 14:36:59 -0800261 mergePendingTransactions(&t, std::numeric_limits<uint64_t>::max() /* frameNumber */);
Robert Carr79dc06a2022-02-22 15:28:59 -0800262 // All transactions on our apply token are one-way. See comment on mAppliedLastTransaction
263 t.setApplyToken(mApplyToken).apply(false, true);
chaviw3b4bdcf2022-03-17 09:27:03 -0500264
265 if (mTransactionReadyCallback) {
266 mTransactionReadyCallback(mSyncTransaction);
267 }
Vishnu Nairc4a40c12020-12-23 09:14:32 -0800268}
269
Patrick Williamsf5b42de2024-08-01 16:08:51 -0500270void BLASTBufferQueue::onFirstRef() {
271 // safe default, most producers are expected to override this
272 mProducer->setMaxDequeuedBufferCount(2);
273}
274
chaviw565ee542021-01-14 10:21:23 -0800275void BLASTBufferQueue::update(const sp<SurfaceControl>& surface, uint32_t width, uint32_t height,
Vishnu Naird2aaab12022-02-10 14:49:09 -0800276 int32_t format) {
Vishnu Nair1e8bf102021-12-28 14:36:59 -0800277 LOG_ALWAYS_FATAL_IF(surface == nullptr, "BLASTBufferQueue: mSurfaceControl must not be NULL");
278
Chavi Weingartene0237bb2023-02-06 21:48:32 +0000279 std::lock_guard _lock{mMutex};
chaviw565ee542021-01-14 10:21:23 -0800280 if (mFormat != format) {
281 mFormat = format;
chaviw497e81c2021-02-04 17:09:47 -0800282 mBufferItemConsumer->setDefaultBufferFormat(convertBufferFormat(format));
chaviw565ee542021-01-14 10:21:23 -0800283 }
284
Vishnu Nair1e8bf102021-12-28 14:36:59 -0800285 const bool surfaceControlChanged = !SurfaceControl::isSameSurface(mSurfaceControl, surface);
Vishnu Nairab066512022-01-04 22:28:00 +0000286 if (surfaceControlChanged && mSurfaceControl != nullptr) {
287 BQA_LOGD("Updating SurfaceControl without recreating BBQ");
288 }
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800289 bool applyTransaction = false;
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800290
Vishnu Nair5fa91c22021-06-29 14:30:48 -0700291 // Always update the native object even though they might have the same layer handle, so we can
292 // get the updated transform hint from WM.
293 mSurfaceControl = surface;
Vishnu Naird2aaab12022-02-10 14:49:09 -0800294 SurfaceComposerClient::Transaction t;
Vishnu Nair1e8bf102021-12-28 14:36:59 -0800295 if (surfaceControlChanged) {
Patrick Williamsc16a4a52024-10-26 01:48:01 -0500296#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BUFFER_RELEASE_CHANNEL)
Patrick Williamsa419faa2024-10-29 16:50:27 -0500297 updateBufferReleaseProducer();
Patrick Williamsc16a4a52024-10-26 01:48:01 -0500298#endif
Vishnu Nair1e8bf102021-12-28 14:36:59 -0800299 t.setFlags(mSurfaceControl, layer_state_t::eEnableBackpressure,
300 layer_state_t::eEnableBackpressure);
301 applyTransaction = true;
Arthur Hungb6aa9a02021-06-09 14:23:01 +0800302 }
Vishnu Nair1e8bf102021-12-28 14:36:59 -0800303 mTransformHint = mSurfaceControl->getTransformHint();
304 mBufferItemConsumer->setTransformHint(mTransformHint);
Vishnu Naira4fbca52021-07-07 16:52:34 -0700305 BQA_LOGV("update width=%d height=%d format=%d mTransformHint=%d", width, height, format,
306 mTransformHint);
Arthur Hungb6aa9a02021-06-09 14:23:01 +0800307
Vishnu Nairea0de002020-11-17 17:42:37 -0800308 ui::Size newSize(width, height);
309 if (mRequestedSize != newSize) {
310 mRequestedSize.set(newSize);
311 mBufferItemConsumer->setDefaultBufferSize(mRequestedSize.width, mRequestedSize.height);
Chavi Weingartena5aedbd2021-04-09 13:37:33 +0000312 if (mLastBufferInfo.scalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE) {
Vishnu Nair53c936c2020-12-03 11:46:37 -0800313 // If the buffer supports scaling, update the frame immediately since the client may
314 // want to scale the existing buffer to the new size.
315 mSize = mRequestedSize;
Vishnu Naird2aaab12022-02-10 14:49:09 -0800316 if (mUpdateDestinationFrame) {
317 t.setDestinationFrame(mSurfaceControl, Rect(newSize));
318 applyTransaction = true;
319 }
Vishnu Nair53c936c2020-12-03 11:46:37 -0800320 }
Robert Carrfc416512020-04-02 12:32:44 -0700321 }
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800322 if (applyTransaction) {
Robert Carr79dc06a2022-02-22 15:28:59 -0800323 // All transactions on our apply token are one-way. See comment on mAppliedLastTransaction
Patrick Williamsc16a4a52024-10-26 01:48:01 -0500324 t.setApplyToken(mApplyToken).apply(false /* synchronous */, true /* oneWay */);
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800325 }
Robert Carr78c25dd2019-08-15 14:10:33 -0700326}
327
chaviwd7deef72021-10-06 11:53:40 -0500328static std::optional<SurfaceControlStats> findMatchingStat(
329 const std::vector<SurfaceControlStats>& stats, const sp<SurfaceControl>& sc) {
330 for (auto stat : stats) {
331 if (SurfaceControl::isSameSurface(sc, stat.surfaceControl)) {
332 return stat;
333 }
334 }
335 return std::nullopt;
336}
337
Patrick Williams5312ec12024-08-23 16:11:10 -0500338TransactionCompletedCallbackTakesContext BLASTBufferQueue::makeTransactionCommittedCallbackThunk() {
339 return [bbq = sp<BLASTBufferQueue>::fromExisting(
340 this)](void* /*context*/, nsecs_t latchTime, const sp<Fence>& presentFence,
341 const std::vector<SurfaceControlStats>& stats) {
342 bbq->transactionCommittedCallback(latchTime, presentFence, stats);
343 };
chaviwd7deef72021-10-06 11:53:40 -0500344}
345
346void BLASTBufferQueue::transactionCommittedCallback(nsecs_t /*latchTime*/,
347 const sp<Fence>& /*presentFence*/,
348 const std::vector<SurfaceControlStats>& stats) {
349 {
Chavi Weingartene0237bb2023-02-06 21:48:32 +0000350 std::lock_guard _lock{mMutex};
chaviw57ae4b22022-02-03 16:51:39 -0600351 BBQ_TRACE();
chaviwd7deef72021-10-06 11:53:40 -0500352 BQA_LOGV("transactionCommittedCallback");
353 if (!mSurfaceControlsWithPendingCallback.empty()) {
354 sp<SurfaceControl> pendingSC = mSurfaceControlsWithPendingCallback.front();
355 std::optional<SurfaceControlStats> stat = findMatchingStat(stats, pendingSC);
356 if (stat) {
357 uint64_t currFrameNumber = stat->frameEventStats.frameNumber;
358
359 // We need to check if we were waiting for a transaction callback in order to
360 // process any pending buffers and unblock. It's possible to get transaction
chaviwc1cf4022022-06-03 13:32:33 -0500361 // callbacks for previous requests so we need to ensure that there are no pending
362 // frame numbers that were in a sync. We remove the frame from mSyncedFrameNumbers
363 // set and then check if it's empty. If there are no more pending syncs, we can
364 // proceed with flushing the shadow queue.
chaviwc1cf4022022-06-03 13:32:33 -0500365 mSyncedFrameNumbers.erase(currFrameNumber);
Chavi Weingartend48797b2023-08-04 13:11:39 +0000366 if (mSyncedFrameNumbers.empty()) {
chaviwd7deef72021-10-06 11:53:40 -0500367 flushShadowQueue();
368 }
369 } else {
chaviw768bfa02021-11-01 09:50:57 -0500370 BQA_LOGE("Failed to find matching SurfaceControl in transactionCommittedCallback");
chaviwd7deef72021-10-06 11:53:40 -0500371 }
372 } else {
373 BQA_LOGE("No matching SurfaceControls found: mSurfaceControlsWithPendingCallback was "
374 "empty.");
375 }
chaviwd7deef72021-10-06 11:53:40 -0500376 }
377}
378
Patrick Williams5312ec12024-08-23 16:11:10 -0500379TransactionCompletedCallbackTakesContext BLASTBufferQueue::makeTransactionCallbackThunk() {
380 return [bbq = sp<BLASTBufferQueue>::fromExisting(
381 this)](void* /*context*/, nsecs_t latchTime, const sp<Fence>& presentFence,
382 const std::vector<SurfaceControlStats>& stats) {
383 bbq->transactionCallback(latchTime, presentFence, stats);
384 };
Robert Carr78c25dd2019-08-15 14:10:33 -0700385}
386
387void BLASTBufferQueue::transactionCallback(nsecs_t /*latchTime*/, const sp<Fence>& /*presentFence*/,
388 const std::vector<SurfaceControlStats>& stats) {
chaviw71c2cc42020-10-23 16:42:02 -0700389 {
Chavi Weingartene0237bb2023-02-06 21:48:32 +0000390 std::lock_guard _lock{mMutex};
chaviw57ae4b22022-02-03 16:51:39 -0600391 BBQ_TRACE();
chaviw71c2cc42020-10-23 16:42:02 -0700392 BQA_LOGV("transactionCallback");
chaviw71c2cc42020-10-23 16:42:02 -0700393
chaviw42026162021-04-16 15:46:12 -0500394 if (!mSurfaceControlsWithPendingCallback.empty()) {
395 sp<SurfaceControl> pendingSC = mSurfaceControlsWithPendingCallback.front();
396 mSurfaceControlsWithPendingCallback.pop();
chaviwd7deef72021-10-06 11:53:40 -0500397 std::optional<SurfaceControlStats> statsOptional = findMatchingStat(stats, pendingSC);
398 if (statsOptional) {
399 SurfaceControlStats stat = *statsOptional;
Vishnu Nair71fcf912022-10-18 09:14:20 -0700400 if (stat.transformHint) {
401 mTransformHint = *stat.transformHint;
402 mBufferItemConsumer->setTransformHint(mTransformHint);
403 BQA_LOGV("updated mTransformHint=%d", mTransformHint);
404 }
Vishnu Nairde66dc72021-06-17 17:54:41 -0700405 // Update frametime stamps if the frame was latched and presented, indicated by a
406 // valid latch time.
407 if (stat.latchTime > 0) {
408 mBufferItemConsumer
409 ->updateFrameTimestamps(stat.frameEventStats.frameNumber,
Alec Mouri21d94322023-10-17 19:51:39 +0000410 stat.frameEventStats.previousFrameNumber,
Vishnu Nairde66dc72021-06-17 17:54:41 -0700411 stat.frameEventStats.refreshStartTime,
412 stat.frameEventStats.gpuCompositionDoneFence,
413 stat.presentFence, stat.previousReleaseFence,
414 stat.frameEventStats.compositorTiming,
415 stat.latchTime,
416 stat.frameEventStats.dequeueReadyTime);
417 }
Robert Carr405e2f62021-12-31 16:59:34 -0800418 auto currFrameNumber = stat.frameEventStats.frameNumber;
419 std::vector<ReleaseCallbackId> staleReleases;
420 for (const auto& [key, value]: mSubmitted) {
421 if (currFrameNumber > key.framenumber) {
422 staleReleases.push_back(key);
423 }
424 }
425 for (const auto& staleRelease : staleReleases) {
Robert Carr405e2f62021-12-31 16:59:34 -0800426 releaseBufferCallbackLocked(staleRelease,
Vishnu Nair28fe2e62022-11-01 14:29:10 -0700427 stat.previousReleaseFence
428 ? stat.previousReleaseFence
429 : Fence::NO_FENCE,
430 stat.currentMaxAcquiredBufferCount,
431 true /* fakeRelease */);
Robert Carr405e2f62021-12-31 16:59:34 -0800432 }
chaviwd7deef72021-10-06 11:53:40 -0500433 } else {
chaviw768bfa02021-11-01 09:50:57 -0500434 BQA_LOGE("Failed to find matching SurfaceControl in transactionCallback");
chaviw42026162021-04-16 15:46:12 -0500435 }
436 } else {
437 BQA_LOGE("No matching SurfaceControls found: mSurfaceControlsWithPendingCallback was "
438 "empty.");
Valerie Haua32c5522019-12-09 10:11:08 -0800439 }
Robert Carr78c25dd2019-08-15 14:10:33 -0700440 }
Robert Carr78c25dd2019-08-15 14:10:33 -0700441}
442
Patrick Williams7c9fa272024-08-30 12:38:43 +0000443void BLASTBufferQueue::flushShadowQueue() {
444 BQA_LOGV("flushShadowQueue");
445 int numFramesToFlush = mNumFrameAvailable;
446 while (numFramesToFlush > 0) {
447 acquireNextBufferLocked(std::nullopt);
448 numFramesToFlush--;
449 }
450}
451
Vishnu Nair1506b182021-02-22 14:35:15 -0800452// Unlike transactionCallbackThunk the release buffer callback does not extend the life of the
453// BBQ. This is because if the BBQ is destroyed, then the buffers will be released by the client.
454// So we pass in a weak pointer to the BBQ and if it still alive, then we release the buffer.
455// Otherwise, this is a no-op.
Patrick Williams5312ec12024-08-23 16:11:10 -0500456ReleaseBufferCallback BLASTBufferQueue::makeReleaseBufferCallbackThunk() {
457 return [weakBbq = wp<BLASTBufferQueue>::fromExisting(
458 this)](const ReleaseCallbackId& id, const sp<Fence>& releaseFence,
459 std::optional<uint32_t> currentMaxAcquiredBufferCount) {
460 sp<BLASTBufferQueue> bbq = weakBbq.promote();
461 if (!bbq) {
462 ALOGV("releaseBufferCallbackThunk %s blastBufferQueue is dead", id.to_string().c_str());
463 return;
464 }
465 bbq->releaseBufferCallback(id, releaseFence, currentMaxAcquiredBufferCount);
Patrick Williamsc16a4a52024-10-26 01:48:01 -0500466#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BUFFER_RELEASE_CHANNEL)
467 bbq->drainBufferReleaseConsumer();
468#endif
Patrick Williams5312ec12024-08-23 16:11:10 -0500469 };
Vishnu Nair1506b182021-02-22 14:35:15 -0800470}
471
chaviw69058fb2021-09-27 09:37:30 -0500472void BLASTBufferQueue::releaseBufferCallback(
473 const ReleaseCallbackId& id, const sp<Fence>& releaseFence,
474 std::optional<uint32_t> currentMaxAcquiredBufferCount) {
Chavi Weingartene0237bb2023-02-06 21:48:32 +0000475 std::lock_guard _lock{mMutex};
chaviw57ae4b22022-02-03 16:51:39 -0600476 BBQ_TRACE();
Vishnu Nair28fe2e62022-11-01 14:29:10 -0700477 releaseBufferCallbackLocked(id, releaseFence, currentMaxAcquiredBufferCount,
478 false /* fakeRelease */);
Robert Carr405e2f62021-12-31 16:59:34 -0800479}
480
Vishnu Nair28fe2e62022-11-01 14:29:10 -0700481void BLASTBufferQueue::releaseBufferCallbackLocked(
482 const ReleaseCallbackId& id, const sp<Fence>& releaseFence,
483 std::optional<uint32_t> currentMaxAcquiredBufferCount, bool fakeRelease) {
Robert Carr405e2f62021-12-31 16:59:34 -0800484 ATRACE_CALL();
Vishnu Nair4ba0c2e2021-06-24 11:27:17 -0700485 BQA_LOGV("releaseBufferCallback %s", id.to_string().c_str());
Vishnu Nair1506b182021-02-22 14:35:15 -0800486
Ady Abraham899dcdb2021-06-15 16:56:21 -0700487 // Calculate how many buffers we need to hold before we release them back
488 // to the buffer queue. This will prevent higher latency when we are running
489 // on a lower refresh rate than the max supported. We only do that for EGL
490 // clients as others don't care about latency
Chavi Weingartene0237bb2023-02-06 21:48:32 +0000491 const auto it = mSubmitted.find(id);
492 const bool isEGL = it != mSubmitted.end() && it->second.mApi == NATIVE_WINDOW_API_EGL;
Ady Abraham899dcdb2021-06-15 16:56:21 -0700493
chaviw69058fb2021-09-27 09:37:30 -0500494 if (currentMaxAcquiredBufferCount) {
495 mCurrentMaxAcquiredBufferCount = *currentMaxAcquiredBufferCount;
496 }
497
liulijunf90df632022-11-14 14:24:48 +0800498 const uint32_t numPendingBuffersToHold =
499 isEGL ? std::max(0, mMaxAcquiredBuffers - (int32_t)mCurrentMaxAcquiredBufferCount) : 0;
Robert Carr405e2f62021-12-31 16:59:34 -0800500
501 auto rb = ReleasedBuffer{id, releaseFence};
502 if (std::find(mPendingRelease.begin(), mPendingRelease.end(), rb) == mPendingRelease.end()) {
503 mPendingRelease.emplace_back(rb);
Vishnu Nair28fe2e62022-11-01 14:29:10 -0700504 if (fakeRelease) {
505 BQA_LOGE("Faking releaseBufferCallback from transactionCompleteCallback %" PRIu64,
506 id.framenumber);
507 BBQ_TRACE("FakeReleaseCallback");
508 }
Robert Carr405e2f62021-12-31 16:59:34 -0800509 }
Ady Abraham899dcdb2021-06-15 16:56:21 -0700510
511 // Release all buffers that are beyond the ones that we need to hold
512 while (mPendingRelease.size() > numPendingBuffersToHold) {
chaviw0acd33a2021-11-02 11:55:37 -0500513 const auto releasedBuffer = mPendingRelease.front();
Ady Abraham899dcdb2021-06-15 16:56:21 -0700514 mPendingRelease.pop_front();
chaviw0acd33a2021-11-02 11:55:37 -0500515 releaseBuffer(releasedBuffer.callbackId, releasedBuffer.releaseFence);
chaviwc1cf4022022-06-03 13:32:33 -0500516 // Don't process the transactions here if mSyncedFrameNumbers is not empty. That means
517 // are still transactions that have sync buffers in them that have not been applied or
518 // dropped. Instead, let onFrameAvailable handle processing them since it will merge with
519 // the syncTransaction.
520 if (mSyncedFrameNumbers.empty()) {
chaviwd7deef72021-10-06 11:53:40 -0500521 acquireNextBufferLocked(std::nullopt);
522 }
Vishnu Nair1506b182021-02-22 14:35:15 -0800523 }
524
Ady Abraham899dcdb2021-06-15 16:56:21 -0700525 ATRACE_INT("PendingRelease", mPendingRelease.size());
Vishnu Nair2a52ca62021-06-24 13:08:53 -0700526 ATRACE_INT(mQueuedBufferTrace.c_str(),
527 mNumFrameAvailable + mNumAcquired - mPendingRelease.size());
Vishnu Nair1506b182021-02-22 14:35:15 -0800528 mCallbackCV.notify_all();
529}
530
chaviw0acd33a2021-11-02 11:55:37 -0500531void BLASTBufferQueue::releaseBuffer(const ReleaseCallbackId& callbackId,
532 const sp<Fence>& releaseFence) {
533 auto it = mSubmitted.find(callbackId);
534 if (it == mSubmitted.end()) {
chaviw0acd33a2021-11-02 11:55:37 -0500535 return;
536 }
537 mNumAcquired--;
chaviw57ae4b22022-02-03 16:51:39 -0600538 BBQ_TRACE("frame=%" PRIu64, callbackId.framenumber);
chaviw0acd33a2021-11-02 11:55:37 -0500539 BQA_LOGV("released %s", callbackId.to_string().c_str());
540 mBufferItemConsumer->releaseBuffer(it->second, releaseFence);
541 mSubmitted.erase(it);
chaviwc1cf4022022-06-03 13:32:33 -0500542 // Remove the frame number from mSyncedFrameNumbers since we can get a release callback
543 // without getting a transaction committed if the buffer was dropped.
544 mSyncedFrameNumbers.erase(callbackId.framenumber);
chaviw0acd33a2021-11-02 11:55:37 -0500545}
546
Chavi Weingarten70670e62023-02-22 17:36:40 +0000547static ui::Size getBufferSize(const BufferItem& item) {
548 uint32_t bufWidth = item.mGraphicBuffer->getWidth();
549 uint32_t bufHeight = item.mGraphicBuffer->getHeight();
550
551 // Take the buffer's orientation into account
552 if (item.mTransform & ui::Transform::ROT_90) {
553 std::swap(bufWidth, bufHeight);
554 }
555 return ui::Size(bufWidth, bufHeight);
556}
557
Chavi Weingarten3a8f19b2022-12-27 22:00:24 +0000558status_t BLASTBufferQueue::acquireNextBufferLocked(
chaviwd7deef72021-10-06 11:53:40 -0500559 const std::optional<SurfaceComposerClient::Transaction*> transaction) {
Vishnu Nairb4b484a2023-01-20 10:00:18 -0800560 // Check if we have frames available and we have not acquired the maximum number of buffers.
561 // Even with this check, the consumer can fail to acquire an additional buffer if the consumer
562 // has already acquired (mMaxAcquiredBuffers + 1) and the new buffer is not droppable. In this
563 // case mBufferItemConsumer->acquireBuffer will return with NO_BUFFER_AVAILABLE.
Chavi Weingarten3a8f19b2022-12-27 22:00:24 +0000564 if (mNumFrameAvailable == 0) {
Vishnu Nairb4b484a2023-01-20 10:00:18 -0800565 BQA_LOGV("Can't acquire next buffer. No available frames");
566 return BufferQueue::NO_BUFFER_AVAILABLE;
567 }
568
569 if (mNumAcquired >= (mMaxAcquiredBuffers + 2)) {
570 BQA_LOGV("Can't acquire next buffer. Already acquired max frames %d max:%d + 2",
571 mNumAcquired, mMaxAcquiredBuffers);
572 return BufferQueue::NO_BUFFER_AVAILABLE;
Valerie Haud3b90d22019-11-06 09:37:31 -0800573 }
574
Valerie Haua32c5522019-12-09 10:11:08 -0800575 if (mSurfaceControl == nullptr) {
Vishnu Nair670b3f72020-09-29 17:52:18 -0700576 BQA_LOGE("ERROR : surface control is null");
Chavi Weingarten3a8f19b2022-12-27 22:00:24 +0000577 return NAME_NOT_FOUND;
Valerie Haud3b90d22019-11-06 09:37:31 -0800578 }
579
Robert Carr78c25dd2019-08-15 14:10:33 -0700580 SurfaceComposerClient::Transaction localTransaction;
581 bool applyTransaction = true;
582 SurfaceComposerClient::Transaction* t = &localTransaction;
chaviwd7deef72021-10-06 11:53:40 -0500583 if (transaction) {
584 t = *transaction;
Robert Carr78c25dd2019-08-15 14:10:33 -0700585 applyTransaction = false;
586 }
587
Patrick Williams3ced5382024-08-21 15:39:32 -0500588 BufferItem bufferItem;
Valerie Haud3b90d22019-11-06 09:37:31 -0800589
Vishnu Nairc6f89ee2020-12-11 14:27:32 -0800590 status_t status =
591 mBufferItemConsumer->acquireBuffer(&bufferItem, 0 /* expectedPresent */, false);
Vishnu Nair8b30dd12021-01-25 14:16:54 -0800592 if (status == BufferQueue::NO_BUFFER_AVAILABLE) {
593 BQA_LOGV("Failed to acquire a buffer, err=NO_BUFFER_AVAILABLE");
Chavi Weingarten3a8f19b2022-12-27 22:00:24 +0000594 return status;
Vishnu Nair8b30dd12021-01-25 14:16:54 -0800595 } else if (status != OK) {
Vishnu Nairbf255772020-10-16 10:54:41 -0700596 BQA_LOGE("Failed to acquire a buffer, err=%s", statusToString(status).c_str());
Chavi Weingarten3a8f19b2022-12-27 22:00:24 +0000597 return status;
Robert Carr78c25dd2019-08-15 14:10:33 -0700598 }
chaviw57ae4b22022-02-03 16:51:39 -0600599
Valerie Haua32c5522019-12-09 10:11:08 -0800600 auto buffer = bufferItem.mGraphicBuffer;
601 mNumFrameAvailable--;
chaviw57ae4b22022-02-03 16:51:39 -0600602 BBQ_TRACE("frame=%" PRIu64, bufferItem.mFrameNumber);
Valerie Haua32c5522019-12-09 10:11:08 -0800603
604 if (buffer == nullptr) {
605 mBufferItemConsumer->releaseBuffer(bufferItem, Fence::NO_FENCE);
Vishnu Nairbf255772020-10-16 10:54:41 -0700606 BQA_LOGE("Buffer was empty");
Chavi Weingarten3a8f19b2022-12-27 22:00:24 +0000607 return BAD_VALUE;
Valerie Haua32c5522019-12-09 10:11:08 -0800608 }
609
Vishnu Nair670b3f72020-09-29 17:52:18 -0700610 if (rejectBuffer(bufferItem)) {
Vishnu Naira4fbca52021-07-07 16:52:34 -0700611 BQA_LOGE("rejecting buffer:active_size=%dx%d, requested_size=%dx%d "
Vishnu Nairea0de002020-11-17 17:42:37 -0800612 "buffer{size=%dx%d transform=%d}",
613 mSize.width, mSize.height, mRequestedSize.width, mRequestedSize.height,
614 buffer->getWidth(), buffer->getHeight(), bufferItem.mTransform);
615 mBufferItemConsumer->releaseBuffer(bufferItem, Fence::NO_FENCE);
Chavi Weingarten3a8f19b2022-12-27 22:00:24 +0000616 return acquireNextBufferLocked(transaction);
Vishnu Nair670b3f72020-09-29 17:52:18 -0700617 }
618
Valerie Haua32c5522019-12-09 10:11:08 -0800619 mNumAcquired++;
Vishnu Nair4ba0c2e2021-06-24 11:27:17 -0700620 mLastAcquiredFrameNumber = bufferItem.mFrameNumber;
621 ReleaseCallbackId releaseCallbackId(buffer->getId(), mLastAcquiredFrameNumber);
622 mSubmitted[releaseCallbackId] = bufferItem;
Robert Carr78c25dd2019-08-15 14:10:33 -0700623
Valerie Hau871d6352020-01-29 08:44:02 -0800624 bool needsDisconnect = false;
625 mBufferItemConsumer->getConnectionEvents(bufferItem.mFrameNumber, &needsDisconnect);
626
627 // if producer disconnected before, notify SurfaceFlinger
628 if (needsDisconnect) {
629 t->notifyProducerDisconnect(mSurfaceControl);
630 }
631
Chavi Weingarten70670e62023-02-22 17:36:40 +0000632 // Only update mSize for destination bounds if the incoming buffer matches the requested size.
633 // Otherwise, it could cause stretching since the destination bounds will update before the
634 // buffer with the new size is acquired.
Vishnu Nair5b5f6932023-04-12 16:28:19 -0700635 if (mRequestedSize == getBufferSize(bufferItem) ||
636 bufferItem.mScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE) {
Chavi Weingarten70670e62023-02-22 17:36:40 +0000637 mSize = mRequestedSize;
638 }
Vishnu Nair5cc9ac02021-04-19 13:23:38 -0700639 Rect crop = computeCrop(bufferItem);
Chavi Weingartena5aedbd2021-04-09 13:37:33 +0000640 mLastBufferInfo.update(true /* hasBuffer */, bufferItem.mGraphicBuffer->getWidth(),
641 bufferItem.mGraphicBuffer->getHeight(), bufferItem.mTransform,
Vishnu Nair5cc9ac02021-04-19 13:23:38 -0700642 bufferItem.mScalingMode, crop);
Vishnu Nair53c936c2020-12-03 11:46:37 -0800643
Patrick Williams5312ec12024-08-23 16:11:10 -0500644 auto releaseBufferCallback = makeReleaseBufferCallbackThunk();
chaviwba4320c2021-09-15 15:20:53 -0500645 sp<Fence> fence = bufferItem.mFence ? new Fence(bufferItem.mFence->dup()) : Fence::NO_FENCE;
Nergi Rahardi39f510f2024-05-23 15:16:54 +0900646
647 nsecs_t dequeueTime = -1;
648 {
649 std::lock_guard _lock{mTimestampMutex};
650 auto dequeueTimeIt = mDequeueTimestamps.find(buffer->getId());
651 if (dequeueTimeIt != mDequeueTimestamps.end()) {
652 dequeueTime = dequeueTimeIt->second;
653 mDequeueTimestamps.erase(dequeueTimeIt);
654 }
655 }
656
liulijuneb489f62022-10-17 22:02:14 +0800657 t->setBuffer(mSurfaceControl, buffer, fence, bufferItem.mFrameNumber, mProducerId,
Nergi Rahardi39f510f2024-05-23 15:16:54 +0900658 releaseBufferCallback, dequeueTime);
John Reck137069e2020-12-10 22:07:37 -0500659 t->setDataspace(mSurfaceControl, static_cast<ui::Dataspace>(bufferItem.mDataSpace));
660 t->setHdrMetadata(mSurfaceControl, bufferItem.mHdrMetadata);
661 t->setSurfaceDamageRegion(mSurfaceControl, bufferItem.mSurfaceDamage);
Patrick Williams5312ec12024-08-23 16:11:10 -0500662 t->addTransactionCompletedCallback(makeTransactionCallbackThunk(), nullptr);
chaviwf2dace72021-11-17 17:36:50 -0600663
chaviw42026162021-04-16 15:46:12 -0500664 mSurfaceControlsWithPendingCallback.push(mSurfaceControl);
Robert Carr78c25dd2019-08-15 14:10:33 -0700665
Vishnu Naird2aaab12022-02-10 14:49:09 -0800666 if (mUpdateDestinationFrame) {
667 t->setDestinationFrame(mSurfaceControl, Rect(mSize));
668 } else {
669 const bool ignoreDestinationFrame =
670 bufferItem.mScalingMode == NATIVE_WINDOW_SCALING_MODE_FREEZE;
671 t->setFlags(mSurfaceControl,
672 ignoreDestinationFrame ? layer_state_t::eIgnoreDestinationFrame : 0,
673 layer_state_t::eIgnoreDestinationFrame);
Vishnu Nair084514a2021-07-30 16:07:42 -0700674 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700675 t->setBufferCrop(mSurfaceControl, crop);
Valerie Haua32c5522019-12-09 10:11:08 -0800676 t->setTransform(mSurfaceControl, bufferItem.mTransform);
Valerie Hau2882e982020-01-23 13:33:10 -0800677 t->setTransformToDisplayInverse(mSurfaceControl, bufferItem.mTransformToDisplayInverse);
Vishnu Naird2aaab12022-02-10 14:49:09 -0800678 t->setAutoRefresh(mSurfaceControl, bufferItem.mAutoRefresh);
Ady Abrahamf0c56492020-12-17 18:04:15 -0800679 if (!bufferItem.mIsAutoTimestamp) {
680 t->setDesiredPresentTime(bufferItem.mTimestamp);
681 }
Robert Carr78c25dd2019-08-15 14:10:33 -0700682
Ady Abrahamd6e409e2023-01-19 16:07:31 -0800683 // Drop stale frame timeline infos
684 while (!mPendingFrameTimelines.empty() &&
685 mPendingFrameTimelines.front().first < bufferItem.mFrameNumber) {
686 ATRACE_FORMAT_INSTANT("dropping stale frameNumber: %" PRIu64 " vsyncId: %" PRId64,
687 mPendingFrameTimelines.front().first,
688 mPendingFrameTimelines.front().second.vsyncId);
689 mPendingFrameTimelines.pop();
690 }
691
692 if (!mPendingFrameTimelines.empty() &&
693 mPendingFrameTimelines.front().first == bufferItem.mFrameNumber) {
694 ATRACE_FORMAT_INSTANT("Transaction::setFrameTimelineInfo frameNumber: %" PRIu64
695 " vsyncId: %" PRId64,
696 bufferItem.mFrameNumber,
697 mPendingFrameTimelines.front().second.vsyncId);
698 t->setFrameTimelineInfo(mPendingFrameTimelines.front().second);
699 mPendingFrameTimelines.pop();
Jorim Jaggia3fe67b2020-12-01 00:24:33 +0100700 }
701
chaviw6a195272021-09-03 16:14:25 -0500702 mergePendingTransactions(t, bufferItem.mFrameNumber);
Robert Carr78c25dd2019-08-15 14:10:33 -0700703 if (applyTransaction) {
Robert Carr79dc06a2022-02-22 15:28:59 -0800704 // All transactions on our apply token are one-way. See comment on mAppliedLastTransaction
705 t->setApplyToken(mApplyToken).apply(false, true);
706 mAppliedLastTransaction = true;
707 mLastAppliedFrameNumber = bufferItem.mFrameNumber;
708 } else {
709 t->setBufferHasBarrier(mSurfaceControl, mLastAppliedFrameNumber);
710 mAppliedLastTransaction = false;
Robert Carr78c25dd2019-08-15 14:10:33 -0700711 }
Vishnu Nairdab94092020-09-29 16:09:04 -0700712
chaviwd7deef72021-10-06 11:53:40 -0500713 BQA_LOGV("acquireNextBufferLocked size=%dx%d mFrameNumber=%" PRIu64
Vishnu Nair1506b182021-02-22 14:35:15 -0800714 " applyTransaction=%s mTimestamp=%" PRId64 "%s mPendingTransactions.size=%d"
Vishnu Naira4fbca52021-07-07 16:52:34 -0700715 " graphicBufferId=%" PRIu64 "%s transform=%d",
chaviw3277faf2021-05-19 16:45:23 -0500716 mSize.width, mSize.height, bufferItem.mFrameNumber, boolToString(applyTransaction),
Vishnu Nair1506b182021-02-22 14:35:15 -0800717 bufferItem.mTimestamp, bufferItem.mIsAutoTimestamp ? "(auto)" : "",
Vishnu Nair4ba0c2e2021-06-24 11:27:17 -0700718 static_cast<uint32_t>(mPendingTransactions.size()), bufferItem.mGraphicBuffer->getId(),
Vishnu Naira4fbca52021-07-07 16:52:34 -0700719 bufferItem.mAutoRefresh ? " mAutoRefresh" : "", bufferItem.mTransform);
Chavi Weingarten3a8f19b2022-12-27 22:00:24 +0000720 return OK;
Robert Carr78c25dd2019-08-15 14:10:33 -0700721}
722
Valerie Hau45e4b3b2019-12-03 10:49:17 -0800723Rect BLASTBufferQueue::computeCrop(const BufferItem& item) {
724 if (item.mScalingMode == NATIVE_WINDOW_SCALING_MODE_SCALE_CROP) {
Vishnu Nairea0de002020-11-17 17:42:37 -0800725 return GLConsumer::scaleDownCrop(item.mCrop, mSize.width, mSize.height);
Valerie Hau45e4b3b2019-12-03 10:49:17 -0800726 }
727 return item.mCrop;
728}
729
chaviwd7deef72021-10-06 11:53:40 -0500730void BLASTBufferQueue::acquireAndReleaseBuffer() {
Chavi Weingartend00e0f72022-07-14 15:59:20 +0000731 BBQ_TRACE();
chaviwd7deef72021-10-06 11:53:40 -0500732 BufferItem bufferItem;
chaviw6ebdf5f2021-10-14 11:57:22 -0500733 status_t status =
734 mBufferItemConsumer->acquireBuffer(&bufferItem, 0 /* expectedPresent */, false);
735 if (status != OK) {
736 BQA_LOGE("Failed to acquire a buffer in acquireAndReleaseBuffer, err=%s",
737 statusToString(status).c_str());
738 return;
739 }
chaviwd7deef72021-10-06 11:53:40 -0500740 mNumFrameAvailable--;
chaviw6ebdf5f2021-10-14 11:57:22 -0500741 mBufferItemConsumer->releaseBuffer(bufferItem, bufferItem.mFence);
chaviwd7deef72021-10-06 11:53:40 -0500742}
743
Vishnu Nairaef1de92020-10-22 12:15:53 -0700744void BLASTBufferQueue::onFrameAvailable(const BufferItem& item) {
Tianhao Yao4861b102022-02-03 20:18:35 +0000745 std::function<void(SurfaceComposerClient::Transaction*)> prevCallback = nullptr;
746 SurfaceComposerClient::Transaction* prevTransaction = nullptr;
chaviwc1cf4022022-06-03 13:32:33 -0500747
Tianhao Yao4861b102022-02-03 20:18:35 +0000748 {
Chavi Weingartene0237bb2023-02-06 21:48:32 +0000749 UNIQUE_LOCK_WITH_ASSERTION(mMutex);
Chavi Weingartend00e0f72022-07-14 15:59:20 +0000750 BBQ_TRACE();
Chavi Weingartene0237bb2023-02-06 21:48:32 +0000751 bool waitForTransactionCallback = !mSyncedFrameNumbers.empty();
Ady Abrahamd6e409e2023-01-19 16:07:31 -0800752
Tianhao Yao4861b102022-02-03 20:18:35 +0000753 const bool syncTransactionSet = mTransactionReadyCallback != nullptr;
754 BQA_LOGV("onFrameAvailable-start syncTransactionSet=%s", boolToString(syncTransactionSet));
Valerie Haud3b90d22019-11-06 09:37:31 -0800755
Tianhao Yao4861b102022-02-03 20:18:35 +0000756 if (syncTransactionSet) {
Tianhao Yao4861b102022-02-03 20:18:35 +0000757 // If we are going to re-use the same mSyncTransaction, release the buffer that may
758 // already be set in the Transaction. This is to allow us a free slot early to continue
759 // processing a new buffer.
760 if (!mAcquireSingleBuffer) {
761 auto bufferData = mSyncTransaction->getAndClearBuffer(mSurfaceControl);
762 if (bufferData) {
763 BQA_LOGD("Releasing previous buffer when syncing: framenumber=%" PRIu64,
764 bufferData->frameNumber);
765 releaseBuffer(bufferData->generateReleaseCallbackId(),
766 bufferData->acquireFence);
Tianhao Yao4861b102022-02-03 20:18:35 +0000767 }
768 }
chaviw0acd33a2021-11-02 11:55:37 -0500769
Chavi Weingarten3a8f19b2022-12-27 22:00:24 +0000770 if (waitForTransactionCallback) {
771 // We are waiting on a previous sync's transaction callback so allow another sync
772 // transaction to proceed.
773 //
774 // We need to first flush out the transactions that were in between the two syncs.
775 // We do this by merging them into mSyncTransaction so any buffer merging will get
776 // a release callback invoked.
777 while (mNumFrameAvailable > 0) {
778 // flush out the shadow queue
779 acquireAndReleaseBuffer();
780 }
Vishnu Nairb4b484a2023-01-20 10:00:18 -0800781 } else {
782 // Make sure the frame available count is 0 before proceeding with a sync to ensure
783 // the correct frame is used for the sync. The only way mNumFrameAvailable would be
784 // greater than 0 is if we already ran out of buffers previously. This means we
785 // need to flush the buffers before proceeding with the sync.
786 while (mNumFrameAvailable > 0) {
787 BQA_LOGD("waiting until no queued buffers");
788 mCallbackCV.wait(_lock);
789 }
chaviwd7deef72021-10-06 11:53:40 -0500790 }
791 }
792
Tianhao Yao4861b102022-02-03 20:18:35 +0000793 // add to shadow queue
794 mNumFrameAvailable++;
chaviwc1cf4022022-06-03 13:32:33 -0500795 if (waitForTransactionCallback && mNumFrameAvailable >= 2) {
Tianhao Yao4861b102022-02-03 20:18:35 +0000796 acquireAndReleaseBuffer();
797 }
798 ATRACE_INT(mQueuedBufferTrace.c_str(),
799 mNumFrameAvailable + mNumAcquired - mPendingRelease.size());
800
801 BQA_LOGV("onFrameAvailable framenumber=%" PRIu64 " syncTransactionSet=%s",
802 item.mFrameNumber, boolToString(syncTransactionSet));
803
804 if (syncTransactionSet) {
Vishnu Nairb4b484a2023-01-20 10:00:18 -0800805 // Add to mSyncedFrameNumbers before waiting in case any buffers are released
806 // while waiting for a free buffer. The release and commit callback will try to
807 // acquire buffers if there are any available, but we don't want it to acquire
808 // in the case where a sync transaction wants the buffer.
809 mSyncedFrameNumbers.emplace(item.mFrameNumber);
Chavi Weingarten3a8f19b2022-12-27 22:00:24 +0000810 // If there's no available buffer and we're in a sync transaction, we need to wait
811 // instead of returning since we guarantee a buffer will be acquired for the sync.
812 while (acquireNextBufferLocked(mSyncTransaction) == BufferQueue::NO_BUFFER_AVAILABLE) {
813 BQA_LOGD("waiting for available buffer");
814 mCallbackCV.wait(_lock);
815 }
Tianhao Yao4861b102022-02-03 20:18:35 +0000816
817 // Only need a commit callback when syncing to ensure the buffer that's synced has been
818 // sent to SF
Patrick Williams5312ec12024-08-23 16:11:10 -0500819 mSyncTransaction
820 ->addTransactionCommittedCallback(makeTransactionCommittedCallbackThunk(),
821 nullptr);
Tianhao Yao4861b102022-02-03 20:18:35 +0000822 if (mAcquireSingleBuffer) {
823 prevCallback = mTransactionReadyCallback;
824 prevTransaction = mSyncTransaction;
825 mTransactionReadyCallback = nullptr;
826 mSyncTransaction = nullptr;
827 }
chaviwc1cf4022022-06-03 13:32:33 -0500828 } else if (!waitForTransactionCallback) {
Tianhao Yao4861b102022-02-03 20:18:35 +0000829 acquireNextBufferLocked(std::nullopt);
Valerie Hau0188adf2020-02-13 08:29:20 -0800830 }
831 }
Tianhao Yao4861b102022-02-03 20:18:35 +0000832 if (prevCallback) {
833 prevCallback(prevTransaction);
chaviwd7deef72021-10-06 11:53:40 -0500834 }
Valerie Haud3b90d22019-11-06 09:37:31 -0800835}
836
Vishnu Nairaef1de92020-10-22 12:15:53 -0700837void BLASTBufferQueue::onFrameReplaced(const BufferItem& item) {
838 BQA_LOGV("onFrameReplaced framenumber=%" PRIu64, item.mFrameNumber);
839 // Do nothing since we are not storing unacquired buffer items locally.
840}
841
Vishnu Nairadf632b2021-01-07 14:05:08 -0800842void BLASTBufferQueue::onFrameDequeued(const uint64_t bufferId) {
Chavi Weingartene0237bb2023-02-06 21:48:32 +0000843 std::lock_guard _lock{mTimestampMutex};
Vishnu Nairadf632b2021-01-07 14:05:08 -0800844 mDequeueTimestamps[bufferId] = systemTime();
Patrick Williams4b9507d2024-07-25 09:55:52 -0500845};
Vishnu Nairadf632b2021-01-07 14:05:08 -0800846
847void BLASTBufferQueue::onFrameCancelled(const uint64_t bufferId) {
Patrick Williams3ced5382024-08-21 15:39:32 -0500848 std::lock_guard _lock{mTimestampMutex};
849 mDequeueTimestamps.erase(bufferId);
Patrick Williamsf5b42de2024-08-01 16:08:51 -0500850}
Vishnu Nairadf632b2021-01-07 14:05:08 -0800851
Chavi Weingartenc398c012023-04-12 17:26:02 +0000852bool BLASTBufferQueue::syncNextTransaction(
Tianhao Yao4861b102022-02-03 20:18:35 +0000853 std::function<void(SurfaceComposerClient::Transaction*)> callback,
854 bool acquireSingleBuffer) {
Chavi Weingartenc398c012023-04-12 17:26:02 +0000855 LOG_ALWAYS_FATAL_IF(!callback,
856 "BLASTBufferQueue: callback passed in to syncNextTransaction must not be "
857 "NULL");
chaviw3b4bdcf2022-03-17 09:27:03 -0500858
Chavi Weingartenc398c012023-04-12 17:26:02 +0000859 std::lock_guard _lock{mMutex};
860 BBQ_TRACE();
861 if (mTransactionReadyCallback) {
862 ALOGW("Attempting to overwrite transaction callback in syncNextTransaction");
863 return false;
Tianhao Yao4861b102022-02-03 20:18:35 +0000864 }
chaviw3b4bdcf2022-03-17 09:27:03 -0500865
Chavi Weingartenc398c012023-04-12 17:26:02 +0000866 mTransactionReadyCallback = callback;
867 mSyncTransaction = new SurfaceComposerClient::Transaction();
868 mAcquireSingleBuffer = acquireSingleBuffer;
869 return true;
Tianhao Yao4861b102022-02-03 20:18:35 +0000870}
871
872void BLASTBufferQueue::stopContinuousSyncTransaction() {
873 std::function<void(SurfaceComposerClient::Transaction*)> prevCallback = nullptr;
874 SurfaceComposerClient::Transaction* prevTransaction = nullptr;
875 {
876 std::lock_guard _lock{mMutex};
Chavi Weingartenc398c012023-04-12 17:26:02 +0000877 if (mAcquireSingleBuffer || !mTransactionReadyCallback) {
878 ALOGW("Attempting to stop continuous sync when none are active");
879 return;
Tianhao Yao4861b102022-02-03 20:18:35 +0000880 }
Chavi Weingartenc398c012023-04-12 17:26:02 +0000881
882 prevCallback = mTransactionReadyCallback;
883 prevTransaction = mSyncTransaction;
884
Tianhao Yao4861b102022-02-03 20:18:35 +0000885 mTransactionReadyCallback = nullptr;
886 mSyncTransaction = nullptr;
887 mAcquireSingleBuffer = true;
888 }
Chavi Weingartenc398c012023-04-12 17:26:02 +0000889
Tianhao Yao4861b102022-02-03 20:18:35 +0000890 if (prevCallback) {
891 prevCallback(prevTransaction);
892 }
Robert Carr78c25dd2019-08-15 14:10:33 -0700893}
894
Chavi Weingartenc398c012023-04-12 17:26:02 +0000895void BLASTBufferQueue::clearSyncTransaction() {
896 std::lock_guard _lock{mMutex};
897 if (!mAcquireSingleBuffer) {
898 ALOGW("Attempting to clear sync transaction when none are active");
899 return;
900 }
901
902 mTransactionReadyCallback = nullptr;
903 mSyncTransaction = nullptr;
904}
905
Vishnu Nairea0de002020-11-17 17:42:37 -0800906bool BLASTBufferQueue::rejectBuffer(const BufferItem& item) {
Vishnu Nair670b3f72020-09-29 17:52:18 -0700907 if (item.mScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE) {
908 // Only reject buffers if scaling mode is freeze.
909 return false;
910 }
911
Chavi Weingarten70670e62023-02-22 17:36:40 +0000912 ui::Size bufferSize = getBufferSize(item);
Vishnu Nairea0de002020-11-17 17:42:37 -0800913 if (mRequestedSize != mSize && mRequestedSize == bufferSize) {
Vishnu Nairea0de002020-11-17 17:42:37 -0800914 return false;
915 }
Vishnu Naire1a42322020-10-02 17:42:04 -0700916
Vishnu Nair670b3f72020-09-29 17:52:18 -0700917 // reject buffers if the buffer size doesn't match.
Vishnu Nairea0de002020-11-17 17:42:37 -0800918 return mSize != bufferSize;
Vishnu Nair670b3f72020-09-29 17:52:18 -0700919}
Vishnu Nairbf255772020-10-16 10:54:41 -0700920
Robert Carr05086b22020-10-13 18:22:51 -0700921class BBQSurface : public Surface {
Robert Carr9c006e02020-10-14 13:41:57 -0700922private:
Vishnu Nair95b6d512021-08-30 15:31:08 -0700923 std::mutex mMutex;
Chavi Weingartene0237bb2023-02-06 21:48:32 +0000924 sp<BLASTBufferQueue> mBbq GUARDED_BY(mMutex);
925 bool mDestroyed GUARDED_BY(mMutex) = false;
Vishnu Nair95b6d512021-08-30 15:31:08 -0700926
Robert Carr05086b22020-10-13 18:22:51 -0700927public:
Vishnu Nair992496b2020-10-22 17:27:21 -0700928 BBQSurface(const sp<IGraphicBufferProducer>& igbp, bool controlledByApp,
929 const sp<IBinder>& scHandle, const sp<BLASTBufferQueue>& bbq)
930 : Surface(igbp, controlledByApp, scHandle), mBbq(bbq) {}
Robert Carr9c006e02020-10-14 13:41:57 -0700931
Robert Carr05086b22020-10-13 18:22:51 -0700932 void allocateBuffers() override {
933 uint32_t reqWidth = mReqWidth ? mReqWidth : mUserWidth;
934 uint32_t reqHeight = mReqHeight ? mReqHeight : mUserHeight;
935 auto gbp = getIGraphicBufferProducer();
936 std::thread ([reqWidth, reqHeight, gbp=getIGraphicBufferProducer(),
937 reqFormat=mReqFormat, reqUsage=mReqUsage] () {
938 gbp->allocateBuffers(reqWidth, reqHeight,
939 reqFormat, reqUsage);
940
941 }).detach();
942 }
Robert Carr9c006e02020-10-14 13:41:57 -0700943
Marin Shalamanovc5986772021-03-16 16:09:49 +0100944 status_t setFrameRate(float frameRate, int8_t compatibility,
945 int8_t changeFrameRateStrategy) override {
Ady Abraham6cdd3fd2023-09-07 18:45:58 -0700946 if (flags::bq_setframerate()) {
947 return Surface::setFrameRate(frameRate, compatibility, changeFrameRateStrategy);
948 }
949
Chavi Weingartene0237bb2023-02-06 21:48:32 +0000950 std::lock_guard _lock{mMutex};
Vishnu Nair95b6d512021-08-30 15:31:08 -0700951 if (mDestroyed) {
952 return DEAD_OBJECT;
953 }
Marin Shalamanovc5986772021-03-16 16:09:49 +0100954 if (!ValidateFrameRate(frameRate, compatibility, changeFrameRateStrategy,
955 "BBQSurface::setFrameRate")) {
Robert Carr9c006e02020-10-14 13:41:57 -0700956 return BAD_VALUE;
957 }
Marin Shalamanovc5986772021-03-16 16:09:49 +0100958 return mBbq->setFrameRate(frameRate, compatibility, changeFrameRateStrategy);
Robert Carr9c006e02020-10-14 13:41:57 -0700959 }
Robert Carr9b611b72020-10-19 12:00:23 -0700960
Ady Abrahamd6e409e2023-01-19 16:07:31 -0800961 status_t setFrameTimelineInfo(uint64_t frameNumber,
962 const FrameTimelineInfo& frameTimelineInfo) override {
Chavi Weingartene0237bb2023-02-06 21:48:32 +0000963 std::lock_guard _lock{mMutex};
Vishnu Nair95b6d512021-08-30 15:31:08 -0700964 if (mDestroyed) {
965 return DEAD_OBJECT;
966 }
Ady Abrahamd6e409e2023-01-19 16:07:31 -0800967 return mBbq->setFrameTimelineInfo(frameNumber, frameTimelineInfo);
Robert Carr9b611b72020-10-19 12:00:23 -0700968 }
Vishnu Nair95b6d512021-08-30 15:31:08 -0700969
970 void destroy() override {
971 Surface::destroy();
972
Chavi Weingartene0237bb2023-02-06 21:48:32 +0000973 std::lock_guard _lock{mMutex};
Vishnu Nair95b6d512021-08-30 15:31:08 -0700974 mDestroyed = true;
975 mBbq = nullptr;
976 }
Robert Carr05086b22020-10-13 18:22:51 -0700977};
978
Robert Carr9c006e02020-10-14 13:41:57 -0700979// TODO: Can we coalesce this with frame updates? Need to confirm
980// no timing issues.
Marin Shalamanov46084422020-10-13 12:33:42 +0200981status_t BLASTBufferQueue::setFrameRate(float frameRate, int8_t compatibility,
982 bool shouldBeSeamless) {
Chavi Weingartene0237bb2023-02-06 21:48:32 +0000983 std::lock_guard _lock{mMutex};
Robert Carr9c006e02020-10-14 13:41:57 -0700984 SurfaceComposerClient::Transaction t;
985
Marin Shalamanov46084422020-10-13 12:33:42 +0200986 return t.setFrameRate(mSurfaceControl, frameRate, compatibility, shouldBeSeamless).apply();
Robert Carr9c006e02020-10-14 13:41:57 -0700987}
988
Ady Abrahamd6e409e2023-01-19 16:07:31 -0800989status_t BLASTBufferQueue::setFrameTimelineInfo(uint64_t frameNumber,
990 const FrameTimelineInfo& frameTimelineInfo) {
991 ATRACE_FORMAT("%s(%s) frameNumber: %" PRIu64 " vsyncId: %" PRId64, __func__, mName.c_str(),
992 frameNumber, frameTimelineInfo.vsyncId);
Chavi Weingartene0237bb2023-02-06 21:48:32 +0000993 std::lock_guard _lock{mMutex};
Ady Abrahamd6e409e2023-01-19 16:07:31 -0800994 mPendingFrameTimelines.push({frameNumber, frameTimelineInfo});
Jorim Jaggia3fe67b2020-12-01 00:24:33 +0100995 return OK;
Robert Carr9b611b72020-10-19 12:00:23 -0700996}
997
Hongguang Chen621ec582021-02-16 15:42:35 -0800998void BLASTBufferQueue::setSidebandStream(const sp<NativeHandle>& stream) {
Chavi Weingartene0237bb2023-02-06 21:48:32 +0000999 std::lock_guard _lock{mMutex};
Hongguang Chen621ec582021-02-16 15:42:35 -08001000 SurfaceComposerClient::Transaction t;
1001
1002 t.setSidebandStream(mSurfaceControl, stream).apply();
1003}
1004
Vishnu Nair992496b2020-10-22 17:27:21 -07001005sp<Surface> BLASTBufferQueue::getSurface(bool includeSurfaceControlHandle) {
Chavi Weingartene0237bb2023-02-06 21:48:32 +00001006 std::lock_guard _lock{mMutex};
Vishnu Nair992496b2020-10-22 17:27:21 -07001007 sp<IBinder> scHandle = nullptr;
1008 if (includeSurfaceControlHandle && mSurfaceControl) {
1009 scHandle = mSurfaceControl->getHandle();
1010 }
1011 return new BBQSurface(mProducer, true, scHandle, this);
Robert Carr05086b22020-10-13 18:22:51 -07001012}
1013
Vishnu Nairc4a40c12020-12-23 09:14:32 -08001014void BLASTBufferQueue::mergeWithNextTransaction(SurfaceComposerClient::Transaction* t,
1015 uint64_t frameNumber) {
1016 std::lock_guard _lock{mMutex};
1017 if (mLastAcquiredFrameNumber >= frameNumber) {
1018 // Apply the transaction since we have already acquired the desired frame.
1019 t->apply();
1020 } else {
chaviwaad6cf52021-03-23 17:27:20 -05001021 mPendingTransactions.emplace_back(frameNumber, *t);
1022 // Clear the transaction so it can't be applied elsewhere.
1023 t->clear();
Vishnu Nairc4a40c12020-12-23 09:14:32 -08001024 }
1025}
1026
chaviw6a195272021-09-03 16:14:25 -05001027void BLASTBufferQueue::applyPendingTransactions(uint64_t frameNumber) {
1028 std::lock_guard _lock{mMutex};
1029
1030 SurfaceComposerClient::Transaction t;
1031 mergePendingTransactions(&t, frameNumber);
Robert Carr79dc06a2022-02-22 15:28:59 -08001032 // All transactions on our apply token are one-way. See comment on mAppliedLastTransaction
1033 t.setApplyToken(mApplyToken).apply(false, true);
chaviw6a195272021-09-03 16:14:25 -05001034}
1035
1036void BLASTBufferQueue::mergePendingTransactions(SurfaceComposerClient::Transaction* t,
1037 uint64_t frameNumber) {
1038 auto mergeTransaction =
1039 [&t, currentFrameNumber = frameNumber](
1040 std::tuple<uint64_t, SurfaceComposerClient::Transaction> pendingTransaction) {
1041 auto& [targetFrameNumber, transaction] = pendingTransaction;
1042 if (currentFrameNumber < targetFrameNumber) {
1043 return false;
1044 }
1045 t->merge(std::move(transaction));
1046 return true;
1047 };
1048
1049 mPendingTransactions.erase(std::remove_if(mPendingTransactions.begin(),
1050 mPendingTransactions.end(), mergeTransaction),
1051 mPendingTransactions.end());
1052}
1053
chaviwd84085a2022-02-08 11:07:04 -06001054SurfaceComposerClient::Transaction* BLASTBufferQueue::gatherPendingTransactions(
1055 uint64_t frameNumber) {
1056 std::lock_guard _lock{mMutex};
1057 SurfaceComposerClient::Transaction* t = new SurfaceComposerClient::Transaction();
1058 mergePendingTransactions(t, frameNumber);
1059 return t;
1060}
1061
Vishnu Nair89496122020-12-14 17:14:53 -08001062// Maintains a single worker thread per process that services a list of runnables.
1063class AsyncWorker : public Singleton<AsyncWorker> {
1064private:
1065 std::thread mThread;
1066 bool mDone = false;
1067 std::deque<std::function<void()>> mRunnables;
1068 std::mutex mMutex;
1069 std::condition_variable mCv;
1070 void run() {
1071 std::unique_lock<std::mutex> lock(mMutex);
1072 while (!mDone) {
Vishnu Nair89496122020-12-14 17:14:53 -08001073 while (!mRunnables.empty()) {
Vishnu Nair51e4dc82021-10-01 15:32:33 -07001074 std::deque<std::function<void()>> runnables = std::move(mRunnables);
1075 mRunnables.clear();
1076 lock.unlock();
1077 // Run outside the lock since the runnable might trigger another
1078 // post to the async worker.
1079 execute(runnables);
1080 lock.lock();
Vishnu Nair89496122020-12-14 17:14:53 -08001081 }
Wonsik Kim567533e2021-05-04 19:31:29 -07001082 mCv.wait(lock);
Vishnu Nair89496122020-12-14 17:14:53 -08001083 }
1084 }
1085
Vishnu Nair51e4dc82021-10-01 15:32:33 -07001086 void execute(std::deque<std::function<void()>>& runnables) {
1087 while (!runnables.empty()) {
1088 std::function<void()> runnable = runnables.front();
1089 runnables.pop_front();
1090 runnable();
1091 }
1092 }
1093
Vishnu Nair89496122020-12-14 17:14:53 -08001094public:
1095 AsyncWorker() : Singleton<AsyncWorker>() { mThread = std::thread(&AsyncWorker::run, this); }
1096
1097 ~AsyncWorker() {
1098 mDone = true;
1099 mCv.notify_all();
1100 if (mThread.joinable()) {
1101 mThread.join();
1102 }
1103 }
1104
1105 void post(std::function<void()> runnable) {
1106 std::unique_lock<std::mutex> lock(mMutex);
1107 mRunnables.emplace_back(std::move(runnable));
1108 mCv.notify_one();
1109 }
1110};
1111ANDROID_SINGLETON_STATIC_INSTANCE(AsyncWorker);
1112
1113// Asynchronously calls ProducerListener functions so we can emulate one way binder calls.
1114class AsyncProducerListener : public BnProducerListener {
1115private:
1116 const sp<IProducerListener> mListener;
1117
1118public:
1119 AsyncProducerListener(const sp<IProducerListener>& listener) : mListener(listener) {}
1120
1121 void onBufferReleased() override {
1122 AsyncWorker::getInstance().post([listener = mListener]() { listener->onBufferReleased(); });
1123 }
1124
1125 void onBuffersDiscarded(const std::vector<int32_t>& slots) override {
1126 AsyncWorker::getInstance().post(
1127 [listener = mListener, slots = slots]() { listener->onBuffersDiscarded(slots); });
1128 }
Sungtak Lee7c935092024-09-16 16:55:04 +00001129
1130 void onBufferDetached(int slot) override {
1131 AsyncWorker::getInstance().post(
1132 [listener = mListener, slot = slot]() { listener->onBufferDetached(slot); });
1133 }
1134
1135#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_CONSUMER_ATTACH_CALLBACK)
1136 void onBufferAttached() override {
1137 AsyncWorker::getInstance().post([listener = mListener]() { listener->onBufferAttached(); });
1138 }
1139#endif
Vishnu Nair89496122020-12-14 17:14:53 -08001140};
1141
Patrick Williams078d7362024-08-27 10:20:39 -05001142#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BUFFER_RELEASE_CHANNEL)
1143class BBQBufferQueueCore : public BufferQueueCore {
1144public:
1145 explicit BBQBufferQueueCore(const wp<BLASTBufferQueue>& bbq) : mBLASTBufferQueue{bbq} {}
1146
1147 void notifyBufferReleased() const override {
1148 sp<BLASTBufferQueue> bbq = mBLASTBufferQueue.promote();
1149 if (!bbq) {
1150 return;
1151 }
1152 bbq->mBufferReleaseReader->interruptBlockingRead();
1153 }
1154
1155private:
1156 wp<BLASTBufferQueue> mBLASTBufferQueue;
1157};
1158#endif
1159
Vishnu Nair89496122020-12-14 17:14:53 -08001160// Extends the BufferQueueProducer to create a wrapper around the listener so the listener calls
1161// can be non-blocking when the producer is in the client process.
1162class BBQBufferQueueProducer : public BufferQueueProducer {
1163public:
Patrick Williamsca81c052024-08-15 12:38:34 -05001164 BBQBufferQueueProducer(const sp<BufferQueueCore>& core, const wp<BLASTBufferQueue>& bbq)
Brian Lindahlc794b692023-01-31 15:42:47 -07001165 : BufferQueueProducer(core, false /* consumerIsSurfaceFlinger*/),
Patrick Williamsca81c052024-08-15 12:38:34 -05001166 mBLASTBufferQueue(bbq) {}
Vishnu Nair89496122020-12-14 17:14:53 -08001167
1168 status_t connect(const sp<IProducerListener>& listener, int api, bool producerControlledByApp,
1169 QueueBufferOutput* output) override {
1170 if (!listener) {
1171 return BufferQueueProducer::connect(listener, api, producerControlledByApp, output);
1172 }
1173
1174 return BufferQueueProducer::connect(new AsyncProducerListener(listener), api,
1175 producerControlledByApp, output);
1176 }
Vishnu Nair17dde612020-12-28 11:39:59 -08001177
Brian Lindahlc794b692023-01-31 15:42:47 -07001178 // We want to resize the frame history when changing the size of the buffer queue
1179 status_t setMaxDequeuedBufferCount(int maxDequeuedBufferCount) override {
1180 int maxBufferCount;
Patrick Williamsf5b42de2024-08-01 16:08:51 -05001181 if (status_t status = BufferQueueProducer::setMaxDequeuedBufferCount(maxDequeuedBufferCount,
1182 &maxBufferCount);
1183 status != OK) {
1184 return status;
Brian Lindahlc794b692023-01-31 15:42:47 -07001185 }
Patrick Williamsf5b42de2024-08-01 16:08:51 -05001186
1187 sp<BLASTBufferQueue> bbq = mBLASTBufferQueue.promote();
1188 if (!bbq) {
1189 return OK;
1190 }
1191
1192 // if we can't determine the max buffer count, then just skip growing the history size
1193 size_t newFrameHistorySize = maxBufferCount + 2; // +2 because triple buffer rendering
1194 // optimize away resizing the frame history unless it will grow
1195 if (newFrameHistorySize > FrameEventHistory::INITIAL_MAX_FRAME_HISTORY) {
1196 ALOGV("increasing frame history size to %zu", newFrameHistorySize);
1197 bbq->resizeFrameEventHistory(newFrameHistorySize);
1198 }
1199
Patrick Williamsf5b42de2024-08-01 16:08:51 -05001200 return OK;
Brian Lindahlc794b692023-01-31 15:42:47 -07001201 }
1202
Vishnu Nair17dde612020-12-28 11:39:59 -08001203 int query(int what, int* value) override {
1204 if (what == NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER) {
1205 *value = 1;
Patrick Williamsf5b42de2024-08-01 16:08:51 -05001206 return OK;
Vishnu Nair17dde612020-12-28 11:39:59 -08001207 }
1208 return BufferQueueProducer::query(what, value);
1209 }
Brian Lindahlc794b692023-01-31 15:42:47 -07001210
Patrick Williams078d7362024-08-27 10:20:39 -05001211#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BUFFER_RELEASE_CHANNEL)
1212 status_t waitForBufferRelease(std::unique_lock<std::mutex>& bufferQueueLock,
1213 nsecs_t timeout) const override {
1214 sp<BLASTBufferQueue> bbq = mBLASTBufferQueue.promote();
1215 if (!bbq) {
1216 return OK;
1217 }
1218
1219 // BufferQueue has already checked if we have a free buffer. If there's an unread interrupt,
1220 // we want to ignore it. This must be done before unlocking the BufferQueue lock to ensure
1221 // we don't miss an interrupt.
1222 bbq->mBufferReleaseReader->clearInterrupts();
Patrick Williamsc16a4a52024-10-26 01:48:01 -05001223 UnlockGuard unlockGuard{bufferQueueLock};
Patrick Williams078d7362024-08-27 10:20:39 -05001224
1225 ATRACE_FORMAT("waiting for free buffer");
1226 ReleaseCallbackId id;
1227 sp<Fence> fence;
1228 uint32_t maxAcquiredBufferCount;
1229 status_t status =
1230 bbq->mBufferReleaseReader->readBlocking(id, fence, maxAcquiredBufferCount, timeout);
1231 if (status == TIMED_OUT) {
1232 return TIMED_OUT;
1233 } else if (status != OK) {
1234 // Waiting was interrupted or an error occurred. BufferQueueProducer will check if we
1235 // have a free buffer and call this method again if not.
1236 return OK;
1237 }
1238
1239 bbq->releaseBufferCallback(id, fence, maxAcquiredBufferCount);
1240 return OK;
1241 }
1242#endif
1243
Brian Lindahlc794b692023-01-31 15:42:47 -07001244private:
1245 const wp<BLASTBufferQueue> mBLASTBufferQueue;
Vishnu Nair89496122020-12-14 17:14:53 -08001246};
1247
1248// Similar to BufferQueue::createBufferQueue but creates an adapter specific bufferqueue producer.
1249// This BQP allows invoking client specified ProducerListeners and invoke them asynchronously,
1250// emulating one way binder call behavior. Without this, if the listener calls back into the queue,
1251// we can deadlock.
1252void BLASTBufferQueue::createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
1253 sp<IGraphicBufferConsumer>* outConsumer) {
1254 LOG_ALWAYS_FATAL_IF(outProducer == nullptr, "BLASTBufferQueue: outProducer must not be NULL");
1255 LOG_ALWAYS_FATAL_IF(outConsumer == nullptr, "BLASTBufferQueue: outConsumer must not be NULL");
1256
Patrick Williams078d7362024-08-27 10:20:39 -05001257#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BUFFER_RELEASE_CHANNEL)
1258 auto core = sp<BBQBufferQueueCore>::make(this);
1259#else
1260 auto core = sp<BufferQueueCore>::make();
1261#endif
Vishnu Nair89496122020-12-14 17:14:53 -08001262 LOG_ALWAYS_FATAL_IF(core == nullptr, "BLASTBufferQueue: failed to create BufferQueueCore");
1263
Patrick Williams078d7362024-08-27 10:20:39 -05001264 auto producer = sp<BBQBufferQueueProducer>::make(core, this);
Vishnu Nair89496122020-12-14 17:14:53 -08001265 LOG_ALWAYS_FATAL_IF(producer == nullptr,
1266 "BLASTBufferQueue: failed to create BBQBufferQueueProducer");
1267
Patrick Williams078d7362024-08-27 10:20:39 -05001268 auto consumer = sp<BufferQueueConsumer>::make(core);
Vishnu Nair8b30dd12021-01-25 14:16:54 -08001269 consumer->setAllowExtraAcquire(true);
Vishnu Nair89496122020-12-14 17:14:53 -08001270 LOG_ALWAYS_FATAL_IF(consumer == nullptr,
1271 "BLASTBufferQueue: failed to create BufferQueueConsumer");
1272
1273 *outProducer = producer;
1274 *outConsumer = consumer;
1275}
1276
Brian Lindahlc794b692023-01-31 15:42:47 -07001277void BLASTBufferQueue::resizeFrameEventHistory(size_t newSize) {
1278 // This can be null during creation of the buffer queue, but resizing won't do anything at that
1279 // point in time, so just ignore. This can go away once the class relationships and lifetimes of
1280 // objects are cleaned up with a major refactor of BufferQueue as a whole.
1281 if (mBufferItemConsumer != nullptr) {
1282 std::unique_lock _lock{mMutex};
1283 mBufferItemConsumer->resizeFrameEventHistory(newSize);
1284 }
1285}
1286
chaviw497e81c2021-02-04 17:09:47 -08001287PixelFormat BLASTBufferQueue::convertBufferFormat(PixelFormat& format) {
1288 PixelFormat convertedFormat = format;
1289 switch (format) {
1290 case PIXEL_FORMAT_TRANSPARENT:
1291 case PIXEL_FORMAT_TRANSLUCENT:
1292 convertedFormat = PIXEL_FORMAT_RGBA_8888;
1293 break;
1294 case PIXEL_FORMAT_OPAQUE:
1295 convertedFormat = PIXEL_FORMAT_RGBX_8888;
1296 break;
1297 }
1298 return convertedFormat;
1299}
1300
Robert Carr82d07c92021-05-10 11:36:43 -07001301uint32_t BLASTBufferQueue::getLastTransformHint() const {
Chavi Weingartene0237bb2023-02-06 21:48:32 +00001302 std::lock_guard _lock{mMutex};
Robert Carr82d07c92021-05-10 11:36:43 -07001303 if (mSurfaceControl != nullptr) {
1304 return mSurfaceControl->getTransformHint();
1305 } else {
1306 return 0;
1307 }
1308}
1309
chaviw0b020f82021-08-20 12:00:47 -05001310uint64_t BLASTBufferQueue::getLastAcquiredFrameNum() {
Chavi Weingartene0237bb2023-02-06 21:48:32 +00001311 std::lock_guard _lock{mMutex};
chaviw0b020f82021-08-20 12:00:47 -05001312 return mLastAcquiredFrameNumber;
1313}
1314
Vishnu Nair1e8bf102021-12-28 14:36:59 -08001315bool BLASTBufferQueue::isSameSurfaceControl(const sp<SurfaceControl>& surfaceControl) const {
Chavi Weingartene0237bb2023-02-06 21:48:32 +00001316 std::lock_guard _lock{mMutex};
Vishnu Nair1e8bf102021-12-28 14:36:59 -08001317 return SurfaceControl::isSameSurface(mSurfaceControl, surfaceControl);
1318}
1319
Patrick Williamsf1e5df12022-10-17 21:37:42 +00001320void BLASTBufferQueue::setTransactionHangCallback(
1321 std::function<void(const std::string&)> callback) {
Chavi Weingartene0237bb2023-02-06 21:48:32 +00001322 std::lock_guard _lock{mMutex};
Patrick Williams7c9fa272024-08-30 12:38:43 +00001323 mTransactionHangCallback = std::move(callback);
Robert Carr4c1b6462021-12-21 10:30:50 -08001324}
1325
Vishnu Nairaf15fab2024-07-30 08:59:26 -07001326void BLASTBufferQueue::setApplyToken(sp<IBinder> applyToken) {
1327 std::lock_guard _lock{mMutex};
1328 mApplyToken = std::move(applyToken);
1329}
1330
Patrick Williams7c9fa272024-08-30 12:38:43 +00001331#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BUFFER_RELEASE_CHANNEL)
1332
Patrick Williamsa419faa2024-10-29 16:50:27 -05001333void BLASTBufferQueue::updateBufferReleaseProducer() {
1334 // SELinux policy may prevent this process from sending the BufferReleaseChannel's file
1335 // descriptor to SurfaceFlinger, causing the entire transaction to be dropped. We send this
1336 // transaction independently of any other updates to ensure those updates aren't lost.
1337 SurfaceComposerClient::Transaction t;
1338 status_t status = t.setApplyToken(mApplyToken)
1339 .setBufferReleaseChannel(mSurfaceControl, mBufferReleaseProducer)
1340 .apply(false /* synchronous */, true /* oneWay */);
1341 if (status != OK) {
1342 ALOGW("[%s] %s - failed to set buffer release channel on %s", mName.c_str(),
1343 statusToString(status).c_str(), mSurfaceControl->getName().c_str());
1344 }
1345}
1346
Patrick Williamsc16a4a52024-10-26 01:48:01 -05001347void BLASTBufferQueue::drainBufferReleaseConsumer() {
1348 ATRACE_CALL();
1349 while (true) {
1350 ReleaseCallbackId id;
1351 sp<Fence> fence;
1352 uint32_t maxAcquiredBufferCount;
1353 status_t status =
1354 mBufferReleaseConsumer->readReleaseFence(id, fence, maxAcquiredBufferCount);
1355 if (status != OK) {
1356 return;
1357 }
1358 releaseBufferCallback(id, fence, maxAcquiredBufferCount);
1359 }
1360}
1361
Patrick Williams078d7362024-08-27 10:20:39 -05001362BLASTBufferQueue::BufferReleaseReader::BufferReleaseReader(BLASTBufferQueue& bbq) : mBbq{bbq} {
1363 mEpollFd = android::base::unique_fd{epoll_create1(EPOLL_CLOEXEC)};
Patrick Williams7c9fa272024-08-30 12:38:43 +00001364 LOG_ALWAYS_FATAL_IF(!mEpollFd.ok(),
1365 "Failed to create buffer release epoll file descriptor. errno=%d "
1366 "message='%s'",
1367 errno, strerror(errno));
1368
1369 epoll_event registerEndpointFd{};
1370 registerEndpointFd.events = EPOLLIN;
Patrick Williams078d7362024-08-27 10:20:39 -05001371 registerEndpointFd.data.fd = mBbq.mBufferReleaseConsumer->getFd();
1372 status_t status = epoll_ctl(mEpollFd.get(), EPOLL_CTL_ADD, mBbq.mBufferReleaseConsumer->getFd(),
1373 &registerEndpointFd);
Patrick Williams7c9fa272024-08-30 12:38:43 +00001374 LOG_ALWAYS_FATAL_IF(status == -1,
1375 "Failed to register buffer release consumer file descriptor with epoll. "
1376 "errno=%d message='%s'",
1377 errno, strerror(errno));
1378
1379 mEventFd = android::base::unique_fd(eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK));
1380 LOG_ALWAYS_FATAL_IF(!mEventFd.ok(),
1381 "Failed to create buffer release event file descriptor. errno=%d "
1382 "message='%s'",
1383 errno, strerror(errno));
1384
1385 epoll_event registerEventFd{};
1386 registerEventFd.events = EPOLLIN;
1387 registerEventFd.data.fd = mEventFd.get();
1388 status = epoll_ctl(mEpollFd.get(), EPOLL_CTL_ADD, mEventFd.get(), &registerEventFd);
1389 LOG_ALWAYS_FATAL_IF(status == -1,
1390 "Failed to register buffer release event file descriptor with epoll. "
1391 "errno=%d message='%s'",
1392 errno, strerror(errno));
1393}
1394
Patrick Williams7c9fa272024-08-30 12:38:43 +00001395status_t BLASTBufferQueue::BufferReleaseReader::readBlocking(ReleaseCallbackId& outId,
1396 sp<Fence>& outFence,
Patrick Williams078d7362024-08-27 10:20:39 -05001397 uint32_t& outMaxAcquiredBufferCount,
1398 nsecs_t timeout) {
1399 // TODO(b/363290953) epoll_wait only has millisecond timeout precision. If timeout is less than
1400 // 1ms, then we round timeout up to 1ms. Otherwise, we round timeout to the nearest
1401 // millisecond. Once epoll_pwait2 can be used in libgui, we can specify timeout with nanosecond
1402 // precision.
1403 int timeoutMs = -1;
1404 if (timeout == 0) {
1405 timeoutMs = 0;
1406 } else if (timeout > 0) {
1407 const int nsPerMs = 1000000;
1408 if (timeout < nsPerMs) {
1409 timeoutMs = 1;
1410 } else {
1411 timeoutMs = static_cast<int>(
1412 std::chrono::round<std::chrono::milliseconds>(std::chrono::nanoseconds{timeout})
1413 .count());
1414 }
1415 }
1416
Patrick Williams7c9fa272024-08-30 12:38:43 +00001417 epoll_event event{};
Patrick Williams078d7362024-08-27 10:20:39 -05001418 int eventCount;
1419 do {
1420 eventCount = epoll_wait(mEpollFd.get(), &event, 1 /*maxevents*/, timeoutMs);
1421 } while (eventCount == -1 && errno != EINTR);
1422
1423 if (eventCount == -1) {
1424 ALOGE("epoll_wait error while waiting for buffer release. errno=%d message='%s'", errno,
1425 strerror(errno));
1426 return UNKNOWN_ERROR;
1427 }
1428
1429 if (eventCount == 0) {
1430 return TIMED_OUT;
Patrick Williams7c9fa272024-08-30 12:38:43 +00001431 }
1432
1433 if (event.data.fd == mEventFd.get()) {
Patrick Williams078d7362024-08-27 10:20:39 -05001434 clearInterrupts();
Patrick Williams7c9fa272024-08-30 12:38:43 +00001435 return WOULD_BLOCK;
1436 }
1437
Patrick Williams078d7362024-08-27 10:20:39 -05001438 return mBbq.mBufferReleaseConsumer->readReleaseFence(outId, outFence,
1439 outMaxAcquiredBufferCount);
Patrick Williams7c9fa272024-08-30 12:38:43 +00001440}
1441
1442void BLASTBufferQueue::BufferReleaseReader::interruptBlockingRead() {
Patrick Williams078d7362024-08-27 10:20:39 -05001443 if (eventfd_write(mEventFd.get(), 1) == -1) {
Patrick Williams7c9fa272024-08-30 12:38:43 +00001444 ALOGE("failed to notify dequeue event. errno=%d message='%s'", errno, strerror(errno));
1445 }
1446}
1447
Patrick Williams078d7362024-08-27 10:20:39 -05001448void BLASTBufferQueue::BufferReleaseReader::clearInterrupts() {
1449 eventfd_t value;
1450 if (eventfd_read(mEventFd.get(), &value) == -1 && errno != EWOULDBLOCK) {
1451 ALOGE("error while reading from eventfd. errno=%d message='%s'", errno, strerror(errno));
1452 }
1453}
1454
Patrick Williams7c9fa272024-08-30 12:38:43 +00001455#endif
1456
Robert Carr78c25dd2019-08-15 14:10:33 -07001457} // namespace android