Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: gm/polygons.cpp

Issue 805963002: There can be only one (SkRandom)! (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gm/points.cpp ('k') | gm/quadpaths.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 } 81 }
82 } 82 }
83 83
84 // Set the location for the current test on the canvas 84 // Set the location for the current test on the canvas
85 static void SetLocation(SkCanvas* canvas, int counter, int lineNum) { 85 static void SetLocation(SkCanvas* canvas, int counter, int lineNum) {
86 SkScalar x = SK_Scalar1 * kCellSize * (counter % lineNum) + 30 + SK_Scal ar1 / 4; 86 SkScalar x = SK_Scalar1 * kCellSize * (counter % lineNum) + 30 + SK_Scal ar1 / 4;
87 SkScalar y = SK_Scalar1 * kCellSize * (counter / lineNum) + 30 + 3 * SK_ Scalar1 / 4; 87 SkScalar y = SK_Scalar1 * kCellSize * (counter / lineNum) + 30 + 3 * SK_ Scalar1 / 4;
88 canvas->translate(x, y); 88 canvas->translate(x, y);
89 } 89 }
90 90
91 static void SetColorAndAlpha(SkPaint* paint, SkLCGRandom* 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 virtual 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));
111 111
112 int counter = 0; 112 int counter = 0;
113 SkPaint paint; 113 SkPaint paint;
114 paint.setAntiAlias(true); 114 paint.setAntiAlias(true);
115 115
116 SkLCGRandom rand; 116 SkRandom rand;
117 // For stroke style painter 117 // For stroke style painter
118 paint.setStyle(SkPaint::kStroke_Style); 118 paint.setStyle(SkPaint::kStroke_Style);
119 for (int join = 0; join < kNumJoins; ++join) { 119 for (int join = 0; join < kNumJoins; ++join) {
120 for (int width = 0; width < kNumStrokeWidths; ++width) { 120 for (int width = 0; width < kNumStrokeWidths; ++width) {
121 for (int i = 0; i < fPolygons.count(); ++i) { 121 for (int i = 0; i < fPolygons.count(); ++i) {
122 canvas->save(); 122 canvas->save();
123 SetLocation(canvas, counter, fPolygons.count()); 123 SetLocation(canvas, counter, fPolygons.count());
124 124
125 SetColorAndAlpha(&paint, &rand); 125 SetColorAndAlpha(&paint, &rand);
126 paint.setStrokeJoin(kJoins[join]); 126 paint.setStrokeJoin(kJoins[join]);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « gm/points.cpp ('k') | gm/quadpaths.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698