skia2/gm/bigblurs.cpp
caryclark 65cdba6ba7 Revert of Revert of make gm background colors 565 compatible (patchset #1 id:1 of https://codereview.chromium.org/1184123002/)
Reason for revert:
underlying problem with portable refs deleted more than once fixed

Original issue's description:
> Revert of make gm background colors 565 compatible (patchset #2 id:20001 of https://codereview.chromium.org/1176243006/)
>
> Reason for revert:
> breaks many bots with refcnt error
>
> Original issue's description:
> > make gm background colors 565 compatible
> >
> > Change a batch of GM tests to convert their background color
> > so that it is representable in 8888 and 565.
> >
> > Enable portable text in those same tests to minimize platform
> > differences.
> >
> > In a couple of bitmap tests, use portable typefaces instead of
> > choosing 'Times' which may or may not be available on the platform.
> >
> > R=borenet@google.com
> >
> > Committed: https://skia.googlesource.com/skia/+/be7f768a357aefb39c42d24b81b24d647bb6ab70
>
> TBR=borenet@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Committed: https://skia.googlesource.com/skia/+/0bdb08b1ba8fbd18c4838f86a23f1ef4b3a3bfdf

TBR=borenet@google.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Review URL: https://codereview.chromium.org/1182403003
2015-06-15 06:51:08 -07:00

117 lines
3.8 KiB
C++

/*
* 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"
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.
// It creates a large blurred rect/rectori then renders the 4 corners and the
// middle.
class BigBlursGM : public GM {
public:
BigBlursGM() {
this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
}
protected:
SkString onShortName() override {
return SkString("bigblurs");
}
SkISize onISize() override {
return SkISize::Make(kWidth, kHeight);
}
void onDraw(SkCanvas* canvas) override {
static const int kBig = 65536;
static const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4));
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
static const SkScalar kLeftTopPad = 3*kSigma; // use on left & up of big rect
static const SkScalar kRightBotPad = kCloseUpSize-3*kSigma; // use on right and bot sides
// 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) {
for (int j = 0; j <= kLastEnum_SkBlurStyle; ++j) {
SkMaskFilter* mf = SkBlurMaskFilter::Create((SkBlurStyle)j, kSigma);
blurPaint.setMaskFilter(mf)->unref();
for (int k = 0; k < (int)SK_ARRAY_COUNT(origins); ++k) {
canvas->save();
SkRect clipRect = SkRect::MakeXYWH(SkIntToScalar(desiredX),
SkIntToScalar(desiredY),
SkIntToScalar(kCloseUpSize),
SkIntToScalar(kCloseUpSize));
canvas->clipRect(clipRect, SkRegion::kReplace_Op, false);
canvas->translate(desiredX-origins[k].fX,
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:
static const int kCloseUpSize = 64;
static const int kWidth = 5 * kCloseUpSize;
static const int kHeight = 2 * (kLastEnum_SkBlurStyle + 1) * kCloseUpSize;
typedef GM INHERITED;
};
DEF_GM( return SkNEW(BigBlursGM); )
}