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) {
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);
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);
return SkShader::MakeEmptyShader();
}
}
- if (1 == colorCount) {
- return SkShader::MakeColorShader(colors[0]);
- }
+
+ EXPAND_1_COLOR(colorCount);
bool flipGradient = startRadius > endRadius;
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);