Index: src/effects/gradients/SkGradientShader.cpp |
diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp |
index 3b761a51cadabba2175375df9b5292f66470c344..6ffe56b9d4299d7c80a1312b5a8c0d6c2514e728 100644 |
--- a/src/effects/gradients/SkGradientShader.cpp |
+++ b/src/effects/gradients/SkGradientShader.cpp |
@@ -742,6 +742,18 @@ |
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 @@ |
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 @@ |
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 @@ |
return SkShader::MakeEmptyShader(); |
} |
} |
- if (1 == colorCount) { |
- return SkShader::MakeColorShader(colors[0]); |
- } |
+ |
+ EXPAND_1_COLOR(colorCount); |
bool flipGradient = startRadius > endRadius; |
@@ -860,9 +867,7 @@ |
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); |