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

Side by Side Diff: tests/DrawPathTest.cpp

Issue 164203003: replace setConfig+allocPixels with alloc-or-install-pixels (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 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
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* create(SkBitmap::Config config, int w, int h, int rb, 14 static SkCanvas* create(int w, int h, int rb, void* addr = NULL) {
scroggo 2014/02/13 20:26:03 It looks like create can be merged into new_canvas
reed1 2014/02/13 20:48:37 Done.
15 void* addr = NULL) { 15 const SkImageInfo info = SkImageInfo::MakeN32Premul(w, h);
16
16 SkBitmap bm; 17 SkBitmap bm;
17 bm.setConfig(config, w, h, rb);
18 if (addr) { 18 if (addr) {
19 bm.setPixels(addr); 19 bm.installPixels(info, addr, rb, NULL, NULL);
20 } else { 20 } else {
21 bm.allocPixels(); 21 bm.allocPixels(info);
22 } 22 }
23 return new SkCanvas(bm); 23 return new SkCanvas(bm);
24 } 24 }
25 25
26 static SkCanvas* new_canvas(int w, int h) { 26 static SkCanvas* new_canvas(int w, int h) {
27 return create(SkBitmap::kARGB_8888_Config, w, h, 0, NULL); 27 return create(w, h, 0, NULL);
28 } 28 }
29 29
30 /////////////////////////////////////////////////////////////////////////////// 30 ///////////////////////////////////////////////////////////////////////////////
31 31
32 // test that we can draw an aa-rect at coordinates > 32K (bigger than fixedpoint ) 32 // test that we can draw an aa-rect at coordinates > 32K (bigger than fixedpoint )
33 static void test_big_aa_rect(skiatest::Reporter* reporter) { 33 static void test_big_aa_rect(skiatest::Reporter* reporter) {
34 SkBitmap output; 34 SkBitmap output;
35 SkPMColor pixel[1]; 35 SkPMColor pixel[1];
36 output.setConfig(SkBitmap::kARGB_8888_Config, 1, 1, 4); 36 output.installPixels(SkImageInfo::MakeN32Premul(1, 1),
37 output.setPixels(pixel); 37 pixel, 4, NULL, NULL);
38 38
39 SkSurface* surf = SkSurface::NewRasterPMColor(300, 33300); 39 SkSurface* surf = SkSurface::NewRasterPMColor(300, 33300);
40 SkCanvas* canvas = surf->getCanvas(); 40 SkCanvas* canvas = surf->getCanvas();
41 41
42 SkRect r = { 0, 33000, 300, 33300 }; 42 SkRect r = { 0, 33000, 300, 33300 };
43 int x = SkScalarRoundToInt(r.left()); 43 int x = SkScalarRoundToInt(r.left());
44 int y = SkScalarRoundToInt(r.top()); 44 int y = SkScalarRoundToInt(r.top());
45 45
46 // check that the pixel in question starts as transparent (by the surface) 46 // check that the pixel in question starts as transparent (by the surface)
47 if (canvas->readPixels(&output, x, y)) { 47 if (canvas->readPixels(&output, x, y)) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 SkPaint paint; 118 SkPaint paint;
119 paint.setAntiAlias(true); 119 paint.setAntiAlias(true);
120 canvas->drawPath(path, paint); 120 canvas->drawPath(path, paint);
121 } 121 }
122 122
123 // This used to assert in debug builds (and crash writing bad memory in release) 123 // This used to assert in debug builds (and crash writing bad memory in release)
124 // because we overflowed an intermediate value (B coefficient) setting up our 124 // because we overflowed an intermediate value (B coefficient) setting up our
125 // stepper for the quadratic. Now we bias that value by 1/2 so we don't overflow 125 // stepper for the quadratic. Now we bias that value by 1/2 so we don't overflow
126 static void test_crbug_140803() { 126 static void test_crbug_140803() {
127 SkBitmap bm; 127 SkBitmap bm;
128 bm.setConfig(SkBitmap::kARGB_8888_Config, 2700, 30*1024); 128 bm.allocN32Pixels(2700, 30*1024);
129 bm.allocPixels();
130 SkCanvas canvas(bm); 129 SkCanvas canvas(bm);
131 130
132 SkPath path; 131 SkPath path;
133 path.moveTo(2762, 20); 132 path.moveTo(2762, 20);
134 path.quadTo(11, 21702, 10, 21706); 133 path.quadTo(11, 21702, 10, 21706);
135 SkPaint paint; 134 SkPaint paint;
136 paint.setAntiAlias(true); 135 paint.setAntiAlias(true);
137 canvas.drawPath(path, paint); 136 canvas.drawPath(path, paint);
138 } 137 }
139 138
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 test_crbug_124652(); 303 test_crbug_124652();
305 test_crbug_140642(); 304 test_crbug_140642();
306 test_crbug_140803(); 305 test_crbug_140803();
307 test_inversepathwithclip(); 306 test_inversepathwithclip();
308 // why? 307 // why?
309 if (false) test_crbug131181(); 308 if (false) test_crbug131181();
310 test_infinite_dash(reporter); 309 test_infinite_dash(reporter);
311 test_crbug_165432(reporter); 310 test_crbug_165432(reporter);
312 test_big_aa_rect(reporter); 311 test_big_aa_rect(reporter);
313 } 312 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698