blob: efccc88acea6f29a6579fc151fb9b6cc6c0bb655 [file] [log] [blame]
msarett44df6512016-08-25 13:54:30 -07001/*
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 "SkBlurMaskFilter.h"
10#include "SkCanvas.h"
11#include "SkDashPathEffect.h"
12#include "SkGradientShader.h"
13#include "SkImageFilter.h"
Mike Reed267be7f2017-02-13 09:32:54 -050014#include "SkRegion.h"
msarett44df6512016-08-25 13:54:30 -070015
16class DrawRegionModesGM : public skiagm::GM {
17public:
18 DrawRegionModesGM() {}
19
20protected:
21 SkString onShortName() override {
22 return SkString("drawregionmodes");
23 }
24
25 SkISize onISize() override {
26 return SkISize::Make(375, 500);
27 }
28
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
34 void onDraw(SkCanvas* canvas) override {
35 canvas->clear(SK_ColorGREEN);
36
37 SkPaint paint;
38 paint.setStyle(SkPaint::kFill_Style);
39 paint.setColor(0xFFFF0000);
40 paint.setAntiAlias(true);
41
42 canvas->translate(-50.0f, 75.0f);
43 canvas->rotate(-45.0f);
44 canvas->drawRegion(fRegion, paint);
45
46 canvas->translate(125.0f, 125.0f);
47 paint.setImageFilter(SkImageFilter::MakeBlur(5.0f, 5.0f, nullptr, nullptr));
48 canvas->drawRegion(fRegion, paint);
49
50 canvas->translate(-125.0f, 125.0f);
51 paint.setImageFilter(nullptr);
52 SkRect occluder = SkRect::MakeEmpty();
53 paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 5.0f, occluder, 0));
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->setMatrix(SkMatrix::I());
64 canvas->translate(100, 325);
65 paint.setPathEffect(nullptr);
66 paint.setStyle(SkPaint::kFill_Style);
67 SkPoint points[] = { SkPoint::Make(50.0f, 50.0f), SkPoint::Make(150.0f, 150.0f) };
68 SkColor colors[] = { SK_ColorBLUE, SK_ColorYELLOW };
69 paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 2,
70 SkShader::kClamp_TileMode));
71 canvas->drawRegion(fRegion, paint);
72 }
73
74 SkRegion fRegion;
75
76private:
77 typedef skiagm::GM INHERITED;
78};
79DEF_GM( return new DrawRegionModesGM; )