2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "sk_tool_utils.h"
10 #include "SkGradientShader.h"
16 static uint16_t gData[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF };
18 class ColorEmojiBlendModesGM : public GM {
20 const static int W = 64;
21 const static int H = 64;
22 ColorEmojiBlendModesGM() {}
25 void onOnceBeforeDraw() override {
26 const SkColor colors[] = {
27 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE,
28 SK_ColorMAGENTA, SK_ColorCYAN, SK_ColorYELLOW
33 paint.setAntiAlias(true);
34 paint.setShader(SkGradientShader::MakeSweep(0, 0, colors, nullptr, SK_ARRAY_COUNT(colors),
37 sk_sp<SkTypeface> orig(sk_tool_utils::create_portable_typeface("serif",
38 SkFontStyle::FromOldStyle(SkTypeface::kBold)));
39 if (nullptr == orig) {
40 orig = SkTypeface::MakeDefault();
42 fColorType = sk_tool_utils::emoji_typeface();
44 fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType,
45 kOpaque_SkAlphaType), gData, 4);
48 virtual SkString onShortName() override {
49 SkString name("coloremoji_blendmodes");
50 name.append(sk_tool_utils::platform_os_emoji());
54 virtual SkISize onISize() override {
55 return SkISize::Make(400, 640);
58 virtual void onDraw(SkCanvas* canvas) override {
59 canvas->translate(SkIntToScalar(10), SkIntToScalar(20));
61 const SkBlendMode gModes[] = {
65 SkBlendMode::kSrcOver,
66 SkBlendMode::kDstOver,
71 SkBlendMode::kSrcATop,
72 SkBlendMode::kDstATop,
76 SkBlendMode::kModulate,
78 SkBlendMode::kOverlay,
80 SkBlendMode::kLighten,
81 SkBlendMode::kColorDodge,
82 SkBlendMode::kColorBurn,
83 SkBlendMode::kHardLight,
84 SkBlendMode::kSoftLight,
85 SkBlendMode::kDifference,
86 SkBlendMode::kExclusion,
87 SkBlendMode::kMultiply,
89 SkBlendMode::kSaturation,
91 SkBlendMode::kLuminosity,
94 const SkScalar w = SkIntToScalar(W);
95 const SkScalar h = SkIntToScalar(H);
97 m.setScale(SkIntToScalar(6), SkIntToScalar(6));
98 auto s = SkShader::MakeBitmapShader(fBG, SkShader::kRepeat_TileMode,
99 SkShader::kRepeat_TileMode, &m);
102 labelP.setAntiAlias(true);
103 sk_tool_utils::set_portable_typeface(&labelP);
104 labelP.setTextAlign(SkPaint::kCenter_Align);
107 textP.setAntiAlias(true);
108 textP.setTypeface(fColorType);
109 textP.setTextSize(SkIntToScalar(70));
115 SkScalar x = x0, y = y0;
116 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) {
118 r.set(x, y, x+w, y+h);
121 p.setStyle(SkPaint::kFill_Style);
123 canvas->drawRect(r, p);
125 r.inset(-SK_ScalarHalf, -SK_ScalarHalf);
126 p.setStyle(SkPaint::kStroke_Style);
127 p.setShader(nullptr);
128 canvas->drawRect(r, p);
131 SkAutoCanvasRestore arc(canvas, true);
133 textP.setBlendMode(gModes[i]);
134 textP.setTextEncoding(SkPaint::kUTF32_TextEncoding);
135 const char* text = sk_tool_utils::emoji_sample_text();
136 SkUnichar unichar = SkUTF8_ToUnichar(text);
137 canvas->drawText(&unichar, 4, x+ w/10.f, y + 7.f*h/8.f, textP);
140 const char* label = SkBlendMode_Name(gModes[i]);
141 canvas->drawString(label, x + w/2, y - labelP.getTextSize()/2, labelP);
143 x += w + SkIntToScalar(10);
144 if ((i % W) == W - 1) {
146 y += h + SkIntToScalar(30);
153 sk_sp<SkTypeface> fColorType;
155 typedef GM INHERITED;
158 //////////////////////////////////////////////////////////////////////////////
160 static GM* MyFactory(void*) { return new ColorEmojiBlendModesGM; }
161 static GMRegistry reg(MyFactory);