Fix Two Pt Radial when circles are concentric.
Review URL: http://codereview.appspot.com/4368047/ git-svn-id: http://skia.googlecode.com/svn/trunk@1069 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
139d84b263
commit
dc66c42d7d
@ -94,10 +94,21 @@ static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
|
||||
data.fColors, data.fPos, data.fCount, tm, mapper);
|
||||
}
|
||||
|
||||
static SkShader* Make2RadialConcentric(const SkPoint pts[2], const GradData& data,
|
||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
||||
SkPoint center;
|
||||
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||
return SkGradientShader::CreateTwoPointRadial(
|
||||
center, (pts[1].fX - pts[0].fX) / 7,
|
||||
center, (pts[1].fX - pts[0].fX) / 2,
|
||||
data.fColors, data.fPos, data.fCount, tm, mapper);
|
||||
}
|
||||
|
||||
typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
|
||||
SkShader::TileMode tm, SkUnitMapper* mapper);
|
||||
static const GradMaker gGradMakers[] = {
|
||||
MakeLinear, MakeRadial, MakeSweep, Make2Radial
|
||||
MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2RadialConcentric
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -127,24 +138,29 @@ protected:
|
||||
{ 0, 0 },
|
||||
{ SkIntToScalar(100), SkIntToScalar(100) }
|
||||
};
|
||||
SkShader::TileMode tm = SkShader::kClamp_TileMode;
|
||||
SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) };
|
||||
SkPaint paint;
|
||||
paint.setDither(true);
|
||||
|
||||
canvas->save();
|
||||
canvas->translate(SkIntToScalar(20), SkIntToScalar(10));
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
|
||||
|
||||
for (int tm = 0; tm < SkShader::kTileModeCount; ++tm) {
|
||||
canvas->save();
|
||||
for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) {
|
||||
SkShader* shader;
|
||||
shader = gGradMakers[j](pts, gGradData[i], tm, NULL);
|
||||
paint.setShader(shader)->unref();
|
||||
canvas->drawRect(r, paint);
|
||||
canvas->translate(0, SkIntToScalar(120));
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
|
||||
canvas->save();
|
||||
for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) {
|
||||
SkShader* shader;
|
||||
shader = gGradMakers[j](pts, gGradData[i], (SkShader::TileMode)tm, NULL);
|
||||
paint.setShader(shader)->unref();
|
||||
canvas->drawRect(r, paint);
|
||||
canvas->translate(0, SkIntToScalar(120));
|
||||
}
|
||||
canvas->restore();
|
||||
canvas->translate(SkIntToScalar(120), 0);
|
||||
}
|
||||
canvas->restore();
|
||||
canvas->translate(SkIntToScalar(120), 0);
|
||||
canvas->translate(SK_ARRAY_COUNT(gGradData)*SkIntToScalar(120), 0);
|
||||
}
|
||||
canvas->restore();
|
||||
|
||||
|
@ -1397,9 +1397,13 @@ public:
|
||||
SkScalarSquare(fDiff.fY));
|
||||
}
|
||||
if (matrix) {
|
||||
SkScalar invDiffL = SkScalarInvert(diffL);
|
||||
matrix->setSinCos(-SkScalarMul(invDiffL, fDiff.fY),
|
||||
SkScalarMul(invDiffL, fDiff.fX));
|
||||
if (diffL) {
|
||||
SkScalar invDiffL = SkScalarInvert(diffL);
|
||||
matrix->setSinCos(-SkScalarMul(invDiffL, fDiff.fY),
|
||||
SkScalarMul(invDiffL, fDiff.fX));
|
||||
} else {
|
||||
matrix->reset();
|
||||
}
|
||||
matrix->preConcat(fPtsToUnit);
|
||||
}
|
||||
if (xy) {
|
||||
|
Loading…
Reference in New Issue
Block a user