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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kCl
amp_TileMode); | 118 return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kCl
amp_TileMode); |
119 } | 119 } |
120 | 120 |
121 static SkShader* make_cf_sh() { | 121 static SkShader* make_cf_sh() { |
122 SkAutoTUnref<SkColorFilter> filter(make_mx_cf()); | 122 SkAutoTUnref<SkColorFilter> filter(make_mx_cf()); |
123 SkAutoTUnref<SkShader> shader(make_color_sh()); | 123 SkAutoTUnref<SkShader> shader(make_color_sh()); |
124 return shader->newWithColorFilter(filter); | 124 return shader->newWithColorFilter(filter); |
125 } | 125 } |
126 | 126 |
127 static void compare_spans(const SkPM4f span4f[], const SkPMColor span4b[], int c
ount, | 127 static void compare_spans(const SkPM4f span4f[], const SkPMColor span4b[], int c
ount, |
128 skiatest::Reporter* reporter) { | 128 skiatest::Reporter* reporter, float tolerance = 1.0f/2
55) { |
129 for (int i = 0; i < count; ++i) { | 129 for (int i = 0; i < count; ++i) { |
130 SkPM4f c0 = SkPM4f::FromPMColor(span4b[i]); | 130 SkPM4f c0 = SkPM4f::FromPMColor(span4b[i]); |
131 SkPM4f c1 = span4f[i]; | 131 SkPM4f c1 = span4f[i]; |
132 REPORTER_ASSERT(reporter, nearly_equal(c0, c1, 1.0f/255)); | 132 REPORTER_ASSERT(reporter, nearly_equal(c0, c1, tolerance)); |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 DEF_TEST(Color4f_shader, reporter) { | 136 DEF_TEST(Color4f_shader, reporter) { |
137 struct { | 137 struct { |
138 SkShader* (*fFact)(); | 138 SkShader* (*fFact)(); |
139 bool fSupports4f; | 139 bool fSupports4f; |
| 140 float fTolerance; |
140 } recs[] = { | 141 } recs[] = { |
141 { make_color_sh, true }, | 142 { make_color_sh, true, 1.0f/255 }, |
142 { make_grad_sh, false }, | 143 // PMColor 4f gradients are interpolated in 255-multiplied values, so we
need a |
143 { make_image_sh, false }, | 144 // slightly relaxed tolerance to accommodate the cumulative precision de
viation. |
144 { make_cf_sh, true }, | 145 { make_grad_sh, true, 1.001f/255 }, |
| 146 { make_image_sh, false, 1.0f/255 }, |
| 147 { make_cf_sh, true, 1.0f/255 }, |
145 }; | 148 }; |
146 | 149 |
147 SkPaint paint; | 150 SkPaint paint; |
148 for (const auto& rec : recs) { | 151 for (const auto& rec : recs) { |
149 uint32_t storage[200]; | 152 uint32_t storage[200]; |
150 paint.setShader(rec.fFact())->unref(); | 153 paint.setShader(rec.fFact())->unref(); |
151 // Encourage 4f context selection. At some point we may need | 154 // Encourage 4f context selection. At some point we may need |
152 // to instantiate two separate contexts for optimal 4b/4f selection. | 155 // to instantiate two separate contexts for optimal 4b/4f selection. |
153 const SkShader::ContextRec contextRec(paint, SkMatrix::I(), nullptr, | 156 const SkShader::ContextRec contextRec(paint, SkMatrix::I(), nullptr, |
154 SkShader::ContextRec::kPM4f_DstTyp
e); | 157 SkShader::ContextRec::kPM4f_DstTyp
e); |
155 SkASSERT(paint.getShader()->contextSize(contextRec) <= sizeof(storage)); | 158 SkASSERT(paint.getShader()->contextSize(contextRec) <= sizeof(storage)); |
156 SkShader::Context* ctx = paint.getShader()->createContext(contextRec, st
orage); | 159 SkShader::Context* ctx = paint.getShader()->createContext(contextRec, st
orage); |
157 REPORTER_ASSERT(reporter, ctx->supports4f() == rec.fSupports4f); | 160 REPORTER_ASSERT(reporter, ctx->supports4f() == rec.fSupports4f); |
158 if (ctx->supports4f()) { | 161 if (ctx->supports4f()) { |
159 const int N = 100; | 162 const int N = 100; |
160 SkPM4f buffer4f[N]; | 163 SkPM4f buffer4f[N]; |
161 ctx->shadeSpan4f(0, 0, buffer4f, N); | 164 ctx->shadeSpan4f(0, 0, buffer4f, N); |
162 SkPMColor buffer4b[N]; | 165 SkPMColor buffer4b[N]; |
163 ctx->shadeSpan(0, 0, buffer4b, N); | 166 ctx->shadeSpan(0, 0, buffer4b, N); |
164 compare_spans(buffer4f, buffer4b, N, reporter); | 167 compare_spans(buffer4f, buffer4b, N, reporter, rec.fTolerance); |
165 } | 168 } |
166 ctx->~Context(); | 169 ctx->~Context(); |
167 } | 170 } |
168 } | 171 } |
169 | 172 |
170 DEF_TEST(Color4f_colorfilter, reporter) { | 173 DEF_TEST(Color4f_colorfilter, reporter) { |
171 struct { | 174 struct { |
172 SkColorFilter* (*fFact)(); | 175 SkColorFilter* (*fFact)(); |
173 bool fSupports4f; | 176 bool fSupports4f; |
174 } recs[] = { | 177 } recs[] = { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 // | 236 // |
234 DEF_TEST(Color4f_xfermode_proc4f, reporter) { | 237 DEF_TEST(Color4f_xfermode_proc4f, reporter) { |
235 // TODO: extend xfermodes so that all cases can be tested. | 238 // TODO: extend xfermodes so that all cases can be tested. |
236 // | 239 // |
237 for (int mode = SkXfermode::kClear_Mode; mode <= SkXfermode::kScreen_Mode; +
+mode) { | 240 for (int mode = SkXfermode::kClear_Mode; mode <= SkXfermode::kScreen_Mode; +
+mode) { |
238 SkXfermodeProc proc32 = SkXfermode::GetProc((SkXfermode::Mode)mode); | 241 SkXfermodeProc proc32 = SkXfermode::GetProc((SkXfermode::Mode)mode); |
239 SkXfermodeProc4f proc4f = SkXfermode::GetProc4f((SkXfermode::Mode)mode); | 242 SkXfermodeProc4f proc4f = SkXfermode::GetProc4f((SkXfermode::Mode)mode); |
240 REPORTER_ASSERT(reporter, compare_procs(proc32, proc4f)); | 243 REPORTER_ASSERT(reporter, compare_procs(proc32, proc4f)); |
241 } | 244 } |
242 } | 245 } |
OLD | NEW |