From 85a216ce891c58c42cdb8b79985d8b3ee2bd1171 Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Fri, 7 Dec 2018 16:15:41 -0500 Subject: [PATCH] Convert bitmap device drawing to SkFont removing all LEGACY calls Change-Id: I096042a63395f361f758306993cdbb2621937aef Reviewed-on: https://skia-review.googlesource.com/c/175840 Reviewed-by: Mike Reed Commit-Queue: Herb Derby --- include/core/SkFont.h | 1 + src/core/SkGlyphRunPainter.cpp | 43 +++++++++++++++++----------------- src/core/SkGlyphRunPainter.h | 2 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/include/core/SkFont.h b/include/core/SkFont.h index 08928ae4ec..a27a142b06 100644 --- a/include/core/SkFont.h +++ b/include/core/SkFont.h @@ -495,6 +495,7 @@ private: void glyphsToUnichars(const SkGlyphID glyphs[], int count, SkUnichar text[]) const; friend class SkCanonicalizeFont; + friend class SkGlyphRunListPainter; friend class SkPaint; friend class SVGTextBuilder; }; diff --git a/src/core/SkGlyphRunPainter.cpp b/src/core/SkGlyphRunPainter.cpp index b1d0a0e439..09bcd11966 100644 --- a/src/core/SkGlyphRunPainter.cpp +++ b/src/core/SkGlyphRunPainter.cpp @@ -19,6 +19,7 @@ #include "SkDevice.h" #include "SkDistanceFieldGen.h" #include "SkDraw.h" +#include "SkFontPriv.h" #include "SkGlyphCache.h" #include "SkMaskFilter.h" #include "SkPaintPriv.h" @@ -101,7 +102,8 @@ SkGlyphRunListPainter::SkGlyphRunListPainter(const GrRenderTargetContext& rtc) #endif -bool SkGlyphRunListPainter::ShouldDrawAsPath(const SkPaint& paint, const SkMatrix& matrix) { +bool SkGlyphRunListPainter::ShouldDrawAsPath( + const SkPaint& paint, const SkFont& font, const SkMatrix& matrix) { // hairline glyphs are fast enough so we don't need to cache them if (SkPaint::kStroke_Style == paint.getStyle() && 0 == paint.getStrokeWidth()) { return true; @@ -112,9 +114,7 @@ bool SkGlyphRunListPainter::ShouldDrawAsPath(const SkPaint& paint, const SkMatri return true; } - SkMatrix textM; - SkPaintPriv::MakeTextMatrix(&textM, paint); - return SkPaint::TooBigToUseCache(matrix, textM, 1024); + return SkPaint::TooBigToUseCache(matrix, SkFontPriv::MakeTextMatrix(font), 1024); } void SkGlyphRunListPainter::ensureBitmapBuffers(size_t runSize) { @@ -161,28 +161,28 @@ void SkGlyphRunListPainter::drawForBitmapDevice( const BitmapDevicePainter* bitmapDevice) { SkPoint origin = glyphRunList.origin(); + const SkPaint& runPaint = glyphRunList.paint(); + // The bitmap blitters can only draw lcd text to a N32 bitmap in srcOver. Otherwise, + // convert the lcd text into A8 text. The props communicates this to the scaler. + auto& props = (kN32_SkColorType == fColorType && runPaint.isSrcOver()) + ? fDeviceProps + : fBitmapFallbackProps; for (auto& glyphRun : glyphRunList) { - // The bitmap blitters can only draw lcd text to a N32 bitmap in srcOver. Otherwise, - // convert the lcd text into A8 text. The props communicates this to the scaler. - auto& props = (kN32_SkColorType == fColorType && glyphRunList.paint().isSrcOver()) - ? fDeviceProps - : fBitmapFallbackProps; - - SkPaint paint{glyphRunList.paint()}; - glyphRun.font().LEGACY_applyToPaint(&paint); auto runSize = glyphRun.runSize(); this->ensureBitmapBuffers(runSize); - if (ShouldDrawAsPath(paint, deviceMatrix)) { + const SkFont& runFont = glyphRun.font(); + + if (ShouldDrawAsPath(runPaint, runFont, deviceMatrix)) { SkMatrix::MakeTrans(origin.x(), origin.y()).mapPoints( fPositions, glyphRun.positions().data(), runSize); // setup our std pathPaint, in hopes of getting hits in the cache - SkPaint pathPaint(paint); - SkScalar textScale = pathPaint.setupForAsPaths(); + SkPaint pathPaint(runPaint); + SkFont pathFont = runFont; + SkScalar textScale = pathFont.setupForAsPaths(&pathPaint); auto pathCache = SkStrikeCache::FindOrCreateStrikeExclusive( - SkFont::LEGACY_ExtractFromPaint(pathPaint), pathPaint, props, - fScalerContextFlags, SkMatrix::I()); + pathFont, pathPaint, props, fScalerContextFlags, SkMatrix::I()); SkTDArray pathsAndPositions; pathsAndPositions.setReserve(runSize); @@ -202,12 +202,10 @@ void SkGlyphRunListPainter::drawForBitmapDevice( bitmapDevice->paintPaths( SkSpan{pathsAndPositions.begin(), pathsAndPositions.size()}, - textScale, - paint); + textScale, runPaint); } else { auto cache = SkStrikeCache::FindOrCreateStrikeExclusive( - SkFont::LEGACY_ExtractFromPaint(paint), paint, props, - fScalerContextFlags, deviceMatrix); + runFont, runPaint, props, fScalerContextFlags, deviceMatrix); // Add rounding and origin. SkMatrix matrix = deviceMatrix; @@ -229,7 +227,8 @@ void SkGlyphRunListPainter::drawForBitmapDevice( } } } - bitmapDevice->paintMasks(SkSpan{masks.begin(), masks.size()}, paint); + bitmapDevice->paintMasks( + SkSpan{masks.begin(), masks.size()}, runPaint); } } } diff --git a/src/core/SkGlyphRunPainter.h b/src/core/SkGlyphRunPainter.h index abe36da38f..cd50048cad 100644 --- a/src/core/SkGlyphRunPainter.h +++ b/src/core/SkGlyphRunPainter.h @@ -107,7 +107,7 @@ public: PerEmptyT&& perEmpty, PerSDFT&& perSDF, PerPathT&& perPath, ARGBFallback&& perFallback); private: - static bool ShouldDrawAsPath(const SkPaint& paint, const SkMatrix& matrix); + static bool ShouldDrawAsPath(const SkPaint& paint, const SkFont& font, const SkMatrix& matrix); void ensureBitmapBuffers(size_t runSize); void processARGBFallback(