OLD | NEW |
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 Loading... |
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::MakeWH(100, 100), nul
lptr, SkImageFilter::kApprox_SizeConstraint); | 322 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nul
lptr); |
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 Loading... |
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::MakeWH(32, 32), nullptr,
SkImageFilter::kApprox_SizeConstraint); | 367 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr); |
368 REPORTER_ASSERT(reporter, positiveFilter->filterImage(proxy, gradient, ctx,
&positiveResult1, &offset)); | 368 REPORTER_ASSERT(reporter, positiveFilter->filterImage(proxy, gradient, ctx,
&positiveResult1, &offset)); |
369 REPORTER_ASSERT(reporter, 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::MakeWH(32, 32), n
ullptr, SkImageFilter::kApprox_SizeConstraint); | 372 SkImageFilter::Context negativeCTX(negativeScale, SkIRect::MakeWH(32, 32), n
ullptr); |
373 REPORTER_ASSERT(reporter, positiveFilter->filterImage(proxy, gradient, negat
iveCTX, &negativeResult2, &offset)); | 373 REPORTER_ASSERT(reporter, positiveFilter->filterImage(proxy, gradient, negat
iveCTX, &negativeResult2, &offset)); |
374 REPORTER_ASSERT(reporter, negativeFilter->filterImage(proxy, gradient, negat
iveCTX, &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) { |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 SkAutoTUnref<SkImageFilter> source(SkImageSource::Create(greenImage.get())); | 651 SkAutoTUnref<SkImageFilter> source(SkImageSource::Create(greenImage.get())); |
652 SkAutoTUnref<SkImageFilter> merge(SkMergeImageFilter::Create(source.get(), s
ource.get())); | 652 SkAutoTUnref<SkImageFilter> merge(SkMergeImageFilter::Create(source.get(), s
ource.get())); |
653 | 653 |
654 SkBitmap bitmap; | 654 SkBitmap bitmap; |
655 bitmap.allocN32Pixels(1, 1); | 655 bitmap.allocN32Pixels(1, 1); |
656 bitmap.eraseColor(0); | 656 bitmap.eraseColor(0); |
657 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); | 657 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); |
658 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 658 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); |
659 SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(info, props)); | 659 SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(info, props)); |
660 SkImageFilter::DeviceProxy proxy(device); | 660 SkImageFilter::DeviceProxy proxy(device); |
661 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 100, 100),
nullptr, | 661 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 100, 100),
nullptr); |
662 SkImageFilter::kApprox_SizeConstraint); | |
663 SkBitmap result; | 662 SkBitmap result; |
664 SkIPoint offset; | 663 SkIPoint offset; |
665 REPORTER_ASSERT(reporter, merge->filterImage(&proxy, bitmap, ctx, &result, &
offset)); | 664 REPORTER_ASSERT(reporter, merge->filterImage(&proxy, bitmap, ctx, &result, &
offset)); |
666 REPORTER_ASSERT(reporter, result.width() == 20 && result.height() == 20); | 665 REPORTER_ASSERT(reporter, result.width() == 20 && result.height() == 20); |
667 } | 666 } |
668 | 667 |
669 static void draw_blurred_rect(SkCanvas* canvas) { | 668 static void draw_blurred_rect(SkCanvas* canvas) { |
670 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8
), 0)); | 669 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8
), 0)); |
671 SkPaint filterPaint; | 670 SkPaint filterPaint; |
672 filterPaint.setColor(SK_ColorWHITE); | 671 filterPaint.setColor(SK_ColorWHITE); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 // Create an SkPicture which simply draws a green 1x1 rectangle. | 898 // Create an SkPicture which simply draws a green 1x1 rectangle. |
900 SkPaint greenPaint; | 899 SkPaint greenPaint; |
901 greenPaint.setColor(SK_ColorGREEN); | 900 greenPaint.setColor(SK_ColorGREEN); |
902 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), greenPaint); | 901 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), greenPaint); |
903 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 902 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
904 | 903 |
905 SkAutoTUnref<SkImageFilter> imageFilter(SkPictureImageFilter::Create(picture
.get())); | 904 SkAutoTUnref<SkImageFilter> imageFilter(SkPictureImageFilter::Create(picture
.get())); |
906 | 905 |
907 SkBitmap result; | 906 SkBitmap result; |
908 SkIPoint offset; | 907 SkIPoint offset; |
909 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), nul
lptr, SkImageFilter::kApprox_SizeConstraint); | 908 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), nul
lptr); |
910 SkBitmap bitmap; | 909 SkBitmap bitmap; |
911 bitmap.allocN32Pixels(2, 2); | 910 bitmap.allocN32Pixels(2, 2); |
912 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 911 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); |
913 SkBitmapDevice device(bitmap, props); | 912 SkBitmapDevice device(bitmap, props); |
914 SkImageFilter::DeviceProxy proxy(&device); | 913 SkImageFilter::DeviceProxy proxy(&device); |
915 REPORTER_ASSERT(reporter, !imageFilter->filterImage(&proxy, bitmap, ctx, &re
sult, &offset)); | 914 REPORTER_ASSERT(reporter, !imageFilter->filterImage(&proxy, bitmap, ctx, &re
sult, &offset)); |
916 } | 915 } |
917 | 916 |
918 DEF_TEST(ImageFilterEmptySaveLayer, reporter) { | 917 DEF_TEST(ImageFilterEmptySaveLayer, reporter) { |
919 // Even when there's an empty saveLayer()/restore(), ensure that an image | 918 // Even when there's an empty saveLayer()/restore(), ensure that an image |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1152 SkImageFilter::DeviceProxy proxy(&device); | 1151 SkImageFilter::DeviceProxy proxy(&device); |
1153 | 1152 |
1154 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); | 1153 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); |
1155 SkAutoTUnref<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, n
ullptr, &cropRect)); | 1154 SkAutoTUnref<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, n
ullptr, &cropRect)); |
1156 SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(SK_Scalar1,
SK_Scalar1, | 1155 SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(SK_Scalar1,
SK_Scalar1, |
1157 nullptr, &c
ropRect)); | 1156 nullptr, &c
ropRect)); |
1158 SkAutoTUnref<SkImageFilter> composedFilter(SkComposeImageFilter::Create(blur
Filter, | 1157 SkAutoTUnref<SkImageFilter> composedFilter(SkComposeImageFilter::Create(blur
Filter, |
1159 offs
etFilter.get())); | 1158 offs
etFilter.get())); |
1160 SkBitmap result; | 1159 SkBitmap result; |
1161 SkIPoint offset; | 1160 SkIPoint offset; |
1162 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr
, SkImageFilter::kApprox_SizeConstraint); | 1161 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr
); |
1163 REPORTER_ASSERT(reporter, composedFilter->filterImage(&proxy, bitmap, ctx, &
result, &offset)); | 1162 REPORTER_ASSERT(reporter, composedFilter->filterImage(&proxy, bitmap, ctx, &
result, &offset)); |
1164 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0); | 1163 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0); |
1165 } | 1164 } |
1166 | 1165 |
1167 DEF_TEST(PartialCropRect, reporter) { | 1166 DEF_TEST(PartialCropRect, reporter) { |
1168 SkBitmap bitmap; | 1167 SkBitmap bitmap; |
1169 bitmap.allocN32Pixels(100, 100); | 1168 bitmap.allocN32Pixels(100, 100); |
1170 bitmap.eraseARGB(0, 0, 0, 0); | 1169 bitmap.eraseARGB(0, 0, 0, 0); |
1171 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 1170 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); |
1172 SkBitmapDevice device(bitmap, props); | 1171 SkBitmapDevice device(bitmap, props); |
1173 SkImageFilter::DeviceProxy proxy(&device); | 1172 SkImageFilter::DeviceProxy proxy(&device); |
1174 | 1173 |
1175 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30), | 1174 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30), |
1176 SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::k
HasHeight_CropEdge); | 1175 SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::k
HasHeight_CropEdge); |
1177 SkAutoTUnref<SkImageFilter> filter(make_grayscale(nullptr, &cropRect)); | 1176 SkAutoTUnref<SkImageFilter> filter(make_grayscale(nullptr, &cropRect)); |
1178 SkBitmap result; | 1177 SkBitmap result; |
1179 SkIPoint offset; | 1178 SkIPoint offset; |
1180 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr
, SkImageFilter::kApprox_SizeConstraint); | 1179 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr
); |
1181 REPORTER_ASSERT(reporter, filter->filterImage(&proxy, bitmap, ctx, &result,
&offset)); | 1180 REPORTER_ASSERT(reporter, filter->filterImage(&proxy, bitmap, ctx, &result,
&offset)); |
1182 REPORTER_ASSERT(reporter, offset.fX == 0); | 1181 REPORTER_ASSERT(reporter, offset.fX == 0); |
1183 REPORTER_ASSERT(reporter, offset.fY == 0); | 1182 REPORTER_ASSERT(reporter, offset.fY == 0); |
1184 REPORTER_ASSERT(reporter, result.width() == 20); | 1183 REPORTER_ASSERT(reporter, result.width() == 20); |
1185 REPORTER_ASSERT(reporter, result.height() == 30); | 1184 REPORTER_ASSERT(reporter, result.height() == 30); |
1186 } | 1185 } |
1187 | 1186 |
1188 DEF_TEST(ImageFilterCanComputeFastBounds, reporter) { | 1187 DEF_TEST(ImageFilterCanComputeFastBounds, reporter) { |
1189 | 1188 |
1190 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); | 1189 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1367 test_negative_blur_sigma(&proxy, reporter); | 1366 test_negative_blur_sigma(&proxy, reporter); |
1368 } | 1367 } |
1369 | 1368 |
1370 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { | 1369 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { |
1371 SkAutoTUnref<SkSurface> surface( | 1370 SkAutoTUnref<SkSurface> surface( |
1372 SkSurface::NewRenderTarget(context, SkSurface::kYes_Budgeted, | 1371 SkSurface::NewRenderTarget(context, SkSurface::kYes_Budgeted, |
1373 SkImageInfo::MakeN32Premul(100, 100))); | 1372 SkImageInfo::MakeN32Premul(100, 100))); |
1374 test_large_blur_input(reporter, surface->getCanvas()); | 1373 test_large_blur_input(reporter, surface->getCanvas()); |
1375 } | 1374 } |
1376 #endif | 1375 #endif |
OLD | NEW |