OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "effects/GrPorterDuffXferProcessor.h" | 8 #include "effects/GrPorterDuffXferProcessor.h" |
9 | 9 |
10 #include "GrBlend.h" | 10 #include "GrBlend.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 case GrPorterDuffXferProcessor::kCoverageISC_SecondaryOutputType
: | 59 case GrPorterDuffXferProcessor::kCoverageISC_SecondaryOutputType
: |
60 fsBuilder->codeAppendf("%s = (vec4(1.0) - %s) * %s;", | 60 fsBuilder->codeAppendf("%s = (vec4(1.0) - %s) * %s;", |
61 args.fOutputSecondary, args.fInputCol
or, | 61 args.fOutputSecondary, args.fInputCol
or, |
62 args.fInputCoverage); | 62 args.fInputCoverage); |
63 break; | 63 break; |
64 default: | 64 default: |
65 SkFAIL("Unexpected Secondary Output"); | 65 SkFAIL("Unexpected Secondary Output"); |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 fsBuilder->codeAppendf("%s = %s * %s;", args.fOutputPrimary, args.fInput
Color, | 69 switch (xp.primaryOutputType()) { |
70 args.fInputCoverage); | 70 case GrPorterDuffXferProcessor::kNone_PrimaryOutputType: |
71 if (GrPorterDuffXferProcessor::kCombineWithDst_PrimaryOutputType == xp.p
rimaryOutputType()){ | 71 fsBuilder->codeAppendf("%s = vec4(0);", args.fOutputPrimary); |
72 fsBuilder->codeAppendf("%s += (vec4(1.0) - %s) * %s;", args.fOutputP
rimary, | 72 break; |
73 args.fInputCoverage, fsBuilder->dstColor()); | 73 case GrPorterDuffXferProcessor::kColor_PrimaryOutputType: |
| 74 fsBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fIn
putColor); |
| 75 break; |
| 76 case GrPorterDuffXferProcessor::kCoverage_PrimaryOutputType: |
| 77 fsBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fIn
putCoverage); |
| 78 break; |
| 79 case GrPorterDuffXferProcessor::kModulate_PrimaryOutputType: |
| 80 case GrPorterDuffXferProcessor::kCombineWithDst_PrimaryOutputType: |
| 81 fsBuilder->codeAppendf("%s = %s * %s;", args.fOutputPrimary, arg
s.fInputColor, |
| 82 args.fInputCoverage); |
| 83 if (GrPorterDuffXferProcessor::kCombineWithDst_PrimaryOutputType
== |
| 84 xp.primaryOutputType()){ |
| 85 fsBuilder->codeAppendf("%s += (vec4(1.0) - %s) * %s;", args.
fOutputPrimary, |
| 86 args.fInputCoverage, fsBuilder->dstCo
lor()); |
| 87 } |
| 88 break; |
| 89 default: |
| 90 SkFAIL("Unexpected Primary Output"); |
74 } | 91 } |
75 } | 92 } |
76 | 93 |
77 virtual void setData(const GrGLProgramDataManager&, const GrXferProcessor&)
SK_OVERRIDE {}; | 94 virtual void setData(const GrGLProgramDataManager&, const GrXferProcessor&)
SK_OVERRIDE {}; |
78 | 95 |
79 static void GenKey(const GrProcessor& processor, const GrGLCaps& caps, | 96 static void GenKey(const GrProcessor& processor, const GrGLCaps& caps, |
80 GrProcessorKeyBuilder* b) { | 97 GrProcessorKeyBuilder* b) { |
81 const GrPorterDuffXferProcessor& xp = processor.cast<GrPorterDuffXferPro
cessor>(); | 98 const GrPorterDuffXferProcessor& xp = processor.cast<GrPorterDuffXferPro
cessor>(); |
82 b->add32(xp.primaryOutputType()); | 99 b->add32(xp.primaryOutputType()); |
83 b->add32(xp.secondaryOutputType()); | 100 b->add32(xp.secondaryOutputType()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 coverage
); | 149 coverage
); |
133 | 150 |
134 this->calcOutputTypes(optFlags, caps, isCoverageDrawing || coveragePOI.isSol
idWhite(), | 151 this->calcOutputTypes(optFlags, caps, isCoverageDrawing || coveragePOI.isSol
idWhite(), |
135 colorPOI.readsDst() || coveragePOI.readsDst()); | 152 colorPOI.readsDst() || coveragePOI.readsDst()); |
136 return optFlags; | 153 return optFlags; |
137 } | 154 } |
138 | 155 |
139 void GrPorterDuffXferProcessor::calcOutputTypes(GrXferProcessor::OptFlags optFla
gs, | 156 void GrPorterDuffXferProcessor::calcOutputTypes(GrXferProcessor::OptFlags optFla
gs, |
140 const GrDrawTargetCaps& caps, | 157 const GrDrawTargetCaps& caps, |
141 bool hasSolidCoverage, bool read
sDst) { | 158 bool hasSolidCoverage, bool read
sDst) { |
| 159 if (optFlags & kClearColorStages_OptFlag) { |
| 160 if (optFlags & kClearCoverageStages_OptFlag) { |
| 161 fPrimaryOutputType = kNone_PrimaryOutputType; |
| 162 return; |
| 163 } else { |
| 164 fPrimaryOutputType = kCoverage_PrimaryOutputType; |
| 165 return; |
| 166 } |
| 167 } else if (optFlags & kClearCoverageStages_OptFlag) { |
| 168 fPrimaryOutputType = kColor_PrimaryOutputType; |
| 169 return; |
| 170 } |
| 171 |
142 // If we do have coverage determine whether it matters. Dual source blendin
g is expensive so | 172 // If we do have coverage determine whether it matters. Dual source blendin
g is expensive so |
143 // we don't do it if we are doing coverage drawing. If we aren't then We al
ways do dual source | 173 // we don't do it if we are doing coverage drawing. If we aren't then We al
ways do dual source |
144 // blending if we have any effective coverage stages OR the geometry process
or doesn't emits | 174 // blending if we have any effective coverage stages OR the geometry process
or doesn't emits |
145 // solid coverage. | 175 // solid coverage. |
146 if (!(optFlags & kSetCoverageDrawing_OptFlag) && !hasSolidCoverage) { | 176 if (!(optFlags & kSetCoverageDrawing_OptFlag) && !hasSolidCoverage) { |
147 if (caps.dualSourceBlendingSupport()) { | 177 if (caps.dualSourceBlendingSupport()) { |
148 if (kZero_GrBlendCoeff == fDstBlend) { | 178 if (kZero_GrBlendCoeff == fDstBlend) { |
149 // write the coverage value to second color | 179 // write the coverage value to second color |
150 fSecondaryOutputType = kCoverage_SecondaryOutputType; | 180 fSecondaryOutputType = kCoverage_SecondaryOutputType; |
151 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | 181 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 } while (GrBlendCoeffRefsSrc(src)); | 579 } while (GrBlendCoeffRefsSrc(src)); |
550 | 580 |
551 GrBlendCoeff dst; | 581 GrBlendCoeff dst; |
552 do { | 582 do { |
553 dst = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPub
licGrBlendCoeff)); | 583 dst = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPub
licGrBlendCoeff)); |
554 } while (GrBlendCoeffRefsDst(dst)); | 584 } while (GrBlendCoeffRefsDst(dst)); |
555 | 585 |
556 return GrPorterDuffXPFactory::Create(src, dst); | 586 return GrPorterDuffXPFactory::Create(src, dst); |
557 } | 587 } |
558 | 588 |
OLD | NEW |