msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 9 | #include "include/core/SkBlurTypes.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkCanvas.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 11 | #include "include/core/SkColor.h" |
| 12 | #include "include/core/SkImageFilter.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "include/core/SkMaskFilter.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 14 | #include "include/core/SkPaint.h" |
| 15 | #include "include/core/SkPathEffect.h" |
| 16 | #include "include/core/SkPoint.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "include/core/SkRegion.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 18 | #include "include/core/SkShader.h" |
| 19 | #include "include/core/SkSize.h" |
| 20 | #include "include/core/SkString.h" |
| 21 | #include "include/core/SkTileMode.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 22 | #include "include/effects/SkDashPathEffect.h" |
| 23 | #include "include/effects/SkGradientShader.h" |
Michael Ludwig | 898bbfa | 2019-08-02 15:21:23 -0400 | [diff] [blame] | 24 | #include "include/effects/SkImageFilters.h" |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 25 | |
| 26 | class DrawRegionModesGM : public skiagm::GM { |
| 27 | public: |
| 28 | DrawRegionModesGM() {} |
| 29 | |
| 30 | protected: |
| 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 { |
Mike Reed | 92b3335 | 2019-08-24 19:39:13 -0400 | [diff] [blame] | 40 | fRegion.op({50, 50, 100, 100}, SkRegion::kUnion_Op); |
| 41 | fRegion.op({50, 100, 150, 150}, SkRegion::kUnion_Op); |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | void onDraw(SkCanvas* canvas) override { |
| 45 | canvas->clear(SK_ColorGREEN); |
| 46 | |
| 47 | SkPaint paint; |
| 48 | paint.setStyle(SkPaint::kFill_Style); |
Robert Phillips | 2748391 | 2018-04-20 12:43:18 -0400 | [diff] [blame] | 49 | paint.setColor(SK_ColorRED); |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 50 | paint.setAntiAlias(true); |
| 51 | |
Robert Phillips | 2748391 | 2018-04-20 12:43:18 -0400 | [diff] [blame] | 52 | canvas->save(); |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 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); |
Michael Ludwig | 898bbfa | 2019-08-02 15:21:23 -0400 | [diff] [blame] | 58 | paint.setImageFilter(SkImageFilters::Blur(5.0f, 5.0f, nullptr, nullptr)); |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 59 | canvas->drawRegion(fRegion, paint); |
| 60 | |
| 61 | canvas->translate(-125.0f, 125.0f); |
| 62 | paint.setImageFilter(nullptr); |
Robert Phillips | 557aad7 | 2018-08-17 08:10:27 -0400 | [diff] [blame] | 63 | paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 5.0f)); |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 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 | |
Robert Phillips | 2748391 | 2018-04-20 12:43:18 -0400 | [diff] [blame] | 73 | canvas->restore(); |
| 74 | |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 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, |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 81 | SkTileMode::kClamp)); |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 82 | canvas->drawRegion(fRegion, paint); |
| 83 | } |
| 84 | |
Robert Phillips | 2748391 | 2018-04-20 12:43:18 -0400 | [diff] [blame] | 85 | private: |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 86 | SkRegion fRegion; |
| 87 | |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 88 | typedef skiagm::GM INHERITED; |
| 89 | }; |
| 90 | DEF_GM( return new DrawRegionModesGM; ) |