void generatePath(int glyphID, SkPath* out) override { SkGlyph skGlyph; skGlyph.initWithGlyphID(glyphID); fScalerContext->getMetrics(&skGlyph); fScalerContext->getPath(skGlyph, out); }
bool GrFontScaler::getPackedGlyphDFImage(const SkGlyph& glyph, int width, int height, void* dst) { SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width); SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height); const void* image = fStrike->findImage(glyph); if (NULL == image) { return false; } // now generate the distance field SkASSERT(dst); SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); if (SkMask::kA8_Format == maskFormat) { // make the distance field from the image SkGenerateDistanceFieldFromA8Image((unsigned char*)dst, (unsigned char*)image, glyph.fWidth, glyph.fHeight, glyph.rowBytes()); } else if (SkMask::kBW_Format == maskFormat) { // make the distance field from the image SkGenerateDistanceFieldFromBWImage((unsigned char*)dst, (unsigned char*)image, glyph.fWidth, glyph.fHeight, glyph.rowBytes()); } else { return false; } return true; }
void SkScalerContext_CairoFT::generateImage(const SkGlyph& glyph) { SkASSERT(fScaledFont != nullptr); CairoLockedFTFace faceLock(fScaledFont); FT_Face face = faceLock.getFace(); FT_Error err = FT_Load_Glyph(face, glyph.getGlyphID(), fLoadGlyphFlags); if (err != 0) { memset(glyph.fImage, 0, glyph.rowBytes() * glyph.fHeight); return; } prepareGlyph(face->glyph); bool useLcdFilter = face->glyph->format == FT_GLYPH_FORMAT_OUTLINE && isLCD(glyph) && gSetLcdFilter; if (useLcdFilter) { gSetLcdFilter(face->glyph->library, fLcdFilter); } generateGlyphImage(face, glyph); if (useLcdFilter) { gSetLcdFilter(face->glyph->library, FT_LCD_FILTER_NONE); } }
void GrTextUtils::BmpAppendGlyph(GrAtlasTextBlob* blob, int runIndex, GrBatchFontCache* fontCache, GrBatchTextStrike** strike, const SkGlyph& skGlyph, int vx, int vy, GrColor color, GrFontScaler* scaler) { if (!*strike) { *strike = fontCache->getStrike(scaler); } GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(), skGlyph.getSubXFixed(), skGlyph.getSubYFixed(), GrGlyph::kCoverage_MaskStyle); GrGlyph* glyph = (*strike)->getGlyph(skGlyph, id, scaler); if (!glyph) { return; } int x = vx + glyph->fBounds.fLeft; int y = vy + glyph->fBounds.fTop; // keep them as ints until we've done the clip-test int width = glyph->fBounds.width(); int height = glyph->fBounds.height(); SkRect r; r.fLeft = SkIntToScalar(x); r.fTop = SkIntToScalar(y); r.fRight = r.fLeft + SkIntToScalar(width); r.fBottom = r.fTop + SkIntToScalar(height); blob->appendGlyph(runIndex, r, color, *strike, glyph, scaler, skGlyph, SkIntToScalar(vx), SkIntToScalar(vy), 1.0f, false); }
void generatePath(int glyphID, SkPath* out) override { SkGlyph skGlyph; skGlyph.initWithGlyphID(glyphID); fScalerContext->getMetrics(&skGlyph); fScalerContext->getPath(skGlyph, out); out->transform(fFlipMatrix); // Load glyphs with the inverted y-direction. }
static bool get_packed_glyph_df_image(SkGlyphCache* cache, const SkGlyph& glyph, int width, int height, void* dst) { SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width); SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height); #ifndef SK_USE_LEGACY_DISTANCE_FIELDS const SkPath* path = cache->findPath(glyph); if (nullptr == path) { return false; } SkDEBUGCODE(SkRect glyphBounds = SkRect::MakeXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight)); SkASSERT(glyphBounds.contains(path->getBounds())); // now generate the distance field SkASSERT(dst); SkMatrix drawMatrix; drawMatrix.setTranslate((SkScalar)-glyph.fLeft, (SkScalar)-glyph.fTop); // Generate signed distance field directly from SkPath bool succeed = GrGenerateDistanceFieldFromPath((unsigned char*)dst, *path, drawMatrix, width, height, width * sizeof(unsigned char)); if (!succeed) { #endif const void* image = cache->findImage(glyph); if (nullptr == image) { return false; } // now generate the distance field SkASSERT(dst); SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); if (SkMask::kA8_Format == maskFormat) { // make the distance field from the image SkGenerateDistanceFieldFromA8Image((unsigned char*)dst, (unsigned char*)image, glyph.fWidth, glyph.fHeight, glyph.rowBytes()); } else if (SkMask::kBW_Format == maskFormat) { // make the distance field from the image SkGenerateDistanceFieldFromBWImage((unsigned char*)dst, (unsigned char*)image, glyph.fWidth, glyph.fHeight, glyph.rowBytes()); } else { return false; } #ifndef SK_USE_LEGACY_DISTANCE_FIELDS } #endif return true; }
SkGlyph* SkGlyphCache::lookupByPackedGlyphID(PackedGlyphID packedGlyphID, MetricsType type) { SkGlyph* glyph = fGlyphMap.find(packedGlyphID); if (nullptr == glyph) { glyph = this->allocateNewGlyph(packedGlyphID, type); } else { if (type == kFull_MetricsType && glyph->isJustAdvance()) { fScalerContext->getMetrics(glyph); } } return glyph; }
inline void GrStencilAndCoverTextContext::TextRun::appendGlyph(const SkGlyph& glyph, const SkPoint& pos, FallbackBlobBuilder* fallback) { // Stick the glyphs we can't draw into the fallback text blob. if (SkMask::kARGB32_Format == glyph.fMaskFormat) { if (!fallback->isInitialized()) { fallback->init(fFont, fTextRatio); } fallback->appendGlyph(glyph.getGlyphID(), pos); } else { fInstanceData->append(glyph.getGlyphID(), fTextInverseRatio * pos.x(), fTextInverseRatio * pos.y()); } }
SkGlyph* SkGlyphCache::lookupMetrics(uint32_t id, MetricsType mtype) { SkGlyph* glyph; int hi = 0; int count = fGlyphArray.count(); if (count) { SkGlyph** gptr = fGlyphArray.begin(); int lo = 0; hi = count - 1; while (lo < hi) { int mid = (hi + lo) >> 1; if (gptr[mid]->fID < id) { lo = mid + 1; } else { hi = mid; } } glyph = gptr[hi]; if (glyph->fID == id) { if (kFull_MetricsType == mtype && glyph->isJustAdvance()) { fScalerContext->getMetrics(glyph); } return glyph; } // check if we need to bump hi before falling though to the allocator if (glyph->fID < id) { hi += 1; } } // not found, but hi tells us where to inser the new glyph fMemoryUsed += sizeof(SkGlyph); glyph = (SkGlyph*)fGlyphAlloc.alloc(sizeof(SkGlyph), SkChunkAlloc::kThrow_AllocFailType); glyph->init(id); *fGlyphArray.insert(hi) = glyph; if (kJustAdvance_MetricsType == mtype) { fScalerContext->getAdvance(glyph); } else { SkASSERT(kFull_MetricsType == mtype); fScalerContext->getMetrics(glyph); } return glyph; }
void SkScalerContext_CairoFT::generateImage(const SkGlyph& glyph) { SkASSERT(fScaledFont != NULL); CairoLockedFTFace faceLock(fScaledFont); FT_Face face = faceLock.getFace(); FT_Error err = FT_Load_Glyph(face, glyph.getGlyphID(), fLoadGlyphFlags); if (err != 0) { memset(glyph.fImage, 0, glyph.rowBytes() * glyph.fHeight); return; } generateGlyphImage(face, glyph); }
bool SkScalerContext_DW::getColorGlyphRun(const SkGlyph& glyph, IDWriteColorGlyphRunEnumerator** colorGlyph) { FLOAT advance = 0; UINT16 glyphId = glyph.getGlyphID(); DWRITE_GLYPH_OFFSET offset; offset.advanceOffset = 0.0f; offset.ascenderOffset = 0.0f; DWRITE_GLYPH_RUN run; run.glyphCount = 1; run.glyphAdvances = &advance; run.fontFace = fTypeface->fDWriteFontFace.get(); run.fontEmSize = SkScalarToFloat(fTextSizeRender); run.bidiLevel = 0; run.glyphIndices = &glyphId; run.isSideways = FALSE; run.glyphOffsets = &offset; HRESULT hr = fFactory2->TranslateColorGlyphRun( 0, 0, &run, nullptr, fMeasuringMode, &fXform, 0, colorGlyph); if (hr == DWRITE_E_NOCOLOR) { return false; } HRBM(hr, "Failed to translate color glyph run"); return true; }
inline void GrStencilAndCoverTextContext::appendGlyph(const SkGlyph& glyph, const SkPoint& pos) { // Stick the glyphs we can't draw into the fallback arrays. if (SkMask::kARGB32_Format == glyph.fMaskFormat) { fFallbackIndices.push_back(glyph.getGlyphID()); fFallbackPositions.push_back().set(fTextInverseRatio * pos.x(), -fTextInverseRatio * pos.y()); } else { // TODO: infer the reserve count from the text length. if (!fDraw) { fDraw = GrPathRangeDraw::Create(fGlyphs, GrPathRendering::kTranslate_PathTransformType, 64); } float translate[] = { fTextInverseRatio * pos.x(), -fTextInverseRatio * pos.y() }; fDraw->append(glyph.getGlyphID(), translate); } }
void SkRandomScalerContext::generateImage(const SkGlyph& glyph) { SkMask::Format format = (SkMask::Format)glyph.fMaskFormat; switch (glyph.getGlyphID() % 4) { case 0: format = SkMask::kLCD16_Format; break; case 1: format = SkMask::kA8_Format; break; case 2: format = SkMask::kARGB32_Format; break; case 3: format = SkMask::kBW_Format; break; } const_cast<SkGlyph&>(glyph).fMaskFormat = format; // if the format is ARGB, we just draw the glyph from path ourselves. Otherwise, we force // our proxy context to generate the image from paths. if (!fFakeIt) { if (SkMask::kARGB32_Format == glyph.fMaskFormat) { SkPath path; fProxy->getPath(glyph, &path); SkBitmap bm; bm.installPixels(SkImageInfo::MakeN32Premul(glyph.fWidth, glyph.fHeight), glyph.fImage, glyph.rowBytes()); bm.eraseColor(0); SkCanvas canvas(bm); canvas.translate(-SkIntToScalar(glyph.fLeft), -SkIntToScalar(glyph.fTop)); canvas.drawPath(path, fFace->paint()); } else { fProxy->forceGenerateImageFromPath(); fProxy->getImage(glyph); fProxy->forceOffGenerateImageFromPath(); } } else { sk_bzero(glyph.fImage, glyph.computeImageSize()); } }
const SkGlyph& SkGlyphCache::getGlyphIDMetrics(uint16_t glyphID) { VALIDATE(); uint32_t id = SkGlyph::MakeID(glyphID); unsigned index = ID2HashIndex(id); SkGlyph* glyph = fGlyphHash[index]; if (NULL == glyph || glyph->fID != id) { RecordHashCollisionIf(glyph != NULL); glyph = this->lookupMetrics(glyphID, kFull_MetricsType); fGlyphHash[index] = glyph; } else { RecordHashSuccess(); if (glyph->isJustAdvance()) { fScalerContext->getMetrics(glyph); } } SkASSERT(glyph->isFullMetrics()); return *glyph; }
static bool get_packed_glyph_image(SkGlyphCache* cache, const SkGlyph& glyph, int width, int height, int dstRB, GrMaskFormat expectedMaskFormat, void* dst) { SkASSERT(glyph.fWidth == width); SkASSERT(glyph.fHeight == height); const void* src = cache->findImage(glyph); if (nullptr == src) { return false; } // crbug:510931 // Retrieving the image from the cache can actually change the mask format. This case is very // uncommon so for now we just draw a clear box for these glyphs. if (get_packed_glyph_mask_format(glyph) != expectedMaskFormat) { const int bpp = GrMaskFormatBytesPerPixel(expectedMaskFormat); for (int y = 0; y < height; y++) { sk_bzero(dst, width * bpp); dst = (char*)dst + dstRB; } return true; } int srcRB = glyph.rowBytes(); // The windows font host sometimes has BW glyphs in a non-BW strike. So it is important here to // check the glyph's format, not the strike's format, and to be able to convert to any of the // GrMaskFormats. if (SkMask::kBW_Format == glyph.fMaskFormat) { // expand bits to our mask type const uint8_t* bits = reinterpret_cast<const uint8_t*>(src); switch (expectedMaskFormat) { case kA8_GrMaskFormat:{ uint8_t* bytes = reinterpret_cast<uint8_t*>(dst); expand_bits(bytes, bits, width, height, dstRB, srcRB); break; } case kA565_GrMaskFormat: { uint16_t* rgb565 = reinterpret_cast<uint16_t*>(dst); expand_bits(rgb565, bits, width, height, dstRB, srcRB); break; } default: SkFAIL("Invalid GrMaskFormat"); } } else if (srcRB == dstRB) { memcpy(dst, src, dstRB * height); } else { const int bbp = GrMaskFormatBytesPerPixel(expectedMaskFormat); for (int y = 0; y < height; y++) { memcpy(dst, src, width * bbp); src = (const char*)src + srcRB; dst = (char*)dst + dstRB; } } return true; }
SkGlyph* SkGlyphCache::allocateNewGlyph(PackedGlyphID packedGlyphID, MetricsType mtype) { fMemoryUsed += sizeof(SkGlyph); SkGlyph* glyphPtr; { SkGlyph glyph; glyph.initGlyphFromCombinedID(packedGlyphID); glyphPtr = fGlyphMap.set(glyph); } if (kJustAdvance_MetricsType == mtype) { fScalerContext->getAdvance(glyphPtr); } else { SkASSERT(kFull_MetricsType == mtype); fScalerContext->getMetrics(glyphPtr); } SkASSERT(glyphPtr->fID != SkGlyph::kImpossibleID); return glyphPtr; }
bool GrTextUtils::DfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, GrBatchFontCache* cache, GrBatchTextStrike** strike, const SkGlyph& skGlyph, SkScalar sx, SkScalar sy, GrColor color, GrFontScaler* scaler, SkScalar textRatio, const SkMatrix& viewMatrix) { if (!*strike) { *strike = cache->getStrike(scaler); } GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(), skGlyph.getSubXFixed(), skGlyph.getSubYFixed(), GrGlyph::kDistance_MaskStyle); GrGlyph* glyph = (*strike)->getGlyph(skGlyph, id, scaler); if (!glyph) { return true; } // fallback to color glyph support if (kA8_GrMaskFormat != glyph->fMaskFormat) { return false; } SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft + SK_DistanceFieldInset); SkScalar dy = SkIntToScalar(glyph->fBounds.fTop + SK_DistanceFieldInset); SkScalar width = SkIntToScalar(glyph->fBounds.width() - 2 * SK_DistanceFieldInset); SkScalar height = SkIntToScalar(glyph->fBounds.height() - 2 * SK_DistanceFieldInset); SkScalar scale = textRatio; dx *= scale; dy *= scale; width *= scale; height *= scale; sx += dx; sy += dy; SkRect glyphRect = SkRect::MakeXYWH(sx, sy, width, height); blob->appendGlyph(runIndex, glyphRect, color, *strike, glyph, scaler, skGlyph, sx - dx, sy - dy, scale, true); return true; }
void RandomScalerContext::generateImage(const SkGlyph& glyph) { // TODO: can force down but not up /* SkMask::Format format = (SkMask::Format)glyph.fMaskFormat; switch (glyph.getGlyphID() % 4) { case 0: format = SkMask::kLCD16_Format; break; case 1: format = SkMask::kA8_Format; break; case 2: format = SkMask::kARGB32_Format; break; case 3: format = SkMask::kBW_Format; break; } const_cast<SkGlyph&>(glyph).fMaskFormat = format; */ if (fFakeIt) { sk_bzero(glyph.fImage, glyph.computeImageSize()); return; } if (SkMask::kARGB32_Format != glyph.fMaskFormat) { fProxy->getImage(glyph); return; } // If the format is ARGB, just draw the glyph from path. SkPath path; if (!fProxy->getPath(glyph.getPackedID(), &path)) { fProxy->getImage(glyph); return; } SkBitmap bm; bm.installPixels(SkImageInfo::MakeN32Premul(glyph.fWidth, glyph.fHeight), glyph.fImage, glyph.rowBytes()); bm.eraseColor(0); SkCanvas canvas(bm); canvas.translate(-SkIntToScalar(glyph.fLeft), -SkIntToScalar(glyph.fTop)); canvas.drawPath(path, this->getRandomTypeface()->paint()); }
inline void GrStencilAndCoverTextContext::appendGlyph(const SkGlyph& glyph, const SkPoint& pos) { if (fQueuedGlyphCount >= fFallbackGlyphsIdx) { SkASSERT(fQueuedGlyphCount == fFallbackGlyphsIdx); this->flush(); } // Stick the glyphs we can't draw at the end of the buffer, growing backwards. int index = (SkMask::kARGB32_Format == glyph.fMaskFormat) ? --fFallbackGlyphsIdx : fQueuedGlyphCount++; fGlyphIndices[index] = glyph.getGlyphID(); fGlyphPositions[index].set(fTextInverseRatio * pos.x(), -fTextInverseRatio * pos.y()); }
SkGlyph* SkGlyphCache::allocateNewGlyph(SkPackedGlyphID packedGlyphID, MetricsType mtype) { fMemoryUsed += sizeof(SkGlyph); SkGlyph* glyphPtr; { SkGlyph glyph; glyph.initWithGlyphID(packedGlyphID); glyphPtr = fGlyphMap.set(glyph); } if (kNothing_MetricsType == mtype) { return glyphPtr; } else if (kJustAdvance_MetricsType == mtype) { fScalerContext->getAdvance(glyphPtr); } else { SkASSERT(kFull_MetricsType == mtype); fScalerContext->getMetrics(glyphPtr); } SkASSERT(glyphPtr->fID != SkPackedGlyphID()); return glyphPtr; }
void SkScalerContext_Ascender::generateImage(const SkGlyph& glyph) { aca_GlyphImageRec rec; aca_Vector topLeft; aca_Rasterize(glyph.getGlyphID(), fHandle, &rec, &topLeft); const uint8_t* src = (const uint8_t*)rec.buffer; uint8_t* dst = (uint8_t*)glyph.fImage; int height = glyph.fHeight; src += rec.y0 * rec.pitch + rec.x0; while (--height >= 0) { memcpy(dst, src, glyph.fWidth); src += rec.pitch; dst += glyph.fRowBytes; } }
void SkGScalerContext::generateImage(const SkGlyph& glyph) { if (SkMask::kARGB32_Format == glyph.fMaskFormat) { SkPath path; fProxy->getPath(glyph, &path); SkBitmap bm; bm.installPixels(SkImageInfo::MakeN32Premul(glyph.fWidth, glyph.fHeight), glyph.fImage, glyph.rowBytes()); bm.eraseColor(0); SkCanvas canvas(bm); canvas.translate(-SkIntToScalar(glyph.fLeft), -SkIntToScalar(glyph.fTop)); canvas.concat(fMatrix); canvas.drawPath(path, fFace->paint()); } else { fProxy->getImage(glyph); } }
void SkScalerContext_CairoFT::generatePath(const SkGlyph& glyph, SkPath* path) { SkASSERT(fScaledFont != NULL); CairoLockedFTFace faceLock(fScaledFont); FT_Face face = faceLock.getFace(); SkASSERT(&glyph && path); uint32_t flags = fLoadGlyphFlags; flags |= FT_LOAD_NO_BITMAP; // ignore embedded bitmaps so we're sure to get the outline flags &= ~FT_LOAD_RENDER; // don't scan convert (we just want the outline) FT_Error err = FT_Load_Glyph(face, glyph.getGlyphID(), flags); if (err != 0) { path->reset(); return; } generateGlyphPath(face, path); }
void SkScalerContext_FreeType_Base::generateGlyphImage( FT_Face face, const SkGlyph& glyph, const SkMatrix& bitmapTransform) { const bool doBGR = SkToBool(fRec.fFlags & SkScalerContext::kLCD_BGROrder_Flag); const bool doVert = SkToBool(fRec.fFlags & SkScalerContext::kLCD_Vertical_Flag); switch ( face->glyph->format ) { case FT_GLYPH_FORMAT_OUTLINE: { FT_Outline* outline = &face->glyph->outline; int dx = 0, dy = 0; if (fRec.fFlags & SkScalerContext::kSubpixelPositioning_Flag) { dx = SkFixedToFDot6(glyph.getSubXFixed()); dy = SkFixedToFDot6(glyph.getSubYFixed()); // negate dy since freetype-y-goes-up and skia-y-goes-down dy = -dy; } memset(glyph.fImage, 0, glyph.rowBytes() * glyph.fHeight); if (SkMask::kLCD16_Format == glyph.fMaskFormat) { FT_Outline_Translate(outline, dx, dy); FT_Error err = FT_Render_Glyph(face->glyph, doVert ? FT_RENDER_MODE_LCD_V : FT_RENDER_MODE_LCD); if (err) { SK_TRACEFTR(err, "Could not render glyph."); return; } SkMask mask; glyph.toMask(&mask); #ifdef SK_SHOW_TEXT_BLIT_COVERAGE memset(mask.fImage, 0x80, mask.fBounds.height() * mask.fRowBytes); #endif FT_GlyphSlotRec& ftGlyph = *face->glyph; if (!SkIRect::Intersects(mask.fBounds, SkIRect::MakeXYWH( ftGlyph.bitmap_left, -ftGlyph.bitmap_top, ftGlyph.bitmap.width, ftGlyph.bitmap.rows))) { return; } // If the FT_Bitmap extent is larger, discard bits of the bitmap outside the mask. // If the SkMask extent is larger, shrink mask to fit bitmap (clearing discarded). unsigned char* origBuffer = ftGlyph.bitmap.buffer; // First align the top left (origin). if (-ftGlyph.bitmap_top < mask.fBounds.fTop) { int32_t topDiff = mask.fBounds.fTop - (-ftGlyph.bitmap_top); ftGlyph.bitmap.buffer += ftGlyph.bitmap.pitch * topDiff; ftGlyph.bitmap.rows -= topDiff; ftGlyph.bitmap_top = -mask.fBounds.fTop; } if (ftGlyph.bitmap_left < mask.fBounds.fLeft) { int32_t leftDiff = mask.fBounds.fLeft - ftGlyph.bitmap_left; ftGlyph.bitmap.buffer += leftDiff; ftGlyph.bitmap.width -= leftDiff; ftGlyph.bitmap_left = mask.fBounds.fLeft; } if (mask.fBounds.fTop < -ftGlyph.bitmap_top) { mask.fImage += mask.fRowBytes * (-ftGlyph.bitmap_top - mask.fBounds.fTop); mask.fBounds.fTop = -ftGlyph.bitmap_top; } if (mask.fBounds.fLeft < ftGlyph.bitmap_left) { mask.fImage += sizeof(uint16_t) * (ftGlyph.bitmap_left - mask.fBounds.fLeft); mask.fBounds.fLeft = ftGlyph.bitmap_left; } // Origins aligned, clean up the width and height. int ftVertScale = (doVert ? 3 : 1); int ftHoriScale = (doVert ? 1 : 3); if (mask.fBounds.height() * ftVertScale < SkToInt(ftGlyph.bitmap.rows)) { ftGlyph.bitmap.rows = mask.fBounds.height() * ftVertScale; } if (mask.fBounds.width() * ftHoriScale < SkToInt(ftGlyph.bitmap.width)) { ftGlyph.bitmap.width = mask.fBounds.width() * ftHoriScale; } if (SkToInt(ftGlyph.bitmap.rows) < mask.fBounds.height() * ftVertScale) { mask.fBounds.fBottom = mask.fBounds.fTop + ftGlyph.bitmap.rows / ftVertScale; } if (SkToInt(ftGlyph.bitmap.width) < mask.fBounds.width() * ftHoriScale) { mask.fBounds.fRight = mask.fBounds.fLeft + ftGlyph.bitmap.width / ftHoriScale; } if (fPreBlend.isApplicable()) { copyFT2LCD16<true>(ftGlyph.bitmap, mask, doBGR, fPreBlend.fR, fPreBlend.fG, fPreBlend.fB); } else { copyFT2LCD16<false>(ftGlyph.bitmap, mask, doBGR, fPreBlend.fR, fPreBlend.fG, fPreBlend.fB); } // Restore the buffer pointer so FreeType can properly free it. ftGlyph.bitmap.buffer = origBuffer; } else { FT_BBox bbox; FT_Bitmap target; FT_Outline_Get_CBox(outline, &bbox); /* what we really want to do for subpixel is offset(dx, dy) compute_bounds offset(bbox & !63) but that is two calls to offset, so we do the following, which achieves the same thing with only one offset call. */ FT_Outline_Translate(outline, dx - ((bbox.xMin + dx) & ~63), dy - ((bbox.yMin + dy) & ~63)); target.width = glyph.fWidth; target.rows = glyph.fHeight; target.pitch = glyph.rowBytes(); target.buffer = reinterpret_cast<uint8_t*>(glyph.fImage); target.pixel_mode = compute_pixel_mode( (SkMask::Format)fRec.fMaskFormat); target.num_grays = 256; FT_Outline_Get_Bitmap(face->glyph->library, outline, &target); #ifdef SK_SHOW_TEXT_BLIT_COVERAGE for (int y = 0; y < glyph.fHeight; ++y) { for (int x = 0; x < glyph.fWidth; ++x) { uint8_t& a = ((uint8_t*)glyph.fImage)[(glyph.rowBytes() * y) + x]; a = SkTMax<uint8_t>(a, 0x20); } } #endif } } break; case FT_GLYPH_FORMAT_BITMAP: { FT_Pixel_Mode pixel_mode = static_cast<FT_Pixel_Mode>(face->glyph->bitmap.pixel_mode); SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); // Assume that the other formats do not exist. SkASSERT(FT_PIXEL_MODE_MONO == pixel_mode || FT_PIXEL_MODE_GRAY == pixel_mode || FT_PIXEL_MODE_BGRA == pixel_mode); // These are the only formats this ScalerContext should request. SkASSERT(SkMask::kBW_Format == maskFormat || SkMask::kA8_Format == maskFormat || SkMask::kARGB32_Format == maskFormat || SkMask::kLCD16_Format == maskFormat); // If no scaling needed, directly copy glyph bitmap. if (bitmapTransform.isIdentity()) { SkMask dstMask; glyph.toMask(&dstMask); copyFTBitmap(face->glyph->bitmap, dstMask); break; } // Otherwise, scale the bitmap. // Copy the FT_Bitmap into an SkBitmap (either A8 or ARGB) SkBitmap unscaledBitmap; // TODO: mark this as sRGB when the blits will be sRGB. unscaledBitmap.allocPixels(SkImageInfo::Make(face->glyph->bitmap.width, face->glyph->bitmap.rows, SkColorType_for_FTPixelMode(pixel_mode), kPremul_SkAlphaType)); SkMask unscaledBitmapAlias; unscaledBitmapAlias.fImage = reinterpret_cast<uint8_t*>(unscaledBitmap.getPixels()); unscaledBitmapAlias.fBounds.set(0, 0, unscaledBitmap.width(), unscaledBitmap.height()); unscaledBitmapAlias.fRowBytes = unscaledBitmap.rowBytes(); unscaledBitmapAlias.fFormat = SkMaskFormat_for_SkColorType(unscaledBitmap.colorType()); copyFTBitmap(face->glyph->bitmap, unscaledBitmapAlias); // Wrap the glyph's mask in a bitmap, unless the glyph's mask is BW or LCD. // BW requires an A8 target for resizing, which can then be down sampled. // LCD should use a 4x A8 target, which will then be down sampled. // For simplicity, LCD uses A8 and is replicated. int bitmapRowBytes = 0; if (SkMask::kBW_Format != maskFormat && SkMask::kLCD16_Format != maskFormat) { bitmapRowBytes = glyph.rowBytes(); } SkBitmap dstBitmap; // TODO: mark this as sRGB when the blits will be sRGB. dstBitmap.setInfo(SkImageInfo::Make(glyph.fWidth, glyph.fHeight, SkColorType_for_SkMaskFormat(maskFormat), kPremul_SkAlphaType), bitmapRowBytes); if (SkMask::kBW_Format == maskFormat || SkMask::kLCD16_Format == maskFormat) { dstBitmap.allocPixels(); } else { dstBitmap.setPixels(glyph.fImage); } // Scale unscaledBitmap into dstBitmap. SkCanvas canvas(dstBitmap); #ifdef SK_SHOW_TEXT_BLIT_COVERAGE canvas.clear(0x33FF0000); #else canvas.clear(SK_ColorTRANSPARENT); #endif canvas.translate(-glyph.fLeft, -glyph.fTop); canvas.concat(bitmapTransform); canvas.translate(face->glyph->bitmap_left, -face->glyph->bitmap_top); SkPaint paint; paint.setFilterQuality(kMedium_SkFilterQuality); canvas.drawBitmap(unscaledBitmap, 0, 0, &paint); // If the destination is BW or LCD, convert from A8. if (SkMask::kBW_Format == maskFormat) { // Copy the A8 dstBitmap into the A1 glyph.fImage. SkMask dstMask; glyph.toMask(&dstMask); packA8ToA1(dstMask, dstBitmap.getAddr8(0, 0), dstBitmap.rowBytes()); } else if (SkMask::kLCD16_Format == maskFormat) { // Copy the A8 dstBitmap into the LCD16 glyph.fImage. uint8_t* src = dstBitmap.getAddr8(0, 0); uint16_t* dst = reinterpret_cast<uint16_t*>(glyph.fImage); for (int y = dstBitmap.height(); y --> 0;) { for (int x = 0; x < dstBitmap.width(); ++x) { dst[x] = grayToRGB16(src[x]); } dst = (uint16_t*)((char*)dst + glyph.rowBytes()); src += dstBitmap.rowBytes(); } } } break; default: SkDEBUGFAIL("unknown glyph format"); memset(glyph.fImage, 0, glyph.rowBytes() * glyph.fHeight); return; } // We used to always do this pre-USE_COLOR_LUMINANCE, but with colorlum, // it is optional #if defined(SK_GAMMA_APPLY_TO_A8) if (SkMask::kA8_Format == glyph.fMaskFormat && fPreBlend.isApplicable()) { uint8_t* SK_RESTRICT dst = (uint8_t*)glyph.fImage; unsigned rowBytes = glyph.rowBytes(); for (int y = glyph.fHeight - 1; y >= 0; --y) { for (int x = glyph.fWidth - 1; x >= 0; --x) { dst[x] = fPreBlend.fG[dst[x]]; } dst += rowBytes; } } #endif }
void SkScalerContext::getImage(const SkGlyph& origGlyph) { const SkGlyph* glyph = &origGlyph; SkGlyph tmpGlyph; if (fMaskFilter) { // restore the prefilter bounds tmpGlyph.init(origGlyph.fID); // need the original bounds, sans our maskfilter SkMaskFilter* mf = fMaskFilter; fMaskFilter = NULL; // temp disable this->getMetrics(&tmpGlyph); fMaskFilter = mf; // restore tmpGlyph.fImage = origGlyph.fImage; // we need the prefilter bounds to be <= filter bounds SkASSERT(tmpGlyph.fWidth <= origGlyph.fWidth); SkASSERT(tmpGlyph.fHeight <= origGlyph.fHeight); glyph = &tmpGlyph; } if (fRec.fFrameWidth > 0 || fPathEffect != NULL || fRasterizer != NULL) { SkPath devPath, fillPath; SkMatrix fillToDevMatrix; this->internalGetPath(*glyph, &fillPath, &devPath, &fillToDevMatrix); if (fRasterizer) { SkMask mask; glyph->toMask(&mask); mask.fFormat = SkMask::kA8_Format; sk_bzero(glyph->fImage, mask.computeImageSize()); if (!fRasterizer->rasterize(fillPath, fillToDevMatrix, NULL, fMaskFilter, &mask, SkMask::kJustRenderImage_CreateMode)) { return; } } else { SkBitmap bm; SkBitmap::Config config; SkMatrix matrix; SkRegion clip; SkPaint paint; SkDraw draw; if (SkMask::kA8_Format == fRec.fMaskFormat) { config = SkBitmap::kA8_Config; paint.setAntiAlias(true); } else { SkASSERT(SkMask::kBW_Format == fRec.fMaskFormat); config = SkBitmap::kA1_Config; paint.setAntiAlias(false); } clip.setRect(0, 0, glyph->fWidth, glyph->fHeight); matrix.setTranslate(-SkIntToScalar(glyph->fLeft), -SkIntToScalar(glyph->fTop)); bm.setConfig(config, glyph->fWidth, glyph->fHeight, glyph->rowBytes()); bm.setPixels(glyph->fImage); sk_bzero(glyph->fImage, bm.height() * bm.rowBytes()); draw.fClip = &clip; draw.fMatrix = &matrix; draw.fBitmap = &bm; draw.fBounder = NULL; draw.drawPath(devPath, paint); } } else { this->getGlyphContext(*glyph)->generateImage(*glyph); } if (fMaskFilter) { SkMask srcM, dstM; SkMatrix matrix; // the src glyph image shouldn't be 3D SkASSERT(SkMask::k3D_Format != glyph->fMaskFormat); glyph->toMask(&srcM); fRec.getMatrixFrom2x2(&matrix); if (fMaskFilter->filterMask(&dstM, srcM, matrix, NULL)) { int width = SkFastMin32(origGlyph.fWidth, dstM.fBounds.width()); int height = SkFastMin32(origGlyph.fHeight, dstM.fBounds.height()); int dstRB = origGlyph.rowBytes(); int srcRB = dstM.fRowBytes; const uint8_t* src = (const uint8_t*)dstM.fImage; uint8_t* dst = (uint8_t*)origGlyph.fImage; if (SkMask::k3D_Format == dstM.fFormat) { // we have to copy 3 times as much height *= 3; } // clean out our glyph, since it may be larger than dstM //sk_bzero(dst, height * dstRB); while (--height >= 0) { memcpy(dst, src, width); src += srcRB; dst += dstRB; } SkMask::FreeImage(dstM.fImage); } } // check to see if we should filter the alpha channel if (NULL == fMaskFilter && fRec.fMaskFormat != SkMask::kBW_Format && fRec.fMaskFormat != SkMask::kLCD16_Format && fRec.fMaskFormat != SkMask::kLCD32_Format && (fRec.fFlags & (kGammaForBlack_Flag | kGammaForWhite_Flag)) != 0) { const uint8_t* table = (fRec.fFlags & kGammaForBlack_Flag) ? gBlackGammaTable : gWhiteGammaTable; if (NULL != table) { uint8_t* dst = (uint8_t*)origGlyph.fImage; unsigned rowBytes = origGlyph.rowBytes(); for (int y = origGlyph.fHeight - 1; y >= 0; --y) { for (int x = origGlyph.fWidth - 1; x >= 0; --x) { dst[x] = table[dst[x]]; } dst += rowBytes; } } } }
void SkScalerContext::internalGetPath(const SkGlyph& glyph, SkPath* fillPath, SkPath* devPath, SkMatrix* fillToDevMatrix) { SkPath path; this->getGlyphContext(glyph)->generatePath(glyph, &path); if (fRec.fFlags & SkScalerContext::kSubpixelPositioning_Flag) { SkFixed dx = glyph.getSubXFixed(); SkFixed dy = glyph.getSubYFixed(); if (dx | dy) { path.offset(SkFixedToScalar(dx), SkFixedToScalar(dy)); } } if (fRec.fFrameWidth > 0 || fPathEffect != NULL) { // need the path in user-space, with only the point-size applied // so that our stroking and effects will operate the same way they // would if the user had extracted the path themself, and then // called drawPath SkPath localPath; SkMatrix matrix, inverse; fRec.getMatrixFrom2x2(&matrix); matrix.invert(&inverse); path.transform(inverse, &localPath); // now localPath is only affected by the paint settings, and not the canvas matrix SkScalar width = fRec.fFrameWidth; if (fPathEffect) { SkPath effectPath; if (fPathEffect->filterPath(&effectPath, localPath, &width)) { localPath.swap(effectPath); } } if (width > 0) { SkStroke stroker; SkPath outline; stroker.setWidth(width); stroker.setMiterLimit(fRec.fMiterLimit); stroker.setJoin((SkPaint::Join)fRec.fStrokeJoin); stroker.setDoFill(SkToBool(fRec.fFlags & kFrameAndFill_Flag)); stroker.strokePath(localPath, &outline); localPath.swap(outline); } // now return stuff to the caller if (fillToDevMatrix) { *fillToDevMatrix = matrix; } if (devPath) { localPath.transform(matrix, devPath); } if (fillPath) { fillPath->swap(localPath); } } else { // nothing tricky to do if (fillToDevMatrix) { fillToDevMatrix->reset(); } if (devPath) { if (fillPath == NULL) { devPath->swap(path); } else { *devPath = path; } } if (fillPath) { fillPath->swap(path); } } if (devPath) { devPath->updateBoundsCache(); } if (fillPath) { fillPath->updateBoundsCache(); } }
void SkScalerContext::getImage(const SkGlyph& origGlyph) { const SkGlyph* glyph = &origGlyph; SkGlyph tmpGlyph; if (fMaskFilter) { // restore the prefilter bounds tmpGlyph.init(origGlyph.fID); // need the original bounds, sans our maskfilter SkMaskFilter* mf = fMaskFilter; fMaskFilter = NULL; // temp disable this->getMetrics(&tmpGlyph); fMaskFilter = mf; // restore tmpGlyph.fImage = origGlyph.fImage; // we need the prefilter bounds to be <= filter bounds SkASSERT(tmpGlyph.fWidth <= origGlyph.fWidth); SkASSERT(tmpGlyph.fHeight <= origGlyph.fHeight); glyph = &tmpGlyph; } if (fGenerateImageFromPath) { SkPath devPath, fillPath; SkMatrix fillToDevMatrix; SkMask mask; this->internalGetPath(*glyph, &fillPath, &devPath, &fillToDevMatrix); glyph->toMask(&mask); if (fRasterizer) { mask.fFormat = SkMask::kA8_Format; sk_bzero(glyph->fImage, mask.computeImageSize()); if (!fRasterizer->rasterize(fillPath, fillToDevMatrix, NULL, fMaskFilter, &mask, SkMask::kJustRenderImage_CreateMode)) { return; } } else { generateMask(mask, devPath); } } else { this->getGlyphContext(*glyph)->generateImage(*glyph); } if (fMaskFilter) { SkMask srcM, dstM; SkMatrix matrix; // the src glyph image shouldn't be 3D SkASSERT(SkMask::k3D_Format != glyph->fMaskFormat); glyph->toMask(&srcM); fRec.getMatrixFrom2x2(&matrix); if (fMaskFilter->filterMask(&dstM, srcM, matrix, NULL)) { int width = SkFastMin32(origGlyph.fWidth, dstM.fBounds.width()); int height = SkFastMin32(origGlyph.fHeight, dstM.fBounds.height()); int dstRB = origGlyph.rowBytes(); int srcRB = dstM.fRowBytes; const uint8_t* src = (const uint8_t*)dstM.fImage; uint8_t* dst = (uint8_t*)origGlyph.fImage; if (SkMask::k3D_Format == dstM.fFormat) { // we have to copy 3 times as much height *= 3; } // clean out our glyph, since it may be larger than dstM //sk_bzero(dst, height * dstRB); while (--height >= 0) { memcpy(dst, src, width); src += srcRB; dst += dstRB; } SkMask::FreeImage(dstM.fImage); } } }
void SkScalerContext_Windows::generateImage(const SkGlyph& glyph) { SkAutoMutexAcquire ac(gFTMutex); SkASSERT(fDDC); const bool isBW = SkMask::kBW_Format == fRec.fMaskFormat; if ((SkMask::kLCD16_Format == fRec.fMaskFormat) || isBW) { HDC dc = CreateCompatibleDC(0); void* bits = 0; int biWidth = isBW ? alignTo32(glyph.fWidth) : glyph.fWidth; MyBitmapInfo info; sk_bzero(&info, sizeof(info)); if (isBW) { RGBQUAD blackQuad = { 0, 0, 0, 0 }; RGBQUAD whiteQuad = { 0xFF, 0xFF, 0xFF, 0 }; info.bmiColors[0] = blackQuad; info.bmiColors[1] = whiteQuad; } info.bmiHeader.biSize = sizeof(info.bmiHeader); info.bmiHeader.biWidth = biWidth; info.bmiHeader.biHeight = glyph.fHeight; info.bmiHeader.biPlanes = 1; info.bmiHeader.biBitCount = isBW ? 1 : 32; info.bmiHeader.biCompression = BI_RGB; if (isBW) { info.bmiHeader.biClrUsed = 2; } HBITMAP bm = CreateDIBSection(dc, &info, DIB_RGB_COLORS, &bits, 0, 0); SelectObject(dc, bm); // erase to white size_t srcRB = isBW ? (biWidth >> 3) : (glyph.fWidth << 2); size_t size = glyph.fHeight * srcRB; memset(bits, isBW ? 0 : 0xFF, size); SetGraphicsMode(dc, GM_ADVANCED); SetBkMode(dc, TRANSPARENT); SetTextAlign(dc, TA_LEFT | TA_BASELINE); XFORM xform = fXform; xform.eDx = (float)-glyph.fLeft; xform.eDy = (float)-glyph.fTop; SetWorldTransform(dc, &xform); HGDIOBJ prevFont = SelectObject(dc, fFont); COLORREF color = SetTextColor(dc, isBW ? 0xFFFFFF : 0); SkASSERT(color != CLR_INVALID); uint16_t glyphID = glyph.getGlyphID(); #if defined(UNICODE) ExtTextOut(dc, 0, 0, ETO_GLYPH_INDEX, NULL, (LPCWSTR)&glyphID, 1, NULL); #else ExtTextOut(dc, 0, 0, ETO_GLYPH_INDEX, NULL, (LPCSTR)&glyphID, 1, NULL); #endif GdiFlush(); // downsample from rgba to rgb565 int width = glyph.fWidth; size_t dstRB = glyph.rowBytes(); if (isBW) { const uint8_t* src = (const uint8_t*)bits; // gdi's bitmap is upside-down, so we reverse dst walking in Y uint8_t* dst = (uint8_t*)((char*)glyph.fImage + (glyph.fHeight - 1) * dstRB); for (int y = 0; y < glyph.fHeight; y++) { memcpy(dst, src, dstRB); src += srcRB; dst -= dstRB; } } else { // LCD16 const uint32_t* src = (const uint32_t*)bits; // gdi's bitmap is upside-down, so we reverse dst walking in Y uint16_t* dst = (uint16_t*)((char*)glyph.fImage + (glyph.fHeight - 1) * dstRB); for (int y = 0; y < glyph.fHeight; y++) { for (int i = 0; i < width; i++) { dst[i] = rgb_to_lcd16(src[i]); } src = (const uint32_t*)((const char*)src + srcRB); dst = (uint16_t*)((char*)dst - dstRB); } } DeleteDC(dc); DeleteObject(bm); return; }
void SkScalerContext::getImage(const SkGlyph& origGlyph) { const SkGlyph* glyph = &origGlyph; SkGlyph tmpGlyph; // in case we need to call generateImage on a mask-format that is different // (i.e. larger) than what our caller allocated by looking at origGlyph. SkAutoMalloc tmpGlyphImageStorage; // If we are going to draw-from-path, then we cannot generate color, since // the path only makes a mask. This case should have been caught up in // generateMetrics(). SkASSERT(!fGenerateImageFromPath || SkMask::kARGB32_Format != origGlyph.fMaskFormat); if (fMaskFilter) { // restore the prefilter bounds tmpGlyph.initGlyphIdFrom(origGlyph); // need the original bounds, sans our maskfilter SkMaskFilter* mf = fMaskFilter; fMaskFilter = nullptr; // temp disable this->getMetrics(&tmpGlyph); fMaskFilter = mf; // restore // we need the prefilter bounds to be <= filter bounds SkASSERT(tmpGlyph.fWidth <= origGlyph.fWidth); SkASSERT(tmpGlyph.fHeight <= origGlyph.fHeight); if (tmpGlyph.fMaskFormat == origGlyph.fMaskFormat) { tmpGlyph.fImage = origGlyph.fImage; } else { tmpGlyphImageStorage.reset(tmpGlyph.computeImageSize()); tmpGlyph.fImage = tmpGlyphImageStorage.get(); } glyph = &tmpGlyph; } if (fGenerateImageFromPath) { SkPath devPath, fillPath; SkMatrix fillToDevMatrix; SkMask mask; this->internalGetPath(*glyph, &fillPath, &devPath, &fillToDevMatrix); glyph->toMask(&mask); if (fRasterizer) { mask.fFormat = SkMask::kA8_Format; sk_bzero(glyph->fImage, mask.computeImageSize()); if (!fRasterizer->rasterize(fillPath, fillToDevMatrix, nullptr, fMaskFilter, &mask, SkMask::kJustRenderImage_CreateMode)) { return; } if (fPreBlend.isApplicable()) { applyLUTToA8Mask(mask, fPreBlend.fG); } } else { SkASSERT(SkMask::kARGB32_Format != mask.fFormat); generateMask(mask, devPath, fPreBlend); } } else { generateImage(*glyph); } if (fMaskFilter) { SkMask srcM, dstM; SkMatrix matrix; // the src glyph image shouldn't be 3D SkASSERT(SkMask::k3D_Format != glyph->fMaskFormat); SkAutoSMalloc<32*32> a8storage; glyph->toMask(&srcM); if (SkMask::kARGB32_Format == srcM.fFormat) { // now we need to extract the alpha-channel from the glyph's image // and copy it into a temp buffer, and then point srcM at that temp. srcM.fFormat = SkMask::kA8_Format; srcM.fRowBytes = SkAlign4(srcM.fBounds.width()); size_t size = srcM.computeImageSize(); a8storage.reset(size); srcM.fImage = (uint8_t*)a8storage.get(); extract_alpha(srcM, (const SkPMColor*)glyph->fImage, glyph->rowBytes()); } fRec.getMatrixFrom2x2(&matrix); if (fMaskFilter->filterMask(&dstM, srcM, matrix, nullptr)) { int width = SkFastMin32(origGlyph.fWidth, dstM.fBounds.width()); int height = SkFastMin32(origGlyph.fHeight, dstM.fBounds.height()); int dstRB = origGlyph.rowBytes(); int srcRB = dstM.fRowBytes; const uint8_t* src = (const uint8_t*)dstM.fImage; uint8_t* dst = (uint8_t*)origGlyph.fImage; if (SkMask::k3D_Format == dstM.fFormat) { // we have to copy 3 times as much height *= 3; } // clean out our glyph, since it may be larger than dstM //sk_bzero(dst, height * dstRB); while (--height >= 0) { memcpy(dst, src, width); src += srcRB; dst += dstRB; } SkMask::FreeImage(dstM.fImage); if (fPreBlendForFilter.isApplicable()) { applyLUTToA8Mask(srcM, fPreBlendForFilter.fG); } } } }
void SkScalerContext::internalGetPath(const SkGlyph& glyph, SkPath* fillPath, SkPath* devPath, SkMatrix* fillToDevMatrix) { SkPath path; generatePath(glyph, &path); if (fRec.fFlags & SkScalerContext::kSubpixelPositioning_Flag) { SkFixed dx = glyph.getSubXFixed(); SkFixed dy = glyph.getSubYFixed(); if (dx | dy) { path.offset(SkFixedToScalar(dx), SkFixedToScalar(dy)); } } if (fRec.fFrameWidth > 0 || fPathEffect != nullptr) { // need the path in user-space, with only the point-size applied // so that our stroking and effects will operate the same way they // would if the user had extracted the path themself, and then // called drawPath SkPath localPath; SkMatrix matrix, inverse; fRec.getMatrixFrom2x2(&matrix); if (!matrix.invert(&inverse)) { // assume fillPath and devPath are already empty. return; } path.transform(inverse, &localPath); // now localPath is only affected by the paint settings, and not the canvas matrix SkStrokeRec rec(SkStrokeRec::kFill_InitStyle); if (fRec.fFrameWidth > 0) { rec.setStrokeStyle(fRec.fFrameWidth, SkToBool(fRec.fFlags & kFrameAndFill_Flag)); // glyphs are always closed contours, so cap type is ignored, // so we just pass something. rec.setStrokeParams((SkPaint::Cap)fRec.fStrokeCap, (SkPaint::Join)fRec.fStrokeJoin, fRec.fMiterLimit); } if (fPathEffect) { SkPath effectPath; if (fPathEffect->filterPath(&effectPath, localPath, &rec, nullptr)) { localPath.swap(effectPath); } } if (rec.needToApply()) { SkPath strokePath; if (rec.applyToPath(&strokePath, localPath)) { localPath.swap(strokePath); } } // now return stuff to the caller if (fillToDevMatrix) { *fillToDevMatrix = matrix; } if (devPath) { localPath.transform(matrix, devPath); } if (fillPath) { fillPath->swap(localPath); } } else { // nothing tricky to do if (fillToDevMatrix) { fillToDevMatrix->reset(); } if (devPath) { if (fillPath == nullptr) { devPath->swap(path); } else { *devPath = path; } } if (fillPath) { fillPath->swap(path); } } if (devPath) { devPath->updateBoundsCache(); } if (fillPath) { fillPath->updateBoundsCache(); } }