2012-04-16 14:19:32 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Intel Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2019-05-01 21:28:53 +00:00
|
|
|
|
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"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkMaskFilter.h"
|
|
|
|
#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/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 "include/utils/SkRandom.h"
|
|
|
|
#include "src/core/SkBlurMask.h"
|
2012-04-16 14:19:32 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class CircleGM : public GM {
|
2019-07-23 13:49:59 +00:00
|
|
|
sk_sp<SkDrawLooper> fLooper;
|
|
|
|
enum {
|
|
|
|
kLooperColorSentinel = 0x01020304
|
|
|
|
};
|
2012-04-16 14:19:32 +00:00
|
|
|
public:
|
|
|
|
CircleGM() {
|
|
|
|
this->setBGColor(0xFF000000);
|
|
|
|
this->makePaints();
|
|
|
|
this->makeMatrices();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2012-04-16 14:19:32 +00:00
|
|
|
return SkString("circles");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(1200, 900);
|
2012-04-16 14:19:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void makePaints() {
|
|
|
|
{
|
|
|
|
// no AA
|
|
|
|
SkPaint p;
|
|
|
|
fPaints.push_back(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// AA
|
|
|
|
SkPaint p;
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
fPaints.push_back(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// AA with mask filter
|
|
|
|
SkPaint p;
|
|
|
|
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))));
|
2012-04-16 14:19:32 +00:00
|
|
|
fPaints.push_back(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// AA with radial shader
|
|
|
|
SkPaint p;
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
SkPoint center = SkPoint::Make(SkIntToScalar(40), SkIntToScalar(40));
|
|
|
|
SkColor colors[] = { SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN };
|
|
|
|
SkScalar pos[] = { 0, SK_ScalarHalf, SK_Scalar1 };
|
2016-03-09 17:50:50 +00:00
|
|
|
p.setShader(SkGradientShader::MakeRadial(center, 20, colors, pos, SK_ARRAY_COUNT(colors),
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode::kClamp));
|
2012-04-16 14:19:32 +00:00
|
|
|
fPaints.push_back(p);
|
|
|
|
}
|
|
|
|
|
2019-07-23 13:49:59 +00:00
|
|
|
fLooper = SkBlurDrawLooper::Make(SK_ColorBLUE, SkBlurMask::ConvertRadiusToSigma(10),5,10);
|
|
|
|
{
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(kLooperColorSentinel);
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
fPaints.push_back(p);
|
|
|
|
}
|
2012-04-16 14:19:32 +00:00
|
|
|
{
|
|
|
|
// AA with stroke style
|
|
|
|
SkPaint p;
|
|
|
|
p.setAntiAlias(true);
|
2020-05-19 01:25:44 +00:00
|
|
|
p.setStroke(true);
|
2012-04-16 14:19:32 +00:00
|
|
|
p.setStrokeWidth(SkIntToScalar(3));
|
|
|
|
fPaints.push_back(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// AA with stroke style, width = 0
|
|
|
|
SkPaint p;
|
|
|
|
p.setAntiAlias(true);
|
2020-05-19 01:25:44 +00:00
|
|
|
p.setStroke(true);
|
2012-04-16 14:19:32 +00:00
|
|
|
fPaints.push_back(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// AA with stroke and fill style
|
|
|
|
SkPaint p;
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
p.setStyle(SkPaint::kStrokeAndFill_Style);
|
|
|
|
p.setStrokeWidth(SkIntToScalar(2));
|
|
|
|
fPaints.push_back(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void makeMatrices() {
|
|
|
|
{
|
|
|
|
SkMatrix m;
|
|
|
|
m.setScale(SkIntToScalar(2), SkIntToScalar(3));
|
|
|
|
fMatrices.push_back(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkMatrix m;
|
|
|
|
m.setScale(SkIntToScalar(2), SkIntToScalar(2));
|
|
|
|
fMatrices.push_back(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkMatrix m;
|
|
|
|
m.setSkew(SkIntToScalar(2), SkIntToScalar(3));
|
|
|
|
fMatrices.push_back(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkMatrix m;
|
|
|
|
m.setSkew(SkIntToScalar(2), SkIntToScalar(2));
|
|
|
|
fMatrices.push_back(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkMatrix m;
|
|
|
|
m.setRotate(SkIntToScalar(30));
|
|
|
|
fMatrices.push_back(m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2014-12-15 15:11:22 +00:00
|
|
|
// Draw a giant AA circle as the background.
|
|
|
|
SkISize size = this->getISize();
|
2020-02-07 15:36:46 +00:00
|
|
|
SkScalar giantRadius = std::min(SkIntToScalar(size.fWidth),
|
2014-12-15 15:11:22 +00:00
|
|
|
SkIntToScalar(size.fHeight)) / 2.f;
|
|
|
|
SkPoint giantCenter = SkPoint::Make(SkIntToScalar(size.fWidth/2),
|
|
|
|
SkIntToScalar(size.fHeight/2));
|
|
|
|
SkPaint giantPaint;
|
|
|
|
giantPaint.setAntiAlias(true);
|
|
|
|
giantPaint.setColor(0x80808080);
|
2017-05-15 17:35:35 +00:00
|
|
|
canvas->drawCircle(giantCenter, giantRadius, giantPaint);
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2014-12-15 20:54:51 +00:00
|
|
|
SkRandom rand;
|
2012-04-16 14:19:32 +00:00
|
|
|
canvas->translate(20 * SK_Scalar1, 20 * SK_Scalar1);
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < fPaints.count(); ++i) {
|
|
|
|
canvas->save();
|
|
|
|
// position the path, and make it at off-integer coords.
|
|
|
|
canvas->translate(SK_Scalar1 * 200 * (i % 5) + SK_Scalar1 / 4,
|
|
|
|
SK_Scalar1 * 200 * (i / 5) + 3 * SK_Scalar1 / 4);
|
2019-07-23 13:49:59 +00:00
|
|
|
SkPaint p = fPaints[i];
|
|
|
|
p.setColor(rand.nextU() | 0xff000000);
|
|
|
|
if (fPaints[i].getColor() == kLooperColorSentinel) {
|
|
|
|
fLooper->apply(canvas, p, [](SkCanvas* c, const SkPaint& p) {
|
|
|
|
c->drawCircle(40, 40, 20, p);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
canvas->drawCircle(40, 40, 20, p);
|
|
|
|
}
|
2012-04-16 14:19:32 +00:00
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int j = 0; j < fMatrices.count(); ++j, ++i) {
|
|
|
|
canvas->save();
|
|
|
|
|
|
|
|
canvas->translate(SK_Scalar1 * 200 * (i % 5) + SK_Scalar1 / 4,
|
|
|
|
SK_Scalar1 * 200 * (i / 5) + 3 * SK_Scalar1 / 4);
|
|
|
|
|
|
|
|
canvas->concat(fMatrices[j]);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
2019-07-23 13:49:59 +00:00
|
|
|
paint.setColor(rand.nextU() | 0xff000000);
|
|
|
|
canvas->drawCircle(40, 40, 20, paint);
|
2012-04-16 14:19:32 +00:00
|
|
|
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
SkTArray<SkPaint> fPaints;
|
|
|
|
SkTArray<SkMatrix> fMatrices;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-01-23 15:22:01 +00:00
|
|
|
DEF_GM( return new CircleGM; )
|
2012-04-16 14:19:32 +00:00
|
|
|
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|