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 |
13 #include "SkDistanceFieldGen.h" | 13 #include "SkDistanceFieldGen.h" |
14 | 14 |
15 #include "gl/GrGLProcessor.h" | 15 #include "gl/GrGLProcessor.h" |
16 #include "gl/GrGLSL.h" | 16 #include "gl/GrGLSL.h" |
17 #include "gl/GrGLTexture.h" | 17 #include "gl/GrGLTexture.h" |
18 #include "gl/GrGLGeometryProcessor.h" | 18 #include "gl/GrGLGeometryProcessor.h" |
19 #include "gl/builders/GrGLProgramBuilder.h" | 19 #include "gl/builders/GrGLProgramBuilder.h" |
20 | 20 |
21 // Assuming a radius of a little less than the diagonal of the fragment | 21 // Assuming a radius of a little less than the diagonal of the fragment |
22 #define SK_DistanceFieldAAFactor "0.65" | 22 #define SK_DistanceFieldAAFactor "0.65" |
23 | 23 |
24 struct DistanceFieldBatchTracker { | 24 struct DistanceFieldBatchTracker { |
25 GrGPInput fInputColorType; | 25 GrGPInput fInputColorType; |
26 GrColor fColor; | 26 GrColor fColor; |
27 bool fUsesLocalCoords; | 27 bool fUsesLocalCoords; |
28 }; | 28 }; |
29 | 29 |
30 class GrGLDistanceFieldTextureEffect : public GrGLGeometryProcessor { | 30 class GrGLDistanceFieldA8TextGeoProc : public GrGLGeometryProcessor { |
31 public: | 31 public: |
32 GrGLDistanceFieldTextureEffect(const GrGeometryProcessor&, | 32 GrGLDistanceFieldA8TextGeoProc(const GrGeometryProcessor&, |
33 const GrBatchTracker&) | 33 const GrBatchTracker&) |
34 : fColor(GrColor_ILLEGAL) | 34 : fColor(GrColor_ILLEGAL) |
35 #ifdef SK_GAMMA_APPLY_TO_A8 | 35 #ifdef SK_GAMMA_APPLY_TO_A8 |
36 , fDistanceAdjust(-1.0f) | 36 , fDistanceAdjust(-1.0f) |
37 #endif | 37 #endif |
38 {} | 38 {} |
39 | 39 |
40 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 40 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
41 const GrDistanceFieldTextureEffect& dfTexEffect = | 41 const GrDistanceFieldA8TextGeoProc& dfTexEffect = args.fGP.cast<GrDistan ceFieldA8TextGeoProc>(); |
joshualitt
2015/04/08 18:20:51
Line wrap but I have not strong preference
jvanverth1
2015/04/08 18:45:21
Done.
| |
42 args.fGP.cast<GrDistanceFieldTextureEffect>(); | |
43 const DistanceFieldBatchTracker& local = args.fBT.cast<DistanceFieldBatc hTracker>(); | 42 const DistanceFieldBatchTracker& local = args.fBT.cast<DistanceFieldBatc hTracker>(); |
44 GrGLGPBuilder* pb = args.fPB; | 43 GrGLGPBuilder* pb = args.fPB; |
45 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 44 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
46 SkAssertResult(fsBuilder->enableFeature( | 45 SkAssertResult(fsBuilder->enableFeature( |
47 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); | 46 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
48 | 47 |
49 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 48 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
50 | 49 |
51 // emit attributes | 50 // emit attributes |
52 vsBuilder->emitAttributes(dfTexEffect); | 51 vsBuilder->emitAttributes(dfTexEffect); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 } | 152 } |
154 fsBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, distanc e);"); | 153 fsBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, distanc e);"); |
155 | 154 |
156 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); | 155 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); |
157 } | 156 } |
158 | 157 |
159 virtual void setData(const GrGLProgramDataManager& pdman, | 158 virtual void setData(const GrGLProgramDataManager& pdman, |
160 const GrPrimitiveProcessor& proc, | 159 const GrPrimitiveProcessor& proc, |
161 const GrBatchTracker& bt) override { | 160 const GrBatchTracker& bt) override { |
162 #ifdef SK_GAMMA_APPLY_TO_A8 | 161 #ifdef SK_GAMMA_APPLY_TO_A8 |
163 const GrDistanceFieldTextureEffect& dfTexEffect = | 162 const GrDistanceFieldA8TextGeoProc& dfTexEffect = proc.cast<GrDistanceFi eldA8TextGeoProc>(); |
164 proc.cast<GrDistanceFieldTextureEffect>(); | |
165 float distanceAdjust = dfTexEffect.getDistanceAdjust(); | 163 float distanceAdjust = dfTexEffect.getDistanceAdjust(); |
166 if (distanceAdjust != fDistanceAdjust) { | 164 if (distanceAdjust != fDistanceAdjust) { |
167 pdman.set1f(fDistanceAdjustUni, distanceAdjust); | 165 pdman.set1f(fDistanceAdjustUni, distanceAdjust); |
168 fDistanceAdjust = distanceAdjust; | 166 fDistanceAdjust = distanceAdjust; |
169 } | 167 } |
170 #endif | 168 #endif |
171 | 169 |
172 this->setUniformViewMatrix(pdman, proc.viewMatrix()); | 170 this->setUniformViewMatrix(pdman, proc.viewMatrix()); |
173 | 171 |
174 const DistanceFieldBatchTracker& local = bt.cast<DistanceFieldBatchTrack er>(); | 172 const DistanceFieldBatchTracker& local = bt.cast<DistanceFieldBatchTrack er>(); |
175 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo r) { | 173 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo r) { |
176 GrGLfloat c[4]; | 174 GrGLfloat c[4]; |
177 GrColorToRGBAFloat(local.fColor, c); | 175 GrColorToRGBAFloat(local.fColor, c); |
178 pdman.set4fv(fColorUniform, 1, c); | 176 pdman.set4fv(fColorUniform, 1, c); |
179 fColor = local.fColor; | 177 fColor = local.fColor; |
180 } | 178 } |
181 } | 179 } |
182 | 180 |
183 static inline void GenKey(const GrGeometryProcessor& gp, | 181 static inline void GenKey(const GrGeometryProcessor& gp, |
184 const GrBatchTracker& bt, | 182 const GrBatchTracker& bt, |
185 const GrGLCaps&, | 183 const GrGLCaps&, |
186 GrProcessorKeyBuilder* b) { | 184 GrProcessorKeyBuilder* b) { |
187 const GrDistanceFieldTextureEffect& dfTexEffect = gp.cast<GrDistanceFiel dTextureEffect>(); | 185 const GrDistanceFieldA8TextGeoProc& dfTexEffect = gp.cast<GrDistanceFiel dA8TextGeoProc>(); |
188 const DistanceFieldBatchTracker& local = bt.cast<DistanceFieldBatchTrack er>(); | 186 const DistanceFieldBatchTracker& local = bt.cast<DistanceFieldBatchTrack er>(); |
189 uint32_t key = dfTexEffect.getFlags(); | 187 uint32_t key = dfTexEffect.getFlags(); |
190 key |= local.fInputColorType << 16; | 188 key |= local.fInputColorType << 16; |
191 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 << 24: 0x0; | 189 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 << 24: 0x0; |
192 key |= ComputePosKey(gp.viewMatrix()) << 25; | 190 key |= ComputePosKey(gp.viewMatrix()) << 25; |
193 key |= (!gp.viewMatrix().isIdentity() && !gp.localMatrix().isIdentity()) ? 0x1 << 27 : 0x0; | 191 key |= (!gp.viewMatrix().isIdentity() && !gp.localMatrix().isIdentity()) ? 0x1 << 27 : 0x0; |
194 b->add32(key); | 192 b->add32(key); |
195 } | 193 } |
196 | 194 |
197 private: | 195 private: |
198 GrColor fColor; | 196 GrColor fColor; |
199 UniformHandle fColorUniform; | 197 UniformHandle fColorUniform; |
200 #ifdef SK_GAMMA_APPLY_TO_A8 | 198 #ifdef SK_GAMMA_APPLY_TO_A8 |
201 float fDistanceAdjust; | 199 float fDistanceAdjust; |
202 UniformHandle fDistanceAdjustUni; | 200 UniformHandle fDistanceAdjustUni; |
203 #endif | 201 #endif |
204 | 202 |
205 typedef GrGLGeometryProcessor INHERITED; | 203 typedef GrGLGeometryProcessor INHERITED; |
206 }; | 204 }; |
207 | 205 |
208 /////////////////////////////////////////////////////////////////////////////// | 206 /////////////////////////////////////////////////////////////////////////////// |
209 | 207 |
210 GrDistanceFieldTextureEffect::GrDistanceFieldTextureEffect(GrColor color, | 208 GrDistanceFieldA8TextGeoProc::GrDistanceFieldA8TextGeoProc(GrColor color, |
211 const SkMatrix& viewM atrix, | 209 const SkMatrix& viewM atrix, |
212 const SkMatrix& local Matrix, | 210 const SkMatrix& local Matrix, |
213 GrTexture* texture, | 211 GrTexture* texture, |
214 const GrTextureParams & params, | 212 const GrTextureParams & params, |
215 #ifdef SK_GAMMA_APPLY_TO_A8 | 213 #ifdef SK_GAMMA_APPLY_TO_A8 |
216 float distanceAdjust, | 214 float distanceAdjust, |
217 #endif | 215 #endif |
218 uint32_t flags, bool opaqueVertexColors) | 216 uint32_t flags, bool opaqueVertexColors) |
219 : INHERITED(color, viewMatrix, localMatrix, opaqueVertexColors) | 217 : INHERITED(color, viewMatrix, localMatrix, opaqueVertexColors) |
220 , fTextureAccess(texture, params) | 218 , fTextureAccess(texture, params) |
221 #ifdef SK_GAMMA_APPLY_TO_A8 | 219 #ifdef SK_GAMMA_APPLY_TO_A8 |
222 , fDistanceAdjust(distanceAdjust) | 220 , fDistanceAdjust(distanceAdjust) |
223 #endif | 221 #endif |
224 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) | 222 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) |
225 , fInColor(NULL) { | 223 , fInColor(NULL) { |
226 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); | 224 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); |
227 this->initClassID<GrDistanceFieldTextureEffect>(); | 225 this->initClassID<GrDistanceFieldA8TextGeoProc>(); |
228 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType)); | 226 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType)); |
229 if (flags & kColorAttr_DistanceFieldEffectFlag) { | 227 if (flags & kColorAttr_DistanceFieldEffectFlag) { |
230 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA ttribType)); | 228 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA ttribType)); |
231 this->setHasVertexColor(); | 229 this->setHasVertexColor(); |
232 } | 230 } |
233 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 231 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
234 kVec2s_GrVertexAttribT ype)); | 232 kVec2s_GrVertexAttribT ype)); |
235 this->addTextureAccess(&fTextureAccess); | 233 this->addTextureAccess(&fTextureAccess); |
236 } | 234 } |
237 | 235 |
238 bool GrDistanceFieldTextureEffect::onIsEqual(const GrGeometryProcessor& other) c onst { | 236 bool GrDistanceFieldA8TextGeoProc::onIsEqual(const GrGeometryProcessor& other) c onst { |
239 const GrDistanceFieldTextureEffect& cte = other.cast<GrDistanceFieldTextureE ffect>(); | 237 const GrDistanceFieldA8TextGeoProc& cte = other.cast<GrDistanceFieldA8TextGe oProc>(); |
240 return | 238 return |
241 #ifdef SK_GAMMA_APPLY_TO_A8 | 239 #ifdef SK_GAMMA_APPLY_TO_A8 |
242 fDistanceAdjust == cte.fDistanceAdjust && | 240 fDistanceAdjust == cte.fDistanceAdjust && |
243 #endif | 241 #endif |
244 fFlags == cte.fFlags; | 242 fFlags == cte.fFlags; |
245 } | 243 } |
246 | 244 |
247 void GrDistanceFieldTextureEffect::onGetInvariantOutputCoverage(GrInitInvariantO utput* out) const { | 245 void GrDistanceFieldA8TextGeoProc::onGetInvariantOutputCoverage(GrInitInvariantO utput* out) const { |
248 out->setUnknownSingleComponent(); | 246 out->setUnknownSingleComponent(); |
249 } | 247 } |
250 | 248 |
251 void GrDistanceFieldTextureEffect::getGLProcessorKey(const GrBatchTracker& bt, | 249 void GrDistanceFieldA8TextGeoProc::getGLProcessorKey(const GrBatchTracker& bt, |
252 const GrGLCaps& caps, | 250 const GrGLCaps& caps, |
253 GrProcessorKeyBuilder* b) c onst { | 251 GrProcessorKeyBuilder* b) c onst { |
254 GrGLDistanceFieldTextureEffect::GenKey(*this, bt, caps, b); | 252 GrGLDistanceFieldA8TextGeoProc::GenKey(*this, bt, caps, b); |
255 } | 253 } |
256 | 254 |
257 GrGLPrimitiveProcessor* | 255 GrGLPrimitiveProcessor* |
258 GrDistanceFieldTextureEffect::createGLInstance(const GrBatchTracker& bt, | 256 GrDistanceFieldA8TextGeoProc::createGLInstance(const GrBatchTracker& bt, |
259 const GrGLCaps&) const { | 257 const GrGLCaps&) const { |
260 return SkNEW_ARGS(GrGLDistanceFieldTextureEffect, (*this, bt)); | 258 return SkNEW_ARGS(GrGLDistanceFieldA8TextGeoProc, (*this, bt)); |
261 } | 259 } |
262 | 260 |
263 void GrDistanceFieldTextureEffect::initBatchTracker(GrBatchTracker* bt, | 261 void GrDistanceFieldA8TextGeoProc::initBatchTracker(GrBatchTracker* bt, |
264 const GrPipelineInfo& init) const { | 262 const GrPipelineInfo& init) const { |
265 DistanceFieldBatchTracker* local = bt->cast<DistanceFieldBatchTracker>(); | 263 DistanceFieldBatchTracker* local = bt->cast<DistanceFieldBatchTracker>(); |
266 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in it, | 264 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in it, |
267 SkToBool(fInColor)); | 265 SkToBool(fInColor)); |
268 local->fUsesLocalCoords = init.fUsesLocalCoords; | 266 local->fUsesLocalCoords = init.fUsesLocalCoords; |
269 } | 267 } |
270 | 268 |
271 bool GrDistanceFieldTextureEffect::onCanMakeEqual(const GrBatchTracker& m, | 269 bool GrDistanceFieldA8TextGeoProc::onCanMakeEqual(const GrBatchTracker& m, |
272 const GrGeometryProcessor& tha t, | 270 const GrGeometryProcessor& tha t, |
273 const GrBatchTracker& t) const { | 271 const GrBatchTracker& t) const { |
274 const DistanceFieldBatchTracker& mine = m.cast<DistanceFieldBatchTracker>(); | 272 const DistanceFieldBatchTracker& mine = m.cast<DistanceFieldBatchTracker>(); |
275 const DistanceFieldBatchTracker& theirs = t.cast<DistanceFieldBatchTracker>( ); | 273 const DistanceFieldBatchTracker& theirs = t.cast<DistanceFieldBatchTracker>( ); |
276 return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, | 274 return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, |
277 that, theirs.fUsesLocalCoords) && | 275 that, theirs.fUsesLocalCoords) && |
278 CanCombineOutput(mine.fInputColorType, mine.fColor, | 276 CanCombineOutput(mine.fInputColorType, mine.fColor, |
279 theirs.fInputColorType, theirs.fColor); | 277 theirs.fInputColorType, theirs.fColor); |
280 } | 278 } |
281 | 279 |
282 /////////////////////////////////////////////////////////////////////////////// | 280 /////////////////////////////////////////////////////////////////////////////// |
283 | 281 |
284 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldTextureEffect); | 282 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldA8TextGeoProc); |
285 | 283 |
286 GrGeometryProcessor* GrDistanceFieldTextureEffect::TestCreate(SkRandom* random, | 284 GrGeometryProcessor* GrDistanceFieldA8TextGeoProc::TestCreate(SkRandom* random, |
287 GrContext*, | 285 GrContext*, |
288 const GrDrawTarget Caps&, | 286 const GrDrawTarget Caps&, |
289 GrTexture* texture s[]) { | 287 GrTexture* texture s[]) { |
290 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : | 288 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : |
291 GrProcessorUnitTest::kAlphaTextureIdx; | 289 GrProcessorUnitTest::kAlphaTextureIdx; |
292 static const SkShader::TileMode kTileModes[] = { | 290 static const SkShader::TileMode kTileModes[] = { |
293 SkShader::kClamp_TileMode, | 291 SkShader::kClamp_TileMode, |
294 SkShader::kRepeat_TileMode, | 292 SkShader::kRepeat_TileMode, |
295 SkShader::kMirror_TileMode, | 293 SkShader::kMirror_TileMode, |
296 }; | 294 }; |
297 SkShader::TileMode tileModes[] = { | 295 SkShader::TileMode tileModes[] = { |
298 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 296 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
299 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 297 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
300 }; | 298 }; |
301 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil erp_FilterMode : | 299 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil erp_FilterMode : |
302 GrTextureParams::kNon e_FilterMode); | 300 GrTextureParams::kNon e_FilterMode); |
303 | 301 |
304 return GrDistanceFieldTextureEffect::Create(GrRandomColor(random), | 302 return GrDistanceFieldA8TextGeoProc::Create(GrRandomColor(random), |
305 GrProcessorUnitTest::TestMatrix( random), | 303 GrProcessorUnitTest::TestMatrix( random), |
306 GrProcessorUnitTest::TestMatrix( random), | 304 GrProcessorUnitTest::TestMatrix( random), |
307 textures[texIdx], params, | 305 textures[texIdx], params, |
308 #ifdef SK_GAMMA_APPLY_TO_A8 | 306 #ifdef SK_GAMMA_APPLY_TO_A8 |
309 random->nextF(), | 307 random->nextF(), |
310 #endif | 308 #endif |
311 random->nextBool() ? | 309 random->nextBool() ? |
312 kSimilarity_DistanceFieldEff ectFlag : 0, | 310 kSimilarity_DistanceFieldEff ectFlag : 0, |
313 random->nextBool()); | 311 random->nextBool()); |
314 } | 312 } |
315 | 313 |
316 /////////////////////////////////////////////////////////////////////////////// | 314 /////////////////////////////////////////////////////////////////////////////// |
317 | 315 |
318 struct DistanceFieldNoGammaBatchTracker { | 316 struct DistanceFieldPathBatchTracker { |
319 GrGPInput fInputColorType; | 317 GrGPInput fInputColorType; |
320 GrColor fColor; | 318 GrColor fColor; |
321 bool fUsesLocalCoords; | 319 bool fUsesLocalCoords; |
322 }; | 320 }; |
323 | 321 |
324 class GrGLDistanceFieldNoGammaTextureEffect : public GrGLGeometryProcessor { | 322 class GrGLDistanceFieldPathGeoProc : public GrGLGeometryProcessor { |
325 public: | 323 public: |
326 GrGLDistanceFieldNoGammaTextureEffect(const GrGeometryProcessor&, | 324 GrGLDistanceFieldPathGeoProc(const GrGeometryProcessor&, |
327 const GrBatchTracker&) | 325 const GrBatchTracker&) |
328 : fColor(GrColor_ILLEGAL), fTextureSize(SkISize::Make(-1, -1)) {} | 326 : fColor(GrColor_ILLEGAL), fTextureSize(SkISize::Make(-1, -1)) {} |
329 | 327 |
330 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 328 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
331 const GrDistanceFieldNoGammaTextureEffect& dfTexEffect = | 329 const GrDistanceFieldPathGeoProc& dfTexEffect = args.fGP.cast<GrDistance FieldPathGeoProc>(); |
332 args.fGP.cast<GrDistanceFieldNoGammaTextureEffect>(); | |
333 | 330 |
334 const DistanceFieldNoGammaBatchTracker& local = | 331 const DistanceFieldPathBatchTracker& local = args.fBT.cast<DistanceField PathBatchTracker>(); |
335 args.fBT.cast<DistanceFieldNoGammaBatchTracker>(); | |
336 GrGLGPBuilder* pb = args.fPB; | 332 GrGLGPBuilder* pb = args.fPB; |
337 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 333 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
338 SkAssertResult(fsBuilder->enableFeature( | 334 SkAssertResult(fsBuilder->enableFeature( |
339 GrGLFragmentShaderBuilder::kStandardDerivat ives_GLSLFeature)); | 335 GrGLFragmentShaderBuilder::kStandardDerivat ives_GLSLFeature)); |
340 | 336 |
341 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 337 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
342 | 338 |
343 // emit attributes | 339 // emit attributes |
344 vsBuilder->emitAttributes(dfTexEffect); | 340 vsBuilder->emitAttributes(dfTexEffect); |
345 | 341 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 if (texture->width() != fTextureSize.width() || | 420 if (texture->width() != fTextureSize.width() || |
425 texture->height() != fTextureSize.height()) { | 421 texture->height() != fTextureSize.height()) { |
426 fTextureSize = SkISize::Make(texture->width(), texture->height()); | 422 fTextureSize = SkISize::Make(texture->width(), texture->height()); |
427 pdman.set2f(fTextureSizeUni, | 423 pdman.set2f(fTextureSizeUni, |
428 SkIntToScalar(fTextureSize.width()), | 424 SkIntToScalar(fTextureSize.width()), |
429 SkIntToScalar(fTextureSize.height())); | 425 SkIntToScalar(fTextureSize.height())); |
430 } | 426 } |
431 | 427 |
432 this->setUniformViewMatrix(pdman, proc.viewMatrix()); | 428 this->setUniformViewMatrix(pdman, proc.viewMatrix()); |
433 | 429 |
434 const DistanceFieldNoGammaBatchTracker& local = bt.cast<DistanceFieldNoG ammaBatchTracker>(); | 430 const DistanceFieldPathBatchTracker& local = bt.cast<DistanceFieldPathBa tchTracker>(); |
435 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo r) { | 431 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo r) { |
436 GrGLfloat c[4]; | 432 GrGLfloat c[4]; |
437 GrColorToRGBAFloat(local.fColor, c); | 433 GrColorToRGBAFloat(local.fColor, c); |
438 pdman.set4fv(fColorUniform, 1, c); | 434 pdman.set4fv(fColorUniform, 1, c); |
439 fColor = local.fColor; | 435 fColor = local.fColor; |
440 } | 436 } |
441 } | 437 } |
442 | 438 |
443 static inline void GenKey(const GrGeometryProcessor& gp, | 439 static inline void GenKey(const GrGeometryProcessor& gp, |
444 const GrBatchTracker& bt, | 440 const GrBatchTracker& bt, |
445 const GrGLCaps&, | 441 const GrGLCaps&, |
446 GrProcessorKeyBuilder* b) { | 442 GrProcessorKeyBuilder* b) { |
447 const GrDistanceFieldNoGammaTextureEffect& dfTexEffect = | 443 const GrDistanceFieldPathGeoProc& dfTexEffect = gp.cast<GrDistanceFieldP athGeoProc>(); |
448 gp.cast<GrDistanceFieldNoGammaTextureEffect>(); | |
449 | 444 |
450 const DistanceFieldNoGammaBatchTracker& local = bt.cast<DistanceFieldNoG ammaBatchTracker>(); | 445 const DistanceFieldPathBatchTracker& local = bt.cast<DistanceFieldPathBa tchTracker>(); |
451 uint32_t key = dfTexEffect.getFlags(); | 446 uint32_t key = dfTexEffect.getFlags(); |
452 key |= local.fInputColorType << 16; | 447 key |= local.fInputColorType << 16; |
453 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 << 24: 0x0; | 448 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 << 24: 0x0; |
454 key |= ComputePosKey(gp.viewMatrix()) << 25; | 449 key |= ComputePosKey(gp.viewMatrix()) << 25; |
455 b->add32(key); | 450 b->add32(key); |
456 } | 451 } |
457 | 452 |
458 private: | 453 private: |
459 UniformHandle fColorUniform; | 454 UniformHandle fColorUniform; |
460 UniformHandle fTextureSizeUni; | 455 UniformHandle fTextureSizeUni; |
461 GrColor fColor; | 456 GrColor fColor; |
462 SkISize fTextureSize; | 457 SkISize fTextureSize; |
463 | 458 |
464 typedef GrGLGeometryProcessor INHERITED; | 459 typedef GrGLGeometryProcessor INHERITED; |
465 }; | 460 }; |
466 | 461 |
467 /////////////////////////////////////////////////////////////////////////////// | 462 /////////////////////////////////////////////////////////////////////////////// |
468 | 463 |
469 GrDistanceFieldNoGammaTextureEffect::GrDistanceFieldNoGammaTextureEffect( | 464 GrDistanceFieldPathGeoProc::GrDistanceFieldPathGeoProc( |
470 GrColor color, | 465 GrColor color, |
471 const SkMatrix& viewMatrix, | 466 const SkMatrix& viewMatrix, |
472 GrTexture* texture, | 467 GrTexture* texture, |
473 const GrTextureParams& params, | 468 const GrTextureParams& params, |
474 uint32_t flags, | 469 uint32_t flags, |
475 bool opaqueVertexColors) | 470 bool opaqueVertexColors) |
476 : INHERITED(color, viewMatrix, SkMatrix::I(), opaqueVertexColors) | 471 : INHERITED(color, viewMatrix, SkMatrix::I(), opaqueVertexColors) |
477 , fTextureAccess(texture, params) | 472 , fTextureAccess(texture, params) |
478 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) | 473 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) |
479 , fInColor(NULL) { | 474 , fInColor(NULL) { |
480 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); | 475 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); |
481 this->initClassID<GrDistanceFieldNoGammaTextureEffect>(); | 476 this->initClassID<GrDistanceFieldPathGeoProc>(); |
482 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType)); | 477 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType)); |
483 if (flags & kColorAttr_DistanceFieldEffectFlag) { | 478 if (flags & kColorAttr_DistanceFieldEffectFlag) { |
484 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA ttribType)); | 479 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA ttribType)); |
485 this->setHasVertexColor(); | 480 this->setHasVertexColor(); |
486 } | 481 } |
487 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 482 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
488 kVec2f_GrVertexAttribT ype)); | 483 kVec2f_GrVertexAttribT ype)); |
489 this->addTextureAccess(&fTextureAccess); | 484 this->addTextureAccess(&fTextureAccess); |
490 } | 485 } |
491 | 486 |
492 bool GrDistanceFieldNoGammaTextureEffect::onIsEqual(const GrGeometryProcessor& o ther) const { | 487 bool GrDistanceFieldPathGeoProc::onIsEqual(const GrGeometryProcessor& other) con st { |
493 const GrDistanceFieldNoGammaTextureEffect& cte = | 488 const GrDistanceFieldPathGeoProc& cte = other.cast<GrDistanceFieldPathGeoPro c>(); |
494 other.cast<GrDistanceFieldNoGam maTextureEffect>(); | |
495 return fFlags == cte.fFlags; | 489 return fFlags == cte.fFlags; |
496 } | 490 } |
497 | 491 |
498 void GrDistanceFieldNoGammaTextureEffect::onGetInvariantOutputCoverage(GrInitInv ariantOutput* out) | 492 void GrDistanceFieldPathGeoProc::onGetInvariantOutputCoverage(GrInitInvariantOut put* out) const { |
499 const { | |
500 out->setUnknownSingleComponent(); | 493 out->setUnknownSingleComponent(); |
501 } | 494 } |
502 | 495 |
503 void GrDistanceFieldNoGammaTextureEffect::getGLProcessorKey(const GrBatchTracker & bt, | 496 void GrDistanceFieldPathGeoProc::getGLProcessorKey(const GrBatchTracker& bt, |
504 const GrGLCaps& caps , | 497 const GrGLCaps& caps, |
505 GrProcessorKeyBuilde r* b) const { | 498 GrProcessorKeyBuilder* b) con st { |
506 GrGLDistanceFieldNoGammaTextureEffect::GenKey(*this, bt, caps, b); | 499 GrGLDistanceFieldPathGeoProc::GenKey(*this, bt, caps, b); |
507 } | 500 } |
508 | 501 |
509 GrGLPrimitiveProcessor* | 502 GrGLPrimitiveProcessor* |
510 GrDistanceFieldNoGammaTextureEffect::createGLInstance(const GrBatchTracker& bt, | 503 GrDistanceFieldPathGeoProc::createGLInstance(const GrBatchTracker& bt, const GrG LCaps&) const { |
511 const GrGLCaps&) const { | 504 return SkNEW_ARGS(GrGLDistanceFieldPathGeoProc, (*this, bt)); |
512 return SkNEW_ARGS(GrGLDistanceFieldNoGammaTextureEffect, (*this, bt)); | |
513 } | 505 } |
514 | 506 |
515 void GrDistanceFieldNoGammaTextureEffect::initBatchTracker(GrBatchTracker* bt, | 507 void GrDistanceFieldPathGeoProc::initBatchTracker(GrBatchTracker* bt, |
516 const GrPipelineInfo& init) const { | 508 const GrPipelineInfo& init) co nst { |
517 DistanceFieldNoGammaBatchTracker* local = bt->cast<DistanceFieldNoGammaBatch Tracker>(); | 509 DistanceFieldPathBatchTracker* local = bt->cast<DistanceFieldPathBatchTracke r>(); |
518 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in it, | 510 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in it, |
519 SkToBool(fInColor)); | 511 SkToBool(fInColor)); |
520 local->fUsesLocalCoords = init.fUsesLocalCoords; | 512 local->fUsesLocalCoords = init.fUsesLocalCoords; |
521 } | 513 } |
522 | 514 |
523 bool GrDistanceFieldNoGammaTextureEffect::onCanMakeEqual(const GrBatchTracker& m , | 515 bool GrDistanceFieldPathGeoProc::onCanMakeEqual(const GrBatchTracker& m, |
524 const GrGeometryProcess or& that, | 516 const GrGeometryProcessor& that, |
525 const GrBatchTracker& t ) const { | 517 const GrBatchTracker& t) const { |
526 const DistanceFieldNoGammaBatchTracker& mine = m.cast<DistanceFieldNoGammaBa tchTracker>(); | 518 const DistanceFieldPathBatchTracker& mine = m.cast<DistanceFieldPathBatchTra cker>(); |
527 const DistanceFieldNoGammaBatchTracker& theirs = t.cast<DistanceFieldNoGamma BatchTracker>(); | 519 const DistanceFieldPathBatchTracker& theirs = t.cast<DistanceFieldPathBatchT racker>(); |
528 return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, | 520 return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, |
529 that, theirs.fUsesLocalCoords) && | 521 that, theirs.fUsesLocalCoords) && |
530 CanCombineOutput(mine.fInputColorType, mine.fColor, | 522 CanCombineOutput(mine.fInputColorType, mine.fColor, |
531 theirs.fInputColorType, theirs.fColor); | 523 theirs.fInputColorType, theirs.fColor); |
532 } | 524 } |
533 | 525 |
534 /////////////////////////////////////////////////////////////////////////////// | 526 /////////////////////////////////////////////////////////////////////////////// |
535 | 527 |
536 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldNoGammaTextureEffect); | 528 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldPathGeoProc); |
537 | 529 |
538 GrGeometryProcessor* GrDistanceFieldNoGammaTextureEffect::TestCreate(SkRandom* r andom, | 530 GrGeometryProcessor* GrDistanceFieldPathGeoProc::TestCreate(SkRandom* random, |
539 GrContext*, | 531 GrContext*, |
540 const GrDra wTargetCaps&, | 532 const GrDrawTargetCa ps&, |
541 GrTexture* textures[]) { | 533 GrTexture* textures[ ]) { |
542 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx | 534 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx |
543 : GrProcessorUnitTest::kAlphaTextureIdx; | 535 : GrProcessorUnitTest::kAlphaTextureIdx; |
544 static const SkShader::TileMode kTileModes[] = { | 536 static const SkShader::TileMode kTileModes[] = { |
545 SkShader::kClamp_TileMode, | 537 SkShader::kClamp_TileMode, |
546 SkShader::kRepeat_TileMode, | 538 SkShader::kRepeat_TileMode, |
547 SkShader::kMirror_TileMode, | 539 SkShader::kMirror_TileMode, |
548 }; | 540 }; |
549 SkShader::TileMode tileModes[] = { | 541 SkShader::TileMode tileModes[] = { |
550 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 542 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
551 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 543 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
552 }; | 544 }; |
553 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil erp_FilterMode | 545 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil erp_FilterMode |
554 : GrTextureParams::kNon e_FilterMode); | 546 : GrTextureParams::kNon e_FilterMode); |
555 | 547 |
556 return GrDistanceFieldNoGammaTextureEffect::Create(GrRandomColor(random), | 548 return GrDistanceFieldPathGeoProc::Create(GrRandomColor(random), |
557 GrProcessorUnitTest::Test Matrix(random), | 549 GrProcessorUnitTest::TestMatrix(ra ndom), |
558 textures[texIdx], | 550 textures[texIdx], |
559 params, | 551 params, |
560 random->nextBool() ? kSimilarity_DistanceFieldEffectFlag : 0, random->ne xtBool()); | 552 random->nextBool() ? kSimilarity_DistanceFieldEffectFlag : 0, random->ne xtBool()); |
561 } | 553 } |
562 | 554 |
563 /////////////////////////////////////////////////////////////////////////////// | 555 /////////////////////////////////////////////////////////////////////////////// |
564 | 556 |
565 struct DistanceFieldLCDBatchTracker { | 557 struct DistanceFieldLCDBatchTracker { |
566 GrGPInput fInputColorType; | 558 GrGPInput fInputColorType; |
567 GrColor fColor; | 559 GrColor fColor; |
568 bool fUsesLocalCoords; | 560 bool fUsesLocalCoords; |
569 }; | 561 }; |
570 | 562 |
571 class GrGLDistanceFieldLCDTextureEffect : public GrGLGeometryProcessor { | 563 class GrGLDistanceFieldLCDTextGeoProc : public GrGLGeometryProcessor { |
572 public: | 564 public: |
573 GrGLDistanceFieldLCDTextureEffect(const GrGeometryProcessor&, | 565 GrGLDistanceFieldLCDTextGeoProc(const GrGeometryProcessor&, const GrBatchTra cker&) |
574 const GrBatchTracker&) | |
575 : fColor(GrColor_ILLEGAL) { | 566 : fColor(GrColor_ILLEGAL) { |
576 fDistanceAdjust = GrDistanceFieldLCDTextureEffect::DistanceAdjust::Make( 1.0f, 1.0f, 1.0f); | 567 fDistanceAdjust = GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(1. 0f, 1.0f, 1.0f); |
577 } | 568 } |
578 | 569 |
579 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 570 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
580 const GrDistanceFieldLCDTextureEffect& dfTexEffect = | 571 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = |
581 args.fGP.cast<GrDistanceFieldLCDTextureEffect>(); | 572 args.fGP.cast<GrDistanceFieldLCDTextGeoProc>(); |
582 const DistanceFieldLCDBatchTracker& local = args.fBT.cast<DistanceFieldL CDBatchTracker>(); | 573 const DistanceFieldLCDBatchTracker& local = args.fBT.cast<DistanceFieldL CDBatchTracker>(); |
583 GrGLGPBuilder* pb = args.fPB; | 574 GrGLGPBuilder* pb = args.fPB; |
584 | 575 |
585 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 576 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
586 | 577 |
587 // emit attributes | 578 // emit attributes |
588 vsBuilder->emitAttributes(dfTexEffect); | 579 vsBuilder->emitAttributes(dfTexEffect); |
589 | 580 |
590 // setup pass through color | 581 // setup pass through color |
591 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor , NULL, | 582 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor , NULL, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
722 "vec4 val = vec4(smoothstep(vec3(-afwidth), vec3(afwidth), distance), 1.0);"); | 713 "vec4 val = vec4(smoothstep(vec3(-afwidth), vec3(afwidth), distance), 1.0);"); |
723 | 714 |
724 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); | 715 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); |
725 } | 716 } |
726 | 717 |
727 virtual void setData(const GrGLProgramDataManager& pdman, | 718 virtual void setData(const GrGLProgramDataManager& pdman, |
728 const GrPrimitiveProcessor& processor, | 719 const GrPrimitiveProcessor& processor, |
729 const GrBatchTracker& bt) override { | 720 const GrBatchTracker& bt) override { |
730 SkASSERT(fDistanceAdjustUni.isValid()); | 721 SkASSERT(fDistanceAdjustUni.isValid()); |
731 | 722 |
732 const GrDistanceFieldLCDTextureEffect& dfTexEffect = | 723 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = |
733 processor.cast<GrDistanceFieldLCDTextureEffect>(); | 724 processor.cast<GrDistanceFieldLCDTextGeoProc>(); |
734 GrDistanceFieldLCDTextureEffect::DistanceAdjust wa = dfTexEffect.getDist anceAdjust(); | 725 GrDistanceFieldLCDTextGeoProc::DistanceAdjust wa = dfTexEffect.getDistan ceAdjust(); |
735 if (wa != fDistanceAdjust) { | 726 if (wa != fDistanceAdjust) { |
736 pdman.set3f(fDistanceAdjustUni, | 727 pdman.set3f(fDistanceAdjustUni, |
737 wa.fR, | 728 wa.fR, |
738 wa.fG, | 729 wa.fG, |
739 wa.fB); | 730 wa.fB); |
740 fDistanceAdjust = wa; | 731 fDistanceAdjust = wa; |
741 } | 732 } |
742 | 733 |
743 this->setUniformViewMatrix(pdman, processor.viewMatrix()); | 734 this->setUniformViewMatrix(pdman, processor.viewMatrix()); |
744 | 735 |
745 const DistanceFieldLCDBatchTracker& local = bt.cast<DistanceFieldLCDBatc hTracker>(); | 736 const DistanceFieldLCDBatchTracker& local = bt.cast<DistanceFieldLCDBatc hTracker>(); |
746 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo r) { | 737 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo r) { |
747 GrGLfloat c[4]; | 738 GrGLfloat c[4]; |
748 GrColorToRGBAFloat(local.fColor, c); | 739 GrColorToRGBAFloat(local.fColor, c); |
749 pdman.set4fv(fColorUniform, 1, c); | 740 pdman.set4fv(fColorUniform, 1, c); |
750 fColor = local.fColor; | 741 fColor = local.fColor; |
751 } | 742 } |
752 } | 743 } |
753 | 744 |
754 static inline void GenKey(const GrGeometryProcessor& gp, | 745 static inline void GenKey(const GrGeometryProcessor& gp, |
755 const GrBatchTracker& bt, | 746 const GrBatchTracker& bt, |
756 const GrGLCaps&, | 747 const GrGLCaps&, |
757 GrProcessorKeyBuilder* b) { | 748 GrProcessorKeyBuilder* b) { |
758 const GrDistanceFieldLCDTextureEffect& dfTexEffect = | 749 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = gp.cast<GrDistanceFie ldLCDTextGeoProc>(); |
759 gp.cast<GrDistanceFieldLCDTextureEffect>(); | |
760 | 750 |
761 const DistanceFieldLCDBatchTracker& local = bt.cast<DistanceFieldLCDBatc hTracker>(); | 751 const DistanceFieldLCDBatchTracker& local = bt.cast<DistanceFieldLCDBatc hTracker>(); |
762 uint32_t key = dfTexEffect.getFlags(); | 752 uint32_t key = dfTexEffect.getFlags(); |
763 key |= local.fInputColorType << 16; | 753 key |= local.fInputColorType << 16; |
764 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 << 24: 0x0; | 754 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 << 24: 0x0; |
765 key |= ComputePosKey(gp.viewMatrix()) << 25; | 755 key |= ComputePosKey(gp.viewMatrix()) << 25; |
766 key |= (!gp.viewMatrix().isIdentity() && !gp.localMatrix().isIdentity()) ? 0x1 << 27 : 0x0; | 756 key |= (!gp.viewMatrix().isIdentity() && !gp.localMatrix().isIdentity()) ? 0x1 << 27 : 0x0; |
767 b->add32(key); | 757 b->add32(key); |
768 } | 758 } |
769 | 759 |
770 private: | 760 private: |
771 GrColor fColor; | 761 GrColor fColor; |
772 UniformHandle fColorUniform; | 762 UniformHandle fColorUniform; |
773 GrDistanceFieldLCDTextureEffect::DistanceAdjust fDistanceAdjust; | 763 GrDistanceFieldLCDTextGeoProc::DistanceAdjust fDistanceAdjust; |
774 UniformHandle fDistanceAdjustUni; | 764 UniformHandle fDistanceAdjustUni; |
775 | 765 |
776 typedef GrGLGeometryProcessor INHERITED; | 766 typedef GrGLGeometryProcessor INHERITED; |
777 }; | 767 }; |
778 | 768 |
779 /////////////////////////////////////////////////////////////////////////////// | 769 /////////////////////////////////////////////////////////////////////////////// |
780 | 770 |
781 GrDistanceFieldLCDTextureEffect::GrDistanceFieldLCDTextureEffect( | 771 GrDistanceFieldLCDTextGeoProc::GrDistanceFieldLCDTextGeoProc( |
782 GrColor color, const SkMatrix& viewMatrix, | 772 GrColor color, const SkMatrix& viewMatrix, |
783 const SkMatrix& localMatrix, | 773 const SkMatrix& localMatrix, |
784 GrTexture* texture, const GrTe xtureParams& params, | 774 GrTexture* texture, const GrTe xtureParams& params, |
785 DistanceAdjust distanceAdjust, | 775 DistanceAdjust distanceAdjust, |
786 uint32_t flags) | 776 uint32_t flags) |
787 : INHERITED(color, viewMatrix, localMatrix) | 777 : INHERITED(color, viewMatrix, localMatrix) |
788 , fTextureAccess(texture, params) | 778 , fTextureAccess(texture, params) |
789 , fDistanceAdjust(distanceAdjust) | 779 , fDistanceAdjust(distanceAdjust) |
790 , fFlags(flags & kLCD_DistanceFieldEffectMask){ | 780 , fFlags(flags & kLCD_DistanceFieldEffectMask){ |
791 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan ceFieldEffectFlag)); | 781 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan ceFieldEffectFlag)); |
792 this->initClassID<GrDistanceFieldLCDTextureEffect>(); | 782 this->initClassID<GrDistanceFieldLCDTextGeoProc>(); |
793 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType)); | 783 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType)); |
794 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 784 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
795 kVec2s_GrVertexAttribT ype)); | 785 kVec2s_GrVertexAttribT ype)); |
796 this->addTextureAccess(&fTextureAccess); | 786 this->addTextureAccess(&fTextureAccess); |
797 } | 787 } |
798 | 788 |
799 bool GrDistanceFieldLCDTextureEffect::onIsEqual(const GrGeometryProcessor& other ) const { | 789 bool GrDistanceFieldLCDTextGeoProc::onIsEqual(const GrGeometryProcessor& other) const { |
800 const GrDistanceFieldLCDTextureEffect& cte = other.cast<GrDistanceFieldLCDTe xtureEffect>(); | 790 const GrDistanceFieldLCDTextGeoProc& cte = other.cast<GrDistanceFieldLCDText GeoProc>(); |
801 return (fDistanceAdjust == cte.fDistanceAdjust && | 791 return (fDistanceAdjust == cte.fDistanceAdjust && |
802 fFlags == cte.fFlags); | 792 fFlags == cte.fFlags); |
803 } | 793 } |
804 | 794 |
805 void GrDistanceFieldLCDTextureEffect::onGetInvariantOutputCoverage(GrInitInvaria ntOutput* out) | 795 void GrDistanceFieldLCDTextGeoProc::onGetInvariantOutputCoverage(GrInitInvariant Output* out) const { |
806 const { | |
807 out->setUnknownFourComponents(); | 796 out->setUnknownFourComponents(); |
808 out->setUsingLCDCoverage(); | 797 out->setUsingLCDCoverage(); |
809 } | 798 } |
810 | 799 |
811 void GrDistanceFieldLCDTextureEffect::getGLProcessorKey(const GrBatchTracker& bt , | 800 void GrDistanceFieldLCDTextGeoProc::getGLProcessorKey(const GrBatchTracker& bt, |
812 const GrGLCaps& caps, | 801 const GrGLCaps& caps, |
813 GrProcessorKeyBuilder* b ) const { | 802 GrProcessorKeyBuilder* b) const { |
814 GrGLDistanceFieldLCDTextureEffect::GenKey(*this, bt, caps, b); | 803 GrGLDistanceFieldLCDTextGeoProc::GenKey(*this, bt, caps, b); |
815 } | 804 } |
816 | 805 |
817 GrGLPrimitiveProcessor* | 806 GrGLPrimitiveProcessor* |
818 GrDistanceFieldLCDTextureEffect::createGLInstance(const GrBatchTracker& bt, | 807 GrDistanceFieldLCDTextGeoProc::createGLInstance(const GrBatchTracker& bt, |
819 const GrGLCaps&) const { | 808 const GrGLCaps&) const { |
820 return SkNEW_ARGS(GrGLDistanceFieldLCDTextureEffect, (*this, bt)); | 809 return SkNEW_ARGS(GrGLDistanceFieldLCDTextGeoProc, (*this, bt)); |
821 } | 810 } |
822 | 811 |
823 void GrDistanceFieldLCDTextureEffect::initBatchTracker(GrBatchTracker* bt, | 812 void GrDistanceFieldLCDTextGeoProc::initBatchTracker(GrBatchTracker* bt, |
824 const GrPipelineInfo& ini t) const { | 813 const GrPipelineInfo& init) const { |
825 DistanceFieldLCDBatchTracker* local = bt->cast<DistanceFieldLCDBatchTracker> (); | 814 DistanceFieldLCDBatchTracker* local = bt->cast<DistanceFieldLCDBatchTracker> (); |
826 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in it, false); | 815 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in it, false); |
827 local->fUsesLocalCoords = init.fUsesLocalCoords; | 816 local->fUsesLocalCoords = init.fUsesLocalCoords; |
828 } | 817 } |
829 | 818 |
830 bool GrDistanceFieldLCDTextureEffect::onCanMakeEqual(const GrBatchTracker& m, | 819 bool GrDistanceFieldLCDTextGeoProc::onCanMakeEqual(const GrBatchTracker& m, |
831 const GrGeometryProcessor& that, | 820 const GrGeometryProcessor& th at, |
832 const GrBatchTracker& t) co nst { | 821 const GrBatchTracker& t) cons t { |
833 const DistanceFieldLCDBatchTracker& mine = m.cast<DistanceFieldLCDBatchTrack er>(); | 822 const DistanceFieldLCDBatchTracker& mine = m.cast<DistanceFieldLCDBatchTrack er>(); |
834 const DistanceFieldLCDBatchTracker& theirs = t.cast<DistanceFieldLCDBatchTra cker>(); | 823 const DistanceFieldLCDBatchTracker& theirs = t.cast<DistanceFieldLCDBatchTra cker>(); |
835 return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, | 824 return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, |
836 that, theirs.fUsesLocalCoords) && | 825 that, theirs.fUsesLocalCoords) && |
837 CanCombineOutput(mine.fInputColorType, mine.fColor, | 826 CanCombineOutput(mine.fInputColorType, mine.fColor, |
838 theirs.fInputColorType, theirs.fColor); | 827 theirs.fInputColorType, theirs.fColor); |
839 } | 828 } |
840 | 829 |
841 /////////////////////////////////////////////////////////////////////////////// | 830 /////////////////////////////////////////////////////////////////////////////// |
842 | 831 |
843 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldLCDTextureEffect); | 832 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldLCDTextGeoProc); |
844 | 833 |
845 GrGeometryProcessor* GrDistanceFieldLCDTextureEffect::TestCreate(SkRandom* rando m, | 834 GrGeometryProcessor* GrDistanceFieldLCDTextGeoProc::TestCreate(SkRandom* random, |
846 GrContext*, | 835 GrContext*, |
847 const GrDrawTar getCaps&, | 836 const GrDrawTar getCaps&, |
848 GrTexture* text ures[]) { | 837 GrTexture* text ures[]) { |
849 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : | 838 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : |
850 GrProcessorUnitTest::kAlphaTextureIdx; | 839 GrProcessorUnitTest::kAlphaTextureIdx; |
851 static const SkShader::TileMode kTileModes[] = { | 840 static const SkShader::TileMode kTileModes[] = { |
852 SkShader::kClamp_TileMode, | 841 SkShader::kClamp_TileMode, |
853 SkShader::kRepeat_TileMode, | 842 SkShader::kRepeat_TileMode, |
854 SkShader::kMirror_TileMode, | 843 SkShader::kMirror_TileMode, |
855 }; | 844 }; |
856 SkShader::TileMode tileModes[] = { | 845 SkShader::TileMode tileModes[] = { |
857 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 846 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
858 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 847 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
859 }; | 848 }; |
860 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil erp_FilterMode : | 849 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil erp_FilterMode : |
861 GrTextureParams::kNone_FilterMode); | 850 GrTextureParams::kNone_FilterMode); |
862 DistanceAdjust wa = { 0.0f, 0.1f, -0.1f }; | 851 DistanceAdjust wa = { 0.0f, 0.1f, -0.1f }; |
863 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; | 852 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; |
864 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; | 853 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; |
865 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 854 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; |
866 return GrDistanceFieldLCDTextureEffect::Create(GrRandomColor(random), | 855 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(random), |
867 GrProcessorUnitTest::TestMatr ix(random), | 856 GrProcessorUnitTest::TestMatrix (random), |
868 GrProcessorUnitTest::TestMatr ix(random), | 857 GrProcessorUnitTest::TestMatrix (random), |
869 textures[texIdx], params, | 858 textures[texIdx], params, |
870 wa, | 859 wa, |
871 flags); | 860 flags); |
872 } | 861 } |
OLD | NEW |