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

Unified Diff: tests/ImageFilterTest.cpp

Issue 220723007: Fix SkXfermodeImageFilter when an input is cropped out. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Don't bother checking drawsNothing() Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/effects/SkXfermodeImageFilter.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ImageFilterTest.cpp
diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp
index 7d465c15e625683ef7b0e11a62da19d57668a12d..cfba1fa87df55fcde08f13dbc47f538dd3241159 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp
@@ -317,6 +317,58 @@ DEF_TEST(HugeBlurImageFilter, reporter) {
test_huge_blur(&device, reporter);
}
+static void test_xfermode_cropped_input(SkBaseDevice* device, skiatest::Reporter* reporter) {
+ SkCanvas canvas(device);
+ canvas.clear(0);
+
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(1, 1);
+ bitmap.eraseARGB(255, 255, 255, 255);
+
+ SkAutoTUnref<SkColorFilter> green(
+ SkColorFilter::CreateModeFilter(SK_ColorGREEN, SkXfermode::kSrcIn_Mode));
+ SkAutoTUnref<SkColorFilterImageFilter> greenFilter(
+ SkColorFilterImageFilter::Create(green.get()));
+ SkImageFilter::CropRect cropRect(SkRect::MakeEmpty());
+ SkAutoTUnref<SkColorFilterImageFilter> croppedOut(
+ SkColorFilterImageFilter::Create(green.get(), NULL, &cropRect));
+
+ // Check that an xfermode image filter whose input has been cropped out still draws the other
+ // input. Also check that drawing with both inputs cropped out doesn't cause a GPU warning.
+ SkXfermode* mode = SkXfermode::Create(SkXfermode::kSrcOver_Mode);
+ SkAutoTUnref<SkImageFilter> xfermodeNoFg(
+ SkXfermodeImageFilter::Create(mode, greenFilter, croppedOut));
+ SkAutoTUnref<SkImageFilter> xfermodeNoBg(
+ SkXfermodeImageFilter::Create(mode, croppedOut, greenFilter));
+ SkAutoTUnref<SkImageFilter> xfermodeNoFgNoBg(
+ SkXfermodeImageFilter::Create(mode, croppedOut, croppedOut));
+
+ SkPaint paint;
+ paint.setImageFilter(xfermodeNoFg);
+ canvas.drawSprite(bitmap, 0, 0, &paint);
+
+ uint32_t pixel;
+ SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
+ canvas.readPixels(info, &pixel, 4, 0, 0);
+ REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
+
+ paint.setImageFilter(xfermodeNoBg);
+ canvas.drawSprite(bitmap, 0, 0, &paint);
+ canvas.readPixels(info, &pixel, 4, 0, 0);
+ REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
+
+ paint.setImageFilter(xfermodeNoFgNoBg);
+ canvas.drawSprite(bitmap, 0, 0, &paint);
+ canvas.readPixels(info, &pixel, 4, 0, 0);
+ REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
+}
+
+DEF_TEST(XfermodeImageFilterCroppedInput, reporter) {
+ SkBitmap temp;
+ temp.allocN32Pixels(100, 100);
+ SkBitmapDevice device(temp);
+ test_xfermode_cropped_input(&device, reporter);
+}
#if SK_SUPPORT_GPU
DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) {
@@ -334,4 +386,12 @@ DEF_GPUTEST(HugeBlurImageFilterGPU, reporter, factory) {
0));
test_huge_blur(device, reporter);
}
+
+DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) {
+ GrContext* context = factory->get(static_cast<GrContextFactory::GLContextType>(0));
+ SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
+ SkImageInfo::MakeN32Premul(1, 1),
+ 0));
+ test_xfermode_cropped_input(device, reporter);
+}
#endif
« no previous file with comments | « src/effects/SkXfermodeImageFilter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698