| 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 "GrDistanceFieldGeoProc.h" | 8 #include "GrDistanceFieldGeoProc.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 { |
| 25 GrGPInput fInputColorType; |
| 26 GrColor fColor; |
| 27 bool fUsesLocalCoords; |
| 28 }; |
| 29 |
| 24 class GrGLDistanceFieldA8TextGeoProc : public GrGLGeometryProcessor { | 30 class GrGLDistanceFieldA8TextGeoProc : public GrGLGeometryProcessor { |
| 25 public: | 31 public: |
| 26 GrGLDistanceFieldA8TextGeoProc(const GrGeometryProcessor&, | 32 GrGLDistanceFieldA8TextGeoProc(const GrGeometryProcessor&, |
| 27 const GrBatchTracker&) | 33 const GrBatchTracker&) |
| 28 : fColor(GrColor_ILLEGAL) | 34 : fColor(GrColor_ILLEGAL) |
| 29 #ifdef SK_GAMMA_APPLY_TO_A8 | 35 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 30 , fDistanceAdjust(-1.0f) | 36 , fDistanceAdjust(-1.0f) |
| 31 #endif | 37 #endif |
| 32 {} | 38 {} |
| 33 | 39 |
| 34 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 40 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
| 35 const GrDistanceFieldA8TextGeoProc& dfTexEffect = | 41 const GrDistanceFieldA8TextGeoProc& dfTexEffect = |
| 36 args.fGP.cast<GrDistanceFieldA8TextGeoProc>(); | 42 args.fGP.cast<GrDistanceFieldA8TextGeoProc>(); |
| 43 const DistanceFieldBatchTracker& local = args.fBT.cast<DistanceFieldBatc
hTracker>(); |
| 37 GrGLGPBuilder* pb = args.fPB; | 44 GrGLGPBuilder* pb = args.fPB; |
| 38 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 45 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 39 SkAssertResult(fsBuilder->enableFeature( | 46 SkAssertResult(fsBuilder->enableFeature( |
| 40 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); | 47 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
| 41 | 48 |
| 42 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 49 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 43 | 50 |
| 44 // emit attributes | 51 // emit attributes |
| 45 vsBuilder->emitAttributes(dfTexEffect); | 52 vsBuilder->emitAttributes(dfTexEffect); |
| 46 | 53 |
| 47 #ifdef SK_GAMMA_APPLY_TO_A8 | 54 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 48 // adjust based on gamma | 55 // adjust based on gamma |
| 49 const char* distanceAdjustUniName = NULL; | 56 const char* distanceAdjustUniName = NULL; |
| 50 // width, height, 1/(3*width) | 57 // width, height, 1/(3*width) |
| 51 fDistanceAdjustUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_
Visibility, | 58 fDistanceAdjustUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_
Visibility, |
| 52 kFloat_GrSLType, kDefault_GrSLPrecision, | 59 kFloat_GrSLType, kDefault_GrSLPrecision, |
| 53 "DistanceAdjust", &distanceAdjustUniName); | 60 "DistanceAdjust", &distanceAdjustUniName); |
| 54 #endif | 61 #endif |
| 55 | 62 |
| 56 // Setup pass through color | 63 // Setup pass through color |
| 57 if (!dfTexEffect.colorIgnored()) { | 64 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor
, |
| 58 if (dfTexEffect.hasVertexColor()) { | 65 dfTexEffect.inColor(), &fColorUniform); |
| 59 pb->addPassThroughAttribute(dfTexEffect.inColor(), args.fOutputC
olor); | |
| 60 } else { | |
| 61 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); | |
| 62 } | |
| 63 } | |
| 64 | 66 |
| 65 // Setup position | 67 // Setup position |
| 66 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix()); | 68 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix()); |
| 67 | 69 |
| 68 // emit transforms | 70 // emit transforms |
| 69 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, | 71 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, |
| 70 args.fTransformsIn, args.fTransformsOut); | 72 args.fTransformsIn, args.fTransformsOut); |
| 71 | 73 |
| 72 // add varyings | 74 // add varyings |
| 73 GrGLVertToFrag recipScale(kFloat_GrSLType); | 75 GrGLVertToFrag recipScale(kFloat_GrSLType); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 float distanceAdjust = dfTexEffect.getDistanceAdjust(); | 147 float distanceAdjust = dfTexEffect.getDistanceAdjust(); |
| 146 if (distanceAdjust != fDistanceAdjust) { | 148 if (distanceAdjust != fDistanceAdjust) { |
| 147 pdman.set1f(fDistanceAdjustUni, distanceAdjust); | 149 pdman.set1f(fDistanceAdjustUni, distanceAdjust); |
| 148 fDistanceAdjust = distanceAdjust; | 150 fDistanceAdjust = distanceAdjust; |
| 149 } | 151 } |
| 150 #endif | 152 #endif |
| 151 | 153 |
| 152 const GrDistanceFieldA8TextGeoProc& dfa8gp = proc.cast<GrDistanceFieldA8
TextGeoProc>(); | 154 const GrDistanceFieldA8TextGeoProc& dfa8gp = proc.cast<GrDistanceFieldA8
TextGeoProc>(); |
| 153 this->setUniformViewMatrix(pdman, dfa8gp.viewMatrix()); | 155 this->setUniformViewMatrix(pdman, dfa8gp.viewMatrix()); |
| 154 | 156 |
| 155 if (dfa8gp.color() != fColor && !dfa8gp.hasVertexColor()) { | 157 const DistanceFieldBatchTracker& local = bt.cast<DistanceFieldBatchTrack
er>(); |
| 158 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
| 156 GrGLfloat c[4]; | 159 GrGLfloat c[4]; |
| 157 GrColorToRGBAFloat(dfa8gp.color(), c); | 160 GrColorToRGBAFloat(local.fColor, c); |
| 158 pdman.set4fv(fColorUniform, 1, c); | 161 pdman.set4fv(fColorUniform, 1, c); |
| 159 fColor = dfa8gp.color(); | 162 fColor = local.fColor; |
| 160 } | 163 } |
| 161 } | 164 } |
| 162 | 165 |
| 163 static inline void GenKey(const GrGeometryProcessor& gp, | 166 static inline void GenKey(const GrGeometryProcessor& gp, |
| 164 const GrBatchTracker& bt, | 167 const GrBatchTracker& bt, |
| 165 const GrGLSLCaps&, | 168 const GrGLSLCaps&, |
| 166 GrProcessorKeyBuilder* b) { | 169 GrProcessorKeyBuilder* b) { |
| 167 const GrDistanceFieldA8TextGeoProc& dfTexEffect = gp.cast<GrDistanceFiel
dA8TextGeoProc>(); | 170 const GrDistanceFieldA8TextGeoProc& dfTexEffect = gp.cast<GrDistanceFiel
dA8TextGeoProc>(); |
| 171 const DistanceFieldBatchTracker& local = bt.cast<DistanceFieldBatchTrack
er>(); |
| 168 uint32_t key = dfTexEffect.getFlags(); | 172 uint32_t key = dfTexEffect.getFlags(); |
| 169 key |= dfTexEffect.hasVertexColor() << 16; | 173 key |= local.fInputColorType << 16; |
| 170 key |= dfTexEffect.colorIgnored() << 17; | |
| 171 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; | 174 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
| 172 b->add32(key); | 175 b->add32(key); |
| 173 } | 176 } |
| 174 | 177 |
| 175 private: | 178 private: |
| 176 GrColor fColor; | 179 GrColor fColor; |
| 177 UniformHandle fColorUniform; | 180 UniformHandle fColorUniform; |
| 178 #ifdef SK_GAMMA_APPLY_TO_A8 | 181 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 179 float fDistanceAdjust; | 182 float fDistanceAdjust; |
| 180 UniformHandle fDistanceAdjustUni; | 183 UniformHandle fDistanceAdjustUni; |
| 181 #endif | 184 #endif |
| 182 | 185 |
| 183 typedef GrGLGeometryProcessor INHERITED; | 186 typedef GrGLGeometryProcessor INHERITED; |
| 184 }; | 187 }; |
| 185 | 188 |
| 186 /////////////////////////////////////////////////////////////////////////////// | 189 /////////////////////////////////////////////////////////////////////////////// |
| 187 | 190 |
| 188 GrDistanceFieldA8TextGeoProc::GrDistanceFieldA8TextGeoProc(GrColor color, | 191 GrDistanceFieldA8TextGeoProc::GrDistanceFieldA8TextGeoProc(GrColor color, |
| 189 const SkMatrix& viewM
atrix, | 192 const SkMatrix& viewM
atrix, |
| 190 GrTexture* texture, | 193 GrTexture* texture, |
| 191 const GrTextureParams
& params, | 194 const GrTextureParams
& params, |
| 192 #ifdef SK_GAMMA_APPLY_TO_A8 | 195 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 193 float distanceAdjust, | 196 float distanceAdjust, |
| 194 #endif | 197 #endif |
| 195 uint32_t flags, | 198 uint32_t flags) |
| 196 bool usesLocalCoords) | |
| 197 : fColor(color) | 199 : fColor(color) |
| 198 , fViewMatrix(viewMatrix) | 200 , fViewMatrix(viewMatrix) |
| 199 , fTextureAccess(texture, params) | 201 , fTextureAccess(texture, params) |
| 200 #ifdef SK_GAMMA_APPLY_TO_A8 | 202 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 201 , fDistanceAdjust(distanceAdjust) | 203 , fDistanceAdjust(distanceAdjust) |
| 202 #endif | 204 #endif |
| 203 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) | 205 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) |
| 204 , fInColor(NULL) | 206 , fInColor(NULL) { |
| 205 , fUsesLocalCoords(usesLocalCoords) { | |
| 206 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); | 207 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); |
| 207 this->initClassID<GrDistanceFieldA8TextGeoProc>(); | 208 this->initClassID<GrDistanceFieldA8TextGeoProc>(); |
| 208 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); | 209 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); |
| 209 if (flags & kColorAttr_DistanceFieldEffectFlag) { | 210 if (flags & kColorAttr_DistanceFieldEffectFlag) { |
| 210 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); | 211 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); |
| 211 } | 212 } |
| 212 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 213 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
| 213 kVec2s_GrVertexAttribT
ype)); | 214 kVec2s_GrVertexAttribT
ype)); |
| 214 this->addTextureAccess(&fTextureAccess); | 215 this->addTextureAccess(&fTextureAccess); |
| 215 } | 216 } |
| 216 | 217 |
| 217 void GrDistanceFieldA8TextGeoProc::getGLProcessorKey(const GrBatchTracker& bt, | 218 void GrDistanceFieldA8TextGeoProc::getGLProcessorKey(const GrBatchTracker& bt, |
| 218 const GrGLSLCaps& caps, | 219 const GrGLSLCaps& caps, |
| 219 GrProcessorKeyBuilder* b) c
onst { | 220 GrProcessorKeyBuilder* b) c
onst { |
| 220 GrGLDistanceFieldA8TextGeoProc::GenKey(*this, bt, caps, b); | 221 GrGLDistanceFieldA8TextGeoProc::GenKey(*this, bt, caps, b); |
| 221 } | 222 } |
| 222 | 223 |
| 223 GrGLPrimitiveProcessor* | 224 GrGLPrimitiveProcessor* |
| 224 GrDistanceFieldA8TextGeoProc::createGLInstance(const GrBatchTracker& bt, | 225 GrDistanceFieldA8TextGeoProc::createGLInstance(const GrBatchTracker& bt, |
| 225 const GrGLSLCaps&) const { | 226 const GrGLSLCaps&) const { |
| 226 return SkNEW_ARGS(GrGLDistanceFieldA8TextGeoProc, (*this, bt)); | 227 return SkNEW_ARGS(GrGLDistanceFieldA8TextGeoProc, (*this, bt)); |
| 227 } | 228 } |
| 228 | 229 |
| 230 void GrDistanceFieldA8TextGeoProc::initBatchTracker(GrBatchTracker* bt, |
| 231 const GrPipelineInfo& init)
const { |
| 232 DistanceFieldBatchTracker* local = bt->cast<DistanceFieldBatchTracker>(); |
| 233 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, |
| 234 SkToBool(fInColor)); |
| 235 local->fUsesLocalCoords = init.fUsesLocalCoords; |
| 236 } |
| 237 |
| 229 /////////////////////////////////////////////////////////////////////////////// | 238 /////////////////////////////////////////////////////////////////////////////// |
| 230 | 239 |
| 231 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldA8TextGeoProc); | 240 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldA8TextGeoProc); |
| 232 | 241 |
| 233 GrGeometryProcessor* GrDistanceFieldA8TextGeoProc::TestCreate(SkRandom* random, | 242 GrGeometryProcessor* GrDistanceFieldA8TextGeoProc::TestCreate(SkRandom* random, |
| 234 GrContext*, | 243 GrContext*, |
| 235 const GrDrawTarget
Caps&, | 244 const GrDrawTarget
Caps&, |
| 236 GrTexture* texture
s[]) { | 245 GrTexture* texture
s[]) { |
| 237 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : | 246 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : |
| 238 GrProcessorUnitTest::kAlphaTextureIdx; | 247 GrProcessorUnitTest::kAlphaTextureIdx; |
| 239 static const SkShader::TileMode kTileModes[] = { | 248 static const SkShader::TileMode kTileModes[] = { |
| 240 SkShader::kClamp_TileMode, | 249 SkShader::kClamp_TileMode, |
| 241 SkShader::kRepeat_TileMode, | 250 SkShader::kRepeat_TileMode, |
| 242 SkShader::kMirror_TileMode, | 251 SkShader::kMirror_TileMode, |
| 243 }; | 252 }; |
| 244 SkShader::TileMode tileModes[] = { | 253 SkShader::TileMode tileModes[] = { |
| 245 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 254 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 246 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 255 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 247 }; | 256 }; |
| 248 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : | 257 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : |
| 249 GrTextureParams::kNon
e_FilterMode); | 258 GrTextureParams::kNon
e_FilterMode); |
| 250 | 259 |
| 251 return GrDistanceFieldA8TextGeoProc::Create(GrRandomColor(random), | 260 return GrDistanceFieldA8TextGeoProc::Create(GrRandomColor(random), |
| 252 GrTest::TestMatrix(random), | 261 GrTest::TestMatrix(random), |
| 253 textures[texIdx], params, | 262 textures[texIdx], params, |
| 254 #ifdef SK_GAMMA_APPLY_TO_A8 | 263 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 255 random->nextF(), | 264 random->nextF(), |
| 256 #endif | 265 #endif |
| 257 random->nextBool() ? | 266 random->nextBool() ? |
| 258 kSimilarity_DistanceFieldEff
ectFlag : 0, | 267 kSimilarity_DistanceFieldEff
ectFlag : 0); |
| 259 random->nextBool()); | |
| 260 } | 268 } |
| 261 | 269 |
| 262 /////////////////////////////////////////////////////////////////////////////// | 270 /////////////////////////////////////////////////////////////////////////////// |
| 263 | 271 |
| 272 struct DistanceFieldPathBatchTracker { |
| 273 GrGPInput fInputColorType; |
| 274 GrColor fColor; |
| 275 bool fUsesLocalCoords; |
| 276 }; |
| 277 |
| 264 class GrGLDistanceFieldPathGeoProc : public GrGLGeometryProcessor { | 278 class GrGLDistanceFieldPathGeoProc : public GrGLGeometryProcessor { |
| 265 public: | 279 public: |
| 266 GrGLDistanceFieldPathGeoProc(const GrGeometryProcessor&, | 280 GrGLDistanceFieldPathGeoProc(const GrGeometryProcessor&, |
| 267 const GrBatchTracker&) | 281 const GrBatchTracker&) |
| 268 : fColor(GrColor_ILLEGAL), fTextureSize(SkISize::Make(-1, -1)) {} | 282 : fColor(GrColor_ILLEGAL), fTextureSize(SkISize::Make(-1, -1)) {} |
| 269 | 283 |
| 270 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 284 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
| 271 const GrDistanceFieldPathGeoProc& dfTexEffect = args.fGP.cast<GrDistance
FieldPathGeoProc>(); | 285 const GrDistanceFieldPathGeoProc& dfTexEffect = args.fGP.cast<GrDistance
FieldPathGeoProc>(); |
| 272 | 286 |
| 287 const DistanceFieldPathBatchTracker& local = args.fBT.cast<DistanceField
PathBatchTracker>(); |
| 273 GrGLGPBuilder* pb = args.fPB; | 288 GrGLGPBuilder* pb = args.fPB; |
| 274 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 289 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 275 SkAssertResult(fsBuilder->enableFeature( | 290 SkAssertResult(fsBuilder->enableFeature( |
| 276 GrGLFragmentShaderBuilder::kStandardDerivat
ives_GLSLFeature)); | 291 GrGLFragmentShaderBuilder::kStandardDerivat
ives_GLSLFeature)); |
| 277 | 292 |
| 278 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 293 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 279 | 294 |
| 280 // emit attributes | 295 // emit attributes |
| 281 vsBuilder->emitAttributes(dfTexEffect); | 296 vsBuilder->emitAttributes(dfTexEffect); |
| 282 | 297 |
| 283 GrGLVertToFrag v(kVec2f_GrSLType); | 298 GrGLVertToFrag v(kVec2f_GrSLType); |
| 284 args.fPB->addVarying("TextureCoords", &v, kHigh_GrSLPrecision); | 299 args.fPB->addVarying("TextureCoords", &v, kHigh_GrSLPrecision); |
| 285 | 300 |
| 286 // setup pass through color | 301 // setup pass through color |
| 287 if (!dfTexEffect.colorIgnored()) { | 302 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor
, |
| 288 if (dfTexEffect.hasVertexColor()) { | 303 dfTexEffect.inColor(), &fColorUniform); |
| 289 pb->addPassThroughAttribute(dfTexEffect.inColor(), args.fOutputC
olor); | 304 |
| 290 } else { | |
| 291 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); | |
| 292 } | |
| 293 } | |
| 294 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoord
s()->fName); | 305 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoord
s()->fName); |
| 295 | 306 |
| 296 // Setup position | 307 // Setup position |
| 297 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix()); | 308 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix()); |
| 298 | 309 |
| 299 // emit transforms | 310 // emit transforms |
| 300 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, | 311 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, |
| 301 args.fTransformsIn, args.fTransformsOut); | 312 args.fTransformsIn, args.fTransformsOut); |
| 302 | 313 |
| 303 const char* textureSizeUniName = NULL; | 314 const char* textureSizeUniName = NULL; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 texture->height() != fTextureSize.height()) { | 377 texture->height() != fTextureSize.height()) { |
| 367 fTextureSize = SkISize::Make(texture->width(), texture->height()); | 378 fTextureSize = SkISize::Make(texture->width(), texture->height()); |
| 368 pdman.set2f(fTextureSizeUni, | 379 pdman.set2f(fTextureSizeUni, |
| 369 SkIntToScalar(fTextureSize.width()), | 380 SkIntToScalar(fTextureSize.width()), |
| 370 SkIntToScalar(fTextureSize.height())); | 381 SkIntToScalar(fTextureSize.height())); |
| 371 } | 382 } |
| 372 | 383 |
| 373 const GrDistanceFieldPathGeoProc& dfpgp = proc.cast<GrDistanceFieldPathG
eoProc>(); | 384 const GrDistanceFieldPathGeoProc& dfpgp = proc.cast<GrDistanceFieldPathG
eoProc>(); |
| 374 this->setUniformViewMatrix(pdman, dfpgp.viewMatrix()); | 385 this->setUniformViewMatrix(pdman, dfpgp.viewMatrix()); |
| 375 | 386 |
| 376 if (dfpgp.color() != fColor) { | 387 const DistanceFieldPathBatchTracker& local = bt.cast<DistanceFieldPathBa
tchTracker>(); |
| 388 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
| 377 GrGLfloat c[4]; | 389 GrGLfloat c[4]; |
| 378 GrColorToRGBAFloat(dfpgp.color(), c); | 390 GrColorToRGBAFloat(local.fColor, c); |
| 379 pdman.set4fv(fColorUniform, 1, c); | 391 pdman.set4fv(fColorUniform, 1, c); |
| 380 fColor = dfpgp.color(); | 392 fColor = local.fColor; |
| 381 } | 393 } |
| 382 } | 394 } |
| 383 | 395 |
| 384 static inline void GenKey(const GrGeometryProcessor& gp, | 396 static inline void GenKey(const GrGeometryProcessor& gp, |
| 385 const GrBatchTracker& bt, | 397 const GrBatchTracker& bt, |
| 386 const GrGLSLCaps&, | 398 const GrGLSLCaps&, |
| 387 GrProcessorKeyBuilder* b) { | 399 GrProcessorKeyBuilder* b) { |
| 388 const GrDistanceFieldPathGeoProc& dfTexEffect = gp.cast<GrDistanceFieldP
athGeoProc>(); | 400 const GrDistanceFieldPathGeoProc& dfTexEffect = gp.cast<GrDistanceFieldP
athGeoProc>(); |
| 389 | 401 |
| 402 const DistanceFieldPathBatchTracker& local = bt.cast<DistanceFieldPathBa
tchTracker>(); |
| 390 uint32_t key = dfTexEffect.getFlags(); | 403 uint32_t key = dfTexEffect.getFlags(); |
| 391 key |= dfTexEffect.colorIgnored() << 16; | 404 key |= local.fInputColorType << 16; |
| 392 key |= dfTexEffect.hasVertexColor() << 17; | |
| 393 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; | 405 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
| 394 b->add32(key); | 406 b->add32(key); |
| 395 } | 407 } |
| 396 | 408 |
| 397 private: | 409 private: |
| 398 UniformHandle fColorUniform; | 410 UniformHandle fColorUniform; |
| 399 UniformHandle fTextureSizeUni; | 411 UniformHandle fTextureSizeUni; |
| 400 GrColor fColor; | 412 GrColor fColor; |
| 401 SkISize fTextureSize; | 413 SkISize fTextureSize; |
| 402 | 414 |
| 403 typedef GrGLGeometryProcessor INHERITED; | 415 typedef GrGLGeometryProcessor INHERITED; |
| 404 }; | 416 }; |
| 405 | 417 |
| 406 /////////////////////////////////////////////////////////////////////////////// | 418 /////////////////////////////////////////////////////////////////////////////// |
| 407 | 419 |
| 408 GrDistanceFieldPathGeoProc::GrDistanceFieldPathGeoProc( | 420 GrDistanceFieldPathGeoProc::GrDistanceFieldPathGeoProc( |
| 409 GrColor color, | 421 GrColor color, |
| 410 const SkMatrix& viewMatrix, | 422 const SkMatrix& viewMatrix, |
| 411 GrTexture* texture, | 423 GrTexture* texture, |
| 412 const GrTextureParams& params, | 424 const GrTextureParams& params, |
| 413 uint32_t flags, | 425 uint32_t flags) |
| 414 bool usesLocalCoords) | |
| 415 : fColor(color) | 426 : fColor(color) |
| 416 , fViewMatrix(viewMatrix) | 427 , fViewMatrix(viewMatrix) |
| 417 , fTextureAccess(texture, params) | 428 , fTextureAccess(texture, params) |
| 418 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) | 429 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) |
| 419 , fInColor(NULL) | 430 , fInColor(NULL) { |
| 420 , fUsesLocalCoords(usesLocalCoords) { | |
| 421 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); | 431 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); |
| 422 this->initClassID<GrDistanceFieldPathGeoProc>(); | 432 this->initClassID<GrDistanceFieldPathGeoProc>(); |
| 423 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); | 433 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); |
| 424 if (flags & kColorAttr_DistanceFieldEffectFlag) { | 434 if (flags & kColorAttr_DistanceFieldEffectFlag) { |
| 425 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); | 435 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); |
| 426 } | 436 } |
| 427 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 437 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
| 428 kVec2f_GrVertexAttribTyp
e)); | 438 kVec2f_GrVertexAttribT
ype)); |
| 429 this->addTextureAccess(&fTextureAccess); | 439 this->addTextureAccess(&fTextureAccess); |
| 430 } | 440 } |
| 431 | 441 |
| 432 void GrDistanceFieldPathGeoProc::getGLProcessorKey(const GrBatchTracker& bt, | 442 void GrDistanceFieldPathGeoProc::getGLProcessorKey(const GrBatchTracker& bt, |
| 433 const GrGLSLCaps& caps, | 443 const GrGLSLCaps& caps, |
| 434 GrProcessorKeyBuilder* b) con
st { | 444 GrProcessorKeyBuilder* b) con
st { |
| 435 GrGLDistanceFieldPathGeoProc::GenKey(*this, bt, caps, b); | 445 GrGLDistanceFieldPathGeoProc::GenKey(*this, bt, caps, b); |
| 436 } | 446 } |
| 437 | 447 |
| 438 GrGLPrimitiveProcessor* | 448 GrGLPrimitiveProcessor* |
| 439 GrDistanceFieldPathGeoProc::createGLInstance(const GrBatchTracker& bt, const GrG
LSLCaps&) const { | 449 GrDistanceFieldPathGeoProc::createGLInstance(const GrBatchTracker& bt, const GrG
LSLCaps&) const { |
| 440 return SkNEW_ARGS(GrGLDistanceFieldPathGeoProc, (*this, bt)); | 450 return SkNEW_ARGS(GrGLDistanceFieldPathGeoProc, (*this, bt)); |
| 441 } | 451 } |
| 442 | 452 |
| 453 void GrDistanceFieldPathGeoProc::initBatchTracker(GrBatchTracker* bt, |
| 454 const GrPipelineInfo& init) co
nst { |
| 455 DistanceFieldPathBatchTracker* local = bt->cast<DistanceFieldPathBatchTracke
r>(); |
| 456 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, |
| 457 SkToBool(fInColor)); |
| 458 local->fUsesLocalCoords = init.fUsesLocalCoords; |
| 459 } |
| 460 |
| 443 /////////////////////////////////////////////////////////////////////////////// | 461 /////////////////////////////////////////////////////////////////////////////// |
| 444 | 462 |
| 445 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldPathGeoProc); | 463 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldPathGeoProc); |
| 446 | 464 |
| 447 GrGeometryProcessor* GrDistanceFieldPathGeoProc::TestCreate(SkRandom* random, | 465 GrGeometryProcessor* GrDistanceFieldPathGeoProc::TestCreate(SkRandom* random, |
| 448 GrContext*, | 466 GrContext*, |
| 449 const GrDrawTargetCa
ps&, | 467 const GrDrawTargetCa
ps&, |
| 450 GrTexture* textures[
]) { | 468 GrTexture* textures[
]) { |
| 451 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx | 469 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx |
| 452 : GrProcessorUnitTest::kAlphaTextureIdx; | 470 : GrProcessorUnitTest::kAlphaTextureIdx; |
| 453 static const SkShader::TileMode kTileModes[] = { | 471 static const SkShader::TileMode kTileModes[] = { |
| 454 SkShader::kClamp_TileMode, | 472 SkShader::kClamp_TileMode, |
| 455 SkShader::kRepeat_TileMode, | 473 SkShader::kRepeat_TileMode, |
| 456 SkShader::kMirror_TileMode, | 474 SkShader::kMirror_TileMode, |
| 457 }; | 475 }; |
| 458 SkShader::TileMode tileModes[] = { | 476 SkShader::TileMode tileModes[] = { |
| 459 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 477 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 460 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 478 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 461 }; | 479 }; |
| 462 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode | 480 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode |
| 463 : GrTextureParams::kNon
e_FilterMode); | 481 : GrTextureParams::kNon
e_FilterMode); |
| 464 | 482 |
| 465 return GrDistanceFieldPathGeoProc::Create(GrRandomColor(random), | 483 return GrDistanceFieldPathGeoProc::Create(GrRandomColor(random), |
| 466 GrTest::TestMatrix(random), | 484 GrTest::TestMatrix(random), |
| 467 textures[texIdx], | 485 textures[texIdx], |
| 468 params, | 486 params, |
| 469 random->nextBool() ? | 487 random->nextBool() ? kSimilarity_DistanceFieldEffectFlag : 0); |
| 470 kSimilarity_DistanceFieldE
ffectFlag : 0, | |
| 471 random->nextBool()); | |
| 472 } | 488 } |
| 473 | 489 |
| 474 /////////////////////////////////////////////////////////////////////////////// | 490 /////////////////////////////////////////////////////////////////////////////// |
| 475 | 491 |
| 492 struct DistanceFieldLCDBatchTracker { |
| 493 GrGPInput fInputColorType; |
| 494 GrColor fColor; |
| 495 bool fUsesLocalCoords; |
| 496 }; |
| 497 |
| 476 class GrGLDistanceFieldLCDTextGeoProc : public GrGLGeometryProcessor { | 498 class GrGLDistanceFieldLCDTextGeoProc : public GrGLGeometryProcessor { |
| 477 public: | 499 public: |
| 478 GrGLDistanceFieldLCDTextGeoProc(const GrGeometryProcessor&, const GrBatchTra
cker&) | 500 GrGLDistanceFieldLCDTextGeoProc(const GrGeometryProcessor&, const GrBatchTra
cker&) |
| 479 : fColor(GrColor_ILLEGAL) { | 501 : fColor(GrColor_ILLEGAL) { |
| 480 fDistanceAdjust = GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(1.
0f, 1.0f, 1.0f); | 502 fDistanceAdjust = GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(1.
0f, 1.0f, 1.0f); |
| 481 } | 503 } |
| 482 | 504 |
| 483 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 505 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
| 484 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = | 506 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = |
| 485 args.fGP.cast<GrDistanceFieldLCDTextGeoProc>(); | 507 args.fGP.cast<GrDistanceFieldLCDTextGeoProc>(); |
| 508 const DistanceFieldLCDBatchTracker& local = args.fBT.cast<DistanceFieldL
CDBatchTracker>(); |
| 486 GrGLGPBuilder* pb = args.fPB; | 509 GrGLGPBuilder* pb = args.fPB; |
| 487 | 510 |
| 488 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 511 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 489 | 512 |
| 490 // emit attributes | 513 // emit attributes |
| 491 vsBuilder->emitAttributes(dfTexEffect); | 514 vsBuilder->emitAttributes(dfTexEffect); |
| 492 | 515 |
| 493 // setup pass through color | 516 // setup pass through color |
| 494 if (!dfTexEffect.colorIgnored()) { | 517 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor
, NULL, |
| 495 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); | 518 &fColorUniform); |
| 496 } | |
| 497 | 519 |
| 498 // Setup position | 520 // Setup position |
| 499 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix()); | 521 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix()); |
| 500 | 522 |
| 501 // emit transforms | 523 // emit transforms |
| 502 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, | 524 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, |
| 503 args.fTransformsIn, args.fTransformsOut); | 525 args.fTransformsIn, args.fTransformsOut); |
| 504 | 526 |
| 505 // set up varyings | 527 // set up varyings |
| 506 bool isUniformScale = SkToBool(dfTexEffect.getFlags() & kUniformScale_Di
stanceFieldEffectMask); | 528 bool isUniformScale = SkToBool(dfTexEffect.getFlags() & kUniformScale_Di
stanceFieldEffectMask); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 if (wa != fDistanceAdjust) { | 645 if (wa != fDistanceAdjust) { |
| 624 pdman.set3f(fDistanceAdjustUni, | 646 pdman.set3f(fDistanceAdjustUni, |
| 625 wa.fR, | 647 wa.fR, |
| 626 wa.fG, | 648 wa.fG, |
| 627 wa.fB); | 649 wa.fB); |
| 628 fDistanceAdjust = wa; | 650 fDistanceAdjust = wa; |
| 629 } | 651 } |
| 630 | 652 |
| 631 this->setUniformViewMatrix(pdman, dfTexEffect.viewMatrix()); | 653 this->setUniformViewMatrix(pdman, dfTexEffect.viewMatrix()); |
| 632 | 654 |
| 633 if (dfTexEffect.color() != fColor) { | 655 const DistanceFieldLCDBatchTracker& local = bt.cast<DistanceFieldLCDBatc
hTracker>(); |
| 656 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
| 634 GrGLfloat c[4]; | 657 GrGLfloat c[4]; |
| 635 GrColorToRGBAFloat(dfTexEffect.color(), c); | 658 GrColorToRGBAFloat(local.fColor, c); |
| 636 pdman.set4fv(fColorUniform, 1, c); | 659 pdman.set4fv(fColorUniform, 1, c); |
| 637 fColor = dfTexEffect.color(); | 660 fColor = local.fColor; |
| 638 } | 661 } |
| 639 } | 662 } |
| 640 | 663 |
| 641 static inline void GenKey(const GrGeometryProcessor& gp, | 664 static inline void GenKey(const GrGeometryProcessor& gp, |
| 642 const GrBatchTracker& bt, | 665 const GrBatchTracker& bt, |
| 643 const GrGLSLCaps&, | 666 const GrGLSLCaps&, |
| 644 GrProcessorKeyBuilder* b) { | 667 GrProcessorKeyBuilder* b) { |
| 645 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = gp.cast<GrDistanceFie
ldLCDTextGeoProc>(); | 668 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = gp.cast<GrDistanceFie
ldLCDTextGeoProc>(); |
| 646 | 669 |
| 670 const DistanceFieldLCDBatchTracker& local = bt.cast<DistanceFieldLCDBatc
hTracker>(); |
| 647 uint32_t key = dfTexEffect.getFlags(); | 671 uint32_t key = dfTexEffect.getFlags(); |
| 648 key |= dfTexEffect.colorIgnored() << 16; | 672 key |= local.fInputColorType << 16; |
| 649 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; | 673 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
| 650 b->add32(key); | 674 b->add32(key); |
| 651 } | 675 } |
| 652 | 676 |
| 653 private: | 677 private: |
| 654 GrColor fColor; | 678 GrColor fColor; |
| 655 UniformHandle fColorUniform; | 679 UniformHandle fColorUniform; |
| 656 GrDistanceFieldLCDTextGeoProc::DistanceAdjust fDistanceAdjust; | 680 GrDistanceFieldLCDTextGeoProc::DistanceAdjust fDistanceAdjust; |
| 657 UniformHandle fDistanceAdjustUni; | 681 UniformHandle fDistanceAdjustUni; |
| 658 | 682 |
| 659 typedef GrGLGeometryProcessor INHERITED; | 683 typedef GrGLGeometryProcessor INHERITED; |
| 660 }; | 684 }; |
| 661 | 685 |
| 662 /////////////////////////////////////////////////////////////////////////////// | 686 /////////////////////////////////////////////////////////////////////////////// |
| 663 | 687 |
| 664 GrDistanceFieldLCDTextGeoProc::GrDistanceFieldLCDTextGeoProc( | 688 GrDistanceFieldLCDTextGeoProc::GrDistanceFieldLCDTextGeoProc( |
| 665 GrColor color, const SkMatrix&
viewMatrix, | 689 GrColor color, const SkMatrix&
viewMatrix, |
| 666 GrTexture* texture, const GrTe
xtureParams& params, | 690 GrTexture* texture, const GrTe
xtureParams& params, |
| 667 DistanceAdjust distanceAdjust, | 691 DistanceAdjust distanceAdjust, |
| 668 uint32_t flags, bool usesLocal
Coords) | 692 uint32_t flags) |
| 669 : fColor(color) | 693 : fColor(color) |
| 670 , fViewMatrix(viewMatrix) | 694 , fViewMatrix(viewMatrix) |
| 671 , fTextureAccess(texture, params) | 695 , fTextureAccess(texture, params) |
| 672 , fDistanceAdjust(distanceAdjust) | 696 , fDistanceAdjust(distanceAdjust) |
| 673 , fFlags(flags & kLCD_DistanceFieldEffectMask) | 697 , fFlags(flags & kLCD_DistanceFieldEffectMask){ |
| 674 , fUsesLocalCoords(usesLocalCoords) { | |
| 675 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan
ceFieldEffectFlag)); | 698 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan
ceFieldEffectFlag)); |
| 676 this->initClassID<GrDistanceFieldLCDTextGeoProc>(); | 699 this->initClassID<GrDistanceFieldLCDTextGeoProc>(); |
| 677 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); | 700 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); |
| 678 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 701 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
| 679 kVec2s_GrVertexAttribTyp
e)); | 702 kVec2s_GrVertexAttribT
ype)); |
| 680 this->addTextureAccess(&fTextureAccess); | 703 this->addTextureAccess(&fTextureAccess); |
| 681 } | 704 } |
| 682 | 705 |
| 683 void GrDistanceFieldLCDTextGeoProc::getGLProcessorKey(const GrBatchTracker& bt, | 706 void GrDistanceFieldLCDTextGeoProc::getGLProcessorKey(const GrBatchTracker& bt, |
| 684 const GrGLSLCaps& caps, | 707 const GrGLSLCaps& caps, |
| 685 GrProcessorKeyBuilder* b)
const { | 708 GrProcessorKeyBuilder* b)
const { |
| 686 GrGLDistanceFieldLCDTextGeoProc::GenKey(*this, bt, caps, b); | 709 GrGLDistanceFieldLCDTextGeoProc::GenKey(*this, bt, caps, b); |
| 687 } | 710 } |
| 688 | 711 |
| 689 GrGLPrimitiveProcessor* | 712 GrGLPrimitiveProcessor* |
| 690 GrDistanceFieldLCDTextGeoProc::createGLInstance(const GrBatchTracker& bt, | 713 GrDistanceFieldLCDTextGeoProc::createGLInstance(const GrBatchTracker& bt, |
| 691 const GrGLSLCaps&) const { | 714 const GrGLSLCaps&) const { |
| 692 return SkNEW_ARGS(GrGLDistanceFieldLCDTextGeoProc, (*this, bt)); | 715 return SkNEW_ARGS(GrGLDistanceFieldLCDTextGeoProc, (*this, bt)); |
| 693 } | 716 } |
| 694 | 717 |
| 718 void GrDistanceFieldLCDTextGeoProc::initBatchTracker(GrBatchTracker* bt, |
| 719 const GrPipelineInfo& init)
const { |
| 720 DistanceFieldLCDBatchTracker* local = bt->cast<DistanceFieldLCDBatchTracker>
(); |
| 721 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, false); |
| 722 local->fUsesLocalCoords = init.fUsesLocalCoords; |
| 723 } |
| 724 |
| 695 /////////////////////////////////////////////////////////////////////////////// | 725 /////////////////////////////////////////////////////////////////////////////// |
| 696 | 726 |
| 697 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldLCDTextGeoProc); | 727 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldLCDTextGeoProc); |
| 698 | 728 |
| 699 GrGeometryProcessor* GrDistanceFieldLCDTextGeoProc::TestCreate(SkRandom* random, | 729 GrGeometryProcessor* GrDistanceFieldLCDTextGeoProc::TestCreate(SkRandom* random, |
| 700 GrContext*, | 730 GrContext*, |
| 701 const GrDrawTar
getCaps&, | 731 const GrDrawTar
getCaps&, |
| 702 GrTexture* text
ures[]) { | 732 GrTexture* text
ures[]) { |
| 703 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : | 733 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : |
| 704 GrProcessorUnitTest::kAlphaTextureIdx; | 734 GrProcessorUnitTest::kAlphaTextureIdx; |
| 705 static const SkShader::TileMode kTileModes[] = { | 735 static const SkShader::TileMode kTileModes[] = { |
| 706 SkShader::kClamp_TileMode, | 736 SkShader::kClamp_TileMode, |
| 707 SkShader::kRepeat_TileMode, | 737 SkShader::kRepeat_TileMode, |
| 708 SkShader::kMirror_TileMode, | 738 SkShader::kMirror_TileMode, |
| 709 }; | 739 }; |
| 710 SkShader::TileMode tileModes[] = { | 740 SkShader::TileMode tileModes[] = { |
| 711 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 741 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 712 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 742 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 713 }; | 743 }; |
| 714 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : | 744 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : |
| 715 GrTextureParams::kNone_FilterMode); | 745 GrTextureParams::kNone_FilterMode); |
| 716 DistanceAdjust wa = { 0.0f, 0.1f, -0.1f }; | 746 DistanceAdjust wa = { 0.0f, 0.1f, -0.1f }; |
| 717 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; | 747 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; |
| 718 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; | 748 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; |
| 719 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 749 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; |
| 720 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(random), | 750 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(random), |
| 721 GrTest::TestMatrix(random), | 751 GrTest::TestMatrix(random), |
| 722 textures[texIdx], params, | 752 textures[texIdx], params, |
| 723 wa, | 753 wa, |
| 724 flags, | 754 flags); |
| 725 random->nextBool()); | |
| 726 } | 755 } |
| OLD | NEW |