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" |
11 #include "SkRandom.h" | 11 #include "SkRandom.h" |
12 #include "SkScalar.h" | 12 #include "SkScalar.h" |
13 #include "SkTArray.h" | 13 #include "SkTArray.h" |
14 | 14 |
15 namespace skiagm { | 15 namespace skiagm { |
16 | 16 |
17 // This GM tests a grab-bag of convex and concave polygons. They are triangles, | 17 // This GM tests a grab-bag of convex and concave polygons. They are triangles, |
18 // trapezoid, diamond, polygons with lots of edges, several concave polygons... | 18 // trapezoid, diamond, polygons with lots of edges, several concave polygons... |
19 // But rectangles are excluded. | 19 // But rectangles are excluded. |
20 class PolygonsGM: public GM { | 20 class PolygonsGM: public GM { |
21 public: | 21 public: |
22 PolygonsGM() {} | 22 PolygonsGM() {} |
23 | 23 |
24 protected: | 24 protected: |
25 virtual uint32_t onGetFlags() const SK_OVERRIDE { | 25 uint32_t onGetFlags() const SK_OVERRIDE { |
26 return kSkipTiled_Flag; | 26 return kSkipTiled_Flag; |
27 } | 27 } |
28 | 28 |
29 virtual SkString onShortName() SK_OVERRIDE { | 29 SkString onShortName() SK_OVERRIDE { |
30 return SkString("polygons"); | 30 return SkString("polygons"); |
31 } | 31 } |
32 | 32 |
33 virtual SkISize onISize() SK_OVERRIDE { | 33 SkISize onISize() SK_OVERRIDE { |
34 int width = kNumPolygons * kCellSize + 40; | 34 int width = kNumPolygons * kCellSize + 40; |
35 int height = (kNumJoins * kNumStrokeWidths + kNumExtraStyles) * kCellSiz
e + 40; | 35 int height = (kNumJoins * kNumStrokeWidths + kNumExtraStyles) * kCellSiz
e + 40; |
36 return SkISize::Make(width, height); | 36 return SkISize::Make(width, height); |
37 } | 37 } |
38 | 38 |
39 // Construct all polygons | 39 // Construct all polygons |
40 virtual void onOnceBeforeDraw() SK_OVERRIDE { | 40 void onOnceBeforeDraw() SK_OVERRIDE { |
41 SkPoint p0[] = {{0, 0}, {60, 0}, {90, 40}}; // triangle | 41 SkPoint p0[] = {{0, 0}, {60, 0}, {90, 40}}; // triangle |
42 SkPoint p1[] = {{0, 0}, {0, 40}, {60, 40}, {40, 0}}; // trapezoid | 42 SkPoint p1[] = {{0, 0}, {0, 40}, {60, 40}, {40, 0}}; // trapezoid |
43 SkPoint p2[] = {{0, 0}, {40, 40}, {80, 40}, {40, 0}}; // diamond | 43 SkPoint p2[] = {{0, 0}, {40, 40}, {80, 40}, {40, 0}}; // diamond |
44 SkPoint p3[] = {{10, 0}, {50, 0}, {60, 10}, {60, 30}, {50, 40}, | 44 SkPoint p3[] = {{10, 0}, {50, 0}, {60, 10}, {60, 30}, {50, 40}, |
45 {10, 40}, {0, 30}, {0, 10}}; // octagon | 45 {10, 40}, {0, 30}, {0, 10}}; // octagon |
46 SkPoint p4[32]; // circle-like polygons with 32-edges. | 46 SkPoint p4[32]; // circle-like polygons with 32-edges. |
47 SkPoint p5[] = {{0, 0}, {20, 20}, {0, 40}, {60, 20}}; // concave polygo
n with 4 edges | 47 SkPoint p5[] = {{0, 0}, {20, 20}, {0, 40}, {60, 20}}; // concave polygo
n with 4 edges |
48 SkPoint p6[] = {{0, 40}, {0, 30}, {15, 30}, {15, 20}, {30, 20}, | 48 SkPoint p6[] = {{0, 40}, {0, 30}, {15, 30}, {15, 20}, {30, 20}, |
49 {30, 10}, {45, 10}, {45, 0}, {60, 0}, {60, 40}}; // sta
irs-like polygon | 49 {30, 10}, {45, 10}, {45, 0}, {60, 0}, {60, 40}}; // sta
irs-like polygon |
50 SkPoint p7[] = {{0, 20}, {20, 20}, {30, 0}, {40, 20}, {60, 20}, | 50 SkPoint p7[] = {{0, 20}, {20, 20}, {30, 0}, {40, 20}, {60, 20}, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 90 |
91 static void SetColorAndAlpha(SkPaint* paint, SkRandom* rand) { | 91 static void SetColorAndAlpha(SkPaint* paint, SkRandom* rand) { |
92 SkColor color = rand->nextU(); | 92 SkColor color = rand->nextU(); |
93 color |= 0xff000000; | 93 color |= 0xff000000; |
94 paint->setColor(color); | 94 paint->setColor(color); |
95 if (40 == paint->getStrokeWidth()) { | 95 if (40 == paint->getStrokeWidth()) { |
96 paint->setAlpha(0xA0); | 96 paint->setAlpha(0xA0); |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 100 void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
101 // Stroke widths are: | 101 // Stroke widths are: |
102 // 0(may use hairline rendering), 10(common case for stroke-style) | 102 // 0(may use hairline rendering), 10(common case for stroke-style) |
103 // 40(>= geometry width/height, make the contour filled in fact) | 103 // 40(>= geometry width/height, make the contour filled in fact) |
104 static const int kStrokeWidths[] = {0, 10, 40}; | 104 static const int kStrokeWidths[] = {0, 10, 40}; |
105 SkASSERT(kNumStrokeWidths == SK_ARRAY_COUNT(kStrokeWidths)); | 105 SkASSERT(kNumStrokeWidths == SK_ARRAY_COUNT(kStrokeWidths)); |
106 | 106 |
107 static const SkPaint::Join kJoins[] = { | 107 static const SkPaint::Join kJoins[] = { |
108 SkPaint::kMiter_Join, SkPaint::kRound_Join, SkPaint::kBevel_Join | 108 SkPaint::kMiter_Join, SkPaint::kRound_Join, SkPaint::kBevel_Join |
109 }; | 109 }; |
110 SkASSERT(kNumJoins == SK_ARRAY_COUNT(kJoins)); | 110 SkASSERT(kNumJoins == SK_ARRAY_COUNT(kJoins)); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 163 |
164 SkTArray<SkPath> fPolygons; | 164 SkTArray<SkPath> fPolygons; |
165 typedef GM INHERITED; | 165 typedef GM INHERITED; |
166 }; | 166 }; |
167 | 167 |
168 ////////////////////////////////////////////////////////////////////////////// | 168 ////////////////////////////////////////////////////////////////////////////// |
169 | 169 |
170 DEF_GM(return new PolygonsGM;) | 170 DEF_GM(return new PolygonsGM;) |
171 | 171 |
172 } | 172 } |
OLD | NEW |