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
diff --git a/include/core/SkMatrix.h b/include/core/SkMatrix.h
index 0ebe328..adebada 100644
--- a/include/core/SkMatrix.h
+++ b/include/core/SkMatrix.h
@@ -591,11 +591,16 @@
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
diff --git a/src/core/SkMatrix.cpp b/src/core/SkMatrix.cpp
index 7ae4ed2..f60ce85 100644
--- a/src/core/SkMatrix.cpp
+++ b/src/core/SkMatrix.cpp
@@ -1150,30 +1150,19 @@
// 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 @@
quad[3].set(m01 * height + m02, m11 * height + m12);
#endif
}
-
diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp
index 4b5dc5d..20402a9 100644
--- a/src/core/SkShader.cpp
+++ b/src/core/SkShader.cpp
@@ -201,7 +201,7 @@
MatrixClass mc = kLinear_MatrixClass;
if (mat.hasPerspective()) {
- if (mat.fixedStepInX(0, nullptr, nullptr)) {
+ if (mat.isFixedStepInX()) {
mc = kFixedStepInX_MatrixClass;
} else {
mc = kPerspective_MatrixClass;
diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp
index 4a27a35..a1abe54 100644
--- a/src/effects/gradients/SkLinearGradient.cpp
+++ b/src/effects/gradients/SkLinearGradient.cpp
@@ -287,10 +287,9 @@
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 @@
}
}
}
-
diff --git a/src/effects/gradients/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp
index 7e7ac7a..020c25e 100644
--- a/src/effects/gradients/SkRadialGradient.cpp
+++ b/src/effects/gradients/SkRadialGradient.cpp
@@ -206,11 +206,9 @@
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);
}
diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp
index ddff882..9468652 100644
--- a/src/effects/gradients/SkSweepGradient.cpp
+++ b/src/effects/gradients/SkSweepGradient.cpp
@@ -92,11 +92,9 @@
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();
diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp
index 918f2e0..b7c95bc 100644
--- a/src/effects/gradients/SkTwoPointConicalGradient.cpp
+++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp
@@ -261,10 +261,9 @@
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();