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-11-14 16:27:40 +00:00
|
|
|
|
2011-02-16 21:50:04 +00:00
|
|
|
#include "gm.h"
|
2017-03-22 17:47:51 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2017-06-07 19:23:49 +00:00
|
|
|
#include "Resources.h"
|
2013-09-06 14:16:12 +00:00
|
|
|
#include "SkBlurMask.h"
|
2011-02-16 21:50:04 +00:00
|
|
|
#include "SkBlurMaskFilter.h"
|
2017-06-07 19:23:49 +00:00
|
|
|
#include "SkImage.h"
|
2015-08-05 20:57:49 +00:00
|
|
|
#include "SkPath.h"
|
2011-02-16 21:50:04 +00:00
|
|
|
|
2015-09-09 15:16:41 +00:00
|
|
|
DEF_SIMPLE_GM_BG(blurs, canvas, 700, 500, sk_tool_utils::color_to_565(0xFFDDDDDD)) {
|
2014-04-28 16:25:35 +00:00
|
|
|
SkBlurStyle NONE = SkBlurStyle(-999);
|
2016-09-01 18:24:54 +00:00
|
|
|
const struct {
|
2014-04-28 16:25:35 +00:00
|
|
|
SkBlurStyle fStyle;
|
|
|
|
int fCx, fCy;
|
2011-02-16 21:50:04 +00:00
|
|
|
} gRecs[] = {
|
2014-04-28 16:25:35 +00:00
|
|
|
{ NONE, 0, 0 },
|
|
|
|
{ kInner_SkBlurStyle, -1, 0 },
|
|
|
|
{ kNormal_SkBlurStyle, 0, 1 },
|
|
|
|
{ kSolid_SkBlurStyle, 0, -1 },
|
|
|
|
{ kOuter_SkBlurStyle, 1, 0 },
|
2011-02-16 21:50:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
2015-07-24 19:09:25 +00:00
|
|
|
sk_tool_utils::set_portable_typeface(&paint);
|
2011-05-20 14:05:03 +00:00
|
|
|
paint.setTextSize(SkIntToScalar(25));
|
|
|
|
canvas->translate(SkIntToScalar(-40), SkIntToScalar(0));
|
2011-02-16 21:50:04 +00:00
|
|
|
|
|
|
|
SkBlurMaskFilter::BlurFlags flags = SkBlurMaskFilter::kNone_BlurFlag;
|
|
|
|
for (int j = 0; j < 2; j++) {
|
|
|
|
canvas->save();
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) {
|
|
|
|
if (gRecs[i].fStyle != NONE) {
|
2016-04-04 17:02:58 +00:00
|
|
|
paint.setMaskFilter(SkBlurMaskFilter::Make(gRecs[i].fStyle,
|
2013-09-06 14:16:12 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(20)),
|
2016-04-04 17:02:58 +00:00
|
|
|
flags));
|
2011-02-16 21:50:04 +00:00
|
|
|
} else {
|
2015-08-27 14:41:13 +00:00
|
|
|
paint.setMaskFilter(nullptr);
|
2011-02-16 21:50:04 +00:00
|
|
|
}
|
2013-08-27 16:14:03 +00:00
|
|
|
canvas->drawCircle(SkIntToScalar(200 + gRecs[i].fCx*100),
|
|
|
|
SkIntToScalar(200 + gRecs[i].fCy*100),
|
|
|
|
SkIntToScalar(50),
|
|
|
|
paint);
|
2011-02-16 21:50:04 +00:00
|
|
|
}
|
|
|
|
// draw text
|
|
|
|
{
|
2016-04-04 17:02:58 +00:00
|
|
|
paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
|
2013-09-06 14:16:12 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4)),
|
2016-04-04 17:02:58 +00:00
|
|
|
flags));
|
2011-02-16 21:50:04 +00:00
|
|
|
SkScalar x = SkIntToScalar(70);
|
|
|
|
SkScalar y = SkIntToScalar(400);
|
|
|
|
paint.setColor(SK_ColorBLACK);
|
2017-04-28 19:35:12 +00:00
|
|
|
canvas->drawString("Hamburgefons Style", x, y, paint);
|
|
|
|
canvas->drawString("Hamburgefons Style",
|
2013-08-27 16:14:03 +00:00
|
|
|
x, y + SkIntToScalar(50), paint);
|
2015-08-27 14:41:13 +00:00
|
|
|
paint.setMaskFilter(nullptr);
|
2011-02-16 21:50:04 +00:00
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
x -= SkIntToScalar(2);
|
|
|
|
y -= SkIntToScalar(2);
|
2017-04-28 19:35:12 +00:00
|
|
|
canvas->drawString("Hamburgefons Style", x, y, paint);
|
2011-02-16 21:50:04 +00:00
|
|
|
}
|
|
|
|
canvas->restore();
|
2011-02-18 20:20:51 +00:00
|
|
|
flags = SkBlurMaskFilter::kHighQuality_BlurFlag;
|
2011-05-20 14:05:03 +00:00
|
|
|
canvas->translate(SkIntToScalar(350), SkIntToScalar(0));
|
2011-02-16 21:50:04 +00:00
|
|
|
}
|
2015-09-09 15:16:41 +00:00
|
|
|
}
|
2014-11-14 16:27:40 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// exercise a special-case of blurs, which is two nested rects. These are drawn specially,
|
|
|
|
// and possibly cached.
|
|
|
|
//
|
|
|
|
// in particular, we want to notice that the 2nd rect draws slightly differently, since it
|
|
|
|
// is translated a fractional amount.
|
|
|
|
//
|
2015-09-09 15:16:41 +00:00
|
|
|
DEF_SIMPLE_GM(blur2rects, canvas, 700, 500) {
|
2014-11-14 16:27:40 +00:00
|
|
|
SkPaint paint;
|
2011-02-16 21:50:04 +00:00
|
|
|
|
2016-04-04 17:02:58 +00:00
|
|
|
paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 2.3f));
|
2011-02-16 21:50:04 +00:00
|
|
|
|
2014-11-17 15:41:35 +00:00
|
|
|
SkRect outer = SkRect::MakeXYWH(10.125f, 10.125f, 100.125f, 100);
|
|
|
|
SkRect inner = SkRect::MakeXYWH(20.25f, 20.125f, 80, 80);
|
2014-11-14 16:27:40 +00:00
|
|
|
SkPath path;
|
|
|
|
path.addRect(outer, SkPath::kCW_Direction);
|
|
|
|
path.addRect(inner, SkPath::kCCW_Direction);
|
|
|
|
|
|
|
|
canvas->drawPath(path, paint);
|
2014-11-14 19:59:10 +00:00
|
|
|
// important to translate by a factional amount to exercise a different "phase"
|
2014-11-14 16:27:40 +00:00
|
|
|
// of the same path w.r.t. the pixel grid
|
2014-11-17 15:41:35 +00:00
|
|
|
SkScalar dx = SkScalarRoundToScalar(path.getBounds().width()) + 14 + 0.25f;
|
2014-11-14 19:59:10 +00:00
|
|
|
canvas->translate(dx, 0);
|
2014-11-14 16:27:40 +00:00
|
|
|
canvas->drawPath(path, paint);
|
2015-09-09 15:16:41 +00:00
|
|
|
}
|
2014-12-10 15:40:36 +00:00
|
|
|
|
2015-09-09 15:16:41 +00:00
|
|
|
DEF_SIMPLE_GM(blur2rectsnonninepatch, canvas, 700, 500) {
|
2014-12-10 15:40:36 +00:00
|
|
|
SkPaint paint;
|
2016-04-04 17:02:58 +00:00
|
|
|
paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 4.3f));
|
2014-12-10 15:40:36 +00:00
|
|
|
|
|
|
|
SkRect outer = SkRect::MakeXYWH(10, 110, 100, 100);
|
|
|
|
SkRect inner = SkRect::MakeXYWH(50, 150, 10, 10);
|
|
|
|
SkPath path;
|
|
|
|
path.addRect(outer, SkPath::kCW_Direction);
|
|
|
|
path.addRect(inner, SkPath::kCW_Direction);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
|
|
|
|
SkScalar dx = SkScalarRoundToScalar(path.getBounds().width()) + 40 + 0.25f;
|
|
|
|
canvas->translate(dx, 0);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
|
|
|
|
// Translate to outside of clip bounds.
|
|
|
|
canvas->translate(-dx, 0);
|
|
|
|
canvas->translate(-30, -150);
|
|
|
|
canvas->drawPath(path, paint);
|
2015-09-09 15:16:41 +00:00
|
|
|
}
|
2017-06-07 19:23:49 +00:00
|
|
|
|
|
|
|
DEF_SIMPLE_GM(BlurDrawImage, canvas, 256, 256) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 10, 0));
|
|
|
|
canvas->clear(0xFF88FF88);
|
2017-12-08 15:21:31 +00:00
|
|
|
if (auto image = GetResourceAsImage("images/mandrill_512_q075.jpg")) {
|
2017-06-07 19:23:49 +00:00
|
|
|
canvas->scale(0.25, 0.25);
|
|
|
|
canvas->drawImage(image, 256, 256, &paint);
|
|
|
|
}
|
|
|
|
}
|