Revert of Return color shader instead of 2-color gradient when color count is 1 (patchset #3 id:40001 of https://codereview.chromium.org/2259823005/ )
Reason for revert: breaks 2-pt-conical, which can sometimes not draw anything Original issue's description: > Return color shader instead of 2-color gradient when color count is 1 > > BUG=skia: > GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2259823005 > > Committed: https://skia.googlesource.com/skia/+/da082a5767d7edfd3abe74fc683392422565a606 TBR=fmenozzi@google.com # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia: Review-Url: https://codereview.chromium.org/2257993002
This commit is contained in:
parent
f1b6030b44
commit
6b7a6c74dc
@ -742,6 +742,18 @@ static bool valid_grad(const SkColor colors[], const SkScalar pos[], int count,
|
||||
return nullptr != colors && count >= 1 && tileMode < (unsigned)SkShader::kTileModeCount;
|
||||
}
|
||||
|
||||
// assumes colors is SkColor* and pos is SkScalar*
|
||||
#define EXPAND_1_COLOR(count) \
|
||||
SkColor tmp[2]; \
|
||||
do { \
|
||||
if (1 == count) { \
|
||||
tmp[0] = tmp[1] = colors[0]; \
|
||||
colors = tmp; \
|
||||
pos = nullptr; \
|
||||
count = 2; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static void desc_init(SkGradientShaderBase::Descriptor* desc,
|
||||
const SkColor colors[], const SkScalar pos[], int colorCount,
|
||||
SkShader::TileMode mode, uint32_t flags, const SkMatrix* localMatrix) {
|
||||
@ -767,9 +779,7 @@ sk_sp<SkShader> SkGradientShader::MakeLinear(const SkPoint pts[2],
|
||||
if (!valid_grad(colors, pos, colorCount, mode)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (1 == colorCount) {
|
||||
return SkShader::MakeColorShader(colors[0]);
|
||||
}
|
||||
EXPAND_1_COLOR(colorCount);
|
||||
|
||||
SkGradientShaderBase::Descriptor desc;
|
||||
desc_init(&desc, colors, pos, colorCount, mode, flags, localMatrix);
|
||||
@ -788,9 +798,7 @@ sk_sp<SkShader> SkGradientShader::MakeRadial(const SkPoint& center, SkScalar rad
|
||||
if (!valid_grad(colors, pos, colorCount, mode)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (1 == colorCount) {
|
||||
return SkShader::MakeColorShader(colors[0]);
|
||||
}
|
||||
EXPAND_1_COLOR(colorCount);
|
||||
|
||||
SkGradientShaderBase::Descriptor desc;
|
||||
desc_init(&desc, colors, pos, colorCount, mode, flags, localMatrix);
|
||||
@ -818,9 +826,8 @@ sk_sp<SkShader> SkGradientShader::MakeTwoPointConical(const SkPoint& start,
|
||||
return SkShader::MakeEmptyShader();
|
||||
}
|
||||
}
|
||||
if (1 == colorCount) {
|
||||
return SkShader::MakeColorShader(colors[0]);
|
||||
}
|
||||
|
||||
EXPAND_1_COLOR(colorCount);
|
||||
|
||||
bool flipGradient = startRadius > endRadius;
|
||||
|
||||
@ -860,9 +867,7 @@ sk_sp<SkShader> SkGradientShader::MakeSweep(SkScalar cx, SkScalar cy,
|
||||
if (!valid_grad(colors, pos, colorCount, SkShader::kClamp_TileMode)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (1 == colorCount) {
|
||||
return SkShader::MakeColorShader(colors[0]);
|
||||
}
|
||||
EXPAND_1_COLOR(colorCount);
|
||||
|
||||
SkGradientShaderBase::Descriptor desc;
|
||||
desc_init(&desc, colors, pos, colorCount, SkShader::kClamp_TileMode, flags, localMatrix);
|
||||
|
Loading…
Reference in New Issue
Block a user