aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2016-07-10 11:35:03 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-07-10 11:35:03 -0700
commit14dce6ed5934d7a6e1fac79f8e76e12f5670aae2 (patch)
tree12d660e3d38ed118faf4aa2635db4c52eed87627
parent4c42eebc55518019e6c2437e59adba28297221df (diff)
change mapRectScaleTranslate to pass args/ret by value
-rw-r--r--bench/MatrixBench.cpp2
-rw-r--r--include/core/SkMatrix.h2
-rw-r--r--src/core/SkCanvas.cpp13
-rw-r--r--src/core/SkMatrix.cpp11
-rw-r--r--src/utils/SkDeferredCanvas.cpp2
-rw-r--r--tests/MatrixTest.cpp2
6 files changed, 15 insertions, 17 deletions
diff --git a/bench/MatrixBench.cpp b/bench/MatrixBench.cpp
index 53e7296731..185ea7924c 100644
--- a/bench/MatrixBench.cpp
+++ b/bench/MatrixBench.cpp
@@ -320,7 +320,7 @@ public:
SkRect dst;
if (fScaleTrans) {
for (int i = 0; i < MEGA_LOOP; ++i) {
- fM.mapRectScaleTranslate(&dst, fR);
+ dst = fM.mapRectScaleTranslate(fR);
}
} else {
for (int i = 0; i < MEGA_LOOP; ++i) {
diff --git a/include/core/SkMatrix.h b/include/core/SkMatrix.h
index 5b22a77481..8f70d4c91b 100644
--- a/include/core/SkMatrix.h
+++ b/include/core/SkMatrix.h
@@ -565,7 +565,7 @@ public:
* Maps a rect to another rect, asserting (in debug mode) that the matrix only contains
* scale and translate elements. If it contains other elements, the results are undefined.
*/
- void mapRectScaleTranslate(SkRect* dst, const SkRect& src) const;
+ SkRect mapRectScaleTranslate(SkRect src) const;
/** Return the mean radius of a circle after it has been mapped by
this matrix. NOTE: in perspective this value assumes the circle
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 0ce97fff20..23442779ce 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -75,13 +75,11 @@ bool SkCanvas::wouldOverwriteEntireSurface(const SkRect* rect, const SkPaint* pa
}
if (rect) {
- if (!this->getTotalMatrix().isScaleTranslate()) {
+ const SkMatrix& ctm = this->getTotalMatrix();
+ if (!ctm.isScaleTranslate()) {
return false; // conservative
}
-
- SkRect devRect;
- this->getTotalMatrix().mapRectScaleTranslate(&devRect, *rect);
- if (!devRect.contains(bounds)) {
+ if (!ctm.mapRectScaleTranslate(*rect).contains(bounds)) {
return false;
}
}
@@ -1544,8 +1542,7 @@ void SkCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
// Check if we can quick-accept the clip call (and do nothing)
//
if (SkRegion::kIntersect_Op == op && !doAA && fMCRec->fMatrix.isScaleTranslate()) {
- SkRect devR;
- fMCRec->fMatrix.mapRectScaleTranslate(&devR, rect);
+ SkRect devR = fMCRec->fMatrix.mapRectScaleTranslate(rect);
// NOTE: this check is CTM specific, since we might round differently with a different
// CTM. Thus this is only 100% reliable if there is not global CTM scale to be
// applied later (i.e. if this is going into a picture).
@@ -1585,7 +1582,7 @@ void SkCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edg
const bool isScaleTrans = fMCRec->fMatrix.isScaleTranslate();
SkRect devR;
if (isScaleTrans) {
- fMCRec->fMatrix.mapRectScaleTranslate(&devR, rect);
+ devR = fMCRec->fMatrix.mapRectScaleTranslate(rect);
}
#ifndef SK_SUPPORT_PRECHECK_CLIPRECT
diff --git a/src/core/SkMatrix.cpp b/src/core/SkMatrix.cpp
index 492f3f6ac4..71ef24c5e8 100644
--- a/src/core/SkMatrix.cpp
+++ b/src/core/SkMatrix.cpp
@@ -1097,8 +1097,7 @@ void SkMatrix::mapVectors(SkPoint dst[], const SkPoint src[], int count) const {
}
}
-void SkMatrix::mapRectScaleTranslate(SkRect* dst, const SkRect& src) const {
- SkASSERT(dst);
+SkRect SkMatrix::mapRectScaleTranslate(SkRect src) const {
SkASSERT(this->isScaleTranslate());
SkScalar sx = fMat[kMScaleX];
@@ -1107,7 +1106,7 @@ void SkMatrix::mapRectScaleTranslate(SkRect* dst, const SkRect& src) const {
SkScalar ty = fMat[kMTransY];
Sk4f scale(sx, sy, sx, sy);
Sk4f trans(tx, ty, tx, ty);
-
+
Sk4f ltrb = Sk4f::Load(&src.fLeft) * scale + trans;
// need to sort so we're not inverted
Sk4f rblt(ltrb[2], ltrb[3], ltrb[0], ltrb[1]);
@@ -1115,14 +1114,16 @@ void SkMatrix::mapRectScaleTranslate(SkRect* dst, const SkRect& src) const {
Sk4f max = Sk4f::Max(ltrb, rblt);
// We can extract either pair [0,1] or [2,3] from min and max and be correct, but on
// ARM this sequence generates the fastest (a single instruction).
- Sk4f(min[2], min[3], max[0], max[1]).store(&dst->fLeft);
+ SkRect dst;
+ Sk4f(min[0], min[1], max[0], max[1]).store(&dst.fLeft);
+ return dst;
}
bool SkMatrix::mapRect(SkRect* dst, const SkRect& src) const {
SkASSERT(dst);
if (this->isScaleTranslate()) {
- this->mapRectScaleTranslate(dst, src);
+ *dst = this->mapRectScaleTranslate(src);
return true;
} else {
SkPoint quad[4];
diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp
index 14220209cc..c8a37c36b7 100644
--- a/src/utils/SkDeferredCanvas.cpp
+++ b/src/utils/SkDeferredCanvas.cpp
@@ -200,7 +200,7 @@ void SkDeferredCanvas::flush_check(SkRect* bounds, const SkPaint* paint, unsigne
if (canScale) {
SkMatrix m;
rec.getConcat(&m);
- m.mapRectScaleTranslate(bounds, *bounds);
+ *bounds = m.mapRectScaleTranslate(*bounds);
} else {
goto STOP;
}
diff --git a/tests/MatrixTest.cpp b/tests/MatrixTest.cpp
index c4eb9c7011..4386c5f491 100644
--- a/tests/MatrixTest.cpp
+++ b/tests/MatrixTest.cpp
@@ -978,7 +978,7 @@ DEF_TEST(Matrix_maprects, r) {
mat.mapPoints((SkPoint*)&dst[0].fLeft, (SkPoint*)&src.fLeft, 2);
dst[0].sort();
mat.mapRect(&dst[1], src);
- mat.mapRectScaleTranslate(&dst[2], src);
+ dst[2] = mat.mapRectScaleTranslate(src);
REPORTER_ASSERT(r, dst[0] == dst[1]);
REPORTER_ASSERT(r, dst[0] == dst[2]);