diff options
author | 2018-05-23 00:15:37 +0000 | |
---|---|---|
committer | 2018-05-23 00:17:16 +0000 | |
commit | 7257e22e43a56a5f4f772b687034580061cd011f (patch) | |
tree | c7f8b54f2d35b3be50309f559ac886a0ec9ddb7a /src | |
parent | fc6cf92e4b21c92ead769fae557534056eac6d83 (diff) |
Revert "fonts: Add support for distance field text to font remoting."
This reverts commit 35e0a1a6908492c754156d1abb785da3a9ce2a6b.
Reason for revert: looks like we're leaking paths?
https://chromium-swarm.appspot.com/task?id=3da25e2f0cadb210&refresh=10
Original change's description:
> fonts: Add support for distance field text to font remoting.
>
> R=jvanverth@google.com, herb@google.com
>
> Bug: skia:7913
> Change-Id: Id3f5b3e75005be9a7234df774268359b406c99a8
> Reviewed-on: https://skia-review.googlesource.com/128970
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Reviewed-by: Jim Van Verth <jvanverth@google.com>
> Commit-Queue: Khusal Sagar <khushalsagar@chromium.org>
TBR=jvanverth@google.com,bsalomon@google.com,bungeman@google.com,herb@google.com,khushalsagar@chromium.org
Change-Id: I37c54c8748db9b20e1f48016d8298808a1999fdb
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:7913
Reviewed-on: https://skia-review.googlesource.com/129681
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkRemoteGlyphCache.cpp | 69 | ||||
-rw-r--r-- | src/core/SkRemoteGlyphCache.h | 17 | ||||
-rw-r--r-- | src/gpu/GrContext.cpp | 4 | ||||
-rw-r--r-- | src/gpu/GrShaderCaps.h | 2 | ||||
-rw-r--r-- | src/gpu/text/GrAtlasTextContext.cpp | 68 | ||||
-rw-r--r-- | src/gpu/text/GrAtlasTextContext.h | 24 |
6 files changed, 53 insertions, 131 deletions
diff --git a/src/core/SkRemoteGlyphCache.cpp b/src/core/SkRemoteGlyphCache.cpp index d5e96fce88..c7f1f4497b 100644 --- a/src/core/SkRemoteGlyphCache.cpp +++ b/src/core/SkRemoteGlyphCache.cpp @@ -23,7 +23,6 @@ #if SK_SUPPORT_GPU #include "GrDrawOpAtlas.h" -#include "text/GrAtlasTextContext.h" #endif static SkDescriptor* auto_descriptor_from_desc(const SkDescriptor* source_desc, @@ -189,18 +188,14 @@ public: }; // -- SkTextBlobCacheDiffCanvas ------------------------------------------------------------------- -SkTextBlobCacheDiffCanvas::Settings::Settings() = default; -SkTextBlobCacheDiffCanvas::Settings::~Settings() = default; - SkTextBlobCacheDiffCanvas::SkTextBlobCacheDiffCanvas(int width, int height, const SkMatrix& deviceMatrix, const SkSurfaceProps& props, - SkStrikeServer* strikeSever, Settings settings) + SkStrikeServer* strikeSever) : SkNoDrawCanvas{sk_make_sp<TrackLayerDevice>(SkIRect::MakeWH(width, height), props)} , fDeviceMatrix{deviceMatrix} , fSurfaceProps{props} - , fStrikeServer{strikeSever} - , fSettings{settings} { + , fStrikeServer{strikeSever} { SkASSERT(fStrikeServer); } @@ -279,23 +274,6 @@ 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)) { @@ -356,11 +334,9 @@ void SkTextBlobCacheDiffCanvas::processGlyphRun( SkScalerContextRec deviceSpecificRec; SkScalerContextEffects effects; - auto* glyphCacheState = - static_cast<SkStrikeServer*>(fStrikeServer) - ->getOrCreateCache(runPaint, &fSurfaceProps, &runMatrix, - SkScalerContextFlags::kFakeGammaAndBoostContrast, - &deviceSpecificRec, &effects); + auto* glyphCacheState = static_cast<SkStrikeServer*>(fStrikeServer) + ->getOrCreateCache(runPaint, &fSurfaceProps, &runMatrix, + &deviceSpecificRec, &effects); SkASSERT(glyphCacheState); const bool asPath = false; @@ -395,33 +371,11 @@ 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(runPaint, &fSurfaceProps, nullptr, flags, + ->getOrCreateCache(pathPaint, &fSurfaceProps, nullptr, &deviceSpecificRec, &effects); - const bool asPath = false; + const bool asPath = true; const SkIPoint subPixelPos{0, 0}; const uint16_t* glyphs = it.glyphs(); for (uint32_t index = 0; index < it.glyphCount(); index++) { @@ -497,12 +451,15 @@ 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, flags, deviceRec, effects, true); - SkScalerContext::MakeRecAndEffects(paint, props, matrix, flags, &keyRec, effects, false); + SkScalerContext::MakeRecAndEffects(paint, props, matrix, + SkScalerContextFlags::kFakeGammaAndBoostContrast, deviceRec, + effects, true); + SkScalerContext::MakeRecAndEffects(paint, props, matrix, + SkScalerContextFlags::kFakeGammaAndBoostContrast, &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 d1119cf70a..60d880791f 100644 --- a/src/core/SkRemoteGlyphCache.h +++ b/src/core/SkRemoteGlyphCache.h @@ -28,7 +28,6 @@ class Serializer; class SkDescriptor; class SkGlyphCache; struct SkPackedGlyphID; -enum SkScalerContextFlags : uint32_t; class SkScalerContextRecDescriptor; class SkTextBlobRunIterator; class SkTypefaceProxy; @@ -52,17 +51,8 @@ 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, - Settings settings = Settings()); + const SkSurfaceProps& props, SkStrikeServer* strikeserver); ~SkTextBlobCacheDiffCanvas() override; protected: @@ -80,13 +70,10 @@ 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; @@ -174,7 +161,7 @@ public: }; SkGlyphCacheState* getOrCreateCache(const SkPaint&, const SkSurfaceProps*, const SkMatrix*, - SkScalerContextFlags flags, SkScalerContextRec* deviceRec, + SkScalerContextRec* deviceRec, SkScalerContextEffects* effects); private: diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 24c28e6d86..5be510d131 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -1514,10 +1514,6 @@ bool GrContext::validPMUPMConversionExists() { return fPMUPMConversionsRoundTrip; } -bool GrContext::supportsDistanceFieldText() const { - return fCaps->shaderCaps()->supportsDistanceFieldText(); -} - ////////////////////////////////////////////////////////////////////////////// // DDL TODO: remove 'maxResources' diff --git a/src/gpu/GrShaderCaps.h b/src/gpu/GrShaderCaps.h index 3e85b6c1aa..2f2d27708a 100644 --- a/src/gpu/GrShaderCaps.h +++ b/src/gpu/GrShaderCaps.h @@ -37,8 +37,6 @@ public: void dumpJSON(SkJSONWriter*) const; - bool supportsDistanceFieldText() const { return fShaderDerivativeSupport; } - bool shaderDerivativeSupport() const { return fShaderDerivativeSupport; } bool geometryShaderSupport() const { return fGeometryShaderSupport; } bool gsInvocationsSupport() const { return fGSInvocationsSupport; } diff --git a/src/gpu/text/GrAtlasTextContext.cpp b/src/gpu/text/GrAtlasTextContext.cpp index 1f06cfefba..8c964ba35e 100644 --- a/src/gpu/text/GrAtlasTextContext.cpp +++ b/src/gpu/text/GrAtlasTextContext.cpp @@ -41,8 +41,14 @@ static const int kDefaultMaxDistanceFieldFontSize = 2 * kLargeDFFontSize; #endif GrAtlasTextContext::GrAtlasTextContext(const Options& options) - : fDistanceAdjustTable(new GrDistanceFieldAdjustTable), fOptions(options) { - SanitizeOptions(&fOptions); + : fDistanceAdjustTable(new GrDistanceFieldAdjustTable) { + fMaxDistanceFieldFontSize = options.fMaxDistanceFieldFontSize < 0.f + ? kDefaultMaxDistanceFieldFontSize + : options.fMaxDistanceFieldFontSize; + fMinDistanceFieldFontSize = options.fMinDistanceFieldFontSize < 0.f + ? kDefaultMinDistanceFieldFontSize + : options.fMinDistanceFieldFontSize; + fDistanceFieldVerticesAlwaysHaveW = options.fDistanceFieldVerticesAlwaysHaveW; } std::unique_ptr<GrAtlasTextContext> GrAtlasTextContext::Make(const Options& options) { @@ -205,8 +211,7 @@ void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob, } cacheBlob->setRunPaintFlags(run, runPaint.skPaint().getFlags()); - if (CanDrawAsDistanceFields(runPaint, viewMatrix, props, - shaderCaps.supportsDistanceFieldText(), fOptions)) { + if (this->canDrawAsDistanceFields(runPaint, viewMatrix, props, shaderCaps)) { switch (it.positioning()) { case SkTextBlob::kDefault_Positioning: { this->drawDFText(cacheBlob, run, glyphCache, props, runPaint, scalerContextFlags, @@ -269,8 +274,7 @@ GrAtlasTextContext::makeDrawTextBlob(GrTextBlobCache* blobCache, blob->initThrowawayBlob(viewMatrix, x, y); blob->setRunPaintFlags(0, paint.skPaint().getFlags()); - if (CanDrawAsDistanceFields(paint, viewMatrix, props, shaderCaps.supportsDistanceFieldText(), - fOptions)) { + if (this->canDrawAsDistanceFields(paint, viewMatrix, props, shaderCaps)) { this->drawDFText(blob.get(), 0, glyphCache, props, paint, scalerContextFlags, viewMatrix, text, byteLength, x, y); } else { @@ -300,8 +304,7 @@ GrAtlasTextContext::makeDrawPosTextBlob(GrTextBlobCache* blobCache, blob->initThrowawayBlob(viewMatrix, offset.x(), offset.y()); blob->setRunPaintFlags(0, paint.skPaint().getFlags()); - if (CanDrawAsDistanceFields(paint, viewMatrix, props, shaderCaps.supportsDistanceFieldText(), - fOptions)) { + if (this->canDrawAsDistanceFields(paint, viewMatrix, props, shaderCaps)) { this->drawDFPosText(blob.get(), 0, glyphCache, props, paint, scalerContextFlags, viewMatrix, text, byteLength, pos, scalarsPerPosition, offset); } else { @@ -562,26 +565,16 @@ void GrAtlasTextContext::BmpAppendGlyph(GrAtlasTextBlob* blob, int runIndex, textRatio, true); } -void GrAtlasTextContext::SanitizeOptions(Options* options) { - if (options->fMaxDistanceFieldFontSize < 0.f) { - options->fMaxDistanceFieldFontSize = kDefaultMaxDistanceFieldFontSize; - } - if (options->fMinDistanceFieldFontSize < 0.f) { - options->fMinDistanceFieldFontSize = kDefaultMinDistanceFieldFontSize; - } -} - -bool GrAtlasTextContext::CanDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix, +bool GrAtlasTextContext::canDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix, const SkSurfaceProps& props, - bool contextSupportsDistanceFieldText, - const Options& options) { + const GrShaderCaps& caps) const { if (!viewMatrix.hasPerspective()) { SkScalar maxScale = viewMatrix.getMaxScale(); SkScalar scaledTextSize = maxScale * skPaint.getTextSize(); // Hinted text looks far better at small resolutions // Scaling up beyond 2x yields undesireable artifacts - if (scaledTextSize < options.fMinDistanceFieldFontSize || - scaledTextSize > options.fMaxDistanceFieldFontSize) { + if (scaledTextSize < fMinDistanceFieldFontSize || + scaledTextSize > fMaxDistanceFieldFontSize) { return false; } @@ -596,7 +589,7 @@ bool GrAtlasTextContext::CanDrawAsDistanceFields(const SkPaint& skPaint, const S } // mask filters modify alpha, which doesn't translate well to distance - if (skPaint.getMaskFilter() || !contextSupportsDistanceFieldText) { + if (skPaint.getMaskFilter() || !caps.shaderDerivativeSupport()) { return false; } @@ -608,12 +601,10 @@ bool GrAtlasTextContext::CanDrawAsDistanceFields(const SkPaint& skPaint, const S return true; } -void GrAtlasTextContext::InitDistanceFieldPaint(GrAtlasTextBlob* blob, +void GrAtlasTextContext::initDistanceFieldPaint(GrAtlasTextBlob* blob, SkPaint* skPaint, - const SkMatrix& viewMatrix, - const Options& options, SkScalar* textRatio, - SkScalerContextFlags* flags) { + const SkMatrix& viewMatrix) const { SkScalar textSize = skPaint->getTextSize(); SkScalar scaledTextSize = textSize; @@ -636,7 +627,7 @@ void GrAtlasTextContext::InitDistanceFieldPaint(GrAtlasTextBlob* blob, SkScalar dfMaskScaleFloor; SkScalar dfMaskScaleCeil; if (scaledTextSize <= kSmallDFFontLimit) { - dfMaskScaleFloor = options.fMinDistanceFieldFontSize; + dfMaskScaleFloor = fMinDistanceFieldFontSize; dfMaskScaleCeil = kSmallDFFontLimit; *textRatio = textSize / kSmallDFFontSize; skPaint->setTextSize(SkIntToScalar(kSmallDFFontSize)); @@ -647,7 +638,7 @@ void GrAtlasTextContext::InitDistanceFieldPaint(GrAtlasTextBlob* blob, skPaint->setTextSize(SkIntToScalar(kMediumDFFontSize)); } else { dfMaskScaleFloor = kMediumDFFontLimit; - dfMaskScaleCeil = options.fMaxDistanceFieldFontSize; + dfMaskScaleCeil = fMaxDistanceFieldFontSize; *textRatio = textSize / kLargeDFFontSize; skPaint->setTextSize(SkIntToScalar(kLargeDFFontSize)); } @@ -660,10 +651,7 @@ void GrAtlasTextContext::InitDistanceFieldPaint(GrAtlasTextBlob* blob, // against these values to decide if we can reuse or not(ie, will a given scale change our mip // level) SkASSERT(dfMaskScaleFloor <= scaledTextSize && scaledTextSize <= dfMaskScaleCeil); - if (blob) { - blob->setMinAndMaxScale(dfMaskScaleFloor / scaledTextSize, - dfMaskScaleCeil / scaledTextSize); - } + blob->setMinAndMaxScale(dfMaskScaleFloor / scaledTextSize, dfMaskScaleCeil / scaledTextSize); skPaint->setAntiAlias(true); skPaint->setLCDRenderText(false); @@ -672,10 +660,6 @@ void GrAtlasTextContext::InitDistanceFieldPaint(GrAtlasTextBlob* blob, skPaint->setSubpixelText(true); skPaint->setMaskFilter(GrSDFMaskFilter::Make()); - - // We apply the fake-gamma by altering the distance in the shader, so we ignore the - // passed-in scaler context flags. (It's only used when we fall-back to bitmap text). - *flags = SkScalerContextFlags::kNone; } void GrAtlasTextContext::drawDFText(GrAtlasTextBlob* blob, int runIndex, @@ -761,13 +745,12 @@ void GrAtlasTextContext::drawDFPosText(GrAtlasTextBlob* blob, int runIndex, return; } - bool hasWCoord = viewMatrix.hasPerspective() || fOptions.fDistanceFieldVerticesAlwaysHaveW; + bool hasWCoord = viewMatrix.hasPerspective() || fDistanceFieldVerticesAlwaysHaveW; // Setup distance field paint and text ratio SkScalar textRatio; SkPaint dfPaint(paint); - SkScalerContextFlags flags; - InitDistanceFieldPaint(blob, &dfPaint, viewMatrix, fOptions, &textRatio, &flags); + this->initDistanceFieldPaint(blob, &dfPaint, &textRatio, viewMatrix); blob->setHasDistanceField(); blob->setSubRunHasDistanceFields(runIndex, paint.skPaint().isLCDRenderText(), paint.skPaint().isAntiAlias(), hasWCoord); @@ -777,7 +760,10 @@ void GrAtlasTextContext::drawDFPosText(GrAtlasTextBlob* blob, int runIndex, sk_sp<GrTextStrike> currStrike; { - auto cache = blob->setupCache(runIndex, props, flags, dfPaint, nullptr); + // We apply the fake-gamma by altering the distance in the shader, so we ignore the + // passed-in scaler context flags. (It's only used when we fall-back to bitmap text). + auto cache = blob->setupCache(runIndex, props, SkScalerContextFlags::kNone, dfPaint, + nullptr); SkPaint::GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(dfPaint.getTextEncoding(), true); diff --git a/src/gpu/text/GrAtlasTextContext.h b/src/gpu/text/GrAtlasTextContext.h index e2531b3d59..1342ee7ac8 100644 --- a/src/gpu/text/GrAtlasTextContext.h +++ b/src/gpu/text/GrAtlasTextContext.h @@ -60,18 +60,6 @@ public: const SkMatrix& viewMatrix, const char* text, int x, int y); - static void SanitizeOptions(Options* options); - static bool CanDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix, - const SkSurfaceProps& props, - bool contextSupportsDistanceFieldText, - const Options& options); - static void InitDistanceFieldPaint(GrAtlasTextBlob* blob, - SkPaint* skPaint, - const SkMatrix& viewMatrix, - const Options& options, - SkScalar* textRatio, - SkScalerContextFlags* flags); - private: GrAtlasTextContext(const Options& options); @@ -170,6 +158,9 @@ private: const SkPoint& offset); // functions for appending distance field text + bool canDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix, + const SkSurfaceProps& props, const GrShaderCaps& caps) const; + void drawDFText(GrAtlasTextBlob* blob, int runIndex, GrGlyphCache*, const SkSurfaceProps&, const GrTextUtils::Paint& paint, SkScalerContextFlags scalerContextFlags, const SkMatrix& viewMatrix, const char text[], size_t byteLength, SkScalar x, @@ -182,6 +173,11 @@ private: size_t byteLength, const SkScalar pos[], int scalarsPerPosition, const SkPoint& offset) const; + void initDistanceFieldPaint(GrAtlasTextBlob* blob, + SkPaint* skPaint, + SkScalar* textRatio, + const SkMatrix& viewMatrix) const; + static void BmpAppendGlyph(GrAtlasTextBlob*, int runIndex, GrGlyphCache*, sk_sp<GrTextStrike>*, const SkGlyph&, SkScalar sx, SkScalar sy, GrColor color, SkGlyphCache*, SkScalar textRatio); @@ -194,7 +190,9 @@ private: sk_sp<const GrDistanceFieldAdjustTable> fDistanceAdjustTable; - Options fOptions; + SkScalar fMinDistanceFieldFontSize; + SkScalar fMaxDistanceFieldFontSize; + bool fDistanceFieldVerticesAlwaysHaveW; #if GR_TEST_UTILS static const SkScalerContextFlags kTextBlobOpScalerContextFlags = |