Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: src/gpu/effects/GrDistanceFieldTextureEffect.cpp

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

Powered by Google App Engine
This is Rietveld 408576698