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

Unified Diff: tests/ImageFilterTest.cpp

Issue 982933002: Use ComposColorFilter to collaps hierarchy (when possible). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix unused parameter warning Created 5 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/SkColorFilterImageFilter.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 430481fcc6eda17fcfecff5281a4836fd4df9e2f..5e92ee35f73511b0591611777b655241a8a79a9f 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,29 +144,65 @@ 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<SkColorFilter> 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<SkImageFilter> halfBrightness(make_scale(0.5f));
SkAutoTUnref<SkImageFilter> 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<SkImageFilter> doubleBrightness(make_scale(2.0f));
SkAutoTUnref<SkImageFilter> 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<SkImageFilter> gray(make_grayscale());
+ SkAutoTUnref<SkImageFilter> 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<SkImageFilter> mode(make_blue(NULL, NULL));
+ SkAutoTUnref<SkImageFilter> 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<SkImageFilter> 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.
SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(0, 0, 100, 100));
« no previous file with comments | « src/effects/SkColorFilterImageFilter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698