2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2015-08-05 20:57:49 +00:00
|
|
|
|
2011-02-18 19:03:01 +00:00
|
|
|
#include "gm.h"
|
2015-08-05 01:44:56 +00:00
|
|
|
#include "SkBlurDrawLooper.h"
|
2015-08-05 20:57:49 +00:00
|
|
|
#include "SkBlurMask.h"
|
2016-08-04 13:19:33 +00:00
|
|
|
#include "SkColorFilter.h"
|
|
|
|
#include "SkMaskFilter.h"
|
2015-08-05 20:57:49 +00:00
|
|
|
#include "SkPath.h"
|
2011-02-18 19:03:01 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-05-26 15:12:35 +00:00
|
|
|
static void setup(SkPaint* paint, SkColor c, SkScalar strokeWidth) {
|
|
|
|
paint->setColor(c);
|
|
|
|
if (strokeWidth < 0) {
|
|
|
|
paint->setStyle(SkPaint::kFill_Style);
|
|
|
|
} else {
|
|
|
|
paint->setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint->setStrokeWidth(strokeWidth);
|
|
|
|
}
|
|
|
|
}
|
2011-02-18 19:03:01 +00:00
|
|
|
|
2011-05-26 15:12:35 +00:00
|
|
|
class ShadowsGM : public GM {
|
2011-02-18 19:03:01 +00:00
|
|
|
public:
|
|
|
|
SkPath fCirclePath;
|
2011-05-26 15:12:35 +00:00
|
|
|
SkRect fRect;
|
2015-09-04 12:20:32 +00:00
|
|
|
SkBitmap fBitmap;
|
2011-05-26 15:12:35 +00:00
|
|
|
|
2015-02-25 17:04:04 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2018-08-16 14:17:03 +00:00
|
|
|
this->setBGColor(0xFFDDDDDD);
|
2011-02-18 19:03:01 +00:00
|
|
|
fCirclePath.addCircle(SkIntToScalar(20), SkIntToScalar(20), SkIntToScalar(10) );
|
2011-05-26 15:12:35 +00:00
|
|
|
fRect.set(SkIntToScalar(10), SkIntToScalar(10),
|
|
|
|
SkIntToScalar(30), SkIntToScalar(30));
|
2015-09-04 12:20:32 +00:00
|
|
|
fBitmap.allocPixels(SkImageInfo::Make(20, 20, SkColorType::kAlpha_8_SkColorType,
|
|
|
|
kPremul_SkAlphaType));
|
|
|
|
SkCanvas canvas(fBitmap);
|
|
|
|
canvas.clear(0x0);
|
|
|
|
SkPaint p;
|
|
|
|
canvas.drawRect(SkRect::MakeXYWH(10, 0, 10, 10), p);
|
|
|
|
canvas.drawRect(SkRect::MakeXYWH(0, 10, 10, 10), p);
|
2011-02-18 19:03:01 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
SkString onShortName() override {
|
2011-02-18 19:03:01 +00:00
|
|
|
return SkString("shadows");
|
|
|
|
}
|
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
SkISize onISize() override {
|
2015-09-04 13:19:48 +00:00
|
|
|
return SkISize::Make(200, 200);
|
2011-02-18 19:03:01 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2016-03-21 20:25:16 +00:00
|
|
|
sk_sp<SkDrawLooper> shadowLoopers[] = {
|
|
|
|
SkBlurDrawLooper::Make(SK_ColorBLUE,
|
2015-07-13 13:18:39 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
|
2017-03-23 20:23:38 +00:00
|
|
|
SkIntToScalar(5), SkIntToScalar(10)),
|
2016-03-21 20:25:16 +00:00
|
|
|
SkBlurDrawLooper::Make(SK_ColorBLUE,
|
2015-07-13 13:18:39 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
|
2017-03-23 20:23:38 +00:00
|
|
|
SkIntToScalar(5), SkIntToScalar(10)),
|
2016-03-21 20:25:16 +00:00
|
|
|
SkBlurDrawLooper::Make(SK_ColorBLACK,
|
2015-07-13 13:18:39 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
|
|
|
|
SkIntToScalar(5),
|
2017-03-23 20:23:38 +00:00
|
|
|
SkIntToScalar(10)),
|
2016-03-21 20:25:16 +00:00
|
|
|
SkBlurDrawLooper::Make(0x7FFF0000,
|
2015-07-13 13:18:39 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
|
2017-03-23 20:23:38 +00:00
|
|
|
SkIntToScalar(-5), SkIntToScalar(-10)),
|
2016-03-21 20:25:16 +00:00
|
|
|
SkBlurDrawLooper::Make(SK_ColorBLACK, SkIntToScalar(0),
|
2017-03-23 20:23:38 +00:00
|
|
|
SkIntToScalar(5), SkIntToScalar(5)),
|
2016-03-21 20:25:16 +00:00
|
|
|
};
|
2015-07-13 13:18:39 +00:00
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr struct {
|
2015-07-13 13:18:39 +00:00
|
|
|
SkColor fColor;
|
|
|
|
SkScalar fStrokeWidth;
|
|
|
|
} gRec[] = {
|
|
|
|
{ SK_ColorRED, -SK_Scalar1 },
|
|
|
|
{ SK_ColorGREEN, SkIntToScalar(4) },
|
|
|
|
{ SK_ColorBLUE, SkIntToScalar(0)},
|
|
|
|
};
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(shadowLoopers); ++i) {
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
|
|
|
|
paint.setLooper(shadowLoopers[i]);
|
|
|
|
|
|
|
|
canvas->translate(SkIntToScalar((unsigned int)i*40), SkIntToScalar(0));
|
|
|
|
setup(&paint, gRec[0].fColor, gRec[0].fStrokeWidth);
|
|
|
|
canvas->drawRect(fRect, paint);
|
|
|
|
|
|
|
|
canvas->translate(SkIntToScalar(0), SkIntToScalar(40));
|
|
|
|
setup(&paint, gRec[1].fColor, gRec[1].fStrokeWidth);
|
|
|
|
canvas->drawPath(fCirclePath, paint);
|
|
|
|
|
|
|
|
canvas->translate(SkIntToScalar(0), SkIntToScalar(40));
|
|
|
|
setup(&paint, gRec[2].fColor, gRec[2].fStrokeWidth);
|
|
|
|
canvas->drawPath(fCirclePath, paint);
|
2015-09-04 12:20:32 +00:00
|
|
|
|
|
|
|
// see bug.skia.org/562 (reference, draws correct)
|
|
|
|
canvas->translate(0, 40);
|
|
|
|
paint.setColor(SK_ColorBLACK);
|
|
|
|
canvas->drawBitmap(fBitmap, 10, 10, &paint);
|
|
|
|
|
|
|
|
canvas->translate(0, 40);
|
2016-03-13 21:13:58 +00:00
|
|
|
paint.setShader(SkShader::MakeBitmapShader(
|
2015-09-04 12:20:32 +00:00
|
|
|
fBitmap, SkShader::kRepeat_TileMode,
|
|
|
|
SkShader::kRepeat_TileMode));
|
|
|
|
|
|
|
|
// see bug.skia.org/562 (shows bug as reported)
|
|
|
|
paint.setStyle(SkPaint::kFill_Style);
|
|
|
|
canvas->drawRect(SkRect::MakeXYWH(10, 10, 20, 20), paint);
|
|
|
|
paint.setShader(nullptr);
|
2015-07-13 13:18:39 +00:00
|
|
|
}
|
2011-02-18 19:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new ShadowsGM; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|