2013-04-17 14:19:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
#include "SkBitmap.h"
|
2016-11-15 21:44:34 +00:00
|
|
|
#include "SkBlendModePriv.h"
|
2013-04-17 14:19:44 +00:00
|
|
|
#include "SkColorPriv.h"
|
2019-03-20 16:12:10 +00:00
|
|
|
#include "SkShader.h"
|
2018-10-25 16:36:06 +00:00
|
|
|
#include "SkTextUtils.h"
|
2019-03-20 16:12:10 +00:00
|
|
|
#include "ToolUtils.h"
|
|
|
|
#include "gm.h"
|
2013-04-17 14:19:44 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class Xfermodes2GM : public GM {
|
|
|
|
public:
|
|
|
|
Xfermodes2GM() {}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2013-04-17 14:19:44 +00:00
|
|
|
return SkString("xfermodes2");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(455, 475);
|
2013-04-17 14:19:44 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2013-04-17 14:19:44 +00:00
|
|
|
canvas->translate(SkIntToScalar(10), SkIntToScalar(20));
|
|
|
|
|
|
|
|
const SkScalar w = SkIntToScalar(kSize);
|
|
|
|
const SkScalar h = SkIntToScalar(kSize);
|
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
SkFont font(ToolUtils::create_portable_typeface());
|
2013-04-17 14:19:44 +00:00
|
|
|
|
|
|
|
const int W = 6;
|
|
|
|
|
|
|
|
SkScalar x = 0, y = 0;
|
2016-11-15 21:44:34 +00:00
|
|
|
for (size_t m = 0; m <= (size_t)SkBlendMode::kLastMode; m++) {
|
2016-10-06 00:33:02 +00:00
|
|
|
SkBlendMode mode = static_cast<SkBlendMode>(m);
|
2013-04-17 14:19:44 +00:00
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
|
|
|
|
canvas->translate(x, y);
|
|
|
|
SkPaint p;
|
|
|
|
p.setAntiAlias(false);
|
|
|
|
p.setStyle(SkPaint::kFill_Style);
|
|
|
|
p.setShader(fBG);
|
|
|
|
SkRect r = SkRect::MakeWH(w, h);
|
|
|
|
canvas->drawRect(r, p);
|
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas->saveLayer(&r, nullptr);
|
2013-04-17 14:19:44 +00:00
|
|
|
|
|
|
|
p.setShader(fDst);
|
|
|
|
canvas->drawRect(r, p);
|
|
|
|
p.setShader(fSrc);
|
2016-10-06 00:33:02 +00:00
|
|
|
p.setBlendMode(mode);
|
2013-04-17 14:19:44 +00:00
|
|
|
canvas->drawRect(r, p);
|
|
|
|
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
r.inset(-SK_ScalarHalf, -SK_ScalarHalf);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
2015-08-27 14:41:13 +00:00
|
|
|
p.setShader(nullptr);
|
2016-10-06 00:33:02 +00:00
|
|
|
p.setBlendMode(SkBlendMode::kSrcOver);
|
2013-04-17 14:19:44 +00:00
|
|
|
canvas->drawRect(r, p);
|
|
|
|
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
#if 1
|
2019-01-03 20:45:53 +00:00
|
|
|
SkTextUtils::DrawString(canvas, SkBlendMode_Name(mode), x + w/2, y - font.getSize()/2, font, SkPaint(),
|
2018-10-30 16:53:21 +00:00
|
|
|
SkTextUtils::kCenter_Align);
|
2013-04-17 14:19:44 +00:00
|
|
|
#endif
|
|
|
|
x += w + SkIntToScalar(10);
|
|
|
|
if ((m % W) == W - 1) {
|
|
|
|
x = 0;
|
|
|
|
y += h + SkIntToScalar(30);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2016-09-01 18:24:54 +00:00
|
|
|
const uint32_t kCheckData[] = {
|
2015-07-21 14:42:45 +00:00
|
|
|
SkPackARGB32(0xFF, 0x42, 0x41, 0x42),
|
|
|
|
SkPackARGB32(0xFF, 0xD6, 0xD3, 0xD6),
|
|
|
|
SkPackARGB32(0xFF, 0xD6, 0xD3, 0xD6),
|
|
|
|
SkPackARGB32(0xFF, 0x42, 0x41, 0x42)
|
2013-04-17 14:19:44 +00:00
|
|
|
};
|
|
|
|
SkBitmap bg;
|
2014-01-25 16:46:20 +00:00
|
|
|
bg.allocN32Pixels(2, 2, true);
|
2013-04-17 14:19:44 +00:00
|
|
|
memcpy(bg.getPixels(), kCheckData, sizeof(kCheckData));
|
2013-04-18 07:01:48 +00:00
|
|
|
|
2013-04-17 14:19:44 +00:00
|
|
|
SkMatrix lm;
|
|
|
|
lm.setScale(SkIntToScalar(16), SkIntToScalar(16));
|
2019-04-08 17:20:23 +00:00
|
|
|
fBG = bg.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &lm);
|
2013-04-18 07:01:48 +00:00
|
|
|
|
2015-03-30 14:52:57 +00:00
|
|
|
SkBitmap srcBmp;
|
|
|
|
srcBmp.allocN32Pixels(kSize, kSize);
|
|
|
|
SkPMColor* pixels = reinterpret_cast<SkPMColor*>(srcBmp.getPixels());
|
2013-04-18 07:01:48 +00:00
|
|
|
|
2013-04-17 14:19:44 +00:00
|
|
|
for (int y = 0; y < kSize; ++y) {
|
|
|
|
int c = y * (1 << kShift);
|
|
|
|
SkPMColor rowColor = SkPackARGB32(c, c, 0, c/2);
|
|
|
|
for (int x = 0; x < kSize; ++x) {
|
|
|
|
pixels[kSize * y + x] = rowColor;
|
|
|
|
}
|
|
|
|
}
|
2019-04-08 17:20:23 +00:00
|
|
|
fSrc = srcBmp.makeShader();
|
2015-03-30 14:52:57 +00:00
|
|
|
SkBitmap dstBmp;
|
|
|
|
dstBmp.allocN32Pixels(kSize, kSize);
|
|
|
|
pixels = reinterpret_cast<SkPMColor*>(dstBmp.getPixels());
|
2013-04-18 07:01:48 +00:00
|
|
|
|
2013-04-17 14:19:44 +00:00
|
|
|
for (int x = 0; x < kSize; ++x) {
|
|
|
|
int c = x * (1 << kShift);
|
|
|
|
SkPMColor colColor = SkPackARGB32(c, 0, c, c/2);
|
|
|
|
for (int y = 0; y < kSize; ++y) {
|
|
|
|
pixels[kSize * y + x] = colColor;
|
|
|
|
}
|
|
|
|
}
|
2019-04-08 17:20:23 +00:00
|
|
|
fDst = dstBmp.makeShader();
|
2013-04-17 14:19:44 +00:00
|
|
|
}
|
2013-04-18 07:01:48 +00:00
|
|
|
|
2013-04-17 14:19:44 +00:00
|
|
|
enum {
|
|
|
|
kShift = 2,
|
|
|
|
kSize = 256 >> kShift,
|
|
|
|
};
|
2013-04-18 07:01:48 +00:00
|
|
|
|
2016-03-13 21:13:58 +00:00
|
|
|
sk_sp<SkShader> fBG;
|
|
|
|
sk_sp<SkShader> fSrc;
|
|
|
|
sk_sp<SkShader> fDst;
|
2013-04-17 14:19:44 +00:00
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-01-23 15:22:01 +00:00
|
|
|
DEF_GM( return new Xfermodes2GM; )
|
2013-04-17 14:19:44 +00:00
|
|
|
|
|
|
|
}
|