OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 //#include "SkParsePath.h" | 10 //#include "SkParsePath.h" |
11 #include "SkPath.h" | 11 #include "SkPath.h" |
12 //#include "SkRandom.h" | 12 //#include "SkRandom.h" |
13 | 13 |
14 namespace skiagm { | 14 namespace skiagm { |
15 | 15 |
16 static const SkColor gPathColor = SK_ColorBLACK; | 16 static const SkColor gPathColor = SK_ColorBLACK; |
17 static const SkColor gClipAColor = SK_ColorBLUE; | 17 static const SkColor gClipAColor = SK_ColorBLUE; |
18 static const SkColor gClipBColor = SK_ColorRED; | 18 static const SkColor gClipBColor = SK_ColorRED; |
19 | 19 |
20 class ComplexClipGM : public GM { | 20 class ComplexClipGM : public GM { |
21 bool fDoAAClip; | |
22 bool fDoSaveLayer; | |
23 public: | 21 public: |
24 ComplexClipGM(bool aaclip, bool saveLayer) | 22 ComplexClipGM(bool aaclip, bool saveLayer, bool invertDraw) |
25 : fDoAAClip(aaclip) | 23 : fDoAAClip(aaclip) |
26 , fDoSaveLayer(saveLayer) { | 24 , fDoSaveLayer(saveLayer) |
| 25 , fInvertDraw(invertDraw) { |
27 this->setBGColor(0xFFDDDDDD); | 26 this->setBGColor(0xFFDDDDDD); |
28 // this->setBGColor(SkColorSetRGB(0xB0,0xDD,0xB0)); | |
29 } | 27 } |
30 | 28 |
31 protected: | 29 protected: |
32 virtual uint32_t onGetFlags() const SK_OVERRIDE { | 30 virtual uint32_t onGetFlags() const SK_OVERRIDE { |
33 return kSkipTiled_Flag; | 31 return kSkipTiled_Flag; |
34 } | 32 } |
35 | 33 |
36 | 34 |
37 SkString onShortName() { | 35 SkString onShortName() { |
38 SkString str; | 36 SkString str; |
39 str.printf("complexclip_%s%s", | 37 str.printf("complexclip_%s%s%s", |
40 fDoAAClip ? "aa" : "bw", | 38 fDoAAClip ? "aa" : "bw", |
41 fDoSaveLayer ? "_layer" : ""); | 39 fDoSaveLayer ? "_layer" : "", |
| 40 fInvertDraw ? "_invert" : ""); |
42 return str; | 41 return str; |
43 } | 42 } |
44 | 43 |
45 SkISize onISize() { return SkISize::Make(970, 780); } | 44 SkISize onISize() { return SkISize::Make(970, 780); } |
46 | 45 |
47 virtual void onDraw(SkCanvas* canvas) { | 46 virtual void onDraw(SkCanvas* canvas) { |
48 SkPath path; | 47 SkPath path; |
49 path.moveTo(SkIntToScalar(0), SkIntToScalar(50)); | 48 path.moveTo(SkIntToScalar(0), SkIntToScalar(50)); |
50 path.quadTo(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(50),
SkIntToScalar(0)); | 49 path.quadTo(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(50),
SkIntToScalar(0)); |
51 path.lineTo(SkIntToScalar(175), SkIntToScalar(0)); | 50 path.lineTo(SkIntToScalar(175), SkIntToScalar(0)); |
52 path.quadTo(SkIntToScalar(200), SkIntToScalar(0), SkIntToScalar(200),
SkIntToScalar(25)); | 51 path.quadTo(SkIntToScalar(200), SkIntToScalar(0), SkIntToScalar(200),
SkIntToScalar(25)); |
53 path.lineTo(SkIntToScalar(200), SkIntToScalar(150)); | 52 path.lineTo(SkIntToScalar(200), SkIntToScalar(150)); |
54 path.quadTo(SkIntToScalar(200), SkIntToScalar(200), SkIntToScalar(150),
SkIntToScalar(200)); | 53 path.quadTo(SkIntToScalar(200), SkIntToScalar(200), SkIntToScalar(150),
SkIntToScalar(200)); |
55 path.lineTo(SkIntToScalar(0), SkIntToScalar(200)); | 54 path.lineTo(SkIntToScalar(0), SkIntToScalar(200)); |
56 path.close(); | 55 path.close(); |
57 path.moveTo(SkIntToScalar(50), SkIntToScalar(50)); | 56 path.moveTo(SkIntToScalar(50), SkIntToScalar(50)); |
58 path.lineTo(SkIntToScalar(150), SkIntToScalar(50)); | 57 path.lineTo(SkIntToScalar(150), SkIntToScalar(50)); |
59 path.lineTo(SkIntToScalar(150), SkIntToScalar(125)); | 58 path.lineTo(SkIntToScalar(150), SkIntToScalar(125)); |
60 path.quadTo(SkIntToScalar(150), SkIntToScalar(150), SkIntToScalar(125),
SkIntToScalar(150)); | 59 path.quadTo(SkIntToScalar(150), SkIntToScalar(150), SkIntToScalar(125),
SkIntToScalar(150)); |
61 path.lineTo(SkIntToScalar(50), SkIntToScalar(150)); | 60 path.lineTo(SkIntToScalar(50), SkIntToScalar(150)); |
62 path.close(); | 61 path.close(); |
63 path.setFillType(SkPath::kEvenOdd_FillType); | 62 if (fInvertDraw) { |
| 63 path.setFillType(SkPath::kInverseEvenOdd_FillType); |
| 64 } else { |
| 65 path.setFillType(SkPath::kEvenOdd_FillType); |
| 66 } |
64 SkPaint pathPaint; | 67 SkPaint pathPaint; |
65 pathPaint.setAntiAlias(true); | 68 pathPaint.setAntiAlias(true); |
66 pathPaint.setColor(gPathColor); | 69 pathPaint.setColor(gPathColor); |
67 | 70 |
68 SkPath clipA; | 71 SkPath clipA; |
69 clipA.moveTo(SkIntToScalar(10), SkIntToScalar(20)); | 72 clipA.moveTo(SkIntToScalar(10), SkIntToScalar(20)); |
70 clipA.lineTo(SkIntToScalar(165), SkIntToScalar(22)); | 73 clipA.lineTo(SkIntToScalar(165), SkIntToScalar(22)); |
71 clipA.lineTo(SkIntToScalar(70), SkIntToScalar(105)); | 74 clipA.lineTo(SkIntToScalar(70), SkIntToScalar(105)); |
72 clipA.lineTo(SkIntToScalar(165), SkIntToScalar(177)); | 75 clipA.lineTo(SkIntToScalar(165), SkIntToScalar(177)); |
73 clipA.lineTo(SkIntToScalar(-5), SkIntToScalar(180)); | 76 clipA.lineTo(SkIntToScalar(-5), SkIntToScalar(180)); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 bool doInvB = SkToBool(invBits & 2); | 130 bool doInvB = SkToBool(invBits & 2); |
128 canvas->save(); | 131 canvas->save(); |
129 // set clip | 132 // set clip |
130 clipA.setFillType(doInvA ? SkPath::kInverseEvenOdd_FillType
: | 133 clipA.setFillType(doInvA ? SkPath::kInverseEvenOdd_FillType
: |
131 SkPath::kEvenOdd_FillType); | 134 SkPath::kEvenOdd_FillType); |
132 clipB.setFillType(doInvB ? SkPath::kInverseEvenOdd_FillType
: | 135 clipB.setFillType(doInvB ? SkPath::kInverseEvenOdd_FillType
: |
133 SkPath::kEvenOdd_FillType); | 136 SkPath::kEvenOdd_FillType); |
134 canvas->clipPath(clipA, SkRegion::kIntersect_Op, fDoAAClip); | 137 canvas->clipPath(clipA, SkRegion::kIntersect_Op, fDoAAClip); |
135 canvas->clipPath(clipB, gOps[op].fOp, fDoAAClip); | 138 canvas->clipPath(clipB, gOps[op].fOp, fDoAAClip); |
136 | 139 |
| 140 // In the inverse case we need to prevent the draw from cove
ring the whole |
| 141 // canvas. |
| 142 if (fInvertDraw) { |
| 143 SkRect rectClip = clipA.getBounds(); |
| 144 rectClip.join(path.getBounds()); |
| 145 rectClip.join(path.getBounds()); |
| 146 rectClip.outset(5, 5); |
| 147 canvas->clipRect(rectClip); |
| 148 } |
| 149 |
137 // draw path clipped | 150 // draw path clipped |
138 canvas->drawPath(path, pathPaint); | 151 canvas->drawPath(path, pathPaint); |
139 canvas->restore(); | 152 canvas->restore(); |
140 | 153 |
141 | 154 |
142 SkScalar txtX = SkIntToScalar(45); | 155 SkScalar txtX = SkIntToScalar(45); |
143 paint.setColor(gClipAColor); | 156 paint.setColor(gClipAColor); |
144 const char* aTxt = doInvA ? "InvA " : "A "; | 157 const char* aTxt = doInvA ? "InvA " : "A "; |
145 canvas->drawText(aTxt, strlen(aTxt), txtX, SkIntToScalar(220), p
aint); | 158 canvas->drawText(aTxt, strlen(aTxt), txtX, SkIntToScalar(220), p
aint); |
146 txtX += paint.measureText(aTxt, strlen(aTxt)); | 159 txtX += paint.measureText(aTxt, strlen(aTxt)); |
(...skipping 27 matching lines...) Expand all Loading... |
174 paint.setColor(gPathColor); paint.setAlpha(fade); | 187 paint.setColor(gPathColor); paint.setAlpha(fade); |
175 canvas->drawPath(path, paint); | 188 canvas->drawPath(path, paint); |
176 | 189 |
177 // draw clips in hair line | 190 // draw clips in hair line |
178 paint.setColor(gClipAColor); paint.setAlpha(fade); | 191 paint.setColor(gClipAColor); paint.setAlpha(fade); |
179 canvas->drawPath(clipA, paint); | 192 canvas->drawPath(clipA, paint); |
180 paint.setColor(gClipBColor); paint.setAlpha(fade); | 193 paint.setColor(gClipBColor); paint.setAlpha(fade); |
181 canvas->drawPath(clipB, paint); | 194 canvas->drawPath(clipB, paint); |
182 } | 195 } |
183 | 196 |
| 197 bool fDoAAClip; |
| 198 bool fDoSaveLayer; |
| 199 bool fInvertDraw; |
| 200 |
184 typedef GM INHERITED; | 201 typedef GM INHERITED; |
185 }; | 202 }; |
186 | 203 |
187 ////////////////////////////////////////////////////////////////////////////// | 204 ////////////////////////////////////////////////////////////////////////////// |
188 | 205 |
189 // aliased and anti-aliased w/o a layer | 206 DEF_GM( return SkNEW_ARGS(ComplexClipGM, (false, false, false)); ) |
190 static GM* gFact0(void*) { return new ComplexClipGM(false, false); } | 207 DEF_GM( return SkNEW_ARGS(ComplexClipGM, (false, false, true)); ) |
191 static GM* gFact1(void*) { return new ComplexClipGM(true, false); } | 208 DEF_GM( return SkNEW_ARGS(ComplexClipGM, (false, true, false)); ) |
192 | 209 DEF_GM( return SkNEW_ARGS(ComplexClipGM, (false, true, true)); ) |
193 // aliased and anti-aliased w/ a layer | 210 DEF_GM( return SkNEW_ARGS(ComplexClipGM, (true, false, false)); ) |
194 static GM* gFact2(void*) { return new ComplexClipGM(false, true); } | 211 DEF_GM( return SkNEW_ARGS(ComplexClipGM, (true, false, true)); ) |
195 static GM* gFact3(void*) { return new ComplexClipGM(true, true); } | 212 DEF_GM( return SkNEW_ARGS(ComplexClipGM, (true, true, false)); ) |
196 | 213 DEF_GM( return SkNEW_ARGS(ComplexClipGM, (true, true, true)); ) |
197 static GMRegistry gReg0(gFact0); | |
198 static GMRegistry gReg1(gFact1); | |
199 static GMRegistry gReg2(gFact2); | |
200 static GMRegistry gReg3(gFact3); | |
201 | 214 |
202 } | 215 } |
OLD | NEW |