Skip to content

Commit f49f949

Browse files
author
Anton Ivanov
committed
Ensure BBQ builds with ANDROID_UTILS_REF_BASE_DISABLE_IMPLICIT_CONSTRUCTION.
Test: presubmit Flag: EXEMPT refactor Bug: 393217449 Change-Id: I7986d96aa8d1bb2eb7cbe2abe01df95809a505b5
1 parent 1b7198f commit f49f949

File tree

3 files changed

+46
-32
lines changed

3 files changed

+46
-32
lines changed

libs/gui/BLASTBufferQueue.cpp

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -187,37 +187,30 @@ void BLASTBufferItemConsumer::resizeFrameEventHistory(size_t newSize) {
187187
mFrameEventHistory.resize(newSize);
188188
}
189189

190-
BLASTBufferQueue::BLASTBufferQueue(const std::string& name, bool updateDestinationFrame)
191-
: mSurfaceControl(nullptr),
192-
mSize(1, 1),
193-
mRequestedSize(mSize),
194-
mFormat(PIXEL_FORMAT_RGBA_8888),
195-
mTransactionReadyCallback(nullptr),
196-
mSyncTransaction(nullptr),
197-
mUpdateDestinationFrame(updateDestinationFrame) {
190+
void BLASTBufferQueue::initialize() {
191+
std::lock_guard _lock{mMutex};
198192
createBufferQueue(&mProducer, &mConsumer);
199193
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
200-
mBufferItemConsumer = sp<BLASTBufferItemConsumer>::make(mProducer, mConsumer,
201-
GraphicBuffer::USAGE_HW_COMPOSER |
202-
GraphicBuffer::USAGE_HW_TEXTURE,
203-
1, false, this);
194+
mBufferItemConsumer =
195+
sp<BLASTBufferItemConsumer>::make(mProducer, mConsumer,
196+
GraphicBuffer::USAGE_HW_COMPOSER |
197+
GraphicBuffer::USAGE_HW_TEXTURE,
198+
1, false, wp<BLASTBufferQueue>::fromExisting(this));
204199
#else
205-
mBufferItemConsumer = sp<BLASTBufferItemConsumer>::make(mConsumer,
206-
GraphicBuffer::USAGE_HW_COMPOSER |
207-
GraphicBuffer::USAGE_HW_TEXTURE,
208-
1, false, this);
200+
mBufferItemConsumer =
201+
sp<BLASTBufferItemConsumer>::make(mConsumer,
202+
GraphicBuffer::USAGE_HW_COMPOSER |
203+
GraphicBuffer::USAGE_HW_TEXTURE,
204+
1, false, wp<BLASTBufferQueue>::fromExisting(this));
209205
#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
210206
// since the adapter is in the client process, set dequeue timeout
211207
// explicitly so that dequeueBuffer will block
212208
mProducer->setDequeueTimeout(std::numeric_limits<int64_t>::max());
213209

214-
static std::atomic<uint32_t> nextId = 0;
215-
mProducerId = nextId++;
216-
mName = name + "#" + std::to_string(mProducerId);
217210
auto consumerName = mName + "(BLAST Consumer)" + std::to_string(mProducerId);
218211
mQueuedBufferTrace = "QueuedBuffer - " + mName + "BLAST#" + std::to_string(mProducerId);
219212
mBufferItemConsumer->setName(String8(consumerName.c_str()));
220-
mBufferItemConsumer->setFrameAvailableListener(this);
213+
mBufferItemConsumer->setFrameAvailableListener(wp<BLASTBufferQueue>::fromExisting(this));
221214

222215
ComposerServiceAIDL::getComposerService()->getMaxAcquiredBufferCount(&mMaxAcquiredBuffers);
223216
mBufferItemConsumer->setMaxAcquiredBufferCount(mMaxAcquiredBuffers);
@@ -239,9 +232,25 @@ BLASTBufferQueue::BLASTBufferQueue(const std::string& name, bool updateDestinati
239232
mBufferReleaseReader.emplace(*this);
240233
#endif
241234

235+
// safe default, most producers are expected to override this
236+
mProducer->setMaxDequeuedBufferCount(2);
237+
242238
BQA_LOGV("BLASTBufferQueue created");
243239
}
244240

241+
BLASTBufferQueue::BLASTBufferQueue(const std::string& name, bool updateDestinationFrame)
242+
: mSurfaceControl(nullptr),
243+
mSize(1, 1),
244+
mRequestedSize(mSize),
245+
mFormat(PIXEL_FORMAT_RGBA_8888),
246+
mTransactionReadyCallback(nullptr),
247+
mSyncTransaction(nullptr),
248+
mUpdateDestinationFrame(updateDestinationFrame) {
249+
static std::atomic<uint32_t> nextId = 0;
250+
mProducerId = nextId++;
251+
mName = name + "#" + std::to_string(mProducerId);
252+
}
253+
245254
BLASTBufferQueue::~BLASTBufferQueue() {
246255
TransactionCompletedListener::getInstance()->removeQueueStallListener(this);
247256
if (mPendingTransactions.empty()) {
@@ -260,8 +269,7 @@ BLASTBufferQueue::~BLASTBufferQueue() {
260269
}
261270

262271
void BLASTBufferQueue::onFirstRef() {
263-
// safe default, most producers are expected to override this
264-
mProducer->setMaxDequeuedBufferCount(2);
272+
initialize();
265273
}
266274

267275
void BLASTBufferQueue::update(const sp<SurfaceControl>& surface, uint32_t width, uint32_t height,
@@ -1022,7 +1030,8 @@ sp<Surface> BLASTBufferQueue::getSurface(bool includeSurfaceControlHandle) {
10221030
if (includeSurfaceControlHandle && mSurfaceControl) {
10231031
scHandle = mSurfaceControl->getHandle();
10241032
}
1025-
return sp<BBQSurface>::make(mProducer, true, scHandle, this);
1033+
return sp<BBQSurface>::make(mProducer, true, scHandle,
1034+
sp<BLASTBufferQueue>::fromExisting(this));
10261035
}
10271036

10281037
void BLASTBufferQueue::mergeWithNextTransaction(SurfaceComposerClient::Transaction* t,
@@ -1278,13 +1287,14 @@ void BLASTBufferQueue::createBufferQueue(sp<IGraphicBufferProducer>* outProducer
12781287
LOG_ALWAYS_FATAL_IF(outConsumer == nullptr, "BLASTBufferQueue: outConsumer must not be NULL");
12791288

12801289
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BUFFER_RELEASE_CHANNEL)
1281-
auto core = sp<BBQBufferQueueCore>::make(this);
1290+
auto core = sp<BBQBufferQueueCore>::make(wp<BLASTBufferQueue>::fromExisting(this));
12821291
#else
12831292
auto core = sp<BufferQueueCore>::make();
12841293
#endif
12851294
LOG_ALWAYS_FATAL_IF(core == nullptr, "BLASTBufferQueue: failed to create BufferQueueCore");
12861295

1287-
auto producer = sp<BBQBufferQueueProducer>::make(core, this);
1296+
auto producer =
1297+
sp<BBQBufferQueueProducer>::make(core, wp<BLASTBufferQueue>::fromExisting(this));
12881298
LOG_ALWAYS_FATAL_IF(producer == nullptr,
12891299
"BLASTBufferQueue: failed to create BBQBufferQueueProducer");
12901300

libs/gui/include/gui/BLASTBufferQueue.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class BLASTBufferQueue : public ConsumerBase::FrameAvailableListener {
155155

156156
virtual ~BLASTBufferQueue();
157157

158-
void onFirstRef() override;
158+
void onFirstRef() override final;
159159

160160
private:
161161
// Not public to ensure construction via sp<>::make().
@@ -175,6 +175,7 @@ class BLASTBufferQueue : public ConsumerBase::FrameAvailableListener {
175175
void createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
176176
sp<IGraphicBufferConsumer>* outConsumer);
177177

178+
void initialize();
178179
void resizeFrameEventHistory(size_t newSize);
179180

180181
status_t acquireNextBufferLocked(

libs/gui/tests/BLASTBufferQueue_test.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ class CountProducerListener : public BnProducerListener {
7979

8080
class TestBLASTBufferQueue : public BLASTBufferQueue {
8181
public:
82-
TestBLASTBufferQueue(const std::string& name, const sp<SurfaceControl>& surface, int width,
83-
int height, int32_t format)
84-
: BLASTBufferQueue(name) {
85-
update(surface, width, height, format);
82+
static sp<TestBLASTBufferQueue> create(const sp<SurfaceControl>& surface, int width,
83+
int height) {
84+
auto blastBufferQueueAdapter = sp<TestBLASTBufferQueue>::make("TestBLASTBufferQueue");
85+
blastBufferQueueAdapter->update(surface, width, height, PIXEL_FORMAT_RGBA_8888);
86+
return blastBufferQueueAdapter;
8687
}
8788

8889
void transactionCallback(nsecs_t latchTime, const sp<Fence>& presentFence,
@@ -106,6 +107,9 @@ class TestBLASTBufferQueue : public BLASTBufferQueue {
106107
}
107108

108109
private:
110+
friend class sp<TestBLASTBufferQueue>;
111+
TestBLASTBufferQueue(const std::string& name) : BLASTBufferQueue(name) {}
112+
109113
std::mutex frameNumberMutex;
110114
std::condition_variable mWaitForCallbackCV;
111115
int64_t mLastTransactionFrameNumber = -1;
@@ -114,8 +118,7 @@ class TestBLASTBufferQueue : public BLASTBufferQueue {
114118
class BLASTBufferQueueHelper {
115119
public:
116120
BLASTBufferQueueHelper(const sp<SurfaceControl>& sc, int width, int height) {
117-
mBlastBufferQueueAdapter = sp<TestBLASTBufferQueue>::make("TestBLASTBufferQueue", sc, width,
118-
height, PIXEL_FORMAT_RGBA_8888);
121+
mBlastBufferQueueAdapter = TestBLASTBufferQueue::create(sc, width, height);
119122
}
120123

121124
void update(const sp<SurfaceControl>& sc, int width, int height) {

0 commit comments

Comments
 (0)