2013-11-05 15:57:21 +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 "gm.h"
|
|
|
|
#include "SkBlurMask.h"
|
|
|
|
#include "SkBlurMaskFilter.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkColorFilter.h"
|
|
|
|
#include "SkLayerDrawLooper.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkPoint.h"
|
|
|
|
#include "SkRect.h"
|
|
|
|
#include "SkRRect.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
#include "SkXfermode.h"
|
|
|
|
|
2013-11-05 21:10:58 +00:00
|
|
|
// This GM mimics a blurred RR seen in the wild.
|
2013-11-05 15:57:21 +00:00
|
|
|
class BlurRoundRectGM : public skiagm::GM {
|
|
|
|
public:
|
2013-11-05 21:10:58 +00:00
|
|
|
BlurRoundRectGM(int width, int height)
|
2016-01-08 21:48:43 +00:00
|
|
|
: fName("blurroundrect"), fWidth(width), fHeight(height) {
|
2014-06-03 13:50:26 +00:00
|
|
|
fName.appendf("-WH-%ix%i-unevenCorners", width, height);
|
2013-11-05 15:57:21 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2013-11-05 15:57:21 +00:00
|
|
|
return fName;
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2016-01-08 21:48:43 +00:00
|
|
|
return SkISize::Make(fWidth, fHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
SkVector radii[4];
|
|
|
|
radii[0].set(SkIntToScalar(30), SkIntToScalar(30));
|
|
|
|
radii[1].set(SkIntToScalar(10), SkIntToScalar(10));
|
|
|
|
radii[2].set(SkIntToScalar(30), SkIntToScalar(30));
|
|
|
|
radii[3].set(SkIntToScalar(10), SkIntToScalar(10));
|
|
|
|
SkRect r = SkRect::MakeWH(SkIntToScalar(fWidth), SkIntToScalar(fHeight));
|
|
|
|
fRRect.setRectRadii(r, radii);
|
2013-11-05 15:57:21 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2014-04-15 15:48:36 +00:00
|
|
|
SkLayerDrawLooper::Builder looperBuilder;
|
2013-11-05 15:57:21 +00:00
|
|
|
{
|
|
|
|
SkLayerDrawLooper::LayerInfo info;
|
2013-11-05 21:10:58 +00:00
|
|
|
info.fPaintBits = SkLayerDrawLooper::kMaskFilter_Bit
|
|
|
|
| SkLayerDrawLooper::kColorFilter_Bit;
|
2016-11-03 18:45:31 +00:00
|
|
|
info.fColorMode = SkBlendMode::kSrc;
|
2013-11-05 15:57:21 +00:00
|
|
|
info.fOffset = SkPoint::Make(SkIntToScalar(-1), SkIntToScalar(0));
|
|
|
|
info.fPostTranslate = false;
|
2014-04-15 15:48:36 +00:00
|
|
|
SkPaint* paint = looperBuilder.addLayerOnTop(info);
|
2016-04-04 17:02:58 +00:00
|
|
|
paint->setMaskFilter(SkBlurMaskFilter::Make(
|
2014-04-28 16:25:35 +00:00
|
|
|
kNormal_SkBlurStyle,
|
2013-11-10 15:08:45 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(SK_ScalarHalf),
|
2016-04-04 17:02:58 +00:00
|
|
|
SkBlurMaskFilter::kHighQuality_BlurFlag));
|
2016-03-22 17:17:23 +00:00
|
|
|
paint->setColorFilter(SkColorFilter::MakeModeFilter(
|
2015-07-28 17:37:53 +00:00
|
|
|
sk_tool_utils::color_to_565(SK_ColorLTGRAY),
|
2016-10-28 19:42:34 +00:00
|
|
|
SkBlendMode::kSrcIn));
|
2015-07-28 17:37:53 +00:00
|
|
|
paint->setColor(sk_tool_utils::color_to_565(SK_ColorGRAY));
|
2013-11-05 15:57:21 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
SkLayerDrawLooper::LayerInfo info;
|
2014-04-15 15:48:36 +00:00
|
|
|
looperBuilder.addLayerOnTop(info);
|
2013-11-05 15:57:21 +00:00
|
|
|
}
|
|
|
|
SkPaint paint;
|
2013-11-05 21:10:58 +00:00
|
|
|
canvas->drawRect(fRRect.rect(), paint);
|
2013-11-05 15:57:21 +00:00
|
|
|
|
2016-03-21 20:25:16 +00:00
|
|
|
paint.setLooper(looperBuilder.detach());
|
2013-11-05 16:28:38 +00:00
|
|
|
paint.setColor(SK_ColorCYAN);
|
2013-11-05 15:57:21 +00:00
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
2013-11-05 21:10:58 +00:00
|
|
|
canvas->drawRRect(fRRect, paint);
|
2013-11-05 15:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-11-05 21:10:58 +00:00
|
|
|
SkString fName;
|
|
|
|
SkRRect fRRect;
|
2016-01-08 21:48:43 +00:00
|
|
|
int fWidth, fHeight;
|
2013-11-05 21:10:58 +00:00
|
|
|
|
|
|
|
typedef skiagm::GM INHERITED;
|
2013-11-05 15:57:21 +00:00
|
|
|
};
|
|
|
|
|
2014-12-18 19:54:13 +00:00
|
|
|
#include "SkGradientShader.h"
|
|
|
|
/*
|
|
|
|
* Spits out a dummy gradient to test blur with shader on paint
|
|
|
|
*/
|
2016-03-09 17:50:50 +00:00
|
|
|
static sk_sp<SkShader> MakeRadial() {
|
2014-12-18 19:54:13 +00:00
|
|
|
SkPoint pts[2] = {
|
|
|
|
{ 0, 0 },
|
|
|
|
{ SkIntToScalar(100), SkIntToScalar(100) }
|
|
|
|
};
|
|
|
|
SkShader::TileMode tm = SkShader::kClamp_TileMode;
|
|
|
|
const SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, };
|
|
|
|
const SkScalar pos[] = { SK_Scalar1/4, SK_Scalar1*3/4 };
|
|
|
|
SkMatrix scale;
|
|
|
|
scale.setScale(0.5f, 0.5f);
|
|
|
|
scale.postTranslate(5.f, 5.f);
|
|
|
|
SkPoint center0, center1;
|
|
|
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
|
|
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
|
|
|
center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
|
|
|
|
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
2016-03-09 17:50:50 +00:00
|
|
|
return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
|
|
|
|
center0, (pts[1].fX - pts[0].fX) / 2,
|
|
|
|
colors, pos, SK_ARRAY_COUNT(colors), tm,
|
|
|
|
0, &scale);
|
2014-12-18 19:54:13 +00:00
|
|
|
}
|
|
|
|
|
2013-11-05 21:10:58 +00:00
|
|
|
// Simpler blurred RR test cases where all the radii are the same.
|
|
|
|
class SimpleBlurRoundRectGM : public skiagm::GM {
|
2013-11-05 15:57:21 +00:00
|
|
|
public:
|
2013-11-05 21:10:58 +00:00
|
|
|
SimpleBlurRoundRectGM()
|
|
|
|
: fName("simpleblurroundrect") {
|
2013-11-05 15:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-12-18 19:54:13 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2013-11-05 21:10:58 +00:00
|
|
|
return fName;
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-12-18 19:54:13 +00:00
|
|
|
return SkISize::Make(1000, 500);
|
2013-11-05 15:57:21 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2013-11-25 19:44:07 +00:00
|
|
|
canvas->scale(1.5f, 1.5f);
|
2014-04-28 19:49:24 +00:00
|
|
|
canvas->translate(50,50);
|
2013-11-05 21:10:58 +00:00
|
|
|
|
2014-04-28 19:49:24 +00:00
|
|
|
const float blurRadii[] = { 1,5,10,20 };
|
|
|
|
const int cornerRadii[] = { 1,5,10,20 };
|
2014-12-18 19:54:13 +00:00
|
|
|
const SkRect r = SkRect::MakeWH(SkIntToScalar(25), SkIntToScalar(25));
|
2013-11-05 21:10:58 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(blurRadii); ++i) {
|
|
|
|
SkAutoCanvasRestore autoRestore(canvas, true);
|
2014-04-28 19:49:24 +00:00
|
|
|
canvas->translate(0, (r.height() + SkIntToScalar(50)) * i);
|
2013-11-05 21:10:58 +00:00
|
|
|
for (size_t j = 0; j < SK_ARRAY_COUNT(cornerRadii); ++j) {
|
2014-12-18 19:54:13 +00:00
|
|
|
for (int k = 0; k <= 1; k++) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorBLACK);
|
2016-04-04 17:02:58 +00:00
|
|
|
paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
|
|
|
|
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(blurRadii[i])),
|
|
|
|
SkBlurMaskFilter::kHighQuality_BlurFlag));
|
2014-12-18 19:54:13 +00:00
|
|
|
|
|
|
|
bool useRadial = SkToBool(k);
|
|
|
|
if (useRadial) {
|
2016-03-09 17:50:50 +00:00
|
|
|
paint.setShader(MakeRadial());
|
2014-12-18 19:54:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkRRect rrect;
|
|
|
|
rrect.setRectXY(r, SkIntToScalar(cornerRadii[j]),
|
|
|
|
SkIntToScalar(cornerRadii[j]));
|
|
|
|
canvas->drawRRect(rrect, paint);
|
|
|
|
canvas->translate(r.width() + SkIntToScalar(50), 0);
|
|
|
|
}
|
2013-11-05 21:10:58 +00:00
|
|
|
}
|
|
|
|
}
|
2013-11-05 15:57:21 +00:00
|
|
|
}
|
|
|
|
private:
|
2013-11-05 21:10:58 +00:00
|
|
|
const SkString fName;
|
2013-11-05 15:57:21 +00:00
|
|
|
|
2013-11-05 21:10:58 +00:00
|
|
|
typedef skiagm::GM INHERITED;
|
2013-11-05 15:57:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Create one with dimensions/rounded corners based on the skp
|
2013-11-05 22:04:53 +00:00
|
|
|
//
|
|
|
|
// TODO(scroggo): Disabled in an attempt to rememdy
|
|
|
|
// https://code.google.com/p/skia/issues/detail?id=1801 ('Win7 Test bots all failing GenerateGMs:
|
|
|
|
// ran wrong number of tests')
|
|
|
|
//DEF_GM(return new BlurRoundRectGM(600, 5514, 6);)
|
|
|
|
|
2013-11-05 15:57:21 +00:00
|
|
|
// Rounded rect with two opposite corners with large radii, the other two
|
|
|
|
// small.
|
2013-11-05 21:10:58 +00:00
|
|
|
DEF_GM(return new BlurRoundRectGM(100, 100);)
|
|
|
|
|
|
|
|
DEF_GM(return new SimpleBlurRoundRectGM();)
|