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