diff options
author | Herb Derby <herb@google.com> | 2018-04-18 11:36:12 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-04-18 22:07:13 +0000 |
commit | fa996908466f96ab21908258283995ccec40f2a5 (patch) | |
tree | 40bdfee106e42794fd7595207e974a2a6a4816e5 /src/core | |
parent | 881091f62ea5bbcc8c9f856c12aef3c74f9bf991 (diff) |
Move strike cache Find*() to strike cache
BUG=skia:7515
Change-Id: Ic1580d4752d51a62df5427a28f843bc7b3181797
Reviewed-on: https://skia-review.googlesource.com/122020
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkDraw.cpp | 6 | ||||
-rw-r--r-- | src/core/SkGlyphCache.cpp | 33 | ||||
-rw-r--r-- | src/core/SkGlyphCache.h | 22 | ||||
-rw-r--r-- | src/core/SkOverdrawCanvas.cpp | 4 | ||||
-rw-r--r-- | src/core/SkPaint.cpp | 16 | ||||
-rw-r--r-- | src/core/SkRemoteGlyphCache.cpp | 4 | ||||
-rw-r--r-- | src/core/SkStrikeCache.cpp | 34 | ||||
-rw-r--r-- | src/core/SkStrikeCache.h | 19 |
8 files changed, 66 insertions, 72 deletions
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp index f205080c25..71d0d13463 100644 --- a/src/core/SkDraw.cpp +++ b/src/core/SkDraw.cpp @@ -1543,7 +1543,7 @@ void SkDraw::drawText(const char text[], size_t byteLength, SkScalar x, SkScalar return; } - auto cache = SkGlyphCache::FindOrCreateStrikeExclusive( + auto cache = SkStrikeCache::FindOrCreateStrikeExclusive( paint, props, this->scalerContextFlags(), fMatrix); // The Blitter Choose needs to be live while using the blitter below. @@ -1575,7 +1575,7 @@ void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength, const SkS SkPaint::GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(paint.getTextEncoding(), paint.isDevKernText(), true); - auto cache = SkGlyphCache::FindOrCreateStrikeExclusive( + auto cache = SkStrikeCache::FindOrCreateStrikeExclusive( paint, props, this->scalerContextFlags(), nullptr); const char* stop = text + byteLength; @@ -1623,7 +1623,7 @@ void SkDraw::drawPosText(const char text[], size_t byteLength, const SkScalar po return; } - auto cache = SkGlyphCache::FindOrCreateStrikeExclusive( + auto cache = SkStrikeCache::FindOrCreateStrikeExclusive( paint, props, this->scalerContextFlags(), fMatrix); // The Blitter Choose needs to be live while using the blitter below. diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp index 5327d1accb..3475b6037d 100644 --- a/src/core/SkGlyphCache.cpp +++ b/src/core/SkGlyphCache.cpp @@ -9,7 +9,6 @@ #include "SkGraphics.h" #include "SkMutex.h" #include "SkOnce.h" -#include "SkPaintPriv.h" #include "SkPath.h" #include "SkTemplates.h" #include "SkTypeface.h" @@ -387,38 +386,6 @@ void SkGlyphCache::dump() const { SkDebugf("%s\n", msg.c_str()); } -SkExclusiveStrikePtr SkGlyphCache::FindStrikeExclusive(const SkDescriptor& desc) { - return SkStrikeCache::FindStrikeExclusive(desc); -} - -SkExclusiveStrikePtr SkGlyphCache::FindOrCreateStrikeExclusive( - const SkDescriptor& desc, const SkScalerContextEffects& effects, const SkTypeface& typeface) -{ - auto cache = SkGlyphCache::FindStrikeExclusive(desc); - if (cache == nullptr) { - auto scaler = SkStrikeCache::CreateScalerContext(desc, effects, typeface); - cache = SkStrikeCache::CreateStrikeExclusive(desc, std::move(scaler)); - } - return cache; -} - -SkExclusiveStrikePtr SkGlyphCache::FindOrCreateStrikeExclusive( - const SkPaint& paint, - const SkSurfaceProps* surfaceProps, - SkScalerContextFlags scalerContextFlags, - const SkMatrix* deviceMatrix) -{ - SkAutoDescriptor ad; - SkScalerContextEffects effects; - - auto desc = SkScalerContext::CreateDescriptorAndEffectsUsingPaint( - paint, surfaceProps, scalerContextFlags, deviceMatrix, &ad, &effects); - - auto tf = SkPaintPriv::GetTypefaceOrDefault(paint); - - return FindOrCreateStrikeExclusive(*desc, effects, *tf); -} - #ifdef SK_DEBUG void SkGlyphCache::validate() const { diff --git a/src/core/SkGlyphCache.h b/src/core/SkGlyphCache.h index ca6ae8fb09..8d5098a496 100644 --- a/src/core/SkGlyphCache.h +++ b/src/core/SkGlyphCache.h @@ -123,24 +123,6 @@ public: SkScalerContext* getScalerContext() const { return fScalerContext.get(); } - static SkExclusiveStrikePtr FindStrikeExclusive(const SkDescriptor& desc); - - static SkExclusiveStrikePtr FindOrCreateStrikeExclusive( - const SkDescriptor& desc, - const SkScalerContextEffects& effects, - const SkTypeface& typeface); - - static SkExclusiveStrikePtr FindOrCreateStrikeExclusive( - const SkPaint& paint, - const SkSurfaceProps* surfaceProps, - SkScalerContextFlags scalerContextFlags, - const SkMatrix* deviceMatrix); - - static SkExclusiveStrikePtr FindOrCreateStrikeExclusive(const SkPaint& paint) { - return FindOrCreateStrikeExclusive( - paint, nullptr, SkScalerContextFlags::kFakeGammaAndBoostContrast, nullptr); - } - #ifdef SK_DEBUG void validate() const; #else @@ -244,11 +226,9 @@ public: SkAutoGlyphCacheNoGamma(const SkPaint& paint, const SkSurfaceProps* surfaceProps, const SkMatrix* matrix) - : INHERITED(SkGlyphCache::FindOrCreateStrikeExclusive( + : SkExclusiveStrikePtr(SkStrikeCache::FindOrCreateStrikeExclusive( paint, surfaceProps, SkScalerContextFlags::kNone, matrix)) {} -private: - using INHERITED = SkExclusiveStrikePtr; }; #define SkAutoGlyphCacheNoGamma(...) SK_REQUIRE_LOCAL_VAR(SkAutoGlyphCacheNoGamma) #endif diff --git a/src/core/SkOverdrawCanvas.cpp b/src/core/SkOverdrawCanvas.cpp index eee7d83afb..118b9431e3 100644 --- a/src/core/SkOverdrawCanvas.cpp +++ b/src/core/SkOverdrawCanvas.cpp @@ -63,7 +63,7 @@ void SkOverdrawCanvas::onDrawText(const void* text, size_t byteLength, SkScalar ProcessOneGlyphBounds processBounds(this); SkSurfaceProps props(0, kUnknown_SkPixelGeometry); this->getProps(&props); - auto cache = SkGlyphCache::FindOrCreateStrikeExclusive( + auto cache = SkStrikeCache::FindOrCreateStrikeExclusive( paint, &props, SkScalerContextFlags::kNone, &this->getTotalMatrix()); SkFindAndPlaceGlyph::ProcessText(paint.getTextEncoding(), (const char*) text, byteLength, SkPoint::Make(x, y), SkMatrix(), paint.getTextAlign(), @@ -76,7 +76,7 @@ void SkOverdrawCanvas::drawPosTextCommon(const void* text, size_t byteLength, co ProcessOneGlyphBounds processBounds(this); SkSurfaceProps props(0, kUnknown_SkPixelGeometry); this->getProps(&props); - auto cache = SkGlyphCache::FindOrCreateStrikeExclusive( + auto cache = SkStrikeCache::FindOrCreateStrikeExclusive( paint, &props, SkScalerContextFlags::kNone, &this->getTotalMatrix()); SkFindAndPlaceGlyph::ProcessPosText(paint.getTextEncoding(), (const char*) text, byteLength, SkPoint::Make(0, 0), SkMatrix(), (const SkScalar*) pos, 2, diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 3dc0af66f1..141b60b252 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -430,7 +430,7 @@ int SkPaint::textToGlyphs(const void* textData, size_t byteLength, uint16_t glyp return SkToInt(byteLength >> 1); } - auto cache = SkGlyphCache::FindOrCreateStrikeExclusive(*this); + auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(*this); const char* text = (const char*)textData; const char* stop = text + byteLength; @@ -487,7 +487,7 @@ bool SkPaint::containsText(const void* textData, size_t byteLength) const { return true; } - auto cache = SkGlyphCache::FindOrCreateStrikeExclusive(*this); + auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(*this); switch (this->getTextEncoding()) { case SkPaint::kUTF8_TextEncoding: { @@ -536,7 +536,7 @@ void SkPaint::glyphsToUnichars(const uint16_t glyphs[], int count, SkUnichar tex SkASSERT(textData != nullptr); SkSurfaceProps props(0, kUnknown_SkPixelGeometry); - auto cache = SkGlyphCache::FindOrCreateStrikeExclusive( + auto cache = SkStrikeCache::FindOrCreateStrikeExclusive( *this, &props, SkScalerContextFlags::kFakeGammaAndBoostContrast, nullptr); for (int index = 0; index < count; index++) { @@ -801,7 +801,7 @@ SkScalar SkPaint::measureText(const void* textData, size_t length, SkRect* bound const SkPaint& paint = canon.getPaint(); SkScalar scale = canon.getScale(); - auto cache = SkGlyphCache::FindOrCreateStrikeExclusive(paint); + auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(paint); SkScalar width = 0; @@ -854,7 +854,7 @@ size_t SkPaint::breakText(const void* textD, size_t length, SkScalar maxWidth, maxWidth /= scale; } - auto cache = SkGlyphCache::FindOrCreateStrikeExclusive(paint); + auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(paint); GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(paint.getTextEncoding(), paint.isDevKernText(), @@ -924,7 +924,7 @@ SkScalar SkPaint::getFontMetrics(FontMetrics* metrics, SkScalar zoom) const { { auto typeface = SkPaintPriv::GetTypefaceOrDefault(paint); - auto cache = SkGlyphCache::FindOrCreateStrikeExclusive(*desc, effects, *typeface); + auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(*desc, effects, *typeface); *metrics = cache->getFontMetrics(); } @@ -959,7 +959,7 @@ int SkPaint::getTextWidths(const void* textData, size_t byteLength, const SkPaint& paint = canon.getPaint(); SkScalar scale = canon.getScale(); - auto cache = SkGlyphCache::FindOrCreateStrikeExclusive(paint); + auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(paint); GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(paint.getTextEncoding(), paint.isDevKernText(), nullptr != bounds); @@ -1741,7 +1741,7 @@ SkTextBaseIter::SkTextBaseIter(const char text[], size_t length, } // SRGBTODO: Is this correct? - fCache = SkGlyphCache::FindOrCreateStrikeExclusive( + fCache = SkStrikeCache::FindOrCreateStrikeExclusive( fPaint, nullptr, SkScalerContextFlags::kFakeGammaAndBoostContrast, nullptr); diff --git a/src/core/SkRemoteGlyphCache.cpp b/src/core/SkRemoteGlyphCache.cpp index 9252589461..d73622327f 100644 --- a/src/core/SkRemoteGlyphCache.cpp +++ b/src/core/SkRemoteGlyphCache.cpp @@ -326,7 +326,7 @@ void SkTextBlobCacheDiffCanvas::processGlyphRun( auto typefaceID = SkTypefaceProxy::DownCast(runPaint.getTypeface())->remoteTypefaceID(); auto& diffs = fStrikeCacheDiff->findStrikeDifferences(*desc, typefaceID); - auto cache = SkGlyphCache::FindStrikeExclusive(*desc); + auto cache = SkStrikeCache::FindStrikeExclusive(*desc); bool isSubpixel = SkToBool(rec.fFlags & SkScalerContext::kSubpixelPositioning_Flag); SkAxisAlignment axisAlignment = SkAxisAlignment::kNone_SkAxisAlignment; if (it.positioning() == SkTextBlob::kHorizontal_Positioning) { @@ -480,7 +480,7 @@ static void update_caches_from_strikes_data(SkStrikeClient *client, // TODO: implement effects handling. SkScalerContextEffects effects; - auto strike = SkGlyphCache::FindStrikeExclusive(*desc); + auto strike = SkStrikeCache::FindStrikeExclusive(*desc); if (strike == nullptr) { auto scaler = SkStrikeCache::CreateScalerContext(*desc, effects, *tf); strike = SkStrikeCache::CreateStrikeExclusive(*desc, std::move(scaler), fontMetrics); diff --git a/src/core/SkStrikeCache.cpp b/src/core/SkStrikeCache.cpp index 8d0b8326d3..f5ae5bce35 100644 --- a/src/core/SkStrikeCache.cpp +++ b/src/core/SkStrikeCache.cpp @@ -17,6 +17,7 @@ #include "SkTraceMemoryDump.h" #include "SkTypeface.h" #include "SkTypefaceCache.h" +#include "SkPaintPriv.h" // Returns the shared globals static SkStrikeCache& get_globals() { @@ -378,4 +379,37 @@ SkExclusiveStrikePtr SkStrikeCache::CreateStrikeExclusive( } return SkExclusiveStrikePtr(new SkGlyphCache(desc, move(scaler), fontMetrics)); +} + +SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeExclusive( + const SkDescriptor& desc, const SkScalerContextEffects& effects, const SkTypeface& typeface) +{ + auto cache = FindStrikeExclusive(desc); + if (cache == nullptr) { + auto scaler = CreateScalerContext(desc, effects, typeface); + cache = CreateStrikeExclusive(desc, move(scaler)); + } + return cache; +} + +SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeExclusive( + const SkPaint& paint, + const SkSurfaceProps* surfaceProps, + SkScalerContextFlags scalerContextFlags, + const SkMatrix* deviceMatrix) +{ + SkAutoDescriptor ad; + SkScalerContextEffects effects; + + auto desc = SkScalerContext::CreateDescriptorAndEffectsUsingPaint( + paint, surfaceProps, scalerContextFlags, deviceMatrix, &ad, &effects); + + auto tf = SkPaintPriv::GetTypefaceOrDefault(paint); + + return FindOrCreateStrikeExclusive(*desc, effects, *tf); +} + +SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeExclusive(const SkPaint& paint) { + return FindOrCreateStrikeExclusive( + paint, nullptr, kFakeGammaAndBoostContrast, nullptr); }
\ No newline at end of file diff --git a/src/core/SkStrikeCache.h b/src/core/SkStrikeCache.h index 078adfe9de..a72e71f232 100644 --- a/src/core/SkStrikeCache.h +++ b/src/core/SkStrikeCache.h @@ -46,14 +46,27 @@ public: static ExclusiveStrikePtr FindStrikeExclusive(const SkDescriptor&); - static std::unique_ptr<SkScalerContext> CreateScalerContext( - const SkDescriptor&, const SkScalerContextEffects&, const SkTypeface&); - static ExclusiveStrikePtr CreateStrikeExclusive( const SkDescriptor& desc, std::unique_ptr<SkScalerContext> scaler, SkPaint::FontMetrics* maybeMetrics = nullptr); + static ExclusiveStrikePtr FindOrCreateStrikeExclusive( + const SkDescriptor& desc, + const SkScalerContextEffects& effects, + const SkTypeface& typeface); + + static ExclusiveStrikePtr FindOrCreateStrikeExclusive( + const SkPaint& paint, + const SkSurfaceProps* surfaceProps, + SkScalerContextFlags scalerContextFlags, + const SkMatrix* deviceMatrix); + + static ExclusiveStrikePtr FindOrCreateStrikeExclusive(const SkPaint& paint); + + static std::unique_ptr<SkScalerContext> CreateScalerContext( + const SkDescriptor&, const SkScalerContextEffects&, const SkTypeface&); + static void PurgeAll(); static void Dump(); |