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

Side by Side Diff: tests/ImageFilterTest.cpp

Issue 1709753002: Mark existing image filter entry points that will be going away with Deprecated (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update to ToT Created 4 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
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | tests/PDFPrimitivesTest.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 2013 Google Inc. 3 * Copyright 2013 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 8
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkBitmapDevice.h" 10 #include "SkBitmapDevice.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 static const int kBitmapSize = 4; 46 static const int kBitmapSize = 4;
47 47
48 namespace { 48 namespace {
49 49
50 class MatrixTestImageFilter : public SkImageFilter { 50 class MatrixTestImageFilter : public SkImageFilter {
51 public: 51 public:
52 MatrixTestImageFilter(skiatest::Reporter* reporter, const SkMatrix& expected Matrix) 52 MatrixTestImageFilter(skiatest::Reporter* reporter, const SkMatrix& expected Matrix)
53 : SkImageFilter(0, nullptr), fReporter(reporter), fExpectedMatrix(expected Matrix) { 53 : SkImageFilter(0, nullptr), fReporter(reporter), fExpectedMatrix(expected Matrix) {
54 } 54 }
55 55
56 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context& ctx, 56 bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context& ctx ,
57 SkBitmap* result, SkIPoint* offset) const overrid e { 57 SkBitmap* result, SkIPoint* offset) const overr ide {
58 REPORTER_ASSERT(fReporter, ctx.ctm() == fExpectedMatrix); 58 REPORTER_ASSERT(fReporter, ctx.ctm() == fExpectedMatrix);
59 return true; 59 return true;
60 } 60 }
61 61
62 SK_TO_STRING_OVERRIDE() 62 SK_TO_STRING_OVERRIDE()
63 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(MatrixTestImageFilter) 63 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(MatrixTestImageFilter)
64 64
65 protected: 65 protected:
66 void flatten(SkWriteBuffer& buffer) const override { 66 void flatten(SkWriteBuffer& buffer) const override {
67 this->INHERITED::flatten(buffer); 67 this->INHERITED::flatten(buffer);
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 SkXfermodeImageFilter::Create(SkXfermode::Create(SkXfermode::kSrcOver_Mo de), input.get(), input.get(), &cropRect), 314 SkXfermodeImageFilter::Create(SkXfermode::Create(SkXfermode::kSrcOver_Mo de), input.get(), input.get(), &cropRect),
315 }; 315 };
316 316
317 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { 317 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
318 SkImageFilter* filter = filters[i]; 318 SkImageFilter* filter = filters[i];
319 SkBitmap result; 319 SkBitmap result;
320 SkIPoint offset; 320 SkIPoint offset;
321 SkString str; 321 SkString str;
322 str.printf("filter %d", static_cast<int>(i)); 322 str.printf("filter %d", static_cast<int>(i));
323 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nul lptr); 323 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nul lptr);
324 REPORTER_ASSERT_MESSAGE(reporter, filter->filterImage(proxy, bitmap, ctx , 324 REPORTER_ASSERT_MESSAGE(reporter,
325 &result, &offset), str.c_str()); 325 filter->filterImageDeprecated(proxy, bitmap, ctx ,
326 &result, &offset),
327 str.c_str());
326 REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, st r.c_str()); 328 REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, st r.c_str());
327 } 329 }
328 330
329 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { 331 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
330 SkSafeUnref(filters[i]); 332 SkSafeUnref(filters[i]);
331 } 333 }
332 } 334 }
333 335
334 static SkBitmap make_gradient_circle(int width, int height) { 336 static SkBitmap make_gradient_circle(int width, int height) {
335 SkBitmap bitmap; 337 SkBitmap bitmap;
(...skipping 23 matching lines...) Expand all
359 const SkScalar five = SkIntToScalar(5); 361 const SkScalar five = SkIntToScalar(5);
360 362
361 SkAutoTUnref<SkImageFilter> positiveFilter(SkBlurImageFilter::Create(five, f ive)); 363 SkAutoTUnref<SkImageFilter> positiveFilter(SkBlurImageFilter::Create(five, f ive));
362 SkAutoTUnref<SkImageFilter> negativeFilter(SkBlurImageFilter::Create(-five, five)); 364 SkAutoTUnref<SkImageFilter> negativeFilter(SkBlurImageFilter::Create(-five, five));
363 365
364 SkBitmap gradient = make_gradient_circle(width, height); 366 SkBitmap gradient = make_gradient_circle(width, height);
365 SkBitmap positiveResult1, negativeResult1; 367 SkBitmap positiveResult1, negativeResult1;
366 SkBitmap positiveResult2, negativeResult2; 368 SkBitmap positiveResult2, negativeResult2;
367 SkIPoint offset; 369 SkIPoint offset;
368 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr); 370 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr);
369 REPORTER_ASSERT(reporter, positiveFilter->filterImage(proxy, gradient, ctx, &positiveResult1, &offset)); 371 REPORTER_ASSERT(reporter,
370 REPORTER_ASSERT(reporter, negativeFilter->filterImage(proxy, gradient, ctx, &negativeResult1, &offset)); 372 positiveFilter->filterImageDeprecated(proxy, gradient, ctx,
373 &positiveResult1, &off set));
374 REPORTER_ASSERT(reporter,
375 negativeFilter->filterImageDeprecated(proxy, gradient, ctx,
376 &negativeResult1, &off set));
371 SkMatrix negativeScale; 377 SkMatrix negativeScale;
372 negativeScale.setScale(-SK_Scalar1, SK_Scalar1); 378 negativeScale.setScale(-SK_Scalar1, SK_Scalar1);
373 SkImageFilter::Context negativeCTX(negativeScale, SkIRect::MakeWH(32, 32), n ullptr); 379 SkImageFilter::Context negativeCTX(negativeScale, SkIRect::MakeWH(32, 32), n ullptr);
374 REPORTER_ASSERT(reporter, positiveFilter->filterImage(proxy, gradient, negat iveCTX, &negativeResult2, &offset)); 380 REPORTER_ASSERT(reporter,
375 REPORTER_ASSERT(reporter, negativeFilter->filterImage(proxy, gradient, negat iveCTX, &positiveResult2, &offset)); 381 positiveFilter->filterImageDeprecated(proxy, gradient, negat iveCTX,
382 &negativeResult2, &off set));
383 REPORTER_ASSERT(reporter,
384 negativeFilter->filterImageDeprecated(proxy, gradient, negat iveCTX,
385 &positiveResult2, &off set));
376 SkAutoLockPixels lockP1(positiveResult1); 386 SkAutoLockPixels lockP1(positiveResult1);
377 SkAutoLockPixels lockP2(positiveResult2); 387 SkAutoLockPixels lockP2(positiveResult2);
378 SkAutoLockPixels lockN1(negativeResult1); 388 SkAutoLockPixels lockN1(negativeResult1);
379 SkAutoLockPixels lockN2(negativeResult2); 389 SkAutoLockPixels lockN2(negativeResult2);
380 for (int y = 0; y < height; y++) { 390 for (int y = 0; y < height; y++) {
381 int diffs = memcmp(positiveResult1.getAddr32(0, y), negativeResult1.getA ddr32(0, y), positiveResult1.rowBytes()); 391 int diffs = memcmp(positiveResult1.getAddr32(0, y), negativeResult1.getA ddr32(0, y), positiveResult1.rowBytes());
382 REPORTER_ASSERT(reporter, !diffs); 392 REPORTER_ASSERT(reporter, !diffs);
383 if (diffs) { 393 if (diffs) {
384 break; 394 break;
385 } 395 }
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 SkBitmap bitmap; 665 SkBitmap bitmap;
656 bitmap.allocN32Pixels(1, 1); 666 bitmap.allocN32Pixels(1, 1);
657 bitmap.eraseColor(0); 667 bitmap.eraseColor(0);
658 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); 668 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
659 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); 669 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
660 SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(info, props)); 670 SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(info, props));
661 SkImageFilter::DeviceProxy proxy(device); 671 SkImageFilter::DeviceProxy proxy(device);
662 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 100, 100), nullptr); 672 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 100, 100), nullptr);
663 SkBitmap result; 673 SkBitmap result;
664 SkIPoint offset; 674 SkIPoint offset;
665 REPORTER_ASSERT(reporter, merge->filterImage(&proxy, bitmap, ctx, &result, & offset)); 675 REPORTER_ASSERT(reporter, merge->filterImageDeprecated(&proxy, bitmap, ctx, &result, &offset));
666 REPORTER_ASSERT(reporter, result.width() == 20 && result.height() == 20); 676 REPORTER_ASSERT(reporter, result.width() == 20 && result.height() == 20);
667 } 677 }
668 678
669 static void draw_blurred_rect(SkCanvas* canvas) { 679 static void draw_blurred_rect(SkCanvas* canvas) {
670 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8 ), 0)); 680 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8 ), 0));
671 SkPaint filterPaint; 681 SkPaint filterPaint;
672 filterPaint.setColor(SK_ColorWHITE); 682 filterPaint.setColor(SK_ColorWHITE);
673 filterPaint.setImageFilter(filter); 683 filterPaint.setImageFilter(filter);
674 canvas->saveLayer(nullptr, &filterPaint); 684 canvas->saveLayer(nullptr, &filterPaint);
675 SkPaint whitePaint; 685 SkPaint whitePaint;
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 SkAutoTUnref<SkImageFilter> imageFilter(SkPictureImageFilter::Create(picture .get())); 915 SkAutoTUnref<SkImageFilter> imageFilter(SkPictureImageFilter::Create(picture .get()));
906 916
907 SkBitmap result; 917 SkBitmap result;
908 SkIPoint offset; 918 SkIPoint offset;
909 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), nul lptr); 919 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), nul lptr);
910 SkBitmap bitmap; 920 SkBitmap bitmap;
911 bitmap.allocN32Pixels(2, 2); 921 bitmap.allocN32Pixels(2, 2);
912 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); 922 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
913 SkBitmapDevice device(bitmap, props); 923 SkBitmapDevice device(bitmap, props);
914 SkImageFilter::DeviceProxy proxy(&device); 924 SkImageFilter::DeviceProxy proxy(&device);
915 REPORTER_ASSERT(reporter, !imageFilter->filterImage(&proxy, bitmap, ctx, &re sult, &offset)); 925 REPORTER_ASSERT(reporter,
926 !imageFilter->filterImageDeprecated(&proxy, bitmap, ctx, &re sult, &offset));
916 } 927 }
917 928
918 DEF_TEST(ImageFilterEmptySaveLayer, reporter) { 929 DEF_TEST(ImageFilterEmptySaveLayer, reporter) {
919 // Even when there's an empty saveLayer()/restore(), ensure that an image 930 // Even when there's an empty saveLayer()/restore(), ensure that an image
920 // filter or color filter which affects transparent black still draws. 931 // filter or color filter which affects transparent black still draws.
921 932
922 SkBitmap bitmap; 933 SkBitmap bitmap;
923 bitmap.allocN32Pixels(10, 10); 934 bitmap.allocN32Pixels(10, 10);
924 SkCanvas canvas(bitmap); 935 SkCanvas canvas(bitmap);
925 936
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 1164
1154 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); 1165 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20));
1155 SkAutoTUnref<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, n ullptr, &cropRect)); 1166 SkAutoTUnref<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, n ullptr, &cropRect));
1156 SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(SK_Scalar1, SK_Scalar1, 1167 SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(SK_Scalar1, SK_Scalar1,
1157 nullptr, &c ropRect)); 1168 nullptr, &c ropRect));
1158 SkAutoTUnref<SkImageFilter> composedFilter(SkComposeImageFilter::Create(blur Filter, 1169 SkAutoTUnref<SkImageFilter> composedFilter(SkComposeImageFilter::Create(blur Filter,
1159 offs etFilter.get())); 1170 offs etFilter.get()));
1160 SkBitmap result; 1171 SkBitmap result;
1161 SkIPoint offset; 1172 SkIPoint offset;
1162 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr ); 1173 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr );
1163 REPORTER_ASSERT(reporter, composedFilter->filterImage(&proxy, bitmap, ctx, & result, &offset)); 1174 REPORTER_ASSERT(reporter,
1175 composedFilter->filterImageDeprecated(&proxy, bitmap, ctx, & result, &offset));
1164 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0); 1176 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0);
1165 } 1177 }
1166 1178
1167 DEF_TEST(PartialCropRect, reporter) { 1179 DEF_TEST(PartialCropRect, reporter) {
1168 SkBitmap bitmap; 1180 SkBitmap bitmap;
1169 bitmap.allocN32Pixels(100, 100); 1181 bitmap.allocN32Pixels(100, 100);
1170 bitmap.eraseARGB(0, 0, 0, 0); 1182 bitmap.eraseARGB(0, 0, 0, 0);
1171 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); 1183 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
1172 SkBitmapDevice device(bitmap, props); 1184 SkBitmapDevice device(bitmap, props);
1173 SkImageFilter::DeviceProxy proxy(&device); 1185 SkImageFilter::DeviceProxy proxy(&device);
1174 1186
1175 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30), 1187 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30),
1176 SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::k HasHeight_CropEdge); 1188 SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::k HasHeight_CropEdge);
1177 SkAutoTUnref<SkImageFilter> filter(make_grayscale(nullptr, &cropRect)); 1189 SkAutoTUnref<SkImageFilter> filter(make_grayscale(nullptr, &cropRect));
1178 SkBitmap result; 1190 SkBitmap result;
1179 SkIPoint offset; 1191 SkIPoint offset;
1180 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr ); 1192 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr );
1181 REPORTER_ASSERT(reporter, filter->filterImage(&proxy, bitmap, ctx, &result, &offset)); 1193 REPORTER_ASSERT(reporter,
1194 filter->filterImageDeprecated(&proxy, bitmap, ctx, &result, &offset));
1182 REPORTER_ASSERT(reporter, offset.fX == 0); 1195 REPORTER_ASSERT(reporter, offset.fX == 0);
1183 REPORTER_ASSERT(reporter, offset.fY == 0); 1196 REPORTER_ASSERT(reporter, offset.fY == 0);
1184 REPORTER_ASSERT(reporter, result.width() == 20); 1197 REPORTER_ASSERT(reporter, result.width() == 20);
1185 REPORTER_ASSERT(reporter, result.height() == 30); 1198 REPORTER_ASSERT(reporter, result.height() == 30);
1186 } 1199 }
1187 1200
1188 DEF_TEST(ImageFilterCanComputeFastBounds, reporter) { 1201 DEF_TEST(ImageFilterCanComputeFastBounds, reporter) {
1189 1202
1190 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); 1203 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1);
1191 SkAutoTUnref<SkImageFilter> lighting(SkLightingImageFilter::CreatePointLitDi ffuse( 1204 SkAutoTUnref<SkImageFilter> lighting(SkLightingImageFilter::CreatePointLitDi ffuse(
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 test_negative_blur_sigma(&proxy, reporter); 1381 test_negative_blur_sigma(&proxy, reporter);
1369 } 1382 }
1370 1383
1371 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { 1384 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) {
1372 SkAutoTUnref<SkSurface> surface( 1385 SkAutoTUnref<SkSurface> surface(
1373 SkSurface::NewRenderTarget(context, SkSurface::kYes_Budgeted, 1386 SkSurface::NewRenderTarget(context, SkSurface::kYes_Budgeted,
1374 SkImageInfo::MakeN32Premul(100, 100))); 1387 SkImageInfo::MakeN32Premul(100, 100)));
1375 test_large_blur_input(reporter, surface->getCanvas()); 1388 test_large_blur_input(reporter, surface->getCanvas());
1376 } 1389 }
1377 #endif 1390 #endif
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | tests/PDFPrimitivesTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698