diff options
author | Khushal <khushalsagar@chromium.org> | 2018-05-23 15:45:01 -0700 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-05-24 01:11:21 +0000 |
commit | 3e7548ca60d9139b650e1f099e6c724b3711dd81 (patch) | |
tree | b12b2d045d8844214bfac0161676e0994bf93783 /src/core | |
parent | daef06ae3bdf6b61bdd13ed1eeb20f51fbedd763 (diff) |
Reland fonts: Add support for distance field text to font remoting.
This reverts commit 7257e22e43a56a5f4f772b687034580061cd011f.
TBR=herb@google.com, bsalomon@google.com
Bug: skia:7913
Change-Id: I51ca5bccdda64cd98e2ad59874e7136ee58cec10
Reviewed-on: https://skia-review.googlesource.com/129809
Reviewed-by: Khusal Sagar <khushalsagar@chromium.org>
Commit-Queue: Khusal Sagar <khushalsagar@chromium.org>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkRemoteGlyphCache.cpp | 69 | ||||
-rw-r--r-- | src/core/SkRemoteGlyphCache.h | 17 |
2 files changed, 71 insertions, 15 deletions
diff --git a/src/core/SkRemoteGlyphCache.cpp b/src/core/SkRemoteGlyphCache.cpp index c7f1f4497b..d5e96fce88 100644 --- a/src/core/SkRemoteGlyphCache.cpp +++ b/src/core/SkRemoteGlyphCache.cpp @@ -23,6 +23,7 @@ #if SK_SUPPORT_GPU #include "GrDrawOpAtlas.h" +#include "text/GrAtlasTextContext.h" #endif static SkDescriptor* auto_descriptor_from_desc(const SkDescriptor* source_desc, @@ -188,14 +189,18 @@ public: }; // -- SkTextBlobCacheDiffCanvas ------------------------------------------------------------------- +SkTextBlobCacheDiffCanvas::Settings::Settings() = default; +SkTextBlobCacheDiffCanvas::Settings::~Settings() = default; + SkTextBlobCacheDiffCanvas::SkTextBlobCacheDiffCanvas(int width, int height, const SkMatrix& deviceMatrix, const SkSurfaceProps& props, - SkStrikeServer* strikeSever) + SkStrikeServer* strikeSever, Settings settings) : SkNoDrawCanvas{sk_make_sp<TrackLayerDevice>(SkIRect::MakeWH(width, height), props)} , fDeviceMatrix{deviceMatrix} , fSurfaceProps{props} - , fStrikeServer{strikeSever} { + , fStrikeServer{strikeSever} + , fSettings{settings} { SkASSERT(fStrikeServer); } @@ -274,6 +279,23 @@ void SkTextBlobCacheDiffCanvas::processGlyphRun( runMatrix.preTranslate(position.x(), position.y()); runMatrix.preTranslate(it.offset().x(), it.offset().y()); +#if SK_SUPPORT_GPU + GrAtlasTextContext::Options options; + options.fMinDistanceFieldFontSize = fSettings.fMinDistanceFieldFontSize; + options.fMaxDistanceFieldFontSize = fSettings.fMaxDistanceFieldFontSize; + GrAtlasTextContext::SanitizeOptions(&options); + if (GrAtlasTextContext::CanDrawAsDistanceFields(runPaint, runMatrix, fSurfaceProps, + fSettings.fContextSupportsDistanceFieldText, + options)) { + SkScalar textRatio; + SkPaint dfPaint(runPaint); + SkScalerContextFlags flags; + GrAtlasTextContext::InitDistanceFieldPaint(nullptr, &dfPaint, runMatrix, options, + &textRatio, &flags); + this->processGlyphRunForDFT(it, dfPaint, flags); + } +#endif + // If the matrix has perspective, we fall back to using distance field text or paths. // TODO: Add distance field text support, and FallbackTextHelper logic from GrAtlasTextContext. if (SkDraw::ShouldDrawTextAsPaths(runPaint, runMatrix)) { @@ -334,9 +356,11 @@ void SkTextBlobCacheDiffCanvas::processGlyphRun( SkScalerContextRec deviceSpecificRec; SkScalerContextEffects effects; - auto* glyphCacheState = static_cast<SkStrikeServer*>(fStrikeServer) - ->getOrCreateCache(runPaint, &fSurfaceProps, &runMatrix, - &deviceSpecificRec, &effects); + auto* glyphCacheState = + static_cast<SkStrikeServer*>(fStrikeServer) + ->getOrCreateCache(runPaint, &fSurfaceProps, &runMatrix, + SkScalerContextFlags::kFakeGammaAndBoostContrast, + &deviceSpecificRec, &effects); SkASSERT(glyphCacheState); const bool asPath = false; @@ -371,11 +395,33 @@ void SkTextBlobCacheDiffCanvas::processGlyphRunForPaths(const SkTextBlobRunItera SkScalerContextRec deviceSpecificRec; SkScalerContextEffects effects; + auto* glyphCacheState = + static_cast<SkStrikeServer*>(fStrikeServer) + ->getOrCreateCache(pathPaint, &fSurfaceProps, nullptr, + SkScalerContextFlags::kFakeGammaAndBoostContrast, + &deviceSpecificRec, &effects); + + const bool asPath = true; + const SkIPoint subPixelPos{0, 0}; + const uint16_t* glyphs = it.glyphs(); + for (uint32_t index = 0; index < it.glyphCount(); index++) { + glyphCacheState->addGlyph(runPaint.getTypeface(), + effects, + SkPackedGlyphID(glyphs[index], subPixelPos.x(), subPixelPos.y()), + asPath); + } +} + +void SkTextBlobCacheDiffCanvas::processGlyphRunForDFT(const SkTextBlobRunIterator& it, + const SkPaint& runPaint, + SkScalerContextFlags flags) { + SkScalerContextRec deviceSpecificRec; + SkScalerContextEffects effects; auto* glyphCacheState = static_cast<SkStrikeServer*>(fStrikeServer) - ->getOrCreateCache(pathPaint, &fSurfaceProps, nullptr, + ->getOrCreateCache(runPaint, &fSurfaceProps, nullptr, flags, &deviceSpecificRec, &effects); - const bool asPath = true; + const bool asPath = false; const SkIPoint subPixelPos{0, 0}; const uint16_t* glyphs = it.glyphs(); for (uint32_t index = 0; index < it.glyphCount(); index++) { @@ -451,15 +497,12 @@ SkStrikeServer::SkGlyphCacheState* SkStrikeServer::getOrCreateCache( const SkPaint& paint, const SkSurfaceProps* props, const SkMatrix* matrix, + SkScalerContextFlags flags, SkScalerContextRec* deviceRec, SkScalerContextEffects* effects) { SkScalerContextRec keyRec; - SkScalerContext::MakeRecAndEffects(paint, props, matrix, - SkScalerContextFlags::kFakeGammaAndBoostContrast, deviceRec, - effects, true); - SkScalerContext::MakeRecAndEffects(paint, props, matrix, - SkScalerContextFlags::kFakeGammaAndBoostContrast, &keyRec, - effects, false); + SkScalerContext::MakeRecAndEffects(paint, props, matrix, flags, deviceRec, effects, true); + SkScalerContext::MakeRecAndEffects(paint, props, matrix, flags, &keyRec, effects, false); TRACE_EVENT1("skia", "RecForDesc", "rec", TRACE_STR_COPY(keyRec.dump().c_str())); // TODO: possible perf improvement - don't recompute the device desc on cache hit. diff --git a/src/core/SkRemoteGlyphCache.h b/src/core/SkRemoteGlyphCache.h index 60d880791f..d1119cf70a 100644 --- a/src/core/SkRemoteGlyphCache.h +++ b/src/core/SkRemoteGlyphCache.h @@ -28,6 +28,7 @@ class Serializer; class SkDescriptor; class SkGlyphCache; struct SkPackedGlyphID; +enum SkScalerContextFlags : uint32_t; class SkScalerContextRecDescriptor; class SkTextBlobRunIterator; class SkTypefaceProxy; @@ -51,8 +52,17 @@ using SkDescriptorSet = // which will be serialized and renderered using the SkStrikeClient. class SK_API SkTextBlobCacheDiffCanvas : public SkNoDrawCanvas { public: + struct SK_API Settings { + Settings(); + ~Settings(); + + bool fContextSupportsDistanceFieldText = true; + SkScalar fMinDistanceFieldFontSize = -1.f; + SkScalar fMaxDistanceFieldFontSize = -1.f; + }; SkTextBlobCacheDiffCanvas(int width, int height, const SkMatrix& deviceMatrix, - const SkSurfaceProps& props, SkStrikeServer* strikeserver); + const SkSurfaceProps& props, SkStrikeServer* strikeserver, + Settings settings = Settings()); ~SkTextBlobCacheDiffCanvas() override; protected: @@ -70,10 +80,13 @@ private: const SkTextBlobRunIterator& it, const SkPaint& runPaint); void processGlyphRunForPaths(const SkTextBlobRunIterator& it, const SkPaint& runPaint); + void processGlyphRunForDFT(const SkTextBlobRunIterator& it, const SkPaint& runPaint, + SkScalerContextFlags flags); const SkMatrix fDeviceMatrix; const SkSurfaceProps fSurfaceProps; SkStrikeServer* const fStrikeServer; + const Settings fSettings; }; using SkDiscardableHandleId = uint32_t; @@ -161,7 +174,7 @@ public: }; SkGlyphCacheState* getOrCreateCache(const SkPaint&, const SkSurfaceProps*, const SkMatrix*, - SkScalerContextRec* deviceRec, + SkScalerContextFlags flags, SkScalerContextRec* deviceRec, SkScalerContextEffects* effects); private: |