OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPath.h" | 10 #include "SkPath.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 SkString onShortName() override { | 30 SkString onShortName() override { |
31 return SkString("circular-clips"); | 31 return SkString("circular-clips"); |
32 } | 32 } |
33 | 33 |
34 SkISize onISize() override { | 34 SkISize onISize() override { |
35 return SkISize::Make(800, 600); | 35 return SkISize::Make(800, 600); |
36 } | 36 } |
37 | 37 |
38 void onDraw(SkCanvas* canvas) override { | 38 void onDraw(SkCanvas* canvas) override { |
39 SkRegion::Op ops[] = { | 39 SkCanvas::ClipOp ops[] = { |
40 SkRegion::kDifference_Op, | 40 SkCanvas::kDifference_Op, |
41 SkRegion::kIntersect_Op, | 41 SkCanvas::kIntersect_Op, |
42 SkRegion::kUnion_Op, | 42 SkCanvas::kUnion_Op, |
43 SkRegion::kXOR_Op, | 43 SkCanvas::kXOR_Op, |
44 SkRegion::kReverseDifference_Op, | 44 SkCanvas::kReverseDifference_Op, |
45 SkRegion::kReplace_Op, | 45 SkCanvas::kReplace_Op, |
46 }; | 46 }; |
47 | 47 |
48 SkRect rect = SkRect::MakeLTRB(fX1 - fR, fY - fR, fX2 + fR, fY + fR); | 48 SkRect rect = SkRect::MakeLTRB(fX1 - fR, fY - fR, fX2 + fR, fY + fR); |
49 | 49 |
50 SkPaint fillPaint; | 50 SkPaint fillPaint; |
51 | 51 |
52 // Giant background circular clips (AA, non-inverted, replace/isect) | 52 // Giant background circular clips (AA, non-inverted, replace/isect) |
53 fillPaint.setColor(0x80808080); | 53 fillPaint.setColor(0x80808080); |
54 canvas->save(); | 54 canvas->save(); |
55 canvas->scale(10, 10); | 55 canvas->scale(10, 10); |
56 canvas->translate(-((fX1 + fX2)/2 - fR), -(fY - 2*fR/3)); | 56 canvas->translate(-((fX1 + fX2)/2 - fR), -(fY - 2*fR/3)); |
57 canvas->clipPath(fCircle1, SkRegion::kReplace_Op, true); | 57 canvas->clipPath(fCircle1, SkCanvas::kReplace_Op, true); |
58 canvas->clipPath(fCircle2, SkRegion::kIntersect_Op, true); | 58 canvas->clipPath(fCircle2, SkCanvas::kIntersect_Op, true); |
59 | 59 |
60 canvas->drawRect(rect, fillPaint); | 60 canvas->drawRect(rect, fillPaint); |
61 | 61 |
62 canvas->restore(); | 62 canvas->restore(); |
63 | 63 |
64 fillPaint.setColor(0xFF000000); | 64 fillPaint.setColor(0xFF000000); |
65 | 65 |
66 for (size_t i = 0; i < 4; i++) { | 66 for (size_t i = 0; i < 4; i++) { |
67 fCircle1.toggleInverseFillType(); | 67 fCircle1.toggleInverseFillType(); |
68 if (i % 2 == 0) { | 68 if (i % 2 == 0) { |
69 fCircle2.toggleInverseFillType(); | 69 fCircle2.toggleInverseFillType(); |
70 } | 70 } |
71 | 71 |
72 canvas->save(); | 72 canvas->save(); |
73 for (size_t op = 0; op < SK_ARRAY_COUNT(ops); op++) { | 73 for (size_t op = 0; op < SK_ARRAY_COUNT(ops); op++) { |
74 canvas->save(); | 74 canvas->save(); |
75 | 75 |
76 canvas->clipPath(fCircle1, SkRegion::kReplace_Op); | 76 canvas->clipPath(fCircle1, SkCanvas::kReplace_Op); |
77 canvas->clipPath(fCircle2, ops[op]); | 77 canvas->clipPath(fCircle2, ops[op]); |
78 | 78 |
79 canvas->drawRect(rect, fillPaint); | 79 canvas->drawRect(rect, fillPaint); |
80 | 80 |
81 canvas->restore(); | 81 canvas->restore(); |
82 canvas->translate(0, 2 * fY); | 82 canvas->translate(0, 2 * fY); |
83 } | 83 } |
84 canvas->restore(); | 84 canvas->restore(); |
85 canvas->translate(fX1 + fX2, 0); | 85 canvas->translate(fX1 + fX2, 0); |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 private: | 89 private: |
90 typedef skiagm::GM INHERITED; | 90 typedef skiagm::GM INHERITED; |
91 }; | 91 }; |
92 | 92 |
93 ////////////////////////////////////////////////////////////////////////////// | 93 ////////////////////////////////////////////////////////////////////////////// |
94 | 94 |
95 DEF_GM( return new CircularClipsGM; ) | 95 DEF_GM( return new CircularClipsGM; ) |
OLD | NEW |