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