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