1 /* 2 * Copyright 2016 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "gm.h" 9 #include "SkBlurImageFilter.h" 10 #include "SkCanvas.h" 11 #include "SkDashPathEffect.h" 12 #include "SkGradientShader.h" 13 #include "SkMaskFilter.h" 14 #include "SkRegion.h" 15 16 class DrawRegionModesGM : public skiagm::GM { 17 public: DrawRegionModesGM()18 DrawRegionModesGM() {} 19 20 protected: onShortName()21 SkString onShortName() override { 22 return SkString("drawregionmodes"); 23 } 24 onISize()25 SkISize onISize() override { 26 return SkISize::Make(375, 500); 27 } 28 onOnceBeforeDraw()29 void onOnceBeforeDraw() override { 30 fRegion.op( 50, 50, 100, 100, SkRegion::kUnion_Op); 31 fRegion.op( 50, 100, 150, 150, SkRegion::kUnion_Op); 32 } 33 onDraw(SkCanvas * canvas)34 void onDraw(SkCanvas* canvas) override { 35 canvas->clear(SK_ColorGREEN); 36 37 SkPaint paint; 38 paint.setStyle(SkPaint::kFill_Style); 39 paint.setColor(SK_ColorRED); 40 paint.setAntiAlias(true); 41 42 canvas->save(); 43 canvas->translate(-50.0f, 75.0f); 44 canvas->rotate(-45.0f); 45 canvas->drawRegion(fRegion, paint); 46 47 canvas->translate(125.0f, 125.0f); 48 paint.setImageFilter(SkBlurImageFilter::Make(5.0f, 5.0f, nullptr, nullptr)); 49 canvas->drawRegion(fRegion, paint); 50 51 canvas->translate(-125.0f, 125.0f); 52 paint.setImageFilter(nullptr); 53 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 5.0f)); 54 canvas->drawRegion(fRegion, paint); 55 56 canvas->translate(-125.0f, -125.0f); 57 paint.setMaskFilter(nullptr); 58 paint.setStyle(SkPaint::kStroke_Style); 59 float intervals[] = { 5.0f, 5.0f }; 60 paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 2.5f)); 61 canvas->drawRegion(fRegion, paint); 62 63 canvas->restore(); 64 65 canvas->translate(100, 325); 66 paint.setPathEffect(nullptr); 67 paint.setStyle(SkPaint::kFill_Style); 68 SkPoint points[] = { SkPoint::Make(50.0f, 50.0f), SkPoint::Make(150.0f, 150.0f) }; 69 SkColor colors[] = { SK_ColorBLUE, SK_ColorYELLOW }; 70 paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 2, 71 SkShader::kClamp_TileMode)); 72 canvas->drawRegion(fRegion, paint); 73 } 74 75 private: 76 SkRegion fRegion; 77 78 typedef skiagm::GM INHERITED; 79 }; 80 DEF_GM( return new DrawRegionModesGM; ) 81