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 "sk_tool_utils.h"
10 #include "SkBlurMask.h"
11 #include "SkBlurMaskFilter.h"
13 #include "SkGraphics.h"
14 #include "SkLayerDrawLooper.h"
20 class DrawLooperGM : public skiagm::GM {
22 DrawLooperGM() : fLooper(nullptr) {
23 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
27 virtual SkISize onISize() override {
28 return SkISize::Make(520, 160);
31 SkString onShortName() override {
32 return SkString("drawlooper");
35 void onDraw(SkCanvas* canvas) override {
39 paint.setAntiAlias(true);
40 sk_tool_utils::set_portable_typeface(&paint);
41 paint.setTextSize(SkIntToScalar(72));
42 paint.setLooper(fLooper);
44 canvas->drawCircle(50, 50, 30, paint);
45 canvas->drawRect({ 150, 50, 200, 100 }, paint);
46 canvas->drawString("Looper", 230, 100, paint);
50 sk_sp<SkDrawLooper> fLooper;
57 SkPaint::Style fStyle;
62 { SK_ColorWHITE, SkPaint::kStroke_Style, SkIntToScalar(1)*3/4, 0, 0 },
63 { SK_ColorRED, SkPaint::kStroke_Style, SkIntToScalar(4), 0, 0 },
64 { SK_ColorBLUE, SkPaint::kFill_Style, 0, 0, 0 },
65 { 0x88000000, SkPaint::kFill_Style, 0, SkIntToScalar(10), SkIntToScalar(3) }
68 SkLayerDrawLooper::Builder looperBuilder;
70 SkLayerDrawLooper::LayerInfo info;
71 info.fPaintBits = SkLayerDrawLooper::kStyle_Bit | SkLayerDrawLooper::kMaskFilter_Bit;
72 info.fColorMode = SkBlendMode::kSrc;
74 for (size_t i = 0; i < SK_ARRAY_COUNT(gParams); i++) {
75 info.fOffset.set(gParams[i].fOffset, gParams[i].fOffset);
76 SkPaint* paint = looperBuilder.addLayer(info);
77 paint->setColor(gParams[i].fColor);
78 paint->setStyle(gParams[i].fStyle);
79 paint->setStrokeWidth(gParams[i].fWidth);
80 if (gParams[i].fBlur > 0) {
81 paint->setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
82 SkBlurMask::ConvertRadiusToSigma(gParams[i].fBlur)));
85 fLooper = looperBuilder.detach();
91 //////////////////////////////////////////////////////////////////////////////
93 DEF_GM( return new DrawLooperGM; )