libgui: Add support for post-xform crops.
This change adds support for specifying a crop rectangle to a
SurfaceTextureClient that is in post-transformed coordinate space.
Change-Id: I247901de343e71b32850f7ae3bac62dfa612ad3d
Bug: 6299171
diff --git a/libs/gui/SurfaceTexture.cpp b/libs/gui/SurfaceTexture.cpp
index a6ca085..73f7c54 100644
--- a/libs/gui/SurfaceTexture.cpp
+++ b/libs/gui/SurfaceTexture.cpp
@@ -294,7 +294,6 @@
mCurrentTransform = item.mTransform;
mCurrentScalingMode = item.mScalingMode;
mCurrentTimestamp = item.mTimestamp;
- mCurrentActiveRect = item.mActiveRect;
computeCurrentTransformMatrix();
} else {
if (err < 0) {
@@ -534,8 +533,9 @@
}
sp<GraphicBuffer>& buf(mCurrentTextureBuf);
+ Rect cropRect = mCurrentCrop;
float tx, ty, sx, sy;
- if (!mCurrentCrop.isEmpty()) {
+ if (!cropRect.isEmpty()) {
// In order to prevent bilinear sampling at the of the crop rectangle we
// may need to shrink it by 2 texels in each direction. Normally this
// would just need to take 1/2 a texel off each end, but because the
@@ -552,14 +552,16 @@
// correct edge behavior.
const float shrinkAmount = 1.0f; // the amount that each edge is shrunk
- tx = (float(mCurrentCrop.left) + shrinkAmount) /
- float(buf->getWidth());
- ty = (float(buf->getHeight() - mCurrentCrop.bottom) +
- shrinkAmount) / float(buf->getHeight());
- sx = (float(mCurrentCrop.width()) - (2.0f * shrinkAmount)) /
- float(buf->getWidth());
- sy = (float(mCurrentCrop.height()) - (2.0f * shrinkAmount)) /
- float(buf->getHeight());
+ float bufferWidth = buf->getWidth();
+ float bufferHeight = buf->getHeight();
+
+ tx = (float(cropRect.left) + shrinkAmount) / bufferWidth;
+ ty = (float(bufferHeight - cropRect.bottom) + shrinkAmount) /
+ bufferHeight;
+ sx = (float(cropRect.width()) - (2.0f * shrinkAmount)) /
+ bufferWidth;
+ sy = (float(cropRect.height()) - (2.0f * shrinkAmount)) /
+ bufferHeight;
} else {
tx = 0.0f;
ty = 0.0f;
@@ -653,11 +655,6 @@
return outCrop;
}
-Rect SurfaceTexture::getCurrentActiveRect() const {
- Mutex::Autolock lock(mMutex);
- return mCurrentActiveRect;
-}
-
uint32_t SurfaceTexture::getCurrentTransform() const {
Mutex::Autolock lock(mMutex);
return mCurrentTransform;