blob: 71db9939b8882624e040e16aaba05aa777d5f8e1 [file] [log] [blame]
cdalton6fd158e2015-05-27 15:08:33 -07001/*
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
cdalton6fd158e2015-05-27 15:08:33 -070013#include "GrContextFactory.h"
14#include "GrContextOptions.h"
15#include "GrGpu.h"
16#include "GrResourceProvider.h"
17#include "GrXferProcessor.h"
bsalomon16b99132015-08-13 14:55:50 -070018#include "batches/GrVertexBatch.h"
cdalton6fd158e2015-05-27 15:08:33 -070019#include "effects/GrPorterDuffXferProcessor.h"
20#include "gl/GrGLCaps.h"
21
22////////////////////////////////////////////////////////////////////////////////
23
24static void test_color_unknown_with_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
25static void test_color_unknown_no_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
26static void test_color_opaque_with_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
27static void test_color_opaque_no_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
28static void test_lcd_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
egdaniel723b0502015-09-15 09:31:40 -070029static void test_lcd_coverage_fallback_case(skiatest::Reporter* reporter, const GrCaps& caps);
cdalton6fd158e2015-05-27 15:08:33 -070030
bsalomon758586c2016-04-06 14:02:39 -070031DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrPorterDuff, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -070032 const GrCaps& caps = *ctxInfo.grContext()->getGpu()->caps();
cdalton6fd158e2015-05-27 15:08:33 -070033 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);
egdaniel723b0502015-09-15 09:31:40 -070043 test_lcd_coverage_fallback_case(reporter, caps);
cdalton6fd158e2015-05-27 15:08:33 -070044}
45
46////////////////////////////////////////////////////////////////////////////////
47
48#define TEST_ASSERT(...) REPORTER_ASSERT(reporter, __VA_ARGS__)
49
50enum {
51 kNone_OutputType,
52 kCoverage_OutputType,
53 kModulate_OutputType,
egdaniel723b0502015-09-15 09:31:40 -070054 kSAModulate_OutputType,
cdalton6fd158e2015-05-27 15:08:33 -070055 kISAModulate_OutputType,
56 kISCModulate_OutputType
57};
58
59enum {
bsalomon7765a472015-07-08 11:26:37 -070060 kNone_OptFlags = GrXferProcessor::kNone_OptFlags,
cdalton6fd158e2015-05-27 15:08:33 -070061 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
67class GrPorterDuffTest {
68public:
69 struct XPInfo {
70 XPInfo(skiatest::Reporter* reporter, SkXfermode::Mode xfermode, const GrCaps& caps,
ethannicholasde4166a2015-11-30 08:57:38 -080071 const GrPipelineOptimizations& optimizations) {
bungeman06ca8ec2016-06-09 08:01:03 -070072 sk_sp<GrXPFactory> xpf(GrPorterDuffXPFactory::Make(xfermode));
cdalton86ae0a92015-06-08 15:11:04 -070073 SkAutoTUnref<GrXferProcessor> xp(
ethannicholasde4166a2015-11-30 08:57:38 -080074 xpf->createXferProcessor(optimizations, false, nullptr, caps));
cdalton3ccf2e72016-05-06 09:41:16 -070075 TEST_ASSERT(!xpf->willNeedDstTexture(caps, optimizations));
ethannicholasde4166a2015-11-30 08:57:38 -080076 xpf->getInvariantBlendedColor(optimizations.fColorPOI, &fBlendedColor);
77 fOptFlags = xp->getOptimizations(optimizations, false, nullptr, caps);
cdalton6fd158e2015-05-27 15:08:33 -070078 GetXPOutputTypes(xp, &fPrimaryOutputType, &fSecondaryOutputType);
79 xp->getBlendInfo(&fBlendInfo);
80 TEST_ASSERT(!xp->willReadDstColor());
81 TEST_ASSERT(xp->hasSecondaryOutput() == GrBlendCoeffRefsSrc2(fBlendInfo.fDstBlend));
82 }
83
cdalton1fa45722015-06-02 10:43:39 -070084 GrXPFactory::InvariantBlendedColor fBlendedColor;
cdalton6fd158e2015-05-27 15:08:33 -070085 int fOptFlags;
86 int fPrimaryOutputType;
87 int fSecondaryOutputType;
88 GrXferProcessor::BlendInfo fBlendInfo;
89 };
90
91 static void GetXPOutputTypes(const GrXferProcessor* xp, int* outPrimary, int* outSecondary) {
egdanielf2342722015-11-20 15:12:59 -080092 GrPorterDuffXPFactory::TestGetXPOutputTypes(xp, outPrimary, outSecondary);
cdalton6fd158e2015-05-27 15:08:33 -070093 }
94};
95
egdaniel723b0502015-09-15 09:31:40 -070096static void test_lcd_coverage(skiatest::Reporter* reporter, const GrCaps& caps) {
ethannicholasde4166a2015-11-30 08:57:38 -080097 GrPipelineOptimizations opt;
98 opt.fColorPOI.calcWithInitialValues(NULL, 0, 0, kNone_GrColorComponentFlags, false);
egdaniel723b0502015-09-15 09:31:40 -070099 // Setting 2nd to last value to false and last to true will force covPOI to LCD coverage.
ethannicholasde4166a2015-11-30 08:57:38 -0800100 opt.fCoveragePOI.calcWithInitialValues(NULL, 0, 0, kNone_GrColorComponentFlags, false, true);
egdaniel723b0502015-09-15 09:31:40 -0700101
ethannicholasde4166a2015-11-30 08:57:38 -0800102 SkASSERT(!opt.fColorPOI.isOpaque());
103 SkASSERT(!opt.fColorPOI.isSolidWhite());
104 SkASSERT(!opt.fCoveragePOI.isSolidWhite());
105 SkASSERT(opt.fCoveragePOI.isFourChannelOutput());
egdaniel723b0502015-09-15 09:31:40 -0700106
107 for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) {
108 SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m);
ethannicholasde4166a2015-11-30 08:57:38 -0800109 const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, opt);
egdaniel723b0502015-09-15 09:31:40 -0700110
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}
cdalton6fd158e2015-05-27 15:08:33 -0700287static void test_color_unknown_with_coverage(skiatest::Reporter* reporter, const GrCaps& caps) {
ethannicholasde4166a2015-11-30 08:57:38 -0800288 GrPipelineOptimizations optimizations;
halcanary9d524f22016-03-29 09:03:52 -0700289 optimizations.fColorPOI.calcWithInitialValues(nullptr, 0, 0, kNone_GrColorComponentFlags,
ethannicholasde4166a2015-11-30 08:57:38 -0800290 false);
halcanary9d524f22016-03-29 09:03:52 -0700291 optimizations.fCoveragePOI.calcWithInitialValues(nullptr, 0, 0, kNone_GrColorComponentFlags,
ethannicholasde4166a2015-11-30 08:57:38 -0800292 true);
cdalton6fd158e2015-05-27 15:08:33 -0700293
ethannicholasde4166a2015-11-30 08:57:38 -0800294 SkASSERT(!optimizations.fColorPOI.isOpaque());
295 SkASSERT(!optimizations.fColorPOI.isSolidWhite());
296 SkASSERT(!optimizations.fCoveragePOI.isSolidWhite());
297 SkASSERT(!optimizations.fCoveragePOI.isFourChannelOutput());
cdalton6fd158e2015-05-27 15:08:33 -0700298
299 for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) {
300 SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m);
ethannicholasde4166a2015-11-30 08:57:38 -0800301 const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, optimizations);
cdalton6fd158e2015-05-27 15:08:33 -0700302
egdaniel723b0502015-09-15 09:31:40 -0700303
cdalton6fd158e2015-05-27 15:08:33 -0700304 switch (xfermode) {
305 case SkXfermode::kClear_Mode:
cdalton1fa45722015-06-02 10:43:39 -0700306 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
307 TEST_ASSERT(0 == xpi.fBlendedColor.fKnownColor);
308 TEST_ASSERT(kRGBA_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700309 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:
cdalton1fa45722015-06-02 10:43:39 -0700318 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
319 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
bsalomon7765a472015-07-08 11:26:37 -0700320 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700321 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:
cdalton1fa45722015-06-02 10:43:39 -0700329 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
330 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700331 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:
cdalton1fa45722015-06-02 10:43:39 -0700343 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
344 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700345 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:
cdalton1fa45722015-06-02 10:43:39 -0700354 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
355 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700356 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:
cdalton1fa45722015-06-02 10:43:39 -0700365 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
366 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
bsalomon7765a472015-07-08 11:26:37 -0700367 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700368 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:
cdalton1fa45722015-06-02 10:43:39 -0700376 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
377 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
bsalomon7765a472015-07-08 11:26:37 -0700378 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700379 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:
cdalton1fa45722015-06-02 10:43:39 -0700387 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
388 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
bsalomon7765a472015-07-08 11:26:37 -0700389 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700390 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:
cdalton1fa45722015-06-02 10:43:39 -0700398 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
399 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700400 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:
cdalton1fa45722015-06-02 10:43:39 -0700409 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
410 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700411 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:
cdalton1fa45722015-06-02 10:43:39 -0700420 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
421 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
bsalomon7765a472015-07-08 11:26:37 -0700422 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700423 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:
cdalton1fa45722015-06-02 10:43:39 -0700431 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
432 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700433 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:
cdalton1fa45722015-06-02 10:43:39 -0700442 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
443 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700444 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:
cdalton1fa45722015-06-02 10:43:39 -0700453 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
454 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
bsalomon7765a472015-07-08 11:26:37 -0700455 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700456 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:
cdalton1fa45722015-06-02 10:43:39 -0700464 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
465 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700466 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
481static void test_color_unknown_no_coverage(skiatest::Reporter* reporter, const GrCaps& caps) {
ethannicholasde4166a2015-11-30 08:57:38 -0800482 GrPipelineOptimizations optimizations;
483 optimizations.fColorPOI.calcWithInitialValues(nullptr, 0, GrColorPackRGBA(229, 0, 154, 0),
cdalton6fd158e2015-05-27 15:08:33 -0700484 kR_GrColorComponentFlag | kB_GrColorComponentFlag, false);
halcanary9d524f22016-03-29 09:03:52 -0700485 optimizations.fCoveragePOI.calcWithInitialValues(nullptr, 0, GrColorPackA4(255),
ethannicholasde4166a2015-11-30 08:57:38 -0800486 kRGBA_GrColorComponentFlags, true);
cdalton6fd158e2015-05-27 15:08:33 -0700487
ethannicholasde4166a2015-11-30 08:57:38 -0800488 SkASSERT(!optimizations.fColorPOI.isOpaque());
489 SkASSERT(!optimizations.fColorPOI.isSolidWhite());
490 SkASSERT(optimizations.fCoveragePOI.isSolidWhite());
491 SkASSERT(!optimizations.fCoveragePOI.isFourChannelOutput());
cdalton6fd158e2015-05-27 15:08:33 -0700492
493 for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) {
494 SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m);
ethannicholasde4166a2015-11-30 08:57:38 -0800495 const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, optimizations);
cdalton6fd158e2015-05-27 15:08:33 -0700496
497 switch (xfermode) {
498 case SkXfermode::kClear_Mode:
cdalton1fa45722015-06-02 10:43:39 -0700499 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
500 TEST_ASSERT(0 == xpi.fBlendedColor.fKnownColor);
501 TEST_ASSERT(kRGBA_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700502 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:
cdalton1fa45722015-06-02 10:43:39 -0700512 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
513 TEST_ASSERT(229 == GrColorUnpackR(xpi.fBlendedColor.fKnownColor));
514 TEST_ASSERT(154 == GrColorUnpackB(xpi.fBlendedColor.fKnownColor));
cdalton6fd158e2015-05-27 15:08:33 -0700515 TEST_ASSERT((kR_GrColorComponentFlag |
cdalton1fa45722015-06-02 10:43:39 -0700516 kB_GrColorComponentFlag) == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700517 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:
cdalton1fa45722015-06-02 10:43:39 -0700526 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
527 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700528 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:
cdalton1fa45722015-06-02 10:43:39 -0700540 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
541 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700542 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:
cdalton1fa45722015-06-02 10:43:39 -0700552 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
553 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700554 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:
cdalton1fa45722015-06-02 10:43:39 -0700564 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
565 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700566 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:
cdalton1fa45722015-06-02 10:43:39 -0700575 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
576 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700577 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:
cdalton1fa45722015-06-02 10:43:39 -0700586 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
587 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700588 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:
cdalton1fa45722015-06-02 10:43:39 -0700597 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
598 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700599 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:
cdalton1fa45722015-06-02 10:43:39 -0700609 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
610 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700611 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:
cdalton1fa45722015-06-02 10:43:39 -0700621 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
622 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700623 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:
cdalton1fa45722015-06-02 10:43:39 -0700632 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
633 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700634 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:
cdalton1fa45722015-06-02 10:43:39 -0700644 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
645 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700646 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:
cdalton1fa45722015-06-02 10:43:39 -0700656 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
657 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700658 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:
cdalton1fa45722015-06-02 10:43:39 -0700667 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
668 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700669 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
685static void test_color_opaque_with_coverage(skiatest::Reporter* reporter, const GrCaps& caps) {
ethannicholasde4166a2015-11-30 08:57:38 -0800686 GrPipelineOptimizations optimizations;
halcanary9d524f22016-03-29 09:03:52 -0700687 optimizations.fColorPOI.calcWithInitialValues(nullptr, 0, GrColorPackA4(255),
ethannicholasde4166a2015-11-30 08:57:38 -0800688 kA_GrColorComponentFlag, false);
halcanary9d524f22016-03-29 09:03:52 -0700689 optimizations.fCoveragePOI.calcWithInitialValues(nullptr, 0, 0, kNone_GrColorComponentFlags,
ethannicholasde4166a2015-11-30 08:57:38 -0800690 true);
cdalton6fd158e2015-05-27 15:08:33 -0700691
ethannicholasde4166a2015-11-30 08:57:38 -0800692 SkASSERT(optimizations.fColorPOI.isOpaque());
693 SkASSERT(!optimizations.fColorPOI.isSolidWhite());
694 SkASSERT(!optimizations.fCoveragePOI.isSolidWhite());
695 SkASSERT(!optimizations.fCoveragePOI.isFourChannelOutput());
cdalton6fd158e2015-05-27 15:08:33 -0700696
697 for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) {
698 SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m);
ethannicholasde4166a2015-11-30 08:57:38 -0800699 const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, optimizations);
cdalton6fd158e2015-05-27 15:08:33 -0700700
701 switch (xfermode) {
702 case SkXfermode::kClear_Mode:
cdalton1fa45722015-06-02 10:43:39 -0700703 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
704 TEST_ASSERT(0 == xpi.fBlendedColor.fKnownColor);
705 TEST_ASSERT(kRGBA_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700706 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:
cdalton1fa45722015-06-02 10:43:39 -0700715 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
716 TEST_ASSERT(255 == GrColorUnpackA(xpi.fBlendedColor.fKnownColor));
717 TEST_ASSERT(kA_GrColorComponentFlag == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700718 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:
cdalton1fa45722015-06-02 10:43:39 -0700727 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
728 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700729 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:
cdalton1fa45722015-06-02 10:43:39 -0700741 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
742 TEST_ASSERT(255 == GrColorUnpackA(xpi.fBlendedColor.fKnownColor));
743 TEST_ASSERT(kA_GrColorComponentFlag == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700744 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:
cdalton1fa45722015-06-02 10:43:39 -0700753 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
754 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700755 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:
cdalton1fa45722015-06-02 10:43:39 -0700764 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
765 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700766 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:
cdalton1fa45722015-06-02 10:43:39 -0700775 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
776 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700777 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:
cdalton1fa45722015-06-02 10:43:39 -0700789 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
790 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700791 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:
cdalton1fa45722015-06-02 10:43:39 -0700800 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
801 TEST_ASSERT(0 == xpi.fBlendedColor.fKnownColor);
802 TEST_ASSERT(kRGBA_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700803 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:
cdalton1fa45722015-06-02 10:43:39 -0700812 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
813 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700814 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:
cdalton1fa45722015-06-02 10:43:39 -0700823 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
824 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700825 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:
cdalton1fa45722015-06-02 10:43:39 -0700834 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
835 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700836 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:
cdalton1fa45722015-06-02 10:43:39 -0700845 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
846 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700847 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:
cdalton1fa45722015-06-02 10:43:39 -0700856 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
857 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
bsalomon7765a472015-07-08 11:26:37 -0700858 TEST_ASSERT((kNone_OptFlags) == xpi.fOptFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700859 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:
cdalton1fa45722015-06-02 10:43:39 -0700867 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
868 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700869 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
884static void test_color_opaque_no_coverage(skiatest::Reporter* reporter, const GrCaps& caps) {
ethannicholasde4166a2015-11-30 08:57:38 -0800885 GrPipelineOptimizations optimizations;
886 optimizations.fColorPOI.calcWithInitialValues(nullptr, 0, GrColorPackRGBA(0, 82, 0, 255),
cdalton6fd158e2015-05-27 15:08:33 -0700887 kG_GrColorComponentFlag | kA_GrColorComponentFlag, false);
halcanary9d524f22016-03-29 09:03:52 -0700888 optimizations.fCoveragePOI.calcWithInitialValues(nullptr, 0, GrColorPackA4(255),
ethannicholasde4166a2015-11-30 08:57:38 -0800889 kRGBA_GrColorComponentFlags, true);
cdalton6fd158e2015-05-27 15:08:33 -0700890
ethannicholasde4166a2015-11-30 08:57:38 -0800891 SkASSERT(optimizations.fColorPOI.isOpaque());
892 SkASSERT(!optimizations.fColorPOI.isSolidWhite());
893 SkASSERT(optimizations.fCoveragePOI.isSolidWhite());
894 SkASSERT(!optimizations.fCoveragePOI.isFourChannelOutput());
cdalton6fd158e2015-05-27 15:08:33 -0700895
896 for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) {
897 SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m);
ethannicholasde4166a2015-11-30 08:57:38 -0800898 const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, optimizations);
cdalton6fd158e2015-05-27 15:08:33 -0700899
900 switch (xfermode) {
901 case SkXfermode::kClear_Mode:
cdalton1fa45722015-06-02 10:43:39 -0700902 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
903 TEST_ASSERT(0 == xpi.fBlendedColor.fKnownColor);
904 TEST_ASSERT(kRGBA_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700905 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:
cdalton1fa45722015-06-02 10:43:39 -0700915 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
916 TEST_ASSERT(82 == GrColorUnpackG(xpi.fBlendedColor.fKnownColor));
917 TEST_ASSERT(255 == GrColorUnpackA(xpi.fBlendedColor.fKnownColor));
cdalton6fd158e2015-05-27 15:08:33 -0700918 TEST_ASSERT((kG_GrColorComponentFlag |
cdalton1fa45722015-06-02 10:43:39 -0700919 kA_GrColorComponentFlag) == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700920 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:
cdalton1fa45722015-06-02 10:43:39 -0700929 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
930 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700931 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:
cdalton1fa45722015-06-02 10:43:39 -0700943 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
944 TEST_ASSERT(82 == GrColorUnpackG(xpi.fBlendedColor.fKnownColor));
945 TEST_ASSERT(255 == GrColorUnpackA(xpi.fBlendedColor.fKnownColor));
cdalton6fd158e2015-05-27 15:08:33 -0700946 TEST_ASSERT((kG_GrColorComponentFlag |
cdalton1fa45722015-06-02 10:43:39 -0700947 kA_GrColorComponentFlag) == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700948 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:
cdalton1fa45722015-06-02 10:43:39 -0700957 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
958 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700959 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:
cdalton1fa45722015-06-02 10:43:39 -0700969 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
970 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700971 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:
cdalton1fa45722015-06-02 10:43:39 -0700980 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
981 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700982 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:
cdalton1fa45722015-06-02 10:43:39 -0700994 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
995 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -0700996 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:
cdalton1fa45722015-06-02 10:43:39 -07001005 TEST_ASSERT(!xpi.fBlendedColor.fWillBlendWithDst);
1006 TEST_ASSERT(0 == xpi.fBlendedColor.fKnownColor);
1007 TEST_ASSERT(kRGBA_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -07001008 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:
cdalton1fa45722015-06-02 10:43:39 -07001018 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
1019 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -07001020 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:
cdalton1fa45722015-06-02 10:43:39 -07001029 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
1030 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -07001031 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:
cdalton1fa45722015-06-02 10:43:39 -07001041 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
1042 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -07001043 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:
cdalton1fa45722015-06-02 10:43:39 -07001052 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
1053 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -07001054 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:
cdalton1fa45722015-06-02 10:43:39 -07001064 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
1065 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -07001066 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:
cdalton1fa45722015-06-02 10:43:39 -07001075 TEST_ASSERT(xpi.fBlendedColor.fWillBlendWithDst);
1076 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fBlendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -07001077 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
egdaniel723b0502015-09-15 09:31:40 -07001093static void test_lcd_coverage_fallback_case(skiatest::Reporter* reporter, const GrCaps& caps) {
reed1b55a962015-09-17 20:16:13 -07001094 class TestLCDCoverageBatch: public GrVertexBatch {
1095 public:
1096 DEFINE_BATCH_CLASS_ID
1097
1098 TestLCDCoverageBatch() : INHERITED(ClassID()) {}
1099
1100 private:
halcanary9d524f22016-03-29 09:03:52 -07001101 void computePipelineOptimizations(GrInitInvariantOutput* color,
ethannicholasff210322015-11-24 12:10:10 -08001102 GrInitInvariantOutput* coverage,
1103 GrBatchToXPOverrides* overrides) const override {
1104 color->setKnownFourComponents(GrColorPackRGBA(123, 45, 67, 221));
1105 coverage->setUnknownFourComponents();
ethannicholas22793252016-01-30 09:59:10 -08001106 coverage->setUsingLCDCoverage(); }
cdalton6fd158e2015-05-27 15:08:33 -07001107
1108 const char* name() const override { return "Test LCD Text Batch"; }
ethannicholasff210322015-11-24 12:10:10 -08001109 void initBatchTracker(const GrXPOverridesForBatch&) override {}
bsalomoncb02b382015-08-12 11:14:50 -07001110 bool onCombineIfPossible(GrBatch*, const GrCaps&) override { return false; }
joshualitt144c3c82015-11-30 12:30:13 -08001111 void onPrepareDraws(Target*) const override {};
cdalton6fd158e2015-05-27 15:08:33 -07001112
reed1b55a962015-09-17 20:16:13 -07001113 typedef GrVertexBatch INHERITED;
cdalton6fd158e2015-05-27 15:08:33 -07001114 } testLCDCoverageBatch;
1115
ethannicholasff210322015-11-24 12:10:10 -08001116 GrPipelineOptimizations opts;
1117 testLCDCoverageBatch.getPipelineOptimizations(&opts);
1118 GrProcOptInfo colorPOI = opts.fColorPOI;
1119 GrProcOptInfo covPOI = opts.fCoveragePOI;
cdalton6fd158e2015-05-27 15:08:33 -07001120
1121 SkASSERT(kRGBA_GrColorComponentFlags == colorPOI.validFlags());
1122 SkASSERT(covPOI.isFourChannelOutput());
1123
bungeman06ca8ec2016-06-09 08:01:03 -07001124 sk_sp<GrXPFactory> xpf(GrPorterDuffXPFactory::Make(SkXfermode::kSrcOver_Mode));
cdalton3ccf2e72016-05-06 09:41:16 -07001125 TEST_ASSERT(!xpf->willNeedDstTexture(caps, opts));
cdalton6fd158e2015-05-27 15:08:33 -07001126
cdalton86ae0a92015-06-08 15:11:04 -07001127 SkAutoTUnref<GrXferProcessor> xp(
ethannicholasde4166a2015-11-30 08:57:38 -08001128 xpf->createXferProcessor(opts, false, nullptr, caps));
cdalton6fd158e2015-05-27 15:08:33 -07001129 if (!xp) {
1130 ERRORF(reporter, "Failed to create an XP with LCD coverage.");
1131 return;
1132 }
1133
cdalton1fa45722015-06-02 10:43:39 -07001134 GrXPFactory::InvariantBlendedColor blendedColor;
1135 xpf->getInvariantBlendedColor(colorPOI, &blendedColor);
1136 TEST_ASSERT(blendedColor.fWillBlendWithDst);
1137 TEST_ASSERT(kNone_GrColorComponentFlags == blendedColor.fKnownColorFlags);
cdalton6fd158e2015-05-27 15:08:33 -07001138
1139 GrColor overrideColor;
ethannicholasde4166a2015-11-30 08:57:38 -08001140 xp->getOptimizations(opts, false, &overrideColor, caps);
cdalton6fd158e2015-05-27 15:08:33 -07001141
1142 GrXferProcessor::BlendInfo blendInfo;
1143 xp->getBlendInfo(&blendInfo);
1144 TEST_ASSERT(blendInfo.fWriteColor);
1145}
1146
kkinnunen15302832015-12-01 04:35:26 -08001147DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, /*factory*/) {
cdalton6fd158e2015-05-27 15:08:33 -07001148 GrContextOptions opts;
1149 opts.fSuppressDualSourceBlending = true;
bsalomon3724e572016-03-30 18:56:19 -07001150 sk_gpu_test::GrContextFactory mockFactory(opts);
bsalomon85b4b532016-04-05 11:06:27 -07001151 GrContext* ctx = mockFactory.get(sk_gpu_test::GrContextFactory::kNullGL_ContextType);
cdalton6fd158e2015-05-27 15:08:33 -07001152 if (!ctx) {
1153 SkFAIL("Failed to create null context without ARB_blend_func_extended.");
1154 return;
1155 }
1156
bsalomon76228632015-05-29 08:02:10 -07001157 const GrCaps& caps = *ctx->caps();
cdalton6fd158e2015-05-27 15:08:33 -07001158 if (caps.shaderCaps()->dualSourceBlendingSupport()) {
1159 SkFAIL("Null context failed to honor request for no ARB_blend_func_extended.");
1160 return;
1161 }
1162
bsalomon091f60c2015-11-10 11:54:56 -08001163 GrBackendObject backendTex =
kkinnunen15302832015-12-01 04:35:26 -08001164 ctx->getGpu()->createTestingOnlyBackendTexture(nullptr, 100, 100,
1165 kRGBA_8888_GrPixelConfig);
cdalton6fd158e2015-05-27 15:08:33 -07001166 GrBackendTextureDesc fakeDesc;
1167 fakeDesc.fConfig = kRGBA_8888_GrPixelConfig;
1168 fakeDesc.fWidth = fakeDesc.fHeight = 100;
bsalomon091f60c2015-11-10 11:54:56 -08001169 fakeDesc.fTextureHandle = backendTex;
bsalomoneae62002015-07-31 13:59:30 -07001170 SkAutoTUnref<GrTexture> fakeTexture(ctx->textureProvider()->wrapBackendTexture(fakeDesc,
bsalomon6dc6f5f2015-06-18 09:12:16 -07001171 kBorrow_GrWrapOwnership));
cdalton6fd158e2015-05-27 15:08:33 -07001172 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++) {
ethannicholasde4166a2015-11-30 08:57:38 -08001188 GrPipelineOptimizations optimizations;
halcanary9d524f22016-03-29 09:03:52 -07001189 optimizations.fColorPOI.calcWithInitialValues(nullptr, 0, testColors[c], testColorFlags[c],
ethannicholasde4166a2015-11-30 08:57:38 -08001190 false);
cdalton6fd158e2015-05-27 15:08:33 -07001191 for (int f = 0; f <= 1; f++) {
cdalton6fd158e2015-05-27 15:08:33 -07001192 if (!f) {
halcanary9d524f22016-03-29 09:03:52 -07001193 optimizations.fCoveragePOI.calcWithInitialValues(nullptr, 0, 0,
ethannicholasde4166a2015-11-30 08:57:38 -08001194 kNone_GrColorComponentFlags, true);
cdalton6fd158e2015-05-27 15:08:33 -07001195 } else {
ethannicholasde4166a2015-11-30 08:57:38 -08001196 optimizations.fCoveragePOI.calcWithInitialValues(nullptr, 0, GrColorPackA4(255),
1197 kRGBA_GrColorComponentFlags, true);
cdalton6fd158e2015-05-27 15:08:33 -07001198 }
1199 for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) {
1200 SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m);
bungeman06ca8ec2016-06-09 08:01:03 -07001201 sk_sp<GrXPFactory> xpf(GrPorterDuffXPFactory::Make(xfermode));
cdalton86ae0a92015-06-08 15:11:04 -07001202 GrXferProcessor::DstTexture* dstTexture =
cdalton3ccf2e72016-05-06 09:41:16 -07001203 xpf->willNeedDstTexture(caps, optimizations) ? &fakeDstTexture : 0;
cdalton86ae0a92015-06-08 15:11:04 -07001204 SkAutoTUnref<GrXferProcessor> xp(
ethannicholasde4166a2015-11-30 08:57:38 -08001205 xpf->createXferProcessor(optimizations, false, dstTexture, caps));
cdalton6fd158e2015-05-27 15:08:33 -07001206 if (!xp) {
1207 ERRORF(reporter, "Failed to create an XP without dual source blending.");
1208 return;
1209 }
1210 TEST_ASSERT(!xp->hasSecondaryOutput());
ethannicholasde4166a2015-11-30 08:57:38 -08001211 xp->getOptimizations(optimizations, false, 0, caps);
cdalton6fd158e2015-05-27 15:08:33 -07001212 TEST_ASSERT(!xp->hasSecondaryOutput());
1213 }
1214 }
1215 }
bsalomon091f60c2015-11-10 11:54:56 -08001216 ctx->getGpu()->deleteTestingOnlyBackendTexture(backendTex);
cdalton6fd158e2015-05-27 15:08:33 -07001217}
1218
1219#endif