Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
coloremoji_blendmodes.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm/gm.h"
13#include "include/core/SkFont.h"
19#include "include/core/SkRect.h"
23#include "include/core/SkSize.h"
30#include "src/base/SkUTF.h"
31#include "tools/ToolUtils.h"
33
34#include <string.h>
35
36namespace {
37
38static uint16_t gData[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF };
39
40class ColorEmojiBlendModesGM : public skiagm::GM {
41public:
42 const static int W = 64;
43 const static int H = 64;
44 ColorEmojiBlendModesGM(ToolUtils::EmojiFontFormat format) : fFormat(format) {}
45
46protected:
47 void onOnceBeforeDraw() override {
48 const SkColor colors[] = {
51 };
53 local.setRotate(180);
55 paint.setAntiAlias(true);
56 paint.setShader(SkGradientShader::MakeSweep(0, 0, colors, nullptr, std::size(colors),
57 0, &local));
58
60 SkASSERT(orig);
61 fColorSample = ToolUtils::EmojiSample(fFormat);
62
63 fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType,
65 }
66
67 SkString getName() const override {
68 return SkString("coloremoji_blendmodes_") += ToolUtils::NameForFontFormat(fFormat);
69 }
70
71 SkISize getISize() override { return {400, 640}; }
72
73 DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg) override {
74
75 if (!fColorSample.typeface) {
76 *errorMsg = SkStringPrintf("Unable to instantiate emoji test font of format %s.",
77 ToolUtils::NameForFontFormat(fFormat).c_str());
78 return DrawResult::kSkip;
79 }
80
81 canvas->translate(SkIntToScalar(10), SkIntToScalar(20));
82
83 const SkBlendMode gModes[] = {
95
114 };
115
116 const SkScalar w = SkIntToScalar(W);
117 const SkScalar h = SkIntToScalar(H);
118 SkMatrix m;
119 m.setScale(SkIntToScalar(6), SkIntToScalar(6));
120 auto s = fBG.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, SkSamplingOptions(), m);
121
123
124 SkPaint textP;
125 textP.setAntiAlias(true);
126 SkFont textFont(fColorSample.typeface, 70);
127
128 const int kWrap = 5;
129
130 SkScalar x0 = 0;
131 SkScalar y0 = 0;
132 SkScalar x = x0, y = y0;
133 for (size_t i = 0; i < std::size(gModes); i++) {
134 SkRect r;
135 r.setLTRB(x, y, x+w, y+h);
136
137 SkPaint p;
138 p.setStyle(SkPaint::kFill_Style);
139 p.setShader(s);
140 canvas->drawRect(r, p);
141
143 p.setStyle(SkPaint::kStroke_Style);
144 p.setShader(nullptr);
145 canvas->drawRect(r, p);
146
147 {
148 SkAutoCanvasRestore arc(canvas, true);
149 canvas->clipRect(r);
150 textP.setBlendMode(gModes[i]);
151 const char* text = fColorSample.sampleText;
152 SkUnichar unichar = SkUTF::NextUTF8(&text, text + strlen(text));
153 SkASSERT(unichar >= 0);
154 canvas->drawSimpleText(&unichar, 4, SkTextEncoding::kUTF32,
155 x+ w/10.f, y + 7.f*h/8.f, textFont, textP);
156 }
157#if 1
158 const char* label = SkBlendMode_Name(gModes[i]);
159 SkTextUtils::DrawString(canvas, label, x + w/2, y - labelFont.getSize()/2,
160 labelFont, SkPaint(), SkTextUtils::kCenter_Align);
161#endif
162 x += w + SkIntToScalar(10);
163 if ((i % kWrap) == kWrap - 1) {
164 x = x0;
165 y += h + SkIntToScalar(30);
166 }
167 }
168
169 return DrawResult::kOk;
170 }
171
172private:
173 SkBitmap fBG;
175 ToolUtils::EmojiTestSample fColorSample;
176
177 using INHERITED = GM;
178};
179} // namespace
180
181DEF_GM(return new ColorEmojiBlendModesGM(ToolUtils::EmojiFontFormat::ColrV0);)
182DEF_GM(return new ColorEmojiBlendModesGM(ToolUtils::EmojiFontFormat::Sbix);)
183DEF_GM(return new ColorEmojiBlendModesGM(ToolUtils::EmojiFontFormat::Cbdt);)
184DEF_GM(return new ColorEmojiBlendModesGM(ToolUtils::EmojiFontFormat::Test);)
185DEF_GM(return new ColorEmojiBlendModesGM(ToolUtils::EmojiFontFormat::Svg);)
@ kOpaque_SkAlphaType
pixel is opaque
Definition SkAlphaType.h:28
#define SkASSERT(cond)
Definition SkAssert.h:116
SK_API const char * SkBlendMode_Name(SkBlendMode blendMode)
SkBlendMode
Definition SkBlendMode.h:38
@ kSrcOut
r = s * (1-da)
@ kExclusion
rc = s + d - two(s*d), ra = kSrcOver
@ kSaturation
saturation of source with hue and luminosity of destination
@ kColorBurn
darken destination to reflect source
@ kPlus
r = min(s + d, 1)
@ kLighten
rc = s + d - min(s*da, d*sa), ra = kSrcOver
@ kHue
hue of source with saturation and luminosity of destination
@ kDstIn
r = d * sa
@ kModulate
r = s*d
@ kMultiply
r = s*(1-da) + d*(1-sa) + s*d
@ kColorDodge
brighten destination to reflect source
@ kScreen
r = s + d - s*d
@ kSrcOver
r = s + (1-sa)*d
@ kXor
r = s*(1-da) + d*(1-sa)
@ kLuminosity
luminosity of source with hue and saturation of destination
@ kSoftLight
lighten or darken, depending on source
@ kDifference
rc = s + d - 2*(min(s*da, d*sa)), ra = kSrcOver
@ kOverlay
multiply or screen, depending on destination
@ kSrcATop
r = s*da + d*(1-sa)
@ kDstATop
r = d*sa + s*(1-da)
@ kDstOver
r = d + (1-da)*s
@ kColor
hue and saturation of source with luminosity of destination
@ kHardLight
multiply or screen, depending on source
@ kDstOut
r = d * (1-sa)
@ kDarken
rc = s + d - max(s*da, d*sa), ra = kSrcOver
@ kSrcIn
r = s * da
@ kClear
r = 0
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
Definition SkColorType.h:23
constexpr SkColor SK_ColorYELLOW
Definition SkColor.h:139
constexpr SkColor SK_ColorMAGENTA
Definition SkColor.h:147
uint32_t SkColor
Definition SkColor.h:37
constexpr SkColor SK_ColorCYAN
Definition SkColor.h:143
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
@ kUTF32
uses four byte words to represent all of Unicode
#define INHERITED(method,...)
#define SK_ScalarHalf
Definition SkScalar.h:19
#define SkIntToScalar(x)
Definition SkScalar.h:57
SK_API SkString static SkString SkStringPrintf()
Definition SkString.h:287
int32_t SkUnichar
Definition SkTypes.h:175
#define W
Definition aaa.cpp:17
constexpr SkBlendMode gModes[]
void drawRect(const SkRect &rect, const SkPaint &paint)
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
void translate(SkScalar dx, SkScalar dy)
static constexpr SkFontStyle Bold()
Definition SkFontStyle.h:69
static sk_sp< SkShader > MakeSweep(SkScalar cx, SkScalar cy, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, SkScalar startAngle, SkScalar endAngle, uint32_t flags, const SkMatrix *localMatrix)
void setAntiAlias(bool aa)
Definition SkPaint.h:170
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
void setBlendMode(SkBlendMode mode)
Definition SkPaint.cpp:151
static void DrawString(SkCanvas *canvas, const char text[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint, Align align=kLeft_Align)
Definition SkTextUtils.h:34
virtual SkISize getISize()=0
virtual void onOnceBeforeDraw()
Definition gm.cpp:167
virtual SkString getName() const =0
virtual DrawResult onDraw(SkCanvas *, SkString *errorMsg)
Definition gm.cpp:139
const Paint & paint
float SkScalar
Definition extension.cpp:12
struct MyStruct s
uint32_t uint32_t * format
#define DEF_GM(CODE)
Definition gm.h:40
std::u16string text
double y
double x
PODArray< SkColor > colors
Definition SkRecords.h:276
SK_SPI SkUnichar NextUTF8(const char **ptr, const char *end)
Definition SkUTF.cpp:118
sk_sp< SkTypeface > DefaultPortableTypeface()
SkString NameForFontFormat(EmojiFontFormat format)
sk_sp< SkTypeface > CreatePortableTypeface(const char *name, SkFontStyle style)
EmojiTestSample EmojiSample()
DrawResult
Definition gm.h:104
SkScalar w
SkScalar h
Definition SkMD5.cpp:130
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
void inset(float dx, float dy)
Definition SkRect.h:1060
void setLTRB(float left, float top, float right, float bottom)
Definition SkRect.h:865
static uint16_t gData[]