static SkShader* MakeConicalOutside(const SkPoint pts[2], const GradData& data,
SkShader::TileMode tm, float scale) {
SkPoint center0, center1;
- SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
- SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
+ SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
+ SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
return SkGradientShader::CreateTwoPointConical(center0, radius0,
static SkShader* MakeConicalOutsideZeroRad(const SkPoint pts[2], const GradData& data,
SkShader::TileMode tm, float scale) {
SkPoint center0, center1;
- SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
- SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
+ SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
+ SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
return SkGradientShader::CreateTwoPointConical(center0, 0.0,
SkScalar pre = SkScalarMul(x1, y2) - SkScalarMul(y1, x2),
post = SkScalarMul(x3, y4) - SkScalarMul(y3, x4);
// Compute the point of intersection
- res.set(SkScalarDiv(SkScalarMul(pre, x3 - x4) - SkScalarMul(x1 - x2, post), d),
- SkScalarDiv(SkScalarMul(pre, y3 - y4) - SkScalarMul(y1 - y2, post), d));
+ res.set((SkScalarMul(pre, x3 - x4) - SkScalarMul(x1 - x2, post) / d,
+ (SkScalarMul(pre, y3 - y4) - SkScalarMul(y1 - y2, post) / d);
// Check if the x and y coordinates are within both lines
return (res.x() < GrMin(x1, x2) || res.x() > GrMax(x1, x2) ||
SkPoint miterPt1 = miterPt[0] - *pt1;
SkScalar sqDist0 = miterPt0.dot(miterPt0);
SkScalar sqDist1 = miterPt1.dot(miterPt1);
- const SkScalar rSq =
- SkScalarDiv(SkScalarMul(radius, radius),
- sinHalfAngleSq);
+ const SkScalar rSq = radius*radius / sinHalfAngleSq;
const SkScalar sqRLimit =
SkScalarMul(sqMiterLimit, rSq);
if (sqDist0 > sqRLimit || sqDist1 > sqRLimit) {
canvas->scale(3.0f, 3.0f);
SkMatrix skew;
skew.setIdentity();
- skew.setSkewX(SkScalarDiv(8.0f,
- 25.0f));
- skew.setSkewY(SkScalarDiv(2.0f,
- 25.0f));
+ skew.setSkewX(8.0f / 25.0f);
+ skew.setSkewY(2.0f / 25.0f);
canvas->concat(skew);
drawTestCase(canvas, 1.0f);
canvas->restore();
canvas->save();
SkMatrix perspective;
perspective.setIdentity();
- perspective.setPerspX(-SkScalarDiv(SK_Scalar1, 340.0f));
- perspective.setSkewX(SkScalarDiv(8.0f,
- 25.0f));
- perspective.setSkewY(SkScalarDiv(2.0f,
- 25.0f));
+ perspective.setPerspX(-SkScalarInvert(340));
+ perspective.setSkewX(8.0f / 25.0f);
+ perspective.setSkewY(2.0f / 25.0f);
canvas->concat(perspective);
static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data,
SkShader::TileMode tm, const SkMatrix& localMatrix) {
SkPoint center0, center1;
- SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
- SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
+ SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
+ SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
return SkGradientShader::CreateTwoPointConical(center1, radius1,
// apply an increasing y perspective as we move to the right
SkMatrix perspective;
perspective.setIdentity();
- perspective.setPerspY(SkScalarDiv(SkIntToScalar((unsigned) i+1),
- SkIntToScalar(500)));
- perspective.setSkewX(SkScalarDiv(SkIntToScalar((unsigned) i+1),
- SkIntToScalar(10)));
+ perspective.setPerspY(SkIntToScalar(i+1) / 500);
+ perspective.setSkewX(SkIntToScalar(i+1) / 10);
SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, perspective);
virtual void onDraw(SkCanvas* canvas) {
SkMatrix perspective;
perspective.setIdentity();
- perspective.setPerspY(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000)));
- perspective.setSkewX(SkScalarDiv(SkIntToScalar(8), SkIntToScalar(25)));
+ perspective.setPerspY(0.001f);
+ perspective.setSkewX(SkIntToScalar(8) / 25);
canvas->concat(perspective);
INHERITED::onDraw(canvas);
}
static SkShader* Make2ConicalOutside(const SkPoint pts[2], const GradData& data,
SkShader::TileMode tm, const SkMatrix& localMatrix) {
SkPoint center0, center1;
- SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
- SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
+ SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
+ SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
return SkGradientShader::CreateTwoPointConical(center0, radius0,
static SkShader* Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& data,
SkShader::TileMode tm, const SkMatrix& localMatrix) {
SkPoint center0, center1;
- SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
- SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
+ SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
+ SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
return SkGradientShader::CreateTwoPointConical(center1, radius1,
SkShader::TileMode tm, const SkMatrix& localMatrix) {
SkPoint center0, center1;
SkScalar radius0 = 0.f;
- SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
+ SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
return SkGradientShader::CreateTwoPointConical(center0, radius0,
SkShader::TileMode tm, const SkMatrix& localMatrix) {
SkPoint center0, center1;
SkScalar radius0 = 0.f;
- SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
+ SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
return SkGradientShader::CreateTwoPointConical(center1, radius1,
static SkShader* Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data,
SkShader::TileMode tm, const SkMatrix& localMatrix) {
SkPoint center0, center1;
- SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
- SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
+ SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
+ SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
center0.set(center1.fX + radius1, center1.fY);
static SkShader* Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data,
SkShader::TileMode tm, const SkMatrix& localMatrix) {
SkPoint center0, center1;
- SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
- SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
+ SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
+ SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
center0.set(center1.fX, center1.fY + radius1);
SkShader::TileMode tm, const SkMatrix& localMatrix) {
SkPoint center0, center1;
SkScalar radius0 = 0.f;
- SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
+ SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
center0.set(center1.fX + radius1, center1.fY);
SkShader::TileMode tm, const SkMatrix& localMatrix) {
SkPoint center0, center1;
SkScalar radius0 = 0.f;
- SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
+ SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
center0.set(center1.fX, center1.fY + radius1);
static SkShader* Make2ConicalTouchX(const SkPoint pts[2], const GradData& data,
SkShader::TileMode tm, const SkMatrix& localMatrix) {
SkPoint center0, center1;
- SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
- SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
+ SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
+ SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
center0.set(center1.fX - radius1 + radius0, center1.fY);
static SkShader* Make2ConicalTouchY(const SkPoint pts[2], const GradData& data,
SkShader::TileMode tm, const SkMatrix& localMatrix) {
SkPoint center0, center1;
- SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
- SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
+ SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
+ SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
center0.set(center1.fX, center1.fY + radius1 - radius0);
static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
SkPoint center0, center1;
- SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
- SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
+ SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
+ SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
return SkGradientShader::CreateTwoPointConical(center1, radius1,
canvas->scale(SkScalarInvert(RESIZE_FACTOR_X),
SkScalarInvert(RESIZE_FACTOR_Y));
}
- canvas->drawCircle(r.centerX(), r.centerY(),
- SkScalarDiv(r.width()*2, SkIntToScalar(5)), paint);
+ canvas->drawCircle(r.centerX(), r.centerY(), r.width() * 2 / 5, paint);
canvas->restore();
canvas->translate(r.width() + margin, 0);
}
canvas->scale(SkScalarInvert(RESIZE_FACTOR),
SkScalarInvert(RESIZE_FACTOR));
}
- canvas->drawCircle(r.centerX(), r.centerY(),
- SkScalarDiv(r.width()*2, SkIntToScalar(5)), paint);
+ canvas->drawCircle(r.centerX(), r.centerY(), r.width()*2/5, paint);
canvas->restore();
canvas->translate(r.width() * scales[j].fX + margin, 0);
}
SkRect dstRect;
canvas->getTotalMatrix().mapRect(&dstRect, rect);
canvas->save();
- SkScalar deviceScaleX = SkScalarDiv(deviceSize.width(), dstRect.width());
- SkScalar deviceScaleY = SkScalarDiv(deviceSize.height(), dstRect.height());
+ SkScalar deviceScaleX = deviceSize.width() / dstRect.width();
+ SkScalar deviceScaleY = deviceSize.height() / dstRect.height();
canvas->translate(rect.x(), rect.y());
canvas->scale(deviceScaleX, deviceScaleY);
canvas->translate(-rect.x(), -rect.y());
SkPaint paint;
paint.setColor(0xFF00FF00);
SkRect ovalRect = SkRect::MakeWH(16, 16);
- ovalRect.inset(SkScalarDiv(2.0f, 3.0f), SkScalarDiv(2.0f, 3.0f));
+ ovalRect.inset(SkIntToScalar(2)/3, SkIntToScalar(2)/3);
bitmapCanvas.drawOval(ovalRect, paint);
}
SkRect inRect = SkRect::MakeXYWH(-4, -4, 20, 20);
if (background) {
scale = 0.6f;
}
- SkScalar shaderWidth = SkScalarDiv(SkIntToScalar(width), scale);
- SkScalar shaderHeight = SkScalarDiv(SkIntToScalar(height), scale);
- SkMatrix shaderScale;
- shaderScale.setScale(scale, scale);
+ SkScalar shaderWidth = width / scale;
+ SkScalar shaderHeight = height / scale;
+ SkMatrix shaderScale = SkMatrix::MakeScale(scale);
SkShader* shader = fShaderMaker(shaderWidth, shaderHeight, background, shaderScale);
return shader;
}
SkPoint rp = SkPoint::Make(length*SkScalarCos(step) + center.fX,
length*SkScalarSin(step) + center.fY);
path.lineTo(rp);
- length += SkScalarDiv(angle, SkScalarHalf(SK_ScalarPI));
+ length += angle / SkScalarHalf(SK_ScalarPI);
step += angle;
}
path.close();
m.setScale(sx, sy);
return m;
}
-
+
+ static SkMatrix SK_WARN_UNUSED_RESULT MakeScale(SkScalar scale) {
+ SkMatrix m;
+ m.setScale(scale, scale);
+ return m;
+ }
+
static SkMatrix SK_WARN_UNUSED_RESULT MakeTrans(SkScalar dx, SkScalar dy) {
SkMatrix m;
m.setTranslate(dx, dy);
fY -= v.fY;
}
+ SkPoint operator*(SkScalar scale) const {
+ return Make(fX * scale, fY * scale);
+ }
+
+ SkPoint& operator*=(SkScalar scale) {
+ fX *= scale;
+ fY *= scale;
+ return *this;
+ }
+
/**
* Returns true if both X and Y are finite (not infinity or NaN)
*/
#define SkScalarMul(a, b) ((SkScalar)(a) * (b))
#define SkScalarMulAdd(a, b, c) ((SkScalar)(a) * (b) + (c))
-#define SkScalarDiv(a, b) ((SkScalar)(a) / (b))
+#ifdef SK_SUPPORT_LEGACY_SCALAR_DIV
+ #define SkScalarDiv(a, b) ((SkScalar)(a) / (b))
+#endif
#define SkScalarMulDiv(a, b, c) ((SkScalar)(a) * (b) / (c))
#define SkScalarInvert(x) (SK_Scalar1 / (x))
#define SkScalarFastInvert(x) (SK_Scalar1 / (x))
static const SkScalar gAnimPeriod = 10 * SK_Scalar1;
static const SkScalar gAnimMag = SK_Scalar1 / 1000;
SkScalar t = SkScalarMod(secs, gAnimPeriod);
- if (SkScalarFloorToInt(SkScalarDiv(secs, gAnimPeriod)) & 0x1) {
+ if (SkScalarFloorToInt(secs / gAnimPeriod) & 0x1) {
t = gAnimPeriod - t;
}
t = 2 * t - gAnimPeriod;
- t = SkScalarMul(SkScalarDiv(t, gAnimPeriod), gAnimMag);
+ t *= gAnimMag / gAnimPeriod;
SkMatrix m;
m.reset();
#if 1
m.setPerspY(t);
#else
m.setPerspY(SK_Scalar1 / 1000);
- m.setSkewX(SkScalarDiv(8, 25));
+ m.setSkewX(8.0f / 25);
m.dump();
#endif
canvas->concat(m);
SkPoint rp = SkPoint::Make(length*SkScalarCos(step) + center.fX,
length*SkScalarSin(step) + center.fY);
path.lineTo(rp);
- length += SkScalarDiv(angle, SkScalarHalf(SK_ScalarPI));
+ length += angle / SkScalarHalf(SK_ScalarPI);
step += angle;
}
path.close();
SkDebugf("to=\"%s\" ", to.c_str());
}
if (begin != 0) {
- SkDebugf("begin=\"%g\" ", SkScalarToFloat(SkScalarDiv(begin,1000)));
+ SkDebugf("begin=\"%g\" ", begin * 0.001);
}
}
#endif
SkDebugf("mirror=\"true\" ");
if (fReset)
SkDebugf("reset=\"true\" ");
- SkDebugf("dur=\"%g\" ", SkScalarToFloat(SkScalarDiv(dur,1000)));
+ SkDebugf("dur=\"%g\" ", dur * 0.001);
if (repeat != SK_Scalar1)
SkDebugf("repeat=\"%g\" ", SkScalarToFloat(repeat));
//if (fHasValues)
void SkSet::dump(SkAnimateMaker* maker) {
INHERITED::dump(maker);
if (dur != 1) {
- SkDebugf("dur=\"%g\" ", SkScalarToFloat(SkScalarDiv(dur,1000)));
+ SkDebugf("dur=\"%g\" ", dur * 0.001);
}
//don't want double />\n's
SkDebugf("/>\n");
if (info->fType != SkType_MemberProperty && info->fType != SkType_MemberFunction)
value->fOperand.fS32 = *(int32_t*) info->memberData(displayable); // OK for SkScalar too
if (type == SkType_MSec) {
- value->fOperand.fScalar = SkScalarDiv((SkScalar) value->fOperand.fS32, 1000); // dividing two ints is the same as dividing two scalars
+ value->fOperand.fScalar = value->fOperand.fS32 * 0.001f;
type = SkType_Float;
}
break;
if (info->fType != SkType_MemberProperty && info->fType != SkType_MemberFunction)
value->fS32 = *(int32_t*) info->memberData(displayable); // OK for SkScalar too
if (type == SkType_MSec) {
- value->fScalar = SkScalarDiv((SkScalar) value->fS32, 1000); // dividing two ints is the same as dividing two scalars
+ value->fScalar = value->fS32 * 0.001f;
type = SkType_Float;
}
break;
delete eventType;
if (delay > 0) {
- SkDebugf("delay=\"%g\" ", SkScalarToFloat(SkScalarDiv(delay, 1000)));
+ SkDebugf("delay=\"%g\" ", delay * 0.001);
}
// if (initialized == false)
// SkDebugf("(uninitialized) ");
break;
case SkType_MSec:
if (op.fS32 != blankOp.fS32) {
- SkDebugf(" %s=\"%g\" ", info->fName, SkScalarToFloat(SkScalarDiv(op.fS32, 1000)));
+ SkDebugf(" %s=\"%g\" ", info->fName, op.fS32 * 0.001);
}
default:
SkDebugf("");
if (choice == kGetValue)
return value/255;
SkScalar delta = value - min;
- SkScalar saturation = value == 0 ? 0 : SkScalarDiv(delta, value);
+ SkScalar saturation = value == 0 ? 0 : delta / value;
if (choice == kGetSaturation)
return saturation;
SkScalar hue;
if (saturation == 0)
hue = 0;
else {
- SkScalar part60 = SkScalarDiv(60 * SK_Scalar1, delta);
+ SkScalar part60 = 60 / delta;
if (red == value) {
hue = SkScalarMul(green - blue, part60);
if (hue < 0)
if (operand2.fScalar == 0)
operand2.fScalar = operand1.fScalar == 0 ? SK_ScalarNaN : operand1.fScalar > 0 ? SK_ScalarMax : -SK_ScalarMax;
else
- operand2.fScalar = SkScalarDiv(operand1.fScalar, operand2.fScalar);
+ operand2.fScalar = operand1.fScalar / operand2.fScalar;
break;
case kEqualInt:
operand2.fS32 = operand1.fS32 == operand2.fS32;
operand[0].fScalar = operand[0].fScalar == 0 ? SK_ScalarNaN :
operand[0].fScalar > 0 ? SK_ScalarMax : -SK_ScalarMax;
else
- operand[0].fScalar = SkScalarDiv(operand[0].fScalar, operand[1].fScalar);
+ operand[0].fScalar = operand[0].fScalar / operand[1].fScalar;
break;
case SkScriptEngine2::kEqualInt:
operand[0].fS32 = operand[0].fS32 == operand[1].fS32;
return 0;
}
- SkScalar r = SkScalarDiv(numer, denom);
+ SkScalar r = numer / denom;
if (SkScalarIsNaN(r)) {
return 0;
}
A = -B;
SkScalar denom = SkScalarMulAdd(SkScalarMulAdd(A, t, B), t, C);
- return SkScalarDiv(numer, denom);
+ return numer / denom;
}
// F' = 2 (C t (1 + t (-1 + w)) - A (-1 + t) (t (-1 + w) - w) + B (1 - 2 t) w)
fPaint.setTextSize(SkIntToScalar(SkPaint::kCanonicalTextSizeForPaths));
fScale = paint.getTextSize() / SkPaint::kCanonicalTextSizeForPaths;
if (has_thick_frame(fPaint)) {
- fPaint.setStrokeWidth(SkScalarDiv(fPaint.getStrokeWidth(), fScale));
+ fPaint.setStrokeWidth(fPaint.getStrokeWidth() / fScale);
}
} else {
fScale = SK_Scalar1;
if (SK_Scalar1 == stopT) {
dst->quadTo(tmp0[3], tmp0[4]);
} else {
- SkChopQuadAt(&tmp0[2], tmp1, SkScalarDiv(stopT - startT,
- SK_Scalar1 - startT));
+ SkChopQuadAt(&tmp0[2], tmp1, (stopT - startT) / (1 - startT));
dst->quadTo(tmp1[1], tmp1[2]);
}
}
if (SK_Scalar1 == stopT) {
dst->cubicTo(tmp0[4], tmp0[5], tmp0[6]);
} else {
- SkChopCubicAt(&tmp0[3], tmp1, SkScalarDiv(stopT - startT,
- SK_Scalar1 - startT));
+ SkChopCubicAt(&tmp0[3], tmp1, (stopT - startT) / (1 - startT));
dst->cubicTo(tmp1[1], tmp1[2], tmp1[3]);
}
}
static const SkScalar kMaxTileArea = 2048 * 2048;
SkScalar tileArea = SkScalarMul(scaledSize.width(), scaledSize.height());
if (tileArea > kMaxTileArea) {
- SkScalar clampScale = SkScalarSqrt(SkScalarDiv(kMaxTileArea, tileArea));
+ SkScalar clampScale = SkScalarSqrt(kMaxTileArea / tileArea);
scaledSize.set(SkScalarMul(scaledSize.width(), clampScale),
SkScalarMul(scaledSize.height(), clampScale));
}
// 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 = SkScalarDiv(maxTextureSize,
- SkMax32(scaledSize.width(), scaledSize.height()));
+ SkScalar downScale = maxTextureSize / SkMax32(scaledSize.width(), scaledSize.height());
scaledSize.set(SkScalarFloorToScalar(SkScalarMul(scaledSize.width(), downScale)),
SkScalarFloorToScalar(SkScalarMul(scaledSize.height(), downScale)));
}
}
if (rect.width() < xRad+xRad || rect.height() < yRad+yRad) {
- SkScalar scale = SkMinScalar(SkScalarDiv(rect.width(), xRad + xRad),
- SkScalarDiv(rect.height(), yRad + yRad));
+ SkScalar scale = SkMinScalar(rect.width() / (xRad + xRad), rect.height() / (yRad + yRad));
SkASSERT(scale < SK_Scalar1);
xRad = SkScalarMul(xRad, scale);
yRad = SkScalarMul(yRad, scale);
SkScalar scale = SK_Scalar1;
if (leftRad + rightRad > rect.width()) {
- scale = SkScalarDiv(rect.width(), leftRad + rightRad);
+ scale = rect.width() / (leftRad + rightRad);
}
if (topRad + bottomRad > rect.height()) {
- scale = SkMinScalar(scale, SkScalarDiv(rect.height(), topRad + bottomRad));
+ scale = SkMinScalar(scale, rect.height() / (topRad + bottomRad));
}
if (scale < SK_Scalar1) {
// Otherwise, interpolate between right - 1 and right.
SkScalar rightKey = keys[right];
SkScalar leftKey = keys[right-1];
- SkScalar fract = SkScalarDiv(searchKey-leftKey,rightKey-leftKey);
+ SkScalar fract = (searchKey - leftKey) / (rightKey - leftKey);
return SkScalarInterp(values[right-1], values[right], fract);
}
normalB = pts[2] - pts[0];
normalB.rotateCCW();
SkScalar dot = SkPoint::DotProduct(unitNormalAB, *unitNormalBC);
- SkAssertResult(normalB.setLength(SkScalarDiv(fRadius,
- SkScalarSqrt((SK_Scalar1 + dot)/2))));
+ SkAssertResult(normalB.setLength(fRadius / SkScalarSqrt((SK_Scalar1 + dot)/2)));
fOuter.quadTo( pts[1].fX + normalB.fX, pts[1].fY + normalB.fY,
pts[2].fX + normalBC->fX, pts[2].fY + normalBC->fY);
normalC = *unitNormalCD + unitBC;
SkScalar dot = SkPoint::DotProduct(unitNormalAB, unitBC);
- SkAssertResult(normalB.setLength(SkScalarDiv(fRadius,
- SkScalarSqrt((SK_Scalar1 + dot)/2))));
+ SkAssertResult(normalB.setLength(fRadius / SkScalarSqrt((SK_Scalar1 + dot)/2)));
dot = SkPoint::DotProduct(*unitNormalCD, unitBC);
- SkAssertResult(normalC.setLength(SkScalarDiv(fRadius,
- SkScalarSqrt((SK_Scalar1 + dot)/2))));
+ SkAssertResult(normalC.setLength(fRadius / SkScalarSqrt((SK_Scalar1 + dot)/2)));
fOuter.cubicTo( pts[1].fX + normalB.fX, pts[1].fY + normalB.fY,
pts[2].fX + normalC.fX, pts[2].fY + normalC.fY,
else
mid.set(before.fX + after.fX, before.fY + after.fY);
- mid.setLength(SkScalarDiv(radius, sinHalfAngle));
+ mid.setLength(radius / sinHalfAngle);
DO_MITER:
if (prevIsLine)
outer->setLastPt(pivot.fX + mid.fX, pivot.fY + mid.fY);
SkScalar startToStop = (stopTransformed.fX - startTransformed.fX)
+ (stopTransformed.fY - startTransformed.fY);
//Percentage along transformed line.
- stopOffsets[i] = SkScalarDiv(startToStop, startToEnd);
+ stopOffsets[i] = startToStop / startToEnd;
}
}
SkVector* ppuScale,
const SkIRect& clip, SkIRect* clipIRect) {
//This action is in unit space, but the ppm is specified in physical space.
- ppuScale->fX = SkScalarDiv(this->fCurrentPixelsPerMeter.fX,
- this->fCurrentUnitsPerMeter.fX);
- ppuScale->fY = SkScalarDiv(this->fCurrentPixelsPerMeter.fY,
- this->fCurrentUnitsPerMeter.fY);
+ ppuScale->set(fCurrentPixelsPerMeter.fX / fCurrentUnitsPerMeter.fX,
+ fCurrentPixelsPerMeter.fY / fCurrentUnitsPerMeter.fY);
matrix->postScale(ppuScale->fX, ppuScale->fY);
SkPoint* step) {
SkScalar dist = SkPoint::Distance(a, b);
- step->set(b.fX - a.fX, b.fY - a.fY);
-
+ *step = b - a;
if (dist <= radius * 2) {
- step->scale(SK_ScalarHalf);
+ *step *= SK_ScalarHalf;
return false;
} else {
- step->scale(SkScalarDiv(radius, dist));
+ *step *= radius / dist;
return true;
}
}
bool prevIsValid = true;
// to avoid warnings
+ step.set(0, 0);
moveTo.set(0, 0);
firstStep.set(0, 0);
lastCorner.set(0, 0);
len2 -= clampedInitialDashLength; // skip initial partial empty
}
}
- int numMidPoints = SkScalarFloorToInt(SkScalarDiv(len2, fIntervalLength));
+ int numMidPoints = SkScalarFloorToInt(len2 / fIntervalLength);
results->fNumPoints += numMidPoints;
len2 -= numMidPoints * fIntervalLength;
bool partialLast = false;
SkBitmap* src,
const SkIRect& bounds)
{
- static const SkScalar Inv8bit = SkScalarDiv(SK_Scalar1, 255.0f);
+ static const SkScalar Inv8bit = SkScalarInvert(255);
const int srcW = src->width();
const int srcH = src->height();
const SkVector scaleForColor = SkVector::Make(SkScalarMul(scale.fX, Inv8bit),
const GrProcessor& proc) {
const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMapEffect>();
GrTexture* colorTex = displacementMap.texture(1);
- SkScalar scaleX = SkScalarDiv(displacementMap.scale().fX, SkIntToScalar(colorTex->width()));
- SkScalar scaleY = SkScalarDiv(displacementMap.scale().fY, SkIntToScalar(colorTex->height()));
+ SkScalar scaleX = displacementMap.scale().fX / colorTex->width();
+ SkScalar scaleY = displacementMap.scale().fY / colorTex->height();
pdman.set2f(fScaleUni, SkScalarToFloat(scaleX),
colorTex->origin() == kTopLeft_GrSurfaceOrigin ?
SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY));
mag = SkScalarSqrt(mag);
for (int i = 0; i < 3; i++) {
- v[i] = SkScalarDiv(v[i], mag);
+ v[i] /= mag;
}
}
namespace {
-const SkScalar gOneThird = SkScalarInvert(SkIntToScalar(3));
-const SkScalar gTwoThirds = SkScalarDiv(SkIntToScalar(2), SkIntToScalar(3));
+const SkScalar gOneThird = SkIntToScalar(1) / 3;
+const SkScalar gTwoThirds = SkIntToScalar(2) / 3;
const SkScalar gOneHalf = 0.5f;
const SkScalar gOneQuarter = 0.25f;
SkScalar highFrequencx =
SkScalarCeilToScalar(tileWidth * fBaseFrequency.fX) / tileWidth;
// BaseFrequency should be non-negative according to the standard.
- if (SkScalarDiv(fBaseFrequency.fX, lowFrequencx) <
- SkScalarDiv(highFrequencx, fBaseFrequency.fX)) {
+ if (fBaseFrequency.fX / lowFrequencx < highFrequencx / fBaseFrequency.fX) {
fBaseFrequency.fX = lowFrequencx;
} else {
fBaseFrequency.fX = highFrequencx;
SkScalarFloorToScalar(tileHeight * fBaseFrequency.fY) / tileHeight;
SkScalar highFrequency =
SkScalarCeilToScalar(tileHeight * fBaseFrequency.fY) / tileHeight;
- if (SkScalarDiv(fBaseFrequency.fY, lowFrequency) <
- SkScalarDiv(highFrequency, fBaseFrequency.fY)) {
+ if (fBaseFrequency.fY / lowFrequency < highFrequency / fBaseFrequency.fY) {
fBaseFrequency.fY = lowFrequency;
} else {
fBaseFrequency.fY = highFrequency;
SkScalar ratio = SK_Scalar1;
for (int octave = 0; octave < perlinNoiseShader.fNumOctaves; ++octave) {
SkScalar noise = noise2D(channel, stitchData, noiseVector);
- turbulenceFunctionResult += SkScalarDiv(
- (perlinNoiseShader.fType == kFractalNoise_Type) ? noise : SkScalarAbs(noise), ratio);
+ SkScalar numer = (perlinNoiseShader.fType == kFractalNoise_Type) ?
+ noise : SkScalarAbs(noise);
+ turbulenceFunctionResult += numer / ratio;
noiseVector.fX *= 2;
noiseVector.fY *= 2;
ratio *= 2;
}
if (channel == 3) { // Scale alpha by paint value
- turbulenceFunctionResult = SkScalarMul(turbulenceFunctionResult,
- SkScalarDiv(SkIntToScalar(getPaintAlpha()), SkIntToScalar(255)));
+ turbulenceFunctionResult *= SkIntToScalar(getPaintAlpha()) / 255;
}
// Clamp result
const SkVector& baseFrequency = turbulence.baseFrequency();
pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY);
- pdman.set1f(fAlphaUni, SkScalarDiv(SkIntToScalar(turbulence.alpha()), SkIntToScalar(255)));
+ pdman.set1f(fAlphaUni, SkIntToScalar(turbulence.alpha()) / 255);
if (turbulence.stitchTiles()) {
const SkPerlinNoiseShader::StitchData& stitchData = turbulence.stitchData();
// Scale factor 1 / (1 - focalX * focalX)
SkScalar oneMinusF2 = 1.f - SkScalarMul(*focalX, *focalX);
- SkScalar s = SkScalarDiv(1.f, oneMinusF2);
+ SkScalar s = SkScalarInvert(oneMinusF2);
if (s >= 0.f) {
: INHERITED(ctx, shader, matrix, tm), fInfo(info) {
this->initClassID<CircleOutside2PtConicalEffect>();
if (shader.getStartRadius() != shader.getEndRadius()) {
- fTLimit = SkScalarDiv(shader.getStartRadius(),
- (shader.getStartRadius() - shader.getEndRadius()));
+ fTLimit = shader.getStartRadius() / (shader.getStartRadius() - shader.getEndRadius());
} else {
fTLimit = SK_ScalarMin;
}
*c = avg;
} else {
area *= 3;
- area = SkScalarDiv(SK_Scalar1, area);
+ area = SkScalarInvert(area);
center.fX = SkScalarMul(center.fX, area);
center.fY = SkScalarMul(center.fY, area);
// undo the translate of p0 to the origin.
const SkRect& bounds = geom.fBounds;
// This adjusts the "radius" to include the half-pixel border
- SkScalar offsetDx = SkScalarDiv(geom.fGeoDx, xRadius);
- SkScalar offsetDy = SkScalarDiv(geom.fGeoDy, yRadius);
+ SkScalar offsetDx = geom.fGeoDx / xRadius;
+ SkScalar offsetDy = geom.fGeoDy / yRadius;
- SkScalar innerRatioX = SkScalarDiv(xRadius, geom.fInnerXRadius);
- SkScalar innerRatioY = SkScalarDiv(yRadius, geom.fInnerYRadius);
+ SkScalar innerRatioX = xRadius / geom.fInnerXRadius;
+ SkScalar innerRatioY = yRadius / geom.fInnerYRadius;
verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop);
verts[0].fOuterOffset = SkPoint::Make(-1.0f - offsetDx, -1.0f - offsetDy);
SkScalar b = viewMatrix[SkMatrix::kMSkewX];
SkScalar c = viewMatrix[SkMatrix::kMSkewY];
SkScalar d = viewMatrix[SkMatrix::kMScaleY];
- SkScalar geoDx = SkScalarDiv(SK_ScalarHalf, SkScalarSqrt(a*a + c*c));
- SkScalar geoDy = SkScalarDiv(SK_ScalarHalf, SkScalarSqrt(b*b + d*d));
+ SkScalar geoDx = SK_ScalarHalf / SkScalarSqrt(a*a + c*c);
+ SkScalar geoDy = SK_ScalarHalf / SkScalarSqrt(b*b + d*d);
DIEllipseBatch::Geometry geometry;
geometry.fViewMatrix = viewMatrix;
stretch = SkMaxScalar(stretch, mat.mapRadius(SK_Scalar1));
}
}
- srcTol = SkScalarDiv(srcTol, stretch);
- return srcTol;
+ return srcTol / stretch;
}
static const int MAX_POINTS_PER_CURVE = 1 << 10;
// subdivide x = log4(d/tol) times. x subdivisions creates 2^(x)
// points.
// 2^(log4(x)) = sqrt(x);
- SkScalar divSqrt = SkScalarSqrt(SkScalarDiv(d, tol));
+ SkScalar divSqrt = SkScalarSqrt(d / tol);
if (((SkScalar)SK_MaxS32) <= divSqrt) {
return MAX_POINTS_PER_CURVE;
} else {
if (d <= tol) {
return 1;
} else {
- SkScalar divSqrt = SkScalarSqrt(SkScalarDiv(d, tol));
+ SkScalar divSqrt = SkScalarSqrt(d / tol);
if (((SkScalar)SK_MaxS32) <= divSqrt) {
return MAX_POINTS_PER_CURVE;
} else {
- int temp = SkScalarCeilToInt(SkScalarSqrt(SkScalarDiv(d, tol)));
+ int temp = SkScalarCeilToInt(SkScalarSqrt(d / tol));
int pow2 = GrNextPow2(temp);
// Because of NaNs & INFs we can wind up with a degenerate temp
// such that pow2 comes out negative. Also, our point generator
}
SkScalar srcIntervalLen = intervals[0] + intervals[1];
SkScalar totalLen = pts[1].fX - pts[0].fX;
- SkScalar temp = SkScalarDiv(totalLen, srcIntervalLen);
+ SkScalar temp = totalLen / srcIntervalLen;
SkScalar numFullIntervals = SkScalarFloorToScalar(temp);
*endingInt = totalLen - numFullIntervals * srcIntervalLen + phase;
- temp = SkScalarDiv(*endingInt, srcIntervalLen);
+ temp = *endingInt / srcIntervalLen;
*endingInt = *endingInt - SkScalarFloorToScalar(temp) * srcIntervalLen;
if (0 == *endingInt) {
*endingInt = srcIntervalLen;
static void emit_pdf_color(SkColor color, SkWStream* result) {
SkASSERT(SkColorGetA(color) == 0xFF); // We handle alpha elsewhere.
- SkScalar colorMax = SkIntToScalar(0xFF);
- SkPDFUtils::AppendScalar(
- SkScalarDiv(SkIntToScalar(SkColorGetR(color)), colorMax), result);
+ SkScalar colorScale = SkScalarInvert(0xFF);
+ SkPDFUtils::AppendScalar(SkColorGetR(color) * colorScale, result);
result->writeText(" ");
- SkPDFUtils::AppendScalar(
- SkScalarDiv(SkIntToScalar(SkColorGetG(color)), colorMax), result);
+ SkPDFUtils::AppendScalar(SkColorGetG(color) * colorScale, result);
result->writeText(" ");
- SkPDFUtils::AppendScalar(
- SkScalarDiv(SkIntToScalar(SkColorGetB(color)), colorMax), result);
+ SkPDFUtils::AppendScalar(SkColorGetB(color) * colorScale, result);
result->writeText(" ");
}
SkAutoTUnref<SkPDFDict> dict(SkNEW_ARGS(SkPDFDict, ("ExtGState")));
dict->insertName("Type", "ExtGState");
- SkScalar alpha = SkScalarDiv(fAlpha, 0xFF);
+ SkScalar alpha = SkIntToScalar(fAlpha) / 0xFF;
dict->insertScalar("CA", alpha);
dict->insertScalar("ca", alpha);
// Figure out how to scale each color component.
SkScalar multiplier[kColorComponents];
for (int i = 0; i < kColorComponents; i++) {
- multiplier[i] = SkScalarDiv(curColor[i] - prevColor[i], range);
+ multiplier[i] = (curColor[i] - prevColor[i]) / range;
}
// Calculate when we no longer need to keep a copy of the input parameter t.
static const SkScalar kMaxBitmapArea = 1024 * 1024;
SkScalar bitmapArea = rasterScale * bbox.width() * rasterScale * bbox.height();
if (bitmapArea > kMaxBitmapArea) {
- rasterScale *= SkScalarSqrt(SkScalarDiv(kMaxBitmapArea, bitmapArea));
+ rasterScale *= SkScalarSqrt(kMaxBitmapArea / bitmapArea);
}
SkISize size = SkISize::Make(SkScalarRoundToInt(rasterScale * bbox.width()),
// This means do not try to scale embedded bitmaps; only scale bitmaps in bitmap only fonts.
if (!FT_IS_SCALABLE(fFace) && fScaleY && fFace->size->metrics.y_ppem) {
// NOTE: both dimensions are scaled by y_ppem. this is WAI.
- scaleGlyphMetrics(*glyph, SkScalarDiv(SkFixedToScalar(fScaleY),
- SkIntToScalar(fFace->size->metrics.y_ppem)));
+ scaleGlyphMetrics(*glyph, SkFixedToScalar(fScaleY) / fFace->size->metrics.y_ppem);
}
#ifdef ENABLE_GLYPH_SPEW
if (strcmp(wSuffix, "pt") == 0)
width = SkScalarMulDiv(width, SK_Scalar1 * 72, SK_Scalar1 * 96);
SkParse::FindScalars(f_viewBox.c_str(), viewBox, 4);
- SkRect box;
- box.fLeft = SkScalarDiv(viewBox[0], width);
- box.fTop = SkScalarDiv(viewBox[1], height);
- box.fRight = SkScalarDiv(viewBox[2], width);
- box.fBottom = SkScalarDiv(viewBox[3], height);
+ SkRect box = SkRect::MakeLTRB(viewBox[0] / width, viewBox[1] / height,
+ viewBox[2] / width, viewBox[3] / height);
if (box.fLeft == 0 && box.fTop == 0 &&
box.fRight == SK_Scalar1 && box.fBottom == SK_Scalar1)
return;
SkMSec nextTime, const SkScalar blend[4]) {
SkASSERT(time > prevTime && time < nextTime);
- SkScalar t = SkScalarDiv((SkScalar)(time - prevTime),
- (SkScalar)(nextTime - prevTime));
+ SkScalar t = (SkScalar)(time - prevTime) / (SkScalar)(nextTime - prevTime);
return blend ?
SkUnitCubicInterp(t, blend[0], blend[1], blend[2], blend[3]) : t;
}
if (bounds.width() >= fixed)
stretchX = (bounds.width() - fixed) / stretchSize;
else // reuse stretchX, but keep it negative as a signal
- stretchX = SkScalarDiv(-bounds.width(), fixed);
+ stretchX = -bounds.width() / fixed;
}
if (numYStretch > 0) {
if (bounds.height() >= fixed)
stretchY = (bounds.height() - fixed) / stretchSize;
else // reuse stretchX, but keep it negative as a signal
- stretchY = SkScalarDiv(-bounds.height(), fixed);
+ stretchY = -bounds.height() / fixed;
}
#if 0
REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, bilerBits));
const SkScalar twoThirds = SK_Scalar1 * 2 / 3;
- const SkScalar bigScale = SkScalarDiv(size.width() + twoThirds, size.width());
+ const SkScalar bigScale = (size.width() + twoThirds) / size.width();
mat.setScale(bigScale, bigScale);
REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, false));
REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits));
const SkScalar oneThird = SK_Scalar1 / 3;
- const SkScalar smallScale = SkScalarDiv(size.width() + oneThird, size.width());
+ const SkScalar smallScale = (size.width() + oneThird) / size.width();
mat.setScale(smallScale, smallScale);
REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, false));
REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits));
const SkScalar oneFortyth = SK_Scalar1 / 40;
- const SkScalar tinyScale = SkScalarDiv(size.width() + oneFortyth, size.width());
+ const SkScalar tinyScale = (size.width() + oneFortyth) / size.width();
mat.setScale(tinyScale, tinyScale);
REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, false));
REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, bilerBits));
mat.mapVectors(vectors, SK_ARRAY_COUNT(vectors));
for (size_t i = 0; i < SK_ARRAY_COUNT(vectors); ++i) {
SkScalar d = vectors[i].length();
- REPORTER_ASSERT(reporter, SkScalarDiv(d, maxScale) < gVectorScaleTol);
- REPORTER_ASSERT(reporter, SkScalarDiv(minScale, d) < gVectorScaleTol);
+ REPORTER_ASSERT(reporter, d / maxScale < gVectorScaleTol);
+ REPORTER_ASSERT(reporter, minScale / d < gVectorScaleTol);
if (max < d) {
max = d;
}
min = d;
}
}
- REPORTER_ASSERT(reporter, SkScalarDiv(max, maxScale) >= gCloseScaleTol);
- REPORTER_ASSERT(reporter, SkScalarDiv(minScale, min) >= gCloseScaleTol);
+ REPORTER_ASSERT(reporter, max / maxScale >= gCloseScaleTol);
+ REPORTER_ASSERT(reporter, minScale / min >= gCloseScaleTol);
}
}
if (d < tol) {
return 1;
} else {
- int temp = SkScalarCeilToInt(SkScalarSqrt(SkScalarDiv(d, tol)));
+ int temp = SkScalarCeilToInt(SkScalarSqrt(d / tol));
uint32_t count = SkMin32(SkNextPow2(temp), MAX_POINTS_PER_CURVE);
return count;
}
#include "sk_tool_utils.h"
static inline SkScalar scalar_log2(SkScalar x) {
- static const SkScalar log2_conversion_factor = SkScalarDiv(1, SkScalarLog(2));
+ static const SkScalar log2_conversion_factor = SkScalarInvert(SkScalarLog(2));
return SkScalarLog(x) * log2_conversion_factor;
}