1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "Test.h"
9
10 #include "GrBackendSurface.h"
11 #include "GrContextFactory.h"
12 #include "GrContextOptions.h"
13 #include "GrContextPriv.h"
14 #include "GrGpu.h"
15 #include "GrProxyProvider.h"
16 #include "GrXferProcessor.h"
17 #include "effects/GrPorterDuffXferProcessor.h"
18 #include "gl/GrGLCaps.h"
19 #include "ops/GrMeshDrawOp.h"
20
21 ////////////////////////////////////////////////////////////////////////////////
22
23 static void test_color_unknown_with_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
24 static void test_color_not_opaque_no_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
25 static void test_color_opaque_with_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
26 static void test_color_opaque_no_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
27 static void test_lcd_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
28 static void test_lcd_coverage_fallback_case(skiatest::Reporter* reporter, const GrCaps& caps);
29
DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrPorterDuff,reporter,ctxInfo)30 DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrPorterDuff, reporter, ctxInfo) {
31 const GrCaps& caps = *ctxInfo.grContext()->priv().getGpu()->caps();
32 if (!caps.shaderCaps()->dualSourceBlendingSupport()) {
33 SK_ABORT("Null context does not support dual source blending.");
34 return;
35 }
36
37 test_color_unknown_with_coverage(reporter, caps);
38 test_color_not_opaque_no_coverage(reporter, caps);
39 test_color_opaque_with_coverage(reporter, caps);
40 test_color_opaque_no_coverage(reporter, caps);
41 test_lcd_coverage(reporter, caps);
42 test_lcd_coverage_fallback_case(reporter, caps);
43 }
44
45 ////////////////////////////////////////////////////////////////////////////////
46
47 #define TEST_ASSERT(...) REPORTER_ASSERT(reporter, __VA_ARGS__)
48
49 enum {
50 kNone_OutputType,
51 kCoverage_OutputType,
52 kModulate_OutputType,
53 kSAModulate_OutputType,
54 kISAModulate_OutputType,
55 kISCModulate_OutputType
56 };
57 static const int kInvalid_OutputType = -1;
58
do_analysis(const GrXPFactory * xpf,const GrProcessorAnalysisColor & colorInput,GrProcessorAnalysisCoverage coverageInput,const GrCaps & caps)59 static GrProcessorSet::Analysis do_analysis(const GrXPFactory* xpf,
60 const GrProcessorAnalysisColor& colorInput,
61 GrProcessorAnalysisCoverage coverageInput,
62 const GrCaps& caps) {
63 GrPaint paint;
64 paint.setXPFactory(xpf);
65 GrProcessorSet procs(std::move(paint));
66 SkPMColor4f overrideColor;
67 GrProcessorSet::Analysis analysis = procs.finalize(
68 colorInput, coverageInput, nullptr, &GrUserStencilSettings::kUnused, GrFSAAType::kNone,
69 caps, GrClampType::kAuto, &overrideColor);
70 return analysis;
71 }
72
73 class GrPorterDuffTest {
74 public:
75 struct XPInfo {
XPInfoGrPorterDuffTest::XPInfo76 XPInfo(skiatest::Reporter* reporter, SkBlendMode xfermode, const GrCaps& caps,
77 GrProcessorAnalysisColor inputColor, GrProcessorAnalysisCoverage inputCoverage) {
78 const GrXPFactory* xpf = GrPorterDuffXPFactory::Get(xfermode);
79
80 bool isLCD = GrProcessorAnalysisCoverage::kLCD == inputCoverage;
81
82 GrProcessorSet::Analysis analysis = do_analysis(xpf, inputColor, inputCoverage, caps);
83 fCompatibleWithCoverageAsAlpha = analysis.isCompatibleWithCoverageAsAlpha();
84 fIgnoresInputColor = analysis.inputColorIsIgnored();
85 sk_sp<const GrXferProcessor> xp(
86 GrXPFactory::MakeXferProcessor(xpf, inputColor, inputCoverage, false, caps,
87 GrClampType::kAuto));
88 TEST_ASSERT(!analysis.requiresDstTexture() ||
89 (isLCD &&
90 !caps.shaderCaps()->dstReadInShaderSupport() &&
91 (SkBlendMode::kSrcOver != xfermode ||
92 !inputColor.isOpaque())));
93 // Porter Duff modes currently only use fixed-function or shader blending, and Ganesh
94 // doesn't yet make use of framebuffer fetches that require a barrier
95 // (e.g., QCOM_shader_framebuffer_fetch_noncoherent). So dst textures and xfer barriers
96 // should always go hand in hand for Porter Duff modes.
97 TEST_ASSERT(analysis.requiresDstTexture() == analysis.requiresNonOverlappingDraws());
98 GetXPOutputTypes(xp.get(), &fPrimaryOutputType, &fSecondaryOutputType);
99 xp->getBlendInfo(&fBlendInfo);
100 TEST_ASSERT(!xp->willReadDstColor() ||
101 (isLCD && (SkBlendMode::kSrcOver != xfermode ||
102 !inputColor.isOpaque())));
103 TEST_ASSERT(xp->hasSecondaryOutput() == GrBlendCoeffRefsSrc2(fBlendInfo.fDstBlend));
104 }
105
106 bool fCompatibleWithCoverageAsAlpha;
107 bool fIgnoresInputColor;
108 int fPrimaryOutputType;
109 int fSecondaryOutputType;
110 GrXferProcessor::BlendInfo fBlendInfo;
111 };
112
GetXPOutputTypes(const GrXferProcessor * xp,int * outPrimary,int * outSecondary)113 static void GetXPOutputTypes(const GrXferProcessor* xp, int* outPrimary, int* outSecondary) {
114 GrPorterDuffXPFactory::TestGetXPOutputTypes(xp, outPrimary, outSecondary);
115 }
116 };
117
test_lcd_coverage(skiatest::Reporter * reporter,const GrCaps & caps)118 static void test_lcd_coverage(skiatest::Reporter* reporter, const GrCaps& caps) {
119 GrProcessorAnalysisColor inputColor = GrProcessorAnalysisColor::Opaque::kYes;
120 GrProcessorAnalysisCoverage inputCoverage = GrProcessorAnalysisCoverage::kLCD;
121
122 for (int m = 0; m <= (int)SkBlendMode::kLastCoeffMode; m++) {
123 SkBlendMode xfermode = static_cast<SkBlendMode>(m);
124 const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, inputColor, inputCoverage);
125 switch (xfermode) {
126 case SkBlendMode::kClear:
127 TEST_ASSERT(xpi.fIgnoresInputColor);
128 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
129 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
130 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
131 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
132 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
133 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
134 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
135 break;
136 case SkBlendMode::kSrc:
137 TEST_ASSERT(!xpi.fIgnoresInputColor);
138 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
139 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
140 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
141 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
142 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
143 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
144 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
145 break;
146 case SkBlendMode::kDst:
147 TEST_ASSERT(xpi.fIgnoresInputColor);
148 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
149 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
150 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
151 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
152 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
153 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
154 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
155 break;
156 case SkBlendMode::kSrcOver:
157 TEST_ASSERT(!xpi.fIgnoresInputColor);
158 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
159 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
160 TEST_ASSERT(kSAModulate_OutputType == xpi.fSecondaryOutputType);
161 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
162 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
163 TEST_ASSERT(kIS2C_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
164 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
165 break;
166 case SkBlendMode::kDstOver:
167 TEST_ASSERT(!xpi.fIgnoresInputColor);
168 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
169 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
170 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
171 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
172 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
173 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
174 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
175 break;
176 case SkBlendMode::kSrcIn:
177 TEST_ASSERT(!xpi.fIgnoresInputColor);
178 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
179 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
180 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
181 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
182 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
183 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
184 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
185 break;
186 case SkBlendMode::kDstIn:
187 TEST_ASSERT(!xpi.fIgnoresInputColor);
188 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
189 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
190 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
191 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
192 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
193 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
194 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
195 break;
196 case SkBlendMode::kSrcOut:
197 TEST_ASSERT(!xpi.fIgnoresInputColor);
198 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
199 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
200 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
201 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
202 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
203 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
204 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
205 break;
206 case SkBlendMode::kDstOut:
207 TEST_ASSERT(!xpi.fIgnoresInputColor);
208 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
209 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
210 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
211 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
212 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
213 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
214 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
215 break;
216 case SkBlendMode::kSrcATop:
217 TEST_ASSERT(!xpi.fIgnoresInputColor);
218 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
219 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
220 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
221 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
222 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
223 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
224 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
225 break;
226 case SkBlendMode::kDstATop:
227 TEST_ASSERT(!xpi.fIgnoresInputColor);
228 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
229 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
230 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
231 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
232 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
233 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
234 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
235 break;
236 case SkBlendMode::kXor:
237 TEST_ASSERT(!xpi.fIgnoresInputColor);
238 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
239 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
240 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
241 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
242 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
243 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
244 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
245 break;
246 case SkBlendMode::kPlus:
247 TEST_ASSERT(!xpi.fIgnoresInputColor);
248 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
249 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
250 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
251 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
252 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
253 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
254 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
255 break;
256 case SkBlendMode::kModulate:
257 TEST_ASSERT(!xpi.fIgnoresInputColor);
258 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
259 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
260 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
261 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
262 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
263 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
264 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
265 break;
266 case SkBlendMode::kScreen:
267 TEST_ASSERT(!xpi.fIgnoresInputColor);
268 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
269 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
270 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
271 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
272 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
273 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
274 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
275 break;
276 default:
277 ERRORF(reporter, "Invalid xfermode.");
278 break;
279 }
280 }
281 }
test_color_unknown_with_coverage(skiatest::Reporter * reporter,const GrCaps & caps)282 static void test_color_unknown_with_coverage(skiatest::Reporter* reporter, const GrCaps& caps) {
283 GrProcessorAnalysisColor inputColor = GrProcessorAnalysisColor::Opaque::kNo;
284 GrProcessorAnalysisCoverage inputCoverage = GrProcessorAnalysisCoverage::kSingleChannel;
285
286 for (int m = 0; m <= (int)SkBlendMode::kLastCoeffMode; m++) {
287 SkBlendMode xfermode = static_cast<SkBlendMode>(m);
288 const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, inputColor, inputCoverage);
289 switch (xfermode) {
290 case SkBlendMode::kClear:
291 TEST_ASSERT(xpi.fIgnoresInputColor);
292 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
293 TEST_ASSERT(kCoverage_OutputType == xpi.fPrimaryOutputType);
294 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
295 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.fEquation);
296 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
297 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
298 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
299 break;
300 case SkBlendMode::kSrc:
301 TEST_ASSERT(!xpi.fIgnoresInputColor);
302 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
303 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
304 TEST_ASSERT(kCoverage_OutputType == xpi.fSecondaryOutputType);
305 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
306 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
307 TEST_ASSERT(kIS2A_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
308 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
309 break;
310 case SkBlendMode::kDst:
311 TEST_ASSERT(xpi.fIgnoresInputColor);
312 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
313 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
314 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
315 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
316 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
317 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
318 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor);
319 break;
320 case SkBlendMode::kSrcOver:
321 TEST_ASSERT(!xpi.fIgnoresInputColor);
322 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
323 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
324 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
325 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
326 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
327 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
328 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
329 break;
330 case SkBlendMode::kDstOver:
331 TEST_ASSERT(!xpi.fIgnoresInputColor);
332 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
333 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
334 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
335 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
336 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
337 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
338 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
339 break;
340 case SkBlendMode::kSrcIn:
341 TEST_ASSERT(!xpi.fIgnoresInputColor);
342 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
343 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
344 TEST_ASSERT(kCoverage_OutputType == xpi.fSecondaryOutputType);
345 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
346 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
347 TEST_ASSERT(kIS2A_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
348 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
349 break;
350 case SkBlendMode::kDstIn:
351 TEST_ASSERT(!xpi.fIgnoresInputColor);
352 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
353 TEST_ASSERT(kISAModulate_OutputType == xpi.fPrimaryOutputType);
354 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
355 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.fEquation);
356 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
357 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
358 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
359 break;
360 case SkBlendMode::kSrcOut:
361 TEST_ASSERT(!xpi.fIgnoresInputColor);
362 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
363 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
364 TEST_ASSERT(kCoverage_OutputType == xpi.fSecondaryOutputType);
365 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
366 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
367 TEST_ASSERT(kIS2A_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
368 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
369 break;
370 case SkBlendMode::kDstOut:
371 TEST_ASSERT(!xpi.fIgnoresInputColor);
372 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
373 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
374 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
375 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
376 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
377 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
378 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
379 break;
380 case SkBlendMode::kSrcATop:
381 TEST_ASSERT(!xpi.fIgnoresInputColor);
382 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
383 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
384 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
385 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
386 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
387 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
388 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
389 break;
390 case SkBlendMode::kDstATop:
391 TEST_ASSERT(!xpi.fIgnoresInputColor);
392 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
393 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
394 TEST_ASSERT(kISAModulate_OutputType == xpi.fSecondaryOutputType);
395 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
396 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
397 TEST_ASSERT(kIS2C_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
398 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
399 break;
400 case SkBlendMode::kXor:
401 TEST_ASSERT(!xpi.fIgnoresInputColor);
402 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
403 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
404 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
405 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
406 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
407 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
408 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
409 break;
410 case SkBlendMode::kPlus:
411 TEST_ASSERT(!xpi.fIgnoresInputColor);
412 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
413 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
414 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
415 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
416 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
417 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
418 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
419 break;
420 case SkBlendMode::kModulate:
421 TEST_ASSERT(!xpi.fIgnoresInputColor);
422 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
423 TEST_ASSERT(kISCModulate_OutputType == xpi.fPrimaryOutputType);
424 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
425 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.fEquation);
426 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
427 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
428 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
429 break;
430 case SkBlendMode::kScreen:
431 TEST_ASSERT(!xpi.fIgnoresInputColor);
432 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
433 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
434 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
435 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
436 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
437 TEST_ASSERT(kISC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
438 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
439 break;
440 default:
441 ERRORF(reporter, "Invalid xfermode.");
442 break;
443 }
444 }
445 }
446
test_color_not_opaque_no_coverage(skiatest::Reporter * reporter,const GrCaps & caps)447 static void test_color_not_opaque_no_coverage(skiatest::Reporter* reporter, const GrCaps& caps) {
448 GrProcessorAnalysisColor inputColor(
449 SkPMColor4f::FromBytes_RGBA(GrColorPackRGBA(229, 0, 154, 240)));
450 GrProcessorAnalysisCoverage inputCoverage = GrProcessorAnalysisCoverage::kNone;
451
452 for (int m = 0; m <= (int)SkBlendMode::kLastCoeffMode; m++) {
453 SkBlendMode xfermode = static_cast<SkBlendMode>(m);
454 const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, inputColor, inputCoverage);
455 switch (xfermode) {
456 case SkBlendMode::kClear:
457 TEST_ASSERT(xpi.fIgnoresInputColor);
458 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
459 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
460 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
461 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
462 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
463 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
464 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
465 break;
466 case SkBlendMode::kSrc:
467 TEST_ASSERT(!xpi.fIgnoresInputColor);
468 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
469 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
470 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
471 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
472 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
473 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
474 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
475 break;
476 case SkBlendMode::kDst:
477 TEST_ASSERT(xpi.fIgnoresInputColor);
478 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
479 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
480 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
481 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
482 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
483 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
484 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor);
485 break;
486 case SkBlendMode::kSrcOver:
487 TEST_ASSERT(!xpi.fIgnoresInputColor);
488 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
489 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
490 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
491 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
492 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
493 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
494 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
495 break;
496 case SkBlendMode::kDstOver:
497 TEST_ASSERT(!xpi.fIgnoresInputColor);
498 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
499 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
500 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
501 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
502 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
503 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
504 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
505 break;
506 case SkBlendMode::kSrcIn:
507 TEST_ASSERT(!xpi.fIgnoresInputColor);
508 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
509 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
510 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
511 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
512 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
513 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
514 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
515 break;
516 case SkBlendMode::kDstIn:
517 TEST_ASSERT(!xpi.fIgnoresInputColor);
518 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
519 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
520 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
521 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
522 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
523 TEST_ASSERT(kSA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
524 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
525 break;
526 case SkBlendMode::kSrcOut:
527 TEST_ASSERT(!xpi.fIgnoresInputColor);
528 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
529 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
530 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
531 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
532 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
533 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
534 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
535 break;
536 case SkBlendMode::kDstOut:
537 TEST_ASSERT(!xpi.fIgnoresInputColor);
538 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
539 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
540 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
541 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
542 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
543 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
544 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
545 break;
546 case SkBlendMode::kSrcATop:
547 TEST_ASSERT(!xpi.fIgnoresInputColor);
548 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
549 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
550 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
551 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
552 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
553 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
554 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
555 break;
556 case SkBlendMode::kDstATop:
557 TEST_ASSERT(!xpi.fIgnoresInputColor);
558 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
559 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
560 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
561 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
562 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
563 TEST_ASSERT(kSA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
564 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
565 break;
566 case SkBlendMode::kXor:
567 TEST_ASSERT(!xpi.fIgnoresInputColor);
568 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
569 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
570 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
571 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
572 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
573 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
574 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
575 break;
576 case SkBlendMode::kPlus:
577 TEST_ASSERT(!xpi.fIgnoresInputColor);
578 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
579 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
580 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
581 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
582 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
583 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
584 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
585 break;
586 case SkBlendMode::kModulate:
587 TEST_ASSERT(!xpi.fIgnoresInputColor);
588 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
589 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
590 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
591 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
592 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
593 TEST_ASSERT(kSC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
594 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
595 break;
596 case SkBlendMode::kScreen:
597 TEST_ASSERT(!xpi.fIgnoresInputColor);
598 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
599 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
600 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
601 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
602 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
603 TEST_ASSERT(kISC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
604 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
605 break;
606 default:
607 ERRORF(reporter, "Invalid xfermode.");
608 break;
609 }
610 }
611 }
612
test_color_opaque_with_coverage(skiatest::Reporter * reporter,const GrCaps & caps)613 static void test_color_opaque_with_coverage(skiatest::Reporter* reporter, const GrCaps& caps) {
614 GrProcessorAnalysisColor inputColor = GrProcessorAnalysisColor::Opaque::kYes;
615 GrProcessorAnalysisCoverage inputCoverage = GrProcessorAnalysisCoverage::kSingleChannel;
616
617 for (int m = 0; m <= (int)SkBlendMode::kLastCoeffMode; m++) {
618 SkBlendMode xfermode = static_cast<SkBlendMode>(m);
619 const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, inputColor, inputCoverage);
620 switch (xfermode) {
621 case SkBlendMode::kClear:
622 TEST_ASSERT(xpi.fIgnoresInputColor);
623 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
624 TEST_ASSERT(kCoverage_OutputType == xpi.fPrimaryOutputType);
625 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
626 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.fEquation);
627 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
628 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
629 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
630 break;
631 case SkBlendMode::kSrc:
632 TEST_ASSERT(!xpi.fIgnoresInputColor);
633 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
634 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
635 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
636 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
637 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
638 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
639 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
640 break;
641 case SkBlendMode::kDst:
642 TEST_ASSERT(xpi.fIgnoresInputColor);
643 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
644 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
645 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
646 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
647 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
648 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
649 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor);
650 break;
651 case SkBlendMode::kSrcOver:
652 TEST_ASSERT(!xpi.fIgnoresInputColor);
653 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
654 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
655 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
656 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
657 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
658 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
659 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
660 break;
661 case SkBlendMode::kDstOver:
662 TEST_ASSERT(!xpi.fIgnoresInputColor);
663 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
664 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
665 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
666 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
667 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
668 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
669 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
670 break;
671 case SkBlendMode::kSrcIn:
672 TEST_ASSERT(!xpi.fIgnoresInputColor);
673 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
674 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
675 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
676 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
677 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
678 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
679 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
680 break;
681 case SkBlendMode::kDstIn:
682 TEST_ASSERT(xpi.fIgnoresInputColor);
683 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
684 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
685 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
686 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
687 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
688 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
689 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor);
690 break;
691 case SkBlendMode::kSrcOut:
692 TEST_ASSERT(!xpi.fIgnoresInputColor);
693 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
694 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
695 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
696 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
697 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
698 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
699 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
700 break;
701 case SkBlendMode::kDstOut:
702 TEST_ASSERT(xpi.fIgnoresInputColor);
703 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
704 TEST_ASSERT(kCoverage_OutputType == xpi.fPrimaryOutputType);
705 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
706 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.fEquation);
707 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
708 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
709 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
710 break;
711 case SkBlendMode::kSrcATop:
712 TEST_ASSERT(!xpi.fIgnoresInputColor);
713 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
714 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
715 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
716 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
717 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
718 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
719 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
720 break;
721 case SkBlendMode::kDstATop:
722 TEST_ASSERT(!xpi.fIgnoresInputColor);
723 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
724 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
725 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
726 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
727 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
728 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
729 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
730 break;
731 case SkBlendMode::kXor:
732 TEST_ASSERT(!xpi.fIgnoresInputColor);
733 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
734 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
735 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
736 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
737 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
738 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
739 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
740 break;
741 case SkBlendMode::kPlus:
742 TEST_ASSERT(!xpi.fIgnoresInputColor);
743 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
744 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
745 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
746 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
747 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
748 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
749 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
750 break;
751 case SkBlendMode::kModulate:
752 TEST_ASSERT(!xpi.fIgnoresInputColor);
753 TEST_ASSERT(kISCModulate_OutputType == xpi.fPrimaryOutputType);
754 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
755 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.fEquation);
756 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
757 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
758 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
759 break;
760 case SkBlendMode::kScreen:
761 TEST_ASSERT(!xpi.fIgnoresInputColor);
762 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
763 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
764 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
765 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
766 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
767 TEST_ASSERT(kISC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
768 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
769 break;
770 default:
771 ERRORF(reporter, "Invalid xfermode.");
772 break;
773 }
774 }
775 }
776
test_color_opaque_no_coverage(skiatest::Reporter * reporter,const GrCaps & caps)777 static void test_color_opaque_no_coverage(skiatest::Reporter* reporter, const GrCaps& caps) {
778 GrProcessorAnalysisColor inputColor = GrProcessorAnalysisColor::Opaque::kYes;
779 GrProcessorAnalysisCoverage inputCoverage = GrProcessorAnalysisCoverage::kNone;
780
781 for (int m = 0; m <= (int)SkBlendMode::kLastCoeffMode; m++) {
782 SkBlendMode xfermode = static_cast<SkBlendMode>(m);
783 const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, inputColor, inputCoverage);
784
785 switch (xfermode) {
786 case SkBlendMode::kClear:
787 TEST_ASSERT(xpi.fIgnoresInputColor);
788 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
789 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
790 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
791 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
792 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
793 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
794 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
795 break;
796 case SkBlendMode::kSrc:
797 TEST_ASSERT(!xpi.fIgnoresInputColor);
798 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
799 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
800 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
801 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
802 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
803 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
804 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
805 break;
806 case SkBlendMode::kDst:
807 TEST_ASSERT(xpi.fIgnoresInputColor);
808 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
809 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
810 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
811 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
812 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
813 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
814 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor);
815 break;
816 case SkBlendMode::kSrcOver:
817 // We don't specialize opaque src-over. See note in GrPorterDuffXferProcessor.cpp
818 TEST_ASSERT(!xpi.fIgnoresInputColor);
819 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
820 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
821 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
822 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
823 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
824 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
825 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
826 break;
827 case SkBlendMode::kDstOver:
828 TEST_ASSERT(!xpi.fIgnoresInputColor);
829 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
830 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
831 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
832 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
833 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
834 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
835 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
836 break;
837 case SkBlendMode::kSrcIn:
838 TEST_ASSERT(!xpi.fIgnoresInputColor);
839 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
840 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
841 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
842 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
843 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
844 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
845 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
846 break;
847 case SkBlendMode::kDstIn:
848 TEST_ASSERT(xpi.fIgnoresInputColor);
849 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
850 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
851 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
852 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
853 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
854 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
855 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor);
856 break;
857 case SkBlendMode::kSrcOut:
858 TEST_ASSERT(!xpi.fIgnoresInputColor);
859 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
860 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
861 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
862 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
863 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
864 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
865 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
866 break;
867 case SkBlendMode::kDstOut:
868 TEST_ASSERT(xpi.fIgnoresInputColor);
869 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
870 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
871 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
872 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
873 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
874 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
875 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
876 break;
877 case SkBlendMode::kSrcATop:
878 TEST_ASSERT(!xpi.fIgnoresInputColor);
879 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
880 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
881 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
882 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
883 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
884 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
885 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
886 break;
887 case SkBlendMode::kDstATop:
888 TEST_ASSERT(!xpi.fIgnoresInputColor);
889 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
890 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
891 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
892 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
893 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
894 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
895 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
896 break;
897 case SkBlendMode::kXor:
898 TEST_ASSERT(!xpi.fIgnoresInputColor);
899 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
900 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
901 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
902 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
903 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
904 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
905 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
906 break;
907 case SkBlendMode::kPlus:
908 TEST_ASSERT(!xpi.fIgnoresInputColor);
909 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
910 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
911 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
912 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
913 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
914 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
915 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
916 break;
917 case SkBlendMode::kModulate:
918 TEST_ASSERT(!xpi.fIgnoresInputColor);
919 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
920 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
921 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
922 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
923 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
924 TEST_ASSERT(kSC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
925 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
926 break;
927 case SkBlendMode::kScreen:
928 TEST_ASSERT(!xpi.fIgnoresInputColor);
929 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
930 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
931 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
932 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
933 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
934 TEST_ASSERT(kISC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
935 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
936 break;
937 default:
938 ERRORF(reporter, "Invalid xfermode.");
939 break;
940 }
941 }
942 }
943
test_lcd_coverage_fallback_case(skiatest::Reporter * reporter,const GrCaps & caps)944 static void test_lcd_coverage_fallback_case(skiatest::Reporter* reporter, const GrCaps& caps) {
945 constexpr GrClampType autoClamp = GrClampType::kAuto;
946 const GrXPFactory* xpf = GrPorterDuffXPFactory::Get(SkBlendMode::kSrcOver);
947 GrProcessorAnalysisColor color = SkPMColor4f::FromBytes_RGBA(GrColorPackRGBA(123, 45, 67, 255));
948 GrProcessorAnalysisCoverage coverage = GrProcessorAnalysisCoverage::kLCD;
949 TEST_ASSERT(!(GrXPFactory::GetAnalysisProperties(xpf, color, coverage, caps, autoClamp) &
950 GrXPFactory::AnalysisProperties::kRequiresDstTexture));
951 sk_sp<const GrXferProcessor> xp_opaque(
952 GrXPFactory::MakeXferProcessor(xpf, color, coverage, false, caps, autoClamp));
953 if (!xp_opaque) {
954 ERRORF(reporter, "Failed to create an XP with LCD coverage.");
955 return;
956 }
957
958 GrXferProcessor::BlendInfo blendInfo;
959 xp_opaque->getBlendInfo(&blendInfo);
960 TEST_ASSERT(blendInfo.fWriteColor);
961
962 // Test with non-opaque alpha
963 color = SkPMColor4f::FromBytes_RGBA(GrColorPackRGBA(123, 45, 67, 221));
964 coverage = GrProcessorAnalysisCoverage::kLCD;
965 TEST_ASSERT(!(GrXPFactory::GetAnalysisProperties(xpf, color, coverage, caps, autoClamp) &
966 GrXPFactory::AnalysisProperties::kRequiresDstTexture));
967 sk_sp<const GrXferProcessor> xp(
968 GrXPFactory::MakeXferProcessor(xpf, color, coverage, false, caps, autoClamp));
969 if (!xp) {
970 ERRORF(reporter, "Failed to create an XP with LCD coverage.");
971 return;
972 }
973
974 xp->getBlendInfo(&blendInfo);
975 TEST_ASSERT(blendInfo.fWriteColor);
976 }
977
DEF_GPUTEST(PorterDuffNoDualSourceBlending,reporter,options)978 DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, options) {
979 GrContextOptions opts = options;
980 opts.fSuppressDualSourceBlending = true;
981 sk_gpu_test::GrContextFactory mockFactory(opts);
982 GrContext* ctx = mockFactory.get(sk_gpu_test::GrContextFactory::kNullGL_ContextType);
983 if (!ctx) {
984 SK_ABORT("Failed to create null context without ARB_blend_func_extended.");
985 return;
986 }
987
988 GrGpu* gpu = ctx->priv().getGpu();
989 GrProxyProvider* proxyProvider = ctx->priv().proxyProvider();
990 const GrCaps& caps = *ctx->priv().caps();
991 if (caps.shaderCaps()->dualSourceBlendingSupport()) {
992 SK_ABORT("Null context failed to honor request for no ARB_blend_func_extended.");
993 return;
994 }
995
996 GrBackendTexture backendTex =
997 gpu->createTestingOnlyBackendTexture(nullptr, 100, 100, GrColorType::kRGBA_8888,
998 false, GrMipMapped::kNo);
999
1000 GrXferProcessor::DstProxy fakeDstProxy;
1001 {
1002 sk_sp<GrTextureProxy> proxy = proxyProvider->wrapBackendTexture(
1003 backendTex, kTopLeft_GrSurfaceOrigin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
1004 kRead_GrIOType);
1005 fakeDstProxy.setProxy(std::move(proxy));
1006 }
1007
1008 static const GrProcessorAnalysisColor colorInputs[] = {
1009 GrProcessorAnalysisColor::Opaque::kNo, GrProcessorAnalysisColor::Opaque::kYes,
1010 GrProcessorAnalysisColor(SkPMColor4f::FromBytes_RGBA(GrColorPackRGBA(0, 82, 17, 100))),
1011 GrProcessorAnalysisColor(SkPMColor4f::FromBytes_RGBA(GrColorPackRGBA(0, 82, 17, 255)))};
1012
1013 for (const auto& colorInput : colorInputs) {
1014 for (GrProcessorAnalysisCoverage coverageType :
1015 {GrProcessorAnalysisCoverage::kSingleChannel, GrProcessorAnalysisCoverage::kNone}) {
1016 for (int m = 0; m <= (int)SkBlendMode::kLastCoeffMode; m++) {
1017 SkBlendMode xfermode = static_cast<SkBlendMode>(m);
1018 const GrXPFactory* xpf = GrPorterDuffXPFactory::Get(xfermode);
1019 sk_sp<const GrXferProcessor> xp(
1020 GrXPFactory::MakeXferProcessor(xpf, colorInput, coverageType, false, caps,
1021 GrClampType::kAuto));
1022 if (!xp) {
1023 ERRORF(reporter, "Failed to create an XP without dual source blending.");
1024 return;
1025 }
1026 TEST_ASSERT(!xp->hasSecondaryOutput());
1027 }
1028 }
1029 }
1030 gpu->deleteTestingOnlyBackendTexture(backendTex);
1031 }
1032