Add clamp to Layer and update Transform inverse.

Ensure that the adjusted transparent region is within
the display bounds by clamping after the transformation
is applied and clean up transform's inverse function.

Bug: 18452546

Change-Id: Ia473e483ee8374177bcb84d8192eb1f0e86f022a
This commit is contained in:
Michael Lentine 2014-11-19 18:32:37 -08:00
parent 6b9454d1fe
commit 28ea217ff4
2 changed files with 28 additions and 16 deletions

View File

@ -332,8 +332,12 @@ FloatRect Layer::computeCrop(const sp<const DisplayDevice>& hw) const {
activeCrop.intersect(hw->getViewport(), &activeCrop); activeCrop.intersect(hw->getViewport(), &activeCrop);
activeCrop = s.transform.inverse().transform(activeCrop); activeCrop = s.transform.inverse().transform(activeCrop);
// paranoia: make sure the window-crop is constrained in the // This needs to be here as transform.transform(Rect) computes the
// window's bounds // transformed rect and then takes the bounding box of the result before
// returning. This means
// transform.inverse().transform(transform.transform(Rect)) != Rect
// in which case we need to make sure the final rect is clipped to the
// display bounds.
activeCrop.intersect(Rect(s.active.w, s.active.h), &activeCrop); activeCrop.intersect(Rect(s.active.w, s.active.h), &activeCrop);
// subtract the transparent region and snap to the bounds // subtract the transparent region and snap to the bounds
@ -432,6 +436,13 @@ void Layer::setGeometry(
activeCrop = s.transform.transform(activeCrop); activeCrop = s.transform.transform(activeCrop);
activeCrop.intersect(hw->getViewport(), &activeCrop); activeCrop.intersect(hw->getViewport(), &activeCrop);
activeCrop = s.transform.inverse().transform(activeCrop); activeCrop = s.transform.inverse().transform(activeCrop);
// This needs to be here as transform.transform(Rect) computes the
// transformed rect and then takes the bounding box of the result before
// returning. This means
// transform.inverse().transform(transform.transform(Rect)) != Rect
// in which case we need to make sure the final rect is clipped to the
// display bounds.
activeCrop.intersect(Rect(s.active.w, s.active.h), &activeCrop);
// mark regions outside the crop as transparent // mark regions outside the crop as transparent
activeTransparentRegion.orSelf(Rect(0, 0, s.active.w, activeCrop.top)); activeTransparentRegion.orSelf(Rect(0, 0, s.active.w, activeCrop.top));
activeTransparentRegion.orSelf(Rect(0, activeCrop.bottom, activeTransparentRegion.orSelf(Rect(0, activeCrop.bottom,

View File

@ -301,16 +301,16 @@ Transform Transform::inverse() const {
// (T*M)^-1 = M^-1 * T^-1 // (T*M)^-1 = M^-1 * T^-1
Transform result; Transform result;
if (mType <= TRANSLATE) { if (mType <= TRANSLATE) {
// 1 0 x // 1 0 0
// 0 1 y // 0 1 0
// 0 0 1 // x y 1
result = *this; result = *this;
result.mMatrix[2][0] = -result.mMatrix[2][0]; result.mMatrix[2][0] = -result.mMatrix[2][0];
result.mMatrix[2][1] = -result.mMatrix[2][1]; result.mMatrix[2][1] = -result.mMatrix[2][1];
} else { } else {
// a c x // a c 0
// b d y // b d 0
// 0 0 1 // x y 1
const mat33& M(mMatrix); const mat33& M(mMatrix);
const float a = M[0][0]; const float a = M[0][0];
const float b = M[1][0]; const float b = M[1][0];
@ -319,16 +319,17 @@ Transform Transform::inverse() const {
const float x = M[2][0]; const float x = M[2][0];
const float y = M[2][1]; const float y = M[2][1];
Transform R, T;
const float idet = 1.0 / (a*d - b*c); const float idet = 1.0 / (a*d - b*c);
R.mMatrix[0][0] = d*idet; R.mMatrix[0][1] = -c*idet; result.mMatrix[0][0] = d*idet;
R.mMatrix[1][0] = -b*idet; R.mMatrix[1][1] = a*idet; result.mMatrix[0][1] = -c*idet;
R.mType = mType &= ~TRANSLATE; result.mMatrix[1][0] = -b*idet;
result.mMatrix[1][1] = a*idet;
result.mType = mType;
T.mMatrix[2][0] = -x; vec2 T(-x, -y);
T.mMatrix[2][1] = -y; T = result.transform(T);
T.mType = TRANSLATE; result.mMatrix[2][0] = T[0];
result = R * T; result.mMatrix[2][1] = T[1];
} }
return result; return result;
} }