diff options
author | 2016-03-09 16:03:21 -0800 | |
---|---|---|
committer | 2016-03-09 16:14:35 -0800 | |
commit | 034a10bf216cdef251928edf72d93668d81515f8 (patch) | |
tree | 792bdea747fb449853488748c51fe0d1db1e4d76 | |
parent | a521c4a9fae31a1d51e80b2312c7e2a0b03908a9 (diff) |
Partial revert of 261725fdb2962271c222a049fcdf57bbdc8363c7
Bug:27534946
Mapping empty rects still must be done to get correct positions for
line/point rects describing strokable bounds.
Change-Id: I2f9efe543e58eb438b755276585491c1256d6719
-rw-r--r-- | libs/hwui/Matrix.cpp | 10 | ||||
-rw-r--r-- | libs/hwui/Rect.h | 3 | ||||
-rw-r--r-- | libs/hwui/tests/unit/MatrixTests.cpp | 29 |
3 files changed, 33 insertions, 9 deletions
diff --git a/libs/hwui/Matrix.cpp b/libs/hwui/Matrix.cpp index deab95690d0e..709156c4098b 100644 --- a/libs/hwui/Matrix.cpp +++ b/libs/hwui/Matrix.cpp @@ -437,8 +437,16 @@ void Matrix4::mapPoint(float& x, float& y) const { y = dy * dz; } +/** + * Set the contents of the rect to be the bounding rect around each of the corners, mapped by the + * matrix. + * + * NOTE: an empty rect to an arbitrary matrix isn't guaranteed to have an empty output, since that's + * important for conservative bounds estimation (e.g. rotate45Matrix.mapRect of Rect(0, 10) should + * result in non-empty. + */ void Matrix4::mapRect(Rect& r) const { - if (isIdentity() || r.isEmpty()) return; + if (isIdentity()) return; if (isSimple()) { MUL_ADD_STORE(r.left, data[kScaleX], data[kTranslateX]); diff --git a/libs/hwui/Rect.h b/libs/hwui/Rect.h index d9fce9b2c824..de4fa55bb508 100644 --- a/libs/hwui/Rect.h +++ b/libs/hwui/Rect.h @@ -286,7 +286,8 @@ public: friend std::ostream& operator<<(std::ostream& os, const Rect& rect) { if (rect.isEmpty()) { - return os << "empty"; + // Print empty, but continue, since empty rects may still have useful coordinate info + os << "(empty)"; } if (rect.left == 0 && rect.top == 0) { diff --git a/libs/hwui/tests/unit/MatrixTests.cpp b/libs/hwui/tests/unit/MatrixTests.cpp index da2263788c25..eddab878a49d 100644 --- a/libs/hwui/tests/unit/MatrixTests.cpp +++ b/libs/hwui/tests/unit/MatrixTests.cpp @@ -21,15 +21,30 @@ using namespace android::uirenderer; -TEST(Matrix, mapRect) { +TEST(Matrix, mapRect_emptyScaleSkew) { // Skew, so we don't hit identity/translate/simple fast paths - Matrix4 matrix; - matrix.skew(0.1f, 0.1f); + Matrix4 scaleMatrix; + scaleMatrix.loadScale(10, 10, 1); + scaleMatrix.skew(0.1f, 0.1f); // non-zero empty rect, so sorting x/y would make rect non-empty - Rect empty(100, 100, -100, -100); + Rect empty(15, 20, 15, 100); ASSERT_TRUE(empty.isEmpty()); - matrix.mapRect(empty); - EXPECT_TRUE(empty.isEmpty()) - << "Empty rect should always remain empty, regardless of mapping."; + scaleMatrix.mapRect(empty); + EXPECT_EQ(Rect(170, 215, 250, 1015), empty); + EXPECT_FALSE(empty.isEmpty()) + << "Empty 'line' rect doesn't remain empty when skewed."; +} + +TEST(Matrix, mapRect_emptyRotate) { + // Skew, so we don't hit identity/translate/simple fast paths + Matrix4 skewMatrix; + skewMatrix.loadRotate(45); + + // non-zero empty rect, so sorting x/y would make rect non-empty + Rect lineRect(0, 100); + ASSERT_TRUE(lineRect.isEmpty()); + skewMatrix.mapRect(lineRect); + EXPECT_FALSE(lineRect.isEmpty()) + << "Empty 'line' rect doesn't remain empty when rotated."; } |