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/gm.h" 9#include "include/core/SkBlurTypes.h" 10#include "include/core/SkCanvas.h" 11#include "include/core/SkColor.h" 12#include "include/core/SkImageFilter.h" 13#include "include/core/SkMaskFilter.h" 14#include "include/core/SkPaint.h" 15#include "include/core/SkPathEffect.h" 16#include "include/core/SkPoint.h" 17#include "include/core/SkRegion.h" 18#include "include/core/SkShader.h" 19#include "include/core/SkSize.h" 20#include "include/core/SkString.h" 21#include "include/core/SkTileMode.h" 22#include "include/effects/SkDashPathEffect.h" 23#include "include/effects/SkGradientShader.h" 24#include "include/effects/SkImageFilters.h" 25 26class DrawRegionModesGM : public skiagm::GM { 27public: 28 DrawRegionModesGM() {} 29 30protected: 31 SkString onShortName() override { 32 return SkString("drawregionmodes"); 33 } 34 35 SkISize onISize() override { 36 return SkISize::Make(375, 500); 37 } 38 39 void onOnceBeforeDraw() override { 40 fRegion.op({50, 50, 100, 100}, SkRegion::kUnion_Op); 41 fRegion.op({50, 100, 150, 150}, SkRegion::kUnion_Op); 42 } 43 44 void onDraw(SkCanvas* canvas) override { 45 canvas->clear(SK_ColorGREEN); 46 47 SkPaint paint; 48 paint.setStyle(SkPaint::kFill_Style); 49 paint.setColor(SK_ColorRED); 50 paint.setAntiAlias(true); 51 52 canvas->save(); 53 canvas->translate(-50.0f, 75.0f); 54 canvas->rotate(-45.0f); 55 canvas->drawRegion(fRegion, paint); 56 57 canvas->translate(125.0f, 125.0f); 58 paint.setImageFilter(SkImageFilters::Blur(5.0f, 5.0f, nullptr, nullptr)); 59 canvas->drawRegion(fRegion, paint); 60 61 canvas->translate(-125.0f, 125.0f); 62 paint.setImageFilter(nullptr); 63 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 5.0f)); 64 canvas->drawRegion(fRegion, paint); 65 66 canvas->translate(-125.0f, -125.0f); 67 paint.setMaskFilter(nullptr); 68 paint.setStyle(SkPaint::kStroke_Style); 69 float intervals[] = { 5.0f, 5.0f }; 70 paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 2.5f)); 71 canvas->drawRegion(fRegion, paint); 72 73 canvas->restore(); 74 75 canvas->translate(100, 325); 76 paint.setPathEffect(nullptr); 77 paint.setStyle(SkPaint::kFill_Style); 78 SkPoint points[] = { SkPoint::Make(50.0f, 50.0f), SkPoint::Make(150.0f, 150.0f) }; 79 SkColor colors[] = { SK_ColorBLUE, SK_ColorYELLOW }; 80 paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 2, 81 SkTileMode::kClamp)); 82 canvas->drawRegion(fRegion, paint); 83 } 84 85private: 86 SkRegion fRegion; 87 88 using INHERITED = skiagm::GM; 89}; 90DEF_GM( return new DrawRegionModesGM; ) 91