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