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