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

Side by Side Diff: tests/ImageFilterTest.cpp

Issue 978923005: Revert of check for inputs before reporting asColorFilter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « src/effects/SkColorFilterImageFilter.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 "SkBitmapDevice.h" 9 #include "SkBitmapDevice.h"
10 #include "SkBitmapSource.h" 10 #include "SkBitmapSource.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 static SkImageFilter* make_scale(float amount, SkImageFilter* input = NULL) { 126 static SkImageFilter* make_scale(float amount, SkImageFilter* input = NULL) {
127 SkScalar s = amount; 127 SkScalar s = amount;
128 SkScalar matrix[20] = { s, 0, 0, 0, 0, 128 SkScalar matrix[20] = { s, 0, 0, 0, 0,
129 0, s, 0, 0, 0, 129 0, s, 0, 0, 0,
130 0, 0, s, 0, 0, 130 0, 0, s, 0, 0,
131 0, 0, 0, s, 0 }; 131 0, 0, 0, s, 0 };
132 SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix)); 132 SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix));
133 return SkColorFilterImageFilter::Create(filter, input); 133 return SkColorFilterImageFilter::Create(filter, input);
134 } 134 }
135 135
136 static SkImageFilter* make_grayscale(SkImageFilter* input, const SkImageFilter:: CropRect* cropRect) { 136 static SkImageFilter* make_grayscale(SkImageFilter* input = NULL, const SkImageF ilter::CropRect* cropRect = NULL) {
137 SkScalar matrix[20]; 137 SkScalar matrix[20];
138 memset(matrix, 0, 20 * sizeof(SkScalar)); 138 memset(matrix, 0, 20 * sizeof(SkScalar));
139 matrix[0] = matrix[5] = matrix[10] = 0.2126f; 139 matrix[0] = matrix[5] = matrix[10] = 0.2126f;
140 matrix[1] = matrix[6] = matrix[11] = 0.7152f; 140 matrix[1] = matrix[6] = matrix[11] = 0.7152f;
141 matrix[2] = matrix[7] = matrix[12] = 0.0722f; 141 matrix[2] = matrix[7] = matrix[12] = 0.0722f;
142 matrix[18] = 1.0f; 142 matrix[18] = 1.0f;
143 SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix)); 143 SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix));
144 return SkColorFilterImageFilter::Create(filter, input, cropRect); 144 return SkColorFilterImageFilter::Create(filter, input, cropRect);
145 } 145 }
146 146
147 static SkImageFilter* make_blue(SkImageFilter* input, const SkImageFilter::CropR ect* cropRect) {
148 SkAutoTUnref<SkColorFilter> filter(SkColorFilter::CreateModeFilter(SK_ColorB LUE,
149 SkXfermod e::kSrcIn_Mode));
150 return SkColorFilterImageFilter::Create(filter, input, cropRect);
151 }
152
153 DEF_TEST(ImageFilter, reporter) { 147 DEF_TEST(ImageFilter, reporter) {
154 { 148 {
155 // Check that two non-clipping color-matrice-filters concatenate into a single filter. 149 // Check that two non-clipping color matrices concatenate into a single filter.
156 SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f)); 150 SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f));
157 SkAutoTUnref<SkImageFilter> quarterBrightness(make_scale(0.5f, halfBrigh tness)); 151 SkAutoTUnref<SkImageFilter> quarterBrightness(make_scale(0.5f, halfBrigh tness));
158 REPORTER_ASSERT(reporter, NULL == quarterBrightness->getInput(0)); 152 REPORTER_ASSERT(reporter, NULL == quarterBrightness->getInput(0));
159 SkColorFilter* cf;
160 REPORTER_ASSERT(reporter, quarterBrightness->asColorFilter(&cf));
161 REPORTER_ASSERT(reporter, cf->asColorMatrix(NULL));
162 cf->unref();
163 } 153 }
164 154
165 { 155 {
166 // Check that a clipping color-matrice-filter followed by a color-matric e-filters 156 // Check that a clipping color matrix followed by a grayscale does not c oncatenate into a single filter.
167 // concatenates into a single filter, but not a matrixfilter (due to cla mping).
168 SkAutoTUnref<SkImageFilter> doubleBrightness(make_scale(2.0f)); 157 SkAutoTUnref<SkImageFilter> doubleBrightness(make_scale(2.0f));
169 SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f, doubleBright ness)); 158 SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f, doubleBright ness));
170 REPORTER_ASSERT(reporter, NULL == halfBrightness->getInput(0)); 159 REPORTER_ASSERT(reporter, halfBrightness->getInput(0));
171 SkColorFilter* cf;
172 REPORTER_ASSERT(reporter, halfBrightness->asColorFilter(&cf));
173 REPORTER_ASSERT(reporter, !cf->asColorMatrix(NULL));
174 cf->unref();
175 } 160 }
176 161
177 { 162 {
178 // Check that a color filter image filter without a crop rect can be 163 // Check that a color filter image filter without a crop rect can be
179 // expressed as a color filter. 164 // expressed as a color filter.
180 SkAutoTUnref<SkImageFilter> gray(make_grayscale(NULL, NULL)); 165 SkAutoTUnref<SkImageFilter> gray(make_grayscale());
181 REPORTER_ASSERT(reporter, true == gray->asColorFilter(NULL)); 166 REPORTER_ASSERT(reporter, true == gray->asColorFilter(NULL));
182 } 167 }
183 168
184 {
185 // Check that a colorfilterimage filter without a crop rect but with an input
186 // that is another colorfilterimage can be expressed as a colorfilter (c omposed).
187 SkAutoTUnref<SkImageFilter> mode(make_blue(NULL, NULL));
188 SkAutoTUnref<SkImageFilter> gray(make_grayscale(mode, NULL));
189 REPORTER_ASSERT(reporter, true == gray->asColorFilter(NULL));
190 }
191
192 { 169 {
193 // Check that a color filter image filter with a crop rect cannot 170 // Check that a color filter image filter with a crop rect cannot
194 // be expressed as a color filter. 171 // be expressed as a color filter.
195 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(0, 0, 100, 100)); 172 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(0, 0, 100, 100));
196 SkAutoTUnref<SkImageFilter> grayWithCrop(make_grayscale(NULL, &cropRect) ); 173 SkAutoTUnref<SkImageFilter> grayWithCrop(make_grayscale(NULL, &cropRect) );
197 REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(NULL)); 174 REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(NULL));
198 } 175 }
199 176
200 { 177 {
201 // Check that two non-commutative matrices are concatenated in 178 // Check that two non-commutative matrices are concatenated in
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 DEF_GPUTEST(TestNegativeBlurSigmaGPU, reporter, factory) { 1137 DEF_GPUTEST(TestNegativeBlurSigmaGPU, reporter, factory) {
1161 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0)); 1138 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0));
1162 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, 1139 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
1163 SkSurface::kNo_Budgeted , 1140 SkSurface::kNo_Budgeted ,
1164 SkImageInfo::MakeN32Pre mul(1, 1), 1141 SkImageInfo::MakeN32Pre mul(1, 1),
1165 0, 1142 0,
1166 &gProps)); 1143 &gProps));
1167 test_negative_blur_sigma(device, reporter); 1144 test_negative_blur_sigma(device, reporter);
1168 } 1145 }
1169 #endif 1146 #endif
OLDNEW
« 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