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