Added conical gradient to gm gradients test, and added two variants of that test, one with perspective applied to the local matrices of the gradients and the other with perspective applied to the overall view matrix.
Will require GM rebaselining. Review URL: https://codereview.appspot.com/6344091 git-svn-id: http://skia.googlecode.com/svn/trunk@4468 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
21320a17aa
commit
5cf2c28427
102
gm/gradients.cpp
102
gm/gradients.cpp
@ -70,10 +70,23 @@ static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
|
||||
data.fColors, data.fPos, data.fCount, tm, mapper);
|
||||
}
|
||||
|
||||
static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data,
|
||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
||||
SkPoint center0, center1;
|
||||
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
|
||||
SkScalar radius1 = SkScalarDiv(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,
|
||||
center0, radius0,
|
||||
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, Make2Conical
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -89,7 +102,7 @@ protected:
|
||||
return SkString("gradients");
|
||||
}
|
||||
|
||||
virtual SkISize onISize() { return make_isize(640, 510); }
|
||||
virtual SkISize onISize() { return make_isize(640, 615); }
|
||||
|
||||
virtual void onDraw(SkCanvas* canvas) {
|
||||
|
||||
@ -121,6 +134,84 @@ private:
|
||||
typedef GM INHERITED;
|
||||
};
|
||||
|
||||
// Based on the original gradient slide, but with perspective applied to the
|
||||
// gradient shaders' local matrices
|
||||
class GradientsLocalPerspectiveGM : public GM {
|
||||
public:
|
||||
GradientsLocalPerspectiveGM() {
|
||||
this->setBGColor(0xFFDDDDDD);
|
||||
}
|
||||
|
||||
protected:
|
||||
SkString onShortName() {
|
||||
return SkString("gradients_local_perspective");
|
||||
}
|
||||
|
||||
virtual SkISize onISize() { return make_isize(640, 615); }
|
||||
|
||||
virtual void onDraw(SkCanvas* canvas) {
|
||||
|
||||
SkPoint pts[2] = {
|
||||
{ 0, 0 },
|
||||
{ SkIntToScalar(100), SkIntToScalar(100) }
|
||||
};
|
||||
SkShader::TileMode tm = SkShader::kClamp_TileMode;
|
||||
SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) };
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
|
||||
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
|
||||
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 = gGradMakers[j](pts, gGradData[i], tm, NULL);
|
||||
|
||||
// apply an increasing y perspective as we move to the right
|
||||
SkMatrix perspective;
|
||||
perspective.setIdentity();
|
||||
perspective.setPerspY(SkScalarDiv(SkIntToScalar(i+1),
|
||||
SkIntToScalar(500)));
|
||||
perspective.setSkewX(SkScalarDiv(SkIntToScalar(i+1),
|
||||
SkIntToScalar(10)));
|
||||
shader->setLocalMatrix(perspective);
|
||||
|
||||
paint.setShader(shader);
|
||||
canvas->drawRect(r, paint);
|
||||
shader->unref();
|
||||
canvas->translate(0, SkIntToScalar(120));
|
||||
}
|
||||
canvas->restore();
|
||||
canvas->translate(SkIntToScalar(120), 0);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
typedef GM INHERITED;
|
||||
};
|
||||
|
||||
// Based on the original gradient slide, but with perspective applied to
|
||||
// the view matrix
|
||||
class GradientsViewPerspectiveGM : public GradientsGM {
|
||||
protected:
|
||||
SkString onShortName() {
|
||||
return SkString("gradients_view_perspective");
|
||||
}
|
||||
|
||||
virtual SkISize onISize() { return make_isize(640, 400); }
|
||||
|
||||
virtual void onDraw(SkCanvas* canvas) {
|
||||
SkMatrix perspective;
|
||||
perspective.setIdentity();
|
||||
perspective.setPerspY(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000)));
|
||||
perspective.setSkewX(SkScalarDiv(SkIntToScalar(8), SkIntToScalar(25)));
|
||||
canvas->setMatrix(perspective);
|
||||
INHERITED::onDraw(canvas);
|
||||
}
|
||||
|
||||
private:
|
||||
typedef GradientsGM INHERITED;
|
||||
};
|
||||
|
||||
/*
|
||||
Inspired by this <canvas> javascript, where we need to detect that we are not
|
||||
solving a quadratic equation, but must instead solve a linear (since our X^2
|
||||
@ -269,5 +360,12 @@ static GMRegistry reg3(MyFactory3);
|
||||
|
||||
static GM* MyFactory4(void*) { return new RadialGradientGM; }
|
||||
static GMRegistry reg4(MyFactory4);
|
||||
|
||||
static GM* MyFactory5(void*) { return new GradientsLocalPerspectiveGM; }
|
||||
static GMRegistry reg5(MyFactory5);
|
||||
|
||||
static GM* MyFactory6(void*) { return new GradientsViewPerspectiveGM; }
|
||||
static GMRegistry reg6(MyFactory6);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user