OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkColor.h" | 8 #include "SkColor.h" |
9 #include "SkColorMatrixFilter.h" | 9 #include "SkColorMatrixFilter.h" |
10 #include "SkGradientShader.h" | 10 #include "SkGradientShader.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 } | 161 } |
162 ctx->~Context(); | 162 ctx->~Context(); |
163 } | 163 } |
164 } | 164 } |
165 | 165 |
166 DEF_TEST(Color4f_colorfilter, reporter) { | 166 DEF_TEST(Color4f_colorfilter, reporter) { |
167 struct { | 167 struct { |
168 SkColorFilter* (*fFact)(); | 168 SkColorFilter* (*fFact)(); |
169 bool fSupports4f; | 169 bool fSupports4f; |
170 } recs[] = { | 170 } recs[] = { |
171 { make_mode_cf, false }, | 171 { make_mode_cf, true }, |
172 { make_mx_cf, true }, | 172 { make_mx_cf, true }, |
173 { make_compose_cf, false }, | 173 { make_compose_cf, true }, |
174 }; | 174 }; |
175 | 175 |
176 // prepare the src | 176 // prepare the src |
177 const int N = 100; | 177 const int N = 100; |
178 SkPMColor src4b[N]; | 178 SkPMColor src4b[N]; |
179 SkPM4f src4f[N]; | 179 SkPM4f src4f[N]; |
180 SkRandom rand; | 180 SkRandom rand; |
181 for (int i = 0; i < N; ++i) { | 181 for (int i = 0; i < N; ++i) { |
182 src4b[i] = SkPreMultiplyColor(rand.nextU()); | 182 src4b[i] = SkPreMultiplyColor(rand.nextU()); |
183 src4f[i] = SkPM4f::FromPMColor(src4b[i]); | 183 src4f[i] = SkPM4f::FromPMColor(src4b[i]); |
184 } | 184 } |
185 // confirm that our srcs are (nearly) equal | 185 // confirm that our srcs are (nearly) equal |
186 compare_spans(src4f, src4b, N, reporter); | 186 compare_spans(src4f, src4b, N, reporter); |
187 | 187 |
188 for (const auto& rec : recs) { | 188 for (const auto& rec : recs) { |
189 SkAutoTUnref<SkColorFilter> filter(rec.fFact()); | 189 SkAutoTUnref<SkColorFilter> filter(rec.fFact()); |
190 REPORTER_ASSERT(reporter, filter->supports4f() == rec.fSupports4f); | 190 REPORTER_ASSERT(reporter, filter->supports4f() == rec.fSupports4f); |
191 if (filter->supports4f()) { | 191 if (filter->supports4f()) { |
192 SkPMColor dst4b[N]; | 192 SkPMColor dst4b[N]; |
193 filter->filterSpan(src4b, N, dst4b); | 193 filter->filterSpan(src4b, N, dst4b); |
194 SkPM4f dst4f[N]; | 194 SkPM4f dst4f[N]; |
195 filter->filterSpan4f(src4f, N, dst4f); | 195 filter->filterSpan4f(src4f, N, dst4f); |
196 compare_spans(dst4f, dst4b, N, reporter); | 196 compare_spans(dst4f, dst4b, N, reporter); |
197 } | 197 } |
198 } | 198 } |
199 } | 199 } |
| 200 |
| 201 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 202 |
| 203 typedef SkPM4f (*SkXfermodeProc4f)(const SkPM4f& src, const SkPM4f& dst); |
| 204 |
| 205 static bool compare_procs(SkXfermodeProc proc32, SkXfermodeProc4f proc4f) { |
| 206 const float kTolerance = 1.0f / 255; |
| 207 |
| 208 const SkColor colors[] = { |
| 209 0, 0xFF000000, 0xFFFFFFFF, 0x80FF0000 |
| 210 }; |
| 211 |
| 212 for (auto s32 : colors) { |
| 213 SkPMColor s_pm32 = SkPreMultiplyColor(s32); |
| 214 SkPM4f s_pm4f = SkColor4f::FromColor(s32).premul(); |
| 215 for (auto d32 : colors) { |
| 216 SkPMColor d_pm32 = SkPreMultiplyColor(d32); |
| 217 SkPM4f d_pm4f = SkColor4f::FromColor(d32).premul(); |
| 218 |
| 219 SkPMColor r32 = proc32(s_pm32, d_pm32); |
| 220 SkPM4f r4f = proc4f(s_pm4f, d_pm4f); |
| 221 |
| 222 SkPM4f r32_4f = SkPM4f::FromPMColor(r32); |
| 223 if (!nearly_equal(r4f, r32_4f, kTolerance)) { |
| 224 return false; |
| 225 } |
| 226 } |
| 227 } |
| 228 return true; |
| 229 } |
| 230 |
| 231 // Check that our Proc and Proc4f return (nearly) the same results |
| 232 // |
| 233 DEF_TEST(Color4f_xfermode_proc4f, reporter) { |
| 234 // TODO: extend xfermodes so that all cases can be tested. |
| 235 // |
| 236 for (int mode = SkXfermode::kClear_Mode; mode <= SkXfermode::kScreen_Mode; +
+mode) { |
| 237 SkXfermodeProc proc32 = SkXfermode::GetProc((SkXfermode::Mode)mode); |
| 238 SkXfermodeProc4f proc4f = SkXfermode::GetProc4f((SkXfermode::Mode)mode); |
| 239 REPORTER_ASSERT(reporter, compare_procs(proc32, proc4f)); |
| 240 } |
| 241 } |
OLD | NEW |