OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 | 8 |
9 #include "gm.h" | 9 #include "gm.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.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 class ComplexClip2GM : public GM { | 16 class ComplexClip2GM : public GM { |
17 public: | 17 public: |
18 enum Clip { | 18 enum Clip { |
19 kRect_Clip, | 19 kRect_Clip, |
20 kRRect_Clip, | 20 kRRect_Clip, |
21 kPath_Clip | 21 kPath_Clip |
22 }; | 22 }; |
23 | 23 |
24 ComplexClip2GM(Clip clip, bool antiAlias) | 24 ComplexClip2GM(Clip clip, bool antiAlias) |
25 : fClip(clip) | 25 : fClip(clip) |
26 , fAntiAlias(antiAlias) { | 26 , fAntiAlias(antiAlias) { |
| 27 SkScalar xA = 0.65f; |
| 28 SkScalar xF = 50.65f; |
| 29 |
| 30 SkScalar yA = 0.65f; |
| 31 SkScalar yF = 50.65f; |
| 32 |
| 33 fWidth = xF - xA; |
| 34 fHeight = yF - yA; |
| 35 |
| 36 fTotalWidth = kCols * fWidth + SK_Scalar1 * (kCols + 1) * kPadX; |
| 37 fTotalHeight = kRows * fHeight + SK_Scalar1 * (kRows + 1) * kPadY; |
| 38 } |
| 39 |
| 40 protected: |
| 41 void onOnceBeforeDraw() SK_OVERRIDE { |
27 this->setBGColor(SkColorSetRGB(0xDD,0xA0,0xDD)); | 42 this->setBGColor(SkColorSetRGB(0xDD,0xA0,0xDD)); |
28 | 43 |
29 // offset the rects a bit so we get antialiasing even in the rect case | 44 // offset the rects a bit so we get antialiasing even in the rect case |
30 SkScalar xA = 0.65f; | 45 SkScalar xA = 0.65f; |
31 SkScalar xB = 10.65f; | 46 SkScalar xB = 10.65f; |
32 SkScalar xC = 20.65f; | 47 SkScalar xC = 20.65f; |
33 SkScalar xD = 30.65f; | 48 SkScalar xD = 30.65f; |
34 SkScalar xE = 40.65f; | 49 SkScalar xE = 40.65f; |
35 SkScalar xF = 50.65f; | 50 SkScalar xF = 50.65f; |
36 | 51 |
37 SkScalar yA = 0.65f; | 52 SkScalar yA = 0.65f; |
38 SkScalar yB = 10.65f; | 53 SkScalar yB = 10.65f; |
39 SkScalar yC = 20.65f; | 54 SkScalar yC = 20.65f; |
40 SkScalar yD = 30.65f; | 55 SkScalar yD = 30.65f; |
41 SkScalar yE = 40.65f; | 56 SkScalar yE = 40.65f; |
42 SkScalar yF = 50.65f; | 57 SkScalar yF = 50.65f; |
43 | 58 |
44 fWidth = xF - xA; | |
45 fHeight = yF - yA; | |
46 | |
47 fRects[0].set(xB, yB, xE, yE); | 59 fRects[0].set(xB, yB, xE, yE); |
48 fRRects[0].setRectXY(fRects[0], 7, 7); | 60 fRRects[0].setRectXY(fRects[0], 7, 7); |
49 fPaths[0].addRoundRect(fRects[0], 5, 5); | 61 fPaths[0].addRoundRect(fRects[0], 5, 5); |
50 fRectColors[0] = SK_ColorRED; | 62 fRectColors[0] = SK_ColorRED; |
51 | 63 |
52 fRects[1].set(xA, yA, xD, yD); | 64 fRects[1].set(xA, yA, xD, yD); |
53 fRRects[1].setRectXY(fRects[1], 7, 7); | 65 fRRects[1].setRectXY(fRects[1], 7, 7); |
54 fPaths[1].addRoundRect(fRects[1], 5, 5); | 66 fPaths[1].addRoundRect(fRects[1], 5, 5); |
55 fRectColors[1] = SK_ColorGREEN; | 67 fRectColors[1] = SK_ColorGREEN; |
56 | 68 |
57 fRects[2].set(xC, yA, xF, yD); | 69 fRects[2].set(xC, yA, xF, yD); |
58 fRRects[2].setRectXY(fRects[2], 7, 7); | 70 fRRects[2].setRectXY(fRects[2], 7, 7); |
59 fPaths[2].addRoundRect(fRects[2], 5, 5); | 71 fPaths[2].addRoundRect(fRects[2], 5, 5); |
60 fRectColors[2] = SK_ColorBLUE; | 72 fRectColors[2] = SK_ColorBLUE; |
61 | 73 |
62 fRects[3].set(xA, yC, xD, yF); | 74 fRects[3].set(xA, yC, xD, yF); |
63 fRRects[3].setRectXY(fRects[3], 7, 7); | 75 fRRects[3].setRectXY(fRects[3], 7, 7); |
64 fPaths[3].addRoundRect(fRects[3], 5, 5); | 76 fPaths[3].addRoundRect(fRects[3], 5, 5); |
65 fRectColors[3] = SK_ColorYELLOW; | 77 fRectColors[3] = SK_ColorYELLOW; |
66 | 78 |
67 fRects[4].set(xC, yC, xF, yF); | 79 fRects[4].set(xC, yC, xF, yF); |
68 fRRects[4].setRectXY(fRects[4], 7, 7); | 80 fRRects[4].setRectXY(fRects[4], 7, 7); |
69 fPaths[4].addRoundRect(fRects[4], 5, 5); | 81 fPaths[4].addRoundRect(fRects[4], 5, 5); |
70 fRectColors[4] = SK_ColorCYAN; | 82 fRectColors[4] = SK_ColorCYAN; |
71 | 83 |
72 fTotalWidth = kCols * fWidth + SK_Scalar1 * (kCols + 1) * kPadX; | |
73 fTotalHeight = kRows * fHeight + SK_Scalar1 * (kRows + 1) * kPadY; | |
74 | |
75 SkRegion::Op ops[] = { | 84 SkRegion::Op ops[] = { |
76 SkRegion::kDifference_Op, | 85 SkRegion::kDifference_Op, |
77 SkRegion::kIntersect_Op, | 86 SkRegion::kIntersect_Op, |
78 SkRegion::kUnion_Op, | 87 SkRegion::kUnion_Op, |
79 SkRegion::kXOR_Op, | 88 SkRegion::kXOR_Op, |
80 SkRegion::kReverseDifference_Op, | 89 SkRegion::kReverseDifference_Op, |
81 SkRegion::kReplace_Op, | 90 SkRegion::kReplace_Op, |
82 }; | 91 }; |
83 | 92 |
84 SkRandom r; | 93 SkRandom r; |
85 for (int i = 0; i < kRows; ++i) { | 94 for (int i = 0; i < kRows; ++i) { |
86 for (int j = 0; j < kCols; ++j) { | 95 for (int j = 0; j < kCols; ++j) { |
87 for (int k = 0; k < 5; ++k) { | 96 for (int k = 0; k < 5; ++k) { |
88 fOps[j*kRows+i][k] = ops[r.nextU() % SK_ARRAY_COUNT(ops)]; | 97 fOps[j*kRows+i][k] = ops[r.nextU() % SK_ARRAY_COUNT(ops)]; |
89 } | 98 } |
90 } | 99 } |
91 } | 100 } |
92 } | 101 } |
93 | 102 |
94 protected: | |
95 | |
96 static const int kRows = 5; | 103 static const int kRows = 5; |
97 static const int kCols = 5; | 104 static const int kCols = 5; |
98 static const int kPadX = 20; | 105 static const int kPadX = 20; |
99 static const int kPadY = 20; | 106 static const int kPadY = 20; |
100 | 107 |
101 static const char* ClipStr(Clip clip) { | 108 static const char* ClipStr(Clip clip) { |
102 switch (clip) { | 109 switch (clip) { |
103 case kRect_Clip: | 110 case kRect_Clip: |
104 return "rect"; | 111 return "rect"; |
105 case kRRect_Clip: | 112 case kRRect_Clip: |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRect_Clip, false); ) | 213 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRect_Clip, false); ) |
207 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRRect_Clip, false); ) | 214 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRRect_Clip, false); ) |
208 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kPath_Clip, false); ) | 215 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kPath_Clip, false); ) |
209 | 216 |
210 // aa | 217 // aa |
211 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRect_Clip, true); ) | 218 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRect_Clip, true); ) |
212 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRRect_Clip, true); ) | 219 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRRect_Clip, true); ) |
213 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kPath_Clip, true); ) | 220 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kPath_Clip, true); ) |
214 | 221 |
215 } | 222 } |
OLD | NEW |