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 "SkXfermode.h"
9 #include "Test.h"
10 
11 #if SK_SUPPORT_GPU
12 
13 #include "GrContextFactory.h"
14 #include "GrContextOptions.h"
15 #include "GrGpu.h"
16 #include "GrResourceProvider.h"
17 #include "GrXferProcessor.h"
18 #include "batches/GrVertexBatch.h"
19 #include "effects/GrPorterDuffXferProcessor.h"
20 #include "gl/GrGLCaps.h"
21 
22 ////////////////////////////////////////////////////////////////////////////////
23 
24 static void test_color_unknown_with_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
25 static void test_color_unknown_no_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
26 static void test_color_opaque_with_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
27 static void test_color_opaque_no_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
28 static void test_lcd_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
29 static void test_lcd_coverage_fallback_case(skiatest::Reporter* reporter, const GrCaps& caps);
30 
DEF_GPUTEST_FOR_NULL_CONTEXT(GrPorterDuff,reporter,context)31 DEF_GPUTEST_FOR_NULL_CONTEXT(GrPorterDuff, reporter, context) {
32     const GrCaps& caps = *context->getGpu()->caps();
33     if (!caps.shaderCaps()->dualSourceBlendingSupport()) {
34         SkFAIL("Null context does not support dual source blending.");
35         return;
36     }
37 
38     test_color_unknown_with_coverage(reporter, caps);
39     test_color_unknown_no_coverage(reporter, caps);
40     test_color_opaque_with_coverage(reporter, caps);
41     test_color_opaque_no_coverage(reporter, caps);
42     test_lcd_coverage(reporter, caps);
43     test_lcd_coverage_fallback_case(reporter, caps);
44 }
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 
48 #define TEST_ASSERT(...) REPORTER_ASSERT(reporter, __VA_ARGS__)
49 
50 enum {
51     kNone_OutputType,
52     kCoverage_OutputType,
53     kModulate_OutputType,
54     kSAModulate_OutputType,
55     kISAModulate_OutputType,
56     kISCModulate_OutputType
57 };
58 
59 enum {
60     kNone_OptFlags                    = GrXferProcessor::kNone_OptFlags,
61     kSkipDraw_OptFlag                 = GrXferProcessor::kSkipDraw_OptFlag,
62     kIgnoreColor_OptFlag              = GrXferProcessor::kIgnoreColor_OptFlag,
63     kIgnoreCoverage_OptFlag           = GrXferProcessor::kIgnoreCoverage_OptFlag,
64     kCanTweakAlphaForCoverage_OptFlag = GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag
65 };
66 
67 class GrPorterDuffTest {
68 public:
69     struct XPInfo {
XPInfoGrPorterDuffTest::XPInfo70         XPInfo(skiatest::Reporter* reporter, SkXfermode::Mode xfermode, const GrCaps& caps,
71                const GrPipelineOptimizations& optimizations) {
72             SkAutoTUnref<GrXPFactory> xpf(GrPorterDuffXPFactory::Create(xfermode));
73             SkAutoTUnref<GrXferProcessor> xp(
74                 xpf->createXferProcessor(optimizations, false, nullptr, caps));
75             TEST_ASSERT(!xpf->willNeedDstTexture(caps, optimizations, false));
76             xpf->getInvariantBlendedColor(optimizations.fColorPOI, &fBlendedColor);
77             fOptFlags = xp->getOptimizations(optimizations, false, nullptr, caps);
78             GetXPOutputTypes(xp, &fPrimaryOutputType, &fSecondaryOutputType);
79             xp->getBlendInfo(&fBlendInfo);
80             TEST_ASSERT(!xp->willReadDstColor());
81             TEST_ASSERT(xp->hasSecondaryOutput() == GrBlendCoeffRefsSrc2(fBlendInfo.fDstBlend));
82         }
83 
84         GrXPFactory::InvariantBlendedColor fBlendedColor;
85         int fOptFlags;
86         int fPrimaryOutputType;
87         int fSecondaryOutputType;
88         GrXferProcessor::BlendInfo fBlendInfo;
89     };
90 
GetXPOutputTypes(const GrXferProcessor * xp,int * outPrimary,int * outSecondary)91     static void GetXPOutputTypes(const GrXferProcessor* xp, int* outPrimary, int* outSecondary) {
92         GrPorterDuffXPFactory::TestGetXPOutputTypes(xp, outPrimary, outSecondary);
93     }
94 };
95 
test_lcd_coverage(skiatest::Reporter * reporter,const GrCaps & caps)96 static void test_lcd_coverage(skiatest::Reporter* reporter, const GrCaps& caps) {
97     GrPipelineOptimizations opt;
98     opt.fColorPOI.calcWithInitialValues(NULL, 0, 0, kNone_GrColorComponentFlags, false);
99     // Setting 2nd to last value to false and last to true will force covPOI to LCD coverage.
100     opt.fCoveragePOI.calcWithInitialValues(NULL, 0, 0, kNone_GrColorComponentFlags, false, true);
101 
102     SkASSERT(!opt.fColorPOI.isOpaque());
103     SkASSERT(!opt.fColorPOI.isSolidWhite());
104     SkASSERT(!opt.fCoveragePOI.isSolidWhite());
105     SkASSERT(opt.fCoveragePOI.isFourChannelOutput());
106 
107     for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) {
108         SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m);
109         const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, opt);
110 
111         switch (xfermode) {
112             case SkXfermode::kClear_Mode:
113                 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
114                 TEST_ASSERT(0 == xpi.fBlendedColor.fKnownColor);
115                 TEST_ASSERT(kRGBA_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
116                 TEST_ASSERT((kIgnoreColor_OptFlag) == xpi.fOptFlags);
117                 TEST_ASSERT(kCoverage_OutputType == xpi.fPrimaryOutputType);
118                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
119                 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.fEquation);
120                 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
121                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
122                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
123                 break;
124             case SkXfermode::kSrc_Mode:
125                 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
126                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
127                 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
128                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
129                 TEST_ASSERT(kCoverage_OutputType == xpi.fSecondaryOutputType);
130                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
131                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
132                 TEST_ASSERT(kIS2C_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
133                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
134                 break;
135             case SkXfermode::kDst_Mode:
136                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
137                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
138                 TEST_ASSERT((kSkipDraw_OptFlag |
139                              kIgnoreColor_OptFlag |
140                              kIgnoreCoverage_OptFlag |
141                              kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
142                 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
143                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
144                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
145                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
146                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
147                 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor);
148                 break;
149             case SkXfermode::kSrcOver_Mode:
150                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
151                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
152                 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
153                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
154                 TEST_ASSERT(kSAModulate_OutputType == xpi.fSecondaryOutputType);
155                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
156                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
157                 TEST_ASSERT(kIS2C_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
158                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
159                 break;
160             case SkXfermode::kDstOver_Mode:
161                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
162                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
163                 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
164                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
165                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
166                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
167                 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
168                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
169                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
170                 break;
171             case SkXfermode::kSrcIn_Mode:
172                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
173                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
174                 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
175                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
176                 TEST_ASSERT(kCoverage_OutputType == xpi.fSecondaryOutputType);
177                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
178                 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
179                 TEST_ASSERT(kIS2C_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
180                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
181                 break;
182             case SkXfermode::kDstIn_Mode:
183                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
184                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
185                 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
186                 TEST_ASSERT(kISAModulate_OutputType == xpi.fPrimaryOutputType);
187                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
188                 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.fEquation);
189                 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
190                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
191                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
192                 break;
193             case SkXfermode::kSrcOut_Mode:
194                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
195                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
196                 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
197                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
198                 TEST_ASSERT(kCoverage_OutputType == xpi.fSecondaryOutputType);
199                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
200                 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
201                 TEST_ASSERT(kIS2C_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
202                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
203                 break;
204             case SkXfermode::kDstOut_Mode:
205                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
206                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
207                 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
208                 TEST_ASSERT(kSAModulate_OutputType == xpi.fPrimaryOutputType);
209                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
210                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
211                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
212                 TEST_ASSERT(kISC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
213                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
214                 break;
215             case SkXfermode::kSrcATop_Mode:
216                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
217                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
218                 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
219                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
220                 TEST_ASSERT(kSAModulate_OutputType == xpi.fSecondaryOutputType);
221                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
222                 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
223                 TEST_ASSERT(kIS2C_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
224                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
225                 break;
226             case SkXfermode::kDstATop_Mode:
227                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
228                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
229                 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
230                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
231                 TEST_ASSERT(kISAModulate_OutputType == xpi.fSecondaryOutputType);
232                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
233                 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
234                 TEST_ASSERT(kIS2C_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
235                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
236                 break;
237             case SkXfermode::kXor_Mode:
238                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
239                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
240                 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
241                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
242                 TEST_ASSERT(kSAModulate_OutputType == xpi.fSecondaryOutputType);
243                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
244                 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
245                 TEST_ASSERT(kIS2C_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
246                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
247                 break;
248             case SkXfermode::kPlus_Mode:
249                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
250                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
251                 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
252                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
253                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
254                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
255                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
256                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
257                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
258                 break;
259             case SkXfermode::kModulate_Mode:
260                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
261                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
262                 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
263                 TEST_ASSERT(kISCModulate_OutputType == xpi.fPrimaryOutputType);
264                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
265                 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.fEquation);
266                 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
267                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
268                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
269                 break;
270             case SkXfermode::kScreen_Mode:
271                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
272                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
273                 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
274                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
275                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
276                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
277                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
278                 TEST_ASSERT(kISC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
279                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
280                 break;
281             default:
282                 ERRORF(reporter, "Invalid xfermode.");
283                 break;
284         }
285     }
286 }
test_color_unknown_with_coverage(skiatest::Reporter * reporter,const GrCaps & caps)287 static void test_color_unknown_with_coverage(skiatest::Reporter* reporter, const GrCaps& caps) {
288     GrPipelineOptimizations optimizations;
289     optimizations.fColorPOI.calcWithInitialValues(nullptr, 0, 0, kNone_GrColorComponentFlags,
290                                                   false);
291     optimizations.fCoveragePOI.calcWithInitialValues(nullptr, 0, 0, kNone_GrColorComponentFlags,
292                                                      true);
293 
294     SkASSERT(!optimizations.fColorPOI.isOpaque());
295     SkASSERT(!optimizations.fColorPOI.isSolidWhite());
296     SkASSERT(!optimizations.fCoveragePOI.isSolidWhite());
297     SkASSERT(!optimizations.fCoveragePOI.isFourChannelOutput());
298 
299     for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) {
300         SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m);
301         const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, optimizations);
302 
303 
304         switch (xfermode) {
305             case SkXfermode::kClear_Mode:
306                 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
307                 TEST_ASSERT(0 == xpi.fBlendedColor.fKnownColor);
308                 TEST_ASSERT(kRGBA_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
309                 TEST_ASSERT((kIgnoreColor_OptFlag) == xpi.fOptFlags);
310                 TEST_ASSERT(kCoverage_OutputType == xpi.fPrimaryOutputType);
311                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
312                 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.fEquation);
313                 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
314                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
315                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
316                 break;
317             case SkXfermode::kSrc_Mode:
318                 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
319                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
320                 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
321                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
322                 TEST_ASSERT(kCoverage_OutputType == xpi.fSecondaryOutputType);
323                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
324                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
325                 TEST_ASSERT(kIS2A_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
326                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
327                 break;
328             case SkXfermode::kDst_Mode:
329                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
330                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
331                 TEST_ASSERT((kSkipDraw_OptFlag |
332                              kIgnoreColor_OptFlag |
333                              kIgnoreCoverage_OptFlag |
334                              kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
335                 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
336                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
337                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
338                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
339                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
340                 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor);
341                 break;
342             case SkXfermode::kSrcOver_Mode:
343                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
344                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
345                 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
346                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
347                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
348                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
349                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
350                 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
351                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
352                 break;
353             case SkXfermode::kDstOver_Mode:
354                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
355                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
356                 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
357                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
358                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
359                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
360                 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
361                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
362                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
363                 break;
364             case SkXfermode::kSrcIn_Mode:
365                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
366                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
367                 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
368                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
369                 TEST_ASSERT(kCoverage_OutputType == xpi.fSecondaryOutputType);
370                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
371                 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
372                 TEST_ASSERT(kIS2A_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
373                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
374                 break;
375             case SkXfermode::kDstIn_Mode:
376                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
377                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
378                 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
379                 TEST_ASSERT(kISAModulate_OutputType == xpi.fPrimaryOutputType);
380                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
381                 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.fEquation);
382                 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
383                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
384                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
385                 break;
386             case SkXfermode::kSrcOut_Mode:
387                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
388                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
389                 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
390                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
391                 TEST_ASSERT(kCoverage_OutputType == xpi.fSecondaryOutputType);
392                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
393                 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
394                 TEST_ASSERT(kIS2A_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
395                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
396                 break;
397             case SkXfermode::kDstOut_Mode:
398                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
399                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
400                 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
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(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
405                 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
406                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
407                 break;
408             case SkXfermode::kSrcATop_Mode:
409                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
410                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
411                 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
412                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
413                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
414                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
415                 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
416                 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
417                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
418                 break;
419             case SkXfermode::kDstATop_Mode:
420                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
421                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
422                 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
423                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
424                 TEST_ASSERT(kISAModulate_OutputType == xpi.fSecondaryOutputType);
425                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
426                 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
427                 TEST_ASSERT(kIS2C_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
428                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
429                 break;
430             case SkXfermode::kXor_Mode:
431                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
432                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
433                 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
434                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
435                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
436                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
437                 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
438                 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
439                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
440                 break;
441             case SkXfermode::kPlus_Mode:
442                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
443                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
444                 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
445                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
446                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
447                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
448                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
449                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
450                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
451                 break;
452             case SkXfermode::kModulate_Mode:
453                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
454                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
455                 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
456                 TEST_ASSERT(kISCModulate_OutputType == xpi.fPrimaryOutputType);
457                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
458                 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.fEquation);
459                 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
460                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
461                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
462                 break;
463             case SkXfermode::kScreen_Mode:
464                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
465                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
466                 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
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(kISC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
472                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
473                 break;
474             default:
475                 ERRORF(reporter, "Invalid xfermode.");
476                 break;
477         }
478     }
479 }
480 
test_color_unknown_no_coverage(skiatest::Reporter * reporter,const GrCaps & caps)481 static void test_color_unknown_no_coverage(skiatest::Reporter* reporter, const GrCaps& caps) {
482     GrPipelineOptimizations optimizations;
483     optimizations.fColorPOI.calcWithInitialValues(nullptr, 0, GrColorPackRGBA(229, 0, 154, 0),
484                                    kR_GrColorComponentFlag | kB_GrColorComponentFlag, false);
485     optimizations.fCoveragePOI.calcWithInitialValues(nullptr, 0, GrColorPackA4(255),
486                                                      kRGBA_GrColorComponentFlags, true);
487 
488     SkASSERT(!optimizations.fColorPOI.isOpaque());
489     SkASSERT(!optimizations.fColorPOI.isSolidWhite());
490     SkASSERT(optimizations.fCoveragePOI.isSolidWhite());
491     SkASSERT(!optimizations.fCoveragePOI.isFourChannelOutput());
492 
493     for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) {
494         SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m);
495         const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, optimizations);
496 
497         switch (xfermode) {
498             case SkXfermode::kClear_Mode:
499                 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
500                 TEST_ASSERT(0 == xpi.fBlendedColor.fKnownColor);
501                 TEST_ASSERT(kRGBA_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
502                 TEST_ASSERT((kIgnoreColor_OptFlag |
503                              kIgnoreCoverage_OptFlag) == xpi.fOptFlags);
504                 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
505                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
506                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
507                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
508                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
509                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
510                 break;
511             case SkXfermode::kSrc_Mode:
512                 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
513                 TEST_ASSERT(229 == GrColorUnpackR(xpi.fBlendedColor.fKnownColor));
514                 TEST_ASSERT(154 == GrColorUnpackB(xpi.fBlendedColor.fKnownColor));
515                 TEST_ASSERT((kR_GrColorComponentFlag |
516                              kB_GrColorComponentFlag) == xpi.fBlendedColor.fKnownColorFlags);
517                 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags);
518                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
519                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
520                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
521                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
522                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
523                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
524                 break;
525             case SkXfermode::kDst_Mode:
526                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
527                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
528                 TEST_ASSERT((kSkipDraw_OptFlag |
529                              kIgnoreColor_OptFlag |
530                              kIgnoreCoverage_OptFlag |
531                              kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
532                 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
533                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
534                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
535                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
536                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
537                 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor);
538                 break;
539             case SkXfermode::kSrcOver_Mode:
540                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
541                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
542                 TEST_ASSERT((kIgnoreCoverage_OptFlag |
543                              kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
544                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
545                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
546                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
547                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
548                 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
549                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
550                 break;
551             case SkXfermode::kDstOver_Mode:
552                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
553                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
554                 TEST_ASSERT((kIgnoreCoverage_OptFlag |
555                              kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
556                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
557                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
558                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
559                 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
560                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
561                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
562                 break;
563             case SkXfermode::kSrcIn_Mode:
564                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
565                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
566                 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags);
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(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
571                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
572                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
573                 break;
574             case SkXfermode::kDstIn_Mode:
575                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
576                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
577                 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags);
578                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
579                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
580                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
581                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
582                 TEST_ASSERT(kSA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
583                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
584                 break;
585             case SkXfermode::kSrcOut_Mode:
586                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
587                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
588                 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags);
589                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
590                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
591                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
592                 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
593                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
594                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
595                 break;
596             case SkXfermode::kDstOut_Mode:
597                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
598                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
599                 TEST_ASSERT((kIgnoreCoverage_OptFlag |
600                              kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
601                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
602                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
603                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
604                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
605                 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
606                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
607                 break;
608             case SkXfermode::kSrcATop_Mode:
609                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
610                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
611                 TEST_ASSERT((kIgnoreCoverage_OptFlag |
612                              kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
613                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
614                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
615                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
616                 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
617                 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
618                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
619                 break;
620             case SkXfermode::kDstATop_Mode:
621                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
622                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
623                 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags);
624                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
625                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
626                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
627                 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
628                 TEST_ASSERT(kSA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
629                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
630                 break;
631             case SkXfermode::kXor_Mode:
632                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
633                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
634                 TEST_ASSERT((kIgnoreCoverage_OptFlag |
635                              kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
636                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
637                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
638                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
639                 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
640                 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
641                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
642                 break;
643             case SkXfermode::kPlus_Mode:
644                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
645                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
646                 TEST_ASSERT((kIgnoreCoverage_OptFlag |
647                              kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
648                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
649                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
650                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
651                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
652                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
653                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
654                 break;
655             case SkXfermode::kModulate_Mode:
656                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
657                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
658                 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags);
659                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
660                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
661                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
662                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
663                 TEST_ASSERT(kSC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
664                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
665                 break;
666             case SkXfermode::kScreen_Mode:
667                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
668                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
669                 TEST_ASSERT((kIgnoreCoverage_OptFlag |
670                              kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
671                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
672                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
673                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
674                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
675                 TEST_ASSERT(kISC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
676                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
677                 break;
678             default:
679                 ERRORF(reporter, "Invalid xfermode.");
680                 break;
681         }
682     }
683 }
684 
test_color_opaque_with_coverage(skiatest::Reporter * reporter,const GrCaps & caps)685 static void test_color_opaque_with_coverage(skiatest::Reporter* reporter, const GrCaps& caps) {
686     GrPipelineOptimizations optimizations;
687     optimizations.fColorPOI.calcWithInitialValues(nullptr, 0, GrColorPackA4(255),
688                                                   kA_GrColorComponentFlag, false);
689     optimizations.fCoveragePOI.calcWithInitialValues(nullptr, 0, 0, kNone_GrColorComponentFlags,
690                                                      true);
691 
692     SkASSERT(optimizations.fColorPOI.isOpaque());
693     SkASSERT(!optimizations.fColorPOI.isSolidWhite());
694     SkASSERT(!optimizations.fCoveragePOI.isSolidWhite());
695     SkASSERT(!optimizations.fCoveragePOI.isFourChannelOutput());
696 
697     for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) {
698         SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m);
699         const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, optimizations);
700 
701         switch (xfermode) {
702             case SkXfermode::kClear_Mode:
703                 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
704                 TEST_ASSERT(0 == xpi.fBlendedColor.fKnownColor);
705                 TEST_ASSERT(kRGBA_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
706                 TEST_ASSERT((kIgnoreColor_OptFlag) == xpi.fOptFlags);
707                 TEST_ASSERT(kCoverage_OutputType == xpi.fPrimaryOutputType);
708                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
709                 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.fEquation);
710                 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
711                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
712                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
713                 break;
714             case SkXfermode::kSrc_Mode:
715                 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
716                 TEST_ASSERT(255 == GrColorUnpackA(xpi.fBlendedColor.fKnownColor));
717                 TEST_ASSERT(kA_GrColorComponentFlag == xpi.fBlendedColor.fKnownColorFlags);
718                 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
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(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
723                 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
724                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
725                 break;
726             case SkXfermode::kDst_Mode:
727                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
728                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
729                 TEST_ASSERT((kSkipDraw_OptFlag |
730                              kIgnoreColor_OptFlag |
731                              kIgnoreCoverage_OptFlag |
732                              kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
733                 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
734                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
735                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
736                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
737                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
738                 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor);
739                 break;
740             case SkXfermode::kSrcOver_Mode:
741                 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
742                 TEST_ASSERT(255 == GrColorUnpackA(xpi.fBlendedColor.fKnownColor));
743                 TEST_ASSERT(kA_GrColorComponentFlag == xpi.fBlendedColor.fKnownColorFlags);
744                 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
745                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
746                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
747                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
748                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
749                 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
750                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
751                 break;
752             case SkXfermode::kDstOver_Mode:
753                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
754                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
755                 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
756                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
757                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
758                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
759                 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
760                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
761                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
762                 break;
763             case SkXfermode::kSrcIn_Mode:
764                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
765                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
766                 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
767                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
768                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
769                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
770                 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
771                 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
772                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
773                 break;
774             case SkXfermode::kDstIn_Mode:
775                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
776                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
777                 TEST_ASSERT((kSkipDraw_OptFlag |
778                              kIgnoreColor_OptFlag |
779                              kIgnoreCoverage_OptFlag |
780                              kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
781                 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
782                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
783                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
784                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
785                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
786                 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor);
787                 break;
788             case SkXfermode::kSrcOut_Mode:
789                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
790                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
791                 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
792                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
793                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
794                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
795                 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
796                 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
797                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
798                 break;
799             case SkXfermode::kDstOut_Mode:
800                 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
801                 TEST_ASSERT(0 == xpi.fBlendedColor.fKnownColor);
802                 TEST_ASSERT(kRGBA_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
803                 TEST_ASSERT((kIgnoreColor_OptFlag) == xpi.fOptFlags);
804                 TEST_ASSERT(kCoverage_OutputType == xpi.fPrimaryOutputType);
805                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
806                 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.fEquation);
807                 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
808                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
809                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
810                 break;
811             case SkXfermode::kSrcATop_Mode:
812                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
813                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
814                 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
815                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
816                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
817                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
818                 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
819                 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
820                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
821                 break;
822             case SkXfermode::kDstATop_Mode:
823                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
824                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
825                 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
826                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
827                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
828                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
829                 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
830                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
831                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
832                 break;
833             case SkXfermode::kXor_Mode:
834                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
835                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
836                 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
837                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
838                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
839                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
840                 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
841                 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
842                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
843                 break;
844             case SkXfermode::kPlus_Mode:
845                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
846                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
847                 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
848                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
849                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
850                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
851                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
852                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
853                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
854                 break;
855             case SkXfermode::kModulate_Mode:
856                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
857                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
858                 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
859                 TEST_ASSERT(kISCModulate_OutputType == xpi.fPrimaryOutputType);
860                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
861                 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.fEquation);
862                 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
863                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
864                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
865                 break;
866             case SkXfermode::kScreen_Mode:
867                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
868                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
869                 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
870                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
871                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
872                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
873                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
874                 TEST_ASSERT(kISC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
875                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
876                 break;
877             default:
878                 ERRORF(reporter, "Invalid xfermode.");
879                 break;
880         }
881     }
882 }
883 
test_color_opaque_no_coverage(skiatest::Reporter * reporter,const GrCaps & caps)884 static void test_color_opaque_no_coverage(skiatest::Reporter* reporter, const GrCaps& caps) {
885     GrPipelineOptimizations optimizations;
886     optimizations.fColorPOI.calcWithInitialValues(nullptr, 0, GrColorPackRGBA(0, 82, 0, 255),
887                                    kG_GrColorComponentFlag | kA_GrColorComponentFlag, false);
888     optimizations.fCoveragePOI.calcWithInitialValues(nullptr, 0, GrColorPackA4(255),
889                                                      kRGBA_GrColorComponentFlags, true);
890 
891     SkASSERT(optimizations.fColorPOI.isOpaque());
892     SkASSERT(!optimizations.fColorPOI.isSolidWhite());
893     SkASSERT(optimizations.fCoveragePOI.isSolidWhite());
894     SkASSERT(!optimizations.fCoveragePOI.isFourChannelOutput());
895 
896     for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) {
897         SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m);
898         const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, optimizations);
899 
900         switch (xfermode) {
901             case SkXfermode::kClear_Mode:
902                 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
903                 TEST_ASSERT(0 == xpi.fBlendedColor.fKnownColor);
904                 TEST_ASSERT(kRGBA_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
905                 TEST_ASSERT((kIgnoreColor_OptFlag |
906                              kIgnoreCoverage_OptFlag) == xpi.fOptFlags);
907                 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
908                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
909                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
910                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
911                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
912                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
913                 break;
914             case SkXfermode::kSrc_Mode:
915                 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
916                 TEST_ASSERT(82 == GrColorUnpackG(xpi.fBlendedColor.fKnownColor));
917                 TEST_ASSERT(255 == GrColorUnpackA(xpi.fBlendedColor.fKnownColor));
918                 TEST_ASSERT((kG_GrColorComponentFlag |
919                              kA_GrColorComponentFlag) == xpi.fBlendedColor.fKnownColorFlags);
920                 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags);
921                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
922                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
923                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
924                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
925                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
926                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
927                 break;
928             case SkXfermode::kDst_Mode:
929                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
930                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
931                 TEST_ASSERT((kSkipDraw_OptFlag |
932                              kIgnoreColor_OptFlag |
933                              kIgnoreCoverage_OptFlag |
934                              kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
935                 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
936                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
937                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
938                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
939                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
940                 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor);
941                 break;
942             case SkXfermode::kSrcOver_Mode:
943                 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
944                 TEST_ASSERT(82 == GrColorUnpackG(xpi.fBlendedColor.fKnownColor));
945                 TEST_ASSERT(255 == GrColorUnpackA(xpi.fBlendedColor.fKnownColor));
946                 TEST_ASSERT((kG_GrColorComponentFlag |
947                              kA_GrColorComponentFlag) == xpi.fBlendedColor.fKnownColorFlags);
948                 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags);
949                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
950                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
951                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
952                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
953                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
954                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
955                 break;
956             case SkXfermode::kDstOver_Mode:
957                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
958                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
959                 TEST_ASSERT((kIgnoreCoverage_OptFlag |
960                              kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
961                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
962                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
963                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
964                 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
965                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
966                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
967                 break;
968             case SkXfermode::kSrcIn_Mode:
969                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
970                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
971                 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags);
972                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
973                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
974                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
975                 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
976                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
977                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
978                 break;
979             case SkXfermode::kDstIn_Mode:
980                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
981                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
982                 TEST_ASSERT((kSkipDraw_OptFlag |
983                              kIgnoreColor_OptFlag |
984                              kIgnoreCoverage_OptFlag |
985                              kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
986                 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
987                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
988                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
989                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
990                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
991                 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor);
992                 break;
993             case SkXfermode::kSrcOut_Mode:
994                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
995                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
996                 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags);
997                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
998                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
999                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
1000                 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
1001                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
1002                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
1003                 break;
1004             case SkXfermode::kDstOut_Mode:
1005                 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
1006                 TEST_ASSERT(0 == xpi.fBlendedColor.fKnownColor);
1007                 TEST_ASSERT(kRGBA_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
1008                 TEST_ASSERT((kIgnoreColor_OptFlag |
1009                              kIgnoreCoverage_OptFlag) == xpi.fOptFlags);
1010                 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
1011                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
1012                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
1013                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
1014                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
1015                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
1016                 break;
1017             case SkXfermode::kSrcATop_Mode:
1018                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
1019                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
1020                 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags);
1021                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
1022                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
1023                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
1024                 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
1025                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
1026                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
1027                 break;
1028             case SkXfermode::kDstATop_Mode:
1029                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
1030                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
1031                 TEST_ASSERT((kIgnoreCoverage_OptFlag |
1032                              kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
1033                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
1034                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
1035                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
1036                 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
1037                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
1038                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
1039                 break;
1040             case SkXfermode::kXor_Mode:
1041                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
1042                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
1043                 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags);
1044                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
1045                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
1046                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
1047                 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
1048                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
1049                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
1050                 break;
1051             case SkXfermode::kPlus_Mode:
1052                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
1053                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
1054                 TEST_ASSERT((kIgnoreCoverage_OptFlag |
1055                              kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
1056                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
1057                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
1058                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
1059                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
1060                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
1061                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
1062                 break;
1063             case SkXfermode::kModulate_Mode:
1064                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
1065                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
1066                 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags);
1067                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
1068                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
1069                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
1070                 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
1071                 TEST_ASSERT(kSC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
1072                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
1073                 break;
1074             case SkXfermode::kScreen_Mode:
1075                 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
1076                 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
1077                 TEST_ASSERT((kIgnoreCoverage_OptFlag |
1078                              kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags);
1079                 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
1080                 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
1081                 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
1082                 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
1083                 TEST_ASSERT(kISC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
1084                 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
1085                 break;
1086             default:
1087                 ERRORF(reporter, "Invalid xfermode.");
1088                 break;
1089         }
1090     }
1091 }
1092 
test_lcd_coverage_fallback_case(skiatest::Reporter * reporter,const GrCaps & caps)1093 static void test_lcd_coverage_fallback_case(skiatest::Reporter* reporter, const GrCaps& caps) {
1094     class TestLCDCoverageBatch: public GrVertexBatch {
1095     public:
1096         DEFINE_BATCH_CLASS_ID
1097 
1098         TestLCDCoverageBatch() : INHERITED(ClassID()) {}
1099 
1100     private:
1101         void computePipelineOptimizations(GrInitInvariantOutput* color,
1102                                           GrInitInvariantOutput* coverage,
1103                                           GrBatchToXPOverrides* overrides) const override {
1104             color->setKnownFourComponents(GrColorPackRGBA(123, 45, 67, 221));
1105             coverage->setUnknownFourComponents();
1106             coverage->setUsingLCDCoverage();        }
1107 
1108         const char* name() const override { return "Test LCD Text Batch"; }
1109         void initBatchTracker(const GrXPOverridesForBatch&) override {}
1110         bool onCombineIfPossible(GrBatch*, const GrCaps&) override  { return false; }
1111         void onPrepareDraws(Target*) const override {};
1112 
1113         typedef GrVertexBatch INHERITED;
1114     } testLCDCoverageBatch;
1115 
1116     GrPipelineOptimizations opts;
1117     testLCDCoverageBatch.getPipelineOptimizations(&opts);
1118     GrProcOptInfo colorPOI = opts.fColorPOI;
1119     GrProcOptInfo covPOI = opts.fCoveragePOI;
1120 
1121     SkASSERT(kRGBA_GrColorComponentFlags == colorPOI.validFlags());
1122     SkASSERT(covPOI.isFourChannelOutput());
1123 
1124     SkAutoTUnref<GrXPFactory> xpf(GrPorterDuffXPFactory::Create(SkXfermode::kSrcOver_Mode));
1125     TEST_ASSERT(!xpf->willNeedDstTexture(caps, opts, false));
1126 
1127     SkAutoTUnref<GrXferProcessor> xp(
1128         xpf->createXferProcessor(opts, false, nullptr, caps));
1129     if (!xp) {
1130         ERRORF(reporter, "Failed to create an XP with LCD coverage.");
1131         return;
1132     }
1133 
1134     GrXPFactory::InvariantBlendedColor blendedColor;
1135     xpf->getInvariantBlendedColor(colorPOI, &blendedColor);
1136     TEST_ASSERT(blendedColor.fWillBlendWithDst);
1137     TEST_ASSERT(kNone_GrColorComponentFlags == blendedColor.fKnownColorFlags);
1138 
1139     GrColor overrideColor;
1140     xp->getOptimizations(opts, false, &overrideColor, caps);
1141 
1142     GrXferProcessor::BlendInfo blendInfo;
1143     xp->getBlendInfo(&blendInfo);
1144     TEST_ASSERT(blendInfo.fWriteColor);
1145 }
1146 
1147 DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, /*factory*/) {
1148     GrContextOptions opts;
1149     opts.fSuppressDualSourceBlending = true;
1150     GrContextFactory mockFactory(opts);
1151     GrContext* ctx = mockFactory.get(GrContextFactory::kNull_GLContextType);
1152     if (!ctx) {
1153         SkFAIL("Failed to create null context without ARB_blend_func_extended.");
1154         return;
1155     }
1156 
1157     const GrCaps& caps = *ctx->caps();
1158     if (caps.shaderCaps()->dualSourceBlendingSupport()) {
1159         SkFAIL("Null context failed to honor request for no ARB_blend_func_extended.");
1160         return;
1161     }
1162 
1163     GrBackendObject backendTex =
1164         ctx->getGpu()->createTestingOnlyBackendTexture(nullptr, 100, 100,
1165                                                            kRGBA_8888_GrPixelConfig);
1166     GrBackendTextureDesc fakeDesc;
1167     fakeDesc.fConfig = kRGBA_8888_GrPixelConfig;
1168     fakeDesc.fWidth = fakeDesc.fHeight = 100;
1169     fakeDesc.fTextureHandle = backendTex;
1170     SkAutoTUnref<GrTexture> fakeTexture(ctx->textureProvider()->wrapBackendTexture(fakeDesc,
1171         kBorrow_GrWrapOwnership));
1172     GrXferProcessor::DstTexture fakeDstTexture;
1173     fakeDstTexture.setTexture(fakeTexture);
1174 
1175     static const GrColor testColors[] = {
1176         0,
1177         GrColorPackRGBA(0, 82, 0, 255),
1178         GrColorPackA4(255)
1179     };
1180     static const GrColorComponentFlags testColorFlags[] = {
1181         kNone_GrColorComponentFlags,
1182         kG_GrColorComponentFlag | kA_GrColorComponentFlag,
1183         kRGBA_GrColorComponentFlags
1184     };
1185     GR_STATIC_ASSERT(SK_ARRAY_COUNT(testColors) == SK_ARRAY_COUNT(testColorFlags));
1186 
1187     for (size_t c = 0; c < SK_ARRAY_COUNT(testColors); c++) {
1188         GrPipelineOptimizations optimizations;
1189         optimizations.fColorPOI.calcWithInitialValues(nullptr, 0, testColors[c], testColorFlags[c],
1190                                                       false);
1191         for (int f = 0; f <= 1; f++) {
1192             if (!f) {
1193                 optimizations.fCoveragePOI.calcWithInitialValues(nullptr, 0, 0,
1194                                                                  kNone_GrColorComponentFlags, true);
1195             } else {
1196                 optimizations.fCoveragePOI.calcWithInitialValues(nullptr, 0, GrColorPackA4(255),
1197                                                                  kRGBA_GrColorComponentFlags, true);
1198             }
1199             for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) {
1200                 SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m);
1201                 SkAutoTUnref<GrXPFactory> xpf(GrPorterDuffXPFactory::Create(xfermode));
1202                 GrXferProcessor::DstTexture* dstTexture =
1203                     xpf->willNeedDstTexture(caps, optimizations, false) ? &fakeDstTexture : 0;
1204                 SkAutoTUnref<GrXferProcessor> xp(
1205                     xpf->createXferProcessor(optimizations, false, dstTexture, caps));
1206                 if (!xp) {
1207                     ERRORF(reporter, "Failed to create an XP without dual source blending.");
1208                     return;
1209                 }
1210                 TEST_ASSERT(!xp->hasSecondaryOutput());
1211                 xp->getOptimizations(optimizations, false, 0, caps);
1212                 TEST_ASSERT(!xp->hasSecondaryOutput());
1213             }
1214         }
1215     }
1216     ctx->getGpu()->deleteTestingOnlyBackendTexture(backendTex);
1217 }
1218 
1219 #endif
1220 
1221