2014-04-22 20:56:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2014-05-22 12:27:41 +00:00
|
|
|
|
2014-04-22 20:56:37 +00:00
|
|
|
#include "gm.h"
|
|
|
|
#include "SkGradientShader.h"
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
struct GradData {
|
|
|
|
int fCount;
|
|
|
|
const SkColor* fColors;
|
|
|
|
const SkScalar* fPos;
|
|
|
|
};
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkColor gColors[] = {
|
2014-04-22 20:56:37 +00:00
|
|
|
SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK
|
|
|
|
};
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkScalar gPos0[] = { 0, SK_Scalar1 };
|
|
|
|
constexpr SkScalar gPos1[] = { SK_Scalar1/4, SK_Scalar1*3/4 };
|
|
|
|
constexpr SkScalar gPos2[] = {
|
2014-04-22 20:56:37 +00:00
|
|
|
0, SK_Scalar1/8, SK_Scalar1/2, SK_Scalar1*7/8, SK_Scalar1
|
|
|
|
};
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkScalar gPosClamp[] = {0.0f, 0.0f, 1.0f, 1.0f};
|
|
|
|
constexpr SkColor gColorClamp[] = {
|
2014-04-22 20:56:37 +00:00
|
|
|
SK_ColorRED, SK_ColorGREEN, SK_ColorGREEN, SK_ColorBLUE
|
|
|
|
};
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr GradData gGradData[] = {
|
2014-04-22 20:56:37 +00:00
|
|
|
{ 2, gColors, gPos0 },
|
|
|
|
{ 2, gColors, gPos1 },
|
|
|
|
{ 5, gColors, gPos2 },
|
|
|
|
{ 4, gColorClamp, gPosClamp }
|
|
|
|
};
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
static sk_sp<SkShader> Make2ConicalOutside(const SkPoint pts[2], const GradData& data,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm, const SkMatrix& localMatrix) {
|
2014-04-22 20:56:37 +00:00
|
|
|
SkPoint center0, center1;
|
2015-05-12 17:37:34 +00:00
|
|
|
SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
|
|
|
|
SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
|
2014-04-22 20:56:37 +00:00
|
|
|
center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
|
|
|
|
center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
|
2016-03-13 21:13:58 +00:00
|
|
|
return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
|
|
|
|
data.fPos, data.fCount, tm, 0, &localMatrix);
|
2014-04-22 20:56:37 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 20:47:26 +00:00
|
|
|
static sk_sp<SkShader> Make2ConicalOutsideStrip(const SkPoint pts[2], const GradData& data,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm, const SkMatrix& localMatrix) {
|
2017-12-13 20:47:26 +00:00
|
|
|
SkPoint center0, center1;
|
|
|
|
SkScalar radius = (pts[1].fX - pts[0].fX) / 3;
|
|
|
|
center0.set(pts[0].fX, pts[0].fY);
|
|
|
|
center1.set(pts[1].fX, pts[1].fY);
|
|
|
|
return SkGradientShader::MakeTwoPointConical(center0, radius, center1, radius, data.fColors,
|
|
|
|
data.fPos, data.fCount, tm, 0, &localMatrix);
|
|
|
|
}
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
static sk_sp<SkShader> Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& data,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm, const SkMatrix& localMatrix) {
|
2014-04-22 20:56:37 +00:00
|
|
|
SkPoint center0, center1;
|
2015-05-12 17:37:34 +00:00
|
|
|
SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
|
|
|
|
SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
|
2014-04-22 20:56:37 +00:00
|
|
|
center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
|
|
|
|
center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
|
2016-03-13 21:13:58 +00:00
|
|
|
return SkGradientShader::MakeTwoPointConical(center1, radius1, center0, radius0, data.fColors,
|
|
|
|
data.fPos, data.fCount, tm, 0, &localMatrix);
|
2014-04-22 20:56:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
static sk_sp<SkShader> Make2ConicalInside(const SkPoint pts[2], const GradData& data,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm, const SkMatrix& localMatrix) {
|
2014-04-22 20:56:37 +00:00
|
|
|
SkPoint center0, center1;
|
|
|
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
|
|
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
|
|
|
center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
|
|
|
|
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
2016-03-13 21:13:58 +00:00
|
|
|
return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
|
|
|
|
center0, (pts[1].fX - pts[0].fX) / 2,
|
|
|
|
data.fColors, data.fPos, data.fCount, tm,
|
|
|
|
0, &localMatrix);
|
2014-04-22 20:56:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
static sk_sp<SkShader> Make2ConicalInsideFlip(const SkPoint pts[2], const GradData& data,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm, const SkMatrix& localMatrix) {
|
2014-04-22 20:56:37 +00:00
|
|
|
SkPoint center0, center1;
|
|
|
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
|
|
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
|
|
|
center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
|
|
|
|
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
2016-03-13 21:13:58 +00:00
|
|
|
return SkGradientShader::MakeTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 2,
|
|
|
|
center1, (pts[1].fX - pts[0].fX) / 7,
|
|
|
|
data.fColors, data.fPos, data.fCount, tm,
|
|
|
|
0, &localMatrix);
|
2014-04-22 20:56:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
static sk_sp<SkShader> Make2ConicalInsideCenter(const SkPoint pts[2], const GradData& data,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm, const SkMatrix& localMatrix) {
|
2018-03-19 18:23:48 +00:00
|
|
|
SkPoint center0;
|
2014-04-22 20:56:37 +00:00
|
|
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
|
|
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
2016-03-13 21:13:58 +00:00
|
|
|
return SkGradientShader::MakeTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 7,
|
|
|
|
center0, (pts[1].fX - pts[0].fX) / 2,
|
|
|
|
data.fColors, data.fPos, data.fCount, tm,
|
|
|
|
0, &localMatrix);
|
2014-04-22 20:56:37 +00:00
|
|
|
}
|
|
|
|
|
2018-03-19 18:23:48 +00:00
|
|
|
static sk_sp<SkShader> Make2ConicalInsideCenterReversed(const SkPoint pts[2], const GradData& data,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm, const SkMatrix& localMatrix) {
|
2018-03-19 18:23:48 +00:00
|
|
|
SkPoint center0;
|
|
|
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
|
|
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
|
|
|
return SkGradientShader::MakeTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 2,
|
|
|
|
center0, (pts[1].fX - pts[0].fX) / 7,
|
|
|
|
data.fColors, data.fPos, data.fCount, tm,
|
|
|
|
0, &localMatrix);
|
|
|
|
}
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
static sk_sp<SkShader> Make2ConicalZeroRad(const SkPoint pts[2], const GradData& data,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm, const SkMatrix& localMatrix) {
|
2014-04-22 20:56:37 +00:00
|
|
|
SkPoint center0, center1;
|
|
|
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
|
|
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
|
|
|
center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
|
|
|
|
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
2016-03-13 21:13:58 +00:00
|
|
|
return SkGradientShader::MakeTwoPointConical(center1, 0.f,
|
|
|
|
center0, (pts[1].fX - pts[0].fX) / 2,
|
|
|
|
data.fColors, data.fPos, data.fCount, tm,
|
|
|
|
0, &localMatrix);
|
2014-04-22 20:56:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
static sk_sp<SkShader> Make2ConicalZeroRadFlip(const SkPoint pts[2], const GradData& data,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm, const SkMatrix& localMatrix) {
|
2014-04-22 20:56:37 +00:00
|
|
|
SkPoint center0, center1;
|
|
|
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
|
|
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
|
|
|
center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
|
|
|
|
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
2016-03-13 21:13:58 +00:00
|
|
|
return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 2,
|
|
|
|
center0, 0.f,
|
|
|
|
data.fColors, data.fPos, data.fCount, tm,
|
|
|
|
0, &localMatrix);
|
2014-04-22 20:56:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
static sk_sp<SkShader> Make2ConicalZeroRadCenter(const SkPoint pts[2], const GradData& data,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm, const SkMatrix& localMatrix) {
|
2014-04-22 20:56:37 +00:00
|
|
|
SkPoint center0, center1;
|
|
|
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
|
|
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
|
|
|
center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
|
|
|
|
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
2016-03-13 21:13:58 +00:00
|
|
|
return SkGradientShader::MakeTwoPointConical(center0, 0.f, center0, (pts[1].fX - pts[0].fX) / 2,
|
|
|
|
data.fColors, data.fPos, data.fCount, tm,
|
|
|
|
0, &localMatrix);
|
2014-04-22 20:56:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
static sk_sp<SkShader> Make2ConicalZeroRadOutside(const SkPoint pts[2], const GradData& data,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm,
|
2016-03-13 21:13:58 +00:00
|
|
|
const SkMatrix& localMatrix) {
|
2014-04-22 20:56:37 +00:00
|
|
|
SkPoint center0, center1;
|
2014-04-22 21:24:22 +00:00
|
|
|
SkScalar radius0 = 0.f;
|
2015-05-12 17:37:34 +00:00
|
|
|
SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
|
2014-04-22 20:56:37 +00:00
|
|
|
center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
|
|
|
|
center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
|
2016-03-13 21:13:58 +00:00
|
|
|
return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1,
|
|
|
|
data.fColors, data.fPos,
|
|
|
|
data.fCount, tm, 0, &localMatrix);
|
2014-04-22 20:56:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
static sk_sp<SkShader> Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], const GradData& data,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm,
|
2016-03-13 21:13:58 +00:00
|
|
|
const SkMatrix& localMatrix) {
|
2014-04-22 20:56:37 +00:00
|
|
|
SkPoint center0, center1;
|
2014-04-22 21:24:22 +00:00
|
|
|
SkScalar radius0 = 0.f;
|
2015-05-12 17:37:34 +00:00
|
|
|
SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
|
2014-04-22 20:56:37 +00:00
|
|
|
center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
|
|
|
|
center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
|
2016-03-13 21:13:58 +00:00
|
|
|
return SkGradientShader::MakeTwoPointConical(center1, radius1, center0, radius0, data.fColors,
|
|
|
|
data.fPos, data.fCount, tm, 0, &localMatrix);
|
2014-04-22 20:56:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
static sk_sp<SkShader> Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm, const SkMatrix& localMatrix) {
|
2014-04-22 20:56:37 +00:00
|
|
|
SkPoint center0, center1;
|
2015-05-12 17:37:34 +00:00
|
|
|
SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
|
|
|
|
SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
|
2014-04-22 20:56:37 +00:00
|
|
|
center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
|
|
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
|
|
|
center0.set(center1.fX + radius1, center1.fY);
|
2016-03-13 21:13:58 +00:00
|
|
|
return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
|
|
|
|
data.fPos, data.fCount, tm, 0, &localMatrix);
|
2014-04-22 20:56:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
static sk_sp<SkShader> Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm, const SkMatrix& localMatrix) {
|
2014-04-22 20:56:37 +00:00
|
|
|
SkPoint center0, center1;
|
2015-05-12 17:37:34 +00:00
|
|
|
SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
|
|
|
|
SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
|
2014-04-22 20:56:37 +00:00
|
|
|
center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
|
|
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
|
|
|
center0.set(center1.fX, center1.fY + radius1);
|
2016-03-13 21:13:58 +00:00
|
|
|
return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
|
|
|
|
data.fPos, data.fCount, tm, 0, &localMatrix);
|
2014-04-22 20:56:37 +00:00
|
|
|
}
|
2014-06-09 18:57:28 +00:00
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
static sk_sp<SkShader> Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const GradData& data,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm,
|
2016-03-13 21:13:58 +00:00
|
|
|
const SkMatrix& localMatrix) {
|
2014-04-22 20:56:37 +00:00
|
|
|
SkPoint center0, center1;
|
2014-04-22 21:24:22 +00:00
|
|
|
SkScalar radius0 = 0.f;
|
2015-05-12 17:37:34 +00:00
|
|
|
SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
|
2014-04-22 20:56:37 +00:00
|
|
|
center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
|
|
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
|
|
|
center0.set(center1.fX + radius1, center1.fY);
|
2016-03-13 21:13:58 +00:00
|
|
|
return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
|
|
|
|
data.fPos, data.fCount, tm, 0, &localMatrix);
|
2014-04-22 20:56:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
static sk_sp<SkShader> Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const GradData& data,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm, const SkMatrix& localMatrix) {
|
2014-04-22 20:56:37 +00:00
|
|
|
SkPoint center0, center1;
|
2014-04-22 21:24:22 +00:00
|
|
|
SkScalar radius0 = 0.f;
|
2015-05-12 17:37:34 +00:00
|
|
|
SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
|
2014-04-22 20:56:37 +00:00
|
|
|
center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
|
|
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
|
|
|
center0.set(center1.fX, center1.fY + radius1);
|
2016-03-13 21:13:58 +00:00
|
|
|
return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
|
|
|
|
data.fPos, data.fCount, tm, 0, &localMatrix);
|
2014-04-22 20:56:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
static sk_sp<SkShader> Make2ConicalTouchX(const SkPoint pts[2], const GradData& data,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm, const SkMatrix& localMatrix) {
|
2014-04-22 20:56:37 +00:00
|
|
|
SkPoint center0, center1;
|
2015-05-12 17:37:34 +00:00
|
|
|
SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
|
|
|
|
SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
|
2014-04-22 20:56:37 +00:00
|
|
|
center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
|
|
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
|
|
|
center0.set(center1.fX - radius1 + radius0, center1.fY);
|
2016-03-13 21:13:58 +00:00
|
|
|
return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
|
|
|
|
data.fPos, data.fCount, tm, 0, &localMatrix);
|
2014-04-22 20:56:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
static sk_sp<SkShader> Make2ConicalTouchY(const SkPoint pts[2], const GradData& data,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm, const SkMatrix& localMatrix) {
|
2014-04-22 20:56:37 +00:00
|
|
|
SkPoint center0, center1;
|
2015-05-12 17:37:34 +00:00
|
|
|
SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
|
|
|
|
SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
|
2014-04-22 20:56:37 +00:00
|
|
|
center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
|
|
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
|
|
|
center0.set(center1.fX, center1.fY + radius1 - radius0);
|
2016-03-13 21:13:58 +00:00
|
|
|
return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
|
|
|
|
data.fPos, data.fCount, tm, 0, &localMatrix);
|
2014-04-22 20:56:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
static sk_sp<SkShader> Make2ConicalInsideSmallRad(const SkPoint pts[2], const GradData& data,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm, const SkMatrix& localMatrix) {
|
2014-04-22 20:56:37 +00:00
|
|
|
SkPoint center0, center1;
|
|
|
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
|
|
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
|
|
|
center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
|
|
|
|
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
2016-03-13 21:13:58 +00:00
|
|
|
return SkGradientShader::MakeTwoPointConical(center0, 0.0000000000000000001f,
|
2014-04-28 14:55:39 +00:00
|
|
|
center0, (pts[1].fX - pts[0].fX) / 2,
|
2014-05-22 12:27:41 +00:00
|
|
|
data.fColors, data.fPos, data.fCount, tm,
|
2014-04-28 14:55:39 +00:00
|
|
|
0, &localMatrix);
|
2014-04-22 20:56:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm, const SkMatrix& localMatrix);
|
2014-04-22 20:56:37 +00:00
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr GradMaker gGradMakersOutside[] = {
|
2014-04-22 20:56:37 +00:00
|
|
|
Make2ConicalOutside, Make2ConicalOutsideFlip,
|
2017-12-13 20:47:26 +00:00
|
|
|
Make2ConicalZeroRadOutside, Make2ConicalZeroRadFlipOutside,
|
|
|
|
Make2ConicalOutsideStrip
|
2014-04-22 20:56:37 +00:00
|
|
|
};
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr GradMaker gGradMakersInside[] = {
|
2014-04-22 20:56:37 +00:00
|
|
|
Make2ConicalInside, Make2ConicalInsideFlip, Make2ConicalInsideCenter,
|
|
|
|
Make2ConicalZeroRad, Make2ConicalZeroRadFlip, Make2ConicalZeroRadCenter,
|
2018-03-19 18:23:48 +00:00
|
|
|
Make2ConicalInsideCenterReversed
|
2014-04-22 20:56:37 +00:00
|
|
|
};
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr GradMaker gGradMakersEdgeCases[] = {
|
2014-04-22 20:56:37 +00:00
|
|
|
Make2ConicalEdgeX, Make2ConicalEdgeY,
|
|
|
|
Make2ConicalZeroRadEdgeX, Make2ConicalZeroRadEdgeY,
|
|
|
|
Make2ConicalTouchX, Make2ConicalTouchY,
|
|
|
|
Make2ConicalInsideSmallRad
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr struct {
|
2014-04-22 20:56:37 +00:00
|
|
|
const GradMaker* fMaker;
|
|
|
|
const int fCount;
|
|
|
|
const char* fName;
|
|
|
|
} gGradCases[] = {
|
|
|
|
{ gGradMakersOutside, SK_ARRAY_COUNT(gGradMakersOutside), "outside" },
|
|
|
|
{ gGradMakersInside, SK_ARRAY_COUNT(gGradMakersInside), "inside" },
|
|
|
|
{ gGradMakersEdgeCases, SK_ARRAY_COUNT(gGradMakersEdgeCases), "edge" },
|
|
|
|
};
|
|
|
|
|
|
|
|
enum GradCaseType { // these must match the order in gGradCases
|
|
|
|
kOutside_GradCaseType,
|
|
|
|
kInside_GradCaseType,
|
|
|
|
kEdge_GradCaseType,
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class ConicalGradientsGM : public GM {
|
|
|
|
public:
|
2017-06-27 17:38:26 +00:00
|
|
|
ConicalGradientsGM(GradCaseType gradCaseType, bool dither,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode mode = SkTileMode::kClamp)
|
2015-10-12 17:41:48 +00:00
|
|
|
: fGradCaseType(gradCaseType)
|
2017-06-27 17:38:26 +00:00
|
|
|
, fDither(dither)
|
|
|
|
, fMode(mode) {
|
2018-08-16 14:17:03 +00:00
|
|
|
this->setBGColor(0xFFDDDDDD);
|
2015-10-12 17:41:48 +00:00
|
|
|
fName.printf("gradients_2pt_conical_%s%s", gGradCases[gradCaseType].fName,
|
|
|
|
fDither ? "" : "_nodither");
|
2017-06-27 17:38:26 +00:00
|
|
|
switch (mode) {
|
2019-04-03 14:27:45 +00:00
|
|
|
case SkTileMode::kRepeat:
|
2017-06-27 17:38:26 +00:00
|
|
|
fName.appendf("_repeat");
|
|
|
|
break;
|
2019-04-03 14:27:45 +00:00
|
|
|
case SkTileMode::kMirror:
|
2017-06-27 17:38:26 +00:00
|
|
|
fName.appendf("_mirror");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-04-22 20:56:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString onShortName() {
|
|
|
|
return fName;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual SkISize onISize() { return SkISize::Make(840, 815); }
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
|
|
|
|
|
|
SkPoint pts[2] = {
|
|
|
|
{ 0, 0 },
|
|
|
|
{ SkIntToScalar(100), SkIntToScalar(100) }
|
|
|
|
};
|
|
|
|
SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) };
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
2015-10-12 17:41:48 +00:00
|
|
|
paint.setDither(fDither);
|
2014-04-22 20:56:37 +00:00
|
|
|
|
|
|
|
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
|
|
|
|
|
|
|
|
const GradMaker* gradMaker = gGradCases[fGradCaseType].fMaker;
|
|
|
|
const int count = gGradCases[fGradCaseType].fCount;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
|
|
|
|
canvas->save();
|
|
|
|
for (int j = 0; j < count; j++) {
|
2014-04-28 14:55:39 +00:00
|
|
|
SkMatrix scale = SkMatrix::I();
|
2014-04-22 20:56:37 +00:00
|
|
|
|
|
|
|
if (i == 3) { // if the clamp case
|
|
|
|
scale.setScale(0.5f, 0.5f);
|
|
|
|
scale.postTranslate(25.f, 25.f);
|
|
|
|
}
|
|
|
|
|
2017-06-27 17:38:26 +00:00
|
|
|
paint.setShader(gradMaker[j](pts, gGradData[i], fMode, scale));
|
2014-04-22 20:56:37 +00:00
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
canvas->translate(0, SkIntToScalar(120));
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(SkIntToScalar(120), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
|
|
|
|
GradCaseType fGradCaseType;
|
|
|
|
SkString fName;
|
2015-10-12 17:41:48 +00:00
|
|
|
bool fDither;
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode fMode;
|
2014-04-22 20:56:37 +00:00
|
|
|
};
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-10-12 17:41:48 +00:00
|
|
|
DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, true); )
|
|
|
|
DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, true); )
|
|
|
|
DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, true); )
|
2014-04-22 20:56:37 +00:00
|
|
|
|
2019-04-03 14:27:45 +00:00
|
|
|
DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, true, SkTileMode::kRepeat); )
|
|
|
|
DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, true, SkTileMode::kRepeat); )
|
|
|
|
DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, true, SkTileMode::kRepeat); )
|
2017-06-27 17:38:26 +00:00
|
|
|
|
2019-04-03 14:27:45 +00:00
|
|
|
DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, true, SkTileMode::kMirror); )
|
|
|
|
DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, true, SkTileMode::kMirror); )
|
|
|
|
DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, true, SkTileMode::kMirror); )
|
2017-06-27 17:38:26 +00:00
|
|
|
|
2015-10-12 17:41:48 +00:00
|
|
|
DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, false); )
|
|
|
|
DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, false); )
|
|
|
|
DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, false); )
|
2014-04-22 20:56:37 +00:00
|
|
|
|
|
|
|
}
|