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

Side by Side Diff: tests/ImageFilterTest.cpp

Issue 1842243002: Update SkImageSource to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update to ToT Created 4 years, 8 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/utils/SkBitmapSourceDeserializer.cpp ('k') | tests/SerializationTest.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 * 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 SkScalar kernel[9] = { 111 SkScalar kernel[9] = {
112 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), 112 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
113 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), 113 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1),
114 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), 114 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
115 }; 115 };
116 const SkISize kernelSize = SkISize::Make(3, 3); 116 const SkISize kernelSize = SkISize::Make(3, 3);
117 const SkScalar gain = SK_Scalar1, bias = 0; 117 const SkScalar gain = SK_Scalar1, bias = 0;
118 const SkScalar five = SkIntToScalar(5); 118 const SkScalar five = SkIntToScalar(5);
119 119
120 sk_sp<SkImage> gradientImage(SkImage::MakeFromBitmap(make_gradient_circl e(64, 64))); 120 sk_sp<SkImage> gradientImage(SkImage::MakeFromBitmap(make_gradient_circl e(64, 64)));
121 SkAutoTUnref<SkImageFilter> gradientSource(SkImageSource::Create(gradien tImage.get())); 121 sk_sp<SkImageFilter> gradientSource(SkImageSource::Make(std::move(gradie ntImage)));
122 sk_sp<SkImageFilter> blur(SkBlurImageFilter::Create(five, five, input)); 122 sk_sp<SkImageFilter> blur(SkBlurImageFilter::Create(five, five, input));
123 SkMatrix matrix; 123 SkMatrix matrix;
124 124
125 matrix.setTranslate(SK_Scalar1, SK_Scalar1); 125 matrix.setTranslate(SK_Scalar1, SK_Scalar1);
126 matrix.postRotate(SkIntToScalar(45), SK_Scalar1, SK_Scalar1); 126 matrix.postRotate(SkIntToScalar(45), SK_Scalar1, SK_Scalar1);
127 127
128 SkRTreeFactory factory; 128 SkRTreeFactory factory;
129 SkPictureRecorder recorder; 129 SkPictureRecorder recorder;
130 SkCanvas* recordingCanvas = recorder.beginRecording(64, 64, &factory, 0) ; 130 SkCanvas* recordingCanvas = recorder.beginRecording(64, 64, &factory, 0) ;
131 131
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 423
424 { 424 {
425 // This tests for : 425 // This tests for :
426 // 1 ) location at (0,0,1) 426 // 1 ) location at (0,0,1)
427 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); 427 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1);
428 // 2 ) location and target at same value 428 // 2 ) location and target at same value
429 SkPoint3 target = SkPoint3::Make(location.fX, location.fY, location. fZ); 429 SkPoint3 target = SkPoint3::Make(location.fX, location.fY, location. fZ);
430 // 3 ) large negative specular exponent value 430 // 3 ) large negative specular exponent value
431 SkScalar specularExponent = -1000; 431 SkScalar specularExponent = -1000;
432 432
433 SkAutoTUnref<SkImageFilter> bmSrc(SkImageSource::Create(image.get()) ); 433 sk_sp<SkImageFilter> bmSrc(SkImageSource::Make(std::move(image)));
434 SkPaint paint; 434 SkPaint paint;
435 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular( 435 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(
436 location, target, specularExponent, 180, 436 location, target, specularExponent, 180,
437 0xFFFFFFFF, SK_Scalar1, SK_Scalar1, SK_Scalar1, 437 0xFFFFFFFF, SK_Scalar1, SK_Scalar1, SK_Scalar1,
438 bmSrc))->unref(); 438 bmSrc.get()))->unref();
439 SkCanvas canvas(result); 439 SkCanvas canvas(result);
440 SkRect r = SkRect::MakeWH(SkIntToScalar(kBitmapSize), 440 SkRect r = SkRect::MakeWH(SkIntToScalar(kBitmapSize),
441 SkIntToScalar(kBitmapSize)); 441 SkIntToScalar(kBitmapSize));
442 canvas.drawRect(r, paint); 442 canvas.drawRect(r, paint);
443 } 443 }
444 } 444 }
445 } 445 }
446 446
447 static void test_crop_rects(SkImageFilter::Proxy* proxy, 447 static void test_crop_rects(SkImageFilter::Proxy* proxy,
448 skiatest::Reporter* reporter, 448 skiatest::Reporter* reporter,
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 } 822 }
823 } 823 }
824 824
825 static void test_imagefilter_merge_result_size(SkImageFilter::Proxy* proxy, 825 static void test_imagefilter_merge_result_size(SkImageFilter::Proxy* proxy,
826 skiatest::Reporter* reporter, 826 skiatest::Reporter* reporter,
827 GrContext* context) { 827 GrContext* context) {
828 SkBitmap greenBM; 828 SkBitmap greenBM;
829 greenBM.allocN32Pixels(20, 20); 829 greenBM.allocN32Pixels(20, 20);
830 greenBM.eraseColor(SK_ColorGREEN); 830 greenBM.eraseColor(SK_ColorGREEN);
831 sk_sp<SkImage> greenImage(SkImage::MakeFromBitmap(greenBM)); 831 sk_sp<SkImage> greenImage(SkImage::MakeFromBitmap(greenBM));
832 sk_sp<SkImageFilter> source(SkImageSource::Create(greenImage.get())); 832 sk_sp<SkImageFilter> source(SkImageSource::Make(std::move(greenImage)));
833 sk_sp<SkImageFilter> merge(SkMergeImageFilter::Make(source, source)); 833 sk_sp<SkImageFilter> merge(SkMergeImageFilter::Make(source, source));
834 834
835 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 1)); 835 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 1));
836 836
837 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 100, 100), nullptr); 837 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 100, 100), nullptr);
838 SkIPoint offset; 838 SkIPoint offset;
839 839
840 sk_sp<SkSpecialImage> resultImg(merge->filterImage(srcImg.get(), ctx, &offse t)); 840 sk_sp<SkSpecialImage> resultImg(merge->filterImage(srcImg.get(), ctx, &offse t));
841 REPORTER_ASSERT(reporter, resultImg); 841 REPORTER_ASSERT(reporter, resultImg);
842 842
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1488 SkAutoTUnref<SkImageFilter> forceOpaque(SkColorFilterImageFilter::Create(for ceOpaqueCF.get())); 1488 SkAutoTUnref<SkImageFilter> forceOpaque(SkColorFilterImageFilter::Create(for ceOpaqueCF.get()));
1489 REPORTER_ASSERT(reporter, forceOpaqueCF->affectsTransparentBlack()); 1489 REPORTER_ASSERT(reporter, forceOpaqueCF->affectsTransparentBlack());
1490 REPORTER_ASSERT(reporter, !forceOpaque->canComputeFastBounds()); 1490 REPORTER_ASSERT(reporter, !forceOpaque->canComputeFastBounds());
1491 } 1491 }
1492 1492
1493 // Verify that SkImageSource survives serialization 1493 // Verify that SkImageSource survives serialization
1494 DEF_TEST(ImageFilterImageSourceSerialization, reporter) { 1494 DEF_TEST(ImageFilterImageSourceSerialization, reporter) {
1495 auto surface(SkSurface::MakeRasterN32Premul(10, 10)); 1495 auto surface(SkSurface::MakeRasterN32Premul(10, 10));
1496 surface->getCanvas()->clear(SK_ColorGREEN); 1496 surface->getCanvas()->clear(SK_ColorGREEN);
1497 sk_sp<SkImage> image(surface->makeImageSnapshot()); 1497 sk_sp<SkImage> image(surface->makeImageSnapshot());
1498 SkAutoTUnref<SkImageFilter> filter(SkImageSource::Create(image.get())); 1498 sk_sp<SkImageFilter> filter(SkImageSource::Make(std::move(image)));
1499 1499
1500 SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(filter)); 1500 sk_sp<SkData> data(SkValidatingSerializeFlattenable(filter.get()));
1501 SkAutoTUnref<SkFlattenable> flattenable(SkValidatingDeserializeFlattenable( 1501 sk_sp<SkFlattenable> flattenable(SkValidatingDeserializeFlattenable(
1502 data->data(), data->size(), SkImageFilter::GetFlattenableType())); 1502 data->data(), data->size(), SkImageFilter::GetFlattenableType()));
1503 SkImageFilter* unflattenedFilter = static_cast<SkImageFilter*>(flattenable.g et()); 1503 SkImageFilter* unflattenedFilter = static_cast<SkImageFilter*>(flattenable.g et());
1504 REPORTER_ASSERT(reporter, unflattenedFilter); 1504 REPORTER_ASSERT(reporter, unflattenedFilter);
1505 1505
1506 SkBitmap bm; 1506 SkBitmap bm;
1507 bm.allocN32Pixels(10, 10); 1507 bm.allocN32Pixels(10, 10);
1508 bm.eraseColor(SK_ColorBLUE); 1508 bm.eraseColor(SK_ColorBLUE);
1509 SkPaint paint; 1509 SkPaint paint;
1510 paint.setColor(SK_ColorRED); 1510 paint.setColor(SK_ColorRED);
1511 paint.setImageFilter(unflattenedFilter); 1511 paint.setImageFilter(unflattenedFilter);
(...skipping 20 matching lines...) Expand all
1532 ERRORF(reporter, "Failed to allocate large bmp."); 1532 ERRORF(reporter, "Failed to allocate large bmp.");
1533 return; 1533 return;
1534 } 1534 }
1535 1535
1536 sk_sp<SkImage> largeImage(SkImage::MakeFromBitmap(largeBmp)); 1536 sk_sp<SkImage> largeImage(SkImage::MakeFromBitmap(largeBmp));
1537 if (!largeImage) { 1537 if (!largeImage) {
1538 ERRORF(reporter, "Failed to create large image."); 1538 ERRORF(reporter, "Failed to create large image.");
1539 return; 1539 return;
1540 } 1540 }
1541 1541
1542 SkAutoTUnref<SkImageFilter> largeSource(SkImageSource::Create(largeImage.get ())); 1542 sk_sp<SkImageFilter> largeSource(SkImageSource::Make(std::move(largeImage))) ;
1543 if (!largeSource) { 1543 if (!largeSource) {
1544 ERRORF(reporter, "Failed to create large SkImageSource."); 1544 ERRORF(reporter, "Failed to create large SkImageSource.");
1545 return; 1545 return;
1546 } 1546 }
1547 1547
1548 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(10.f, 10.f, large Source)); 1548 sk_sp<SkImageFilter> blur(SkBlurImageFilter::Create(10.f, 10.f, largeSource. get()));
1549 if (!blur) { 1549 if (!blur) {
1550 ERRORF(reporter, "Failed to create SkBlurImageFilter."); 1550 ERRORF(reporter, "Failed to create SkBlurImageFilter.");
1551 return; 1551 return;
1552 } 1552 }
1553 1553
1554 SkPaint paint; 1554 SkPaint paint;
1555 paint.setImageFilter(blur); 1555 paint.setImageFilter(std::move(blur));
1556 1556
1557 // This should not crash (http://crbug.com/570479). 1557 // This should not crash (http://crbug.com/570479).
1558 canvas->drawRect(SkRect::MakeIWH(largeW, largeH), paint); 1558 canvas->drawRect(SkRect::MakeIWH(largeW, largeH), paint);
1559 } 1559 }
1560 1560
1561 DEF_TEST(BlurLargeImage, reporter) { 1561 DEF_TEST(BlurLargeImage, reporter) {
1562 auto surface(SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(100, 100))); 1562 auto surface(SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(100, 100)));
1563 test_large_blur_input(reporter, surface->getCanvas()); 1563 test_large_blur_input(reporter, surface->getCanvas());
1564 } 1564 }
1565 1565
(...skipping 26 matching lines...) Expand all
1592 1592
1593 test_xfermode_cropped_input(&canvas, reporter); 1593 test_xfermode_cropped_input(&canvas, reporter);
1594 } 1594 }
1595 1595
1596 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { 1596 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) {
1597 auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, 1597 auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes,
1598 SkImageInfo::MakeN32Premul(100, 100 ))); 1598 SkImageInfo::MakeN32Premul(100, 100 )));
1599 test_large_blur_input(reporter, surface->getCanvas()); 1599 test_large_blur_input(reporter, surface->getCanvas());
1600 } 1600 }
1601 #endif 1601 #endif
OLDNEW
« no previous file with comments | « src/utils/SkBitmapSourceDeserializer.cpp ('k') | tests/SerializationTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698