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.
|
|
|
|
*/
|
2011-02-18 19:03:01 +00:00
|
|
|
#include "gm.h"
|
2013-09-06 14:16:12 +00:00
|
|
|
#include "SkBlurMask.h"
|
2011-02-18 19:03:01 +00:00
|
|
|
#include "SkBlurDrawLooper.h"
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2011-02-18 19:03:01 +00:00
|
|
|
ShadowsGM() {
|
2011-10-31 14:18:20 +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));
|
2011-02-18 19:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual SkString onShortName() {
|
|
|
|
return SkString("shadows");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual SkISize onISize() {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(200, 120);
|
2011-02-18 19:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
|
|
SkBlurDrawLooper* shadowLoopers[5];
|
|
|
|
shadowLoopers[0] =
|
2014-04-15 15:48:36 +00:00
|
|
|
SkBlurDrawLooper::Create(SK_ColorBLUE,
|
|
|
|
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
|
|
|
|
SkIntToScalar(5), SkIntToScalar(10),
|
|
|
|
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
|
|
|
|
SkBlurDrawLooper::kOverrideColor_BlurFlag |
|
|
|
|
SkBlurDrawLooper::kHighQuality_BlurFlag);
|
2011-02-18 19:03:01 +00:00
|
|
|
SkAutoUnref aurL0(shadowLoopers[0]);
|
|
|
|
shadowLoopers[1] =
|
2014-04-15 15:48:36 +00:00
|
|
|
SkBlurDrawLooper::Create(SK_ColorBLUE,
|
|
|
|
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
|
|
|
|
SkIntToScalar(5), SkIntToScalar(10),
|
|
|
|
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
|
|
|
|
SkBlurDrawLooper::kOverrideColor_BlurFlag);
|
2011-02-18 19:03:01 +00:00
|
|
|
SkAutoUnref aurL1(shadowLoopers[1]);
|
|
|
|
shadowLoopers[2] =
|
2014-04-15 15:48:36 +00:00
|
|
|
SkBlurDrawLooper::Create(SK_ColorBLACK,
|
|
|
|
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
|
|
|
|
SkIntToScalar(5),
|
|
|
|
SkIntToScalar(10),
|
|
|
|
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
|
|
|
|
SkBlurDrawLooper::kHighQuality_BlurFlag);
|
2011-02-18 19:03:01 +00:00
|
|
|
SkAutoUnref aurL2(shadowLoopers[2]);
|
|
|
|
shadowLoopers[3] =
|
2014-04-15 15:48:36 +00:00
|
|
|
SkBlurDrawLooper::Create(0x7FFF0000,
|
|
|
|
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
|
|
|
|
SkIntToScalar(-5), SkIntToScalar(-10),
|
|
|
|
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
|
|
|
|
SkBlurDrawLooper::kOverrideColor_BlurFlag |
|
|
|
|
SkBlurDrawLooper::kHighQuality_BlurFlag);
|
2011-02-18 19:03:01 +00:00
|
|
|
SkAutoUnref aurL3(shadowLoopers[3]);
|
|
|
|
shadowLoopers[4] =
|
2014-04-15 15:48:36 +00:00
|
|
|
SkBlurDrawLooper::Create(SK_ColorBLACK, SkIntToScalar(0),
|
|
|
|
SkIntToScalar(5), SkIntToScalar(5),
|
|
|
|
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
|
|
|
|
SkBlurDrawLooper::kOverrideColor_BlurFlag |
|
|
|
|
SkBlurDrawLooper::kHighQuality_BlurFlag);
|
2011-02-18 19:03:01 +00:00
|
|
|
SkAutoUnref aurL4(shadowLoopers[4]);
|
|
|
|
|
2011-05-26 15:12:35 +00:00
|
|
|
static const struct {
|
|
|
|
SkColor fColor;
|
|
|
|
SkScalar fStrokeWidth;
|
|
|
|
} gRec[] = {
|
|
|
|
{ SK_ColorRED, -SK_Scalar1 },
|
|
|
|
{ SK_ColorGREEN, SkIntToScalar(4) },
|
2012-04-05 13:20:59 +00:00
|
|
|
{ SK_ColorBLUE, SkIntToScalar(0)},
|
2011-05-26 15:12:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(shadowLoopers); ++i) {
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
|
|
|
|
paint.setLooper(shadowLoopers[i]);
|
|
|
|
|
2012-05-17 15:38:00 +00:00
|
|
|
canvas->translate(SkIntToScalar((unsigned int)i*40), SkIntToScalar(0));
|
2011-05-26 15:12:35 +00:00
|
|
|
setup(&paint, gRec[0].fColor, gRec[0].fStrokeWidth);
|
|
|
|
canvas->drawRect(fRect, paint);
|
|
|
|
|
2011-02-18 19:03:01 +00:00
|
|
|
canvas->translate(SkIntToScalar(0), SkIntToScalar(40));
|
2011-05-26 15:12:35 +00:00
|
|
|
setup(&paint, gRec[1].fColor, gRec[1].fStrokeWidth);
|
|
|
|
canvas->drawPath(fCirclePath, paint);
|
2012-04-05 13:20:59 +00:00
|
|
|
|
|
|
|
canvas->translate(SkIntToScalar(0), SkIntToScalar(40));
|
|
|
|
setup(&paint, gRec[2].fColor, gRec[2].fStrokeWidth);
|
|
|
|
canvas->drawPath(fCirclePath, paint);
|
2011-02-18 19:03:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new ShadowsGM; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|