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

Side by Side Diff: tests/ImageFilterTest.cpp

Issue 1390913005: add applyFilter() to SkImage (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase to new effect factories, use stroke to show image bounds Created 5 years, 2 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
« src/image/SkImage_Gpu.cpp ('K') | « src/image/SkImage_Gpu.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 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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 break; 393 break;
394 } 394 }
395 } 395 }
396 } 396 }
397 397
398 DEF_TEST(TestNegativeBlurSigma, reporter) { 398 DEF_TEST(TestNegativeBlurSigma, reporter) {
399 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); 399 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
400 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); 400 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
401 401
402 SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(info, props)); 402 SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(info, props));
403 SkImageFilter::Proxy proxy(device); 403 SkImageFilter::DeviceProxy proxy(device);
404 404
405 test_negative_blur_sigma(&proxy, reporter); 405 test_negative_blur_sigma(&proxy, reporter);
406 } 406 }
407 407
408 DEF_TEST(ImageFilterDrawTiled, reporter) { 408 DEF_TEST(ImageFilterDrawTiled, reporter) {
409 // Check that all filters when drawn tiled (with subsequent clip rects) exac tly 409 // Check that all filters when drawn tiled (with subsequent clip rects) exac tly
410 // match the same filters drawn with a single full-canvas bitmap draw. 410 // match the same filters drawn with a single full-canvas bitmap draw.
411 // Tests pass by not asserting. 411 // Tests pass by not asserting.
412 412
413 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode)); 413 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode));
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 canvas.saveLayer(&bounds, &filterPaint); 766 canvas.saveLayer(&bounds, &filterPaint);
767 canvas.drawRect(rect, rectPaint); 767 canvas.drawRect(rect, rectPaint);
768 canvas.restore(); 768 canvas.restore();
769 } 769 }
770 770
771 DEF_TEST(ImageFilterCropRect, reporter) { 771 DEF_TEST(ImageFilterCropRect, reporter) {
772 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); 772 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
773 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); 773 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
774 774
775 SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(info, props)); 775 SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(info, props));
776 SkImageFilter::Proxy proxy(device); 776 SkImageFilter::DeviceProxy proxy(device);
777 777
778 test_crop_rects(&proxy, reporter); 778 test_crop_rects(&proxy, reporter);
779 } 779 }
780 780
781 DEF_TEST(ImageFilterMatrix, reporter) { 781 DEF_TEST(ImageFilterMatrix, reporter) {
782 SkBitmap temp; 782 SkBitmap temp;
783 temp.allocN32Pixels(100, 100); 783 temp.allocN32Pixels(100, 100);
784 SkCanvas canvas(temp); 784 SkCanvas canvas(temp);
785 canvas.scale(SkIntToScalar(2), SkIntToScalar(2)); 785 canvas.scale(SkIntToScalar(2), SkIntToScalar(2));
786 786
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 880
881 SkAutoTUnref<SkImageFilter> imageFilter(SkPictureImageFilter::Create(picture .get())); 881 SkAutoTUnref<SkImageFilter> imageFilter(SkPictureImageFilter::Create(picture .get()));
882 882
883 SkBitmap result; 883 SkBitmap result;
884 SkIPoint offset; 884 SkIPoint offset;
885 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), nul lptr); 885 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), nul lptr);
886 SkBitmap bitmap; 886 SkBitmap bitmap;
887 bitmap.allocN32Pixels(2, 2); 887 bitmap.allocN32Pixels(2, 2);
888 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); 888 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
889 SkBitmapDevice device(bitmap, props); 889 SkBitmapDevice device(bitmap, props);
890 SkImageFilter::Proxy proxy(&device); 890 SkImageFilter::DeviceProxy proxy(&device);
891 REPORTER_ASSERT(reporter, !imageFilter->filterImage(&proxy, bitmap, ctx, &re sult, &offset)); 891 REPORTER_ASSERT(reporter, !imageFilter->filterImage(&proxy, bitmap, ctx, &re sult, &offset));
892 } 892 }
893 893
894 DEF_TEST(ImageFilterEmptySaveLayer, reporter) { 894 DEF_TEST(ImageFilterEmptySaveLayer, reporter) {
895 // Even when there's an empty saveLayer()/restore(), ensure that an image 895 // Even when there's an empty saveLayer()/restore(), ensure that an image
896 // filter or color filter which affects transparent black still draws. 896 // filter or color filter which affects transparent black still draws.
897 897
898 SkBitmap bitmap; 898 SkBitmap bitmap;
899 bitmap.allocN32Pixels(10, 10); 899 bitmap.allocN32Pixels(10, 10);
900 SkCanvas canvas(bitmap); 900 SkCanvas canvas(bitmap);
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 SkCanvas canvas(temp); 1118 SkCanvas canvas(temp);
1119 test_xfermode_cropped_input(&canvas, reporter); 1119 test_xfermode_cropped_input(&canvas, reporter);
1120 } 1120 }
1121 1121
1122 DEF_TEST(ComposedImageFilterOffset, reporter) { 1122 DEF_TEST(ComposedImageFilterOffset, reporter) {
1123 SkBitmap bitmap; 1123 SkBitmap bitmap;
1124 bitmap.allocN32Pixels(100, 100); 1124 bitmap.allocN32Pixels(100, 100);
1125 bitmap.eraseARGB(0, 0, 0, 0); 1125 bitmap.eraseARGB(0, 0, 0, 0);
1126 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); 1126 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
1127 SkBitmapDevice device(bitmap, props); 1127 SkBitmapDevice device(bitmap, props);
1128 SkImageFilter::Proxy proxy(&device); 1128 SkImageFilter::DeviceProxy proxy(&device);
1129 1129
1130 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); 1130 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20));
1131 SkAutoTUnref<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, n ullptr, &cropRect)); 1131 SkAutoTUnref<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, n ullptr, &cropRect));
1132 SkAutoTUnref<SkImageFilter> blurFilter(makeBlur()); 1132 SkAutoTUnref<SkImageFilter> blurFilter(makeBlur());
1133 SkAutoTUnref<SkImageFilter> composedFilter(SkComposeImageFilter::Create(blur Filter, offsetFilter.get())); 1133 SkAutoTUnref<SkImageFilter> composedFilter(SkComposeImageFilter::Create(blur Filter, offsetFilter.get()));
1134 SkBitmap result; 1134 SkBitmap result;
1135 SkIPoint offset; 1135 SkIPoint offset;
1136 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), nullptr); 1136 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), nullptr);
1137 REPORTER_ASSERT(reporter, composedFilter->filterImage(&proxy, bitmap, ctx, & result, &offset)); 1137 REPORTER_ASSERT(reporter, composedFilter->filterImage(&proxy, bitmap, ctx, & result, &offset));
1138 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0); 1138 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0);
1139 } 1139 }
1140 1140
1141 DEF_TEST(PartialCropRect, reporter) { 1141 DEF_TEST(PartialCropRect, reporter) {
1142 SkBitmap bitmap; 1142 SkBitmap bitmap;
1143 bitmap.allocN32Pixels(100, 100); 1143 bitmap.allocN32Pixels(100, 100);
1144 bitmap.eraseARGB(0, 0, 0, 0); 1144 bitmap.eraseARGB(0, 0, 0, 0);
1145 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); 1145 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
1146 SkBitmapDevice device(bitmap, props); 1146 SkBitmapDevice device(bitmap, props);
1147 SkImageFilter::Proxy proxy(&device); 1147 SkImageFilter::DeviceProxy proxy(&device);
1148 1148
1149 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30), 1149 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30),
1150 SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::k HasHeight_CropEdge); 1150 SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::k HasHeight_CropEdge);
1151 SkAutoTUnref<SkImageFilter> filter(make_grayscale(nullptr, &cropRect)); 1151 SkAutoTUnref<SkImageFilter> filter(make_grayscale(nullptr, &cropRect));
1152 SkBitmap result; 1152 SkBitmap result;
1153 SkIPoint offset; 1153 SkIPoint offset;
1154 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), nullptr); 1154 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), nullptr);
1155 REPORTER_ASSERT(reporter, filter->filterImage(&proxy, bitmap, ctx, &result, &offset)); 1155 REPORTER_ASSERT(reporter, filter->filterImage(&proxy, bitmap, ctx, &result, &offset));
1156 REPORTER_ASSERT(reporter, offset.fX == 0); 1156 REPORTER_ASSERT(reporter, offset.fX == 0);
1157 REPORTER_ASSERT(reporter, offset.fY == 0); 1157 REPORTER_ASSERT(reporter, offset.fY == 0);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 return; 1244 return;
1245 } 1245 }
1246 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); 1246 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
1247 1247
1248 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, 1248 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
1249 SkSurface::kNo_Budgeted , 1249 SkSurface::kNo_Budgeted ,
1250 SkImageInfo::MakeN32Pre mul(100, 100), 1250 SkImageInfo::MakeN32Pre mul(100, 100),
1251 0, 1251 0,
1252 &props, 1252 &props,
1253 SkGpuDevice::kUninit_In itContents)); 1253 SkGpuDevice::kUninit_In itContents));
1254 SkImageFilter::Proxy proxy(device); 1254 SkImageFilter::DeviceProxy proxy(device);
1255 1255
1256 test_crop_rects(&proxy, reporter); 1256 test_crop_rects(&proxy, reporter);
1257 } 1257 }
1258 1258
1259 DEF_GPUTEST(HugeBlurImageFilterGPU, reporter, factory) { 1259 DEF_GPUTEST(HugeBlurImageFilterGPU, reporter, factory) {
1260 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0)); 1260 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0));
1261 if (nullptr == context) { 1261 if (nullptr == context) {
1262 return; 1262 return;
1263 } 1263 }
1264 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); 1264 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 return; 1298 return;
1299 } 1299 }
1300 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); 1300 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
1301 1301
1302 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, 1302 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
1303 SkSurface::kNo_Budgeted , 1303 SkSurface::kNo_Budgeted ,
1304 SkImageInfo::MakeN32Pre mul(1, 1), 1304 SkImageInfo::MakeN32Pre mul(1, 1),
1305 0, 1305 0,
1306 &props, 1306 &props,
1307 SkGpuDevice::kUninit_In itContents)); 1307 SkGpuDevice::kUninit_In itContents));
1308 SkImageFilter::Proxy proxy(device); 1308 SkImageFilter::DeviceProxy proxy(device);
1309 1309
1310 test_negative_blur_sigma(&proxy, reporter); 1310 test_negative_blur_sigma(&proxy, reporter);
1311 } 1311 }
1312 #endif 1312 #endif
OLDNEW
« src/image/SkImage_Gpu.cpp ('K') | « src/image/SkImage_Gpu.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698