Chromium Code Reviews| Index: src/core/SkRRect.cpp |
| diff --git a/src/core/SkRRect.cpp b/src/core/SkRRect.cpp |
| index 75af106b7b6eaf81183ce1b977afa27231577aa3..be3f0539f25f3c6f64689aeed8577c33bd20ab5c 100644 |
| --- a/src/core/SkRRect.cpp |
| +++ b/src/core/SkRRect.cpp |
| @@ -6,6 +6,7 @@ |
| */ |
| #include "SkRRect.h" |
| +#include "SkMatrix.h" |
| /////////////////////////////////////////////////////////////////////////////// |
| @@ -254,6 +255,49 @@ void SkRRect::computeType() const { |
| fType = kComplex_Type; |
| } |
| +static bool matrix_only_scale_and_translate(const SkMatrix& matrix) { |
| + const SkMatrix::TypeMask m = (SkMatrix::TypeMask) (SkMatrix::kAffine_Mask |
| + | SkMatrix::kPerspective_Mask); |
| + return (matrix.getType() & m) == 0; |
| +} |
| + |
| +bool SkRRect::transform(const SkMatrix& matrix, SkRRect* dst) const { |
|
robertphillips
2013/10/30 23:55:02
This seems like a complete abrogation of the const
scroggo
2013/10/31 17:40:35
Agreed. This is to be consistent with SkPath::tran
|
| + if (NULL == dst) { |
| + dst = const_cast<SkRRect*>(this); |
| + } |
| + |
| + if (matrix.isIdentity()) { |
| + *dst = *this; |
| + return true; |
| + } |
| + |
| + if (!matrix_only_scale_and_translate(matrix)) { |
| + return false; |
| + } |
| + |
| + SkRect newRect; |
| + if (!matrix.mapRect(&newRect, fRect)) { |
| + return false; |
| + } |
| + |
|
robertphillips
2013/10/30 23:55:02
Will this do the right thing if the matrix is a re
scroggo
2013/10/31 17:40:35
No. Fixed.
|
| + // Now scale each corner |
| + SkScalar xScale = matrix.getScaleX(); |
| + if (xScale < 0) { |
| + xScale = -xScale; |
| + } |
| + SkScalar yScale = matrix.getScaleY(); |
| + if (yScale < 0) { |
| + yScale = -yScale; |
| + } |
|
robertphillips
2013/10/30 23:55:02
Do we actually need "radii" here? Can't we do this
scroggo
2013/10/31 17:40:35
Done.
|
| + SkVector radii[4]; |
| + for (int i = 0; i < 4; ++i) { |
| + radii[i].fX = fRadii[i].fX * xScale; |
| + radii[i].fY = fRadii[i].fY * yScale; |
| + } |
| + dst->setRectRadii(newRect, radii); |
| + return true; |
| +} |
| + |
| /////////////////////////////////////////////////////////////////////////////// |
| void SkRRect::inset(SkScalar dx, SkScalar dy, SkRRect* dst) const { |