blob: 3b153a04544ee233169bd5dc23964a29c1e2b1a9 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#include "include/core/SkBlurTypes.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkCanvas.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040011#include "include/core/SkColor.h"
12#include "include/core/SkImageFilter.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "include/core/SkMaskFilter.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040014#include "include/core/SkPaint.h"
15#include "include/core/SkPathEffect.h"
16#include "include/core/SkPoint.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "include/core/SkRegion.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040018#include "include/core/SkShader.h"
19#include "include/core/SkSize.h"
20#include "include/core/SkString.h"
21#include "include/core/SkTileMode.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050022#include "include/effects/SkDashPathEffect.h"
23#include "include/effects/SkGradientShader.h"
Michael Ludwig898bbfa2019-08-02 15:21:23 -040024#include "include/effects/SkImageFilters.h"
msarett44df6512016-08-25 13:54:30 -070025
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 {
Mike Reed92b33352019-08-24 19:39:13 -040040 fRegion.op({50, 50, 100, 100}, SkRegion::kUnion_Op);
41 fRegion.op({50, 100, 150, 150}, SkRegion::kUnion_Op);
msarett44df6512016-08-25 13:54:30 -070042 }
43
44 void onDraw(SkCanvas* canvas) override {
45 canvas->clear(SK_ColorGREEN);
46
47 SkPaint paint;
48 paint.setStyle(SkPaint::kFill_Style);
Robert Phillips27483912018-04-20 12:43:18 -040049 paint.setColor(SK_ColorRED);
msarett44df6512016-08-25 13:54:30 -070050 paint.setAntiAlias(true);
51
Robert Phillips27483912018-04-20 12:43:18 -040052 canvas->save();
msarett44df6512016-08-25 13:54:30 -070053 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 Ludwig898bbfa2019-08-02 15:21:23 -040058 paint.setImageFilter(SkImageFilters::Blur(5.0f, 5.0f, nullptr, nullptr));
msarett44df6512016-08-25 13:54:30 -070059 canvas->drawRegion(fRegion, paint);
60
61 canvas->translate(-125.0f, 125.0f);
62 paint.setImageFilter(nullptr);
Robert Phillips557aad72018-08-17 08:10:27 -040063 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 5.0f));
msarett44df6512016-08-25 13:54:30 -070064 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 Phillips27483912018-04-20 12:43:18 -040073 canvas->restore();
74
msarett44df6512016-08-25 13:54:30 -070075 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 Reedfae8fce2019-04-03 10:27:45 -040081 SkTileMode::kClamp));
msarett44df6512016-08-25 13:54:30 -070082 canvas->drawRegion(fRegion, paint);
83 }
84
Robert Phillips27483912018-04-20 12:43:18 -040085private:
msarett44df6512016-08-25 13:54:30 -070086 SkRegion fRegion;
87
msarett44df6512016-08-25 13:54:30 -070088 typedef skiagm::GM INHERITED;
89};
90DEF_GM( return new DrawRegionModesGM; )