combine setRectFan and mapRect

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2276603002

Review-Url: https://codereview.chromium.org/2276603002
This commit is contained in:
reed 2016-08-24 04:22:08 -07:00 committed by Commit bot
parent 9dc6cf6b88
commit 6a88206b2e
2 changed files with 34 additions and 2 deletions

View File

@ -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

View File

@ -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) {