OLD | NEW |
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::NewRasterN32Premul(300, 33300); | 20 SkSurface* surf = SkSurface::NewRasterPMColor(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 Loading... |
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<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480)); | 97 SkAutoTUnref<SkCanvas> canvas(SkCanvas::NewRasterN32(640, 480)); |
98 | 98 |
99 SkPaint paint; | 99 SkPaint paint; |
100 paint.setAntiAlias(true); | 100 paint.setAntiAlias(true); |
101 surface->getCanvas()->drawPath(path, paint); | 101 canvas->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, 20); | 128 path.moveTo(0, SkIntToScalar(20)); |
129 path.quadTo(10, 10, 20, 20); | 129 path.quadTo(SkIntToScalar(10), SkIntToScalar(10), |
| 130 SkIntToScalar(20), SkIntToScalar(20)); |
130 path.toggleInverseFillType(); | 131 path.toggleInverseFillType(); |
131 | 132 |
132 SkPaint paint; | 133 SkPaint paint; |
133 | 134 |
134 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480)); | 135 SkAutoTUnref<SkCanvas> canvas(SkCanvas::NewRasterN32(640, 480)); |
135 SkCanvas* canvas = surface->getCanvas(); | 136 canvas.get()->save(); |
136 canvas->save(); | 137 canvas.get()->clipRect(SkRect::MakeWH(SkIntToScalar(19), SkIntToScalar(11)))
; |
137 canvas->clipRect(SkRect::MakeWH(19, 11)); | |
138 | 138 |
139 paint.setAntiAlias(false); | 139 paint.setAntiAlias(false); |
140 canvas->drawPath(path, paint); | 140 canvas.get()->drawPath(path, paint); |
141 paint.setAntiAlias(true); | 141 paint.setAntiAlias(true); |
142 canvas->drawPath(path, paint); | 142 canvas.get()->drawPath(path, paint); |
143 | 143 |
144 canvas->restore(); | 144 canvas.get()->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, 10); | 150 path.moveTo(0, SkIntToScalar(10)); |
151 path.quadTo(10, 20, 20, 10); | 151 path.quadTo(SkIntToScalar(10), SkIntToScalar(20), |
152 canvas->clipRect(SkRect::MakeXYWH(0, 19, 19, 11)); | 152 SkIntToScalar(20), SkIntToScalar(10)); |
| 153 canvas.get()->clipRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(19), |
| 154 SkIntToScalar(19), SkIntToScalar(11)
)); |
153 | 155 |
154 paint.setAntiAlias(false); | 156 paint.setAntiAlias(false); |
155 canvas->drawPath(path, paint); | 157 canvas.get()->drawPath(path, paint); |
156 paint.setAntiAlias(true); | 158 paint.setAntiAlias(true); |
157 canvas->drawPath(path, paint); | 159 canvas.get()->drawPath(path, paint); |
158 } | 160 } |
159 | 161 |
160 static void test_bug533() { | 162 static void test_bug533() { |
161 /* | 163 /* |
162 http://code.google.com/p/skia/issues/detail?id=533 | 164 http://code.google.com/p/skia/issues/detail?id=533 |
163 This particular test/bug only applies to the float case, where the | 165 This particular test/bug only applies to the float case, where the |
164 coordinates are very large. | 166 coordinates are very large. |
165 */ | 167 */ |
166 SkPath path; | 168 SkPath path; |
167 path.moveTo(64, 3); | 169 path.moveTo(64, 3); |
168 path.quadTo(-329936, -100000000, 1153, 330003); | 170 path.quadTo(-329936, -100000000, 1153, 330003); |
169 | 171 |
170 SkPaint paint; | 172 SkPaint paint; |
171 paint.setAntiAlias(true); | 173 paint.setAntiAlias(true); |
172 | 174 |
173 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480)); | 175 SkAutoTUnref<SkCanvas> canvas(SkCanvas::NewRasterN32(640, 480)); |
174 surface->getCanvas()->drawPath(path, paint); | 176 canvas.get()->drawPath(path, paint); |
175 } | 177 } |
176 | 178 |
177 static void test_crbug_140642() { | 179 static void test_crbug_140642() { |
178 /* | 180 /* |
179 * We used to see this construct, and due to rounding as we accumulated | 181 * We used to see this construct, and due to rounding as we accumulated |
180 * our length, the loop where we apply the phase would run off the end of | 182 * our length, the loop where we apply the phase would run off the end of |
181 * the array, since it relied on just -= each interval value, which did not | 183 * the array, since it relied on just -= each interval value, which did not |
182 * behave as "expected". Now the code explicitly checks for walking off the | 184 * behave as "expected". Now the code explicitly checks for walking off the |
183 * end of that array. | 185 * end of that array. |
184 | 186 |
(...skipping 20 matching lines...) Expand all Loading... |
205 } | 207 } |
206 | 208 |
207 static void test_bigcubic() { | 209 static void test_bigcubic() { |
208 SkPath path; | 210 SkPath path; |
209 path.moveTo(64, 3); | 211 path.moveTo(64, 3); |
210 path.cubicTo(-329936, -100000000, -329936, 100000000, 1153, 330003); | 212 path.cubicTo(-329936, -100000000, -329936, 100000000, 1153, 330003); |
211 | 213 |
212 SkPaint paint; | 214 SkPaint paint; |
213 paint.setAntiAlias(true); | 215 paint.setAntiAlias(true); |
214 | 216 |
215 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480)); | 217 SkAutoTUnref<SkCanvas> canvas(SkCanvas::NewRasterN32(640, 480)); |
216 surface->getCanvas()->drawPath(path, paint); | 218 canvas.get()->drawPath(path, paint); |
217 } | 219 } |
218 | 220 |
219 // we used to assert if the bounds of the device (clip) was larger than 32K | 221 // we used to assert if the bounds of the device (clip) was larger than 32K |
220 // even when the path itself was smaller. We just draw and hope in the debug | 222 // even when the path itself was smaller. We just draw and hope in the debug |
221 // version to not assert. | 223 // version to not assert. |
222 static void test_giantaa() { | 224 static void test_giantaa() { |
223 const int W = 400; | 225 const int W = 400; |
224 const int H = 400; | 226 const int H = 400; |
225 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(33000, 10)); | 227 SkAutoTUnref<SkCanvas> canvas(SkCanvas::NewRasterN32(33000, 10)); |
226 | 228 |
227 SkPaint paint; | 229 SkPaint paint; |
228 paint.setAntiAlias(true); | 230 paint.setAntiAlias(true); |
229 SkPath path; | 231 SkPath path; |
230 path.addOval(SkRect::MakeXYWH(-10, -10, 20 + W, 20 + H)); | 232 path.addOval(SkRect::MakeXYWH(-10, -10, 20 + W, 20 + H)); |
231 surface->getCanvas()->drawPath(path, paint); | 233 canvas.get()->drawPath(path, paint); |
232 } | 234 } |
233 | 235 |
234 // Extremely large path_length/dash_length ratios may cause infinite looping | 236 // Extremely large path_length/dash_length ratios may cause infinite looping |
235 // in SkDashPathEffect::filterPath() due to single precision rounding. | 237 // in SkDashPathEffect::filterPath() due to single precision rounding. |
236 // The test is quite expensive, but it should get much faster after the fix | 238 // The test is quite expensive, but it should get much faster after the fix |
237 // for http://crbug.com/165432 goes in. | 239 // for http://crbug.com/165432 goes in. |
238 static void test_infinite_dash(skiatest::Reporter* reporter) { | 240 static void test_infinite_dash(skiatest::Reporter* reporter) { |
239 SkPath path; | 241 SkPath path; |
240 path.moveTo(0, 0); | 242 path.moveTo(0, 0); |
241 path.lineTo(5000000, 0); | 243 path.lineTo(5000000, 0); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 test_crbug_124652(); | 282 test_crbug_124652(); |
281 test_crbug_140642(); | 283 test_crbug_140642(); |
282 test_crbug_140803(); | 284 test_crbug_140803(); |
283 test_inversepathwithclip(); | 285 test_inversepathwithclip(); |
284 // why? | 286 // why? |
285 if (false) test_crbug131181(); | 287 if (false) test_crbug131181(); |
286 test_infinite_dash(reporter); | 288 test_infinite_dash(reporter); |
287 test_crbug_165432(reporter); | 289 test_crbug_165432(reporter); |
288 test_big_aa_rect(reporter); | 290 test_big_aa_rect(reporter); |
289 } | 291 } |
OLD | NEW |