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 "SkRandom.h" | 9 #include "SkRandom.h" |
10 #include "SkRRect.h" | 10 #include "SkRRect.h" |
11 | 11 |
12 namespace skiagm { | 12 namespace skiagm { |
13 | 13 |
14 // Test out various combinations of nested rects, ovals and rrects. | 14 // Test out various combinations of nested rects, ovals and rrects. |
15 class NestedGM : public GM { | 15 class NestedGM : public GM { |
16 public: | 16 public: |
17 NestedGM(bool doAA) : fDoAA(doAA) { | 17 NestedGM(bool doAA, bool flipped) : fDoAA(doAA), fFlipped(flipped) { |
18 this->setBGColor(0xFFDDDDDD); | 18 this->setBGColor(0xFFDDDDDD); |
19 } | 19 } |
20 | 20 |
21 protected: | 21 protected: |
22 | 22 |
23 SkString onShortName() override { | 23 SkString onShortName() override { |
24 SkString name("nested"); | 24 SkString name("nested"); |
| 25 if (fFlipped) { |
| 26 name.append("_flipY"); |
| 27 } |
25 if (fDoAA) { | 28 if (fDoAA) { |
26 name.append("_aa"); | 29 name.append("_aa"); |
27 } else { | 30 } else { |
28 name.append("_bw"); | 31 name.append("_bw"); |
29 } | 32 } |
30 return name; | 33 return name; |
31 } | 34 } |
32 | 35 |
33 SkISize onISize() override { | 36 SkISize onISize() override { |
34 return SkISize::Make(kImageWidth, kImageHeight); | 37 return SkISize::Make(kImageWidth, kImageHeight); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 for (int x = 0; x < kImageWidth; x += 10) { | 83 for (int x = 0; x < kImageWidth; x += 10) { |
81 SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), | 84 SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), |
82 SkIntToScalar(y), | 85 SkIntToScalar(y), |
83 10, 10); | 86 10, 10); |
84 SkPaint p; | 87 SkPaint p; |
85 p.setColor(rand.nextU() | 0xFF000000); | 88 p.setColor(rand.nextU() | 0xFF000000); |
86 canvas->drawRect(r, p); | 89 canvas->drawRect(r, p); |
87 } | 90 } |
88 } | 91 } |
89 | 92 |
90 canvas->translate(2, 2); | 93 SkScalar xOff = 2, yOff = 2; |
91 for (int outerShape = 0; outerShape < kShapeCount; ++outerShape) { | 94 for (int outerShape = 0; outerShape < kShapeCount; ++outerShape) { |
92 canvas->save(); | |
93 for (int innerShape = 0; innerShape < kShapeCount; ++innerShape) { | 95 for (int innerShape = 0; innerShape < kShapeCount; ++innerShape) { |
94 for (size_t innerRect = 0; innerRect < SK_ARRAY_COUNT(innerRects
); ++innerRect) { | 96 for (size_t innerRect = 0; innerRect < SK_ARRAY_COUNT(innerRects
); ++innerRect) { |
95 SkPath path; | 97 SkPath path; |
96 | 98 |
97 AddShape(&path, outerRect, (Shapes) outerShape, SkPath::kCW_
Direction); | 99 AddShape(&path, outerRect, (Shapes) outerShape, SkPath::kCW_
Direction); |
98 AddShape(&path, innerRects[innerRect], (Shapes) innerShape, | 100 AddShape(&path, innerRects[innerRect], (Shapes) innerShape, |
99 SkPath::kCCW_Direction); | 101 SkPath::kCCW_Direction); |
100 | 102 |
| 103 canvas->save(); |
| 104 if (fFlipped) { |
| 105 canvas->scale(1.0f, -1.0f); |
| 106 canvas->translate(xOff, -yOff - 40.0f); |
| 107 } else { |
| 108 canvas->translate(xOff, yOff); |
| 109 } |
| 110 |
101 canvas->drawPath(path, shapePaint); | 111 canvas->drawPath(path, shapePaint); |
102 canvas->translate(45, 0); | 112 canvas->restore(); |
| 113 |
| 114 xOff += 45; |
103 } | 115 } |
104 } | 116 } |
105 canvas->restore(); | 117 |
106 canvas->translate(0, 45); | 118 xOff = 2; |
| 119 yOff += 45; |
107 } | 120 } |
108 | 121 |
109 } | 122 } |
110 | 123 |
111 private: | 124 private: |
112 static const int kImageWidth = 269; | 125 static const int kImageWidth = 269; |
113 static const int kImageHeight = 134; | 126 static const int kImageHeight = 134; |
114 | 127 |
115 bool fDoAA; | 128 bool fDoAA; |
| 129 bool fFlipped; |
116 | 130 |
117 typedef GM INHERITED; | 131 typedef GM INHERITED; |
118 }; | 132 }; |
119 | 133 |
120 /////////////////////////////////////////////////////////////////////////////// | 134 /////////////////////////////////////////////////////////////////////////////// |
121 | 135 |
122 DEF_GM( return new NestedGM(true); ) | 136 DEF_GM( return new NestedGM(/* doAA = */ true, /* flipped = */ false); ) |
123 DEF_GM( return new NestedGM(false); ) | 137 DEF_GM( return new NestedGM(/* doAA = */ false, /* flipped = */ false); ) |
124 | 138 DEF_GM( return new NestedGM(/* doAA = */ true, /* flipped = */ true); ) |
| 139 DEF_GM( return new NestedGM(/* doAA = */ false, /* flipped = */ true); ) |
125 | 140 |
126 } | 141 } |
OLD | NEW |