From 74c6ed3d1f179209ec90025532310d9c8151999f Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Sat, 28 Jul 2018 18:07:54 -0400 Subject: Move one leaf loop from GPU to glyph drawer Encapsulate the bitmap inner loop of regenerate in the SkGlyphRunListDrawer. This changed required placing an SkGlyphRunListDrawer in the two TextTargets. Change-Id: I7ef7a2d0074fe898fce4da82d26ea1f47e1f7a98 Reviewed-on: https://skia-review.googlesource.com/144302 Reviewed-by: Jim Van Verth Reviewed-by: Brian Salomon Commit-Queue: Herb Derby --- src/core/SkGlyphRun.cpp | 57 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 12 deletions(-) (limited to 'src/core/SkGlyphRun.cpp') diff --git a/src/core/SkGlyphRun.cpp b/src/core/SkGlyphRun.cpp index f53f90986e..1a24c3bdb9 100644 --- a/src/core/SkGlyphRun.cpp +++ b/src/core/SkGlyphRun.cpp @@ -11,6 +11,11 @@ #include #include +#if SK_SUPPORT_GPU +#include "GrColorSpaceInfo.h" +#include "GrRenderTargetContext.h" +#endif + #include "SkDevice.h" #include "SkDraw.h" #include "SkFindAndPlaceGlyph.h" @@ -109,6 +114,29 @@ SkGlyphRunListDrawer::SkGlyphRunListDrawer( , fColorType{colorType} , fScalerContextFlags{flags} {} +#if SK_SUPPORT_GPU + +// TODO: unify with code in GrTextContext.cpp +static SkScalerContextFlags compute_scaler_context_flags( + const GrColorSpaceInfo& colorSpaceInfo) { + // If we're doing linear blending, then we can disable the gamma hacks. + // Otherwise, leave them on. In either case, we still want the contrast boost: + // TODO: Can we be even smarter about mask gamma based on the dest transfer function? + if (colorSpaceInfo.isLinearlyBlended()) { + return SkScalerContextFlags::kBoostContrast; + } else { + return SkScalerContextFlags::kFakeGammaAndBoostContrast; + } +} + +SkGlyphRunListDrawer::SkGlyphRunListDrawer( + const SkSurfaceProps& props, const GrColorSpaceInfo& csi) + : SkGlyphRunListDrawer(props, kUnknown_SkColorType, compute_scaler_context_flags(csi)) {} + +SkGlyphRunListDrawer::SkGlyphRunListDrawer(const GrRenderTargetContext& rtc) + : SkGlyphRunListDrawer{rtc.surfaceProps(), rtc.colorSpaceInfo()} {} +#endif + bool SkGlyphRunListDrawer::ShouldDrawAsPath(const SkPaint& paint, 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()) { @@ -134,7 +162,7 @@ bool SkGlyphRunListDrawer::ensureBitmapBuffers(size_t runSize) { return true; } -void SkGlyphRunListDrawer::drawGlyphRunAsPaths( +void SkGlyphRunListDrawer::drawUsingPaths( const SkGlyphRun& glyphRun, SkPoint origin, const SkSurfaceProps& props, PerPath perPath) const { // setup our std paint, in hopes of getting hits in the cache @@ -243,7 +271,7 @@ void SkGlyphRunListDrawer::drawGlyphRunAsSubpixelMask( const SkGlyph& glyph = cache->getGlyphIDMetrics(glyphID, lookupX, lookupY); SkMask mask; if (prepare_mask(cache, glyph, position, &mask)) { - perMask(mask); + perMask(mask, glyph, position); } } } @@ -270,14 +298,14 @@ void SkGlyphRunListDrawer::drawGlyphRunAsFullpixelMask( const SkGlyph& glyph = cache->getGlyphIDMetrics(glyphID); SkMask mask; if (prepare_mask(cache, glyph, position, &mask)) { - perMask(mask); + perMask(mask, glyph, position); } } } } } -void SkGlyphRunListDrawer::drawForBitmap( +void SkGlyphRunListDrawer::drawForBitmapDevice( const SkGlyphRunList& glyphRunList, const SkMatrix& deviceMatrix, PerMaskCreator perMaskCreator, PerPathCreator perPathCreator) { @@ -292,22 +320,27 @@ void SkGlyphRunListDrawer::drawForBitmap( auto paint = glyphRun.paint(); if (ShouldDrawAsPath(glyphRun.paint(), deviceMatrix)) { auto perPath = perPathCreator(paint, &alloc); - this->drawGlyphRunAsPaths(glyphRun, origin, props, perPath); + this->drawUsingPaths(glyphRun, origin, props, perPath); } else { auto cache = SkStrikeCache::FindOrCreateStrikeExclusive( paint, &props, fScalerContextFlags, &deviceMatrix); auto perMask = perMaskCreator(paint, &alloc); - if (cache->isSubpixel()) { - this->drawGlyphRunAsSubpixelMask( - cache.get(), glyphRun, origin, deviceMatrix, perMask); - } else { - this->drawGlyphRunAsFullpixelMask( - cache.get(), glyphRun, origin, deviceMatrix, perMask); - } + this->drawUsingMasks(cache.get(), glyphRun, origin, deviceMatrix, perMask); } } } +void SkGlyphRunListDrawer::drawUsingMasks( + SkGlyphCache* cache, const SkGlyphRun& glyphRun, + SkPoint origin, const SkMatrix& deviceMatrix, + SkGlyphRunListDrawer::PerMask perMask) { + if (cache->isSubpixel()) { + this->drawGlyphRunAsSubpixelMask(cache, glyphRun, origin, deviceMatrix, perMask); + } else { + this->drawGlyphRunAsFullpixelMask(cache, glyphRun, origin, deviceMatrix, perMask); + } +} + // -- SkGlyphRunList ------------------------------------------------------------------------------- SkGlyphRunList::SkGlyphRunList() = default; SkGlyphRunList::SkGlyphRunList( -- cgit v1.2.3