OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "GrDistanceFieldTextureEffect.h" | 8 #include "GrDistanceFieldTextureEffect.h" |
9 #include "GrFontAtlasSizes.h" | 9 #include "GrFontAtlasSizes.h" |
10 #include "GrInvariantOutput.h" | 10 #include "GrInvariantOutput.h" |
11 #include "GrTexture.h" | 11 #include "GrTexture.h" |
| 12 |
12 #include "SkDistanceFieldGen.h" | 13 #include "SkDistanceFieldGen.h" |
| 14 |
13 #include "gl/GrGLProcessor.h" | 15 #include "gl/GrGLProcessor.h" |
14 #include "gl/GrGLSL.h" | 16 #include "gl/GrGLSL.h" |
15 #include "gl/GrGLTexture.h" | 17 #include "gl/GrGLTexture.h" |
16 #include "gl/GrGLGeometryProcessor.h" | 18 #include "gl/GrGLGeometryProcessor.h" |
17 #include "gl/builders/GrGLProgramBuilder.h" | 19 #include "gl/builders/GrGLProgramBuilder.h" |
18 | 20 |
19 // Assuming a radius of the diagonal of the fragment, hence a factor of sqrt(2)/
2 | 21 // Assuming a radius of a little less than the diagonal of the fragment |
20 #define SK_DistanceFieldAAFactor "0.65" | 22 #define SK_DistanceFieldAAFactor "0.65" |
21 | 23 |
22 struct DistanceFieldBatchTracker { | 24 struct DistanceFieldBatchTracker { |
23 GrGPInput fInputColorType; | 25 GrGPInput fInputColorType; |
24 GrColor fColor; | 26 GrColor fColor; |
25 bool fUsesLocalCoords; | 27 bool fUsesLocalCoords; |
26 }; | 28 }; |
27 | 29 |
28 class GrGLDistanceFieldTextureEffect : public GrGLGeometryProcessor { | 30 class GrGLDistanceFieldTextureEffect : public GrGLGeometryProcessor { |
29 public: | 31 public: |
30 GrGLDistanceFieldTextureEffect(const GrGeometryProcessor&, | 32 GrGLDistanceFieldTextureEffect(const GrGeometryProcessor&, |
31 const GrBatchTracker&) | 33 const GrBatchTracker&) |
32 : fColor(GrColor_ILLEGAL) | 34 : fColor(GrColor_ILLEGAL) |
33 #ifdef SK_GAMMA_APPLY_TO_A8 | 35 #ifdef SK_GAMMA_APPLY_TO_A8 |
34 , fLuminance(-1.0f) | 36 , fDistanceAdjust(-1.0f) |
35 #endif | 37 #endif |
36 {} | 38 {} |
37 | 39 |
38 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 40 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
39 const GrDistanceFieldTextureEffect& dfTexEffect = | 41 const GrDistanceFieldTextureEffect& dfTexEffect = |
40 args.fGP.cast<GrDistanceFieldTextureEffect>(); | 42 args.fGP.cast<GrDistanceFieldTextureEffect>(); |
41 const DistanceFieldBatchTracker& local = args.fBT.cast<DistanceFieldBatc
hTracker>(); | 43 const DistanceFieldBatchTracker& local = args.fBT.cast<DistanceFieldBatc
hTracker>(); |
42 GrGLGPBuilder* pb = args.fPB; | 44 GrGLGPBuilder* pb = args.fPB; |
43 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 45 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
44 SkAssertResult(fsBuilder->enableFeature( | 46 SkAssertResult(fsBuilder->enableFeature( |
45 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); | 47 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
46 | 48 |
47 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 49 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
48 | 50 |
49 // emit attributes | 51 // emit attributes |
50 vsBuilder->emitAttributes(dfTexEffect); | 52 vsBuilder->emitAttributes(dfTexEffect); |
51 | 53 |
52 GrGLVertToFrag st(kVec2f_GrSLType); | 54 GrGLVertToFrag st(kVec2f_GrSLType); |
53 args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); | 55 args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); |
54 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor
ds()->fName); | 56 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor
ds()->fName); |
55 | 57 |
56 GrGLVertToFrag uv(kVec2f_GrSLType); | 58 GrGLVertToFrag uv(kVec2f_GrSLType); |
57 args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); | 59 args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); |
58 // this is only used with text, so our texture bounds always match the g
lyph atlas | 60 // this is only used with text, so our texture bounds always match the g
lyph atlas |
59 vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_A8_RECIP_WIDTH ", " | 61 vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_A8_RECIP_WIDTH ", " |
60 GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", uv.vsOut(), | 62 GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", uv.vsOut(), |
61 dfTexEffect.inTextureCoords()->fName); | 63 dfTexEffect.inTextureCoords()->fName); |
| 64 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 65 // adjust based on gamma |
| 66 const char* distanceAdjustUniName = NULL; |
| 67 // width, height, 1/(3*width) |
| 68 fDistanceAdjustUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_
Visibility, |
| 69 kFloat_GrSLType, kDefault_GrSLPrecision, |
| 70 "DistanceAdjust", &distanceAdjustUniName); |
| 71 #endif |
62 | 72 |
63 // Setup pass through color | 73 // Setup pass through color |
64 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor
, | 74 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor
, |
65 dfTexEffect.inColor(), &fColorUniform); | 75 dfTexEffect.inColor(), &fColorUniform); |
66 | 76 |
67 // Setup position | 77 // Setup position |
68 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix()); | 78 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix()); |
69 | 79 |
70 // emit transforms | 80 // emit transforms |
71 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, | 81 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, |
72 dfTexEffect.localMatrix(), args.fTransformsIn, args
.fTransformsOut); | 82 dfTexEffect.localMatrix(), args.fTransformsIn, args
.fTransformsOut); |
73 | 83 |
74 // Use highp to work around aliasing issues | 84 // Use highp to work around aliasing issues |
75 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision
, | 85 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision
, |
76 pb->ctxInfo().stand
ard())); | 86 pb->ctxInfo().stand
ard())); |
77 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); | 87 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); |
78 | 88 |
79 fsBuilder->codeAppend("\tfloat texColor = "); | 89 fsBuilder->codeAppend("\tfloat texColor = "); |
80 fsBuilder->appendTextureLookup(args.fSamplers[0], | 90 fsBuilder->appendTextureLookup(args.fSamplers[0], |
81 "uv", | 91 "uv", |
82 kVec2f_GrSLType); | 92 kVec2f_GrSLType); |
83 fsBuilder->codeAppend(".r;\n"); | 93 fsBuilder->codeAppend(".r;\n"); |
84 fsBuilder->codeAppend("\tfloat distance = " | 94 fsBuilder->codeAppend("\tfloat distance = " |
85 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFie
ldThreshold ");"); | 95 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFie
ldThreshold ");"); |
| 96 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 97 // adjust width based on gamma |
| 98 fsBuilder->codeAppendf("distance -= %s;", distanceAdjustUniName); |
| 99 #endif |
86 | 100 |
87 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision
, | 101 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision
, |
88 pb->ctxInfo().stand
ard())); | 102 pb->ctxInfo().stand
ard())); |
89 fsBuilder->codeAppendf("vec2 st = %s;", st.fsIn()); | 103 fsBuilder->codeAppendf("vec2 st = %s;", st.fsIn()); |
90 fsBuilder->codeAppend("float afwidth;"); | 104 fsBuilder->codeAppend("float afwidth;"); |
91 if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) { | 105 if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) { |
92 // For uniform scale, we adjust for the effect of the transformation
on the distance | 106 // For uniform scale, we adjust for the effect of the transformation
on the distance |
93 // by using the length of the gradient of the texture coordinates. W
e use st coordinates | 107 // by using the length of the gradient of the texture coordinates. W
e use st coordinates |
94 // to ensure we're mapping 1:1 from texel space to pixel space. | 108 // to ensure we're mapping 1:1 from texel space to pixel space. |
95 | 109 |
(...skipping 16 matching lines...) Expand all Loading... |
112 fsBuilder->codeAppend("vec2 Jdx = dFdx(st);"); | 126 fsBuilder->codeAppend("vec2 Jdx = dFdx(st);"); |
113 fsBuilder->codeAppend("vec2 Jdy = dFdy(st);"); | 127 fsBuilder->codeAppend("vec2 Jdy = dFdy(st);"); |
114 fsBuilder->codeAppend("vec2 grad = vec2(dist_grad.x*Jdx.x + dist_gra
d.y*Jdy.x,"); | 128 fsBuilder->codeAppend("vec2 grad = vec2(dist_grad.x*Jdx.x + dist_gra
d.y*Jdy.x,"); |
115 fsBuilder->codeAppend(" dist_grad.x*Jdx.y + dist_gra
d.y*Jdy.y);"); | 129 fsBuilder->codeAppend(" dist_grad.x*Jdx.y + dist_gra
d.y*Jdy.y);"); |
116 | 130 |
117 // this gives us a smooth step across approximately one fragment | 131 // this gives us a smooth step across approximately one fragment |
118 fsBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*length
(grad);"); | 132 fsBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*length
(grad);"); |
119 } | 133 } |
120 fsBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, distanc
e);"); | 134 fsBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, distanc
e);"); |
121 | 135 |
122 #ifdef SK_GAMMA_APPLY_TO_A8 | |
123 // adjust based on gamma | |
124 const char* luminanceUniName = NULL; | |
125 // width, height, 1/(3*width) | |
126 fLuminanceUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visib
ility, | |
127 kFloat_GrSLType, kDefault_GrSLPreci
sion, | |
128 "Luminance", &luminanceUniName); | |
129 | |
130 fsBuilder->codeAppendf("\tuv = vec2(val, %s);\n", luminanceUniName); | |
131 fsBuilder->codeAppend("\tvec4 gammaColor = "); | |
132 fsBuilder->appendTextureLookup(args.fSamplers[1], "uv", kVec2f_GrSLType)
; | |
133 fsBuilder->codeAppend(";\n"); | |
134 fsBuilder->codeAppend("\tval = gammaColor.r;\n"); | |
135 #endif | |
136 | |
137 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); | 136 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); |
138 } | 137 } |
139 | 138 |
140 virtual void setData(const GrGLProgramDataManager& pdman, | 139 virtual void setData(const GrGLProgramDataManager& pdman, |
141 const GrPrimitiveProcessor& proc, | 140 const GrPrimitiveProcessor& proc, |
142 const GrBatchTracker& bt) override { | 141 const GrBatchTracker& bt) override { |
143 #ifdef SK_GAMMA_APPLY_TO_A8 | 142 #ifdef SK_GAMMA_APPLY_TO_A8 |
144 const GrDistanceFieldTextureEffect& dfTexEffect = | 143 const GrDistanceFieldTextureEffect& dfTexEffect = |
145 proc.cast<GrDistanceFieldTextureEffect>(); | 144 proc.cast<GrDistanceFieldTextureEffect>(); |
146 float luminance = dfTexEffect.getLuminance(); | 145 float distanceAdjust = dfTexEffect.getDistanceAdjust(); |
147 if (luminance != fLuminance) { | 146 if (distanceAdjust != fDistanceAdjust) { |
148 pdman.set1f(fLuminanceUni, luminance); | 147 pdman.set1f(fDistanceAdjustUni, distanceAdjust); |
149 fLuminance = luminance; | 148 fDistanceAdjust = distanceAdjust; |
150 } | 149 } |
151 #endif | 150 #endif |
152 | 151 |
153 this->setUniformViewMatrix(pdman, proc.viewMatrix()); | 152 this->setUniformViewMatrix(pdman, proc.viewMatrix()); |
154 | 153 |
155 const DistanceFieldBatchTracker& local = bt.cast<DistanceFieldBatchTrack
er>(); | 154 const DistanceFieldBatchTracker& local = bt.cast<DistanceFieldBatchTrack
er>(); |
156 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { | 155 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
157 GrGLfloat c[4]; | 156 GrGLfloat c[4]; |
158 GrColorToRGBAFloat(local.fColor, c); | 157 GrColorToRGBAFloat(local.fColor, c); |
159 pdman.set4fv(fColorUniform, 1, c); | 158 pdman.set4fv(fColorUniform, 1, c); |
(...skipping 11 matching lines...) Expand all Loading... |
171 key |= local.fInputColorType << 16; | 170 key |= local.fInputColorType << 16; |
172 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1
<< 24: 0x0; | 171 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1
<< 24: 0x0; |
173 key |= ComputePosKey(gp.viewMatrix()) << 25; | 172 key |= ComputePosKey(gp.viewMatrix()) << 25; |
174 b->add32(key); | 173 b->add32(key); |
175 } | 174 } |
176 | 175 |
177 private: | 176 private: |
178 GrColor fColor; | 177 GrColor fColor; |
179 UniformHandle fColorUniform; | 178 UniformHandle fColorUniform; |
180 #ifdef SK_GAMMA_APPLY_TO_A8 | 179 #ifdef SK_GAMMA_APPLY_TO_A8 |
181 UniformHandle fLuminanceUni; | 180 float fDistanceAdjust; |
182 float fLuminance; | 181 UniformHandle fDistanceAdjustUni; |
183 #endif | 182 #endif |
184 | 183 |
185 typedef GrGLGeometryProcessor INHERITED; | 184 typedef GrGLGeometryProcessor INHERITED; |
186 }; | 185 }; |
187 | 186 |
188 /////////////////////////////////////////////////////////////////////////////// | 187 /////////////////////////////////////////////////////////////////////////////// |
189 | 188 |
190 GrDistanceFieldTextureEffect::GrDistanceFieldTextureEffect(GrColor color, | 189 GrDistanceFieldTextureEffect::GrDistanceFieldTextureEffect(GrColor color, |
191 const SkMatrix& viewM
atrix, | 190 const SkMatrix& viewM
atrix, |
192 GrTexture* texture, | 191 GrTexture* texture, |
193 const GrTextureParams
& params, | 192 const GrTextureParams
& params, |
194 #ifdef SK_GAMMA_APPLY_TO_A8 | 193 #ifdef SK_GAMMA_APPLY_TO_A8 |
195 GrTexture* gamma, | 194 float distanceAdjust, |
196 const GrTextureParams
& gammaParams, | |
197 float luminance, | |
198 #endif | 195 #endif |
199 uint32_t flags, bool
opaqueVertexColors) | 196 uint32_t flags, bool
opaqueVertexColors) |
200 : INHERITED(color, viewMatrix, SkMatrix::I(), opaqueVertexColors) | 197 : INHERITED(color, viewMatrix, SkMatrix::I(), opaqueVertexColors) |
201 , fTextureAccess(texture, params) | 198 , fTextureAccess(texture, params) |
202 #ifdef SK_GAMMA_APPLY_TO_A8 | 199 #ifdef SK_GAMMA_APPLY_TO_A8 |
203 , fGammaTextureAccess(gamma, gammaParams) | 200 , fDistanceAdjust(distanceAdjust) |
204 , fLuminance(luminance) | |
205 #endif | 201 #endif |
206 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) | 202 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) |
207 , fInColor(NULL) { | 203 , fInColor(NULL) { |
208 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); | 204 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); |
209 this->initClassID<GrDistanceFieldTextureEffect>(); | 205 this->initClassID<GrDistanceFieldTextureEffect>(); |
210 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); | 206 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); |
211 if (flags & kColorAttr_DistanceFieldEffectFlag) { | 207 if (flags & kColorAttr_DistanceFieldEffectFlag) { |
212 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); | 208 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); |
213 this->setHasVertexColor(); | 209 this->setHasVertexColor(); |
214 } | 210 } |
215 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 211 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
216 kVec2s_GrVertexAttribT
ype)); | 212 kVec2s_GrVertexAttribT
ype)); |
217 this->addTextureAccess(&fTextureAccess); | 213 this->addTextureAccess(&fTextureAccess); |
218 #ifdef SK_GAMMA_APPLY_TO_A8 | |
219 this->addTextureAccess(&fGammaTextureAccess); | |
220 #endif | |
221 } | 214 } |
222 | 215 |
223 bool GrDistanceFieldTextureEffect::onIsEqual(const GrGeometryProcessor& other) c
onst { | 216 bool GrDistanceFieldTextureEffect::onIsEqual(const GrGeometryProcessor& other) c
onst { |
224 const GrDistanceFieldTextureEffect& cte = other.cast<GrDistanceFieldTextureE
ffect>(); | 217 const GrDistanceFieldTextureEffect& cte = other.cast<GrDistanceFieldTextureE
ffect>(); |
225 return | 218 return |
226 #ifdef SK_GAMMA_APPLY_TO_A8 | 219 #ifdef SK_GAMMA_APPLY_TO_A8 |
227 fLuminance == cte.fLuminance && | 220 fDistanceAdjust == cte.fDistanceAdjust && |
228 #endif | 221 #endif |
229 fFlags == cte.fFlags; | 222 fFlags == cte.fFlags; |
230 } | 223 } |
231 | 224 |
232 void GrDistanceFieldTextureEffect::onGetInvariantOutputCoverage(GrInitInvariantO
utput* out) const { | 225 void GrDistanceFieldTextureEffect::onGetInvariantOutputCoverage(GrInitInvariantO
utput* out) const { |
233 out->setUnknownSingleComponent(); | 226 out->setUnknownSingleComponent(); |
234 } | 227 } |
235 | 228 |
236 void GrDistanceFieldTextureEffect::getGLProcessorKey(const GrBatchTracker& bt, | 229 void GrDistanceFieldTextureEffect::getGLProcessorKey(const GrBatchTracker& bt, |
237 const GrGLCaps& caps, | 230 const GrGLCaps& caps, |
238 GrProcessorKeyBuilder* b) c
onst { | 231 GrProcessorKeyBuilder* b) c
onst { |
239 GrGLDistanceFieldTextureEffect::GenKey(*this, bt, caps, b); | 232 GrGLDistanceFieldTextureEffect::GenKey(*this, bt, caps, b); |
240 } | 233 } |
241 | 234 |
242 GrGLPrimitiveProcessor* | 235 GrGLPrimitiveProcessor* |
243 GrDistanceFieldTextureEffect::createGLInstance(const GrBatchTracker& bt, | 236 GrDistanceFieldTextureEffect::createGLInstance(const GrBatchTracker& bt, |
244 const GrGLCaps&) const { | 237 const GrGLCaps&) const { |
245 return SkNEW_ARGS(GrGLDistanceFieldTextureEffect, (*this, bt)); | 238 return SkNEW_ARGS(GrGLDistanceFieldTextureEffect, (*this, bt)); |
246 } | 239 } |
247 | 240 |
248 void GrDistanceFieldTextureEffect::initBatchTracker(GrBatchTracker* bt, const Gr
PipelineInfo& init) const { | 241 void GrDistanceFieldTextureEffect::initBatchTracker(GrBatchTracker* bt, |
| 242 const GrPipelineInfo& init)
const { |
249 DistanceFieldBatchTracker* local = bt->cast<DistanceFieldBatchTracker>(); | 243 DistanceFieldBatchTracker* local = bt->cast<DistanceFieldBatchTracker>(); |
250 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, | 244 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, |
251 SkToBool(fInColor)); | 245 SkToBool(fInColor)); |
252 local->fUsesLocalCoords = init.fUsesLocalCoords; | 246 local->fUsesLocalCoords = init.fUsesLocalCoords; |
253 } | 247 } |
254 | 248 |
255 bool GrDistanceFieldTextureEffect::onCanMakeEqual(const GrBatchTracker& m, | 249 bool GrDistanceFieldTextureEffect::onCanMakeEqual(const GrBatchTracker& m, |
256 const GrGeometryProcessor& tha
t, | 250 const GrGeometryProcessor& tha
t, |
257 const GrBatchTracker& t) const
{ | 251 const GrBatchTracker& t) const
{ |
258 const DistanceFieldBatchTracker& mine = m.cast<DistanceFieldBatchTracker>(); | 252 const DistanceFieldBatchTracker& mine = m.cast<DistanceFieldBatchTracker>(); |
259 const DistanceFieldBatchTracker& theirs = t.cast<DistanceFieldBatchTracker>(
); | 253 const DistanceFieldBatchTracker& theirs = t.cast<DistanceFieldBatchTracker>(
); |
260 return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, | 254 return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, |
261 that, theirs.fUsesLocalCoords) && | 255 that, theirs.fUsesLocalCoords) && |
262 CanCombineOutput(mine.fInputColorType, mine.fColor, | 256 CanCombineOutput(mine.fInputColorType, mine.fColor, |
263 theirs.fInputColorType, theirs.fColor); | 257 theirs.fInputColorType, theirs.fColor); |
264 } | 258 } |
265 | 259 |
266 /////////////////////////////////////////////////////////////////////////////// | 260 /////////////////////////////////////////////////////////////////////////////// |
267 | 261 |
268 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldTextureEffect); | 262 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldTextureEffect); |
269 | 263 |
270 GrGeometryProcessor* GrDistanceFieldTextureEffect::TestCreate(SkRandom* random, | 264 GrGeometryProcessor* GrDistanceFieldTextureEffect::TestCreate(SkRandom* random, |
271 GrContext*, | 265 GrContext*, |
272 const GrDrawTarget
Caps&, | 266 const GrDrawTarget
Caps&, |
273 GrTexture* texture
s[]) { | 267 GrTexture* texture
s[]) { |
274 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : | 268 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : |
275 GrProcessorUnitTest::kAlphaTextureIdx; | 269 GrProcessorUnitTest::kAlphaTextureIdx; |
276 #ifdef SK_GAMMA_APPLY_TO_A8 | |
277 int texIdx2 = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : | |
278 GrProcessorUnitTest::kAlphaTextureIdx; | |
279 #endif | |
280 static const SkShader::TileMode kTileModes[] = { | 270 static const SkShader::TileMode kTileModes[] = { |
281 SkShader::kClamp_TileMode, | 271 SkShader::kClamp_TileMode, |
282 SkShader::kRepeat_TileMode, | 272 SkShader::kRepeat_TileMode, |
283 SkShader::kMirror_TileMode, | 273 SkShader::kMirror_TileMode, |
284 }; | 274 }; |
285 SkShader::TileMode tileModes[] = { | 275 SkShader::TileMode tileModes[] = { |
286 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 276 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
287 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 277 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
288 }; | 278 }; |
289 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : | 279 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : |
290 GrTextureParams::kNon
e_FilterMode); | 280 GrTextureParams::kNon
e_FilterMode); |
291 #ifdef SK_GAMMA_APPLY_TO_A8 | |
292 GrTextureParams params2(tileModes, random->nextBool() ? GrTextureParams::kBi
lerp_FilterMode : | |
293 GrTextureParams::kNo
ne_FilterMode); | |
294 #endif | |
295 | 281 |
296 return GrDistanceFieldTextureEffect::Create(GrRandomColor(random), | 282 return GrDistanceFieldTextureEffect::Create(GrRandomColor(random), |
297 GrProcessorUnitTest::TestMatrix(
random), | 283 GrProcessorUnitTest::TestMatrix(
random), |
298 textures[texIdx], params, | 284 textures[texIdx], params, |
299 #ifdef SK_GAMMA_APPLY_TO_A8 | 285 #ifdef SK_GAMMA_APPLY_TO_A8 |
300 textures[texIdx2], params2, | |
301 random->nextF(), | 286 random->nextF(), |
302 #endif | 287 #endif |
303 random->nextBool() ? | 288 random->nextBool() ? |
304 kSimilarity_DistanceFieldEff
ectFlag : 0, | 289 kSimilarity_DistanceFieldEff
ectFlag : 0, |
305 random->nextBool()); | 290 random->nextBool()); |
306 } | 291 } |
307 | 292 |
308 /////////////////////////////////////////////////////////////////////////////// | 293 /////////////////////////////////////////////////////////////////////////////// |
309 | 294 |
310 struct DistanceFieldNoGammaBatchTracker { | 295 struct DistanceFieldNoGammaBatchTracker { |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 kVec2f_GrVertexAttribT
ype)); | 465 kVec2f_GrVertexAttribT
ype)); |
481 this->addTextureAccess(&fTextureAccess); | 466 this->addTextureAccess(&fTextureAccess); |
482 } | 467 } |
483 | 468 |
484 bool GrDistanceFieldNoGammaTextureEffect::onIsEqual(const GrGeometryProcessor& o
ther) const { | 469 bool GrDistanceFieldNoGammaTextureEffect::onIsEqual(const GrGeometryProcessor& o
ther) const { |
485 const GrDistanceFieldNoGammaTextureEffect& cte = | 470 const GrDistanceFieldNoGammaTextureEffect& cte = |
486 other.cast<GrDistanceFieldNoGam
maTextureEffect>(); | 471 other.cast<GrDistanceFieldNoGam
maTextureEffect>(); |
487 return fFlags == cte.fFlags; | 472 return fFlags == cte.fFlags; |
488 } | 473 } |
489 | 474 |
490 void GrDistanceFieldNoGammaTextureEffect::onGetInvariantOutputCoverage(GrInitInv
ariantOutput* out) const{ | 475 void GrDistanceFieldNoGammaTextureEffect::onGetInvariantOutputCoverage(GrInitInv
ariantOutput* out) |
| 476
const { |
491 out->setUnknownSingleComponent(); | 477 out->setUnknownSingleComponent(); |
492 } | 478 } |
493 | 479 |
494 void GrDistanceFieldNoGammaTextureEffect::getGLProcessorKey(const GrBatchTracker
& bt, | 480 void GrDistanceFieldNoGammaTextureEffect::getGLProcessorKey(const GrBatchTracker
& bt, |
495 const GrGLCaps& caps
, | 481 const GrGLCaps& caps
, |
496 GrProcessorKeyBuilde
r* b) const { | 482 GrProcessorKeyBuilde
r* b) const { |
497 GrGLDistanceFieldNoGammaTextureEffect::GenKey(*this, bt, caps, b); | 483 GrGLDistanceFieldNoGammaTextureEffect::GenKey(*this, bt, caps, b); |
498 } | 484 } |
499 | 485 |
500 GrGLPrimitiveProcessor* | 486 GrGLPrimitiveProcessor* |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 struct DistanceFieldLCDBatchTracker { | 542 struct DistanceFieldLCDBatchTracker { |
557 GrGPInput fInputColorType; | 543 GrGPInput fInputColorType; |
558 GrColor fColor; | 544 GrColor fColor; |
559 bool fUsesLocalCoords; | 545 bool fUsesLocalCoords; |
560 }; | 546 }; |
561 | 547 |
562 class GrGLDistanceFieldLCDTextureEffect : public GrGLGeometryProcessor { | 548 class GrGLDistanceFieldLCDTextureEffect : public GrGLGeometryProcessor { |
563 public: | 549 public: |
564 GrGLDistanceFieldLCDTextureEffect(const GrGeometryProcessor&, | 550 GrGLDistanceFieldLCDTextureEffect(const GrGeometryProcessor&, |
565 const GrBatchTracker&) | 551 const GrBatchTracker&) |
566 : fColor(GrColor_ILLEGAL) | 552 : fColor(GrColor_ILLEGAL) { |
567 , fTextColor(GrColor_ILLEGAL) {} | 553 fDistanceAdjust = GrDistanceFieldLCDTextureEffect::DistanceAdjust::Make(
1.0f, 1.0f, 1.0f); |
| 554 } |
568 | 555 |
569 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 556 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
570 const GrDistanceFieldLCDTextureEffect& dfTexEffect = | 557 const GrDistanceFieldLCDTextureEffect& dfTexEffect = |
571 args.fGP.cast<GrDistanceFieldLCDTextureEffect>(); | 558 args.fGP.cast<GrDistanceFieldLCDTextureEffect>(); |
572 const DistanceFieldLCDBatchTracker& local = args.fBT.cast<DistanceFieldL
CDBatchTracker>(); | 559 const DistanceFieldLCDBatchTracker& local = args.fBT.cast<DistanceFieldL
CDBatchTracker>(); |
573 GrGLGPBuilder* pb = args.fPB; | 560 GrGLGPBuilder* pb = args.fPB; |
574 | 561 |
575 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 562 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
576 | 563 |
577 // emit attributes | 564 // emit attributes |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 // blue is distance to right offset | 630 // blue is distance to right offset |
644 fsBuilder->codeAppend("\tuv_adjusted = uv + offset;\n"); | 631 fsBuilder->codeAppend("\tuv_adjusted = uv + offset;\n"); |
645 fsBuilder->codeAppend("\ttexColor = "); | 632 fsBuilder->codeAppend("\ttexColor = "); |
646 fsBuilder->appendTextureLookup(args.fSamplers[0], "uv_adjusted", kVec2f_
GrSLType); | 633 fsBuilder->appendTextureLookup(args.fSamplers[0], "uv_adjusted", kVec2f_
GrSLType); |
647 fsBuilder->codeAppend(";\n"); | 634 fsBuilder->codeAppend(";\n"); |
648 fsBuilder->codeAppend("\tdistance.z = texColor.r;\n"); | 635 fsBuilder->codeAppend("\tdistance.z = texColor.r;\n"); |
649 | 636 |
650 fsBuilder->codeAppend("\tdistance = " | 637 fsBuilder->codeAppend("\tdistance = " |
651 "vec3(" SK_DistanceFieldMultiplier ")*(distance - vec3(" SK_DistanceF
ieldThreshold"));"); | 638 "vec3(" SK_DistanceFieldMultiplier ")*(distance - vec3(" SK_DistanceF
ieldThreshold"));"); |
652 | 639 |
| 640 // adjust width based on gamma |
| 641 const char* distanceAdjustUniName = NULL; |
| 642 fDistanceAdjustUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_
Visibility, |
| 643 kVec3f_GrSLType, kDefault_GrSLPrecision, |
| 644 "DistanceAdjust", &distanceAdjustUniName); |
| 645 fsBuilder->codeAppendf("distance -= %s;", distanceAdjustUniName); |
| 646 |
653 // To be strictly correct, we should compute the anti-aliasing factor se
parately | 647 // To be strictly correct, we should compute the anti-aliasing factor se
parately |
654 // for each color component. However, this is only important when using
perspective | 648 // for each color component. However, this is only important when using
perspective |
655 // transformations, and even then using a single factor seems like a rea
sonable | 649 // transformations, and even then using a single factor seems like a rea
sonable |
656 // trade-off between quality and speed. | 650 // trade-off between quality and speed. |
657 fsBuilder->codeAppend("float afwidth;"); | 651 fsBuilder->codeAppend("float afwidth;"); |
658 if (isUniformScale) { | 652 if (isUniformScale) { |
659 // For uniform scale, we adjust for the effect of the transformation
on the distance | 653 // For uniform scale, we adjust for the effect of the transformation
on the distance |
660 // by using the length of the gradient of the texture coordinates. W
e use st coordinates | 654 // by using the length of the gradient of the texture coordinates. W
e use st coordinates |
661 // to ensure we're mapping 1:1 from texel space to pixel space. | 655 // to ensure we're mapping 1:1 from texel space to pixel space. |
662 | 656 |
(...skipping 12 matching lines...) Expand all Loading... |
675 fsBuilder->codeAppend("} else {"); | 669 fsBuilder->codeAppend("} else {"); |
676 fsBuilder->codeAppend("dist_grad = dist_grad*inversesqrt(dg_len2);")
; | 670 fsBuilder->codeAppend("dist_grad = dist_grad*inversesqrt(dg_len2);")
; |
677 fsBuilder->codeAppend("}"); | 671 fsBuilder->codeAppend("}"); |
678 fsBuilder->codeAppend("vec2 grad = vec2(dist_grad.x*Jdx.x + dist_gra
d.y*Jdy.x,"); | 672 fsBuilder->codeAppend("vec2 grad = vec2(dist_grad.x*Jdx.x + dist_gra
d.y*Jdy.x,"); |
679 fsBuilder->codeAppend(" dist_grad.x*Jdx.y + dist_gra
d.y*Jdy.y);"); | 673 fsBuilder->codeAppend(" dist_grad.x*Jdx.y + dist_gra
d.y*Jdy.y);"); |
680 | 674 |
681 // this gives us a smooth step across approximately one fragment | 675 // this gives us a smooth step across approximately one fragment |
682 fsBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*length
(grad);"); | 676 fsBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*length
(grad);"); |
683 } | 677 } |
684 | 678 |
685 fsBuilder->codeAppend("vec4 val = vec4(smoothstep(vec3(-afwidth), vec3(a
fwidth), distance), 1.0);"); | 679 fsBuilder->codeAppend( |
686 | 680 "vec4 val = vec4(smoothstep(vec3(-afwidth), vec3(afwidth),
distance), 1.0);"); |
687 // adjust based on gamma | |
688 const char* textColorUniName = NULL; | |
689 fTextColorUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visib
ility, | |
690 kVec3f_GrSLType, kDefault_GrSLPreci
sion, | |
691 "TextColor", &textColorUniName); | |
692 | |
693 fsBuilder->codeAppendf("\tuv = vec2(val.x, %s.x);\n", textColorUniName); | |
694 fsBuilder->codeAppend("float gammaColor = "); | |
695 fsBuilder->appendTextureLookup(args.fSamplers[1], "uv", kVec2f_GrSLType)
; | |
696 fsBuilder->codeAppend(".r;\n"); | |
697 fsBuilder->codeAppend("\tval.x = gammaColor;\n"); | |
698 | |
699 fsBuilder->codeAppendf("\tuv = vec2(val.y, %s.y);\n", textColorUniName); | |
700 fsBuilder->codeAppend("\tgammaColor = "); | |
701 fsBuilder->appendTextureLookup(args.fSamplers[1], "uv", kVec2f_GrSLType)
; | |
702 fsBuilder->codeAppend(".r;\n"); | |
703 fsBuilder->codeAppend("\tval.y = gammaColor;\n"); | |
704 | |
705 fsBuilder->codeAppendf("\tuv = vec2(val.z, %s.z);\n", textColorUniName); | |
706 fsBuilder->codeAppend("\tgammaColor = "); | |
707 fsBuilder->appendTextureLookup(args.fSamplers[1], "uv", kVec2f_GrSLType)
; | |
708 fsBuilder->codeAppend(".r;\n"); | |
709 fsBuilder->codeAppend("\tval.z = gammaColor;\n"); | |
710 | 681 |
711 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); | 682 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); |
712 } | 683 } |
713 | 684 |
714 virtual void setData(const GrGLProgramDataManager& pdman, | 685 virtual void setData(const GrGLProgramDataManager& pdman, |
715 const GrPrimitiveProcessor& processor, | 686 const GrPrimitiveProcessor& processor, |
716 const GrBatchTracker& bt) override { | 687 const GrBatchTracker& bt) override { |
717 SkASSERT(fTextColorUni.isValid()); | 688 SkASSERT(fDistanceAdjustUni.isValid()); |
718 | 689 |
719 const GrDistanceFieldLCDTextureEffect& dfTexEffect = | 690 const GrDistanceFieldLCDTextureEffect& dfTexEffect = |
720 processor.cast<GrDistanceFieldLCDTextureEffect>(); | 691 processor.cast<GrDistanceFieldLCDTextureEffect>(); |
721 GrColor textColor = dfTexEffect.getTextColor(); | 692 GrDistanceFieldLCDTextureEffect::DistanceAdjust wa = dfTexEffect.getDist
anceAdjust(); |
722 if (textColor != fTextColor) { | 693 if (wa != fDistanceAdjust) { |
723 static const float ONE_OVER_255 = 1.f / 255.f; | 694 pdman.set3f(fDistanceAdjustUni, |
724 pdman.set3f(fTextColorUni, | 695 wa.fR, |
725 GrColorUnpackR(textColor) * ONE_OVER_255, | 696 wa.fG, |
726 GrColorUnpackG(textColor) * ONE_OVER_255, | 697 wa.fB); |
727 GrColorUnpackB(textColor) * ONE_OVER_255); | 698 fDistanceAdjust = wa; |
728 fTextColor = textColor; | |
729 } | 699 } |
730 | 700 |
731 this->setUniformViewMatrix(pdman, processor.viewMatrix()); | 701 this->setUniformViewMatrix(pdman, processor.viewMatrix()); |
732 | 702 |
733 const DistanceFieldLCDBatchTracker& local = bt.cast<DistanceFieldLCDBatc
hTracker>(); | 703 const DistanceFieldLCDBatchTracker& local = bt.cast<DistanceFieldLCDBatc
hTracker>(); |
734 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { | 704 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
735 GrGLfloat c[4]; | 705 GrGLfloat c[4]; |
736 GrColorToRGBAFloat(local.fColor, c); | 706 GrColorToRGBAFloat(local.fColor, c); |
737 pdman.set4fv(fColorUniform, 1, c); | 707 pdman.set4fv(fColorUniform, 1, c); |
738 fColor = local.fColor; | 708 fColor = local.fColor; |
739 } | 709 } |
740 } | 710 } |
741 | 711 |
742 static inline void GenKey(const GrGeometryProcessor& gp, | 712 static inline void GenKey(const GrGeometryProcessor& gp, |
743 const GrBatchTracker& bt, | 713 const GrBatchTracker& bt, |
744 const GrGLCaps&, | 714 const GrGLCaps&, |
745 GrProcessorKeyBuilder* b) { | 715 GrProcessorKeyBuilder* b) { |
746 const GrDistanceFieldLCDTextureEffect& dfTexEffect = | 716 const GrDistanceFieldLCDTextureEffect& dfTexEffect = |
747 gp.cast<GrDistanceFieldLCDTextureEffect>(); | 717 gp.cast<GrDistanceFieldLCDTextureEffect>(); |
748 | 718 |
749 const DistanceFieldLCDBatchTracker& local = bt.cast<DistanceFieldLCDBatc
hTracker>(); | 719 const DistanceFieldLCDBatchTracker& local = bt.cast<DistanceFieldLCDBatc
hTracker>(); |
750 uint32_t key = dfTexEffect.getFlags(); | 720 uint32_t key = dfTexEffect.getFlags(); |
751 key |= local.fInputColorType << 16; | 721 key |= local.fInputColorType << 16; |
752 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1
<< 24: 0x0; | 722 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1
<< 24: 0x0; |
753 key |= ComputePosKey(gp.viewMatrix()) << 25; | 723 key |= ComputePosKey(gp.viewMatrix()) << 25; |
754 b->add32(key); | 724 b->add32(key); |
755 } | 725 } |
756 | 726 |
757 private: | 727 private: |
758 GrColor fColor; | 728 GrColor fColor; |
759 UniformHandle fColorUniform; | 729 UniformHandle fColorUniform; |
760 UniformHandle fTextColorUni; | 730 GrDistanceFieldLCDTextureEffect::DistanceAdjust fDistanceAdjust; |
761 SkColor fTextColor; | 731 UniformHandle fDistanceAdjustUni; |
762 | 732 |
763 typedef GrGLGeometryProcessor INHERITED; | 733 typedef GrGLGeometryProcessor INHERITED; |
764 }; | 734 }; |
765 | 735 |
766 /////////////////////////////////////////////////////////////////////////////// | 736 /////////////////////////////////////////////////////////////////////////////// |
767 | 737 |
768 GrDistanceFieldLCDTextureEffect::GrDistanceFieldLCDTextureEffect( | 738 GrDistanceFieldLCDTextureEffect::GrDistanceFieldLCDTextureEffect( |
769 GrColor color, const SkMatrix&
viewMatrix, | 739 GrColor color, const SkMatrix&
viewMatrix, |
770 GrTexture* texture, const GrTe
xtureParams& params, | 740 GrTexture* texture, const GrTe
xtureParams& params, |
771 GrTexture* gamma, const GrText
ureParams& gParams, | 741 DistanceAdjust distanceAdjust, |
772 SkColor textColor, | |
773 uint32_t flags) | 742 uint32_t flags) |
774 : INHERITED(color, viewMatrix, SkMatrix::I()) | 743 : INHERITED(color, viewMatrix, SkMatrix::I()) |
775 , fTextureAccess(texture, params) | 744 , fTextureAccess(texture, params) |
776 , fGammaTextureAccess(gamma, gParams) | 745 , fDistanceAdjust(distanceAdjust) |
777 , fTextColor(textColor) | |
778 , fFlags(flags & kLCD_DistanceFieldEffectMask){ | 746 , fFlags(flags & kLCD_DistanceFieldEffectMask){ |
779 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan
ceFieldEffectFlag)); | 747 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan
ceFieldEffectFlag)); |
780 this->initClassID<GrDistanceFieldLCDTextureEffect>(); | 748 this->initClassID<GrDistanceFieldLCDTextureEffect>(); |
781 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); | 749 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); |
782 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 750 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
783 kVec2s_GrVertexAttribT
ype)); | 751 kVec2s_GrVertexAttribT
ype)); |
784 this->addTextureAccess(&fTextureAccess); | 752 this->addTextureAccess(&fTextureAccess); |
785 this->addTextureAccess(&fGammaTextureAccess); | |
786 } | 753 } |
787 | 754 |
788 bool GrDistanceFieldLCDTextureEffect::onIsEqual(const GrGeometryProcessor& other
) const { | 755 bool GrDistanceFieldLCDTextureEffect::onIsEqual(const GrGeometryProcessor& other
) const { |
789 const GrDistanceFieldLCDTextureEffect& cte = other.cast<GrDistanceFieldLCDTe
xtureEffect>(); | 756 const GrDistanceFieldLCDTextureEffect& cte = other.cast<GrDistanceFieldLCDTe
xtureEffect>(); |
790 return (fTextColor == cte.fTextColor && | 757 return (fDistanceAdjust == cte.fDistanceAdjust && |
791 fFlags == cte.fFlags); | 758 fFlags == cte.fFlags); |
792 } | 759 } |
793 | 760 |
794 void GrDistanceFieldLCDTextureEffect::onGetInvariantOutputCoverage(GrInitInvaria
ntOutput* out) const { | 761 void GrDistanceFieldLCDTextureEffect::onGetInvariantOutputCoverage(GrInitInvaria
ntOutput* out) |
| 762
const { |
795 out->setUnknownFourComponents(); | 763 out->setUnknownFourComponents(); |
796 out->setUsingLCDCoverage(); | 764 out->setUsingLCDCoverage(); |
797 } | 765 } |
798 | 766 |
799 void GrDistanceFieldLCDTextureEffect::getGLProcessorKey(const GrBatchTracker& bt
, | 767 void GrDistanceFieldLCDTextureEffect::getGLProcessorKey(const GrBatchTracker& bt
, |
800 const GrGLCaps& caps, | 768 const GrGLCaps& caps, |
801 GrProcessorKeyBuilder* b
) const { | 769 GrProcessorKeyBuilder* b
) const { |
802 GrGLDistanceFieldLCDTextureEffect::GenKey(*this, bt, caps, b); | 770 GrGLDistanceFieldLCDTextureEffect::GenKey(*this, bt, caps, b); |
803 } | 771 } |
804 | 772 |
(...skipping 24 matching lines...) Expand all Loading... |
829 /////////////////////////////////////////////////////////////////////////////// | 797 /////////////////////////////////////////////////////////////////////////////// |
830 | 798 |
831 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldLCDTextureEffect); | 799 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldLCDTextureEffect); |
832 | 800 |
833 GrGeometryProcessor* GrDistanceFieldLCDTextureEffect::TestCreate(SkRandom* rando
m, | 801 GrGeometryProcessor* GrDistanceFieldLCDTextureEffect::TestCreate(SkRandom* rando
m, |
834 GrContext*, | 802 GrContext*, |
835 const GrDrawTar
getCaps&, | 803 const GrDrawTar
getCaps&, |
836 GrTexture* text
ures[]) { | 804 GrTexture* text
ures[]) { |
837 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : | 805 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : |
838 GrProcessorUnitTest::kAlphaTextureIdx; | 806 GrProcessorUnitTest::kAlphaTextureIdx; |
839 int texIdx2 = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : | |
840 GrProcessorUnitTest::kAlphaTextureIdx; | |
841 static const SkShader::TileMode kTileModes[] = { | 807 static const SkShader::TileMode kTileModes[] = { |
842 SkShader::kClamp_TileMode, | 808 SkShader::kClamp_TileMode, |
843 SkShader::kRepeat_TileMode, | 809 SkShader::kRepeat_TileMode, |
844 SkShader::kMirror_TileMode, | 810 SkShader::kMirror_TileMode, |
845 }; | 811 }; |
846 SkShader::TileMode tileModes[] = { | 812 SkShader::TileMode tileModes[] = { |
847 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 813 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
848 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 814 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
849 }; | 815 }; |
850 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : | 816 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : |
851 GrTextureParams::kNone_FilterMode); | 817 GrTextureParams::kNone_FilterMode); |
852 GrTextureParams params2(tileModes, random->nextBool() ? GrTextureParams::kBi
lerp_FilterMode : | 818 DistanceAdjust wa = { 0.0f, 0.1f, -0.1f }; |
853 GrTextureParams::kNone_FilterMode); | |
854 GrColor textColor = GrColorPackRGBA(random->nextULessThan(256), | |
855 random->nextULessThan(256), | |
856 random->nextULessThan(256), | |
857 random->nextULessThan(256)); | |
858 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; | 819 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; |
859 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; | 820 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; |
860 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 821 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; |
861 return GrDistanceFieldLCDTextureEffect::Create(GrRandomColor(random), | 822 return GrDistanceFieldLCDTextureEffect::Create(GrRandomColor(random), |
862 GrProcessorUnitTest::TestMatr
ix(random), | 823 GrProcessorUnitTest::TestMatr
ix(random), |
863 textures[texIdx], params, | 824 textures[texIdx], params, |
864 textures[texIdx2], params2, | 825 wa, |
865 textColor, | |
866 flags); | 826 flags); |
867 } | 827 } |
OLD | NEW |