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