diff options
author | 2022-07-06 19:18:34 +0000 | |
---|---|---|
committer | 2022-07-06 19:18:34 +0000 | |
commit | ab91a3108d5807b1399b556f5601f0cac44dbd89 (patch) | |
tree | 79954f762bea1ec6095781ab3f6338a115d512ea /libs/hwui/Readback.cpp | |
parent | 5e696dbcb01befb494f50265697840dde6928d22 (diff) | |
parent | 79f7066a466329bc131af3b100c559587ca8704e (diff) |
Merge "PixelCopy: align with legacy GLConsumer::computeTransformMatrix" am: 178f91656b am: 031b2963f1 am: ab99d914c5 am: 4ee48e14af am: 79f7066a46
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2144501
Change-Id: I4ea6a13d0205b8c6d9f46ea74c7776584bcd5dcd
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'libs/hwui/Readback.cpp')
-rw-r--r-- | libs/hwui/Readback.cpp | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/libs/hwui/Readback.cpp b/libs/hwui/Readback.cpp index 79953aa6adc9..1191b92a0aeb 100644 --- a/libs/hwui/Readback.cpp +++ b/libs/hwui/Readback.cpp @@ -102,11 +102,36 @@ CopyResult Readback::copySurfaceInto(ANativeWindow* window, const Rect& inSrcRec SkRect srcRect = inSrcRect.toSkRect(); - SkRect imageSrcRect = - SkRect::MakeLTRB(cropRect.left, cropRect.top, cropRect.right, cropRect.bottom); - if (imageSrcRect.isEmpty()) { - imageSrcRect = SkRect::MakeIWH(description.width, description.height); + SkRect imageSrcRect = SkRect::MakeIWH(description.width, description.height); + SkISize imageWH = SkISize::Make(description.width, description.height); + if (cropRect.left < cropRect.right && cropRect.top < cropRect.bottom) { + imageSrcRect = + SkRect::MakeLTRB(cropRect.left, cropRect.top, cropRect.right, cropRect.bottom); + imageWH = SkISize::Make(cropRect.right - cropRect.left, cropRect.bottom - cropRect.top); + + // Chroma channels of YUV420 images are subsampled we may need to shrink the crop region by + // a whole texel on each side. Since skia still adds its own 0.5 inset, we apply an + // additional 0.5 inset. See GLConsumer::computeTransformMatrix for details. + float shrinkAmount = 0.0f; + switch (description.format) { + // Use HAL formats since some AHB formats are only available in vndk + case HAL_PIXEL_FORMAT_YCBCR_420_888: + case HAL_PIXEL_FORMAT_YV12: + case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: + shrinkAmount = 0.5f; + break; + default: + break; + } + + // Shrink the crop if it has more than 1-px and differs from the buffer size. + if (imageWH.width() > 1 && imageWH.width() < (int32_t)description.width) + imageSrcRect = imageSrcRect.makeInset(shrinkAmount, 0); + + if (imageWH.height() > 1 && imageWH.height() < (int32_t)description.height) + imageSrcRect = imageSrcRect.makeInset(0, shrinkAmount); } + ALOGV("imageSrcRect = " RECT_STRING, SK_RECT_ARGS(imageSrcRect)); // Represents the "logical" width/height of the texture. That is, the dimensions of the buffer @@ -165,7 +190,7 @@ CopyResult Readback::copySurfaceInto(ANativeWindow* window, const Rect& inSrcRec */ SkMatrix m; - const SkRect imageDstRect = SkRect::MakeIWH(imageSrcRect.width(), imageSrcRect.height()); + const SkRect imageDstRect = SkRect::Make(imageWH); const float px = imageDstRect.centerX(); const float py = imageDstRect.centerY(); if (windowTransform & NATIVE_WINDOW_TRANSFORM_FLIP_H) { |