| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkXfermode.h" | 8 #include "SkXfermode.h" |
| 9 #include "Test.h" | 9 #include "Test.h" |
| 10 | 10 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 kIgnoreColor_OptFlag = GrXferProcessor::kIgnoreColor_OptFlag, | 70 kIgnoreColor_OptFlag = GrXferProcessor::kIgnoreColor_OptFlag, |
| 71 kIgnoreCoverage_OptFlag = GrXferProcessor::kIgnoreCoverage_OptFlag
, | 71 kIgnoreCoverage_OptFlag = GrXferProcessor::kIgnoreCoverage_OptFlag
, |
| 72 kCanTweakAlphaForCoverage_OptFlag = GrXferProcessor::kCanTweakAlphaForCovera
ge_OptFlag | 72 kCanTweakAlphaForCoverage_OptFlag = GrXferProcessor::kCanTweakAlphaForCovera
ge_OptFlag |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 class GrPorterDuffTest { | 75 class GrPorterDuffTest { |
| 76 public: | 76 public: |
| 77 struct XPInfo { | 77 struct XPInfo { |
| 78 XPInfo(skiatest::Reporter* reporter, SkXfermode::Mode xfermode, const Gr
Caps& caps, | 78 XPInfo(skiatest::Reporter* reporter, SkXfermode::Mode xfermode, const Gr
Caps& caps, |
| 79 const GrProcOptInfo& colorPOI, const GrProcOptInfo& covPOI) { | 79 const GrProcOptInfo& colorPOI, const GrProcOptInfo& covPOI) { |
| 80 SkAutoTUnref<GrXPFactory> xpf(GrPorterDuffXPFactory::Create(xfermode
)); | 80 SkAutoTUnref<const GrXPFactory> xpf(GrPorterDuffXPFactory::Create(xf
ermode)); |
| 81 SkAutoTUnref<GrXferProcessor> xp( | 81 SkAutoTUnref<GrXferProcessor> xp( |
| 82 xpf->createXferProcessor(colorPOI, covPOI, false, nullptr, caps)
); | 82 xpf->createXferProcessor(colorPOI, covPOI, false, nullptr, caps)
); |
| 83 TEST_ASSERT(!xpf->willNeedDstTexture(caps, colorPOI, covPOI, false))
; | 83 TEST_ASSERT(!xpf->willNeedDstTexture(caps, colorPOI, covPOI, false))
; |
| 84 xpf->getInvariantBlendedColor(colorPOI, &fBlendedColor); | 84 xpf->getInvariantBlendedColor(colorPOI, &fBlendedColor); |
| 85 fOptFlags = xp->getOptimizations(colorPOI, covPOI, false, nullptr, c
aps); | 85 fOptFlags = xp->getOptimizations(colorPOI, covPOI, false, nullptr, c
aps); |
| 86 GetXPOutputTypes(xp, &fPrimaryOutputType, &fSecondaryOutputType); | 86 GetXPOutputTypes(xp, &fPrimaryOutputType, &fSecondaryOutputType); |
| 87 xp->getBlendInfo(&fBlendInfo); | 87 xp->getBlendInfo(&fBlendInfo); |
| 88 TEST_ASSERT(!xp->willReadDstColor()); | 88 TEST_ASSERT(!xp->willReadDstColor()); |
| 89 TEST_ASSERT(xp->hasSecondaryOutput() == GrBlendCoeffRefsSrc2(fBlendI
nfo.fDstBlend)); | 89 TEST_ASSERT(xp->hasSecondaryOutput() == GrBlendCoeffRefsSrc2(fBlendI
nfo.fDstBlend)); |
| 90 } | 90 } |
| 91 | 91 |
| 92 GrXPFactory::InvariantBlendedColor fBlendedColor; | 92 GrXPFactory::InvariantBlendedColor fBlendedColor; |
| 93 int fOptFlags; | 93 int fOptFlags; |
| 94 int fPrimaryOutputType; | 94 int fPrimaryOutputType; |
| 95 int fSecondaryOutputType; | 95 int fSecondaryOutputType; |
| 96 GrXferProcessor::BlendInfo fBlendInfo; | 96 GrXferProcessor::BlendInfo fBlendInfo; |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 static void GetXPOutputTypes(const GrXferProcessor* xp, int* outPrimary, int
* outSecondary) { | 99 static void GetXPOutputTypes(const GrXferProcessor* xp, int* outPrimary, int
* outSecondary) { |
| 100 GrPorterDuffXPFactory::TestGetXPOutputTypes(xp, outPrimary, outSecondary
); | 100 GrPDXPFactory::TestGetXPOutputTypes(xp, outPrimary, outSecondary); |
| 101 } | 101 } |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 static void test_lcd_coverage(skiatest::Reporter* reporter, const GrCaps& caps)
{ | 104 static void test_lcd_coverage(skiatest::Reporter* reporter, const GrCaps& caps)
{ |
| 105 GrProcOptInfo colorPOI, covPOI; | 105 GrProcOptInfo colorPOI, covPOI; |
| 106 colorPOI.calcWithInitialValues(NULL, 0, 0, kNone_GrColorComponentFlags, fals
e); | 106 colorPOI.calcWithInitialValues(NULL, 0, 0, kNone_GrColorComponentFlags, fals
e); |
| 107 // Setting 2nd to last value to false and last to true will force covPOI to
LCD coverage. | 107 // Setting 2nd to last value to false and last to true will force covPOI to
LCD coverage. |
| 108 covPOI.calcWithInitialValues(NULL, 0, 0, kNone_GrColorComponentFlags, false,
true); | 108 covPOI.calcWithInitialValues(NULL, 0, 0, kNone_GrColorComponentFlags, false,
true); |
| 109 | 109 |
| 110 SkASSERT(!colorPOI.isOpaque()); | 110 SkASSERT(!colorPOI.isOpaque()); |
| (...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 typedef GrVertexBatch INHERITED; | 1117 typedef GrVertexBatch INHERITED; |
| 1118 } testLCDCoverageBatch; | 1118 } testLCDCoverageBatch; |
| 1119 | 1119 |
| 1120 GrProcOptInfo colorPOI, covPOI; | 1120 GrProcOptInfo colorPOI, covPOI; |
| 1121 colorPOI.calcColorWithBatch(&testLCDCoverageBatch, nullptr, 0); | 1121 colorPOI.calcColorWithBatch(&testLCDCoverageBatch, nullptr, 0); |
| 1122 covPOI.calcCoverageWithBatch(&testLCDCoverageBatch, nullptr, 0); | 1122 covPOI.calcCoverageWithBatch(&testLCDCoverageBatch, nullptr, 0); |
| 1123 | 1123 |
| 1124 SkASSERT(kRGBA_GrColorComponentFlags == colorPOI.validFlags()); | 1124 SkASSERT(kRGBA_GrColorComponentFlags == colorPOI.validFlags()); |
| 1125 SkASSERT(covPOI.isFourChannelOutput()); | 1125 SkASSERT(covPOI.isFourChannelOutput()); |
| 1126 | 1126 |
| 1127 SkAutoTUnref<GrXPFactory> xpf(GrPorterDuffXPFactory::Create(SkXfermode::kSrc
Over_Mode)); | 1127 SkAutoTUnref<const GrXPFactory> xpf(GrPorterDuffXPFactory::Create(SkXfermode
::kSrcOver_Mode)); |
| 1128 TEST_ASSERT(!xpf->willNeedDstTexture(caps, colorPOI, covPOI, false)); | 1128 TEST_ASSERT(!xpf->willNeedDstTexture(caps, colorPOI, covPOI, false)); |
| 1129 | 1129 |
| 1130 SkAutoTUnref<GrXferProcessor> xp( | 1130 SkAutoTUnref<GrXferProcessor> xp( |
| 1131 xpf->createXferProcessor(colorPOI, covPOI, false, nullptr, caps)); | 1131 xpf->createXferProcessor(colorPOI, covPOI, false, nullptr, caps)); |
| 1132 if (!xp) { | 1132 if (!xp) { |
| 1133 ERRORF(reporter, "Failed to create an XP with LCD coverage."); | 1133 ERRORF(reporter, "Failed to create an XP with LCD coverage."); |
| 1134 return; | 1134 return; |
| 1135 } | 1135 } |
| 1136 | 1136 |
| 1137 GrXPFactory::InvariantBlendedColor blendedColor; | 1137 GrXPFactory::InvariantBlendedColor blendedColor; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1193 for (int f = 0; f <= 1; f++) { | 1193 for (int f = 0; f <= 1; f++) { |
| 1194 GrProcOptInfo covPOI; | 1194 GrProcOptInfo covPOI; |
| 1195 if (!f) { | 1195 if (!f) { |
| 1196 covPOI.calcWithInitialValues(nullptr, 0, 0, kNone_GrColorCompone
ntFlags, true); | 1196 covPOI.calcWithInitialValues(nullptr, 0, 0, kNone_GrColorCompone
ntFlags, true); |
| 1197 } else { | 1197 } else { |
| 1198 covPOI.calcWithInitialValues(nullptr, 0, GrColorPackA4(255), | 1198 covPOI.calcWithInitialValues(nullptr, 0, GrColorPackA4(255), |
| 1199 kRGBA_GrColorComponentFlags, true); | 1199 kRGBA_GrColorComponentFlags, true); |
| 1200 } | 1200 } |
| 1201 for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) { | 1201 for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) { |
| 1202 SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m); | 1202 SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m); |
| 1203 SkAutoTUnref<GrXPFactory> xpf(GrPorterDuffXPFactory::Create(xfer
mode)); | 1203 SkAutoTUnref<const GrXPFactory> xpf(GrPorterDuffXPFactory::Creat
e(xfermode)); |
| 1204 GrXferProcessor::DstTexture* dstTexture = | 1204 GrXferProcessor::DstTexture* dstTexture = |
| 1205 xpf->willNeedDstTexture(caps, colorPOI, covPOI, false) ? &fa
keDstTexture : 0; | 1205 xpf->willNeedDstTexture(caps, colorPOI, covPOI, false) ? &fa
keDstTexture : 0; |
| 1206 SkAutoTUnref<GrXferProcessor> xp( | 1206 SkAutoTUnref<GrXferProcessor> xp( |
| 1207 xpf->createXferProcessor(colorPOI, covPOI, false, dstTexture
, caps)); | 1207 xpf->createXferProcessor(colorPOI, covPOI, false, dstTexture
, caps)); |
| 1208 if (!xp) { | 1208 if (!xp) { |
| 1209 ERRORF(reporter, "Failed to create an XP without dual source
blending."); | 1209 ERRORF(reporter, "Failed to create an XP without dual source
blending."); |
| 1210 return; | 1210 return; |
| 1211 } | 1211 } |
| 1212 TEST_ASSERT(!xp->hasSecondaryOutput()); | 1212 TEST_ASSERT(!xp->hasSecondaryOutput()); |
| 1213 xp->getOptimizations(colorPOI, covPOI, false, 0, caps); | 1213 xp->getOptimizations(colorPOI, covPOI, false, 0, caps); |
| 1214 TEST_ASSERT(!xp->hasSecondaryOutput()); | 1214 TEST_ASSERT(!xp->hasSecondaryOutput()); |
| 1215 } | 1215 } |
| 1216 } | 1216 } |
| 1217 } | 1217 } |
| 1218 ctx->getGpu()->deleteTestingOnlyBackendTexture(backendTex); | 1218 ctx->getGpu()->deleteTestingOnlyBackendTexture(backendTex); |
| 1219 } | 1219 } |
| 1220 | 1220 |
| 1221 #endif | 1221 #endif |
| 1222 | 1222 |
| OLD | NEW |