2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "SkBlurMask.h"
10 #include "SkBlurMaskFilter.h"
12 #include "SkGraphics.h"
13 #include "SkLayerDrawLooper.h"
19 class DrawLooperGM : public skiagm::GM {
21 DrawLooperGM() : fLooper(NULL) {
22 this->setBGColor(0xFFDDDDDD);
25 virtual ~DrawLooperGM() {
30 virtual SkISize onISize() {
31 return SkISize::Make(520, 160);
34 virtual SkString onShortName() SK_OVERRIDE {
35 return SkString("drawlooper");
38 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
42 paint.setAntiAlias(true);
43 sk_tool_utils::set_portable_typeface(&paint);
44 paint.setTextSize(SkIntToScalar(72));
45 paint.setLooper(fLooper);
47 canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50),
48 SkIntToScalar(30), paint);
50 canvas->drawRectCoords(SkIntToScalar(150), SkIntToScalar(50),
51 SkIntToScalar(200), SkIntToScalar(100), paint);
53 canvas->drawText("Looper", 6, SkIntToScalar(230), SkIntToScalar(100),
58 SkLayerDrawLooper* fLooper;
65 SkPaint::Style fStyle;
70 { SK_ColorWHITE, SkPaint::kStroke_Style, SkIntToScalar(1)*3/4, 0, 0 },
71 { SK_ColorRED, SkPaint::kStroke_Style, SkIntToScalar(4), 0, 0 },
72 { SK_ColorBLUE, SkPaint::kFill_Style, 0, 0, 0 },
73 { 0x88000000, SkPaint::kFill_Style, 0, SkIntToScalar(10), SkIntToScalar(3) }
76 SkLayerDrawLooper::Builder looperBuilder;
78 SkLayerDrawLooper::LayerInfo info;
79 info.fPaintBits = SkLayerDrawLooper::kStyle_Bit | SkLayerDrawLooper::kMaskFilter_Bit;
80 info.fColorMode = SkXfermode::kSrc_Mode;
82 for (size_t i = 0; i < SK_ARRAY_COUNT(gParams); i++) {
83 info.fOffset.set(gParams[i].fOffset, gParams[i].fOffset);
84 SkPaint* paint = looperBuilder.addLayer(info);
85 paint->setColor(gParams[i].fColor);
86 paint->setStyle(gParams[i].fStyle);
87 paint->setStrokeWidth(gParams[i].fWidth);
88 if (gParams[i].fBlur > 0) {
89 SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
90 SkBlurMask::ConvertRadiusToSigma(gParams[i].fBlur));
91 paint->setMaskFilter(mf)->unref();
94 fLooper = looperBuilder.detachLooper();
100 //////////////////////////////////////////////////////////////////////////////
102 static skiagm::GM* MyFactory(void*) { return new DrawLooperGM; }
103 static skiagm::GMRegistry reg(MyFactory);