Use SkBlendMode_Name rather than one-off tables

BUG=skia:

Change-Id: I653ff55bc1164ddae4b03967f2f54bb5fece5a33
Reviewed-on: https://skia-review.googlesource.com/9722
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2017-03-15 12:19:37 -04:00 committed by Skia Commit-Bot
parent eaaebb19a1
commit d1e67e70ae
11 changed files with 247 additions and 275 deletions

View File

@ -58,22 +58,19 @@ static void test4(SkCanvas* canvas) {
canvas->drawPath(path, paint);
}
constexpr struct {
SkBlendMode fMode;
const char* fLabel;
} gModes[] = {
{ SkBlendMode::kClear, "Clear" },
{ SkBlendMode::kSrc, "Src" },
{ SkBlendMode::kDst, "Dst" },
{ SkBlendMode::kSrcOver, "SrcOver" },
{ SkBlendMode::kDstOver, "DstOver" },
{ SkBlendMode::kSrcIn, "SrcIn" },
{ SkBlendMode::kDstIn, "DstIn" },
{ SkBlendMode::kSrcOut, "SrcOut" },
{ SkBlendMode::kDstOut, "DstOut" },
{ SkBlendMode::kSrcATop, "SrcATop" },
{ SkBlendMode::kDstATop, "DstATop" },
{ SkBlendMode::kXor, "Xor" },
constexpr SkBlendMode gModes[] = {
SkBlendMode::kClear,
SkBlendMode::kSrc,
SkBlendMode::kDst,
SkBlendMode::kSrcOver,
SkBlendMode::kDstOver,
SkBlendMode::kSrcIn,
SkBlendMode::kDstIn,
SkBlendMode::kSrcOut,
SkBlendMode::kDstOut,
SkBlendMode::kSrcATop,
SkBlendMode::kDstATop,
SkBlendMode::kXor,
};
const int gWidth = 64;
@ -155,7 +152,7 @@ namespace skiagm {
}
canvas->drawRect(bounds, fBGPaint);
canvas->saveLayer(&bounds, nullptr);
SkScalar dy = drawCell(canvas, gModes[i].fMode,
SkScalar dy = drawCell(canvas, gModes[i],
gAlphaValue[alpha & 1],
gAlphaValue[alpha & 2]);
canvas->restore();

View File

@ -55,40 +55,37 @@ protected:
virtual void onDraw(SkCanvas* canvas) override {
canvas->translate(SkIntToScalar(10), SkIntToScalar(20));
const struct {
SkBlendMode fMode;
const char* fLabel;
} gModes[] = {
{ SkBlendMode::kClear, "Clear" },
{ SkBlendMode::kSrc, "Src" },
{ SkBlendMode::kDst, "Dst" },
{ SkBlendMode::kSrcOver, "SrcOver" },
{ SkBlendMode::kDstOver, "DstOver" },
{ SkBlendMode::kSrcIn, "SrcIn" },
{ SkBlendMode::kDstIn, "DstIn" },
{ SkBlendMode::kSrcOut, "SrcOut" },
{ SkBlendMode::kDstOut, "DstOut" },
{ SkBlendMode::kSrcATop, "SrcATop" },
{ SkBlendMode::kDstATop, "DstATop" },
const SkBlendMode gModes[] = {
SkBlendMode::kClear,
SkBlendMode::kSrc,
SkBlendMode::kDst,
SkBlendMode::kSrcOver,
SkBlendMode::kDstOver,
SkBlendMode::kSrcIn,
SkBlendMode::kDstIn,
SkBlendMode::kSrcOut,
SkBlendMode::kDstOut,
SkBlendMode::kSrcATop,
SkBlendMode::kDstATop,
{ SkBlendMode::kXor, "Xor" },
{ SkBlendMode::kPlus, "Plus" },
{ SkBlendMode::kModulate, "Modulate" },
{ SkBlendMode::kScreen, "Screen" },
{ SkBlendMode::kOverlay, "Overlay" },
{ SkBlendMode::kDarken, "Darken" },
{ SkBlendMode::kLighten, "Lighten" },
{ SkBlendMode::kColorDodge, "ColorDodge" },
{ SkBlendMode::kColorBurn, "ColorBurn" },
{ SkBlendMode::kHardLight, "HardLight" },
{ SkBlendMode::kSoftLight, "SoftLight" },
{ SkBlendMode::kDifference, "Difference" },
{ SkBlendMode::kExclusion, "Exclusion" },
{ SkBlendMode::kMultiply, "Multiply" },
{ SkBlendMode::kHue, "Hue" },
{ SkBlendMode::kSaturation, "Saturation" },
{ SkBlendMode::kColor, "Color" },
{ SkBlendMode::kLuminosity, "Luminosity" },
SkBlendMode::kXor,
SkBlendMode::kPlus,
SkBlendMode::kModulate,
SkBlendMode::kScreen,
SkBlendMode::kOverlay,
SkBlendMode::kDarken,
SkBlendMode::kLighten,
SkBlendMode::kColorDodge,
SkBlendMode::kColorBurn,
SkBlendMode::kHardLight,
SkBlendMode::kSoftLight,
SkBlendMode::kDifference,
SkBlendMode::kExclusion,
SkBlendMode::kMultiply,
SkBlendMode::kHue,
SkBlendMode::kSaturation,
SkBlendMode::kColor,
SkBlendMode::kLuminosity,
};
const SkScalar w = SkIntToScalar(W);
@ -127,10 +124,11 @@ protected:
p.setShader(nullptr);
canvas->drawRect(r, p);
textP.setBlendMode(gModes[i].fMode);
textP.setBlendMode(gModes[i]);
canvas->drawText("H", 1, x+ w/10.f, y + 7.f*h/8.f, textP);
#if 1
canvas->drawText(gModes[i].fLabel, strlen(gModes[i].fLabel),
const char* label = SkBlendMode_Name(gModes[i]);
canvas->drawText(label, strlen(label),
x + w/2, y - labelP.getTextSize()/2, labelP);
#endif
x += w + SkIntToScalar(10);

View File

@ -74,39 +74,36 @@ protected:
auto atlas = make_atlas(canvas, kAtlasSize);
const struct {
SkBlendMode fMode;
const char* fLabel;
} gModes[] = {
{ SkBlendMode::kClear, "Clear" },
{ SkBlendMode::kSrc, "Src" },
{ SkBlendMode::kDst, "Dst" },
{ SkBlendMode::kSrcOver, "SrcOver" },
{ SkBlendMode::kDstOver, "DstOver" },
{ SkBlendMode::kSrcIn, "SrcIn" },
{ SkBlendMode::kDstIn, "DstIn" },
{ SkBlendMode::kSrcOut, "SrcOut" },
{ SkBlendMode::kDstOut, "DstOut" },
{ SkBlendMode::kSrcATop, "SrcATop" },
{ SkBlendMode::kDstATop, "DstATop" },
{ SkBlendMode::kXor, "Xor" },
{ SkBlendMode::kPlus, "Plus" },
{ SkBlendMode::kModulate, "Mod" },
{ SkBlendMode::kScreen, "Screen" },
{ SkBlendMode::kOverlay, "Overlay" },
{ SkBlendMode::kDarken, "Darken" },
{ SkBlendMode::kLighten, "Lighten" },
{ SkBlendMode::kColorDodge, "Dodge" },
{ SkBlendMode::kColorBurn, "Burn" },
{ SkBlendMode::kHardLight, "Hard" },
{ SkBlendMode::kSoftLight, "Soft" },
{ SkBlendMode::kDifference, "Diff" },
{ SkBlendMode::kExclusion, "Exclusion" },
{ SkBlendMode::kMultiply, "Multiply" },
{ SkBlendMode::kHue, "Hue" },
{ SkBlendMode::kSaturation, "Sat" },
{ SkBlendMode::kColor, "Color" },
{ SkBlendMode::kLuminosity, "Luminosity"},
const SkBlendMode gModes[] = {
SkBlendMode::kClear,
SkBlendMode::kSrc,
SkBlendMode::kDst,
SkBlendMode::kSrcOver,
SkBlendMode::kDstOver,
SkBlendMode::kSrcIn,
SkBlendMode::kDstIn,
SkBlendMode::kSrcOut,
SkBlendMode::kDstOut,
SkBlendMode::kSrcATop,
SkBlendMode::kDstATop,
SkBlendMode::kXor,
SkBlendMode::kPlus,
SkBlendMode::kModulate,
SkBlendMode::kScreen,
SkBlendMode::kOverlay,
SkBlendMode::kDarken,
SkBlendMode::kLighten,
SkBlendMode::kColorDodge,
SkBlendMode::kColorBurn,
SkBlendMode::kHardLight,
SkBlendMode::kSoftLight,
SkBlendMode::kDifference,
SkBlendMode::kExclusion,
SkBlendMode::kMultiply,
SkBlendMode::kHue,
SkBlendMode::kSaturation,
SkBlendMode::kColor,
SkBlendMode::kLuminosity,
};
SkColor gColors[] = {
@ -139,7 +136,8 @@ protected:
sk_tool_utils::set_portable_typeface(&textP, nullptr);
for (int i = 0; i < numModes; ++i) {
canvas->drawText(gModes[i].fLabel, strlen(gModes[i].fLabel),
const char* label = SkBlendMode_Name(gModes[i]);
canvas->drawText(label, strlen(label),
i*(target.width()+kPad)+kPad, SkIntToScalar(kTextPad),
textP);
}
@ -150,11 +148,11 @@ protected:
SkIntToScalar(kTextPad+kPad));
// w/o a paint
canvas->drawAtlas(atlas.get(), xforms, rects, quadColors, numColors,
gModes[i].fMode, nullptr, nullptr);
gModes[i], nullptr, nullptr);
canvas->translate(0.0f, numColors*(target.height()+kPad));
// w a paint
canvas->drawAtlas(atlas.get(), xforms, rects, quadColors, numColors,
gModes[i].fMode, nullptr, &paint);
gModes[i], nullptr, &paint);
canvas->restore();
}
}

View File

@ -10,22 +10,19 @@
#include "SkColorPriv.h"
#include "SkShader.h"
constexpr struct {
SkBlendMode fMode;
const char* fLabel;
} gModes[] = {
{ SkBlendMode::kClear, "Clear" },
{ SkBlendMode::kSrc, "Src" },
{ SkBlendMode::kDst, "Dst" },
{ SkBlendMode::kSrcOver, "SrcOver" },
{ SkBlendMode::kDstOver, "DstOver" },
{ SkBlendMode::kSrcIn, "SrcIn" },
{ SkBlendMode::kDstIn, "DstIn" },
{ SkBlendMode::kSrcOut, "SrcOut" },
{ SkBlendMode::kDstOut, "DstOut" },
{ SkBlendMode::kSrcATop, "SrcATop" },
{ SkBlendMode::kDstATop, "DstATop" },
{ SkBlendMode::kXor, "Xor" },
constexpr SkBlendMode gModes[] = {
SkBlendMode::kClear,
SkBlendMode::kSrc,
SkBlendMode::kDst,
SkBlendMode::kSrcOver,
SkBlendMode::kDstOver,
SkBlendMode::kSrcIn,
SkBlendMode::kDstIn,
SkBlendMode::kSrcOut,
SkBlendMode::kDstOut,
SkBlendMode::kSrcATop,
SkBlendMode::kDstATop,
SkBlendMode::kXor,
};
const int gWidth = 64;
@ -104,7 +101,7 @@ namespace skiagm {
canvas->drawRect(bounds, fBGPaint);
canvas->saveLayer(&bounds, nullptr);
SkScalar dy = drawCell(canvas, gModes[i].fMode,
SkScalar dy = drawCell(canvas, gModes[i],
gAlphaValue[alpha & 1],
gAlphaValue[alpha & 2]);
canvas->restore();

View File

@ -81,39 +81,36 @@ protected:
}
void drawColumn(SkCanvas* canvas, SkColor backgroundColor, SkColor textColor, bool useGrad) {
const struct {
SkBlendMode fMode;
const char* fLabel;
} gModes[] = {
{ SkBlendMode::kClear, "Clear" },
{ SkBlendMode::kSrc, "Src" },
{ SkBlendMode::kDst, "Dst" },
{ SkBlendMode::kSrcOver, "SrcOver" },
{ SkBlendMode::kDstOver, "DstOver" },
{ SkBlendMode::kSrcIn, "SrcIn" },
{ SkBlendMode::kDstIn, "DstIn" },
{ SkBlendMode::kSrcOut, "SrcOut" },
{ SkBlendMode::kDstOut, "DstOut" },
{ SkBlendMode::kSrcATop, "SrcATop" },
{ SkBlendMode::kDstATop, "DstATop" },
{ SkBlendMode::kXor, "Xor" },
{ SkBlendMode::kPlus, "Plus" },
{ SkBlendMode::kModulate, "Modulate" },
{ SkBlendMode::kScreen, "Screen" },
{ SkBlendMode::kOverlay, "Overlay" },
{ SkBlendMode::kDarken, "Darken" },
{ SkBlendMode::kLighten, "Lighten" },
{ SkBlendMode::kColorDodge, "ColorDodge" },
{ SkBlendMode::kColorBurn, "ColorBurn" },
{ SkBlendMode::kHardLight, "HardLight" },
{ SkBlendMode::kSoftLight, "SoftLight" },
{ SkBlendMode::kDifference, "Difference" },
{ SkBlendMode::kExclusion, "Exclusion" },
{ SkBlendMode::kMultiply, "Multiply" },
{ SkBlendMode::kHue, "Hue" },
{ SkBlendMode::kSaturation, "Saturation" },
{ SkBlendMode::kColor, "Color" },
{ SkBlendMode::kLuminosity, "Luminosity" },
const SkBlendMode gModes[] = {
SkBlendMode::kClear,
SkBlendMode::kSrc,
SkBlendMode::kDst,
SkBlendMode::kSrcOver,
SkBlendMode::kDstOver,
SkBlendMode::kSrcIn,
SkBlendMode::kDstIn,
SkBlendMode::kSrcOut,
SkBlendMode::kDstOut,
SkBlendMode::kSrcATop,
SkBlendMode::kDstATop,
SkBlendMode::kXor,
SkBlendMode::kPlus,
SkBlendMode::kModulate,
SkBlendMode::kScreen,
SkBlendMode::kOverlay,
SkBlendMode::kDarken,
SkBlendMode::kLighten,
SkBlendMode::kColorDodge,
SkBlendMode::kColorBurn,
SkBlendMode::kHardLight,
SkBlendMode::kSoftLight,
SkBlendMode::kDifference,
SkBlendMode::kExclusion,
SkBlendMode::kMultiply,
SkBlendMode::kHue,
SkBlendMode::kSaturation,
SkBlendMode::kColor,
SkBlendMode::kLuminosity,
};
// Draw background rect
SkPaint backgroundPaint;
@ -127,15 +124,15 @@ protected:
paint.setSubpixelText(true);
paint.setLCDRenderText(true);
paint.setTextSize(fTextHeight);
paint.setBlendMode(gModes[m].fMode);
paint.setBlendMode(gModes[m]);
sk_tool_utils::set_portable_typeface(&paint);
if (useGrad) {
SkRect r;
r.setXYWH(0, y - fTextHeight, SkIntToScalar(kColWidth), fTextHeight);
paint.setShader(make_shader(r));
}
SkString string(gModes[m].fLabel);
canvas->drawText(gModes[m].fLabel, string.size(), 0, y, paint);
SkString string(SkBlendMode_Name(gModes[m]));
canvas->drawText(string.c_str(), string.size(), 0, y, paint);
y+=fTextHeight;
}
}

View File

@ -48,46 +48,43 @@ protected:
canvas->clear(SK_ColorBLACK);
SkPaint paint;
const struct {
SkBlendMode fMode;
const char* fLabel;
} gModes[] = {
{ SkBlendMode::kClear, "Clear" },
{ SkBlendMode::kSrc, "Src" },
{ SkBlendMode::kDst, "Dst" },
{ SkBlendMode::kSrcOver, "SrcOver" },
{ SkBlendMode::kDstOver, "DstOver" },
{ SkBlendMode::kSrcIn, "SrcIn" },
{ SkBlendMode::kDstIn, "DstIn" },
{ SkBlendMode::kSrcOut, "SrcOut" },
{ SkBlendMode::kDstOut, "DstOut" },
{ SkBlendMode::kSrcATop, "SrcATop" },
{ SkBlendMode::kDstATop, "DstATop" },
{ SkBlendMode::kXor, "Xor" },
const SkBlendMode gModes[] = {
SkBlendMode::kClear,
SkBlendMode::kSrc,
SkBlendMode::kDst,
SkBlendMode::kSrcOver,
SkBlendMode::kDstOver,
SkBlendMode::kSrcIn,
SkBlendMode::kDstIn,
SkBlendMode::kSrcOut,
SkBlendMode::kDstOut,
SkBlendMode::kSrcATop,
SkBlendMode::kDstATop,
SkBlendMode::kXor,
{ SkBlendMode::kPlus, "Plus" },
{ SkBlendMode::kModulate, "Modulate" },
{ SkBlendMode::kScreen, "Screen" },
{ SkBlendMode::kOverlay, "Overlay" },
{ SkBlendMode::kDarken, "Darken" },
{ SkBlendMode::kLighten, "Lighten" },
{ SkBlendMode::kColorDodge, "ColorDodge" },
{ SkBlendMode::kColorBurn, "ColorBurn" },
{ SkBlendMode::kHardLight, "HardLight" },
{ SkBlendMode::kSoftLight, "SoftLight" },
{ SkBlendMode::kDifference, "Difference" },
{ SkBlendMode::kExclusion, "Exclusion" },
{ SkBlendMode::kMultiply, "Multiply" },
{ SkBlendMode::kHue, "Hue" },
{ SkBlendMode::kSaturation, "Saturation" },
{ SkBlendMode::kColor, "Color" },
{ SkBlendMode::kLuminosity, "Luminosity" },
SkBlendMode::kPlus,
SkBlendMode::kModulate,
SkBlendMode::kScreen,
SkBlendMode::kOverlay,
SkBlendMode::kDarken,
SkBlendMode::kLighten,
SkBlendMode::kColorDodge,
SkBlendMode::kColorBurn,
SkBlendMode::kHardLight,
SkBlendMode::kSoftLight,
SkBlendMode::kDifference,
SkBlendMode::kExclusion,
SkBlendMode::kMultiply,
SkBlendMode::kHue,
SkBlendMode::kSaturation,
SkBlendMode::kColor,
SkBlendMode::kLuminosity,
};
int x = 0, y = 0;
sk_sp<SkImageFilter> background(SkImageSource::Make(fCheckerboard));
for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) {
paint.setImageFilter(SkXfermodeImageFilter::Make(gModes[i].fMode, background));
paint.setImageFilter(SkXfermodeImageFilter::Make(gModes[i], background));
DrawClippedBitmap(canvas, fBitmap, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {

View File

@ -34,7 +34,6 @@ enum SrcType {
const struct {
SkBlendMode fMode;
const char* fLabel;
int fSourceTypeMask; // The source types to use this
// mode with. See draw_mode for
// an explanation of each type.
@ -42,36 +41,36 @@ const struct {
// to support the base modes,
// test those more extensively.
} gModes[] = {
{ SkBlendMode::kClear, "Clear", kAll_SrcType },
{ SkBlendMode::kSrc, "Src", kAll_SrcType },
{ SkBlendMode::kDst, "Dst", kAll_SrcType },
{ SkBlendMode::kSrcOver, "SrcOver", kAll_SrcType },
{ SkBlendMode::kDstOver, "DstOver", kAll_SrcType },
{ SkBlendMode::kSrcIn, "SrcIn", kAll_SrcType },
{ SkBlendMode::kDstIn, "DstIn", kAll_SrcType },
{ SkBlendMode::kSrcOut, "SrcOut", kAll_SrcType },
{ SkBlendMode::kDstOut, "DstOut", kAll_SrcType },
{ SkBlendMode::kSrcATop, "SrcATop", kAll_SrcType },
{ SkBlendMode::kDstATop, "DstATop", kAll_SrcType },
{ SkBlendMode::kClear, kAll_SrcType },
{ SkBlendMode::kSrc, kAll_SrcType },
{ SkBlendMode::kDst, kAll_SrcType },
{ SkBlendMode::kSrcOver, kAll_SrcType },
{ SkBlendMode::kDstOver, kAll_SrcType },
{ SkBlendMode::kSrcIn, kAll_SrcType },
{ SkBlendMode::kDstIn, kAll_SrcType },
{ SkBlendMode::kSrcOut, kAll_SrcType },
{ SkBlendMode::kDstOut, kAll_SrcType },
{ SkBlendMode::kSrcATop, kAll_SrcType },
{ SkBlendMode::kDstATop, kAll_SrcType },
{ SkBlendMode::kXor, "Xor", kBasic_SrcType },
{ SkBlendMode::kPlus, "Plus", kBasic_SrcType },
{ SkBlendMode::kModulate, "Modulate", kAll_SrcType },
{ SkBlendMode::kScreen, "Screen", kBasic_SrcType },
{ SkBlendMode::kOverlay, "Overlay", kBasic_SrcType },
{ SkBlendMode::kDarken, "Darken", kBasic_SrcType },
{ SkBlendMode::kLighten, "Lighten", kBasic_SrcType },
{ SkBlendMode::kColorDodge, "ColorDodge", kBasic_SrcType },
{ SkBlendMode::kColorBurn, "ColorBurn", kBasic_SrcType },
{ SkBlendMode::kHardLight, "HardLight", kBasic_SrcType },
{ SkBlendMode::kSoftLight, "SoftLight", kBasic_SrcType },
{ SkBlendMode::kDifference, "Difference", kBasic_SrcType },
{ SkBlendMode::kExclusion, "Exclusion", kBasic_SrcType },
{ SkBlendMode::kMultiply, "Multiply", kAll_SrcType },
{ SkBlendMode::kHue, "Hue", kBasic_SrcType },
{ SkBlendMode::kSaturation, "Saturation", kBasic_SrcType },
{ SkBlendMode::kColor, "Color", kBasic_SrcType },
{ SkBlendMode::kLuminosity, "Luminosity", kBasic_SrcType },
{ SkBlendMode::kXor, kBasic_SrcType },
{ SkBlendMode::kPlus, kBasic_SrcType },
{ SkBlendMode::kModulate, kAll_SrcType },
{ SkBlendMode::kScreen, kBasic_SrcType },
{ SkBlendMode::kOverlay, kBasic_SrcType },
{ SkBlendMode::kDarken, kBasic_SrcType },
{ SkBlendMode::kLighten, kBasic_SrcType },
{ SkBlendMode::kColorDodge, kBasic_SrcType },
{ SkBlendMode::kColorBurn, kBasic_SrcType },
{ SkBlendMode::kHardLight, kBasic_SrcType },
{ SkBlendMode::kSoftLight, kBasic_SrcType },
{ SkBlendMode::kDifference, kBasic_SrcType },
{ SkBlendMode::kExclusion, kBasic_SrcType },
{ SkBlendMode::kMultiply, kAll_SrcType },
{ SkBlendMode::kHue, kBasic_SrcType },
{ SkBlendMode::kSaturation, kBasic_SrcType },
{ SkBlendMode::kColor, kBasic_SrcType },
{ SkBlendMode::kLuminosity, kBasic_SrcType },
};
static void make_bitmaps(int w, int h, SkBitmap* src, SkBitmap* dst,
@ -258,7 +257,8 @@ protected:
canvas->drawRect(r, p);
#if 1
canvas->drawText(gModes[i].fLabel, strlen(gModes[i].fLabel),
const char* label = SkBlendMode_Name(gModes[i].fMode);
canvas->drawText(label, strlen(label),
x + w/2, y - labelP.getTextSize()/2, labelP);
#endif
x += w + SkIntToScalar(10);

View File

@ -11,22 +11,19 @@
#include "SkColorPriv.h"
#include "SkShader.h"
static const struct {
SkBlendMode fMode;
const char* fLabel;
} gModes[] = {
{ SkBlendMode::kClear, "Clear" },
{ SkBlendMode::kSrc, "Src" },
{ SkBlendMode::kDst, "Dst" },
{ SkBlendMode::kSrcOver, "SrcOver" },
{ SkBlendMode::kDstOver, "DstOver" },
{ SkBlendMode::kSrcIn, "SrcIn" },
{ SkBlendMode::kDstIn, "DstIn" },
{ SkBlendMode::kSrcOut, "SrcOut" },
{ SkBlendMode::kDstOut, "DstOut" },
{ SkBlendMode::kSrcATop, "SrcATop" },
{ SkBlendMode::kDstATop, "DstATop" },
{ SkBlendMode::kXor, "Xor" },
static const SkBlendMode gModes[] = {
SkBlendMode::kClear,
SkBlendMode::kSrc,
SkBlendMode::kDst,
SkBlendMode::kSrcOver,
SkBlendMode::kDstOver,
SkBlendMode::kSrcIn,
SkBlendMode::kDstIn,
SkBlendMode::kSrcOut,
SkBlendMode::kDstOut,
SkBlendMode::kSrcATop,
SkBlendMode::kDstATop,
SkBlendMode::kXor,
};
const int gWidth = 64;
@ -109,7 +106,7 @@ protected:
canvas->drawRect(bounds, fBGPaint);
canvas->saveLayer(&bounds, nullptr);
SkScalar dy = drawCell(canvas, gModes[i].fMode, gAlphaValue[alpha & 1],
SkScalar dy = drawCell(canvas, gModes[i], gAlphaValue[alpha & 1],
gAlphaValue[alpha & 2]);
canvas->restore();

View File

@ -11,22 +11,19 @@
#include "SkColorPriv.h"
#include "SkShader.h"
static const struct {
SkBlendMode fMode;
const char* fLabel;
} gModes[] = {
{ SkBlendMode::kClear, "Clear" },
{ SkBlendMode::kSrc, "Src" },
{ SkBlendMode::kDst, "Dst" },
{ SkBlendMode::kSrcOver, "SrcOver" },
{ SkBlendMode::kDstOver, "DstOver" },
{ SkBlendMode::kSrcIn, "SrcIn" },
{ SkBlendMode::kDstIn, "DstIn" },
{ SkBlendMode::kSrcOut, "SrcOut" },
{ SkBlendMode::kDstOut, "DstOut" },
{ SkBlendMode::kSrcATop, "SrcATop" },
{ SkBlendMode::kDstATop, "DstATop" },
{ SkBlendMode::kXor, "Xor" },
static const SkBlendMode gModes[] = {
SkBlendMode::kClear,
SkBlendMode::kSrc,
SkBlendMode::kDst,
SkBlendMode::kSrcOver,
SkBlendMode::kDstOver,
SkBlendMode::kSrcIn,
SkBlendMode::kDstIn,
SkBlendMode::kSrcOut,
SkBlendMode::kDstOut,
SkBlendMode::kSrcATop,
SkBlendMode::kDstATop,
SkBlendMode::kXor,
};
const int gWidth = 64;
@ -105,7 +102,7 @@ protected:
}
canvas->drawRect(bounds, fBGPaint);
canvas->saveLayer(&bounds, nullptr);
SkScalar dy = drawCell(canvas, gModes[i].fMode,
SkScalar dy = drawCell(canvas, gModes[i],
gAlphaValue[alpha & 1],
gAlphaValue[alpha & 2]);
canvas->restore();

View File

@ -17,19 +17,16 @@
#include "SkSurface.h"
#include "SkGradientShader.h"
const struct {
SkBlendMode fMode;
const char* fName;
} gModes[] = {
{ SkBlendMode::kSrcOver, "src-over" },
{ SkBlendMode::kSrc, "src" },
{ SkBlendMode::kSrcIn, "src-in" },
{ SkBlendMode::kSrcOut, "src-out" },
{ SkBlendMode::kSrcATop, "src-atop" },
{ SkBlendMode::kDstOver, "dst-over" },
{ SkBlendMode::kDstIn, "dst-in" },
{ SkBlendMode::kDstOut, "dst-out" },
{ SkBlendMode::kDstATop, "dst-atop" },
const SkBlendMode gModes[] = {
SkBlendMode::kSrcOver,
SkBlendMode::kSrc,
SkBlendMode::kSrcIn,
SkBlendMode::kSrcOut,
SkBlendMode::kSrcATop,
SkBlendMode::kDstOver,
SkBlendMode::kDstIn,
SkBlendMode::kDstOut,
SkBlendMode::kDstATop,
};
const int N_Modes = SK_ARRAY_COUNT(gModes);
@ -160,7 +157,7 @@ class XferDemo : public SampleView {
SkScalar x = 10;
SkScalar y = 10;
for (int i = 0; i < N_Modes; ++i) {
sk_sp<SkView> v(new PushButtonWig(gModes[i].fName, (int)gModes[i].fMode));
sk_sp<SkView> v(new PushButtonWig(SkBlendMode_Name(gModes[i]), (int)gModes[i]));
v->setSize(70, 25);
v->setLoc(x, y);
v->setVisibleP(true);
@ -209,7 +206,7 @@ protected:
SkPaint paint;
if (fSelected) {
for (int i = 0; i < N_Modes; ++i) {
if (fSelected->fMode == gModes[i].fMode) {
if (fSelected->fMode == gModes[i]) {
canvas->drawRect(fModeRect[i], paint);
break;
}

View File

@ -107,24 +107,20 @@ protected:
return;
}
const struct {
SkBlendMode fMode;
const char* fLabel;
} gModes[] = {
{ SkBlendMode::kClear, "Clear" },
{ SkBlendMode::kSrc, "Src" },
{ SkBlendMode::kDst, "Dst" },
{ SkBlendMode::kSrcOver, "SrcOver" },
{ SkBlendMode::kDstOver, "DstOver" },
{ SkBlendMode::kSrcIn, "SrcIn" },
{ SkBlendMode::kDstIn, "DstIn" },
{ SkBlendMode::kSrcOut, "SrcOut" },
{ SkBlendMode::kDstOut, "DstOut" },
{ SkBlendMode::kSrcATop, "SrcATop" },
{ SkBlendMode::kDstATop, "DstATop" },
{ SkBlendMode::kXor, "Xor" },
{ SkBlendMode::kPlus, "Plus" },
const SkBlendMode gModes[] = {
SkBlendMode::kClear,
SkBlendMode::kSrc,
SkBlendMode::kDst,
SkBlendMode::kSrcOver,
SkBlendMode::kDstOver,
SkBlendMode::kSrcIn,
SkBlendMode::kDstIn,
SkBlendMode::kSrcOut,
SkBlendMode::kDstOut,
SkBlendMode::kSrcATop,
SkBlendMode::kDstATop,
SkBlendMode::kXor,
SkBlendMode::kPlus,
};
const SkScalar w = SkIntToScalar(W);
@ -155,7 +151,7 @@ protected:
canvas->drawRect(r, p);
canvas->saveLayer(&r, nullptr);
draw_mode(canvas, gModes[i].fMode, twice ? 0x88 : 0xFF, r.fLeft, r.fTop);
draw_mode(canvas, gModes[i], twice ? 0x88 : 0xFF, r.fLeft, r.fTop);
canvas->restore();
r.inset(-SK_ScalarHalf, -SK_ScalarHalf);
@ -163,7 +159,8 @@ protected:
p.setShader(nullptr);
canvas->drawRect(r, p);
canvas->drawText(gModes[i].fLabel, strlen(gModes[i].fLabel),
const char* label = SkBlendMode_Name(gModes[i]);
canvas->drawText(label, strlen(label),
x + w/2, y - labelP.getTextSize()/2, labelP);
x += w + SkIntToScalar(10);
if ((i % W) == W - 1) {