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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkBlendMode.h"
|
|
|
|
#include "include/core/SkBlurTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkColor.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkColorFilter.h"
|
|
|
|
#include "include/core/SkMaskFilter.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkMatrix.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkRRect.h"
|
|
|
|
#include "include/core/SkRect.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkSize.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkString.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkTileMode.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
#include "include/effects/SkGradientShader.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkBlurMask.h"
|
2013-11-05 15:57:21 +00:00
|
|
|
|
2014-12-18 19:54:13 +00:00
|
|
|
/*
|
|
|
|
* 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) }
|
|
|
|
};
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm = SkTileMode::kClamp;
|
2014-12-18 19:54:13 +00:00
|
|
|
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 {
|
2019-07-18 17:35:49 +00:00
|
|
|
SkString onShortName() override { return SkString("simpleblurroundrect"); }
|
2013-11-05 15:57:21 +00:00
|
|
|
|
2019-07-18 17:35:49 +00:00
|
|
|
SkISize onISize() override { return {1000, 500}; }
|
2013-11-05 15:57:21 +00:00
|
|
|
|
2020-06-11 18:12:44 +00:00
|
|
|
bool runAsBench() const override { return true; }
|
|
|
|
|
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);
|
2018-03-14 17:01:17 +00:00
|
|
|
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle,
|
|
|
|
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(blurRadii[i]))));
|
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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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 21:10:58 +00:00
|
|
|
DEF_GM(return new SimpleBlurRoundRectGM();)
|
2020-10-21 18:28:47 +00:00
|
|
|
|
|
|
|
// From crbug.com/1138810
|
|
|
|
DEF_SIMPLE_GM(blur_large_rrects, canvas, 300, 300) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 20.f));
|
|
|
|
|
|
|
|
auto rect = SkRect::MakeLTRB(5.f, -20000.f, 240.f, 25.f);
|
|
|
|
SkRRect rrect = SkRRect::MakeRectXY(rect, 40.f, 40.f);
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
SkColor4f color{(i & 1) ? 1.f : 0.f,
|
|
|
|
(i & 2) ? 1.f : 0.f,
|
|
|
|
(i < 2) ? 1.f : 0.f,
|
|
|
|
1.f};
|
|
|
|
paint.setColor(color);
|
|
|
|
canvas->drawRRect(rrect, paint);
|
|
|
|
canvas->rotate(90.f, 150.f, 150.f);
|
|
|
|
}
|
|
|
|
}
|