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

Side by Side Diff: tests/ImageFilterTest.cpp

Issue 1479563002: Don't use SkRect::MakeLargest() for clip bounds in image filter tests. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 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 | « no previous file | 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 2013 Google Inc. 2 * Copyright 2013 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 "SkBitmapDevice.h" 9 #include "SkBitmapDevice.h"
10 #include "SkBlurImageFilter.h" 10 #include "SkBlurImageFilter.h"
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 SkTileImageFilter::Create(inputCropRect.rect(), cropRect.rect(), input.g et()), 312 SkTileImageFilter::Create(inputCropRect.rect(), cropRect.rect(), input.g et()),
313 SkXfermodeImageFilter::Create(SkXfermode::Create(SkXfermode::kSrcOver_Mo de), input.get(), input.get(), &cropRect), 313 SkXfermodeImageFilter::Create(SkXfermode::Create(SkXfermode::kSrcOver_Mo de), input.get(), input.get(), &cropRect),
314 }; 314 };
315 315
316 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { 316 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
317 SkImageFilter* filter = filters[i]; 317 SkImageFilter* filter = filters[i];
318 SkBitmap result; 318 SkBitmap result;
319 SkIPoint offset; 319 SkIPoint offset;
320 SkString str; 320 SkString str;
321 str.printf("filter %d", static_cast<int>(i)); 321 str.printf("filter %d", static_cast<int>(i));
322 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), nullpt r, SkImageFilter::kApprox_SizeConstraint); 322 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nul lptr, SkImageFilter::kApprox_SizeConstraint);
323 REPORTER_ASSERT_MESSAGE(reporter, filter->filterImage(proxy, bitmap, ctx , 323 REPORTER_ASSERT_MESSAGE(reporter, filter->filterImage(proxy, bitmap, ctx ,
324 &result, &offset), str.c_str()); 324 &result, &offset), str.c_str());
325 REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, st r.c_str()); 325 REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, st r.c_str());
326 } 326 }
327 327
328 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { 328 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
329 SkSafeUnref(filters[i]); 329 SkSafeUnref(filters[i]);
330 } 330 }
331 } 331 }
332 332
(...skipping 24 matching lines...) Expand all
357 const int width = 32, height = 32; 357 const int width = 32, height = 32;
358 const SkScalar five = SkIntToScalar(5); 358 const SkScalar five = SkIntToScalar(5);
359 359
360 SkAutoTUnref<SkImageFilter> positiveFilter(SkBlurImageFilter::Create(five, f ive)); 360 SkAutoTUnref<SkImageFilter> positiveFilter(SkBlurImageFilter::Create(five, f ive));
361 SkAutoTUnref<SkImageFilter> negativeFilter(SkBlurImageFilter::Create(-five, five)); 361 SkAutoTUnref<SkImageFilter> negativeFilter(SkBlurImageFilter::Create(-five, five));
362 362
363 SkBitmap gradient = make_gradient_circle(width, height); 363 SkBitmap gradient = make_gradient_circle(width, height);
364 SkBitmap positiveResult1, negativeResult1; 364 SkBitmap positiveResult1, negativeResult1;
365 SkBitmap positiveResult2, negativeResult2; 365 SkBitmap positiveResult2, negativeResult2;
366 SkIPoint offset; 366 SkIPoint offset;
367 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), nullptr, S kImageFilter::kApprox_SizeConstraint); 367 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr, SkImageFilter::kApprox_SizeConstraint);
368 positiveFilter->filterImage(proxy, gradient, ctx, &positiveResult1, &offset) ; 368 REPORTER_ASSERT(reporter, positiveFilter->filterImage(proxy, gradient, ctx, &positiveResult1, &offset));
369 negativeFilter->filterImage(proxy, gradient, ctx, &negativeResult1, &offset) ; 369 REPORTER_ASSERT(reporter, negativeFilter->filterImage(proxy, gradient, ctx, &negativeResult1, &offset));
370 SkMatrix negativeScale; 370 SkMatrix negativeScale;
371 negativeScale.setScale(-SK_Scalar1, SK_Scalar1); 371 negativeScale.setScale(-SK_Scalar1, SK_Scalar1);
372 SkImageFilter::Context negativeCTX(negativeScale, SkIRect::MakeLargest(), nu llptr, SkImageFilter::kApprox_SizeConstraint); 372 SkImageFilter::Context negativeCTX(negativeScale, SkIRect::MakeWH(32, 32), n ullptr, SkImageFilter::kApprox_SizeConstraint);
373 positiveFilter->filterImage(proxy, gradient, negativeCTX, &negativeResult2, &offset); 373 REPORTER_ASSERT(reporter, positiveFilter->filterImage(proxy, gradient, negat iveCTX, &negativeResult2, &offset));
374 negativeFilter->filterImage(proxy, gradient, negativeCTX, &positiveResult2, &offset); 374 REPORTER_ASSERT(reporter, negativeFilter->filterImage(proxy, gradient, negat iveCTX, &positiveResult2, &offset));
375 SkAutoLockPixels lockP1(positiveResult1); 375 SkAutoLockPixels lockP1(positiveResult1);
376 SkAutoLockPixels lockP2(positiveResult2); 376 SkAutoLockPixels lockP2(positiveResult2);
377 SkAutoLockPixels lockN1(negativeResult1); 377 SkAutoLockPixels lockN1(negativeResult1);
378 SkAutoLockPixels lockN2(negativeResult2); 378 SkAutoLockPixels lockN2(negativeResult2);
379 for (int y = 0; y < height; y++) { 379 for (int y = 0; y < height; y++) {
380 int diffs = memcmp(positiveResult1.getAddr32(0, y), negativeResult1.getA ddr32(0, y), positiveResult1.rowBytes()); 380 int diffs = memcmp(positiveResult1.getAddr32(0, y), negativeResult1.getA ddr32(0, y), positiveResult1.rowBytes());
381 REPORTER_ASSERT(reporter, !diffs); 381 REPORTER_ASSERT(reporter, !diffs);
382 if (diffs) { 382 if (diffs) {
383 break; 383 break;
384 } 384 }
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); 1149 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
1150 SkBitmapDevice device(bitmap, props); 1150 SkBitmapDevice device(bitmap, props);
1151 SkImageFilter::DeviceProxy proxy(&device); 1151 SkImageFilter::DeviceProxy proxy(&device);
1152 1152
1153 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); 1153 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20));
1154 SkAutoTUnref<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, n ullptr, &cropRect)); 1154 SkAutoTUnref<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, n ullptr, &cropRect));
1155 SkAutoTUnref<SkImageFilter> blurFilter(makeBlur()); 1155 SkAutoTUnref<SkImageFilter> blurFilter(makeBlur());
1156 SkAutoTUnref<SkImageFilter> composedFilter(SkComposeImageFilter::Create(blur Filter, offsetFilter.get())); 1156 SkAutoTUnref<SkImageFilter> composedFilter(SkComposeImageFilter::Create(blur Filter, offsetFilter.get()));
1157 SkBitmap result; 1157 SkBitmap result;
1158 SkIPoint offset; 1158 SkIPoint offset;
1159 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), nullptr, S kImageFilter::kApprox_SizeConstraint); 1159 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr , SkImageFilter::kApprox_SizeConstraint);
1160 REPORTER_ASSERT(reporter, composedFilter->filterImage(&proxy, bitmap, ctx, & result, &offset)); 1160 REPORTER_ASSERT(reporter, composedFilter->filterImage(&proxy, bitmap, ctx, & result, &offset));
1161 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0); 1161 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0);
1162 } 1162 }
1163 1163
1164 DEF_TEST(PartialCropRect, reporter) { 1164 DEF_TEST(PartialCropRect, reporter) {
1165 SkBitmap bitmap; 1165 SkBitmap bitmap;
1166 bitmap.allocN32Pixels(100, 100); 1166 bitmap.allocN32Pixels(100, 100);
1167 bitmap.eraseARGB(0, 0, 0, 0); 1167 bitmap.eraseARGB(0, 0, 0, 0);
1168 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); 1168 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
1169 SkBitmapDevice device(bitmap, props); 1169 SkBitmapDevice device(bitmap, props);
1170 SkImageFilter::DeviceProxy proxy(&device); 1170 SkImageFilter::DeviceProxy proxy(&device);
1171 1171
1172 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30), 1172 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30),
1173 SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::k HasHeight_CropEdge); 1173 SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::k HasHeight_CropEdge);
1174 SkAutoTUnref<SkImageFilter> filter(make_grayscale(nullptr, &cropRect)); 1174 SkAutoTUnref<SkImageFilter> filter(make_grayscale(nullptr, &cropRect));
1175 SkBitmap result; 1175 SkBitmap result;
1176 SkIPoint offset; 1176 SkIPoint offset;
1177 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), nullptr, S kImageFilter::kApprox_SizeConstraint); 1177 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr , SkImageFilter::kApprox_SizeConstraint);
1178 REPORTER_ASSERT(reporter, filter->filterImage(&proxy, bitmap, ctx, &result, &offset)); 1178 REPORTER_ASSERT(reporter, filter->filterImage(&proxy, bitmap, ctx, &result, &offset));
1179 REPORTER_ASSERT(reporter, offset.fX == 0); 1179 REPORTER_ASSERT(reporter, offset.fX == 0);
1180 REPORTER_ASSERT(reporter, offset.fY == 0); 1180 REPORTER_ASSERT(reporter, offset.fY == 0);
1181 REPORTER_ASSERT(reporter, result.width() == 20); 1181 REPORTER_ASSERT(reporter, result.width() == 20);
1182 REPORTER_ASSERT(reporter, result.height() == 30); 1182 REPORTER_ASSERT(reporter, result.height() == 30);
1183 } 1183 }
1184 1184
1185 DEF_TEST(ImageFilterCanComputeFastBounds, reporter) { 1185 DEF_TEST(ImageFilterCanComputeFastBounds, reporter) {
1186 1186
1187 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); 1187 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 SkSurface::kNo_Budgeted , 1326 SkSurface::kNo_Budgeted ,
1327 SkImageInfo::MakeN32Pre mul(1, 1), 1327 SkImageInfo::MakeN32Pre mul(1, 1),
1328 0, 1328 0,
1329 &props, 1329 &props,
1330 SkGpuDevice::kUninit_In itContents)); 1330 SkGpuDevice::kUninit_In itContents));
1331 SkImageFilter::DeviceProxy proxy(device); 1331 SkImageFilter::DeviceProxy proxy(device);
1332 1332
1333 test_negative_blur_sigma(&proxy, reporter); 1333 test_negative_blur_sigma(&proxy, reporter);
1334 } 1334 }
1335 #endif 1335 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698