From cedc36f18b2254c5ee21f6348124886b6db4f4c2 Mon Sep 17 00:00:00 2001 From: reed Date: Sun, 8 Mar 2015 04:42:52 -0700 Subject: Use ComposColorFilter to collaps hierarchy (when possible). Clarify asColorFilter ... 1. Rename to isColorFilterNode for DAG reduction 2. Add asAColorFilter for removing the imagefilter entirely (future use-case) Need layouttest rebaseline suppression before this can land in chrome... https://codereview.chromium.org/984023004/ BUG=skia: Review URL: https://codereview.chromium.org/982933002 --- tests/ImageFilterTest.cpp | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp index 430481fcc6..5e92ee35f7 100644 --- a/tests/ImageFilterTest.cpp +++ b/tests/ImageFilterTest.cpp @@ -133,7 +133,7 @@ static SkImageFilter* make_scale(float amount, SkImageFilter* input = NULL) { return SkColorFilterImageFilter::Create(filter, input); } -static SkImageFilter* make_grayscale(SkImageFilter* input = NULL, const SkImageFilter::CropRect* cropRect = NULL) { +static SkImageFilter* make_grayscale(SkImageFilter* input, const SkImageFilter::CropRect* cropRect) { SkScalar matrix[20]; memset(matrix, 0, 20 * sizeof(SkScalar)); matrix[0] = matrix[5] = matrix[10] = 0.2126f; @@ -144,28 +144,64 @@ static SkImageFilter* make_grayscale(SkImageFilter* input = NULL, const SkImageF return SkColorFilterImageFilter::Create(filter, input, cropRect); } +static SkImageFilter* make_blue(SkImageFilter* input, const SkImageFilter::CropRect* cropRect) { + SkAutoTUnref filter(SkColorFilter::CreateModeFilter(SK_ColorBLUE, + SkXfermode::kSrcIn_Mode)); + return SkColorFilterImageFilter::Create(filter, input, cropRect); +} + DEF_TEST(ImageFilter, reporter) { { - // Check that two non-clipping color matrices concatenate into a single filter. + // Check that two non-clipping color-matrice-filters concatenate into a single filter. SkAutoTUnref halfBrightness(make_scale(0.5f)); SkAutoTUnref quarterBrightness(make_scale(0.5f, halfBrightness)); REPORTER_ASSERT(reporter, NULL == quarterBrightness->getInput(0)); + SkColorFilter* cf; + REPORTER_ASSERT(reporter, quarterBrightness->asColorFilter(&cf)); + REPORTER_ASSERT(reporter, cf->asColorMatrix(NULL)); + cf->unref(); } { - // Check that a clipping color matrix followed by a grayscale does not concatenate into a single filter. + // Check that a clipping color-matrice-filter followed by a color-matrice-filters + // concatenates into a single filter, but not a matrixfilter (due to clamping). SkAutoTUnref doubleBrightness(make_scale(2.0f)); SkAutoTUnref halfBrightness(make_scale(0.5f, doubleBrightness)); - REPORTER_ASSERT(reporter, halfBrightness->getInput(0)); + REPORTER_ASSERT(reporter, NULL == halfBrightness->getInput(0)); + SkColorFilter* cf; + REPORTER_ASSERT(reporter, halfBrightness->asColorFilter(&cf)); + REPORTER_ASSERT(reporter, !cf->asColorMatrix(NULL)); + cf->unref(); } { // Check that a color filter image filter without a crop rect can be // expressed as a color filter. - SkAutoTUnref gray(make_grayscale()); + SkAutoTUnref gray(make_grayscale(NULL, NULL)); + REPORTER_ASSERT(reporter, true == gray->asColorFilter(NULL)); + } + + { + // Check that a colorfilterimage filter without a crop rect but with an input + // that is another colorfilterimage can be expressed as a colorfilter (composed). + SkAutoTUnref mode(make_blue(NULL, NULL)); + SkAutoTUnref gray(make_grayscale(mode, NULL)); REPORTER_ASSERT(reporter, true == gray->asColorFilter(NULL)); } + { + // Test that if we exceed the limit of what ComposeColorFilter can combine, we still + // can build the DAG and won't assert if we call asColorFilter. + SkAutoTUnref filter(make_blue(NULL, NULL)); + const int kWayTooManyForComposeColorFilter = 100; + for (int i = 0; i < kWayTooManyForComposeColorFilter; ++i) { + filter.reset(make_blue(filter, NULL)); + // the first few of these will succeed, but after we hit the internal limit, + // it will then return false. + (void)filter->asColorFilter(NULL); + } + } + { // Check that a color filter image filter with a crop rect cannot // be expressed as a color filter. -- cgit v1.2.3