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