From 6b7a6c74dcf84ee00ed5a24d27ed9baca8fce10f Mon Sep 17 00:00:00 2001 From: reed Date: Thu, 18 Aug 2016 16:13:50 -0700 Subject: [PATCH] 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 --- src/effects/gradients/SkGradientShader.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp index 3b761a5..6ffe56b 100644 --- a/src/effects/gradients/SkGradientShader.cpp +++ b/src/effects/gradients/SkGradientShader.cpp @@ -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 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 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 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 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); -- 2.7.4