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

Side by Side Diff: tests/DrawPathTest.cpp

Issue 183533004: add SkCanvas::NewRaster factory -- a very common use-case in chrome (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 9 months 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 | Annotate | Revision Log
« no previous file with comments | « tests/CanvasTest.cpp ('k') | no next file » | 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 static SkCanvas* new_canvas(int w, int h) {
15 SkBitmap bm;
16 bm.allocN32Pixels(w, h);
17 return new SkCanvas(bm);
18 }
19
20 ///////////////////////////////////////////////////////////////////////////////
21
22 // 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 )
23 static void test_big_aa_rect(skiatest::Reporter* reporter) { 15 static void test_big_aa_rect(skiatest::Reporter* reporter) {
24 SkBitmap output; 16 SkBitmap output;
25 SkPMColor pixel[1]; 17 SkPMColor pixel[1];
26 output.installPixels(SkImageInfo::MakeN32Premul(1, 1), 18 output.installPixels(SkImageInfo::MakeN32Premul(1, 1),
27 pixel, 4, NULL, NULL); 19 pixel, 4, NULL, NULL);
28 20
29 SkSurface* surf = SkSurface::NewRasterPMColor(300, 33300); 21 SkSurface* surf = SkSurface::NewRasterPMColor(300, 33300);
30 SkCanvas* canvas = surf->getCanvas(); 22 SkCanvas* canvas = surf->getCanvas();
31 23
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 */ 88 */
97 uint32_t data[] = { 89 uint32_t data[] = {
98 0x419727af, 0x43011f0c, 0x41972663, 0x43011f27, 90 0x419727af, 0x43011f0c, 0x41972663, 0x43011f27,
99 0x419728fc, 0x43011ed4, 0x4194064b, 0x43012197 91 0x419728fc, 0x43011ed4, 0x4194064b, 0x43012197
100 }; 92 };
101 93
102 SkPath path; 94 SkPath path;
103 moveToH(&path, &data[0]); 95 moveToH(&path, &data[0]);
104 cubicToH(&path, &data[2]); 96 cubicToH(&path, &data[2]);
105 97
106 SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480)); 98 SkAutoTUnref<SkCanvas> canvas(SkCanvas::NewRasterN32(640, 480));
107 99
108 SkPaint paint; 100 SkPaint paint;
109 paint.setAntiAlias(true); 101 paint.setAntiAlias(true);
110 canvas->drawPath(path, paint); 102 canvas->drawPath(path, paint);
111 } 103 }
112 104
113 // This used to assert in debug builds (and crash writing bad memory in release) 105 // This used to assert in debug builds (and crash writing bad memory in release)
114 // because we overflowed an intermediate value (B coefficient) setting up our 106 // because we overflowed an intermediate value (B coefficient) setting up our
115 // stepper for the quadratic. Now we bias that value by 1/2 so we don't overflow 107 // stepper for the quadratic. Now we bias that value by 1/2 so we don't overflow
116 static void test_crbug_140803() { 108 static void test_crbug_140803() {
(...skipping 17 matching lines...) Expand all
134 static void test_inversepathwithclip() { 126 static void test_inversepathwithclip() {
135 SkPath path; 127 SkPath path;
136 128
137 path.moveTo(0, SkIntToScalar(20)); 129 path.moveTo(0, SkIntToScalar(20));
138 path.quadTo(SkIntToScalar(10), SkIntToScalar(10), 130 path.quadTo(SkIntToScalar(10), SkIntToScalar(10),
139 SkIntToScalar(20), SkIntToScalar(20)); 131 SkIntToScalar(20), SkIntToScalar(20));
140 path.toggleInverseFillType(); 132 path.toggleInverseFillType();
141 133
142 SkPaint paint; 134 SkPaint paint;
143 135
144 SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480)); 136 SkAutoTUnref<SkCanvas> canvas(SkCanvas::NewRasterN32(640, 480));
145 canvas.get()->save(); 137 canvas.get()->save();
146 canvas.get()->clipRect(SkRect::MakeWH(SkIntToScalar(19), SkIntToScalar(11))) ; 138 canvas.get()->clipRect(SkRect::MakeWH(SkIntToScalar(19), SkIntToScalar(11))) ;
147 139
148 paint.setAntiAlias(false); 140 paint.setAntiAlias(false);
149 canvas.get()->drawPath(path, paint); 141 canvas.get()->drawPath(path, paint);
150 paint.setAntiAlias(true); 142 paint.setAntiAlias(true);
151 canvas.get()->drawPath(path, paint); 143 canvas.get()->drawPath(path, paint);
152 144
153 canvas.get()->restore(); 145 canvas.get()->restore();
154 146
(...skipping 19 matching lines...) Expand all
174 This particular test/bug only applies to the float case, where the 166 This particular test/bug only applies to the float case, where the
175 coordinates are very large. 167 coordinates are very large.
176 */ 168 */
177 SkPath path; 169 SkPath path;
178 path.moveTo(64, 3); 170 path.moveTo(64, 3);
179 path.quadTo(-329936, -100000000, 1153, 330003); 171 path.quadTo(-329936, -100000000, 1153, 330003);
180 172
181 SkPaint paint; 173 SkPaint paint;
182 paint.setAntiAlias(true); 174 paint.setAntiAlias(true);
183 175
184 SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480)); 176 SkAutoTUnref<SkCanvas> canvas(SkCanvas::NewRasterN32(640, 480));
185 canvas.get()->drawPath(path, paint); 177 canvas.get()->drawPath(path, paint);
186 } 178 }
187 179
188 static void test_crbug_140642() { 180 static void test_crbug_140642() {
189 /* 181 /*
190 * We used to see this construct, and due to rounding as we accumulated 182 * We used to see this construct, and due to rounding as we accumulated
191 * our length, the loop where we apply the phase would run off the end of 183 * our length, the loop where we apply the phase would run off the end of
192 * the array, since it relied on just -= each interval value, which did not 184 * the array, since it relied on just -= each interval value, which did not
193 * behave as "expected". Now the code explicitly checks for walking off the 185 * behave as "expected". Now the code explicitly checks for walking off the
194 * end of that array. 186 * end of that array.
(...skipping 21 matching lines...) Expand all
216 } 208 }
217 209
218 static void test_bigcubic() { 210 static void test_bigcubic() {
219 SkPath path; 211 SkPath path;
220 path.moveTo(64, 3); 212 path.moveTo(64, 3);
221 path.cubicTo(-329936, -100000000, -329936, 100000000, 1153, 330003); 213 path.cubicTo(-329936, -100000000, -329936, 100000000, 1153, 330003);
222 214
223 SkPaint paint; 215 SkPaint paint;
224 paint.setAntiAlias(true); 216 paint.setAntiAlias(true);
225 217
226 SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480)); 218 SkAutoTUnref<SkCanvas> canvas(SkCanvas::NewRasterN32(640, 480));
227 canvas.get()->drawPath(path, paint); 219 canvas.get()->drawPath(path, paint);
228 } 220 }
229 221
230 // we used to assert if the bounds of the device (clip) was larger than 32K 222 // we used to assert if the bounds of the device (clip) was larger than 32K
231 // even when the path itself was smaller. We just draw and hope in the debug 223 // even when the path itself was smaller. We just draw and hope in the debug
232 // version to not assert. 224 // version to not assert.
233 static void test_giantaa() { 225 static void test_giantaa() {
234 const int W = 400; 226 const int W = 400;
235 const int H = 400; 227 const int H = 400;
236 SkAutoTUnref<SkCanvas> canvas(new_canvas(33000, 10)); 228 SkAutoTUnref<SkCanvas> canvas(SkCanvas::NewRasterN32(33000, 10));
237 canvas.get()->clear(SK_ColorTRANSPARENT);
238 229
239 SkPaint paint; 230 SkPaint paint;
240 paint.setAntiAlias(true); 231 paint.setAntiAlias(true);
241 SkPath path; 232 SkPath path;
242 path.addOval(SkRect::MakeXYWH(-10, -10, 20 + W, 20 + H)); 233 path.addOval(SkRect::MakeXYWH(-10, -10, 20 + W, 20 + H));
243 canvas.get()->drawPath(path, paint); 234 canvas.get()->drawPath(path, paint);
244 } 235 }
245 236
246 // Extremely large path_length/dash_length ratios may cause infinite looping 237 // Extremely large path_length/dash_length ratios may cause infinite looping
247 // in SkDashPathEffect::filterPath() due to single precision rounding. 238 // in SkDashPathEffect::filterPath() due to single precision rounding.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 test_crbug_124652(); 283 test_crbug_124652();
293 test_crbug_140642(); 284 test_crbug_140642();
294 test_crbug_140803(); 285 test_crbug_140803();
295 test_inversepathwithclip(); 286 test_inversepathwithclip();
296 // why? 287 // why?
297 if (false) test_crbug131181(); 288 if (false) test_crbug131181();
298 test_infinite_dash(reporter); 289 test_infinite_dash(reporter);
299 test_crbug_165432(reporter); 290 test_crbug_165432(reporter);
300 test_big_aa_rect(reporter); 291 test_big_aa_rect(reporter);
301 } 292 }
OLDNEW
« no previous file with comments | « tests/CanvasTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698