Change SkMatrix::fixedStepInX to return SkVector (of SkScalar) rather than SkFixed.

All users were immediately converting to SkScalar or SkFixed3232.

This method is not used in Chromium, Android, or Google3.

BUG=skia:4632
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1692013002

Review URL: https://codereview.chromium.org/1692013002
This commit is contained in:
benjaminwagner 2016-02-16 10:09:40 -08:00 committed by Commit bot
parent e71dc3fd0d
commit 8e17556349
7 changed files with 33 additions and 47 deletions

View File

@ -591,11 +591,16 @@ public:
return GetMapPtsProc(this->getType());
}
/** If the matrix can be stepped in X (not complex perspective)
then return true and if step[XY] is not null, return the step[XY] value.
If it cannot, return false and ignore step.
/** Returns true if the matrix can be stepped in X (not complex
perspective).
*/
bool fixedStepInX(SkScalar y, SkFixed* stepX, SkFixed* stepY) const;
bool isFixedStepInX() const;
/** If the matrix can be stepped in X (not complex perspective)
then return the step value.
If it cannot, behavior is undefined.
*/
SkVector fixedStepInX(SkScalar y) const;
/** Efficient comparison of two matrices. It distinguishes between zero and
* negative zero. It will return false when the sign of zero values is the

View File

@ -1150,30 +1150,19 @@ const SkMatrix::MapXYProc SkMatrix::gMapXYProcs[] = {
// if its nearly zero (just made up 26, perhaps it should be bigger or smaller)
#define PerspNearlyZero(x) SkScalarNearlyZero(x, (1.0f / (1 << 26)))
bool SkMatrix::fixedStepInX(SkScalar y, SkFixed* stepX, SkFixed* stepY) const {
if (PerspNearlyZero(fMat[kMPersp0])) {
if (stepX || stepY) {
if (PerspNearlyZero(fMat[kMPersp1]) &&
PerspNearlyZero(fMat[kMPersp2] - 1)) {
if (stepX) {
*stepX = SkScalarToFixed(fMat[kMScaleX]);
}
if (stepY) {
*stepY = SkScalarToFixed(fMat[kMSkewY]);
}
} else {
SkScalar z = y * fMat[kMPersp1] + fMat[kMPersp2];
if (stepX) {
*stepX = SkScalarToFixed(fMat[kMScaleX] / z);
}
if (stepY) {
*stepY = SkScalarToFixed(fMat[kMSkewY] / z);
}
}
}
return true;
bool SkMatrix::isFixedStepInX() const {
return PerspNearlyZero(fMat[kMPersp0]);
}
SkVector SkMatrix::fixedStepInX(SkScalar y) const {
SkASSERT(PerspNearlyZero(fMat[kMPersp0]));
if (PerspNearlyZero(fMat[kMPersp1]) &&
PerspNearlyZero(fMat[kMPersp2] - 1)) {
return SkVector::Make(fMat[kMScaleX], fMat[kMSkewY]);
} else {
SkScalar z = y * fMat[kMPersp1] + fMat[kMPersp2];
return SkVector::Make(fMat[kMScaleX] / z, fMat[kMSkewY] / z);
}
return false;
}
///////////////////////////////////////////////////////////////////////////////
@ -1800,4 +1789,3 @@ void SkRSXform::toQuad(SkScalar width, SkScalar height, SkPoint quad[4]) const {
quad[3].set(m01 * height + m02, m11 * height + m12);
#endif
}

View File

@ -201,7 +201,7 @@ SkShader::Context::MatrixClass SkShader::Context::ComputeMatrixClass(const SkMat
MatrixClass mc = kLinear_MatrixClass;
if (mat.hasPerspective()) {
if (mat.fixedStepInX(0, nullptr, nullptr)) {
if (mat.isFixedStepInX()) {
mc = kFixedStepInX_MatrixClass;
} else {
mc = kPerspective_MatrixClass;

View File

@ -287,10 +287,9 @@ void SkLinearGradient::LinearGradientContext::shadeSpan(int x, int y, SkPMColor*
SkGradFixed dx, fx = SkScalarToGradFixed(srcPt.fX);
if (fDstToIndexClass == kFixedStepInX_MatrixClass) {
SkFixed dxStorage[1];
(void)fDstToIndex.fixedStepInX(SkIntToScalar(y), dxStorage, nullptr);
const auto step = fDstToIndex.fixedStepInX(SkIntToScalar(y));
// todo: do we need a real/high-precision value for dx here?
dx = SkFixedToGradFixed(dxStorage[0]);
dx = SkScalarToGradFixed(step.fX);
} else {
SkASSERT(fDstToIndexClass == kLinear_MatrixClass);
dx = SkScalarToGradFixed(fDstToIndex.getScaleX());
@ -747,4 +746,3 @@ void SkLinearGradient::LinearGradientContext::shade4_clamp(int x, int y, SkPMCol
}
}
}

View File

@ -206,11 +206,9 @@ void SkRadialGradient::RadialGradientContext::shadeSpan(int x, int y,
SkScalar sdy = fDstToIndex.getSkewY();
if (fDstToIndexClass == kFixedStepInX_MatrixClass) {
SkFixed storage[2];
(void)fDstToIndex.fixedStepInX(SkIntToScalar(y),
&storage[0], &storage[1]);
sdx = SkFixedToScalar(storage[0]);
sdy = SkFixedToScalar(storage[1]);
const auto step = fDstToIndex.fixedStepInX(SkIntToScalar(y));
sdx = step.fX;
sdy = step.fY;
} else {
SkASSERT(fDstToIndexClass == kLinear_MatrixClass);
}

View File

@ -92,11 +92,9 @@ void SkSweepGradient::SweepGradientContext::shadeSpan(int x, int y, SkPMColor* S
SkScalar dy, fy = srcPt.fY;
if (fDstToIndexClass == kFixedStepInX_MatrixClass) {
SkFixed storage[2];
(void)matrix.fixedStepInX(SkIntToScalar(y) + SK_ScalarHalf,
&storage[0], &storage[1]);
dx = SkFixedToScalar(storage[0]);
dy = SkFixedToScalar(storage[1]);
const auto step = matrix.fixedStepInX(SkIntToScalar(y) + SK_ScalarHalf);
dx = step.fX;
dy = step.fY;
} else {
SkASSERT(fDstToIndexClass == kLinear_MatrixClass);
dx = matrix.getScaleX();

View File

@ -261,10 +261,9 @@ void SkTwoPointConicalGradient::TwoPointConicalGradientContext::shadeSpan(
SkScalar dy, fy = srcPt.fY;
if (fDstToIndexClass == kFixedStepInX_MatrixClass) {
SkFixed fixedX, fixedY;
(void)fDstToIndex.fixedStepInX(SkIntToScalar(y), &fixedX, &fixedY);
dx = SkFixedToScalar(fixedX);
dy = SkFixedToScalar(fixedY);
const auto step = fDstToIndex.fixedStepInX(SkIntToScalar(y));
dx = step.fX;
dy = step.fY;
} else {
SkASSERT(fDstToIndexClass == kLinear_MatrixClass);
dx = fDstToIndex.getScaleX();