diff options
author | 2016-08-24 04:22:08 -0700 | |
---|---|---|
committer | 2016-08-24 04:22:08 -0700 | |
commit | 6a88206b2ece8b64534c87fca156e5fe161f884e (patch) | |
tree | 340348c99fcd4b8f04153beb00b6645648553da5 | |
parent | 9dc6cf6b8833d36c29a23d2519989b069745fcd5 (diff) |
combine setRectFan and mapRect
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2276603002
Review-Url: https://codereview.chromium.org/2276603002
-rw-r--r-- | src/core/SkMatrixPriv.h | 32 | ||||
-rw-r--r-- | src/gpu/GrQuad.h | 4 |
2 files changed, 34 insertions, 2 deletions
diff --git a/src/core/SkMatrixPriv.h b/src/core/SkMatrixPriv.h index 91185f08d1..844901c011 100644 --- a/src/core/SkMatrixPriv.h +++ b/src/core/SkMatrixPriv.h @@ -65,6 +65,38 @@ public: pts = (SkPoint*)((intptr_t)pts + stride); } } + + static void SetMappedRectFan(const SkMatrix& mx, const SkRect& rect, SkPoint quad[4]) { + SkMatrix::TypeMask tm = mx.getType(); + SkScalar l = rect.fLeft; + SkScalar t = rect.fTop; + SkScalar r = rect.fRight; + SkScalar b = rect.fBottom; + if (tm <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask)) { + const SkScalar tx = mx.getTranslateX(); + const SkScalar ty = mx.getTranslateY(); + if (tm <= SkMatrix::kTranslate_Mask) { + l += tx; + t += ty; + r += tx; + b += ty; + } else { + const SkScalar sx = mx.getScaleX(); + const SkScalar sy = mx.getScaleY(); + l = sx * l + tx; + t = sy * t + ty; + r = sx * r + tx; + b = sy * b + ty; + } + quad[0].set(l, t); + quad[1].set(l, b); + quad[2].set(r, b); + quad[3].set(r, t); + } else { + quad[0].setRectFan(l, t, r, b); + mx.mapPoints(quad, quad, 4); + } + } }; #endif diff --git a/src/gpu/GrQuad.h b/src/gpu/GrQuad.h index 9a8d1f3a4a..3a202c61cb 100644 --- a/src/gpu/GrQuad.h +++ b/src/gpu/GrQuad.h @@ -10,6 +10,7 @@ #include "SkPoint.h" #include "SkMatrix.h" +#include "SkMatrixPriv.h" /** * GrQuad is a collection of 4 points which can be used to represent an arbitrary quadrilateral @@ -35,8 +36,7 @@ public: } void setFromMappedRect(const SkRect& rect, const SkMatrix& matrix) { - this->set(rect); - matrix.mapPoints(fPoints, kNumPoints); + SkMatrixPriv::SetMappedRectFan(matrix, rect, fPoints); } const GrQuad& operator=(const GrQuad& that) { |