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

Side by Side Diff: tests/DrawPathTest.cpp

Issue 790733003: remove (dumb) canvas::NewRaster, and rename surface::NewRasterPMColor to N32Premul (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase after chrome patches have landed 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 | « tests/DrawBitmapRectTest.cpp ('k') | tests/PathTest.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 2012 Google Inc. 2 * Copyright 2012 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkDashPathEffect.h" 10 #include "SkDashPathEffect.h"
11 #include "SkSurface.h" 11 #include "SkSurface.h"
12 #include "Test.h" 12 #include "Test.h"
13 13
14 // test that we can draw an aa-rect at coordinates > 32K (bigger than fixedpoint ) 14 // test that we can draw an aa-rect at coordinates > 32K (bigger than fixedpoint )
15 static void test_big_aa_rect(skiatest::Reporter* reporter) { 15 static void test_big_aa_rect(skiatest::Reporter* reporter) {
16 SkBitmap output; 16 SkBitmap output;
17 SkPMColor pixel[1]; 17 SkPMColor pixel[1];
18 output.installPixels(SkImageInfo::MakeN32Premul(1, 1), pixel, 4); 18 output.installPixels(SkImageInfo::MakeN32Premul(1, 1), pixel, 4);
19 19
20 SkSurface* surf = SkSurface::NewRasterPMColor(300, 33300); 20 SkSurface* surf = SkSurface::NewRasterN32Premul(300, 33300);
21 SkCanvas* canvas = surf->getCanvas(); 21 SkCanvas* canvas = surf->getCanvas();
22 22
23 SkRect r = { 0, 33000, 300, 33300 }; 23 SkRect r = { 0, 33000, 300, 33300 };
24 int x = SkScalarRoundToInt(r.left()); 24 int x = SkScalarRoundToInt(r.left());
25 int y = SkScalarRoundToInt(r.top()); 25 int y = SkScalarRoundToInt(r.top());
26 26
27 // check that the pixel in question starts as transparent (by the surface) 27 // check that the pixel in question starts as transparent (by the surface)
28 if (canvas->readPixels(&output, x, y)) { 28 if (canvas->readPixels(&output, x, y)) {
29 REPORTER_ASSERT(reporter, 0 == pixel[0]); 29 REPORTER_ASSERT(reporter, 0 == pixel[0]);
30 } else { 30 } else {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 */ 87 */
88 uint32_t data[] = { 88 uint32_t data[] = {
89 0x419727af, 0x43011f0c, 0x41972663, 0x43011f27, 89 0x419727af, 0x43011f0c, 0x41972663, 0x43011f27,
90 0x419728fc, 0x43011ed4, 0x4194064b, 0x43012197 90 0x419728fc, 0x43011ed4, 0x4194064b, 0x43012197
91 }; 91 };
92 92
93 SkPath path; 93 SkPath path;
94 moveToH(&path, &data[0]); 94 moveToH(&path, &data[0]);
95 cubicToH(&path, &data[2]); 95 cubicToH(&path, &data[2]);
96 96
97 SkAutoTUnref<SkCanvas> canvas(SkCanvas::NewRasterN32(640, 480)); 97 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480));
98 98
99 SkPaint paint; 99 SkPaint paint;
100 paint.setAntiAlias(true); 100 paint.setAntiAlias(true);
101 canvas->drawPath(path, paint); 101 surface->getCanvas()->drawPath(path, paint);
102 } 102 }
103 103
104 // This used to assert in debug builds (and crash writing bad memory in release) 104 // This used to assert in debug builds (and crash writing bad memory in release)
105 // because we overflowed an intermediate value (B coefficient) setting up our 105 // because we overflowed an intermediate value (B coefficient) setting up our
106 // stepper for the quadratic. Now we bias that value by 1/2 so we don't overflow 106 // stepper for the quadratic. Now we bias that value by 1/2 so we don't overflow
107 static void test_crbug_140803() { 107 static void test_crbug_140803() {
108 SkBitmap bm; 108 SkBitmap bm;
109 bm.allocN32Pixels(2700, 30*1024); 109 bm.allocN32Pixels(2700, 30*1024);
110 SkCanvas canvas(bm); 110 SkCanvas canvas(bm);
111 111
112 SkPath path; 112 SkPath path;
113 path.moveTo(2762, 20); 113 path.moveTo(2762, 20);
114 path.quadTo(11, 21702, 10, 21706); 114 path.quadTo(11, 21702, 10, 21706);
115 SkPaint paint; 115 SkPaint paint;
116 paint.setAntiAlias(true); 116 paint.setAntiAlias(true);
117 canvas.drawPath(path, paint); 117 canvas.drawPath(path, paint);
118 } 118 }
119 119
120 // Need to exercise drawing an inverse-path whose bounds intersect the clip, 120 // Need to exercise drawing an inverse-path whose bounds intersect the clip,
121 // but whose edges do not (since its a quad which draws only in the bottom half 121 // but whose edges do not (since its a quad which draws only in the bottom half
122 // of its bounds). 122 // of its bounds).
123 // In the debug build, we used to assert in this case, until it was fixed. 123 // In the debug build, we used to assert in this case, until it was fixed.
124 // 124 //
125 static void test_inversepathwithclip() { 125 static void test_inversepathwithclip() {
126 SkPath path; 126 SkPath path;
127 127
128 path.moveTo(0, SkIntToScalar(20)); 128 path.moveTo(0, 20);
129 path.quadTo(SkIntToScalar(10), SkIntToScalar(10), 129 path.quadTo(10, 10, 20, 20);
130 SkIntToScalar(20), SkIntToScalar(20));
131 path.toggleInverseFillType(); 130 path.toggleInverseFillType();
132 131
133 SkPaint paint; 132 SkPaint paint;
134 133
135 SkAutoTUnref<SkCanvas> canvas(SkCanvas::NewRasterN32(640, 480)); 134 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480));
136 canvas.get()->save(); 135 SkCanvas* canvas = surface->getCanvas();
137 canvas.get()->clipRect(SkRect::MakeWH(SkIntToScalar(19), SkIntToScalar(11))) ; 136 canvas->save();
137 canvas->clipRect(SkRect::MakeWH(19, 11));
138 138
139 paint.setAntiAlias(false); 139 paint.setAntiAlias(false);
140 canvas.get()->drawPath(path, paint); 140 canvas->drawPath(path, paint);
141 paint.setAntiAlias(true); 141 paint.setAntiAlias(true);
142 canvas.get()->drawPath(path, paint); 142 canvas->drawPath(path, paint);
143 143
144 canvas.get()->restore(); 144 canvas->restore();
145 145
146 // Now do the test again, with the path flipped, so we only draw in the 146 // Now do the test again, with the path flipped, so we only draw in the
147 // top half of our bounds, and have the clip intersect our bounds at the 147 // top half of our bounds, and have the clip intersect our bounds at the
148 // bottom. 148 // bottom.
149 path.reset(); // preserves our filltype 149 path.reset(); // preserves our filltype
150 path.moveTo(0, SkIntToScalar(10)); 150 path.moveTo(0, 10);
151 path.quadTo(SkIntToScalar(10), SkIntToScalar(20), 151 path.quadTo(10, 20, 20, 10);
152 SkIntToScalar(20), SkIntToScalar(10)); 152 canvas->clipRect(SkRect::MakeXYWH(0, 19, 19, 11));
153 canvas.get()->clipRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(19),
154 SkIntToScalar(19), SkIntToScalar(11) ));
155 153
156 paint.setAntiAlias(false); 154 paint.setAntiAlias(false);
157 canvas.get()->drawPath(path, paint); 155 canvas->drawPath(path, paint);
158 paint.setAntiAlias(true); 156 paint.setAntiAlias(true);
159 canvas.get()->drawPath(path, paint); 157 canvas->drawPath(path, paint);
160 } 158 }
161 159
162 static void test_bug533() { 160 static void test_bug533() {
163 /* 161 /*
164 http://code.google.com/p/skia/issues/detail?id=533 162 http://code.google.com/p/skia/issues/detail?id=533
165 This particular test/bug only applies to the float case, where the 163 This particular test/bug only applies to the float case, where the
166 coordinates are very large. 164 coordinates are very large.
167 */ 165 */
168 SkPath path; 166 SkPath path;
169 path.moveTo(64, 3); 167 path.moveTo(64, 3);
170 path.quadTo(-329936, -100000000, 1153, 330003); 168 path.quadTo(-329936, -100000000, 1153, 330003);
171 169
172 SkPaint paint; 170 SkPaint paint;
173 paint.setAntiAlias(true); 171 paint.setAntiAlias(true);
174 172
175 SkAutoTUnref<SkCanvas> canvas(SkCanvas::NewRasterN32(640, 480)); 173 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480));
176 canvas.get()->drawPath(path, paint); 174 surface->getCanvas()->drawPath(path, paint);
177 } 175 }
178 176
179 static void test_crbug_140642() { 177 static void test_crbug_140642() {
180 /* 178 /*
181 * We used to see this construct, and due to rounding as we accumulated 179 * We used to see this construct, and due to rounding as we accumulated
182 * our length, the loop where we apply the phase would run off the end of 180 * our length, the loop where we apply the phase would run off the end of
183 * the array, since it relied on just -= each interval value, which did not 181 * the array, since it relied on just -= each interval value, which did not
184 * behave as "expected". Now the code explicitly checks for walking off the 182 * behave as "expected". Now the code explicitly checks for walking off the
185 * end of that array. 183 * end of that array.
186 184
(...skipping 20 matching lines...) Expand all
207 } 205 }
208 206
209 static void test_bigcubic() { 207 static void test_bigcubic() {
210 SkPath path; 208 SkPath path;
211 path.moveTo(64, 3); 209 path.moveTo(64, 3);
212 path.cubicTo(-329936, -100000000, -329936, 100000000, 1153, 330003); 210 path.cubicTo(-329936, -100000000, -329936, 100000000, 1153, 330003);
213 211
214 SkPaint paint; 212 SkPaint paint;
215 paint.setAntiAlias(true); 213 paint.setAntiAlias(true);
216 214
217 SkAutoTUnref<SkCanvas> canvas(SkCanvas::NewRasterN32(640, 480)); 215 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480));
218 canvas.get()->drawPath(path, paint); 216 surface->getCanvas()->drawPath(path, paint);
219 } 217 }
220 218
221 // we used to assert if the bounds of the device (clip) was larger than 32K 219 // we used to assert if the bounds of the device (clip) was larger than 32K
222 // even when the path itself was smaller. We just draw and hope in the debug 220 // even when the path itself was smaller. We just draw and hope in the debug
223 // version to not assert. 221 // version to not assert.
224 static void test_giantaa() { 222 static void test_giantaa() {
225 const int W = 400; 223 const int W = 400;
226 const int H = 400; 224 const int H = 400;
227 SkAutoTUnref<SkCanvas> canvas(SkCanvas::NewRasterN32(33000, 10)); 225 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(33000, 10));
228 226
229 SkPaint paint; 227 SkPaint paint;
230 paint.setAntiAlias(true); 228 paint.setAntiAlias(true);
231 SkPath path; 229 SkPath path;
232 path.addOval(SkRect::MakeXYWH(-10, -10, 20 + W, 20 + H)); 230 path.addOval(SkRect::MakeXYWH(-10, -10, 20 + W, 20 + H));
233 canvas.get()->drawPath(path, paint); 231 surface->getCanvas()->drawPath(path, paint);
234 } 232 }
235 233
236 // Extremely large path_length/dash_length ratios may cause infinite looping 234 // Extremely large path_length/dash_length ratios may cause infinite looping
237 // in SkDashPathEffect::filterPath() due to single precision rounding. 235 // in SkDashPathEffect::filterPath() due to single precision rounding.
238 // The test is quite expensive, but it should get much faster after the fix 236 // The test is quite expensive, but it should get much faster after the fix
239 // for http://crbug.com/165432 goes in. 237 // for http://crbug.com/165432 goes in.
240 static void test_infinite_dash(skiatest::Reporter* reporter) { 238 static void test_infinite_dash(skiatest::Reporter* reporter) {
241 SkPath path; 239 SkPath path;
242 path.moveTo(0, 0); 240 path.moveTo(0, 0);
243 path.lineTo(5000000, 0); 241 path.lineTo(5000000, 0);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 test_crbug_124652(); 280 test_crbug_124652();
283 test_crbug_140642(); 281 test_crbug_140642();
284 test_crbug_140803(); 282 test_crbug_140803();
285 test_inversepathwithclip(); 283 test_inversepathwithclip();
286 // why? 284 // why?
287 if (false) test_crbug131181(); 285 if (false) test_crbug131181();
288 test_infinite_dash(reporter); 286 test_infinite_dash(reporter);
289 test_crbug_165432(reporter); 287 test_crbug_165432(reporter);
290 test_big_aa_rect(reporter); 288 test_big_aa_rect(reporter);
291 } 289 }
OLDNEW
« no previous file with comments | « tests/DrawBitmapRectTest.cpp ('k') | tests/PathTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698