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

Side by Side Diff: tests/BlurTest.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
« no previous file with comments | « tests/BlitRowTest.cpp ('k') | tests/CanvasStateTest.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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SkBlurMask.h" 8 #include "SkBlurMask.h"
9 #include "SkBlurMaskFilter.h" 9 #include "SkBlurMaskFilter.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkMath.h" 11 #include "SkMath.h"
12 #include "SkPaint.h" 12 #include "SkPaint.h"
13 #include "Test.h" 13 #include "Test.h"
14 14
15 #if SK_SUPPORT_GPU 15 #if SK_SUPPORT_GPU
16 #include "GrContextFactory.h" 16 #include "GrContextFactory.h"
17 #include "SkGpuDevice.h" 17 #include "SkGpuDevice.h"
18 #endif 18 #endif
19 19
20 #define WRITE_CSV 0 20 #define WRITE_CSV 0
21 21
22 /////////////////////////////////////////////////////////////////////////////// 22 ///////////////////////////////////////////////////////////////////////////////
23 23
24 #define ILLEGAL_MODE ((SkXfermode::Mode)-1) 24 #define ILLEGAL_MODE ((SkXfermode::Mode)-1)
25 25
26 static const int outset = 100; 26 static const int outset = 100;
27 static const SkColor bgColor = SK_ColorWHITE; 27 static const SkColor bgColor = SK_ColorWHITE;
28 static const int strokeWidth = 4; 28 static const int strokeWidth = 4;
29 29
30 static void create(SkBitmap* bm, SkIRect bound, SkBitmap::Config config) { 30 static void create(SkBitmap* bm, const SkIRect& bound) {
31 bm->setConfig(config, bound.width(), bound.height()); 31 bm->allocN32Pixels(bound.width(), bound.height());
32 bm->allocPixels();
33 } 32 }
34 33
35 static void drawBG(SkCanvas* canvas) { 34 static void drawBG(SkCanvas* canvas) {
36 canvas->drawColor(bgColor); 35 canvas->drawColor(bgColor);
37 } 36 }
38 37
39 38
40 struct BlurTest { 39 struct BlurTest {
41 void (*addPath)(SkPath*); 40 void (*addPath)(SkPath*);
42 int viewLen; 41 int viewLen;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 for (size_t test = 0; test < SK_ARRAY_COUNT(tests); ++test) { 118 for (size_t test = 0; test < SK_ARRAY_COUNT(tests); ++test) {
120 SkPath path; 119 SkPath path;
121 tests[test].addPath(&path); 120 tests[test].addPath(&path);
122 SkPath strokedPath; 121 SkPath strokedPath;
123 paint.getFillPath(path, &strokedPath); 122 paint.getFillPath(path, &strokedPath);
124 SkRect refBound = strokedPath.getBounds(); 123 SkRect refBound = strokedPath.getBounds();
125 SkIRect iref; 124 SkIRect iref;
126 refBound.roundOut(&iref); 125 refBound.roundOut(&iref);
127 iref.inset(-outset, -outset); 126 iref.inset(-outset, -outset);
128 SkBitmap refBitmap; 127 SkBitmap refBitmap;
129 create(&refBitmap, iref, SkBitmap::kARGB_8888_Config); 128 create(&refBitmap, iref);
130 129
131 SkCanvas refCanvas(refBitmap); 130 SkCanvas refCanvas(refBitmap);
132 refCanvas.translate(SkIntToScalar(-iref.fLeft), 131 refCanvas.translate(SkIntToScalar(-iref.fLeft),
133 SkIntToScalar(-iref.fTop)); 132 SkIntToScalar(-iref.fTop));
134 drawBG(&refCanvas); 133 drawBG(&refCanvas);
135 refCanvas.drawPath(path, paint); 134 refCanvas.drawPath(path, paint);
136 135
137 for (int view = 0; view < tests[test].viewLen; ++view) { 136 for (int view = 0; view < tests[test].viewLen; ++view) {
138 SkIRect itest = tests[test].views[view]; 137 SkIRect itest = tests[test].views[view];
139 SkBitmap testBitmap; 138 SkBitmap testBitmap;
140 create(&testBitmap, itest, SkBitmap::kARGB_8888_Config); 139 create(&testBitmap, itest);
141 140
142 SkCanvas testCanvas(testBitmap); 141 SkCanvas testCanvas(testBitmap);
143 testCanvas.translate(SkIntToScalar(-itest.fLeft), 142 testCanvas.translate(SkIntToScalar(-itest.fLeft),
144 SkIntToScalar(-itest.fTop)); 143 SkIntToScalar(-itest.fTop));
145 drawBG(&testCanvas); 144 drawBG(&testCanvas);
146 testCanvas.drawPath(path, paint); 145 testCanvas.drawPath(path, paint);
147 146
148 REPORTER_ASSERT(reporter, 147 REPORTER_ASSERT(reporter,
149 compare(refBitmap, iref, testBitmap, itest)); 148 compare(refBitmap, iref, testBitmap, itest));
150 } 149 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 SkBlurMaskFilter::kHighQuali ty_BlurFlag); 236 SkBlurMaskFilter::kHighQuali ty_BlurFlag);
238 blurPaint.setMaskFilter(filter)->unref(); 237 blurPaint.setMaskFilter(filter)->unref();
239 238
240 canvas->drawColor(SK_ColorBLACK); 239 canvas->drawColor(SK_ColorBLACK);
241 canvas->drawPath(path, blurPaint); 240 canvas->drawPath(path, blurPaint);
242 } 241 }
243 242
244 // Readback the blurred draw results from the canvas 243 // Readback the blurred draw results from the canvas
245 static void readback(SkCanvas* canvas, int* result, int resultCount) { 244 static void readback(SkCanvas* canvas, int* result, int resultCount) {
246 SkBitmap readback; 245 SkBitmap readback;
247 readback.setConfig(SkBitmap::kARGB_8888_Config, resultCount, 30); 246 readback.allocN32Pixels(resultCount, 30);
248 readback.allocPixels();
249 247
250 SkIRect readBackRect = { 0, 0, resultCount, 30 }; 248 SkIRect readBackRect = { 0, 0, resultCount, 30 };
251 249
252 canvas->readPixels(readBackRect, &readback); 250 canvas->readPixels(readBackRect, &readback);
253 251
254 readback.lockPixels(); 252 readback.lockPixels();
255 SkPMColor* pixels = (SkPMColor*) readback.getAddr32(0, 15); 253 SkPMColor* pixels = (SkPMColor*) readback.getAddr32(0, 15);
256 254
257 for (int i = 0; i < resultCount; ++i) { 255 for (int i = 0; i < resultCount; ++i) {
258 result[i] = SkColorGetR(pixels[i]); 256 result[i] = SkColorGetR(pixels[i]);
259 } 257 }
260 } 258 }
261 259
262 // Draw a blurred version of the provided path. 260 // Draw a blurred version of the provided path.
263 // Return the right half of the middle row in 'result'. 261 // Return the right half of the middle row in 'result'.
264 static void cpu_blur_path(const SkPath& path, SkScalar gaussianSigma, 262 static void cpu_blur_path(const SkPath& path, SkScalar gaussianSigma,
265 int* result, int resultCount) { 263 int* result, int resultCount) {
266 264
267 SkBitmap bitmap; 265 SkBitmap bitmap;
268 bitmap.setConfig(SkBitmap::kARGB_8888_Config, resultCount, 30); 266 bitmap.allocN32Pixels(resultCount, 30);
269 bitmap.allocPixels();
270 SkCanvas canvas(bitmap); 267 SkCanvas canvas(bitmap);
271 268
272 blur_path(&canvas, path, gaussianSigma); 269 blur_path(&canvas, path, gaussianSigma);
273 readback(&canvas, result, resultCount); 270 readback(&canvas, result, resultCount);
274 } 271 }
275 272
276 #if SK_SUPPORT_GPU 273 #if SK_SUPPORT_GPU
277 static bool gpu_blur_path(GrContextFactory* factory, const SkPath& path, 274 static bool gpu_blur_path(GrContextFactory* factory, const SkPath& path,
278 SkScalar gaussianSigma, 275 SkScalar gaussianSigma,
279 int* result, int resultCount) { 276 int* result, int resultCount) {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 write_as_csv("GroundTruth2D", sigma, groundTruthResult, kSize); 378 write_as_csv("GroundTruth2D", sigma, groundTruthResult, kSize);
382 write_as_csv("BruteForce1D", sigma, bruteForce1DResult, kSize); 379 write_as_csv("BruteForce1D", sigma, bruteForce1DResult, kSize);
383 #endif 380 #endif
384 } 381 }
385 } 382 }
386 383
387 DEF_GPUTEST(Blur, reporter, factory) { 384 DEF_GPUTEST(Blur, reporter, factory) {
388 test_blur_drawing(reporter); 385 test_blur_drawing(reporter);
389 test_sigma_range(reporter, factory); 386 test_sigma_range(reporter, factory);
390 } 387 }
OLDNEW
« no previous file with comments | « tests/BlitRowTest.cpp ('k') | tests/CanvasStateTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698