OLD | NEW |
(Empty) | |
| 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 |
| 13 #include "GrBatch.h" |
| 14 #include "GrContextFactory.h" |
| 15 #include "GrContextOptions.h" |
| 16 #include "GrGpu.h" |
| 17 #include "GrResourceProvider.h" |
| 18 #include "GrXferProcessor.h" |
| 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 G
rCaps& 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 Gr
Caps& caps); |
| 28 static void test_lcd_coverage(skiatest::Reporter* reporter, const GrCaps& caps); |
| 29 static void test_no_dual_source_blending(skiatest::Reporter* reporter); |
| 30 |
| 31 DEF_GPUTEST(GrPorterDuff, reporter, factory) { |
| 32 GrContext* ctx = factory->get(GrContextFactory::kNull_GLContextType); |
| 33 if (!ctx) { |
| 34 SkFAIL("Failed to create null context."); |
| 35 return; |
| 36 } |
| 37 |
| 38 const GrCaps& caps = *ctx->getGpu()->caps(); |
| 39 if (!caps.shaderCaps()->dualSourceBlendingSupport()) { |
| 40 SkFAIL("Null context does not support dual source blending."); |
| 41 return; |
| 42 } |
| 43 |
| 44 test_color_unknown_with_coverage(reporter, caps); |
| 45 test_color_unknown_no_coverage(reporter, caps); |
| 46 test_color_opaque_with_coverage(reporter, caps); |
| 47 test_color_opaque_no_coverage(reporter, caps); |
| 48 test_lcd_coverage(reporter, caps); |
| 49 test_no_dual_source_blending(reporter); |
| 50 } |
| 51 |
| 52 //////////////////////////////////////////////////////////////////////////////// |
| 53 |
| 54 #define TEST_ASSERT(...) REPORTER_ASSERT(reporter, __VA_ARGS__) |
| 55 |
| 56 enum { |
| 57 kNone_OutputType, |
| 58 kCoverage_OutputType, |
| 59 kModulate_OutputType, |
| 60 kISAModulate_OutputType, |
| 61 kISCModulate_OutputType |
| 62 }; |
| 63 |
| 64 enum { |
| 65 kNone_Opt = GrXferProcessor::kNone_Opt, |
| 66 kSkipDraw_OptFlag = GrXferProcessor::kSkipDraw_OptFlag, |
| 67 kIgnoreColor_OptFlag = GrXferProcessor::kIgnoreColor_OptFlag, |
| 68 kIgnoreCoverage_OptFlag = GrXferProcessor::kIgnoreCoverage_OptFlag
, |
| 69 kCanTweakAlphaForCoverage_OptFlag = GrXferProcessor::kCanTweakAlphaForCovera
ge_OptFlag |
| 70 }; |
| 71 |
| 72 class GrPorterDuffTest { |
| 73 public: |
| 74 struct XPInfo { |
| 75 XPInfo(skiatest::Reporter* reporter, SkXfermode::Mode xfermode, const Gr
Caps& caps, |
| 76 const GrProcOptInfo& colorPOI, const GrProcOptInfo& covPOI) { |
| 77 SkAutoTUnref<GrXPFactory> xpf(GrPorterDuffXPFactory::Create(xfermode
)); |
| 78 SkAutoTUnref<GrXferProcessor> xp(xpf->createXferProcessor(colorPOI,
covPOI, 0, caps)); |
| 79 TEST_ASSERT(!xpf->willNeedDstTexture(caps, colorPOI, covPOI)); |
| 80 xpf->getInvariantOutput(colorPOI, covPOI, &fInvariantOutput); |
| 81 fOptFlags = xp->getOptimizations(colorPOI, covPOI, false, 0, caps); |
| 82 GetXPOutputTypes(xp, &fPrimaryOutputType, &fSecondaryOutputType); |
| 83 xp->getBlendInfo(&fBlendInfo); |
| 84 TEST_ASSERT(!xp->willReadDstColor()); |
| 85 TEST_ASSERT(xp->hasSecondaryOutput() == GrBlendCoeffRefsSrc2(fBlendI
nfo.fDstBlend)); |
| 86 } |
| 87 |
| 88 GrXPFactory::InvariantOutput fInvariantOutput; |
| 89 int fOptFlags; |
| 90 int fPrimaryOutputType; |
| 91 int fSecondaryOutputType; |
| 92 GrXferProcessor::BlendInfo fBlendInfo; |
| 93 }; |
| 94 |
| 95 static void GetXPOutputTypes(const GrXferProcessor* xp, int* outPrimary, int
* outSecondary) { |
| 96 GrPorterDuffXPFactory::TestGetXPOutputTypes(xp, outPrimary, outSecondary
); |
| 97 } |
| 98 }; |
| 99 |
| 100 static void test_color_unknown_with_coverage(skiatest::Reporter* reporter, const
GrCaps& caps) { |
| 101 GrProcOptInfo colorPOI, covPOI; |
| 102 colorPOI.calcWithInitialValues(NULL, 0, 0, kNone_GrColorComponentFlags, fals
e); |
| 103 covPOI.calcWithInitialValues(NULL, 0, 0, kNone_GrColorComponentFlags, true); |
| 104 |
| 105 SkASSERT(!colorPOI.isOpaque()); |
| 106 SkASSERT(!colorPOI.isSolidWhite()); |
| 107 SkASSERT(!covPOI.isSolidWhite()); |
| 108 SkASSERT(!covPOI.isFourChannelOutput()); |
| 109 |
| 110 for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) { |
| 111 SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m); |
| 112 const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, colorPOI, c
ovPOI); |
| 113 |
| 114 switch (xfermode) { |
| 115 case SkXfermode::kClear_Mode: |
| 116 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 117 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 118 TEST_ASSERT((kIgnoreColor_OptFlag) == xpi.fOptFlags); |
| 119 TEST_ASSERT(kCoverage_OutputType == xpi.fPrimaryOutputType); |
| 120 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 121 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.f
Equation); |
| 122 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 123 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 124 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 125 break; |
| 126 case SkXfermode::kSrc_Mode: |
| 127 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 128 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 129 TEST_ASSERT((kNone_Opt) == xpi.fOptFlags); |
| 130 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 131 TEST_ASSERT(kCoverage_OutputType == xpi.fSecondaryOutputType); |
| 132 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 133 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 134 TEST_ASSERT(kIS2A_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 135 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 136 break; |
| 137 case SkXfermode::kDst_Mode: |
| 138 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 139 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 140 TEST_ASSERT((kSkipDraw_OptFlag | |
| 141 kIgnoreColor_OptFlag | |
| 142 kIgnoreCoverage_OptFlag | |
| 143 kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 144 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType); |
| 145 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 146 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 147 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 148 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 149 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor); |
| 150 break; |
| 151 case SkXfermode::kSrcOver_Mode: |
| 152 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 153 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 154 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 155 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 156 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 157 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 158 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 159 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 160 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 161 break; |
| 162 case SkXfermode::kDstOver_Mode: |
| 163 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 164 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 165 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 166 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 167 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 168 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 169 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 170 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 171 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 172 break; |
| 173 case SkXfermode::kSrcIn_Mode: |
| 174 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 175 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 176 TEST_ASSERT((kNone_Opt) == xpi.fOptFlags); |
| 177 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 178 TEST_ASSERT(kCoverage_OutputType == xpi.fSecondaryOutputType); |
| 179 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 180 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 181 TEST_ASSERT(kIS2A_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 182 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 183 break; |
| 184 case SkXfermode::kDstIn_Mode: |
| 185 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 186 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 187 TEST_ASSERT((kNone_Opt) == xpi.fOptFlags); |
| 188 TEST_ASSERT(kISAModulate_OutputType == xpi.fPrimaryOutputType); |
| 189 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 190 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.f
Equation); |
| 191 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 192 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 193 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 194 break; |
| 195 case SkXfermode::kSrcOut_Mode: |
| 196 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 197 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 198 TEST_ASSERT((kNone_Opt) == xpi.fOptFlags); |
| 199 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 200 TEST_ASSERT(kCoverage_OutputType == xpi.fSecondaryOutputType); |
| 201 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 202 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 203 TEST_ASSERT(kIS2A_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 204 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 205 break; |
| 206 case SkXfermode::kDstOut_Mode: |
| 207 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 208 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 209 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 210 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 211 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 212 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 213 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 214 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 215 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 216 break; |
| 217 case SkXfermode::kSrcATop_Mode: |
| 218 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 219 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 220 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 221 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 222 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 223 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 224 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 225 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 226 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 227 break; |
| 228 case SkXfermode::kDstATop_Mode: |
| 229 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 230 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 231 TEST_ASSERT((kNone_Opt) == xpi.fOptFlags); |
| 232 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 233 TEST_ASSERT(kISAModulate_OutputType == xpi.fSecondaryOutputType)
; |
| 234 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 235 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 236 TEST_ASSERT(kIS2C_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 237 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 238 break; |
| 239 case SkXfermode::kXor_Mode: |
| 240 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 241 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 242 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 243 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 244 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 245 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 246 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 247 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 248 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 249 break; |
| 250 case SkXfermode::kPlus_Mode: |
| 251 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 252 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 253 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 254 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 255 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 256 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 257 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 258 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 259 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 260 break; |
| 261 case SkXfermode::kModulate_Mode: |
| 262 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 263 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 264 TEST_ASSERT((kNone_Opt) == xpi.fOptFlags); |
| 265 TEST_ASSERT(kISCModulate_OutputType == xpi.fPrimaryOutputType); |
| 266 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 267 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.f
Equation); |
| 268 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 269 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 270 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 271 break; |
| 272 case SkXfermode::kScreen_Mode: |
| 273 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 274 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 275 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 276 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 277 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 278 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 279 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 280 TEST_ASSERT(kISC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 281 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 282 break; |
| 283 default: |
| 284 ERRORF(reporter, "Invalid xfermode."); |
| 285 break; |
| 286 } |
| 287 } |
| 288 } |
| 289 |
| 290 static void test_color_unknown_no_coverage(skiatest::Reporter* reporter, const G
rCaps& caps) { |
| 291 GrProcOptInfo colorPOI, covPOI; |
| 292 colorPOI.calcWithInitialValues(NULL, 0, GrColorPackRGBA(229, 0, 154, 0), |
| 293 kR_GrColorComponentFlag | kB_GrColorComponent
Flag, false); |
| 294 covPOI.calcWithInitialValues(NULL, 0, GrColorPackA4(255), kRGBA_GrColorCompo
nentFlags, true); |
| 295 |
| 296 SkASSERT(!colorPOI.isOpaque()); |
| 297 SkASSERT(!colorPOI.isSolidWhite()); |
| 298 SkASSERT(covPOI.isSolidWhite()); |
| 299 SkASSERT(!covPOI.isFourChannelOutput()); |
| 300 |
| 301 for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) { |
| 302 SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m); |
| 303 const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, colorPOI, c
ovPOI); |
| 304 |
| 305 switch (xfermode) { |
| 306 case SkXfermode::kClear_Mode: |
| 307 TEST_ASSERT(!xpi.fInvariantOutput.fWillBlendWithDst); |
| 308 TEST_ASSERT(0 == xpi.fInvariantOutput.fBlendedColor); |
| 309 TEST_ASSERT(kRGBA_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 310 TEST_ASSERT((kIgnoreColor_OptFlag | |
| 311 kIgnoreCoverage_OptFlag) == xpi.fOptFlags); |
| 312 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType); |
| 313 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 314 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 315 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 316 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 317 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 318 break; |
| 319 case SkXfermode::kSrc_Mode: |
| 320 TEST_ASSERT(!xpi.fInvariantOutput.fWillBlendWithDst); |
| 321 TEST_ASSERT(229 == GrColorUnpackR(xpi.fInvariantOutput.fBlendedC
olor)); |
| 322 TEST_ASSERT(154 == GrColorUnpackB(xpi.fInvariantOutput.fBlendedC
olor)); |
| 323 TEST_ASSERT((kR_GrColorComponentFlag | |
| 324 kB_GrColorComponentFlag) == xpi.fInvariantOutput.fB
lendedColorFlags); |
| 325 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags); |
| 326 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 327 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 328 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 329 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 330 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 331 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 332 break; |
| 333 case SkXfermode::kDst_Mode: |
| 334 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 335 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 336 TEST_ASSERT((kSkipDraw_OptFlag | |
| 337 kIgnoreColor_OptFlag | |
| 338 kIgnoreCoverage_OptFlag | |
| 339 kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 340 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType); |
| 341 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 342 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 343 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 344 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 345 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor); |
| 346 break; |
| 347 case SkXfermode::kSrcOver_Mode: |
| 348 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 349 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 350 TEST_ASSERT((kIgnoreCoverage_OptFlag | |
| 351 kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 352 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 353 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 354 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 355 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 356 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 357 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 358 break; |
| 359 case SkXfermode::kDstOver_Mode: |
| 360 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 361 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 362 TEST_ASSERT((kIgnoreCoverage_OptFlag | |
| 363 kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 364 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 365 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 366 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 367 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 368 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 369 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 370 break; |
| 371 case SkXfermode::kSrcIn_Mode: |
| 372 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 373 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 374 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags); |
| 375 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 376 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 377 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 378 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 379 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 380 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 381 break; |
| 382 case SkXfermode::kDstIn_Mode: |
| 383 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 384 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 385 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags); |
| 386 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 387 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 388 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 389 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 390 TEST_ASSERT(kSA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 391 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 392 break; |
| 393 case SkXfermode::kSrcOut_Mode: |
| 394 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 395 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 396 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags); |
| 397 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 398 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 399 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 400 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 401 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 402 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 403 break; |
| 404 case SkXfermode::kDstOut_Mode: |
| 405 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 406 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 407 TEST_ASSERT((kIgnoreCoverage_OptFlag | |
| 408 kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 409 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 410 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 411 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 412 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 413 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 414 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 415 break; |
| 416 case SkXfermode::kSrcATop_Mode: |
| 417 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 418 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 419 TEST_ASSERT((kIgnoreCoverage_OptFlag | |
| 420 kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 421 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 422 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 423 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 424 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 425 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 426 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 427 break; |
| 428 case SkXfermode::kDstATop_Mode: |
| 429 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 430 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 431 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags); |
| 432 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 433 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 434 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 435 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 436 TEST_ASSERT(kSA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 437 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 438 break; |
| 439 case SkXfermode::kXor_Mode: |
| 440 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 441 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 442 TEST_ASSERT((kIgnoreCoverage_OptFlag | |
| 443 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(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 448 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 449 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 450 break; |
| 451 case SkXfermode::kPlus_Mode: |
| 452 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 453 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 454 TEST_ASSERT((kIgnoreCoverage_OptFlag | |
| 455 kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 456 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 457 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 458 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 459 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 460 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 461 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 462 break; |
| 463 case SkXfermode::kModulate_Mode: |
| 464 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 465 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 466 TEST_ASSERT((kIgnoreCoverage_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(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 471 TEST_ASSERT(kSC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 472 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 473 break; |
| 474 case SkXfermode::kScreen_Mode: |
| 475 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 476 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 477 TEST_ASSERT((kIgnoreCoverage_OptFlag | |
| 478 kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 479 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 480 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 481 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 482 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 483 TEST_ASSERT(kISC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 484 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 485 break; |
| 486 default: |
| 487 ERRORF(reporter, "Invalid xfermode."); |
| 488 break; |
| 489 } |
| 490 } |
| 491 } |
| 492 |
| 493 static void test_color_opaque_with_coverage(skiatest::Reporter* reporter, const
GrCaps& caps) { |
| 494 GrProcOptInfo colorPOI, covPOI; |
| 495 colorPOI.calcWithInitialValues(NULL, 0, GrColorPackA4(255), kA_GrColorCompon
entFlag, false); |
| 496 covPOI.calcWithInitialValues(NULL, 0, 0, kNone_GrColorComponentFlags, true); |
| 497 |
| 498 SkASSERT(colorPOI.isOpaque()); |
| 499 SkASSERT(!colorPOI.isSolidWhite()); |
| 500 SkASSERT(!covPOI.isSolidWhite()); |
| 501 SkASSERT(!covPOI.isFourChannelOutput()); |
| 502 |
| 503 for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) { |
| 504 SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m); |
| 505 const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, colorPOI, c
ovPOI); |
| 506 |
| 507 switch (xfermode) { |
| 508 case SkXfermode::kClear_Mode: |
| 509 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 510 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 511 TEST_ASSERT((kIgnoreColor_OptFlag) == xpi.fOptFlags); |
| 512 TEST_ASSERT(kCoverage_OutputType == xpi.fPrimaryOutputType); |
| 513 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 514 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.f
Equation); |
| 515 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 516 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 517 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 518 break; |
| 519 case SkXfermode::kSrc_Mode: |
| 520 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 521 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 522 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 523 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 524 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 525 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 526 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 527 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 528 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 529 break; |
| 530 case SkXfermode::kDst_Mode: |
| 531 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 532 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 533 TEST_ASSERT((kSkipDraw_OptFlag | |
| 534 kIgnoreColor_OptFlag | |
| 535 kIgnoreCoverage_OptFlag | |
| 536 kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 537 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType); |
| 538 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 539 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 540 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 541 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 542 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor); |
| 543 break; |
| 544 case SkXfermode::kSrcOver_Mode: |
| 545 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 546 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 547 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 548 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 549 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 550 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 551 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 552 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 553 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 554 break; |
| 555 case SkXfermode::kDstOver_Mode: |
| 556 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 557 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 558 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 559 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 560 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 561 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 562 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 563 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 564 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 565 break; |
| 566 case SkXfermode::kSrcIn_Mode: |
| 567 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 568 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 569 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 570 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 571 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 572 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 573 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 574 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 575 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 576 break; |
| 577 case SkXfermode::kDstIn_Mode: |
| 578 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 579 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 580 TEST_ASSERT((kSkipDraw_OptFlag | |
| 581 kIgnoreColor_OptFlag | |
| 582 kIgnoreCoverage_OptFlag | |
| 583 kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 584 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType); |
| 585 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 586 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 587 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 588 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 589 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor); |
| 590 break; |
| 591 case SkXfermode::kSrcOut_Mode: |
| 592 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 593 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 594 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 595 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 596 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 597 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 598 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 599 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 600 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 601 break; |
| 602 case SkXfermode::kDstOut_Mode: |
| 603 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 604 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 605 TEST_ASSERT((kIgnoreColor_OptFlag) == xpi.fOptFlags); |
| 606 TEST_ASSERT(kCoverage_OutputType == xpi.fPrimaryOutputType); |
| 607 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 608 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.f
Equation); |
| 609 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 610 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 611 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 612 break; |
| 613 case SkXfermode::kSrcATop_Mode: |
| 614 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 615 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 616 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 617 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 618 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 619 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 620 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 621 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 622 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 623 break; |
| 624 case SkXfermode::kDstATop_Mode: |
| 625 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 626 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 627 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 628 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 629 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 630 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 631 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 632 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 633 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 634 break; |
| 635 case SkXfermode::kXor_Mode: |
| 636 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 637 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 638 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 639 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 640 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 641 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 642 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 643 TEST_ASSERT(kISA_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 644 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 645 break; |
| 646 case SkXfermode::kPlus_Mode: |
| 647 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 648 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 649 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 650 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 651 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 652 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 653 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 654 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 655 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 656 break; |
| 657 case SkXfermode::kModulate_Mode: |
| 658 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 659 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 660 TEST_ASSERT((kNone_Opt) == xpi.fOptFlags); |
| 661 TEST_ASSERT(kISCModulate_OutputType == xpi.fPrimaryOutputType); |
| 662 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 663 TEST_ASSERT(kReverseSubtract_GrBlendEquation == xpi.fBlendInfo.f
Equation); |
| 664 TEST_ASSERT(kDC_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 665 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 666 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 667 break; |
| 668 case SkXfermode::kScreen_Mode: |
| 669 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 670 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 671 TEST_ASSERT((kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 672 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 673 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 674 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 675 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 676 TEST_ASSERT(kISC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 677 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 678 break; |
| 679 default: |
| 680 ERRORF(reporter, "Invalid xfermode."); |
| 681 break; |
| 682 } |
| 683 } |
| 684 } |
| 685 |
| 686 static void test_color_opaque_no_coverage(skiatest::Reporter* reporter, const Gr
Caps& caps) { |
| 687 GrProcOptInfo colorPOI, covPOI; |
| 688 colorPOI.calcWithInitialValues(NULL, 0, GrColorPackRGBA(0, 82, 0, 255), |
| 689 kG_GrColorComponentFlag | kA_GrColorComponent
Flag, false); |
| 690 covPOI.calcWithInitialValues(NULL, 0, GrColorPackA4(255), kRGBA_GrColorCompo
nentFlags, true); |
| 691 |
| 692 SkASSERT(colorPOI.isOpaque()); |
| 693 SkASSERT(!colorPOI.isSolidWhite()); |
| 694 SkASSERT(covPOI.isSolidWhite()); |
| 695 SkASSERT(!covPOI.isFourChannelOutput()); |
| 696 |
| 697 for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) { |
| 698 SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m); |
| 699 const GrPorterDuffTest::XPInfo xpi(reporter, xfermode, caps, colorPOI, c
ovPOI); |
| 700 |
| 701 switch (xfermode) { |
| 702 case SkXfermode::kClear_Mode: |
| 703 TEST_ASSERT(!xpi.fInvariantOutput.fWillBlendWithDst); |
| 704 TEST_ASSERT(0 == xpi.fInvariantOutput.fBlendedColor); |
| 705 TEST_ASSERT(kRGBA_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 706 TEST_ASSERT((kIgnoreColor_OptFlag | |
| 707 kIgnoreCoverage_OptFlag) == xpi.fOptFlags); |
| 708 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType); |
| 709 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 710 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 711 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 712 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 713 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 714 break; |
| 715 case SkXfermode::kSrc_Mode: |
| 716 TEST_ASSERT(!xpi.fInvariantOutput.fWillBlendWithDst); |
| 717 TEST_ASSERT(82 == GrColorUnpackG(xpi.fInvariantOutput.fBlendedCo
lor)); |
| 718 TEST_ASSERT(255 == GrColorUnpackA(xpi.fInvariantOutput.fBlendedC
olor)); |
| 719 TEST_ASSERT((kG_GrColorComponentFlag | |
| 720 kA_GrColorComponentFlag) == xpi.fInvariantOutput.fB
lendedColorFlags); |
| 721 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags); |
| 722 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 723 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 724 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 725 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 726 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 727 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 728 break; |
| 729 case SkXfermode::kDst_Mode: |
| 730 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 731 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 732 TEST_ASSERT((kSkipDraw_OptFlag | |
| 733 kIgnoreColor_OptFlag | |
| 734 kIgnoreCoverage_OptFlag | |
| 735 kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 736 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType); |
| 737 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 738 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 739 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 740 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 741 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor); |
| 742 break; |
| 743 case SkXfermode::kSrcOver_Mode: |
| 744 TEST_ASSERT(!xpi.fInvariantOutput.fWillBlendWithDst); |
| 745 TEST_ASSERT(82 == GrColorUnpackG(xpi.fInvariantOutput.fBlendedCo
lor)); |
| 746 TEST_ASSERT(255 == GrColorUnpackA(xpi.fInvariantOutput.fBlendedC
olor)); |
| 747 TEST_ASSERT((kG_GrColorComponentFlag | |
| 748 kA_GrColorComponentFlag) == xpi.fInvariantOutput.fB
lendedColorFlags); |
| 749 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags); |
| 750 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 751 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 752 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 753 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 754 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 755 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 756 break; |
| 757 case SkXfermode::kDstOver_Mode: |
| 758 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 759 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 760 TEST_ASSERT((kIgnoreCoverage_OptFlag | |
| 761 kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 762 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 763 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 764 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 765 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 766 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 767 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 768 break; |
| 769 case SkXfermode::kSrcIn_Mode: |
| 770 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 771 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 772 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags); |
| 773 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 774 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 775 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 776 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 777 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 778 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 779 break; |
| 780 case SkXfermode::kDstIn_Mode: |
| 781 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 782 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 783 TEST_ASSERT((kSkipDraw_OptFlag | |
| 784 kIgnoreColor_OptFlag | |
| 785 kIgnoreCoverage_OptFlag | |
| 786 kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 787 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType); |
| 788 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 789 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 790 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 791 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 792 TEST_ASSERT(!xpi.fBlendInfo.fWriteColor); |
| 793 break; |
| 794 case SkXfermode::kSrcOut_Mode: |
| 795 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 796 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 797 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags); |
| 798 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 799 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 800 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 801 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 802 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 803 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 804 break; |
| 805 case SkXfermode::kDstOut_Mode: |
| 806 TEST_ASSERT(!xpi.fInvariantOutput.fWillBlendWithDst); |
| 807 TEST_ASSERT(0 == xpi.fInvariantOutput.fBlendedColor); |
| 808 TEST_ASSERT(kRGBA_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 809 TEST_ASSERT((kIgnoreColor_OptFlag | |
| 810 kIgnoreCoverage_OptFlag) == xpi.fOptFlags); |
| 811 TEST_ASSERT(kNone_OutputType == xpi.fPrimaryOutputType); |
| 812 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 813 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 814 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 815 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 816 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 817 break; |
| 818 case SkXfermode::kSrcATop_Mode: |
| 819 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 820 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 821 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags); |
| 822 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 823 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 824 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 825 TEST_ASSERT(kDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 826 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 827 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 828 break; |
| 829 case SkXfermode::kDstATop_Mode: |
| 830 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 831 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 832 TEST_ASSERT((kIgnoreCoverage_OptFlag | |
| 833 kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 834 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 835 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 836 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 837 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 838 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 839 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 840 break; |
| 841 case SkXfermode::kXor_Mode: |
| 842 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 843 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 844 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags); |
| 845 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 846 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 847 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 848 TEST_ASSERT(kIDA_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 849 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 850 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 851 break; |
| 852 case SkXfermode::kPlus_Mode: |
| 853 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 854 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 855 TEST_ASSERT((kIgnoreCoverage_OptFlag | |
| 856 kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 857 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 858 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 859 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 860 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 861 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 862 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 863 break; |
| 864 case SkXfermode::kModulate_Mode: |
| 865 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 866 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 867 TEST_ASSERT((kIgnoreCoverage_OptFlag) == xpi.fOptFlags); |
| 868 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 869 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 870 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 871 TEST_ASSERT(kZero_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 872 TEST_ASSERT(kSC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 873 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 874 break; |
| 875 case SkXfermode::kScreen_Mode: |
| 876 TEST_ASSERT(xpi.fInvariantOutput.fWillBlendWithDst); |
| 877 TEST_ASSERT(kNone_GrColorComponentFlags == xpi.fInvariantOutput.
fBlendedColorFlags); |
| 878 TEST_ASSERT((kIgnoreCoverage_OptFlag | |
| 879 kCanTweakAlphaForCoverage_OptFlag) == xpi.fOptFlags
); |
| 880 TEST_ASSERT(kModulate_OutputType == xpi.fPrimaryOutputType); |
| 881 TEST_ASSERT(kNone_OutputType == xpi.fSecondaryOutputType); |
| 882 TEST_ASSERT(kAdd_GrBlendEquation == xpi.fBlendInfo.fEquation); |
| 883 TEST_ASSERT(kOne_GrBlendCoeff == xpi.fBlendInfo.fSrcBlend); |
| 884 TEST_ASSERT(kISC_GrBlendCoeff == xpi.fBlendInfo.fDstBlend); |
| 885 TEST_ASSERT(xpi.fBlendInfo.fWriteColor); |
| 886 break; |
| 887 default: |
| 888 ERRORF(reporter, "Invalid xfermode."); |
| 889 break; |
| 890 } |
| 891 } |
| 892 } |
| 893 |
| 894 static void test_lcd_coverage(skiatest::Reporter* reporter, const GrCaps& caps)
{ |
| 895 class : public GrBatch { |
| 896 void getInvariantOutputColor(GrInitInvariantOutput* out) const override
{ |
| 897 out->setKnownFourComponents(GrColorPackRGBA(123, 45, 67, 221)); |
| 898 } |
| 899 |
| 900 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const overri
de { |
| 901 out->setUnknownFourComponents(); |
| 902 out->setUsingLCDCoverage(); |
| 903 } |
| 904 |
| 905 const char* name() const override { return "Test LCD Text Batch"; } |
| 906 void initBatchTracker(const GrPipelineInfo&) override {} |
| 907 bool onCombineIfPossible(GrBatch*) override { return false; } |
| 908 void generateGeometry(GrBatchTarget*, const GrPipeline*) override {} |
| 909 |
| 910 } testLCDCoverageBatch; |
| 911 |
| 912 GrProcOptInfo colorPOI, covPOI; |
| 913 colorPOI.calcColorWithBatch(&testLCDCoverageBatch, NULL, 0); |
| 914 covPOI.calcCoverageWithBatch(&testLCDCoverageBatch, NULL, 0); |
| 915 |
| 916 SkASSERT(kRGBA_GrColorComponentFlags == colorPOI.validFlags()); |
| 917 SkASSERT(covPOI.isFourChannelOutput()); |
| 918 |
| 919 SkAutoTUnref<GrXPFactory> xpf(GrPorterDuffXPFactory::Create(SkXfermode::kSrc
Over_Mode)); |
| 920 TEST_ASSERT(!xpf->willNeedDstTexture(caps, colorPOI, covPOI)); |
| 921 |
| 922 SkAutoTUnref<GrXferProcessor> xp(xpf->createXferProcessor(colorPOI, covPOI,
0, caps)); |
| 923 if (!xp) { |
| 924 ERRORF(reporter, "Failed to create an XP with LCD coverage."); |
| 925 return; |
| 926 } |
| 927 |
| 928 GrXPFactory::InvariantOutput invariantOutput; |
| 929 xpf->getInvariantOutput(colorPOI, covPOI, &invariantOutput); |
| 930 TEST_ASSERT(invariantOutput.fWillBlendWithDst); |
| 931 TEST_ASSERT(kNone_GrColorComponentFlags == invariantOutput.fBlendedColorFlag
s); |
| 932 |
| 933 GrColor overrideColor; |
| 934 xp->getOptimizations(colorPOI, covPOI, false, &overrideColor, caps); |
| 935 |
| 936 GrXferProcessor::BlendInfo blendInfo; |
| 937 xp->getBlendInfo(&blendInfo); |
| 938 TEST_ASSERT(blendInfo.fWriteColor); |
| 939 } |
| 940 |
| 941 static void test_no_dual_source_blending(skiatest::Reporter* reporter) { |
| 942 GrContextOptions opts; |
| 943 opts.fSuppressDualSourceBlending = true; |
| 944 GrContextFactory factory(opts); |
| 945 factory.get(GrContextFactory::kNull_GLContextType); |
| 946 GrContext* ctx = factory.get(GrContextFactory::kNull_GLContextType); |
| 947 if (!ctx) { |
| 948 SkFAIL("Failed to create null context without ARB_blend_func_extended.")
; |
| 949 return; |
| 950 } |
| 951 |
| 952 const GrCaps& caps = *ctx->getGpu()->caps(); |
| 953 if (caps.shaderCaps()->dualSourceBlendingSupport()) { |
| 954 SkFAIL("Null context failed to honor request for no ARB_blend_func_exten
ded."); |
| 955 return; |
| 956 } |
| 957 |
| 958 GrBackendTextureDesc fakeDesc; |
| 959 fakeDesc.fConfig = kRGBA_8888_GrPixelConfig; |
| 960 fakeDesc.fWidth = fakeDesc.fHeight = 100; |
| 961 fakeDesc.fTextureHandle = 1; |
| 962 SkAutoTUnref<GrTexture> fakeTexture(ctx->resourceProvider()->wrapBackendText
ure(fakeDesc)); |
| 963 GrXferProcessor::DstTexture fakeDstTexture; |
| 964 fakeDstTexture.setTexture(fakeTexture); |
| 965 |
| 966 static const GrColor testColors[] = { |
| 967 0, |
| 968 GrColorPackRGBA(0, 82, 0, 255), |
| 969 GrColorPackA4(255) |
| 970 }; |
| 971 static const GrColorComponentFlags testColorFlags[] = { |
| 972 kNone_GrColorComponentFlags, |
| 973 kG_GrColorComponentFlag | kA_GrColorComponentFlag, |
| 974 kRGBA_GrColorComponentFlags |
| 975 }; |
| 976 GR_STATIC_ASSERT(SK_ARRAY_COUNT(testColors) == SK_ARRAY_COUNT(testColorFlags
)); |
| 977 |
| 978 for (size_t c = 0; c < SK_ARRAY_COUNT(testColors); c++) { |
| 979 GrProcOptInfo colorPOI; |
| 980 colorPOI.calcWithInitialValues(NULL, 0, testColors[c], testColorFlags[c]
, false); |
| 981 for (int f = 0; f <= 1; f++) { |
| 982 GrProcOptInfo covPOI; |
| 983 if (!f) { |
| 984 covPOI.calcWithInitialValues(NULL, 0, 0, kNone_GrColorComponentF
lags, true); |
| 985 } else { |
| 986 covPOI.calcWithInitialValues(NULL, 0, GrColorPackA4(255), |
| 987 kRGBA_GrColorComponentFlags, true); |
| 988 } |
| 989 for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) { |
| 990 SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m); |
| 991 SkAutoTUnref<GrXPFactory> xpf(GrPorterDuffXPFactory::Create(xfer
mode)); |
| 992 SkAutoTUnref<GrXferProcessor> xp; |
| 993 if (xpf->willNeedDstTexture(caps, colorPOI, covPOI)) { |
| 994 xp.reset(xpf->createXferProcessor(colorPOI, covPOI, &fakeDst
Texture, caps)); |
| 995 } else { |
| 996 xp.reset(xpf->createXferProcessor(colorPOI, covPOI, NULL, ca
ps)); |
| 997 } |
| 998 if (!xp) { |
| 999 ERRORF(reporter, "Failed to create an XP without dual source
blending."); |
| 1000 return; |
| 1001 } |
| 1002 TEST_ASSERT(!xp->hasSecondaryOutput()); |
| 1003 xp->getOptimizations(colorPOI, covPOI, false, 0, caps); |
| 1004 TEST_ASSERT(!xp->hasSecondaryOutput()); |
| 1005 } |
| 1006 } |
| 1007 } |
| 1008 } |
| 1009 |
| 1010 #endif |
| 1011 |
OLD | NEW |