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, int radius)
|
2013-11-05 15:57:21 +00:00
|
|
|
: fName("blurroundrect")
|
2013-11-05 21:10:58 +00:00
|
|
|
{
|
|
|
|
SkRect r = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
|
|
|
|
fRRect.setRectXY(r, SkIntToScalar(radius), SkIntToScalar(radius));
|
|
|
|
fName.appendf("-WH[%ix%i]-corner[%i]", width, height, radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
BlurRoundRectGM(int width, int height)
|
|
|
|
: fName("blurroundrect") {
|
|
|
|
fName.appendf("-WH[%ix%i]-unevenCorners",
|
|
|
|
width, height);
|
2013-11-05 15:57:21 +00:00
|
|
|
SkVector radii[4];
|
2013-11-05 21:10:58 +00:00
|
|
|
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(width), SkIntToScalar(height));
|
2013-11-05 15:57:21 +00:00
|
|
|
fRRect.setRectRadii(r, radii);
|
|
|
|
}
|
|
|
|
|
2014-04-30 13:20:45 +00:00
|
|
|
virtual uint32_t onGetFlags() const SK_OVERRIDE {
|
|
|
|
return kSkipTiled_Flag;
|
|
|
|
}
|
|
|
|
|
2013-11-05 15:57:21 +00:00
|
|
|
virtual SkString onShortName() SK_OVERRIDE {
|
|
|
|
return fName;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual SkISize onISize() SK_OVERRIDE {
|
2013-11-05 21:10:58 +00:00
|
|
|
return SkISize::Make(SkScalarCeilToInt(fRRect.rect().width()),
|
|
|
|
SkScalarCeilToInt(fRRect.rect().height()));
|
2013-11-05 15:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) SK_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;
|
2013-11-05 15:57:21 +00:00
|
|
|
info.fColorMode = SkXfermode::kSrc_Mode;
|
|
|
|
info.fOffset = SkPoint::Make(SkIntToScalar(-1), SkIntToScalar(0));
|
|
|
|
info.fPostTranslate = false;
|
2014-04-15 15:48:36 +00:00
|
|
|
SkPaint* paint = looperBuilder.addLayerOnTop(info);
|
2013-11-10 15:08:45 +00:00
|
|
|
SkMaskFilter* maskFilter = SkBlurMaskFilter::Create(
|
2014-04-28 16:25:35 +00:00
|
|
|
kNormal_SkBlurStyle,
|
2013-11-10 15:08:45 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(SK_ScalarHalf),
|
2013-11-05 15:57:21 +00:00
|
|
|
SkBlurMaskFilter::kHighQuality_BlurFlag);
|
|
|
|
paint->setMaskFilter(maskFilter)->unref();
|
2013-11-05 16:28:38 +00:00
|
|
|
SkColorFilter* colorFilter = SkColorFilter::CreateModeFilter(SK_ColorLTGRAY,
|
2013-11-05 15:57:21 +00:00
|
|
|
SkXfermode::kSrcIn_Mode);
|
|
|
|
paint->setColorFilter(colorFilter)->unref();
|
2013-11-05 16:28:38 +00:00
|
|
|
paint->setColor(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
|
|
|
|
2014-04-15 15:48:36 +00:00
|
|
|
paint.setLooper(looperBuilder.detachLooper())->unref();
|
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;
|
|
|
|
|
|
|
|
typedef skiagm::GM INHERITED;
|
2013-11-05 15:57:21 +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-04-30 13:20:45 +00:00
|
|
|
virtual uint32_t onGetFlags() const SK_OVERRIDE {
|
|
|
|
return kSkipTiled_Flag;
|
|
|
|
}
|
|
|
|
|
2013-11-05 21:10:58 +00:00
|
|
|
virtual SkString onShortName() SK_OVERRIDE {
|
|
|
|
return fName;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual SkISize onISize() SK_OVERRIDE {
|
2014-04-28 19:49:24 +00:00
|
|
|
return SkISize::Make(950, 950);
|
2013-11-05 15:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) SK_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 };
|
2013-11-05 21:10:58 +00:00
|
|
|
const SkRect r = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100));
|
|
|
|
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) {
|
2013-11-10 15:08:45 +00:00
|
|
|
SkMaskFilter* filter = SkBlurMaskFilter::Create(
|
2014-04-28 16:25:35 +00:00
|
|
|
kNormal_SkBlurStyle,
|
2014-04-28 19:49:24 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(blurRadii[i])),
|
|
|
|
SkBlurMaskFilter::kHighQuality_BlurFlag);
|
2013-11-05 21:10:58 +00:00
|
|
|
SkPaint paint;
|
2014-04-28 19:49:24 +00:00
|
|
|
paint.setColor(SK_ColorBLACK);
|
2013-11-05 21:10:58 +00:00
|
|
|
paint.setMaskFilter(filter)->unref();
|
|
|
|
|
|
|
|
SkRRect rrect;
|
|
|
|
rrect.setRectXY(r, SkIntToScalar(cornerRadii[j]), SkIntToScalar(cornerRadii[j]));
|
|
|
|
canvas->drawRRect(rrect, paint);
|
2014-04-28 19:49:24 +00:00
|
|
|
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();)
|