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