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
diff --git a/services/surfaceflinger/BufferStateLayer.cpp b/services/surfaceflinger/BufferStateLayer.cpp
index ac2edbe..a2915c9 100644
--- a/services/surfaceflinger/BufferStateLayer.cpp
+++ b/services/surfaceflinger/BufferStateLayer.cpp
@@ -790,7 +790,7 @@
mBufferInfo.mFence = s.acquireFence;
mBufferInfo.mTransform = s.bufferTransform;
mBufferInfo.mDataspace = translateDataspace(s.dataspace);
- mBufferInfo.mCrop = computeCrop(s);
+ mBufferInfo.mCrop = computeBufferCrop(s);
mBufferInfo.mScaleMode = NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW;
mBufferInfo.mSurfaceDamage = s.surfaceDamageRegion;
mBufferInfo.mHdrMetadata = s.hdrMetadata;
@@ -803,27 +803,11 @@
return NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW;
}
-Rect BufferStateLayer::computeCrop(const State& s) {
- if (s.crop.isEmpty() && s.buffer) {
+Rect BufferStateLayer::computeBufferCrop(const State& s) {
+ if (s.buffer) {
return s.buffer->getBuffer()->getBounds();
- } else if (s.buffer) {
- Rect crop = s.crop;
- crop.left = std::max(crop.left, 0);
- crop.top = std::max(crop.top, 0);
- uint32_t bufferWidth = s.buffer->getBuffer()->getWidth();
- uint32_t bufferHeight = s.buffer->getBuffer()->getHeight();
- if (bufferHeight <= std::numeric_limits<int32_t>::max() &&
- bufferWidth <= std::numeric_limits<int32_t>::max()) {
- crop.right = std::min(crop.right, static_cast<int32_t>(bufferWidth));
- crop.bottom = std::min(crop.bottom, static_cast<int32_t>(bufferHeight));
- }
- if (!crop.isValid()) {
- // Crop rect is out of bounds, return whole buffer
- return s.buffer->getBuffer()->getBounds();
- }
- return crop;
}
- return s.crop;
+ return Rect::INVALID_RECT;
}
sp<Layer> BufferStateLayer::createClone() {