summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
author Vishnu Nair <vishnun@google.com> 2020-11-19 18:26:04 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2020-11-19 18:26:04 +0000
commit7752fe5b2eb82c0cfd09f60d11a72ed7352b7ab8 (patch)
treea2675212637963aa78386b775c346bed4c8b5f91 /libs
parent6693932947b18a11970f1f6729c721321dcd7885 (diff)
parentcf26a0a9c5467ca6ff0ab71dc944ea7341ec62e1 (diff)
Merge changes I25ddd986,I3cc43b2b
* changes: BlastBufferQueue: Add support for auto refresh BlastBufferQueue: Add buffer rejection
Diffstat (limited to 'libs')
-rw-r--r--libs/gui/BLASTBufferQueue.cpp47
-rw-r--r--libs/gui/LayerState.cpp20
-rw-r--r--libs/gui/SurfaceComposerClient.cpp13
-rw-r--r--libs/gui/include/gui/BLASTBufferQueue.h10
-rw-r--r--libs/gui/include/gui/LayerState.h6
-rw-r--r--libs/gui/include/gui/SurfaceComposerClient.h5
-rw-r--r--libs/gui/tests/BLASTBufferQueue_test.cpp15
7 files changed, 92 insertions, 24 deletions
diff --git a/libs/gui/BLASTBufferQueue.cpp b/libs/gui/BLASTBufferQueue.cpp
index ac1c7369b6..e6aa02a8fe 100644
--- a/libs/gui/BLASTBufferQueue.cpp
+++ b/libs/gui/BLASTBufferQueue.cpp
@@ -111,8 +111,8 @@ BLASTBufferQueue::BLASTBufferQueue(const std::string& name, const sp<SurfaceCont
int width, int height, bool enableTripleBuffering)
: mName(name),
mSurfaceControl(surface),
- mWidth(width),
- mHeight(height),
+ mSize(width, height),
+ mRequestedSize(mSize),
mNextTransaction(nullptr) {
BufferQueue::createBufferQueue(&mProducer, &mConsumer);
// since the adapter is in the client process, set dequeue timeout
@@ -130,7 +130,7 @@ BLASTBufferQueue::BLASTBufferQueue(const std::string& name, const sp<SurfaceCont
mBufferItemConsumer->setName(String8(consumerName.c_str()));
mBufferItemConsumer->setFrameAvailableListener(this);
mBufferItemConsumer->setBufferFreedListener(this);
- mBufferItemConsumer->setDefaultBufferSize(mWidth, mHeight);
+ mBufferItemConsumer->setDefaultBufferSize(mSize.width, mSize.height);
mBufferItemConsumer->setDefaultBufferFormat(PIXEL_FORMAT_RGBA_8888);
mTransformHint = mSurfaceControl->getTransformHint();
@@ -146,10 +146,10 @@ void BLASTBufferQueue::update(const sp<SurfaceControl>& surface, uint32_t width,
std::unique_lock _lock{mMutex};
mSurfaceControl = surface;
- if (mWidth != width || mHeight != height) {
- mWidth = width;
- mHeight = height;
- mBufferItemConsumer->setDefaultBufferSize(mWidth, mHeight);
+ ui::Size newSize(width, height);
+ if (mRequestedSize != newSize) {
+ mRequestedSize.set(newSize);
+ mBufferItemConsumer->setDefaultBufferSize(mRequestedSize.width, mRequestedSize.height);
}
}
@@ -218,6 +218,7 @@ void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) {
// number of buffers.
if (mNumFrameAvailable == 0 || maxBuffersAcquired()) {
BQA_LOGV("processNextBufferLocked waiting for frame available or callback");
+ mCallbackCV.notify_all();
return;
}
@@ -252,10 +253,13 @@ void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) {
}
if (rejectBuffer(bufferItem)) {
- BQA_LOGE("rejecting buffer:configured size=%dx%d, buffer{size=%dx%d transform=%d}", mWidth,
- mHeight, buffer->getWidth(), buffer->getHeight(), bufferItem.mTransform);
- // TODO(b/168917217) temporarily don't reject buffers until we can synchronize buffer size
- // changes from ViewRootImpl.
+ BQA_LOGE("rejecting buffer:active_size=%dx%d, requested_size=%dx%d"
+ "buffer{size=%dx%d transform=%d}",
+ mSize.width, mSize.height, mRequestedSize.width, mRequestedSize.height,
+ buffer->getWidth(), buffer->getHeight(), bufferItem.mTransform);
+ mBufferItemConsumer->releaseBuffer(bufferItem, Fence::NO_FENCE);
+ processNextBufferLocked(useNextTransaction);
+ return;
}
mNumAcquired++;
@@ -278,26 +282,31 @@ void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) {
t->addTransactionCompletedCallback(transactionCallbackThunk, static_cast<void*>(this));
t->setFrame(mSurfaceControl,
- {0, 0, static_cast<int32_t>(mWidth), static_cast<int32_t>(mHeight)});
+ {0, 0, static_cast<int32_t>(mSize.width), static_cast<int32_t>(mSize.height)});
t->setCrop(mSurfaceControl, computeCrop(bufferItem));
t->setTransform(mSurfaceControl, bufferItem.mTransform);
t->setTransformToDisplayInverse(mSurfaceControl, bufferItem.mTransformToDisplayInverse);
t->setDesiredPresentTime(bufferItem.mTimestamp);
t->setFrameNumber(mSurfaceControl, bufferItem.mFrameNumber);
+ if (mAutoRefresh != bufferItem.mAutoRefresh) {
+ t->setAutoRefresh(mSurfaceControl, bufferItem.mAutoRefresh);
+ mAutoRefresh = bufferItem.mAutoRefresh;
+ }
+
if (applyTransaction) {
t->apply();
}
BQA_LOGV("processNextBufferLocked size=%dx%d mFrameNumber=%" PRIu64
" applyTransaction=%s mTimestamp=%" PRId64,
- mWidth, mHeight, bufferItem.mFrameNumber, toString(applyTransaction),
+ mSize.width, mSize.height, bufferItem.mFrameNumber, toString(applyTransaction),
bufferItem.mTimestamp);
}
Rect BLASTBufferQueue::computeCrop(const BufferItem& item) {
if (item.mScalingMode == NATIVE_WINDOW_SCALING_MODE_SCALE_CROP) {
- return GLConsumer::scaleDownCrop(item.mCrop, mWidth, mHeight);
+ return GLConsumer::scaleDownCrop(item.mCrop, mSize.width, mSize.height);
}
return item.mCrop;
}
@@ -332,8 +341,9 @@ void BLASTBufferQueue::setNextTransaction(SurfaceComposerClient::Transaction* t)
mNextTransaction = t;
}
-bool BLASTBufferQueue::rejectBuffer(const BufferItem& item) const {
+bool BLASTBufferQueue::rejectBuffer(const BufferItem& item) {
if (item.mScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE) {
+ mSize = mRequestedSize;
// Only reject buffers if scaling mode is freeze.
return false;
}
@@ -345,9 +355,14 @@ bool BLASTBufferQueue::rejectBuffer(const BufferItem& item) const {
if (item.mTransform & ui::Transform::ROT_90) {
std::swap(bufWidth, bufHeight);
}
+ ui::Size bufferSize(bufWidth, bufHeight);
+ if (mRequestedSize != mSize && mRequestedSize == bufferSize) {
+ mSize = mRequestedSize;
+ return false;
+ }
// reject buffers if the buffer size doesn't match.
- return bufWidth != mWidth || bufHeight != mHeight;
+ return mSize != bufferSize;
}
// Check if we have acquired the maximum number of buffers.
diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp
index 90999faa78..7d2c7b88df 100644
--- a/libs/gui/LayerState.cpp
+++ b/libs/gui/LayerState.cpp
@@ -61,7 +61,9 @@ layer_state_t::layer_state_t()
frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
shouldBeSeamless(true),
fixedTransformHint(ui::Transform::ROT_INVALID),
- frameNumber(0) {
+ frameNumber(0),
+ frameTimelineVsyncId(ISurfaceComposer::INVALID_VSYNC_ID),
+ autoRefresh(false) {
matrix.dsdx = matrix.dtdy = 1.0f;
matrix.dsdy = matrix.dtdx = 0.0f;
hdrMetadata.validTypes = 0;
@@ -149,6 +151,7 @@ status_t layer_state_t::write(Parcel& output) const
SAFE_PARCEL(output.writeUint32, fixedTransformHint);
SAFE_PARCEL(output.writeUint64, frameNumber);
SAFE_PARCEL(output.writeInt64, frameTimelineVsyncId);
+ SAFE_PARCEL(output.writeBool, autoRefresh);
SAFE_PARCEL(output.writeUint32, blurRegions.size());
for (auto region : blurRegions) {
@@ -269,6 +272,7 @@ status_t layer_state_t::read(const Parcel& input)
fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
SAFE_PARCEL(input.readUint64, &frameNumber);
SAFE_PARCEL(input.readInt64, &frameTimelineVsyncId);
+ SAFE_PARCEL(input.readBool, &autoRefresh);
uint32_t numRegions = 0;
SAFE_PARCEL(input.readUint32, &numRegions);
@@ -534,6 +538,20 @@ void layer_state_t::merge(const layer_state_t& other) {
what |= eFrameNumberChanged;
frameNumber = other.frameNumber;
}
+ if (other.what & eFrameTimelineVsyncChanged) {
+ // When merging vsync Ids we take the oldest valid one
+ if (frameTimelineVsyncId != ISurfaceComposer::INVALID_VSYNC_ID &&
+ other.frameTimelineVsyncId != ISurfaceComposer::INVALID_VSYNC_ID) {
+ frameTimelineVsyncId = std::max(frameTimelineVsyncId, other.frameTimelineVsyncId);
+ } else if (frameTimelineVsyncId == ISurfaceComposer::INVALID_VSYNC_ID) {
+ frameTimelineVsyncId = other.frameTimelineVsyncId;
+ }
+ what |= eFrameTimelineVsyncChanged;
+ }
+ if (other.what & eAutoRefreshChanged) {
+ what |= eAutoRefreshChanged;
+ autoRefresh = other.autoRefresh;
+ }
if ((other.what & what) != other.what) {
ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
"other.what=0x%" PRIu64 " what=0x%" PRIu64,
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index a822598d82..47a08ab500 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -1527,6 +1527,19 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrame
return *this;
}
+SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setAutoRefresh(
+ const sp<SurfaceControl>& sc, bool autoRefresh) {
+ layer_state_t* s = getLayerState(sc);
+ if (!s) {
+ mStatus = BAD_INDEX;
+ return *this;
+ }
+
+ s->what |= layer_state_t::eAutoRefreshChanged;
+ s->autoRefresh = autoRefresh;
+ return *this;
+}
+
// ---------------------------------------------------------------------------
DisplayState& SurfaceComposerClient::Transaction::getDisplayState(const sp<IBinder>& token) {
diff --git a/libs/gui/include/gui/BLASTBufferQueue.h b/libs/gui/include/gui/BLASTBufferQueue.h
index 7741d8c38a..9fb7d6fd36 100644
--- a/libs/gui/include/gui/BLASTBufferQueue.h
+++ b/libs/gui/include/gui/BLASTBufferQueue.h
@@ -100,7 +100,7 @@ private:
void processNextBufferLocked(bool useNextTransaction) REQUIRES(mMutex);
Rect computeCrop(const BufferItem& item) REQUIRES(mMutex);
// Return true if we need to reject the buffer based on the scaling mode and the buffer size.
- bool rejectBuffer(const BufferItem& item) const REQUIRES(mMutex);
+ bool rejectBuffer(const BufferItem& item) REQUIRES(mMutex);
bool maxBuffersAcquired() const REQUIRES(mMutex);
std::string mName;
@@ -126,8 +126,8 @@ private:
// is ready to be presented.
PendingReleaseItem mPendingReleaseItem GUARDED_BY(mMutex);
- uint32_t mWidth GUARDED_BY(mMutex);
- uint32_t mHeight GUARDED_BY(mMutex);
+ ui::Size mSize GUARDED_BY(mMutex);
+ ui::Size mRequestedSize GUARDED_BY(mMutex);
uint32_t mTransformHint GUARDED_BY(mMutex);
@@ -139,6 +139,10 @@ private:
// If set to true, the next queue buffer will wait until the shadow queue has been processed by
// the adapter.
bool mFlushShadowQueue = false;
+ // Last requested auto refresh state set by the producer. The state indicates that the consumer
+ // should acquire the next frame as soon as it can and not wait for a frame to become available.
+ // This is only relevant for shared buffer mode.
+ bool mAutoRefresh GUARDED_BY(mMutex) = false;
};
} // namespace android
diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h
index d9f280684f..f1c5d6712d 100644
--- a/libs/gui/include/gui/LayerState.h
+++ b/libs/gui/include/gui/LayerState.h
@@ -130,6 +130,7 @@ struct layer_state_t {
eFrameNumberChanged = 0x400'00000000,
eFrameTimelineVsyncChanged = 0x800'00000000,
eBlurRegionsChanged = 0x1000'00000000,
+ eAutoRefreshChanged = 0x2000'00000000,
};
layer_state_t();
@@ -234,6 +235,11 @@ struct layer_state_t {
uint64_t frameNumber;
int64_t frameTimelineVsyncId;
+
+ // Indicates that the consumer should acquire the next frame as soon as it
+ // can and not wait for a frame to become available. This is only relevant
+ // in shared buffer mode.
+ bool autoRefresh;
};
struct ComposerState {
diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h
index 6289c6a3cd..2eb97f27a1 100644
--- a/libs/gui/include/gui/SurfaceComposerClient.h
+++ b/libs/gui/include/gui/SurfaceComposerClient.h
@@ -541,6 +541,11 @@ public:
Transaction& setFrameTimelineVsync(const sp<SurfaceControl>& sc,
int64_t frameTimelineVsyncId);
+ // Indicates that the consumer should acquire the next frame as soon as it
+ // can and not wait for a frame to become available. This is only relevant
+ // in shared buffer mode.
+ Transaction& setAutoRefresh(const sp<SurfaceControl>& sc, bool autoRefresh);
+
status_t setDisplaySurface(const sp<IBinder>& token,
const sp<IGraphicBufferProducer>& bufferProducer);
diff --git a/libs/gui/tests/BLASTBufferQueue_test.cpp b/libs/gui/tests/BLASTBufferQueue_test.cpp
index f3559fa6c1..4282ef9e99 100644
--- a/libs/gui/tests/BLASTBufferQueue_test.cpp
+++ b/libs/gui/tests/BLASTBufferQueue_test.cpp
@@ -55,9 +55,9 @@ public:
mBlastBufferQueueAdapter->setNextTransaction(next);
}
- int getWidth() { return mBlastBufferQueueAdapter->mWidth; }
+ int getWidth() { return mBlastBufferQueueAdapter->mSize.width; }
- int getHeight() { return mBlastBufferQueueAdapter->mHeight; }
+ int getHeight() { return mBlastBufferQueueAdapter->mSize.height; }
Transaction* getNextTransaction() { return mBlastBufferQueueAdapter->mNextTransaction; }
@@ -250,8 +250,15 @@ TEST_F(BLASTBufferQueueTest, Update) {
PIXEL_FORMAT_RGBA_8888);
adapter.update(updateSurface, mDisplayWidth / 2, mDisplayHeight / 2);
ASSERT_EQ(updateSurface, adapter.getSurfaceControl());
- ASSERT_EQ(mDisplayWidth / 2, adapter.getWidth());
- ASSERT_EQ(mDisplayHeight / 2, adapter.getHeight());
+ sp<IGraphicBufferProducer> igbProducer;
+ setUpProducer(adapter, igbProducer);
+
+ int32_t width;
+ igbProducer->query(NATIVE_WINDOW_WIDTH, &width);
+ ASSERT_EQ(mDisplayWidth / 2, width);
+ int32_t height;
+ igbProducer->query(NATIVE_WINDOW_HEIGHT, &height);
+ ASSERT_EQ(mDisplayHeight / 2, height);
}
TEST_F(BLASTBufferQueueTest, SetNextTransaction) {