/** We always use per-vertex colors so that rects can be batched across color changes. Sometimes we have explicit local coords and sometimes not. We *could* always provide explicit local coords and just duplicate the positions when the caller hasn't provided a local coord rect, but we haven't seen a use case which frequently switches between local rect and no local rect draws. The color param is used to determine whether the opaque hint can be set on the draw state. The caller must populate the vertex colors itself. The vertex attrib order is always pos, color, [local coords]. */ static const GrGeometryProcessor* create_rect_gp(bool hasExplicitLocalCoords, GrColor color, const SkMatrix* localMatrix) { uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | GrDefaultGeoProcFactory::kColor_GPType; flags |= hasExplicitLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPType : 0; if (localMatrix) { return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), *localMatrix, GrColorIsOpaque(color)); } else { return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), SkMatrix::I(), GrColorIsOpaque(color)); } }
static const GrGeometryProcessor* create_rect_gp(const GrDrawState& drawState, GrColor color, CoverageAttribType* type) { uint32_t flags = GrDefaultGeoProcFactory::kColor_GPType; const GrGeometryProcessor* gp; if (drawState.canTweakAlphaForCoverage()) { gp = GrDefaultGeoProcFactory::Create(color, flags); SkASSERT(gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::PositionColorAttr)); *type = kUseColor_CoverageAttribType; } else { flags |= GrDefaultGeoProcFactory::kCoverage_GPType; gp = GrDefaultGeoProcFactory::Create(color, flags, GrColorIsOpaque(color)); SkASSERT(gp->getVertexStride()==sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr)); *type = kUseCoverage_CoverageAttribType; } return gp; }
fDistanceAdjustTable[GrColorUnpackG(colorNoPreMul) >> kDistanceAdjustLumShift]; float blueCorrection = fDistanceAdjustTable[GrColorUnpackB(colorNoPreMul) >> kDistanceAdjustLumShift]; GrDistanceFieldLCDTextureEffect::DistanceAdjust widthAdjust = GrDistanceFieldLCDTextureEffect::DistanceAdjust::Make(redCorrection, greenCorrection, blueCorrection); fCachedGeometryProcessor.reset(GrDistanceFieldLCDTextureEffect::Create(color, fViewMatrix, fCurrTexture, params, widthAdjust, flags)); } else { flags |= kColorAttr_DistanceFieldEffectFlag; bool opaque = GrColorIsOpaque(color); #ifdef SK_GAMMA_APPLY_TO_A8 U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDeviceProperties.gamma(), filteredColor); float correction = fDistanceAdjustTable[lum >> kDistanceAdjustLumShift]; fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create(color, fViewMatrix, fCurrTexture, params, correction, flags, opaque)); #else fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create(color, fViewMatrix, fCurrTexture,
void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColor) { GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_FilterMode); GrTextureParams gammaParams(SkShader::kClamp_TileMode, GrTextureParams::kNone_FilterMode); uint32_t textureUniqueID = fCurrTexture->getUniqueID(); const SkMatrix& ctm = fViewMatrix; // set up any flags uint32_t flags = 0; flags |= ctm.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0; flags |= fUseLCDText ? kUseLCD_DistanceFieldEffectFlag : 0; flags |= fUseLCDText && ctm.rectStaysRect() ? kRectToRect_DistanceFieldEffectFlag : 0; bool useBGR = SkPixelGeometryIsBGR(fDeviceProperties.pixelGeometry()); flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0; // see if we need to create a new effect if (textureUniqueID != fEffectTextureUniqueID || filteredColor != fEffectColor || flags != fEffectFlags || !fCachedGeometryProcessor->viewMatrix().cheapEqualTo(fViewMatrix)) { GrColor color = fPaint.getColor(); if (fUseLCDText) { GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredColor); fCachedGeometryProcessor.reset(GrDistanceFieldLCDTextureEffect::Create(color, fViewMatrix, fCurrTexture, params, fGammaTexture, gammaParams, colorNoPreMul, flags)); } else { flags |= kColorAttr_DistanceFieldEffectFlag; bool opaque = GrColorIsOpaque(color); #ifdef SK_GAMMA_APPLY_TO_A8 U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDeviceProperties.gamma(), filteredColor); fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create(color, fViewMatrix, fCurrTexture, params, fGammaTexture, gammaParams, lum/255.f, flags, opaque)); #else fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create(color, fViewMatrix, fCurrTexture, params, flags, opaque)); #endif } fEffectTextureUniqueID = textureUniqueID; fEffectColor = filteredColor; fEffectFlags = flags; } }