2014-10-31 13:55:45 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2018-03-14 19:07:43 +00:00
|
|
|
|
2014-10-31 13:55:45 +00:00
|
|
|
#include "SkBitmap.h"
|
2018-03-14 19:07:43 +00:00
|
|
|
#include "SkBlendMode.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkColor.h"
|
|
|
|
#include "SkFontStyle.h"
|
2014-10-31 13:55:45 +00:00
|
|
|
#include "SkGradientShader.h"
|
2018-03-14 19:07:43 +00:00
|
|
|
#include "SkImageInfo.h"
|
|
|
|
#include "SkMatrix.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRect.h"
|
|
|
|
#include "SkRefCnt.h"
|
|
|
|
#include "SkScalar.h"
|
2014-10-31 13:55:45 +00:00
|
|
|
#include "SkShader.h"
|
2018-03-14 19:07:43 +00:00
|
|
|
#include "SkSize.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
#include "SkTypeface.h"
|
|
|
|
#include "SkTypes.h"
|
2018-08-21 15:45:46 +00:00
|
|
|
#include "SkUTF.h"
|
2018-03-14 19:07:43 +00:00
|
|
|
#include "gm.h"
|
|
|
|
#include "sk_tool_utils.h"
|
2014-10-31 13:55:45 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
static uint16_t gData[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF };
|
|
|
|
|
2017-04-25 15:09:16 +00:00
|
|
|
class ColorEmojiBlendModesGM : public GM {
|
2014-10-31 13:55:45 +00:00
|
|
|
public:
|
|
|
|
const static int W = 64;
|
|
|
|
const static int H = 64;
|
2017-04-25 15:09:16 +00:00
|
|
|
ColorEmojiBlendModesGM() {}
|
2015-05-21 13:15:28 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void onOnceBeforeDraw() override {
|
2014-10-31 13:55:45 +00:00
|
|
|
const SkColor colors[] = {
|
|
|
|
SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE,
|
|
|
|
SK_ColorMAGENTA, SK_ColorCYAN, SK_ColorYELLOW
|
|
|
|
};
|
|
|
|
SkMatrix local;
|
|
|
|
local.setRotate(180);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
2016-03-09 17:50:50 +00:00
|
|
|
paint.setShader(SkGradientShader::MakeSweep(0, 0, colors, nullptr, SK_ARRAY_COUNT(colors),
|
|
|
|
0, &local));
|
2014-10-31 13:55:45 +00:00
|
|
|
|
2016-05-31 18:42:36 +00:00
|
|
|
sk_sp<SkTypeface> orig(sk_tool_utils::create_portable_typeface("serif",
|
2017-07-27 14:45:29 +00:00
|
|
|
SkFontStyle::Bold()));
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == orig) {
|
2016-05-12 17:09:30 +00:00
|
|
|
orig = SkTypeface::MakeDefault();
|
2014-10-31 13:55:45 +00:00
|
|
|
}
|
2017-04-25 15:09:16 +00:00
|
|
|
fColorType = sk_tool_utils::emoji_typeface();
|
2014-10-31 13:55:45 +00:00
|
|
|
|
2015-05-21 13:15:28 +00:00
|
|
|
fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType,
|
|
|
|
kOpaque_SkAlphaType), gData, 4);
|
2014-10-31 13:55:45 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
virtual SkString onShortName() override {
|
2017-04-25 15:09:16 +00:00
|
|
|
SkString name("coloremoji_blendmodes");
|
2017-11-15 15:42:46 +00:00
|
|
|
name.append(sk_tool_utils::platform_font_manager());
|
2017-04-25 15:09:16 +00:00
|
|
|
return name;
|
2014-10-31 13:55:45 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
virtual SkISize onISize() override {
|
2014-10-31 13:55:45 +00:00
|
|
|
return SkISize::Make(400, 640);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
virtual void onDraw(SkCanvas* canvas) override {
|
2014-10-31 13:55:45 +00:00
|
|
|
canvas->translate(SkIntToScalar(10), SkIntToScalar(20));
|
|
|
|
|
2017-03-15 16:19:37 +00:00
|
|
|
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,
|
2014-10-31 13:55:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const SkScalar w = SkIntToScalar(W);
|
|
|
|
const SkScalar h = SkIntToScalar(H);
|
|
|
|
SkMatrix m;
|
|
|
|
m.setScale(SkIntToScalar(6), SkIntToScalar(6));
|
2016-03-09 17:50:50 +00:00
|
|
|
auto s = SkShader::MakeBitmapShader(fBG, SkShader::kRepeat_TileMode,
|
|
|
|
SkShader::kRepeat_TileMode, &m);
|
2014-10-31 13:55:45 +00:00
|
|
|
|
|
|
|
SkPaint labelP;
|
|
|
|
labelP.setAntiAlias(true);
|
2015-07-24 19:09:25 +00:00
|
|
|
sk_tool_utils::set_portable_typeface(&labelP);
|
2014-10-31 13:55:45 +00:00
|
|
|
labelP.setTextAlign(SkPaint::kCenter_Align);
|
|
|
|
|
|
|
|
SkPaint textP;
|
|
|
|
textP.setAntiAlias(true);
|
|
|
|
textP.setTypeface(fColorType);
|
|
|
|
textP.setTextSize(SkIntToScalar(70));
|
|
|
|
|
|
|
|
const int W = 5;
|
|
|
|
|
|
|
|
SkScalar x0 = 0;
|
|
|
|
SkScalar y0 = 0;
|
|
|
|
SkScalar x = x0, y = y0;
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) {
|
|
|
|
SkRect r;
|
|
|
|
r.set(x, y, x+w, y+h);
|
|
|
|
|
|
|
|
SkPaint p;
|
|
|
|
p.setStyle(SkPaint::kFill_Style);
|
|
|
|
p.setShader(s);
|
|
|
|
canvas->drawRect(r, p);
|
|
|
|
|
|
|
|
r.inset(-SK_ScalarHalf, -SK_ScalarHalf);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
2015-08-27 14:41:13 +00:00
|
|
|
p.setShader(nullptr);
|
2014-10-31 13:55:45 +00:00
|
|
|
canvas->drawRect(r, p);
|
|
|
|
|
2017-04-25 15:09:16 +00:00
|
|
|
{
|
|
|
|
SkAutoCanvasRestore arc(canvas, true);
|
|
|
|
canvas->clipRect(r);
|
|
|
|
textP.setBlendMode(gModes[i]);
|
|
|
|
textP.setTextEncoding(SkPaint::kUTF32_TextEncoding);
|
|
|
|
const char* text = sk_tool_utils::emoji_sample_text();
|
2018-07-25 20:52:48 +00:00
|
|
|
SkUnichar unichar = SkUTF::NextUTF8(&text, text + strlen(text));
|
|
|
|
SkASSERT(unichar >= 0);
|
2017-04-25 15:09:16 +00:00
|
|
|
canvas->drawText(&unichar, 4, x+ w/10.f, y + 7.f*h/8.f, textP);
|
|
|
|
}
|
2014-10-31 13:55:45 +00:00
|
|
|
#if 1
|
2017-03-15 16:19:37 +00:00
|
|
|
const char* label = SkBlendMode_Name(gModes[i]);
|
2017-04-28 19:35:12 +00:00
|
|
|
canvas->drawString(label, x + w/2, y - labelP.getTextSize()/2, labelP);
|
2014-10-31 13:55:45 +00:00
|
|
|
#endif
|
|
|
|
x += w + SkIntToScalar(10);
|
|
|
|
if ((i % W) == W - 1) {
|
|
|
|
x = x0;
|
|
|
|
y += h + SkIntToScalar(30);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-05-12 17:09:30 +00:00
|
|
|
SkBitmap fBG;
|
|
|
|
sk_sp<SkTypeface> fColorType;
|
2014-10-31 13:55:45 +00:00
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-04-25 15:09:16 +00:00
|
|
|
static GM* MyFactory(void*) { return new ColorEmojiBlendModesGM; }
|
2014-10-31 13:55:45 +00:00
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|