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

Side by Side Diff: tests/ImageFilterTest.cpp

Issue 1964043002: Image filters: implement SkImage::makeWithFilter(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixes per Rob's comments Created 4 years, 7 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/image/SkImage.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 "SkBlurImageFilter.h" 9 #include "SkBlurImageFilter.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 kSkia8888_GrPixelConfig); 370 kSkia8888_GrPixelConfig);
371 } else 371 } else
372 #endif 372 #endif
373 { 373 {
374 const SkImageInfo info = SkImageInfo::MakeN32(widthHeight, widthHeight, 374 const SkImageInfo info = SkImageInfo::MakeN32(widthHeight, widthHeight,
375 kOpaque_SkAlphaType); 375 kOpaque_SkAlphaType);
376 return SkSpecialSurface::MakeRaster(info); 376 return SkSpecialSurface::MakeRaster(info);
377 } 377 }
378 } 378 }
379 379
380 static sk_sp<SkSurface> create_surface(GrContext* context, int width, int height ) {
381 const SkImageInfo info = SkImageInfo::MakeN32(width, height, kOpaque_SkAlpha Type);
382 #if SK_SUPPORT_GPU
383 if (context) {
384 return SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info);
385 } else
386 #endif
387 {
388 return SkSurface::MakeRaster(info);
389 }
390 }
391
380 static sk_sp<SkSpecialImage> create_empty_special_image(GrContext* context, int widthHeight) { 392 static sk_sp<SkSpecialImage> create_empty_special_image(GrContext* context, int widthHeight) {
381 sk_sp<SkSpecialSurface> surf(create_empty_special_surface(context, widthHeig ht)); 393 sk_sp<SkSpecialSurface> surf(create_empty_special_surface(context, widthHeig ht));
382 394
383 SkASSERT(surf); 395 SkASSERT(surf);
384 396
385 SkCanvas* canvas = surf->getCanvas(); 397 SkCanvas* canvas = surf->getCanvas();
386 SkASSERT(canvas); 398 SkASSERT(canvas);
387 399
388 canvas->clear(0x0); 400 canvas->clear(0x0);
389 401
(...skipping 1272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1662 1674
1663 // This should not crash (http://crbug.com/570479). 1675 // This should not crash (http://crbug.com/570479).
1664 canvas->drawRect(SkRect::MakeIWH(largeW, largeH), paint); 1676 canvas->drawRect(SkRect::MakeIWH(largeW, largeH), paint);
1665 } 1677 }
1666 1678
1667 DEF_TEST(ImageFilterBlurLargeImage, reporter) { 1679 DEF_TEST(ImageFilterBlurLargeImage, reporter) {
1668 auto surface(SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(100, 100))); 1680 auto surface(SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(100, 100)));
1669 test_large_blur_input(reporter, surface->getCanvas()); 1681 test_large_blur_input(reporter, surface->getCanvas());
1670 } 1682 }
1671 1683
1684 static void test_make_with_filter(skiatest::Reporter* reporter, GrContext* conte xt) {
1685 sk_sp<SkSurface> surface(create_surface(context, 100, 100));
1686 surface->getCanvas()->clear(SK_ColorRED);
1687 SkPaint bluePaint;
1688 bluePaint.setColor(SK_ColorBLUE);
1689 SkIRect subset = SkIRect::MakeXYWH(25, 20, 50, 50);
1690 surface->getCanvas()->drawRect(SkRect::Make(subset), bluePaint);
1691 sk_sp<SkImage> sourceImage = surface->makeImageSnapshot();
1692
1693 sk_sp<SkImageFilter> filter = make_grayscale(nullptr, nullptr);
1694 SkIRect clipBounds = SkIRect::MakeXYWH(30, 35, 100, 100);
1695 SkIRect outSubset;
1696 SkIPoint offset;
1697 sk_sp<SkImage> result;
1698
1699 result = sourceImage->makeWithFilter(nullptr, subset, clipBounds, &outSubset , &offset);
1700 REPORTER_ASSERT(reporter, !result);
1701
1702 result = sourceImage->makeWithFilter(filter.get(), subset, clipBounds, nullp tr, &offset);
1703 REPORTER_ASSERT(reporter, !result);
1704
1705 result = sourceImage->makeWithFilter(filter.get(), subset, clipBounds, &outS ubset, nullptr);
1706 REPORTER_ASSERT(reporter, !result);
1707
1708 SkIRect bigSubset = SkIRect::MakeXYWH(-10000, -10000, 20000, 20000);
1709 result = sourceImage->makeWithFilter(filter.get(), bigSubset, clipBounds, &o utSubset, &offset);
1710 REPORTER_ASSERT(reporter, !result);
1711
1712 SkIRect empty = SkIRect::MakeEmpty();
1713 result = sourceImage->makeWithFilter(filter.get(), empty, clipBounds, &outSu bset, &offset);
1714 REPORTER_ASSERT(reporter, !result);
1715
1716 result = sourceImage->makeWithFilter(filter.get(), subset, empty, &outSubset , &offset);
1717 REPORTER_ASSERT(reporter, !result);
1718
1719 SkIRect leftField = SkIRect::MakeXYWH(-1000, 0, 100, 100);
1720 result = sourceImage->makeWithFilter(filter.get(), subset, leftField, &outSu bset, &offset);
1721 REPORTER_ASSERT(reporter, !result);
1722
1723 result = sourceImage->makeWithFilter(filter.get(), subset, clipBounds, &outS ubset, &offset);
1724
1725 REPORTER_ASSERT(reporter, result);
1726 REPORTER_ASSERT(reporter, result->bounds().contains(outSubset));
1727 SkIRect destRect = SkIRect::MakeXYWH(offset.x(), offset.y(),
1728 outSubset.width(), outSubset.height()) ;
1729 REPORTER_ASSERT(reporter, clipBounds.contains(destRect));
1730 }
1731
1732 DEF_TEST(ImageFilterMakeWithFilter, reporter) {
1733 test_make_with_filter(reporter, nullptr);
1734 }
1735
1736 #if SK_SUPPORT_GPU
1737 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterMakeWithFilter_Gpu, reporter, ctxI nfo) {
1738 test_make_with_filter(reporter, ctxInfo.grContext());
1739 }
1740 #endif
1741
1672 #if SK_SUPPORT_GPU 1742 #if SK_SUPPORT_GPU
1673 1743
1674 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterHugeBlur_Gpu, reporter, ctxInfo) { 1744 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterHugeBlur_Gpu, reporter, ctxInfo) {
1675 1745
1676 sk_sp<SkSurface> surf(SkSurface::MakeRenderTarget(ctxInfo.grContext(), 1746 sk_sp<SkSurface> surf(SkSurface::MakeRenderTarget(ctxInfo.grContext(),
1677 SkBudgeted::kNo, 1747 SkBudgeted::kNo,
1678 SkImageInfo::MakeN32Premul (100, 100))); 1748 SkImageInfo::MakeN32Premul (100, 100)));
1679 1749
1680 1750
1681 SkCanvas* canvas = surf->getCanvas(); 1751 SkCanvas* canvas = surf->getCanvas();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 { SkColorFilterImageFilter::Make(cf, blif), false }, 1796 { SkColorFilterImageFilter::Make(cf, blif), false },
1727 { SkMergeImageFilter::Make(cfif, blif), false }, 1797 { SkMergeImageFilter::Make(cfif, blif), false },
1728 { SkComposeImageFilter::Make(blif, cfif), false }, 1798 { SkComposeImageFilter::Make(blif, cfif), false },
1729 }; 1799 };
1730 1800
1731 for (const auto& rec : recs) { 1801 for (const auto& rec : recs) {
1732 const bool canHandle = rec.fFilter->canHandleComplexCTM(); 1802 const bool canHandle = rec.fFilter->canHandleComplexCTM();
1733 REPORTER_ASSERT(reporter, canHandle == rec.fExpectCanHandle); 1803 REPORTER_ASSERT(reporter, canHandle == rec.fExpectCanHandle);
1734 } 1804 }
1735 } 1805 }
OLDNEW
« no previous file with comments | « src/image/SkImage.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698