2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2014-01-13 14:53:55 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColorFilter.h"
|
|
|
|
#include "include/core/SkColorPriv.h"
|
|
|
|
#include "include/core/SkFont.h"
|
|
|
|
#include "include/core/SkGraphics.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/core/SkRegion.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkTime.h"
|
|
|
|
#include "include/core/SkTypeface.h"
|
|
|
|
#include "include/effects/SkCornerPathEffect.h"
|
|
|
|
#include "include/effects/SkGradientShader.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
|
|
|
#include "include/utils/SkTextUtils.h"
|
|
|
|
#include "samplecode/Sample.h"
|
|
|
|
#include "src/core/SkBlurMask.h"
|
|
|
|
#include "src/utils/SkUTF.h"
|
|
|
|
|
|
|
|
#include "include/core/SkColorPriv.h"
|
2019-12-30 15:09:43 +00:00
|
|
|
#include "include/core/SkMaskFilter.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkStream.h"
|
2011-05-20 14:13:56 +00:00
|
|
|
|
2019-01-03 20:45:53 +00:00
|
|
|
static void setNamedTypeface(SkFont* font, const char name[]) {
|
|
|
|
font->setTypeface(SkTypeface::MakeFromName(name, SkFontStyle()));
|
2011-05-20 14:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint16_t gBG[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF };
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class XfermodesBlurView : public Sample {
|
2011-05-20 14:13:56 +00:00
|
|
|
SkBitmap fBG;
|
|
|
|
SkBitmap fSrcB, fDstB;
|
|
|
|
|
2016-10-06 00:33:02 +00:00
|
|
|
void draw_mode(SkCanvas* canvas, SkBlendMode mode, int alpha, SkScalar x, SkScalar y) {
|
2011-05-20 14:13:56 +00:00
|
|
|
SkPaint p;
|
2018-03-14 17:01:17 +00:00
|
|
|
p.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle,
|
|
|
|
SkBlurMask::ConvertRadiusToSigma(5)));
|
2011-05-20 14:13:56 +00:00
|
|
|
|
|
|
|
SkScalar ww = SkIntToScalar(W);
|
|
|
|
SkScalar hh = SkIntToScalar(H);
|
|
|
|
|
|
|
|
// draw a circle covering the upper
|
|
|
|
// left three quarters of the canvas
|
|
|
|
p.setColor(0xFFCC44FF);
|
|
|
|
SkRect r;
|
2019-08-24 23:39:13 +00:00
|
|
|
r.setLTRB(0, 0, ww*3/4, hh*3/4);
|
2011-05-20 14:13:56 +00:00
|
|
|
r.offset(x, y);
|
|
|
|
canvas->drawOval(r, p);
|
|
|
|
|
2016-10-06 00:33:02 +00:00
|
|
|
p.setBlendMode(mode);
|
2011-05-20 14:13:56 +00:00
|
|
|
|
|
|
|
// draw a square overlapping the circle
|
|
|
|
// in the lower right of the canvas
|
|
|
|
p.setColor(0x00AA6633 | alpha << 24);
|
2019-08-24 23:39:13 +00:00
|
|
|
r.setLTRB(ww/3, hh/3, ww*19/20, hh*19/20);
|
2011-05-20 14:13:56 +00:00
|
|
|
r.offset(x, y);
|
|
|
|
canvas->drawRect(r, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
const static int W = 64;
|
|
|
|
const static int H = 64;
|
2011-07-07 14:38:03 +00:00
|
|
|
XfermodesBlurView() {
|
2014-05-29 15:57:20 +00:00
|
|
|
fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, kPremul_SkAlphaType),
|
|
|
|
gBG, 4);
|
2011-05-20 14:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2019-07-03 14:55:44 +00:00
|
|
|
virtual SkString name() { return SkString("XfermodesBlur"); }
|
2011-05-20 14:13:56 +00:00
|
|
|
|
|
|
|
virtual void onDrawContent(SkCanvas* canvas) {
|
|
|
|
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,
|
2011-05-20 14:13:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const SkScalar w = SkIntToScalar(W);
|
|
|
|
const SkScalar h = SkIntToScalar(H);
|
|
|
|
SkMatrix m;
|
|
|
|
m.setScale(SkIntToScalar(6), SkIntToScalar(6));
|
2019-04-08 17:20:23 +00:00
|
|
|
auto s = fBG.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &m);
|
2011-05-20 14:13:56 +00:00
|
|
|
|
2019-01-03 20:45:53 +00:00
|
|
|
SkFont font;
|
|
|
|
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
|
|
|
|
setNamedTypeface(&font, "Menlo Regular");
|
2011-05-20 14:13:56 +00:00
|
|
|
|
|
|
|
const int W = 5;
|
|
|
|
|
|
|
|
SkScalar x0 = 0;
|
|
|
|
for (int twice = 0; twice < 2; twice++) {
|
|
|
|
SkScalar x = x0, y = 0;
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) {
|
|
|
|
SkRect r;
|
2019-08-24 23:39:13 +00:00
|
|
|
r.setLTRB(x, y, x+w, y+h);
|
2011-05-20 14:13:56 +00:00
|
|
|
|
|
|
|
SkPaint p;
|
|
|
|
p.setStyle(SkPaint::kFill_Style);
|
|
|
|
p.setShader(s);
|
|
|
|
canvas->drawRect(r, p);
|
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas->saveLayer(&r, nullptr);
|
2017-03-15 16:19:37 +00:00
|
|
|
draw_mode(canvas, gModes[i], twice ? 0x88 : 0xFF, r.fLeft, r.fTop);
|
2011-05-20 14:13:56 +00:00
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
r.inset(-SK_ScalarHalf, -SK_ScalarHalf);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
2015-08-27 14:41:13 +00:00
|
|
|
p.setShader(nullptr);
|
2011-05-20 14:13:56 +00:00
|
|
|
canvas->drawRect(r, p);
|
|
|
|
|
2017-03-15 16:19:37 +00:00
|
|
|
const char* label = SkBlendMode_Name(gModes[i]);
|
2019-01-03 20:45:53 +00:00
|
|
|
SkTextUtils::DrawString(canvas, label, x + w/2, y - font.getSize()/2, font, SkPaint(),
|
2018-10-30 16:53:21 +00:00
|
|
|
SkTextUtils::kCenter_Align);
|
2011-05-20 14:13:56 +00:00
|
|
|
x += w + SkIntToScalar(10);
|
|
|
|
if ((i % W) == W - 1) {
|
|
|
|
x = x0;
|
|
|
|
y += h + SkIntToScalar(30);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
x0 += SkIntToScalar(400);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2011-05-20 14:13:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new XfermodesBlurView(); )
|