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 "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 Loading... |
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 = NULL, const SkImageF
ilter::CropRect* cropRect = NULL) { | 136 static SkImageFilter* make_grayscale(SkImageFilter* input, const SkImageFilter::
CropRect* cropRect) { |
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 |
147 DEF_TEST(ImageFilter, reporter) { | 153 DEF_TEST(ImageFilter, reporter) { |
148 { | 154 { |
149 // Check that two non-clipping color matrices concatenate into a single
filter. | 155 // Check that two non-clipping color-matrice-filters concatenate into a
single filter. |
150 SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f)); | 156 SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f)); |
151 SkAutoTUnref<SkImageFilter> quarterBrightness(make_scale(0.5f, halfBrigh
tness)); | 157 SkAutoTUnref<SkImageFilter> quarterBrightness(make_scale(0.5f, halfBrigh
tness)); |
152 REPORTER_ASSERT(reporter, NULL == quarterBrightness->getInput(0)); | 158 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(); |
153 } | 163 } |
154 | 164 |
155 { | 165 { |
156 // Check that a clipping color matrix followed by a grayscale does not c
oncatenate into a single filter. | 166 // Check that a clipping color-matrice-filter followed by a color-matric
e-filters |
| 167 // concatenates into a single filter, but not a matrixfilter (due to cla
mping). |
157 SkAutoTUnref<SkImageFilter> doubleBrightness(make_scale(2.0f)); | 168 SkAutoTUnref<SkImageFilter> doubleBrightness(make_scale(2.0f)); |
158 SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f, doubleBright
ness)); | 169 SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f, doubleBright
ness)); |
159 REPORTER_ASSERT(reporter, halfBrightness->getInput(0)); | 170 REPORTER_ASSERT(reporter, NULL == halfBrightness->getInput(0)); |
| 171 SkColorFilter* cf; |
| 172 REPORTER_ASSERT(reporter, halfBrightness->asColorFilter(&cf)); |
| 173 REPORTER_ASSERT(reporter, !cf->asColorMatrix(NULL)); |
| 174 cf->unref(); |
160 } | 175 } |
161 | 176 |
162 { | 177 { |
163 // Check that a color filter image filter without a crop rect can be | 178 // Check that a color filter image filter without a crop rect can be |
164 // expressed as a color filter. | 179 // expressed as a color filter. |
165 SkAutoTUnref<SkImageFilter> gray(make_grayscale()); | 180 SkAutoTUnref<SkImageFilter> gray(make_grayscale(NULL, NULL)); |
166 REPORTER_ASSERT(reporter, true == gray->asColorFilter(NULL)); | 181 REPORTER_ASSERT(reporter, true == gray->asColorFilter(NULL)); |
167 } | 182 } |
| 183 |
| 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 { |
| 193 // Test that if we exceed the limit of what ComposeColorFilter can combi
ne, we still |
| 194 // can build the DAG and won't assert if we call asColorFilter. |
| 195 SkAutoTUnref<SkImageFilter> filter(make_blue(NULL, NULL)); |
| 196 const int kWayTooManyForComposeColorFilter = 100; |
| 197 for (int i = 0; i < kWayTooManyForComposeColorFilter; ++i) { |
| 198 filter.reset(make_blue(filter, NULL)); |
| 199 // the first few of these will succeed, but after we hit the interna
l limit, |
| 200 // it will then return false. |
| 201 (void)filter->asColorFilter(NULL); |
| 202 } |
| 203 } |
168 | 204 |
169 { | 205 { |
170 // Check that a color filter image filter with a crop rect cannot | 206 // Check that a color filter image filter with a crop rect cannot |
171 // be expressed as a color filter. | 207 // be expressed as a color filter. |
172 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(0, 0, 100, 100)); | 208 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(0, 0, 100, 100)); |
173 SkAutoTUnref<SkImageFilter> grayWithCrop(make_grayscale(NULL, &cropRect)
); | 209 SkAutoTUnref<SkImageFilter> grayWithCrop(make_grayscale(NULL, &cropRect)
); |
174 REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(NULL)); | 210 REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(NULL)); |
175 } | 211 } |
176 | 212 |
177 { | 213 { |
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1137 DEF_GPUTEST(TestNegativeBlurSigmaGPU, reporter, factory) { | 1173 DEF_GPUTEST(TestNegativeBlurSigmaGPU, reporter, factory) { |
1138 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); | 1174 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); |
1139 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 1175 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
1140 SkSurface::kNo_Budgeted
, | 1176 SkSurface::kNo_Budgeted
, |
1141 SkImageInfo::MakeN32Pre
mul(1, 1), | 1177 SkImageInfo::MakeN32Pre
mul(1, 1), |
1142 0, | 1178 0, |
1143 &gProps)); | 1179 &gProps)); |
1144 test_negative_blur_sigma(device, reporter); | 1180 test_negative_blur_sigma(device, reporter); |
1145 } | 1181 } |
1146 #endif | 1182 #endif |
OLD | NEW |