Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Unified Diff: src/core/SkRRect.cpp

Issue 52703003: Add SkRRect::transform. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« include/core/SkRRect.h ('K') | « include/core/SkRRect.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {
« include/core/SkRRect.h ('K') | « include/core/SkRRect.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698