blob: c3553ad541d7f8812374c1a93704618e6bc17c41 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "tests/Test.h"
cdalton6fd158e2015-05-27 15:08:33 -07009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/gpu/GrBackendSurface.h"
11#include "include/gpu/GrContextOptions.h"
Robert Phillips6d344c32020-07-06 10:56:46 -040012#include "include/gpu/GrDirectContext.h"
Adlai Hollera0693042020-10-14 11:23:11 -040013#include "src/gpu/GrDirectContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrGpu.h"
15#include "src/gpu/GrProxyProvider.h"
16#include "src/gpu/GrXferProcessor.h"
17#include "src/gpu/effects/GrPorterDuffXferProcessor.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050018#include "tools/gpu/GrContextFactory.h"
Brian Salomon72050802020-10-12 20:45:06 -040019#include "tools/gpu/ManagedBackendTexture.h"
cdalton6fd158e2015-05-27 15:08:33 -070020
21////////////////////////////////////////////////////////////////////////////////
22
23static void test_color_unknown_with_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
Brian Salomon31853842017-03-28 16:32:05 -040024static void test_color_not_opaque_no_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
cdalton6fd158e2015-05-27 15:08:33 -070025static void test_color_opaque_with_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
26static void test_color_opaque_no_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
27static void test_lcd_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
egdaniel723b0502015-09-15 09:31:40 -070028static void test_lcd_coverage_fallback_case(skiatest::Reporter* reporter, const GrCaps& caps);
cdalton6fd158e2015-05-27 15:08:33 -070029
Brian Osmand2ca3122019-03-26 11:31:16 -040030DEF_GPUTEST(GrPorterDuff, reporter, /*ctxInfo*/) {
31 GrMockOptions mockOptions;
32 mockOptions.fDualSourceBlendingSupport = true;
Robert Phillipsf4f80112020-07-13 16:13:31 -040033 sk_sp<GrDirectContext> context = GrDirectContext::MakeMock(&mockOptions, GrContextOptions());
Brian Osmand2ca3122019-03-26 11:31:16 -040034 const GrCaps& caps = *context->priv().getGpu()->caps();
35
cdalton6fd158e2015-05-27 15:08:33 -070036 if (!caps.shaderCaps()->dualSourceBlendingSupport()) {
Ben Wagnerb4aab9a2017-08-16 10:53:04 -040037 SK_ABORT("Null context does not support dual source blending.");
cdalton6fd158e2015-05-27 15:08:33 -070038 }
39
40 test_color_unknown_with_coverage(reporter, caps);
Brian Salomon31853842017-03-28 16:32:05 -040041 test_color_not_opaque_no_coverage(reporter, caps);
cdalton6fd158e2015-05-27 15:08:33 -070042 test_color_opaque_with_coverage(reporter, caps);
43 test_color_opaque_no_coverage(reporter, caps);
44 test_lcd_coverage(reporter, caps);
egdaniel723b0502015-09-15 09:31:40 -070045 test_lcd_coverage_fallback_case(reporter, caps);
cdalton6fd158e2015-05-27 15:08:33 -070046}
47
48////////////////////////////////////////////////////////////////////////////////
49
50#define TEST_ASSERT(...) REPORTER_ASSERT(reporter, __VA_ARGS__)
51
52enum {
53 kNone_OutputType,
54 kCoverage_OutputType,
55 kModulate_OutputType,
egdaniel723b0502015-09-15 09:31:40 -070056 kSAModulate_OutputType,
cdalton6fd158e2015-05-27 15:08:33 -070057 kISAModulate_OutputType,
58 kISCModulate_OutputType
59};
Greg Daniel79cdf282017-05-22 15:56:22 -040060static const int kInvalid_OutputType = -1;
cdalton6fd158e2015-05-27 15:08:33 -070061
Brian Salomon48d1b4c2017-04-08 07:38:53 -040062static GrProcessorSet::Analysis do_analysis(const GrXPFactory* xpf,
63 const GrProcessorAnalysisColor& colorInput,
64 GrProcessorAnalysisCoverage coverageInput,
65 const GrCaps& caps) {
66 GrPaint paint;
67 paint.setXPFactory(xpf);
68 GrProcessorSet procs(std::move(paint));
Brian Osmancf860852018-10-31 14:04:39 -040069 SkPMColor4f overrideColor;
Chris Daltonb8fff0d2019-03-05 10:11:58 -070070 GrProcessorSet::Analysis analysis = procs.finalize(
Chris Dalton57ab06c2021-04-22 12:57:28 -060071 colorInput, coverageInput, nullptr, &GrUserStencilSettings::kUnused, caps,
72 GrClampType::kAuto, &overrideColor);
Brian Salomon48d1b4c2017-04-08 07:38:53 -040073 return analysis;
74}
75
cdalton6fd158e2015-05-27 15:08:33 -070076class GrPorterDuffTest {
77public:
78 struct XPInfo {
Mike Reed7d954ad2016-10-28 15:42:34 -040079 XPInfo(skiatest::Reporter* reporter, SkBlendMode xfermode, const GrCaps& caps,
Brian Salomona811b122017-03-30 08:21:32 -040080 GrProcessorAnalysisColor inputColor, GrProcessorAnalysisCoverage inputCoverage) {
Brian Salomona1633922017-01-09 11:46:10 -050081 const GrXPFactory* xpf = GrPorterDuffXPFactory::Get(xfermode);
Brian Salomon48d1b4c2017-04-08 07:38:53 -040082
Greg Daniel79cdf282017-05-22 15:56:22 -040083 bool isLCD = GrProcessorAnalysisCoverage::kLCD == inputCoverage;
84
Brian Salomon48d1b4c2017-04-08 07:38:53 -040085 GrProcessorSet::Analysis analysis = do_analysis(xpf, inputColor, inputCoverage, caps);
Brian Salomon31853842017-03-28 16:32:05 -040086 fCompatibleWithCoverageAsAlpha = analysis.isCompatibleWithCoverageAsAlpha();
Chris Daltonf2fb80f2020-12-03 12:37:59 -070087 fUnaffectedByDstValue = analysis.unaffectedByDstValue();
Brian Salomon48d1b4c2017-04-08 07:38:53 -040088 fIgnoresInputColor = analysis.inputColorIsIgnored();
Brian Salomond61c9d92017-04-10 10:54:25 -040089 sk_sp<const GrXferProcessor> xp(
Chris Dalton57ab06c2021-04-22 12:57:28 -060090 GrXPFactory::MakeXferProcessor(xpf, inputColor, inputCoverage, caps,
Brian Osman5ced0bf2019-03-15 10:15:29 -040091 GrClampType::kAuto));
Greg Daniel79cdf282017-05-22 15:56:22 -040092 TEST_ASSERT(!analysis.requiresDstTexture() ||
93 (isLCD &&
94 !caps.shaderCaps()->dstReadInShaderSupport() &&
95 (SkBlendMode::kSrcOver != xfermode ||
96 !inputColor.isOpaque())));
Chris Dalton945ee652019-01-23 09:10:36 -070097 // Porter Duff modes currently only use fixed-function or shader blending, and Ganesh
98 // doesn't yet make use of framebuffer fetches that require a barrier
99 // (e.g., QCOM_shader_framebuffer_fetch_noncoherent). So dst textures and xfer barriers
100 // should always go hand in hand for Porter Duff modes.
101 TEST_ASSERT(analysis.requiresDstTexture() == analysis.requiresNonOverlappingDraws());
Hal Canary342b7ac2016-11-04 11:49:42 -0400102 GetXPOutputTypes(xp.get(), &fPrimaryOutputType, &fSecondaryOutputType);
Chris Daltonbbb3f642019-07-24 12:25:08 -0400103 fBlendInfo = xp->getBlendInfo();
Greg Daniel79cdf282017-05-22 15:56:22 -0400104 TEST_ASSERT(!xp->willReadDstColor() ||
105 (isLCD && (SkBlendMode::kSrcOver != xfermode ||
106 !inputColor.isOpaque())));
cdalton6fd158e2015-05-27 15:08:33 -0700107 TEST_ASSERT(xp->hasSecondaryOutput() == GrBlendCoeffRefsSrc2(fBlendInfo.fDstBlend));
108 }
109
Brian Salomon31853842017-03-28 16:32:05 -0400110 bool fCompatibleWithCoverageAsAlpha;
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700111 bool fUnaffectedByDstValue;
Brian Salomon31853842017-03-28 16:32:05 -0400112 bool fIgnoresInputColor;
cdalton6fd158e2015-05-27 15:08:33 -0700113 int fPrimaryOutputType;
114 int fSecondaryOutputType;
115 GrXferProcessor::BlendInfo fBlendInfo;
116 };
117
118 static void GetXPOutputTypes(const GrXferProcessor* xp, int* outPrimary, int* outSecondary) {
egdanielf2342722015-11-20 15:12:59 -0800119 GrPorterDuffXPFactory::TestGetXPOutputTypes(xp, outPrimary, outSecondary);
cdalton6fd158e2015-05-27 15:08:33 -0700120 }
121};
122
egdaniel723b0502015-09-15 09:31:40 -0700123static void test_lcd_coverage(skiatest::Reporter* reporter, const GrCaps& caps) {
Greg Daniel6ebe4b92017-05-19 10:56:46 -0400124 GrProcessorAnalysisColor inputColor = GrProcessorAnalysisColor::Opaque::kYes;
Brian Salomona811b122017-03-30 08:21:32 -0400125 GrProcessorAnalysisCoverage inputCoverage = GrProcessorAnalysisCoverage::kLCD;
egdaniel723b0502015-09-15 09:31:40 -0700126
Mike Reed7d954ad2016-10-28 15:42:34 -0400127 for (int m = 0; m <= (int)SkBlendMode::kLastCoeffMode; m++) {
128 SkBlendMode xfermode = static_cast<SkBlendMode>(m);
Brian Salomon31853842017-03-28 16:32:05 -0400129 const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, inputColor, inputCoverage);
egdaniel723b0502015-09-15 09:31:40 -0700130 switch (xfermode) {
Mike Reed7d954ad2016-10-28 15:42:34 -0400131 case SkBlendMode::kClear:
Brian Salomon31853842017-03-28 16:32:05 -0400132 TEST_ASSERT(xpi.fIgnoresInputColor);
133 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700134 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
Greg Daniel79cdf282017-05-22 15:56:22 -0400135 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
136 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
137 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
138 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
139 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
egdaniel723b0502015-09-15 09:31:40 -0700140 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
141 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400142 case SkBlendMode::kSrc:
Brian Salomon31853842017-03-28 16:32:05 -0400143 TEST_ASSERT(!xpi.fIgnoresInputColor);
144 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700145 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
Greg Daniel79cdf282017-05-22 15:56:22 -0400146 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
147 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
egdaniel723b0502015-09-15 09:31:40 -0700148 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
149 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
Greg Daniel79cdf282017-05-22 15:56:22 -0400150 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
egdaniel723b0502015-09-15 09:31:40 -0700151 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
152 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400153 case SkBlendMode::kDst:
Brian Salomon31853842017-03-28 16:32:05 -0400154 TEST_ASSERT(xpi.fIgnoresInputColor);
155 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700156 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
Greg Daniel79cdf282017-05-22 15:56:22 -0400157 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
158 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
egdaniel723b0502015-09-15 09:31:40 -0700159 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
Greg Daniel79cdf282017-05-22 15:56:22 -0400160 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
161 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
162 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
egdaniel723b0502015-09-15 09:31:40 -0700163 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400164 case SkBlendMode::kSrcOver:
Brian Salomon31853842017-03-28 16:32:05 -0400165 TEST_ASSERT(!xpi.fIgnoresInputColor);
166 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700167 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
egdaniel723b0502015-09-15 09:31:40 -0700168 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
169 TEST_ASSERT(kSAModulate_OutputType == xpi.fSecondaryOutputType);
170 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
171 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
172 TEST_ASSERT(kIS2C_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
173 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
174 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400175 case SkBlendMode::kDstOver:
Brian Salomon31853842017-03-28 16:32:05 -0400176 TEST_ASSERT(!xpi.fIgnoresInputColor);
177 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700178 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
Greg Daniel79cdf282017-05-22 15:56:22 -0400179 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
180 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
egdaniel723b0502015-09-15 09:31:40 -0700181 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
Greg Daniel79cdf282017-05-22 15:56:22 -0400182 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
183 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
egdaniel723b0502015-09-15 09:31:40 -0700184 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
185 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400186 case SkBlendMode::kSrcIn:
Brian Salomon31853842017-03-28 16:32:05 -0400187 TEST_ASSERT(!xpi.fIgnoresInputColor);
188 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700189 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
Greg Daniel79cdf282017-05-22 15:56:22 -0400190 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
191 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
egdaniel723b0502015-09-15 09:31:40 -0700192 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
Greg Daniel79cdf282017-05-22 15:56:22 -0400193 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
194 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
egdaniel723b0502015-09-15 09:31:40 -0700195 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
196 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400197 case SkBlendMode::kDstIn:
Brian Salomon31853842017-03-28 16:32:05 -0400198 TEST_ASSERT(!xpi.fIgnoresInputColor);
199 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700200 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
Greg Daniel79cdf282017-05-22 15:56:22 -0400201 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
202 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
203 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
204 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
205 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
egdaniel723b0502015-09-15 09:31:40 -0700206 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
207 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400208 case SkBlendMode::kSrcOut:
Brian Salomon31853842017-03-28 16:32:05 -0400209 TEST_ASSERT(!xpi.fIgnoresInputColor);
210 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700211 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
Greg Daniel79cdf282017-05-22 15:56:22 -0400212 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
213 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
egdaniel723b0502015-09-15 09:31:40 -0700214 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
Greg Daniel79cdf282017-05-22 15:56:22 -0400215 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
216 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
egdaniel723b0502015-09-15 09:31:40 -0700217 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
218 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400219 case SkBlendMode::kDstOut:
Brian Salomon31853842017-03-28 16:32:05 -0400220 TEST_ASSERT(!xpi.fIgnoresInputColor);
221 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700222 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
Greg Daniel79cdf282017-05-22 15:56:22 -0400223 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
224 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
egdaniel723b0502015-09-15 09:31:40 -0700225 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
Greg Daniel79cdf282017-05-22 15:56:22 -0400226 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
227 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
egdaniel723b0502015-09-15 09:31:40 -0700228 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
229 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400230 case SkBlendMode::kSrcATop:
Brian Salomon31853842017-03-28 16:32:05 -0400231 TEST_ASSERT(!xpi.fIgnoresInputColor);
232 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700233 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
Greg Daniel79cdf282017-05-22 15:56:22 -0400234 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
235 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
egdaniel723b0502015-09-15 09:31:40 -0700236 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
Greg Daniel79cdf282017-05-22 15:56:22 -0400237 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
238 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
egdaniel723b0502015-09-15 09:31:40 -0700239 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
240 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400241 case SkBlendMode::kDstATop:
Brian Salomon31853842017-03-28 16:32:05 -0400242 TEST_ASSERT(!xpi.fIgnoresInputColor);
243 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700244 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
Greg Daniel79cdf282017-05-22 15:56:22 -0400245 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
246 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
egdaniel723b0502015-09-15 09:31:40 -0700247 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
Greg Daniel79cdf282017-05-22 15:56:22 -0400248 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
249 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
egdaniel723b0502015-09-15 09:31:40 -0700250 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
251 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400252 case SkBlendMode::kXor:
Brian Salomon31853842017-03-28 16:32:05 -0400253 TEST_ASSERT(!xpi.fIgnoresInputColor);
254 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700255 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
Greg Daniel79cdf282017-05-22 15:56:22 -0400256 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
257 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
egdaniel723b0502015-09-15 09:31:40 -0700258 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
Greg Daniel79cdf282017-05-22 15:56:22 -0400259 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
260 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
egdaniel723b0502015-09-15 09:31:40 -0700261 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
262 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400263 case SkBlendMode::kPlus:
Brian Salomon31853842017-03-28 16:32:05 -0400264 TEST_ASSERT(!xpi.fIgnoresInputColor);
265 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700266 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
Greg Daniel79cdf282017-05-22 15:56:22 -0400267 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
268 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
egdaniel723b0502015-09-15 09:31:40 -0700269 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
270 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
Greg Daniel79cdf282017-05-22 15:56:22 -0400271 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
egdaniel723b0502015-09-15 09:31:40 -0700272 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
273 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400274 case SkBlendMode::kModulate:
Brian Salomon31853842017-03-28 16:32:05 -0400275 TEST_ASSERT(!xpi.fIgnoresInputColor);
276 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700277 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
Greg Daniel79cdf282017-05-22 15:56:22 -0400278 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
279 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
280 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
281 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
282 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
egdaniel723b0502015-09-15 09:31:40 -0700283 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
284 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400285 case SkBlendMode::kScreen:
Brian Salomon31853842017-03-28 16:32:05 -0400286 TEST_ASSERT(!xpi.fIgnoresInputColor);
287 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700288 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
Greg Daniel79cdf282017-05-22 15:56:22 -0400289 TEST_ASSERT(kInvalid_OutputType == xpi.fPrimaryOutputType);
290 TEST_ASSERT(kInvalid_OutputType == xpi.fSecondaryOutputType);
egdaniel723b0502015-09-15 09:31:40 -0700291 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
292 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
Greg Daniel79cdf282017-05-22 15:56:22 -0400293 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
egdaniel723b0502015-09-15 09:31:40 -0700294 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
295 break;
296 default:
297 ERRORF(reporter, "Invalid xfermode.");
298 break;
299 }
300 }
301}
cdalton6fd158e2015-05-27 15:08:33 -0700302static void test_color_unknown_with_coverage(skiatest::Reporter* reporter, const GrCaps& caps) {
Brian Salomona811b122017-03-30 08:21:32 -0400303 GrProcessorAnalysisColor inputColor = GrProcessorAnalysisColor::Opaque::kNo;
304 GrProcessorAnalysisCoverage inputCoverage = GrProcessorAnalysisCoverage::kSingleChannel;
cdalton6fd158e2015-05-27 15:08:33 -0700305
Mike Reed7d954ad2016-10-28 15:42:34 -0400306 for (int m = 0; m <= (int)SkBlendMode::kLastCoeffMode; m++) {
307 SkBlendMode xfermode = static_cast<SkBlendMode>(m);
Brian Salomon31853842017-03-28 16:32:05 -0400308 const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, inputColor, inputCoverage);
cdalton6fd158e2015-05-27 15:08:33 -0700309 switch (xfermode) {
Mike Reed7d954ad2016-10-28 15:42:34 -0400310 case SkBlendMode::kClear:
Brian Salomon31853842017-03-28 16:32:05 -0400311 TEST_ASSERT(xpi.fIgnoresInputColor);
312 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700313 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700314 TEST_ASSERT(kCoverage_OutputType == xpi.fPrimaryOutputType);
315 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
316 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.fEquation);
317 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
318 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
319 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
320 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400321 case SkBlendMode::kSrc:
Brian Salomon31853842017-03-28 16:32:05 -0400322 TEST_ASSERT(!xpi.fIgnoresInputColor);
323 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700324 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700325 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
326 TEST_ASSERT(kCoverage_OutputType == xpi.fSecondaryOutputType);
327 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
328 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
329 TEST_ASSERT(kIS2A_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
330 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
331 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400332 case SkBlendMode::kDst:
Brian Salomon31853842017-03-28 16:32:05 -0400333 TEST_ASSERT(xpi.fIgnoresInputColor);
334 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700335 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700336 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
337 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
338 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
339 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
340 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
341 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor);
342 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400343 case SkBlendMode::kSrcOver:
Brian Salomon31853842017-03-28 16:32:05 -0400344 TEST_ASSERT(!xpi.fIgnoresInputColor);
345 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700346 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700347 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
348 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
349 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
350 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
351 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
352 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
353 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400354 case SkBlendMode::kDstOver:
Brian Salomon31853842017-03-28 16:32:05 -0400355 TEST_ASSERT(!xpi.fIgnoresInputColor);
356 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700357 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700358 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
359 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
360 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
361 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
362 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
363 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
364 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400365 case SkBlendMode::kSrcIn:
Brian Salomon31853842017-03-28 16:32:05 -0400366 TEST_ASSERT(!xpi.fIgnoresInputColor);
367 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700368 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700369 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
370 TEST_ASSERT(kCoverage_OutputType == xpi.fSecondaryOutputType);
371 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
372 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
373 TEST_ASSERT(kIS2A_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
374 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
375 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400376 case SkBlendMode::kDstIn:
Brian Salomon31853842017-03-28 16:32:05 -0400377 TEST_ASSERT(!xpi.fIgnoresInputColor);
378 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700379 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700380 TEST_ASSERT(kISAModulate_OutputType == xpi.fPrimaryOutputType);
381 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
382 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.fEquation);
383 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
384 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
385 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
386 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400387 case SkBlendMode::kSrcOut:
Brian Salomon31853842017-03-28 16:32:05 -0400388 TEST_ASSERT(!xpi.fIgnoresInputColor);
389 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700390 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700391 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
392 TEST_ASSERT(kCoverage_OutputType == xpi.fSecondaryOutputType);
393 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
394 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
395 TEST_ASSERT(kIS2A_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
396 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
397 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400398 case SkBlendMode::kDstOut:
Brian Salomon31853842017-03-28 16:32:05 -0400399 TEST_ASSERT(!xpi.fIgnoresInputColor);
400 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700401 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700402 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
403 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
404 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
405 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
406 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
407 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
408 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400409 case SkBlendMode::kSrcATop:
Brian Salomon31853842017-03-28 16:32:05 -0400410 TEST_ASSERT(!xpi.fIgnoresInputColor);
411 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700412 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700413 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
414 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
415 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
416 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
417 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
418 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
419 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400420 case SkBlendMode::kDstATop:
Brian Salomon31853842017-03-28 16:32:05 -0400421 TEST_ASSERT(!xpi.fIgnoresInputColor);
422 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700423 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700424 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
425 TEST_ASSERT(kISAModulate_OutputType == xpi.fSecondaryOutputType);
426 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
427 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
428 TEST_ASSERT(kIS2C_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
429 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
430 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400431 case SkBlendMode::kXor:
Brian Salomon31853842017-03-28 16:32:05 -0400432 TEST_ASSERT(!xpi.fIgnoresInputColor);
433 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700434 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700435 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
436 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
437 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
438 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
439 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
440 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
441 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400442 case SkBlendMode::kPlus:
Brian Salomon31853842017-03-28 16:32:05 -0400443 TEST_ASSERT(!xpi.fIgnoresInputColor);
444 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700445 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700446 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
447 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
448 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
449 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
450 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
451 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
452 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400453 case SkBlendMode::kModulate:
Brian Salomon31853842017-03-28 16:32:05 -0400454 TEST_ASSERT(!xpi.fIgnoresInputColor);
455 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700456 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700457 TEST_ASSERT(kISCModulate_OutputType == xpi.fPrimaryOutputType);
458 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
459 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.fEquation);
460 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
461 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
462 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
463 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400464 case SkBlendMode::kScreen:
Brian Salomon31853842017-03-28 16:32:05 -0400465 TEST_ASSERT(!xpi.fIgnoresInputColor);
466 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700467 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700468 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
469 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
470 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
471 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
472 TEST_ASSERT(kISC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
473 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
474 break;
475 default:
476 ERRORF(reporter, "Invalid xfermode.");
477 break;
478 }
479 }
480}
481
Brian Salomon31853842017-03-28 16:32:05 -0400482static void test_color_not_opaque_no_coverage(skiatest::Reporter* reporter, const GrCaps& caps) {
Brian Osmancf860852018-10-31 14:04:39 -0400483 GrProcessorAnalysisColor inputColor(
484 SkPMColor4f::FromBytes_RGBA(GrColorPackRGBA(229, 0, 154, 240)));
Brian Salomona811b122017-03-30 08:21:32 -0400485 GrProcessorAnalysisCoverage inputCoverage = GrProcessorAnalysisCoverage::kNone;
cdalton6fd158e2015-05-27 15:08:33 -0700486
Mike Reed7d954ad2016-10-28 15:42:34 -0400487 for (int m = 0; m <= (int)SkBlendMode::kLastCoeffMode; m++) {
488 SkBlendMode xfermode = static_cast<SkBlendMode>(m);
Brian Salomon31853842017-03-28 16:32:05 -0400489 const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, inputColor, inputCoverage);
cdalton6fd158e2015-05-27 15:08:33 -0700490 switch (xfermode) {
Mike Reed7d954ad2016-10-28 15:42:34 -0400491 case SkBlendMode::kClear:
Brian Salomon31853842017-03-28 16:32:05 -0400492 TEST_ASSERT(xpi.fIgnoresInputColor);
Greg Danielc5296812020-02-28 13:06:02 -0500493 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700494 TEST_ASSERT(xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700495 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
496 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
497 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
498 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
499 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
500 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
501 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400502 case SkBlendMode::kSrc:
Brian Salomon31853842017-03-28 16:32:05 -0400503 TEST_ASSERT(!xpi.fIgnoresInputColor);
Greg Danielc5296812020-02-28 13:06:02 -0500504 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700505 TEST_ASSERT(xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700506 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
507 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
508 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
509 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
510 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
511 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
512 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400513 case SkBlendMode::kDst:
Brian Salomon31853842017-03-28 16:32:05 -0400514 TEST_ASSERT(xpi.fIgnoresInputColor);
515 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700516 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700517 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
518 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
519 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
520 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
521 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
522 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor);
523 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400524 case SkBlendMode::kSrcOver:
Brian Salomon31853842017-03-28 16:32:05 -0400525 TEST_ASSERT(!xpi.fIgnoresInputColor);
526 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700527 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700528 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
529 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
530 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
531 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
532 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
533 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
534 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400535 case SkBlendMode::kDstOver:
Brian Salomon31853842017-03-28 16:32:05 -0400536 TEST_ASSERT(!xpi.fIgnoresInputColor);
537 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700538 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700539 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
540 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
541 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
542 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
543 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
544 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
545 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400546 case SkBlendMode::kSrcIn:
Brian Salomon31853842017-03-28 16:32:05 -0400547 TEST_ASSERT(!xpi.fIgnoresInputColor);
Greg Danielc5296812020-02-28 13:06:02 -0500548 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700549 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700550 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
551 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
552 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
553 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
554 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
555 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
556 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400557 case SkBlendMode::kDstIn:
Brian Salomon31853842017-03-28 16:32:05 -0400558 TEST_ASSERT(!xpi.fIgnoresInputColor);
Greg Danielc5296812020-02-28 13:06:02 -0500559 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700560 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700561 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
562 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
563 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
564 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
565 TEST_ASSERT(kSA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
566 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
567 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400568 case SkBlendMode::kSrcOut:
Brian Salomon31853842017-03-28 16:32:05 -0400569 TEST_ASSERT(!xpi.fIgnoresInputColor);
Greg Danielc5296812020-02-28 13:06:02 -0500570 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700571 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700572 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
573 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
574 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
575 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
576 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
577 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
578 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400579 case SkBlendMode::kDstOut:
Brian Salomon31853842017-03-28 16:32:05 -0400580 TEST_ASSERT(!xpi.fIgnoresInputColor);
581 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700582 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700583 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
584 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
585 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
586 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
587 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
588 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
589 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400590 case SkBlendMode::kSrcATop:
Brian Salomon31853842017-03-28 16:32:05 -0400591 TEST_ASSERT(!xpi.fIgnoresInputColor);
592 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700593 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700594 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
595 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
596 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
597 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
598 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
599 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
600 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400601 case SkBlendMode::kDstATop:
Brian Salomon31853842017-03-28 16:32:05 -0400602 TEST_ASSERT(!xpi.fIgnoresInputColor);
Greg Danielc5296812020-02-28 13:06:02 -0500603 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700604 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700605 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
606 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
607 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
608 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
609 TEST_ASSERT(kSA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
610 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
611 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400612 case SkBlendMode::kXor:
Brian Salomon31853842017-03-28 16:32:05 -0400613 TEST_ASSERT(!xpi.fIgnoresInputColor);
614 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700615 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700616 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
617 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
618 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
619 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
620 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
621 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
622 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400623 case SkBlendMode::kPlus:
Brian Salomon31853842017-03-28 16:32:05 -0400624 TEST_ASSERT(!xpi.fIgnoresInputColor);
625 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700626 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700627 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
628 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
629 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
630 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
631 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
632 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
633 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400634 case SkBlendMode::kModulate:
Brian Salomon31853842017-03-28 16:32:05 -0400635 TEST_ASSERT(!xpi.fIgnoresInputColor);
Greg Danielc5296812020-02-28 13:06:02 -0500636 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700637 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700638 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
639 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
640 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
641 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
642 TEST_ASSERT(kSC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
643 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
644 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400645 case SkBlendMode::kScreen:
Brian Salomon31853842017-03-28 16:32:05 -0400646 TEST_ASSERT(!xpi.fIgnoresInputColor);
647 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700648 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700649 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
650 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
651 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
652 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
653 TEST_ASSERT(kISC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
654 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
655 break;
656 default:
657 ERRORF(reporter, "Invalid xfermode.");
658 break;
659 }
660 }
661}
662
663static void test_color_opaque_with_coverage(skiatest::Reporter* reporter, const GrCaps& caps) {
Brian Salomona811b122017-03-30 08:21:32 -0400664 GrProcessorAnalysisColor inputColor = GrProcessorAnalysisColor::Opaque::kYes;
665 GrProcessorAnalysisCoverage inputCoverage = GrProcessorAnalysisCoverage::kSingleChannel;
cdalton6fd158e2015-05-27 15:08:33 -0700666
Mike Reed7d954ad2016-10-28 15:42:34 -0400667 for (int m = 0; m <= (int)SkBlendMode::kLastCoeffMode; m++) {
668 SkBlendMode xfermode = static_cast<SkBlendMode>(m);
Brian Salomon31853842017-03-28 16:32:05 -0400669 const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, inputColor, inputCoverage);
cdalton6fd158e2015-05-27 15:08:33 -0700670 switch (xfermode) {
Mike Reed7d954ad2016-10-28 15:42:34 -0400671 case SkBlendMode::kClear:
Brian Salomon31853842017-03-28 16:32:05 -0400672 TEST_ASSERT(xpi.fIgnoresInputColor);
673 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700674 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700675 TEST_ASSERT(kCoverage_OutputType == xpi.fPrimaryOutputType);
676 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
677 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.fEquation);
678 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
679 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
680 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
681 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400682 case SkBlendMode::kSrc:
Brian Salomon31853842017-03-28 16:32:05 -0400683 TEST_ASSERT(!xpi.fIgnoresInputColor);
684 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700685 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700686 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
687 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
688 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
689 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
690 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
691 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
692 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400693 case SkBlendMode::kDst:
Brian Salomon31853842017-03-28 16:32:05 -0400694 TEST_ASSERT(xpi.fIgnoresInputColor);
695 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700696 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700697 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
698 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
699 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
700 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
701 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
702 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor);
703 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400704 case SkBlendMode::kSrcOver:
Brian Salomon31853842017-03-28 16:32:05 -0400705 TEST_ASSERT(!xpi.fIgnoresInputColor);
706 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700707 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700708 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
709 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
710 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
711 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
712 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
713 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
714 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400715 case SkBlendMode::kDstOver:
Brian Salomon31853842017-03-28 16:32:05 -0400716 TEST_ASSERT(!xpi.fIgnoresInputColor);
717 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700718 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700719 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
720 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
721 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
722 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
723 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
724 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
725 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400726 case SkBlendMode::kSrcIn:
Brian Salomon31853842017-03-28 16:32:05 -0400727 TEST_ASSERT(!xpi.fIgnoresInputColor);
728 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700729 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700730 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
731 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
732 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
733 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
734 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
735 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
736 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400737 case SkBlendMode::kDstIn:
Brian Salomon31853842017-03-28 16:32:05 -0400738 TEST_ASSERT(xpi.fIgnoresInputColor);
739 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700740 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700741 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
742 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
743 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
744 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
745 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
746 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor);
747 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400748 case SkBlendMode::kSrcOut:
Brian Salomon31853842017-03-28 16:32:05 -0400749 TEST_ASSERT(!xpi.fIgnoresInputColor);
750 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700751 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700752 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
753 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
754 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
755 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
756 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
757 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
758 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400759 case SkBlendMode::kDstOut:
Brian Salomon31853842017-03-28 16:32:05 -0400760 TEST_ASSERT(xpi.fIgnoresInputColor);
761 TEST_ASSERT(!xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700762 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700763 TEST_ASSERT(kCoverage_OutputType == xpi.fPrimaryOutputType);
764 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
765 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.fEquation);
766 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
767 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
768 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
769 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400770 case SkBlendMode::kSrcATop:
Brian Salomon31853842017-03-28 16:32:05 -0400771 TEST_ASSERT(!xpi.fIgnoresInputColor);
772 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700773 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700774 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
775 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
776 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
777 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
778 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
779 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
780 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400781 case SkBlendMode::kDstATop:
Brian Salomon31853842017-03-28 16:32:05 -0400782 TEST_ASSERT(!xpi.fIgnoresInputColor);
783 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700784 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700785 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
786 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
787 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
788 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
789 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
790 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
791 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400792 case SkBlendMode::kXor:
Brian Salomon31853842017-03-28 16:32:05 -0400793 TEST_ASSERT(!xpi.fIgnoresInputColor);
794 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700795 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700796 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
797 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
798 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
799 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
800 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
801 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
802 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400803 case SkBlendMode::kPlus:
Brian Salomon31853842017-03-28 16:32:05 -0400804 TEST_ASSERT(!xpi.fIgnoresInputColor);
805 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700806 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700807 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
808 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
809 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
810 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
811 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
812 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
813 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400814 case SkBlendMode::kModulate:
Brian Salomon31853842017-03-28 16:32:05 -0400815 TEST_ASSERT(!xpi.fIgnoresInputColor);
cdalton6fd158e2015-05-27 15:08:33 -0700816 TEST_ASSERT(kISCModulate_OutputType == xpi.fPrimaryOutputType);
817 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
818 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.fEquation);
819 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
820 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
821 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
822 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400823 case SkBlendMode::kScreen:
Brian Salomon31853842017-03-28 16:32:05 -0400824 TEST_ASSERT(!xpi.fIgnoresInputColor);
825 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700826 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700827 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
828 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
829 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
830 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
831 TEST_ASSERT(kISC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
832 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
833 break;
834 default:
835 ERRORF(reporter, "Invalid xfermode.");
836 break;
837 }
838 }
839}
840
841static void test_color_opaque_no_coverage(skiatest::Reporter* reporter, const GrCaps& caps) {
Brian Salomona811b122017-03-30 08:21:32 -0400842 GrProcessorAnalysisColor inputColor = GrProcessorAnalysisColor::Opaque::kYes;
843 GrProcessorAnalysisCoverage inputCoverage = GrProcessorAnalysisCoverage::kNone;
cdalton6fd158e2015-05-27 15:08:33 -0700844
Mike Reed7d954ad2016-10-28 15:42:34 -0400845 for (int m = 0; m <= (int)SkBlendMode::kLastCoeffMode; m++) {
846 SkBlendMode xfermode = static_cast<SkBlendMode>(m);
Brian Salomon31853842017-03-28 16:32:05 -0400847 const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, inputColor, inputCoverage);
cdalton6fd158e2015-05-27 15:08:33 -0700848
849 switch (xfermode) {
Mike Reed7d954ad2016-10-28 15:42:34 -0400850 case SkBlendMode::kClear:
Brian Salomon31853842017-03-28 16:32:05 -0400851 TEST_ASSERT(xpi.fIgnoresInputColor);
Greg Danielc5296812020-02-28 13:06:02 -0500852 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700853 TEST_ASSERT(xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700854 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
855 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
856 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
857 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
858 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
859 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
860 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400861 case SkBlendMode::kSrc:
Brian Salomon31853842017-03-28 16:32:05 -0400862 TEST_ASSERT(!xpi.fIgnoresInputColor);
Greg Danielc5296812020-02-28 13:06:02 -0500863 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700864 TEST_ASSERT(xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700865 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
866 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
867 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
868 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
869 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
870 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
871 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400872 case SkBlendMode::kDst:
Brian Salomon31853842017-03-28 16:32:05 -0400873 TEST_ASSERT(xpi.fIgnoresInputColor);
874 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700875 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700876 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
877 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
878 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
879 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
880 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
881 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor);
882 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400883 case SkBlendMode::kSrcOver:
Brian Salomon28207df2017-06-05 12:25:13 -0400884 // We don't specialize opaque src-over. See note in GrPorterDuffXferProcessor.cpp
Brian Salomon31853842017-03-28 16:32:05 -0400885 TEST_ASSERT(!xpi.fIgnoresInputColor);
Brian Salomon28207df2017-06-05 12:25:13 -0400886 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700887 TEST_ASSERT(xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700888 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
889 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
890 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
891 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
Greg Danielf6d60d32020-01-08 13:39:16 -0500892 if (caps.shouldCollapseSrcOverToSrcWhenAble()) {
893 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
894 } else {
895 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
896 }
cdalton6fd158e2015-05-27 15:08:33 -0700897 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
898 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400899 case SkBlendMode::kDstOver:
Brian Salomon31853842017-03-28 16:32:05 -0400900 TEST_ASSERT(!xpi.fIgnoresInputColor);
901 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700902 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700903 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
904 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
905 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
906 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
907 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
908 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
909 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400910 case SkBlendMode::kSrcIn:
Brian Salomon31853842017-03-28 16:32:05 -0400911 TEST_ASSERT(!xpi.fIgnoresInputColor);
Greg Danielc5296812020-02-28 13:06:02 -0500912 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700913 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700914 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
915 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
916 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
917 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
918 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
919 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
920 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400921 case SkBlendMode::kDstIn:
Brian Salomon31853842017-03-28 16:32:05 -0400922 TEST_ASSERT(xpi.fIgnoresInputColor);
923 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700924 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700925 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
926 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
927 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
928 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
929 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
930 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor);
931 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400932 case SkBlendMode::kSrcOut:
Brian Salomon31853842017-03-28 16:32:05 -0400933 TEST_ASSERT(!xpi.fIgnoresInputColor);
Greg Danielc5296812020-02-28 13:06:02 -0500934 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700935 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700936 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
937 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
938 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
939 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
940 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
941 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
942 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400943 case SkBlendMode::kDstOut:
Brian Salomon31853842017-03-28 16:32:05 -0400944 TEST_ASSERT(xpi.fIgnoresInputColor);
Greg Danielc5296812020-02-28 13:06:02 -0500945 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700946 TEST_ASSERT(xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700947 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType);
948 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
949 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
950 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
951 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
952 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
953 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400954 case SkBlendMode::kSrcATop:
Brian Salomon31853842017-03-28 16:32:05 -0400955 TEST_ASSERT(!xpi.fIgnoresInputColor);
Greg Danielc5296812020-02-28 13:06:02 -0500956 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700957 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700958 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
959 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
960 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
961 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
962 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
963 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
964 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400965 case SkBlendMode::kDstATop:
Brian Salomon31853842017-03-28 16:32:05 -0400966 TEST_ASSERT(!xpi.fIgnoresInputColor);
967 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700968 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700969 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
970 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
971 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
972 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
973 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
974 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
975 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400976 case SkBlendMode::kXor:
Brian Salomon31853842017-03-28 16:32:05 -0400977 TEST_ASSERT(!xpi.fIgnoresInputColor);
Greg Danielc5296812020-02-28 13:06:02 -0500978 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700979 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700980 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
981 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
982 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
983 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
984 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
985 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
986 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400987 case SkBlendMode::kPlus:
Brian Salomon31853842017-03-28 16:32:05 -0400988 TEST_ASSERT(!xpi.fIgnoresInputColor);
989 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -0700990 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -0700991 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
992 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
993 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
994 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
995 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
996 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
997 break;
Mike Reed7d954ad2016-10-28 15:42:34 -0400998 case SkBlendMode::kModulate:
Brian Salomon31853842017-03-28 16:32:05 -0400999 TEST_ASSERT(!xpi.fIgnoresInputColor);
Greg Danielc5296812020-02-28 13:06:02 -05001000 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -07001001 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -07001002 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
1003 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
1004 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
1005 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
1006 TEST_ASSERT(kSC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
1007 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
1008 break;
Mike Reed7d954ad2016-10-28 15:42:34 -04001009 case SkBlendMode::kScreen:
Brian Salomon31853842017-03-28 16:32:05 -04001010 TEST_ASSERT(!xpi.fIgnoresInputColor);
1011 TEST_ASSERT(xpi.fCompatibleWithCoverageAsAlpha);
Chris Daltonf2fb80f2020-12-03 12:37:59 -07001012 TEST_ASSERT(!xpi.fUnaffectedByDstValue);
cdalton6fd158e2015-05-27 15:08:33 -07001013 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType);
1014 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType);
1015 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation);
1016 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend);
1017 TEST_ASSERT(kISC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend);
1018 TEST_ASSERT(xpi.fBlendInfo.fWriteColor);
1019 break;
1020 default:
1021 ERRORF(reporter, "Invalid xfermode.");
1022 break;
1023 }
1024 }
1025}
1026
egdaniel723b0502015-09-15 09:31:40 -07001027static void test_lcd_coverage_fallback_case(skiatest::Reporter* reporter, const GrCaps& caps) {
Brian Osman5ced0bf2019-03-15 10:15:29 -04001028 constexpr GrClampType autoClamp = GrClampType::kAuto;
Brian Salomon31853842017-03-28 16:32:05 -04001029 const GrXPFactory* xpf = GrPorterDuffXPFactory::Get(SkBlendMode::kSrcOver);
Brian Osmancf860852018-10-31 14:04:39 -04001030 GrProcessorAnalysisColor color = SkPMColor4f::FromBytes_RGBA(GrColorPackRGBA(123, 45, 67, 255));
Brian Salomona811b122017-03-30 08:21:32 -04001031 GrProcessorAnalysisCoverage coverage = GrProcessorAnalysisCoverage::kLCD;
Chris Dalton57ab06c2021-04-22 12:57:28 -06001032 TEST_ASSERT(!(GrXPFactory::GetAnalysisProperties(xpf, color, coverage, caps, autoClamp) &
Greg Daniel6ebe4b92017-05-19 10:56:46 -04001033 GrXPFactory::AnalysisProperties::kRequiresDstTexture));
1034 sk_sp<const GrXferProcessor> xp_opaque(
Chris Dalton57ab06c2021-04-22 12:57:28 -06001035 GrXPFactory::MakeXferProcessor(xpf, color, coverage, caps, autoClamp));
Greg Daniel6ebe4b92017-05-19 10:56:46 -04001036 if (!xp_opaque) {
1037 ERRORF(reporter, "Failed to create an XP with LCD coverage.");
1038 return;
1039 }
1040
Chris Daltonbbb3f642019-07-24 12:25:08 -04001041 GrXferProcessor::BlendInfo blendInfo = xp_opaque->getBlendInfo();
Greg Daniel6ebe4b92017-05-19 10:56:46 -04001042 TEST_ASSERT(blendInfo.fWriteColor);
1043
1044 // Test with non-opaque alpha
Brian Osmancf860852018-10-31 14:04:39 -04001045 color = SkPMColor4f::FromBytes_RGBA(GrColorPackRGBA(123, 45, 67, 221));
Greg Daniel6ebe4b92017-05-19 10:56:46 -04001046 coverage = GrProcessorAnalysisCoverage::kLCD;
Chris Dalton57ab06c2021-04-22 12:57:28 -06001047 TEST_ASSERT(!(GrXPFactory::GetAnalysisProperties(xpf, color, coverage, caps, autoClamp) &
Greg Danield7b11592017-06-14 13:37:12 -04001048 GrXPFactory::AnalysisProperties::kRequiresDstTexture));
Brian Salomond61c9d92017-04-10 10:54:25 -04001049 sk_sp<const GrXferProcessor> xp(
Chris Dalton57ab06c2021-04-22 12:57:28 -06001050 GrXPFactory::MakeXferProcessor(xpf, color, coverage, caps, autoClamp));
cdalton6fd158e2015-05-27 15:08:33 -07001051 if (!xp) {
1052 ERRORF(reporter, "Failed to create an XP with LCD coverage.");
1053 return;
1054 }
1055
Chris Daltonbbb3f642019-07-24 12:25:08 -04001056 blendInfo = xp->getBlendInfo();
cdalton6fd158e2015-05-27 15:08:33 -07001057 TEST_ASSERT(blendInfo.fWriteColor);
1058}
1059
Brian Salomondcfca432017-11-15 15:48:03 -05001060DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, options) {
1061 GrContextOptions opts = options;
cdalton6fd158e2015-05-27 15:08:33 -07001062 opts.fSuppressDualSourceBlending = true;
bsalomon3724e572016-03-30 18:56:19 -07001063 sk_gpu_test::GrContextFactory mockFactory(opts);
Robert Phillips6d344c32020-07-06 10:56:46 -04001064 auto ctx = mockFactory.get(sk_gpu_test::GrContextFactory::kMock_ContextType);
cdalton6fd158e2015-05-27 15:08:33 -07001065 if (!ctx) {
Brian Osman7c597742019-03-26 11:10:11 -04001066 SK_ABORT("Failed to create mock context without ARB_blend_func_extended.");
cdalton6fd158e2015-05-27 15:08:33 -07001067 }
1068
Robert Phillips9da87e02019-02-04 13:26:26 -05001069 GrProxyProvider* proxyProvider = ctx->priv().proxyProvider();
1070 const GrCaps& caps = *ctx->priv().caps();
cdalton6fd158e2015-05-27 15:08:33 -07001071 if (caps.shaderCaps()->dualSourceBlendingSupport()) {
Brian Osman7c597742019-03-26 11:10:11 -04001072 SK_ABORT("Mock context failed to honor request for no ARB_blend_func_extended.");
cdalton6fd158e2015-05-27 15:08:33 -07001073 }
1074
Brian Salomon72050802020-10-12 20:45:06 -04001075 auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(
1076 ctx, 100, 100, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kNo);
Brian Salomon88d7e622020-11-05 11:11:20 -05001077 if (!mbet) {
1078 ERRORF(reporter, "Could not make texture.");
1079 return;
1080 }
John Stiles52cb1d02021-06-02 11:58:05 -04001081 GrDstProxyView fakeDstProxyView;
Robert Phillipsbb581ce2017-05-29 15:05:15 -04001082 {
Brian Salomonc67c31c2018-12-06 10:00:03 -05001083 sk_sp<GrTextureProxy> proxy = proxyProvider->wrapBackendTexture(
Brian Salomon72050802020-10-12 20:45:06 -04001084 mbet->texture(), kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType,
1085 mbet->refCountedCallback());
1086 GrSwizzle swizzle =
1087 caps.getReadSwizzle(mbet->texture().getBackendFormat(), GrColorType::kRGBA_8888);
Greg Daniel524e28b2019-11-01 11:48:53 -04001088 fakeDstProxyView.setProxyView({std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle});
Robert Phillipsbb581ce2017-05-29 15:05:15 -04001089 }
cdalton6fd158e2015-05-27 15:08:33 -07001090
Brian Salomona811b122017-03-30 08:21:32 -04001091 static const GrProcessorAnalysisColor colorInputs[] = {
1092 GrProcessorAnalysisColor::Opaque::kNo, GrProcessorAnalysisColor::Opaque::kYes,
Brian Osmancf860852018-10-31 14:04:39 -04001093 GrProcessorAnalysisColor(SkPMColor4f::FromBytes_RGBA(GrColorPackRGBA(0, 82, 17, 100))),
1094 GrProcessorAnalysisColor(SkPMColor4f::FromBytes_RGBA(GrColorPackRGBA(0, 82, 17, 255)))};
cdalton6fd158e2015-05-27 15:08:33 -07001095
Brian Salomonc6b71462017-02-14 11:33:01 -05001096 for (const auto& colorInput : colorInputs) {
Brian Salomona811b122017-03-30 08:21:32 -04001097 for (GrProcessorAnalysisCoverage coverageType :
1098 {GrProcessorAnalysisCoverage::kSingleChannel, GrProcessorAnalysisCoverage::kNone}) {
Mike Reed7d954ad2016-10-28 15:42:34 -04001099 for (int m = 0; m <= (int)SkBlendMode::kLastCoeffMode; m++) {
1100 SkBlendMode xfermode = static_cast<SkBlendMode>(m);
Brian Salomona1633922017-01-09 11:46:10 -05001101 const GrXPFactory* xpf = GrPorterDuffXPFactory::Get(xfermode);
Brian Salomond61c9d92017-04-10 10:54:25 -04001102 sk_sp<const GrXferProcessor> xp(
Chris Dalton57ab06c2021-04-22 12:57:28 -06001103 GrXPFactory::MakeXferProcessor(xpf, colorInput, coverageType, caps,
Brian Osman5ced0bf2019-03-15 10:15:29 -04001104 GrClampType::kAuto));
cdalton6fd158e2015-05-27 15:08:33 -07001105 if (!xp) {
1106 ERRORF(reporter, "Failed to create an XP without dual source blending.");
1107 return;
1108 }
1109 TEST_ASSERT(!xp->hasSecondaryOutput());
cdalton6fd158e2015-05-27 15:08:33 -07001110 }
1111 }
1112 }
cdalton6fd158e2015-05-27 15:08:33 -07001113}