From 5cc9ac0ab36848468100353fc31a42cf0753b9e4 Mon Sep 17 00:00:00 2001 From: Vishnu Nair Date: Mon, 19 Apr 2021 13:23:38 -0700 Subject: Fix crop scaling with BSL With BQL, each layer had a concept of buffer space and layer space. The caller could set a buffer crop and a layer crop. The buffer crop would be applied in buffer space and the content would be scaled to the buffer size. Then the scaled content would then be scaled again to the layer size (also referred to as the window size). With BSL we do not have a concept of buffer space and layer space. So we should not set a buffer/content crop otherwise this might result in incorrect scaling or cropping. To fix this, in BBQ, when calculating the scale, use the buffer crop provided by the client and in SurfaceFlinger, instead of setting a buffer crop only set the layer crop. The buffer crop/content crop can be cleaned up once BQL is removed. Test: BLASTBufferQueueTest (cropped buffer scales to buffer and window size) Test: 720p content in android tv is not cropped incorrectly Bug: 178622186 Change-Id: I173df901120a43f397f6d623a7e7b93537a508e2 --- libs/gui/BLASTBufferQueue.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'libs/gui/BLASTBufferQueue.cpp') diff --git a/libs/gui/BLASTBufferQueue.cpp b/libs/gui/BLASTBufferQueue.cpp index e3b59b2584..65c893af99 100644 --- a/libs/gui/BLASTBufferQueue.cpp +++ b/libs/gui/BLASTBufferQueue.cpp @@ -186,6 +186,7 @@ BLASTBufferQueue::~BLASTBufferQueue() { void BLASTBufferQueue::update(const sp& surface, uint32_t width, uint32_t height, int32_t format) { std::unique_lock _lock{mMutex}; + BQA_LOGV("update width=%d height=%d format=%d", width, height, format); if (mFormat != format) { mFormat = format; mBufferItemConsumer->setDefaultBufferFormat(convertBufferFormat(format)); @@ -377,10 +378,11 @@ void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) { // Ensure BLASTBufferQueue stays alive until we receive the transaction complete callback. incStrong((void*)transactionCallbackThunk); + Rect crop = computeCrop(bufferItem); mLastAcquiredFrameNumber = bufferItem.mFrameNumber; mLastBufferInfo.update(true /* hasBuffer */, bufferItem.mGraphicBuffer->getWidth(), bufferItem.mGraphicBuffer->getHeight(), bufferItem.mTransform, - bufferItem.mScalingMode); + bufferItem.mScalingMode, crop); auto releaseBufferCallback = std::bind(releaseBufferCallbackThunk, wp(this) /* callbackContext */, @@ -394,7 +396,7 @@ void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) { t->addTransactionCompletedCallback(transactionCallbackThunk, static_cast(this)); setMatrix(t, mLastBufferInfo); - t->setCrop(mSurfaceControl, computeCrop(bufferItem)); + t->setCrop(mSurfaceControl, crop); t->setTransform(mSurfaceControl, bufferItem.mTransform); t->setTransformToDisplayInverse(mSurfaceControl, bufferItem.mTransformToDisplayInverse); if (!bufferItem.mIsAutoTimestamp) { @@ -522,13 +524,15 @@ bool BLASTBufferQueue::rejectBuffer(const BufferItem& item) { void BLASTBufferQueue::setMatrix(SurfaceComposerClient::Transaction* t, const BufferInfo& bufferInfo) { - uint32_t bufWidth = bufferInfo.width; - uint32_t bufHeight = bufferInfo.height; + uint32_t bufWidth = bufferInfo.crop.getWidth(); + uint32_t bufHeight = bufferInfo.crop.getHeight(); - float dsdx = mSize.width / static_cast(bufWidth); - float dsdy = mSize.height / static_cast(bufHeight); + float sx = mSize.width / static_cast(bufWidth); + float sy = mSize.height / static_cast(bufHeight); - t->setMatrix(mSurfaceControl, dsdx, 0, 0, dsdy); + t->setMatrix(mSurfaceControl, sx, 0, 0, sy); + // Update position based on crop. + t->setPosition(mSurfaceControl, bufferInfo.crop.left * sx * -1, bufferInfo.crop.top * sy * -1); } void BLASTBufferQueue::setTransactionCompleteCallback( -- cgit v1.2.3-59-g8ed1b