Chromium Code Reviews| 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 "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 Loading... | |
| 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 Loading... | |
| 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 greenPaint; | |
|
robertphillips
2016/05/19 21:14:44
bluePaint? SK_ColorGreen ?
Stephen White
2016/05/19 21:27:43
LOL
What... is your favourite colour?
https://ww
| |
| 1688 greenPaint.setColor(SK_ColorBLUE); | |
| 1689 SkIRect subset = SkIRect::MakeXYWH(25, 20, 50, 50); | |
| 1690 surface->getCanvas()->drawRect(SkRect::Make(subset), greenPaint); | |
| 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(); | |
|
robertphillips
2016/05/19 21:14:44
Do you intend the offset out pointer to be null he
Stephen White
2016/05/19 21:27:43
Nope. Thanks.
| |
| 1713 result = sourceImage->makeWithFilter(filter.get(), empty, clipBounds, &outSu bset, nullptr); | |
| 1714 REPORTER_ASSERT(reporter, !result); | |
| 1715 | |
| 1716 result = sourceImage->makeWithFilter(filter.get(), subset, clipBounds, &outS ubset, &offset); | |
| 1717 | |
| 1718 REPORTER_ASSERT(reporter, result); | |
| 1719 REPORTER_ASSERT(reporter, result->bounds().contains(outSubset)); | |
|
robertphillips
2016/05/19 21:14:44
destRect ?
Stephen White
2016/05/19 21:27:43
Done.
| |
| 1720 SkIRect dest_rect = SkIRect::MakeXYWH(offset.x(), offset.y(), | |
|
reed1
2016/05/19 20:12:10
nit: can just use outSubset.makeOffset(offset.x(),
Stephen White
2016/05/19 21:27:43
Can't do that; we wan to use only the outSubset si
| |
| 1721 outSubset.width(), outSubset.height()) ; | |
| 1722 REPORTER_ASSERT(reporter, clipBounds.contains(dest_rect)); | |
|
robertphillips
2016/05/19 21:14:44
Do you not want to test the case where clipBounds
Stephen White
2016/05/19 21:27:43
Good point. Done.
| |
| 1723 } | |
| 1724 | |
| 1725 DEF_TEST(ImageFilterMakeWithFilter, reporter) { | |
| 1726 test_make_with_filter(reporter, nullptr); | |
| 1727 } | |
| 1728 | |
| 1729 #if SK_SUPPORT_GPU | |
| 1730 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterMakeWithFilter_Gpu, reporter, ctxI nfo) { | |
| 1731 test_make_with_filter(reporter, ctxInfo.grContext()); | |
| 1732 } | |
| 1733 #endif | |
| 1734 | |
| 1672 #if SK_SUPPORT_GPU | 1735 #if SK_SUPPORT_GPU |
| 1673 | 1736 |
| 1674 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterHugeBlur_Gpu, reporter, ctxInfo) { | 1737 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterHugeBlur_Gpu, reporter, ctxInfo) { |
| 1675 | 1738 |
| 1676 sk_sp<SkSurface> surf(SkSurface::MakeRenderTarget(ctxInfo.grContext(), | 1739 sk_sp<SkSurface> surf(SkSurface::MakeRenderTarget(ctxInfo.grContext(), |
| 1677 SkBudgeted::kNo, | 1740 SkBudgeted::kNo, |
| 1678 SkImageInfo::MakeN32Premul (100, 100))); | 1741 SkImageInfo::MakeN32Premul (100, 100))); |
| 1679 | 1742 |
| 1680 | 1743 |
| 1681 SkCanvas* canvas = surf->getCanvas(); | 1744 SkCanvas* canvas = surf->getCanvas(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1726 { SkColorFilterImageFilter::Make(cf, blif), false }, | 1789 { SkColorFilterImageFilter::Make(cf, blif), false }, |
| 1727 { SkMergeImageFilter::Make(cfif, blif), false }, | 1790 { SkMergeImageFilter::Make(cfif, blif), false }, |
| 1728 { SkComposeImageFilter::Make(blif, cfif), false }, | 1791 { SkComposeImageFilter::Make(blif, cfif), false }, |
| 1729 }; | 1792 }; |
| 1730 | 1793 |
| 1731 for (const auto& rec : recs) { | 1794 for (const auto& rec : recs) { |
| 1732 const bool canHandle = rec.fFilter->canHandleComplexCTM(); | 1795 const bool canHandle = rec.fFilter->canHandleComplexCTM(); |
| 1733 REPORTER_ASSERT(reporter, canHandle == rec.fExpectCanHandle); | 1796 REPORTER_ASSERT(reporter, canHandle == rec.fExpectCanHandle); |
| 1734 } | 1797 } |
| 1735 } | 1798 } |
| OLD | NEW |