2013-11-07 22:25: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"
|
2017-03-22 17:47:51 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2013-11-07 22:25:21 +00:00
|
|
|
#include "SkBlurMask.h"
|
2018-03-14 17:01:17 +00:00
|
|
|
#include "SkMaskFilter.h"
|
2015-08-05 20:57:49 +00:00
|
|
|
#include "SkPath.h"
|
2013-11-07 22:25:21 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
// This GM exercises the blurred rect nine-patching special cases when the
|
|
|
|
// blurred rect is very large and/or very far from the origin.
|
2013-11-08 07:01:56 +00:00
|
|
|
// It creates a large blurred rect/rectori then renders the 4 corners and the
|
2013-11-07 22:25:21 +00:00
|
|
|
// middle.
|
|
|
|
class BigBlursGM : public GM {
|
|
|
|
public:
|
|
|
|
BigBlursGM() {
|
2015-06-15 13:51:08 +00:00
|
|
|
this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
|
2013-11-07 22:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2013-11-07 22:25:21 +00:00
|
|
|
return SkString("bigblurs");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(kWidth, kHeight);
|
2013-11-07 22:25:21 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr int kBig = 65536;
|
|
|
|
const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4));
|
2013-11-07 22:25:21 +00:00
|
|
|
|
|
|
|
const SkRect bigRect = SkRect::MakeWH(SkIntToScalar(kBig), SkIntToScalar(kBig));
|
|
|
|
SkRect insetRect = bigRect;
|
|
|
|
insetRect.inset(20, 20);
|
|
|
|
|
|
|
|
SkPath rectori;
|
|
|
|
|
|
|
|
rectori.addRect(bigRect);
|
|
|
|
rectori.addRect(insetRect, SkPath::kCCW_Direction);
|
|
|
|
|
|
|
|
// The blur extends 3*kSigma out from the big rect.
|
|
|
|
// Offset the close-up windows so we get the entire blur
|
2016-09-01 18:24:54 +00:00
|
|
|
const SkScalar kLeftTopPad = 3*kSigma; // use on left & up of big rect
|
|
|
|
const SkScalar kRightBotPad = kCloseUpSize-3*kSigma; // use on right and bot sides
|
2013-11-07 22:25:21 +00:00
|
|
|
|
|
|
|
// UL hand corners of the rendered closeups
|
|
|
|
const SkPoint origins[] = {
|
|
|
|
{ -kLeftTopPad, -kLeftTopPad }, // UL
|
|
|
|
{ kBig-kRightBotPad, -kLeftTopPad }, // UR
|
|
|
|
{ kBig-kRightBotPad, kBig-kRightBotPad }, // LR
|
|
|
|
{ -kLeftTopPad, kBig-kRightBotPad }, // LL
|
|
|
|
{ kBig/2-kCloseUpSize/2, kBig/2-kCloseUpSize/2 }, // center
|
|
|
|
};
|
|
|
|
|
|
|
|
SkPaint outlinePaint;
|
|
|
|
outlinePaint.setColor(SK_ColorRED);
|
|
|
|
outlinePaint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
SkPaint blurPaint;
|
|
|
|
blurPaint.setAntiAlias(true);
|
|
|
|
blurPaint.setColor(SK_ColorBLACK);
|
|
|
|
|
|
|
|
int desiredX = 0, desiredY = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
2014-04-28 16:25:35 +00:00
|
|
|
for (int j = 0; j <= kLastEnum_SkBlurStyle; ++j) {
|
2018-03-14 17:01:17 +00:00
|
|
|
blurPaint.setMaskFilter(SkMaskFilter::MakeBlur((SkBlurStyle)j, kSigma));
|
2013-11-07 22:25:21 +00:00
|
|
|
|
|
|
|
for (int k = 0; k < (int)SK_ARRAY_COUNT(origins); ++k) {
|
|
|
|
canvas->save();
|
|
|
|
|
2013-11-08 07:01:56 +00:00
|
|
|
SkRect clipRect = SkRect::MakeXYWH(SkIntToScalar(desiredX),
|
2013-11-07 22:25:21 +00:00
|
|
|
SkIntToScalar(desiredY),
|
2013-11-08 07:01:56 +00:00
|
|
|
SkIntToScalar(kCloseUpSize),
|
2013-11-07 22:25:21 +00:00
|
|
|
SkIntToScalar(kCloseUpSize));
|
|
|
|
|
2016-09-21 18:15:07 +00:00
|
|
|
canvas->clipRect(clipRect);
|
2013-11-07 22:25:21 +00:00
|
|
|
|
2013-11-08 07:01:56 +00:00
|
|
|
canvas->translate(desiredX-origins[k].fX,
|
2013-11-07 22:25:21 +00:00
|
|
|
desiredY-origins[k].fY);
|
|
|
|
|
|
|
|
if (0 == i) {
|
|
|
|
canvas->drawRect(bigRect, blurPaint);
|
|
|
|
} else {
|
|
|
|
canvas->drawPath(rectori, blurPaint);
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
canvas->drawRect(clipRect, outlinePaint);
|
|
|
|
|
|
|
|
desiredX += kCloseUpSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
desiredX = 0;
|
|
|
|
desiredY += kCloseUpSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-09-01 18:24:54 +00:00
|
|
|
static constexpr int kCloseUpSize = 64;
|
|
|
|
static constexpr int kWidth = 5 * kCloseUpSize;
|
|
|
|
static constexpr int kHeight = 2 * (kLastEnum_SkBlurStyle + 1) * kCloseUpSize;
|
2013-11-07 22:25:21 +00:00
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new BigBlursGM;)
|
2013-11-07 22:43:04 +00:00
|
|
|
}
|