std::unique_ptr<GrAtlasTextOp> GrAtlasTextOp::MakeDistanceField( GrContext* context, GrPaint&& paint, int glyphCount, const GrDistanceFieldAdjustTable* distanceAdjustTable, bool useGammaCorrectDistanceTable, SkColor luminanceColor, const SkSurfaceProps& props, bool isAntiAliased, bool useLCD) { GrOpMemoryPool* pool = context->contextPriv().opMemoryPool(); std::unique_ptr<GrAtlasTextOp> op = pool->allocate<GrAtlasTextOp>(std::move(paint)); bool isBGR = SkPixelGeometryIsBGR(props.pixelGeometry()); bool isLCD = useLCD && SkPixelGeometryIsH(props.pixelGeometry()); op->fMaskType = !isAntiAliased ? kAliasedDistanceField_MaskType : isLCD ? (isBGR ? kLCDBGRDistanceField_MaskType : kLCDDistanceField_MaskType) : kGrayscaleDistanceField_MaskType; op->fDistanceAdjustTable.reset(SkRef(distanceAdjustTable)); op->fUseGammaCorrectDistanceTable = useGammaCorrectDistanceTable; op->fLuminanceColor = luminanceColor; op->fNumGlyphs = glyphCount; op->fGeoCount = 1; return op; }
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 = fContext->getMatrix(); // 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) { if (fUseLCDText) { GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredColor); fCachedGeometryProcessor.reset(GrDistanceFieldLCDTextureEffect::Create(fCurrTexture, params, fGammaTexture, gammaParams, colorNoPreMul, flags)); } else { #ifdef SK_GAMMA_APPLY_TO_A8 U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDeviceProperties.gamma(), filteredColor); fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create(fCurrTexture, params, fGammaTexture, gammaParams, lum/255.f, flags)); #else fCachedGeometryProcessor.reset(GrDistanceFieldNoGammaTextureEffect::Create(fCurrTexture, params, flags)); #endif } fEffectTextureUniqueID = textureUniqueID; fEffectColor = filteredColor; fEffectFlags = flags; } }
inline GrDrawBatch* GrAtlasTextBlob::createBatch( const Run::SubRunInfo& info, int glyphCount, int run, int subRun, const SkMatrix& viewMatrix, SkScalar x, SkScalar y, GrColor color, const SkPaint& skPaint, const SkSurfaceProps& props, const GrDistanceFieldAdjustTable* distanceAdjustTable, bool useGammaCorrectDistanceTable, GrBatchFontCache* cache) { GrMaskFormat format = info.maskFormat(); GrColor subRunColor; if (kARGB_GrMaskFormat == format) { uint8_t paintAlpha = skPaint.getAlpha(); subRunColor = SkColorSetARGB(paintAlpha, paintAlpha, paintAlpha, paintAlpha); } else { subRunColor = color; } GrAtlasTextBatch* batch; if (info.drawAsDistanceFields()) { SkColor filteredColor; SkColorFilter* colorFilter = skPaint.getColorFilter(); if (colorFilter) { filteredColor = colorFilter->filterColor(skPaint.getColor()); } else { filteredColor = skPaint.getColor(); } bool useBGR = SkPixelGeometryIsBGR(props.pixelGeometry()); batch = GrAtlasTextBatch::CreateDistanceField(glyphCount, cache, distanceAdjustTable, useGammaCorrectDistanceTable, filteredColor, info.hasUseLCDText(), useBGR); } else { batch = GrAtlasTextBatch::CreateBitmap(format, glyphCount, cache); } GrAtlasTextBatch::Geometry& geometry = batch->geometry(); geometry.fViewMatrix = viewMatrix; geometry.fBlob = SkRef(this); geometry.fRun = run; geometry.fSubRun = subRun; geometry.fColor = subRunColor; geometry.fX = x; geometry.fY = y; batch->init(); return batch; }
void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColor) { GrTextureParams params(SkShader::kClamp_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); float redCorrection = fDistanceAdjustTable[GrColorUnpackR(colorNoPreMul) >> kDistanceAdjustLumShift]; float greenCorrection = fDistanceAdjustTable[GrColorUnpackG(colorNoPreMul) >> kDistanceAdjustLumShift]; float blueCorrection = fDistanceAdjustTable[GrColorUnpackB(colorNoPreMul) >> kDistanceAdjustLumShift]; GrDistanceFieldLCDTextGeoProc::DistanceAdjust widthAdjust = GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(redCorrection, greenCorrection, blueCorrection); fCachedGeometryProcessor.reset(GrDistanceFieldLCDTextGeoProc::Create(color, fViewMatrix, fCurrTexture, params, widthAdjust, flags)); } else {