aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-02-04 11:04:26 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-02-06 15:12:41 +0000
commita99b6ceff92183b424634f2e7276b9ea1d59e69d (patch)
tree64c99a642565c74e7aac703f07b8669825c90d40
parentadacaef799455013bf00b85a43237ac8d9471ade (diff)
start removing uses of SkScalarMul
BUG=skia:6197 Change-Id: Ic444c7ee4ca547f483dc8232dcacd6d4ba87d913 Reviewed-on: https://skia-review.googlesource.com/8041 Reviewed-by: Cary Clark <caryclark@google.com> Commit-Queue: Mike Reed <reed@google.com>
-rw-r--r--src/core/SkBlurImageFilter.cpp6
-rw-r--r--src/core/SkCanvas.cpp10
-rw-r--r--src/core/SkDevice.cpp3
-rw-r--r--src/core/SkDraw.cpp4
-rw-r--r--src/core/SkGpuBlurUtils.cpp8
-rw-r--r--src/core/SkMatrix.cpp16
-rw-r--r--src/core/SkPaint.cpp48
-rw-r--r--src/core/SkPath.cpp43
-rw-r--r--src/core/SkPathMeasure.cpp7
-rw-r--r--src/core/SkPictureShader.cpp10
-rw-r--r--src/core/SkPoint.cpp2
-rw-r--r--src/core/SkRRect.cpp22
-rw-r--r--src/core/SkStrokeRec.cpp2
-rw-r--r--src/core/SkStrokerPriv.cpp103
-rw-r--r--src/core/SkTextMapStateProc.h6
-rw-r--r--src/core/SkTextToPathIter.h2
-rw-r--r--src/utils/SkCamera.cpp8
-rw-r--r--src/utils/SkDashPath.cpp14
-rw-r--r--src/utils/SkTextBox.cpp4
19 files changed, 144 insertions, 174 deletions
diff --git a/src/core/SkBlurImageFilter.cpp b/src/core/SkBlurImageFilter.cpp
index 1a0515bd00..71b5cdc82e 100644
--- a/src/core/SkBlurImageFilter.cpp
+++ b/src/core/SkBlurImageFilter.cpp
@@ -274,16 +274,14 @@ sk_sp<SkSpecialImage> SkBlurImageFilterImpl::onFilterImage(SkSpecialImage* sourc
SkRect SkBlurImageFilterImpl::computeFastBounds(const SkRect& src) const {
SkRect bounds = this->getInput(0) ? this->getInput(0)->computeFastBounds(src) : src;
- bounds.outset(SkScalarMul(fSigma.width(), SkIntToScalar(3)),
- SkScalarMul(fSigma.height(), SkIntToScalar(3)));
+ bounds.outset(fSigma.width() * 3, fSigma.height() * 3);
return bounds;
}
SkIRect SkBlurImageFilterImpl::onFilterNodeBounds(const SkIRect& src, const SkMatrix& ctm,
MapDirection) const {
SkVector sigma = map_sigma(fSigma, ctm);
- return src.makeOutset(SkScalarCeilToInt(SkScalarMul(sigma.x(), SkIntToScalar(3))),
- SkScalarCeilToInt(SkScalarMul(sigma.y(), SkIntToScalar(3))));
+ return src.makeOutset(SkScalarCeilToInt(sigma.x() * 3), SkScalarCeilToInt(sigma.y() * 3));
}
#ifndef SK_IGNORE_TO_STRING
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 8fb83b46d0..41c5116718 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -2588,7 +2588,7 @@ void SkCanvas::DrawRect(const SkDraw& draw, const SkPaint& paint,
draw.fDevice->drawRect(draw, r, paint);
} else {
SkPaint p(paint);
- p.setStrokeWidth(SkScalarMul(textSize, paint.getStrokeWidth()));
+ p.setStrokeWidth(textSize * paint.getStrokeWidth());
draw.fDevice->drawRect(draw, r, p);
}
}
@@ -2631,22 +2631,20 @@ void SkCanvas::DrawTextDecorations(const SkDraw& draw, const SkPaint& paint,
if (flags & (SkPaint::kUnderlineText_Flag |
SkPaint::kStrikeThruText_Flag)) {
SkScalar textSize = paint.getTextSize();
- SkScalar height = SkScalarMul(textSize, kStdUnderline_Thickness);
+ SkScalar height = textSize * kStdUnderline_Thickness;
SkRect r;
r.fLeft = start.fX;
r.fRight = start.fX + width;
if (flags & SkPaint::kUnderlineText_Flag) {
- SkScalar offset = SkScalarMulAdd(textSize, kStdUnderline_Offset,
- start.fY);
+ SkScalar offset = textSize * kStdUnderline_Offset + start.fY;
r.fTop = offset;
r.fBottom = offset + height;
DrawRect(draw, paint, r, 1);
}
if (flags & SkPaint::kStrikeThruText_Flag) {
- SkScalar offset = SkScalarMulAdd(textSize, kStdStrikeThru_Offset,
- start.fY);
+ SkScalar offset = textSize * kStdStrikeThru_Offset + start.fY;
r.fTop = offset;
r.fBottom = offset + height;
DrawRect(draw, paint, r, 1);
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp
index ab75dbc0bc..8042c16f2c 100644
--- a/src/core/SkDevice.cpp
+++ b/src/core/SkDevice.cpp
@@ -380,8 +380,7 @@ static void morphpoints(SkPoint dst[], const SkPoint src[], int count,
matrix.postTranslate(pos.fX, pos.fY);
matrix.mapPoints(&dst[i], &pt, 1);
*/
- dst[i].set(pos.fX - SkScalarMul(tangent.fY, sy),
- pos.fY + SkScalarMul(tangent.fX, sy));
+ dst[i].set(pos.fX - tangent.fY * sy, pos.fY + tangent.fX * sy);
}
}
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index d63abd3c88..dd39d9eb97 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -470,7 +470,7 @@ bool PtProcRec::init(SkCanvas::PointMode mode, const SkPaint& paint,
fPaint = &paint;
fClip = nullptr;
fRC = rc;
- fRadius = SkScalarToFixed(SkScalarMul(width, sx)) >> 1;
+ fRadius = SkScalarToFixed(width * sx) >> 1;
return true;
}
}
@@ -1148,7 +1148,7 @@ void SkDraw::drawPath(const SkPath& origSrcPath, const SkPaint& origPaint,
// this is the old technique, which we preserve for now so
// we don't change previous results (testing)
// the new way seems fine, its just (a tiny bit) different
- int scale = (int)SkScalarMul(coverage, 256);
+ int scale = (int)(coverage * 256);
newAlpha = origPaint.getAlpha() * scale >> 8;
#endif
SkPaint* writablePaint = paint.writable();
diff --git a/src/core/SkGpuBlurUtils.cpp b/src/core/SkGpuBlurUtils.cpp
index c052c50dcb..3c2115e740 100644
--- a/src/core/SkGpuBlurUtils.cpp
+++ b/src/core/SkGpuBlurUtils.cpp
@@ -21,10 +21,10 @@
#define MAX_BLUR_SIGMA 4.0f
static void scale_irect_roundout(SkIRect* rect, float xScale, float yScale) {
- rect->fLeft = SkScalarFloorToInt(SkScalarMul(rect->fLeft, xScale));
- rect->fTop = SkScalarFloorToInt(SkScalarMul(rect->fTop, yScale));
- rect->fRight = SkScalarCeilToInt(SkScalarMul(rect->fRight, xScale));
- rect->fBottom = SkScalarCeilToInt(SkScalarMul(rect->fBottom, yScale));
+ rect->fLeft = SkScalarFloorToInt(rect->fLeft * xScale);
+ rect->fTop = SkScalarFloorToInt(rect->fTop * yScale);
+ rect->fRight = SkScalarCeilToInt(rect->fRight * xScale);
+ rect->fBottom = SkScalarCeilToInt(rect->fBottom * yScale);
}
static void scale_irect(SkIRect* rect, int xScale, int yScale) {
diff --git a/src/core/SkMatrix.cpp b/src/core/SkMatrix.cpp
index 390ebe08de..dc1ae09242 100644
--- a/src/core/SkMatrix.cpp
+++ b/src/core/SkMatrix.cpp
@@ -1410,32 +1410,32 @@ bool SkMatrix::Poly4Proc(const SkPoint srcPt[], SkMatrix* dst,
/* check if abs(x2) > abs(y2) */
if ( x2 > 0 ? y2 > 0 ? x2 > y2 : x2 > -y2 : y2 > 0 ? -x2 > y2 : x2 < y2) {
- float denom = SkScalarMulDiv(x1, y2, x2) - y1;
+ float denom = (x1 * y2 / x2) - y1;
if (checkForZero(denom)) {
return false;
}
- a1 = (SkScalarMulDiv(x0 - x1, y2, x2) - y0 + y1) / denom;
+ a1 = (((x0 - x1) * y2 / x2) - y0 + y1) / denom;
} else {
- float denom = x1 - SkScalarMulDiv(y1, x2, y2);
+ float denom = x1 - (y1 * x2 / y2);
if (checkForZero(denom)) {
return false;
}
- a1 = (x0 - x1 - SkScalarMulDiv(y0 - y1, x2, y2)) / denom;
+ a1 = (x0 - x1 - ((y0 - y1) * x2 / y2)) / denom;
}
/* check if abs(x1) > abs(y1) */
if ( x1 > 0 ? y1 > 0 ? x1 > y1 : x1 > -y1 : y1 > 0 ? -x1 > y1 : x1 < y1) {
- float denom = y2 - SkScalarMulDiv(x2, y1, x1);
+ float denom = y2 - (x2 * y1 / x1);
if (checkForZero(denom)) {
return false;
}
- a2 = (y0 - y2 - SkScalarMulDiv(x0 - x2, y1, x1)) / denom;
+ a2 = (y0 - y2 - ((x0 - x2) * y1 / x1)) / denom;
} else {
- float denom = SkScalarMulDiv(y2, x1, y1) - x2;
+ float denom = (y2 * x1 / y1) - x2;
if (checkForZero(denom)) {
return false;
}
- a2 = (SkScalarMulDiv(y0 - y2, x1, y1) - x0 + x2) / denom;
+ a2 = (((y0 - y2) * x1 / y1) - x0 + x2) / denom;
}
float invScale = SkScalarInvert(scale.fX);
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index ea33d5b6c9..04fd13e02d 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -825,12 +825,12 @@ SkScalar SkPaint::measureText(const void* textData, size_t length, SkRect* bound
width = paint.measure_text(cache, text, length, &tempCount, bounds);
if (scale) {
- width = SkScalarMul(width, scale);
+ width *= scale;
if (bounds) {
- bounds->fLeft = SkScalarMul(bounds->fLeft, scale);
- bounds->fTop = SkScalarMul(bounds->fTop, scale);
- bounds->fRight = SkScalarMul(bounds->fRight, scale);
- bounds->fBottom = SkScalarMul(bounds->fBottom, scale);
+ bounds->fLeft *= scale;
+ bounds->fTop *= scale;
+ bounds->fRight *= scale;
+ bounds->fBottom *= scale;
}
}
} else if (bounds) {
@@ -945,17 +945,17 @@ SkScalar SkPaint::getFontMetrics(FontMetrics* metrics, SkScalar zoom) const {
paint.descriptorProc(nullptr, kNone_ScalerContextFlags, zoomPtr, FontMetricsDescProc, metrics);
if (scale) {
- metrics->fTop = SkScalarMul(metrics->fTop, scale);
- metrics->fAscent = SkScalarMul(metrics->fAscent, scale);
- metrics->fDescent = SkScalarMul(metrics->fDescent, scale);
- metrics->fBottom = SkScalarMul(metrics->fBottom, scale);
- metrics->fLeading = SkScalarMul(metrics->fLeading, scale);
- metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale);
- metrics->fXMin = SkScalarMul(metrics->fXMin, scale);
- metrics->fXMax = SkScalarMul(metrics->fXMax, scale);
- metrics->fXHeight = SkScalarMul(metrics->fXHeight, scale);
- metrics->fUnderlineThickness = SkScalarMul(metrics->fUnderlineThickness, scale);
- metrics->fUnderlinePosition = SkScalarMul(metrics->fUnderlinePosition, scale);
+ metrics->fTop *= scale;
+ metrics->fAscent *= scale;
+ metrics->fDescent *= scale;
+ metrics->fBottom *= scale;
+ metrics->fLeading *= scale;
+ metrics->fAvgCharWidth *= scale;
+ metrics->fXMin *= scale;
+ metrics->fXMax *= scale;
+ metrics->fXHeight *= scale;
+ metrics->fUnderlineThickness *= scale;
+ metrics->fUnderlinePosition *= scale;
}
return metrics->fDescent - metrics->fAscent + metrics->fLeading;
}
@@ -1008,7 +1008,7 @@ int SkPaint::getTextWidths(const void* textData, size_t byteLength,
SkScalar adjust = autokern.adjust(g);
if (count > 0) {
- *widths++ = SkScalarMul(prevWidth + adjust, scale);
+ *widths++ = (prevWidth + adjust) * scale;
}
prevWidth = advance(g, xyIndex);
}
@@ -1018,7 +1018,7 @@ int SkPaint::getTextWidths(const void* textData, size_t byteLength,
++count;
}
if (count > 0 && widths) {
- *widths = SkScalarMul(prevWidth, scale);
+ *widths = prevWidth * scale;
}
} else {
while (text < stop) {
@@ -1045,8 +1045,7 @@ int SkPaint::getTextWidths(const void* textData, size_t byteLength,
while (text < stop) {
const SkGlyph& g = glyphCacheProc(cache, &text);
if (widths) {
- *widths++ = SkScalarMul(advance(g, xyIndex),
- scale);
+ *widths++ = advance(g, xyIndex) * scale;
}
if (bounds) {
set_bounds(g, bounds++, scale);
@@ -1371,7 +1370,7 @@ void SkScalerContext::MakeRec(const SkPaint& paint,
kStdFakeBoldInterpKeys,
kStdFakeBoldInterpValues,
kStdFakeBoldInterpLength);
- SkScalar extra = SkScalarMul(paint.getTextSize(), fakeBoldScale);
+ SkScalar extra = paint.getTextSize() * fakeBoldScale;
if (style == SkPaint::kFill_Style) {
style = SkPaint::kStrokeAndFill_Style;
@@ -2267,8 +2266,7 @@ SkTextBaseIter::SkTextBaseIter(const char text[], size_t length,
SkScalar xOffset = 0;
if (paint.getTextAlign() != SkPaint::kLeft_Align) { // need to measure first
int count;
- SkScalar width = SkScalarMul(fPaint.measure_text(fCache, text, length,
- &count, nullptr), fScale);
+ SkScalar width = fPaint.measure_text(fCache, text, length, &count, nullptr) * fScale;
if (paint.getTextAlign() == SkPaint::kCenter_Align) {
width = SkScalarHalf(width);
}
@@ -2291,7 +2289,7 @@ bool SkTextToPathIter::next(const SkPath** path, SkScalar* xpos) {
if (fText < fStop) {
const SkGlyph& glyph = fGlyphCacheProc(fCache, &fText);
- fXPos += SkScalarMul(fPrevAdvance + fAutoKern.adjust(glyph), fScale);
+ fXPos += (fPrevAdvance + fAutoKern.adjust(glyph)) * fScale;
fPrevAdvance = advance(glyph, fXYIndex); // + fPaint.getTextTracking();
if (glyph.fWidth) {
@@ -2313,7 +2311,7 @@ bool SkTextToPathIter::next(const SkPath** path, SkScalar* xpos) {
bool SkTextInterceptsIter::next(SkScalar* array, int* count) {
const SkGlyph& glyph = fGlyphCacheProc(fCache, &fText);
- fXPos += SkScalarMul(fPrevAdvance + fAutoKern.adjust(glyph), fScale);
+ fXPos += (fPrevAdvance + fAutoKern.adjust(glyph)) * fScale;
fPrevAdvance = advance(glyph, fXYIndex); // + fPaint.getTextTracking();
if (fCache->findPath(glyph)) {
fCache->findIntercepts(fBounds, fScale, fXPos, SkToBool(fXYIndex),
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index 84dfca1fc7..0cb5853b77 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -14,6 +14,14 @@
#include "SkPathRef.h"
#include "SkRRect.h"
+static float poly_eval(float A, float B, float C, float t) {
+ return (A * t + B) * t + C;
+}
+
+static float poly_eval(float A, float B, float C, float D, float t) {
+ return ((A * t + B) * t + C) * t + D;
+}
+
////////////////////////////////////////////////////////////////////////////
/**
@@ -239,10 +247,10 @@ static inline bool check_edge_against_rect(const SkPoint& p0,
}
if (v.fX || v.fY) {
// check the cross product of v with the vec from edgeBegin to each rect corner
- SkScalar yL = SkScalarMul(v.fY, rect.fLeft - edgeBegin->fX);
- SkScalar xT = SkScalarMul(v.fX, rect.fTop - edgeBegin->fY);
- SkScalar yR = SkScalarMul(v.fY, rect.fRight - edgeBegin->fX);
- SkScalar xB = SkScalarMul(v.fX, rect.fBottom - edgeBegin->fY);
+ SkScalar yL = v.fY * (rect.fLeft - edgeBegin->fX);
+ SkScalar xT = v.fX * (rect.fTop - edgeBegin->fY);
+ SkScalar yR = v.fY * (rect.fRight - edgeBegin->fX);
+ SkScalar xB = v.fX * (rect.fBottom - edgeBegin->fY);
if ((xT < yL) || (xT < yR) || (xB < yL) || (xB < yR)) {
return false;
}
@@ -1483,10 +1491,10 @@ void SkPath::arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar
return;
}
- SkScalar dist = SkScalarAbs(SkScalarMulDiv(radius, SK_Scalar1 - cosh, sinh));
+ SkScalar dist = SkScalarAbs(radius * (1 - cosh) / sinh);
- SkScalar xx = x1 - SkScalarMul(dist, before.fX);
- SkScalar yy = y1 - SkScalarMul(dist, before.fY);
+ SkScalar xx = x1 - dist * before.fX;
+ SkScalar yy = y1 - dist * before.fY;
after.setLength(dist);
this->lineTo(xx, yy);
SkScalar weight = SkScalarSqrt(SK_ScalarHalf + cosh * SK_ScalarHalf);
@@ -1738,8 +1746,8 @@ void SkPath::transform(const SkMatrix& matrix, SkPath* dst) const {
dst->fFirstDirection = SkPathPriv::kUnknown_FirstDirection;
} else {
SkScalar det2x2 =
- SkScalarMul(matrix.get(SkMatrix::kMScaleX), matrix.get(SkMatrix::kMScaleY)) -
- SkScalarMul(matrix.get(SkMatrix::kMSkewX), matrix.get(SkMatrix::kMSkewY));
+ matrix.get(SkMatrix::kMScaleX) * matrix.get(SkMatrix::kMScaleY) -
+ matrix.get(SkMatrix::kMSkewX) * matrix.get(SkMatrix::kMSkewY);
if (det2x2 < 0) {
dst->fFirstDirection = SkPathPriv::OppositeFirstDirection(
(SkPathPriv::FirstDirection)fFirstDirection.load());
@@ -2760,18 +2768,13 @@ static bool between(SkScalar a, SkScalar b, SkScalar c) {
return (a - b) * (c - b) <= 0;
}
-static SkScalar eval_cubic_coeff(SkScalar A, SkScalar B, SkScalar C,
- SkScalar D, SkScalar t) {
- return SkScalarMulAdd(SkScalarMulAdd(SkScalarMulAdd(A, t, B), t, C), t, D);
-}
-
static SkScalar eval_cubic_pts(SkScalar c0, SkScalar c1, SkScalar c2, SkScalar c3,
SkScalar t) {
SkScalar A = c3 + 3*(c1 - c2) - c0;
SkScalar B = 3*(c2 - c1 - c1 + c0);
SkScalar C = 3*(c1 - c0);
SkScalar D = c0;
- return eval_cubic_coeff(A, B, C, D, t);
+ return poly_eval(A, B, C, D, t);
}
template <size_t N> static void find_minmax(const SkPoint pts[],
@@ -2856,7 +2859,7 @@ static double conic_eval_numerator(const SkScalar src[], SkScalar w, SkScalar t)
SkScalar C = src[0];
SkScalar A = src[4] - 2 * src2w + C;
SkScalar B = 2 * (src2w - C);
- return (A * t + B) * t + C;
+ return poly_eval(A, B, C, t);
}
@@ -2864,7 +2867,7 @@ static double conic_eval_denominator(SkScalar w, SkScalar t) {
SkScalar B = 2 * (w - 1);
SkScalar C = 1;
SkScalar A = -B;
- return (A * t + B) * t + C;
+ return poly_eval(A, B, C, t);
}
static int winding_mono_conic(const SkConic& conic, SkScalar x, SkScalar y, int* onCurveCount) {
@@ -2985,7 +2988,7 @@ static int winding_mono_quad(const SkPoint pts[], SkScalar x, SkScalar y, int* o
SkScalar C = pts[0].fX;
SkScalar A = pts[2].fX - 2 * pts[1].fX + C;
SkScalar B = 2 * (pts[1].fX - C);
- xt = SkScalarMulAdd(SkScalarMulAdd(A, t, B), t, C);
+ xt = poly_eval(A, B, C, t);
}
if (SkScalarNearlyEqual(xt, x)) {
if (x != pts[2].fX || y != pts[2].fY) { // don't test end points; they're start points
@@ -3034,7 +3037,7 @@ static int winding_line(const SkPoint pts[], SkScalar x, SkScalar y, int* onCurv
if (y == y1) {
return 0;
}
- SkScalar cross = SkScalarMul(x1 - x0, y - pts[0].fY) - SkScalarMul(dy, x - x0);
+ SkScalar cross = (x1 - x0) * (y - pts[0].fY) - dy * (x - x0);
if (!cross) {
// zero cross means the point is on the line, and since the case where
@@ -3123,7 +3126,7 @@ static void tangent_quad(const SkPoint pts[], SkScalar x, SkScalar y,
SkScalar C = pts[0].fX;
SkScalar A = pts[2].fX - 2 * pts[1].fX + C;
SkScalar B = 2 * (pts[1].fX - C);
- SkScalar xt = (A * t + B) * t + C;
+ SkScalar xt = poly_eval(A, B, C, t);
if (!SkScalarNearlyEqual(x, xt)) {
continue;
}
diff --git a/src/core/SkPathMeasure.cpp b/src/core/SkPathMeasure.cpp
index 05d14d647c..626deebd72 100644
--- a/src/core/SkPathMeasure.cpp
+++ b/src/core/SkPathMeasure.cpp
@@ -575,14 +575,11 @@ const SkPathMeasure::Segment* SkPathMeasure::distanceToSegment(
SkASSERT(distance >= startD);
SkASSERT(seg->fDistance > startD);
- *t = startT + SkScalarMulDiv(seg->getScalarT() - startT,
- distance - startD,
- seg->fDistance - startD);
+ *t = startT + (seg->getScalarT() - startT) * (distance - startD) / (seg->fDistance - startD);
return seg;
}
-bool SkPathMeasure::getPosTan(SkScalar distance, SkPoint* pos,
- SkVector* tangent) {
+bool SkPathMeasure::getPosTan(SkScalar distance, SkPoint* pos, SkVector* tangent) {
if (nullptr == fPath) {
return false;
}
diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp
index af66eb2789..bdb6d060a7 100644
--- a/src/core/SkPictureShader.cpp
+++ b/src/core/SkPictureShader.cpp
@@ -183,19 +183,19 @@ sk_sp<SkShader> SkPictureShader::refBitmapShader(const SkMatrix& viewMatrix, con
// Clamp the tile size to about 4M pixels
static const SkScalar kMaxTileArea = 2048 * 2048;
- SkScalar tileArea = SkScalarMul(scaledSize.width(), scaledSize.height());
+ SkScalar tileArea = scaledSize.width() * scaledSize.height();
if (tileArea > kMaxTileArea) {
SkScalar clampScale = SkScalarSqrt(kMaxTileArea / tileArea);
- scaledSize.set(SkScalarMul(scaledSize.width(), clampScale),
- SkScalarMul(scaledSize.height(), clampScale));
+ scaledSize.set(scaledSize.width() * clampScale,
+ scaledSize.height() * clampScale);
}
#if SK_SUPPORT_GPU
// Scale down the tile size if larger than maxTextureSize for GPU Path or it should fail on create texture
if (maxTextureSize) {
if (scaledSize.width() > maxTextureSize || scaledSize.height() > maxTextureSize) {
SkScalar downScale = maxTextureSize / SkMaxScalar(scaledSize.width(), scaledSize.height());
- scaledSize.set(SkScalarFloorToScalar(SkScalarMul(scaledSize.width(), downScale)),
- SkScalarFloorToScalar(SkScalarMul(scaledSize.height(), downScale)));
+ scaledSize.set(SkScalarFloorToScalar(scaledSize.width() * downScale),
+ SkScalarFloorToScalar(scaledSize.height() * downScale));
}
}
#endif
diff --git a/src/core/SkPoint.cpp b/src/core/SkPoint.cpp
index 162c62acad..dfa484bb4c 100644
--- a/src/core/SkPoint.cpp
+++ b/src/core/SkPoint.cpp
@@ -62,7 +62,7 @@ void SkPoint::rotateCCW(SkPoint* dst) const {
void SkPoint::scale(SkScalar scale, SkPoint* dst) const {
SkASSERT(dst);
- dst->set(SkScalarMul(fX, scale), SkScalarMul(fY, scale));
+ dst->set(fX * scale, fY * scale);
}
bool SkPoint::normalize() {
diff --git a/src/core/SkRRect.cpp b/src/core/SkRRect.cpp
index 1188989cdb..2ed8bbfc5e 100644
--- a/src/core/SkRRect.cpp
+++ b/src/core/SkRRect.cpp
@@ -33,8 +33,8 @@ void SkRRect::setRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad) {
if (fRect.width() < xRad+xRad || fRect.height() < yRad+yRad) {
SkScalar scale = SkMinScalar(fRect.width() / (xRad + xRad), fRect.height() / (yRad + yRad));
SkASSERT(scale < SK_Scalar1);
- xRad = SkScalarMul(xRad, scale);
- yRad = SkScalarMul(yRad, scale);
+ xRad *= scale;
+ yRad *= scale;
}
for (int i = 0; i < 4; ++i) {
@@ -79,10 +79,10 @@ void SkRRect::setNinePatch(const SkRect& rect, SkScalar leftRad, SkScalar topRad
}
if (scale < SK_Scalar1) {
- leftRad = SkScalarMul(leftRad, scale);
- topRad = SkScalarMul(topRad, scale);
- rightRad = SkScalarMul(rightRad, scale);
- bottomRad = SkScalarMul(bottomRad, scale);
+ leftRad *= scale;
+ topRad *= scale;
+ rightRad *= scale;
+ bottomRad *= scale;
}
if (leftRad == rightRad && topRad == bottomRad) {
@@ -246,9 +246,9 @@ bool SkRRect::checkCornerContainment(SkScalar x, SkScalar y) const {
// a^2 b^2
// or :
// b^2*x^2 + a^2*y^2 <= (ab)^2
- SkScalar dist = SkScalarMul(SkScalarSquare(canonicalPt.fX), SkScalarSquare(fRadii[index].fY)) +
- SkScalarMul(SkScalarSquare(canonicalPt.fY), SkScalarSquare(fRadii[index].fX));
- return dist <= SkScalarSquare(SkScalarMul(fRadii[index].fX, fRadii[index].fY));
+ SkScalar dist = SkScalarSquare(canonicalPt.fX) * SkScalarSquare(fRadii[index].fY) +
+ SkScalarSquare(canonicalPt.fY) * SkScalarSquare(fRadii[index].fX);
+ return dist <= SkScalarSquare(fRadii[index].fX * fRadii[index].fY);
}
bool SkRRect::allCornersCircular() const {
@@ -404,8 +404,8 @@ bool SkRRect::transform(const SkMatrix& matrix, SkRRect* dst) const {
// Scale the radii without respecting the flip.
for (int i = 0; i < 4; ++i) {
- dst->fRadii[i].fX = SkScalarMul(fRadii[i].fX, xScale);
- dst->fRadii[i].fY = SkScalarMul(fRadii[i].fY, yScale);
+ dst->fRadii[i].fX = fRadii[i].fX * xScale;
+ dst->fRadii[i].fY = fRadii[i].fY * yScale;
}
// Now swap as necessary.
diff --git a/src/core/SkStrokeRec.cpp b/src/core/SkStrokeRec.cpp
index f3cca1653f..7e667bc668 100644
--- a/src/core/SkStrokeRec.cpp
+++ b/src/core/SkStrokeRec.cpp
@@ -147,7 +147,7 @@ static inline SkScalar get_inflation_bounds(SkPaint::Join join,
SkScalar radius = SkScalarHalf(strokeWidth);
if (SkPaint::kMiter_Join == join) {
if (miterLimit > SK_Scalar1) {
- radius = SkScalarMul(miterLimit, radius);
+ radius *= miterLimit;
}
}
return radius;
diff --git a/src/core/SkStrokerPriv.cpp b/src/core/SkStrokerPriv.cpp
index 840f961982..52144cdc5f 100644
--- a/src/core/SkStrokerPriv.cpp
+++ b/src/core/SkStrokerPriv.cpp
@@ -5,22 +5,17 @@
* found in the LICENSE file.
*/
-
#include "SkStrokerPriv.h"
#include "SkGeometry.h"
#include "SkPath.h"
-static void ButtCapper(SkPath* path, const SkPoint& pivot,
- const SkVector& normal, const SkPoint& stop,
- SkPath*)
-{
+static void ButtCapper(SkPath* path, const SkPoint& pivot, const SkVector& normal,
+ const SkPoint& stop, SkPath*) {
path->lineTo(stop.fX, stop.fY);
}
-static void RoundCapper(SkPath* path, const SkPoint& pivot,
- const SkVector& normal, const SkPoint& stop,
- SkPath*)
-{
+static void RoundCapper(SkPath* path, const SkPoint& pivot, const SkVector& normal,
+ const SkPoint& stop, SkPath*) {
SkVector parallel;
normal.rotateCW(&parallel);
@@ -30,20 +25,15 @@ static void RoundCapper(SkPath* path, const SkPoint& pivot,
path->conicTo(projectedCenter - normal, stop, SK_ScalarRoot2Over2);
}
-static void SquareCapper(SkPath* path, const SkPoint& pivot,
- const SkVector& normal, const SkPoint& stop,
- SkPath* otherPath)
-{
+static void SquareCapper(SkPath* path, const SkPoint& pivot, const SkVector& normal,
+ const SkPoint& stop, SkPath* otherPath) {
SkVector parallel;
normal.rotateCW(&parallel);
- if (otherPath)
- {
+ if (otherPath) {
path->setLastPt(pivot.fX + normal.fX + parallel.fX, pivot.fY + normal.fY + parallel.fY);
path->lineTo(pivot.fX - normal.fX + parallel.fX, pivot.fY - normal.fY + parallel.fY);
- }
- else
- {
+ } else {
path->lineTo(pivot.fX + normal.fX + parallel.fX, pivot.fY + normal.fY + parallel.fY);
path->lineTo(pivot.fX - normal.fX + parallel.fX, pivot.fY - normal.fY + parallel.fY);
path->lineTo(stop.fX, stop.fY);
@@ -52,9 +42,8 @@ static void SquareCapper(SkPath* path, const SkPoint& pivot,
/////////////////////////////////////////////////////////////////////////////
-static bool is_clockwise(const SkVector& before, const SkVector& after)
-{
- return SkScalarMul(before.fX, after.fY) - SkScalarMul(before.fY, after.fX) > 0;
+static bool is_clockwise(const SkVector& before, const SkVector& after) {
+ return before.fX * after.fY > before.fY * after.fX;
}
enum AngleType {
@@ -64,19 +53,18 @@ enum AngleType {
kNearlyLine_AngleType
};
-static AngleType Dot2AngleType(SkScalar dot)
-{
+static AngleType Dot2AngleType(SkScalar dot) {
// need more precise fixed normalization
// SkASSERT(SkScalarAbs(dot) <= SK_Scalar1 + SK_ScalarNearlyZero);
- if (dot >= 0) // shallow or line
+ if (dot >= 0) { // shallow or line
return SkScalarNearlyZero(SK_Scalar1 - dot) ? kNearlyLine_AngleType : kShallow_AngleType;
- else // sharp or 180
+ } else { // sharp or 180
return SkScalarNearlyZero(SK_Scalar1 + dot) ? kNearly180_AngleType : kSharp_AngleType;
+ }
}
-static void HandleInnerJoin(SkPath* inner, const SkPoint& pivot, const SkVector& after)
-{
+static void HandleInnerJoin(SkPath* inner, const SkPoint& pivot, const SkVector& after) {
#if 1
/* In the degenerate case that the stroke radius is larger than our segments
just connecting the two inner segments may "show through" as a funny
@@ -92,13 +80,11 @@ static void HandleInnerJoin(SkPath* inner, const SkPoint& pivot, const SkVector&
static void BluntJoiner(SkPath* outer, SkPath* inner, const SkVector& beforeUnitNormal,
const SkPoint& pivot, const SkVector& afterUnitNormal,
- SkScalar radius, SkScalar invMiterLimit, bool, bool)
-{
+ SkScalar radius, SkScalar invMiterLimit, bool, bool) {
SkVector after;
afterUnitNormal.scale(radius, &after);
- if (!is_clockwise(beforeUnitNormal, afterUnitNormal))
- {
+ if (!is_clockwise(beforeUnitNormal, afterUnitNormal)) {
SkTSwap<SkPath*>(outer, inner);
after.negate();
}
@@ -109,8 +95,7 @@ static void BluntJoiner(SkPath* outer, SkPath* inner, const SkVector& beforeUnit
static void RoundJoiner(SkPath* outer, SkPath* inner, const SkVector& beforeUnitNormal,
const SkPoint& pivot, const SkVector& afterUnitNormal,
- SkScalar radius, SkScalar invMiterLimit, bool, bool)
-{
+ SkScalar radius, SkScalar invMiterLimit, bool, bool) {
SkScalar dotProd = SkPoint::DotProduct(beforeUnitNormal, afterUnitNormal);
AngleType angleType = Dot2AngleType(dotProd);
@@ -121,8 +106,7 @@ static void RoundJoiner(SkPath* outer, SkPath* inner, const SkVector& beforeUnit
SkVector after = afterUnitNormal;
SkRotationDirection dir = kCW_SkRotationDirection;
- if (!is_clockwise(before, after))
- {
+ if (!is_clockwise(before, after)) {
SkTSwap<SkPath*>(outer, inner);
before.negate();
after.negate();
@@ -148,8 +132,7 @@ static void RoundJoiner(SkPath* outer, SkPath* inner, const SkVector& beforeUnit
static void MiterJoiner(SkPath* outer, SkPath* inner, const SkVector& beforeUnitNormal,
const SkPoint& pivot, const SkVector& afterUnitNormal,
SkScalar radius, SkScalar invMiterLimit,
- bool prevIsLine, bool currIsLine)
-{
+ bool prevIsLine, bool currIsLine) {
// negate the dot since we're using normals instead of tangents
SkScalar dotProd = SkPoint::DotProduct(beforeUnitNormal, afterUnitNormal);
AngleType angleType = Dot2AngleType(dotProd);
@@ -159,17 +142,16 @@ static void MiterJoiner(SkPath* outer, SkPath* inner, const SkVector& beforeUnit
SkScalar sinHalfAngle;
bool ccw;
- if (angleType == kNearlyLine_AngleType)
+ if (angleType == kNearlyLine_AngleType) {
return;
- if (angleType == kNearly180_AngleType)
- {
+ }
+ if (angleType == kNearly180_AngleType) {
currIsLine = false;
goto DO_BLUNT;
}
ccw = !is_clockwise(before, after);
- if (ccw)
- {
+ if (ccw) {
SkTSwap<SkPath*>(outer, inner);
before.negate();
after.negate();
@@ -181,10 +163,8 @@ static void MiterJoiner(SkPath* outer, SkPath* inner, const SkVector& beforeUnit
that (for speed an accuracy).
Note: we only need to check one normal if dot==0
*/
- if (0 == dotProd && invMiterLimit <= kOneOverSqrt2)
- {
- mid.set(SkScalarMul(before.fX + after.fX, radius),
- SkScalarMul(before.fY + after.fY, radius));
+ if (0 == dotProd && invMiterLimit <= kOneOverSqrt2) {
+ mid = (before + after) * radius;
goto DO_MITER;
}
@@ -197,41 +177,41 @@ static void MiterJoiner(SkPath* outer, SkPath* inner, const SkVector& beforeUnit
hence 1 + dot instead of 1 - dot in the formula
*/
sinHalfAngle = SkScalarSqrt(SkScalarHalf(SK_Scalar1 + dotProd));
- if (sinHalfAngle < invMiterLimit)
- {
+ if (sinHalfAngle < invMiterLimit) {
currIsLine = false;
goto DO_BLUNT;
}
// choose the most accurate way to form the initial mid-vector
- if (angleType == kSharp_AngleType)
- {
+ if (angleType == kSharp_AngleType) {
mid.set(after.fY - before.fY, before.fX - after.fX);
- if (ccw)
+ if (ccw) {
mid.negate();
- }
- else
+ }
+ } else {
mid.set(before.fX + after.fX, before.fY + after.fY);
+ }
mid.setLength(radius / sinHalfAngle);
DO_MITER:
- if (prevIsLine)
+ if (prevIsLine) {
outer->setLastPt(pivot.fX + mid.fX, pivot.fY + mid.fY);
- else
+ } else {
outer->lineTo(pivot.fX + mid.fX, pivot.fY + mid.fY);
+ }
DO_BLUNT:
after.scale(radius);
- if (!currIsLine)
+ if (!currIsLine) {
outer->lineTo(pivot.fX + after.fX, pivot.fY + after.fY);
+ }
HandleInnerJoin(inner, pivot, after);
}
/////////////////////////////////////////////////////////////////////////////
-SkStrokerPriv::CapProc SkStrokerPriv::CapFactory(SkPaint::Cap cap)
-{
- static const SkStrokerPriv::CapProc gCappers[] = {
+SkStrokerPriv::CapProc SkStrokerPriv::CapFactory(SkPaint::Cap cap) {
+ const SkStrokerPriv::CapProc gCappers[] = {
ButtCapper, RoundCapper, SquareCapper
};
@@ -239,9 +219,8 @@ SkStrokerPriv::CapProc SkStrokerPriv::CapFactory(SkPaint::Cap cap)
return gCappers[cap];
}
-SkStrokerPriv::JoinProc SkStrokerPriv::JoinFactory(SkPaint::Join join)
-{
- static const SkStrokerPriv::JoinProc gJoiners[] = {
+SkStrokerPriv::JoinProc SkStrokerPriv::JoinFactory(SkPaint::Join join) {
+ const SkStrokerPriv::JoinProc gJoiners[] = {
MiterJoiner, RoundJoiner, BluntJoiner
};
diff --git a/src/core/SkTextMapStateProc.h b/src/core/SkTextMapStateProc.h
index 944050917c..81ef5dee50 100644
--- a/src/core/SkTextMapStateProc.h
+++ b/src/core/SkTextMapStateProc.h
@@ -26,8 +26,8 @@ public:
} else {
// Bake the matrix scale/translation components into fOffset,
// to expedite proc computations.
- fOffset.set(SkScalarMul(offset.x(), fMatrix.getScaleX()) + fMatrix.getTranslateX(),
- SkScalarMul(offset.y(), fMatrix.getScaleY()) + fMatrix.getTranslateY());
+ fOffset.set(offset.x() * fMatrix.getScaleX() + fMatrix.getTranslateX(),
+ offset.y() * fMatrix.getScaleY() + fMatrix.getTranslateY());
if (mtype & SkMatrix::kScale_Mask) {
fMapCase = kOnlyScaleX;
@@ -61,7 +61,7 @@ inline void SkTextMapStateProc::operator()(const SkScalar pos[], SkPoint* loc) c
fProc(fMatrix, pos[0] + fOffset.x(), pos[1] + fOffset.y(), loc);
break;
case kOnlyScaleX:
- loc->set(SkScalarMul(fScaleX, *pos) + fOffset.x(), fOffset.y());
+ loc->set(fScaleX * *pos + fOffset.x(), fOffset.y());
break;
case kOnlyTransX:
loc->set(*pos + fOffset.x(), fOffset.y());
diff --git a/src/core/SkTextToPathIter.h b/src/core/SkTextToPathIter.h
index dcd5a01cd3..6de12a84ce 100644
--- a/src/core/SkTextToPathIter.h
+++ b/src/core/SkTextToPathIter.h
@@ -75,7 +75,7 @@ public:
&& fPaint.getTextAlign() != SkPaint::kLeft_Align) { // need to measure first
const char* text = fText;
const SkGlyph& glyph = fGlyphCacheProc(fCache, &text);
- SkScalar width = SkScalarMul(SkFloatToScalar((&glyph.fAdvanceX)[0]), fScale);
+ SkScalar width = (&glyph.fAdvanceX)[0] * fScale;
if (fPaint.getTextAlign() == SkPaint::kCenter_Align) {
width = SkScalarHalf(width);
}
diff --git a/src/utils/SkCamera.cpp b/src/utils/SkCamera.cpp
index c8c462a5f7..23ab396c98 100644
--- a/src/utils/SkCamera.cpp
+++ b/src/utils/SkCamera.cpp
@@ -83,11 +83,11 @@ void SkPatch3D::transform(const SkMatrix3D& m, SkPatch3D* dst) const {
}
SkScalar SkPatch3D::dotWith(SkScalar dx, SkScalar dy, SkScalar dz) const {
- SkScalar cx = SkScalarMul(fU.fY, fV.fZ) - SkScalarMul(fU.fZ, fV.fY);
- SkScalar cy = SkScalarMul(fU.fZ, fV.fX) - SkScalarMul(fU.fX, fV.fY);
- SkScalar cz = SkScalarMul(fU.fX, fV.fY) - SkScalarMul(fU.fY, fV.fX);
+ SkScalar cx = fU.fY * fV.fZ - fU.fZ * fV.fY;
+ SkScalar cy = fU.fZ * fV.fX - fU.fX * fV.fY;
+ SkScalar cz = fU.fX * fV.fY - fU.fY * fV.fX;
- return SkScalarMul(cx, dx) + SkScalarMul(cy, dy) + SkScalarMul(cz, dz);
+ return cx * dx + cy * dy + cz * dz;
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/utils/SkDashPath.cpp b/src/utils/SkDashPath.cpp
index c0cdcc195d..4b5e58ef4f 100644
--- a/src/utils/SkDashPath.cpp
+++ b/src/utils/SkDashPath.cpp
@@ -77,7 +77,7 @@ static void outset_for_stroke(SkRect* rect, const SkStrokeRec& rec) {
radius = SK_Scalar1; // hairlines
}
if (SkPaint::kMiter_Join == rec.getJoin()) {
- radius = SkScalarMul(radius, rec.getMiter());
+ radius *= rec.getMiter();
}
rect->outset(radius, radius);
}
@@ -173,9 +173,7 @@ public:
// resulting segments = pathLen * intervalCount / intervalLen
// resulting points = 4 * segments
- SkScalar ptCount = SkScalarMulDiv(pathLength,
- SkIntToScalar(intervalCount),
- intervalLength);
+ SkScalar ptCount = pathLength * intervalCount / (float)intervalLength;
ptCount = SkTMin(ptCount, SkDashPath::kMaxDashCount);
int n = SkScalarCeilToInt(ptCount) << 2;
dst->incReserve(n);
@@ -192,10 +190,10 @@ public:
d1 = fPathLength;
}
- SkScalar x0 = fPts[0].fX + SkScalarMul(fTangent.fX, d0);
- SkScalar x1 = fPts[0].fX + SkScalarMul(fTangent.fX, d1);
- SkScalar y0 = fPts[0].fY + SkScalarMul(fTangent.fY, d0);
- SkScalar y1 = fPts[0].fY + SkScalarMul(fTangent.fY, d1);
+ SkScalar x0 = fPts[0].fX + fTangent.fX * d0;
+ SkScalar x1 = fPts[0].fX + fTangent.fX * d1;
+ SkScalar y0 = fPts[0].fY + fTangent.fY * d0;
+ SkScalar y1 = fPts[0].fY + fTangent.fY * d1;
SkPoint pts[4];
pts[0].set(x0 + fNormal.fX, y0 + fNormal.fY); // moveTo
diff --git a/src/utils/SkTextBox.cpp b/src/utils/SkTextBox.cpp
index bc2e2217d9..9b26a9f00b 100644
--- a/src/utils/SkTextBox.cpp
+++ b/src/utils/SkTextBox.cpp
@@ -192,7 +192,7 @@ SkScalar SkTextBox::visit(Visitor& visitor, const char text[], size_t len,
x += fBox.fLeft;
fontHeight = paint.getFontMetrics(&metrics);
- scaledSpacing = SkScalarMul(fontHeight, fSpacingMul) + fSpacingAdd;
+ scaledSpacing = fontHeight * fSpacingMul + fSpacingAdd;
height = fBox.height();
// compute Y position for first line
@@ -271,7 +271,7 @@ int SkTextBox::countLines() const {
}
SkScalar SkTextBox::getTextHeight() const {
- SkScalar spacing = SkScalarMul(fPaint->getTextSize(), fSpacingMul) + fSpacingAdd;
+ SkScalar spacing = fPaint->getTextSize() * fSpacingMul + fSpacingAdd;
return this->countLines() * spacing;
}