2013-03-19 14:11:15 +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 21:28:53 +00:00
|
|
|
#include "include/core/SkBlurTypes.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkDrawLooper.h"
|
|
|
|
#include "include/core/SkMaskFilter.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkMatrix.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTileMode.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/effects/SkBlurDrawLooper.h"
|
|
|
|
#include "include/effects/SkGradientShader.h"
|
|
|
|
#include "include/private/SkTArray.h"
|
|
|
|
#include "src/core/SkBlurMask.h"
|
2013-03-19 14:11:15 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class RectsGM : public GM {
|
2019-07-23 13:49:59 +00:00
|
|
|
sk_sp<SkDrawLooper> fLooper;
|
|
|
|
enum {
|
|
|
|
kLooperColorSentinel = 0x01020304
|
|
|
|
};
|
2013-03-19 14:11:15 +00:00
|
|
|
public:
|
|
|
|
RectsGM() {
|
|
|
|
this->setBGColor(0xFF000000);
|
|
|
|
this->makePaints();
|
|
|
|
this->makeMatrices();
|
|
|
|
this->makeRects();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2013-03-19 14:11:15 +00:00
|
|
|
return SkString("rects");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(1200, 900);
|
2013-03-19 14:11:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void makePaints() {
|
|
|
|
{
|
|
|
|
// no AA
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorWHITE);
|
|
|
|
fPaints.push_back(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// AA
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorWHITE);
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
fPaints.push_back(p);
|
|
|
|
}
|
|
|
|
|
2013-11-01 11:54:29 +00:00
|
|
|
{
|
|
|
|
// AA with translucent
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorWHITE);
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
p.setAlpha(0x66);
|
|
|
|
fPaints.push_back(p);
|
|
|
|
}
|
|
|
|
|
2013-03-19 14:11:15 +00:00
|
|
|
{
|
|
|
|
// AA with mask filter
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorWHITE);
|
|
|
|
p.setAntiAlias(true);
|
2018-03-14 17:01:17 +00:00
|
|
|
p.setMaskFilter(SkMaskFilter::MakeBlur(
|
2014-04-28 16:25:35 +00:00
|
|
|
kNormal_SkBlurStyle,
|
2018-03-14 17:01:17 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5))));
|
2013-03-19 14:11:15 +00:00
|
|
|
fPaints.push_back(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// AA with radial shader
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorWHITE);
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
SkPoint center = SkPoint::Make(SkIntToScalar(-5), SkIntToScalar(30));
|
|
|
|
SkColor colors[] = { SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN };
|
|
|
|
SkScalar pos[] = { 0, SK_ScalarHalf, SK_Scalar1 };
|
2016-03-13 21:13:58 +00:00
|
|
|
p.setShader(SkGradientShader::MakeRadial(center, 20, colors, pos,
|
|
|
|
SK_ARRAY_COUNT(colors),
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode::kClamp));
|
2013-03-19 14:11:15 +00:00
|
|
|
fPaints.push_back(p);
|
|
|
|
}
|
|
|
|
|
2019-07-23 13:49:59 +00:00
|
|
|
fLooper = SkBlurDrawLooper::Make(SK_ColorWHITE, SkBlurMask::ConvertRadiusToSigma(10),5,10);
|
|
|
|
{
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(kLooperColorSentinel);
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
fPaints.push_back(p);
|
|
|
|
}
|
2013-03-19 14:11:15 +00:00
|
|
|
{
|
|
|
|
// AA with stroke style
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorWHITE);
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setStrokeWidth(SkIntToScalar(3));
|
|
|
|
fPaints.push_back(p);
|
|
|
|
}
|
|
|
|
|
2013-11-01 11:54:29 +00:00
|
|
|
{
|
|
|
|
// AA with bevel-stroke style
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorWHITE);
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setStrokeJoin(SkPaint::kBevel_Join);
|
|
|
|
p.setStrokeWidth(SkIntToScalar(3));
|
|
|
|
fPaints.push_back(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// AA with round-stroke style
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorWHITE);
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setStrokeJoin(SkPaint::kRound_Join);
|
|
|
|
p.setStrokeWidth(SkIntToScalar(3));
|
|
|
|
fPaints.push_back(p);
|
|
|
|
}
|
|
|
|
|
2013-03-19 14:11:15 +00:00
|
|
|
{
|
|
|
|
// AA with stroke style, width = 0
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorWHITE);
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
fPaints.push_back(p);
|
|
|
|
}
|
|
|
|
|
2013-11-01 11:54:29 +00:00
|
|
|
{
|
|
|
|
// AA with stroke style, width wider than rect width and/or height
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorWHITE);
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setStrokeWidth(SkIntToScalar(40));
|
|
|
|
fPaints.push_back(p);
|
|
|
|
}
|
|
|
|
|
2013-03-19 14:11:15 +00:00
|
|
|
{
|
|
|
|
// AA with stroke and fill style
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorWHITE);
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
p.setStyle(SkPaint::kStrokeAndFill_Style);
|
|
|
|
p.setStrokeWidth(SkIntToScalar(2));
|
|
|
|
fPaints.push_back(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void makeMatrices() {
|
|
|
|
{
|
|
|
|
// 1x1.5 scale
|
|
|
|
SkMatrix m;
|
2013-03-19 14:50:41 +00:00
|
|
|
m.setScale(1, 1.5f);
|
2013-03-19 14:11:15 +00:00
|
|
|
fMatrices.push_back(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// 1.5x1.5 scale
|
|
|
|
SkMatrix m;
|
2013-03-19 14:50:41 +00:00
|
|
|
m.setScale(1.5f, 1.5f);
|
2013-03-19 14:11:15 +00:00
|
|
|
fMatrices.push_back(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// 1x1.5 skew
|
|
|
|
SkMatrix m;
|
2013-03-19 14:50:41 +00:00
|
|
|
m.setSkew(1, 1.5f);
|
2013-03-19 14:11:15 +00:00
|
|
|
fMatrices.push_back(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// 1.5x1.5 skew
|
|
|
|
SkMatrix m;
|
2013-03-19 14:50:41 +00:00
|
|
|
m.setSkew(1.5f, 1.5f);
|
2013-03-19 14:11:15 +00:00
|
|
|
fMatrices.push_back(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// 30 degree rotation
|
|
|
|
SkMatrix m;
|
|
|
|
m.setRotate(SkIntToScalar(30));
|
|
|
|
fMatrices.push_back(m);
|
|
|
|
}
|
2013-04-29 17:44:45 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
// 90 degree rotation
|
|
|
|
SkMatrix m;
|
|
|
|
m.setRotate(SkIntToScalar(90));
|
|
|
|
fMatrices.push_back(m);
|
|
|
|
}
|
2013-03-19 14:11:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void makeRects() {
|
|
|
|
{
|
|
|
|
// small square
|
|
|
|
SkRect r = SkRect::MakeLTRB(0, 0, 30, 30);
|
|
|
|
fRects.push_back(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// thin vertical
|
|
|
|
SkRect r = SkRect::MakeLTRB(0, 0, 2, 40);
|
|
|
|
fRects.push_back(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// thin horizontal
|
|
|
|
SkRect r = SkRect::MakeLTRB(0, 0, 40, 2);
|
|
|
|
fRects.push_back(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// very thin
|
|
|
|
SkRect r = SkRect::MakeLTRB(0, 0, 0.25f, 10);
|
|
|
|
fRects.push_back(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// zaftig
|
|
|
|
SkRect r = SkRect::MakeLTRB(0, 0, 60, 60);
|
|
|
|
fRects.push_back(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// position the current test on the canvas
|
|
|
|
static void position(SkCanvas* canvas, int testCount) {
|
|
|
|
canvas->translate(SK_Scalar1 * 100 * (testCount % 10) + SK_Scalar1 / 4,
|
|
|
|
SK_Scalar1 * 100 * (testCount / 10) + 3 * SK_Scalar1 / 4);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2013-03-19 14:11:15 +00:00
|
|
|
canvas->translate(20 * SK_Scalar1, 20 * SK_Scalar1);
|
|
|
|
|
|
|
|
int testCount = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < fPaints.count(); ++i) {
|
|
|
|
for (int j = 0; j < fRects.count(); ++j, ++testCount) {
|
|
|
|
canvas->save();
|
|
|
|
this->position(canvas, testCount);
|
2019-07-23 13:49:59 +00:00
|
|
|
SkPaint p = fPaints[i];
|
|
|
|
if (p.getColor() == kLooperColorSentinel) {
|
|
|
|
p.setColor(SK_ColorWHITE);
|
|
|
|
SkRect r = fRects[j];
|
|
|
|
fLooper->apply(canvas, p, [r](SkCanvas* c, const SkPaint& p) {
|
|
|
|
c->drawRect(r, p);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
canvas->drawRect(fRects[j], p);
|
|
|
|
}
|
2013-03-19 14:11:15 +00:00
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
|
|
|
for (int i = 0; i < fMatrices.count(); ++i) {
|
|
|
|
for (int j = 0; j < fRects.count(); ++j, ++testCount) {
|
|
|
|
canvas->save();
|
|
|
|
this->position(canvas, testCount);
|
|
|
|
canvas->concat(fMatrices[i]);
|
|
|
|
canvas->drawRect(fRects[j], paint);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkTArray<SkPaint> fPaints;
|
|
|
|
SkTArray<SkMatrix> fMatrices;
|
|
|
|
SkTArray<SkRect> fRects;
|
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-01-23 15:22:01 +00:00
|
|
|
DEF_GM( return new RectsGM; )
|
2013-03-19 14:11:15 +00:00
|
|
|
|
|
|
|
}
|